From patchwork Tue Jan 9 14:26:38 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Andrew Burgess X-Patchwork-Id: 83649 Return-Path: X-Original-To: patchwork@sourceware.org Delivered-To: patchwork@sourceware.org Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 525CE3857C70 for ; Tue, 9 Jan 2024 14:31:32 +0000 (GMT) X-Original-To: gdb-patches@sourceware.org Delivered-To: gdb-patches@sourceware.org Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.133.124]) by sourceware.org (Postfix) with ESMTPS id E4CCD3857C5A for ; Tue, 9 Jan 2024 14:27:08 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org E4CCD3857C5A 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 E4CCD3857C5A 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=1704810431; cv=none; b=v+R40z85rBj4TIDBTu4VDmRbfdfefeiaWKgwFFPPWk+b2m3vSu8rieY7ICYkEv90oYWa2rnXo43vg/El1L+vu6N6eg+5+94pKvoNKE0/ipV91ItRPzG1Is1WCbTUDeqD0bM83BWJmFQRWmsMO20iHUGfBJBsV5boVhtl9E3mOxY= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1704810431; c=relaxed/simple; bh=JGn7oOCpRgHExvPgnyrz2JIBlQBNWK10REZxnZCHcfc=; h=DKIM-Signature:From:To:Subject:Date:Message-Id:MIME-Version; b=ngjqqLtyqWCsdTE8v7J7gp5jNUPFB76nXSjvtApIY/zM30B6mkKTWNerINjjIzw+ik/TnOVvSlI45vU3i45LVZuYfRDY/4GqHEDWHz7kfSzOYWhEcKbe+drnz2qSgQUBPQHdqZL65RN0fpINUkxPoPmr0bi73D9rIrnDuQVq3a4= ARC-Authentication-Results: i=1; server2.sourceware.org DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1704810428; 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=yomtnGXzR5y/RK5a0HonjNymvkiDuTb4bB2ViShqU70=; b=XmXPUa5Xc/cCgjvE6XyYLYj9lUG/zhPgN4FGhUgH95OCRf4ObrbyUcNNfzOlaj4MDWyLLj DF0K29/0ENvUt+pw7KYOVKswOWr9IPNLihFY5jhSiZXPnPDA/vuZN/dveS9lDS3T/ocbaj CWP46V7QpNeg7GIT3Q1UX8c8OdSbOys= Received: from mail-wr1-f72.google.com (mail-wr1-f72.google.com [209.85.221.72]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-624-5dsr5v8OPM2RyFYf28A0WQ-1; Tue, 09 Jan 2024 09:27:07 -0500 X-MC-Unique: 5dsr5v8OPM2RyFYf28A0WQ-1 Received: by mail-wr1-f72.google.com with SMTP id ffacd0b85a97d-336937b3cf5so1952346f8f.3 for ; Tue, 09 Jan 2024 06:27:07 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1704810426; x=1705415226; 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=yomtnGXzR5y/RK5a0HonjNymvkiDuTb4bB2ViShqU70=; b=KWktTgP1TL+xjvaIplND85mRHIf+gSa98EXXTo8NQy/QfVmHmp7RG4tveGbnjiNWvS 3uLAgXxw6EquPr0PXteC5ERIscSfW9QckjdqY3mVNOQ8+Kb2kyKi+fYt0Xcg12TJa0e7 hIg7yBFuQHBcWVPyYbAUVc/PeE6T1RvDWzAFVD1wFYn3IB4btgnqe36JqEI7uqQv0s2A GzCKyGkF1jTuFYg1/Lose2M3GRQt0XgH5DbYTvaX5HbL+c2nc+nmth82uf4uA3incufO McGZVEtsUMxCSMHCclvFbobRzqmL+q6hKnJEkHeGhm47JaTPr9U6raizZBgqAVaqK10W OL5A== X-Gm-Message-State: AOJu0YyvR/Fgdj917KHwY5v8Y7q/2K/9QqkuD+sNf2WbPvHVsFR2gBDV YCd7xYGbir/4f7bjw7KlXYWC5oWhsBdKme45dlRACbaKcFdBdq/p7wfWvclcw/i3XpebS+3Qe9i 5apipX0WHnRrEZc1NDDVZw+6luCF3dNO9y4K4xRrmS7v3NepL/zyHTozL/G7Y2lIvL0ua9vEgs5 S50GFUFRRGWfa9uA== X-Received: by 2002:a5d:6448:0:b0:336:6422:708d with SMTP id d8-20020a5d6448000000b003366422708dmr401988wrw.116.1704810425808; Tue, 09 Jan 2024 06:27:05 -0800 (PST) X-Google-Smtp-Source: AGHT+IG3I9wWgf0pOpfzjifFmxKmoXWcfync/SEqOkTux6eFxfpqt4mqXbeM0mGZhxA8tqzo0pcdCQ== X-Received: by 2002:a5d:6448:0:b0:336:6422:708d with SMTP id d8-20020a5d6448000000b003366422708dmr401982wrw.116.1704810425452; Tue, 09 Jan 2024 06:27:05 -0800 (PST) Received: from localhost (185.223.159.143.dyn.plus.net. [143.159.223.185]) by smtp.gmail.com with ESMTPSA id e30-20020adfa45e000000b003373ece28efsm2582389wra.29.2024.01.09.06.27.04 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 09 Jan 2024 06:27:04 -0800 (PST) From: Andrew Burgess To: gdb-patches@sourceware.org Cc: Andrew Burgess , Michael Weghorn Subject: [PATCH 15/16] gdb: new maintenance command to help debug remote argument issues Date: Tue, 9 Jan 2024 14:26:38 +0000 Message-Id: <4d76e490c2285dd7858b853f03465a1d798d6240.1704809585.git.aburgess@redhat.com> 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 X-Spam-Status: No, score=-13.4 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, T_SCC_BODY_TEXT_LINE autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on server2.sourceware.org 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+patchwork=sourceware.org@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, 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 | 21 +++++++ gdb/remote.c | 59 +++++++++++++++++++ .../gdb.base/maint-test-remote-args.exp | 40 +++++++++++++ 4 files changed, 124 insertions(+) create mode 100644 gdb/testsuite/gdb.base/maint-test-remote-args.exp diff --git a/gdb/NEWS b/gdb/NEWS index 2ba1899f78c..8f0bf34fccc 100644 --- a/gdb/NEWS +++ b/gdb/NEWS @@ -51,6 +51,10 @@ set remote thread-options-packet show remote thread-options-packet Set/show the use of the thread options packet. +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 set args diff --git a/gdb/doc/gdb.texinfo b/gdb/doc/gdb.texinfo index 2015293ee0d..6ff059d14ed 100644 --- a/gdb/doc/gdb.texinfo +++ b/gdb/doc/gdb.texinfo @@ -42204,6 +42204,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] @@ -44548,6 +44568,7 @@ This feature indicates whether @value{GDBN} wants to know the supported actions in the reply to @samp{vCont?} packet. +@anchor{single-inf-arg} @item single-inf-arg This feature indicates that @value{GDBN} would like to send the inferior arguments as a single string within the @samp{vRun} packet. diff --git a/gdb/remote.c b/gdb/remote.c index 75d275d38df..9b4d31dc633 100644 --- a/gdb/remote.c +++ b/gdb/remote.c @@ -12029,6 +12029,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 (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 (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 ------------------- */ @@ -16145,6 +16190,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\\)"]