linux-test-project / lcov

LCOV
GNU General Public License v2.0
866 stars 234 forks source link

genhtml: ERROR: unexpected .info file record 'BFH:0' #275

Closed dilyanpalauzov closed 3 months ago

dilyanpalauzov commented 3 months ago

I have these files:

linux-gcc: g++ --coverage u.cpp -o u -g ./u lcov --directory . --capture -o output2 genhtml -o html_report output1 output2

* u.cpp:
```c++
#include <iostream>

int main() {
#ifdef WIN32
  std::cout << "Brum" << std::endl;
#else
  std::cout << "Woohoo" << std::endl;
#endif
  return 0;
}

Under Windows I execute

CALL "C:\Program Files (x86)\Microsoft Visual Studio\2019\Community\VC\Auxiliary\Build\vcvarsall.bat" x86 10.0.17763.0 
nmake win32

This utilizes clang 12 and then output1 has

SF:C:\somepath\u.cpp
FN:3,main
FNDA:1,main
FNF:1
FNH:1
DA:3,1
DA:4,1
DA:5,1
DA:9,1
DA:10,1
BRF:0
BFH:0
LF:5
LH:5
end_of_record

In the same directory under Linux (WSL2) I execute make linux-gcc, which prints

genhtml -o html_report output1 output2
genhtml: ERROR: "output1":12: unexpected .info file record 'BFH:0'
        (use "genhtml --ignore-errors format ..." to bypass this error)
make: *** [Makefile:12: linux-gcc] Error 1

For reference, the content of output2 is

TN:
SF:/mnt/c/somepath/u.cpp
FN:3,10,main
FNDA:1,main
FNF:1
FNH:1
DA:3,1
DA:7,1
DA:9,1
LF:3
LH:3
end_of_record

My understanding is that gcov is somehow interchangeable format between clang, gcc and lcov. But BFH in this format is not understood by lcov.

LCOV version 2.0-1 (as reported on Fedora)

In any case I want to compile code under Windows with either cl.exe or clang-cl.exe and produce code coverage files. Then I want to compile and run the same source code under Linux with g++, produce other coverage files and at the end merge the code coverage files executed under both platforms. I want to see the code, which is never executed.

henry2cox commented 3 months ago

Looks like your version of llvm/12 is generating invalid lcov syntax. The record should have been: BRH:0

There is no valid key called BFH.

The message from genhtml also tells you what to do, if you want to ignore this error rather than fixing it. There is more information on error management, in the man page.

WRT llvm and gcc - I had added discussion #234 on the topic, some months ago. It may (or may not) help to clarify the issues for you.

dilyanpalauzov commented 3 months ago

If you say BRH:0 is invalid or not defined, then I close this ticket. --ignore-erros format does the right thing.

Where is the definition of the gcov format and its fields?

henry2cox commented 3 months ago

Where is the definition of the gcov format and its fields?

There is another long discussion of exactly this in issue #113 The upshot is that this is defined in the source code and is also described in the geninfo man page.

dilyanpalauzov commented 3 months ago

https://github.com/llvm/llvm-project/commit/9116211d180ca417fa93d4e97e60f4ba849d58d9 changes the export in llvm-cov from BFH to BRH. clang-tools, delivered with Visual Studio 2019, are in version 12 and export BFH.

dilyanpalauzov commented 3 months ago

I suggest replacing on https://github.com/linux-test-project/lcov/discussions/234 the text 9116211d180ca417fa93d4e97e60f4ba849d58d9 with a hyperlink to https://github.com/llvm/llvm-project/commit/9116211d180ca417fa93d4e97e60f4ba849d58d9 and the text 9f2967bcfe2f7d1fc02281f0098306c90c2c10a5 with a hyperlink to https://github.com/llvm/llvm-project/commit/9f2967bcfe2f7d1fc02281f0098306c90c2c10a5 .

The first hyperlink makes easy to understand how to use old clang : substitute BFH with BRH.

dilyanpalauzov commented 3 months ago

My understanding is that in fact the substitution BFH to BRH in the lcov files is the only necessary change needed, when llvm-cov export -format=lcov is from llvm 12. The 234-discussion suggests upgrading LLVM, which is correct, but it could also state that the substitution in the files generated by llvm-cov export -format=lcov is the single change needed to get it running.

henry2cox commented 3 months ago

My understanding is that in fact the substitution BFH to BRH in the lcov files is the only necessary change needed, when llvm-cov export -format=lcov is from llvm 12. The 234-discussion suggests upgrading LLVM, which is correct, but it could also state that the substitution in the files generated by llvm-cov export -format=lcov is the single change needed to get it running.

Or just tell lcov to --ignore the format error. That may or may not be easier than adding a sed step to fix the text. Also won't change anything, if you later upgrade your compiler.

Seems like the bug is in certain versions of llvm/12 - but was fixed shortly after.