LinuxQuestions.org
Support LQ: Use code LQ3 and save $3 on Domain Registration
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices

Reply
 
Search this Thread
Old 02-19-2011, 01:53 AM   #1
TheIndependentAquarius
Senior Member
 
Registered: Dec 2008
Posts: 4,622
Blog Entries: 29

Rep: Reputation: 896Reputation: 896Reputation: 896Reputation: 896Reputation: 896Reputation: 896Reputation: 896
Any option in GCC to SEE the dynamic bindings processing happening, in the compilation output?


No, I am not talking about linking the dynamic libraries,
I am talking about the dynamic binding happening w.r.t
the virtual functions.
 
Click here to see the post LQ members have rated as the most helpful post in this thread.
Old 02-20-2011, 10:51 AM   #2
Kenny_Strawn
Senior Member
 
Registered: Feb 2010
Location: /usa/ca/orange_county/lake_forest
Distribution: ArchBang, Google Android 2.1 + Motoblur (on Motortola Flipside), Google Chrome OS (on Cr-48)
Posts: 1,791
Blog Entries: 62

Rep: Reputation: 54
Well, make does post output, but not GCC. Of course, you do get error messages from GCC, but that's normal. I suppose if you have enough programming skills you could fork GCC to make it display a progress bar or something (or maybe create a GUI frontend to GCC), but either of these things would be pushing it.
 
0 members found this post helpful.
Old 02-21-2011, 07:25 PM   #3
wje_lq
Member
 
Registered: Sep 2007
Location: Mariposa
Distribution: Debian lenny, Slackware 12
Posts: 808

Rep: Reputation: 178Reputation: 178
Quote:
Originally Posted by Anisha Kaul View Post
No, I am not talking about linking the dynamic libraries,
I am talking about the dynamic binding happening w.r.t
the virtual functions.
C++, right? It's been a while since I've used virtual functions, or even C++. Could you illustrate with a tiny, compilable C++ program we can play around with?
 
Old 02-21-2011, 07:28 PM   #4
TheIndependentAquarius
Senior Member
 
Registered: Dec 2008
Posts: 4,622
Blog Entries: 29

Original Poster
Rep: Reputation: 896Reputation: 896Reputation: 896Reputation: 896Reputation: 896Reputation: 896Reputation: 896
Thanks a ton for responding wje_lq,

I thought I asked a pathetic question I have an example too and have found a possible solution option too, but
it doesn't seem to work , soon I'll present them here.
 
Old 02-21-2011, 11:32 PM   #5
TheIndependentAquarius
Senior Member
 
Registered: Dec 2008
Posts: 4,622
Blog Entries: 29

Original Poster
Rep: Reputation: 896Reputation: 896Reputation: 896Reputation: 896Reputation: 896Reputation: 896Reputation: 896
Yeah on C++, but could have been Java too, how did you guess it?

With respect to this quote:
Code:
G++'s -fdump-class-hierarchy argument can be used to dump virtual method tables for manual inspection.
from this link: http://en.wikipedia.org/wiki/Virtual_method_table

I tried the following:
Code:
#include <iostream>
using namespace std;

class a
{
     public:
	  virtual void f1 ();
};

void a :: f1 () {}

class b : public a
{
     public:
	  void f1 ();
};

void b :: f1 () {}

int main ()
{
     b obj1;
     obj1.f1 ();
     
     return 0;
}
Its compilation output shows NOTHING
Code:
anisha@linux-uitj:~> g++ -Wall -Wextra virtual.cpp -fdump-class-hierarchy
anisha@linux-uitj:~>
 
Old 02-22-2011, 05:08 AM   #6
wje_lq
Member
 
Registered: Sep 2007
Location: Mariposa
Distribution: Debian lenny, Slackware 12
Posts: 808

Rep: Reputation: 178Reputation: 178
When I ran this shell script:
Code:
rm -f *.class; cat > virtual.cpp <<EOD; g++ -Wall -Wextra virtual.cpp -fdump-class-hierarchy; ls -l virtual*.class; cat virtual*.class
#include <iostream>
using namespace std;

class a
{
     public:
          virtual void f1 ();
};

void a :: f1 () {}

class b : public a
{
     public:
          void f1 ();
};

void b :: f1 () {}

int main ()
{
     b obj1;
     obj1.f1 ();
     
     return 0;
}
EOD
I got this output (snipped in the middle for brevity):
Code:
-rw------- 1 wally wally 67688 Feb 22 02:57 virtual.cpp.002t.class
Class <anonymous struct>::<anonymous union>
   size=4 align=4
   base size=4 base align=4
<anonymous struct>::<anonymous union> (0xb777c078) 0

Class <anonymous struct>
   size=8 align=4
   base size=8 base align=4
<anonymous struct> (0xb777c000) 0

Class __locale_struct
   size=116 align=4
   base size=116 base align=4
__locale_struct (0xb777c0b4) 0

Vtable for std::exception
std::exception::_ZTVSt9exception: 5u entries
0     (int (*)(...))0
4     (int (*)(...))(& _ZTISt9exception)
8     std::exception::~exception
12    std::exception::~exception
16    std::exception::what

Class std::exception
   size=4 align=4
   base size=4 base align=4
std::exception (0xb777c708) 0 nearly-empty
    vptr=((& std::exception::_ZTVSt9exception) + 8u)

---------->8---------->8---------->8----------

Class std::basic_iostream<wchar_t, std::char_traits<wchar_t> >
   size=152 align=4
   base size=12 base align=4
