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.133.124]) by sourceware.org (Postfix) with ESMTPS id B88FC3858C52 for ; Thu, 1 Sep 2022 21:31:26 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org B88FC3858C52 Received: from mail-wm1-f70.google.com (mail-wm1-f70.google.com [209.85.128.70]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_128_GCM_SHA256) id us-mta-524-auLvAG4vO9iN2ecwA4LUdA-1; Thu, 01 Sep 2022 17:31:25 -0400 X-MC-Unique: auLvAG4vO9iN2ecwA4LUdA-1 Received: by mail-wm1-f70.google.com with SMTP id q10-20020a1ce90a000000b003a60123678aso75839wmc.6 for ; Thu, 01 Sep 2022 14:31:25 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; 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; bh=hRMvuWi16MBlAmS3KciC/WXPPltoYCnPvVCw+w8L8sc=; b=NvonrA+7fnk1HsWGiNmSSYNAyPPmIupsRPCQ0P+gmx7qxNHba+d/qzlW+lyUFEGIjd ci5jDABCTkMaieiIZllH0EcCq64jYYrU1qwVGSLLHvUnAfujALFkz7043XDkgjZStHt0 lJ/OtMZR+NBQoFpPIOzMz9FRzJxJwq+yF/gTqqbtzQowN45lq5g/A1ohbRfJiUXSQJtq rOwTsXEy/mA947Os56GZPu46FdC6+0Kbu8MhywpgIfKpPuczLkl5tM35H/DTH9nInXLM DHDVEkeGdDYp1aDH7XMDqFeUt1E4WeoUnp+DLQjAHraTQVl2Kz3t/rBVygNDsFryZBnS tkmQ== X-Gm-Message-State: ACgBeo3ftdGgAiEjYfjsfb+3G/OJdQ+FpbMz9Ez6Kw3O6Bc3m96d+/st NprzdoJYvasa/zhQQCgboDaOo+KRq1DyRtC+rSvusy/SMpQ1+RBH5m/QGwhWqK3b7jAfG+otU34 w+RfG0CDbAe0UqlVAF/4kRN3DJS7bj2t2CvYl8oLiceMYMMKWDtxrA3BkgUNiAeJJmQTW+pDwqw == X-Received: by 2002:a05:6000:178c:b0:222:f8ec:9977 with SMTP id e12-20020a056000178c00b00222f8ec9977mr15114004wrg.509.1662067882500; Thu, 01 Sep 2022 14:31:22 -0700 (PDT) X-Google-Smtp-Source: AA6agR4k0gHUak5CU4aQIOJk9d0T+BD5NWsawzgyoYEvI6tX8ba06svDr75801gS3IZDwvyA01qHCA== X-Received: by 2002:a05:6000:178c:b0:222:f8ec:9977 with SMTP id e12-20020a056000178c00b00222f8ec9977mr15113993wrg.509.1662067882230; Thu, 01 Sep 2022 14:31:22 -0700 (PDT) Received: from localhost ([31.111.84.229]) by smtp.gmail.com with ESMTPSA id o16-20020a05600c4fd000b003a5c999cd1asm325294wmq.14.2022.09.01.14.31.21 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 01 Sep 2022 14:31:21 -0700 (PDT) From: Andrew Burgess To: gdb-patches@sourceware.org Subject: [PATCH 1/9] gdb/testsuite: rewrite capture_command_output proc Date: Thu, 1 Sep 2022 22:31:09 +0100 Message-Id: X-Mailer: git-send-email 2.25.4 In-Reply-To: References: 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.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, SPF_HELO_NONE, SPF_NONE, TXREP, T_SCC_BODY_TEXT_LINE 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.29 Precedence: list List-Id: Gdb-patches mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Thu, 01 Sep 2022 21:31:32 -0000 I noticed a test failure in gdb.base/completion.exp for RISC-V on a native Linux target. Upon investigation I discovered a couple of reasons for the failure, this commit addresses one of them. A later commit will address the other issue. The completion.exp test makes use of the capture_command_output proc to collect the output of the 'maint print registers' command. For RISC-V this command produces a lot of output. Currently the capture_command_output proc tries to collect the complete command output in a single expect buffer, and what I see is an error caused by the expect buffer becoming full. This commit rewrites capture_command_output to make use of gdb_test_multiple to collect the command output line at a time, in this way we avoid overflowing the expect buffer. The capture_command_output proc has some logic for skipping a prefix pattern, which is passed in to the proc as an argument. In order to handle this correctly (only matching the prefix at the start of the command output), I use two gdb_test_multiple calls, the first spots and discards the echoed command and the (optional) prefix pattern, the second gdb_test_multiple call then collects the rest of the command output line at a time until a prompt is seen. There is one slight oddity with the current implementation, which I have changed in my rewrite, this does, slightly, change the behaviour of the proc. The current implementation uses this pattern: -re "[string_to_regexp ${command}]\[\r\n\]+${prefix}(.*)\[\r\n\]+$gdb_prompt $" Now a typical command output will look like this: output here\r\n (gdb) As the TCL regexp matching is greedy, TCL will try to match as much as possible in one part of the pattern before moving on to the next. Thus, when this matches against (.*)[\r\n]+, the (.*) will end up matching against 'output here\r' and the [\r\n]+ will match '\n' only. In short the previous implementation would leave the '\r' on the end of the returned text, but not the final trailing '\n'. Now clearly I could make a new version of capture_command_output that maintained this behaviour, but I couldn't see any reason to do this. So, my new implementation drops the final '\r\n' completely, in our example above we now return 'output here' with no '\r'. This change doesn't seem to affect any of the existing tests, but I thought it was worth mentioning. --- gdb/testsuite/lib/gdb.exp | 35 ++++++++++++++++++++++++++++++++--- 1 file changed, 32 insertions(+), 3 deletions(-) diff --git a/gdb/testsuite/lib/gdb.exp b/gdb/testsuite/lib/gdb.exp index 17523f82996..65318f1cd55 100644 --- a/gdb/testsuite/lib/gdb.exp +++ b/gdb/testsuite/lib/gdb.exp @@ -7862,12 +7862,41 @@ proc capture_command_output { command prefix } { global gdb_prompt global expect_out + set code { + -re "^[string_to_regexp ${command}]\r\n" { + if { $prefix != "" } { + exp_continue + } + } + } + + if { $prefix != "" } { + append code { + -re "^${prefix}" { + # Nothing, we just move onto the next gdb_test_multiple + # call, which actually collects the command output. + } + } + } + + gdb_test_multiple "$command" "capture_command_output for $command" $code + set output_string "" - gdb_test_multiple "$command" "capture_command_output for $command" { - -re "[string_to_regexp ${command}]\[\r\n\]+${prefix}(.*)\[\r\n\]+$gdb_prompt $" { - set output_string $expect_out(1,string) + gdb_test_multiple "" "" { + -re "^(\[^\r\n\]+\r\n)" { + if { ![string equal $output_string ""] } { + set output_string [join [list $output_string $expect_out(1,string)] ""] + } else { + set output_string $expect_out(1,string) + } + exp_continue + } + + -re "^$gdb_prompt $" { } } + + set output_string [regsub "\r\n$" $output_string ""] return $output_string } -- 2.25.4