1 # Copyright 2021 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] != "" } {
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 # The inferior created by the -add-inferior MI command does not inherit the
61 # target connection of the first inferior. If debugging through an
62 # extended-remote connection, that means we can't run that second inferior
63 # on the remote connection. Use the add-inferior CLI command as a stop-gap.
64 if { [mi_is_target_remote] } {
65 mi_gdb_test "add-inferior" \
69 mi_gdb_test "-add-inferior" \
70 "\\^done,inferior=\"i2\"" \
73 mi_gdb_test "-file-exec-and-symbols --thread-group i2 $::binfile" \
75 "set executable of inferior 2"
76 # Run second inferior to all_threads_started (to ensure all threads are
77 # started) and resume it.
78 mi_gdb_test "-exec-run --thread-group i2" \
82 mi_expect_stop "breakpoint-hit" "all_threads_started" ".*" ".*" ".*" {"" "disp=\"keep\""} \
83 "inferior i2 stops at all_threads_started"
85 mi_send_resuming_command "exec-continue --thread-group i2" \
88 mi_check_thread_states {
89 "running" "running" "running" "running" "running"
90 "running" "running" "running" "running" "running"
91 } "before interrupting"
93 mi_check_thread_states {
94 "running" "running" "running" "running" "running"
95 } "before interrupting"
98 # Interrupt inferior 1, wait for events.
99 mi_gdb_test "-exec-interrupt --thread-group i1" \
101 "interrupt inferior 1"
103 for {set i 0} {$i < 5} {incr i} {
104 mi_expect_interrupt "inferior 1, interrupt $i"
107 if { $use_second_inferior } {
108 mi_check_thread_states {
109 "stopped" "stopped" "stopped" "stopped" "stopped"
110 "running" "running" "running" "running" "running"
111 } "after interrupting inferior 1"
113 # Interrupt inferior 2, wait for events.
114 mi_gdb_test "-exec-interrupt --thread-group i2" \
116 "interrupt inferior 2"
118 for {set i 0} {$i < 5} {incr i} {
119 mi_expect_interrupt "inferior 2, interrupt $i"
122 mi_check_thread_states {
123 "stopped" "stopped" "stopped" "stopped" "stopped"
124 "stopped" "stopped" "stopped" "stopped" "stopped"
125 } "after interrupting inferior 2"
127 mi_check_thread_states {
128 "stopped" "stopped" "stopped" "stopped" "stopped"
129 } "after interrupting inferior 1"