[pushed 2/2] [gdb/testsuite] Reimplement Term::command_no_prompt_prefix

Tom de Vries tdevries@suse.de
Wed Jun 21 13:32:00 GMT 2023


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



More information about the Gdb-patches mailing list