summaryrefslogtreecommitdiffstats
path: root/tester/covoar/ExecutableInfo.h
blob: 34f023d8d70b5794149557e27baff70c0af1fc75 (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
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
/*! @file ExecutableInfo.h
 *  @brief ExecutableInfo Specification
 *
 *  This file contains the specification of the ExecutableInfo class.
 */

#ifndef __EXECUTABLEINFO_H__
#define __EXECUTABLEINFO_H__

#include <map>
#include <stdint.h>
#include <string>

#include <rld-dwarf.h>
#include <rld-files.h>
#include <rld-symbols.h>

#include "AddressToLineMapper.h"
#include "CoverageMapBase.h"
#include "SymbolTable.h"
#include "DesiredSymbols.h"

namespace Coverage {

class DesiredSymbols;

  /*! @class ExecutableInfo
   *
   *  This class holds a collection of information for an executable
   *  that is to be analyzed.
   */
  class ExecutableInfo {

  public:

    class CoverageMapNotFoundError : public std::runtime_error {
      /* Use the base class constructors. */
      using std::runtime_error::runtime_error;
    };

    /*!
     *  This method constructs an ExecutableInfo instance.
     *
     *  @param[in] theExecutableName specifies the name of the executable
     *  @param[in] theLibraryName specifies the name of the executable
     *  @param[in] verbose specifies whether to be verbose with output
     *  @param[in] symbolsToAnalyze the symbols to be analyzed
     */
    ExecutableInfo(
      const char* const  theExecutableName,
      const std::string& theLibraryName,
      bool               verbose,
      DesiredSymbols&    symbolsToAnalyze
    );

    /*!
     *  This method destructs an ExecutableInfo instance.
     */
    virtual ~ExecutableInfo();

    /*!
     *  This method prints the contents of all coverage maps for
     *  this executable.
     */
    void dumpCoverageMaps();

    /*!
     *  This method prints the contents of Executable info containers
     */
    void dumpExecutableInfo();

    /*!
     *  This method returns a pointer to the executable's coverage map
     *  that contains the specified address.
     *
     *  @param[in] address specifies the desired address
     *
     *  @return Returns a pointer to the coverage map
     */
    CoverageMapBase* getCoverageMap( uint32_t address );

    /*!
     *  This method returns the file name of the executable.
     *
     *  @return Returns the executable's file name
     */
    const std::string& getFileName() const;

    /*!
     *  This method returns the library name associated with the executable.
     *
     *  @return Returns the executable's library name
     */
    const std::string getLibraryName() const;

    /*!
     *  This method returns the load address of the dynamic library
     *
     *  @return Returns the load address of the dynamic library
     */
    uint32_t getLoadAddress() const;

    /*!
     *  This method returns a pointer to the executable's symbol table.
     *
     *  @return Returns a pointer to the symbol table.
     */
    SymbolTable* getSymbolTable();

    /*!
     *  This method finds a coverage map for the specified symbol.
     *
     *  @param[in] symbolName specifies the name of the symbol
     *
     *  @return Returns a reference to the coverage map
     */
    CoverageMapBase& findCoverageMap( const std::string& symbolName );

    /*!
     *  This method gets the source location, the file and line number given an
     *  address.
     */
    void getSourceAndLine(
      const unsigned int address,
      std::string&       location
    );

    /*!
     *  This method indicates whether a dynamic library has been
     *  associated with the executable.
     *
     *  @return Returns TRUE if
     */
    bool hasDynamicLibrary();

    /*!
     *  This method merges the coverage maps for this executable into
     *  the unified coverage map.
     */
    void mergeCoverage();

    /*!
     *  This method sets the load address of the dynamic library
     *
     *  @param[in] address specifies the load address of the dynamic
     *             library
     */
    void setLoadAddress( uint32_t address );

  private:

    /*!
     *  This method creates a coverage map for the specified symbol.
     *
     *  @param[in] exefileName specifies the source of the information
     *  @param[in] symbolName specifies the name of the symbol
     *  @param[in] lowAddress specifies the low address of the coverage map
     *  @param[in] highAddress specifies the high address of the coverage map
     */
    void createCoverageMap (
      const std::string& exefileName,
      const std::string& symbolName,
      uint32_t           lowAddress,
      uint32_t           highAddress
    );

    /*!
     *  The executable's file name.
     */
    std::string fileName;

    /*!
     *  The executable's symbol table.
     */
    rld::symbols::table symbols;

    /*!
     *  The address-to-line mapper for this executable.
     */
    AddressToLineMapper mapper;

    /*!
     *  This map associates a symbol with its coverage map.
     */
    typedef std::map<std::string, CoverageMapBase *> CoverageMaps;
    CoverageMaps coverageMaps;

    /*!
     *  This member variable contains the name of a dynamic library
     *  associated with the executable.
     */
    std::string libraryName;

    /*!
     *  This member variable contains the load address of a dynamic library
     *  if one has been specified for the executable.
     */
    uint32_t loadAddress;

    /*!
     *  This member variable contains a pointer to the symbol table
     *  of the executable or library.
     */
    SymbolTable theSymbolTable;

    /*!
     * This member variable contains the symbols to be analyzed.
     */
    DesiredSymbols& symbolsToAnalyze_m;

  };
}
#endif