diff --git a/gdb/testsuite/gdb.arch/amd64-entry-value.exp b/gdb/testsuite/gdb.arch/amd64-entry-value.exp
index a700e9a691b..3c666acc117 100644
--- a/gdb/testsuite/gdb.arch/amd64-entry-value.exp
+++ b/gdb/testsuite/gdb.arch/amd64-entry-value.exp
@@ -48,8 +48,11 @@ gdb_breakpoint "breakhere_reference"
 
 gdb_continue_to_breakpoint "entry: breakhere"
 
-gdb_test "bt" "^bt\r\n#0 +d *\\(i=31, i@entry=30, j=31\\.5, j@entry=30\\.5\\) \[^\r\n\]*\r\n#1 +0x\[0-9a-f\]+ in main .*" \
-	 "entry: bt"
+gdb_test "bt" \
+    [multi_line \
+	 "^#0 +d *\\(i=31, i@entry=30, j=31\\.5, j@entry=30\\.5\\) \[^\r\n\]*" \
+	 "#1 +0x\[0-9a-f\]+ in main .*"] \
+    "entry: bt"
 gdb_test "p i" " = 31" "entry: p i"
 gdb_test "p i@entry" " = 30" "entry: p i@entry"
 gdb_test "p j" { = 31\.5} "entry: p j"
@@ -61,21 +64,30 @@ gdb_test "p j@entry" { = 30\.5} "entry: p j@entry"
 gdb_continue_to_breakpoint "entry_locexpr: breakhere_locexpr"
 gdb_test "p i" " = 30" "entry_locexpr: p i"
 gdb_test_no_output "set variable i = 0" "entry_locexpr: set variable i = 0"
-gdb_test "bt" "^bt\r\n#0 +locexpr *\\(i=0, i@entry=30\\) \[^\r\n\]*\r\n#1 +0x\[0-9a-f\]+ in main .*" \
-	 "entry_locexpr: bt"
+gdb_test "bt" \
+    [multi_line \
+	 "^#0 +locexpr *\\(i=0, i@entry=30\\) \[^\r\n\]*" \
+	 "#1 +0x\[0-9a-f\]+ in main .*"] \
+    "entry_locexpr: bt"
 
 
 # Test @entry values for stack passed parameters.
 
 gdb_continue_to_breakpoint "entry_stack: stacktest"
 
-gdb_test "bt" "^bt\r\n#0 +stacktest *\\(r1=r1@entry=1, r2=r2@entry=2, \[^\r\n\]+, s1=s1@entry=11, s2=s2@entry=12, \[^\r\n\]+, d9=d9@entry=11\\.5, da=da@entry=12\\.5\\) \[^\r\n\]*\r\n#1 +0x\[0-9a-f\]+ in main .*" \
-	 "entry_stack: bt at entry"
+gdb_test "bt" \
+    [multi_line \
+	 "^#0 +stacktest *\\(r1=r1@entry=1, r2=r2@entry=2, \[^\r\n\]+, s1=s1@entry=11, s2=s2@entry=12, \[^\r\n\]+, d9=d9@entry=11\\.5, da=da@entry=12\\.5\\) \[^\r\n\]*" \
+	 "#1 +0x\[0-9a-f\]+ in main .*"] \
+    "entry_stack: bt at entry"
 
 gdb_continue_to_breakpoint "entry_stack: breakhere_stacktest"
 
-gdb_test "bt" "^bt\r\n#0 +stacktest *\\(r1=r1@entry=1, r2=r2@entry=2, \[^\r\n\]+, s1=3, s1@entry=11, s2=4, s2@entry=12, \[^\r\n\]+, d9=3\\.5, d9@entry=11\\.5, da=4\\.5, da@entry=12\\.5\\) \[^\r\n\]*\r\n#1 +0x\[0-9a-f\]+ in main .*" \
-	 "entry_stack: bt"
+gdb_test "bt" \
+    [multi_line \
+	 "^#0 +stacktest *\\(r1=r1@entry=1, r2=r2@entry=2, \[^\r\n\]+, s1=3, s1@entry=11, s2=4, s2@entry=12, \[^\r\n\]+, d9=3\\.5, d9@entry=11\\.5, da=4\\.5, da@entry=12\\.5\\) \[^\r\n\]*" \
+	 "#1 +0x\[0-9a-f\]+ in main .*"] \
+    "entry_stack: bt"
 
 gdb_test "p s1" " = 3" "entry_stack: p s1"
 gdb_test "p s1@entry" " = 11" "entry_stack: p s1@entry"
