]> git.ipfire.org Git - thirdparty/binutils-gdb.git/blame - gdb/testsuite/gdb.mi/mi-nsmoribund.exp
Update copyright year range in header of all files managed by GDB
[thirdparty/binutils-gdb.git] / gdb / testsuite / gdb.mi / mi-nsmoribund.exp
CommitLineData
1d506c26 1# Copyright 2008-2024 Free Software Foundation, Inc.
1c5cfe86
PA
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
0a7043e0 16require support_displaced_stepping
d5b4a7be 17
1c5cfe86
PA
18load_lib mi-support.exp
19set MIFLAGS "-i=mi"
20
1c5cfe86
PA
21#
22# Start here
23#
298a9cf0 24standard_testfile nsmoribund.c
1c5cfe86 25
298a9cf0 26set options [list debug]
1c5cfe86
PA
27if {[gdb_compile_pthreads "$srcdir/$subdir/$srcfile" $binfile executable $options] != "" } {
28 return -1
29}
30
7cb2893d
SM
31save_vars { GDBFLAGS } {
32 append GDBFLAGS " -ex \"set non-stop on\""
33 mi_clean_restart $binfile
34}
1c5cfe86 35
329ea579 36mi_gdb_test "-gdb-set mi-async 1" ".*"
fcdfa280 37mi_detect_async
1c5cfe86 38
b75d55d4 39if { [mi_runto_main] < 0 } {
cdd42066 40 return
1c5cfe86 41}
1c5cfe86 42
7a9dd1b2 43# Keep this in sync with THREADS in the $srcfile.
1c5cfe86
PA
44set nthreads 10
45
46# Set a breakpoint and let all threads hit it (except the main
47# thread).
48
49set bkpt_line [gdb_get_line_number "set breakpoint here"]
50
4b48d439
KS
51mi_create_breakpoint "$srcfile:$bkpt_line" \
52 "breakpoint at thread_function" \
53 -number 2 -function thread_function
1c5cfe86
PA
54
55mi_send_resuming_command "exec-continue --all" "resume all"
56for {set i 0} {$i < $nthreads} {incr i} {
57 mi_expect_stop "breakpoint-hit" "thread_function" "\[^\n\]*" "$srcfile" \
58 "\[0-9\]*" {"" "disp=\"keep\""} "stop $i"
59}
60
61# All but the main thread should have hit it.
62
63mi_check_thread_states \
64 {"running" "stopped" "stopped" "stopped" "stopped" "stopped" "stopped" "stopped" "stopped" "stopped" "stopped"} \
65 "thread state: all stopped except the main thread"
66
67# Select a stopped thread to make sure we're able to delete
68# breakpoints
69mi_gdb_test "-thread-select 5" "\\^done.*" "select thread 5"
70
71# Now that we know about all the threads, we can get rid of
72# breakpoint.
73mi_delete_breakpoints
74
75# Recreate the same breakpoint, but this time, specific to thread 5.
c8dfa492
AB
76mi_create_breakpoint "-p 5 $srcfile:$bkpt_line" \
77 "thread specific breakpoint at thread_function" \
78 -number "3" -type "breakpoint" -disp "keep" -enabled "y" \
79 -func "thread_function" -line "$bkpt_line" -thread "5" -times "0"
1c5cfe86
PA
80
81# Resume all threads. Only thread 5 should report a stop.
82
83set running_re ""
d0b1d624 84for {set i $nthreads} {$i > 1} {incr i -1} {
1c5cfe86
PA
85 set running_re "$running_re\\*running,thread-id=\"$decimal\"\r\n"
86}
d0b1d624
MP
87# Don't append \r\n after last line.
88set running_re "$running_re\\*running,thread-id=\"$decimal\""
1c5cfe86 89
d0b1d624
MP
90mi_gdb_test "-exec-continue --all" "\[^\n\]*\r\n$running_re" \
91 "resume all, thread specific breakpoint"
1c5cfe86
PA
92
93mi_expect_stop "breakpoint-hit" "thread_function" "\[^\n\]*" "$srcfile" \
94 "\[0-9\]*" {"" "disp=\"keep\""} "hit thread specific breakpoint"
95
96# All threads except both thread 5 (and the main thread) should now be
97# repeatedly hitting the thread specific breakpoint and stepping over
98# it transparently. These are internal events, so the frontend should
99# see those threads as running.
100
101mi_check_thread_states \
102 {"running" "running" "running" "running" "stopped" "running" "running" "running" "running"} \
103 "thread state: all running except the breakpoint thread"
104
105# Get rid of the breakpoint while the other threads are stepping over
106# it, and tell all threads to exit. The program should exit
107# gracefully shortly. Send all commands in a row, since if something
108# goes wrong with moribund locations support or displaced stepping (or
109# a target bug if it can step over breakpoints itself), a spurious
110# SIGTRAP/SIGSEGV can come at any time after deleting the breakpoint.
2ed91d1b
PA
111# Note that this causes multiple prompts to appear before the output
112# we are interested in, so we can't use mi_gdb_test or
113# gdb_test_multiple (or an MI equivalent)
1c5cfe86 114
e809353a 115mi_gdb_test "102-break-delete" "102\\^done.*"
e36788d1
TV
116set re [list \
117 [string_list_to_regexp ~ {"} $] \
118 $decimal \
119 [string_list_to_regexp " = 1" \\ n {"} \r\n ^ done]]
120set re [join $re ""]
121mi_gdb_test "print done = 1" $re
25b0a571
TV
122
123# Command exec-continue --all attempts to resume all threads, but only
124# thread 5 was stopped, so only that one is reported as running.
125set running_re "\\*running,thread-id=\"5\""
126mi_gdb_test "103-exec-continue --all" "\[^\n\]*\r\n$running_re" \
2ed91d1b
PA
127
128gdb_expect {
129 -re "\\*stopped,reason=\"exited-normally\"" {
130 pass "resume all, program exited normally"
1c5cfe86 131 }
2ed91d1b
PA
132 timeout {
133 fail "resume all, waiting for program exit (timeout)"
134 }
135}
1c5cfe86
PA
136
137mi_gdb_exit