1 # Copyright 2021-2024 Free Software Foundation, Inc.
3 # This program is free software; you can redistribute it and/or modify
4 # it under the terms of the GNU General Public License as published by
5 # the Free Software Foundation; either version 3 of the License, or
6 # (at your option) any later version.
8 # This program is distributed in the hope that it will be useful,
9 # but WITHOUT ANY WARRANTY; without even the implied warranty of
10 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 # GNU General Public License for more details.
13 # You should have received a copy of the GNU General Public License
14 # along with this program. If not, see <http://www.gnu.org/licenses/>.
16 # Test --exec-interrupt with thread-group.
18 # Run two inferiors, try interrupting them both with --exec-interrupt +
21 load_lib mi-support.exp
26 if {[gdb_compile_pthreads "$srcdir/$subdir/$srcfile" $binfile \
27 executable {debug additional_flags=-std=gnu99}] != "" } {
31 save_vars { GDBFLAGS } {
32 append GDBFLAGS " -ex \"set non-stop on\" -ex \"set mi-async\""
33 mi_clean_restart $binfile
38 # Create breakpoint by hand instead of using mi_runto, since we'll need it for
40 mi_create_breakpoint "all_threads_started" \
41 "set breakpoint on all_threads_started"
43 # Run first inferior to all_threads_started (to ensure all threads are started)
45 if { [mi_run_cmd] < 0 } {
49 mi_expect_stop "breakpoint-hit" "all_threads_started" ".*" ".*" ".*" {"" "disp=\"keep\""} \
50 "inferior i1 stops at all_threads_started"
52 mi_send_resuming_command "exec-continue --thread-group i1" \
55 # We can't run a second inferior on stub targets. We can still test with one
56 # inferior and ensure that the command has the desired effect.
57 set use_second_inferior [expr {![use_gdb_stub]}]
59 if { $use_second_inferior } {
60 mi_gdb_test "-add-inferior" \
61 "\\^done,inferior=\"i2\",connection=\\{\[^\}\]+\\}" \
63 mi_gdb_test "-file-exec-and-symbols --thread-group i2 $::binfile" \
65 "set executable of inferior 2"
66 # Run second inferior to all_threads_started (to ensure all threads are
67 # started) and resume it.
68 mi_gdb_test "-exec-run --thread-group i2" \
72 mi_expect_stop "breakpoint-hit" "all_threads_started" ".*" ".*" ".*" {"" "disp=\"keep\"" "locno=\"[0-9]+\""} \
73 "inferior i2 stops at all_threads_started"
75 mi_send_resuming_command "exec-continue --thread-group i2" \
78 mi_check_thread_states {
79 "running" "running" "running" "running" "running"
80 "running" "running" "running" "running" "running"
81 } "before interrupting"
83 mi_check_thread_states {
84 "running" "running" "running" "running" "running"
85 } "before interrupting"
88 # Interrupt inferior 1, wait for events.
89 mi_gdb_test "-exec-interrupt --thread-group i1" \
91 "interrupt inferior 1"
93 for {set i 0} {$i < 5} {incr i} {
94 mi_expect_interrupt "inferior 1, interrupt $i"
97 if { $use_second_inferior } {
98 mi_check_thread_states {
99 "stopped" "stopped" "stopped" "stopped" "stopped"
100 "running" "running" "running" "running" "running"
101 } "after interrupting inferior 1"
103 # Interrupt inferior 2, wait for events.
104 mi_gdb_test "-exec-interrupt --thread-group i2" \
106 "interrupt inferior 2"
108 for {set i 0} {$i < 5} {incr i} {
109 mi_expect_interrupt "inferior 2, interrupt $i"
112 mi_check_thread_states {
113 "stopped" "stopped" "stopped" "stopped" "stopped"
114 "stopped" "stopped" "stopped" "stopped" "stopped"
115 } "after interrupting inferior 2"
117 mi_check_thread_states {
118 "stopped" "stopped" "stopped" "stopped" "stopped"
119 } "after interrupting inferior 1"