1 # Copyright (C) 2015-2024 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 # This test spawns a few threads that constantly trip on a breakpoint
17 # that does not cause a user-visible stop. While one of those
18 # breakpoints is being handled, the main thread exits the whole
19 # process. The result is that the current thread for which GDB is
20 # handling the event disappears too and any attempt to access
21 # register/memory now errors out. GDB and GDBserver should be able to
22 # handle this scenario gracefully.
24 # See https://sourceware.org/bugzilla/show_bug.cgi?id=18749
28 set linenum [gdb_get_line_number "set break here"]
30 if {[build_executable "failed to prepare" $testfile $srcfile {debug pthreads}] == -1} {
34 # The test proper. If COND_BP_TARGET is true, then test with
35 # conditional breakpoints evaluated on the target side, if possible.
37 proc do_test { non_stop cond_bp_target } {
43 save_vars { GDBFLAGS } {
44 set GDBFLAGS [concat $GDBFLAGS " -ex \"set non-stop $non_stop\""]
45 clean_restart $binfile
52 # Whether it's known that the test fails.
55 if {![gdb_protocol_is_remote]} {
58 if {!$cond_bp_target} {
59 # Leaving breakpoint evaluation to GDB exposes failures
60 # similar to native debugging.
62 "set remote conditional-breakpoints-packet off" \
63 "Support for the 'ConditionalBreakpoints' packet on the current remote target is set to \"off\"."
67 set test "show remote conditional-breakpoints-packet"
68 gdb_test_multiple $test $test {
69 -re "\, currently enabled.*\r\n$gdb_prompt $" {
72 -re "\, currently disabled.*\r\n$gdb_prompt $" {
73 unsupported "no support for target-side conditional breakpoints"
81 gdb_test "break $linenum if zero == 1" \
83 "set breakpoint that evals false"
86 gdb_test_multiple $test $test {
94 # Setup the kfail upfront in order to also catch GDB internal
97 setup_kfail "gdb/18749" "*-*-*"
100 set test "inferior 1 exited"
101 gdb_test_multiple "" $test {
102 -re "Inferior 1 \(\[^\r\n\]+\) exited normally" {
105 # Clear the kfail to avoid a PASS -> KPASS dance across
107 clear_kfail "*-*-linux*"
112 # Several errors end up at the top level, and printing the
114 fail "$test (prompt)"
116 -re "Cannot access memory" {
117 fail "$test (memory error)"
120 fail "$test (GDB died)"
125 # No use testing further.
129 gdb_test "info threads" "No threads\." \
133 foreach_with_prefix non_stop {"on" "off"} {
134 foreach_with_prefix cond_bp_target {1 0} {
135 do_test $non_stop $cond_bp_target