[gdb/testsuite] Fix unbalanced quotes in mi_expect_stop argument
authorTom de Vries <tdevries@suse.de>
Fri, 24 Mar 2023 09:45:37 +0000 (10:45 +0100)
committerTom de Vries <tdevries@suse.de>
Fri, 24 Mar 2023 09:45:37 +0000 (10:45 +0100)
In proc mi_expect_stop there's a proc argument reason that's handled like so:
...
set r "reason=\"$reason\","
...

That's fine for say:
...
set reason "foo"
...
for which this evaluates to:
...
set r "reason=\"foo\","
...

But there are more complex uses, for instance:
...
set reason "breakpoint-hit\",disp=\"keep\",bkptno=\"$decimal"
...
which evaluates to:
...
set r "\"breakpoint-hit\",disp=\"keep\",bkptno=\"$decimal\""
...

Note how in this reason argument, the first two '\"' seems to form a pair
surrounding ',disp=', which is not the case, which is confusing.

Fix this by only adding the quotes in mi_expect_stop if the string doesn't
already contain quotes, such that we have the more readable:
...
set reason "\"breakpoint-hit\",disp=\"keep\",bkptno=\"$decimal\""
...

Tested on x86_64-linux.

gdb/testsuite/gdb.ada/mi_catch_assert.exp
gdb/testsuite/gdb.ada/mi_catch_ex.exp
gdb/testsuite/gdb.ada/mi_catch_ex_hand.exp
gdb/testsuite/gdb.ada/mi_ex_cond.exp
gdb/testsuite/lib/mi-support.exp

index e0d5439dc2659d3d391730d4699217fa708081b6..c3673fab8e8f6cefe32afd027c49374786d41c95 100644 (file)
@@ -79,7 +79,7 @@ mi_gdb_test "-catch-assert -c \"Global_Var = 2\"" \
 
 set bp_location [gdb_get_line_number "STOP" ${testdir}/bla.adb]
 mi_execute_to "exec-continue" \
-              "breakpoint-hit\",disp=\"keep\",bkptno=\"$decimal" \
+              "\"breakpoint-hit\",disp=\"keep\",bkptno=\"$decimal\"" \
               "bla" "" ".*" "$bp_location" \
               ".*" \
               "continue to assert failure catchpoint hit"
index 6a0f94a5f875a3d5764b1479952af0fca571cf7e..d0dfbd59764a9f8d6d6d20fbfa9d98bf7b3cef46 100644 (file)
@@ -92,7 +92,7 @@ proc continue_to_exception { exception_name exception_message test } {
 
     # Now MI stream output.
     mi_expect_stop \
-       "breakpoint-hit\",disp=\"keep\",bkptno=\"$any_nb\",exception-name=\"$exception_name\(\",exception-message=\"$exception_message\)?" \
+       "\"breakpoint-hit\",disp=\"keep\",bkptno=\"$any_nb\",exception-name=\"$exception_name\(\",exception-message=\"$exception_message\)?\"" \
        "foo" "" ".*" ".*" \
        ".*" \
        $test
@@ -140,19 +140,19 @@ mi_gdb_test "-catch-exception -u" \
             "catch unhandled exceptions"
 
 mi_execute_to "exec-continue" \
-              "breakpoint-hit\",disp=\"keep\",bkptno=\"$any_nb\",exception-name=\"PROGRAM_ERROR(\",exception-message=\"foo\\.adb:$decimal explicit raise)?" \
+              "\"breakpoint-hit\",disp=\"keep\",bkptno=\"$any_nb\",exception-name=\"PROGRAM_ERROR(\",exception-message=\"foo\\.adb:$decimal explicit raise)?\"" \
               "foo" "" ".*" ".*" \
               ".*" \
               "continue to exception catchpoint hit"
 
 mi_execute_to "exec-continue" \
-              "breakpoint-hit\",disp=\"keep\",bkptno=\"$any_nb" \
+              "\"breakpoint-hit\",disp=\"keep\",bkptno=\"$any_nb\"" \
               "foo" "" ".*" ".*" \
               ".*" \
               "continue to assert failure catchpoint hit"
 
 mi_execute_to "exec-continue" \
-              "breakpoint-hit\",disp=\"keep\",bkptno=\"$any_nb\",exception-name=\"CONSTRAINT_ERROR" \
+              "\"breakpoint-hit\",disp=\"keep\",bkptno=\"$any_nb\",exception-name=\"CONSTRAINT_ERROR\"" \
               "foo" "" ".*" ".*" \
               ".*" \
               "continue to unhandled exception catchpoint hit"
index 82c7b2a300abec81bf82cd97dacb05bea4876fdc..2cd175f098b72cb85ec887e4c0910ab1622b9a46 100644 (file)
@@ -82,7 +82,7 @@ proc continue_to_exception_handler { test line } {
 
     # Now MI stream output.
     mi_expect_stop \
-       "breakpoint-hit\",disp=\"keep\",bkptno=\"$decimal\",exception-name=\"exception\"?" \
+       "\"breakpoint-hit\",disp=\"keep\",bkptno=\"$decimal\",exception-name=\"exception\"" \
        "foo" "" ".*" "$line" \
        ".*" \
         $test
@@ -125,7 +125,7 @@ mi_gdb_test "-catch-handlers -e Constraint_Error" \
             "catch Constraint_Error"
 
 mi_execute_to "exec-continue" \
-              "breakpoint-hit\",disp=\"keep\",bkptno=\"$decimal\",exception-name=\"exception\"?" \
+              "\"breakpoint-hit\",disp=\"keep\",bkptno=\"$decimal\",exception-name=\"exception\"" \
               "foo" "" ".*" "$bp_ce_location" \
               ".*" \
               "continue to exception catchpoint hit"
index f41b633a8220f8dc628aae545dbc724aa856c67e..54aa6b54ee14b1bb7ba36f3f9c0d8a710e26a03f 100644 (file)
@@ -77,7 +77,7 @@ mi_gdb_test "-catch-exception -c \"i = 2\" -e constraint_error" \
 mi_run_cmd
 
 mi_expect_stop \
-    "breakpoint-hit\",disp=\"keep\",bkptno=\"$any_nb\",exception-name=\"CONSTRAINT_ERROR(\",exception-message=\"foo\\.adb:$decimal explicit raise)?" \
+    "\"breakpoint-hit\",disp=\"keep\",bkptno=\"$any_nb\",exception-name=\"CONSTRAINT_ERROR(\",exception-message=\"foo\\.adb:$decimal explicit raise)?\"" \
     "foo" "" ".*" ".*" \
     ".*" \
     "run to exception catchpoint hit"
index 3c2dd2fab2b4142c7236dbda31d5e8e117dd3a4b..c738b7be505afac665161d61d51f1f87ad81db42 100644 (file)
@@ -1267,7 +1267,11 @@ proc mi_expect_stop { reason func args file line extra test } {
 
     set r ""
     if { $reason != "" } {
-       set r "reason=\"$reason\","
+       if { [regexp {"} $reason] } {
+          set r "reason=$reason,"
+       } else {
+          set r "reason=\"$reason\","
+       }       
     }