Solved

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

Posted on 2012-04-11
2
1,011 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

VMware Disaster Recovery and Data Protection

In this expert guide, you’ll learn about the components of a Modern Data Center. You will use cases for the value-added capabilities of Veeam®, including combining backup and replication for VMware disaster recovery and using replication for data center migration.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
installing docker on ubuntu 6 29
linux(debian) mouse poor performance 4 41
Bash script - Exit out of choice loop 2 28
Linux mount of Windows Shared Now Fails 8 33
If you have a server on collocation with the super-fast CPU, that doesn't mean that you get it running at full power. Here is a preamble. When doing inventory of Linux servers, that I'm administering, I've found that some of them are running on l…
Fine Tune your automatic Updates for Ubuntu / Debian
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…
The viewer will be introduced to the technique of using vectors in C++. The video will cover how to define a vector, store values in the vector and retrieve data from the values stored in the vector.

770 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