Commit 7d63a2fa by Nathan Sidwell Committed by Nathan Sidwell

gcov-io.h (gcov_write_bytes, [...]): Remove here.

	* gcov-io.h (gcov_write_bytes, gcov_read_bytes): Remove here.
	(GCOV_TAG_*) Force type to gcov_unsigned_t.
	(GCOV_CHECK, GCOV_CHECK_READING, GCOV_CHECK_WRITING): New.
	(struct gcov_var): Remove modified. Add start, length, offset,
	overread. Have buffer array for libgcov.
	(gcov_sync, gcov_seek): Definitions moved to gcov-io.c.
	(gcov_position, gcov_rewrite, gcov_is_eof): Adjust.
	* gcov-io.c (gcov_open): Set mode, do not read anything.
	(gcov_close): Write final block.
	 (gcov_write_block, gcov_allocate): New.
	(gcov_write_bytes): Make static. Write or allocate buffer.
	(gcov_write_unsigned, gcov_write_counter): Buffer can never be
	null.
	(gcov_write_string): Adjust.
	(gcov_write_tag)
	(gcov_write_length): Adjust. Flush the block.
	(gcov_write_tag_length): Buffer can never be null.
	(gcov_read_bytes): Make static. Read in block.
	(gcov_sync): Moved here. Adjust.
	(gcov_seek): Moved here. Adjust.
	* coverage.c (read_counts_file): Adjust.
	* gcov-dump.c (print_prefix): Add position parameter.
	(flag_dump_positions): New flag.
	(options, main, print_usage): Add it.
	(dump_file, tag_blocks, tag_arcs, tag_lines, tag_counters,
	tag_summary): Adjust.
	* gcov.c (read_graph_file, read_count_file): Adjust.
	* libgcov.c (gcov_exit): Adjust.

