Update the copyright notice of some of the files I missed
[deliverable/binutils-gdb.git] / gdb / testsuite / gdb.mi / mi-nsmoribund.exp
1 # Copyright 2008, 2009 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 "nsmoribund"
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\]+" \
88 { "" "disp=\"del\"" } "run to main"
89
90 # Keep this in sync with THREADS in the the $srcfile.
91 set nthreads 10
92
93 # Set a breakpoint and let all threads hit it (except the main
94 # thread).
95
96 set bkpt_line [gdb_get_line_number "set breakpoint here"]
97
98 mi_create_breakpoint "$srcfile:$bkpt_line" 2 keep thread_function .* .* .* \
99 "breakpoint at thread_function"
100
101 mi_send_resuming_command "exec-continue --all" "resume all"
102 for {set i 0} {$i < $nthreads} {incr i} {
103 mi_expect_stop "breakpoint-hit" "thread_function" "\[^\n\]*" "$srcfile" \
104 "\[0-9\]*" {"" "disp=\"keep\""} "stop $i"
105 }
106
107 # All but the main thread should have hit it.
108
109 mi_check_thread_states \
110 {"running" "stopped" "stopped" "stopped" "stopped" "stopped" "stopped" "stopped" "stopped" "stopped" "stopped"} \
111 "thread state: all stopped except the main thread"
112
113 # Select a stopped thread to make sure we're able to delete
114 # breakpoints
115 mi_gdb_test "-thread-select 5" "\\^done.*" "select thread 5"
116
117 # Now that we know about all the threads, we can get rid of
118 # breakpoint.
119 mi_delete_breakpoints
120
121 # Recreate the same breakpoint, but this time, specific to thread 5.
122 mi_create_breakpoint "-p 5 $srcfile:$bkpt_line" 3 keep thread_function .* .* .* \
123 "thread specific breakpoint at thread_function"
124
125 # Resume all threads. Only thread 5 should report a stop.
126
127 set running_re ""
128 for {set i $nthreads} {$i > 0} {incr i -1} {
129 set running_re "$running_re\\*running,thread-id=\"$decimal\"\r\n"
130 }
131
132 send_gdb "-exec-continue --all\n"
133 gdb_expect {
134 -re ".*$running_re$mi_gdb_prompt" {
135 pass "resume all, thread specific breakpoint"
136 }
137 timeout {
138 fail "resume all, thread specific breakpoint (timeout)"
139 }
140 }
141
142 mi_expect_stop "breakpoint-hit" "thread_function" "\[^\n\]*" "$srcfile" \
143 "\[0-9\]*" {"" "disp=\"keep\""} "hit thread specific breakpoint"
144
145 # All threads except both thread 5 (and the main thread) should now be
146 # repeatedly hitting the thread specific breakpoint and stepping over
147 # it transparently. These are internal events, so the frontend should
148 # see those threads as running.
149
150 mi_check_thread_states \
151 {"running" "running" "running" "running" "stopped" "running" "running" "running" "running"} \
152 "thread state: all running except the breakpoint thread"
153
154 # Get rid of the breakpoint while the other threads are stepping over
155 # it, and tell all threads to exit. The program should exit
156 # gracefully shortly. Send all commands in a row, since if something
157 # goes wrong with moribund locations support or displaced stepping (or
158 # a target bug if it can step over breakpoints itself), a spurious
159 # SIGTRAP/SIGSEGV can come at any time after deleting the breakpoint.
160
161 send_gdb "102-break-delete\n"
162 send_gdb "print done = 1\n"
163 send_gdb "103-exec-continue --all\n"
164
165 gdb_expect {
166 -re "\\*stopped,reason=\"exited-normally\"" {
167 pass "resume all, program exited normally"
168 }
169 -re "\\*stopped" {
170 fail "unexpected stop"
171 }
172 timeout {
173 fail "resume all, waiting for program exit (timeout)"
174 }
175 }
176
177 mi_gdb_exit
This page took 0.037869 seconds and 4 git commands to generate.