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

5
Last change on this file since 1f1a10f was d6ae3ae, checked in by Chris Johns <chrisj@…>, on 05/11/18 at 05:25:53

tester/covoar: ExecutableInfo? C to C++ change.

  • 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  }
35
36  ExecutableInfo::~ExecutableInfo()
37  {
38    debug.end();
39    executable.end();
40    executable.close();
41  }
42
43  void ExecutableInfo::dumpCoverageMaps( void ) {
44    ExecutableInfo::CoverageMaps::iterator  itr;
45
46    for (auto& cm : coverageMaps) {
47      std::cerr << "Coverage Map for " << cm.first << std::endl;
48      cm.second->dump();
49    }
50  }
51
52  void ExecutableInfo::dumpExecutableInfo( void ){
53    std::cout << std::endl
54              << "== Executable info ==" << std::endl
55              << "executable = " << getFileName () << std::endl
56              << "library = " << libraryName << std::endl
57              << "loadAddress = " << loadAddress << std::endl;
58    theSymbolTable.dumpSymbolTable();
59  }
60
61  CoverageMapBase* ExecutableInfo::getCoverageMap ( uint32_t address )
62  {
63    CoverageMapBase*       aCoverageMap = NULL;
64    CoverageMaps::iterator it;
65    std::string            itsSymbol;
66
67    // Obtain the coverage map containing the specified address.
68    itsSymbol = theSymbolTable.getSymbol( address );
69    if (itsSymbol != "") {
70      it = coverageMaps.find( itsSymbol );
71      aCoverageMap = (*it).second;
72    }
73
74    return aCoverageMap;
75  }
76
77  const std::string ExecutableInfo::getFileName ( void ) const
78  {
79    return executable.name().full();
80  }
81
82  const std::string ExecutableInfo::getLibraryName( void ) const
83  {
84    return libraryName;
85  }
86
87  uint32_t ExecutableInfo::getLoadAddress( void ) const
88  {
89    return loadAddress;
90  }
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    ExecutableInfo::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.