Commit 546d2adb by Nathan Sidwell Committed by Nathan Sidwell

Change gcov file interface to single file at a time.

	* gcov-io.h: Replace IN_LIBGCC1 with IN_LIBGCOV. Use IN_GCOV.
	Convert to C89 prototypes.
	(gcov_file, gcov_length, gcov_position, gcov_buffer, gcov_alloc,
	gcov_error, gcov_modified): New static variables.
	(gcov_open, gcov_close, gcov_read_bytes, gcov_write_bytes): New
	functions.
	(gcov_write_unsigned, gcov_write_counter, gcov_write_string,
	gcov_read_unsigned, gcov_read_counter, gcov_read_string): Adjust.
	(gcov_read_summary, gcov_write_summary): Adjust.
	(gcov_save_position, gcov_reserve_length, gcov_write_length):
	Adjust.
	(gcov_resync, gcov_skip, gcov_skip_string): Adjust.
	(da_file_open, da_file_close, da_file_eof, da_file_error): Remove.
	(da_file_position, da_file_seek, da_file_write, da_file_read):
	Remove.
	(gcov_error, gcov_eof, gcov_ok, gcov_time): New functions.
	* gcov.c (gcov_type): Don't typedef here.
	(IN_GCOV): #define
	(read_graph_file, read_count_file): Adjust.
	* gcov-dump.c (gcov_type): Don't typedef here.
	(IN_GCOV): #define.
	(tag_function, tag_blocks, tag_arcs, tag_lines, tag_arc_counts):
	Remove FILE parameter, adjust.
	(struct tag_format): Adjust proc member.
	(dump_file): Adjust.
	* libgcov.c (IN_LIBGCOV): #define.
	(gcov_exit): Adjust.
	* loop-init.c: Don't #include gcov-io.h
	* profile.c (struct counts_entry): New structure to hold counter
	values.
	(struct section_reference, struct da_index_entry): Remove.
	(bbg_file, da_file): Remove.
	(htab_counts_index_hash, htab_counts_index_eq,
	htab_counts_index_del): Replace with ...
	(htab_counts_entry_hash, htab_counts_entry_eq,
	htab_counts_entry_del): ... these.
	(cleanup_counts_index, index_counts_file): Remove.
	(read_counts_file): New function.
	(get_exec_counts): Adjust.
	(compute_branch_probabilities): Don't free the exec counts here.
	(branch_prob): Adjust.
	(init_branch_prob): Adjust.
	(end_branch_prob): Adjust.

