Solved

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

Posted on 2012-04-11
2
976 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
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

How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

Join & Write a Comment

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…
Container Orchestration platforms empower organizations to scale their apps at an exceptional rate. This is the reason numerous innovation-driven companies are moving apps to an appropriated datacenter wide platform that empowers them to scale at a …
Learn how to get help with Linux/Unix bash shell commands. Use help to read help documents for built in bash shell commands.: Use man to interface with the online reference manuals for shell commands.: Use man to search man pages for unknown command…
The goal of the tutorial is to teach the user how to use functions in C++. The video will cover how to define functions, how to call functions and how to create functions prototypes. Microsoft Visual C++ 2010 Express will be used as a text editor an…

708 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

Need Help in Real-Time?

Connect with top rated Experts

14 Experts available now in Live!

Get 1:1 Help Now