public inbox for gdb-patches@sourceware.org
 help / color / mirror / Atom feed
From: Tom de Vries <tdevries@suse.de>
To: gdb-patches@sourceware.org
Subject: [pushed 2/2] [gdb/testsuite] Reimplement Term::command_no_prompt_prefix
Date: Wed, 21 Jun 2023 15:32:00 +0200	[thread overview]
Message-ID: <20230621133200.25576-2-tdevries@suse.de> (raw)
In-Reply-To: <20230621133200.25576-1-tdevries@suse.de>

Say we run test-case gdb.tui/basic.exp.  It calls Term::enter_tui, which does:
...
	command_no_prompt_prefix "tui enable"
...

The proc command_no_prompt_prefix is documented as:
...
    # As proc command, but don't wait for an initial prompt.  This is used for
    # initial terminal commands, where there's no prompt yet.
...

Indeed, before the "tui enable" command, the tuiterm is empty, so there is no
prompt and just before switching to TUI we have in the tuiterm:
...
tui enable
...

The reason that there is no prompt, is that:
- in order for tuiterm to show something, its input processing procs need to
  be called, and
- the initial gdb prompt, and subsequent prompts generated by gdb_test-style
  procs, are all consumed by those procs instead.

This is in principle not a problem, but the absence of a prompt makes a
tuiterm session look less like a session on an actual xterm.

Add a new proc gen_prompt, that:
- generates a prompt using echo
- consumes the response before the prompt using gdb_expect
- consumes the prompt using Term::wait_for "".

This allows us to reimplement Term::command_no_prompt_prefix using
Term::command, and just before switching to TUI we have in the tuiterm:
...
(gdb) tui enable
...

Tested on x86_64-linux.
---
 gdb/testsuite/lib/tuiterm.exp | 20 +++++++++++++++++---
 1 file changed, 17 insertions(+), 3 deletions(-)

diff --git a/gdb/testsuite/lib/tuiterm.exp b/gdb/testsuite/lib/tuiterm.exp
index 41fa554aa09..598c1f8cbdf 100644
--- a/gdb/testsuite/lib/tuiterm.exp
+++ b/gdb/testsuite/lib/tuiterm.exp
@@ -875,6 +875,21 @@ namespace eval Term {
 	}
     }
 
+    # Generate prompt on TUIterm.
+    proc gen_prompt {} {
+	# Generate a prompt.
+	send_gdb "echo\n"
+
+	# Drain the output before the prompt.
+	gdb_expect {
+	    -re "echo\r\n" {
+	    }
+	}
+
+	# Interpret prompt using TUIterm.
+	wait_for ""
+    }
+
     # Setup ready for starting the tui, but don't actually start it.
     # Returns 1 on success, 0 if TUI tests should be skipped.
     proc prepare_for_tui {} {
@@ -920,9 +935,8 @@ namespace eval Term {
     # As proc command, but don't wait for an initial prompt.  This is used for
     # initial terminal commands, where there's no prompt yet.
     proc command_no_prompt_prefix {cmd} {
-	send_gdb "$cmd\n"
-	set str [string_to_regexp $cmd]
-	wait_for "^$str"
+	gen_prompt
+	command $cmd
     }
 
     # Apply the attribute list in ATTRS to attributes array UPVAR_NAME.
-- 
2.35.3


      reply	other threads:[~2023-06-21 13:31 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-06-21 13:31 [pushed 1/2] [gdb/testsuite] Make Term::wait_for "" match only a prompt Tom de Vries
2023-06-21 13:32 ` Tom de Vries [this message]

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=20230621133200.25576-2-tdevries@suse.de \
    --to=tdevries@suse.de \
    --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).