public inbox for gdb@sourceware.org
 help / color / mirror / Atom feed
From: Tom Tromey <tom@tromey.com>
To: Andrew Dinn via Gdb <gdb@sourceware.org>
Cc: Andrew Dinn <adinn@redhat.com>
Subject: Re: gcj debug question
Date: Wed, 09 Nov 2022 09:10:59 -0700	[thread overview]
Message-ID: <87h6z82jn0.fsf@tromey.com> (raw)
In-Reply-To: <2932d319-9e73-53f1-0f97-bf2d67fdb879@redhat.com> (Andrew Dinn via Gdb's message of "Tue, 25 Oct 2022 11:48:41 +0100")

>>>>> "Andrew" == Andrew Dinn via Gdb <gdb@sourceware.org> writes:

Andrew> I'm hoping there is still enough institutional memory left somewhere
Andrew> in this forum to provide info about (the now defunct) DWARF support
Andrew> for gcj. Specifically, does anyone have a long enough memory to recall 
Andrew> whether and, if so, how gcj advertised the presence of Java reflective
Andrew> class objects (instances of java.lang.Class) to the debugger?

You can see all the old code in commit 9c37b5ae, which removed it.
Most of what you want is in jv-lang.c.

Andrew>   - Did it insert linker symbols for e.g. org.my.Foo.class into a
Andrew>     generated binary?

I believe gcj did do this, but gdb also knew how to extract the vtable
from an object, use that to find the runtime's class object, and then
decode that object to make a gdb 'struct type'.  See
java_class_from_object and type_from_class.

It's been a long time but my recollection is that debugging Java didn't
work extremely well.  When I worked on gcj I basically knew nothing
about gdb and so I never tried to fix any of the bugs.

The main issue with this kind of thing is that there has to be a way to
communicate the Class layout from the runtime to gdb.  DWARF could be
used for this, of course, but often these kinds of system libraries are
stripped.  Ada has this problem for task objects, and there we just have
gdb know the object layout... not really ideal.

If I was doing this again I'd probably look into whether enough Python
infrastructure could be added so that the magic could be done in Python
code that was shipped alongside libgcj.  That would break this link
between the runtime and the debugger.  For basic debugging it could
maybe all be done via pretty-printers; though of course that doesn't
work if you want to support 'ptype'.

Andrew>   - Did it emit DWARF info records with tag DW_TAG_variable and
Andrew>     associated attributes like name, type, linkage name and location?

I am not sure.

One thing to note is that gcj had two ABIs.  One ABI was C++-like and
was used for the core classes.  For example, all of java.lang (IIRC)
would have been built this way.  In this mode, object and vtable layout
was mostly compatible with C++ and so (I assume, I don't recall looking
at this much) ordinary C++-ish DWARF would have been emitted.

There was also the "binary compatibility ABI", which tried to follow the
Java binary compatibility rules.  This mode deferred object and vtable
layout (and other related decisions) until class initialization.
Normally, user code would be compiled in this mode.  I'm not sure what
the DWARF would have looked like here, but it couldn't have been very
ordinary, because things like data member offsets wouldn't be known
until after class initialization, and in those days gdb didn't
understand things like dynamic type layout.

Andrew>   - In the latter case were these records located in the class (tag
Andrew>     DW_TAG_class) info record or at top level in the same compile unit
Andrew>    as the class?

In DWARF these are always nested in the DW_TAG_class.  Top-level is for
things like global variables.  (A Java static member would still be
under the class, Java doesn't have this kind of global.)

Tom

  reply	other threads:[~2022-11-09 16:11 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-10-25 10:48 Andrew Dinn
2022-11-09 16:10 ` Tom Tromey [this message]
2022-11-21 14:23   ` Andrew Dinn
2022-11-21 14:35     ` Jan Vrany

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=87h6z82jn0.fsf@tromey.com \
    --to=tom@tromey.com \
    --cc=adinn@redhat.com \
    --cc=gdb@sourceware.org \
    /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;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).