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

5
Last change on this file since efbf8f0 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
Line 
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
10#include <rld.h>
11
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
23    ) : executable(theExecutableName),
24        loadAddress(0)
25  {
26    if (theLibraryName)
27      libraryName = theLibraryName;
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    }
42  }
43
44  ExecutableInfo::~ExecutableInfo()
45  {
46    debug.end();
47    executable.end();
48    executable.close();
49  }
50
51  void ExecutableInfo::dumpCoverageMaps( void ) {
52    ExecutableInfo::CoverageMaps::iterator  itr;
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 ){
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();
67  }
68
69  CoverageMapBase* ExecutableInfo::getCoverageMap ( uint32_t address )
70  {
71    CoverageMapBase*       aCoverageMap = NULL;
72    CoverageMaps::iterator it;
73    std::string            itsSymbol;
74
75    // Obtain the coverage map containing the specified address.
76    itsSymbol = theSymbolTable.getSymbol( address );
77    if (itsSymbol != "") {
78      it = coverageMaps.find( itsSymbol );
79      aCoverageMap = (*it).second;
80    }
81
82    return aCoverageMap;
83  }
84
85  const std::string ExecutableInfo::getFileName ( void ) const
86  {
87    return executable.name().full();
88  }
89
90  const std::string ExecutableInfo::getLibraryName( void ) const
91  {
92    return libraryName;
93  }
94
95  uint32_t ExecutableInfo::getLoadAddress( void ) const
96  {
97    return loadAddress;
98  }
99
100
101  SymbolTable* ExecutableInfo::getSymbolTable ( void )
102  {
103    return &theSymbolTable;
104  }
105
106  CoverageMapBase* ExecutableInfo::createCoverageMap (
107    const std::string& fileName,
108    const std::string& symbolName,
109    uint32_t           lowAddress,
110    uint32_t           highAddress
111  )
112  {
113    CoverageMapBase                        *theMap;
114    ExecutableInfo::CoverageMaps::iterator  itr;
115
116    itr = coverageMaps.find( symbolName );
117    if ( itr == coverageMaps.end() ) {
118      theMap = new CoverageMap( fileName, lowAddress, highAddress );
119      coverageMaps[ symbolName ] = theMap;
120    } else {
121      theMap = itr->second;
122      theMap->Add( lowAddress, highAddress );
123    }
124    return theMap;
125  }
126
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
140  bool ExecutableInfo::hasDynamicLibrary( void )
141  {
142    return !libraryName.empty();
143  }
144
145  void ExecutableInfo::mergeCoverage( void ) {
146    ExecutableInfo::CoverageMaps::iterator  itr;
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.