How to print virtual table

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Owen Zhang

    #1

    How to print virtual table

    I am trying to debug a problem using dbx in sun 5.9. I want to print
    the virtual table from dbx. Find the real address of the virtual
    function of the object.
  • Victor Bazarov

    #2
    Re: How to print virtual table

    Owen Zhang wrote:
    I am trying to debug a problem using dbx in sun 5.9. I want to print
    the virtual table from dbx. Find the real address of the virtual
    function of the object.
    This is not a C++ language question, but rather a 'dbx' question.
    C++ language has no concept of "virtual table". I am guessing that
    you are referring to the virtual function table, a common virtual
    function mechanism implementation. Unfortunately it's not defined
    by the language itself, it's an implementation detail. Besides,
    you're asking how to do something in a product, which makes it OT
    altogether. We don't discuss products here beyond their existence
    and maybe quality of C++ compilers (a little bit).

    Please consider asking in the newsgroup for your OS if there is no
    group for 'dbx' specifically.

    V
    --
    Please remove capital 'A's when replying by e-mail
    I do not respond to top-posted replies, please don't ask


    Comment

    • terminator

      #3
      Re: How to print virtual table

      On Dec 7, 6:05 pm, "Victor Bazarov" <v.Abaza...@com Acast.netwrote:
      Please consider asking in the newsgroup for your OS if there is no
      group for 'dbx' specifically.
      >
      Sorry,I do not want to get you upset but must have meant 'the news
      group for your compiler/platform'.becau se implementation is more of a
      compiler design issue than OS.

      regards,
      FM.

      Comment

      • Victor Bazarov

        #4
        Re: How to print virtual table

        terminator wrote:
        On Dec 7, 6:05 pm, "Victor Bazarov" <v.Abaza...@com Acast.netwrote:
        >
        >Please consider asking in the newsgroup for your OS if there is no
        >group for 'dbx' specifically.
        >>
        >
        Sorry,I do not want to get you upset but must have meant 'the news
        group for your compiler/platform'.becau se implementation is more of a
        compiler design issue than OS.
        While AFAIK _all_ compilers implement the virtual function mechanism
        using a virtual function table, printing it out is never a feature
        a compiler has (at least none of the compilers I've seen offered that
        as an extension). The debugger, on the other hand, has more insight
        into the guts of the process/objects, and it is usually a feature of
        the OS (although I suppose the compiler must be able to work with it
        to introduce debugging information accordingly). That's why asking
        in the newsgroup dedicated to debuggers (tools) or OS is what I meant.

        V
        --
        Please remove capital 'A's when replying by e-mail
        I do not respond to top-posted replies, please don't ask


        Comment

        • Abhishek Padmanabh

          #5
          Re: How to print virtual table

          On Dec 7, 8:01 pm, Owen Zhang <owenzhang.chic ...@gmail.comwr ote:
          I am trying to debug a problem using dbx in sun 5.9. I want to print
          the virtual table from dbx. Find the real address of the virtual
          function of the object.
          There might be a little misunderstandin g here, or not. The virtual
          function pointer usually will be the same for all the objects as the v-
          table that contains the vptrs is common to the class. But there is a
          pointer at the starting address of a polymorphic object that points to
          the corresponding vtable. That pointer will be a different one but
          will probably point on the same table depending upon the dynamic type
          of the object. (-- all this, related to vtable/vfptr/vptr depends on
          your particular compiler implementation of the runtime polymorphism/
          dynamic dispatch).

          I am not sure how the actual virtual function pointers are going to
          help you with the debugging but then I don't know your problem at hand
          as well. There are specific compiler flags that may be help you get
          some data around the vtable structures. For example, with g++, you
          could analyze that with the build option -fdump-class-hierarchy. There
          might (or might not) be some other alternative for your specific
          compiler. You could use that to see the v-table layout.

          You could also, add some code to help you with that information at
          runtime. This could be done by creating a bunch of objects of the
          types that you are dealing with/want to analyze the v-table/v-ptrs of,
          and take addresses of the various functions that are part of that
          object's interface. You could tweak around the data that you want,
          depending upon what actually do you want it for.

          Comment

          Working...