From: Eli Zaretskii <eliz@gnu.org>
To: Andrew Burgess <aburgess@redhat.com>
Cc: gdb-patches@sourceware.org
Subject: Re: [PATCH 2/2] gdb: use current executable for 'remote exec-file' in some cases
Date: Sat, 11 Oct 2025 17:45:32 +0300 [thread overview]
Message-ID: <86347p5wfn.fsf@gnu.org> (raw)
In-Reply-To: <e8ed8893919474e529d30b9ce52fd5dad418f3f7.1760189398.git.aburgess@redhat.com> (message from Andrew Burgess on Sat, 11 Oct 2025 14:34:04 +0100)
> From: Andrew Burgess <aburgess@redhat.com>
> Cc: Andrew Burgess <aburgess@redhat.com>,
> Eli Zaretskii <eliz@gnu.org>
> Date: Sat, 11 Oct 2025 14:34:04 +0100
>
> This commit allows GDB to make use of the file set with the 'file'
> command when starting a new inferior on an extended-remote target.
> There are however some restrictions.
>
> If the user has used 'set remote exec-file', then this setting is
> always used in preference to the file set with the 'file' command.
>
> Similarly, if the qExecAndArgs packet has succeeded, and GDB knows
> that the remote target has an executable set, then this will be used
> in preference to the file set with the 'file' command; this preserves
> GDB's existing behaviour. In effect, when GDB connects to the remote
> target, the remote sets the 'remote exec-file' and this prevents GDB
> from using the 'file' filename.
>
> And, GDB can only use the file set with the 'file' command if it
> believes that both GDB and the remote target will both be able to
> access this file. This means that one of these is true:
>
> + the the remote_target::filesystem_is_local function returns
> true (see the implementation of that function for details of when
> this can happen). This means GDB and the remote target can see
> the same file system, GDB can just use the current executable's
> filename as is, or
>
> + the user has set the 'file' to something with a 'target:' prefix,
> e.g. 'file target:/path/to/exec'. In this last case, GDB will use
> the exec filename without the 'target:' prefix, this filename is,
> by definition, something the remote target can see, or
>
> + the sysroot has been updated by the user and no longer contains a
> 'target:' prefix. In this case, if the 'file' filename is within
> the sysroot, then it is assumed the remote will also be able to
> see a file with the same filename. For example, if the sysroot is
> '/aa/', and the current executable is '/aa/bb/cc', then GDB will
> tell the remote to run '/bb/cc'. One common case here is when the
> sysroot is set to the empty string, which is usually done when GDB
> and the remote target can see the same filesystem, in this case
> GDB will use the current executable's filename unmodified.
>
> If one of these conditions is met, then GDB will use the current
> executable's filename (with possible modifications as mentioned
> above), when starting a new extended-remote inferior, in all other
> cases, GDB will use the file name set with 'set remote exec-file'.
>
> This change could be useful any time a user is running a remote target
> on the same machine as GDB, but I am specifically thinking of the case
> where GDB is using a tool other than gdbserver, e.g. valgrind, as this
> saves one additional step that a user must remember. The current
> steps to start valgrind with GDB, as given on the valgrind
> website (https://valgrind.org/docs/manual/manual-core-adv.html) are:
>
> $ gdb prog
> (gdb) set remote exec-file prog
> (gdb) set sysroot /
> (gdb) target extended-remote | vgdb --multi --vargs -q
> (gdb) start
>
> With this GDB work, and once support for the qExecAndArgs packet is
> added to valgrind, then the 'set remote exec-file' line can be dropped
> from those instructions.
>
> This commit also extends the 'show remote exec-file' command so that
> GDB will display the automatic value that it plans to use. Here's an
> example of the new output:
>
> $ gdb -q /tmp/hello
> Reading symbols from /tmp/hello...
> (gdb) set sysroot
> (gdb) target extended-remote | ./gdbserver/gdbserver --multi --once -
> Remote debugging using | ./gdbserver/gdbserver --multi --once -
> Remote debugging using stdio
> (gdb) show remote exec-file
> The remote exec-file is unset, using automatic value "/tmp/hello".
>
> The last line shows the new output.
>
> Reviewed-By: Eli Zaretskii <eliz@gnu.org>
> ---
> gdb/NEWS | 8 ++
> gdb/doc/gdb.texinfo | 4 +-
> gdb/remote.c | 156 +++++++++++++++++++++++---
> gdb/testsuite/gdb.server/ext-run.exp | 160 ++++++++++++++++++++++-----
> 4 files changed, 286 insertions(+), 42 deletions(-)
Thanks, the documentation parts are okay.
Reviewed-By: Eli Zaretskii <eliz@gnu.org>
next prev parent reply other threads:[~2025-10-11 14:46 UTC|newest]
Thread overview: 20+ messages / expand[flat|nested] mbox.gz Atom feed top
2025-10-06 15:07 [PATCH] " Andrew Burgess
2025-10-06 15:43 ` Eli Zaretskii
2025-10-09 16:17 ` Simon Marchi
2025-10-11 13:34 ` [PATCH 0/2] Auto setting of 'remote exec-file' Andrew Burgess
2025-10-11 13:34 ` [PATCH 1/2] gdb/remote: replace use of std::pair with an actual struct Andrew Burgess
2025-10-11 13:46 ` Simon Marchi
2025-10-12 8:57 ` Andrew Burgess
2025-10-12 12:05 ` Simon Marchi
2025-10-12 13:13 ` Andrew Burgess
2025-11-19 10:32 ` Andrew Burgess
2025-10-11 13:34 ` [PATCH 2/2] gdb: use current executable for 'remote exec-file' in some cases Andrew Burgess
2025-10-11 14:45 ` Eli Zaretskii [this message]
2025-11-07 20:46 ` Simon Marchi
2025-11-11 15:59 ` Andrew Burgess
2026-01-14 1:17 ` Simon Marchi
2026-01-14 16:48 ` Andrew Burgess
2026-01-14 20:01 ` [PATCH] gdb/testsuite: fix failure in gdb.server/fetch-exec-and-args.exp Andrew Burgess
2026-01-15 21:13 ` Simon Marchi
2026-01-22 15:31 ` Andrew Burgess
2025-11-19 10:32 ` [PATCH 2/2] gdb: use current executable for 'remote exec-file' in some cases Andrew Burgess
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=86347p5wfn.fsf@gnu.org \
--to=eliz@gnu.org \
--cc=aburgess@redhat.com \
--cc=gdb-patches@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