The Gaudi Framework  v31r0 (aeb156f0)
FileInfo Class Reference
Collaboration diagram for FileInfo:

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 143 of file pfm_gen_analysis.cpp.

Member Typedef Documentation

typedef int FileInfo::Offset

Definition at line 145 of file pfm_gen_analysis.cpp.

Definition at line 178 of file pfm_gen_analysis.cpp.

Constructor & Destructor Documentation

FileInfo::FileInfo ( void  )
inline

Definition at line 147 of file pfm_gen_analysis.cpp.

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

Definition at line 148 of file pfm_gen_analysis.cpp.

148  : NAME( name ) {
149  if ( useGdb ) { this->createOffsetMap(); }
150  }
std::string NAME
void createOffsetMap(void)

Member Function Documentation

void FileInfo::createOffsetMap ( void  )
inlineprivate

Definition at line 186 of file pfm_gen_analysis.cpp.

186  {
187  std::string commandLine = "objdump -p " + NAME;
188  PipeReader objdump( commandLine.c_str() );
189  std::string oldname;
190  std::string suffix;
191  int vmbase = 0;
192  bool matched = false;
193  while ( objdump.output() ) {
194  // Checks the following regexp
195  //
196  // LOAD\\s+off\\s+(0x[0-9A-Fa-f]+)\\s+vaddr\\s+(0x[0-9A-Fa-f]+)
197  //
198  // and sets vmbase to be $2 - $1 of the first matched entry.
199 
201  std::getline( objdump.output(), line );
202 
203  if ( !objdump.output() ) break;
204  if ( line.empty() ) continue;
205  const char* lineptr = line.c_str();
206  if ( !skipWhitespaces( lineptr, &lineptr ) ) continue;
207  if ( !skipString( "LOAD", lineptr, &lineptr ) ) continue;
208  if ( !skipWhitespaces( lineptr, &lineptr ) ) continue;
209  if ( !skipString( "off", lineptr, &lineptr ) ) continue;
210  char* endptr = 0;
211  int initialBase = strtol( lineptr, &endptr, 16 );
212  if ( lineptr == endptr ) continue;
213  lineptr = endptr;
214  if ( !skipWhitespaces( lineptr, &lineptr ) ) continue;
215  if ( !skipString( "vaddr", lineptr, &lineptr ) ) continue;
216  if ( !skipWhitespaces( lineptr, &lineptr ) ) continue;
217  int finalBase = strtol( lineptr, &endptr, 16 );
218  if ( lineptr == endptr ) continue;
219  vmbase = finalBase - initialBase;
220  matched = true;
221  break;
222  }
223  if ( !matched ) {
224  fprintf( stderr, "Cannot determine VM base address for %s\n", NAME.c_str() );
225  fprintf( stderr, "Error while running `objdump -p %s`\n", NAME.c_str() );
226  exit( 1 );
227  }
228  std::string commandLine2 = "nm -t d -n " + NAME;
229  PipeReader nm( commandLine2.c_str() );
230  while ( nm.output() ) {
232  std::getline( nm.output(), line );
233  if ( !nm.output() ) break;
234  if ( line.empty() ) continue;
235  // If line does not match "^(\\d+)[ ]\\S[ ](\S+)$", exit.
236  const char* begin = line.c_str();
237  char* endptr = 0;
238  int address = strtol( begin, &endptr, 10 );
239  if ( endptr == begin ) continue;
240  if ( *endptr++ != ' ' ) continue;
241  if ( isspace( *endptr++ ) ) continue;
242  if ( *endptr++ != ' ' ) continue;
243  char* symbolName = endptr;
244  while ( *endptr && !isspace( *endptr ) ) endptr++;
245  if ( *endptr != 0 ) continue;
246  // If line starts with '.' forget about it.
247  if ( symbolName[0] == '.' ) continue;
248  // Create a new symbol with the given fileoffset.
249  // The symbol is automatically saved in the FileInfo cache by offset.
250  // If a symbol with the same offset is already there, the new one
251  // replaces the old one.
252  int offset = address - vmbase;
253  if ( m_symbolCache.size() && ( m_symbolCache.back().OFFSET == offset ) )
254  m_symbolCache.back().NAME = symbolName;
255  else
256  m_symbolCache.push_back( CacheItem( address - vmbase, symbolName ) );
257  }
258  }
T empty(T...args)
bool skipString(const char *strptr, const char *srcbuffer, const char **dstbuffer)
T getline(T...args)
std::string NAME
STL class.
T push_back(T...args)
T exit(T...args)
constexpr double nm
Definition: SystemOfUnits.h:81
T size(T...args)
SymbolCache m_symbolCache
T c_str(T...args)
T strtol(T...args)
T back(T...args)
AttribStringParser::Iterator begin(const AttribStringParser &parser)
bool skipWhitespaces(const char *srcbuffer, const char **destbuffer)
T fprintf(T...args)
T isspace(T...args)
Offset FileInfo::next ( Offset  offset)
inline

Definition at line 165 of file pfm_gen_analysis.cpp.

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

Definition at line 152 of file pfm_gen_analysis.cpp.

152  {
153  if ( m_symbolCache.empty() ) { return 0; }
154 
155  SymbolCache::iterator i = lower_bound( m_symbolCache.begin(), m_symbolCache.end(), offset, CacheItemComparator() );
156  if ( i->OFFSET == offset ) { return i->NAME.c_str(); }
157 
158  if ( i == m_symbolCache.begin() ) { return m_symbolCache.begin()->NAME.c_str(); }
159 
160  --i;
161 
162  return i->NAME.c_str();
163  }
T empty(T...args)
T end(T...args)
T lower_bound(T...args)
T begin(T...args)
SymbolCache m_symbolCache
T c_str(T...args)

Member Data Documentation

SymbolCache FileInfo::m_symbolCache
private

Definition at line 179 of file pfm_gen_analysis.cpp.

std::string FileInfo::NAME

Definition at line 146 of file pfm_gen_analysis.cpp.


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