how to debug with interpreter

Hi,

I'm using the JIT execution engine for my language, and I'm finding it
extremely painful to find bugs in generated code. I get a "seg fault"
and I can't see where it happened. Writing a debugger or generating
info for GDB seems like too much work at this point. Is there a way
to use the Interpreter to run this code, stepping through and printing
the LLVM instructions, to find the one that triggers the seg fault? I
have not been writing any files to disk and have not yet used much in
LLVM except the C++ API.

thanks,
Rob

x/20i $pc - 20 or so is your friend. In general, you can't
disassemble x86 backwards, but gdb does a reasonably good job if you
just guess.

Alternatively, if you're on Linux, there's the gdb-jit interface,
which should give you symbols and unwind tables without any extra
effort on your part:
http://llvm.org/docs/DebuggingJITedCode.html

To answer your original question about the interpreter, you can pass
-force-interpreter to lli or pass args to the execution engine
creation, but the interpreter is considered incomplete and buggy. Its
original purpose was to help debug the JIT, but now the JIT works
reliably, so it hasn't been maintained.

Reid

This page says to run `lli -jit-emit-debug myfile.bc' under gdb. Does
the entire program need to be .bc files running through lli, or is
there a way to pass that -jit-emit-debug flag to the C++ api, inside a
normally compiled program?

thanks,
Rob

I thought there was a mechanism for doing that, but I can't find it.
If you build LLVM in debug mode, it will be on by default. Or
wherever you wrap LLVM's parsing of command line flags you can pass it
in.

Reid