Changeset fb987e8 in rtems-tools for tester/covoar/ExecutableInfo.cc


Ignore:
Timestamp:
May 8, 2018, 5:09:39 AM (18 months ago)
Author:
Chris Johns <chrisj@…>
Branches:
master
Children:
efbf8f0
Parents:
558cab8
git-author:
Chris Johns <chrisj@…> (05/08/18 05:09:39)
git-committer:
Chris Johns <chrisj@…> (06/15/18 05:54:25)
Message:

covoar: Use DWARF to map addresses to source files and lines.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • tester/covoar/ExecutableInfo.cc

    r558cab8 rfb987e8  
    77
    88#include <stdio.h>
     9
     10#include <rld.h>
    911
    1012#include "ExecutableInfo.h"
     
    1921    const char* const theExecutableName,
    2022    const char* const theLibraryName
    21   )
     23    ) : executable(theExecutableName),
     24        loadAddress(0)
    2225  {
    23     executableName = theExecutableName;
    24     loadAddress = 0;
    25     libraryName = "";
    2626    if (theLibraryName)
    2727      libraryName = theLibraryName;
    28     theSymbolTable = new SymbolTable();
     28    try {
     29      executable.open();
     30      executable.begin();
     31      executable.load_symbols(symbols);
     32      debug.begin(executable.elf());
     33      debug.load_debug();
     34    } catch (rld::error re) {
     35      std::cerr << "error: "
     36                << re.where << ": " << re.what
     37                << std::endl;
     38      exit(2);
     39    } catch (...) {
     40      exit(2);
     41    }
    2942  }
    3043
    3144  ExecutableInfo::~ExecutableInfo()
    3245  {
    33     if (theSymbolTable)
    34       delete theSymbolTable;
     46    debug.end();
     47    executable.end();
     48    executable.close();
    3549  }
    3650
    3751  void ExecutableInfo::dumpCoverageMaps( void ) {
    38     ExecutableInfo::coverageMaps_t::iterator  itr;
     52    ExecutableInfo::CoverageMaps::iterator  itr;
    3953
    4054    for (itr = coverageMaps.begin(); itr != coverageMaps.end(); itr++) {
     
    4559
    4660  void ExecutableInfo::dumpExecutableInfo( void ){
    47     fprintf( stdout, "\n== Executable info ==\n");
    48     fprintf( stdout, "executableName = %s\n", executableName.c_str());
    49     fprintf( stdout, "libraryName = %s\n", libraryName.c_str());
    50     fprintf( stdout, "loadAddress = %u\n", loadAddress);
    51     theSymbolTable->dumpSymbolTable();
     61    std::cout << std::endl
     62              << "== Executable info ==" << std::endl
     63              << "executable = " << getFileName () << std::endl
     64              << "library = " << libraryName << std::endl
     65              << "loadAddress = " << loadAddress << std::endl;
     66    theSymbolTable.dumpSymbolTable();
    5267  }
    5368
    5469  CoverageMapBase* ExecutableInfo::getCoverageMap ( uint32_t address )
    5570  {
    56     CoverageMapBase*         aCoverageMap = NULL;
    57     coverageMaps_t::iterator it;
    58     std::string              itsSymbol;
     71    CoverageMapBase*       aCoverageMap = NULL;
     72    CoverageMaps::iterator it;
     73    std::string            itsSymbol;
    5974
    6075    // Obtain the coverage map containing the specified address.
    61     itsSymbol = theSymbolTable->getSymbol( address );
     76    itsSymbol = theSymbolTable.getSymbol( address );
    6277    if (itsSymbol != "") {
    6378      it = coverageMaps.find( itsSymbol );
     
    6883  }
    6984
    70   const std::string& ExecutableInfo::getFileName ( void ) const
     85  const std::string ExecutableInfo::getFileName ( void ) const
    7186  {
    72     return executableName;
     87    return executable.name().full();
    7388  }
    7489
    75   const std::string& ExecutableInfo::getLibraryName( void ) const
     90  const std::string ExecutableInfo::getLibraryName( void ) const
    7691  {
    7792    return libraryName;
     
    8499
    85100
    86   SymbolTable* ExecutableInfo::getSymbolTable ( void ) const
     101  SymbolTable* ExecutableInfo::getSymbolTable ( void )
    87102  {
    88     return theSymbolTable;
     103    return &theSymbolTable;
    89104  }
    90105
     
    96111  )
    97112  {
    98     CoverageMapBase                          *theMap;
    99     ExecutableInfo::coverageMaps_t::iterator  itr;
     113    CoverageMapBase                        *theMap;
     114    ExecutableInfo::CoverageMaps::iterator  itr;
    100115
    101116    itr = coverageMaps.find( symbolName );
     
    110125  }
    111126
     127  void ExecutableInfo::getSourceAndLine(
     128    const unsigned int address,
     129    std::string&       line
     130  )
     131  {
     132    std::string file;
     133    int         lno;
     134    debug.get_source (address, file, lno);
     135    std::ostringstream ss;
     136    ss << file << ':' << lno;
     137    line = ss.str ();
     138  }
     139
    112140  bool ExecutableInfo::hasDynamicLibrary( void )
    113141  {
    114      return (libraryName != "");
     142    return !libraryName.empty();
    115143  }
    116144
    117145  void ExecutableInfo::mergeCoverage( void ) {
    118     ExecutableInfo::coverageMaps_t::iterator  itr;
     146    ExecutableInfo::CoverageMaps::iterator  itr;
    119147
    120148    for (itr = coverageMaps.begin(); itr != coverageMaps.end(); itr++) {
Note: See TracChangeset for help on using the changeset viewer.