Mirror of the gdb mailing list
 help / color / mirror / Atom feed
From: Jeffrey Yasskin <jyasskin@google.com>
To: LLVM Developers Mailing List <llvmdev@cs.uiuc.edu>, gdb@sourceware.org
Subject: Re: [LLVMdev] Connecting JITted code to gdb
Date: Tue, 31 Mar 2009 19:34:00 -0000	[thread overview]
Message-ID: <bb55930e0903311233y561e7d7cs8d28fd132b8fd23f@mail.gmail.com> (raw)
In-Reply-To: <C752E939-A789-4958-9BA8-FDB0663585E3@apple.com>

I'm adding the gdb list because it appears there's currently no way to
tell gdb about newly-JITted code. That is, it's not an LLVM-specific
problem.

There appear to be two techniques in common use to debug
dynamically-generated code despite this. First, as Evan suggests
below, we can have the JIT print the address range that it's written a
function into, have gdb disassemble that, set breakpoints at
particular addresses, and print variables by knowing what register
they live in. Second, as described at
http://www.mono-project.com/Debugging#Debugging_with_GDB_in_XDEBUG_mode,
we can write out a full object file with dwarf tables, and use
add-symbol-file to get gdb to load that on demand.

Neither of these is ideal. add-symbol-file is better, but it doesn't
allow us to set breakpoints inside the JITted code until it's
generated, and it doesn't let those breakpoints follow the code as
it's re-optimized and re-translated. It currently also requires user
interaction, but it's possible that we could write a -gdb.py file to
reload the debug information every time the user gets to the gdb
prompt. There may be other problems I haven't though of.

It would be better to have an interface through which a JITting
library could tell gdb about newly-generated code. This could resemble
the overlay interface
(http://sourceware.org/gdb/current/onlinedocs/gdb_13.html#SEC108) or
the interface through which dynamic loaders tell gdb about
newly-loaded code. There are a couple considerations that are specific
to JITting, of course:
 1. A JIT compiler generates new code frequently, and having to do
lots of extra work, especially while the debugger isn't attached, may
hurt performance.
 2. Translated code gets duplicated, replaced, and freed, and gdb
needs to modify its breakpoints to keep up.

I don't really know enough about the internals of LLVM or gdb to make
any recommendations, but I think it would be useful to find some way
for them (and other debuggers and JITs) to talk to each other.

Jeffrey

On Fri, Mar 27, 2009 at 1:48 PM, Evan Cheng <evan.cheng@apple.com> wrote:
> Run with -debug-only=jit.
>
> Break on line 1148 of JITEmitter.cpp. The debugging message will tell
> you the address and size of the function that was jitted. You can then
> tell gdb to disassemble the code.


       reply	other threads:[~2009-03-31 19:34 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
     [not found] <bb55930e0903262335q2023929ew9d30e03a1fff4867@mail.gmail.com>
     [not found] ` <C752E939-A789-4958-9BA8-FDB0663585E3@apple.com>
2009-03-31 19:34   ` Jeffrey Yasskin [this message]
2009-04-01 19:20     ` Tom Tromey

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=bb55930e0903311233y561e7d7cs8d28fd132b8fd23f@mail.gmail.com \
    --to=jyasskin@google.com \
    --cc=gdb@sourceware.org \
    --cc=llvmdev@cs.uiuc.edu \
    /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