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

Last change on this file since bf8e59f was bf8e59f, checked in by Chris Johns <chrisj@…>, on Jun 21, 2018 at 7:55:24 AM

covoar: Covert CoverageMapBase? C to C++

Updates #3462

  • Property mode set to 100644
File size: 3.5 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
29    executable.open();
30    executable.begin();
31    executable.load_symbols(symbols);
32    debug.begin(executable.elf());
33    debug.load_debug();
34    debug.load_functions();
35  }
36
37  ExecutableInfo::~ExecutableInfo()
38  {
39    debug.end();
40    executable.end();
41    executable.close();
42  }
43
44  void ExecutableInfo::dumpCoverageMaps( void ) {
45    ExecutableInfo::CoverageMaps::iterator  itr;
46
47    for (auto& cm : coverageMaps) {
48      std::cerr << "Coverage Map for " << cm.first << std::endl;
49      cm.second->dump();
50    }
51  }
52
53  void ExecutableInfo::dumpExecutableInfo( void ){
54    std::cout << std::endl
55              << "== Executable info ==" << std::endl
56              << "executable = " << getFileName () << std::endl
57              << "library = " << libraryName << std::endl
58              << "loadAddress = " << loadAddress << std::endl;
59    theSymbolTable.dumpSymbolTable();
60  }
61
62  CoverageMapBase* ExecutableInfo::getCoverageMap ( uint32_t address )
63  {
64    CoverageMapBase*       aCoverageMap = NULL;
65    CoverageMaps::iterator it;
66    std::string            itsSymbol;
67
68    // Obtain the coverage map containing the specified address.
69    itsSymbol = theSymbolTable.getSymbol( address );
70    if (itsSymbol != "") {
71      it = coverageMaps.find( itsSymbol );
72      aCoverageMap = (*it).second;
73    }
74
75    return aCoverageMap;
76  }
77
78  const std::string ExecutableInfo::getFileName ( void ) const
79  {
80    return executable.name().full();
81  }
82
83  const std::string ExecutableInfo::getLibraryName( void ) const
84  {
85    return libraryName;
86  }
87
88  uint32_t ExecutableInfo::getLoadAddress( void ) const
89  {
90    return loadAddress;
91  }
92
93  SymbolTable* ExecutableInfo::getSymbolTable ( void )
94  {
95    return &theSymbolTable;
96  }
97
98  CoverageMapBase* ExecutableInfo::createCoverageMap (
99    const std::string& fileName,
100    const std::string& symbolName,
101    uint32_t           lowAddress,
102    uint32_t           highAddress
103  )
104  {
105    CoverageMapBase        *theMap;
106    CoverageMaps::iterator  itr;
107
108    itr = coverageMaps.find( symbolName );
109    if ( itr == coverageMaps.end() ) {
110      theMap = new CoverageMap( fileName, lowAddress, highAddress );
111      coverageMaps[ symbolName ] = theMap;
112    } else {
113      theMap = itr->second;
114      theMap->Add( lowAddress, highAddress );
115    }
116    return theMap;
117  }
118
119  void ExecutableInfo::getSourceAndLine(
120    const unsigned int address,
121    std::string&       line
122  )
123  {
124    std::string file;
125    int         lno;
126    debug.get_source (address, file, lno);
127    std::ostringstream ss;
128    ss << file << ':' << lno;
129    line = ss.str ();
130  }
131
132  bool ExecutableInfo::hasDynamicLibrary( void )
133  {
134    return !libraryName.empty();
135  }
136
137  void ExecutableInfo::mergeCoverage( void ) {
138    ExecutableInfo::CoverageMaps::iterator  itr;
139
140    for (itr = coverageMaps.begin(); itr != coverageMaps.end(); itr++) {
141      SymbolsToAnalyze->mergeCoverageMap( (*itr).first, (*itr).second );
142    }
143  }
144
145  void ExecutableInfo::setLoadAddress( uint32_t address )
146  {
147    loadAddress = address;
148  }
149
150}
Note: See TracBrowser for help on using the repository browser.