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 29F9D3858D33 for ; Wed, 27 Sep 2023 12:21:20 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 29F9D3858D33 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=1695817279; 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=2wSNe6ICc8zUtFbhhTWqzb0F/b28QDlm7uE57xdshQQ=; b=EgWDfB7UglPHSMOs9NZ3lkx2PqcyGiNbOSnGpTv2C+3DXIBONELRc7co0OXRszFZ4OknhS npjelvBv2PvcIFfnKMa7VffCWOFexPuDRRqmbVqSfc8FcZFYmbFQLoPL9eq1n0+vm7THFv mblq2/KrNRHaikg/joZvq5hgLkgNURc= Received: from mail-qt1-f197.google.com (mail-qt1-f197.google.com [209.85.160.197]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-59-X8FDjjVGPXaKA727oEQTFA-1; Wed, 27 Sep 2023 08:21:18 -0400 X-MC-Unique: X8FDjjVGPXaKA727oEQTFA-1 Received: by mail-qt1-f197.google.com with SMTP id d75a77b69052e-4180c303ef1so145045471cf.0 for ; Wed, 27 Sep 2023 05:21:18 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1695817278; x=1696422078; 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=2wSNe6ICc8zUtFbhhTWqzb0F/b28QDlm7uE57xdshQQ=; b=Nfj1sArTaEg7hXjaf2kGDbRQjxLo+u/FsheyzT3B22/Y4ZGdRbuiv/1vqMLrCIdq/i D2AScFqyRrvvJmqRzi6Y9jaeloELpEzYtpq3NcV4pUpsl4NCd6Fexc8acM38aVIgcZf0 3JLnk3csIYm2PkE6WagcUOZ8HYakOyXfgqf/8PAXahSElTJ3RYR00U0mqeYJpXH0SbfU 3lCKK4QRegB8cPgZ0HvwvReYUHhI6UHHzC1QT0wcNsy+zS3QifMteQjGcQEbs9w+6H2i dCa+8jGguIue7e4IXlG2QcaggafnqG3qBtakYfBzT5wO/et+41fse78OZ4CE6GwfJ+Ri Lq0g== X-Gm-Message-State: AOJu0Yzm01Z4ZfUEIs5iTqphhA3RWmr55CXenlT9d5Aad5AMDDqFMCpz N21GhHSMeMojZZS8zYlzfe8lCoWLIn+5wve0JYq20JWb+8Be60ZovH+U1wLNJp6o8lrI4o/zrbe jfLMxUjP2HS1qqsxFE94/8x1XK6FKMeAHYb9OB5YjOwzFWQ9BOYUuu+CYUwshk32Me5PzYPT75J ZY7Hg+vw== X-Received: by 2002:ac8:5ad5:0:b0:418:1c31:dada with SMTP id d21-20020ac85ad5000000b004181c31dadamr2287827qtd.31.1695817278014; Wed, 27 Sep 2023 05:21:18 -0700 (PDT) X-Google-Smtp-Source: AGHT+IE8HB5THh1MEHusvKqgss55Tp5Rgvg5xdgb/39EqZ5bUcgleF2x6mIuVzYmHOk/XIyIEDV6wg== X-Received: by 2002:ac8:5ad5:0:b0:418:1c31:dada with SMTP id d21-20020ac85ad5000000b004181c31dadamr2287809qtd.31.1695817277636; Wed, 27 Sep 2023 05:21:17 -0700 (PDT) Received: from localhost ([31.111.84.209]) by smtp.gmail.com with ESMTPSA id l13-20020ac84a8d000000b004181b41e793sm2148028qtq.50.2023.09.27.05.21.16 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 27 Sep 2023 05:21:17 -0700 (PDT) From: Andrew Burgess To: gdb-patches@sourceware.org Cc: Andrew Burgess Subject: [PATCH] gdbserver: fix handling of single quote arguments Date: Wed, 27 Sep 2023 13:21:14 +0100 Message-Id: <2b98ca58e47638b4760d86bd6e1fa9a9a79fa2ad.1695817255.git.aburgess@redhat.com> X-Mailer: git-send-email 2.25.4 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.5 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. --- gdb/testsuite/gdb.base/inferior-args.exp | 7 +++++-- gdbserver/server.cc | 6 ------ 2 files changed, 5 insertions(+), 8 deletions(-) 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; } base-commit: f586e3409b752748bf213520c2dbb0b44e0005d8 -- 2.25.4