[PATCH] Debugging LLVM IR with LLDB (and gdb)

Duncan Sands baldrick at free.fr
Sat Apr 13 09:26:09 PDT 2013


Hi Daniel,

On 11/04/13 22:53, Malea, Daniel wrote:
> Hi all,
>
> There has been some talk about debugging LLVM IR on the lists and on IRC, so I implemented a transform pass that allows just that! Here's a screenshot of me stepping through the IR generated by clang to catch an exception: http://i.imgur.com/OG6rUIE.png

this is great!

> Before I get into the details, here are some limitations:
>
>    *   It is a requirement (for now) that the input module have debug metadata (that is, it was generated with clang –g or equivalent)
>    *   By running the pass, metadata that correlates machine code back to the original source file are lost. Until debuggers know about IR, this will remain a limitation.

Maybe you could cheat, and nest the IR scope inside a fake lexical block
scope that has the file and line number from the original source.  Dunno
if this would actually allow you to find the original from the debugger...

Ciao, Duncan.

>    *   Printing variables that exist in the original source works, but LLVM temporaries not so much (in the current implementation)
>
> That said, the patch includes a few test cases that use opt to modify code with debug metadata decorators to allow debugging of IR. If you'd like to give it a shot, add the pass to your PassManager by calling createDebugIRPass()!
>
> I'd be appreciative of testing and/or review comments! The patch is available on phabricator http://llvm-reviews.chandlerc.com/D659 and the details from the review request follow.
>
>
> I plan to commit it as 4 separate patches, here's what they do:
>
>
> Part #1: FormattedStream -- Add line tracking
> - previously formatted_raw_ostream tracked columns, now it tracks lines too
> - used by DebugIR pass to know the line number to connect to each IR instruction
>
> Part #2: Pull up AssemblyWriter interface into header to allow subclassing
> - made all functions virtual so that subclasses can specialize them
> - add printInstructionLine so that subclasses can choose whether or not to
> print the newline character (without having to implement printBasicBlock()
>
> Part #3: DebugIR -- emit IR file and replace source lines with IR lines in MD
> - requires existing debug information to be present
> - fixes up file name and line number information
> - emits a "<orig_filename>-debug.ll" succinct IR file (without !dbg metadata
> or debug intrinsics) that can be read by a debugger
>
> Part #4: DebugIR tests -- lit tests for the line number transform
> - simple one-function case
> - function-calling case
> - external function calling case
> - exception throwing case
> - vector case
> - O3 (vector) case
>
>
>
> Thanks,
>
>
> --
>
> Daniel Malea <daniel.malea at intel.com<mailto:daniel.malea at intel.com>>
>
> Intel Waterloo
>
> _______________________________________________
> llvm-commits mailing list
> llvm-commits at cs.uiuc.edu
> http://lists.cs.uiuc.edu/mailman/listinfo/llvm-commits
>




More information about the llvm-commits mailing list