gdb/testsuite: introduce is_target_non_stop helper proc
authorAndrew Burgess <aburgess@redhat.com>
Sat, 18 Feb 2023 20:52:40 +0000 (20:52 +0000)
committerAndrew Burgess <aburgess@redhat.com>
Tue, 28 Feb 2023 10:56:28 +0000 (10:56 +0000)
I noticed that several tests included copy & pasted code to run the
'maint show target-non-stop' command, and then switch based on the
result.

In this commit I factor this code out into a helper proc in
lib/gdb.exp, and update all the places I could find that used this
pattern to make use of the helper proc.

There should be no change in what is tested after this commit.

Reviewed-By: Pedro Alves <pedro@palves.net>
gdb/testsuite/gdb.base/access-mem-running.exp
gdb/testsuite/gdb.base/fork-running-state.exp
gdb/testsuite/gdb.threads/access-mem-running-thread-exit.exp
gdb/testsuite/gdb.threads/clone-attach-detach.exp
gdb/testsuite/gdb.threads/detach-step-over.exp
gdb/testsuite/lib/gdb.exp

index 90ddedc470d6de8725c130aef2fb9f01c61ace81..d0f7871fc0f6f2636243e76babf316bba682960b 100644 (file)
@@ -46,13 +46,9 @@ proc test { non_stop } {
        && ([target_info gdb_protocol] == "remote"
            || [target_info gdb_protocol] == "extended-remote")} {
 
-       gdb_test_multiple "maint show target-non-stop" "" {
-           -wrap -re "(is|currently) on.*" {
-           }
-           -wrap -re "(is|currently) off.*" {
-               unsupported "can't issue commands while target is running"
-               return 0
-           }
+       if {![is_target_non_stop]} {
+           unsupported "can't issue commands while target is running"
+           return 0
        }
     }
 
index b8045ad490f94fb2c8afcffa5ab2020c507bba97..9a18193c4dc1b0eb89a964e2be6dd9cfc342f93f 100644 (file)
@@ -46,14 +46,9 @@ proc do_test { detach_on_fork follow_fork non_stop schedule_multiple } {
         && ([target_info gdb_protocol] == "remote"
             || [target_info gdb_protocol] == "extended-remote")} {
 
-       set test "maint show target-non-stop"
-       gdb_test_multiple "maint show target-non-stop" $test {
-           -re "(is|currently) on.*$gdb_prompt $" {
-           }
-           -re "(is|currently) off.*$gdb_prompt $" {
-               unsupported "can't issue info threads while target is running"
-               return 0
-           }
+       if {![is_target_non_stop]} {
+           unsupported "can't issue info threads while target is running"
+           return 0
        }
     }
 
index 09b05480c045def4b90753f0708103ab898bdd28..2d3ace44ccd5ec67a1be2eec4fb45f9601442d75 100644 (file)
@@ -65,13 +65,9 @@ proc test { non_stop } {
        && ([target_info gdb_protocol] == "remote"
            || [target_info gdb_protocol] == "extended-remote")} {
 
-       gdb_test_multiple "maint show target-non-stop" "" {
-           -wrap -re "(is|currently) on.*" {
-           }
-           -wrap -re "(is|currently) off.*" {
-               unsupported "can't issue commands while target is running"
-               return 0
-           }
+       if {![is_target_non_stop]} {
+           unsupported "can't issue commands while target is running"
+           return 0
        }
     }
 
index ac9b92d5f57db7bdb9ce6434648cd3356e49320f..a71713ea8ba3a11ceecdb1a3ced30d2d2df2c5ee 100644 (file)
@@ -64,14 +64,9 @@ if {[target_info exists gdb_protocol]
     && ([target_info gdb_protocol] == "remote"
        || [target_info gdb_protocol] == "extended-remote")} {
 
-    set test "maint show target-non-stop"
-    gdb_test_multiple "maint show target-non-stop" $test {
-       -re "(is|currently) on.*$gdb_prompt $" {
-       }
-       -re "(is|currently) off.*$gdb_prompt $" {
-           unsupported "bg attach: can't issue info threads while target is running"
-           return 0
-       }
+    if {![is_target_non_stop]} {
+       unsupported "bg attach: can't issue info threads while target is running"
+       return 0
     }
 }
 
index ed9dc1aab88dcc99e21066941ba31e31a404c76a..bf5ef6b06a1b3a498e724e242f7e122359bb172b 100644 (file)
@@ -314,12 +314,8 @@ proc_with_prefix test_detach_quit {condition_eval target_non_stop \
        start_gdb_for_test $condition_eval $target_non_stop \
            $non_stop $displaced
 
-       gdb_test_multiple "maint show target-non-stop" "" {
-           -wrap -re "(is|currently) on.*" {
-           }
-           -wrap -re "(is|currently) off.*" {
-               return
-           }
+       if {![is_target_non_stop]} {
+           return
        }
     }
 
index 669a5f606d6a76cd3eb62889515a973099cdbbfd..19c782bea4600341f4fdccd98252ea048f306fa2 100644 (file)
@@ -9298,6 +9298,28 @@ proc gdb_step_until { regexp {test_name ""} {max_steps 10} } {
     }
 }
 
+# Return false if the current target is not operating in non-stop
+# mode, otherwise, return true.
+#
+# The inferior will need to have started running in order to get the
+# correct result.
+
+proc is_target_non_stop { {testname ""} } {
+    # For historical reasons we assume non-stop mode is on.  If the
+    # maintenance command fails for any reason then we're going to
+    # return true.
+    set is_non_stop true
+    gdb_test_multiple "maint show target-non-stop" $testname {
+       -wrap -re "(is|currently) on.*" {
+           set is_non_stop true
+       }
+       -wrap -re "(is|currently) off.*" {
+           set is_non_stop false
+       }
+    }
+    return $is_non_stop
+}
+
 # Check if the compiler emits epilogue information associated
 # with the closing brace or with the last statement line.
 #