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>
* doc/invoke.texi (RS/6000 and PowerPC Options): Document
......
......@@ -23,26 +23,26 @@ Boston, MA 02111-1307, USA. */
#include "tm.h"
#include "version.h"
#include <getopt.h>
typedef HOST_WIDEST_INT gcov_type;
#define IN_GCOV (-1)
#include "gcov-io.h"
static void dump_file PARAMS ((const char *));
static void print_prefix PARAMS ((const char *, unsigned));
static void print_usage PARAMS ((void));
static void print_version PARAMS ((void));
static int tag_function PARAMS ((const char *, FILE *, unsigned, unsigned));
static int tag_blocks PARAMS ((const char *, FILE *, unsigned, unsigned));
static int tag_arcs PARAMS ((const char *, FILE *, unsigned, unsigned));
static int tag_lines PARAMS ((const char *, FILE *, unsigned, unsigned));
static int tag_arc_counts PARAMS ((const char *, FILE *, unsigned, unsigned));
static int tag_summary PARAMS ((const char *, FILE *, unsigned, unsigned));
static int tag_function PARAMS ((const char *, unsigned, unsigned));
static int tag_blocks PARAMS ((const char *, unsigned, unsigned));
static int tag_arcs PARAMS ((const char *, unsigned, unsigned));
static int tag_lines PARAMS ((const char *, unsigned, unsigned));
static int tag_arc_counts PARAMS ((const char *, unsigned, unsigned));
static int tag_summary PARAMS ((const char *, unsigned, unsigned));
extern int main PARAMS ((int, char **));
typedef struct tag_format
{
unsigned tag;
char const *name;
int (*proc) (const char *, FILE *, unsigned, unsigned);
int (*proc) (const char *, unsigned, unsigned);
} tag_format_t;
static int flag_dump_contents = 0;
......@@ -138,24 +138,22 @@ static void
dump_file (filename)
const char *filename;
{
FILE *file = fopen (filename, "rb");
unsigned tags[4];
unsigned depth = 0;
unsigned magic, version;
unsigned tag, length;
if (!file)
if (!gcov_open (filename, 1))
{
fprintf (stderr, "%s:cannot open\n", filename);
return;
}
if (gcov_read_unsigned (file, &magic)
|| gcov_read_unsigned (file, &version))
if (gcov_read_unsigned (&magic) || gcov_read_unsigned (&version))
{
read_error:;
printf ("%s:read error at %ld\n", filename, ftell (file));
fclose (file);
printf ("%s:read error at %lu\n", filename, gcov_save_position ());
gcov_close ();
return;
}
......@@ -174,7 +172,7 @@ dump_file (filename)
else
{
printf ("%s:not a gcov file\n", filename);
fclose (file);
gcov_close ();
return;
}
for (ix = 4; ix--; expected >>= 8, version >>= 8, magic >>= 8)
......@@ -189,14 +187,13 @@ dump_file (filename)
printf ("%s:warning:current version is `%.4s'\n", filename, e);
}
while (!gcov_read_unsigned (file, &tag)
&& !gcov_read_unsigned (file, &length))
while (!gcov_read_unsigned (&tag) && !gcov_read_unsigned (&length))
{
tag_format_t const *format;
unsigned tag_depth;
long base, end;
base = gcov_save_position (file);
base = gcov_save_position ();
if (!tag)
tag_depth = depth;
......@@ -234,11 +231,11 @@ dump_file (filename)
print_prefix (filename, tag_depth);
printf ("%08x:%4u:%s", tag, length, format->name);
if (format->proc)
if ((*format->proc) (filename, file, tag, length))
if ((*format->proc) (filename, tag, length))
goto read_error;
printf ("\n");
end = gcov_save_position (file);
gcov_resync (file, base, length);
end = gcov_save_position ();
gcov_resync (base, length);
if (format->proc && end != base + (long)length)
{
if (end > base + (long)length)
......@@ -249,35 +246,44 @@ dump_file (filename)
filename, length - (end - base));
}
}
if (!feof (file))
if (!gcov_eof ())
goto read_error;
fclose (file);
gcov_close ();
}
static int
tag_function (filename, file, tag, length)
tag_function (filename, tag, length)
const char *filename ATTRIBUTE_UNUSED;
FILE *file ATTRIBUTE_UNUSED;
unsigned tag ATTRIBUTE_UNUSED;
unsigned length ATTRIBUTE_UNUSED;
{
char *name = NULL;
unsigned checksum;
char *src = NULL;
unsigned lineno = 0;
unsigned long pos = gcov_save_position ();
if (gcov_read_string (file, &name, NULL)
|| gcov_read_unsigned (file, &checksum))
if (gcov_read_string (&name)
|| gcov_read_unsigned (&checksum))
return 1;
if (gcov_save_position () - pos != length
&& (gcov_read_string (&src)
|| gcov_read_unsigned (&lineno)))
return 1;
printf (" `%s' checksum=0x%08x", name, checksum);
if (src)
printf (" %s:%u", src, lineno);
free (name);
free (src);
return 0;
}
static int
tag_blocks (filename, file, tag, length)
tag_blocks (filename, tag, length)
const char *filename ATTRIBUTE_UNUSED;
FILE *file ATTRIBUTE_UNUSED;
unsigned tag ATTRIBUTE_UNUSED;
unsigned length ATTRIBUTE_UNUSED;
{
......@@ -292,7 +298,7 @@ tag_blocks (filename, file, tag, length)
for (ix = 0; ix != n_blocks; ix++)
{
unsigned flags;
if (gcov_read_unsigned (file, &flags))
if (gcov_read_unsigned (&flags))
return 1;
if (!(ix & 7))
printf ("\n%s:\t\t%u", filename, ix);
......@@ -301,15 +307,14 @@ tag_blocks (filename, file, tag, length)
}
else
gcov_skip (file, n_blocks * 4);
gcov_skip (n_blocks * 4);
return 0;
}
static int
tag_arcs (filename, file, tag, length)
tag_arcs (filename, tag, length)
const char *filename ATTRIBUTE_UNUSED;
FILE *file ATTRIBUTE_UNUSED;
unsigned tag ATTRIBUTE_UNUSED;
unsigned length ATTRIBUTE_UNUSED;
{
......@@ -321,15 +326,14 @@ tag_arcs (filename, file, tag, length)
unsigned ix;
unsigned blockno;
if (gcov_read_unsigned (file, &blockno))
if (gcov_read_unsigned (&blockno))
return 1;
for (ix = 0; ix != n_arcs; ix++)
{
unsigned dst, flags;
if (gcov_read_unsigned (file, &dst)
|| gcov_read_unsigned (file, &flags))
if (gcov_read_unsigned (&dst) || gcov_read_unsigned (&flags))
return 1;
if (!(ix & 3))
printf ("\n%s:\t\t%u:", filename, blockno);
......@@ -337,15 +341,14 @@ tag_arcs (filename, file, tag, length)
}
}
else
gcov_skip (file, 4 + n_arcs * 8);
gcov_skip (4 + n_arcs * 8);
return 0;
}
static int
tag_lines (filename, file, tag, length)
tag_lines (filename, tag, length)
const char *filename ATTRIBUTE_UNUSED;
FILE *file ATTRIBUTE_UNUSED;
unsigned tag ATTRIBUTE_UNUSED;
unsigned length ATTRIBUTE_UNUSED;
{
......@@ -355,21 +358,21 @@ tag_lines (filename, file, tag, length)
unsigned blockno;
char const *sep = NULL;
if (gcov_read_unsigned (file, &blockno))
if (gcov_read_unsigned (&blockno))
return 1;
while (1)
{
unsigned lineno;
if (gcov_read_unsigned (file, &lineno))
if (gcov_read_unsigned (&lineno))
{
free (source);
return 1;
}
if (!lineno)
{
if (gcov_read_string (file, &source, NULL))
if (gcov_read_string (&source))
return 1;
if (!source)
break;
......@@ -394,15 +397,14 @@ tag_lines (filename, file, tag, length)
}
}
else
gcov_skip (file, length);
gcov_skip (length);
return 0;
}
static int
tag_arc_counts (filename, file, tag, length)
tag_arc_counts (filename, tag, length)
const char *filename ATTRIBUTE_UNUSED;
FILE *file ATTRIBUTE_UNUSED;
unsigned tag ATTRIBUTE_UNUSED;
unsigned length ATTRIBUTE_UNUSED;
{
......@@ -417,7 +419,7 @@ tag_arc_counts (filename, file, tag, length)
{
gcov_type count;
if (gcov_read_counter (file, &count))
if (gcov_read_counter (&count))
return 1;
if (!(ix & 7))
printf ("\n%s:\t\t%u", filename, ix);
......@@ -426,21 +428,20 @@ tag_arc_counts (filename, file, tag, length)
}
}
else
gcov_skip (file, n_counts * 8);
gcov_skip (n_counts * 8);
return 0;
}
static int
tag_summary (filename, file, tag, length)
tag_summary (filename, tag, length)
const char *filename ATTRIBUTE_UNUSED;
FILE *file ATTRIBUTE_UNUSED;
unsigned tag ATTRIBUTE_UNUSED;
unsigned length ATTRIBUTE_UNUSED;
{
struct gcov_summary summary;
if (gcov_read_summary (file, &summary))
if (gcov_read_summary (&summary))
return 1;
printf (" checksum=0x%08x", summary.checksum);
......
......@@ -51,7 +51,7 @@ Boston, MA 02111-1307, USA. */
#include <getopt.h>
typedef HOST_WIDEST_INT gcov_type;
#define IN_GCOV 1
#include "gcov-io.h"
/* The bbg file is generated by -ftest-coverage option. The da file is
......@@ -706,8 +706,6 @@ find_source (file_name)
static int
read_graph_file ()
{
FILE *file;
struct stat status;
unsigned magic, version;
unsigned current_tag = 0;
unsigned tag;
......@@ -715,22 +713,20 @@ read_graph_file ()
source_t *src = NULL;
unsigned ix;
file = fopen (bbg_file_name, "rb");
if (!file)
if (!gcov_open (bbg_file_name, 1))
{
fnotice (stderr, "%s:cannot open graph file\n", bbg_file_name);
return 1;
}
if (!fstat (fileno (file), &status))
bbg_file_time = status.st_mtime;
if (gcov_read_unsigned (file, &magic) || magic != GCOV_GRAPH_MAGIC)
bbg_file_time = gcov_time ();
if (gcov_read_unsigned (&magic) || magic != GCOV_GRAPH_MAGIC)
{
fnotice (stderr, "%s:not a gcov graph file\n", bbg_file_name);
fclose (file);
gcov_close ();
return 1;
}
if (gcov_read_unsigned (file, &version) || version != GCOV_VERSION)
if (gcov_read_unsigned (&version) || version != GCOV_VERSION)
{
char v[4], e[4];
......@@ -745,15 +741,15 @@ read_graph_file ()
bbg_file_name, v, e);
}
while (!gcov_read_unsigned (file, &tag))
while (!gcov_read_unsigned (&tag))
{
unsigned length;
long base;
if (gcov_read_unsigned (file, &length))
if (gcov_read_unsigned (&length))
goto corrupt;
base = gcov_save_position (file);
base = gcov_save_position ();
if (tag == GCOV_TAG_FUNCTION)
{
......@@ -763,10 +759,10 @@ read_graph_file ()
source_t *src;
function_t *probe, *prev;
if (gcov_read_string (file, &function_name, NULL)
|| gcov_read_unsigned (file, &checksum)
|| gcov_read_string (file, &function_file, NULL)
|| gcov_read_unsigned (file, &lineno))
if (gcov_read_string (&function_name)
|| gcov_read_unsigned (&checksum)
|| gcov_read_string (&function_file)
|| gcov_read_unsigned (&lineno))
goto corrupt;
src = find_source (function_file);
fn = (function_t *)xcalloc (1, sizeof (function_t));
......@@ -810,7 +806,7 @@ read_graph_file ()
{
unsigned flags;
if (gcov_read_unsigned (file, &flags))
if (gcov_read_unsigned (&flags))
goto corrupt;
fn->blocks[ix].flags = flags;
}
......@@ -822,7 +818,7 @@ read_graph_file ()
unsigned num_dests = (length - 4) / 8;
unsigned dest, flags;
if (gcov_read_unsigned (file, &src)
if (gcov_read_unsigned (&src)
|| src >= fn->num_blocks
|| fn->blocks[src].succ)
goto corrupt;
......@@ -831,8 +827,8 @@ read_graph_file ()
{
struct arc_info *arc;
if (gcov_read_unsigned (file, &dest)
|| gcov_read_unsigned (file, &flags)
if (gcov_read_unsigned (&dest)
|| gcov_read_unsigned (&flags)
|| dest >= fn->num_blocks)
goto corrupt;
arc = (arc_t *) xcalloc (1, sizeof (arc_t));
......@@ -883,7 +879,7 @@ read_graph_file ()
unsigned *line_nos
= (unsigned *)xcalloc ((length - 4) / 4, sizeof (unsigned));
if (gcov_read_unsigned (file, &blockno)
if (gcov_read_unsigned (&blockno)
|| blockno >= fn->num_blocks
|| fn->blocks[blockno].u.line.encoding)
goto corrupt;
......@@ -892,7 +888,7 @@ read_graph_file ()
{
unsigned lineno;
if (gcov_read_unsigned (file, &lineno))
if (gcov_read_unsigned (&lineno))
goto corrupt;
if (lineno)
{
......@@ -909,7 +905,7 @@ read_graph_file ()
{
char *file_name = NULL;
if (gcov_read_string (file, &file_name, NULL))
if (gcov_read_string (&file_name))
goto corrupt;
if (!file_name)
break;
......@@ -928,15 +924,15 @@ read_graph_file ()
fn = NULL;
current_tag = 0;
}
if (gcov_resync (file, base, length))
if (gcov_resync (base, length))
{
corrupt:;
fnotice (stderr, "%s:corrupted\n", bbg_file_name);
fclose (file);
gcov_close ();
return 1;
}
}
fclose (file);
gcov_close ();
/* We built everything backwards, so nreverse them all */
......@@ -997,27 +993,25 @@ read_graph_file ()
static int
read_count_file ()
{
FILE *file;
unsigned ix;
char *function_name_buffer = NULL;
unsigned magic, version;
function_t *fn = NULL;
file = fopen (da_file_name, "rb");
if (!file)
if (!gcov_open (da_file_name, 1))
{
fnotice (stderr, "%s:cannot open data file\n", da_file_name);
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);
cleanup:;
free (function_name_buffer);
fclose (file);
gcov_close ();
return 1;
}
if (gcov_read_unsigned (file, &version) || version != GCOV_VERSION)
if (gcov_read_unsigned (&version) || version != GCOV_VERSION)
{
char v[4], e[4];
......@@ -1036,32 +1030,35 @@ read_count_file ()
unsigned tag, length;
long base;
if (gcov_read_unsigned (file, &tag)
|| gcov_read_unsigned (file, &length))
if (gcov_read_unsigned (&tag)
|| gcov_read_unsigned (&length))
{
if (feof (file))
if (gcov_eof ())
break;
corrupt:;
fnotice (stderr, "%s:corrupted\n", da_file_name);
goto cleanup;
}
base = gcov_save_position (file);
base = gcov_save_position ();
if (tag == GCOV_TAG_OBJECT_SUMMARY)
{
if (gcov_read_summary (file, &object_summary))
if (gcov_read_summary (&object_summary))
goto corrupt;
}
else if (tag == GCOV_TAG_PROGRAM_SUMMARY
|| tag == GCOV_TAG_INCORRECT_SUMMARY)
{
program_count++;
gcov_resync (base, length);
}
else if (tag == GCOV_TAG_FUNCTION)
{
unsigned checksum;
struct function_info *fn_n = functions;
if (gcov_read_string (file, &function_name_buffer, NULL)
|| gcov_read_unsigned (file, &checksum))
if (gcov_read_string (&function_name_buffer)
|| gcov_read_unsigned (&checksum))
goto corrupt;
for (fn = fn ? fn->next : NULL; ; fn = fn->next)
......@@ -1103,15 +1100,16 @@ read_count_file ()
{
gcov_type count;
if (gcov_read_counter (file, &count))
if (gcov_read_counter (&count))
goto corrupt;
fn->counts[ix] += count;
}
}
gcov_resync (file, base, length);
else
gcov_resync (base, length);
}
fclose (file);
gcov_close ();
free (function_name_buffer);
return 0;
}
......
......@@ -57,6 +57,7 @@ void __gcov_flush (void) { }
#include <fcntl.h>
#include <errno.h>
#endif
#define IN_LIBGCOV 1
#include "gcov-io.h"
/* Chain of per-object gcov structures. */
......@@ -102,16 +103,6 @@ gcov_exit (void)
gcov_type program_sum = 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));
program.checksum = gcov_crc32;
......@@ -119,7 +110,7 @@ gcov_exit (void)
{
struct gcov_summary object;
struct gcov_summary local_prg;
int merging = 0;
int merging;
long base;
const struct function_info *fn_info;
gcov_type **counters;
......@@ -164,27 +155,28 @@ gcov_exit (void)
memset (&object, 0, sizeof (object));
/* 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);
ptr->filename = 0;
continue;
}
if (merging)
if (merging > 0)
{
/* Merge data from file. */
if (gcov_read_unsigned (0, &tag) || tag != GCOV_DATA_MAGIC)
if (gcov_read_unsigned (&tag) || tag != GCOV_DATA_MAGIC)
{
fprintf (stderr, "profiling:%s:Not a gcov data file\n",
ptr->filename);
read_fatal:;
da_file_close ();
gcov_close ();
ptr->filename = 0;
continue;
}
if (gcov_read_unsigned (0, &length) || length != GCOV_VERSION)
if (gcov_read_unsigned (&length) || length != GCOV_VERSION)
{
gcov_version_mismatch (ptr, length);
goto read_fatal;
......@@ -194,8 +186,7 @@ gcov_exit (void)
for (ix = ptr->n_functions, fn_info = ptr->functions;
ix--; fn_info++)
{
if (gcov_read_unsigned (0, &tag)
|| gcov_read_unsigned (0, &length))
if (gcov_read_unsigned (&tag) || gcov_read_unsigned (&length))
{
read_error:;
fprintf (stderr, "profiling:%s:Error merging\n",
......@@ -212,9 +203,9 @@ gcov_exit (void)
goto read_fatal;
}
if (gcov_read_unsigned (0, &flength)
|| gcov_skip_string (0, flength)
|| gcov_read_unsigned (0, &checksum))
if (gcov_read_unsigned (&flength)
|| gcov_skip_string (flength)
|| gcov_read_unsigned (&checksum))
goto read_error;
if (flength != strlen (fn_info->name)
|| checksum != fn_info->checksum)
......@@ -227,8 +218,8 @@ gcov_exit (void)
{
unsigned n_counters;
if (gcov_read_unsigned (0, &tag)
|| gcov_read_unsigned (0, &length))
if (gcov_read_unsigned (&tag)
|| gcov_read_unsigned (&length))
goto read_error;
for (sect_index = 0;
sect_index < ptr->n_counter_sections;
......@@ -244,7 +235,7 @@ gcov_exit (void)
goto read_mismatch;
for (jx = 0; jx < n_counters; jx++)
if (gcov_read_counter (0, &count))
if (gcov_read_counter (&count))
goto read_error;
else
counters[sect_index][jx] += count;
......@@ -253,23 +244,22 @@ gcov_exit (void)
}
/* Check object summary */
if (gcov_read_unsigned (0, &tag)
|| gcov_read_unsigned (0, &length))
if (gcov_read_unsigned (&tag) || gcov_read_unsigned (&length))
goto read_error;
if (tag != GCOV_TAG_OBJECT_SUMMARY)
goto read_mismatch;
if (gcov_read_summary (0, &object))
if (gcov_read_summary (&object))
goto read_error;
/* Check program summary */
while (1)
{
long base = da_file_position (0);
long base = gcov_save_position ();
if (gcov_read_unsigned (0, &tag)
|| gcov_read_unsigned (0, &length))
if (gcov_read_unsigned (&tag)
|| gcov_read_unsigned (&length))
{
if (da_file_eof ())
if (gcov_eof ())
break;
goto read_error;
}
......@@ -277,7 +267,7 @@ gcov_exit (void)
&& tag != GCOV_TAG_PLACEHOLDER_SUMMARY
&& tag != GCOV_TAG_INCORRECT_SUMMARY)
goto read_mismatch;
if (gcov_read_summary (0, &local_prg))
if (gcov_read_summary (&local_prg))
goto read_error;
if (local_prg.checksum != program.checksum)
continue;
......@@ -288,7 +278,7 @@ gcov_exit (void)
ptr->filename);
goto read_fatal;
}
merging = -1;
merging = 0;
if (tag != GCOV_TAG_PROGRAM_SUMMARY)
break;
......@@ -304,7 +294,7 @@ gcov_exit (void)
ptr->wkspc = base;
break;
}
da_file_seek (0, 0, SEEK_SET);
gcov_resync (0, 0);
}
object.runs++;
......@@ -316,12 +306,12 @@ gcov_exit (void)
/* Write out the data. */
if (/* magic */
gcov_write_unsigned (0, GCOV_DATA_MAGIC)
gcov_write_unsigned (GCOV_DATA_MAGIC)
/* version number */
|| gcov_write_unsigned (0, GCOV_VERSION))
|| gcov_write_unsigned (GCOV_VERSION))
{
write_error:;
da_file_close ();
gcov_close ();
fprintf (stderr, "profiling:%s:Error writing\n", ptr->filename);
ptr->filename = 0;
continue;
......@@ -333,14 +323,13 @@ gcov_exit (void)
for (ix = ptr->n_functions, fn_info = ptr->functions; ix--; fn_info++)
{
/* Announce function. */
if (gcov_write_unsigned (0, GCOV_TAG_FUNCTION)
|| !(base = gcov_reserve_length (0))
if (gcov_write_unsigned (GCOV_TAG_FUNCTION)
|| !(base = gcov_reserve_length ())
/* function name */
|| gcov_write_string (0, fn_info->name,
strlen (fn_info->name))
|| gcov_write_string (fn_info->name)
/* function checksum */
|| gcov_write_unsigned (0, fn_info->checksum)
|| gcov_write_length (0, base))
|| gcov_write_unsigned (fn_info->checksum)
|| gcov_write_length (base))
goto write_error;
/* counters. */
......@@ -357,8 +346,8 @@ gcov_exit (void)
if (sect_index == ptr->n_counter_sections)
abort ();
if (gcov_write_unsigned (0, tag)
|| !(base = gcov_reserve_length (0)))
if (gcov_write_unsigned (tag)
|| !(base = gcov_reserve_length ()))
goto write_error;
for (jx = fn_info->counter_sections[f_sect_index].n_counters; jx--;)
......@@ -371,41 +360,39 @@ gcov_exit (void)
if (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 */
}
if (gcov_write_length (0, base))
if (gcov_write_length (base))
goto write_error;
}
}
/* 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;
if (merging >= 0)
if (merging)
{
if (da_file_seek (0, 0, SEEK_END))
goto write_error;
ptr->wkspc = da_file_position (0);
if (gcov_write_summary (0, GCOV_TAG_PLACEHOLDER_SUMMARY,
ptr->wkspc = gcov_seek_end ();
if (gcov_write_summary (GCOV_TAG_PLACEHOLDER_SUMMARY,
&program))
goto write_error;
}
else if (ptr->wkspc)
{
/* Zap trailing program summary */
if (da_file_seek (0, ptr->wkspc, SEEK_SET))
if (gcov_resync (ptr->wkspc, 0))
goto write_error;
if (!local_prg.runs)
ptr->wkspc = 0;
if (gcov_write_unsigned (0, local_prg.runs
if (gcov_write_unsigned (local_prg.runs
? GCOV_TAG_PLACEHOLDER_SUMMARY
: GCOV_TAG_INCORRECT_SUMMARY))
goto write_error;
}
if (da_file_close ())
if (gcov_close ())
{
fprintf (stderr, "profiling:%s:Error closing\n", ptr->filename);
ptr->filename = 0;
......@@ -434,25 +421,16 @@ gcov_exit (void)
for (ptr = gcov_list; ptr; ptr = ptr->next)
if (ptr->filename && ptr->wkspc)
{
FILE *da_file;
da_file = fopen (ptr->filename, "r+b");
if (!da_file)
if (!gcov_open (ptr->filename, 1))
{
fprintf (stderr, "profiling:%s:Cannot open\n", ptr->filename);
continue;
}
#if defined (TARGET_HAS_F_SETLKW)
while (fcntl (fileno (da_file), F_SETLKW, &s_flock)
&& 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))
if (gcov_resync (ptr->wkspc, 0)
|| gcov_write_summary (GCOV_TAG_PROGRAM_SUMMARY, &program))
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);
}
}
......
......@@ -27,7 +27,6 @@ Software Foundation, 59 Temple Place - Suite 330, Boston, MA
#include "basic-block.h"
#include "cfgloop.h"
#include "cfglayout.h"
#include "gcov-io.h"
#include "profile.h"
/* 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