By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
448,677 Members | 1,272 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 448,677 IT Pros & Developers. It's quick & easy.

How to dump inheritance information of c++ binaries?

P: n/a
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

Jul 23 '05 #1
Share this Question
Share on Google+
9 Replies


P: n/a
Peter Jakobi wrote:
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.

--

Pete Becker
Dinkumware, Ltd. (http://www.dinkumware.com)
Jul 23 '05 #2

P: n/a
>> 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.


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

Pet

Jul 23 '05 #3

P: n/a
Peter Jakobi wrote:
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

Jul 23 '05 #4

P: n/a
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

Jul 23 '05 #5

P: n/a
Peter Jakobi wrote:
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
Jul 23 '05 #6

P: n/a
Peter Jakobi wrote:
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

Jul 23 '05 #7

P: n/a
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

Jul 23 '05 #8

P: n/a
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
Jul 23 '05 #9

P: n/a
Michael Davis wrote:
Peter Jakobi wrote:
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

Jul 23 '05 #10

This discussion thread is closed

Replies have been disabled for this discussion.