The Gaudi Framework  master (37c0b60a)
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 152 of file pfm_gen_analysis.cpp.

Member Typedef Documentation

◆ Offset

typedef int FileInfo::Offset

Definition at line 154 of file pfm_gen_analysis.cpp.

◆ SymbolCache

Definition at line 187 of file pfm_gen_analysis.cpp.

Constructor & Destructor Documentation

◆ FileInfo() [1/2]

FileInfo::FileInfo ( void  )
inline

Definition at line 156 of file pfm_gen_analysis.cpp.

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

◆ FileInfo() [2/2]

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

Definition at line 157 of file pfm_gen_analysis.cpp.

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

Member Function Documentation

◆ createOffsetMap()

void FileInfo::createOffsetMap ( void  )
inlineprivate

Definition at line 195 of file pfm_gen_analysis.cpp.

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

◆ next()

Offset FileInfo::next ( Offset  offset)
inline

Definition at line 174 of file pfm_gen_analysis.cpp.

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

◆ symbolByOffset()

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

Definition at line 161 of file pfm_gen_analysis.cpp.

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

Member Data Documentation

◆ m_symbolCache

SymbolCache FileInfo::m_symbolCache
private

Definition at line 188 of file pfm_gen_analysis.cpp.

◆ NAME

std::string FileInfo::NAME

Definition at line 155 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.
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:182
std::vector::back
T back(T... args)
std::vector::push_back
T push_back(T... args)
fixtures.stderr
Generator[bytes, None, None] stderr(subprocess.CompletedProcess completed_process)
Definition: fixtures.py:147
Gaudi::Utils::begin
AttribStringParser::Iterator begin(const AttribStringParser &parser)
Definition: AttribStringParser.h:136
std::fprintf
T fprintf(T... args)
FileInfo::createOffsetMap
void createOffsetMap(void)
Definition: pfm_gen_analysis.cpp:195
std::string::c_str
T c_str(T... args)
FileInfo::CacheItem::NAME
std::string NAME
Definition: pfm_gen_analysis.cpp:184
PipeReader
Definition: pfm_gen_analysis.cpp:101
FileInfo::NAME
std::string NAME
Definition: pfm_gen_analysis.cpp:155
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:132
ConditionsStallTest.name
name
Definition: ConditionsStallTest.py:77
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:146
std::exit
T exit(T... args)
FileInfo::m_symbolCache
SymbolCache m_symbolCache
Definition: pfm_gen_analysis.cpp:188