public inbox for gdb-patches@sourceware.org
 help / color / mirror / Atom feed
* [PATCH] [gdb/testsuite] Remove Term::command_no_prompt_prefix
@ 2023-06-09  7:26 Tom de Vries
  2023-06-21 13:35 ` Tom de Vries
  0 siblings, 1 reply; 2+ messages in thread
From: Tom de Vries @ 2023-06-09  7:26 UTC (permalink / raw)
  To: gdb-patches; +Cc: Tom Tromey

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.

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.

Fix this by using a new proc gen_prompt, that:
- generates a prompt using ^C (though also something like echo \n would work)
- consumes the response before the prompt using gdb_expect
- consumes the prompt using Term::wait_for "".

A fix was necessary to Term::wait_for, to make sure that Term::wait_for ""
consumes just one prompt.

This allows us to use the regular proc command instead:
...
        gen_prompt
	command "tui enable"
...
such that we have in tuiterm:
...
(gdb) tui enable
...
instead of:
...
tui enable
...

Fix all uses of command_no_prompt_prefix, and remove it.

Tested on x86_64-linux.
---
 .../gdb.python/tui-window-factory.exp         |  3 +-
 gdb/testsuite/gdb.tui/completion.exp          |  3 +-
 gdb/testsuite/gdb.tui/resize-2.exp            |  3 +-
 .../gdb.tui/tui-disasm-long-lines.exp         |  3 +-
 gdb/testsuite/gdb.tui/tui-focus.exp           |  6 ++--
 .../gdb.tui/tui-layout-asm-short-prog.exp     |  3 +-
 gdb/testsuite/gdb.tui/tui-layout-asm.exp      |  3 +-
 gdb/testsuite/gdb.tui/tui-layout.exp          |  3 +-
 gdb/testsuite/lib/tuiterm.exp                 | 31 +++++++++++++------
 9 files changed, 40 insertions(+), 18 deletions(-)

diff --git a/gdb/testsuite/gdb.python/tui-window-factory.exp b/gdb/testsuite/gdb.python/tui-window-factory.exp
index e3b403bdea0..c41e12881e5 100644
--- a/gdb/testsuite/gdb.python/tui-window-factory.exp
+++ b/gdb/testsuite/gdb.python/tui-window-factory.exp
@@ -53,7 +53,8 @@ gdb_test_no_output "tui new-layout test test_window 1 cmd 1 status 1"
 # Load the custom window layout and ensure that the correct window
 # factory was used.
 with_test_prefix "msg_2" {
-    Term::command_no_prompt_prefix "layout test"
+    Term::gen_prompt
+    Term::command "layout test"
     Term::check_box_contents "check test_window box" 0 0 80 15 \
 	"TestWindow \\(msg_2\\)"
 }
diff --git a/gdb/testsuite/gdb.tui/completion.exp b/gdb/testsuite/gdb.tui/completion.exp
index 9cf8dc2ee25..37e9cc93805 100644
--- a/gdb/testsuite/gdb.tui/completion.exp
+++ b/gdb/testsuite/gdb.tui/completion.exp
@@ -66,7 +66,8 @@ if {![Term::prepare_for_tui]} {
     return
 }
 
-Term::command_no_prompt_prefix "layout src"
+Term::gen_prompt
+Term::command "layout src"
 Term::command "complete focus "
 Term::dump_screen
 Term::check_region_contents "check focus completions" 0 17 80 5 \
diff --git a/gdb/testsuite/gdb.tui/resize-2.exp b/gdb/testsuite/gdb.tui/resize-2.exp
index ebe8216c05d..456558abdca 100644
--- a/gdb/testsuite/gdb.tui/resize-2.exp
+++ b/gdb/testsuite/gdb.tui/resize-2.exp
@@ -31,7 +31,8 @@ if {![Term::prepare_for_tui]} {
 }
 
 # Enter TUI.
-Term::command_no_prompt_prefix "layout command-layout"
+Term::gen_prompt
+Term::command "layout command-layout"
 
 proc check_width { what n } {
     set re "Number of characters $what thinks are in a line is $n"
diff --git a/gdb/testsuite/gdb.tui/tui-disasm-long-lines.exp b/gdb/testsuite/gdb.tui/tui-disasm-long-lines.exp
index 5d395cd604b..c425df87e67 100644
--- a/gdb/testsuite/gdb.tui/tui-disasm-long-lines.exp
+++ b/gdb/testsuite/gdb.tui/tui-disasm-long-lines.exp
@@ -41,6 +41,7 @@ if {![Term::prepare_for_tui]} {
     return
 }
 
-Term::command_no_prompt_prefix "layout asm"
+Term::gen_prompt
+Term::command "layout asm"
 Term::check_box "asm box" 0 0 80 15
 Term::check_box_contents "check asm box contents" 0 0 80 15 "<main>"
diff --git a/gdb/testsuite/gdb.tui/tui-focus.exp b/gdb/testsuite/gdb.tui/tui-focus.exp
index 72f80523af3..2266f0cc34b 100644
--- a/gdb/testsuite/gdb.tui/tui-focus.exp
+++ b/gdb/testsuite/gdb.tui/tui-focus.exp
@@ -42,7 +42,8 @@ foreach spec {{src true} {cmd true} {status true} {regs false} \
 	    return
 	}
 
-	Term::command_no_prompt_prefix "focus $window"
+	Term::gen_prompt
+	Term::command "focus $window"
 
 	if {$valid_p} {
 	    # The 'status' window is special, it's present in the
@@ -110,7 +111,8 @@ if {[allow_python_tests]} {
     # Try to focus using an ambiguous, partial window name.  This
     # should fail as the default layout (src) doesn't include any
     # windows matching this name.
-    Term::command_no_prompt_prefix "focus test"
+    Term::gen_prompt
+    Term::command "focus test"
     Term::check_region_contents "check no matching window focus message" \
 	0 16 80 1 \
 	"^No windows matching \"test\" in the current layout\\s*"
diff --git a/gdb/testsuite/gdb.tui/tui-layout-asm-short-prog.exp b/gdb/testsuite/gdb.tui/tui-layout-asm-short-prog.exp
index 9014622d35c..4347c3b6d3c 100644
--- a/gdb/testsuite/gdb.tui/tui-layout-asm-short-prog.exp
+++ b/gdb/testsuite/gdb.tui/tui-layout-asm-short-prog.exp
@@ -41,7 +41,8 @@ if { $gdb_file_cmd_debug_info == "nodebug" } {
 gdb_test_no_output "maint set tui-left-margin-verbose on"
 
 # This puts us into TUI mode, and should display the ASM window.
-Term::command_no_prompt_prefix "layout asm"
+Term::gen_prompt
+Term::command "layout asm"
 Term::check_box_contents "check asm box contents" 0 0 80 15 "<_start>"
 
 # Record the first line of output, we'll need this later.
diff --git a/gdb/testsuite/gdb.tui/tui-layout-asm.exp b/gdb/testsuite/gdb.tui/tui-layout-asm.exp
index 380477cb457..42f5dbf6a79 100644
--- a/gdb/testsuite/gdb.tui/tui-layout-asm.exp
+++ b/gdb/testsuite/gdb.tui/tui-layout-asm.exp
@@ -39,7 +39,8 @@ proc count_whitespace { string } {
 }
 
 # This puts us into TUI mode, and should display the ASM window.
-Term::command_no_prompt_prefix "layout asm"
+Term::gen_prompt
+Term::command "layout asm"
 Term::check_box_contents "check asm box contents" 0 0 ${tui_asm_window_width} 15 "<main>"
 
 # Scroll the ASM window down using the down arrow key.  In an ideal
diff --git a/gdb/testsuite/gdb.tui/tui-layout.exp b/gdb/testsuite/gdb.tui/tui-layout.exp
index 13823387e72..eb0ad1787b8 100644
--- a/gdb/testsuite/gdb.tui/tui-layout.exp
+++ b/gdb/testsuite/gdb.tui/tui-layout.exp
@@ -68,7 +68,8 @@ proc test_layout_or_focus {layout_name terminal execution} {
 	gdb_test "layout $layout_name" \
 	    "Cannot enable the TUI: terminal doesn't support cursor addressing \\\[TERM=dumb\\\]"
     } else {
-	Term::command_no_prompt_prefix "layout $layout_name"
+	Term::gen_prompt
+	Term::command "layout $layout_name"
 	if {$layout_name == "asm"} {
 	    Term::check_box "asm box" 0 0 80 15
 	} elseif {$layout_name == "reg"} {
diff --git a/gdb/testsuite/lib/tuiterm.exp b/gdb/testsuite/lib/tuiterm.exp
index 171b242aa80..4fac47578f4 100644
--- a/gdb/testsuite/lib/tuiterm.exp
+++ b/gdb/testsuite/lib/tuiterm.exp
@@ -789,6 +789,10 @@ namespace eval Term {
 	set fn "wait_for"
 
 	set prompt_wait_for "$gdb_prompt \$"
+	if { $wait_for == "" } {
+	    set wait_for $prompt_wait_for
+	}
+
 	debug_tui_matching "$fn: regexp: '$wait_for'"
 
 	while 1 {
@@ -871,6 +875,22 @@ namespace eval Term {
 	}
     }
 
+    # Generate prompt on TUIterm.
+    proc gen_prompt {} {
+	# Send ^C, generate a prompt.
+	send_gdb "\003"
+
+	# Drain the output before the prompt.
+	gdb_expect {
+	    -re "Quit\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 {} {
@@ -898,7 +918,8 @@ namespace eval Term {
 	    return 0
 	}
 
-	command_no_prompt_prefix "tui enable"
+	gen_prompt
+	command "tui enable"
 	return 1
     }
 
@@ -913,14 +934,6 @@ namespace eval Term {
 	wait_for $str
     }
 
-    # 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"
-    }
-
     # Apply the attribute list in ATTRS to attributes array UPVAR_NAME.
     # Return a string annotating the changed attributes.
     proc apply_attrs { upvar_name attrs } {

base-commit: 30711c89cc7dcd2bd4ea772b2f5dc639c5b1cfcc
-- 
2.35.3


^ permalink raw reply	[flat|nested] 2+ messages in thread

* Re: [PATCH] [gdb/testsuite] Remove Term::command_no_prompt_prefix
  2023-06-09  7:26 [PATCH] [gdb/testsuite] Remove Term::command_no_prompt_prefix Tom de Vries
@ 2023-06-21 13:35 ` Tom de Vries
  0 siblings, 0 replies; 2+ messages in thread
