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';