Gaudi Framework, version v22r0

Home   Generated: 9 Feb 2011

FileInfo Class Reference

Collaboration diagram for FileInfo:
Collaboration graph
[legend]

List of all members.

Classes

struct  CacheItem
struct  CacheItemComparator

Public Types

typedef int Offset

Public Member Functions

 FileInfo (void)
 FileInfo (const std::string &name, bool useGdb)
const char * symbolByOffset (Offset offset)
Offset next (Offset offset)

Public Attributes

std::string NAME

Private Types

typedef std::vector< CacheItemSymbolCache

Private Member Functions

void createOffsetMap (void)

Private Attributes

SymbolCache m_symbolCache

Detailed Description

Definition at line 163 of file pfm_gen_analysis.cpp.


Member Typedef Documentation

typedef int FileInfo::Offset

Definition at line 166 of file pfm_gen_analysis.cpp.

Definition at line 218 of file pfm_gen_analysis.cpp.


Constructor & Destructor Documentation

FileInfo::FileInfo ( void   )  [inline]

Definition at line 168 of file pfm_gen_analysis.cpp.

00168 : NAME("<dynamically generated>") {}

FileInfo::FileInfo ( const std::string name,
bool  useGdb 
) [inline]

Definition at line 169 of file pfm_gen_analysis.cpp.

00169                                                : NAME(name)
00170   {
00171    if(useGdb)
00172    {
00173     this->createOffsetMap();
00174    }
00175   }


Member Function Documentation

void FileInfo::createOffsetMap ( void   )  [inline, private]

Definition at line 233 of file pfm_gen_analysis.cpp.

00234   {
00235    std::string commandLine = "objdump -p " + NAME;
00236    PipeReader objdump(commandLine.c_str());
00237    std::string oldname;
00238    std::string suffix;
00239    int vmbase = 0;
00240    bool matched = false;
00241    while(objdump.output())
00242    {
00243     // Checks the following regexp
00244     //    
00245     //    LOAD\\s+off\\s+(0x[0-9A-Fa-f]+)\\s+vaddr\\s+(0x[0-9A-Fa-f]+)
00246     // 
00247     // and sets vmbase to be $2 - $1 of the first matched entry.
00248       
00249     std::string line;
00250     std::getline(objdump.output(), line);
00251     
00252     if(!objdump.output()) break;
00253     if(line.empty()) continue;      
00254     const char *lineptr = line.c_str();
00255     if(!skipWhitespaces(lineptr, &lineptr)) continue;
00256     if(!skipString("LOAD", lineptr, &lineptr)) continue;
00257     if(!skipWhitespaces(lineptr, &lineptr)) continue;
00258     if(!skipString("off", lineptr, &lineptr))  continue;
00259     char *endptr = 0;
00260     int initialBase = strtol(lineptr, &endptr, 16);
00261     if(lineptr == endptr) continue;
00262     lineptr = endptr;
00263     if(!skipWhitespaces(lineptr, &lineptr)) continue;
00264     if(!skipString("vaddr", lineptr, &lineptr)) continue;
00265     if(!skipWhitespaces(lineptr, &lineptr)) continue;
00266     int finalBase = strtol(lineptr, &endptr, 16);
00267     if(lineptr == endptr) continue;
00268     vmbase=finalBase - initialBase;
00269     matched = true;
00270     break;
00271    }    
00272    if(!matched)
00273    {
00274     fprintf(stderr, "Cannot determine VM base address for %s\n", NAME.c_str());
00275     fprintf(stderr, "Error while running `objdump -p %s`\n", NAME.c_str());
00276     exit(1);
00277    }    
00278    std::string commandLine2 = "nm -t d -n " + NAME;
00279    PipeReader nm(commandLine2.c_str());
00280    while(nm.output())
00281    {
00282     std::string line;
00283     std::getline(nm.output(), line);
00284     if(!nm.output()) break;
00285     if(line.empty()) continue;
00286     // If line does not match "^(\\d+)[ ]\\S[ ](\S+)$", exit.
00287     const char *begin = line.c_str();
00288     char *endptr = 0;
00289     int address = strtol(begin, &endptr, 10);
00290     if(endptr == begin) continue; 
00291     if(*endptr++ != ' ') continue; 
00292     if(isspace(*endptr++)) continue; 
00293     if(*endptr++ != ' ') continue; 
00294     char *symbolName = endptr;
00295     while(*endptr && !isspace(*endptr)) endptr++;
00296     if(*endptr != 0) continue;
00297     // If line starts with '.' forget about it.
00298     if(symbolName[0] == '.') continue;
00299     // Create a new symbol with the given fileoffset.
00300     // The symbol is automatically saved in the FileInfo cache by offset.
00301     // If a symbol with the same offset is already there, the new one 
00302     // replaces the old one.
00303     int offset = address-vmbase;
00304     if(m_symbolCache.size() && (m_symbolCache.back().OFFSET == offset)) m_symbolCache.back().NAME = symbolName;
00305     else m_symbolCache.push_back(CacheItem(address-vmbase, symbolName));
00306    }
00307   }

Offset FileInfo::next ( Offset  offset  )  [inline]

Definition at line 200 of file pfm_gen_analysis.cpp.

00201   {
00202    SymbolCache::iterator i = upper_bound(m_symbolCache.begin(), m_symbolCache.end(), offset, CacheItemComparator());
00203    if(i == m_symbolCache.end())
00204    {
00205     return 0;
00206    }
00207    return i->OFFSET;      
00208   }

const char* FileInfo::symbolByOffset ( Offset  offset  )  [inline]

Definition at line 177 of file pfm_gen_analysis.cpp.

00178   {
00179    if(m_symbolCache.empty())
00180    {
00181     return 0;
00182    }
00183 
00184    SymbolCache::iterator i = lower_bound(m_symbolCache.begin(), m_symbolCache.end(), offset, CacheItemComparator());
00185    if(i->OFFSET == offset)
00186    {
00187     return i->NAME.c_str();
00188    }
00189     
00190    if(i == m_symbolCache.begin())
00191    {
00192     return m_symbolCache.begin()->NAME.c_str();
00193    }
00194 
00195    --i;
00196 
00197    return i->NAME.c_str(); 
00198   }


Member Data Documentation

Definition at line 219 of file pfm_gen_analysis.cpp.

Definition at line 167 of file pfm_gen_analysis.cpp.


The documentation for this class was generated from the following file:
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Defines

Generated at Wed Feb 9 16:30:36 2011 for Gaudi Framework, version v22r0 by Doxygen version 1.6.2 written by Dimitri van Heesch, © 1997-2004