summaryrefslogtreecommitdiffstats
path: root/tester/covoar/DesiredSymbols.h
blob: 5cf96e92ebaf43636460f04e426826948e9eb1bb (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
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
/*! @file DesiredSymbols.h
 *  @brief DesiredSymbols Specification
 *
 *  This file contains the specification of the DesiredSymbols class.
 */

#ifndef __DESIRED_SYMBOLS_H__
#define __DESIRED_SYMBOLS_H__

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

#include "CoverageMapBase.h"
#include "CoverageRanges.h"
#include "ExecutableInfo.h"
#include "ObjdumpProcessor.h"

namespace Coverage {


  /*!
   *
   *  This class defines the statistics that are tracked.
   */
  class Statistics {
    public:

    /*!
     *  This member variable contains the total number of branches always
     *  taken.
     */
    int branchesAlwaysTaken;

    /*!
     *  This member variable contains the total number of branches where
     *  one or more paths were executed.
     */
    int branchesExecuted;

    /*!
     *  This member variable contains the total number of branches never
     *  taken.
     */
    int branchesNeverTaken;

    /*!
     *  This member variable contains the total number of branches not
     *  executed AT ALL.
     */
    int branchesNotExecuted;

    /*!
     *  This member contains the size in Bytes.
     */
    uint32_t sizeInBytes;

    /*!
     *  This member contains the size in Bytes not accounting for NOPs.
     */
    uint32_t sizeInBytesWithoutNops;

    /*!
     *  This member contains the size in instructions.
     */
    uint32_t sizeInInstructions;

    /*!
     *  This member variable contains the total number of uncovered bytes.
     */
    int uncoveredBytes;

    /*!
     *  This member variable contains the total number of uncovered assembly
     *  instructions.
     */
    int uncoveredInstructions;

    /*!
     *  This member variable contains the total number of uncovered ranges.
     */
    int uncoveredRanges;

    /*!
     *  This member variable contains the total number of unreferenced symbols.
     */
    int unreferencedSymbols;

    /*!
     *  This method returns the percentage of uncovered instructions.
     *
     *  @return Returns the percent uncovered instructions
     */
    uint32_t getPercentUncoveredInstructions( void ) const;

    /*!
     *  This method returns the percentage of uncovered bytes.
     *
     *  @return Returns the percent uncovered bytes
     */
     uint32_t getPercentUncoveredBytes( void ) const;

    /*!
     *  This method constructs a Statistics instance.
     */
     Statistics():
       branchesAlwaysTaken(0),
       branchesExecuted(0),
       branchesNeverTaken(0),
       branchesNotExecuted(0),
       sizeInBytes(0),
       sizeInBytesWithoutNops(0),
       sizeInInstructions(0),
       uncoveredBytes(0),
       uncoveredInstructions(0),
       uncoveredRanges(0),
       unreferencedSymbols(0)
     {
     }

  };

  /*! @class SymbolInformation
   *
   *  This class defines the information kept for each symbol that is
   *  to be analyzed.
   */
  class SymbolInformation {

  public:

    /*!
     *  This member contains the base address of the symbol.
     */
    uint32_t baseAddress;


    /*!
     *  This member contains the disassembly associated with a symbol.
     */
    std::list<ObjdumpProcessor::objdumpLine_t> instructions;

    /*!
     *  This member contains the executable that was used to
     *  generate the disassembled instructions.
     */
    ExecutableInfo* sourceFile;

    /*!
     *  This member contains the statistics kept on each symbol.
     */
    Statistics stats;

    /*!
     *  This member contains information about the branch instructions of
     *  a symbol that were not fully covered (i.e. taken/not taken).
     */
    CoverageRanges* uncoveredBranches;

    /*!
     *  This member contains information about the instructions of a
     *  symbol that were not executed.
     */
    CoverageRanges* uncoveredRanges;

    /*!
     *  This member contains the unified or merged coverage map
     *  for the symbol.
     */
    CoverageMapBase* unifiedCoverageMap;

    /*!
     *  This method constructs a SymbolInformation instance.
     */
    SymbolInformation() :
      baseAddress( 0 ),
      uncoveredBranches( NULL ),
      uncoveredRanges( NULL ),
      unifiedCoverageMap( NULL )
    {
    }

    ~SymbolInformation() {}
  };

  /*! @class DesiredSymbols
   *
   *  This class defines the set of desired symbols to analyze.
   */
  class DesiredSymbols {

  public:

    /*!
     *  This map associates each symbol with its symbol information.
     */
    typedef std::map<std::string, SymbolInformation> symbolSet_t;

    /*!
     *  This variable contains a map of symbol sets for each
     *  symbol in the system keyed on the symbol name.
     */
    symbolSet_t set;

    /*!
     *  This method constructs a DesiredSymbols instance.
     */
    DesiredSymbols();

    /*!
     *  This method destructs a DesiredSymbols instance.
     */
    ~DesiredSymbols();

    /*!
     *  This method loops through the coverage map and
     *  calculates the statistics that have not already
     *  been filled in.
     */
    void calculateStatistics( void );

    /*!
     *  This method analyzes each symbols coverage map to determine any
     *  uncovered ranges or branches.
     */
    void computeUncovered( void );

    /*!
     *  This method creates a coverage map for the specified symbol
     *  using the specified size.
     *
     *  @param[in] exefileName specifies the executable from which the
     *             coverage map is being created
     *  @param[in] symbolName specifies the symbol for which to create
     *             a coverage map
     *  @param[in] size specifies the size of the coverage map to create
     */
    void createCoverageMap(
      const std::string& exefileName,
      const std::string& symbolName,
      uint32_t           size,
      uint32_t           sizeWithoutNops
    );

    /*!
     *  This method looks up the symbol information for the specified symbol.
     *
     *  @param[in] symbolName specifies the symbol for which to search
     *
     *  @return Returns a pointer to the symbol's information
     */
    SymbolInformation* find(
      const std::string& symbolName
    );

    /*!
     *  This method determines the source lines that correspond to any
     *  uncovered ranges or branches.
     */
    void findSourceForUncovered( void );

    /*!
     *  This method returns the total number of branches always taken
     *  for all analyzed symbols.
     *
     *  @return Returns the total number of branches always taken
     */
    uint32_t getNumberBranchesAlwaysTaken( void ) const;

    /*!
     *  This method returns the total number of branches found for
     *  all analyzed symbols.
     *
     *  @return Returns the total number of branches found
     */
    uint32_t getNumberBranchesFound( void ) const;

    /*!
     *  This method returns the total number of branches never taken
     *  for all analyzed symbols.
     *
     *  @return Returns the total number of branches never taken
     */
    uint32_t getNumberBranchesNeverTaken( void ) const;

    /*!
     *  This method returns the total number of branches not executed
     *  for all analyzed symbols.
     *
     *  @return Returns the total number of branches not executed
     */
    uint32_t getNumberBranchesNotExecuted( void ) const;

    /*!
     *  This method returns the total number of uncovered ranges
     *  for all analyzed symbols.
     *
     *  @return Returns the total number of uncovered ranges
     */
    uint32_t getNumberUncoveredRanges( void ) const;

    /*!
     *  This method returns the total number of unreferenced symbols
     *  for all analyzed symbols.
     *
     *  @return Returns the total number of unreferenced symbols
     */
    uint32_t getNumberUnreferencedSymbols( void ) const;

    /*!
     *  This method returns an indication of whether or not the specified
     *  symbol is a symbol to analyze.
     *
     *  @return Returns TRUE if the specified symbol is a symbol to analyze
     *   and FALSE otherwise.
     */
    bool isDesired (
      const std::string& symbolName
    ) const;

    /*!
     *  This method creates the set of symbols to analyze from the symbols
     *  listed in the specified file.
     *
     *  @param[in] symbolsSet An INI format file of the symbols to be loaded.
     *  @param[in] buildTarget The build target
     *  @param[in] buildBSP The BSP
     */
    void load(
      const std::string& symbolsSet,
      const std::string& buildTarget,
      const std::string& buildBSP,
      bool               verbose
    );

    /*!
     *  This method merges the coverage information from the source
     *  coverage map into the unified coverage map for the specified symbol.
     *
     *  @param[in] symbolName specifies the symbol associated with the
     *             destination coverage map
     *  @param[in] sourceCoverageMap specifies the source coverage map
     */
    void mergeCoverageMap(
      const std::string&           symbolName,
      const CoverageMapBase* const sourceCoverageMap
    );

    /*!
     *  This method preprocesses each symbol's coverage map to mark nop
     *  and branch information.
     */
    void preprocess( void );

    /*!
     *  This member contains the statistics kept on each symbol.
     */
    Statistics stats;

  private:

    /*!
     *  This method uses the specified executable file to determine the
     *  source lines for the elements in the specified ranges.
     */
    void determineSourceLines(
      CoverageRanges* const theRanges,
      ExecutableInfo* const theExecutable
    );

  };
}

#endif