From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: by sourceware.org (Postfix, from userid 1726) id C44A83858D32; Sun, 2 Oct 2022 16:27:35 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org C44A83858D32 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=sourceware.org; s=default; t=1664728055; bh=pp+C79c2Vq0BKnoAbmNSPCUyvRLiko99BRFzDr3tg5k=; h=From:To:Subject:Date:From; b=noOvWdr6Iw1tlA/3SU0CRWeMT5ty4smbDBd57ziG9Q+TEmKmwxv17c/FU523w4tfi Tya0Yw1nvKw9s6NNOzUCqtnsOHu4MqZU4Tt/JPfH9Z8iG5AsYGGJWfZhnahkEIdmYO ZRYyFQZq20Wcj6nsD8KS9Q4BnsfZdvOx4DQZGd/4= Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable From: Andrew Burgess To: gdb-cvs@sourceware.org Subject: [binutils-gdb] gdb/testsuite: rewrite capture_command_output proc X-Act-Checkin: binutils-gdb X-Git-Author: Andrew Burgess X-Git-Refname: refs/heads/master X-Git-Oldrev: 08f406e9a1e3b83d0778493cb219075bbae7bb59 X-Git-Newrev: e7b1ba07bc9dc28819c9a2523f5e5cdb43e13ca2 Message-Id: <20221002162735.C44A83858D32@sourceware.org> Date: Sun, 2 Oct 2022 16:27:35 +0000 (GMT) List-Id: https://sourceware.org/git/gitweb.cgi?p=3Dbinutils-gdb.git;h=3De7b1ba07bc9d= c28819c9a2523f5e5cdb43e13ca2 commit e7b1ba07bc9dc28819c9a2523f5e5cdb43e13ca2 Author: Andrew Burgess Date: Sun Aug 28 20:21:07 2022 +0100 gdb/testsuite: rewrite capture_command_output proc =20 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. =20 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. =20 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. =20 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. =20 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. =20 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. =20 The current implementation uses this pattern: =20 -re "[string_to_regexp ${command}]\[\r\n\]+${prefix}(.*)\[\r\n\]+$gdb= _prompt $" =20 Now a typical command output will look like this: =20 output here\r\n (gdb) =20 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. =20 In short the previous implementation would leave the '\r' on the end of the returned text, but not the final trailing '\n'. =20 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'. =20 This change doesn't seem to affect any of the existing tests, but I thought it was worth mentioning. Diff: --- 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 5ab4df1bcf3..432ed5e34ca 100644 --- a/gdb/testsuite/lib/gdb.exp +++ b/gdb/testsuite/lib/gdb.exp @@ -7857,12 +7857,41 @@ proc capture_command_output { command prefix } { global gdb_prompt global expect_out =20 + set code { + -re "^[string_to_regexp ${command}]\r\n" { + if { $prefix !=3D "" } { + exp_continue + } + } + } + + if { $prefix !=3D "" } { + 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" $co= de + set output_string "" - gdb_test_multiple "$command" "capture_command_output for $command" { - -re "[string_to_regexp ${command}]\[\r\n\]+${prefix}(.*)\[\r\n\]+$gdb_pro= mpt $" { - 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 }