public inbox for gdb-patches@sourceware.org
 help / color / mirror / Atom feed
From: Andrew Burgess <aburgess@redhat.com>
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	[thread overview]
Message-ID: <bebc14f74cfa6921f2958c9e273689ba837d7451.1662067442.git.aburgess@redhat.com> (raw)
In-Reply-To: <cover.1662067442.git.aburgess@redhat.com>

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


  reply	other threads:[~2022-09-01 21:31 UTC|newest]

Thread overview: 13+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-09-01 21:31 [PATCH 0/9] Lots of changes to gdbarch_register_name (many architectures) Andrew Burgess
2022-09-01 21:31 ` Andrew Burgess [this message]
2022-09-01 21:31 ` [PATCH 2/9] gdb/riscv: fix failure in gdb.base/completion.exp Andrew Burgess
2022-09-01 21:31 ` [PATCH 3/9] gdb/gdbarch: add a comment to gdbarch_register_name Andrew Burgess
2022-09-01 21:31 ` [PATCH 4/9] gdb: add a gdbarch_register_name self test, and fix some architectures Andrew Burgess
2022-09-01 21:31 ` [PATCH 5/9] gdb: check for duplicate register names in selftest Andrew Burgess
2022-09-01 21:31 ` [PATCH 6/9] gdb: add asserts to gdbarch_register_name Andrew Burgess
2022-09-21 18:04   ` Tom Tromey
2022-09-01 21:31 ` [PATCH 7/9] gdb/csky: remove nullptr return from csky_pseudo_register_name Andrew Burgess
2022-09-01 21:31 ` [PATCH 8/9] gdb: final cleanup of various gdbarch_register_name methods Andrew Burgess
2022-09-01 21:31 ` [PATCH 9/9] gdb: update now gdbarch_register_name doesn't return nullptr Andrew Burgess
2022-09-21 18:07 ` [PATCH 0/9] Lots of changes to gdbarch_register_name (many architectures) Tom Tromey
2022-10-02 16:28   ` Andrew Burgess

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=bebc14f74cfa6921f2958c9e273689ba837d7451.1662067442.git.aburgess@redhat.com \
    --to=aburgess@redhat.com \
    --cc=gdb-patches@sourceware.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).