1 | /*! @file DesiredSymbols.h |
---|
2 | * @brief DesiredSymbols Specification |
---|
3 | * |
---|
4 | * This file contains the specification of the DesiredSymbols class. |
---|
5 | */ |
---|
6 | |
---|
7 | #ifndef __DESIRED_SYMBOLS_H__ |
---|
8 | #define __DESIRED_SYMBOLS_H__ |
---|
9 | |
---|
10 | #include <list> |
---|
11 | #include <map> |
---|
12 | #include <stdint.h> |
---|
13 | #include <string> |
---|
14 | |
---|
15 | #include "CoverageMapBase.h" |
---|
16 | #include "CoverageRanges.h" |
---|
17 | #include "ExecutableInfo.h" |
---|
18 | #include "ObjdumpProcessor.h" |
---|
19 | |
---|
20 | namespace Coverage { |
---|
21 | |
---|
22 | |
---|
23 | /*! |
---|
24 | * |
---|
25 | * This class defines the statistics that are tracked. |
---|
26 | */ |
---|
27 | class Statistics { |
---|
28 | public: |
---|
29 | |
---|
30 | /*! |
---|
31 | * This member variable contains the total number of branches always |
---|
32 | * taken. |
---|
33 | */ |
---|
34 | int branchesAlwaysTaken; |
---|
35 | |
---|
36 | /*! |
---|
37 | * This member variable contains the total number of branches where |
---|
38 | * one or more paths were executed. |
---|
39 | */ |
---|
40 | int branchesExecuted; |
---|
41 | |
---|
42 | /*! |
---|
43 | * This member variable contains the total number of branches never |
---|
44 | * taken. |
---|
45 | */ |
---|
46 | int branchesNeverTaken; |
---|
47 | |
---|
48 | /*! |
---|
49 | * This member variable contains the total number of branches not |
---|
50 | * executed AT ALL. |
---|
51 | */ |
---|
52 | int branchesNotExecuted; |
---|
53 | |
---|
54 | /*! |
---|
55 | * This member contains the size in Bytes. |
---|
56 | */ |
---|
57 | uint32_t sizeInBytes; |
---|
58 | |
---|
59 | /*! |
---|
60 | * This member contains the size in Bytes not accounting for NOPs. |
---|
61 | */ |
---|
62 | uint32_t sizeInBytesWithoutNops; |
---|
63 | |
---|
64 | /*! |
---|
65 | * This member contains the size in instructions. |
---|
66 | */ |
---|
67 | uint32_t sizeInInstructions; |
---|
68 | |
---|
69 | /*! |
---|
70 | * This member variable contains the total number of uncovered bytes. |
---|
71 | */ |
---|
72 | int uncoveredBytes; |
---|
73 | |
---|
74 | /*! |
---|
75 | * This member variable contains the total number of uncovered assembly |
---|
76 | * instructions. |
---|
77 | */ |
---|
78 | int uncoveredInstructions; |
---|
79 | |
---|
80 | /*! |
---|
81 | * This member variable contains the total number of uncovered ranges. |
---|
82 | */ |
---|
83 | int uncoveredRanges; |
---|
84 | |
---|
85 | /*! |
---|
86 | * This member variable contains the total number of unreferenced symbols. |
---|
87 | */ |
---|
88 | int unreferencedSymbols; |
---|
89 | |
---|
90 | /*! |
---|
91 | * This method returns the percentage of uncovered instructions. |
---|
92 | * |
---|
93 | * @return Returns the percent uncovered instructions |
---|
94 | */ |
---|
95 | uint32_t getPercentUncoveredInstructions( void ) const; |
---|
96 | |
---|
97 | /*! |
---|
98 | * This method returns the percentage of uncovered bytes. |
---|
99 | * |
---|
100 | * @return Returns the percent uncovered bytes |
---|
101 | */ |
---|
102 | uint32_t getPercentUncoveredBytes( void ) const; |
---|
103 | |
---|
104 | /*! |
---|
105 | * This method constructs a Statistics instance. |
---|
106 | */ |
---|
107 | Statistics(): |
---|
108 | branchesAlwaysTaken(0), |
---|
109 | branchesExecuted(0), |
---|
110 | branchesNeverTaken(0), |
---|
111 | branchesNotExecuted(0), |
---|
112 | sizeInBytes(0), |
---|
113 | sizeInBytesWithoutNops(0), |
---|
114 | sizeInInstructions(0), |
---|
115 | uncoveredBytes(0), |
---|
116 | uncoveredInstructions(0), |
---|
117 | uncoveredRanges(0), |
---|
118 | unreferencedSymbols(0) |
---|
119 | { |
---|
120 | } |
---|
121 | |
---|
122 | }; |
---|
123 | |
---|
124 | /*! @class SymbolInformation |
---|
125 | * |
---|
126 | * This class defines the information kept for each symbol that is |
---|
127 | * to be analyzed. |
---|
128 | */ |
---|
129 | class SymbolInformation { |
---|
130 | |
---|
131 | public: |
---|
132 | |
---|
133 | /*! |
---|
134 | * This member contains the base address of the symbol. |
---|
135 | */ |
---|
136 | uint32_t baseAddress; |
---|
137 | |
---|
138 | |
---|
139 | /*! |
---|
140 | * This member contains the disassembly associated with a symbol. |
---|
141 | */ |
---|
142 | std::list<ObjdumpProcessor::objdumpLine_t> instructions; |
---|
143 | |
---|
144 | /*! |
---|
145 | * This member contains the executable that was used to |
---|
146 | * generate the disassembled instructions. |
---|
147 | */ |
---|
148 | ExecutableInfo* sourceFile; |
---|
149 | |
---|
150 | /*! |
---|
151 | * This member contains the statistics kept on each symbol. |
---|
152 | */ |
---|
153 | Statistics stats; |
---|
154 | |
---|
155 | /*! |
---|
156 | * This member contains information about the branch instructions of |
---|
157 | * a symbol that were not fully covered (i.e. taken/not taken). |
---|
158 | */ |
---|
159 | CoverageRanges* uncoveredBranches; |
---|
160 | |
---|
161 | /*! |
---|
162 | * This member contains information about the instructions of a |
---|
163 | * symbol that were not executed. |
---|
164 | */ |
---|
165 | CoverageRanges* uncoveredRanges; |
---|
166 | |
---|
167 | /*! |
---|
168 | * This member contains the unified or merged coverage map |
---|
169 | * for the symbol. |
---|
170 | */ |
---|
171 | CoverageMapBase* unifiedCoverageMap; |
---|
172 | |
---|
173 | /*! |
---|
174 | * This method constructs a SymbolInformation instance. |
---|
175 | */ |
---|
176 | SymbolInformation() : |
---|
177 | baseAddress( 0 ), |
---|
178 | uncoveredBranches( NULL ), |
---|
179 | uncoveredRanges( NULL ), |
---|
180 | unifiedCoverageMap( NULL ) |
---|
181 | { |
---|
182 | } |
---|
183 | |
---|
184 | ~SymbolInformation() {} |
---|
185 | }; |
---|
186 | |
---|
187 | /*! @class DesiredSymbols |
---|
188 | * |
---|
189 | * This class defines the set of desired symbols to analyze. |
---|
190 | */ |
---|
191 | class DesiredSymbols { |
---|
192 | |
---|
193 | public: |
---|
194 | |
---|
195 | /*! |
---|
196 | * This map associates each symbol with its symbol information. |
---|
197 | */ |
---|
198 | typedef std::map<std::string, SymbolInformation> symbolSet_t; |
---|
199 | |
---|
200 | /*! |
---|
201 | * This method constructs a DesiredSymbols instance. |
---|
202 | */ |
---|
203 | DesiredSymbols(); |
---|
204 | |
---|
205 | /*! |
---|
206 | * This method destructs a DesiredSymbols instance. |
---|
207 | */ |
---|
208 | ~DesiredSymbols(); |
---|
209 | |
---|
210 | /*! |
---|
211 | * The set of all symbols. |
---|
212 | */ |
---|
213 | const symbolSet_t& allSymbols() const; |
---|
214 | |
---|
215 | /*! |
---|
216 | * This method loops through the coverage map and |
---|
217 | * calculates the statistics that have not already |
---|
218 | * been filled in. |
---|
219 | */ |
---|
220 | void calculateStatistics( void ); |
---|
221 | |
---|
222 | /*! |
---|
223 | * This method analyzes each symbols coverage map to determine any |
---|
224 | * uncovered ranges or branches. |
---|
225 | */ |
---|
226 | void computeUncovered( void ); |
---|
227 | |
---|
228 | /*! |
---|
229 | * This method creates a coverage map for the specified symbol |
---|
230 | * using the specified size. |
---|
231 | * |
---|
232 | * @param[in] exefileName specifies the executable from which the |
---|
233 | * coverage map is being created |
---|
234 | * @param[in] symbolName specifies the symbol for which to create |
---|
235 | * a coverage map |
---|
236 | * @param[in] size specifies the size of the coverage map to create |
---|
237 | */ |
---|
238 | void createCoverageMap( |
---|
239 | const std::string& exefileName, |
---|
240 | const std::string& symbolName, |
---|
241 | uint32_t size, |
---|
242 | uint32_t sizeWithoutNops |
---|
243 | ); |
---|
244 | |
---|
245 | /*! |
---|
246 | * This method looks up the symbol information for the specified symbol. |
---|
247 | * |
---|
248 | * @param[in] symbolName specifies the symbol for which to search |
---|
249 | * |
---|
250 | * @return Returns a pointer to the symbol's information |
---|
251 | */ |
---|
252 | SymbolInformation* find( |
---|
253 | const std::string& symbolName |
---|
254 | ); |
---|
255 | |
---|
256 | /*! |
---|
257 | * This method determines the source lines that correspond to any |
---|
258 | * uncovered ranges or branches. |
---|
259 | */ |
---|
260 | void findSourceForUncovered( void ); |
---|
261 | |
---|
262 | /*! |
---|
263 | * This method returns the total number of branches always taken |
---|
264 | * for all analyzed symbols in a given set. |
---|
265 | * |
---|
266 | * @param[in] symbolSetName specifies the symbol set of interest |
---|
267 | * |
---|
268 | * @return Returns the total number of branches always taken |
---|
269 | */ |
---|
270 | uint32_t getNumberBranchesAlwaysTaken( |
---|
271 | const std::string& symbolSetName |
---|
272 | ) const; |
---|
273 | |
---|
274 | /*! |
---|
275 | * This method returns the total number of branches found for |
---|
276 | * all analyzed symbols in a given set. |
---|
277 | * |
---|
278 | * @param[in] symbolSetName specifies the symbol set of interest |
---|
279 | * |
---|
280 | * @return Returns the total number of branches found |
---|
281 | */ |
---|
282 | uint32_t getNumberBranchesFound( |
---|
283 | const std::string& symbolSetName |
---|
284 | ) const; |
---|
285 | |
---|
286 | /*! |
---|
287 | * This method returns the total number of branches never taken |
---|
288 | * for all analyzed symbols in a given set. |
---|
289 | * |
---|
290 | * @param[in] symbolSetName specifies the symbol set of interest |
---|
291 | * |
---|
292 | * @return Returns the total number of branches never taken |
---|
293 | */ |
---|
294 | uint32_t getNumberBranchesNeverTaken( |
---|
295 | const std::string& symbolSetName |
---|
296 | ) const; |
---|
297 | |
---|
298 | /*! |
---|
299 | * This method returns the total number of branches not executed |
---|
300 | * for all analyzed symbols in a given set. |
---|
301 | * |
---|
302 | * @param[in] symbolSetName specifies the symbol set of interest |
---|
303 | * |
---|
304 | * @return Returns the total number of branches not executed |
---|
305 | */ |
---|
306 | uint32_t getNumberBranchesNotExecuted( |
---|
307 | const std::string& symbolSetName |
---|
308 | ) const; |
---|
309 | |
---|
310 | /*! |
---|
311 | * This method returns the total number of uncovered ranges |
---|
312 | * for all analyzed symbols in a given set. |
---|
313 | * |
---|
314 | * @param[in] symbolSetName specifies the symbol set of interest |
---|
315 | * |
---|
316 | * @return Returns the total number of uncovered ranges |
---|
317 | */ |
---|
318 | uint32_t getNumberUncoveredRanges( |
---|
319 | const std::string& symbolSetName |
---|
320 | ) const; |
---|
321 | |
---|
322 | /*! |
---|
323 | * This method returns the total number of unreferenced symbols |
---|
324 | * for all analyzed symbols in a given set. |
---|
325 | * |
---|
326 | * @param[in] symbolSetName specifies the symbol set of interest |
---|
327 | * |
---|
328 | * @return Returns the total number of unreferenced symbols |
---|
329 | */ |
---|
330 | uint32_t getNumberUnreferencedSymbols( |
---|
331 | const std::string& symbolSetName |
---|
332 | ) const; |
---|
333 | |
---|
334 | /*! |
---|
335 | * This method returns all symbol set names. |
---|
336 | * |
---|
337 | * @return Returns all symbol set names |
---|
338 | */ |
---|
339 | std::vector<std::string> getSetNames( void ) const; |
---|
340 | |
---|
341 | /*! |
---|
342 | * This method returns all symbols for a given set. |
---|
343 | * |
---|
344 | * @param[in] symbolSetName specifies the symbol set of interest |
---|
345 | * |
---|
346 | * @return Returns all symbols for the given set |
---|
347 | */ |
---|
348 | const std::vector<std::string>& getSymbolsForSet( |
---|
349 | const std::string& symbolSetName |
---|
350 | ) const; |
---|
351 | |
---|
352 | /*! |
---|
353 | * This method returns an indication of whether or not the specified |
---|
354 | * symbol is a symbol to analyze. |
---|
355 | * |
---|
356 | * @return Returns TRUE if the specified symbol is a symbol to analyze |
---|
357 | * and FALSE otherwise. |
---|
358 | */ |
---|
359 | bool isDesired ( |
---|
360 | const std::string& symbolName |
---|
361 | ) const; |
---|
362 | |
---|
363 | /*! |
---|
364 | * This method creates the set of symbols to analyze from the symbols |
---|
365 | * listed in the specified file. |
---|
366 | * |
---|
367 | * @param[in] symbolsSet An INI format file of the symbols to be loaded. |
---|
368 | * @param[in] buildTarget The build target |
---|
369 | * @param[in] buildBSP The BSP |
---|
370 | */ |
---|
371 | void load( |
---|
372 | const std::string& symbolsSet, |
---|
373 | const std::string& buildTarget, |
---|
374 | const std::string& buildBSP, |
---|
375 | bool verbose |
---|
376 | ); |
---|
377 | |
---|
378 | /*! |
---|
379 | * This method merges the coverage information from the source |
---|
380 | * coverage map into the unified coverage map for the specified symbol. |
---|
381 | * |
---|
382 | * @param[in] symbolName specifies the symbol associated with the |
---|
383 | * destination coverage map |
---|
384 | * @param[in] sourceCoverageMap specifies the source coverage map |
---|
385 | */ |
---|
386 | void mergeCoverageMap( |
---|
387 | const std::string& symbolName, |
---|
388 | const CoverageMapBase* const sourceCoverageMap |
---|
389 | ); |
---|
390 | |
---|
391 | /*! |
---|
392 | * This method preprocesses each symbol's coverage map to mark nop |
---|
393 | * and branch information. |
---|
394 | */ |
---|
395 | void preprocess( void ); |
---|
396 | |
---|
397 | private: |
---|
398 | |
---|
399 | /*! |
---|
400 | * This method uses the specified executable file to determine the |
---|
401 | * source lines for the elements in the specified ranges. |
---|
402 | */ |
---|
403 | void determineSourceLines( |
---|
404 | CoverageRanges* const theRanges, |
---|
405 | ExecutableInfo* const theExecutable |
---|
406 | ); |
---|
407 | |
---|
408 | /*! |
---|
409 | * This variable contains a map of symbol sets for each |
---|
410 | * symbol in the system keyed on the symbol name. |
---|
411 | */ |
---|
412 | symbolSet_t set; |
---|
413 | |
---|
414 | /*! |
---|
415 | * This variable contains a map of symbol set names to symbol name lists. |
---|
416 | */ |
---|
417 | std::map<std::string, std::vector<std::string>> setNamesToSymbols; |
---|
418 | |
---|
419 | /*! |
---|
420 | * This member contains a map of symbol set names to statistics. |
---|
421 | */ |
---|
422 | std::map<std::string, Statistics> stats; |
---|
423 | |
---|
424 | }; |
---|
425 | } |
---|
426 | |
---|
427 | #endif |
---|