gdb/
[deliverable/binutils-gdb.git] / gdb / testsuite / gdb.mi / mi-nonstop.exp
CommitLineData
8cf6e61a
VP
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
17if {![isnative]} {
18 return
19}
20
21load_lib mi-support.exp
22set MIFLAGS "-i=mi"
23
24gdb_exit
25if {[mi_gdb_start]} {
26 continue
27}
28
8cf6e61a
VP
29#
30# Start here
31#
32set testfile "non-stop"
33set srcfile "$testfile.c"
34set binfile "$objdir/$subdir/mi-$testfile"
35
36set options [list debug incdir=$objdir]
37if {[gdb_compile_pthreads "$srcdir/$subdir/$srcfile" $binfile executable $options] != "" } {
38 return -1
39}
40
41mi_gdb_reinitialize_dir $srcdir/$subdir
42mi_gdb_load $binfile
43
44set supported 0
45send_gdb "-gdb-show non-stop\n"
46gdb_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
8cf6e61a
VP
56mi_gdb_test "-gdb-set non-stop 1" ".*"
57mi_gdb_test "-gdb-set target-async 1" ".*"
58detect_async
59
80f73d71 60mi_gdb_test "200-break-insert -t main" ".*"
1ad15515
PA
61
62set created "=thread-created,id=\"$decimal\"\r\n"
63set running "\\*running,thread-id=\"$decimal\"\r\n"
64
65set notifs "($created)*($running)*"
66
80f73d71
VP
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.
70send_gdb "-exec-run\n"
71gdb_expect {
1ad15515 72 -re "\\^running\r\n$notifs$mi_gdb_prompt" {
80f73d71
VP
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 }
1ad15515 78 -re "\r\n$mi_gdb_prompt" {
80f73d71
VP
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}
87mi_expect_stop "breakpoint-hit" main ".*" ".*" "\[0-9\]+" { "" "disp=\"del\"" } "run to main"
8cf6e61a
VP
88
89mi_create_breakpoint break_at_me 2 keep break_at_me .* .* .* "breakpoint at marker"
90
91mi_send_resuming_command "exec-continue" "resume 1"
92mi_expect_stop "breakpoint-hit" "break_at_me" ".*" "non-stop.c" ".*" {"" "disp=\"keep\""} "w0,i0 stop"
93mi_expect_stop "breakpoint-hit" "break_at_me" ".*" "non-stop.c" ".*" {"" "disp=\"keep\""} "w1,i0 stop"
94
1ad15515 95mi_check_thread_states {"running" "stopped" "stopped"} "thread state, stop 1"
8cf6e61a
VP
96
97mi_gdb_test "-thread-select 2" "\\^done.*" "select thread 2"
98mi_create_varobj I_W0 "i" "create varobj in first thread"
99mi_gdb_test "-thread-select 3" "\\^done.*" "select thread 3"
100mi_create_varobj I_W1 "i" "create varobj in second thread"
101
102mi_send_resuming_command "exec-continue --thread 2" "resume 1"
1ad15515 103mi_check_thread_states {"running" "running" "stopped"} "thread state, resume 1"
8cf6e61a 104mi_expect_stop "breakpoint-hit" "break_at_me" ".*" "non-stop.c" ".*" {"" "disp=\"keep\""} "w0,i1 stop"
1ad15515 105mi_check_thread_states {"running" "stopped" "stopped"} "thread state, stop 2"
8cf6e61a
VP
106
107mi_send_resuming_command "exec-continue --thread 3" "resume 2"
1ad15515 108mi_check_thread_states {"running" "stopped" "running"} "thread state, resume 2"
8cf6e61a 109mi_expect_stop "breakpoint-hit" "break_at_me" ".*" "non-stop.c" ".*" {"" "disp=\"keep\""} "w1,i1 stop"
1ad15515 110mi_check_thread_states {"running" "stopped" "stopped"} "thread state, stop 3"
8cf6e61a
VP
111
112mi_varobj_update * {I_W1 I_W0} "update varobj, 1"
113mi_check_varobj_value I_W0 1 "check varobj, w0, 1"
114mi_check_varobj_value I_W1 1 "check varobj, w1, 1"
115
116send_gdb "-exec-interrupt --thread 1\n"
117gdb_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
128sleep 1
1ad15515 129mi_check_thread_states {"stopped" "stopped" "stopped"} "thread state, stop 4"
8cf6e61a 130
8cf6e61a
VP
131send_gdb "-exec-continue --all\n"
132gdb_expect {
80f73d71 133 -re ".*\\*running,thread-id=\"3\"\r\n\\*running,thread-id=\"2\"\r\n\\*running,thread-id=\"1\"\r\n$mi_gdb_prompt" {
8cf6e61a
VP
134 pass "resume all"
135 }
136 timeout {
137 fail "resume all (timeout)"
138 }
139}
140
d0b76dc6 141mi_expect_stop "breakpoint-hit" "break_at_me" "\[^\n\]*" "non-stop.c" "\[0-9\]*" {"" "disp=\"keep\""} "w0,i2 stop"
8cf6e61a
VP
142mi_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.
147mi_gdb_test "-break-condition --thread 1 2 id==1" "\\^done" "set condition, 1"
148
149mi_send_resuming_command "exec-continue --thread 2" "resume 2"
150mi_send_resuming_command "exec-continue --thread 3" "resume 3"
151
152sleep 2
153mi_expect_stop "breakpoint-hit" "break_at_me" ".*" "non-stop.c" ".*" {"" "disp=\"keep\""} "w0,i3 stop"
1ad15515 154mi_check_thread_states {"running" "running" "stopped"} "thread state, stop on cond breakpoint"
8cf6e61a
VP
155
156# Check that when we update all varobj, we don't get no error about varobj
157# bound to running thread.
158mi_varobj_update * {I_W1} "update varobj, 2"
159mi_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.
164mi_gdb_test "-stack-list-frames --thread 2" "\\^error,msg=\".*\"" "stacktrace of running thread"
165mi_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.
171mi_gdb_test "-thread-select 2" "\\^done.*" "select first worker thread"
172# Since thread 2 is running, we need to set variable via another thread.
173mi_gdb_test "-gdb-set --thread 3 variable exit_first_thread=1" ".*\\^done" "ask the second thread to exit"
174gdb_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.
184mi_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
189mi_gdb_exit
190
This page took 0.079554 seconds and 4 git commands to generate.