Commit | Line | Data |
---|---|---|
88b9d363 | 1 | # Copyright 2021-2022 Free Software Foundation, Inc. |
1bdfa2b1 SM |
2 | |
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. | |
7 | # | |
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. | |
12 | # | |
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/>. | |
15 | ||
16 | # Test --exec-interrupt with thread-group. | |
17 | # | |
18 | # Run two inferiors, try interrupting them both with --exec-interrupt + | |
19 | # --thread-group. | |
20 | ||
21 | load_lib mi-support.exp | |
22 | set MIFLAGS "-i=mi" | |
23 | ||
24 | standard_testfile .c | |
25 | ||
26 | if {[gdb_compile_pthreads "$srcdir/$subdir/$srcfile" $binfile \ | |
27 | executable debug] != "" } { | |
28 | return -1 | |
29 | } | |
30 | ||
31 | save_vars { GDBFLAGS } { | |
32 | append GDBFLAGS " -ex \"set non-stop on\" -ex \"set mi-async\"" | |
33 | mi_clean_restart $binfile | |
34 | } | |
35 | ||
36 | mi_detect_async | |
37 | ||
38 | # Create breakpoint by hand instead of using mi_runto, since we'll need it for | |
39 | # both inferiors. | |
40 | mi_create_breakpoint "all_threads_started" \ | |
41 | "set breakpoint on all_threads_started" | |
42 | ||
43 | # Run first inferior to all_threads_started (to ensure all threads are started) | |
44 | # and resume it. | |
45 | if { [mi_run_cmd] < 0 } { | |
46 | return | |
47 | } | |
48 | ||
49 | mi_expect_stop "breakpoint-hit" "all_threads_started" ".*" ".*" ".*" {"" "disp=\"keep\""} \ | |
50 | "inferior i1 stops at all_threads_started" | |
51 | ||
52 | mi_send_resuming_command "exec-continue --thread-group i1" \ | |
53 | "continue inferior 1" | |
54 | ||
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]}] | |
58 | ||
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" \ | |
66 | "\\^done" \ | |
67 | "add inferior 2" | |
68 | } else { | |
69 | mi_gdb_test "-add-inferior" \ | |
70 | "\\^done,inferior=\"i2\"" \ | |
71 | "add inferior 2" | |
72 | } | |
73 | mi_gdb_test "-file-exec-and-symbols --thread-group i2 $::binfile" \ | |
74 | "\\^done" \ | |
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" \ | |
79 | "\\^running.*" \ | |
80 | "run inferior 2" | |
81 | ||
82 | mi_expect_stop "breakpoint-hit" "all_threads_started" ".*" ".*" ".*" {"" "disp=\"keep\""} \ | |
83 | "inferior i2 stops at all_threads_started" | |
84 | ||
85 | mi_send_resuming_command "exec-continue --thread-group i2" \ | |
86 | "continue inferior 2" | |
87 | ||
88 | mi_check_thread_states { | |
89 | "running" "running" "running" "running" "running" | |
90 | "running" "running" "running" "running" "running" | |
91 | } "before interrupting" | |
92 | } else { | |
93 | mi_check_thread_states { | |
94 | "running" "running" "running" "running" "running" | |
95 | } "before interrupting" | |
96 | } | |
97 | ||
98 | # Interrupt inferior 1, wait for events. | |
99 | mi_gdb_test "-exec-interrupt --thread-group i1" \ | |
100 | "\\^done" \ | |
101 | "interrupt inferior 1" | |
102 | ||
103 | for {set i 0} {$i < 5} {incr i} { | |
104 | mi_expect_interrupt "inferior 1, interrupt $i" | |
105 | } | |
106 | ||
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" | |
112 | ||
113 | # Interrupt inferior 2, wait for events. | |
114 | mi_gdb_test "-exec-interrupt --thread-group i2" \ | |
115 | "\\^done" \ | |
116 | "interrupt inferior 2" | |
117 | ||
118 | for {set i 0} {$i < 5} {incr i} { | |
119 | mi_expect_interrupt "inferior 2, interrupt $i" | |
120 | } | |
121 | ||
122 | mi_check_thread_states { | |
123 | "stopped" "stopped" "stopped" "stopped" "stopped" | |
124 | "stopped" "stopped" "stopped" "stopped" "stopped" | |
125 | } "after interrupting inferior 2" | |
126 | } else { | |
127 | mi_check_thread_states { | |
128 | "stopped" "stopped" "stopped" "stopped" "stopped" | |
129 | } "after interrupting inferior 1" | |
130 | } |