From patchwork Wed Sep 27 17:27:54 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Andrew Burgess X-Patchwork-Id: 76789 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 7CEB73847EC7 for ; Wed, 27 Sep 2023 17:28:35 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 7CEB73847EC7 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=sourceware.org; s=default; t=1695835715; bh=6ys2jqDVHK252FxUKhSYTuCTn2TuacqxhtjlU3Uz6vg=; h=To:Cc:Subject:Date:In-Reply-To:References:List-Id: List-Unsubscribe:List-Archive:List-Post:List-Help:List-Subscribe: From:Reply-To:From; b=IyAZRbcdlBqOzP3xWeQbIX2v6jgILLj0vakd3ltQBwQWENovKNf+ZVnlPkoEMPbf9 N2IgZ0jXPbK5BTD3zqBxLxsltzloiYGFL2mKE5GSx1IwfInIIrXWLetRLpdnmXaIHm DGQkYTsZBriLLwjCTI4sYWQUoGOxZMt4eh++SE0Q= 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.129.124]) by sourceware.org (Postfix) with ESMTPS id BA0EF3857726 for ; Wed, 27 Sep 2023 17:28:05 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org BA0EF3857726 Received: from mail-qk1-f200.google.com (mail-qk1-f200.google.com [209.85.222.200]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-657-EDGcUz45P8C8MCDfLReu3w-1; Wed, 27 Sep 2023 13:28:04 -0400 X-MC-Unique: EDGcUz45P8C8MCDfLReu3w-1 Received: by mail-qk1-f200.google.com with SMTP id af79cd13be357-774105f6fb1so1966402785a.3 for ; Wed, 27 Sep 2023 10:28:04 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1695835683; x=1696440483; 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=6ys2jqDVHK252FxUKhSYTuCTn2TuacqxhtjlU3Uz6vg=; b=L2DZciRrAOEgJaBOpmqmNqDbQPHamgTd4wbj11yzxEpAnw9Dx27UfNAr/ni+AfHJE/ Tmje+ssaubB5BShL0UL/LlGcdcVEyhaDOwZXgfdgnCDpkI9PTZXq0NXsJUPH00Msxr83 2Yxc0QTXjSD7IMlclJyr5ARKQ3lB7hCt8nXuEeJWEcOZmTUSyaqBCnjLUjEHti/RfyiZ dj2rDwz4frsQkWQwSnhAM2ORTWGgP3mGANPtO15j1MHAyPO85JoPwOQ4Ps6FIz1mfJ/b 5xyguHCF21v/NWwGtcfCc1hhhvU02ocKYCWI9YX/QUaXKUf9J7lhPQQNB/5XPxoqWhH5 tP1Q== X-Gm-Message-State: AOJu0YyNFE7ZFjCWq3XlnH1W3CasIAsMKvhbY0qOCDWDkzJK6xVwiBYU 9S9JJzSZWj0tLR4Ue75inlORp+qJXnW3y66OaZ8hIzBvNGiJfLPPTbapfuZbOjMj90f+k2SKLtb 54wfqqVFzYX4HZZCSSKX2BeC+fHxTMs7cZmKR+Lmi3+NEoCBvtHJibEnVin47Y6hndqDdP1Lgon XPWZ4VXA== X-Received: by 2002:a05:620a:b5a:b0:770:9bd2:b3be with SMTP id x26-20020a05620a0b5a00b007709bd2b3bemr2544782qkg.5.1695835683469; Wed, 27 Sep 2023 10:28:03 -0700 (PDT) X-Google-Smtp-Source: AGHT+IF6npL/DhdXBmWDEgjfOTGtnGpnSaxwooJYEBSC4tkYTd/E1gZgj7vaAnlaP/m/0fo+vAFriw== X-Received: by 2002:a05:620a:b5a:b0:770:9bd2:b3be with SMTP id x26-20020a05620a0b5a00b007709bd2b3bemr2544764qkg.5.1695835683109; Wed, 27 Sep 2023 10:28:03 -0700 (PDT) Received: from localhost ([31.111.84.209]) by smtp.gmail.com with ESMTPSA id e15-20020a05620a12cf00b007756d233fbdsm1078368qkl.37.2023.09.27.10.28.02 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 27 Sep 2023 10:28:02 -0700 (PDT) To: gdb-patches@sourceware.org Cc: Andrew Burgess , Andreas Schwab Subject: [PATCHv2 1/5] gdbserver: fix handling of single quote arguments Date: Wed, 27 Sep 2023 18:27:54 +0100 Message-Id: <3769240b9f09529cb43eb4b6fe7d502db4c5c738.1695835626.git.aburgess@redhat.com> X-Mailer: git-send-email 2.25.4 In-Reply-To: References: <2b98ca58e47638b4760d86bd6e1fa9a9a79fa2ad.1695817255.git.aburgess@redhat.com> MIME-Version: 1.0 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com X-Spam-Status: No, score=-11.6 required=5.0 tests=BAYES_00, DKIMWL_WL_HIGH, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, GIT_PATCH_0, RCVD_IN_DNSWL_NONE, RCVD_IN_MSPIKE_H4, 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 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: , X-Patchwork-Original-From: Andrew Burgess via Gdb-patches From: Andrew Burgess Reply-To: Andrew Burgess Errors-To: gdb-patches-bounces+patchwork=sourceware.org@sourceware.org Sender: "Gdb-patches" I noticed that passing arguments containing single quotes to gdbserver didn't work correctly: gdb -ex 'set sysroot' --args /tmp/show-args Reading symbols from /tmp/show-args... (gdb) target extended-remote | gdbserver --once --multi - /tmp/show-args Remote debugging using | gdbserver --once --multi - /tmp/show-args stdin/stdout redirected Process /tmp/show-args created; pid = 176054 Remote debugging using stdio Reading symbols from /lib64/ld-linux-x86-64.so.2... (No debugging symbols found in /lib64/ld-linux-x86-64.so.2) 0x00007ffff7fd3110 in _start () from /lib64/ld-linux-x86-64.so.2 (gdb) set args \' (gdb) r The program being debugged has been started already. Start it from the beginning? (y or n) y Starting program: /tmp/show-args \' stdin/stdout redirected Process /tmp/show-args created; pid = 176088 2 args are: /tmp/show-args \' Done. [Inferior 1 (process 176088) exited normally] (gdb) target native Done. Use the "run" command to start a process. (gdb) run Starting program: /tmp/show-args \' 2 args are: /tmp/show-args ' Done. [Inferior 1 (process 176095) exited normally] (gdb) q The 'shows-args' program used here just prints the arguments passed to the inferior. Notice that when starting the inferior using the extended-remote target the second argument is "\'", while when running using native target the argument is "'". The second of these is correct, the \' used with the "set args" command is just to show GDB that the single quote is not opening an argument string. It turns out that the extra backslash is injected on the gdbserver side when gdbserver processes the arguments that GDB passes it, the code that does this was added as part of this much larger commit: commit 2090129c36c7e582943b7d300968d19b46160d84 Date: Thu Dec 22 21:11:11 2016 -0500 Share fork_inferior et al with gdbserver In this commit I propose removing the specific code that adds what I believe is a stray backslash. I've extended an existing test to cover this case, and I now see identical behaviour when using an extended-remote target as with the native target. This partially fixes PR gdb/27989, though there are still some issues with newline handling which I'll address in a later commit. Bug: https://sourceware.org/bugzilla/show_bug.cgi?id=27989 --- gdb/testsuite/gdb.base/args.exp | 4 ++-- gdb/testsuite/gdb.base/inferior-args.exp | 7 +++++-- gdbserver/server.cc | 6 ------ 3 files changed, 7 insertions(+), 10 deletions(-) diff --git a/gdb/testsuite/gdb.base/args.exp b/gdb/testsuite/gdb.base/args.exp index 0b55c4444aa..092b44bd61d 100644 --- a/gdb/testsuite/gdb.base/args.exp +++ b/gdb/testsuite/gdb.base/args.exp @@ -94,10 +94,10 @@ save_vars { GDBFLAGS } { # Try with arguments containing literal single quotes. set GDBFLAGS "$old_gdbflags --args $binfile 1 '' 3" - args_test "one empty with single quotes" {{1} {''} {3}} $single_quotes_newline_kfail + args_test "one empty with single quotes" {{1} {''} {3}} set GDBFLAGS "$old_gdbflags --args $binfile 1 '' '' 3" - args_test "two empty with single quotes" {{1} {''} {''} {3}} $single_quotes_newline_kfail + args_test "two empty with single quotes" {{1} {''} {''} {3}} # try with arguments containing literal newlines. diff --git a/gdb/testsuite/gdb.base/inferior-args.exp b/gdb/testsuite/gdb.base/inferior-args.exp index 19bada6d2c7..3d3cd39a706 100644 --- a/gdb/testsuite/gdb.base/inferior-args.exp +++ b/gdb/testsuite/gdb.base/inferior-args.exp @@ -29,7 +29,7 @@ proc do_test { method } { global binfile hex # The second arg is an empty string on purpose. - set inferior_args { "first arg" "" "third-arg" } + set inferior_args { "first arg" "" "third-arg" "'" "\"" " " } clean_restart $binfile @@ -109,11 +109,14 @@ proc do_test { method } { } # Now that we are stopped at main, inspect argc/argv. - gdb_test "print argc" " = 4" + gdb_test "print argc" " = 7" gdb_test "print argv\[0\]" " = $hex \".*\"" gdb_test "print argv\[1\]" " = $hex \"first arg\"" gdb_test "print argv\[2\]" " = $hex \"\"" gdb_test "print argv\[3\]" " = $hex \"third-arg\"" + gdb_test "print argv\[4\]" " = $hex \"'\"" + gdb_test "print argv\[5\]" " = $hex \"\\\\\"\"" + gdb_test "print argv\[6\]" " = $hex \" \"" } foreach_with_prefix method { "start" "starti" "run" "set args" } { diff --git a/gdbserver/server.cc b/gdbserver/server.cc index c57270175b4..496b9bebb7d 100644 --- a/gdbserver/server.cc +++ b/gdbserver/server.cc @@ -3011,12 +3011,6 @@ handle_v_run (char *own_buf) need_quote = 1; break; - case '\'': - /* Quote single quote. */ - *tmp_full_arg = '\\'; - ++tmp_full_arg; - break; - default: break; } From patchwork Wed Sep 27 17:27:55 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Andrew Burgess X-Patchwork-Id: 76790 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 B6A3F387541E for ; Wed, 27 Sep 2023 17:28:38 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org B6A3F387541E DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=sourceware.org; s=default; t=1695835718; bh=DpUvlrQbepz882xS6zMkjNs73A0ENg9b34IBsupWyyc=; h=To:Cc:Subject:Date:In-Reply-To:References:List-Id: List-Unsubscribe:List-Archive:List-Post:List-Help:List-Subscribe: From:Reply-To:From; b=dLoHyel88o5pxLLBjJ/cr1jLrIiv5w/qlWSXsVGZa2aw4E9UEaqS1vQJSmlridTb2 jQy0hJEG6PQW/2xSg4kZkTpBicnaGR8DyibocTH5eWwN6Ua+UQDQd8uNqNe5xnNmRh KNtaYA8rGesJQig3TMIDg17kvJpj1uip18sPBXDU= 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 C8AD7385E03D for ; Wed, 27 Sep 2023 17:28:07 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org C8AD7385E03D Received: from mail-qk1-f199.google.com (mail-qk1-f199.google.com [209.85.222.199]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-176-l7yLvrxwMUKW7GxXkHIOQA-1; Wed, 27 Sep 2023 13:28:06 -0400 X-MC-Unique: l7yLvrxwMUKW7GxXkHIOQA-1 Received: by mail-qk1-f199.google.com with SMTP id af79cd13be357-7740c35073bso2324634685a.3 for ; Wed, 27 Sep 2023 10:28:06 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1695835685; x=1696440485; 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=DpUvlrQbepz882xS6zMkjNs73A0ENg9b34IBsupWyyc=; b=k5CzuKjgnARhAbjlMw9GDWYUuRqlltRb5xFXhT6Btl1Wi1KaM197RTLokDOdd+m9ht kN4Nya/HEHseaE0M7Md4iH1o24gZkWIz3nN3iTAemCd65Z0oHHYFJOgU7eVYhkBw8Ao5 AQkhHDUtzTGKyGFq2WuTjXQy/9gOKB5tW90ru5Q7wQEGlRUDKevpWdsc4zvNRg/qZFpj kNDqppKhXIl7Yl/dLpEFCJkzlmgYRQMaF/z6fo04qnCOXV7I/vYFzPbyzmUdqZ0hF40l NztyauvISelqq1m5Tjs8lc+/KYyw2ldN5UY0y2e7YThRzInil239ASDUUcO29NFgdR1B kllg== X-Gm-Message-State: AOJu0YyijtdUuDgSI3ZsOeBjSLgRlSzafNsrxRWCa2o2GKFdw3q8jRty bFwicst5NdRrbhstjBf37vxTl25fqxmk6cPLSzGq3TdirRIbgXbeyorgQDwlm2imOAwg/yC5+zi 0DeH9Fk8djbrSyGSUGSkab7d332azR0uQrOonwdzrrP0u1w5gIcTB7TRp6VJpd6jeY+p7LdVbdc A5V0O7Yw== X-Received: by 2002:a05:620a:254b:b0:76f:135d:ce08 with SMTP id s11-20020a05620a254b00b0076f135dce08mr2954064qko.57.1695835685470; Wed, 27 Sep 2023 10:28:05 -0700 (PDT) X-Google-Smtp-Source: AGHT+IGIxGFywhkj2DTQYN7h7FvZy0WrXtRBPgSogiOr7LkA5EB0J7Qm8p3WDDRQkA4OMibPuffdLw== X-Received: by 2002:a05:620a:254b:b0:76f:135d:ce08 with SMTP id s11-20020a05620a254b00b0076f135dce08mr2954043qko.57.1695835685080; Wed, 27 Sep 2023 10:28:05 -0700 (PDT) Received: from localhost ([31.111.84.209]) by smtp.gmail.com with ESMTPSA id 17-20020a05620a06d100b00767d2870e39sm3589098qky.41.2023.09.27.10.28.04 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 27 Sep 2023 10:28:04 -0700 (PDT) To: gdb-patches@sourceware.org Cc: Andrew Burgess , Andreas Schwab Subject: [PATCHv2 2/5] gdbserver: fix handling of trailing empty argument Date: Wed, 27 Sep 2023 18:27:55 +0100 Message-Id: <3485c21f838f6df48b865663aa637d21d6656661.1695835626.git.aburgess@redhat.com> X-Mailer: git-send-email 2.25.4 In-Reply-To: References: <2b98ca58e47638b4760d86bd6e1fa9a9a79fa2ad.1695817255.git.aburgess@redhat.com> MIME-Version: 1.0 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com X-Spam-Status: No, score=-10.9 required=5.0 tests=BAYES_00, DKIMWL_WL_HIGH, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, GIT_PATCH_0, RCVD_IN_DNSWL_NONE, RCVD_IN_MSPIKE_H3, RCVD_IN_MSPIKE_WL, RCVD_IN_SORBS_WEB, 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 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: , X-Patchwork-Original-From: Andrew Burgess via Gdb-patches From: Andrew Burgess Reply-To: Andrew Burgess Errors-To: gdb-patches-bounces+patchwork=sourceware.org@sourceware.org Sender: "Gdb-patches" When I posted the previous patch for review Andreas Schwab pointed out that passing a trailing empty argument also doesn't work. The fix for this is in the same area of code as the previous patch, but is sufficiently different that I felt it deserved a patch of its own. I noticed that passing arguments containing single quotes to gdbserver didn't work correctly: gdb -ex 'set sysroot' --args /tmp/show-args Reading symbols from /tmp/show-args... (gdb) target extended-remote | gdbserver --once --multi - /tmp/show-args Remote debugging using | gdbserver --once --multi - /tmp/show-args stdin/stdout redirected Process /tmp/show-args created; pid = 176054 Remote debugging using stdio Reading symbols from /lib64/ld-linux-x86-64.so.2... (No debugging symbols found in /lib64/ld-linux-x86-64.so.2) 0x00007ffff7fd3110 in _start () from /lib64/ld-linux-x86-64.so.2 (gdb) set args abc "" (gdb) run The program being debugged has been started already. Start it from the beginning? (y or n) y Starting program: /tmp/show-args \' stdin/stdout redirected Process /tmp/show-args created; pid = 176088 2 args are: /tmp/show-args abc Done. [Inferior 1 (process 176088) exited normally] (gdb) target native Done. Use the "run" command to start a process. (gdb) run Starting program: /tmp/show-args \' 2 args are: /tmp/show-args abc Done. [Inferior 1 (process 176095) exited normally] (gdb) q The 'shows-args' program used here just prints the arguments passed to the inferior. Notice that when starting the inferior using the extended-remote target there is only a single argument 'abc', while when using the native target there is a second argument, the blank line, representing the empty argument. The problem here is that the vRun packet coming from GDB looks like this (I've removing the trailing checksum): $vRun;PROGRAM_NAME;616263; If we compare this to a packet with only a single argument and no trailing empty argument: $vRun;PROGRAM_NAME;616263 Notice the lack of the trailing ';' character here. The problem is that gdbserver processes this string in a loop. At each point we maintain a pointer to the character just after a ';', and then we process everything up to either the next ';' character, or to the end of the string. We break out of this loop when the character we start with (in that loop iteration) is the null-character. This means in the trailing empty argument case, we abort the loop before doing anything with the empty argument. In this commit I've updated the loop, we now break out using a 'break' statement at the end of the loop if the (sub-)string we just processed was empty, with this change we now notice the trailing empty argument. I've updated the test case to cover this issue. --- gdb/testsuite/gdb.base/inferior-args.exp | 9 ++++++--- gdbserver/server.cc | 8 +++++--- 2 files changed, 11 insertions(+), 6 deletions(-) diff --git a/gdb/testsuite/gdb.base/inferior-args.exp b/gdb/testsuite/gdb.base/inferior-args.exp index 3d3cd39a706..2c920ab14ec 100644 --- a/gdb/testsuite/gdb.base/inferior-args.exp +++ b/gdb/testsuite/gdb.base/inferior-args.exp @@ -28,8 +28,10 @@ if {[build_executable "failed to prepare" $testfile $srcfile \ proc do_test { method } { global binfile hex - # The second arg is an empty string on purpose. - set inferior_args { "first arg" "" "third-arg" "'" "\"" " " } + # The second arg is an empty string on purpose. The last argument + # must be the empty argument -- we once had a bug where that + # wouldn't work! + set inferior_args { "first arg" "" "third-arg" "'" "\"" " " "" } clean_restart $binfile @@ -109,7 +111,7 @@ proc do_test { method } { } # Now that we are stopped at main, inspect argc/argv. - gdb_test "print argc" " = 7" + gdb_test "print argc" " = 8" gdb_test "print argv\[0\]" " = $hex \".*\"" gdb_test "print argv\[1\]" " = $hex \"first arg\"" gdb_test "print argv\[2\]" " = $hex \"\"" @@ -117,6 +119,7 @@ proc do_test { method } { gdb_test "print argv\[4\]" " = $hex \"'\"" gdb_test "print argv\[5\]" " = $hex \"\\\\\"\"" gdb_test "print argv\[6\]" " = $hex \" \"" + gdb_test "print argv\[7\]" " = $hex \"\"" } foreach_with_prefix method { "start" "starti" "run" "set args" } { diff --git a/gdbserver/server.cc b/gdbserver/server.cc index 496b9bebb7d..d78eb5a7d94 100644 --- a/gdbserver/server.cc +++ b/gdbserver/server.cc @@ -2969,7 +2969,9 @@ handle_v_run (char *own_buf) char *new_program_name = NULL; int i; - for (i = 0, p = own_buf + strlen ("vRun;"); *p; p = next_p, ++i) + for (i = 0, p = own_buf + strlen ("vRun;"); + /* Exit condition is at the end of the loop. */; + p = next_p + 1, ++i) { next_p = strchr (p, ';'); if (next_p == NULL) @@ -3032,8 +3034,8 @@ handle_v_run (char *own_buf) new_argv.push_back (full_arg); xfree (arg); } - if (*next_p) - next_p++; + if (*next_p == '\0') + break; } if (new_program_name == NULL) From patchwork Wed Sep 27 17:27:56 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Andrew Burgess X-Patchwork-Id: 76791 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 A5D6F3875DC1 for ; Wed, 27 Sep 2023 17:28:46 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org A5D6F3875DC1 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=sourceware.org; s=default; t=1695835726; bh=AaXZ+b3cduJkMqgiNW10cM0ptL+sPguiXDpUat2PXGs=; h=To:Cc:Subject:Date:In-Reply-To:References:List-Id: List-Unsubscribe:List-Archive:List-Post:List-Help:List-Subscribe: From:Reply-To:From; b=k3cdsau6SAhOdcRnP3q0VH/kiaR1nA1iSDMlgrhJEfw8jEuH5tWN6UZJidu394tKu 9WvNg//1IhD120DjZNQVSqknhgtALvyoxcTDvjD1zeGBUa7/GC+bt3q7slguf4+PBM 24TTDkYvPnDx9Sksp8Jg0tdkMvOVCN5k/rxEaBNA= 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 A77A738618A0 for ; Wed, 27 Sep 2023 17:28:10 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org A77A738618A0 Received: from mail-qv1-f72.google.com (mail-qv1-f72.google.com [209.85.219.72]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-358-DAJsW_BFMT2J4zmwBvHX3g-1; Wed, 27 Sep 2023 13:28:08 -0400 X-MC-Unique: DAJsW_BFMT2J4zmwBvHX3g-1 Received: by mail-qv1-f72.google.com with SMTP id 6a1803df08f44-65b107812f0so116057416d6.1 for ; Wed, 27 Sep 2023 10:28:08 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1695835687; x=1696440487; 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=AaXZ+b3cduJkMqgiNW10cM0ptL+sPguiXDpUat2PXGs=; b=ZkXSvhDrD0D1zfbMUmL90OXAruYBY3I3qki1l9EvF2Zwcu02ZyTCkshrMF+/TD0DZ5 sj6lQUtYUFJzDdkTwldlprfrt/B0gnW3q4jpJkwnUnUNyo1xWPAnm+NJK47+UlDxk54a u5pPQROPhrCBOrQ4isKOYORblu1JeuOnc5VdyfQF+H8jBpzgN5+KPz54K6VEydMg24Eq 2cmH90/4f88CEunfB0vkOOweByZU6Jwlna1SmVAVltSBvhMMUcDs0MU4gkFJU22fG99G lL7osO56bLO40weoaNLXbT7L5lctVw9xQlnraepudmxVvKy3aNKx8Oj1pEsxjI+R38a2 WqpA== X-Gm-Message-State: AOJu0YxtDkVLFW3tHuGSrPg0UDMr8hvCReMfOeKTz8hwc0Kt0r3uu9Ue TL6smXhgeo/V4pWnFntl/cm2Bh2HH12bxGib49BFBKWNXwpS2wRMHL4NaA/iGpTRMit5S8RGemb JNEmpASP+jHfOvOwW/UqxTKu8b8UcH3+2Z+jzFb+Sr2RMD9mradYKSNaVp00tESqB6iKsYuaBFF NvmFQDTw== X-Received: by 2002:a0c:a602:0:b0:658:95a9:ac21 with SMTP id s2-20020a0ca602000000b0065895a9ac21mr2365558qva.55.1695835687550; Wed, 27 Sep 2023 10:28:07 -0700 (PDT) X-Google-Smtp-Source: AGHT+IESfz3epJ2xpZ5yNUSZXX84RRHFQknWID0hHVC0Ul/tBPCQ+4EO8BKrxBjo6w3rpYsoqssN6g== X-Received: by 2002:a0c:a602:0:b0:658:95a9:ac21 with SMTP id s2-20020a0ca602000000b0065895a9ac21mr2365542qva.55.1695835687192; Wed, 27 Sep 2023 10:28:07 -0700 (PDT) Received: from localhost ([31.111.84.209]) by smtp.gmail.com with ESMTPSA id j7-20020a0ce007000000b0063d252a141dsm5934400qvk.116.2023.09.27.10.28.06 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 27 Sep 2023 10:28:07 -0700 (PDT) To: gdb-patches@sourceware.org Cc: Andrew Burgess , Andreas Schwab Subject: [PATCHv2 3/5] gdbserver: handle newlines in inferior arguments Date: Wed, 27 Sep 2023 18:27:56 +0100 Message-Id: <8c64b64c6ff1e2567d25ffcc39217a61e856e873.1695835626.git.aburgess@redhat.com> X-Mailer: git-send-email 2.25.4 In-Reply-To: References: <2b98ca58e47638b4760d86bd6e1fa9a9a79fa2ad.1695817255.git.aburgess@redhat.com> MIME-Version: 1.0 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com X-Spam-Status: No, score=-11.6 required=5.0 tests=BAYES_00, DKIMWL_WL_HIGH, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, GIT_PATCH_0, 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 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: , X-Patchwork-Original-From: Andrew Burgess via Gdb-patches From: Andrew Burgess Reply-To: Andrew Burgess Errors-To: gdb-patches-bounces+patchwork=sourceware.org@sourceware.org Sender: "Gdb-patches" Similarly to how single quotes were mishandled, which was fixed two commits ago, this commit fixes handling of newlines in arguments passed to gdbserver. We already had a test that covered this, gdb.base/args.exp, which, when run with the native-extended-gdbserver board contained several KFAIL covering this situation. In this commit I remove the unnecessary, attempt to quote incoming newlines within arguments, and do some minimal cleanup of the related code. There is additional cleanup that can be done, but I'm leaving that for the next commit. Then I've removed the KFAIL from the test case, and performed some minimal cleanup there too. After this commit the gdb.base/args.exp is 100% passing with the native-extended-gdbserver board file. Bug: https://sourceware.org/bugzilla/show_bug.cgi?id=27989 --- gdb/testsuite/gdb.base/args.exp | 20 +++++--------------- gdbserver/server.cc | 17 ----------------- 2 files changed, 5 insertions(+), 32 deletions(-) diff --git a/gdb/testsuite/gdb.base/args.exp b/gdb/testsuite/gdb.base/args.exp index 092b44bd61d..0e2dc8b1399 100644 --- a/gdb/testsuite/gdb.base/args.exp +++ b/gdb/testsuite/gdb.base/args.exp @@ -30,10 +30,10 @@ if {[build_executable $testfile.exp $testfile \ return -1 } -# If SINGLE_QUOTES_NEWLINE_KFAIL true, arguments made of exactly '' or a -# newline character will fail, so kfail those tests. +# NAME is the name to use for the tests and ARGLIST is the list of +# expected arguments. -proc args_test { name arglist {single_quotes_newline_kfail false}} { +proc args_test { name arglist } { global srcdir global subdir global testfile @@ -51,10 +51,6 @@ proc args_test { name arglist {single_quotes_newline_kfail false}} { set i 1 foreach arg $arglist { - if { $single_quotes_newline_kfail - && ($arg == {''} || $arg == {\\n}) } { - setup_kfail "gdb/27989" "*-*-*" - } gdb_test "print argv\[$i\]" "\\\$$decimal = $hex \"$arg\"" \ "argv\[$i\] for $name" set i [expr $i + 1] @@ -68,12 +64,6 @@ proc args_test { name arglist {single_quotes_newline_kfail false}} { save_vars { GDBFLAGS } { set old_gdbflags $GDBFLAGS - # Single quotes and newlines are not well handled by the extended-remote - # target: https://sourceware.org/bugzilla/show_bug.cgi?id=27989 - set single_quotes_newline_kfail \ - [expr { [target_info exists gdb_protocol] \ - && [target_info gdb_protocol] == "extended-remote" }] - set GDBFLAGS "$old_gdbflags --args $binfile 1 3" args_test basic {{1} {3}} @@ -102,8 +92,8 @@ save_vars { GDBFLAGS } { # try with arguments containing literal newlines. set GDBFLAGS "$old_gdbflags --args $binfile 1 {\n} 3" - args_test "one newline" {{1} {\\n} {3}} $single_quotes_newline_kfail + args_test "one newline" {{1} {\\n} {3}} set GDBFLAGS "$old_gdbflags --args $binfile 1 {\n} {\n} 3" - args_test "two newlines" {{1} {\\n} {\\n} {3}} $single_quotes_newline_kfail + args_test "two newlines" {{1} {\\n} {\\n} {3}} } diff --git a/gdbserver/server.cc b/gdbserver/server.cc index d78eb5a7d94..84b8712e668 100644 --- a/gdbserver/server.cc +++ b/gdbserver/server.cc @@ -2997,34 +2997,17 @@ handle_v_run (char *own_buf) /* These are pointers used to navigate the strings above. */ char *tmp_arg = arg; char *tmp_full_arg = full_arg; - int need_quote = 0; hex2bin (p, (gdb_byte *) arg, len); arg[len] = '\0'; while (*tmp_arg != '\0') { - switch (*tmp_arg) - { - case '\n': - /* Quote \n. */ - *tmp_full_arg = '\''; - ++tmp_full_arg; - need_quote = 1; - break; - - default: - break; - } - *tmp_full_arg = *tmp_arg; ++tmp_full_arg; ++tmp_arg; } - if (need_quote) - *tmp_full_arg++ = '\''; - /* Finish FULL_ARG and push it into the vector containing the argv. */ *tmp_full_arg = '\0'; From patchwork Wed Sep 27 17:27:57 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Andrew Burgess X-Patchwork-Id: 76793 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 5FEE23875457 for ; Wed, 27 Sep 2023 17:29:08 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 5FEE23875457 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=sourceware.org; s=default; t=1695835748; bh=cVXJkOhgOE1IPgbkg7YemK/5JU48WvXKHmQxFUAD+Bs=; h=To:Cc:Subject:Date:In-Reply-To:References:List-Id: List-Unsubscribe:List-Archive:List-Post:List-Help:List-Subscribe: From:Reply-To:From; b=YVtgz1eV/FDs84EYg5IXKD6/a/l9QYcEmlDLKpJP+CUFOup2xgRVy6wbD9Vp1477o rV7XUbYHh6gGvXCzX+MkLJefVMjK2APSpTLlf/mQFWVF8WP8nWYDVVZYrPLWa4Gma0 2VDyg0Ykw1yF8y+nnj9mKQGsNfOltKvosfhDu+6U= 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 7A9DC38618FD for ; Wed, 27 Sep 2023 17:28:12 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 7A9DC38618FD Received: from mail-qk1-f198.google.com (mail-qk1-f198.google.com [209.85.222.198]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-404-10hiKaefMZiaYfpUvOh9eQ-1; Wed, 27 Sep 2023 13:28:10 -0400 X-MC-Unique: 10hiKaefMZiaYfpUvOh9eQ-1 Received: by mail-qk1-f198.google.com with SMTP id af79cd13be357-7740cf4136aso2067032185a.2 for ; Wed, 27 Sep 2023 10:28:10 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1695835690; x=1696440490; 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=cVXJkOhgOE1IPgbkg7YemK/5JU48WvXKHmQxFUAD+Bs=; b=p9v0vRUu5a4t7NDR60mqGfLFJA59Tp/6aTL3FYzEZrcn/UviRr5xWujcqLWRap/1ws 6sDbC77yX+YCLOGb2RjMn4qBanXqhxcQ4WfbNVk6z4TENdZoVVyFzFCqjIOn4zKAEt4S ksQHThBDyQxiC8EN8IzCwF9mVg8UjGTC5bA1f5yMpy5ZAL8BPAskH3PFDzfO6QrU299L fUjICHXomcSuO3mA8fuCerNVMlIi2dtrR9aB5FA0ii6uCr2cy/CitsGvxssMRycpz1o8 +BwoQTTAQ4yAG4bokOoZDFGkedsgdmVYjp+Uwn7GKLC/uy1n55wmgv9zrJlSTDnPz93P GorA== X-Gm-Message-State: AOJu0Yypi2zpm6CindVihKssjcjgE6qO+RzwdVF+haJW83YOfLVvMa22 pPIi/vkRhRdDs80uZuGUxcB9b7+UzaJPHb9f8c4QW0pgaEiM+bwNsenTJ7NPSQ0VHr0az6ZJF5I S+t/kOK1pp3j9ndtsmNYG+1yiLOBmnHQvznQ00fyhANbpKkkQjd65305DOSf1nDb1RXBdy6SRqO lOcLxXWA== X-Received: by 2002:a05:620a:2494:b0:773:eb81:d043 with SMTP id i20-20020a05620a249400b00773eb81d043mr2790846qkn.52.1695835689891; Wed, 27 Sep 2023 10:28:09 -0700 (PDT) X-Google-Smtp-Source: AGHT+IH5dkkRoVry4lH6CrVc2HHz85v/zOcKCLiZgEgcWw6Equj8NZG+JECEN+qPKTQhM7tvjlCuRw== X-Received: by 2002:a05:620a:2494:b0:773:eb81:d043 with SMTP id i20-20020a05620a249400b00773eb81d043mr2790831qkn.52.1695835689542; Wed, 27 Sep 2023 10:28:09 -0700 (PDT) Received: from localhost ([31.111.84.209]) by smtp.gmail.com with ESMTPSA id e5-20020a0cb445000000b0063d5d173a51sm3650535qvf.50.2023.09.27.10.28.09 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 27 Sep 2023 10:28:09 -0700 (PDT) To: gdb-patches@sourceware.org Cc: Andrew Burgess , Andreas Schwab Subject: [PATCHv2 4/5] gdbserver: cleanup in handle_v_run Date: Wed, 27 Sep 2023 18:27:57 +0100 Message-Id: <101de2688bc146244f0ae89477cfd4adf3606551.1695835626.git.aburgess@redhat.com> X-Mailer: git-send-email 2.25.4 In-Reply-To: References: <2b98ca58e47638b4760d86bd6e1fa9a9a79fa2ad.1695817255.git.aburgess@redhat.com> MIME-Version: 1.0 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com X-Spam-Status: No, score=-11.6 required=5.0 tests=BAYES_00, DKIMWL_WL_HIGH, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, GIT_PATCH_0, 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 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: , X-Patchwork-Original-From: Andrew Burgess via Gdb-patches From: Andrew Burgess Reply-To: Andrew Burgess Errors-To: gdb-patches-bounces+patchwork=sourceware.org@sourceware.org Sender: "Gdb-patches" After the previous commit there is now a redundant string copy in handle_v_run, this commit cleans that up. There should be no functional change after this commit. --- gdbserver/server.cc | 24 +++++------------------- 1 file changed, 5 insertions(+), 19 deletions(-) diff --git a/gdbserver/server.cc b/gdbserver/server.cc index 84b8712e668..e02cdb83b51 100644 --- a/gdbserver/server.cc +++ b/gdbserver/server.cc @@ -2989,33 +2989,19 @@ handle_v_run (char *own_buf) } else { + /* The length of the decoded argument. */ size_t len = (next_p - p) / 2; - /* ARG is the unquoted argument received via the RSP. */ + + /* Buffer to decode the argument into. */ char *arg = (char *) xmalloc (len + 1); - /* FULL_ARGS will contain the quoted version of ARG. */ - char *full_arg = (char *) xmalloc ((len + 1) * 2); - /* These are pointers used to navigate the strings above. */ - char *tmp_arg = arg; - char *tmp_full_arg = full_arg; hex2bin (p, (gdb_byte *) arg, len); arg[len] = '\0'; - while (*tmp_arg != '\0') - { - *tmp_full_arg = *tmp_arg; - ++tmp_full_arg; - ++tmp_arg; - } - - /* Finish FULL_ARG and push it into the vector containing - the argv. */ - *tmp_full_arg = '\0'; if (i == 0) - new_program_name = full_arg; + new_program_name = arg; else - new_argv.push_back (full_arg); - xfree (arg); + new_argv.push_back (arg); } if (*next_p == '\0') break; From patchwork Wed Sep 27 17:27:58 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Andrew Burgess X-Patchwork-Id: 76792 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 BB0973875463 for ; Wed, 27 Sep 2023 17:29:02 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org BB0973875463 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=sourceware.org; s=default; t=1695835742; bh=dMCnzAUBv4x5wdKLT2L0TstnMWoykZtsQkW7hTpu/Tg=; h=To:Cc:Subject:Date:In-Reply-To:References:List-Id: List-Unsubscribe:List-Archive:List-Post:List-Help:List-Subscribe: From:Reply-To:From; b=Fdz5EkQMlbUVErGih8pnqxVIOYFVFchqFCp7cQQ6UjTAroYqVch/RNeeHXG2nTFQU 0Xxc6zOimbwszO0BymPgXe6GeQaZEhflbK86k03ak8EsPklheVgnEpYIgDBQY95pHe 6QlL6cW8Fu+O4l0CpS/88+zlP8RhoZVCwcoEsVYs= 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.129.124]) by sourceware.org (Postfix) with ESMTPS id 437A73861864 for ; Wed, 27 Sep 2023 17:28:14 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 437A73861864 Received: from mail-qk1-f200.google.com (mail-qk1-f200.google.com [209.85.222.200]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-185-qoQ_mkXYO3qcWj_H2QCOFQ-1; Wed, 27 Sep 2023 13:28:12 -0400 X-MC-Unique: qoQ_mkXYO3qcWj_H2QCOFQ-1 Received: by mail-qk1-f200.google.com with SMTP id af79cd13be357-77574c4394aso312279885a.2 for ; Wed, 27 Sep 2023 10:28:12 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1695835692; x=1696440492; 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=dMCnzAUBv4x5wdKLT2L0TstnMWoykZtsQkW7hTpu/Tg=; b=tNd1Gf1LL4G1NTKW4g3LQT6nVmaGGRXDtLgFIsI+kbQ9FUv2OQGub+v989qNzjeLEY 0XIKzfKcpTwiphLi5Leeb6S6BPAadfxZyPPW/youxFdWCt0/PrJlxKjI0stW1KfRnUR4 iQHW3ZCfJsdi0JQQdhqfb2EFNKxoxkfaChFvfk1dOmqKY22rU6UnjbuiGdCDSLKwiOlb cA+V6tMrANUvNXhI9mVftNf9LQM9cs8Xju+3bvTTbWWK9n8FBLtUi+JR31dYXRU1gK2+ TlHZ9xnjWs8LhMh8TDKiHuMOD8jV2zSEQTZi/uT9KxpuclJ/jX04or8szLQSJVYVkAM3 3eqw== X-Gm-Message-State: AOJu0YxRQv4VPqROCHtAoTMIJWiUuA8r9jTN/sdQdsoyajfzslx7rLCj UiEWnim5NaKrm+Op4m0fR5KLD/6MZtJioMQq7xQeK3AmdtSfqYMDLEpzy2V9/8EFpMUk6DebLMz OO1iDGOcXxaE5AO4SXnZmPLcgmSZJ8hxPYwNjCRUTzgY0Wm+32Z06acBrj5rgT3lkMAAmTwCY9T y5Rt1k7Q== X-Received: by 2002:a05:620a:4415:b0:774:244c:8b21 with SMTP id v21-20020a05620a441500b00774244c8b21mr3764242qkp.15.1695835691784; Wed, 27 Sep 2023 10:28:11 -0700 (PDT) X-Google-Smtp-Source: AGHT+IHhQ1zw98C9C3Ojn4CCSVdrm5ZYWw5pT4kEL7JWgbTt/s9g/aD3SASv7rudJeebyP3ASZ5BPg== X-Received: by 2002:a05:620a:4415:b0:774:244c:8b21 with SMTP id v21-20020a05620a441500b00774244c8b21mr3764217qkp.15.1695835691487; Wed, 27 Sep 2023 10:28:11 -0700 (PDT) Received: from localhost ([31.111.84.209]) by smtp.gmail.com with ESMTPSA id x7-20020ae9f807000000b0076da620166bsm5592020qkh.103.2023.09.27.10.28.10 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 27 Sep 2023 10:28:11 -0700 (PDT) To: gdb-patches@sourceware.org Cc: Andrew Burgess , Andreas Schwab Subject: [PATCHv2 5/5] gdb/testsuite: cleanup in gdb.base/args.exp Date: Wed, 27 Sep 2023 18:27:58 +0100 Message-Id: <34f347e769efca7a502b1466fa0c903c433c1f3a.1695835626.git.aburgess@redhat.com> X-Mailer: git-send-email 2.25.4 In-Reply-To: References: <2b98ca58e47638b4760d86bd6e1fa9a9a79fa2ad.1695817255.git.aburgess@redhat.com> MIME-Version: 1.0 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com X-Spam-Status: No, score=-11.7 required=5.0 tests=BAYES_00, DKIMWL_WL_HIGH, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, GIT_PATCH_0, RCVD_IN_DNSWL_NONE, RCVD_IN_MSPIKE_H4, 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 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: , X-Patchwork-Original-From: Andrew Burgess via Gdb-patches From: Andrew Burgess Reply-To: Andrew Burgess Errors-To: gdb-patches-bounces+patchwork=sourceware.org@sourceware.org Sender: "Gdb-patches" The last few commits resolved the KFAILs in gdb.base/args.exp. With those out of the way we can clean up this test script a little. In this commit I have: - Stopped passing 'nowarnings' flag when building the source file. I see no reason why this source should issue a warning, - Moved setup of GDBFLAGS into args_test proc, callers that passed a newline needed a small tweak, and also the matching code needs updating for newline handling, but I think this is nicer, the argument lists are now given just once, - Updated comment on args_test, - Updated other comments. There should be no change in what is tested after this commit. --- gdb/testsuite/gdb.base/args.exp | 89 ++++++++++++++------------------- 1 file changed, 37 insertions(+), 52 deletions(-) diff --git a/gdb/testsuite/gdb.base/args.exp b/gdb/testsuite/gdb.base/args.exp index 0e2dc8b1399..43ea6e5caa8 100644 --- a/gdb/testsuite/gdb.base/args.exp +++ b/gdb/testsuite/gdb.base/args.exp @@ -24,76 +24,61 @@ require !use_gdb_stub standard_testfile -if {[build_executable $testfile.exp $testfile \ - $srcfile {debug nowarnings}] == -1} { +if {[build_executable $testfile.exp $testfile $srcfile] == -1} { untested "failed to compile" return -1 } # NAME is the name to use for the tests and ARGLIST is the list of -# expected arguments. +# arguments that are passed to GDB when it is started. proc args_test { name arglist } { - global srcdir - global subdir - global testfile - global hex - global decimal - - clean_restart $testfile - - runto_main - gdb_breakpoint [gdb_get_line_number "set breakpoint here"] - gdb_continue_to_breakpoint "breakpoint for $name" - - set expected_len [expr 1 + [llength $arglist]] - gdb_test "print argc" "\\\$$decimal = $expected_len" "argc for $name" - - set i 1 - foreach arg $arglist { - gdb_test "print argv\[$i\]" "\\\$$decimal = $hex \"$arg\"" \ - "argv\[$i\] for $name" - set i [expr $i + 1] + save_vars { ::GDBFLAGS } { + set ::GDBFLAGS "$::GDBFLAGS --args $::binfile $arglist" + + clean_restart $::binfile + + runto_main + gdb_breakpoint [gdb_get_line_number "set breakpoint here"] + gdb_continue_to_breakpoint "breakpoint for $name" + + set expected_len [expr 1 + [llength $arglist]] + gdb_test "print argc" "\\\$$::decimal = $expected_len" "argc for $name" + + set i 1 + foreach arg $arglist { + if { $arg eq "\n" } { + set arg {\\n} + } + verbose -log "APB: regexp '$arg'" + gdb_test "print argv\[$i\]" "\\\$$::decimal = $::hex \"$arg\"" \ + "argv\[$i\] for $name" + set i [expr $i + 1] + } } } -# # Test that the --args are processed correctly. -# -save_vars { GDBFLAGS } { - set old_gdbflags $GDBFLAGS +args_test basic {{1} {3}} - set GDBFLAGS "$old_gdbflags --args $binfile 1 3" - args_test basic {{1} {3}} +# Test that the --args are processed correctly even if one of them is +# empty. - # - # Test that the --args are processed correctly even if one of them is empty. - # The syntax needed is a little peculiar; DejaGNU treats the arguments as a - # list and expands them itself, since no shell redirection is involved. - # - set GDBFLAGS "$old_gdbflags --args $binfile 1 {} 3" - args_test "one empty" {{1} {} {3}} +args_test "one empty" {{1} {} {3}} - # - # try with 2 empty args - # - set GDBFLAGS "$old_gdbflags --args $binfile 1 {} {} 3" - args_test "two empty" {{1} {} {} 3} +# Try with 2 empty args. - # Try with arguments containing literal single quotes. +args_test "two empty" {{1} {} {} 3} - set GDBFLAGS "$old_gdbflags --args $binfile 1 '' 3" - args_test "one empty with single quotes" {{1} {''} {3}} +# Try with arguments containing literal single quotes. - set GDBFLAGS "$old_gdbflags --args $binfile 1 '' '' 3" - args_test "two empty with single quotes" {{1} {''} {''} {3}} +args_test "one empty with single quotes" {{1} {''} {3}} - # try with arguments containing literal newlines. +args_test "two empty with single quotes" {{1} {''} {''} {3}} - set GDBFLAGS "$old_gdbflags --args $binfile 1 {\n} 3" - args_test "one newline" {{1} {\\n} {3}} +# Try with arguments containing literal newlines. - set GDBFLAGS "$old_gdbflags --args $binfile 1 {\n} {\n} 3" - args_test "two newlines" {{1} {\\n} {\\n} {3}} -} +args_test "one newline" {{1} "\n" {3}} + +args_test "two newlines" {{1} "\n" "\n" {3}}