Skip to content

Commit c85e73a

Browse files
Peter Oberparleiteroberpar
authored andcommitted
genhtml: merge function data during demangling
Merge function execution counts when multiple function names demangle to the same name.
1 parent 2dfafc9 commit c85e73a

File tree

1 file changed

+43
-35
lines changed

1 file changed

+43
-35
lines changed

bin/genhtml

Lines changed: 43 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,7 @@ use Digest::MD5 qw(md5_base64);
7373

7474
# Global constants
7575
our $title = "LCOV - code coverage report";
76-
our $lcov_version = 'LCOV version 1.11 pre (CVS $Revision: 1.72 $)';
76+
our $lcov_version = 'LCOV version 1.11 pre (CVS $Revision: 1.73 $)';
7777
our $lcov_url = "http://ltp.sourceforge.net/coverage/lcov.php";
7878
our $tool_name = basename($0);
7979

@@ -706,6 +706,8 @@ sub get_fn_list($)
706706
# rename_functions(info, conv)
707707
#
708708
# Rename all function names in INFO according to CONV: OLD_NAME -> NEW_NAME.
709+
# In case two functions demangle to the same name, assume that they are
710+
# different object code implementations for the same source function.
709711
#
710712

711713
sub rename_functions($$)
@@ -719,57 +721,66 @@ sub rename_functions($$)
719721
my $sumfnccount;
720722
my %newfuncdata;
721723
my %newsumfnccount;
724+
my $f_found;
725+
my $f_hit;
722726

723727
# funcdata: function name -> line number
724728
$funcdata = $data->{"func"};
725-
foreach my $fn_name (keys(%{$funcdata})) {
726-
$newfuncdata{$conv->{$fn_name}} = $funcdata->{$fn_name};
729+
foreach my $fn (keys(%{$funcdata})) {
730+
my $cn = $conv->{$fn};
731+
732+
# Abort if two functions on different lines map to the
733+
# same demangled name.
734+
if (defined($newfuncdata{$cn}) &&
735+
$newfuncdata{$cn} != $funcdata->{$fn}) {
736+
die("ERROR: Demangled function name $fn ".
737+
" maps to different lines (".
738+
$newfuncdata{$cn}." vs ".
739+
$funcdata->{$fn}.")\n");
740+
}
741+
$newfuncdata{$cn} = $funcdata->{$fn};
727742
}
728743
$data->{"func"} = \%newfuncdata;
729744

730745
# testfncdata: test name -> testfnccount
731746
# testfnccount: function name -> execution count
732747
$testfncdata = $data->{"testfnc"};
733-
foreach my $test_name (keys(%{$testfncdata})) {
734-
my $testfnccount = $testfncdata->{$test_name};
748+
foreach my $tn (keys(%{$testfncdata})) {
749+
my $testfnccount = $testfncdata->{$tn};
735750
my %newtestfnccount;
736751

737-
foreach my $fn_name (keys(%{$testfnccount})) {
738-
$newtestfnccount{$conv->{$fn_name}} =
739-
$testfnccount->{$fn_name};
752+
foreach my $fn (keys(%{$testfnccount})) {
753+
my $cn = $conv->{$fn};
754+
755+
# Add counts for different functions that map
756+
# to the same name.
757+
$newtestfnccount{$cn} +=
758+
$testfnccount->{$fn};
740759
}
741-
$testfncdata->{$test_name} = \%newtestfnccount;
760+
$testfncdata->{$tn} = \%newtestfnccount;
742761
}
743762

744763
# sumfnccount: function name -> execution count
745764
$sumfnccount = $data->{"sumfnc"};
746-
foreach my $fn_name (keys(%{$sumfnccount})) {
747-
$newsumfnccount{$conv->{$fn_name}} =
748-
$sumfnccount->{$fn_name};
765+
foreach my $fn (keys(%{$sumfnccount})) {
766+
my $cn = $conv->{$fn};
767+
768+
# Add counts for different functions that map
769+
# to the same name.
770+
$newsumfnccount{$cn} += $sumfnccount->{$fn};
749771
}
750772
$data->{"sumfnc"} = \%newsumfnccount;
751-
}
752-
}
753773

754-
#
755-
# check_unique_conv(CONV)
756-
#
757-
# Check that there is no A in CONV: A -> B where C -> B.
758-
#
759-
760-
sub check_unique_conv($)
761-
{
762-
my ($conv) = @_;
763-
my %rconv;
764-
765-
foreach my $fn_name (keys(%{$conv})) {
766-
my $c = $conv->{$fn_name};
767-
768-
if (defined($rconv{$c})) {
769-
die("ERROR: non-unique c++filt output for ".
770-
"'$fn_name' and '$rconv{$c}!\n");
774+
# Update function found and hit counts since they may have
775+
# changed
776+
$f_found = 0;
777+
$f_hit = 0;
778+
foreach my $fn (keys(%newsumfnccount)) {
779+
$f_found++;
780+
$f_hit++ if ($newsumfnccount{$fn} > 0);
771781
}
772-
$rconv{$c} = $fn_name;
782+
$data->{"f_found"} = $f_found;
783+
$data->{"f_hit"} = $f_hit;
773784
}
774785
}
775786

@@ -821,9 +832,6 @@ sub demangle_cpp($)
821832
$changed++ if ($fn_list->[$i] ne $fn_list_demangled[$i]);
822833
}
823834

824-
# Should not be necessary but could silently produce incorrect results
825-
check_unique_conv(\%demangled);
826-
827835
info("Demangling $changed function names\n");
828836

829837
# Change all occurrences of function names in INFO

0 commit comments

Comments
 (0)