source: rtems-tools/tester/covoar/CoverageMapBase.h @ 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: 12.3 KB
Line 
1/*! @file CoverageMapBase.h
2 *  @brief CoverageMapBase Specification
3 *
4 *  This file contains the specification of the CoverageMapBase class.
5 */
6
7#ifndef __COVERAGE_MAP_BASE_H__
8#define __COVERAGE_MAP_BASE_H__
9
10#include <stdint.h>
11#include <string>
12#include <list>
13
14namespace Coverage {
15
16  /*! @class CoverageMapBase
17   *
18   *  This is the base class for Coverage Map implementations.
19   */
20  class CoverageMapBase {
21
22  public:
23
24    /*!
25     *  This structure identifies the low and high addresses
26     *  of one range.  Note:: There may be more than one address
27     *  range per symbol.
28     */
29    struct AddressRange {
30      /*!
31       *  This is the file from which this originated.
32       */
33      std::string fileName;
34
35      /*!
36       *  This is the low address of the address map range.
37       */
38      uint32_t lowAddress;
39
40      /*!
41       *  This is the high address of the address map range.
42       */
43      uint32_t highAddress;
44
45    };
46
47    /*
48     *  This type identifies a list of ranges.
49     */
50    typedef std::list< AddressRange >  AddressRanges;
51
52    /*!
53     *  This method constructs a CoverageMapBase instance.
54     *
55     *  @param[in] exefileName specifies the executable this originated in
56     *  @param[in] low specifies the lowest address of the coverage map
57     *  @param[in] high specifies the highest address of the coverage map
58     */
59    CoverageMapBase(
60      const std::string& exefileName,
61      uint32_t           low,
62      uint32_t           high
63    );
64
65    /*!
66     *  This method destructs a CoverageMapBase instance.
67     */
68    virtual ~CoverageMapBase();
69
70    /*!
71     *  This method adds a address range to the RangeList.
72     *
73     *  @param[in]  Low specifies the lowAddress
74     *  @param[in]  High specifies the highAddress
75     *
76     */
77    void Add( uint32_t low, uint32_t high );
78
79    /*!
80     *  This method returns true and sets the offset if
81     *  the address falls with the bounds of an address range
82     *  in the RangeList.
83     *
84     *  @param[in]  address specifies the address to find
85     *  @param[out] offset contains the offset from the low
86     *              address of the address range.
87     *
88     *  @return Returns TRUE if the address range can be found
89     *   and FALSE if it was not.
90      */
91    bool determineOffset( uint32_t address, uint32_t *offset ) const;
92
93    /*!
94     *  This method prints the contents of the coverage map to stdout.
95     */
96    void dump( void ) const;
97
98    /*!
99     *  This method will return the low address of the first range in
100     *  the RangeList.
101     *
102     *  @return Returns the low address of the first range in
103     *  the RangeList.
104     */
105    int32_t getFirstLowAddress() const;
106
107    /*!
108     *  This method returns true and sets the address range if
109     *  the address falls with the bounds of an address range
110     *  in the RangeList.
111     *
112     *  @param[in]  address specifies the address to find
113     *  @param[out] range contains the high and low addresse for
114     *              the range
115     *
116     *  @return Returns TRUE if the address range can be found
117     *   and FALSE if it was not.
118     */
119    bool getRange( uint32_t address, AddressRange *range ) const;
120
121    /*!
122     *  This method returns the size of the address range.
123     *
124     *  @return Returns Size of the address range.
125     */
126    uint32_t getSize() const;
127
128
129    /*!
130     *  This method returns the address of the beginning of the
131     *  instruction that contains the specified address.
132     *
133     *  @param[in] address specifies the address to search from
134     *  @param[out] beginning contains the address of the beginning of
135     *              the instruction.
136     *
137     *  @return Returns TRUE if the beginning of the instruction was
138     *   found and FALSE if it was not.
139     */
140    bool getBeginningOfInstruction(
141      uint32_t  address,
142      uint32_t* beginning
143    ) const;
144
145    /*!
146     *  This method returns the high address of the coverage map.
147     *
148     *  @return Returns the high address of the coverage map.
149    uint32_t getHighAddress( void ) const;
150     */
151
152    /*!
153     *  This method returns the low address of the coverage map.
154     *
155     *  @return Returns the low address of the coverage map.
156    uint32_t getLowAddress( void ) const;
157     */
158
159    /*!
160     *  This method sets the boolean which indicates if this
161     *  is the starting address for an instruction.
162     *
163     *  @param[in] address specifies the address of the start of an instruction
164     */
165    void setIsStartOfInstruction(
166      uint32_t address
167    );
168
169    /*!
170     *  This method returns a boolean which indicates if this
171     *  is the starting address of an instruction.
172     *
173     *  @param[in] address specifies the address to check
174     *
175     *  @return Returns TRUE if the specified address is the start
176     *   of an instruction and FALSE otherwise.
177     */
178    bool isStartOfInstruction( uint32_t address ) const;
179
180    /*!
181     *  This method increments the counter which indicates how many times
182     *  the instruction at the specified address was executed.
183     *
184     *  @param[in] address specifies the address which was executed
185     */
186    virtual void setWasExecuted( uint32_t address );
187
188    /*!
189     *  This method returns a boolean which indicates if the instruction
190     *  at the specified address was executed.
191     *
192     *  @param[in] address specifies the address to check
193     *
194     *  @return Returns TRUE if the instruction at the specified
195     *   address was executed and FALSE otherwise.
196     */
197    bool wasExecuted( uint32_t address ) const;
198
199    /*!
200     *  This method increases the counter which indicates how many times
201     *  the instruction at the specified address was executed. It is used
202     *  for merging coverage maps.
203     *
204     *  @param[in] address specifies the address which was executed
205     *  @param[in] address specifies the execution count that should be
206     *             added
207     */
208    virtual void sumWasExecuted( uint32_t address, uint32_t addition );
209
210    /*!
211     *  This method returns an unsigned integer which indicates how often
212     *  the instruction at the specified address was executed.
213     *
214     *  @param[in] address specifies the address to check
215     *
216     *  @return Returns number of executins
217     */
218    uint32_t getWasExecuted( uint32_t address ) const;
219
220    /*!
221     *  This method sets the boolean which indicates if the specified
222     *  address is the starting address of a branch instruction.
223     *
224     *  @param[in] address specifies the address of the branch instruction
225     */
226    void setIsBranch( uint32_t address );
227
228    /*!
229     *  This method returns a boolean which indicates if the specified
230     *  address is the starting address of a NOP instruction.
231     *
232     *  @param[in] address specifies the address to check
233     *
234     *  @return Returns TRUE if a NOP instruction is at the
235     *   specified address and FALSE otherwise.
236     */
237    bool isNop( uint32_t address ) const;
238
239    /*!
240     *  This method sets the boolean which indicates if the specified
241     *  address is the starting address of a NOP instruction.
242     *
243     *  @param[in] address specifies the address of the NOP instruction
244     */
245    void setIsNop( uint32_t address );
246
247    /*!
248     *  This method returns a boolean which indicates if the specified
249     *  address is the starting address of a branch instruction.
250     *
251     *  @param[in] address specifies the address to check
252     *
253     *  @return Returns TRUE if a branch instruction is at the
254     *   specified address and FALSE otherwise.
255     */
256    bool isBranch( uint32_t address ) const;
257
258    /*!
259     *  This method increments the counter which indicates how many times
260     *  the branch at the specified address was taken.
261     *
262     *  @param[in] address specifies the address of the branch instruction
263     */
264    void setWasTaken( uint32_t address );
265
266    /*!
267     *  This method increases the counter which indicates how many times
268     *  the branch at the specified address was taken. It is used
269     *  for merging coverage maps.
270     *
271     *  @param[in] address specifies the address which was executed
272     *  @param[in] address specifies the execution count that should be
273     *             added
274     */
275    virtual void sumWasTaken( uint32_t address, uint32_t addition );
276
277    /*!
278     *  This method returns an unsigned integer which indicates how often
279     *  the branch at the specified address was taken.
280     *
281     *  @param[in] address specifies the address to check
282     *
283     *  @return Returns number of executins
284     */
285    uint32_t getWasTaken( uint32_t address ) const;
286
287    /*!
288     *  This method increments the counter which indicates how many times
289     *  the branch at the specified address was not taken.
290     *
291     *  @param[in] address specifies the address of the branch instruction
292     */
293    void setWasNotTaken( uint32_t address );
294
295    /*!
296     *  This method increases the counter which indicates how many times
297     *  the branch at the specified address was not taken. It is used
298     *  for merging coverage maps.
299     *
300     *  @param[in] address specifies the address which was executed
301     *  @param[in] address specifies the execution count that should be
302     *             added
303     */
304    virtual void sumWasNotTaken( uint32_t address, uint32_t addition );
305
306    /*!
307     *  This method returns an unsigned integer which indicates how often
308     *  the branch at the specified address was not taken.
309     *
310     *  @param[in] address specifies the address to check
311     *
312     *  @return Returns number of executins
313     */
314    uint32_t getWasNotTaken( uint32_t address ) const;
315
316
317    /*!
318     *  This method returns a boolean which indicates if the branch
319     *  instruction at the specified address is ALWAYS taken.
320     *
321     *  @param[in] address specifies the address to check
322     *
323     *  @return Returns TRUE if the branch instruction at the
324     *   specified address is ALWAYS taken and FALSE otherwise.
325     */
326    bool wasAlwaysTaken( uint32_t address ) const;
327
328    /*!
329     *  This method returns a boolean which indicates if the branch
330     *  instruction at the specified address is NEVER taken.
331     *
332     *  @param[in] address specifies the address to check
333     *
334     *  @return Returns TRUE if the branch instruction at the
335     *  specified address is NEVER taken and FALSE otherwise.
336     */
337    bool wasNeverTaken( uint32_t address ) const;
338
339    /*!
340     *  This method returns a boolean which indicates if the branch
341     *  instruction at the specified address was NOT taken.
342     *
343     *  @param[in] address specifies the address to check
344     *
345     *  @return Returns TRUE if the branch instruction at the
346     *   specified address was NOT taken and FALSE otherwise.
347     */
348    bool wasNotTaken( uint32_t address ) const;
349
350    /*!
351     *  This method returns a boolean which indicates if the branch
352     *  instruction at the specified address was taken.
353     *
354     *  @param[in] address specifies the address to check
355     *
356     *  @return Returns TRUE if the branch instruction at the
357     *  specified address was taken and FALSE otherwise.
358     */
359    bool wasTaken( uint32_t address ) const;
360
361  protected:
362
363    /*!
364     *  This structure defines the information that is gathered and
365     *  tracked per address.
366     */
367    struct perAddressInfo {
368      /*!
369       *  This member indicates that the address is the start of
370       *  an instruction.
371       */
372      bool isStartOfInstruction;
373      /*!
374       *  This member indicates how many times the address was executed.
375       */
376      uint32_t wasExecuted;
377      /*!
378       *  This member indicates that the address is a branch instruction.
379       */
380      bool isBranch;
381      /*!
382       *  This member indicates that the address is a NOP instruction.
383       */
384      bool isNop;
385      /*!
386       *  When isBranch is TRUE, this member indicates that the branch
387       *  instruction at the address was taken.
388       */
389      uint32_t wasTaken;
390      /*!
391       *  When isBranch is TRUE, this member indicates that the branch
392       *  instruction at the address was NOT taken.
393       */
394      uint32_t wasNotTaken;
395    };
396
397    /*!
398     *
399     *  This is a list of address ranges for this symbolic address.
400     */
401    AddressRanges Ranges;
402
403    /*!
404     *
405     *  This variable contains the size of the code block.
406     */
407    uint32_t Size;
408
409    /*!
410     *  This is a dynamically allocated array of data that is
411     *  kept for each address.
412     */
413    perAddressInfo* Info;
414  };
415
416}
417#endif
Note: See TracBrowser for help on using the repository browser.