Solved

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

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

The Eight Noble Truths of Backup and Recovery

How can IT departments tackle the challenges of a Big Data world? This white paper provides a roadmap to success and helps companies ensure that all their data is safe and secure, no matter if it resides on-premise with physical or virtual machines or in the cloud.

Question has a verified solution.

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

Article by: SunnyDark
This article's goal is to present you with an easy to use XML wrapper for C++ and also present some interesting techniques that you might use with MS C++. The reason I built this class is to ease the pain of using XML files with C++, since there is…
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…
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.
This demo shows you how to set up the containerized NetScaler CPX with NetScaler Management and Analytics System in a non-routable Mesos/Marathon environment for use with Micro-Services applications.

707 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