@@ -202,8 +214,13 @@ gdb_test "p nodataparam@entry" "Cannot resolve DW_AT_call_data_value" "entry_ref
 
 gdb_continue_to_breakpoint "tailcall: breakhere"
 
-gdb_test "bt" "^bt\r\n#0 +d *\\(i=71, i@entry=70, j=73\\.5, j@entry=72\\.5\\) \[^\r\n\]*\r\n#1 +0x\[0-9a-f\]+ in c \\(i=i@entry=7, j=j@entry=7\\.25\\) \[^\r\n\]*\r\n#2 +0x\[0-9a-f\]+ in b \\(i=i@entry=5, j=j@entry=5\\.25\\) \[^\r\n\]*\r\n#3 +0x\[0-9a-f\]+ in main \[^\r\n\]*" \
-	 "tailcall: bt"
+gdb_test "bt" \
+    [multi_line \
+	 "^#0 +d *\\(i=71, i@entry=70, j=73\\.5, j@entry=72\\.5\\) \[^\r\n\]*" \
+	 "#1 +0x\[0-9a-f\]+ in c \\(i=i@entry=7, j=j@entry=7\\.25\\) \[^\r\n\]*" \
+	 "#2 +0x\[0-9a-f\]+ in b \\(i=i@entry=5, j=j@entry=5\\.25\\) \[^\r\n\]*" \
+	 "#3 +0x\[0-9a-f\]+ in main \[^\r\n\]*"] \
+    "tailcall: bt"
 gdb_test "p i" " = 71" "tailcall: p i"
 gdb_test "p i@entry" " = 70" "tailcall: p i@entry"
 gdb_test "p j" " = 73\\.5" "tailcall: p j"
