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.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 Authentication-Results: sourceware.org; dmarc=pass (p=none dis=none) header.from=redhat.com Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=redhat.com DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1695835685; 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=6ys2jqDVHK252FxUKhSYTuCTn2TuacqxhtjlU3Uz6vg=; b=TzJc0J2XzR4DKRwMRDimM/OGTTbFBR7R6Sdx9I2wImNIyV5o8T4iA7QrUdP53xf4Lt6Lqr ZUYkXjp1lShFjgLMKcx34+JlSSRuoMWHgKpwGjh38XAalHvv+sh4Koyba4/O5HusSxBJPN jCSMbSllGyN3pPIv67L+wCYzFfJcgNk= 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) From: Andrew Burgess 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 Content-Transfer-Encoding: 8bit Content-Type: text/plain; charset="US-ASCII"; x-default=true 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 List-Id: 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; } -- 2.25.4