Commit 27283c73 by Nathan Sidwell Committed by Nathan Sidwell

gcov.c: Add -a & -u options.

	* gcov.c: Add -a & -u options.
	(struct arc_info): Add local_span, is_call_non_return,
	is_nonlocal_return, is_unconditional flags, remove is_call flag.
	(struct block_info): Add flags, is_call_site, is_nonlocal_return
	members. Make encodings a union with span member.
	(struct function_info): Add blocks_executed, line, src, line_next
	members.
	(struct coverage_info): Make branches a union with blocks member.
	(struct source_info): Add functions member.
	(object_summary, program_count): New global variables.
	(flag_all_blocks, flag_unconditional): New flags.
	(find_source, output_branch_count): New functions.
	(print_usage): Adjust.
	(options): Adjust.
	(process_args): Adjust.
	(read_graph_file) <GCOV_TAG_FUNCTION>: Adjust.
	<GCOV_TAG_BLOCKS>: Read flags.
	<GCOV_TAG_LINES>: Adjust.
	(read_count_file): Process SUMMARY tags.
	(solve_flow_graph): Set is_unconditional and clear is_call_site
	appropriately.
	(add_branch_counts): Adjust. Don't count unconditional branches.
	(add_line_counts): Deal with all-blocks mode, accumulate block
	coverage.
	(accumulate_line_counts): Adjust, generate local spanning tree for
	all-blocks mode.
	(output_lines): Adjust.
	* profile.c (branch_prob): Alter GCOV_FUNCTION_TAG record.
	* doc/gcov.texi: Document.
testsuite:
	* lib/gcov.exp: Adjust call return testing strings.
	* g77.dg/gcov/gcov-1.f: Don't expect unconditional branches.

