From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: 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 EB4393857810 for ; Mon, 4 Nov 2024 14:46:24 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org EB4393857810 Authentication-Results: sourceware.org; dmarc=pass (p=none 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 EB4393857810 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=1730731597; cv=none; b=mzOjMrxYHemb7w3CsW6tLDRN+nYPjv7a7+ennbwxwchb+0oIVDnwtIgGyXUoZkd3La6ymRhEcyanx5il0uQ69NOEhp7graSDDNhKG2UBi00KsG/JJDr9zotp+JhCZL37sm1EDL+gkCNnhHrZfVkaSPj7AgnTmLjajXzw9r8AGXA= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1730731597; c=relaxed/simple; bh=j8cBIp9QKYuCY+JicfuYFees5juGIh50nKEA00tKoJw=; h=DKIM-Signature:From:To:Subject:Date:Message-Id:MIME-Version; b=LKrwBes4x4u6I3NQdeMQOxqvhWLqy1eVjTNPIYKKvwHQs+hv1f78ZmSzQS8Eus7TXaIYAf/n2mXZHNr6V+AV7y810WePfuUx7F2PzlhiPgy7ursUfsE+JYYfYHzzCYmqph/X85HshgK/vKDtAkiuUtdBn478HuWSJhSWPgqpffE= ARC-Authentication-Results: i=1; server2.sourceware.org DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1730731584; 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: in-reply-to:in-reply-to:references:references; bh=FSahq60Dx+UNF7gqM4fNXr5n7OcJmXv8VeeOP31YO/Y=; b=C21u6KIajhKjlN07pCQGmaN+PvHMmv4lMrP76nx28kLTvKKhBVL8g2QJ6M3RK6f7Xs3eA1 PInQo19QE2yJorA5KT3NbR/zcr1uDg+BNcDaauzPNjBVNF3I5TlvLgVC2narFsY4hvq7h5 HLhLhYAnr7cocfclXm6/5CvDS5zHtTs= Received: from mail-wm1-f70.google.com (mail-wm1-f70.google.com [209.85.128.70]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-636-kKTrqjWKOOePtr0YJEY7Uw-1; Mon, 04 Nov 2024 09:46:23 -0500 X-MC-Unique: kKTrqjWKOOePtr0YJEY7Uw-1 Received: by mail-wm1-f70.google.com with SMTP id 5b1f17b1804b1-43151e4ef43so30685305e9.3 for ; Mon, 04 Nov 2024 06:46:23 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1730731582; x=1731336382; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=FSahq60Dx+UNF7gqM4fNXr5n7OcJmXv8VeeOP31YO/Y=; b=j39y2BSQ+G0tf4LhoDmCn3odbGKBW5z3HLSxhlYxKmUdh0sM+7OXKRBs3fviESLsHb /BffV2rbgSH3HsHDyRzQlsJ6NBpk1sW+1jKlhyyLHYgGFaQ/Vwycj7k9koWfEpVcYsPt rMq0rjT1IHTrW/ecoHhF3eSIslJsL4LfDsftDL6uGTsahr7wHBbYbwZwRpTzv7q2VPo1 XcodcsyxadUrcNfqDKBFCh/EoJXneHW+uKV9TKpfZC6LtvJlAFssuAlKtlY1PfGEdXgu NCTDq+NVBXu+kSzV1qSMDcLZG1uEFUmVBRdek+DLS0lwacnNkZ09kIGSuvqWMDRSVCna +hpg== X-Gm-Message-State: AOJu0Yw3w30wl7NchjhGrjXx+bivsJOwM5qP6RNIqqqeQTIw+hQgWKCK 3UfPZ55gj54MMmqDuwSQW5+kKZC+tdDmvDFY2AQrdv0L4KjSa7FjP7J7bCGiVIem4A5iZ3rgaLo kI4oGMnMaKPYakXPP23Ap2mZDu+t8Mr4Tr1Zsj9peEwGbSgjjXVd4wMg9JFFp+OqWyo+ntLEOSP +BnyZ5SCUDXmJDaJ+hIWsmTFm/wHsXGWW6sQmykqctZ5c= X-Received: by 2002:a05:600c:4ecc:b0:431:3c67:fb86 with SMTP id 5b1f17b1804b1-4327b801f83mr135398715e9.33.1730731581566; Mon, 04 Nov 2024 06:46:21 -0800 (PST) X-Google-Smtp-Source: AGHT+IEEyOlgspqzjFCnoOHZwS1abB3ePohAbvt0DaBrWcM6A24vXJ/VL3exDnlfGWzqCE/+mzYpnQ== X-Received: by 2002:a05:600c:4ecc:b0:431:3c67:fb86 with SMTP id 5b1f17b1804b1-4327b801f83mr135398495e9.33.1730731581141; Mon, 04 Nov 2024 06:46:21 -0800 (PST) Received: from localhost (197.209.200.146.dyn.plus.net. [146.200.209.197]) by smtp.gmail.com with ESMTPSA id 5b1f17b1804b1-4327d5c65absm153325205e9.16.2024.11.04.06.46.19 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 04 Nov 2024 06:46:20 -0800 (PST) From: Andrew Burgess To: gdb-patches@sourceware.org Cc: Andrew Burgess , Eli Zaretskii Subject: [PATCHv2 13/14] gdb: new maintenance command to help debug remote argument issues Date: Mon, 4 Nov 2024 14:45:57 +0000 Message-Id: X-Mailer: git-send-email 2.25.4 In-Reply-To: References: MIME-Version: 1.0 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Transfer-Encoding: 8bit Content-Type: text/plain; charset="US-ASCII"; x-default=true X-Spam-Status: No, score=-11.8 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH,DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,GIT_PATCH_0,KAM_SHORT,RCVD_IN_DNSWL_NONE,RCVD_IN_MSPIKE_H3,RCVD_IN_MSPIKE_WL,SPF_HELO_NONE,SPF_NONE,TXREP autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on server2.sourceware.org List-Id: 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, I found it easier to have a maintenance command available for testing rather than having to add a new selftest and recompile GDB. Reviewed-By: Eli Zaretskii --- gdb/NEWS | 4 ++ gdb/doc/gdb.texinfo | 20 +++++++ gdb/remote.c | 59 +++++++++++++++++++ .../gdb.base/maint-test-remote-args.exp | 40 +++++++++++++ 4 files changed, 123 insertions(+) create mode 100644 gdb/testsuite/gdb.base/maint-test-remote-args.exp diff --git a/gdb/NEWS b/gdb/NEWS index 6e829d7dc87..674566351f9 100644 --- a/gdb/NEWS +++ b/gdb/NEWS @@ -95,6 +95,10 @@ maintenance info blocks [ADDRESS] are listed starting at the inner global block out to the most inner block. +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 commands remove-symbol-file diff --git a/gdb/doc/gdb.texinfo b/gdb/doc/gdb.texinfo index a7058e4ee4d..fb31b2ca5b3 100644 --- a/gdb/doc/gdb.texinfo +++ b/gdb/doc/gdb.texinfo @@ -42573,6 +42573,26 @@ @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 8c33ec116bd..9361a10bd5e 100644 --- a/gdb/remote.c +++ b/gdb/remote.c @@ -12179,6 +12179,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 auto & a : split_args) + gdb_printf (" (%s)\n", a.c_str ()); + + std::vector> tmp_split_args; + for (const auto & a : split_args) + tmp_split_args.emplace_back (make_unique_xstrdup (a.c_str ())); + + std::string joined_args = gdb::remote_args::join (tmp_split_args); + + gdb_printf ("Output (%s)\n", joined_args.c_str ()); + + std::vector resplit = gdb::remote_args::split (joined_args); + + tmp_split_args.clear (); + for (const auto & a : resplit) + tmp_split_args.emplace_back (make_unique_xstrdup (a.c_str ())); + + std::string rejoined = gdb::remote_args::join (tmp_split_args); + + 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 ------------------- */ @@ -16614,6 +16659,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..3daf0725932 --- /dev/null +++ b/gdb/testsuite/gdb.base/maint-test-remote-args.exp @@ -0,0 +1,40 @@ +# Copyright 2024 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\\)"] -- 2.25.4