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