How to print virtual table

O

Owen Zhang

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.
 
V

Victor Bazarov

Owen said:
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
 
T

terminator

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'.because implementation is more of a
compiler design issue than OS.

regards,
FM.
 
V

Victor Bazarov

terminator said:
Sorry,I do not want to get you upset but must have meant 'the news
group for your compiler/platform'.because 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
 
A

Abhishek Padmanabh

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 misunderstanding 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.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
474,184
Messages
2,570,979
Members
47,579
Latest member
CharaS3188

Latest Threads

Top