Solved

How to intepret output from gcc fdump-class-hierarchy option

Posted on 2012-04-11
2
1,049 Views
Last Modified: 2012-04-11
I have a simple class and wanted to study how it is organized into memory.
How can I interpret the following which was produced by using -fdump-class-hierarchy option in gcc.

Basically, I want to know where the vptr will be located in relation to the array for example.

Vtable for A
A::_ZTV1A: 3u entries
0     (int (*)(...))0
4     (int (*)(...))(& _ZTI1A)
8     A::SendCommand

Class A
   size=48 align=4
   base size=48 base align=4
A (0x223a600) 0
    vptr=((& A::_ZTV1A) + 8u)

Open in new window


class A
{
	public:
		A() { cout << "A's Constructor" << endl; };
		virtual void SendCommand(){};
		void setArray()
		{
			for(int i =0; i < 10; i++ )
			{
				m_array[i] = 'A';
			};
		};
	private:
		int m_a;
		int m_array[MAX_ARRAY];
};

Open in new window

0
Comment
Question by:ambuli
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
2 Comments
 
LVL 53

Accepted Solution

by:
Infinity08 earned 500 total points
ID: 37833826
>> How can I interpret the following which was produced by using -fdump-class-hierarchy option in gcc.

Vtable for A                            # first the vtable for the A class is listed
A::_ZTV1A: 3u entries                   # there are 3 entries in the vtable (aka _ZTV1A)
0     (int (*)(...))0                   # the first entry is always 0
4     (int (*)(...))(& _ZTI1A)          # the second entry is always a pointer to the typeinfo (aka _ZTI1A)
8     A::SendCommand                    # next follow entries for each of the virtual functions

Class A                                 # some more specifics about the A class
   size=48 align=4                      # the total size of an object is 48 bytes, with alignment on 4-byte boundaries
   base size=48 base align=4            # same information, but without taking alignment into account
A (0x223a600) 0                         # the pointer to the vtable can be found at offset 0 of an object
    vptr=((& A::_ZTV1A) + 8u)           # the virtual functions in the vtable can be found at offset 8 into the vtable

Open in new window



>> Basically, I want to know where the vptr will be located in relation to the array for example.

For gcc, the vptr is always in the first word of the object.
0
 

Author Closing Comment

by:ambuli
ID: 37834063
Great! Thank you.
0

Featured Post

Free learning courses: Active Directory Deep Dive

Get a firm grasp on your IT environment when you learn Active Directory best practices with Veeam! Watch all, or choose any amount, of this three-part webinar series to improve your skills. From the basics to virtualization and backup, we got you covered.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

When writing generic code, using template meta-programming techniques, it is sometimes useful to know if a type is convertible to another type. A good example of when this might be is if you are writing diagnostic instrumentation for code to generat…
Using 'screen' for session sharing, The Simple Edition Step 1: user starts session with command: screen Step 2: other user (logged in with same user account) connects with command: screen -x Done. Both users are connected to the same CLI sessio…
The goal of the video will be to teach the user the difference and consequence of passing data by value vs passing data by reference in C++. An example of passing data by value as well as an example of passing data by reference will be be given. Bot…
Get a first impression of how PRTG looks and learn how it works.   This video is a short introduction to PRTG, as an initial overview or as a quick start for new PRTG users.

733 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question