[LLVMdev] Debugging LLVM IR with GDB

Eli Bendersky eliben at gmail.com
Thu Oct 18 06:59:34 PDT 2012

> Has anybody debugged LLVM IR with GDB? I'm using dragonegg to transform C
> into IR, then applying my optimizations. Passing "-g" to dragonegg doesn't
> seem to work since it generates debug info for the C code, not the IR. I
> really need GDB (lli doesn't solve my problems) in order to debug
> multi-threaded and multi-process MPI code.
> More clearly, if I have a file hello.ll and I execute:
> $> llc hello.ll -march=x86-64 -o hello.s
> $> mpicc -O0 hello.s -o hello
> Can I debug "hello" with GDB at the IR level? If so, how? If not, would it
> be possible to add debug info generation at the IR level (and how much
> effort required)? I read something about DwarfDebug but it's not clear to
> me how to use it or even if it does what I need. I hope I didn't miss any
> obvious solution.

With the recent MCJIT work, C code compiled with LLVM can be debugged in
GDB (http://llvm.org/docs/DebuggingJITedCode.html). Alas, this doesn't mean
IR can be debugged as easily :-)

The problem is the following: the debug information attached to each IR
instruction by Clang refers to the original C code. When this debug info
passes through the various layers of optimizations, MC, JITting, it remains
pointing to C code. To debug IR, one would have to add debug info to each
instruction, actually pointing to the IR itself. Then I guess GDB would
know how to debug it, at least with a few tweaks, because GDB generally
doesn't terribly care which language it debugs, as long as it can follow
the debug info and the commands make sense (and this can be handled by
adding appropriate Python plugins).

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/llvm-dev/attachments/20121018/b5c25aae/attachment.html>

More information about the llvm-dev mailing list