std::basic_iostream<wchar_t, std::char_traits<wchar_t> > (0xb706ebd0) 0
    vptridx=0u vptr=((& std::basic_iostream<wchar_t, std::char_traits<wchar_t> >::_ZTVSt14basic_iostreamIwSt11char_traitsIwEE) + 12u)
  std::basic_istream<wchar_t, std::char_traits<wchar_t> > (0xb7252840) 0
      primary-for std::basic_iostream<wchar_t, std::char_traits<wchar_t> > (0xb706ebd0)
      subvttidx=4u
    std::basic_ios<wchar_t, std::char_traits<wchar_t> > (0xb7252880) 12 virtual
        vptridx=20u vbaseoffset=-0x0000000000000000c vptr=((& std::basic_iostream<wchar_t, std::char_traits<wchar_t> >::_ZTVSt14basic_iostreamIwSt11char_traitsIwEE) + 52u)
      std::ios_base (0xb721da14) 12
          primary-for std::basic_ios<wchar_t, std::char_traits<wchar_t> > (0xb7252880)
  std::basic_ostream<wchar_t, std::char_traits<wchar_t> > (0xb72528c0) 8 nearly-empty
      subvttidx=12u vptridx=24u vptr=((& std::basic_iostream<wchar_t, std::char_traits<wchar_t> >::_ZTVSt14basic_iostreamIwSt11char_traitsIwEE) + 32u)
    std::basic_ios<wchar_t, std::char_traits<wchar_t> > (0xb7252880) alternative-path

Vtable for a
a::_ZTV1a: 3u entries
0     (int (*)(...))0
4     (int (*)(...))(& _ZTI1a)
8     a::f1

Class a
   size=4 align=4
   base size=4 base align=4
a (0xb721ddd4) 0 nearly-empty
    vptr=((& a::_ZTV1a) + 8u)

Vtable for b
b::_ZTV1b: 3u entries
0     (int (*)(...))0
4     (int (*)(...))(& _ZTI1b)
8     b::f1

Class b
   size=4 align=4
   base size=4 base align=4
b (0xb7252a40) 0 nearly-empty
    vptr=((& b::_ZTV1b) + 8u)
  a (0xb721dfb4) 0 nearly-empty
      primary-for b (0xb7252a40)
Is this what you wanted?

Last edited by wje_lq; 02-22-2011 at 05:10 AM.
 
2 members found this post helpful.
Old 02-22-2011, 05:40 AM   #7
TheIndependentAquarius
Senior Member
 
Registered: Dec 2008
Posts: 4,622
Blog Entries: 29

Original Poster
Rep: Reputation: 896Reputation: 896Reputation: 896Reputation: 896Reputation: 896Reputation: 896Reputation: 896
Exactly, that's what I was looking for, but I didn't know that that
option produced some output files , now when I do ls, I
see a dozen!

I shall try to understand that vtable now. Thanks again.

(All that's for understanding the conceptual differences between
static and dynamic bindings )

Last edited by TheIndependentAquarius; 02-22-2011 at 05:42 AM.
 
Old 02-22-2011, 11:56 AM   #8
wje_lq
Member
 
Registered: Sep 2007
Location: Mariposa
Distribution: Debian lenny, Slackware 12
Posts: 808

Rep: Reputation: 178Reputation: 178
Quote:
Originally Posted by Anisha Kaul View Post
I didn't know that that option produced some output files
Um, I didn't know until I read the man page for g++ this morning. :)
 
Old 02-23-2011, 01:19 AM   #9
TheIndependentAquarius
Senior Member
 
Registered: Dec 2008
Posts: 4,622
Blog Entries: 29

Original Poster
Rep: Reputation: 896Reputation: 896Reputation: 896Reputation: 896Reputation: 896Reputation: 896Reputation: 896
I too had read the man page but only uptill here:
Code:
Debugging Options
           -dletters  -dumpspecs  -dumpmachine  -dumpversion -fdbg-cnt-list -fdbg-cnt=counter-value-
           list -fdump-noaddr -fdump-unnumbered -fdump-translation-unit[-n] -fdump-class-hierarchy[-n]
           -fdump-ipa-all -fdump-ipa-cgraph -fdump-ipa-inline -fdump-statistics -fdump-tree-all
           -fdump-tree-original[-n] -fdump-tree-optimized[-n] -fdump-tree-cfg -fdump-tree-vcg
           -fdump-tree-alias -fdump-tree-ch -fdump-tree-ssa[-n] -fdump-tree-pre[-n]
           -fdump-tree-ccp[-n] -fdump-tree-dce[-n] -fdump-tree-gimple[-raw] -fdump-tree-mudflap[-n]
           -fdump-tree-dom[-n] -fdump-tree-dse[-n] -fdump-tree-phiopt[-n] -fdump-tree-forwprop[-n]
           -fdump-tree-copyrename[-n] -fdump-tree-nrv -fdump-tree-vect -fdump-tree-sink
How could I have guessed that I need to scroll till end!
 
  


Reply

Tags
c++


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Option negotiation is not happening in TFTP IPv6 mode kamalsivadas Linux - Networking 0 01-05-2010 07:07 AM
gcc (GCC) 4.3.2 20081105 (Red Hat 4.3.2-7) compilation error adhesh_19 Red Hat 0 01-05-2010 05:34 AM
how to place the output of compilation to some file (gcc) mlaich Programming 2 12-13-2005 05:52 PM
apt-get -> testing, errors processing package lists, Dynamic MMap??? gaffel Debian 5 07-16-2004 01:30 PM


All times are GMT -5. The time now is 05:48 PM.

Main Menu
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
identi.ca: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration