I'm trying to insert some DWARF debugging information into a LLVM IR module
by manually parsing the DWARF debug DIEs. I'm doing it that way since I
wrote my custom front-end for my language and the DWARF debugging
information are provided me as a byte stream for the various DWARF sections.
I took a look at the documentation and DwarfDebug class (
<http://llvm.org/docs/doxygen/html/classllvm_1_1DwarfDebug.html> ) but it
doesn't seem to be a quick way to directly "feed the DWARF sections" to the
IR directly generated from my code.
Anyway I'd like to know if what I'm doing (i.e. manually parsing the DWARF
sections, expression trees and everything else to get the variables /
structures I'm interested in) is a useless effort or it is the only way to
insert proper debugging information into the IR code I'm describing.
The way to add information to a module is going to be via DIBuilder,
however, this doesn't match what you're attempting to do if you have
fully fledged sections. You could try to write out type information as
you've parsed it etc, but it's going to be a buyer beware sort of
thing. The way clang does this is to emit type/variable/line
information as it's generating code.
I'd need more information about your actual setup to give any more of
an answer though.
Thanks Eric. Using DIBuilder to manually insert debugging information is what
I had in mind and I believe at the end of the day it will be the only way.
Regarding my setup I'm using a parser which reads code generated by a
front-end comprehensive of all DWARF (v2 IIRC) infos. Unfortunately I
believe the parser I'm using was just designed to set up the IR routines
with a basic debugging support since it doesn't provide (as far as I could
see) any way to "browse" or "explore" the DWARF data, i.e. it just provides
me a number of DWARF sections (debug_abbrev, debug_info, etc..) via byte
streams. I searched through its code but I'm almost sure interpreting that
data will be up to me.
Thus what I had in mind was exactly to write code to parse the debug
information and directly feed them via DIBuilder routines to LLVM. Line
infos are available throughout all my IR representation but in order to at
least enable variable/arrays watches I suppose I'll have to go through DWARF
expressions and such. I will probably not need all the data contained in the
DWARF sections (I'm not looking for a thoroughly debugging description of my
code) but I'll have to do some more tests in order to determine if what I
have in mind can somewhat be accomplished. I'm still pretty new to debugging
I really suggest you take a look at how clang is emitting the
information. It's quite a bit different than what you're looking at -
also trying to figure out why you're trying to take someone else's
dwarf and rewrite your own. That's going to be more complicated than
using ASTs or what have you to generate code.