Skip to content

Commit 8007bcc

Browse files
committed
[llvm-cov] Create syntax to pass source w/o binary.
Since binary ID lookup makes CLI object arguments optional, it should be possible to pass a list of source files without a binary. Unfortunately, the current syntax will always interpret the first source file as a binary. This change adds a `-sources` option to cause all later positional arguments to be considered sources. Reviewed By: gulfem Differential Revision: https://reviews.llvm.org/D144207
1 parent 4eadd19 commit 8007bcc

File tree

3 files changed

+14
-10
lines changed

3 files changed

+14
-10
lines changed

compiler-rt/test/profile/Linux/binary-id-lookup.c

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,9 @@
99
// RUN: cp %t.main %t/.build-id/ab/cd1234.debug
1010
// RUN: llvm-profdata merge -o %t.profdata %t.profdir/default_*.profraw
1111
// RUN: llvm-cov show -instr-profile %t.profdata -debug-file-directory %t | FileCheck %s
12+
// RUN: llvm-cov show -instr-profile %t.profdata %t/libfoo.so -sources %t/foo.c -object %t.main | FileCheck %s --check-prefix=FOO-ONLY
13+
// RUN: llvm-cov show -instr-profile %t.profdata -debug-file-directory %t -sources %t/foo.c | FileCheck %s --check-prefix=FOO-ONLY
14+
// RUN: llvm-cov show -instr-profile %t.profdata -debug-file-directory %t %t/libfoo.so -sources %t/foo.c | FileCheck %s --check-prefix=FOO-ONLY
1215
// RUN: echo "bad" > %t/.build-id/ab/cd1234.debug
1316
// RUN: llvm-cov show -instr-profile %t.profdata -debug-file-directory %t %t.main | FileCheck %s
1417
// RUN: not llvm-cov show -instr-profile %t.profdata -debug-file-directory %t/empty 2>&1 | FileCheck %s --check-prefix=NODATA
@@ -17,6 +20,7 @@
1720
// CHECK: 2| 1|void bar(void) {}
1821
// CHECK: 3| 1|int main() {
1922

23+
// FOO-ONLY: 1| 1|void foo(void) {}
2024
// NODATA: error: Failed to load coverage: '': No coverage data found
2125

2226
//--- foo.c

llvm/docs/CommandGuide/llvm-cov.rst

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -188,14 +188,14 @@ SHOW COMMAND
188188
SYNOPSIS
189189
^^^^^^^^
190190

191-
:program:`llvm-cov show` [*options*] -instr-profile *PROFILE* *BIN* [*-object BIN,...*] [[*-object BIN*]] [*SOURCES*]
191+
:program:`llvm-cov show` [*options*] -instr-profile *PROFILE* [*BIN*] [*-object BIN*]... [*-sources*] [*SOURCE*]...
192192

193193
DESCRIPTION
194194
^^^^^^^^^^^
195195

196196
The :program:`llvm-cov show` command shows line by line coverage of the
197-
binaries *BIN*,... using the profile data *PROFILE*. It can optionally be
198-
filtered to only show the coverage for the files listed in *SOURCES*.
197+
binaries *BIN*... using the profile data *PROFILE*. It can optionally be
198+
filtered to only show the coverage for the files listed in *SOURCE*....
199199

200200
*BIN* may be an executable, object file, dynamic library, or archive (thin or
201201
otherwise).
@@ -370,14 +370,14 @@ REPORT COMMAND
370370
SYNOPSIS
371371
^^^^^^^^
372372

373-
:program:`llvm-cov report` [*options*] -instr-profile *PROFILE* *BIN* [*-object BIN,...*] [[*-object BIN*]] [*SOURCES*]
373+
:program:`llvm-cov report` [*options*] -instr-profile *PROFILE* [*BIN*] [*-object BIN*]... [*-sources*] [*SOURCE*]...
374374

375375
DESCRIPTION
376376
^^^^^^^^^^^
377377

378378
The :program:`llvm-cov report` command displays a summary of the coverage of
379-
the binaries *BIN*,... using the profile data *PROFILE*. It can optionally be
380-
filtered to only show the coverage for the files listed in *SOURCES*.
379+
the binaries *BIN*... using the profile data *PROFILE*. It can optionally be
380+
filtered to only show the coverage for the files listed in *SOURCE*....
381381

382382
*BIN* may be an executable, object file, dynamic library, or archive (thin or
383383
otherwise).
@@ -451,21 +451,21 @@ EXPORT COMMAND
451451
SYNOPSIS
452452
^^^^^^^^
453453

454-
:program:`llvm-cov export` [*options*] -instr-profile *PROFILE* *BIN* [*-object BIN,...*] [[*-object BIN*]] [*SOURCES*]
454+
:program:`llvm-cov export` [*options*] -instr-profile *PROFILE* [*BIN*] [*-object BIN*]... [*-sources*] [*SOURCE*]...
455455

456456
DESCRIPTION
457457
^^^^^^^^^^^
458458

459459
The :program:`llvm-cov export` command exports coverage data of the binaries
460-
*BIN*,... using the profile data *PROFILE* in either JSON or lcov trace file
460+
*BIN*... using the profile data *PROFILE* in either JSON or lcov trace file
461461
format.
462462

463463
When exporting JSON, the regions, functions, branches, expansions, and
464464
summaries of the coverage data will be exported. When exporting an lcov trace
465465
file, the line-based coverage, branch coverage, and summaries will be exported.
466466

467467
The exported data can optionally be filtered to only export the coverage
468-
for the files listed in *SOURCES*.
468+
for the files listed in *SOURCE*....
469469

470470
For information on compiling programs for coverage and generating profile data,
471471
see :ref:`llvm-cov-show`.

llvm/tools/llvm-cov/CodeCoverage.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -636,7 +636,7 @@ int CodeCoverageTool::run(Command Cmd, int argc, const char **argv) {
636636
"dump-collected-objects", cl::Optional, cl::Hidden,
637637
cl::desc("Show the collected coverage object files"));
638638

639-
cl::list<std::string> InputSourceFiles(cl::Positional,
639+
cl::list<std::string> InputSourceFiles("sources", cl::Positional,
640640
cl::desc("<Source files>"));
641641

642642
cl::opt<bool> DebugDumpCollectedPaths(

0 commit comments

Comments
 (0)