From-SVN: r65338
parent 5da702b1
2003-04-07 Nathan Sidwell <nathan@codesourcery.com>
Change gcov file interface to single file at a time.
* gcov-io.h: Replace IN_LIBGCC1 with IN_LIBGCOV. Use IN_GCOV.
Convert to C89 prototypes.
(gcov_file, gcov_length, gcov_position, gcov_buffer, gcov_alloc,
gcov_error, gcov_modified): New static variables.
(gcov_open, gcov_close, gcov_read_bytes, gcov_write_bytes): New
functions.
(gcov_write_unsigned, gcov_write_counter, gcov_write_string,
gcov_read_unsigned, gcov_read_counter, gcov_read_string): Adjust.
(gcov_read_summary, gcov_write_summary): Adjust.
(gcov_save_position, gcov_reserve_length, gcov_write_length):
Adjust.
(gcov_resync, gcov_skip, gcov_skip_string): Adjust.
(da_file_open, da_file_close, da_file_eof, da_file_error): Remove.
(da_file_position, da_file_seek, da_file_write, da_file_read):
Remove.
(gcov_error, gcov_eof, gcov_ok, gcov_time): New functions.
* gcov.c (gcov_type): Don't typedef here.
(IN_GCOV): #define
(read_graph_file, read_count_file): Adjust.
* gcov-dump.c (gcov_type): Don't typedef here.
(IN_GCOV): #define.
(tag_function, tag_blocks, tag_arcs, tag_lines, tag_arc_counts):
Remove FILE parameter, adjust.
(struct tag_format): Adjust proc member.
(dump_file): Adjust.
* libgcov.c (IN_LIBGCOV): #define.
(gcov_exit): Adjust.
* loop-init.c: Don't #include gcov-io.h
* profile.c (struct counts_entry): New structure to hold counter
values.
(struct section_reference, struct da_index_entry): Remove.
(bbg_file, da_file): Remove.
(htab_counts_index_hash, htab_counts_index_eq,
htab_counts_index_del): Replace with ...
(htab_counts_entry_hash, htab_counts_entry_eq,
htab_counts_entry_del): ... these.
(cleanup_counts_index, index_counts_file): Remove.
(read_counts_file): New function.
(get_exec_counts): Adjust.
(compute_branch_probabilities): Don't free the exec counts here.
(branch_prob): Adjust.
(init_branch_prob): Adjust.
(end_branch_prob): Adjust.
2003-04-07 Aldy Hernandez <aldyh@redhat.com> 2003-04-07 Aldy Hernandez <aldyh@redhat.com>
* doc/invoke.texi (RS/6000 and PowerPC Options): Document * doc/invoke.texi (RS/6000 and PowerPC Options): Document
......
...@@ -23,26 +23,26 @@ Boston, MA 02111-1307, USA. */ ...@@ -23,26 +23,26 @@ Boston, MA 02111-1307, USA. */
#include "tm.h" #include "tm.h"
#include "version.h" #include "version.h"
#include <getopt.h> #include <getopt.h>
typedef HOST_WIDEST_INT gcov_type; #define IN_GCOV (-1)
#include "gcov-io.h" #include "gcov-io.h"
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));
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 int tag_function PARAMS ((const char *, FILE *, unsigned, unsigned)); static int tag_function PARAMS ((const char *, unsigned, unsigned));
static int tag_blocks PARAMS ((const char *, FILE *, unsigned, unsigned)); static int tag_blocks PARAMS ((const char *, unsigned, unsigned));
static int tag_arcs PARAMS ((const char *, FILE *, unsigned, unsigned)); static int tag_arcs PARAMS ((const char *, unsigned, unsigned));
static int tag_lines PARAMS ((const char *, FILE *, unsigned, unsigned)); static int tag_lines PARAMS ((const char *, unsigned, unsigned));
static int tag_arc_counts PARAMS ((const char *, FILE *, unsigned, unsigned)); static int tag_arc_counts PARAMS ((const char *, unsigned, unsigned));
static int tag_summary PARAMS ((const char *, FILE *, unsigned, unsigned)); static int tag_summary PARAMS ((const char *, unsigned, unsigned));
extern int main PARAMS ((int, char **)); extern int main PARAMS ((int, char **));
typedef struct tag_format typedef struct tag_format
{ {
unsigned tag; unsigned tag;
char const *name; char const *name;
int (*proc) (const char *, FILE *, unsigned, unsigned); int (*proc) (const char *, unsigned, unsigned);
} tag_format_t; } tag_format_t;
static int flag_dump_contents = 0; static int flag_dump_contents = 0;
...@@ -138,24 +138,22 @@ static void ...@@ -138,24 +138,22 @@ static void
dump_file (filename) dump_file (filename)
const char *filename; const char *filename;
{ {
FILE *file = fopen (filename, "rb");
unsigned tags[4]; unsigned tags[4];
unsigned depth = 0; unsigned depth = 0;
unsigned magic, version; unsigned magic, version;
unsigned tag, length; unsigned tag, length;
if (!file) if (!gcov_open (filename, 1))
{ {
fprintf (stderr, "%s:cannot open\n", filename); fprintf (stderr, "%s:cannot open\n", filename);
return; return;
} }
if (gcov_read_unsigned (file, &magic) if (gcov_read_unsigned (&magic) || gcov_read_unsigned (&version))
|| gcov_read_unsigned (file, &version))
{ {
read_error:; read_error:;
printf ("%s:read error at %ld\n", filename, ftell (file)); printf ("%s:read error at %lu\n", filename, gcov_save_position ());
fclose (file); gcov_close ();
return; return;
} }
...@@ -174,7 +172,7 @@ dump_file (filename) ...@@ -174,7 +172,7 @@ dump_file (filename)
else else
{ {
printf ("%s:not a gcov file\n", filename); printf ("%s:not a gcov file\n", filename);
fclose (file); gcov_close ();
return; return;
} }
for (ix = 4; ix--; expected >>= 8, version >>= 8, magic >>= 8) for (ix = 4; ix--; expected >>= 8, version >>= 8, magic >>= 8)
...@@ -189,14 +187,13 @@ dump_file (filename) ...@@ -189,14 +187,13 @@ 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_read_unsigned (file, &tag) while (!gcov_read_unsigned (&tag) && !gcov_read_unsigned (&length))
&& !gcov_read_unsigned (file, &length))
{ {
tag_format_t const *format; tag_format_t const *format;
unsigned tag_depth; unsigned tag_depth;
long base, end; long base, end;
base = gcov_save_position (file); base = gcov_save_position ();
if (!tag) if (!tag)
tag_depth = depth; tag_depth = depth;
...@@ -234,11 +231,11 @@ dump_file (filename) ...@@ -234,11 +231,11 @@ dump_file (filename)
print_prefix (filename, tag_depth); print_prefix (filename, tag_depth);
printf ("%08x:%4u:%s", tag, length, format->name); printf ("%08x:%4u:%s", tag, length, format->name);
if (format->proc) if (format->proc)
if ((*format->proc) (filename, file, tag, length)) if ((*format->proc) (filename, tag, length))
goto read_error; goto read_error;
printf ("\n"); printf ("\n");
end = gcov_save_position (file); end = gcov_save_position ();
gcov_resync (file, base, length); gcov_resync (base, length);
if (format->proc && end != base + (long)length) if (format->proc && end != base + (long)length)
{ {
if (end > base + (long)length) if (end > base + (long)length)
...@@ -249,35 +246,44 @@ dump_file (filename) ...@@ -249,35 +246,44 @@ dump_file (filename)
filename, length - (end - base)); filename, length - (end - base));
} }
} }
if (!feof (file)) if (!gcov_eof ())
goto read_error; goto read_error;
fclose (file); gcov_close ();
} }
static int static int
tag_function (filename, file, tag, length) tag_function (filename, tag, length)
const char *filename ATTRIBUTE_UNUSED; const char *filename ATTRIBUTE_UNUSED;
FILE *file ATTRIBUTE_UNUSED;
unsigned tag ATTRIBUTE_UNUSED; unsigned tag ATTRIBUTE_UNUSED;
unsigned length ATTRIBUTE_UNUSED; unsigned length ATTRIBUTE_UNUSED;
{ {
char *name = NULL; char *name = NULL;
unsigned checksum; unsigned checksum;
char *src = NULL;
unsigned lineno = 0;
unsigned long pos = gcov_save_position ();
if (gcov_read_string (&name)
|| gcov_read_unsigned (&checksum))
return 1;
if (gcov_read_string (file, &name, NULL) if (gcov_save_position () - pos != length
|| gcov_read_unsigned (file, &checksum)) && (gcov_read_string (&src)
|| gcov_read_unsigned (&lineno)))
return 1; return 1;
printf (" `%s' checksum=0x%08x", name, checksum); printf (" `%s' checksum=0x%08x", name, checksum);
if (src)
printf (" %s:%u", src, lineno);
free (name); free (name);
free (src);
return 0; return 0;
} }
static int static int
tag_blocks (filename, file, tag, length) tag_blocks (filename, tag, length)
const char *filename ATTRIBUTE_UNUSED; const char *filename ATTRIBUTE_UNUSED;
FILE *file ATTRIBUTE_UNUSED;
unsigned tag ATTRIBUTE_UNUSED; unsigned tag ATTRIBUTE_UNUSED;
unsigned length ATTRIBUTE_UNUSED; unsigned length ATTRIBUTE_UNUSED;
{ {
...@@ -292,7 +298,7 @@ tag_blocks (filename, file, tag, length) ...@@ -292,7 +298,7 @@ tag_blocks (filename, file, tag, length)
for (ix = 0; ix != n_blocks; ix++) for (ix = 0; ix != n_blocks; ix++)
{ {
unsigned flags; unsigned flags;
if (gcov_read_unsigned (file, &flags)) if (gcov_read_unsigned (&flags))
return 1; return 1;
if (!(ix & 7)) if (!(ix & 7))
printf ("\n%s:\t\t%u", filename, ix); printf ("\n%s:\t\t%u", filename, ix);
...@@ -301,15 +307,14 @@ tag_blocks (filename, file, tag, length) ...@@ -301,15 +307,14 @@ tag_blocks (filename, file, tag, length)
} }
else else
gcov_skip (file, n_blocks * 4); gcov_skip (n_blocks * 4);
return 0; return 0;
} }
static int static int
tag_arcs (filename, file, tag, length) tag_arcs (filename, tag, length)
const char *filename ATTRIBUTE_UNUSED; const char *filename ATTRIBUTE_UNUSED;
FILE *file ATTRIBUTE_UNUSED;
unsigned tag ATTRIBUTE_UNUSED; unsigned tag ATTRIBUTE_UNUSED;
unsigned length ATTRIBUTE_UNUSED; unsigned length ATTRIBUTE_UNUSED;
{ {
...@@ -321,15 +326,14 @@ tag_arcs (filename, file, tag, length) ...@@ -321,15 +326,14 @@ tag_arcs (filename, file, tag, length)
unsigned ix; unsigned ix;
unsigned blockno; unsigned blockno;
if (gcov_read_unsigned (file, &blockno)) if (gcov_read_unsigned (&blockno))
return 1; return 1;
for (ix = 0; ix != n_arcs; ix++) for (ix = 0; ix != n_arcs; ix++)
{ {
unsigned dst, flags; unsigned dst, flags;
if (gcov_read_unsigned (file, &dst) if (gcov_read_unsigned (&dst) || gcov_read_unsigned (&flags))
|| gcov_read_unsigned (file, &flags))
return 1; return 1;
if (!(ix & 3)) if (!(ix & 3))
printf ("\n%s:\t\t%u:", filename, blockno); printf ("\n%s:\t\t%u:", filename, blockno);
...@@ -337,15 +341,14 @@ tag_arcs (filename, file, tag, length) ...@@ -337,15 +341,14 @@ tag_arcs (filename, file, tag, length)
} }
} }
else else
gcov_skip (file, 4 + n_arcs * 8); gcov_skip (4 + n_arcs * 8);
return 0; return 0;
} }
static int static int
tag_lines (filename, file, tag, length) tag_lines (filename, tag, length)
const char *filename ATTRIBUTE_UNUSED; const char *filename ATTRIBUTE_UNUSED;
FILE *file ATTRIBUTE_UNUSED;
unsigned tag ATTRIBUTE_UNUSED; unsigned tag ATTRIBUTE_UNUSED;
unsigned length ATTRIBUTE_UNUSED; unsigned length ATTRIBUTE_UNUSED;
{ {
...@@ -355,21 +358,21 @@ tag_lines (filename, file, tag, length) ...@@ -355,21 +358,21 @@ tag_lines (filename, file, tag, length)
unsigned blockno; unsigned blockno;
char const *sep = NULL; char const *sep = NULL;
if (gcov_read_unsigned (file, &blockno)) if (gcov_read_unsigned (&blockno))
return 1; return 1;
while (1) while (1)
{ {
unsigned lineno; unsigned lineno;
if (gcov_read_unsigned (file, &lineno)) if (gcov_read_unsigned (&lineno))
{ {
free (source); free (source);
return 1; return 1;
} }
if (!lineno) if (!lineno)
{ {
if (gcov_read_string (file, &source, NULL)) if (gcov_read_string (&source))
return 1; return 1;
if (!source) if (!source)
break; break;
...@@ -394,15 +397,14 @@ tag_lines (filename, file, tag, length) ...@@ -394,15 +397,14 @@ tag_lines (filename, file, tag, length)
} }
} }
else else
gcov_skip (file, length); gcov_skip (length);
return 0; return 0;
} }
static int static int
tag_arc_counts (filename, file, tag, length) tag_arc_counts (filename, tag, length)
const char *filename ATTRIBUTE_UNUSED; const char *filename ATTRIBUTE_UNUSED;
FILE *file ATTRIBUTE_UNUSED;
unsigned tag ATTRIBUTE_UNUSED; unsigned tag ATTRIBUTE_UNUSED;
unsigned length ATTRIBUTE_UNUSED; unsigned length ATTRIBUTE_UNUSED;
{ {
...@@ -417,7 +419,7 @@ tag_arc_counts (filename, file, tag, length) ...@@ -417,7 +419,7 @@ tag_arc_counts (filename, file, tag, length)
{ {
gcov_type count; gcov_type count;
if (gcov_read_counter (file, &count)) if (gcov_read_counter (&count))
return 1; return 1;
if (!(ix & 7)) if (!(ix & 7))
printf ("\n%s:\t\t%u", filename, ix); printf ("\n%s:\t\t%u", filename, ix);
...@@ -426,21 +428,20 @@ tag_arc_counts (filename, file, tag, length) ...@@ -426,21 +428,20 @@ tag_arc_counts (filename, file, tag, length)
} }
} }
else else
gcov_skip (file, n_counts * 8); gcov_skip (n_counts * 8);
return 0; return 0;
} }
static int static int
tag_summary (filename, file, tag, length) tag_summary (filename, tag, length)
const char *filename ATTRIBUTE_UNUSED; const char *filename ATTRIBUTE_UNUSED;
FILE *file ATTRIBUTE_UNUSED;
unsigned tag ATTRIBUTE_UNUSED; unsigned tag ATTRIBUTE_UNUSED;
unsigned length ATTRIBUTE_UNUSED; unsigned length ATTRIBUTE_UNUSED;
{ {
struct gcov_summary summary; struct gcov_summary summary;
if (gcov_read_summary (file, &summary)) if (gcov_read_summary (&summary))
return 1; return 1;
printf (" checksum=0x%08x", summary.checksum); printf (" checksum=0x%08x", summary.checksum);
......
...@@ -51,7 +51,7 @@ Boston, MA 02111-1307, USA. */ ...@@ -51,7 +51,7 @@ Boston, MA 02111-1307, USA. */
#include <getopt.h> #include <getopt.h>
typedef HOST_WIDEST_INT gcov_type; #define IN_GCOV 1
#include "gcov-io.h" #include "gcov-io.h"
/* The bbg file is generated by -ftest-coverage option. The da file is /* The bbg file is generated by -ftest-coverage option. The da file is
...@@ -706,8 +706,6 @@ find_source (file_name) ...@@ -706,8 +706,6 @@ find_source (file_name)
static int static int
read_graph_file () read_graph_file ()
{ {
FILE *file;
struct stat status;
unsigned magic, version; unsigned magic, version;
unsigned current_tag = 0; unsigned current_tag = 0;
unsigned tag; unsigned tag;
...@@ -715,22 +713,20 @@ read_graph_file () ...@@ -715,22 +713,20 @@ read_graph_file ()
source_t *src = NULL; source_t *src = NULL;
unsigned ix; unsigned ix;
file = fopen (bbg_file_name, "rb"); if (!gcov_open (bbg_file_name, 1))
if (!file)
{ {
fnotice (stderr, "%s:cannot open graph file\n", bbg_file_name); fnotice (stderr, "%s:cannot open graph file\n", bbg_file_name);
return 1; return 1;
} }
if (!fstat (fileno (file), &status)) bbg_file_time = gcov_time ();
bbg_file_time = status.st_mtime; if (gcov_read_unsigned (&magic) || magic != GCOV_GRAPH_MAGIC)
if (gcov_read_unsigned (file, &magic) || magic != GCOV_GRAPH_MAGIC)
{ {
fnotice (stderr, "%s:not a gcov graph file\n", bbg_file_name); fnotice (stderr, "%s:not a gcov graph file\n", bbg_file_name);
fclose (file); gcov_close ();
return 1; return 1;
} }
if (gcov_read_unsigned (file, &version) || version != GCOV_VERSION) if (gcov_read_unsigned (&version) || version != GCOV_VERSION)
{ {
char v[4], e[4]; char v[4], e[4];
...@@ -745,15 +741,15 @@ read_graph_file () ...@@ -745,15 +741,15 @@ read_graph_file ()
bbg_file_name, v, e); bbg_file_name, v, e);
} }
while (!gcov_read_unsigned (file, &tag)) while (!gcov_read_unsigned (&tag))
{ {
unsigned length; unsigned length;
long base; long base;
if (gcov_read_unsigned (file, &length)) if (gcov_read_unsigned (&length))
goto corrupt; goto corrupt;
base = gcov_save_position (file); base = gcov_save_position ();
if (tag == GCOV_TAG_FUNCTION) if (tag == GCOV_TAG_FUNCTION)
{ {
...@@ -763,10 +759,10 @@ read_graph_file () ...@@ -763,10 +759,10 @@ read_graph_file ()
source_t *src; source_t *src;
function_t *probe, *prev; function_t *probe, *prev;
if (gcov_read_string (file, &function_name, NULL) if (gcov_read_string (&function_name)
|| gcov_read_unsigned (file, &checksum) || gcov_read_unsigned (&checksum)
|| gcov_read_string (file, &function_file, NULL) || gcov_read_string (&function_file)
|| gcov_read_unsigned (file, &lineno)) || gcov_read_unsigned (&lineno))
goto corrupt; goto corrupt;
src = find_source (function_file); src = find_source (function_file);
fn = (function_t *)xcalloc (1, sizeof (function_t)); fn = (function_t *)xcalloc (1, sizeof (function_t));
...@@ -810,7 +806,7 @@ read_graph_file () ...@@ -810,7 +806,7 @@ read_graph_file ()
{ {
unsigned flags; unsigned flags;
if (gcov_read_unsigned (file, &flags)) if (gcov_read_unsigned (&flags))
goto corrupt; goto corrupt;
fn->blocks[ix].flags = flags; fn->blocks[ix].flags = flags;
} }
...@@ -822,7 +818,7 @@ read_graph_file () ...@@ -822,7 +818,7 @@ read_graph_file ()
unsigned num_dests = (length - 4) / 8; unsigned num_dests = (length - 4) / 8;
unsigned dest, flags; unsigned dest, flags;
if (gcov_read_unsigned (file, &src) if (gcov_read_unsigned (&src)
|| src >= fn->num_blocks || src >= fn->num_blocks
|| fn->blocks[src].succ) || fn->blocks[src].succ)
goto corrupt; goto corrupt;
...@@ -831,8 +827,8 @@ read_graph_file () ...@@ -831,8 +827,8 @@ read_graph_file ()
{ {
struct arc_info *arc; struct arc_info *arc;
if (gcov_read_unsigned (file, &dest) if (gcov_read_unsigned (&dest)
|| gcov_read_unsigned (file, &flags) || gcov_read_unsigned (&flags)
|| dest >= fn->num_blocks) || dest >= fn->num_blocks)
goto corrupt; goto corrupt;
arc = (arc_t *) xcalloc (1, sizeof (arc_t)); arc = (arc_t *) xcalloc (1, sizeof (arc_t));
...@@ -883,7 +879,7 @@ read_graph_file () ...@@ -883,7 +879,7 @@ read_graph_file ()
unsigned *line_nos unsigned *line_nos
= (unsigned *)xcalloc ((length - 4) / 4, sizeof (unsigned)); = (unsigned *)xcalloc ((length - 4) / 4, sizeof (unsigned));
if (gcov_read_unsigned (file, &blockno) if (gcov_read_unsigned (&blockno)
|| blockno >= fn->num_blocks || blockno >= fn->num_blocks
|| fn->blocks[blockno].u.line.encoding) || fn->blocks[blockno].u.line.encoding)
goto corrupt; goto corrupt;
...@@ -892,7 +888,7 @@ read_graph_file () ...@@ -892,7 +888,7 @@ read_graph_file ()
{ {
unsigned lineno; unsigned lineno;
if (gcov_read_unsigned (file, &lineno)) if (gcov_read_unsigned (&lineno))
goto corrupt; goto corrupt;
if (lineno) if (lineno)
{ {
...@@ -909,7 +905,7 @@ read_graph_file () ...@@ -909,7 +905,7 @@ read_graph_file ()
{ {
char *file_name = NULL; char *file_name = NULL;
if (gcov_read_string (file, &file_name, NULL)) if (gcov_read_string (&file_name))
goto corrupt; goto corrupt;
if (!file_name) if (!file_name)
break; break;
...@@ -928,15 +924,15 @@ read_graph_file () ...@@ -928,15 +924,15 @@ read_graph_file ()
fn = NULL; fn = NULL;
current_tag = 0; current_tag = 0;
} }
if (gcov_resync (file, base, length)) if (gcov_resync (base, length))
{ {
corrupt:; corrupt:;
fnotice (stderr, "%s:corrupted\n", bbg_file_name); fnotice (stderr, "%s:corrupted\n", bbg_file_name);
fclose (file); gcov_close ();
return 1; return 1;
} }
} }
fclose (file); gcov_close ();
/* We built everything backwards, so nreverse them all */ /* We built everything backwards, so nreverse them all */
...@@ -997,27 +993,25 @@ read_graph_file () ...@@ -997,27 +993,25 @@ read_graph_file ()
static int static int
read_count_file () read_count_file ()
{ {
FILE *file;
unsigned ix; unsigned ix;
char *function_name_buffer = NULL; char *function_name_buffer = NULL;
unsigned magic, version; unsigned magic, version;
function_t *fn = NULL; function_t *fn = NULL;
file = fopen (da_file_name, "rb"); if (!gcov_open (da_file_name, 1))
if (!file)
{ {
fnotice (stderr, "%s:cannot open data file\n", da_file_name); fnotice (stderr, "%s:cannot open data file\n", da_file_name);
return 1; return 1;
} }
if (gcov_read_unsigned (file, &magic) || magic != GCOV_DATA_MAGIC) if (gcov_read_unsigned (&magic) || magic != GCOV_DATA_MAGIC)
{ {
fnotice (stderr, "%s:not a gcov data file\n", da_file_name); fnotice (stderr, "%s:not a gcov data file\n", da_file_name);
cleanup:; cleanup:;
free (function_name_buffer); free (function_name_buffer);
fclose (file); gcov_close ();
return 1; return 1;
} }
if (gcov_read_unsigned (file, &version) || version != GCOV_VERSION) if (gcov_read_unsigned (&version) || version != GCOV_VERSION)
{ {
char v[4], e[4]; char v[4], e[4];
...@@ -1036,32 +1030,35 @@ read_count_file () ...@@ -1036,32 +1030,35 @@ read_count_file ()
unsigned tag, length; unsigned tag, length;
long base; long base;
if (gcov_read_unsigned (file, &tag) if (gcov_read_unsigned (&tag)
|| gcov_read_unsigned (file, &length)) || gcov_read_unsigned (&length))
{ {
if (feof (file)) if (gcov_eof ())
break; break;
corrupt:; corrupt:;
fnotice (stderr, "%s:corrupted\n", da_file_name); fnotice (stderr, "%s:corrupted\n", da_file_name);
goto cleanup; goto cleanup;
} }
base = gcov_save_position (file); base = gcov_save_position ();
if (tag == GCOV_TAG_OBJECT_SUMMARY) if (tag == GCOV_TAG_OBJECT_SUMMARY)
{ {
if (gcov_read_summary (file, &object_summary)) if (gcov_read_summary (&object_summary))
goto corrupt; goto corrupt;
} }
else if (tag == GCOV_TAG_PROGRAM_SUMMARY else if (tag == GCOV_TAG_PROGRAM_SUMMARY
|| tag == GCOV_TAG_INCORRECT_SUMMARY) || tag == GCOV_TAG_INCORRECT_SUMMARY)
program_count++; {
program_count++;
gcov_resync (base, length);
}
else if (tag == GCOV_TAG_FUNCTION) else if (tag == GCOV_TAG_FUNCTION)
{ {
unsigned checksum; unsigned checksum;
struct function_info *fn_n = functions; struct function_info *fn_n = functions;
if (gcov_read_string (file, &function_name_buffer, NULL) if (gcov_read_string (&function_name_buffer)
|| gcov_read_unsigned (file, &checksum)) || gcov_read_unsigned (&checksum))
goto corrupt; goto corrupt;
for (fn = fn ? fn->next : NULL; ; fn = fn->next) for (fn = fn ? fn->next : NULL; ; fn = fn->next)
...@@ -1103,15 +1100,16 @@ read_count_file () ...@@ -1103,15 +1100,16 @@ read_count_file ()
{ {
gcov_type count; gcov_type count;
if (gcov_read_counter (file, &count)) if (gcov_read_counter (&count))
goto corrupt; goto corrupt;
fn->counts[ix] += count; fn->counts[ix] += count;
} }
} }
gcov_resync (file, base, length); else
gcov_resync (base, length);
} }
fclose (file); gcov_close ();
free (function_name_buffer); free (function_name_buffer);
return 0; return 0;
} }
......
...@@ -57,6 +57,7 @@ void __gcov_flush (void) { } ...@@ -57,6 +57,7 @@ void __gcov_flush (void) { }
#include <fcntl.h> #include <fcntl.h>
#include <errno.h> #include <errno.h>
#endif #endif
#define IN_LIBGCOV 1
#include "gcov-io.h" #include "gcov-io.h"
/* Chain of per-object gcov structures. */ /* Chain of per-object gcov structures. */
...@@ -102,16 +103,6 @@ gcov_exit (void) ...@@ -102,16 +103,6 @@ gcov_exit (void)
gcov_type program_sum = 0; gcov_type program_sum = 0;
unsigned program_arcs = 0; unsigned program_arcs = 0;
#if defined (TARGET_HAS_F_SETLKW)
struct flock s_flock;
s_flock.l_type = F_WRLCK;
s_flock.l_whence = SEEK_SET;
s_flock.l_start = 0;
s_flock.l_len = 0; /* Until EOF. */
s_flock.l_pid = getpid ();
#endif
memset (&program, 0, sizeof (program)); memset (&program, 0, sizeof (program));
program.checksum = gcov_crc32; program.checksum = gcov_crc32;
...@@ -119,7 +110,7 @@ gcov_exit (void) ...@@ -119,7 +110,7 @@ gcov_exit (void)
{ {
struct gcov_summary object; struct gcov_summary object;
struct gcov_summary local_prg; struct gcov_summary local_prg;
int merging = 0; int merging;
long base; long base;
const struct function_info *fn_info; const struct function_info *fn_info;
gcov_type **counters; gcov_type **counters;
...@@ -164,27 +155,28 @@ gcov_exit (void) ...@@ -164,27 +155,28 @@ gcov_exit (void)
memset (&object, 0, sizeof (object)); memset (&object, 0, sizeof (object));
/* Open for modification */ /* Open for modification */
if (!da_file_open (ptr->filename, &merging)) merging = gcov_open (ptr->filename, 0);
if (!merging)
{ {
fprintf (stderr, "profiling:%s:Cannot open\n", ptr->filename); fprintf (stderr, "profiling:%s:Cannot open\n", ptr->filename);
ptr->filename = 0; ptr->filename = 0;
continue; continue;
} }
if (merging) if (merging > 0)
{ {
/* Merge data from file. */ /* Merge data from file. */
if (gcov_read_unsigned (&tag) || tag != GCOV_DATA_MAGIC)
if (gcov_read_unsigned (0, &tag) || tag != GCOV_DATA_MAGIC)
{ {
fprintf (stderr, "profiling:%s:Not a gcov data file\n", fprintf (stderr, "profiling:%s:Not a gcov data file\n",
ptr->filename); ptr->filename);
read_fatal:; read_fatal:;
da_file_close (); gcov_close ();
ptr->filename = 0; ptr->filename = 0;
continue; continue;
} }
if (gcov_read_unsigned (0, &length) || length != GCOV_VERSION) if (gcov_read_unsigned (&length) || length != GCOV_VERSION)
{ {
gcov_version_mismatch (ptr, length); gcov_version_mismatch (ptr, length);
goto read_fatal; goto read_fatal;
...@@ -194,8 +186,7 @@ gcov_exit (void) ...@@ -194,8 +186,7 @@ gcov_exit (void)
for (ix = ptr->n_functions, fn_info = ptr->functions; for (ix = ptr->n_functions, fn_info = ptr->functions;
ix--; fn_info++) ix--; fn_info++)
{ {
if (gcov_read_unsigned (0, &tag) if (gcov_read_unsigned (&tag) || gcov_read_unsigned (&length))
|| gcov_read_unsigned (0, &length))
{ {
read_error:; read_error:;
fprintf (stderr, "profiling:%s:Error merging\n", fprintf (stderr, "profiling:%s:Error merging\n",
...@@ -212,9 +203,9 @@ gcov_exit (void) ...@@ -212,9 +203,9 @@ gcov_exit (void)
goto read_fatal; goto read_fatal;
} }
if (gcov_read_unsigned (0, &flength) if (gcov_read_unsigned (&flength)
|| gcov_skip_string (0, flength) || gcov_skip_string (flength)
|| gcov_read_unsigned (0, &checksum)) || gcov_read_unsigned (&checksum))
goto read_error; goto read_error;
if (flength != strlen (fn_info->name) if (flength != strlen (fn_info->name)
|| checksum != fn_info->checksum) || checksum != fn_info->checksum)
...@@ -227,8 +218,8 @@ gcov_exit (void) ...@@ -227,8 +218,8 @@ gcov_exit (void)
{ {
unsigned n_counters; unsigned n_counters;
if (gcov_read_unsigned (0, &tag) if (gcov_read_unsigned (&tag)
|| gcov_read_unsigned (0, &length)) || gcov_read_unsigned (&length))
goto read_error; goto read_error;
for (sect_index = 0; for (sect_index = 0;
sect_index < ptr->n_counter_sections; sect_index < ptr->n_counter_sections;
...@@ -244,7 +235,7 @@ gcov_exit (void) ...@@ -244,7 +235,7 @@ gcov_exit (void)
goto read_mismatch; goto read_mismatch;
for (jx = 0; jx < n_counters; jx++) for (jx = 0; jx < n_counters; jx++)
if (gcov_read_counter (0, &count)) if (gcov_read_counter (&count))
goto read_error; goto read_error;
else else
counters[sect_index][jx] += count; counters[sect_index][jx] += count;
...@@ -253,23 +244,22 @@ gcov_exit (void) ...@@ -253,23 +244,22 @@ gcov_exit (void)
} }
/* Check object summary */ /* Check object summary */
if (gcov_read_unsigned (0, &tag) if (gcov_read_unsigned (&tag) || gcov_read_unsigned (&length))
|| gcov_read_unsigned (0, &length))
goto read_error; goto read_error;
if (tag != GCOV_TAG_OBJECT_SUMMARY) if (tag != GCOV_TAG_OBJECT_SUMMARY)
goto read_mismatch; goto read_mismatch;
if (gcov_read_summary (0, &object)) if (gcov_read_summary (&object))
goto read_error; goto read_error;
/* Check program summary */ /* Check program summary */
while (1) while (1)
{ {
long base = da_file_position (0); long base = gcov_save_position ();
if (gcov_read_unsigned (0, &tag) if (gcov_read_unsigned (&tag)
|| gcov_read_unsigned (0, &length)) || gcov_read_unsigned (&length))
{ {
if (da_file_eof ()) if (gcov_eof ())
break; break;
goto read_error; goto read_error;
} }
...@@ -277,7 +267,7 @@ gcov_exit (void) ...@@ -277,7 +267,7 @@ gcov_exit (void)
&& tag != GCOV_TAG_PLACEHOLDER_SUMMARY && tag != GCOV_TAG_PLACEHOLDER_SUMMARY
&& tag != GCOV_TAG_INCORRECT_SUMMARY) && tag != GCOV_TAG_INCORRECT_SUMMARY)
goto read_mismatch; goto read_mismatch;
if (gcov_read_summary (0, &local_prg)) if (gcov_read_summary (&local_prg))
goto read_error; goto read_error;
if (local_prg.checksum != program.checksum) if (local_prg.checksum != program.checksum)
continue; continue;
...@@ -288,7 +278,7 @@ gcov_exit (void) ...@@ -288,7 +278,7 @@ gcov_exit (void)
ptr->filename); ptr->filename);
goto read_fatal; goto read_fatal;
} }
merging = -1; merging = 0;
if (tag != GCOV_TAG_PROGRAM_SUMMARY) if (tag != GCOV_TAG_PROGRAM_SUMMARY)
break; break;
...@@ -304,7 +294,7 @@ gcov_exit (void) ...@@ -304,7 +294,7 @@ gcov_exit (void)
ptr->wkspc = base; ptr->wkspc = base;
break; break;
} }
da_file_seek (0, 0, SEEK_SET); gcov_resync (0, 0);
} }
object.runs++; object.runs++;
...@@ -316,12 +306,12 @@ gcov_exit (void) ...@@ -316,12 +306,12 @@ gcov_exit (void)
/* Write out the data. */ /* Write out the data. */
if (/* magic */ if (/* magic */
gcov_write_unsigned (0, GCOV_DATA_MAGIC) gcov_write_unsigned (GCOV_DATA_MAGIC)
/* version number */ /* version number */
|| gcov_write_unsigned (0, GCOV_VERSION)) || gcov_write_unsigned (GCOV_VERSION))
{ {
write_error:; write_error:;
da_file_close (); gcov_close ();
fprintf (stderr, "profiling:%s:Error writing\n", ptr->filename); fprintf (stderr, "profiling:%s:Error writing\n", ptr->filename);
ptr->filename = 0; ptr->filename = 0;
continue; continue;
...@@ -333,14 +323,13 @@ gcov_exit (void) ...@@ -333,14 +323,13 @@ gcov_exit (void)
for (ix = ptr->n_functions, fn_info = ptr->functions; ix--; fn_info++) for (ix = ptr->n_functions, fn_info = ptr->functions; ix--; fn_info++)
{ {
/* Announce function. */ /* Announce function. */
if (gcov_write_unsigned (0, GCOV_TAG_FUNCTION) if (gcov_write_unsigned (GCOV_TAG_FUNCTION)
|| !(base = gcov_reserve_length (0)) || !(base = gcov_reserve_length ())
/* function name */ /* function name */
|| gcov_write_string (0, fn_info->name, || gcov_write_string (fn_info->name)
strlen (fn_info->name))
/* function checksum */ /* function checksum */
|| gcov_write_unsigned (0, fn_info->checksum) || gcov_write_unsigned (fn_info->checksum)
|| gcov_write_length (0, base)) || gcov_write_length (base))
goto write_error; goto write_error;
/* counters. */ /* counters. */
...@@ -357,8 +346,8 @@ gcov_exit (void) ...@@ -357,8 +346,8 @@ gcov_exit (void)
if (sect_index == ptr->n_counter_sections) if (sect_index == ptr->n_counter_sections)
abort (); abort ();
if (gcov_write_unsigned (0, tag) if (gcov_write_unsigned (tag)
|| !(base = gcov_reserve_length (0))) || !(base = gcov_reserve_length ()))
goto write_error; goto write_error;
for (jx = fn_info->counter_sections[f_sect_index].n_counters; jx--;) for (jx = fn_info->counter_sections[f_sect_index].n_counters; jx--;)
...@@ -371,41 +360,39 @@ gcov_exit (void) ...@@ -371,41 +360,39 @@ gcov_exit (void)
if (object.arc_max_sum < count) if (object.arc_max_sum < count)
object.arc_max_sum = count; object.arc_max_sum = count;
} }
if (gcov_write_counter (0, count)) if (gcov_write_counter (count))
goto write_error; /* RIP Edsger Dijkstra */ goto write_error; /* RIP Edsger Dijkstra */
} }
if (gcov_write_length (0, base)) if (gcov_write_length (base))
goto write_error; goto write_error;
} }
} }
/* Object file summary. */ /* Object file summary. */
if (gcov_write_summary (0, GCOV_TAG_OBJECT_SUMMARY, &object)) if (gcov_write_summary (GCOV_TAG_OBJECT_SUMMARY, &object))
goto write_error; goto write_error;
if (merging >= 0) if (merging)
{ {
if (da_file_seek (0, 0, SEEK_END)) ptr->wkspc = gcov_seek_end ();
goto write_error; if (gcov_write_summary (GCOV_TAG_PLACEHOLDER_SUMMARY,
ptr->wkspc = da_file_position (0);
if (gcov_write_summary (0, GCOV_TAG_PLACEHOLDER_SUMMARY,
&program)) &program))
goto write_error; goto write_error;
} }
else if (ptr->wkspc) else if (ptr->wkspc)
{ {
/* Zap trailing program summary */ /* Zap trailing program summary */
if (da_file_seek (0, ptr->wkspc, SEEK_SET)) if (gcov_resync (ptr->wkspc, 0))
goto write_error; goto write_error;
if (!local_prg.runs) if (!local_prg.runs)
ptr->wkspc = 0; ptr->wkspc = 0;
if (gcov_write_unsigned (0, local_prg.runs if (gcov_write_unsigned (local_prg.runs
? GCOV_TAG_PLACEHOLDER_SUMMARY ? GCOV_TAG_PLACEHOLDER_SUMMARY
: GCOV_TAG_INCORRECT_SUMMARY)) : GCOV_TAG_INCORRECT_SUMMARY))
goto write_error; goto write_error;
} }
if (da_file_close ()) if (gcov_close ())
{ {
fprintf (stderr, "profiling:%s:Error closing\n", ptr->filename); fprintf (stderr, "profiling:%s:Error closing\n", ptr->filename);
ptr->filename = 0; ptr->filename = 0;
...@@ -434,25 +421,16 @@ gcov_exit (void) ...@@ -434,25 +421,16 @@ gcov_exit (void)
for (ptr = gcov_list; ptr; ptr = ptr->next) for (ptr = gcov_list; ptr; ptr = ptr->next)
if (ptr->filename && ptr->wkspc) if (ptr->filename && ptr->wkspc)
{ {
FILE *da_file; if (!gcov_open (ptr->filename, 1))
da_file = fopen (ptr->filename, "r+b");
if (!da_file)
{ {
fprintf (stderr, "profiling:%s:Cannot open\n", ptr->filename); fprintf (stderr, "profiling:%s:Cannot open\n", ptr->filename);
continue; continue;
} }
#if defined (TARGET_HAS_F_SETLKW) if (gcov_resync (ptr->wkspc, 0)
while (fcntl (fileno (da_file), F_SETLKW, &s_flock) || gcov_write_summary (GCOV_TAG_PROGRAM_SUMMARY, &program))
&& errno == EINTR)
continue;
#endif
if (fseek (da_file, ptr->wkspc, SEEK_SET)
|| gcov_write_summary (da_file, GCOV_TAG_PROGRAM_SUMMARY, &program)
|| fflush (da_file))
fprintf (stderr, "profiling:%s:Error writing\n", ptr->filename); fprintf (stderr, "profiling:%s:Error writing\n", ptr->filename);
if (fclose (da_file)) if (gcov_close ())
fprintf (stderr, "profiling:%s:Error closing\n", ptr->filename); fprintf (stderr, "profiling:%s:Error closing\n", ptr->filename);
} }
} }
......
...@@ -27,7 +27,6 @@ Software Foundation, 59 Temple Place - Suite 330, Boston, MA ...@@ -27,7 +27,6 @@ Software Foundation, 59 Temple Place - Suite 330, Boston, MA
#include "basic-block.h" #include "basic-block.h"
#include "cfgloop.h" #include "cfgloop.h"
#include "cfglayout.h" #include "cfglayout.h"
#include "gcov-io.h"
#include "profile.h" #include "profile.h"
/* Initialize loop optimizer. */ /* Initialize loop optimizer. */
......
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