From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from simark.ca by simark.ca with LMTP id GU+xNyz64WqkOD4AWB0awg (envelope-from ) for ; Wed, 28 Oct 2026 09:35:40 -0400 Authentication-Results: simark.ca; dkim=pass (1024-bit key; unprotected) header.d=redhat.com header.i=@redhat.com header.a=rsa-sha256 header.s=mimecast20190719 header.b=aIM846Zj; dkim-atps=neutral Received: by simark.ca (Postfix, from userid 112) id DE547378002; Wed, 28 Oct 2026 09:35:40 -0400 (EDT) X-Spam-Checker-Version: SpamAssassin 4.0.1 (2024-03-25) on simark.ca X-Spam-Level: X-Spam-Status: No, score=-6.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 autolearn=ham autolearn_force=no version=4.0.1 Received: from vm01.sourceware.org (vm01.sourceware.org [IPv6:2620:52:6:3111::32]) (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 DFC7A378002 for ; Wed, 28 Oct 2026 09:35:39 -0400 (EDT) Received: from vm01.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 22CB74BA23D9 for ; Wed, 28 Oct 2026 13:35:38 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 22CB74BA23D9 Authentication-Results: sourceware.org; dkim=pass (1024-bit key, unprotected) header.d=redhat.com header.i=@redhat.com header.a=rsa-sha256 header.s=mimecast20190719 header.b=aIM846Zj Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.133.124]) by sourceware.org (Postfix) with ESMTP id 6FF7E4BA2E05 for ; Wed, 28 Oct 2026 13:35:11 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 6FF7E4BA2E05 Authentication-Results: sourceware.org; dmarc=pass (p=quarantine dis=none) header.from=redhat.com Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=redhat.com ARC-Filter: OpenARC Filter v1.0.0 sourceware.org 6FF7E4BA2E05 Authentication-Results: sourceware.org; arc=none smtp.remote-ip=170.10.133.124 ARC-Seal: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1793194511; cv=none; b=GMbawTUBxXECzlmUZir6AWuV2M7AjZZ00+OcXt6FYoYUzzf+SzHerVy9VzXJH3jY62r/Bhjqui29ehL4rMh8SApMNZ1Ofo1c6r4wFFpVlWAZmjw0DDBk0s3IBRsG3rOXqUTjqGH6Gn/38PnaoUAPZZfNoOUEA65NcJplT5qyccs= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1793194511; c=relaxed/simple; bh=bKVd4Q1vRMznqV8RaDKxMDVu9BlcSCbhLhiHUpmuAjU=; h=DKIM-Signature:From:To:Subject:Date:Message-Id:MIME-Version; b=jSBy8ldIfkEPbS2UTEMMMiwvTsjfJlU45TDGTe6JT8o3DrkFE/w3QWhNr+s7rGAsF3H0Ffn+DfD3MqwJTy80eMqSPqUORLS0IzyUMYw/bRrDdeMANukFHsSp5e43/vE67FktcnY4k/kVHbiCbgBuzOSW7cul13y/ci+0qzaZ0ww= ARC-Authentication-Results: i=1; sourceware.org; dkim=pass (1024-bit key, unprotected) header.d=redhat.com header.i=@redhat.com header.a=rsa-sha256 header.s=mimecast20190719 header.b=aIM846Zj DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 6FF7E4BA2E05 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1793194511; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding; bh=QVupsQmxp2k2Zf/cp2IAt8d+n8qnRFUQ1rlVJbsPSJQ=; b=aIM846ZjflVGfVMW5gBbmkkYh2/uOhgA2kRKyrwXvKuU3lyvhIIbXb4PJS0RWWjWyqHf4I BipHS2PbTRpalIGEq10XpjeO2p8ckSsBvoy+UY03wpQ7pGrHnBVY4akE+51DlLh7+E7mf9 CI4htpG1bG4d7e8KbIXvWFnyj9NKHYU= Received: from mail-wm1-f72.google.com (mail-wm1-f72.google.com [209.85.128.72]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-636-wB534NIHMj-D9tya_uJvTw-1; Wed, 28 Oct 2026 09:35:09 -0400 X-MC-Unique: wB534NIHMj-D9tya_uJvTw-1 X-Mimecast-MFC-AGG-ID: wB534NIHMj-D9tya_uJvTw_1793194508 Received: by mail-wm1-f72.google.com with SMTP id 5b1f17b1804b1-4a9d51dc486so3223905e9.1 for ; Wed, 28 Oct 2026 06:35:09 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20260707; t=1793194508; x=1793799308; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:x-gm-gg:x-gm-message-state:from:to:cc:subject:date :message-id:reply-to:content-type; bh=QVupsQmxp2k2Zf/cp2IAt8d+n8qnRFUQ1rlVJbsPSJQ=; b=SwMM5zwNBUH6ROlW6KhHNW+H41Iy+mfevxho5nAndV7hTvsknlvBP/sZ9y26gni2jc 0hmJa7Qxe6OMjvTTjY4gYEMnKVPF7fKNirXs19QbTmu8DkwivHnJ3CcMBAgtPiDCwjOL 2/6Jod5BRrx79UvMOJBbqYIJ8SQr4qySPPb2NmFCYYBlLTVgAmOGuR1NJUrWlRe48W7L Qjm81WqCuB0aOtg9/BurEQel2TvhWstyD8QfgaObWwEDzQUqWzoF4z0RXtAWak4oIRAF HLnoElm835bRGyG+iII47aCsYO7Vd11cyCUMf4v3+OGPZ50r2Qmye24LKFthhBPS9vTi m0Zg== X-Gm-Message-State: AFq9FYIbGaALdUtujdqUUBcnOFtCIISB2Puzx45wo6pCMumjK3u9nkGY H4jqPGgX/pMR22UF5e4BtMnhKhGJnYK4oMa98WBU3wzxC8fMUD/EUSgC7D23vkSGGf6PJDHZhZa mj3e1etKCg3L3MbAtBLmvWXsnVJsAD6dRAho1RWrlLrzCMHHEdeK+QJTg7fS7ys2QeLBMbXukNx 0O353f6P9sUMEOEtWCCAQMMOXdNzDBWx6IRhhQeztTkbkakwI= X-Gm-Gg: AYBFou2bALbCRZ+Cu7oMc++YPINLnqxnVlWqIjzRBLqtDd342Fj/0FjAVHU1Ipm/sJ1 t1/W4RXrfUUMh1h3ZRxD9uP7Ox4n7qG/hTD8Eqqa1SyH9jl9a4c7TJWCbRgawE5QsgqyexqWPE4 090YGF1RInq4UeFcKLK6XEROEGkDj0OD1O/Lrvhs2HmdbBYFhOgzQNnVFHhMlpApdoLl86iim1A WKONCBkeUcnJvI9Y6lbGyKKkPesSe5xJTQhCX/fT98h2BPJMRd80AILaS33qkM/OSIurO/YXOce Lkgcz1WF/OR6vCDbLHzHKrW9OdHgErsMF2pYbbqF5mmqTZg8ZhtRdaf4PcYM3j7YcV8UJDoMdZp G+UVIMi+CGKuHQUXvuyOFMovGVMIyz9XYI/FxUzLl19PBY5M= X-Received: by 2002:a05:6000:310f:b0:48e:1b11:7ee6 with SMTP id ffacd0b85a97d-48e601eb588mr3342718f8f.2.1793194506639; Wed, 28 Oct 2026 06:35:06 -0700 (PDT) X-Received: by 2002:a05:6000:310f:b0:48e:1b11:7ee6 with SMTP id ffacd0b85a97d-48e601eb588mr3341966f8f.2.1793194500202; Wed, 28 Oct 2026 06:35:00 -0700 (PDT) Received: from localhost ([2a00:23c6:e11d:fb01:6748:4fce:3e30:6e23]) by smtp.gmail.com with ESMTPSA id ffacd0b85a97d-48e3ebc3dd7sm28643778f8f.15.2026.10.28.06.34.59 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 28 Oct 2026 06:34:59 -0700 (PDT) From: Andrew Burgess To: gdb-patches@sourceware.org Cc: Andrew Burgess Subject: [PATCH] gdbserver: reset single_inferior_argument feature on a new connection Date: Wed, 28 Oct 2026 13:34:54 +0000 Message-Id: <4797c01ed0887b34fcdf765baa3714fbc7a230bc.1793194469.git.aburgess@redhat.com> X-Mailer: git-send-email 2.25.4 MIME-Version: 1.0 X-Mimecast-Spam-Score: 0 X-Mimecast-MFC-PROC-ID: iSQhB2snrppRx6hxu6n5gjt0SQ38AfLBTQFfJK2VV7I_1793194508 X-Mimecast-Originator: redhat.com Content-Transfer-Encoding: 8bit content-type: text/plain; charset="US-ASCII"; x-default=true 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 In commit: commit 8e28eef6cdcbd86ad61325ce1e6bd563b0fad1e1 Date: Thu Nov 23 18:46:54 2023 +0000 gdb/gdbserver: pass inferior arguments as a single string the new single_inferior_argument feature was added to gdbserver. There was a mistake in that commit though, the new connection flag was not reset at the point that a new connection was established as other flags are. This means that the flag value will carry over from one connection to the next, which in turn means that connecting with a GDB that supports the single-inferior-argument feature will latch the feature on in gdbserver. Reconnecting with a GDB that doesn't support this feature will then mean that GDB is unable to start a new inferior with more than a single argument. I have a test that exposes the issue by switching off the single-inferior-argument feature in GDB. This bug was introduced in the GDB 18 release, so the fix should probably be backported to the gdb-18-branch too. However, I'm not massively worried about this bug. In order to run into the problem users would need to have a single gdbserver session to which they first connect GDB 18, then to the *same* session they connect an older version of GDB. This seems an unlikely use case. Bug: https://sourceware.org/bugzilla/show_bug.cgi?id=34908 --- gdb/testsuite/gdb.server/inferior-args.exp | 101 +++++++++++++++++++++ gdbserver/server.cc | 1 + 2 files changed, 102 insertions(+) diff --git a/gdb/testsuite/gdb.server/inferior-args.exp b/gdb/testsuite/gdb.server/inferior-args.exp index f6ad3e69b40..4fb31ba2fd7 100644 --- a/gdb/testsuite/gdb.server/inferior-args.exp +++ b/gdb/testsuite/gdb.server/inferior-args.exp @@ -145,6 +145,105 @@ proc args_test { name arglist {re_esc_list {}} {re_no_esc_list {}} } { } } +# Start gdbserver in --multi mode, connect and start an inferior. +# Then switch off the single-inferior-argument-feature-packet and +# reconnect to the SAME gdbserver. Then try to start a new inferior +# passing multiple command line arguments. +# +# This checks that gdbserver correctly clears the feature flag for the +# single inferior argument feature. If it doesn't then the second +# connection will fail to start an inferior as there will be a +# disagreement between GDB and gdbserver about how the argument packet +# should be formatted. +proc reconnection_and_single_inf_args {} { + global GDBFLAGS gdbserver_reconnect_p use_gdb_stub + + save_vars { GDBFLAGS } { + # If GDB and GDBserver are both running locally, set the sysroot to avoid + # reading files via the remote protocol (the `is_remote target` check is + # already done above). + if { ![is_remote host] } { + set GDBFLAGS "$GDBFLAGS -ex \"set sysroot\"" + } + clean_restart $::testfile + + # Make sure we're disconnected, in case we're testing with an + # extended-remote board, therefore already connected. + gdb_test "disconnect" ".*" + } + + save_vars { gdbserver_reconnect_p use_gdb_stub } { + # Setting this flag prevents gdbserver being started with the + # --once option; this is required so that we can reconnect. + set gdbserver_reconnect_p 1 + + # This test always starts gdbserver in --multi mode, so clear + # the use_gdb_stub global to allow gdb_start_cmd to work. + set use_gdb_stub 0 + + # Start gdbserver in extended-remote mode. + set res [gdbserver_start "--multi" "$::binfile"] + set gdbserver_protocol "extended-remote" + set gdbserver_gdbport [lindex $res 1] + gdb_target_cmd $gdbserver_protocol $gdbserver_gdbport + + # Start an inferior passing multiple arguments. By default + # this will make use of the single-inferior-argument remote + # feature, passing these arguments as a single string. + if { [gdb_start_cmd "a b c"] < 0 } { + fail "start command" + return -1 + } + + # gdb_start_cmd doesn't consume the prompt. Collect it now. + gdb_test "" "" \ + "wait for prompt after starting the inferior" + + # Check the inferior saw the correct argument count; the + # executable name and three arguments: 'a', 'b', and 'c'. + gdb_test "print argc" " = 4" \ + "print argc after initial start" + + # Turn off the single-inferior-argument feature and reconnect. + # With the new connection gdbserver should reset its feature + # flags and renegotiate, so the new connection should end up + # not using this feature. + gdb_test "set remote single-inferior-argument-feature-packet off" \ + "Support for the 'single-inferior-argument-feature' packet on the current remote target is set to \"off\"\\." + + gdb_target_cmd $gdbserver_protocol $gdbserver_gdbport + + # Now start a new inferior, in the newly connected session. + # GDB will split these arguments and send them as 3 separate + # strings. If gdbserver messed up its feature flags then it + # will only be expecting a single string, in which case it + # will reject this request and not start the inferior. + if { [gdb_start_cmd "a b c"] < 0 } { + fail "second start command" + return -1 + } + + # This time we check for the 'remote target failed' message, + # this is the bug that was fixed when this test was added. + set saw_run_failure false + gdb_test_multiple "" "start inferior after reconnecting" -lbl { + -re "\r\nRunning \"\[^\r\n\]+/$::testfile\" on the remote target failed(?=\r\n)" { + set saw_run_failure true + exp_continue + } + + -re "\r\n$::gdb_prompt " { + gdb_assert { !$saw_run_failure } $gdb_test_name + } + } + + # Print the argc value as a double check. This confirms that + # the inferior started, and saw the correct number of args. + gdb_test "print argc" " = 4" \ + "print argc after reconnecting" + } +} + args_test "basic" {a b c} args_test "one empty" {1 "" 3} args_test "two empty" {1 "" "" 3} @@ -154,3 +253,5 @@ save_vars { env(TEST) } { set env(TEST) "ABCD" args_test "shell variable" {\$TEST} {\\$TEST} {ABCD} } + +reconnection_and_single_inf_args diff --git a/gdbserver/server.cc b/gdbserver/server.cc index 74774fcde7c..a7d966ce7e3 100644 --- a/gdbserver/server.cc +++ b/gdbserver/server.cc @@ -4629,6 +4629,7 @@ captured_main (int argc, char *argv[]) cs.vCont_supported = 0; cs.memory_tagging_feature = false; cs.error_message_supported = false; + cs.single_inferior_argument = false; cs.multiple_wp_addr_feature = false; remote_open (port); base-commit: b2fe3a449cb5d130ea2fec65bb214601826cdeff -- 2.25.4