[LLVMdev] help converting llvm metadata into dwarf tags
devang.patel at gmail.com
Mon Aug 23 17:46:08 PDT 2010
On Mon, Aug 23, 2010 at 4:01 PM, Roger Wang <innit42 at gmail.com> wrote:
> Dear all,
> I'd like to find the memory location of certain instructions in a
> compiled/linked binary. During the IR phase, I tag instructions I'm
> interested in with LLVM'-2.7's new metadata (MDNodes with an identifiable
> ID). I'd now like to propagate that data to the assembly via a custom DWARF
> tag I attach to each X86 instruction created from a tagged IR instruction.
> This will then find its way at assembly time into the binary from where I
> retrieve it (by locating my custom tags with a DWARF consumer and dumping
> the addresses of the instruction they're attached to).
> Does this sound reasonable?
> I've completed the first part, attaching the MDNodes to IR instructions but
> I'm a bit overwhelmed by all the backend stuff.
How can I identify which IR instruction an X86 instruction came from (with a
> view to attaching an identifying DW_TAG to it)?
1) LLVM IR instructions are converted into MachineInstr during instruction
selection time. At this point you need to transfer your custom metadata to
MachineInstr. See how DebugLoc is transfered (in CodeGen/SelectionDAG
2) At AsmPrint time, while emitting your assembly instructions you have
access to coresponding MachineInstr and any custom metadata attached with
> I've found the tag definitions in include/llvm/Support/Dwarf.h and added my
> lib/CodeGen/AsmPrinter/DwarfDebug.cpp seems to be the only place that emits
> dwarf data into the assembly stream.
See have DwarfDebug.cpp handles DebugLoc attached with each instruction
(::beginScope() and ::endScope()).
> It also seems to create a DebugInfoFinder which accesses the IR
This path will allow you to browse entire function and collect info which
you can use later on.
-------------- next part --------------
An HTML attachment was scrubbed...
More information about the llvm-dev