@@ -243,8 +260,16 @@ gdb_test_multiple $test $test {
 
 gdb_continue_to_breakpoint "ambiguous: breakhere"
 
-gdb_test "bt" "^bt\r\n#0 +d \\(i=<optimized out>, j=<optimized out>\\)\[^\r\n\]*\r\n#1 +0x\[0-9a-f\]+ in amb_z \\(i=<optimized out>\\)\[^\r\n\]*\r\n#2 +0x\[0-9a-f\]+ in amb_y \\(i=<optimized out>\\)\[^\r\n\]*\r\n#3 +0x\[0-9a-f\]+ in amb_x \\(i=<optimized out>\\)\[^\r\n\]*\r\n#4 +0x\[0-9a-f\]+ in amb_b \\(i=i@entry=101\\)\[^\r\n\]*\r\n#5 +0x\[0-9a-f\]+ in amb_a \\(i=i@entry=100\\)\[^\r\n\]*\r\n#6 +0x\[0-9a-f\]+ in main \\(\\)\[^\r\n\]*" \
-	 "ambiguous: bt"
+gdb_test "bt" \
+    [multi_line \
+	 "^#0 +d \\(i=<optimized out>, j=<optimized out>\\)\[^\r\n\]*" \
+	 "#1 +0x\[0-9a-f\]+ in amb_z \\(i=<optimized out>\\)\[^\r\n\]*" \
+	 "#2 +0x\[0-9a-f\]+ in amb_y \\(i=<optimized out>\\)\[^\r\n\]*" \
+	 "#3 +0x\[0-9a-f\]+ in amb_x \\(i=<optimized out>\\)\[^\r\n\]*" \
+	 "#4 +0x\[0-9a-f\]+ in amb_b \\(i=i@entry=101\\)\[^\r\n\]*" \
+	 "#5 +0x\[0-9a-f\]+ in amb_a \\(i=i@entry=100\\)\[^\r\n\]*" \
+	 "#6 +0x\[0-9a-f\]+ in main \\(\\)\[^\r\n\]*"] \
+    "ambiguous: bt"
 
 
 # Test self tail calls verification.
@@ -252,8 +277,14 @@ gdb_test "bt" "^bt\r\n#0 +d \\(i=<optimized out>, j=<optimized out>\\)\[^\r\n\]*
 
 gdb_continue_to_breakpoint "self: breakhere"
 
-gdb_test "bt" "^bt\r\n#0 +d \\(i=<optimized out>, j=<optimized out>\\)\[^\r\n\]*\r\n#1 +0x\[0-9a-f\]+ in self \\(i=<optimized out>\\)\[^\r\n\]*\r\n#2 +0x\[0-9a-f\]+ in self2 \\(i=<optimized out>\\)\[^\r\n\]*\r\n#3 +0x\[0-9a-f\]+ in self \\(i=<optimized out>\\)\[^\r\n\]*\r\n#4 +0x\[0-9a-f\]+ in main \\(\\)\[^\r\n\]*" \
-	 "self: bt"
+gdb_test "bt" \
+    [multi_line \
+	 "^#0 +d \\(i=<optimized out>, j=<optimized out>\\)\[^\r\n\]*" \
+	 "#1 +0x\[0-9a-f\]+ in self \\(i=<optimized out>\\)\[^\r\n\]*" \
+	 "#2 +0x\[0-9a-f\]+ in self2 \\(i=<optimized out>\\)\[^\r\n\]*" \
+	 "#3 +0x\[0-9a-f\]+ in self \\(i=<optimized out>\\)\[^\r\n\]*" \
+	 "#4 +0x\[0-9a-f\]+ in main \\(\\)\[^\r\n\]*"] \
+    "self: bt"
 
 gdb_test_no_output "set debug entry-values 1"
 gdb_test "bt" "DW_OP_entry_value resolving has found function \"self\\(int\\)\" at 0x\[0-9a-f\]+ can call itself via tail calls\r\n.*" \
diff --git a/gdb/testsuite/gdb.arch/amd64-invalid-stack-middle.exp b/gdb/testsuite/gdb.arch/amd64-invalid-stack-middle.exp
index 156300be1d9..c90b92cbf3f 100644
--- a/gdb/testsuite/gdb.arch/amd64-invalid-stack-middle.exp
+++ b/gdb/testsuite/gdb.arch/amd64-invalid-stack-middle.exp
@@ -39,10 +39,10 @@ if ![runto breakpt] {
     return -1
 }
 
-gdb_test "bt" "^bt\r\n#0 +breakpt *\\(\\) \[^\r\n\]*\r\n#1 +0x\[0-9a-f\]+ in func5\[^\r\n\]*\r\n#2 +0x\[0-9a-f\]+ in func4\[^\r\n\]*\r\n#3 +0x\[0-9a-f\]+ in func3\[^\r\n\]*\r\nBacktrace stopped: Cannot access memory at address 0x\[0-9a-f\]+" \
+gdb_test "bt" "^#0 +breakpt *\\(\\) \[^\r\n\]*\r\n#1 +0x\[0-9a-f\]+ in func5\[^\r\n\]*\r\n#2 +0x\[0-9a-f\]+ in func4\[^\r\n\]*\r\n#3 +0x\[0-9a-f\]+ in func3\[^\r\n\]*\r\nBacktrace stopped: Cannot access memory at address 0x\[0-9a-f\]+" \
 	 "first backtrace, with error message"
 
-gdb_test "bt" "^bt\r\n#0 +breakpt *\\(\\) \[^\r\n\]*\r\n#1 +0x\[0-9a-f\]+ in func5\[^\r\n\]*\r\n#2 +0x\[0-9a-f\]+ in func4\[^\r\n\]*\r\n#3 +0x\[0-9a-f\]+ in func3\[^\r\n\]*\r\nBacktrace stopped: Cannot access memory at address 0x\[0-9a-f\]+" \
+gdb_test "bt" "^#0 +breakpt *\\(\\) \[^\r\n\]*\r\n#1 +0x\[0-9a-f\]+ in func5\[^\r\n\]*\r\n#2 +0x\[0-9a-f\]+ in func4\[^\r\n\]*\r\n#3 +0x\[0-9a-f\]+ in func3\[^\r\n\]*\r\nBacktrace stopped: Cannot access memory at address 0x\[0-9a-f\]+" \
 	 "second backtrace, with error message"
 
 clean_restart ${binfile}
diff --git a/gdb/testsuite/gdb.arch/amd64-invalid-stack-top.exp b/gdb/testsuite/gdb.arch/amd64-invalid-stack-top.exp
index b6a25f8525f..03edcef7fcc 100644
--- a/gdb/testsuite/gdb.arch/amd64-invalid-stack-top.exp
+++ b/gdb/testsuite/gdb.arch/amd64-invalid-stack-top.exp
@@ -43,10 +43,10 @@ if ![runto breakpt] {
 # Use 'bt no-filters' here as the python filters will raise their own
 # error during initialisation, the no-filters case is simpler.
 
-gdb_test "bt no-filters" "^bt no-filters\r\n#0 +$hex in func2 \\(\\)\r\nBacktrace stopped: Cannot access memory at address 0x\[0-9a-f\]+" \
+gdb_test "bt no-filters" "^#0 +$hex in func2 \\(\\)\r\nBacktrace stopped: Cannot access memory at address 0x\[0-9a-f\]+" \
 	 "first backtrace, with error message"
 
-gdb_test "bt no-filters" "^bt no-filters\r\n#0 +$hex in func2 \\(\\)\r\nBacktrace stopped: Cannot access memory at address 0x\[0-9a-f\]+" \
+gdb_test "bt no-filters" "^#0 +$hex in func2 \\(\\)\r\nBacktrace stopped: Cannot access memory at address 0x\[0-9a-f\]+" \
 	 "second backtrace, with error message"
 
 clean_restart ${binfile}
diff --git a/gdb/testsuite/gdb.base/compare-sections.exp b/gdb/testsuite/gdb.base/compare-sections.exp
index f24ff16f868..7fa89391b4d 100644
--- a/gdb/testsuite/gdb.base/compare-sections.exp
+++ b/gdb/testsuite/gdb.base/compare-sections.exp
@@ -38,7 +38,7 @@ proc compare_sections { {options ""} } {
 	-re "MIS-MATCHED.*$gdb_prompt $" {
 	    fail $test
 	}
-	-re "warning.*One or more sections.*does not match.*loaded file.*$gdb_prompt $" {
+	-re "warning: One or more sections.*does not match.*loaded file.*$gdb_prompt $" {
 	    fail $test
 	}
 	-re "Section.*matched.*$gdb_prompt $" {
diff --git a/gdb/testsuite/gdb.base/fullpath-expand.exp b/gdb/testsuite/gdb.base/fullpath-expand.exp
index 285d0be08ec..82d3b24fe2a 100644
--- a/gdb/testsuite/gdb.base/fullpath-expand.exp
+++ b/gdb/testsuite/gdb.base/fullpath-expand.exp
@@ -41,8 +41,8 @@ if { $result != 0 || $realsrcfile2 == "" } {
 
 clean_restart ${testfile}
 
-gdb_test "rbreak $realsrcfile2:func" "^rbreak \[^\r\n\]*:func\r\nBreakpoint 1 at 0x\[0-9a-f\]+: file [string_to_regexp ${subdir}/${srcfile2}], line \[0-9\]+\\.\r\nvoid func\\(void\\);" "rbreak XXX/fullpath-expand-func.c:func"
+gdb_test "rbreak $realsrcfile2:func" "^Breakpoint 1 at 0x\[0-9a-f\]+: file [string_to_regexp ${subdir}/${srcfile2}], line \[0-9\]+\\.\r\nvoid func\\(void\\);" "rbreak XXX/fullpath-expand-func.c:func"
 
 # Verify the compilation pathnames are as expected:
 gdb_test "list func" "\tfunc \\(void\\)\r\n.*"
-gdb_test "info source" "^info source\r\nCurrent source file is [string_to_regexp ${subdir}/${srcfile2}]\r\nCompilation directory is /.*"
+gdb_test "info source" "^Current source file is [string_to_regexp ${subdir}/${srcfile2}]\r\nCompilation directory is /.*"
diff --git a/gdb/testsuite/gdb.base/multi-line-starts-subshell.exp b/gdb/testsuite/gdb.base/multi-line-starts-subshell.exp
index 640c3be064c..ee58691fd3f 100644
--- a/gdb/testsuite/gdb.base/multi-line-starts-subshell.exp
+++ b/gdb/testsuite/gdb.base/multi-line-starts-subshell.exp
@@ -52,4 +52,4 @@ gdb_test_multiple "if 1\nshell ${shell_cmd}\nend\nPS1=\"$shell_prompt\"" $test {
 }
 
 # Check that we restore input in GDB correctly.
-gdb_test "print 1" "^print 1\r\n.. = 1" "gdb input still works"
+gdb_test "print 1" "^\\\$$decimal = 1" "gdb input still works"
diff --git a/gdb/testsuite/gdb.base/new-ui-echo.exp b/gdb/testsuite/gdb.base/new-ui-echo.exp
index efcc711e666..96181483752 100644
--- a/gdb/testsuite/gdb.base/new-ui-echo.exp
+++ b/gdb/testsuite/gdb.base/new-ui-echo.exp
@@ -103,10 +103,10 @@ proc echo_test {driver} {
 
     # Ensure echo remains enabled in both consoles.
     with_spawn_id $con1_spawn_id {
-	gdb_test "print 1" "^print 1\r\n\\\$1 = 1" "print on $con1_name echoes"
+	gdb_test "print 1" "\\\$1 = 1" "print on $con1_name echoes"
     }
     with_spawn_id $con2_spawn_id {
-	gdb_test "print 2" "^print 2\r\n\\\$2 = 2" "print on $con2_name echoes"
+	gdb_test "print 2" "\\\$2 = 2" "print on $con2_name echoes"
     }
 }
 
diff --git a/gdb/testsuite/gdb.base/new-ui.exp b/gdb/testsuite/gdb.base/new-ui.exp
index 2056d80f6cc..a6a38fa94d4 100644
--- a/gdb/testsuite/gdb.base/new-ui.exp
+++ b/gdb/testsuite/gdb.base/new-ui.exp
@@ -28,7 +28,7 @@ proc ensure_no_output {message} {
 
     # Run a command and use an anchor to make sure no output appears
     # before the command's expected output.
-    gdb_test "print 999" "^print 999\r\n\\\$$decimal = 999" $message
+    gdb_test "print 999" "^\\\$$decimal = 999" $message
 }
 
 # Run a few execution-related commands on CON1, and ensure the proper
@@ -121,10 +121,10 @@ proc_with_prefix do_test {} {
     # Ensure non-execution commands in one console don't cause output
     # in the other consoles.
     with_spawn_id $gdb_main_spawn_id {
-	gdb_test "print 1" "^print 1\r\n\\\$1 = 1" "print on main console"
+	gdb_test "print 1" "^\\\$1 = 1" "print on main console"
     }
     with_spawn_id $extra_spawn_id {
-	gdb_test "print 2" "^print 2\r\n\\\$2 = 2" "print on extra console"
+	gdb_test "print 2" "^\\\$2 = 2" "print on extra console"
     }
 
     # Verify that we get proper queries on the main UI, but that they are
diff --git a/gdb/testsuite/gdb.base/settings.exp b/gdb/testsuite/gdb.base/settings.exp
index e54203924ec..eb127d246d2 100644
--- a/gdb/testsuite/gdb.base/settings.exp
+++ b/gdb/testsuite/gdb.base/settings.exp
@@ -540,7 +540,9 @@ proc test-string {variant} {
 
     # Checks that gdb doesn't crash if we haven't set the string yet.
     if {$variant != "filename"} {
-	gdb_test "$show_cmd" "^$show_cmd\r\n" "$show_cmd: show default"
+	# This odd expected output here is because we expect GDB to
+	# emit a single blank line as a result of this command.
+	gdb_test "$show_cmd" "^" "$show_cmd: show default"
     } else {
 	gdb_test "$show_cmd" "/foo/bar" "$show_cmd: show default"
     }
@@ -570,8 +572,9 @@ proc test-string {variant} {
 	    show_setting "$show_cmd" "\"hello world\""
 	} else {
 	    gdb_test_no_output "$set_cmd"
-	    gdb_test "$show_cmd" \
-		"^$show_cmd\r\n" "$show_cmd: empty second time"
+	    # This odd expected output here is because we expect GDB to
+	    # emit a single blank line as a result of this command.
+	    gdb_test "$show_cmd" "^" "$show_cmd: empty second time"
 	}
     }
 
diff --git a/gdb/testsuite/gdb.base/signals.exp b/gdb/testsuite/gdb.base/signals.exp
index 338cf4b298c..de613a25f49 100644
--- a/gdb/testsuite/gdb.base/signals.exp
+++ b/gdb/testsuite/gdb.base/signals.exp
@@ -88,7 +88,7 @@ if {[runto_main]} {
 
     # ...call the function
 
-    gdb_test "p func1 ()" "^p func1 \\(\\)\r\n.\[0-9\]* = void" \
+    gdb_test "p func1 ()" "^\\\$$decimal = void" \
 	"p func1 () #1"
 
     # ...veryfiy that the cout was updated
diff --git a/gdb/testsuite/gdb.base/with.exp b/gdb/testsuite/gdb.base/with.exp
index 233dc30d509..ebe84c05992 100644
--- a/gdb/testsuite/gdb.base/with.exp
+++ b/gdb/testsuite/gdb.base/with.exp
@@ -54,14 +54,17 @@ proc test_with_error {setting tmp_val expected_re} {
     global gdb_prompt
 
     with_test_prefix "$setting, $tmp_val" {
-	set test "save org value"
 	set org_val ""
-	gdb_test_multiple "maint show test-settings $setting" $test {
-	    -re "(.*)\r\n$gdb_prompt $" {
-		set org_val $expect_out(1,string)
-		pass $test
+	gdb_test_multiple "maint show test-settings $setting" \
+	    "save org value" {
+		-re "^maint show test-settings $setting\r\n" {
+		    exp_continue
+		}
+		-re "^(.*)\r\n$gdb_prompt $" {
+		    set org_val $expect_out(1,string)
+		    pass $gdb_test_name
+		}
 	    }
-	}
 
 	gdb_test \
 	    "maint with test-settings $setting $tmp_val -- p 1" \
diff --git a/gdb/testsuite/gdb.linespec/break-ask.exp b/gdb/testsuite/gdb.linespec/break-ask.exp
index 8de8a958022..251f7dd76ba 100644
--- a/gdb/testsuite/gdb.linespec/break-ask.exp
+++ b/gdb/testsuite/gdb.linespec/break-ask.exp
@@ -68,7 +68,7 @@ gdb_test_multiple $cmd $test {
 	pass $test
     }
 }
-gdb_test "2" "^2\r\nBreakpoint \[0-9\]+ at 0x\[0-9a-f\]+: file thefile\\.cc, line \[0-9a-f\]+\\."
+gdb_test "2" "^Breakpoint \[0-9\]+ at 0x\[0-9a-f\]+: file thefile\\.cc, line \[0-9a-f\]+\\."
 
 gdb_breakpoint "body_elsewhere"
 
@@ -88,7 +88,7 @@ gdb_test_multiple $cmd $test {
 	pass $test
     }
 }
-gdb_test "3" "^3\r\nBreakpoint \[0-9\]+ at 0x\[0-9a-f\]+: file thefile\\.cc, line \[0-9a-f\]+\\."
+gdb_test "3" "^Breakpoint \[0-9\]+ at 0x\[0-9a-f\]+: file thefile\\.cc, line \[0-9a-f\]+\\."
 
 gdb_breakpoint "body_elsewhere"
 
diff --git a/gdb/testsuite/gdb.mi/user-selected-context-sync.exp b/gdb/testsuite/gdb.mi/user-selected-context-sync.exp
index 9bcc90f06b4..4889c31aff3 100644
--- a/gdb/testsuite/gdb.mi/user-selected-context-sync.exp
+++ b/gdb/testsuite/gdb.mi/user-selected-context-sync.exp
@@ -500,7 +500,7 @@ proc ensure_no_output { test } {
     if { $gdb_spawn_id == $gdb_main_spawn_id } {
 	# CLI
 	gdb_test "print 666" \
-		 "^print 666\r\n\\\$$decimal = 666" \
+		 "^\\\$$decimal = 666" \
 		 "$test, ensure no output CLI"
     } elseif { $gdb_spawn_id == $mi_spawn_id } {
 	# MI
diff --git a/gdb/testsuite/gdb.python/py-framefilter.exp b/gdb/testsuite/gdb.python/py-framefilter.exp
index 6897518a20e..f02fc861225 100644
--- a/gdb/testsuite/gdb.python/py-framefilter.exp
+++ b/gdb/testsuite/gdb.python/py-framefilter.exp
@@ -97,7 +97,7 @@ foreach bttype [list "bt" "bt full"] {
 	    pass $test
 	}
     }
-    gdb_test "q" "^q\r\nQuit" "pagination quit - $bttype - q"
+    gdb_test "q" "^Quit" "pagination quit - $bttype - q"
 }
 gdb_test_no_output "set height unlimited" "pagination quit - set height unlimited"
 
diff --git a/gdb/testsuite/gdb.python/python.exp b/gdb/testsuite/gdb.python/python.exp
index 8fe119fead1..7e9ddaa6fcd 100644
--- a/gdb/testsuite/gdb.python/python.exp
+++ b/gdb/testsuite/gdb.python/python.exp
@@ -69,7 +69,7 @@ with_test_prefix "python interactive help" {
 
 	    # The "quit" must be seen on the output.  A buggy GDB
 	    # would not display it.
-	    gdb_test "quit" "^quit.*leaving help.*" "quit help"
+	    gdb_test "quit" "^\r\nYou are now leaving help.*" "quit help"
 	}
     }
 }
diff --git a/gdb/testsuite/lib/gdb.exp b/gdb/testsuite/lib/gdb.exp
index d3245ec3b43..b4746651c15 100644
--- a/gdb/testsuite/lib/gdb.exp
+++ b/gdb/testsuite/lib/gdb.exp
@@ -1400,10 +1400,12 @@ proc gdb_test_multiline { name args } {
 #
 # COMMAND is the command to execute, send to GDB with send_gdb.  If
 #   this is the null string no command is sent.
-# PATTERN is the pattern to match for a PASS, and must NOT include
-#   the \r\n sequence immediately before the gdb prompt.  This argument
-#   may be omitted to just match the prompt, ignoring whatever output 
-#   precedes it.
+# PATTERN is the pattern to match for a PASS, and must NOT include the
+#   \r\n sequence immediately before the gdb prompt (see -nonl below).
+#   This argument may be omitted to just match the prompt, ignoring
+#   whatever output precedes it.  If PATTERN starts with '^' then
+#   PATTERN will be anchored such that it should match all output from
+#   COMMAND.
 # MESSAGE is an optional message to be printed.  If this is
 #   omitted, then the pass/fail messages use the command string as the
 #   message.  (If this is the empty string, then sometimes we don't
@@ -1457,6 +1459,18 @@ proc gdb_test { args } {
 
     set saw_question 0
 
+    # If the pattern starts with a '^' then we want to match all the
+    # output from COMMAND.  To support this, here we inject an
+    # additional pattern that matches the command immediately after
+    # the '^'.
+    if {[string range $pattern 0 0] eq "^"} {
+	set command_regex [string_to_regexp $command]
+	set pattern [string range $pattern 1 end]
+	if {$command_regex ne ""} {
+	    set pattern "^${command_regex}\r\n$pattern"
+	}
+    }
+
     set user_code {}
     lappend user_code {
 	-re "(?:$pattern)$nl$prompt" {
