The Gaudi Framework  v30r3 (a5ef0a68)
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 156 of file pfm_gen_analysis.cpp.

Member Typedef Documentation

typedef int FileInfo::Offset

Definition at line 159 of file pfm_gen_analysis.cpp.

Definition at line 205 of file pfm_gen_analysis.cpp.

Constructor & Destructor Documentation

FileInfo::FileInfo ( void  )
inline

Definition at line 161 of file pfm_gen_analysis.cpp.

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

Definition at line 162 of file pfm_gen_analysis.cpp.

162  : NAME( name )
163  {
164  if ( useGdb ) {
165  this->createOffsetMap();
166  }
167  }
std::string NAME
void createOffsetMap(void)

Member Function Documentation

void FileInfo::createOffsetMap ( void  )
inlineprivate

Definition at line 213 of file pfm_gen_analysis.cpp.

214  {
215  std::string commandLine = "objdump -p " + NAME;
216  PipeReader objdump( commandLine.c_str() );
217  std::string oldname;
218  std::string suffix;
219  int vmbase = 0;
220  bool matched = false;
221  while ( objdump.output() ) {
222  // Checks the following regexp
223  //
224  // LOAD\\s+off\\s+(0x[0-9A-Fa-f]+)\\s+vaddr\\s+(0x[0-9A-Fa-f]+)
225  //
226  // and sets vmbase to be $2 - $1 of the first matched entry.
227 
229  std::getline( objdump.output(), line );
230 
231  if ( !objdump.output() ) break;
232  if ( line.empty() ) continue;
233  const char* lineptr = line.c_str();
234  if ( !skipWhitespaces( lineptr, &lineptr ) ) continue;
235  if ( !skipString( "LOAD", lineptr, &lineptr ) ) continue;
236  if ( !skipWhitespaces( lineptr, &lineptr ) ) continue;
237  if ( !skipString( "off", lineptr, &lineptr ) ) continue;
238  char* endptr = 0;
239  int initialBase = strtol( lineptr, &endptr, 16 );
240  if ( lineptr == endptr ) continue;
241  lineptr = endptr;
242  if ( !skipWhitespaces( lineptr, &lineptr ) ) continue;
243  if ( !skipString( "vaddr", lineptr, &lineptr ) ) continue;
244  if ( !skipWhitespaces( lineptr, &lineptr ) ) continue;
245  int finalBase = strtol( lineptr, &endptr, 16 );
246  if ( lineptr == endptr ) continue;
247  vmbase = finalBase - initialBase;
248  matched = true;
249  break;
250  }
251  if ( !matched ) {
252  fprintf( stderr, "Cannot determine VM base address for %s\n", NAME.c_str() );
253  fprintf( stderr, "Error while running `objdump -p %s`\n", NAME.c_str() );
254  exit( 1 );
255  }
256  std::string commandLine2 = "nm -t d -n " + NAME;
257  PipeReader nm( commandLine2.c_str() );
258  while ( nm.output() ) {
260  std::getline( nm.output(), line );
261  if ( !nm.output() ) break;
262  if ( line.empty() ) continue;
263  // If line does not match "^(\\d+)[ ]\\S[ ](\S+)$", exit.
264  const char* begin = line.c_str();
265  char* endptr = 0;
266  int address = strtol( begin, &endptr, 10 );
267  if ( endptr == begin ) continue;
268  if ( *endptr++ != ' ' ) continue;
269  if ( isspace( *endptr++ ) ) continue;
270  if ( *endptr++ != ' ' ) continue;
271  char* symbolName = endptr;
272  while ( *endptr && !isspace( *endptr ) ) endptr++;
273  if ( *endptr != 0 ) continue;
274  // If line starts with '.' forget about it.
275  if ( symbolName[0] == '.' ) continue;
276  // Create a new symbol with the given fileoffset.
277  // The symbol is automatically saved in the FileInfo cache by offset.
278  // If a symbol with the same offset is already there, the new one
279  // replaces the old one.
280  int offset = address - vmbase;
281  if ( m_symbolCache.size() && ( m_symbolCache.back().OFFSET == offset ) )
282  m_symbolCache.back().NAME = symbolName;
283  else
284  m_symbolCache.push_back( CacheItem( address - vmbase, symbolName ) );
285  }
286  }
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:83
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 189 of file pfm_gen_analysis.cpp.

190  {
191  SymbolCache::iterator i = upper_bound( m_symbolCache.begin(), m_symbolCache.end(), offset, CacheItemComparator() );
192  if ( i == m_symbolCache.end() ) {
193  return 0;
194  }
195  return i->OFFSET;
196  }
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 169 of file pfm_gen_analysis.cpp.

170  {
171  if ( m_symbolCache.empty() ) {
172  return 0;
173  }
174 
175  SymbolCache::iterator i = lower_bound( m_symbolCache.begin(), m_symbolCache.end(), offset, CacheItemComparator() );
176  if ( i->OFFSET == offset ) {
177  return i->NAME.c_str();
178  }
179 
180  if ( i == m_symbolCache.begin() ) {
181  return m_symbolCache.begin()->NAME.c_str();
182  }
183 
184  --i;
185 
186  return i->NAME.c_str();
187  }
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 206 of file pfm_gen_analysis.cpp.

std::string FileInfo::NAME

Definition at line 160 of file pfm_gen_analysis.cpp.


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