diff options
author | Nathan Sidwell <nathan@codesourcery.com> | 2003-04-07 19:37:12 +0000 |
---|---|---|
committer | Nathan Sidwell <nathan@gcc.gnu.org> | 2003-04-07 19:37:12 +0000 |
commit | 546d2adb91fb66d2cb25edafcbdf11d06c9ad65f (patch) | |
tree | 544c50187f4dba610ef1e5aca2d2179d3211968b /gcc/gcov.c | |
parent | 5da702b196433484c7163a827e3202c44664734a (diff) | |
download | gcc-546d2adb91fb66d2cb25edafcbdf11d06c9ad65f.zip gcc-546d2adb91fb66d2cb25edafcbdf11d06c9ad65f.tar.gz gcc-546d2adb91fb66d2cb25edafcbdf11d06c9ad65f.tar.bz2 |
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
Diffstat (limited to 'gcc/gcov.c')
-rw-r--r-- | gcc/gcov.c | 86 |
1 files changed, 42 insertions, 44 deletions
@@ -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; } |