From patchwork Wed Sep 27 12:21:14 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Andrew Burgess X-Patchwork-Id: 76755 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 B97033857725 for ; Wed, 27 Sep 2023 12:21:50 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org B97033857725 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=sourceware.org; s=default; t=1695817310; bh=2wSNe6ICc8zUtFbhhTWqzb0F/b28QDlm7uE57xdshQQ=; h=To:Subject:Date:List-Id:List-Unsubscribe:List-Archive:List-Post: List-Help:List-Subscribe:From:Reply-To:From; b=T7w5jeTVjeYYsOk7QecmoX3YYkzSr1zMKxY94K8v/Qb+QuQez6ljyIlxOjMOZaZEu eVNdBo9+BB0ZiwlXTQnnVQWcud24Wsky6kELnMhaEhatKXOJuN26X+mHExztmYGMhl oMZIPZAVb6kVy0H3LwYu6DY9mwg7tSeNX6G8W3W0= 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 29F9D3858D33 for ; Wed, 27 Sep 2023 12:21:20 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 29F9D3858D33 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) To: gdb-patches@sourceware.org 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 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 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. --- gdb/testsuite/gdb.base/inferior-args.exp | 7 +++++-- gdbserver/server.cc | 6 ------ 2 files changed, 5 insertions(+), 8 deletions(-) base-commit: f586e3409b752748bf213520c2dbb0b44e0005d8 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; }