Dumping debug information from BC files

Hello LLVM-World,

I have a question about dumping debug information.

1.) I have compiled an object file with visual studio and debug information. Then I used “llvm-readobj -codeview” and dumped the debug information into a file.
This is working great

2.) I used clang-cl for the same task and finally dumped it again with “llvm-readobj”.
Worked great too.

3.) Then I used clang-cl to generate a .bc file - but now I’m not able to use “llvm-readobj” anymore. Is there any tool available which can dump this debug information too?

Kind regards
Björn

Als GmbH eingetragen im Handelsregister Bad Homburg v.d.H. HRB 9816, USt.ID-Nr. DE 114 165 789
Geschäftsführer: Dr. Hiroshi Nakamura, Dr. Robert Plank, Markus Bode, Heiko Lampert, Hiroshi Kawamura, Takashi Nagano, Takeshi Fukushima.

3.) Then I used clang-cl to generate a .bc file - but now I'm not able to
use "llvm-readobj" anymore. Is there any tool available which can dump this
debug information too?

​.bc is LLVM bitcode [1], not the usual object file. `llvm-readobj` should
works only on the latter.

​[1] https://llvm.org/docs/BitCodeFormat.html

The debug information is actually still in a different format in the .bc file, it is LLVM metadata. I think the best reference for it is here: https://llvm.org/docs/SourceLevelDebugging.html#ccxx-frontend

You can dump it just by disassembling the .bc file to textual IR using llvm-dis and examining the !DI* metadata nodes. You will have to run the file through llc to generate an object file to generate actual CodeView or DWARF.

Thank you for your reply.

When I’m running “llvm-readobj” on an .obj file I get a result like shown in my attachment. This is very easy to read. I don’t know if this is the codeview format. I would like to get this kind of debug information form a .bc file too, because I JIT them and wanted to try to build a debugger. With the file from “llvm-readobj” I see no problem - but when using the metadata I have no clue how to find variables on the stack - there are only this intrinsics, but I don’t know how to handle them.
Maybe I asked the wrong question :confused:

A .bc file contains a form of LLVM IR (internal representation), it does not contain machine code. You cannot use debug information in IR to find variables on the stack, because variables have not been assigned stack locations or registers until after you finish compiling or JIT the IR.

The JIT will translate IR instructions to machine instructions, assigning stack locations and so forth as it does so. I don’t know whether the JIT also translates the IR debug info into DWARF or CodeView, but that would be the kind of translation you need in order to debug the code produced by the JIT.

–paulr