LLVM IR Debugger

Hi

I am looking at open projects that LLVM want to implement and it seems to be a suggestion to write an LLVM IR level debugger. Is there any existing LLVM projects out there that already does such a thing? If not, I would like to try implementing one myself.

By debugger, I think it means something like gdb, where you can insert breakpoints, run code and observe layout of registers and memory at certain periods of time.

If anyone has suggestions as to how this IR debugger should work please let me know.

Thanks!

Brenda

You can attach debug info to the Llvm module about LLVM IR, at which point one can throw the executable into any debugger and get llvm level debugging.

I’ve started a patch to revive this feature (DebugIR pass). I’ve been sidetracked the past month, but I’ll come back to it soon :slight_smile:
https://reviews.llvm.org/D40778

Cheers,
Siddharth

interesting … just curious, why did they delete “-debug-ir” to begin with ?

Also, it’s extremely interesting that gdb and lldb can be used to debug LLVM IR. How does your code work (on a high level)? A high level explanation will help me understand what you’ve done better.

From first glance, my idea is slight different because your code interfaces with gdb and lldb while i’m more interested in making the debugger itself (sort of an extended interpreter).

Yours,
Brenda

interesting ... just curious, why did they delete "-debug-ir" to begin with ?

The metadata describing the information debuggers need (line numbers,
variable locations and so on) was evolving rapidly at the time I
think. The -debug-ir pass was lagging behind I think, and rarely used
as far as anyone knew.

Also, it's extremely interesting that gdb and lldb can be used to debug LLVM IR. How does your code work (on a high level)? A high level explanation will help me understand what you've done better.

It adds the information necessary to produce normal DWARF debugging
information in the object files. That format is designed to be
generic.

One part is just mapping some byte of the output instructions back to
the source file and line number, which is just as easy for IR as for a
more conventional language. The other major part is describing where
in memory or registers named variables are, which is also pretty much
the same for LLVM IR as for normal code. After that the magic of
debuggers takes over.

Cheers.

Tim.

I worked with LLVM for years and never knew there was an IR debugger. At that stage of my time with it lowering issues / crashes were a bigger problem than code, and assembly language can be correlated to IR in my head pretty accurately because I’m strange that way, so I never looked. I don’t use it as much anymore but I’m sure some people would be interested.

If the IR won’t lower, this pass won’t work, correct? As I said I’m unfamiliar.

To play devil’s advocate, what happens if you need to debug IR from 2 years ago or an unknown build? As long as the IR is compatible the two years situation works, but if it doesn’t and for whatever catastrophe that’s all you have, what do you do about it? IR could be the cause of a bug in one revision and a subtle fix makes it pointless to debug two revisions later without breaking anything and vice versa.
It doesn’t happen as much anymore, but it happens. That was kind of a rhetorical question since I already know what happens when you mix somewhat compatible IR versions.

Since I’m not familiar with the original pass, does this step through and attempt lowering? I know we need an MBB to lower, but being able to ID the exact line of IR causing the lowering error could help nicely. At O0 there isn’t much going on in terms of block changes so it seems reasonable to match up an error to the producing line from what I know of the debug system. There would be problems (Dummy MBBs for targets / unseen preds off the top of my head), but it would be a step up from doing pass debugging directly.

Since you’re more familiar with this, how hard do you think implementing something like that would be, on a scale of 1 to go away with that nonsense. :slight_smile:

GK

Hi Brenda

You may want to have a look here:
The project can be used to re-assemble IR modules and add debug information on the fly. It’s based on the LLVM Assembler as it brings most of the infrastructure already. I ported it to LLVM 4.0 last year and it worked well for my limited purpose. Not sure if it’s suitable for adding symbol information for inspection though. Hope that helps somehow. Best Stefan