summaryrefslogtreecommitdiffstats
path: root/covoar/ExecutableInfo.cc
blob: 770e54d120375b341377545a6599eb2644e5e8e1 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
/*
 * $Id$
 */

/*! @file ExecutableInfo.cc
 *  @brief ExecutableInfo Implementation
 *
 *  This file contains the implementation of the functionality
 *  of the ExecutableInfo class.
 */

#include <stdio.h>

#include "ExecutableInfo.h"
#include "app_common.h"
#include "CoverageMap.h"
#include "DesiredSymbols.h"
#include "SymbolTable.h"

namespace Coverage {

  ExecutableInfo::ExecutableInfo(
    const char* const theExecutableName,
    const char* const theLibraryName
  )
  {
    executableName = theExecutableName;
    loadAddress = 0;
    libraryName = "";
    if (theLibraryName)
      libraryName = theLibraryName;
    theSymbolTable = new SymbolTable();
  }

  ExecutableInfo::~ExecutableInfo()
  {
    if (theSymbolTable)
      delete theSymbolTable;
  }

  void ExecutableInfo::dumpCoverageMaps( void ) {
    ExecutableInfo::coverageMaps_t::iterator  itr;

    for (itr = coverageMaps.begin(); itr != coverageMaps.end(); itr++) {
      fprintf( stderr, "Coverage Map for %s\n", ((*itr).first).c_str() );;
      ((*itr).second)->dump();
    }
  }

  void ExecutableInfo::dumpExecutableInfo( void ){
    fprintf( stdout, "\n== Executable info ==\n");
    fprintf( stdout, "executableName = %s\n", executableName.c_str());
    fprintf( stdout, "libraryName = %s\n", libraryName.c_str());
    fprintf( stdout, "loadAddress = %u\n", loadAddress);
    theSymbolTable->dumpSymbolTable();
  }

  CoverageMapBase* ExecutableInfo::getCoverageMap ( uint32_t address )
  {
    CoverageMapBase*         aCoverageMap = NULL;
    coverageMaps_t::iterator it;
    std::string              itsSymbol;

    // Obtain the coverage map containing the specified address.
    itsSymbol = theSymbolTable->getSymbol( address );
    if (itsSymbol != "") {
      it = coverageMaps.find( itsSymbol );
      aCoverageMap = (*it).second;
    }

    return aCoverageMap;
  }

  std::string ExecutableInfo::getFileName ( void ) const
  {
    return executableName;
  }

  std::string ExecutableInfo::getLibraryName( void ) const
  {
    return libraryName;
  }

  uint32_t ExecutableInfo::getLoadAddress( void ) const
  {
    return loadAddress;
  }


  SymbolTable* ExecutableInfo::getSymbolTable ( void ) const
  {
    return theSymbolTable;
  }

  CoverageMapBase* ExecutableInfo::createCoverageMap (
    const std::string& symbolName,
    uint32_t           lowAddress,
    uint32_t           highAddress
  )
  {
    CoverageMapBase                          *theMap;
    ExecutableInfo::coverageMaps_t::iterator  itr;

    itr = coverageMaps.find( symbolName );
    if ( itr == coverageMaps.end() ) {
      theMap = new CoverageMap( lowAddress, highAddress );
      coverageMaps[ symbolName ] = theMap;
    } else {
      theMap = itr->second;
      theMap->Add( lowAddress, highAddress );
    }
    return theMap;
  }

  bool ExecutableInfo::hasDynamicLibrary( void )
  {
     return (libraryName != "");
  }

  void ExecutableInfo::mergeCoverage( void ) {
    ExecutableInfo::coverageMaps_t::iterator  itr;

    for (itr = coverageMaps.begin(); itr != coverageMaps.end(); itr++) {
      SymbolsToAnalyze->mergeCoverageMap( (*itr).first, (*itr).second );
    }
  }

  void ExecutableInfo::setLoadAddress( uint32_t address )
  {
    loadAddress = address;
  }

}