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