gdb/
[binutils-gdb.git] / gdb / testsuite / gdb.mi / mi-nonstop.exp
1 # Copyright 2002, 2003, 2004, 2005, 2007, 2008 Free Software Foundation, Inc.
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 # This only works with native configurations
17 if {![isnative]} {
18 return
19 }
20
21 load_lib mi-support.exp
22 set MIFLAGS "-i=mi"
23
24 gdb_exit
25 if {[mi_gdb_start]} {
26 continue
27 }
28
29 #
30 # Start here
31 #
32 set testfile "non-stop"
33 set srcfile "$testfile.c"
34 set binfile "$objdir/$subdir/mi-$testfile"
35
36 set options [list debug incdir=$objdir]
37 if {[gdb_compile_pthreads "$srcdir/$subdir/$srcfile" $binfile executable $options] != "" } {
38 return -1
39 }
40
41 mi_gdb_reinitialize_dir $srcdir/$subdir
42 mi_gdb_load $binfile
43
44 set supported 0
45 send_gdb "-gdb-show non-stop\n"
46 gdb_expect {
47 -re ".*\\^done,value=\"off\",supported=\"(\[^\"\]+)\"\r\n$mi_gdb_prompt$" {
48 if { $expect_out(1,string) == "1" } {
49 set supported 1
50 }
51 }
52 -re ".$mi_gdb_prompt$" {
53 }
54 }
55
56 mi_gdb_test "-gdb-set non-stop 1" ".*"
57 mi_gdb_test "-gdb-set target-async 1" ".*"
58 detect_async
59
60 mi_gdb_test "200-break-insert -t main" ".*"
61
62 set created "=thread-created,id=\"$decimal\"\r\n"
63 set running "\\*running,thread-id=\"$decimal\"\r\n"
64
65 set notifs "($created)*($running)*"
66
67 # Note: presently, we skip this test on non-native targets,
68 # so 'run' is OK. As soon as we start to run this on remote
69 # target, the logic from mi_run_cmd will have to be refactored.
70 send_gdb "-exec-run\n"
71 gdb_expect {
72 -re "\\^running\r\n$notifs$mi_gdb_prompt" {
73 }
74 -re "\\^error,msg=\"The target does not support running in non-stop mode.\"" {
75 verbose -log "Non-stop mode not supported, skipping all tests"
76 return
77 }
78 -re "\r\n$mi_gdb_prompt" {
79 perror "Cannot start target (unknown output after running)"
80 return -1
81 }
82 timeout {
83 perror "Cannot start target (timeout)"
84 return -1
85 }
86 }
87 mi_expect_stop "breakpoint-hit" main ".*" ".*" "\[0-9\]+" { "" "disp=\"del\"" } "run to main"
88
89 mi_create_breakpoint break_at_me 2 keep break_at_me .* .* .* "breakpoint at marker"
90
91 mi_send_resuming_command "exec-continue" "resume 1"
92 mi_expect_stop "breakpoint-hit" "break_at_me" ".*" "non-stop.c" ".*" {"" "disp=\"keep\""} "w0,i0 stop"
93 mi_expect_stop "breakpoint-hit" "break_at_me" ".*" "non-stop.c" ".*" {"" "disp=\"keep\""} "w1,i0 stop"
94
95 mi_check_thread_states {"running" "stopped" "stopped"} "thread state, stop 1"
96
97 mi_gdb_test "-thread-select 2" "\\^done.*" "select thread 2"
98 mi_create_varobj I_W0 "i" "create varobj in first thread"
99 mi_gdb_test "-thread-select 3" "\\^done.*" "select thread 3"
100 mi_create_varobj I_W1 "i" "create varobj in second thread"
101
102 mi_send_resuming_command "exec-continue --thread 2" "resume 1"
103 mi_check_thread_states {"running" "running" "stopped"} "thread state, resume 1"
104 mi_expect_stop "breakpoint-hit" "break_at_me" ".*" "non-stop.c" ".*" {"" "disp=\"keep\""} "w0,i1 stop"
105 mi_check_thread_states {"running" "stopped" "stopped"} "thread state, stop 2"
106
107 mi_send_resuming_command "exec-continue --thread 3" "resume 2"
108 mi_check_thread_states {"running" "stopped" "running"} "thread state, resume 2"
109 mi_expect_stop "breakpoint-hit" "break_at_me" ".*" "non-stop.c" ".*" {"" "disp=\"keep\""} "w1,i1 stop"
110 mi_check_thread_states {"running" "stopped" "stopped"} "thread state, stop 3"
111
112 mi_varobj_update * {I_W1 I_W0} "update varobj, 1"
113 mi_check_varobj_value I_W0 1 "check varobj, w0, 1"
114 mi_check_varobj_value I_W1 1 "check varobj, w1, 1"
115
116 send_gdb "-exec-interrupt --thread 1\n"
117 gdb_expect {
118 -re "\\^done\r\n$mi_gdb_prompt\\*stopped\[^\r\n\]+\r\n$" {
119 pass "interrupted"
120 }
121 timeout {
122 fail "interrupted (timeout)"
123 }
124 }
125 # The interrupt command sends SIGINT to the target, and therefore the
126 # thread might not be stopped immediately when we return from the target.
127 # So, wait a bit
128 sleep 1
129 mi_check_thread_states {"stopped" "stopped" "stopped"} "thread state, stop 4"
130
131 send_gdb "-exec-continue --all\n"
132 gdb_expect {
133 -re ".*\\*running,thread-id=\"3\"\r\n\\*running,thread-id=\"2\"\r\n\\*running,thread-id=\"1\"\r\n$mi_gdb_prompt" {
134 pass "resume all"
135 }
136 timeout {
137 fail "resume all (timeout)"
138 }
139 }
140
141 mi_expect_stop "breakpoint-hit" "break_at_me" "\[^\n\]*" "non-stop.c" "\[0-9\]*" {"" "disp=\"keep\""} "w0,i2 stop"
142 mi_expect_stop "breakpoint-hit" "break_at_me" ".*" "non-stop.c" ".*" {"" "disp=\"keep\""} "w1,i2 stop"
143
144 # At this point, thread 1 (main) is running, and worker threads are stopped.
145 # Check that we can modify breakpoint condition, even when operating on a
146 # running thread.
147 mi_gdb_test "-break-condition --thread 1 2 id==1" "\\^done" "set condition, 1"
148
149 mi_send_resuming_command "exec-continue --thread 2" "resume 2"
150 mi_send_resuming_command "exec-continue --thread 3" "resume 3"
151
152 sleep 2
153 mi_expect_stop "breakpoint-hit" "break_at_me" ".*" "non-stop.c" ".*" {"" "disp=\"keep\""} "w0,i3 stop"
154 mi_check_thread_states {"running" "running" "stopped"} "thread state, stop on cond breakpoint"
155
156 # Check that when we update all varobj, we don't get no error about varobj
157 # bound to running thread.
158 mi_varobj_update * {I_W1} "update varobj, 2"
159 mi_check_varobj_value I_W1 3 "check varobj, w1, 1"
160
161
162 # Check that stack commands are allowed on a stopped thread, even if some other threads
163 # are running, and produce something sane. Also check we check error on running thread.
164 mi_gdb_test "-stack-list-frames --thread 2" "\\^error,msg=\".*\"" "stacktrace of running thread"
165 mi_gdb_test "-stack-list-frames --thread 3" \
166 "\\^done,stack=\\\[frame={level=\"0\",addr=\".*\",func=\"break_at_me\".*" \
167 "stacktrace of stopped thread"
168
169 # verify that after thread exit, the thread is reported as exited in -thread-info, and
170 # we can still interact with other threads.
171 mi_gdb_test "-thread-select 2" "\\^done.*" "select first worker thread"
172 # Since thread 2 is running, we need to set variable via another thread.
173 mi_gdb_test "-gdb-set --thread 3 variable exit_first_thread=1" ".*\\^done" "ask the second thread to exit"
174 gdb_expect {
175 -re ".*=thread-exited,id=\"2\"\r\n$" {
176 pass "wait for thread exit"
177 }
178 timeout {
179 fail "wait for thread exit (timeout)"
180 }
181 }
182
183 # See that we can still poke other threads.
184 mi_gdb_test "-stack-list-frames --thread 3" \
185 "\\^done,stack=\\\[frame={level=\"0\",addr=\".*\",func=\"break_at_me\".*" \
186 "stacktrace of stopped thread"
187
188
189 mi_gdb_exit
190