Stefan Gränitz via llvm-dev
2017-Jun-13 14:49 UTC
[llvm-dev] [lldb-dev] JIT debugging on Mac OSX
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 -- (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: https://github.com/llvm-mirror/llvm/blob/master/lib/ExecutionEngine/MCJIT/MCJIT.cpp#L90 (1) 07.04.2014: Disable JITLoaderGDB on "vendor == apple" for now due to performance slowdowns [...] https://github.com/llvm-mirror/lldb/commit/2829ee8e179e9d3381de08dba1502351e34867c0 (2) 03.06.2014: Allow MachO JIT debugging (Review) https://reviews.llvm.org/D4006#C84943OL290 (3) 25.06.2014: [...] enable JITLoaderGDB with mach-o file support https://github.com/llvm-mirror/lldb/commit/a900ab69519016161cd640643776b55a1e56ad84 https://github.com/llvm-mirror/lldb/blob/a900ab69519016161cd640643776b55a1e56ad84/source/Plugins/JITLoader/GDB/JITLoaderGDB.cpp#L367 (4) 16.09.2015: [...] make JIT loader breakpoint optional https://github.com/llvm-mirror/lldb/commit/4066cc33b57758fbc94afc3428c52e817a65c201 (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 -- target.run-args "-O0" "-jit-kind=mcjit" "/Dev/Personal/jitdebug/foo.ll" (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' (x86_64) Process 7433 stopped * thread #1, queue = 'com.apple.main-thread', 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 = 'com.apple.main-thread', 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: lli`llvm::ExecutionEngine::runFunctionAsMain(this=0x0000000106806200, Fn=0x0000000104003238, argv=size=1, envp=0x00007fff5fbff708) at ExecutionEngine.cpp:471 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 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-- https://about.me/stefan.graenitz https://cryptup.org/pub/stefan.graenitz at gmail.com