How to dump inheritance information of c++ binaries?

P

Peter Jakobi

Hello,

i am looking for a tool, which dumps inheritance information of c++
binaries. Does such a tool exist??

Can I retrieve interitance from the output of objdump or something
else? Does someone have an idea?

Thanks!!
Pet
 
P

Pete Becker

Peter said:
Hello,

i am looking for a tool, which dumps inheritance information of c++
binaries. Does such a tool exist??

Not easily. Unlike Java, C++ doesn't build a debugger into every
application.
 
P

Peter Jakobi

Hello,
Not easily. Unlike Java, C++ doesn't build a debugger into every
application.

Maybe there are hints for inheritance in the objdump output?
Unfortunately I am not a profi in disassembler code.

Pet
 
P

Puppet_Sock

Peter said:
i am looking for a tool, which dumps inheritance information of c++
binaries. Does such a tool exist??

Can I retrieve interitance from the output of objdump or something
else? Does someone have an idea?

Search the archive for "decompiler" and read those
threads. Also look for "cow from burger" and "pig
from sausages."

And consider that even if debug information is included,
it does not necessarily include inheritance info. For
example, if a prog defines A->B->C->D then only uses C,
you may not have any infor about classes A,B, and D
in the binary, even in debug.
Socks
 
P

Peter Jakobi

Hello,

I am not sure. But is there not a certain table in each binary which
stores the inheritance??

For example: Someone calls a funtion abc() of a object A. But class A
does not implement this method. The method is implemented by a
superclass B.

Resolves this problem the compiler? Or contains the binary some
information about superclasses or inherit methods?

Thanks,
Pet
 
V

Victor Bazarov

Peter said:
I am not sure. But is there not a certain table in each binary which
stores the inheritance??

No. Inheritance is a concept the programmer uses when writing code.
Binaries are concept-free. They only contain machine instructions and
some limited amount of data.
For example: Someone calls a funtion abc() of a object A. But class A
does not implement this method. The method is implemented by a
superclass B.

If someone calls 'A::abc()' for an object A, and class A does not
implement it, there will be an error.
Resolves this problem the compiler? Or contains the binary some
information about superclasses or inherit methods?

I think you need to read "Inside the C++ Object Model". Whatever you're
asking is (a) phrased too vaguely and (b) cannot be answered using some
few sentences in a newsgroup post.

V
 
M

Michael Davis

Peter said:
Hello,

I am not sure. But is there not a certain table in each binary which
stores the inheritance??

Hi,

It's up to the implementation, but in Stroustrup's book The C++ Programming
Language he describes a possible scheme (probably used by most compilers)
where there is an array of function pointers called _vtab[] (if I remember
correctly), which point to the inherited functions.
For example: Someone calls a funtion abc() of a object A. But class A
does not implement this method. The method is implemented by a
superclass B.

In this case _vtab will just have one entry:

_vtab[0] = (the address of) B:abc()

It's been a long time, but I seem to remember that there is one vtab for
each virual function in each object.

If A did override abc, then there would be two entries in the array.
Resolves this problem the compiler? Or contains the binary some
information about superclasses or inherit methods?

Both, I figure.

Michael Davis
Toronto
 
P

Peter Jakobi

Hi Michael,

thank you very much!! I think the _vtab[] is exactly that, what I need.
Now I have to find out a way to dump the information which are stored
in the _vtab[].

Maybe there are some tools for that kind of work??

Unfortunately I don't find such a tool. Can you give me some hints,
please?

Pet
 
B

benben

It's up to the implementation, but in Stroustrup's book The C++ Programming
Language he describes a possible scheme (probably used by most compilers)
where there is an array of function pointers called _vtab[] (if I remember
correctly), which point to the inherited functions.

Would you tell me on which page is _vtab[] described?? I have been reading
the book for years yet I still haven't got anything like that...??

ben
 
M

msalters

Michael said:
Peter said:
Hello,

I am not sure. But is there not a certain table in each binary which
stores the inheritance??

Hi,

It's up to the implementation, but in Stroustrup's book The C++ Programming
Language he describes a possible scheme (probably used by most compilers)
where there is an array of function pointers called _vtab[] (if I remember
correctly), which point to the inherited functions.

Names vary, but the implementation is a common one.
It works especially well in the presence of single
non-virtual inheritance. However, it's not the only
possible mechanism, and other mechanisms /must/ be used
for virtual inheritance.
For example: Someone calls a funtion abc() of a object A. But class A
does not implement this method. The method is implemented by a
superclass B.

In this case _vtab will just have one entry:

_vtab[0] = (the address of) B:abc()

Perhaps. Another possibility is that the compiler knows
at compile time that you're working on an A, that A has
no abc so you must mean B::abc. In that case it will just
substitute a call to B::abc(). If that's the only call to
abc(), it doesn't even have to appear in the vtable
It's been a long time, but I seem to remember that there is one vtab for
each virual function in each object.

One vtable entry, that is, and per class (not object).
Again, the same disclaimers (not universal, especially
not for complex cases, not when optimized out) apply.
If A did override abc, then there would be two entries in the array.

No. There would be two vtables, each with one entry. Each
object would point to the correct one, set by the ctor.
So if you construct an A, you get the A vtable and A::abc()
even if you use a B* pointer to the A.

(and this all aplies to virtual functions only, hence the
v in vtable.)

You might want to look at "typeid".

HTH,
Michiel Salters
 

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

No members online now.

Forum statistics

Threads
473,769
Messages
2,569,580
Members
45,054
Latest member
TrimKetoBoost

Latest Threads

Top