← 返回命令列表

Linux command

gcov 命令

文件

复制后可按需替换文件名、目录或参数。

常用示例

Example

gcov [path/to/file.cpp]

Example

gcov -a [path/to/file.cpp]

Example

gcov -b [path/to/file.cpp]

Example

gcov -c [path/to/file.cpp]

Example

gcov -n [path/to/file.cpp]

Example

gcov -f [path/to/file.cpp]

说明

gcov is a test coverage program used with GCC to analyze which parts of a program have been executed during testing. It helps identify untested code paths, improving test suite completeness. To use gcov, compile your program with -fprofile-arcs -ftest-coverage (or --coverage). After running the program, gcov reads the generated .gcno and .gcda files to produce annotated source listings showing execution counts for each line. Output files (*.gcov) contain the original source code annotated with execution counts. Lines marked ##### were never executed. Branch information helps identify untested conditional paths.

参数

-a, --all-blocks
Write individual execution counts for every basic block
-b, --branch-probabilities
Write branch frequencies to output file as percentages
-c, --branch-counts
Write branch frequencies as counts rather than percentages
-f, --function-summaries
Output summaries for each function in addition to file summary
-n, --no-output
Do not create gcov output file
-l, --long-file-names
Use long file names for output files
-p, --preserve-paths
Preserve complete path information in output file names
-o, --object-directory _DIR_
Search for object files in _DIR_
-s, --source-prefix _PREFIX_
Remove source path prefix for shorter output names

FAQ

What is the gcov command used for?

gcov is a test coverage program used with GCC to analyze which parts of a program have been executed during testing. It helps identify untested code paths, improving test suite completeness. To use gcov, compile your program with -fprofile-arcs -ftest-coverage (or --coverage). After running the program, gcov reads the generated .gcno and .gcda files to produce annotated source listings showing execution counts for each line. Output files (*.gcov) contain the original source code annotated with execution counts. Lines marked ##### were never executed. Branch information helps identify untested conditional paths.

How do I run a basic gcov example?

Run `gcov [path/to/file.cpp]` in a terminal, then adjust file names, paths, flags, or remote targets for your system.

What does -a, --all-blocks do in gcov?

Write individual execution counts for every basic block