From: Reid Kleckner <rnk@mit.edu>
To: gdb-patches@sourceware.org, unladen-swallow@googlegroups.com
Subject: Re: [RFA] Add interface for registering JITed code
Date: Thu, 23 Jul 2009 12:08:00 -0000 [thread overview]
Message-ID: <9a9942200907221617r4d9d2264q52b4c6605d4389c7@mail.gmail.com> (raw)
In-Reply-To: <9a9942200907221615o570e749fh5cb186c1600f159c@mail.gmail.com>
+ unladen-swallow
On Wed, Jul 22, 2009 at 4:15 PM, Reid Kleckner<rnk@mit.edu> wrote:
> Hi,
>
> I'm working on unladen swallow, and we're trying to speed up Python by
> using the LLVM JIT. However, when we merge back to mainline, we want
> developers to be able to debug CPython with GDB. So that means we
> need LLVM to generate dwarf debug info, and we need to register it
> with GDB. After talking with some GDB developers here at Google, we
> decided the best way to do this was to mirror the dlopen/dlclose
> interface.
>
> On the LLVM side, for each JITed function we create a small ELF in
> memory with the debug info and symbol. LLVM then writes a little code
> entry struct describing the ELF, adds it to a linked list, and calls
> __jit_debug_register_code.
>
> I've added a breakpoint at __jit_debug_register_code and a
> corresponding event handler on the GDB side, which then reads the code
> entry out of another special global symbol (__jit_debug_descriptor).
> GDB then copies over the ELF and creates a BFD with it in memory, as
> is done in symbol-file-from-memory. Then it can call
> add_symbol_file_from_bfd with the BFD, and life is good.
>
> If GDB attaches while the program is running, it reads the linked list
> of code entries from the descriptor and registers each ELF as above.
>
> If LLVM frees machine code, then it sets the action enum in the
> descriptor to JIT_UNREGISTER, points the descriptor at the relevant
> code entry, and calls __jit_debug_register_code again. This way, GDB
> can turn around and free the corresponding object file. It's a nicer
> interface than the shared library interface because it actually passes
> the relevant entry, so you don't have to iterate over the linked list
> in the inferior.
>
> Finally, if the inferior exits, GDB goes through and tosses out all
> the JITed object files.
>
> One nice thing about this interface is that we don't have to reinvent
> another "file" format to encode the debug information, but it is
> annoying that it requires the JIT to link in an object file writer.
> Right now LLVM only has call frame information support (which they use
> for dwarf exception handling), but they have plans to add more after
> this summer. With this interface, we don't have to change anything on
> the GDB side when that happens.
>
> Here is a demo of what this does on x86_64, which relies on call frame
> information to produce a backtrace.
>
> Without the interface, the backtrace is totally garbled (it has way
> too many frames) in addition to not having symbols:
>
> [rnk@knuckles llvm-gdb-64]$ gdb Debug/bin/lli
> GNU gdb 6.8-gg16
> ...
> (gdb) run t.bc
> ...
> Program received signal SIGSEGV, Segmentation fault.
> [Switching to Thread 0x7ffff7fd86f0 (LWP 15017)]
> (gdb) bt
> #0 0x00007ffff61441a4 in ?? ()
> #1 0x0000000000000003 in ?? ()
> #2 0x0000000000000004 in ?? ()
> #3 0x00037ffff5f43fd0 in ?? ()
> #4 0x00007ffff614411c in ?? ()
> #5 0x00027fff00000003 in ?? ()
> #6 0x00007ffff61440aa in ?? ()
> #7 0x01000002f5f43ff0 in ?? ()
> #8 0x00007ffff614402c in ?? ()
> #9 0x0100000000000001 in ?? ()
> #10 0x0000000001438a40 in ?? ()
> #11 0x00007fff00000001 in ?? ()
> #12 0x0000000000b84d63 in llvm::JIT::runFunction (this=0x1405900, F=0x1402e10,
> ArgValues=@0x7fffffffdfd0)
> at /home/rnk/llvm-gdb/lib/ExecutionEngine/JIT/JIT.cpp:411
> #13 0x0000000000ba8985 in llvm::ExecutionEngine::runFunctionAsMain (
> this=0x1405900, Fn=0x1402e10, argv=@0x13efab8, envp=0x7fffffffe3a0)
> at /home/rnk/llvm-gdb/lib/ExecutionEngine/ExecutionEngine.cpp:378
> #14 0x00000000007e8635 in main (argc=2, argv=0x7fffffffe388,
> envp=0x7fffffffe3a0) at /home/rnk/llvm-gdb/tools/lli/lli.cpp:220
> (gdb)
>
> With the interface, it has symbols and no extra frames:
>
> [rnk@knuckles llvm-gdb-64]$ ../gdb-jit-64/gdb/gdb Debug/bin/lli
> ...
> (gdb) run t.bc
> ...
> Program received signal SIGSEGV, Segmentation fault.
> 0x00007ffff61441a4 in baz ()
> (gdb) bt
> #0 0x00007ffff61441a4 in baz ()
> #1 0x00007ffff614411c in bar ()
> #2 0x00007ffff61440aa in foo ()
> #3 0x00007ffff614402c in main ()
> #4 0x0000000000b84d63 in llvm::JIT::runFunction (this=0x1405900, F=0x1402e10,
> ArgValues=...) at /home/rnk/llvm-gdb/lib/ExecutionEngine/JIT/JIT.cpp:411
> #5 0x0000000000ba8985 in llvm::ExecutionEngine::runFunctionAsMain (
> this=0x1405900, Fn=0x1402e10, argv=..., envp=0x7fffffffe390)
> at /home/rnk/llvm-gdb/lib/ExecutionEngine/ExecutionEngine.cpp:378
> #6 0x00000000007e8635 in main (argc=2, argv=0x7fffffffe378,
> envp=0x7fffffffe390) at /home/rnk/llvm-gdb/tools/lli/lli.cpp:220
> (gdb)
>
> I've tested this on x86_64 debugging both 64-bit and 32-bit inferiors.
>
> Please review!
>
> Thanks,
> Reid
>
next prev parent reply other threads:[~2009-07-22 23:17 UTC|newest]
Thread overview: 32+ messages / expand[flat|nested] mbox.gz Atom feed top
2009-07-23 1:58 Reid Kleckner
2009-07-23 12:08 ` Reid Kleckner [this message]
2009-07-23 23:21 ` Tom Tromey
2009-07-24 13:25 ` Ulrich Weigand
2009-07-24 16:52 ` Doug Evans
2009-07-25 0:40 ` [unladen-swallow] " Reid Kleckner
2009-07-24 16:55 ` Reid Kleckner
2009-07-24 20:42 ` Eli Zaretskii
2009-07-24 20:55 ` Tom Tromey
2009-07-25 15:29 ` Eli Zaretskii
2009-07-27 23:20 ` Reid Kleckner
2009-07-28 20:20 ` Eli Zaretskii
2009-07-28 22:23 ` Reid Kleckner
2009-07-29 15:20 ` Eli Zaretskii
2009-07-24 21:06 ` Tom Tromey
2009-07-25 0:23 ` Reid Kleckner
2009-07-30 16:30 ` Tom Tromey
2009-07-30 16:54 ` Tom Tromey
2009-08-05 21:05 ` [unladen-swallow] " Reid Kleckner
2009-07-30 21:10 ` Thiago Jung Bauermann
2009-07-31 18:18 ` Thiago Jung Bauermann
2009-07-31 20:31 ` [unladen-swallow] " Reid Kleckner
2009-08-01 14:43 ` Thiago Jung Bauermann
2009-08-14 19:29 ` Tom Tromey
2009-08-14 23:37 ` Reid Kleckner
2009-08-17 15:31 ` Tom Tromey
2009-08-20 18:22 ` Doug Evans
2009-08-21 15:17 ` Ken Werner
2009-08-21 16:31 ` Doug Evans
2009-08-21 18:59 ` Ken Werner
2009-08-21 19:53 ` Doug Evans
2009-07-31 20:55 ` Paul Pluzhnikov
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=9a9942200907221617r4d9d2264q52b4c6605d4389c7@mail.gmail.com \
--to=rnk@mit.edu \
--cc=gdb-patches@sourceware.org \
--cc=unladen-swallow@googlegroups.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox