Skip to content

Commit

Permalink
geninfo: Fix missing FN: entries in result files
Browse files Browse the repository at this point in the history
geninfo sometimes fails to correctly collect function starting lines for
some source files, resulting in output files with missing FN: lines.
Also such functions are missing from the function list in HTML output.

The problem occurs when
  a) multiple source files contribute to a function implementation (e.g.
     via including code), and
  b) the source file that contains the initial function definition
     is not the source file that contains the most function
     definitions

The problem occurs due to a heuristic in function graph_find_base() that
incorrectly determines the source file for a function in this situation.

Fix this by using the first file that contributes to a function as the
base source file for that function. Only apply this change to data
collected using GCC versions 4 and above since earlier versions did not
produce stable file orders in graph files.

Signed-off-by: Peter Oberparleiter <[email protected]>
Reported-by: Joshua Cranmer
  • Loading branch information
oberpar committed Feb 28, 2019
1 parent 74bae96 commit 29814f1
Showing 1 changed file with 15 additions and 8 deletions.
23 changes: 15 additions & 8 deletions bin/geninfo
Original file line number Diff line number Diff line change
Expand Up @@ -184,7 +184,7 @@ sub sort_uniq(@);
sub sort_uniq_lex(@);
sub graph_cleanup($);
sub graph_find_base($);
sub graph_from_bb($$$);
sub graph_from_bb($$$$);
sub graph_add_order($$$);
sub read_bb_word(*;$);
sub read_bb_value(*;$);
Expand Down Expand Up @@ -2958,9 +2958,13 @@ sub graph_find_base($)
}

#
# graph_from_bb(bb, fileorder, bb_filename)
# graph_from_bb(bb, fileorder, bb_filename, fileorder_first)
#
# Convert data from bb to the graph format and list of instrumented lines.
#
# If FILEORDER_FIRST is set, use fileorder data to determine a functions
# base source file.
#
# Returns (instr, graph).
#
# bb : function name -> file data
Expand All @@ -2978,9 +2982,9 @@ sub graph_find_base($)
# line data : [ line1, line2, ... ]
#

sub graph_from_bb($$$)
sub graph_from_bb($$$$)
{
my ($bb, $fileorder, $bb_filename) = @_;
my ($bb, $fileorder, $bb_filename, $fileorder_first) = @_;
my $graph = {};
my $instr = {};
my $basefile;
Expand All @@ -2997,7 +3001,8 @@ sub graph_from_bb($$$)
$order = $fileorder->{$func};

# Account for lines in functions
if (defined($basefile) && defined($filedata->{$basefile})) {
if (defined($basefile) && defined($filedata->{$basefile}) &&
!$fileorder_first) {
# If the basefile contributes to this function,
# account this function to the basefile.
$graph->{$basefile}->{$func} = $filedata->{$basefile};
Expand Down Expand Up @@ -3159,7 +3164,8 @@ sub read_bb($)
}
}
close(HANDLE);
($instr, $graph) = graph_from_bb($bb, $fileorder, $bb_filename);

($instr, $graph) = graph_from_bb($bb, $fileorder, $bb_filename, 0);
graph_cleanup($graph);

return ($instr, $graph);
Expand Down Expand Up @@ -3347,7 +3353,8 @@ sub read_bbg($)
}
}
close(HANDLE);
($instr, $graph) = graph_from_bb($bb, $fileorder, $bbg_filename);
($instr, $graph) = graph_from_bb($bb, $fileorder, $bbg_filename, 0);

graph_cleanup($graph);

return ($instr, $graph);
Expand Down Expand Up @@ -3731,7 +3738,7 @@ sub read_gcno($)
remove_fn_from_hash($bb, \@artificial_fns);
remove_fn_from_hash($fileorder, \@artificial_fns);

($instr, $graph) = graph_from_bb($bb, $fileorder, $gcno_filename);
($instr, $graph) = graph_from_bb($bb, $fileorder, $gcno_filename, 1);
graph_cleanup($graph);

return ($instr, $graph);
Expand Down

0 comments on commit 29814f1

Please sign in to comment.