[02/16] gdb.base/setshow.exp: use save_vars to save/restore gdb_prompt

Message ID 20210714045520.1623120-3-simon.marchi@polymtl.ca
State New
Headers show
Series
  • Bunch of commands related cleanups
Related show

Commit Message

Simon Marchi via Gdb-patches July 14, 2021, 4:55 a.m.
Using save_vars is a bit better than what we have now, as it ensures the
variable gets restored if the code within it throws an error.

Change-Id: I3bd6836e5b7efb61b078acadff1a1c8182c19a27
---
 gdb/testsuite/gdb.base/setshow.exp | 33 +++++++++++++++---------------
 1 file changed, 16 insertions(+), 17 deletions(-)

-- 
2.32.0

Patch

diff --git a/gdb/testsuite/gdb.base/setshow.exp b/gdb/testsuite/gdb.base/setshow.exp
index 5404b5239671..7b273b3902a5 100644
--- a/gdb/testsuite/gdb.base/setshow.exp
+++ b/gdb/testsuite/gdb.base/setshow.exp
@@ -48,31 +48,30 @@  gdb_test "show annotate" "Annotation_level is 0..*"  "default annotation_level i
 #test set annotate 2
 
 # Here we need to fiddle with prompts.
-set old_gdb_prompt $gdb_prompt
-set gdb_prompt "\r\n\032\032pre-prompt\r\n$gdb_prompt \r\n\032\032prompt\r\n"
+save_vars { gdb_prompt } {
+    set old_gdb_prompt $gdb_prompt
+    set gdb_prompt "\r\n\032\032pre-prompt\r\n$gdb_prompt \r\n\032\032prompt\r\n"
 
-gdb_test_multiple "set annotate 2" "set annotate 2" {
-    -re "\r\n$gdb_prompt$" {
-	pass "set annotate 2"
+    gdb_test_multiple "set annotate 2" "set annotate 2" {
+	-re "\r\n$gdb_prompt$" {
+	    pass "set annotate 2"
+	}
     }
-}
 
-gdb_test_multiple "show annotate" "show annotate 2" {
-    -re ".*\032\032post-prompt.*Annotation_level is 2..*\032\032pre-prompt.*$old_gdb_prompt .*\032\032prompt.*$" {
-	pass "show annotate 2"
+    gdb_test_multiple "show annotate" "show annotate 2" {
+	-re ".*\032\032post-prompt.*Annotation_level is 2..*\032\032pre-prompt.*$old_gdb_prompt .*\032\032prompt.*$" {
+	    pass "show annotate 2"
+	}
     }
-}
 
-#test annotation_level 2
-gdb_test_multiple "info line 1" "annotation_level 2" {
-    -re ".*\032\032post-prompt.*Line 1 of .* is at address .* but contains no code.*:1:0:beg:0x.*\032\032pre-prompt.*$old_gdb_prompt .*\032\032prompt.*$" {
-	pass "annotation_level 2" 
+    #test annotation_level 2
+    gdb_test_multiple "info line 1" "annotation_level 2" {
+	-re ".*\032\032post-prompt.*Line 1 of .* is at address .* but contains no code.*:1:0:beg:0x.*\032\032pre-prompt.*$old_gdb_prompt .*\032\032prompt.*$" {
+	    pass "annotation_level 2"
+	}
     }
 }
 
-# Restore the original prompt for the rest of the testsuite.
-set gdb_prompt $old_gdb_prompt
-
 #test set annotate 1
 gdb_test "set annotate 1" ".*post-prompt.*"
 gdb_test "show annotate" "Annotation_level is 1..*"  "show annotate (1)"