Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Closed
dilyanpalauzov opened this issue Mar 22, 2024 · 7 comments
Closed

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

dilyanpalauzov opened this issue Mar 22, 2024 · 7 comments

Comments

@dilyanpalauzov
Copy link

dilyanpalauzov commented Mar 22, 2024

I have these files:

  • Makefile
win32:
        clang-cl.exe -fprofile-instr-generate -fcoverage-mapping /c u.cpp -o u.o /DEBUG /DWIN32
        clang-cl.exe -fprofile-instr-generate -fcoverage-mapping u.o -o u.exe /DEBUG
        u.exe
        llvm-profdata.exe merge -o merged-data.linux default.profraw
        llvm-cov.exe export --format=lcov --instr-profile merged-data.linux u.o > output1

linux-gcc:
        g++ --coverage u.cpp -o u -g
        ./u
        lcov --directory . --capture -o output2
        genhtml -o html_report output1 output2
  • u.cpp:
#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
Copy link
Collaborator

henry2cox commented Mar 22, 2024

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
Copy link
Author

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
Copy link
Collaborator

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
Copy link
Author

llvm/llvm-project@9116211 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
Copy link
Author

I suggest replacing on #234 the text 9116211d180ca417fa93d4e97e60f4ba849d58d9 with a hyperlink to llvm/llvm-project@9116211 and the text 9f2967bcfe2f7d1fc02281f0098306c90c2c10a5 with a hyperlink to llvm/llvm-project@9f2967b .

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

@dilyanpalauzov
Copy link
Author

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
Copy link
Collaborator

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants