LLDB regained JITed code debugging feature
Last week LLVM 12 was officially released and with it a new LLDB version that (finally!) regained source-level debug support through the GDB JIT interface. It has been broken in releases 6 to 11 due to a regression that involved two autonomous bugs.
The feature is now continuously tested to work for ELF on x86-64. MachO and COFF don’t seem to work and I didn’t investigate the state on ARM and other architectures. If you want to give it a quick try without setting up the environment, there is a Docker container here that reproduces it reliably – additional privileges are required to allow debugging inside the Docker container:
> docker run --privileged --cap-add=SYS_PTRACE --security-opt seccomp=unconfined --security-opt apparmor=unconfined --rm -it weliveindetail/lldb-12-jit-debug-demo
(lldb) target create "lli-12"
Current executable set to 'lli-12' (x86_64).
(lldb) b jitbp
Breakpoint 1: no locations (pending).
WARNING: Unable to resolve breakpoint to any actual locations.
(lldb) run /home/jitbp.ll
1 location added to breakpoint 1
Process 18 stopped
* thread #1, name = 'lli-12', stop reason = breakpoint 1.1
frame #0: 0x00007ffff7fce004 JIT(0x4d0b50)`jitbp() at jitbp.cpp:1:15
-> 1 int jitbp() { return 0; }
2 int main() { return jitbp(); }
Process 18 launched: '/usr/bin/lli-12' (x86_64)
(lldb) bt
* thread #1, name = 'lli-12', stop reason = breakpoint 1.1
* frame #0: 0x00007ffff7fce004 JIT(0x4d0b50)`jitbp() at jitbp.cpp:1:15
frame #1: 0x00007ffff7fce02b JIT(0x4d0b50)`main at jitbp.cpp:2:21
frame #2: 0x00007ffff48f1aa7 libLLVM-12.so.1`llvm::MCJIT::runFunction(llvm::Function*, llvm::ArrayRef<llvm::GenericValue>) + 743
frame #3: 0x00007ffff48a3c00 libLLVM-12.so.1`llvm::ExecutionEngine::runFunctionAsMain(llvm::Function*, std::vector<std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >, std::allocator<std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > > > const&, char const* const*) + 1120
frame #4: 0x0000000000414e53 lli-12`main + 8963