Kcov is implemented on the basis of bcov, which has not been maintained for a long time;
First, download the dependent library libdwraft and specify it in configure:
./Configure -- With-libdwarf =/usr/local/lib
Then make; make install
(1) Sadly, errors occurred during compilation.
'Ptrace _ o_traceclone 'was not declared in this scope
Add a header file <sys/ptrace>
At the same time, the place where ptrace is called is forced type conversion, for example, the original is
Ptrace (ptrace_getregs, activechild, 0, & regs );
Then change
Ptrace (_ ptrace_request) ptrace_getregs, activechild, 0, & regs );
Compilation is successful;
(2) You can use it after installation. You need to add the-G parameter to the source program compilation; otherwise, no information is collected.
g++ t.cpp -O0 -g
Use bcov to start the program:
bcov ./a.out &
Startup will display
probing debug information...found active lines in 1 source filesset 11 breakpoints
Then killall
killall -9 a.out
Display
program terminatedcoverage info written to .bcovdump
In this case, the coverage file. bcovdump is generated
bcov-report ./.bcovdump ~/httpd/htdocs/bcov-report.DhblLi
View:
Statistical analysis of service-type test coverage compared with gcov
(1) bcov does not need to add compilation parameters and connection parameters, but needs to add the-G option;
(2) gcov needs to set environment variables during startup, while bcov needs to use the bcov command to start the program under test;
(3) Merge multiple files. We can see that the bcov output file is. bcovdump is a bunch of numbers and it seems easier to edit.: