From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from simark.ca by simark.ca with LMTP id hLLFJSxFxGh/oAEAWB0awg (envelope-from ) for ; Fri, 12 Sep 2025 12:07:08 -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=U5ncypZO; dkim-atps=neutral Received: by simark.ca (Postfix, from userid 112) id 88C7C1E04C; Fri, 12 Sep 2025 12:07:08 -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 8A9771E04C for ; Fri, 12 Sep 2025 12:07:07 -0400 (EDT) Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 12DAC3857B84 for ; Fri, 12 Sep 2025 16:07:07 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 12DAC3857B84 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=U5ncypZO 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 1FA513858D21 for ; Fri, 12 Sep 2025 16:06:30 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 1FA513858D21 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 1FA513858D21 Authentication-Results: server2.sourceware.org; arc=none smtp.remote-ip=170.10.133.124 ARC-Seal: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1757693190; cv=none; b=K8L3oXeOQ/gK45lfoITdiOsRQZiYpBJUxp7f2hYGFZVRDHkrB2FbPMYNNGPOoflVjMb1a+SiFAMxQsdTHHUVApnrJSKkA0Tqp8e2Er4+R0B3oPA+xeqfn3NoC+3p+9sVFKGrOuYDBvSvdr9KX7bp660/Hr/WyUeG4s1O8Kambm8= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1757693190; c=relaxed/simple; bh=Fg1sTsqoV9KNfrGoiJuRvA4qHb0DH6OKPUBgxPNVaVU=; h=DKIM-Signature:From:To:Subject:Date:Message-ID:MIME-Version; b=NOSF4uAkg/VWamp0RumD0GBTOwey1OvWiIMyS0JLRHpvY0pIdfOfc7yiUNeM888Easz4vsG0HJVY5mGqGNJETItZB/pixfS+Fj6N6TlQ1IxbE6NAzripac/wyUtfDlVEF/4m9YK1RBCCn59p2msvfYAoikNgwdePJ4JRdE79C4A= ARC-Authentication-Results: i=1; server2.sourceware.org DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 1FA513858D21 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1757693189; 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=/9NrJCyFFZB2Wb1i7ZZDF/vX7hXDaPV37023POFrF70=; b=U5ncypZOd50fOgCiSkZmwuRTbgLF6ZE3eODx/N0VKX9s+wGc7I5LTtoB5p33h8AvXoHF6h rInwZ0XHsRTI3iDesNPmF7Xk+bgPqHX7D5BGttHgVH1+TA87lCJdrKdvIrDaQWaIDDcptx 88snjT0CpzckUVgcZOYG9QhMmydvsqs= Received: from mail-wr1-f70.google.com (mail-wr1-f70.google.com [209.85.221.70]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-16-c7Zkhn71Np2XkoZUWA0RGw-1; Fri, 12 Sep 2025 12:06:27 -0400 X-MC-Unique: c7Zkhn71Np2XkoZUWA0RGw-1 X-Mimecast-MFC-AGG-ID: c7Zkhn71Np2XkoZUWA0RGw_1757693186 Received: by mail-wr1-f70.google.com with SMTP id ffacd0b85a97d-3e760a261caso1230802f8f.1 for ; Fri, 12 Sep 2025 09:06:27 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1757693186; x=1758297986; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:x-gm-message-state:from:to:cc:subject:date:message-id :reply-to; bh=/9NrJCyFFZB2Wb1i7ZZDF/vX7hXDaPV37023POFrF70=; b=FEmNTHRFzZWq0D5w2AsgGwUCeWA/lwdFOWAvAAje+RlN2Li+PmPsf9VKKn2C4dkjeH y3QSj/IDEAzEXZXnK2vwX3pkWbL4V8CGF0RgHLFjbMVZO+qNo5SaUtZ39PCcOXArvpZM p7Rd8HZfekcLHv1goVMcVqFw1bfz+5Fld+Z+yGiflvA5KvWOExHHDYLoKKD3aWwa3Fge /TCDmWJ7A6hayVr2XjHOg7MUJ+eUtXl6nSXKs2DBVBVHwQjDAOP8gY5DXSmKk97zTdTO YVcb3w2mcjZ/ix6Ba6Jff2ScbBrqpbSaswKmFtejZv/hPXEsZ+SrV+WnDwSlSDvRL8sX yggg== X-Gm-Message-State: AOJu0Yw3k558kUhYzWbji43LtMwraDMYcHqFFg5EZT4HPrYmnaekCMKW 6kgHEj19wJKZdgVxFbll9xkwBalEauhiHyPQgs1Ola5cuHsipPTk5TmuH4qUkO3ApG5UwqtGQa5 PPxIdtimz9KJqSiNVx6ozDO5zIosg+7hNaaTCrm1akzImIabVh/RNxyXrnuPwuJ5D+ORlhW5I6C nhO/DmMNUNPHepH2B97F80LtAQMdnNNVHcsFJ78luDVjnV4Uw= X-Gm-Gg: ASbGncuGp/qaEqvf1OXBWMIqLu+xbOghV6V7WoVubzYuW5j/mcX8IkBlVZQUQHXS05w UHNf1FYOCSUfHFNk4XiBxjl/JCZ7nc9DObmWbzwK0BhX5Wp8H27/ia2E9EUfm43oxkd9m74OAS6 501fWV//49ilk0WUbwDS9SbMFy1V7NBcFsZprllm/GFURaSI8YJ1Iijzx26nPNIYeXVccKsLjVV G0IXe19a+loKdWPg4hI7DRiuPGPWqf5HdB5OwBv4Xt0eht6tcQoIj1PwLecjcH4jPwRJZ2BQO6v TDTnbSC8X48F7gawR7JsCLDW7wj3awDqpUs= X-Received: by 2002:a05:6000:26cc:b0:3e7:458e:f69 with SMTP id ffacd0b85a97d-3e765a08312mr3887503f8f.56.1757693185682; Fri, 12 Sep 2025 09:06:25 -0700 (PDT) X-Google-Smtp-Source: AGHT+IEewPZJwnWUHsmuYE5R5M6lvrSjAWLUybB4VsN7Skib8IULqvTOFqFzxDEHYqtFxwsE76MI9w== X-Received: by 2002:a05:6000:26cc:b0:3e7:458e:f69 with SMTP id ffacd0b85a97d-3e765a08312mr3887451f8f.56.1757693184965; Fri, 12 Sep 2025 09:06:24 -0700 (PDT) Received: from localhost ([31.111.84.207]) by smtp.gmail.com with ESMTPSA id 5b1f17b1804b1-45e03729c76sm67192385e9.6.2025.09.12.09.06.24 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 12 Sep 2025 09:06:24 -0700 (PDT) From: Andrew Burgess To: gdb-patches@sourceware.org Cc: Andrew Burgess , Eli Zaretskii , Guinevere Larsen Subject: [PATCH] gdb: new maintenance command to help debug remote argument issues Date: Fri, 12 Sep 2025 17:06:21 +0100 Message-ID: X-Mailer: git-send-email 2.47.1 MIME-Version: 1.0 X-Mimecast-Spam-Score: 0 X-Mimecast-MFC-PROC-ID: 3W_L82637JigB6e2JkzZuTOrM-_eusFUxzrrsqzcZXQ_1757693186 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 Add a new maintenance command 'maint test-remote-args', this command takes an argument string and splits it using gdb::remote_args::split and then joins the result using gdb::remote_args::join and prints all of the results. This is useful for diagnosing problems with remote argument passing. This new command is identical to what the remote argument self-tests do, but while I was working on improving remote argument passing it was far easier to have a command that I could just throw example strings at, rather than having to add new selftests and recompile GDB. I ended up adding a couple of additional helper functions to the gdb::argv_vec class. Reviewed-By: Eli Zaretskii Tested-By: Guinevere Larsen --- gdb/NEWS | 6 ++ gdb/doc/gdb.texinfo | 20 +++++++ gdb/remote.c | 60 +++++++++++++++++++ .../gdb.base/maint-test-remote-args.exp | 40 +++++++++++++ gdbsupport/gdb_argv_vec.h | 15 +++++ 5 files changed, 141 insertions(+) create mode 100644 gdb/testsuite/gdb.base/maint-test-remote-args.exp diff --git a/gdb/NEWS b/gdb/NEWS index 01bd1524c7a..e8d69aaa0aa 100644 --- a/gdb/NEWS +++ b/gdb/NEWS @@ -18,6 +18,12 @@ GNU/Linux/MicroBlaze (gdbserver) microblazeel-*linux* +* New commands + +maintenance test-remote-args ARGS + Test splitting and joining of inferior arguments ARGS as they would + be split and joined when being passed to a remote target. + * Changed remote packets single-inf-arg in qSupported diff --git a/gdb/doc/gdb.texinfo b/gdb/doc/gdb.texinfo index 676143be416..1a69d186f71 100644 --- a/gdb/doc/gdb.texinfo +++ b/gdb/doc/gdb.texinfo @@ -42831,6 +42831,26 @@ Maintenance Commands @value{GDBN} supports. They are used by the testsuite for exercising the settings infrastructure. +@kindex maint test-remote-args +@item maint test-remote-args @var{args} +For targets that don't support passing inferior arguments as a single +string (@pxref{single-inf-arg}), @value{GDBN} will attempt to split +the inferior arguments before passing them to the remote target, and +the remote target might choose to join the inferior arguments upon +receipt. Historically gdbserver did join inferior arguments, but now +it will request inferior arguments be passed as a single string if +@value{GDBN} supports this feature. + +This maintenance command splits @var{args} as @value{GDBN} would +normally split such an argument string before passing the arguments to +a remote target, the split arguments are then printed. + +The split arguments are then joined together as gdbserver would join +them, and the result is printed. + +This command is intended to help diagnose issues passing inferior +arguments to remote targets. + @kindex maint set backtrace-on-fatal-signal @kindex maint show backtrace-on-fatal-signal @item maint set backtrace-on-fatal-signal [on|off] diff --git a/gdb/remote.c b/gdb/remote.c index 984b7166b7b..e57f7b0ca63 100644 --- a/gdb/remote.c +++ b/gdb/remote.c @@ -81,6 +81,7 @@ #include "gdbsupport/selftest.h" #include "cli/cli-style.h" #include "gdbsupport/remote-args.h" +#include "gdbsupport/gdb_argv_vec.h" /* The remote target. */ @@ -12265,6 +12266,51 @@ cli_packet_command (const char *args, int from_tty) send_remote_packet (view, &cb); } +/* Implement 'maint test-remote-args' command. + + Treat ARGS as an argument string. Split the remote arguments using + gdb::remote_args::split, and then join using gdb::remote_args::join. + The split and joined arguments are printed out. Additionally, the + joined arguments are split and joined a second time, and compared to the + result of the first join, this provides some basic validation that GDB + sess the joined arguments as equivalent to the original argument + string. */ + +static void +test_remote_args_command (const char *args, int from_tty) +{ + std::vector split_args = gdb::remote_args::split (args); + + gdb_printf ("Input (%s)\n", args); + for (const std::string &a : split_args) + gdb_printf (" (%s)\n", a.c_str ()); + + gdb::argv_vec tmp_split_args; + for (const std::string &a : split_args) + tmp_split_args.emplace_back (xstrdup (a.c_str ())); + + std::string joined_args = gdb::remote_args::join (tmp_split_args.get ()); + + gdb_printf ("Output (%s)\n", joined_args.c_str ()); + + std::vector resplit = gdb::remote_args::split (joined_args); + + tmp_split_args.clear (); + for (const std::string &a : resplit) + tmp_split_args.emplace_back (xstrdup (a.c_str ())); + + std::string rejoined = gdb::remote_args::join (tmp_split_args.get ()); + + if (joined_args != rejoined || split_args != resplit) + { + gdb_printf ("FAILURE ON REJOINING\n"); + gdb_printf ("Resplit args:\n"); + for (const auto & a : resplit) + gdb_printf (" (%s)\n", a.c_str ()); + gdb_printf ("Rejoined (%s)\n", rejoined.c_str ()); + } +} + #if 0 /* --------- UNIT_TEST for THREAD oriented PACKETS ------------------- */ @@ -16708,6 +16754,20 @@ from the target."), /* Eventually initialize fileio. See fileio.c */ initialize_remote_fileio (&remote_set_cmdlist, &remote_show_cmdlist); + add_cmd ("test-remote-args", class_maintenance, + test_remote_args_command, _("\ +Test remote argument splitting and joining.\n \ + maintenance test-remote-args ARGS\n\ +For remote targets that don't support passing inferior arguments as a\n\ +single string, GDB needs to split the inferior arguments before passing\n\ +them, and gdbserver needs to join the arguments it receives.\n\ +This command splits ARGS just as GDB would before passing them to a\n\ +remote target, and prints the result. This command then joins the\n\ +arguments just as gdbserver would, and prints the results.\n\ +This command is useful in diagnosing problems when passing arguments\n\ +between GDB and a remote target."), + &maintenancelist); + #if GDB_SELF_TEST selftests::register_test ("remote_memory_tagging", selftests::test_memory_tagging_functions); diff --git a/gdb/testsuite/gdb.base/maint-test-remote-args.exp b/gdb/testsuite/gdb.base/maint-test-remote-args.exp new file mode 100644 index 00000000000..6cd3006f4c8 --- /dev/null +++ b/gdb/testsuite/gdb.base/maint-test-remote-args.exp @@ -0,0 +1,40 @@ +# Copyright 2024-2025 Free Software Foundation, Inc. +# +# This program is free software; you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation; either version 3 of the License, or +# (at your option) any later version. +# +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with this program. If not, see . + +# Test the 'maint test-remote-args' command. +# +# We do minimal testing in here. If you are thinking of adding a new +# test here then you are most likely adding the test in the wrong +# place. Remote argument testing is checked in the following test +# scripts: gdb.base/args.exp, gdb.base/inferior-args.exp, +# gdb.base/startup-with-shell.exp, and gdb.python/py-inferior.exp. +# The test gdb.gdb/unittest.exp also runs 'maint selftest +# remote-args', which are the remote argument self tests. +# +# If you have a new test for an argument that was being passed +# incorrectly, then add the test to one of those scripts. +# +# This file is ONLY for validating that the 'maint test-remote-args' +# command itself is working. + +gdb_start + +gdb_test "maint test-remote-args a b c" \ + [multi_line \ + "Input \\(a b c\\)" \ + " \\(a\\)" \ + " \\(b\\)" \ + " \\(c\\)" \ + "Output \\(a b c\\)"] diff --git a/gdbsupport/gdb_argv_vec.h b/gdbsupport/gdb_argv_vec.h index 1f3b6dbb40e..43571ae173a 100644 --- a/gdbsupport/gdb_argv_vec.h +++ b/gdbsupport/gdb_argv_vec.h @@ -90,6 +90,15 @@ class argv_vec final m_args.push_back (value); } + /* Like calling emplace_back on the underlying vector. This class takes + ownership of the value added to the vector, and will release the value + by calling xfree() on it when this object is destroyed. */ + template + reference emplace_back (Args &&...args) + { + return m_args.emplace_back (std::forward (args)...); + } + /* Non constant iterator to start of m_args. */ iterator begin () { @@ -133,6 +142,12 @@ class argv_vec final { return m_args.empty (); } + + /* Clear the argument vector. */ + void clear () + { + free_vector_argv (m_args); + } }; } /* namespac gdb */ base-commit: 8e28eef6cdcbd86ad61325ce1e6bd563b0fad1e1 -- 2.47.1