From: Andrew Burgess <aburgess@redhat.com>
To: Eli Zaretskii <eliz@gnu.org>
Cc: guinevere@redhat.com, gdb-patches@sourceware.org
Subject: Re: [PATCH] gdb, configure: Add disable-formats option for configure
Date: Fri, 04 Oct 2024 15:26:25 +0100 [thread overview]
Message-ID: <87bk00x7u6.fsf@redhat.com> (raw)
In-Reply-To: <86ed4y1tgg.fsf@gnu.org>
Eli Zaretskii <eliz@gnu.org> writes:
>> From: Andrew Burgess <aburgess@redhat.com>
>> Cc: gdb-patches@sourceware.org
>> Date: Wed, 02 Oct 2024 14:25:05 +0100
>>
>> Consider the base gdb package as shipped with Fedora Linux. The
>> `--target' is set to match the `--host', but in addition we pass
>> `--enable-targets=' to cover a select few architectures running Linux.
>> There's no Windows, Solaris, FreeBSD, AIX, or any other OS support built
>> in which means the GDB will not be able to remote debug any of these
>> targets in a meaningful way[1]. Fedora just doesn't want to commit to
>> supporting debug for these targets, and this includes both OS and
>> architecture choices. And that's OK. There are other packages which
>> offer builds of GDB for specific other target, for example, there's a
>> package which offers bare-metal AVR support, which is not something the
>> base gdb package supports.
>>
>> However, right now, despite only configuring to support Linux based
>> targets, Fedora GDB still end up building in support for many different
>> file formats that we just don't care about, and we'd really like a
>> configure option that allows distributions to compile out the file
>> formats that they don't want to support, just as, right now, Fedora
>> chooses not to support debug on many different OSes.
>>
>> I hope this helps a little.
>
> It does, thanks. What is still missing is the division of labor
> between GDB and gdbserver in the remote-debugging scenario. What I
> thought was that gdbserver only needs to know some part of the
> target's support, like starting and stopping the program, inserting
> breakpoints, etc. Whereas GDB needs to be able to read the debug
> info, access and show the source and machine code, etc. Is that true?
Yes.
gdbserver supports far fewer target OSes than GDB itself, as far as I
can tell it's Linux, netbsd, or Windows.
Unlike GDB, gdbserver only every supports a single target. This makes
sense as gdbserver only ever controls native processes running on the
same machine as gdbserver itself. This is enforced at configure time,
if we configure the binutils-gdb tree with --target not equal to --host
then the gdbserver directory will be disabled, and we don't even attempt
to build gdbserver.
GDB splits target support into *-tdep.c and *-nat.c files. The *-nat.c
file is for lower level, native target stuff, e.g. how do I create a new
process, how do I read the registers.
Then the *-tdep.c files are for higher level target specific stuff,
e.g. setting up platform specific types, registering special frame
unwinders, signal handling details, etc.
gdbserver only needs to include the lower level knowledge, the
equivalent of the *-nat.c files, though on the gdbserver side these
files are called *-low.cc. Some code is shared between GDB and
gdbserver in this area, but not everything. This can, and should be
improved.
But the high level logic, the *-tdep.c files, only live in GDB. When a
target is compiled into GDB this causes the tdep files to get built in.
Which nat files we build in depends on the --host configure option, that
is, where is GDB (the program) going to run.
> If so, then building GDB with support for reading debug info in
> various formats will allow the user to connect to a gdbserver that
> supports a specific target, even though GDB itself wasn't built with
> support for that target (since GDB can connect and talk to a gdbserver
> from a different build of GDB). Am I wrong about this?
The problem is that reading the file is only one part of the process.
The target specific tdep file adds higher level knowledge on top of the
file contents.
I dug out an old windows machine and setup the following debug
environment: on the windows machine I built gdbserver for
x86_64-w64-mingw32, then on an x86-64 Linux machine I built GDB only
with support for x86_64-redhat-linux. The source I was building from
didn't include Gwen's patch, so all file formats are usable.
GDB is able to connect to gdbserver, and can read the executable and
libraries, and can extract the symbols. However, GDB gets the addresses
for all symbols wrong.
The reason for this can be found in windows_init_abi_common where we
call set_gdbarch_so_ops. This call registers some callbacks that are
used whenever GDB opens a library or executable. These callbacks can do
things like fix up the objfile section addresses, which is exactly
what's being done in this case. As the windows_init_abi_common is in
windows-tdep.c, when this file is not compiled in, GDB doesn't really
"understand" the executable file within a Windows context, and so the
sections offsets are left as 0, and GDB gets all the symbol addresses
wrong.
So, I can disassemble instructions using an address and length,
e.g. 'x/10i ADDRESS', or place breakpoints by address 'b *ADDRESS', but
I can't do anything that relies on symbols, e.g. 'b main', or
'disassemble main'.
In addition GDB isn't going to be able to backtrace correctly, skip
function prologues, or any of that other good stuff.
Out of interest, I also tried building GDB with only Linux support, and,
using Gwen's patch, with only ELF file format support. My thinking was
that, if previously GDB could read the file, but couldn't actually do
anything useful with the symbols, then maybe we're no worse off if GDB
just can't read the file at all...
...unfortunately, GDB segfault. I'll report this to Gwen separately.
But in theory, we'd probably be better off if GDB didn't read the
symbols from the file, given that GDB can't then figure out the correct
addresses.
> If I'm right, then there are two separate aspects to "target": on the
> one side, the ability to start/stop executables, insert breakpoints
> and watchpoints, etc., and OTOH the ability to read and process debug
> info used by that target, implement frame unwinders, etc. Are we
> currently conflating these into a single notion of "target", and if
> so, will the proposed changes include or exclude both parts of each
> "target"?
I agree with you about "target" having two components, the lower level
stuff, and the higher level stuff.
File format support, being able to read from file, only (I think)
impacts higher level functionality. But just reading the file isn't (I
claim) enough, we need the higher level functionality in order to really
"understand" the file contents.
My claim then is that being able to remove the file format support will
actually make the GDB slightly better (in some cases) as GDB will no
longer be able to read a file which it is then unable to correctly
process the contents of.
Thanks,
Andrew
next prev parent reply other threads:[~2024-10-04 14:26 UTC|newest]
Thread overview: 30+ messages / expand[flat|nested] mbox.gz Atom feed top
2024-09-25 17:53 Guinevere Larsen
2024-09-26 5:49 ` Eli Zaretskii
2024-09-26 18:16 ` Guinevere Larsen
2024-09-26 18:35 ` Eli Zaretskii
2024-09-26 21:03 ` Guinevere Larsen
2024-09-27 6:05 ` Eli Zaretskii
2024-10-02 13:25 ` Andrew Burgess
2024-10-02 14:15 ` Eli Zaretskii
2024-10-04 14:26 ` Andrew Burgess [this message]
2024-10-04 14:45 ` Eli Zaretskii
2024-10-07 18:30 ` Guinevere Larsen
2024-10-07 19:17 ` Eli Zaretskii
2024-10-07 19:58 ` Guinevere Larsen
2024-10-08 11:44 ` Eli Zaretskii
2024-10-08 13:03 ` Guinevere Larsen
2024-10-08 13:21 ` Eli Zaretskii
2024-10-10 14:45 ` Guinevere Larsen
2024-10-10 16:10 ` Andrew Burgess
2024-09-26 19:18 ` Tom Tromey
2024-09-26 19:49 ` Guinevere Larsen
2024-09-27 18:01 ` Tom Tromey
2024-10-02 13:56 ` Andrew Burgess
2024-10-02 20:37 ` Guinevere Larsen
2024-10-03 10:15 ` Andrew Burgess
2024-10-04 14:49 ` Andrew Burgess
2024-10-10 20:18 ` Guinevere Larsen
2024-10-16 10:50 ` Andrew Burgess
2024-10-16 21:00 ` Guinevere Larsen
2024-10-17 19:43 ` Tom Tromey
2024-10-17 19:48 ` Guinevere Larsen
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=87bk00x7u6.fsf@redhat.com \
--to=aburgess@redhat.com \
--cc=eliz@gnu.org \
--cc=gdb-patches@sourceware.org \
--cc=guinevere@redhat.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;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).