This is the mail archive of the gcc@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]

-fxref


I would like to generate static call graphs from C++ code, but there is a
substantial problem in handling virtual calls.

See...
http://groups.yahoo.com/group/extremeprogramming/files/call_graph.png
for an example. (Generated from parsing the assembler output of gcc
with class names changed to protect the guilty. Virtual calls are
missing in that graph.)

The -fxref option seems to do almost (but not quite) what I need. For example ....

Using...
gcc --version
2.95.3

If I feed to ... gcc -O0 -fxref...
======================================================================
#include <iostream.h>

class EasyToFindClassName
{
public :
  virtual int easyToSeeFunctionName();
};

class SonOfEasyToFindClassName : public EasyToFindClassName
{
public :
  virtual int easyToSeeFunctionName();
};

class UnrelatedClass
{
public :
  virtual int easyToSeeFunctionName(); // Gotcha, not related at all at all....
};

int EasyToFindClassName::easyToSeeFunctionName()
{
  cout << __PRETTY_FUNCTION__ << endl;
}

int SonOfEasyToFindClassName::easyToSeeFunctionName()
{
  cout << __PRETTY_FUNCTION__ << endl;
}

int UnrelatedClass::easyToSeeFunctionName()
{
  cout << __PRETTY_FUNCTION__ << endl;
}

main()
{
  SonOfEasyToFindClassName soetfcn;
  EasyToFindClassName * etfcn = &soetfcn;
  UnrelatedClass * uc = new UnrelatedClass();

  etfcn->easyToSeeFunctionName();
  uc->easyToSeeFunctionName();
}
======================================================================

The relavent bit of the .gxref is....

======================================================================
REF * 42 * etfcn
REF * 42 * easyToSeeFunctionName
REF * 43 * uc
REF * 43 * easyToSeeFunctionName
======================================================================

Which leaves my post processing script unable to see whether it is
EasyToFindClassName::easyToSeeFunctionName() (or the overiding
function) is being called or UnrelatedClass::easyToSeeFunctionName()
is being called.

I suspect a very simple tweak to xref.c will cure that if I know what
part of and how the TREE can tell me the class name of a virtual
function.

Any help?


John Carter                             Phone : (64)(3) 358 6639
Tait Electronics                        Fax   : (64)(3) 359 4632
PO Box 1645 Christchurch                Email : john.carter@tait.co.nz
New Zealand

Time machine feature - A feature that is best implemented by climbing
into a time machine with an AK-47 and taking out the swine who
spec'd it.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]