I can't seem to find any good documentation for the DWARF DI format to answer my question. I'm writing a language that compiles to C, is there any way that I can produce DWARF Debug Information into the C code or is it assembly only?
Is it impossible to add debug information to some (generated) C code other than using primitive stuff that isn't as good like
I guess you'll compile the generated C with debug info (-g), so what you're asking is how to have additional DWARF records that describe your high level language. Conceivable approaches:
(2) find a way to "smuggle" extra DWARF records through the compiler, e.g. somewhat as linker commands can be given through #pragmas. However I don't know of a compiler that supports this.
(3) LLVM has support for debug records in the IR representation . You could use clang to compile your generated C to IR (
clang foo.c -S -emit-llvm -target arm -o foo.ll), then augment foo.ll, then generate the .o (
llc foo.ll), ready for linking.
The third option seems likely to be the easiest.