From 5014df5d02d9d90bb0a749a035f86bbfbe94bfa4 Mon Sep 17 00:00:00 2001 From: nathan Date: Mon, 7 Nov 2011 18:14:46 +0000 Subject: libgcc/ * libgcov.c (struct gcov_fn_buffer): New struct. (buffer_fn_data): New helper. (gcov_exit): Rework for new gcov data structures. gcc/ * gcov.c (object_summary): Replace with ... (object_runs): ... this. (process_file): Remove functions with no data. (generate_results): Ignore files with no lines. (release_function): New helper, broken out of ... (release_structures): ... here. Use it. (read_count_file): Adjust for new data file format. (output_lines): Use object_runs. * gcov-io.h (GCOV_TAG_OBJECT_SUMMARY): Obsolete. (struct gcov_ctr_info): Move definition. (struct gcov_fn_info): Add key field, use gcov_ctr_info for trailing array. (struct gcov_info): Add merge function array, remove mask and counts. Trailing array is array of pointers to function info. * coverage.c (struct function_list): Replace counter numbers with counter arrays. Add fndecl field. GTYify. (counts_entry): Remove chain workspace. (functions_head): GTYify. (prg_n_ctrs): Remove. (fn_v_ctrs): New. (tree_ctr_tables): Remove. (read_counts_file): Cope with blank entries and expect program summaries before functions. Don't warn on missing entries. (coverage_counter_alloc): Allocate individual function arrays. (tree_coverage_counter_ref, tree_coverage_counter_addr): Adjust for individual function arrays. (coverage_end_function): GTYify function list object. Finalize function's counter arrays. (build_var): New. Create a counter-related variable with appropriate linkage. (build_fn_info_type): Adjust for new runtime structure. (build_fn_info_value): Rename to ... (build_fn_info): ... here. Build new format data. (build_ctr_info_type, build_ctr_info_value): Remove. (build_info_type): New. Build new format data structure. (build_info): Adjust for new format data. (create_coverage): Likewise. * gcov-dump.c (tag_function): Recognize placeholders. gcc/testsuite/ * gcc.dg/profile-dir-1.c: Adjust final scan. * gcc.dg/profile-dir-2.c: Adjust final scan. * gcc.dg/profile-dir-3.c: Adjust final scan. * gcc.misc-tests/gcov.exp: Adjust regexp. * gcc.misc-tests/gcov-12.c: New. * gcc.misc-tests/gcov-13.c: New. * gcc.misc-tests/gcovpart-13b.c: New. * gcc.misc-tests/gcov-14.c: New. git-svn-id: svn+ssh://gcc.gnu.org/svn/gcc/trunk@181105 138bc75d-0d04-0410-961f-82ee72b054a4 --- gcc/gcov.c | 126 +++++++++++++++++++++++++++++++++++++------------------------ 1 file changed, 76 insertions(+), 50 deletions(-) (limited to 'gcc/gcov.c') diff --git a/gcc/gcov.c b/gcc/gcov.c index 94a1c350c80..6711f7e6a47 100644 --- a/gcc/gcov.c +++ b/gcc/gcov.c @@ -265,7 +265,7 @@ static unsigned source_index; /* This holds data summary information. */ -static struct gcov_summary object_summary; +static unsigned object_runs; static unsigned program_count; /* Modification time of graph file. */ @@ -362,6 +362,7 @@ static int output_branch_count (FILE *, int, const arc_t *); static void output_lines (FILE *, const source_t *); static char *make_gcov_file_name (const char *, const char *); static void release_structures (void); +static void release_function (function_t *); extern int main (int, char **); int @@ -537,7 +538,7 @@ static void process_file (const char *file_name) { function_t *fn; - function_t *fn_p; + function_t **fn_p; function_t *old_functions; /* Save and clear the list of current functions. They will be appended @@ -558,11 +559,25 @@ process_file (const char *file_name) if (read_count_file ()) return; - for (fn_p = NULL, fn = functions; fn; fn_p = fn, fn = fn->next) - solve_flow_graph (fn); + fn_p = &functions; + while ((fn = *fn_p) != NULL) + { + if (fn->counts) + { + solve_flow_graph (fn); + fn_p = &fn->next; + } + else + { + /* The function was not in the executable -- some other + instance must have been selected. */ + function_t *next = fn->next; + release_function (fn); + *fn_p = next; + } + } - if (fn_p) - fn_p->next = old_functions; + *fn_p = old_functions; } static void @@ -591,7 +606,7 @@ generate_results (const char *file_name) { accumulate_line_counts (src); function_summary (&src->coverage, "File"); - if (flag_gcov_file) + if (flag_gcov_file && src->coverage.lines) { char *gcov_file_name = make_gcov_file_name (file_name, src->name); FILE *gcov_file = fopen (gcov_file_name, "w"); @@ -615,6 +630,28 @@ generate_results (const char *file_name) } } +/* Release a function structure */ + +static void +release_function (function_t *fn) +{ + unsigned ix; + block_t *block; + + for (ix = fn->num_blocks, block = fn->blocks; ix--; block++) + { + arc_t *arc, *arc_n; + + for (arc = block->succ; arc; arc = arc_n) + { + arc_n = arc->succ_next; + free (arc); + } + } + free (fn->blocks); + free (fn->counts); +} + /* Release all memory used. */ static void @@ -633,22 +670,8 @@ release_structures (void) while ((fn = functions)) { - unsigned ix; - block_t *block; - functions = fn->next; - for (ix = fn->num_blocks, block = fn->blocks; ix--; block++) - { - arc_t *arc, *arc_n; - - for (arc = block->succ; arc; arc = arc_n) - { - arc_n = arc->succ_next; - free (arc); - } - } - free (fn->blocks); - free (fn->counts); + release_function (fn); } } @@ -1085,35 +1108,39 @@ read_count_file (void) unsigned length = gcov_read_unsigned (); unsigned long base = gcov_position (); - if (tag == GCOV_TAG_OBJECT_SUMMARY) - gcov_read_summary (&object_summary); - else if (tag == GCOV_TAG_PROGRAM_SUMMARY) - program_count++; - else if (tag == GCOV_TAG_FUNCTION) + if (tag == GCOV_TAG_PROGRAM_SUMMARY) { - { - unsigned ident = gcov_read_unsigned (); - struct function_info *fn_n = functions; + struct gcov_summary summary; + gcov_read_summary (&summary); + object_runs += summary.ctrs[GCOV_COUNTER_ARCS].runs; + program_count++; + } + else if (tag == GCOV_TAG_FUNCTION && !length) + ; /* placeholder */ + else if (tag == GCOV_TAG_FUNCTION && length == GCOV_TAG_FUNCTION_LENGTH) + { + unsigned ident; + struct function_info *fn_n; - /* Try to find the function in the list. - To speed up the search, first start from the last function - found. */ - for (fn = fn ? fn->next : NULL; ; fn = fn->next) - { - if (fn) - ; - else if ((fn = fn_n)) - fn_n = NULL; - else - { - fnotice (stderr, "%s:unknown function '%u'\n", - da_file_name, ident); - break; - } - if (fn->ident == ident) + /* Try to find the function in the list. To speed up the + search, first start from the last function found. */ + ident = gcov_read_unsigned (); + fn_n = functions; + for (fn = fn ? fn->next : NULL; ; fn = fn->next) + { + if (fn) + ; + else if ((fn = fn_n)) + fn_n = NULL; + else + { + fnotice (stderr, "%s:unknown function '%u'\n", + da_file_name, ident); break; - } - } + } + if (fn->ident == ident) + break; + } if (!fn) ; @@ -1908,8 +1935,7 @@ output_lines (FILE *gcov_file, const source_t *src) fprintf (gcov_file, "%9s:%5d:Graph:%s\n", "-", 0, bbg_file_name); fprintf (gcov_file, "%9s:%5d:Data:%s\n", "-", 0, no_data_file ? "-" : da_file_name); - fprintf (gcov_file, "%9s:%5d:Runs:%u\n", "-", 0, - object_summary.ctrs[GCOV_COUNTER_ARCS].runs); + fprintf (gcov_file, "%9s:%5d:Runs:%u\n", "-", 0, object_runs); } fprintf (gcov_file, "%9s:%5d:Programs:%u\n", "-", 0, program_count); -- cgit v1.2.1