<div dir="ltr"><br><div class="gmail_quote"><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">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.<br>


<br>
More clearly, if I have a file hello.ll and I execute:<br>
<br>
$> llc hello.ll -march=x86-64 -o hello.s<br>
$> mpicc -O0 hello.s -o hello<br>
<br>
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.<br>

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

<br>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).<br>

<br>Eli<br><br><br></div>