]>
Commit | Line | Data |
---|---|---|
cada5fc9 AB |
1 | # This testcase is part of GDB, the GNU debugger. |
2 | # | |
1d506c26 | 3 | # Copyright 2020-2024 Free Software Foundation, Inc. |
cada5fc9 AB |
4 | # |
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. | |
9 | # | |
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. | |
14 | # | |
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/>. | |
17 | ||
18 | # Test that GDB can handle receiving the W and X packets for a target | |
19 | # with multiple threads, but only a single inferior. | |
20 | # | |
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. | |
25 | ||
26 | load_lib gdbserver-support.exp | |
27 | ||
cadfc59b | 28 | require allow_gdbserver_tests |
cada5fc9 AB |
29 | |
30 | standard_testfile | |
31 | ||
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. | |
35 | # | |
36 | # Places a breakpoint in function 'breakpt' and then continues to the | |
37 | # breakpoint, at which point it runs 'info threads'. | |
64c9b639 | 38 | proc prepare_for_test { executable target_executable disable_multi_process } { |
8dc558a0 SM |
39 | global GDBFLAGS |
40 | ||
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\"" | |
46 | } | |
47 | ||
48 | clean_restart ${executable} | |
49 | } | |
cada5fc9 AB |
50 | |
51 | # Make sure we're disconnected, in case we're testing with an | |
52 | # extended-remote board, therefore already connected. | |
53 | gdb_test "disconnect" ".*" | |
54 | ||
55 | # Disable XML-based thread listing, and possible the multi-process | |
56 | # extensions. | |
ff52c073 CS |
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\"." | |
60 | ||
cada5fc9 | 61 | if { $disable_multi_process } { |
ff52c073 CS |
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\"." | |
cada5fc9 AB |
65 | } |
66 | ||
67 | # Start gdbserver and connect. | |
64c9b639 | 68 | set res [gdbserver_start "" $target_executable] |
cada5fc9 AB |
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 | |
74 | } | |
75 | ||
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" ".*" | |
80 | } | |
81 | ||
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. | |
64c9b639 | 86 | proc run_exit_test { executable target_executable disable_multi_process } { |
cada5fc9 AB |
87 | global decimal |
88 | ||
64c9b639 | 89 | prepare_for_test ${executable} $target_executable ${disable_multi_process} |
cada5fc9 AB |
90 | |
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" | |
98 | } | |
99 | gdb_test "continue" \ | |
100 | [multi_line \ | |
101 | "Continuing\\." \ | |
102 | "\\\[Inferior $decimal \\\(${process_pattern}\\\) exited normally\\\]" ] \ | |
103 | "continue until process exits" | |
104 | } | |
105 | ||
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. | |
64c9b639 | 110 | proc run_signal_test { executable target_executable disable_multi_process } { |
cada5fc9 AB |
111 | global decimal gdb_prompt |
112 | ||
64c9b639 | 113 | prepare_for_test ${executable} $target_executable ${disable_multi_process} |
cada5fc9 AB |
114 | |
115 | set inf_pid [get_valueof "/d" "global_pid" "unknown"] | |
116 | gdb_assert ![string eq ${inf_pid} "unknown"] "read the pid" | |
117 | ||
118 | # This sets the inferior running again, with all threads going | |
119 | # into a long delay loop. | |
120 | send_gdb "continue\n" | |
121 | ||
122 | # Send the inferior a signal to kill it. | |
123 | sleep 1 | |
124 | remote_exec target "kill -9 ${inf_pid}" | |
125 | ||
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 | |
130 | } | |
131 | } | |
132 | } | |
133 | ||
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" | |
138 | ||
139 | set executable "$binfile-${test}" | |
98bf5c02 | 140 | if [build_executable "failed to prepare" $executable $srcfile \ |
cada5fc9 AB |
141 | [list debug pthreads additional_flags=-D${def}]] { |
142 | return -1 | |
143 | } | |
144 | ||
64c9b639 TV |
145 | set target_executable [gdb_remote_download target $executable] |
146 | ||
cada5fc9 | 147 | foreach_with_prefix multi_process { 0 1 } { |
64c9b639 | 148 | $func ${executable} $target_executable ${multi_process} |
cada5fc9 AB |
149 | } |
150 | } |