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 } {
