xref: /dflybsd-src/contrib/gcc-4.7/gcc/gcov-dump.c (revision 04febcfb30580676d3e95f58a16c5137ee478b32)
1*e4b17023SJohn Marino /* Dump a gcov file, for debugging use.
2*e4b17023SJohn Marino    Copyright (C) 2002, 2003, 2004, 2005, 2006, 2007, 2008, 2009, 2010, 2011,
3*e4b17023SJohn Marino    2012 Free Software Foundation, Inc.
4*e4b17023SJohn Marino    Contributed by Nathan Sidwell <nathan@codesourcery.com>
5*e4b17023SJohn Marino 
6*e4b17023SJohn Marino Gcov is free software; you can redistribute it and/or modify
7*e4b17023SJohn Marino it under the terms of the GNU General Public License as published by
8*e4b17023SJohn Marino the Free Software Foundation; either version 3, or (at your option)
9*e4b17023SJohn Marino any later version.
10*e4b17023SJohn Marino 
11*e4b17023SJohn Marino Gcov is distributed in the hope that it will be useful,
12*e4b17023SJohn Marino but WITHOUT ANY WARRANTY; without even the implied warranty of
13*e4b17023SJohn Marino MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14*e4b17023SJohn Marino GNU General Public License for more details.
15*e4b17023SJohn Marino 
16*e4b17023SJohn Marino You should have received a copy of the GNU General Public License
17*e4b17023SJohn Marino along with Gcov; see the file COPYING3.  If not see
18*e4b17023SJohn Marino <http://www.gnu.org/licenses/>.  */
19*e4b17023SJohn Marino 
20*e4b17023SJohn Marino #include "config.h"
21*e4b17023SJohn Marino #include "system.h"
22*e4b17023SJohn Marino #include "coretypes.h"
23*e4b17023SJohn Marino #include "tm.h"
24*e4b17023SJohn Marino #include "version.h"
25*e4b17023SJohn Marino #include "intl.h"
26*e4b17023SJohn Marino #include "diagnostic.h"
27*e4b17023SJohn Marino #include <getopt.h>
28*e4b17023SJohn Marino #define IN_GCOV (-1)
29*e4b17023SJohn Marino #include "gcov-io.h"
30*e4b17023SJohn Marino #include "gcov-io.c"
31*e4b17023SJohn Marino 
32*e4b17023SJohn Marino static void dump_file (const char *);
33*e4b17023SJohn Marino static void print_prefix (const char *, unsigned, gcov_position_t);
34*e4b17023SJohn Marino static void print_usage (void);
35*e4b17023SJohn Marino static void print_version (void);
36*e4b17023SJohn Marino static void tag_function (const char *, unsigned, unsigned);
37*e4b17023SJohn Marino static void tag_blocks (const char *, unsigned, unsigned);
38*e4b17023SJohn Marino static void tag_arcs (const char *, unsigned, unsigned);
39*e4b17023SJohn Marino static void tag_lines (const char *, unsigned, unsigned);
40*e4b17023SJohn Marino static void tag_counters (const char *, unsigned, unsigned);
41*e4b17023SJohn Marino static void tag_summary (const char *, unsigned, unsigned);
42*e4b17023SJohn Marino extern int main (int, char **);
43*e4b17023SJohn Marino 
44*e4b17023SJohn Marino typedef struct tag_format
45*e4b17023SJohn Marino {
46*e4b17023SJohn Marino   unsigned tag;
47*e4b17023SJohn Marino   char const *name;
48*e4b17023SJohn Marino   void (*proc) (const char *, unsigned, unsigned);
49*e4b17023SJohn Marino } tag_format_t;
50*e4b17023SJohn Marino 
51*e4b17023SJohn Marino static int flag_dump_contents = 0;
52*e4b17023SJohn Marino static int flag_dump_positions = 0;
53*e4b17023SJohn Marino 
54*e4b17023SJohn Marino static const struct option options[] =
55*e4b17023SJohn Marino {
56*e4b17023SJohn Marino   { "help",                 no_argument,       NULL, 'h' },
57*e4b17023SJohn Marino   { "version",              no_argument,       NULL, 'v' },
58*e4b17023SJohn Marino   { "long",                 no_argument,       NULL, 'l' },
59*e4b17023SJohn Marino   { "positions",	    no_argument,       NULL, 'o' },
60*e4b17023SJohn Marino   { 0, 0, 0, 0 }
61*e4b17023SJohn Marino };
62*e4b17023SJohn Marino 
63*e4b17023SJohn Marino static const tag_format_t tag_table[] =
64*e4b17023SJohn Marino {
65*e4b17023SJohn Marino   {0, "NOP", NULL},
66*e4b17023SJohn Marino   {0, "UNKNOWN", NULL},
67*e4b17023SJohn Marino   {0, "COUNTERS", tag_counters},
68*e4b17023SJohn Marino   {GCOV_TAG_FUNCTION, "FUNCTION", tag_function},
69*e4b17023SJohn Marino   {GCOV_TAG_BLOCKS, "BLOCKS", tag_blocks},
70*e4b17023SJohn Marino   {GCOV_TAG_ARCS, "ARCS", tag_arcs},
71*e4b17023SJohn Marino   {GCOV_TAG_LINES, "LINES", tag_lines},
72*e4b17023SJohn Marino   {GCOV_TAG_OBJECT_SUMMARY, "OBJECT_SUMMARY", tag_summary},
73*e4b17023SJohn Marino   {GCOV_TAG_PROGRAM_SUMMARY, "PROGRAM_SUMMARY", tag_summary},
74*e4b17023SJohn Marino   {0, NULL, NULL}
75*e4b17023SJohn Marino };
76*e4b17023SJohn Marino 
77*e4b17023SJohn Marino int
main(int argc ATTRIBUTE_UNUSED,char ** argv)78*e4b17023SJohn Marino main (int argc ATTRIBUTE_UNUSED, char **argv)
79*e4b17023SJohn Marino {
80*e4b17023SJohn Marino   int opt;
81*e4b17023SJohn Marino   const char *p;
82*e4b17023SJohn Marino 
83*e4b17023SJohn Marino   p = argv[0] + strlen (argv[0]);
84*e4b17023SJohn Marino   while (p != argv[0] && !IS_DIR_SEPARATOR (p[-1]))
85*e4b17023SJohn Marino     --p;
86*e4b17023SJohn Marino   progname = p;
87*e4b17023SJohn Marino 
88*e4b17023SJohn Marino   xmalloc_set_program_name (progname);
89*e4b17023SJohn Marino 
90*e4b17023SJohn Marino   /* Unlock the stdio streams.  */
91*e4b17023SJohn Marino   unlock_std_streams ();
92*e4b17023SJohn Marino 
93*e4b17023SJohn Marino   gcc_init_libintl ();
94*e4b17023SJohn Marino 
95*e4b17023SJohn Marino   diagnostic_initialize (global_dc, 0);
96*e4b17023SJohn Marino 
97*e4b17023SJohn Marino   while ((opt = getopt_long (argc, argv, "hlpv", options, NULL)) != -1)
98*e4b17023SJohn Marino     {
99*e4b17023SJohn Marino       switch (opt)
100*e4b17023SJohn Marino 	{
101*e4b17023SJohn Marino 	case 'h':
102*e4b17023SJohn Marino 	  print_usage ();
103*e4b17023SJohn Marino 	  break;
104*e4b17023SJohn Marino 	case 'v':
105*e4b17023SJohn Marino 	  print_version ();
106*e4b17023SJohn Marino 	  break;
107*e4b17023SJohn Marino 	case 'l':
108*e4b17023SJohn Marino 	  flag_dump_contents = 1;
109*e4b17023SJohn Marino 	  break;
110*e4b17023SJohn Marino 	case 'p':
111*e4b17023SJohn Marino 	  flag_dump_positions = 1;
112*e4b17023SJohn Marino 	  break;
113*e4b17023SJohn Marino 	default:
114*e4b17023SJohn Marino 	  fprintf (stderr, "unknown flag `%c'\n", opt);
115*e4b17023SJohn Marino 	}
116*e4b17023SJohn Marino     }
117*e4b17023SJohn Marino 
118*e4b17023SJohn Marino   while (argv[optind])
119*e4b17023SJohn Marino     dump_file (argv[optind++]);
120*e4b17023SJohn Marino   return 0;
121*e4b17023SJohn Marino }
122*e4b17023SJohn Marino 
123*e4b17023SJohn Marino static void
print_usage(void)124*e4b17023SJohn Marino print_usage (void)
125*e4b17023SJohn Marino {
126*e4b17023SJohn Marino   printf ("Usage: gcov-dump [OPTION] ... gcovfiles\n");
127*e4b17023SJohn Marino   printf ("Print coverage file contents\n");
128*e4b17023SJohn Marino   printf ("  -h, --help           Print this help\n");
129*e4b17023SJohn Marino   printf ("  -v, --version        Print version number\n");
130*e4b17023SJohn Marino   printf ("  -l, --long           Dump record contents too\n");
131*e4b17023SJohn Marino   printf ("  -p, --positions      Dump record positions\n");
132*e4b17023SJohn Marino }
133*e4b17023SJohn Marino 
134*e4b17023SJohn Marino static void
print_version(void)135*e4b17023SJohn Marino print_version (void)
136*e4b17023SJohn Marino {
137*e4b17023SJohn Marino   printf ("gcov-dump %s%s\n", pkgversion_string, version_string);
138*e4b17023SJohn Marino   printf ("Copyright (C) 2012 Free Software Foundation, Inc.\n");
139*e4b17023SJohn Marino   printf ("This is free software; see the source for copying conditions.\n"
140*e4b17023SJohn Marino   	  "There is NO warranty; not even for MERCHANTABILITY or \n"
141*e4b17023SJohn Marino 	  "FITNESS FOR A PARTICULAR PURPOSE.\n\n");
142*e4b17023SJohn Marino }
143*e4b17023SJohn Marino 
144*e4b17023SJohn Marino static void
print_prefix(const char * filename,unsigned depth,gcov_position_t position)145*e4b17023SJohn Marino print_prefix (const char *filename, unsigned depth, gcov_position_t position)
146*e4b17023SJohn Marino {
147*e4b17023SJohn Marino   static const char prefix[] = "    ";
148*e4b17023SJohn Marino 
149*e4b17023SJohn Marino   printf ("%s:", filename);
150*e4b17023SJohn Marino   if (flag_dump_positions)
151*e4b17023SJohn Marino     printf ("%lu:", (unsigned long) position);
152*e4b17023SJohn Marino   printf ("%.*s", (int) depth, prefix);
153*e4b17023SJohn Marino }
154*e4b17023SJohn Marino 
155*e4b17023SJohn Marino static void
dump_file(const char * filename)156*e4b17023SJohn Marino dump_file (const char *filename)
157*e4b17023SJohn Marino {
158*e4b17023SJohn Marino   unsigned tags[4];
159*e4b17023SJohn Marino   unsigned depth = 0;
160*e4b17023SJohn Marino 
161*e4b17023SJohn Marino   if (!gcov_open (filename, 1))
162*e4b17023SJohn Marino     {
163*e4b17023SJohn Marino       fprintf (stderr, "%s:cannot open\n", filename);
164*e4b17023SJohn Marino       return;
165*e4b17023SJohn Marino     }
166*e4b17023SJohn Marino 
167*e4b17023SJohn Marino   /* magic */
168*e4b17023SJohn Marino   {
169*e4b17023SJohn Marino     unsigned magic = gcov_read_unsigned ();
170*e4b17023SJohn Marino     unsigned version;
171*e4b17023SJohn Marino     const char *type = NULL;
172*e4b17023SJohn Marino     int endianness = 0;
173*e4b17023SJohn Marino     char m[4], v[4];
174*e4b17023SJohn Marino 
175*e4b17023SJohn Marino     if ((endianness = gcov_magic (magic, GCOV_DATA_MAGIC)))
176*e4b17023SJohn Marino       type = "data";
177*e4b17023SJohn Marino     else if ((endianness = gcov_magic (magic, GCOV_NOTE_MAGIC)))
178*e4b17023SJohn Marino       type = "note";
179*e4b17023SJohn Marino     else
180*e4b17023SJohn Marino       {
181*e4b17023SJohn Marino 	printf ("%s:not a gcov file\n", filename);
182*e4b17023SJohn Marino 	gcov_close ();
183*e4b17023SJohn Marino 	return;
184*e4b17023SJohn Marino       }
185*e4b17023SJohn Marino     version = gcov_read_unsigned ();
186*e4b17023SJohn Marino     GCOV_UNSIGNED2STRING (v, version);
187*e4b17023SJohn Marino     GCOV_UNSIGNED2STRING (m, magic);
188*e4b17023SJohn Marino 
189*e4b17023SJohn Marino     printf ("%s:%s:magic `%.4s':version `%.4s'%s\n", filename, type,
190*e4b17023SJohn Marino  	    m, v, endianness < 0 ? " (swapped endianness)" : "");
191*e4b17023SJohn Marino     if (version != GCOV_VERSION)
192*e4b17023SJohn Marino       {
193*e4b17023SJohn Marino 	char e[4];
194*e4b17023SJohn Marino 
195*e4b17023SJohn Marino 	GCOV_UNSIGNED2STRING (e, GCOV_VERSION);
196*e4b17023SJohn Marino 	printf ("%s:warning:current version is `%.4s'\n", filename, e);
197*e4b17023SJohn Marino       }
198*e4b17023SJohn Marino   }
199*e4b17023SJohn Marino 
200*e4b17023SJohn Marino   /* stamp */
201*e4b17023SJohn Marino   {
202*e4b17023SJohn Marino     unsigned stamp = gcov_read_unsigned ();
203*e4b17023SJohn Marino 
204*e4b17023SJohn Marino     printf ("%s:stamp %lu\n", filename, (unsigned long)stamp);
205*e4b17023SJohn Marino   }
206*e4b17023SJohn Marino 
207*e4b17023SJohn Marino   while (1)
208*e4b17023SJohn Marino     {
209*e4b17023SJohn Marino       gcov_position_t base, position = gcov_position ();
210*e4b17023SJohn Marino       unsigned tag, length;
211*e4b17023SJohn Marino       tag_format_t const *format;
212*e4b17023SJohn Marino       unsigned tag_depth;
213*e4b17023SJohn Marino       int error;
214*e4b17023SJohn Marino       unsigned mask;
215*e4b17023SJohn Marino 
216*e4b17023SJohn Marino       tag = gcov_read_unsigned ();
217*e4b17023SJohn Marino       if (!tag)
218*e4b17023SJohn Marino 	break;
219*e4b17023SJohn Marino       length = gcov_read_unsigned ();
220*e4b17023SJohn Marino       base = gcov_position ();
221*e4b17023SJohn Marino       mask = GCOV_TAG_MASK (tag) >> 1;
222*e4b17023SJohn Marino       for (tag_depth = 4; mask; mask >>= 8)
223*e4b17023SJohn Marino 	{
224*e4b17023SJohn Marino 	  if ((mask & 0xff) != 0xff)
225*e4b17023SJohn Marino 	    {
226*e4b17023SJohn Marino 	      printf ("%s:tag `%08x' is invalid\n", filename, tag);
227*e4b17023SJohn Marino 	      break;
228*e4b17023SJohn Marino 	    }
229*e4b17023SJohn Marino 	  tag_depth--;
230*e4b17023SJohn Marino 	}
231*e4b17023SJohn Marino       for (format = tag_table; format->name; format++)
232*e4b17023SJohn Marino 	if (format->tag == tag)
233*e4b17023SJohn Marino 	  goto found;
234*e4b17023SJohn Marino       format = &tag_table[GCOV_TAG_IS_COUNTER (tag) ? 2 : 1];
235*e4b17023SJohn Marino     found:;
236*e4b17023SJohn Marino       if (tag)
237*e4b17023SJohn Marino 	{
238*e4b17023SJohn Marino 	  if (depth && depth < tag_depth)
239*e4b17023SJohn Marino 	    {
240*e4b17023SJohn Marino 	      if (!GCOV_TAG_IS_SUBTAG (tags[depth - 1], tag))
241*e4b17023SJohn Marino 		printf ("%s:tag `%08x' is incorrectly nested\n",
242*e4b17023SJohn Marino 			filename, tag);
243*e4b17023SJohn Marino 	    }
244*e4b17023SJohn Marino 	  depth = tag_depth;
245*e4b17023SJohn Marino 	  tags[depth - 1] = tag;
246*e4b17023SJohn Marino 	}
247*e4b17023SJohn Marino 
248*e4b17023SJohn Marino       print_prefix (filename, tag_depth, position);
249*e4b17023SJohn Marino       printf ("%08x:%4u:%s", tag, length, format->name);
250*e4b17023SJohn Marino       if (format->proc)
251*e4b17023SJohn Marino 	(*format->proc) (filename, tag, length);
252*e4b17023SJohn Marino 
253*e4b17023SJohn Marino       printf ("\n");
254*e4b17023SJohn Marino       if (flag_dump_contents && format->proc)
255*e4b17023SJohn Marino 	{
256*e4b17023SJohn Marino 	  unsigned long actual_length = gcov_position () - base;
257*e4b17023SJohn Marino 
258*e4b17023SJohn Marino 	  if (actual_length > length)
259*e4b17023SJohn Marino 	    printf ("%s:record size mismatch %lu bytes overread\n",
260*e4b17023SJohn Marino 		    filename, actual_length - length);
261*e4b17023SJohn Marino 	  else if (length > actual_length)
262*e4b17023SJohn Marino 	    printf ("%s:record size mismatch %lu bytes unread\n",
263*e4b17023SJohn Marino 		    filename, length - actual_length);
264*e4b17023SJohn Marino 	}
265*e4b17023SJohn Marino       gcov_sync (base, length);
266*e4b17023SJohn Marino       if ((error = gcov_is_error ()))
267*e4b17023SJohn Marino 	{
268*e4b17023SJohn Marino 	  printf (error < 0 ? "%s:counter overflow at %lu\n" :
269*e4b17023SJohn Marino 		  "%s:read error at %lu\n", filename,
270*e4b17023SJohn Marino 		  (long unsigned) gcov_position ());
271*e4b17023SJohn Marino 	  break;
272*e4b17023SJohn Marino 	}
273*e4b17023SJohn Marino     }
274*e4b17023SJohn Marino   gcov_close ();
275*e4b17023SJohn Marino }
276*e4b17023SJohn Marino 
277*e4b17023SJohn Marino static void
tag_function(const char * filename ATTRIBUTE_UNUSED,unsigned tag ATTRIBUTE_UNUSED,unsigned length)278*e4b17023SJohn Marino tag_function (const char *filename ATTRIBUTE_UNUSED,
279*e4b17023SJohn Marino 	      unsigned tag ATTRIBUTE_UNUSED, unsigned length)
280*e4b17023SJohn Marino {
281*e4b17023SJohn Marino   unsigned long pos = gcov_position ();
282*e4b17023SJohn Marino 
283*e4b17023SJohn Marino   if (!length)
284*e4b17023SJohn Marino     printf (" placeholder");
285*e4b17023SJohn Marino   else
286*e4b17023SJohn Marino     {
287*e4b17023SJohn Marino       printf (" ident=%u", gcov_read_unsigned ());
288*e4b17023SJohn Marino       printf (", lineno_checksum=0x%08x", gcov_read_unsigned ());
289*e4b17023SJohn Marino       printf (", cfg_checksum=0x%08x", gcov_read_unsigned ());
290*e4b17023SJohn Marino 
291*e4b17023SJohn Marino       if (gcov_position () - pos < length)
292*e4b17023SJohn Marino 	{
293*e4b17023SJohn Marino 	  const char *name;
294*e4b17023SJohn Marino 
295*e4b17023SJohn Marino 	  name = gcov_read_string ();
296*e4b17023SJohn Marino 	  printf (", `%s'", name ? name : "NULL");
297*e4b17023SJohn Marino 	  name = gcov_read_string ();
298*e4b17023SJohn Marino 	  printf (" %s", name ? name : "NULL");
299*e4b17023SJohn Marino 	  printf (":%u", gcov_read_unsigned ());
300*e4b17023SJohn Marino 	}
301*e4b17023SJohn Marino     }
302*e4b17023SJohn Marino }
303*e4b17023SJohn Marino 
304*e4b17023SJohn Marino static void
tag_blocks(const char * filename ATTRIBUTE_UNUSED,unsigned tag ATTRIBUTE_UNUSED,unsigned length ATTRIBUTE_UNUSED)305*e4b17023SJohn Marino tag_blocks (const char *filename ATTRIBUTE_UNUSED,
306*e4b17023SJohn Marino 	    unsigned tag ATTRIBUTE_UNUSED, unsigned length ATTRIBUTE_UNUSED)
307*e4b17023SJohn Marino {
308*e4b17023SJohn Marino   unsigned n_blocks = GCOV_TAG_BLOCKS_NUM (length);
309*e4b17023SJohn Marino 
310*e4b17023SJohn Marino   printf (" %u blocks", n_blocks);
311*e4b17023SJohn Marino 
312*e4b17023SJohn Marino   if (flag_dump_contents)
313*e4b17023SJohn Marino     {
314*e4b17023SJohn Marino       unsigned ix;
315*e4b17023SJohn Marino 
316*e4b17023SJohn Marino       for (ix = 0; ix != n_blocks; ix++)
317*e4b17023SJohn Marino 	{
318*e4b17023SJohn Marino 	  if (!(ix & 7))
319*e4b17023SJohn Marino 	    {
320*e4b17023SJohn Marino 	      printf ("\n");
321*e4b17023SJohn Marino 	      print_prefix (filename, 0, gcov_position ());
322*e4b17023SJohn Marino 	      printf ("\t\t%u", ix);
323*e4b17023SJohn Marino 	    }
324*e4b17023SJohn Marino 	  printf (" %04x", gcov_read_unsigned ());
325*e4b17023SJohn Marino 	}
326*e4b17023SJohn Marino     }
327*e4b17023SJohn Marino }
328*e4b17023SJohn Marino 
329*e4b17023SJohn Marino static void
tag_arcs(const char * filename ATTRIBUTE_UNUSED,unsigned tag ATTRIBUTE_UNUSED,unsigned length ATTRIBUTE_UNUSED)330*e4b17023SJohn Marino tag_arcs (const char *filename ATTRIBUTE_UNUSED,
331*e4b17023SJohn Marino 	  unsigned tag ATTRIBUTE_UNUSED, unsigned length ATTRIBUTE_UNUSED)
332*e4b17023SJohn Marino {
333*e4b17023SJohn Marino   unsigned n_arcs = GCOV_TAG_ARCS_NUM (length);
334*e4b17023SJohn Marino 
335*e4b17023SJohn Marino   printf (" %u arcs", n_arcs);
336*e4b17023SJohn Marino   if (flag_dump_contents)
337*e4b17023SJohn Marino     {
338*e4b17023SJohn Marino       unsigned ix;
339*e4b17023SJohn Marino       unsigned blockno = gcov_read_unsigned ();
340*e4b17023SJohn Marino 
341*e4b17023SJohn Marino       for (ix = 0; ix != n_arcs; ix++)
342*e4b17023SJohn Marino 	{
343*e4b17023SJohn Marino 	  unsigned dst, flags;
344*e4b17023SJohn Marino 
345*e4b17023SJohn Marino 	  if (!(ix & 3))
346*e4b17023SJohn Marino 	    {
347*e4b17023SJohn Marino 	      printf ("\n");
348*e4b17023SJohn Marino 	      print_prefix (filename, 0, gcov_position ());
349*e4b17023SJohn Marino 	      printf ("\tblock %u:", blockno);
350*e4b17023SJohn Marino 	    }
351*e4b17023SJohn Marino 	  dst = gcov_read_unsigned ();
352*e4b17023SJohn Marino 	  flags = gcov_read_unsigned ();
353*e4b17023SJohn Marino 	  printf (" %u:%04x", dst, flags);
354*e4b17023SJohn Marino 	  if (flags)
355*e4b17023SJohn Marino 	    {
356*e4b17023SJohn Marino 	      char c = '(';
357*e4b17023SJohn Marino 
358*e4b17023SJohn Marino 	      if (flags & GCOV_ARC_ON_TREE)
359*e4b17023SJohn Marino 		printf ("%ctree", c), c = ',';
360*e4b17023SJohn Marino 	      if (flags & GCOV_ARC_FAKE)
361*e4b17023SJohn Marino 		printf ("%cfake", c), c = ',';
362*e4b17023SJohn Marino 	      if (flags & GCOV_ARC_FALLTHROUGH)
363*e4b17023SJohn Marino 		printf ("%cfall", c), c = ',';
364*e4b17023SJohn Marino 	      printf (")");
365*e4b17023SJohn Marino 	    }
366*e4b17023SJohn Marino 	}
367*e4b17023SJohn Marino     }
368*e4b17023SJohn Marino }
369*e4b17023SJohn Marino 
370*e4b17023SJohn Marino static void
tag_lines(const char * filename ATTRIBUTE_UNUSED,unsigned tag ATTRIBUTE_UNUSED,unsigned length ATTRIBUTE_UNUSED)371*e4b17023SJohn Marino tag_lines (const char *filename ATTRIBUTE_UNUSED,
372*e4b17023SJohn Marino 	   unsigned tag ATTRIBUTE_UNUSED, unsigned length ATTRIBUTE_UNUSED)
373*e4b17023SJohn Marino {
374*e4b17023SJohn Marino   if (flag_dump_contents)
375*e4b17023SJohn Marino     {
376*e4b17023SJohn Marino       unsigned blockno = gcov_read_unsigned ();
377*e4b17023SJohn Marino       char const *sep = NULL;
378*e4b17023SJohn Marino 
379*e4b17023SJohn Marino       while (1)
380*e4b17023SJohn Marino 	{
381*e4b17023SJohn Marino 	  gcov_position_t position = gcov_position ();
382*e4b17023SJohn Marino 	  const char *source = NULL;
383*e4b17023SJohn Marino 	  unsigned lineno = gcov_read_unsigned ();
384*e4b17023SJohn Marino 
385*e4b17023SJohn Marino 	  if (!lineno)
386*e4b17023SJohn Marino 	    {
387*e4b17023SJohn Marino 	      source = gcov_read_string ();
388*e4b17023SJohn Marino 	      if (!source)
389*e4b17023SJohn Marino 		break;
390*e4b17023SJohn Marino 	      sep = NULL;
391*e4b17023SJohn Marino 	    }
392*e4b17023SJohn Marino 
393*e4b17023SJohn Marino 	  if (!sep)
394*e4b17023SJohn Marino 	    {
395*e4b17023SJohn Marino 	      printf ("\n");
396*e4b17023SJohn Marino 	      print_prefix (filename, 0, position);
397*e4b17023SJohn Marino 	      printf ("\tblock %u:", blockno);
398*e4b17023SJohn Marino 	      sep = "";
399*e4b17023SJohn Marino 	    }
400*e4b17023SJohn Marino 	  if (lineno)
401*e4b17023SJohn Marino 	    {
402*e4b17023SJohn Marino 	      printf ("%s%u", sep, lineno);
403*e4b17023SJohn Marino 	      sep = ", ";
404*e4b17023SJohn Marino 	    }
405*e4b17023SJohn Marino 	  else
406*e4b17023SJohn Marino 	    {
407*e4b17023SJohn Marino 	      printf ("%s`%s'", sep, source);
408*e4b17023SJohn Marino 	      sep = ":";
409*e4b17023SJohn Marino 	    }
410*e4b17023SJohn Marino 	}
411*e4b17023SJohn Marino     }
412*e4b17023SJohn Marino }
413*e4b17023SJohn Marino 
414*e4b17023SJohn Marino static void
tag_counters(const char * filename ATTRIBUTE_UNUSED,unsigned tag ATTRIBUTE_UNUSED,unsigned length ATTRIBUTE_UNUSED)415*e4b17023SJohn Marino tag_counters (const char *filename ATTRIBUTE_UNUSED,
416*e4b17023SJohn Marino 	      unsigned tag ATTRIBUTE_UNUSED, unsigned length ATTRIBUTE_UNUSED)
417*e4b17023SJohn Marino {
418*e4b17023SJohn Marino   static const char *const counter_names[] = GCOV_COUNTER_NAMES;
419*e4b17023SJohn Marino   unsigned n_counts = GCOV_TAG_COUNTER_NUM (length);
420*e4b17023SJohn Marino 
421*e4b17023SJohn Marino   printf (" %s %u counts",
422*e4b17023SJohn Marino 	  counter_names[GCOV_COUNTER_FOR_TAG (tag)], n_counts);
423*e4b17023SJohn Marino   if (flag_dump_contents)
424*e4b17023SJohn Marino     {
425*e4b17023SJohn Marino       unsigned ix;
426*e4b17023SJohn Marino 
427*e4b17023SJohn Marino       for (ix = 0; ix != n_counts; ix++)
428*e4b17023SJohn Marino 	{
429*e4b17023SJohn Marino 	  gcov_type count;
430*e4b17023SJohn Marino 
431*e4b17023SJohn Marino 	  if (!(ix & 7))
432*e4b17023SJohn Marino 	    {
433*e4b17023SJohn Marino 	      printf ("\n");
434*e4b17023SJohn Marino 	      print_prefix (filename, 0, gcov_position ());
435*e4b17023SJohn Marino 	      printf ("\t\t%u", ix);
436*e4b17023SJohn Marino 	    }
437*e4b17023SJohn Marino 
438*e4b17023SJohn Marino 	  count = gcov_read_counter ();
439*e4b17023SJohn Marino 	  printf (" ");
440*e4b17023SJohn Marino 	  printf (HOST_WIDEST_INT_PRINT_DEC, count);
441*e4b17023SJohn Marino 	}
442*e4b17023SJohn Marino     }
443*e4b17023SJohn Marino }
444*e4b17023SJohn Marino 
445*e4b17023SJohn Marino static void
tag_summary(const char * filename ATTRIBUTE_UNUSED,unsigned tag ATTRIBUTE_UNUSED,unsigned length ATTRIBUTE_UNUSED)446*e4b17023SJohn Marino tag_summary (const char *filename ATTRIBUTE_UNUSED,
447*e4b17023SJohn Marino 	     unsigned tag ATTRIBUTE_UNUSED, unsigned length ATTRIBUTE_UNUSED)
448*e4b17023SJohn Marino {
449*e4b17023SJohn Marino   struct gcov_summary summary;
450*e4b17023SJohn Marino   unsigned ix;
451*e4b17023SJohn Marino 
452*e4b17023SJohn Marino   gcov_read_summary (&summary);
453*e4b17023SJohn Marino   printf (" checksum=0x%08x", summary.checksum);
454*e4b17023SJohn Marino 
455*e4b17023SJohn Marino   for (ix = 0; ix != GCOV_COUNTERS_SUMMABLE; ix++)
456*e4b17023SJohn Marino     {
457*e4b17023SJohn Marino       printf ("\n");
458*e4b17023SJohn Marino       print_prefix (filename, 0, 0);
459*e4b17023SJohn Marino       printf ("\t\tcounts=%u, runs=%u",
460*e4b17023SJohn Marino 	      summary.ctrs[ix].num, summary.ctrs[ix].runs);
461*e4b17023SJohn Marino 
462*e4b17023SJohn Marino       printf (", sum_all=" HOST_WIDEST_INT_PRINT_DEC,
463*e4b17023SJohn Marino 	      (HOST_WIDEST_INT)summary.ctrs[ix].sum_all);
464*e4b17023SJohn Marino       printf (", run_max=" HOST_WIDEST_INT_PRINT_DEC,
465*e4b17023SJohn Marino 	      (HOST_WIDEST_INT)summary.ctrs[ix].run_max);
466*e4b17023SJohn Marino       printf (", sum_max=" HOST_WIDEST_INT_PRINT_DEC,
467*e4b17023SJohn Marino 	      (HOST_WIDEST_INT)summary.ctrs[ix].sum_max);
468*e4b17023SJohn Marino     }
469*e4b17023SJohn Marino }
470