aboutsummaryrefslogtreecommitdiff
path: root/gcc/libgcov.c
diff options
context:
space:
mode:
authorNathan Sidwell <nathan@codesourcery.com>2003-05-07 10:40:09 +0000
committerNathan Sidwell <nathan@gcc.gnu.org>2003-05-07 10:40:09 +0000
commit474f141e8d6c6808888ad42842c7cc179c6d3525 (patch)
treeaa2fd5f968bcc9f49c44463d7bb9b157b0c4d790 /gcc/libgcov.c
parent6cbeaa7e52a2ba53925b916a4b181d63e2712014 (diff)
downloadgcc-474f141e8d6c6808888ad42842c7cc179c6d3525.zip
gcc-474f141e8d6c6808888ad42842c7cc179c6d3525.tar.gz
gcc-474f141e8d6c6808888ad42842c7cc179c6d3525.tar.bz2
gcov-io.h (GCOV_LOCKED): New #define.
* gcov-io.h (GCOV_LOCKED): New #define. (GCOV_LINKAGE): Make sure it is #defined. (gcov_write_string, gcov_write_tag, gcov_write_length, gcov_read_string, gcov_time): Poison in libgcov. (gcov_seek_end): Remove. (gcov_write_tag_length, gcov_sync, gcov_rewrite): New. (GCOV_TAG_FUNCTION_LENGTH, GCOV_TAG_BLOCKS_LENGTH, GCOV_TAG_ARCS_LENGTH, GCOV_TAG_COUNTER_LENGTH, GCOV_TAG_SUMMARY_LENGTH): New #defines. (gcov_write_tag, gcov_write_length): Not in libgcov. * gcov-io.c (gcov_open): Use GCOV_LOCKED. (gcov_write_tag, gcov_write_length): Not in libgcov. (gcov_write_tag_length): New. (gcov_write_summary): Use gcov_write_tag_length. * libgcov.c: Always #include gcov-io.h. (IN_LIBGCOV): -1 for inhibit_libc, +1 otherwise. (GCOV_LINKAGE): Define to nothing for L_gcov. (gcov_exit): Replace gcov_write_tag, gcov_write_length with gcov_write_tag_length. Use gcov_rewrite & gcov_seek. * gcov.c (read_graph_file): Replace gcov_seek by gcov_sync. (read_count_file): Likewise. * gcov-dump.c (dump_file): Likewise. * coverag.c (read_counts_file): Likewise. From-SVN: r66555
Diffstat (limited to 'gcc/libgcov.c')
-rw-r--r--gcc/libgcov.c110
1 files changed, 50 insertions, 60 deletions
diff --git a/gcc/libgcov.c b/gcc/libgcov.c
index b85e09e..ed2d3d7 100644
--- a/gcc/libgcov.c
+++ b/gcc/libgcov.c
@@ -29,25 +29,6 @@ along with GCC; see the file COPYING. If not, write to the Free
Software Foundation, 59 Temple Place - Suite 330, Boston, MA
02111-1307, USA. */
-#if defined(inhibit_libc)
-/* If libc and its header files are not available, provide dummy functions. */
-
-#ifdef L_gcov
-void __gcov_init (void *p);
-void __gcov_flush (void);
-
-void __gcov_init (void *p) { }
-void __gcov_flush (void) { }
-#endif
-
-#ifdef L_gcov_merge_add
-void __gcov_merge_add (void *, unsigned);
-
-void __gcov_merge_add (void *counters, unsigned n_counters) { }
-#endif
-
-#else
-
/* It is incorrect to include config.h here, because this file is being
compiled for the target, and hence definitions concerning only the host
do not apply. */
@@ -57,16 +38,38 @@ void __gcov_merge_add (void *counters, unsigned n_counters) { }
#include "coretypes.h"
#include "tm.h"
+#if defined(inhibit_libc)
+#define IN_LIBGCOV (-1)
+#else
#undef NULL /* Avoid errors if stdio.h and our stddef.h mismatch. */
#include <stdio.h>
+#define IN_LIBGCOV 1
+#if defined(L_gcov)
+#define GCOV_LINKAGE /* nothing */
+#endif
+#endif
+#include "gcov-io.h"
+
+#if defined(inhibit_libc)
+/* If libc and its header files are not available, provide dummy functions. */
+
+#ifdef L_gcov
+void __gcov_init (struct gcov_info *p __attribute__ ((unused))) {}
+void __gcov_flush (void) {}
+#endif
+
+#ifdef L_gcov_merge_add
+void __gcov_merge_add (gcov_type *counters __attribute__ ((unused)),
+ unsigned n_counters __attribute__ ((unused))) {}
+#endif
+
+#else
#include <string.h>
-#if defined (TARGET_HAS_F_SETLKW)
+#if GCOV_LOCKED
#include <fcntl.h>
#include <errno.h>
#endif
-#define IN_LIBGCOV 1
-#include "gcov-io.h"
#ifdef L_gcov
#include "gcov-io.c"
@@ -151,9 +154,8 @@ gcov_exit (void)
struct gcov_ctr_summary *cs_obj, *cs_tobj, *cs_prg, *cs_tprg, *cs_all;
int error;
int merging;
- unsigned long base;
unsigned tag, length;
- unsigned long summary_pos = 0;
+ unsigned long summary_pos = ~0UL;
/* Totals for this object file. */
memset (&this_object, 0, sizeof (this_object));
@@ -223,6 +225,7 @@ gcov_exit (void)
/* Check function */
if (tag != GCOV_TAG_FUNCTION
+ || length != GCOV_TAG_FUNCTION_LENGTH
|| gcov_read_unsigned () != fi_ptr->ident
|| gcov_read_unsigned () != fi_ptr->checksum)
{
@@ -236,17 +239,14 @@ gcov_exit (void)
for (c_ix = t_ix = 0; t_ix != GCOV_COUNTERS; t_ix++)
if ((1 << t_ix) & gi_ptr->ctr_mask)
{
- unsigned n_counts;
- gcov_merge_fn merge;
+ unsigned n_counts = fi_ptr->n_ctrs[c_ix];
+ gcov_merge_fn merge = gi_ptr->counts[c_ix].merge;
tag = gcov_read_unsigned ();
length = gcov_read_unsigned ();
-
if (tag != GCOV_TAG_FOR_COUNTER (t_ix)
- || fi_ptr->n_ctrs[c_ix] * 8 != length)
+ || length != GCOV_TAG_COUNTER_LENGTH (n_counts))
goto read_mismatch;
- n_counts = fi_ptr->n_ctrs[c_ix];
- merge = gi_ptr->counts[c_ix].merge;
(*merge) (values[c_ix], n_counts);
values[c_ix] += n_counts;
c_ix++;
@@ -255,41 +255,38 @@ gcov_exit (void)
goto read_error;
}
- /* Check object summary */
- if (gcov_read_unsigned () != GCOV_TAG_OBJECT_SUMMARY)
- goto read_mismatch;
- gcov_read_unsigned ();
- gcov_read_summary (&object);
-
- /* Check program summary */
+ /* Check program & object summary */
while (!gcov_is_eof ())
{
- base = gcov_position ();
+ unsigned long base = gcov_position ();
+ int is_program;
+
tag = gcov_read_unsigned ();
- gcov_read_unsigned ();
- if (tag != GCOV_TAG_PROGRAM_SUMMARY)
+ length = gcov_read_unsigned ();
+ is_program = tag == GCOV_TAG_PROGRAM_SUMMARY;
+ if (length != GCOV_TAG_SUMMARY_LENGTH
+ || (!is_program && tag != GCOV_TAG_OBJECT_SUMMARY))
goto read_mismatch;
- gcov_read_summary (&program);
+ gcov_read_summary (is_program ? &program : &object);
if ((error = gcov_is_error ()))
{
read_error:;
fprintf (stderr, error < 0 ?
"profiling:%s:Overflow merging\n" :
- "profiling:%s:Error merging\n",
- gi_ptr->filename);
+ "profiling:%s:Error merging\n", gi_ptr->filename);
goto read_fatal;
}
- if (program.checksum != gcov_crc32)
+ if (!is_program || program.checksum != gcov_crc32)
continue;
summary_pos = base;
break;
}
- gcov_seek (0, 0);
+ gcov_rewrite ();
}
else
memset (&object, 0, sizeof (object));
- if (!summary_pos)
+ if (!(summary_pos + 1))
memset (&program, 0, sizeof (program));
/* Merge the summaries. */
@@ -352,23 +349,22 @@ gcov_exit (void)
((const char *) fi_ptr + fi_stride))
{
/* Announce function. */
- base = gcov_write_tag (GCOV_TAG_FUNCTION);
+ gcov_write_tag_length (GCOV_TAG_FUNCTION, GCOV_TAG_FUNCTION_LENGTH);
gcov_write_unsigned (fi_ptr->ident);
gcov_write_unsigned (fi_ptr->checksum);
- gcov_write_length (base);
for (c_ix = t_ix = 0; t_ix != GCOV_COUNTERS; t_ix++)
if ((1 << t_ix) & gi_ptr->ctr_mask)
{
- unsigned n_counts;
+ unsigned n_counts = fi_ptr->n_ctrs[c_ix];
gcov_type *c_ptr;
- base = gcov_write_tag (GCOV_TAG_FOR_COUNTER (t_ix));
+ gcov_write_tag_length (GCOV_TAG_FOR_COUNTER (t_ix),
+ GCOV_TAG_COUNTER_LENGTH (n_counts));
c_ptr = values[c_ix];
- for (n_counts = fi_ptr->n_ctrs[c_ix]; n_counts--; c_ptr++)
- gcov_write_counter (*c_ptr);
+ while (n_counts--)
+ gcov_write_counter (*c_ptr++);
values[c_ix] = c_ptr;
- gcov_write_length (base);
c_ix++;
}
}
@@ -377,19 +373,13 @@ gcov_exit (void)
gcov_write_summary (GCOV_TAG_OBJECT_SUMMARY, &object);
/* Generate whole program statistics. */
- if (summary_pos)
- gcov_seek (summary_pos, 0);
- else
- gcov_seek_end ();
+ gcov_seek (summary_pos);
gcov_write_summary (GCOV_TAG_PROGRAM_SUMMARY, &program);
if ((error = gcov_close ()))
- {
fprintf (stderr, error < 0 ?
"profiling:%s:Overflow writing\n" :
"profiling:%s:Error writing\n",
gi_ptr->filename);
- gi_ptr->filename = 0;
- }
}
}