summaryrefslogtreecommitdiff
path: root/gcc/gcov.c
diff options
context:
space:
mode:
Diffstat (limited to 'gcc/gcov.c')
-rw-r--r--gcc/gcov.c86
1 files changed, 42 insertions, 44 deletions
diff --git a/gcc/gcov.c b/gcc/gcov.c
index 95968b585a6..5a2f4291f4a 100644
--- a/gcc/gcov.c
+++ b/gcc/gcov.c
@@ -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++;
+ {
+ 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;
}