source: rtems-tools/tester/covoar/ExecutableInfo.cc @ fb987e8

5
Last change on this file since fb987e8 was fb987e8, checked in by Chris Johns <chrisj@…>, on 05/08/18 at 05:09:39

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

  • Property mode set to 100644
File size: 3.8 KB
RevLine 
[100f517]1/*! @file ExecutableInfo.cc
2 *  @brief ExecutableInfo Implementation
3 *
4 *  This file contains the implementation of the functionality
5 *  of the ExecutableInfo class.
6 */
7
8#include <stdio.h>
9
[fb987e8]10#include <rld.h>
11
[100f517]12#include "ExecutableInfo.h"
13#include "app_common.h"
14#include "CoverageMap.h"
15#include "DesiredSymbols.h"
16#include "SymbolTable.h"
17
18namespace Coverage {
19
20  ExecutableInfo::ExecutableInfo(
21    const char* const theExecutableName,
22    const char* const theLibraryName
[fb987e8]23    ) : executable(theExecutableName),
24        loadAddress(0)
[100f517]25  {
26    if (theLibraryName)
27      libraryName = theLibraryName;
[fb987e8]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    }
[100f517]42  }
43
44  ExecutableInfo::~ExecutableInfo()
45  {
[fb987e8]46    debug.end();
47    executable.end();
48    executable.close();
[100f517]49  }
50
51  void ExecutableInfo::dumpCoverageMaps( void ) {
[fb987e8]52    ExecutableInfo::CoverageMaps::iterator  itr;
[100f517]53
54    for (itr = coverageMaps.begin(); itr != coverageMaps.end(); itr++) {
55      fprintf( stderr, "Coverage Map for %s\n", ((*itr).first).c_str() );;
56      ((*itr).second)->dump();
57    }
58  }
59
60  void ExecutableInfo::dumpExecutableInfo( void ){
[fb987e8]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();
[100f517]67  }
68
69  CoverageMapBase* ExecutableInfo::getCoverageMap ( uint32_t address )
70  {
[fb987e8]71    CoverageMapBase*       aCoverageMap = NULL;
72    CoverageMaps::iterator it;
73    std::string            itsSymbol;
[100f517]74
75    // Obtain the coverage map containing the specified address.
[fb987e8]76    itsSymbol = theSymbolTable.getSymbol( address );
[100f517]77    if (itsSymbol != "") {
78      it = coverageMaps.find( itsSymbol );
79      aCoverageMap = (*it).second;
80    }
81
82    return aCoverageMap;
83  }
84
[fb987e8]85  const std::string ExecutableInfo::getFileName ( void ) const
[100f517]86  {
[fb987e8]87    return executable.name().full();
[100f517]88  }
89
[fb987e8]90  const std::string ExecutableInfo::getLibraryName( void ) const
[100f517]91  {
92    return libraryName;
93  }
94
95  uint32_t ExecutableInfo::getLoadAddress( void ) const
96  {
97    return loadAddress;
98  }
99
100
[fb987e8]101  SymbolTable* ExecutableInfo::getSymbolTable ( void )
[100f517]102  {
[fb987e8]103    return &theSymbolTable;
[100f517]104  }
105
106  CoverageMapBase* ExecutableInfo::createCoverageMap (
[cb018bc]107    const std::string& fileName,
[100f517]108    const std::string& symbolName,
109    uint32_t           lowAddress,
110    uint32_t           highAddress
111  )
112  {
[fb987e8]113    CoverageMapBase                        *theMap;
114    ExecutableInfo::CoverageMaps::iterator  itr;
[100f517]115
116    itr = coverageMaps.find( symbolName );
117    if ( itr == coverageMaps.end() ) {
[cb018bc]118      theMap = new CoverageMap( fileName, lowAddress, highAddress );
[100f517]119      coverageMaps[ symbolName ] = theMap;
120    } else {
121      theMap = itr->second;
122      theMap->Add( lowAddress, highAddress );
123    }
124    return theMap;
125  }
126
[fb987e8]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
[100f517]140  bool ExecutableInfo::hasDynamicLibrary( void )
141  {
[fb987e8]142    return !libraryName.empty();
[100f517]143  }
144
145  void ExecutableInfo::mergeCoverage( void ) {
[fb987e8]146    ExecutableInfo::CoverageMaps::iterator  itr;
[100f517]147
148    for (itr = coverageMaps.begin(); itr != coverageMaps.end(); itr++) {
149      SymbolsToAnalyze->mergeCoverageMap( (*itr).first, (*itr).second );
150    }
151  }
152
153  void ExecutableInfo::setLoadAddress( uint32_t address )
154  {
155    loadAddress = address;
156  }
157
158}
Note: See TracBrowser for help on using the repository browser.