Gaudi Framework, version v23r9

Home   Generated: Thu Jul 18 2013
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Groups Pages
Classes | Public Types | Public Member Functions | Public Attributes | Private Types | Private Member Functions | Private Attributes | List of all members
FileInfo Class Reference
Collaboration diagram for FileInfo:
Collaboration graph
[legend]

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

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.

: NAME("<dynamically generated>") {}
FileInfo::FileInfo ( const std::string name,
bool  useGdb 
)
inline

Definition at line 169 of file pfm_gen_analysis.cpp.

: NAME(name)
{
if(useGdb)
{
this->createOffsetMap();
}
}

Member Function Documentation

void FileInfo::createOffsetMap ( void  )
inlineprivate

Definition at line 233 of file pfm_gen_analysis.cpp.

{
std::string commandLine = "objdump -p " + NAME;
PipeReader objdump(commandLine.c_str());
std::string oldname;
std::string suffix;
int vmbase = 0;
bool matched = false;
while(objdump.output())
{
// Checks the following regexp
//
// LOAD\\s+off\\s+(0x[0-9A-Fa-f]+)\\s+vaddr\\s+(0x[0-9A-Fa-f]+)
//
// and sets vmbase to be $2 - $1 of the first matched entry.
std::getline(objdump.output(), line);
if(!objdump.output()) break;
if(line.empty()) continue;
const char *lineptr = line.c_str();
if(!skipWhitespaces(lineptr, &lineptr)) continue;
if(!skipString("LOAD", lineptr, &lineptr)) continue;
if(!skipWhitespaces(lineptr, &lineptr)) continue;
if(!skipString("off", lineptr, &lineptr)) continue;
char *endptr = 0;
int initialBase = strtol(lineptr, &endptr, 16);
if(lineptr == endptr) continue;
lineptr = endptr;
if(!skipWhitespaces(lineptr, &lineptr)) continue;
if(!skipString("vaddr", lineptr, &lineptr)) continue;
if(!skipWhitespaces(lineptr, &lineptr)) continue;
int finalBase = strtol(lineptr, &endptr, 16);
if(lineptr == endptr) continue;
vmbase=finalBase - initialBase;
matched = true;
break;
}
if(!matched)
{
fprintf(stderr, "Cannot determine VM base address for %s\n", NAME.c_str());
fprintf(stderr, "Error while running `objdump -p %s`\n", NAME.c_str());
exit(1);
}
std::string commandLine2 = "nm -t d -n " + NAME;
PipeReader nm(commandLine2.c_str());
while(nm.output())
{
std::getline(nm.output(), line);
if(!nm.output()) break;
if(line.empty()) continue;
// If line does not match "^(\\d+)[ ]\\S[ ](\S+)$", exit.
const char *begin = line.c_str();
char *endptr = 0;
int address = strtol(begin, &endptr, 10);
if(endptr == begin) continue;
if(*endptr++ != ' ') continue;
if(isspace(*endptr++)) continue;
if(*endptr++ != ' ') continue;
char *symbolName = endptr;
while(*endptr && !isspace(*endptr)) endptr++;
if(*endptr != 0) continue;
// If line starts with '.' forget about it.
if(symbolName[0] == '.') continue;
// Create a new symbol with the given fileoffset.
// The symbol is automatically saved in the FileInfo cache by offset.
// If a symbol with the same offset is already there, the new one
// replaces the old one.
int offset = address-vmbase;
if(m_symbolCache.size() && (m_symbolCache.back().OFFSET == offset)) m_symbolCache.back().NAME = symbolName;
else m_symbolCache.push_back(CacheItem(address-vmbase, symbolName));
}
}
Offset FileInfo::next ( Offset  offset)
inline

Definition at line 200 of file pfm_gen_analysis.cpp.

{
SymbolCache::iterator i = upper_bound(m_symbolCache.begin(), m_symbolCache.end(), offset, CacheItemComparator());
if(i == m_symbolCache.end())
{
return 0;
}
return i->OFFSET;
}
const char* FileInfo::symbolByOffset ( Offset  offset)
inline

Definition at line 177 of file pfm_gen_analysis.cpp.

{
{
return 0;
}
SymbolCache::iterator i = lower_bound(m_symbolCache.begin(), m_symbolCache.end(), offset, CacheItemComparator());
if(i->OFFSET == offset)
{
return i->NAME.c_str();
}
if(i == m_symbolCache.begin())
{
return m_symbolCache.begin()->NAME.c_str();
}
--i;
return i->NAME.c_str();
}

Member Data Documentation

SymbolCache FileInfo::m_symbolCache
private

Definition at line 219 of file pfm_gen_analysis.cpp.

std::string FileInfo::NAME

Definition at line 167 of file pfm_gen_analysis.cpp.


The documentation for this class was generated from the following file:

Generated at Thu Jul 18 2013 12:18:08 for Gaudi Framework, version v23r9 by Doxygen version 1.8.2 written by Dimitri van Heesch, © 1997-2004