GDB: trad-frame: Store length of value_bytes in trad_frame_saved_reg
[binutils-gdb.git] / gdb / testsuite / gdb.server / exit-multiple-threads.exp
blob79ff176e19addd6e60674d19f06cea47c21fac07
1 # This testcase is part of GDB, the GNU debugger.
3 # Copyright 2020-2024 Free Software Foundation, Inc.
5 # This program is free software; you can redistribute it and/or modify
6 # it under the terms of the GNU General Public License as published by
7 # the Free Software Foundation; either version 3 of the License, or
8 # (at your option) any later version.
10 # This program is distributed in the hope that it will be useful,
11 # but WITHOUT ANY WARRANTY; without even the implied warranty of
12 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 # GNU General Public License for more details.
15 # You should have received a copy of the GNU General Public License
16 # along with this program. If not, see <http://www.gnu.org/licenses/>.
18 # Test that GDB can handle receiving the W and X packets for a target
19 # with multiple threads, but only a single inferior.
21 # Specifically, check GDB handles this case where multi-process
22 # extensions are turned off. At one point this was causing GDB to
23 # give a warning when the exit arrived that the remote needed to
24 # include a thread-id, which was not correct.
26 load_lib gdbserver-support.exp
28 require allow_gdbserver_tests
30 standard_testfile
32 # Start up GDB and GDBserver debugging EXECUTABLE. When
33 # DISABLE_MULTI_PROCESS is true then disable GDB's remote
34 # multi-process support, otherwise, leave it enabled.
36 # Places a breakpoint in function 'breakpt' and then continues to the
37 # breakpoint, at which point it runs 'info threads'.
38 proc prepare_for_test { executable target_executable disable_multi_process } {
39 global GDBFLAGS
41 save_vars { GDBFLAGS } {
42 # If GDB and GDBserver are both running locally, set the sysroot to avoid
43 # reading files via the remote protocol.
44 if { ![is_remote host] && ![is_remote target] } {
45 set GDBFLAGS "$GDBFLAGS -ex \"set sysroot\""
48 clean_restart ${executable}
51 # Make sure we're disconnected, in case we're testing with an
52 # extended-remote board, therefore already connected.
53 gdb_test "disconnect" ".*"
55 # Disable XML-based thread listing, and possible the multi-process
56 # extensions.
57 gdb_test \
58 "set remote threads-packet off" \
59 "Support for the 'qXfer:threads:read' packet on future remote targets is set to \"off\"."
61 if { $disable_multi_process } {
62 gdb_test \
63 "set remote multiprocess-feature-packet off" \
64 "Support for the 'multiprocess-feature' packet on future remote targets is set to \"off\"."
67 # Start gdbserver and connect.
68 set res [gdbserver_start "" $target_executable]
69 set gdbserver_protocol [lindex $res 0]
70 set gdbserver_gdbport [lindex $res 1]
71 set res [gdb_target_cmd $gdbserver_protocol $gdbserver_gdbport]
72 if ![gdb_assert {$res == 0} "connect"] {
73 return
76 # Run until we hit the breakpt function, then list all threads.
77 gdb_breakpoint "breakpt"
78 gdb_continue_to_breakpoint "breakpt"
79 gdb_test "info threads" ".*"
82 # Run the tests where the inferior exits normally (the W packet) while
83 # we have multiple-threads. EXECUTABLE is the binary under test, and
84 # DISABLE_MULTI_PROCESS indicates if we should disable GDB's remote
85 # multi-process support.
86 proc run_exit_test { executable target_executable disable_multi_process } {
87 global decimal
89 prepare_for_test ${executable} $target_executable ${disable_multi_process}
91 # Finally, continue until the process exits, ensure we don't see
92 # any warnings between "Continuing." and the final process has
93 # exited message.
94 if { $disable_multi_process } {
95 set process_pattern "Remote target"
96 } else {
97 set process_pattern "process $decimal"
99 gdb_test "continue" \
100 [multi_line \
101 "Continuing\\." \
102 "\\\[Inferior $decimal \\\(${process_pattern}\\\) exited normally\\\]" ] \
103 "continue until process exits"
106 # Run the tests where the inferior exits with a signal (the X packet)
107 # while we have multiple-threads. EXECUTABLE is the binary under
108 # test, and DISABLE_MULTI_PROCESS indicates if we should disable GDB's
109 # remote multi-process support.
110 proc run_signal_test { executable target_executable disable_multi_process } {
111 global decimal gdb_prompt
113 prepare_for_test ${executable} $target_executable ${disable_multi_process}
115 set inf_pid [get_valueof "/d" "global_pid" "unknown"]
116 gdb_assert ![string eq ${inf_pid} "unknown"] "read the pid"
118 # This sets the inferior running again, with all threads going
119 # into a long delay loop.
120 send_gdb "continue\n"
122 # Send the inferior a signal to kill it.
123 sleep 1
124 remote_exec target "kill -9 ${inf_pid}"
126 # Process the output from GDB.
127 gdb_test_multiple "" "inferior exited with signal" {
128 -re "Continuing\\.\r\n\r\nProgram terminated with signal SIGKILL, Killed.\r\nThe program no longer exists.\r\n$gdb_prompt $" {
129 pass $gdb_test_name
134 # Run all of the tests.
135 foreach_with_prefix test { exit signal } {
136 set def "DO_[string toupper $test]_TEST"
137 set func "run_${test}_test"
139 set executable "$binfile-${test}"
140 if [build_executable "failed to prepare" $executable $srcfile \
141 [list debug pthreads additional_flags=-D${def}]] {
142 return -1
145 set target_executable [gdb_remote_download target $executable]
147 foreach_with_prefix multi_process { 0 1 } {
148 $func ${executable} $target_executable ${multi_process}