From-SVN: r65090
parent 212d9313
2003-03-31 Nathan Sidwell <nathan@codesourcery.com>
* gcov.c: Add -a & -u options.
(struct arc_info): Add local_span, is_call_non_return,
is_nonlocal_return, is_unconditional flags, remove is_call flag.
(struct block_info): Add flags, is_call_site, is_nonlocal_return
members. Make encodings a union with span member.
(struct function_info): Add blocks_executed, line, src, line_next
members.
(struct coverage_info): Make branches a union with blocks member.
(struct source_info): Add functions member.
(object_summary, program_count): New global variables.
(flag_all_blocks, flag_unconditional): New flags.
(find_source, output_branch_count): New functions.
(print_usage): Adjust.
(options): Adjust.
(process_args): Adjust.
(read_graph_file) <GCOV_TAG_FUNCTION>: Adjust.
<GCOV_TAG_BLOCKS>: Read flags.
<GCOV_TAG_LINES>: Adjust.
(read_count_file): Process SUMMARY tags.
(solve_flow_graph): Set is_unconditional and clear is_call_site
appropriately.
(add_branch_counts): Adjust. Don't count unconditional branches.
(add_line_counts): Deal with all-blocks mode, accumulate block
coverage.
(accumulate_line_counts): Adjust, generate local spanning tree for
all-blocks mode.
(output_lines): Adjust.
* profile.c (branch_prob): Alter GCOV_FUNCTION_TAG record.
* doc/gcov.texi: Document.
2003-03-31 Kazu Hirata <kazu@cs.umass.edu> 2003-03-31 Kazu Hirata <kazu@cs.umass.edu>
* config/h8300/h8300.md: Organize peephole2's that trasform * config/h8300/h8300.md: Organize peephole2's that trasform
......
...@@ -120,6 +120,7 @@ gcov @r{[}@var{options}@r{]} @var{sourcefile} ...@@ -120,6 +120,7 @@ gcov @r{[}@var{options}@r{]} @var{sourcefile}
@ignore @ignore
@c man begin SYNOPSIS @c man begin SYNOPSIS
gcov [@option{-v}|@option{--version}] [@option{-h}|@option{--help}] gcov [@option{-v}|@option{--version}] [@option{-h}|@option{--help}]
[@option{-a}|@option{--all-blocks}]
[@option{-b}|@option{--branch-probabilities}] [@option{-b}|@option{--branch-probabilities}]
[@option{-c}|@option{--branch-counts}] [@option{-c}|@option{--branch-counts}]
[@option{-n}|@option{--no-output}] [@option{-n}|@option{--no-output}]
...@@ -127,6 +128,7 @@ gcov [@option{-v}|@option{--version}] [@option{-h}|@option{--help}] ...@@ -127,6 +128,7 @@ gcov [@option{-v}|@option{--version}] [@option{-h}|@option{--help}]
[@option{-p}|@option{--preserve-paths}] [@option{-p}|@option{--preserve-paths}]
[@option{-f}|@option{--function-summaries}] [@option{-f}|@option{--function-summaries}]
[@option{-o}|@option{--object-directory} @var{directory|file}] @var{sourcefile} [@option{-o}|@option{--object-directory} @var{directory|file}] @var{sourcefile}
[@option{-u}|@option{--unconditional-branches}]
@c man end @c man end
@c man begin SEEALSO @c man begin SEEALSO
gpl(7), gfdl(7), fsf-funding(7), gcc(1) and the Info entry for @file{gcc}. gpl(7), gfdl(7), fsf-funding(7), gcc(1) and the Info entry for @file{gcc}.
...@@ -145,11 +147,23 @@ exit without doing any further processing. ...@@ -145,11 +147,23 @@ exit without doing any further processing.
Display the @command{gcov} version number (on the standard output), Display the @command{gcov} version number (on the standard output),
and exit without doing any further processing. and exit without doing any further processing.
@item -a
@itemx --all-blocks
Write individual execution counts for every basic block. Normally gcov
outputs execution counts only for the main blocks of a line. With this
option you can determine if blocks within a single line are not being
executed. In this mode each block is shown, and contributes to the
occupancy and execution count of, the first line of source that it
contains. A multi-line block will only contribute to that first line,
and other lines will not be show to contain code, unless a subsequent
block begins on those lines.
@item -b @item -b
@itemx --branch-probabilities @itemx --branch-probabilities
Write branch frequencies to the output file, and write branch summary Write branch frequencies to the output file, and write branch summary
info to the standard output. This option allows you to see how often info to the standard output. This option allows you to see how often
each branch in your program was taken. each branch in your program was taken. Unconditional branches will not
be shown, unless the @option{-u} option is given.
@item -c @item -c
@itemx --branch-counts @itemx --branch-counts
...@@ -192,6 +206,11 @@ source file name, without its extension. If a file is specified here, ...@@ -192,6 +206,11 @@ source file name, without its extension. If a file is specified here,
the data files are named after that file, without its extension. If this the data files are named after that file, without its extension. If this
option is not supplied, it defaults to the current directory. option is not supplied, it defaults to the current directory.
@item -u
@itemx --unconditional-branches
When branch counts are given, include those of unconditional branches.
Unconditional branches are normally not interesting.
@end table @end table
Gcov should be run with the current directory the same as that when you Gcov should be run with the current directory the same as that when you
...@@ -248,26 +267,68 @@ Here is a sample: ...@@ -248,26 +267,68 @@ Here is a sample:
@smallexample @smallexample
-: 0:Source:tmp.c -: 0:Source:tmp.c
-: 0:Object:tmp.bb -: 0:Graph:tmp.bbg
-: 0:Data:tmp.da
-: 0:Runs:1
-: 0:Programs:1
-: 1:#include <stdio.h>
-: 2:
-: 3:int main (void)
function main called 1 returned 1 blocks executed 75%
1: 4:@{
1: 5: int i, total;
-: 6:
1: 7: total = 0;
-: 8:
11: 9: for (i = 0; i < 10; i++)
10: 10: total += i;
-: 11:
1: 12: if (total != 45)
#####: 13: printf ("Failure\n");
-: 14: else
1: 15: printf ("Success\n");
1: 16: return 0;
-: 17:@}
@end smallexample
When you use the @option{-a} option, you will get individual block
counts, and the output looks like this:
@smallexample
-: 0:Source:tmp.c
-: 0:Graph:tmp.bbg
-: 0:Data:tmp.da
-: 0:Runs:1
-: 0:Programs:1
-: 1:#include <stdio.h> -: 1:#include <stdio.h>
-: 2: -: 2:
-: 3:int main (void) -: 3:int main (void)
function main called 1 returned 1 blocks executed 75%
1: 4:@{ 1: 4:@{
1: 4-block 0
1: 5: int i, total; 1: 5: int i, total;
-: 6: -: 6:
1: 7: total = 0; 1: 7: total = 0;
-: 8: -: 8:
11: 9: for (i = 0; i < 10; i++) 11: 9: for (i = 0; i < 10; i++)
11: 9-block 0
10: 10: total += i; 10: 10: total += i;
10: 10-block 0
-: 11: -: 11:
1: 12: if (total != 45) 1: 12: if (total != 45)
1: 12-block 0
#####: 13: printf ("Failure\n"); #####: 13: printf ("Failure\n");
$$$$$: 13-block 0
-: 14: else -: 14: else
1: 15: printf ("Success\n"); 1: 15: printf ("Success\n");
1: 15-block 0
1: 16: return 0; 1: 16: return 0;
1: 17:@} 1: 16-block 0
-: 17:@}
@end smallexample @end smallexample
As you can see, line 13 contains a basic block that was not executed.
@need 450 @need 450
When you use the @option{-b} option, your output looks like this: When you use the @option{-b} option, your output looks like this:
...@@ -284,31 +345,34 @@ Here is a sample of a resulting @file{tmp.c.gcov} file: ...@@ -284,31 +345,34 @@ Here is a sample of a resulting @file{tmp.c.gcov} file:
@smallexample @smallexample
-: 0:Source:tmp.c -: 0:Source:tmp.c
-: 0:Object:tmp.bb -: 0:Graph:tmp.bbg
-: 0:Data:tmp.da
-: 0:Runs:1
-: 0:Programs:1
-: 1:#include <stdio.h> -: 1:#include <stdio.h>
-: 2: -: 2:
-: 3:int main (void) -: 3:int main (void)
function main called 1 returned 1 blocks executed 75%
1: 4:@{ 1: 4:@{
1: 5: int i, total; 1: 5: int i, total;
-: 6: -: 6:
1: 7: total = 0; 1: 7: total = 0;
-: 8: -: 8:
11: 9: for (i = 0; i < 10; i++) 11: 9: for (i = 0; i < 10; i++)
branch 0: taken 90% branch 0 taken 91% (fallthrough)
branch 1: taken 100% branch 1 taken 9%
branch 2: taken 100%
10: 10: total += i; 10: 10: total += i;
-: 11: -: 11:
1: 12: if (total != 45) 1: 12: if (total != 45)
branch 0: taken 100% branch 0 taken 0% (fallthrough)
branch 1 taken 100%
#####: 13: printf ("Failure\n"); #####: 13: printf ("Failure\n");
call 0: never executed call 0 never executed
branch 1: never executed
-: 14: else -: 14: else
1: 15: printf ("Success\n"); 1: 15: printf ("Success\n");
call 0: returns 100% call 0 called 1 returned 100%
1: 16: return 0; 1: 16: return 0;
1: 17:@} -: 17:@}
@end smallexample @end smallexample
For each basic block, a line is printed after the last line of the basic For each basic block, a line is printed after the last line of the basic
......
...@@ -90,6 +90,7 @@ Software Foundation, 59 Temple Place - Suite 330, Boston, MA ...@@ -90,6 +90,7 @@ Software Foundation, 59 Temple Place - Suite 330, Boston, MA
bbg: function-graph* bbg: function-graph*
function-graph: announce_function basic_blocks {arcs | lines}* function-graph: announce_function basic_blocks {arcs | lines}*
announce_function: header string:name int32:checksum announce_function: header string:name int32:checksum
string:source int32:lineno
basic_block: header int32:flags* basic_block: header int32:flags*
arcs: header int32:block_no arc* arcs: header int32:block_no arc*
arc: int32:dest_block int32:flags arc: int32:dest_block int32:flags
...@@ -121,7 +122,8 @@ Software Foundation, 59 Temple Place - Suite 330, Boston, MA ...@@ -121,7 +122,8 @@ Software Foundation, 59 Temple Place - Suite 330, Boston, MA
summary: in32:checksum int32:runs int32:arcs int64:sum int64:max \ summary: in32:checksum int32:runs int32:arcs int64:sum int64:max \
int64:max_sum int64:sum_max int64:max_sum int64:sum_max
The ANNOUNCE_FUNCTION record is the same as that in the BBG file. The ANNOUNCE_FUNCTION record is the same as that in the BBG file,
but without the source location.
The ARC_COUNTS gives the counter values for those arcs that are The ARC_COUNTS gives the counter values for those arcs that are
instrumented. The SUMMARY records give information about the whole instrumented. The SUMMARY records give information about the whole
object file and about the whole program. The checksum is used for object file and about the whole program. The checksum is used for
...@@ -195,7 +197,7 @@ typedef long long gcov_type; ...@@ -195,7 +197,7 @@ typedef long long gcov_type;
(GCOV_TAG_MASK (TAG) > GCOV_TAG_MASK (SUB)) (GCOV_TAG_MASK (TAG) > GCOV_TAG_MASK (SUB))
/* Basic block flags. */ /* Basic block flags. */
#define GCOV_BLOCK_UNEXPECTED (1 << 0) #define GCOV_BLOCK_UNEXPECTED (1 << 1)
/* Arc flags. */ /* Arc flags. */
#define GCOV_ARC_ON_TREE (1 << 0) #define GCOV_ARC_ON_TREE (1 << 0)
......
...@@ -926,7 +926,7 @@ branch_prob () ...@@ -926,7 +926,7 @@ branch_prob ()
unsigned num_edges, ignored_edges; unsigned num_edges, ignored_edges;
struct edge_list *el; struct edge_list *el;
const char *name = IDENTIFIER_POINTER const char *name = IDENTIFIER_POINTER
(DECL_ASSEMBLER_NAME (current_function_decl)); (DECL_ASSEMBLER_NAME (current_function_decl));
profile_info.current_function_cfg_checksum = compute_checksum (); profile_info.current_function_cfg_checksum = compute_checksum ();
for (i = 0; i < profile_info.n_sections; i++) for (i = 0; i < profile_info.n_sections; i++)
...@@ -1086,6 +1086,8 @@ branch_prob () ...@@ -1086,6 +1086,8 @@ branch_prob ()
if (flag_test_coverage && bbg_file) if (flag_test_coverage && bbg_file)
{ {
long offset; long offset;
const char *file = DECL_SOURCE_FILE (current_function_decl);
unsigned line = DECL_SOURCE_LINE (current_function_decl);
/* Announce function */ /* Announce function */
if (gcov_write_unsigned (bbg_file, GCOV_TAG_FUNCTION) if (gcov_write_unsigned (bbg_file, GCOV_TAG_FUNCTION)
...@@ -1094,6 +1096,8 @@ branch_prob () ...@@ -1094,6 +1096,8 @@ branch_prob ()
strlen (name)) strlen (name))
|| gcov_write_unsigned (bbg_file, || gcov_write_unsigned (bbg_file,
profile_info.current_function_cfg_checksum) profile_info.current_function_cfg_checksum)
|| gcov_write_string (bbg_file, file, strlen (file))
|| gcov_write_unsigned (bbg_file, line)
|| gcov_write_length (bbg_file, offset)) || gcov_write_length (bbg_file, offset))
goto bbg_error; goto bbg_error;
......
2003-03-31 Nathan Sidwell <nathan@codesourcery.com>
* lib/gcov.exp: Adjust call return testing strings.
* g77.dg/gcov/gcov-1.f: Don't expect unconditional branches.
2003-03-31 Roger Sayle <roger@eyesopen.com> 2003-03-31 Roger Sayle <roger@eyesopen.com>
* gcc.dg/builtins-3.c: Add new tests for sin and cos. * gcc.dg/builtins-3.c: Add new tests for sin and cos.
......
...@@ -118,9 +118,7 @@ C Test simple GOTO. ...@@ -118,9 +118,7 @@ C Test simple GOTO.
if (f .ne. 0) goto 100 ! count(2) if (f .ne. 0) goto 100 ! count(2)
! branch(end) ! branch(end)
gt1 = 1 ! count(1) gt1 = 1 ! count(1)
! branch(100)
goto 101 ! count(1) goto 101 ! count(1)
! branch(end)
100 gt1 = 2 ! count(1) 100 gt1 = 2 ! count(1)
101 continue ! count(2) 101 continue ! count(2)
end end
...@@ -136,9 +134,7 @@ C Test simple GOTO again, this time out of a DO loop. ...@@ -136,9 +134,7 @@ C Test simple GOTO again, this time out of a DO loop.
if (i .eq. f) goto 100 ! count(19) if (i .eq. f) goto 100 ! count(19)
end do end do
gt2 = 4 ! count(1) gt2 = 4 ! count(1)
! branch(100)
goto 101 ! count(1) goto 101 ! count(1)
! branch(end)
100 gt2 = 8 ! count(1) 100 gt2 = 8 ! count(1)
101 continue ! count(2) 101 continue ! count(2)
end end
...@@ -149,17 +145,13 @@ C Test computed GOTO. ...@@ -149,17 +145,13 @@ C Test computed GOTO.
integer i integer i
goto (101, 102, 103, 104), i ! count(2) goto (101, 102, 103, 104), i ! count(2)
gt3 = 8 ! count(1) gt3 = 8 ! count(1)
! branch(100)
goto 105 ! count(1) goto 105 ! count(1)
! branch(end)
101 gt3 = 1024 101 gt3 = 1024
goto 105 goto 105
102 gt3 = 2048 102 gt3 = 2048
goto 105 goto 105
103 gt3 = 16 ! count(1) 103 gt3 = 16 ! count(1)
! branch(100)
goto 105 ! count(1) goto 105 ! count(1)
! branch(end)
104 gt3 = 4096 104 gt3 = 4096
goto 105 goto 105
105 gt3 = gt3 * 2 ! count(2) 105 gt3 = gt3 * 2 ! count(2)
......
...@@ -168,7 +168,7 @@ proc verify-calls { testcase file } { ...@@ -168,7 +168,7 @@ proc verify-calls { testcase file } {
set n 0 set n 0
while { [gets $fd line] >= 0 } { while { [gets $fd line] >= 0 } {
regexp "^\[^:\]+: *(\[0-9\]+):" "$line" all n regexp "^\[^:\]+: *(\[0-9\]+):" "$line" all n
if [regexp "returns" $line] { if [regexp "return" $line] {
verbose "Processing returns line $n: $line" 3 verbose "Processing returns line $n: $line" 3
if [regexp "returns\\((\[0-9 \]+)\\)" "$line" all new_shouldbe] { if [regexp "returns\\((\[0-9 \]+)\\)" "$line" all new_shouldbe] {
# All percentages in the current list should have been seen. # All percentages in the current list should have been seen.
...@@ -179,12 +179,12 @@ proc verify-calls { testcase file } { ...@@ -179,12 +179,12 @@ proc verify-calls { testcase file } {
} }
# Record the percentages to check for. # Record the percentages to check for.
set shouldbe $new_shouldbe set shouldbe $new_shouldbe
} elseif [regexp "call +\[0-9\]+ returns (-\[0-9\]+)%" "$line" \ } elseif [regexp "call +\[0-9\]+ returned (-\[0-9\]+)%" "$line" \
all returns] { all returns] {
# Percentages should never be negative. # Percentages should never be negative.
fail "$n: negative percentage: $returns" fail "$n: negative percentage: $returns"
incr failed incr failed
} elseif [regexp "call +\[0-9\]+ returns (\[0-9\]+)%" "$line" \ } elseif [regexp "call +\[0-9\]+ returned (\[0-9\]+)%" "$line" \
all returns] { all returns] {
# For branches we check that percentages are not greater than # For branches we check that percentages are not greater than
# 100 but call return percentages can be, as for setjmp(), so # 100 but call return percentages can be, as for setjmp(), so
......
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