1 # Copyright 2008, 2009, 2010, 2011 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 load_lib mi-support.exp
27 set testfile "nsmoribund"
28 set srcfile "$testfile.c"
29 set binfile "$objdir/$subdir/mi-$testfile"
31 set options [list debug incdir=$objdir]
32 if {[gdb_compile_pthreads "$srcdir/$subdir/$srcfile" $binfile executable $options] != "" } {
36 mi_gdb_reinitialize_dir $srcdir/$subdir
40 gdb_test_multiple "-gdb-show non-stop" "" {
41 -re ".*\\^done,value=\"off\",supported=\"(\[^\"\]+)\"\r\n$mi_gdb_prompt$" {
42 if { $expect_out(1,string) == "1" } {
46 -re ".*$mi_gdb_prompt$" {
50 mi_gdb_test "-gdb-set non-stop 1" ".*"
51 mi_gdb_test "-gdb-set target-async 1" ".*"
54 if { [mi_run_to_main] < 0 } {
58 # Keep this in sync with THREADS in the $srcfile.
61 # Set a breakpoint and let all threads hit it (except the main
64 set bkpt_line [gdb_get_line_number "set breakpoint here"]
66 mi_create_breakpoint "$srcfile:$bkpt_line" 2 keep thread_function .* .* .* \
67 "breakpoint at thread_function"
69 mi_send_resuming_command "exec-continue --all" "resume all"
70 for {set i 0} {$i < $nthreads} {incr i} {
71 mi_expect_stop "breakpoint-hit" "thread_function" "\[^\n\]*" "$srcfile" \
72 "\[0-9\]*" {"" "disp=\"keep\""} "stop $i"
75 # All but the main thread should have hit it.
77 mi_check_thread_states \
78 {"running" "stopped" "stopped" "stopped" "stopped" "stopped" "stopped" "stopped" "stopped" "stopped" "stopped"} \
79 "thread state: all stopped except the main thread"
81 # Select a stopped thread to make sure we're able to delete
83 mi_gdb_test "-thread-select 5" "\\^done.*" "select thread 5"
85 # Now that we know about all the threads, we can get rid of
89 # Recreate the same breakpoint, but this time, specific to thread 5.
90 mi_create_breakpoint "-p 5 $srcfile:$bkpt_line" 3 keep thread_function .* .* .* \
91 "thread specific breakpoint at thread_function"
93 # Resume all threads. Only thread 5 should report a stop.
96 for {set i $nthreads} {$i > 0} {incr i -1} {
97 set running_re "$running_re\\*running,thread-id=\"$decimal\"\r\n"
100 gdb_test_multiple "-exec-continue --all" "resume all, thread specific breakpoint" {
101 -re ".*$running_re$mi_gdb_prompt" {
102 pass "resume all, thread specific breakpoint"
106 mi_expect_stop "breakpoint-hit" "thread_function" "\[^\n\]*" "$srcfile" \
107 "\[0-9\]*" {"" "disp=\"keep\""} "hit thread specific breakpoint"
109 # All threads except both thread 5 (and the main thread) should now be
110 # repeatedly hitting the thread specific breakpoint and stepping over
111 # it transparently. These are internal events, so the frontend should
112 # see those threads as running.
114 mi_check_thread_states \
115 {"running" "running" "running" "running" "stopped" "running" "running" "running" "running"} \
116 "thread state: all running except the breakpoint thread"
118 # Get rid of the breakpoint while the other threads are stepping over
119 # it, and tell all threads to exit. The program should exit
120 # gracefully shortly. Send all commands in a row, since if something
121 # goes wrong with moribund locations support or displaced stepping (or
122 # a target bug if it can step over breakpoints itself), a spurious
123 # SIGTRAP/SIGSEGV can come at any time after deleting the breakpoint.
124 # Note that this causes multiple prompts to appear before the output
125 # we are interested in, so we can't use mi_gdb_test or
126 # gdb_test_multiple (or an MI equivalent)
128 send_gdb "102-break-delete\n"
129 send_gdb "print done = 1\n"
130 send_gdb "103-exec-continue --all\n"
133 -re "\\*stopped,reason=\"exited-normally\"" {
134 pass "resume all, program exited normally"
137 fail "resume all, waiting for program exit (timeout)"