[LLVMdev] Idioms for retrieving global symbols and inheritance

Pratik Mehta mehta.pr.y at gmail.com
Sun Mar 19 02:58:09 PST 2006


Hello,

  I have a couple of doubts, as listed below:

1. To list all the global variables in the module, I am iterating
using type_iterator and for each Type I get, I am using value_iterator
to iterate over Values . In the second iteration I am getting
unexpected results. For each type obtained from type_iterator->second,
value_iterator->first produces the same list as what
type_iterator->first would produce. Also, an attempt to access
value_iterator->second->getName() produces junk names.
value_iterator->second->hasName() causes segfaults. All this is
compiled fine. Following is sample code and output.

Code:
-------------
for ( SymbolTable::type_iterator itr1 = symbTab.type_begin(), itrend1
= symbTab.type_end(); itr1 != itrend1; itr1++ ) {
  string typeName = itr1->first;
  if ( lldbprfx.compare( typeName.substr( 0, 5 ) ) != 0 ) {
    cerr << typeName << endl;
    for ( SymbolTable::value_const_iterator itr2 =
symbTab.value_begin( itr1->second ),
     itrend2 = symbTab.value_end( itr1->second ); itr2 != itrend2; itr2++ ) {
      if ( lldbprfx.compare( ( itr2->first ).substr( 0, 5 ) ) != 0 ) {
        cerr << "\t" << itr2->first << endl; //Produces same list that
is produced by itr1
//      cerr << itr2->second->getName() << endl;
//      This outputs junk (including unprintablecharacters)
      }
    }
  }
}
-----------
Output: for a small sample file
-----------
struct.TiXmlString
        struct.TiXmlString
        struct.TiXmlString::Rep
struct.TiXmlString::Rep
        struct.TiXmlString
        struct.TiXmlString::Rep

2. To retrieve subtypes of a given type, subtype_iterator can be used,
but how to obtain type names from the subtype pointers obtained is not
clear. In general, for an analyzed C++ code, is it possible to obtain
inheritance information?

TIA




More information about the llvm-dev mailing list