From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from simark.ca by simark.ca with LMTP id 2xZiC7ht6mjStCkAWB0awg (envelope-from ) for ; Sat, 11 Oct 2025 10:46:16 -0400 Authentication-Results: simark.ca; dkim=pass (2048-bit key; unprotected) header.d=gnu.org header.i=@gnu.org header.a=rsa-sha256 header.s=fencepost-gnu-org header.b=TkK7uiT0; dkim-atps=neutral Received: by simark.ca (Postfix, from userid 112) id 1FE821E047; Sat, 11 Oct 2025 10:46:16 -0400 (EDT) X-Spam-Checker-Version: SpamAssassin 4.0.1 (2024-03-25) on simark.ca X-Spam-Level: X-Spam-Status: No, score=-3.4 required=5.0 tests=ARC_SIGNED,ARC_VALID,BAYES_00, DKIMWL_WL_HIGH,DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,MAILING_LIST_MULTI, RCVD_IN_DNSWL_MED,RCVD_IN_VALIDITY_CERTIFIED_BLOCKED, RCVD_IN_VALIDITY_RPBL_BLOCKED,RCVD_IN_VALIDITY_SAFE_BLOCKED autolearn=ham autolearn_force=no version=4.0.1 Received: from server2.sourceware.org (server2.sourceware.org [8.43.85.97]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange x25519 server-signature ECDSA (prime256v1) server-digest SHA256) (No client certificate requested) by simark.ca (Postfix) with ESMTPS id 576D81E047 for ; Sat, 11 Oct 2025 10:46:14 -0400 (EDT) Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id E35953857835 for ; Sat, 11 Oct 2025 14:46:13 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org E35953857835 Authentication-Results: sourceware.org; dkim=pass (2048-bit key, unprotected) header.d=gnu.org header.i=@gnu.org header.a=rsa-sha256 header.s=fencepost-gnu-org header.b=TkK7uiT0 Received: from eggs.gnu.org (eggs.gnu.org [IPv6:2001:470:142:3::10]) by sourceware.org (Postfix) with ESMTPS id DA6973857C6C for ; Sat, 11 Oct 2025 14:45:39 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org DA6973857C6C Authentication-Results: sourceware.org; dmarc=pass (p=none dis=none) header.from=gnu.org Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=gnu.org ARC-Filter: OpenARC Filter v1.0.0 sourceware.org DA6973857C6C Authentication-Results: server2.sourceware.org; arc=none smtp.remote-ip=2001:470:142:3::10 ARC-Seal: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1760193940; cv=none; b=ok/FlBO7Sv2a0xJ/kZmfhqW8X0VurJI/QqyNok9fR8uu7mfz5e3mnqtJm8zXkQWMrKGL5VKXVZauYoMp//S/9K343s+sWBqpzP+2+D54oy+kRvz7/sihH0PzJvPDLVqPHQRVkZM795cd2nypVCbSUgCedRq856qGGPcLWRKU3vk= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1760193940; c=relaxed/simple; bh=4bWdUUlTk+9xZyIwav0R/HqhW6/0ilE8FJMZoZ9cOCE=; h=DKIM-Signature:Date:Message-Id:From:To:Subject; b=eI85QfN41dvxps/sY0KAmA16KVxSL/2MCYsyu17OxC2nJz1xMonpo2JhLHy3SzsEWSNZ041+VEaKc0fMuJUzv/Vrk1rhFkeyoa5PZ5TRFtIaJnl/rLxLGkK+VxHM2nsulQt/pMzyzkhAUw7JxgtYpnFE0EgRCL7S71KZMMpfyNw= ARC-Authentication-Results: i=1; server2.sourceware.org DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org DA6973857C6C Received: from fencepost.gnu.org ([2001:470:142:3::e]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1v7aqn-00050S-I6; Sat, 11 Oct 2025 10:45:37 -0400 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=gnu.org; s=fencepost-gnu-org; h=References:Subject:In-Reply-To:To:From:Date: mime-version; bh=/AZakgsxsYx6PM1nMBs5SxwtTpNs03YEtGh5o3xLGXw=; b=TkK7uiT0Xht7 6tjK4uumpwUoROwF0SjjHwAMf8X1WDEEdoe+oeElzrQjHrjIXTkVHOmrDlgDvYYWdZz8CIqmI6EZV QepW+ZhDWPXCRH2Jb7AKA72CIWvJsMh7zUiOS04NYUCqeWeSXcR6m8K5vMHALjjkAt0kKKhIAndp/ q5yitF1DEggt3xqQ5wV0MqtWMq/ZXPrrLXLa5+aPtYR72yRmjYfbv/L8pjsyT7zX53t9wV/KMwvvL iCzhX8O/AlTuxYVHPQo2882YyyA989nc2dyasDKuO7Se5v4HdBvLsgteOJGySBcuxZntsH0sy3Lg4 UYj2veeEuSJYSbUrdB7HVQ==; Date: Sat, 11 Oct 2025 17:45:32 +0300 Message-Id: <86347p5wfn.fsf@gnu.org> From: Eli Zaretskii To: Andrew Burgess Cc: gdb-patches@sourceware.org In-Reply-To: (message from Andrew Burgess on Sat, 11 Oct 2025 14:34:04 +0100) Subject: Re: [PATCH 2/2] gdb: use current executable for 'remote exec-file' in some cases References: <40cbbd9f0082b07e9767656fe044bbe9280983a3.1759763251.git.aburgess@redhat.com> X-BeenThere: gdb-patches@sourceware.org X-Mailman-Version: 2.1.30 Precedence: list List-Id: Gdb-patches mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: gdb-patches-bounces~public-inbox=simark.ca@sourceware.org > From: Andrew Burgess > Cc: Andrew Burgess , > Eli Zaretskii > 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 > --- > 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