Re: [llvm-dev] [lldb-dev] JIT debugging on Mac OSX

Previous Topic Next Topic
classic Classic list List threaded Threaded
1 message Options
Reply | Threaded
Open this post in threaded view
Report Content as Inappropriate

Re: [llvm-dev] [lldb-dev] JIT debugging on Mac OSX

Hal Finkel via llvm-dev
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):

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

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.



(0) The docs could be updated as the mentioned lli flag recently changed
from "-use-mcjit" to "-jit-kind=mcjit". Also it won't work with
"-jit-kind=orc-mcjit" as  OrcMCJITReplacement does not register
GDBRegistrationListener as MCJIT does:

(1) 07.04.2014:
Disable JITLoaderGDB on "vendor == apple" for now due to performance
slowdowns [...]

(2) 03.06.2014:
Allow MachO JIT debugging (Review)

(3) 25.06.2014:
[...] enable JITLoaderGDB with mach-o file support

(4) 16.09.2015:
[...] make JIT loader breakpoint optional

(5) Debugging JITed code with LLDB & LLVM Release 4.0 on OSX 10.12:

(lldb) target create "/Dev/3rdParty/llvm40-build-xcode/Debug/bin/lli"
Current executable set to
'/Dev/3rdParty/llvm40-build-xcode/Debug/bin/lli' (x86_64).
(lldb) settings set --  "-O0" "-jit-kind=mcjit"
(lldb) log enable lldb jit
(lldb) settings set plugin.jit-loader.gdb.enable-jit-breakpoint true
(lldb) b foo.c:4
Breakpoint 1: no locations (pending).
WARNING:  Unable to resolve breakpoint to any actual locations.
(lldb) run
JITLoaderGDB::SetJITBreakpoint looking for JIT register hook
JITLoaderGDB::SetJITBreakpoint setting JIT breakpoint
Process 7433 launched: '/Dev/3rdParty/llvm40-build-xcode/Debug/bin/lli'
Process 7433 stopped
* thread #1, queue = '', stop reason =
EXC_BAD_ACCESS (code=1, address=0x0)
    frame #0: 0x0000000103fd000c
->  0x103fd000c: movl   (%rcx), %esi
    0x103fd000e: movabsq $0x103fd1000, %rdi        ; imm = 0x103FD1000
    0x103fd0018: movabsq $0x7fffcb06f180, %rcx     ; imm = 0x7FFFCB06F180
    0x103fd0022: xorl   %eax, %eax
(lldb) bt
* thread #1, queue = '', stop reason =
EXC_BAD_ACCESS (code=1, address=0x0)
  * frame #0: 0x0000000103fd000c
    frame #1: 0x0000000103fd0050
    frame #2: 0x0000000103fd0070
    frame #3: 0x0000000103fd009b
    frame #4: lli`llvm::MCJIT::runFunction(this=0x0000000106806200,
F=0x0000000104003238, ArgValues=ArrayRef<llvm::GenericValue> @
0x00007fff5fbfacd0) at MCJIT.cpp:538
    frame #5:
Fn=0x0000000104003238, argv=size=1, envp=0x00007fff5fbff708) at
    frame #6: lli`main(argc=6, argv=0x00007fff5fbff6d0,
envp=0x00007fff5fbff708) at lli.cpp:632
    frame #7: 0x00007fffcaff6235 libdyld.dylib`start + 1

On Sat Jul 6 05:58:39 PDT 2013 HaiTao Feng wrote:

> 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
>   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
> I tried to use LLDB to debug the test case mentioned in
>, 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
> The interface
> in that patch looked like "__jit_debug_register_code" provided from gdb,
> but that patch was not merged in master.
> Thanks
> -Haitao

LLVM Developers mailing list
[hidden email]