Commit ec4a0419 by Zdenek Dvorak Committed by Zdenek Dvorak

gcov-io.h (gcov_save_position, [...]): Modified to enable reading/ writing of…

gcov-io.h (gcov_save_position, [...]): Modified to enable reading/ writing of whole .da file just once.

	* gcov-io.h (gcov_save_position, gcov_reserve_length, gcov_resync,
	gcov_skip, gcov_skip_string, gcov_write_unsigned, gcov_write_counter,
	gcov_write_string, gcov_read_unsigned, gcov_read_counter,
	gcov_read_string, gcov_write_length): Modified to enable reading/
	writing of whole .da file just once.
	(da_file_open, da_file_close, da_file_eof, da_file_error,
	da_file_position, da_file_seek, da_file_write, da_file_read): New
	functions.
	(actual_da_file, actual_da_file_position, actual_da_file_length,
	actual_da_file_buffer, actual_da_file_buffer_size): New static
	functions.
	* libgcov.c (gcov_exit): Modified to read/write the whole .da file at
	just once.

From-SVN: r63800
parent 79dbeefc
2003-03-04 Zdenek Dvorak <rakdver@atrey.karlin.mff.cuni.cz>
* gcov-io.h (gcov_save_position, gcov_reserve_length, gcov_resync,
gcov_skip, gcov_skip_string, gcov_write_unsigned, gcov_write_counter,
gcov_write_string, gcov_read_unsigned, gcov_read_counter,
gcov_read_string, gcov_write_length): Modified to enable reading/
writing of whole .da file just once.
(da_file_open, da_file_close, da_file_eof, da_file_error,
da_file_position, da_file_seek, da_file_write, da_file_read): New
functions.
(actual_da_file, actual_da_file_position, actual_da_file_length,
actual_da_file_buffer, actual_da_file_buffer_size): New static
functions.
* libgcov.c (gcov_exit): Modified to read/write the whole .da file at
just once.
2003-03-04 Andreas Schwab <schwab@suse.de>
* config/m68k/m68k.c (m68k_output_function_prologue): Fix CFA
......
......@@ -41,12 +41,12 @@ Software Foundation, 59 Temple Place - Suite 330, Boston, MA
#undef NULL /* Avoid errors if stdio.h and our stddef.h mismatch. */
#include <stdio.h>
#include "gcov-io.h"
#include <string.h>
#if defined (TARGET_HAS_F_SETLKW)
#include <fcntl.h>
#include <errno.h>
#endif
#include "gcov-io.h"
/* Chain of per-object gcov structures. */
static struct gcov_info *gcov_list;
......@@ -106,7 +106,6 @@ gcov_exit (void)
for (ptr = gcov_list; ptr; ptr = ptr->next)
{
FILE *da_file;
struct gcov_summary object;
struct gcov_summary local_prg;
int merging = 0;
......@@ -154,39 +153,27 @@ gcov_exit (void)
memset (&object, 0, sizeof (object));
/* Open for modification */
if ((da_file = fopen (ptr->filename, "r+b")))
merging = 1;
else if ((da_file = fopen (ptr->filename, "w+b")))
;
else
if (!da_file_open (ptr->filename, &merging))
{
fprintf (stderr, "profiling:%s:Cannot open\n", ptr->filename);
ptr->filename = 0;
continue;
}
#if defined (TARGET_HAS_F_SETLKW)
/* After a fork, another process might try to read and/or write
the same file simultaneously. So if we can, lock the file to
avoid race conditions. */
while (fcntl (fileno (da_file), F_SETLKW, &s_flock)
&& errno == EINTR)
continue;
#endif
if (merging)
{
/* Merge data from file. */
if (gcov_read_unsigned (da_file, &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",
ptr->filename);
read_fatal:;
fclose (da_file);
da_file_close ();
ptr->filename = 0;
continue;
}
if (gcov_read_unsigned (da_file, &length) || length != GCOV_VERSION)
if (gcov_read_unsigned (0, &length) || length != GCOV_VERSION)
{
gcov_version_mismatch (ptr, length);
goto read_fatal;
......@@ -196,8 +183,8 @@ gcov_exit (void)
for (ix = ptr->n_functions, fn_info = ptr->functions;
ix--; fn_info++)
{
if (gcov_read_unsigned (da_file, &tag)
|| gcov_read_unsigned (da_file, &length))
if (gcov_read_unsigned (0, &tag)
|| gcov_read_unsigned (0, &length))
{
read_error:;
fprintf (stderr, "profiling:%s:Error merging\n",
......@@ -214,9 +201,9 @@ gcov_exit (void)
goto read_fatal;
}
if (gcov_read_unsigned (da_file, &flength)
|| gcov_skip_string (da_file, flength)
|| gcov_read_unsigned (da_file, &checksum))
if (gcov_read_unsigned (0, &flength)
|| gcov_skip_string (0, flength)
|| gcov_read_unsigned (0, &checksum))
goto read_error;
if (flength != strlen (fn_info->name)
|| checksum != fn_info->checksum)
......@@ -227,46 +214,51 @@ gcov_exit (void)
f_sect_index < fn_info->n_counter_sections;
f_sect_index++)
{
if (gcov_read_unsigned (da_file, &tag)
|| gcov_read_unsigned (da_file, &length))
unsigned n_counters;
if (gcov_read_unsigned (0, &tag)
|| gcov_read_unsigned (0, &length))
goto read_error;
for (sect_index = 0;
sect_index < ptr->n_counter_sections;
sect_index++)
if (ptr->counter_sections[sect_index].tag == tag)
break;
if (fn_info->counter_sections[f_sect_index].tag != tag
|| sect_index == ptr->n_counter_sections
|| length / 8 != fn_info->counter_sections[f_sect_index].n_counters)
if (sect_index == ptr->n_counter_sections
|| fn_info->counter_sections[f_sect_index].tag != tag)
goto read_mismatch;
for (jx = fn_info->counter_sections[f_sect_index].n_counters;
jx--; counters[sect_index]++)
if (gcov_read_counter (da_file, &count))
goto read_error;
n_counters = fn_info->counter_sections[f_sect_index].n_counters;
if (n_counters != length / 8)
goto read_mismatch;
for (jx = 0; jx < n_counters; jx++)
if (gcov_read_counter (0, &count))
goto read_error;
else
*counters[sect_index] += count;
counters[sect_index][jx] += count;
counters[sect_index] += n_counters;
}
}
/* Check object summary */
if (gcov_read_unsigned (da_file, &tag)
|| gcov_read_unsigned (da_file, &length))
if (gcov_read_unsigned (0, &tag)
|| gcov_read_unsigned (0, &length))
goto read_error;
if (tag != GCOV_TAG_OBJECT_SUMMARY)
goto read_mismatch;
if (gcov_read_summary (da_file, &object))
if (gcov_read_summary (0, &object))
goto read_error;
/* Check program summary */
while (1)
{
long base = ftell (da_file);
long base = da_file_position (0);
if (gcov_read_unsigned (da_file, &tag)
|| gcov_read_unsigned (da_file, &length))
if (gcov_read_unsigned (0, &tag)
|| gcov_read_unsigned (0, &length))
{
if (feof (da_file))
if (da_file_eof ())
break;
goto read_error;
}
......@@ -274,7 +266,7 @@ gcov_exit (void)
&& tag != GCOV_TAG_PLACEHOLDER_SUMMARY
&& tag != GCOV_TAG_INCORRECT_SUMMARY)
goto read_mismatch;
if (gcov_read_summary (da_file, &local_prg))
if (gcov_read_summary (0, &local_prg))
goto read_error;
if (local_prg.checksum != program.checksum)
continue;
......@@ -301,7 +293,7 @@ gcov_exit (void)
ptr->wkspc = base;
break;
}
fseek (da_file, 0, SEEK_SET);
da_file_seek (0, 0, SEEK_SET);
}
object.runs++;
......@@ -313,12 +305,12 @@ gcov_exit (void)
/* Write out the data. */
if (/* magic */
gcov_write_unsigned (da_file, GCOV_DATA_MAGIC)
gcov_write_unsigned (0, GCOV_DATA_MAGIC)
/* version number */
|| gcov_write_unsigned (da_file, GCOV_VERSION))
|| gcov_write_unsigned (0, GCOV_VERSION))
{
write_error:;
fclose (da_file);
da_file_close ();
fprintf (stderr, "profiling:%s:Error writing\n", ptr->filename);
ptr->filename = 0;
continue;
......@@ -330,14 +322,14 @@ gcov_exit (void)
for (ix = ptr->n_functions, fn_info = ptr->functions; ix--; fn_info++)
{
/* Announce function. */
if (gcov_write_unsigned (da_file, GCOV_TAG_FUNCTION)
|| !(base = gcov_reserve_length (da_file))
if (gcov_write_unsigned (0, GCOV_TAG_FUNCTION)
|| !(base = gcov_reserve_length (0))
/* function name */
|| gcov_write_string (da_file, fn_info->name,
|| gcov_write_string (0, fn_info->name,
strlen (fn_info->name))
/* function checksum */
|| gcov_write_unsigned (da_file, fn_info->checksum)
|| gcov_write_length (da_file, base))
|| gcov_write_unsigned (0, fn_info->checksum)
|| gcov_write_length (0, base))
goto write_error;
/* counters. */
......@@ -354,8 +346,8 @@ gcov_exit (void)
if (sect_index == ptr->n_counter_sections)
abort ();
if (gcov_write_unsigned (da_file, tag)
|| !(base = gcov_reserve_length (da_file)))
if (gcov_write_unsigned (0, tag)
|| !(base = gcov_reserve_length (0)))
goto write_error;
for (jx = fn_info->counter_sections[f_sect_index].n_counters; jx--;)
......@@ -368,43 +360,41 @@ gcov_exit (void)
if (object.arc_max_sum < count)
object.arc_max_sum = count;
}
if (gcov_write_counter (da_file, count))
if (gcov_write_counter (0, count))
goto write_error; /* RIP Edsger Dijkstra */
}
if (gcov_write_length (da_file, base))
if (gcov_write_length (0, base))
goto write_error;
}
}
/* Object file summary. */
if (gcov_write_summary (da_file, GCOV_TAG_OBJECT_SUMMARY, &object))
if (gcov_write_summary (0, GCOV_TAG_OBJECT_SUMMARY, &object))
goto write_error;
if (merging >= 0)
{
if (fseek (da_file, 0, SEEK_END))
if (da_file_seek (0, 0, SEEK_END))
goto write_error;
ptr->wkspc = ftell (da_file);
if (gcov_write_summary (da_file, GCOV_TAG_PLACEHOLDER_SUMMARY,
ptr->wkspc = da_file_position (0);
if (gcov_write_summary (0, GCOV_TAG_PLACEHOLDER_SUMMARY,
&program))
goto write_error;
}
else if (ptr->wkspc)
{
/* Zap trailing program summary */
if (fseek (da_file, ptr->wkspc, SEEK_SET))
if (da_file_seek (0, ptr->wkspc, SEEK_SET))
goto write_error;
if (!local_prg.runs)
ptr->wkspc = 0;
if (gcov_write_unsigned (da_file,
local_prg.runs ? GCOV_TAG_PLACEHOLDER_SUMMARY
: GCOV_TAG_INCORRECT_SUMMARY))
if (gcov_write_unsigned (0, local_prg.runs
? GCOV_TAG_PLACEHOLDER_SUMMARY
: GCOV_TAG_INCORRECT_SUMMARY))
goto write_error;
}
if (fflush (da_file))
goto write_error;
if (fclose (da_file))
if (da_file_close ())
{
fprintf (stderr, "profiling:%s:Error closing\n", ptr->filename);
ptr->filename = 0;
......
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