1# Copyright (C) 2015-2023 Free Software Foundation, Inc. 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 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. 23# 24# See https://sourceware.org/bugzilla/show_bug.cgi?id=18749 25 26standard_testfile 27 28set linenum [gdb_get_line_number "set break here"] 29 30if {[build_executable "failed to prepare" $testfile $srcfile {debug pthreads}] == -1} { 31 return -1 32} 33 34# The test proper. If COND_BP_TARGET is true, then test with 35# conditional breakpoints evaluated on the target side, if possible. 36 37proc do_test { non_stop cond_bp_target } { 38 global GDBFLAGS 39 global gdb_prompt 40 global binfile 41 global linenum 42 43 set saved_gdbflags $GDBFLAGS 44 set GDBFLAGS [concat $GDBFLAGS " -ex \"set non-stop $non_stop\""] 45 clean_restart $binfile 46 set GDBFLAGS $saved_gdbflags 47 48 if {![runto_main]} { 49 return 0 50 } 51 52 # Whether it's known that the test fails. 53 set should_kfail 0 54 55 if {![gdb_is_target_remote]} { 56 set should_kfail 1 57 } else { 58 if {!$cond_bp_target} { 59 # Leaving breakpoint evaluation to GDB exposes failures 60 # similar to native debugging. 61 gdb_test_no_output "set remote conditional-breakpoints-packet off" 62 set should_kfail 1 63 } else { 64 set test "show remote conditional-breakpoints-packet" 65 gdb_test_multiple $test $test { 66 -re "currently enabled\.\r\n$gdb_prompt $" { 67 pass $test 68 } 69 -re "currently disabled\.\r\n$gdb_prompt $" { 70 unsupported "no support for target-side conditional breakpoints" 71 return 72 } 73 } 74 set should_kfail 1 75 } 76 } 77 78 gdb_test "break $linenum if zero == 1" \ 79 "Breakpoint .*" \ 80 "set breakpoint that evals false" 81 82 set test "continue &" 83 gdb_test_multiple $test $test { 84 -re "$gdb_prompt " { 85 pass $test 86 } 87 } 88 89 set ok 0 90 91 # Setup the kfail upfront in order to also catch GDB internal 92 # errors. 93 if {$should_kfail} { 94 setup_kfail "gdb/18749" "*-*-*" 95 } 96 97 set test "inferior 1 exited" 98 gdb_test_multiple "" $test { 99 -re "Inferior 1 \(\[^\r\n\]+\) exited normally" { 100 set ok 1 101 102 # Clear the kfail to avoid a PASS -> KPASS dance across 103 # runs. 104 clear_kfail "*-*-linux*" 105 106 pass $test 107 } 108 -re "$gdb_prompt " { 109 # Several errors end up at the top level, and printing the 110 # prompt. 111 fail "$test (prompt)" 112 } 113 -re "Cannot access memory" { 114 fail "$test (memory error)" 115 } 116 eof { 117 fail "$test (GDB died)" 118 } 119 } 120 121 if {!$ok} { 122 # No use testing further. 123 return 124 } 125 126 gdb_test "info threads" "No threads\." \ 127 "no threads left" 128} 129 130foreach_with_prefix non_stop {"on" "off"} { 131 foreach_with_prefix cond_bp_target {1 0} { 132 do_test $non_stop $cond_bp_target 133 } 134} 135