Skip to content

Commit 3a68239

Browse files
skrapoberpar
authored andcommitted
lcov: make geninfo compatible with LLVM's gcov
These changes are needed to make geninfo compatible with LLVM's gcov: * Use --version rather than -v to probe version info * Convert LLVM gcov version numbers to the GCC gcov version they emulate * Translate short options into their equivalent long option capabilities Signed-off-by: Jonah Petri <[email protected]>
1 parent a74bdee commit 3a68239

File tree

1 file changed

+49
-8
lines changed

1 file changed

+49
-8
lines changed

bin/geninfo

Lines changed: 49 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,7 @@ if( $^O eq "msys" )
6161
}
6262

6363
# Constants
64-
our $lcov_version = 'LCOV version 1.11 pre (CVS $Revision: 1.126 $)';
64+
our $lcov_version = 'LCOV version 1.11 pre (CVS $Revision: 1.127 $)';
6565
our $lcov_url = "http://ltp.sourceforge.net/coverage/lcov.php";
6666
our $gcov_tool = "gcov";
6767
our $tool_name = basename($0);
@@ -1894,9 +1894,14 @@ sub get_gcov_version()
18941894
my $version_string;
18951895
my $result;
18961896

1897-
open(GCOV_PIPE, "-|", "$gcov_tool -v")
1897+
open(GCOV_PIPE, "-|", "$gcov_tool --version")
18981898
or die("ERROR: cannot retrieve gcov version!\n");
18991899
$version_string = <GCOV_PIPE>;
1900+
# LLVM gcov keeps version information on the second line.
1901+
# For example, gcov --version yields:
1902+
# LLVM (http://llvm.org/):
1903+
# LLVM version 3.4svn
1904+
$version_string = <GCOV_PIPE> if ($version_string =~ /LLVM/);
19001905
close(GCOV_PIPE);
19011906

19021907
# Remove version information in parenthesis to cope with the following:
@@ -1918,6 +1923,21 @@ sub get_gcov_version()
19181923
$result = $1 << 16 | $2 << 8;
19191924
}
19201925
}
1926+
if ($version_string =~ /LLVM/)
1927+
{
1928+
# Map LLVM versions to the version of GCC gcov which
1929+
# they emulate
1930+
if ($result >= 0x030400)
1931+
{
1932+
info("Found LLVM gcov version 3.4, which emulates gcov version 4.2\n");
1933+
$result = 0x040200;
1934+
}
1935+
else
1936+
{
1937+
warn("This version of LLVM's gcov is unknown. Assuming it emulates GCC gcov version 4.2.\n");
1938+
$result = 0x040200;
1939+
}
1940+
}
19211941
return ($result, $version_string);
19221942
}
19231943

@@ -3496,15 +3516,36 @@ sub get_gcov_capabilities()
34963516
{
34973517
my $help = `$gcov_tool --help`;
34983518
my %capabilities;
3519+
my %short_option_translations = (
3520+
'a' => 'all-blocks',
3521+
'b' => 'branch-probabilities',
3522+
'c' => 'branch-counts',
3523+
'f' => 'function-summaries',
3524+
'h' => 'help',
3525+
'l' => 'long-file-names',
3526+
'n' => 'no-output',
3527+
'o' => 'object-directory',
3528+
'p' => 'preserve-paths',
3529+
'u' => 'unconditional-branches',
3530+
'v' => 'version',
3531+
);
34993532

35003533
foreach (split(/\n/, $help)) {
3501-
next if (!/--(\S+)/);
3502-
next if ($1 eq 'help');
3503-
next if ($1 eq 'version');
3504-
next if ($1 eq 'object-directory');
3534+
my $capability;
3535+
if (/--(\S+)/) {
3536+
$capability = $1;
3537+
} else {
3538+
# If the line provides a short option, translate it.
3539+
next if (!/^\s*-(\S)\s/);
3540+
$capability = $short_option_translations{$1};
3541+
next if not defined($capability);
3542+
}
3543+
next if ($capability eq 'help');
3544+
next if ($capability eq 'version');
3545+
next if ($capability eq 'object-directory');
35053546

3506-
$capabilities{$1} = 1;
3507-
debug("gcov has capability '$1'\n");
3547+
$capabilities{$capability} = 1;
3548+
debug("gcov has capability '$capability'\n");
35083549
}
35093550

35103551
return \%capabilities;

0 commit comments

Comments
 (0)