JIT debugging on Mac OSX

Hi,

How does JIT debugging feature work on Mac OSX?

It seems that some LLVM documents implied lldb supports JIT debugging on Mac OSX.

  1. “LLDB may be a better option for debugging JIT-ed code on Mac OS X.” from http://llvm.org/docs/DebuggingJITedCode.html.
  2. “Upcoming features include JIT debugging, core file support and support of new processor features.” in the section of “Recent LLDB packages have closed some of the feature gap with LLDB on Linux relative to Darwin.” from http://blog.llvm.org/2013/06/lldb-33-and-beyond.html.

I tried to use LLDB to debug the test case mentioned in http://llvm.org/docs/DebuggingJITedCode.html, but found that the JITed function names are not shown in the stack backtrace. From the LLVM source codes, there is only a gdb register for ELF format in MCJIT, for MachO, the debugger register is {}. Do I need some compiler time or runtime configuration to make lldb debug Jitted code?

The discussion I could find in the mailing list was http://lists.cs.uiuc.edu/pipermail/lldb-dev/2010-December/000314.html. The interface in that patch looked like “__jit_debug_register_code” provided from gdb, but that patch was not merged in master.

Thanks
-Haitao

Hello everyone, Haitao, Greg, Keno

Reviving this topic as I am investigating the current state of JITed
code debugging in LLVM release 4.0 for our upcoming LLVM Social in
Berlin. Following the docs I got everything working on Linux (for a side
note see 0):
http://llvm.org/docs/DebuggingJITedCode.html

On OSX it doesn't work as there's a special check preventing
JITLoaderGDB instantiation:

ArchSpec arch (process->GetTarget().GetArchitecture());
if (arch.GetTriple().getVendor() != llvm::Triple::Apple)
  jit_loader_sp.reset(new JITLoaderGDB(process));

Trying to reconstruct history: The check was introduced due to a
performance issuein 2014 (see 1). Shortly afterwards Keno Fischer
submitted his implementation for MachO support and in the original
patch, the OSX limitation was removed as I'd expected(see 2). However,
in the final LLDB commit these lines remained inside (see 3), I guess
because the performance issue was still present? IIUC this was
onlysolved in 2015 with a special option to enable the JIT loader
breakpoint (see 4). Though the check for llvm::Triple::Apple is still in
there..

So I guess there are more reasons why JITed code debugging is still not
available on OSX?

Just removing the line, doesn't get me anywhere (see terminal output in
5). Although LLI's __jit_debug_register_code and __jit_debug_descriptor
symbols are found correctly, the jit-debug-register breakpoint set in
JITLoaderGDB::SetJITBreakpoint will never be hit, so source locations
are not resolved and debug symbols not available.

It would be great to hear if anyone knows more about the topic, how to
fix or workaround it, or maybe alternative ways to get it done on OSX.

Thanks
Stefan