The Gaudi Framework  v38r0 (2143aa4c)
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 153 of file pfm_gen_analysis.cpp.

Member Typedef Documentation

◆ Offset

typedef int FileInfo::Offset

Definition at line 155 of file pfm_gen_analysis.cpp.

◆ SymbolCache

Definition at line 188 of file pfm_gen_analysis.cpp.

Constructor & Destructor Documentation

◆ FileInfo() [1/2]

FileInfo::FileInfo ( void  )
inline

Definition at line 157 of file pfm_gen_analysis.cpp.

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

◆ FileInfo() [2/2]

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

Definition at line 158 of file pfm_gen_analysis.cpp.

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

Member Function Documentation

◆ createOffsetMap()

void FileInfo::createOffsetMap ( void  )
inlineprivate

Definition at line 196 of file pfm_gen_analysis.cpp.

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

◆ next()

Offset FileInfo::next ( Offset  offset)
inline

Definition at line 175 of file pfm_gen_analysis.cpp.

175  {
176  SymbolCache::iterator i = upper_bound( m_symbolCache.begin(), m_symbolCache.end(), offset, CacheItemComparator() );
177  if ( i == m_symbolCache.end() ) { return 0; }
178  return i->OFFSET;
179  }

◆ symbolByOffset()

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

Definition at line 162 of file pfm_gen_analysis.cpp.

162  {
163  if ( m_symbolCache.empty() ) { return 0; }
164 
165  SymbolCache::iterator i = lower_bound( m_symbolCache.begin(), m_symbolCache.end(), offset, CacheItemComparator() );
166  if ( i->OFFSET == offset ) { return i->NAME.c_str(); }
167 
168  if ( i == m_symbolCache.begin() ) { return m_symbolCache.begin()->NAME.c_str(); }
169 
170  --i;
171 
172  return i->NAME.c_str();
173  }

Member Data Documentation

◆ m_symbolCache

SymbolCache FileInfo::m_symbolCache
private

Definition at line 189 of file pfm_gen_analysis.cpp.

◆ NAME

std::string FileInfo::NAME

Definition at line 156 of file pfm_gen_analysis.cpp.


The documentation for this class was generated from the following file:
std::strtol
T strtol(T... args)
std::string
STL class.
bug_34121.name
name
Definition: bug_34121.py:20
std::vector::size
T size(T... args)
Gaudi::Units::nm
constexpr double nm
Definition: SystemOfUnits.h:97
FileInfo::CacheItem::OFFSET
Offset OFFSET
Definition: pfm_gen_analysis.cpp:183
std::vector::back
T back(T... args)
std::vector::push_back
T push_back(T... args)
std::fprintf
T fprintf(T... args)
FileInfo::createOffsetMap
void createOffsetMap(void)
Definition: pfm_gen_analysis.cpp:196
CLHEP::begin
double * begin(CLHEP::HepVector &v)
Definition: TupleAlg.cpp:45
std::string::c_str
T c_str(T... args)
FileInfo::CacheItem::NAME
std::string NAME
Definition: pfm_gen_analysis.cpp:185
PipeReader
Definition: pfm_gen_analysis.cpp:99
FileInfo::NAME
std::string NAME
Definition: pfm_gen_analysis.cpp:156
std::upper_bound
T upper_bound(T... args)
std::lower_bound
T lower_bound(T... args)
skipWhitespaces
bool skipWhitespaces(const char *srcbuffer, const char **destbuffer)
Definition: pfm_gen_analysis.cpp:133
std::vector::begin
T begin(T... args)
std::getline
T getline(T... args)
std::isspace
T isspace(T... args)
std::vector::empty
T empty(T... args)
plotSpeedupsPyRoot.line
line
Definition: plotSpeedupsPyRoot.py:198
std::vector::end
T end(T... args)
skipString
bool skipString(const char *strptr, const char *srcbuffer, const char **dstbuffer)
Definition: pfm_gen_analysis.cpp:147
std::exit
T exit(T... args)
FileInfo::m_symbolCache
SymbolCache m_symbolCache
Definition: pfm_gen_analysis.cpp:189