Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

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

Posted on 2012-04-11
2
Medium Priority
?
1,116 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 2000 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

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

Little introduction about CP: CP is a command on linux that use to copy files and folder from one location to another location. Example usage of CP as follow: cp /myfoder /pathto/destination/folder/ cp abc.tar.gz /pathto/destination/folder/ab…
Google Drive is extremely cheap offsite storage, and it's even possible to get extra storage for free for two years.  You can use the free account 15GB, and if you have an Android device..when you install Google Drive for the first time it will give…
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…
How to Install VMware Tools in Red Hat Enterprise Linux 6.4 (RHEL 6.4) Step-by-Step Tutorial
Suggested Courses

610 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