File: | build/gcc/gcov-dump.cc |
Warning: | line 388, column 25 Although the value stored to 'c' is used in the enclosing expression, the value is never actually read from 'c' |
Press '?' to see keyboard shortcuts
Keyboard shortcuts:
1 | /* Dump a gcov file, for debugging use. |
2 | Copyright (C) 2002-2023 Free Software Foundation, Inc. |
3 | Contributed by Nathan Sidwell <nathan@codesourcery.com> |
4 | |
5 | Gcov is free software; you can redistribute it and/or modify |
6 | it under the terms of the GNU General Public License as published by |
7 | the Free Software Foundation; either version 3, or (at your option) |
8 | any later version. |
9 | |
10 | Gcov is distributed in the hope that it will be useful, |
11 | but WITHOUT ANY WARRANTY; without even the implied warranty of |
12 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
13 | GNU General Public License for more details. |
14 | |
15 | You should have received a copy of the GNU General Public License |
16 | along with Gcov; see the file COPYING3. If not see |
17 | <http://www.gnu.org/licenses/>. */ |
18 | |
19 | #include "config.h" |
20 | #define INCLUDE_VECTOR |
21 | #include "system.h" |
22 | #include "coretypes.h" |
23 | #include "tm.h" |
24 | #include "version.h" |
25 | #include "intl.h" |
26 | #include "diagnostic.h" |
27 | #include <getopt.h> |
28 | #define IN_GCOV(-1) (-1) |
29 | #include "gcov-io.h" |
30 | #include "gcov-io.cc" |
31 | |
32 | using namespace std; |
33 | |
34 | static void dump_gcov_file (const char *); |
35 | static void print_prefix (const char *, unsigned, gcov_position_t); |
36 | static void print_usage (void); |
37 | static void print_version (void); |
38 | static void tag_function (const char *, unsigned, int, unsigned); |
39 | static void tag_blocks (const char *, unsigned, int, unsigned); |
40 | static void tag_arcs (const char *, unsigned, int, unsigned); |
41 | static void tag_lines (const char *, unsigned, int, unsigned); |
42 | static void tag_counters (const char *, unsigned, int, unsigned); |
43 | static void tag_summary (const char *, unsigned, int, unsigned); |
44 | extern int main (int, char **); |
45 | |
46 | typedef struct tag_format |
47 | { |
48 | unsigned tag; |
49 | char const *name; |
50 | void (*proc) (const char *, unsigned, int, unsigned); |
51 | } tag_format_t; |
52 | |
53 | static int flag_dump_contents = 0; |
54 | static int flag_dump_positions = 0; |
55 | static int flag_dump_raw = 0; |
56 | static int flag_dump_stable = 0; |
57 | |
58 | static const struct option options[] = |
59 | { |
60 | { "help", no_argument0, NULL__null, 'h' }, |
61 | { "version", no_argument0, NULL__null, 'v' }, |
62 | { "long", no_argument0, NULL__null, 'l' }, |
63 | { "positions", no_argument0, NULL__null, 'o' }, |
64 | { "raw", no_argument0, NULL__null, 'r' }, |
65 | { "stable", no_argument0, NULL__null, 's' }, |
66 | {} |
67 | }; |
68 | |
69 | #define VALUE_PADDING_PREFIX" " " " |
70 | #define VALUE_PREFIX"%2d: " "%2d: " |
71 | |
72 | static const tag_format_t tag_table[] = |
73 | { |
74 | {0, "NOP", NULL__null}, |
75 | {0, "UNKNOWN", NULL__null}, |
76 | {0, "COUNTERS", tag_counters}, |
77 | {GCOV_TAG_FUNCTION((gcov_unsigned_t)0x01000000), "FUNCTION", tag_function}, |
78 | {GCOV_TAG_BLOCKS((gcov_unsigned_t)0x01410000), "BLOCKS", tag_blocks}, |
79 | {GCOV_TAG_ARCS((gcov_unsigned_t)0x01430000), "ARCS", tag_arcs}, |
80 | {GCOV_TAG_LINES((gcov_unsigned_t)0x01450000), "LINES", tag_lines}, |
81 | {GCOV_TAG_OBJECT_SUMMARY((gcov_unsigned_t)0xa1000000), "OBJECT_SUMMARY", tag_summary}, |
82 | {0, NULL__null, NULL__null} |
83 | }; |
84 | |
85 | int |
86 | main (int argc ATTRIBUTE_UNUSED__attribute__ ((__unused__)), char **argv) |
87 | { |
88 | int opt; |
89 | const char *p; |
90 | |
91 | p = argv[0] + strlen (argv[0]); |
92 | while (p != argv[0] && !IS_DIR_SEPARATOR (p[-1])(((p[-1]) == '/') || (((p[-1]) == '\\') && (0)))) |
93 | --p; |
94 | progname = p; |
95 | |
96 | xmalloc_set_program_name (progname); |
97 | |
98 | /* Unlock the stdio streams. */ |
99 | unlock_std_streams (); |
100 | |
101 | gcc_init_libintl (); |
102 | |
103 | diagnostic_initialize (global_dc, 0); |
104 | |
105 | while ((opt = getopt_long (argc, argv, "hlprsvw", options, NULL__null)) != -1) |
106 | { |
107 | switch (opt) |
108 | { |
109 | case 'h': |
110 | print_usage (); |
111 | break; |
112 | case 'v': |
113 | print_version (); |
114 | break; |
115 | case 'l': |
116 | flag_dump_contents = 1; |
117 | break; |
118 | case 'p': |
119 | flag_dump_positions = 1; |
120 | break; |
121 | case 'r': |
122 | flag_dump_raw = 1; |
123 | break; |
124 | case 's': |
125 | flag_dump_stable = 1; |
126 | break; |
127 | default: |
128 | fprintf (stderrstderr, "unknown flag `%c'\n", opt); |
129 | } |
130 | } |
131 | |
132 | while (argv[optind]) |
133 | dump_gcov_file (argv[optind++]); |
134 | return 0; |
135 | } |
136 | |
137 | static void |
138 | print_usage (void) |
139 | { |
140 | printf ("Usage: gcov-dump [OPTION] ... gcovfiles\n"); |
141 | printf ("Print coverage file contents\n"); |
142 | printf (" -h, --help Print this help\n"); |
143 | printf (" -l, --long Dump record contents too\n"); |
144 | printf (" -p, --positions Dump record positions\n"); |
145 | printf (" -r, --raw Print content records in raw format\n"); |
146 | printf (" -s, --stable Print content in stable " |
147 | "format usable for comparison\n"); |
148 | printf (" -v, --version Print version number\n"); |
149 | printf ("\nFor bug reporting instructions, please see:\n%s.\n", |
150 | bug_report_url"<https://gcc.gnu.org/bugs/>"); |
151 | } |
152 | |
153 | static void |
154 | print_version (void) |
155 | { |
156 | printf ("gcov-dump %s%s\n", pkgversion_string"(GCC) ", version_string"13.0.1 20230327 (experimental)"); |
157 | printf ("Copyright (C) 2023 Free Software Foundation, Inc.\n"); |
158 | printf ("This is free software; see the source for copying conditions. There is NO\n\ |
159 | warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.\n\n"); |
160 | } |
161 | |
162 | static void |
163 | print_prefix (const char *filename, unsigned depth, gcov_position_t position) |
164 | { |
165 | static const char prefix[] = " "; |
166 | |
167 | printf ("%s:", filename); |
168 | if (flag_dump_positions) |
169 | printf ("%5lu:", (unsigned long) position); |
170 | printf ("%.*s", (int) 2 * depth, prefix); |
171 | } |
172 | |
173 | static void |
174 | dump_gcov_file (const char *filename) |
175 | { |
176 | unsigned tags[4]; |
177 | unsigned depth = 0; |
178 | bool is_data_type; |
179 | |
180 | if (!gcov_open (filename, 1)) |
181 | { |
182 | fprintf (stderrstderr, "%s:cannot open\n", filename); |
183 | return; |
184 | } |
185 | |
186 | /* magic */ |
187 | { |
188 | unsigned magic = gcov_read_unsigned (); |
189 | unsigned version; |
190 | int endianness = 0; |
191 | char m[4], v[4]; |
192 | |
193 | if ((endianness = gcov_magic (magic, GCOV_DATA_MAGIC((gcov_unsigned_t)0x67636461)))) |
194 | is_data_type = true; |
195 | else if ((endianness = gcov_magic (magic, GCOV_NOTE_MAGIC((gcov_unsigned_t)0x67636e6f)))) |
196 | is_data_type = false; |
197 | else |
198 | { |
199 | printf ("%s:not a gcov file\n", filename); |
200 | gcov_close (); |
201 | return; |
202 | } |
203 | version = gcov_read_unsigned (); |
204 | GCOV_UNSIGNED2STRING (v, version)((v)[0] = (char)((version) >> 24), (v)[1] = (char)((version ) >> 16), (v)[2] = (char)((version) >> 8), (v)[3] = (char)((version) >> 0)); |
205 | GCOV_UNSIGNED2STRING (m, magic)((m)[0] = (char)((magic) >> 24), (m)[1] = (char)((magic ) >> 16), (m)[2] = (char)((magic) >> 8), (m)[3] = (char)((magic) >> 0)); |
206 | |
207 | printf ("%s:%s:magic `%.4s':version `%.4s'%s\n", filename, |
208 | is_data_type ? "data" : "note", |
209 | m, v, endianness < 0 ? " (swapped endianness)" : ""); |
210 | if (version != GCOV_VERSION((gcov_unsigned_t)0x42333020)) |
211 | { |
212 | char e[4]; |
213 | |
214 | GCOV_UNSIGNED2STRING (e, GCOV_VERSION)((e)[0] = (char)((((gcov_unsigned_t)0x42333020)) >> 24) , (e)[1] = (char)((((gcov_unsigned_t)0x42333020)) >> 16 ), (e)[2] = (char)((((gcov_unsigned_t)0x42333020)) >> 8 ), (e)[3] = (char)((((gcov_unsigned_t)0x42333020)) >> 0 )); |
215 | printf ("%s:warning:current version is `%.4s'\n", filename, e); |
216 | } |
217 | } |
218 | |
219 | /* stamp */ |
220 | unsigned stamp = gcov_read_unsigned (); |
221 | printf ("%s:stamp %lu\n", filename, (unsigned long)stamp); |
222 | |
223 | /* Checksum */ |
224 | unsigned checksum = gcov_read_unsigned (); |
225 | printf ("%s:checksum %lu\n", filename, (unsigned long)checksum); |
226 | |
227 | if (!is_data_type) |
228 | { |
229 | printf ("%s:cwd: %s\n", filename, gcov_read_string ()); |
230 | |
231 | /* Support for unexecuted basic blocks. */ |
232 | unsigned support_unexecuted_blocks = gcov_read_unsigned (); |
233 | if (!support_unexecuted_blocks) |
234 | printf ("%s: has_unexecuted_block is not supported\n", filename); |
235 | } |
236 | |
237 | while (1) |
238 | { |
239 | gcov_position_t base, position = gcov_position (); |
240 | int read_length; |
241 | unsigned tag, length; |
242 | tag_format_t const *format; |
243 | unsigned tag_depth; |
244 | int error; |
245 | unsigned mask; |
246 | |
247 | tag = gcov_read_unsigned (); |
248 | if (!tag) |
249 | break; |
250 | read_length = (int)gcov_read_unsigned (); |
251 | length = read_length > 0 ? read_length : 0; |
252 | base = gcov_position (); |
253 | mask = GCOV_TAG_MASK (tag)(((tag) - 1) ^ (tag)) >> 1; |
254 | for (tag_depth = 4; mask; mask >>= 8) |
255 | { |
256 | if ((mask & 0xff) != 0xff) |
257 | { |
258 | printf ("%s:tag `%08x' is invalid\n", filename, tag); |
259 | break; |
260 | } |
261 | tag_depth--; |
262 | } |
263 | for (format = tag_table; format->name; format++) |
264 | if (format->tag == tag) |
265 | goto found; |
266 | format = &tag_table[GCOV_TAG_IS_COUNTER (tag)(!((tag) & 0xFFFF) && ((unsigned)(((tag) - ((gcov_unsigned_t )0x01a10000)) >> 17)) < GCOV_COUNTERS) ? 2 : 1]; |
267 | found:; |
268 | if (tag) |
269 | { |
270 | if (depth && depth < tag_depth) |
271 | { |
272 | if (!GCOV_TAG_IS_SUBTAG (tags[depth - 1], tag)((((tags[depth - 1]) - 1) ^ (tags[depth - 1])) >> 8 == ( ((tag) - 1) ^ (tag)) && !(((tag) ^ (tags[depth - 1])) & ~(((tags[depth - 1]) - 1) ^ (tags[depth - 1]))))) |
273 | printf ("%s:tag `%08x' is incorrectly nested\n", |
274 | filename, tag); |
275 | } |
276 | depth = tag_depth; |
277 | tags[depth - 1] = tag; |
278 | } |
279 | |
280 | print_prefix (filename, tag_depth, position); |
281 | printf ("%08x:%4u:%s", tag, abs (read_length), format->name); |
282 | if (format->proc) |
283 | (*format->proc) (filename, tag, read_length, depth); |
284 | |
285 | printf ("\n"); |
286 | if (flag_dump_contents && format->proc) |
287 | { |
288 | unsigned long actual_length = gcov_position () - base; |
289 | |
290 | if (actual_length > length) |
291 | printf ("%s:record size mismatch %lu bytes overread\n", |
292 | filename, actual_length - length); |
293 | else if (length > actual_length) |
294 | printf ("%s:record size mismatch %lu bytes unread\n", |
295 | filename, length - actual_length); |
296 | } |
297 | gcov_sync (base, length); |
298 | if ((error = gcov_is_error ())) |
299 | { |
300 | printf (error < 0 ? "%s:counter overflow at %lu\n" : |
301 | "%s:read error at %lu\n", filename, |
302 | (long unsigned) gcov_position ()); |
303 | break; |
304 | } |
305 | } |
306 | gcov_close (); |
307 | } |
308 | |
309 | static void |
310 | tag_function (const char *filename ATTRIBUTE_UNUSED__attribute__ ((__unused__)), |
311 | unsigned tag ATTRIBUTE_UNUSED__attribute__ ((__unused__)), int length, |
312 | unsigned depth ATTRIBUTE_UNUSED__attribute__ ((__unused__))) |
313 | { |
314 | gcov_position_t pos = gcov_position (); |
315 | |
316 | if (!length) |
317 | printf (" placeholder"); |
318 | else |
319 | { |
320 | printf (" ident=%u", gcov_read_unsigned ()); |
321 | printf (", lineno_checksum=0x%08x", gcov_read_unsigned ()); |
322 | printf (", cfg_checksum=0x%08x", gcov_read_unsigned ()); |
323 | |
324 | if (gcov_position () - pos < (gcov_position_t) length) |
325 | { |
326 | const char *name; |
327 | |
328 | name = gcov_read_string (); |
329 | printf (", `%s'", name ? name : "NULL"); |
330 | unsigned artificial = gcov_read_unsigned (); |
331 | name = gcov_read_string (); |
332 | printf (" %s", name ? name : "NULL"); |
333 | unsigned line_start = gcov_read_unsigned (); |
334 | unsigned column_start = gcov_read_unsigned (); |
335 | unsigned line_end = gcov_read_unsigned (); |
336 | unsigned column_end = gcov_read_unsigned (); |
337 | printf (":%u:%u-%u:%u", line_start, column_start, |
338 | line_end, column_end); |
339 | if (artificial) |
340 | printf (", artificial"); |
341 | } |
342 | } |
343 | } |
344 | |
345 | static void |
346 | tag_blocks (const char *filename ATTRIBUTE_UNUSED__attribute__ ((__unused__)), |
347 | unsigned tag ATTRIBUTE_UNUSED__attribute__ ((__unused__)), int length ATTRIBUTE_UNUSED__attribute__ ((__unused__)), |
348 | unsigned depth ATTRIBUTE_UNUSED__attribute__ ((__unused__))) |
349 | { |
350 | printf (" %u blocks", gcov_read_unsigned ()); |
351 | } |
352 | |
353 | static void |
354 | tag_arcs (const char *filename ATTRIBUTE_UNUSED__attribute__ ((__unused__)), |
355 | unsigned tag ATTRIBUTE_UNUSED__attribute__ ((__unused__)), int length ATTRIBUTE_UNUSED__attribute__ ((__unused__)), |
356 | unsigned depth) |
357 | { |
358 | unsigned n_arcs = GCOV_TAG_ARCS_NUM (length)(((length / 4) - 1) / 2); |
359 | |
360 | printf (" %u arcs", n_arcs); |
361 | if (flag_dump_contents) |
362 | { |
363 | unsigned ix; |
364 | unsigned blockno = gcov_read_unsigned (); |
365 | |
366 | for (ix = 0; ix != n_arcs; ix++) |
367 | { |
368 | unsigned dst, flags; |
369 | |
370 | if (!(ix & 3)) |
371 | { |
372 | printf ("\n"); |
373 | print_prefix (filename, depth, gcov_position ()); |
374 | printf (VALUE_PADDING_PREFIX" " "block %u:", blockno); |
375 | } |
376 | dst = gcov_read_unsigned (); |
377 | flags = gcov_read_unsigned (); |
378 | printf (" %u:%04x", dst, flags); |
379 | if (flags) |
380 | { |
381 | char c = '('; |
382 | |
383 | if (flags & GCOV_ARC_ON_TREE(1 << 0)) |
384 | printf ("%ctree", c), c = ','; |
385 | if (flags & GCOV_ARC_FAKE(1 << 1)) |
386 | printf ("%cfake", c), c = ','; |
387 | if (flags & GCOV_ARC_FALLTHROUGH(1 << 2)) |
388 | printf ("%cfall", c), c = ','; |
Although the value stored to 'c' is used in the enclosing expression, the value is never actually read from 'c' | |
389 | printf (")"); |
390 | } |
391 | } |
392 | } |
393 | } |
394 | |
395 | static void |
396 | tag_lines (const char *filename ATTRIBUTE_UNUSED__attribute__ ((__unused__)), |
397 | unsigned tag ATTRIBUTE_UNUSED__attribute__ ((__unused__)), int length ATTRIBUTE_UNUSED__attribute__ ((__unused__)), |
398 | unsigned depth) |
399 | { |
400 | if (flag_dump_contents) |
401 | { |
402 | unsigned blockno = gcov_read_unsigned (); |
403 | char const *sep = NULL__null; |
404 | |
405 | while (1) |
406 | { |
407 | gcov_position_t position = gcov_position (); |
408 | const char *source = NULL__null; |
409 | unsigned lineno = gcov_read_unsigned (); |
410 | |
411 | if (!lineno) |
412 | { |
413 | source = gcov_read_string (); |
414 | if (!source) |
415 | break; |
416 | sep = NULL__null; |
417 | } |
418 | |
419 | if (!sep) |
420 | { |
421 | printf ("\n"); |
422 | print_prefix (filename, depth, position); |
423 | printf (VALUE_PADDING_PREFIX" " "block %u:", blockno); |
424 | sep = ""; |
425 | } |
426 | if (lineno) |
427 | { |
428 | printf ("%s%u", sep, lineno); |
429 | sep = ", "; |
430 | } |
431 | else |
432 | { |
433 | printf ("%s`%s'", sep, source); |
434 | sep = ":"; |
435 | } |
436 | } |
437 | } |
438 | } |
439 | |
440 | static void |
441 | tag_counters (const char *filename ATTRIBUTE_UNUSED__attribute__ ((__unused__)), |
442 | unsigned tag ATTRIBUTE_UNUSED__attribute__ ((__unused__)), int length ATTRIBUTE_UNUSED__attribute__ ((__unused__)), |
443 | unsigned depth) |
444 | { |
445 | #define DEF_GCOV_COUNTER(COUNTER, NAME, MERGE_FN) NAME, |
446 | static const char *const counter_names[] = { |
447 | #include "gcov-counter.def" |
448 | }; |
449 | #undef DEF_GCOV_COUNTER |
450 | int n_counts = GCOV_TAG_COUNTER_NUM (length)((length / 4) / 2); |
451 | bool has_zeros = n_counts < 0; |
452 | n_counts = abs (n_counts); |
453 | unsigned counter_idx = GCOV_COUNTER_FOR_TAG (tag)((unsigned)(((tag) - ((gcov_unsigned_t)0x01a10000)) >> 17 )); |
454 | |
455 | printf (" %s %u counts%s", |
456 | counter_names[counter_idx], n_counts, |
457 | has_zeros ? " (all zero)" : ""); |
458 | if (flag_dump_contents) |
459 | { |
460 | vector<gcov_type> counters; |
461 | for (int ix = 0; ix != n_counts; ix++) |
462 | counters.push_back (has_zeros ? 0 : gcov_read_counter ()); |
463 | |
464 | /* Make stable sort for TOP N counters. */ |
465 | if (flag_dump_stable) |
466 | if (counter_idx == GCOV_COUNTER_V_INDIR |
467 | || counter_idx == GCOV_COUNTER_V_TOPN) |
468 | { |
469 | unsigned start = 0; |
470 | while (start < counters.size ()) |
471 | { |
472 | unsigned n = counters[start + 1]; |
473 | |
474 | /* Use bubble sort. */ |
475 | for (unsigned i = 1; i <= n; ++i) |
476 | for (unsigned j = i; j <= n; ++j) |
477 | { |
478 | gcov_type key1 = counters[start + 2 * i]; |
479 | gcov_type value1 = counters[start + 2 * i + 1]; |
480 | gcov_type key2 = counters[start + 2 * j]; |
481 | gcov_type value2 = counters[start + 2 * j + 1]; |
482 | |
483 | if (value1 < value2 || (value1 == value2 && key1 < key2)) |
484 | { |
485 | std::swap (counters[start + 2 * i], |
486 | counters[start + 2 * j]); |
487 | std::swap (counters[start + 2 * i + 1], |
488 | counters[start + 2 * j + 1]); |
489 | } |
490 | } |
491 | start += 2 * (n + 1); |
492 | } |
493 | if (start != counters.size ()) |
494 | abort ()fancy_abort ("/buildworker/marxinbox-gcc-clang-static-analyzer/build/gcc/gcov-dump.cc" , 494, __FUNCTION__); |
495 | } |
496 | |
497 | for (unsigned ix = 0; ix < counters.size (); ++ix) |
498 | { |
499 | if (flag_dump_raw) |
500 | { |
501 | if (ix == 0) |
502 | printf (": "); |
503 | } |
504 | else if (!(ix & 7)) |
505 | { |
506 | printf ("\n"); |
507 | print_prefix (filename, depth, gcov_position ()); |
508 | printf (VALUE_PADDING_PREFIX" " VALUE_PREFIX"%2d: ", ix); |
509 | } |
510 | |
511 | printf ("%" PRId64"l" "d" " ", counters[ix]); |
512 | } |
513 | } |
514 | } |
515 | |
516 | static void |
517 | tag_summary (const char *filename ATTRIBUTE_UNUSED__attribute__ ((__unused__)), |
518 | unsigned tag ATTRIBUTE_UNUSED__attribute__ ((__unused__)), int length ATTRIBUTE_UNUSED__attribute__ ((__unused__)), |
519 | unsigned depth ATTRIBUTE_UNUSED__attribute__ ((__unused__))) |
520 | { |
521 | gcov_summary summary; |
522 | gcov_read_summary (&summary); |
523 | printf (" runs=%d, sum_max=%" PRId64"l" "d", |
524 | summary.runs, summary.sum_max); |
525 | } |