From: Tom de Vries @ 2023-06-21 13:35 UTC (permalink / raw)
  To: gdb-patches; +Cc: Tom Tromey

On 6/9/23 09:26, Tom de Vries via Gdb-patches wrote:
> 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.
> 
> 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.
> 
> Fix this by using a new proc gen_prompt, that:
> - generates a prompt using ^C (though also something like echo \n would work)
> - consumes the response before the prompt using gdb_expect
> - consumes the prompt using Term::wait_for "".
> 
> A fix was necessary to Term::wait_for, to make sure that Term::wait_for ""
> consumes just one prompt.
> 
> This allows us to use the regular proc command instead:
> ...
>          gen_prompt
> 	command "tui enable"
> ...
> such that we have in tuiterm:
> ...
> (gdb) tui enable
> ...
> instead of:
> ...
> tui enable
> ...
> 
> Fix all uses of command_no_prompt_prefix, and remove it.
> 

I split up the patch in two parts (one separate patch for the change in 
Term::wait_for), and rather than removing command_no_prompt_prefix, 
reimplemented it.  Committed, and posted here:
- https://sourceware.org/pipermail/gdb-patches/2023-June/200422.html
- https://sourceware.org/pipermail/gdb-patches/2023-June/200423.html

Thanks,
- Tom





^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2023-06-21 13:35 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2023-06-09  7:26 [PATCH] [gdb/testsuite] Remove Term::command_no_prompt_prefix Tom de Vries
2023-06-21 13:35 ` Tom de Vries

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).