From: Tom Tromey <tromey@redhat.com>
To: Reid Kleckner <rnk@mit.edu>
Cc: gdb-patches@sourceware.org, unladen-swallow@googlegroups.com
Subject: Re: [RFA] Add interface for registering JITed code
Date: Fri, 24 Jul 2009 21:06:00 -0000 [thread overview]
Message-ID: <m38widq0dh.fsf@fleche.redhat.com> (raw)
In-Reply-To: <9a9942200907240946q1546646ft6e9112f263bcefdf@mail.gmail.com> (Reid Kleckner's message of "Fri\, 24 Jul 2009 09\:46\:52 -0700")
>>>>> "Reid" == Reid Kleckner <rnk@mit.edu> writes:
Reid> Here's an updated patch.
Very quick!
Reid> Where should this go? It doesn't really fit under any of the
Reid> top-level topics, so far as I can tell. I only have about a page to
Reid> write about it.
Yeah, I don't really have a suggestion for this.
Today I've also been wondering whether this works with core files.
Have you tried that? (I can't imagine why it wouldn't work. And I
don't think it is really a requirement; I'm just curious.)q
Also I was wondering about a multi-threaded JIT. I suppose it is
sufficient to mention in the documentation that the JIT is responsible
for making sure only a single thread can call __jit_debug_register_code
at a time.
Tom> Does the current code work ok if LLVM is a .so linked into the
Tom> application? I suspect, but do not know for sure, that in this
Tom> situation gdb will not see the JIT symbols when the inferior-created
Tom> hook is run.
Reid> I don't know, since we statically link to LLVM. I'm not an expert in
Reid> how dynamic loaders work, so I don't know how to fix this.
Ok. One way would be to stick some code in breakpoint_re_set and
update_breakpoints_after_exec. (I am not sure if this is the best way or
not.) Anyway the idea is that after a .so is noticed, re-do the searching,
in case the new .so is a JIT. So, the work would be done per-objfile,
and not once per inferior.
Maybe this can be done via observers as well; I don't know.
Tom> There is also the somewhat more pathological case of a program with
Tom> multiple JITs linked in. I'm on the fence about whether this is really
Tom> needed.
Reid> How would this work? Would they both have separate functions
Reid> __jit_debug_register at different addresses?
Yeah. This would work if you had two JITs in a process, say loaded
dynamically, and the various __jit symbols had hidden visibility.
Tom> You can store arbitrary module-specific data in an objfile using the
Tom> objfile_data API. This would be better because it is an already
Tom> supported way of dealing with the lifetime of the associated data.
Reid> Ah, that's much better. Unfortunately because the data for other
Reid> objfiles is uninitialized (it's returned from calloc), there's no way
Reid> for me to check which objfiles contain JITed code.
I don't think I understand. I thought you meant that you couldn't
detect whether or not the JIT datum was set on an objfile, but I see
that jit_inferior_exit_hook already does this the way that I would
expect.
Reid> Do I actually need to have this inferior_exit hook? I just
Reid> noticed that when I kill and restart the inferior it doesn't seem
Reid> to free these objfiles, so I added the hook.
Yeah, I think you need it.
I was thinking maybe this should just be a flag on the objfile, plus a
change to delete such objfiles in reread_symbols. But I am not sure
which is better, really; and your way is less invasive.
Reid> I took a shot at putting cleanups in, but I'm not sure I did it
Reid> correctly. In particular, I'm not sure about the discard_cleanups
Reid> logic.
It looks ok to me.
Just FYI, there's a section in the internals manual about cleanups that
is reasonably clear.
Tom> Please update the comment here to explain that these values are exported
Tom> and used by the inferior, so they cannot be changed.
Reid> Done. The same is true about the rest of the structs, the ordering of
Reid> the fields cannot be changed without updating the protocol version.
My reading of the code is that it unpacks target memory field-by-field
into the host-side structure. So, it is ok for this to change. What
cannot change is the definition of these structs on the target.
Am I misreading this?
These structs, in their target form, should probably all go in the
manual as well.
Reid> + /* Remember a mapping from entry_addr to objfile. */
Reid> + set_objfile_data (objfile, jit_objfile_data, (void*) entry_addr);
I don't think you need the cast here. There are a few of these.
Reid> + printf_unfiltered ("Unable to find JITed code entry at address: %p\n",
Reid> + (void*) entry_addr);
A style nit, in GNU style the cast is written "(void *)".
Reid> + nbfd = bfd_open_from_memory (templ, buffer, size, filename);
Reid> + if (nbfd == NULL)
Reid> + error (_("Unable to create BFD from local memory: %s"),
Reid> + bfd_errmsg (bfd_get_error ()));
Reid> +
Reid> + /* We set loadbase to 0 and assume that the symbol file we're loading has the
Reid> + absolute addresses set in the ELF. */
Reid> + loadbase = 0;
Reid> + objfile = symbol_file_add_from_memory_common (nbfd, loadbase, 0);
I suspect this needs a cleanup to free the BFD in case
symbol_file_add_from_memory_common errors. But I couldn't tell
immediately if that is possible (in gdb I tend to assume that anything
can throw...).
Tom
next prev parent reply other threads:[~2009-07-24 20:42 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
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 [this message]
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=m38widq0dh.fsf@fleche.redhat.com \
--to=tromey@redhat.com \
--cc=gdb-patches@sourceware.org \
--cc=rnk@mit.edu \
--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