From-SVN: r66805
parent 990f4800
2003-05-14 Nathan Sidwell <nathan@codesourcery.com> 2003-05-14 Nathan Sidwell <nathan@codesourcery.com>
* gcov-io.h (gcov_write_bytes, gcov_read_bytes): Remove here.
(GCOV_TAG_*) Force type to gcov_unsigned_t.
(GCOV_CHECK, GCOV_CHECK_READING, GCOV_CHECK_WRITING): New.
(struct gcov_var): Remove modified. Add start, length, offset,
overread. Have buffer array for libgcov.
(gcov_sync, gcov_seek): Definitions moved to gcov-io.c.
(gcov_position, gcov_rewrite, gcov_is_eof): Adjust.
* gcov-io.c (gcov_open): Set mode, do not read anything.
(gcov_close): Write final block.
(gcov_write_block, gcov_allocate): New.
(gcov_write_bytes): Make static. Write or allocate buffer.
(gcov_write_unsigned, gcov_write_counter): Buffer can never be
null.
(gcov_write_string): Adjust.
(gcov_write_tag)
(gcov_write_length): Adjust. Flush the block.
(gcov_write_tag_length): Buffer can never be null.
(gcov_read_bytes): Make static. Read in block.
(gcov_sync): Moved here. Adjust.
(gcov_seek): Moved here. Adjust.
* coverage.c (read_counts_file): Adjust.
* gcov-dump.c (print_prefix): Add position parameter.
(flag_dump_positions): New flag.
(options, main, print_usage): Add it.
(dump_file, tag_blocks, tag_arcs, tag_lines, tag_counters,
tag_summary): Adjust.
* gcov.c (read_graph_file, read_count_file): Adjust.
* libgcov.c (gcov_exit): Adjust.
* Makefile.in (LIBGCC_DEPS): Use $(srcdir) on gcov files * Makefile.in (LIBGCC_DEPS): Use $(srcdir) on gcov files
(libgcov.a): Depend on libgcc.a. (libgcov.a): Depend on libgcc.a.
(gcov.o, gcov-dump.o): Add gcov-io.c. (gcov.o, gcov-dump.o): Add gcov-io.c.
......
...@@ -158,7 +158,9 @@ read_counts_file () ...@@ -158,7 +158,9 @@ read_counts_file ()
unsigned ix; unsigned ix;
counts_entry_t *summaried = NULL; counts_entry_t *summaried = NULL;
unsigned seen_summary = 0; unsigned seen_summary = 0;
gcov_unsigned_t tag;
int error = 0;
if (!gcov_open (da_file_name, 1)) if (!gcov_open (da_file_name, 1))
return; return;
...@@ -187,13 +189,11 @@ read_counts_file () ...@@ -187,13 +189,11 @@ read_counts_file ()
counts_hash = htab_create (10, counts_hash = htab_create (10,
htab_counts_entry_hash, htab_counts_entry_eq, htab_counts_entry_hash, htab_counts_entry_eq,
htab_counts_entry_del); htab_counts_entry_del);
while (!gcov_is_eof ()) while ((tag = gcov_read_unsigned ()))
{ {
gcov_unsigned_t tag, length; gcov_unsigned_t length;
gcov_position_t offset; gcov_position_t offset;
int error;
tag = gcov_read_unsigned ();
length = gcov_read_unsigned (); length = gcov_read_unsigned ();
offset = gcov_position (); offset = gcov_position ();
if (tag == GCOV_TAG_FUNCTION) if (tag == GCOV_TAG_FUNCTION)
...@@ -284,14 +284,16 @@ read_counts_file () ...@@ -284,14 +284,16 @@ read_counts_file ()
} }
gcov_sync (offset, length); gcov_sync (offset, length);
if ((error = gcov_is_error ())) if ((error = gcov_is_error ()))
{ break;
warning (error < 0 ? "`%s' has overflowed" : "`%s' is corrupted",
da_file_name);
htab_delete (counts_hash);
break;
}
} }
if (!gcov_is_eof ())
{
warning (error < 0 ? "`%s' has overflowed" : "`%s' is corrupted",
da_file_name);
htab_delete (counts_hash);
}
gcov_close (); gcov_close ();
} }
......
...@@ -28,7 +28,7 @@ Boston, MA 02111-1307, USA. */ ...@@ -28,7 +28,7 @@ Boston, MA 02111-1307, USA. */
#include "gcov-io.c" #include "gcov-io.c"
static void dump_file PARAMS ((const char *)); static void dump_file PARAMS ((const char *));
static void print_prefix PARAMS ((const char *, unsigned)); static void print_prefix PARAMS ((const char *, unsigned, gcov_position_t));
static void print_usage PARAMS ((void)); static void print_usage PARAMS ((void));
static void print_version PARAMS ((void)); static void print_version PARAMS ((void));
static void tag_function PARAMS ((const char *, unsigned, unsigned)); static void tag_function PARAMS ((const char *, unsigned, unsigned));
...@@ -47,12 +47,14 @@ typedef struct tag_format ...@@ -47,12 +47,14 @@ typedef struct tag_format
} tag_format_t; } tag_format_t;
static int flag_dump_contents = 0; static int flag_dump_contents = 0;
static int flag_dump_positions = 0;
static const struct option options[] = static const struct option options[] =
{ {
{ "help", no_argument, NULL, 'h' }, { "help", no_argument, NULL, 'h' },
{ "version", no_argument, NULL, 'v' }, { "version", no_argument, NULL, 'v' },
{ "long", no_argument, NULL, 'l' }, { "long", no_argument, NULL, 'l' },
{ "positions", no_argument, NULL, 'o' },
}; };
static const tag_format_t tag_table[] = static const tag_format_t tag_table[] =
...@@ -75,7 +77,7 @@ int main (argc, argv) ...@@ -75,7 +77,7 @@ int main (argc, argv)
{ {
int opt; int opt;
while ((opt = getopt_long (argc, argv, "hlv", options, NULL)) != -1) while ((opt = getopt_long (argc, argv, "hlpv", options, NULL)) != -1)
{ {
switch (opt) switch (opt)
{ {
...@@ -88,6 +90,9 @@ int main (argc, argv) ...@@ -88,6 +90,9 @@ int main (argc, argv)
case 'l': case 'l':
flag_dump_contents = 1; flag_dump_contents = 1;
break; break;
case 'p':
flag_dump_positions = 1;
break;
default: default:
fprintf (stderr, "unknown flag `%c'\n", opt); fprintf (stderr, "unknown flag `%c'\n", opt);
} }
...@@ -106,6 +111,7 @@ print_usage () ...@@ -106,6 +111,7 @@ print_usage ()
printf (" -h, --help Print this help\n"); printf (" -h, --help Print this help\n");
printf (" -v, --version Print version number\n"); printf (" -v, --version Print version number\n");
printf (" -l, --long Dump record contents too\n"); printf (" -l, --long Dump record contents too\n");
printf (" -p, --positions Dump record positions\n");
} }
static void static void
...@@ -124,13 +130,17 @@ warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.\n\n" ...@@ -124,13 +130,17 @@ warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.\n\n"
} }
static void static void
print_prefix (filename, depth) print_prefix (filename, depth, position)
const char *filename; const char *filename;
unsigned depth; unsigned depth;
gcov_position_t position;
{ {
static const char prefix[] = " "; static const char prefix[] = " ";
printf ("%s:%.*s", filename, (int) depth, prefix); printf ("%s:", filename);
if (flag_dump_positions)
printf ("%lu:", (unsigned long) position);
printf ("%.*s", (int) depth, prefix);
} }
static void static void
...@@ -178,30 +188,29 @@ dump_file (filename) ...@@ -178,30 +188,29 @@ dump_file (filename)
printf ("%s:warning:current version is `%.4s'\n", filename, e); printf ("%s:warning:current version is `%.4s'\n", filename, e);
} }
while (!gcov_is_eof ()) while (1)
{ {
unsigned tag = gcov_read_unsigned (); gcov_position_t base, position = gcov_position ();
unsigned length = gcov_read_unsigned (); unsigned tag, length;
unsigned long base = gcov_position ();
tag_format_t const *format; tag_format_t const *format;
unsigned tag_depth; unsigned tag_depth;
int error; int error;
unsigned mask;
tag = gcov_read_unsigned ();
if (!tag) if (!tag)
tag_depth = depth; break;
else length = gcov_read_unsigned ();
base = gcov_position ();
mask = GCOV_TAG_MASK (tag) >> 1;
for (tag_depth = 4; mask; mask >>= 8)
{ {
unsigned mask = GCOV_TAG_MASK (tag) >> 1; if ((mask & 0xff) != 0xff)
for (tag_depth = 4; mask; mask >>= 8)
{ {
if ((mask & 0xff) != 0xff) printf ("%s:tag `%08x' is invalid\n", filename, tag);
{ break;
printf ("%s:tag `%08x' is invalid\n", filename, tag);
break;
}
tag_depth--;
} }
tag_depth--;
} }
for (format = tag_table; format->name; format++) for (format = tag_table; format->name; format++)
if (format->tag == tag) if (format->tag == tag)
...@@ -220,7 +229,7 @@ dump_file (filename) ...@@ -220,7 +229,7 @@ dump_file (filename)
tags[depth - 1] = tag; tags[depth - 1] = tag;
} }
print_prefix (filename, tag_depth); print_prefix (filename, tag_depth, position);
printf ("%08x:%4u:%s", tag, length, format->name); printf ("%08x:%4u:%s", tag, length, format->name);
if (format->proc) if (format->proc)
(*format->proc) (filename, tag, length); (*format->proc) (filename, tag, length);
...@@ -246,6 +255,8 @@ dump_file (filename) ...@@ -246,6 +255,8 @@ dump_file (filename)
break; break;
} }
} }
if (!gcov_is_eof ())
printf ("%s:early end of file\n", filename);
gcov_close (); gcov_close ();
} }
...@@ -289,7 +300,11 @@ tag_blocks (filename, tag, length) ...@@ -289,7 +300,11 @@ tag_blocks (filename, tag, length)
for (ix = 0; ix != n_blocks; ix++) for (ix = 0; ix != n_blocks; ix++)
{ {
if (!(ix & 7)) if (!(ix & 7))
printf ("\n%s:\t\t%u", filename, ix); {
printf ("\n");
print_prefix (filename, 0, gcov_position ());
printf ("\t\t%u", ix);
}
printf (" %04x", gcov_read_unsigned ()); printf (" %04x", gcov_read_unsigned ());
} }
} }
...@@ -311,11 +326,16 @@ tag_arcs (filename, tag, length) ...@@ -311,11 +326,16 @@ tag_arcs (filename, tag, length)
for (ix = 0; ix != n_arcs; ix++) for (ix = 0; ix != n_arcs; ix++)
{ {
unsigned dst = gcov_read_unsigned (); unsigned dst, flags;
unsigned flags = gcov_read_unsigned ();
if (!(ix & 3)) if (!(ix & 3))
printf ("\n%s:\tblock %u:", filename, blockno); {
printf ("\n");
print_prefix (filename, 0, gcov_position ());
printf ("\tblock %u:", blockno);
}
dst = gcov_read_unsigned ();
flags = gcov_read_unsigned ();
printf (" %u:%04x", dst, flags); printf (" %u:%04x", dst, flags);
} }
} }
...@@ -334,6 +354,7 @@ tag_lines (filename, tag, length) ...@@ -334,6 +354,7 @@ tag_lines (filename, tag, length)
while (1) while (1)
{ {
gcov_position_t position = gcov_position ();
const char *source = NULL; const char *source = NULL;
unsigned lineno = gcov_read_unsigned (); unsigned lineno = gcov_read_unsigned ();
...@@ -347,7 +368,9 @@ tag_lines (filename, tag, length) ...@@ -347,7 +368,9 @@ tag_lines (filename, tag, length)
if (!sep) if (!sep)
{ {
printf ("\n%s:\tblock %u:", filename, blockno); printf ("\n");
print_prefix (filename, 0, position);
printf ("\tblock %u:", blockno);
sep = ""; sep = "";
} }
if (lineno) if (lineno)
...@@ -381,10 +404,16 @@ tag_counters (filename, tag, length) ...@@ -381,10 +404,16 @@ tag_counters (filename, tag, length)
for (ix = 0; ix != n_counts; ix++) for (ix = 0; ix != n_counts; ix++)
{ {
gcov_type count = gcov_read_counter (); gcov_type count;
if (!(ix & 7)) if (!(ix & 7))
printf ("\n%s:\t\t%u", filename, ix); {
printf ("\n");
print_prefix (filename, 0, gcov_position ());
printf ("\t\t%u", ix);
}
count = gcov_read_counter ();
printf (" "); printf (" ");
printf (HOST_WIDEST_INT_PRINT_DEC, count); printf (HOST_WIDEST_INT_PRINT_DEC, count);
} }
...@@ -405,7 +434,9 @@ tag_summary (filename, tag, length) ...@@ -405,7 +434,9 @@ tag_summary (filename, tag, length)
for (ix = 0; ix != GCOV_COUNTERS; ix++) for (ix = 0; ix != GCOV_COUNTERS; ix++)
{ {
printf ("\n%sL\t\tcounts=%u, runs=%u", filename, printf ("\n");
print_prefix (filename, 0, 0);
printf ("\t\tcounts=%u, runs=%u",
summary.ctrs[ix].num, summary.ctrs[ix].runs); summary.ctrs[ix].num, summary.ctrs[ix].runs);
printf (", sum_all=" HOST_WIDEST_INT_PRINT_DEC, printf (", sum_all=" HOST_WIDEST_INT_PRINT_DEC,
......
...@@ -711,7 +711,8 @@ read_graph_file () ...@@ -711,7 +711,8 @@ read_graph_file ()
struct function_info *fn = NULL; struct function_info *fn = NULL;
source_t *src = NULL; source_t *src = NULL;
unsigned ix; unsigned ix;
unsigned tag;
if (!gcov_open (bbg_file_name, 1)) if (!gcov_open (bbg_file_name, 1))
{ {
fnotice (stderr, "%s:cannot open graph file\n", bbg_file_name); fnotice (stderr, "%s:cannot open graph file\n", bbg_file_name);
...@@ -740,11 +741,10 @@ read_graph_file () ...@@ -740,11 +741,10 @@ read_graph_file ()
bbg_file_name, v, e); bbg_file_name, v, e);
} }
while (!gcov_is_eof ()) while ((tag = gcov_read_unsigned ()))
{ {
unsigned tag = gcov_read_unsigned ();
unsigned length = gcov_read_unsigned (); unsigned length = gcov_read_unsigned ();
unsigned long base = gcov_position (); gcov_position_t base = gcov_position ();
if (tag == GCOV_TAG_FUNCTION) if (tag == GCOV_TAG_FUNCTION)
{ {
...@@ -906,12 +906,14 @@ read_graph_file () ...@@ -906,12 +906,14 @@ read_graph_file ()
} }
gcov_sync (base, length); gcov_sync (base, length);
if (gcov_is_error ()) if (gcov_is_error ())
{ break;
corrupt:; }
fnotice (stderr, "%s:corrupted\n", bbg_file_name); if (!gcov_is_eof ())
gcov_close (); {
return 1; corrupt:;
} fnotice (stderr, "%s:corrupted\n", bbg_file_name);
gcov_close ();
return 1;
} }
gcov_close (); gcov_close ();
...@@ -976,7 +978,9 @@ read_count_file () ...@@ -976,7 +978,9 @@ read_count_file ()
{ {
unsigned ix; unsigned ix;
unsigned version; unsigned version;
unsigned tag;
function_t *fn = NULL; function_t *fn = NULL;
int error = 0;
if (!gcov_open (da_file_name, 1)) if (!gcov_open (da_file_name, 1))
{ {
...@@ -1005,12 +1009,10 @@ read_count_file () ...@@ -1005,12 +1009,10 @@ read_count_file ()
da_file_name, v, e); da_file_name, v, e);
} }
while (!gcov_is_eof ()) while ((tag = gcov_read_unsigned ()))
{ {
unsigned tag = gcov_read_unsigned ();
unsigned length = gcov_read_unsigned (); unsigned length = gcov_read_unsigned ();
unsigned long base = gcov_position (); unsigned long base = gcov_position ();
int error;
if (tag == GCOV_TAG_OBJECT_SUMMARY) if (tag == GCOV_TAG_OBJECT_SUMMARY)
gcov_read_summary (&object_summary); gcov_read_summary (&object_summary);
...@@ -1061,13 +1063,16 @@ read_count_file () ...@@ -1061,13 +1063,16 @@ read_count_file ()
} }
gcov_sync (base, length); gcov_sync (base, length);
if ((error = gcov_is_error ())) if ((error = gcov_is_error ()))
{ break;
fnotice (stderr, error < 0
? "%s:overflowed\n" : "%s:corrupted\n", da_file_name);
goto cleanup;
}
} }
if (!gcov_is_eof ())
{
fnotice (stderr, error < 0 ? "%s:overflowed\n" : "%s:corrupted\n",
da_file_name);
goto cleanup;
}
gcov_close (); gcov_close ();
return 0; return 0;
} }
......
...@@ -152,10 +152,10 @@ gcov_exit (void) ...@@ -152,10 +152,10 @@ gcov_exit (void)
const struct gcov_ctr_info *ci_ptr; const struct gcov_ctr_info *ci_ptr;
struct gcov_ctr_summary *cs_ptr; struct gcov_ctr_summary *cs_ptr;
struct gcov_ctr_summary *cs_obj, *cs_tobj, *cs_prg, *cs_tprg, *cs_all; struct gcov_ctr_summary *cs_obj, *cs_tobj, *cs_prg, *cs_tprg, *cs_all;
int error; int error = 0;
int merging; int merging;
gcov_unsigned_t tag, length; gcov_unsigned_t tag, length;
gcov_position_t summary_pos = ~(gcov_position_t)0; gcov_position_t summary_pos = 0;
/* Totals for this object file. */ /* Totals for this object file. */
memset (&this_object, 0, sizeof (this_object)); memset (&this_object, 0, sizeof (this_object));
...@@ -256,12 +256,14 @@ gcov_exit (void) ...@@ -256,12 +256,14 @@ gcov_exit (void)
} }
/* Check program & object summary */ /* Check program & object summary */
while (!gcov_is_eof ()) while (1)
{ {
gcov_position_t base = gcov_position (); gcov_position_t base = gcov_position ();
int is_program; int is_program;
tag = gcov_read_unsigned (); tag = gcov_read_unsigned ();
if (!tag)
break;
length = gcov_read_unsigned (); length = gcov_read_unsigned ();
is_program = tag == GCOV_TAG_PROGRAM_SUMMARY; is_program = tag == GCOV_TAG_PROGRAM_SUMMARY;
if (length != GCOV_TAG_SUMMARY_LENGTH if (length != GCOV_TAG_SUMMARY_LENGTH
...@@ -269,24 +271,26 @@ gcov_exit (void) ...@@ -269,24 +271,26 @@ gcov_exit (void)
goto read_mismatch; goto read_mismatch;
gcov_read_summary (is_program ? &program : &object); gcov_read_summary (is_program ? &program : &object);
if ((error = gcov_is_error ())) if ((error = gcov_is_error ()))
goto read_error;
if (is_program && program.checksum == gcov_crc32)
{ {
read_error:; summary_pos = base;
fprintf (stderr, error < 0 ? goto rewrite;
"profiling:%s:Overflow merging\n" :
"profiling:%s:Error merging\n", gi_ptr->filename);
goto read_fatal;
} }
if (!is_program || program.checksum != gcov_crc32)
continue;
summary_pos = base;
break;
} }
if (!gcov_is_eof ())
{
read_error:;
fprintf (stderr, error < 0 ? "profiling:%s:Overflow merging\n"
: "profiling:%s:Error merging\n", gi_ptr->filename);
goto read_fatal;
}
rewrite:;
gcov_rewrite (); gcov_rewrite ();
} }
else else
memset (&object, 0, sizeof (object)); memset (&object, 0, sizeof (object));
if (!(summary_pos + 1)) if (!summary_pos)
memset (&program, 0, sizeof (program)); memset (&program, 0, sizeof (program));
/* Merge the summaries. */ /* Merge the summaries. */
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment