1 1.1.1.7 christos # Copyright (C) 2015-2024 Free Software Foundation, Inc. 2 1.1 christos 3 1.1 christos # This program is free software; you can redistribute it and/or modify 4 1.1 christos # it under the terms of the GNU General Public License as published by 5 1.1 christos # the Free Software Foundation; either version 3 of the License, or 6 1.1 christos # (at your option) any later version. 7 1.1 christos # 8 1.1 christos # This program is distributed in the hope that it will be useful, 9 1.1 christos # but WITHOUT ANY WARRANTY; without even the implied warranty of 10 1.1 christos # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 11 1.1 christos # GNU General Public License for more details. 12 1.1 christos # 13 1.1 christos # You should have received a copy of the GNU General Public License 14 1.1 christos # along with this program. If not, see <http://www.gnu.org/licenses/>. 15 1.1 christos 16 1.1 christos # This test verifies that several threads forking while another thread 17 1.1 christos # is constantly stepping over a breakpoint is properly handled. 18 1.1 christos 19 1.1 christos standard_testfile 20 1.1 christos 21 1.1 christos set linenum [gdb_get_line_number "set break here"] 22 1.1 christos 23 1.1 christos if {[build_executable "failed to prepare" $testfile $srcfile {debug pthreads}] == -1} { 24 1.1 christos return -1 25 1.1 christos } 26 1.1 christos 27 1.1.1.2 christos # Assume yes. 28 1.1.1.2 christos set displaced_stepping_supported 1 29 1.1.1.2 christos 30 1.1.1.2 christos # "set displaced on" only tells gdb to use displaced stepping if 31 1.1.1.2 christos # possible. Probe for actual support. 32 1.1.1.2 christos 33 1.1.1.2 christos proc probe_displaced_stepping_support {} { 34 1.1.1.2 christos global displaced_stepping_supported 35 1.1.1.2 christos global binfile gdb_prompt 36 1.1.1.2 christos 37 1.1.1.2 christos with_test_prefix "probe displaced-stepping support" { 38 1.1.1.2 christos clean_restart $binfile 39 1.1.1.2 christos 40 1.1.1.2 christos gdb_test_no_output "set displaced on" 41 1.1.1.6 christos if {![runto_main]} { 42 1.1.1.2 christos return 0 43 1.1.1.2 christos } 44 1.1.1.2 christos 45 1.1.1.2 christos # We're stopped at the main breakpoint. If displaced stepping is 46 1.1.1.2 christos # supported, we'll see related debug output while we step past 47 1.1.1.2 christos # that breakpoint. 48 1.1.1.2 christos gdb_test_no_output "set debug displaced 1" 49 1.1.1.2 christos gdb_test_multiple "next" "probe" { 50 1.1.1.6 christos -re "prepared successfully .*$gdb_prompt $" { 51 1.1.1.2 christos pass "supported" 52 1.1.1.2 christos } 53 1.1.1.2 christos -re ".*$gdb_prompt $" { 54 1.1.1.2 christos set displaced_stepping_supported 0 55 1.1.1.2 christos pass "not supported" 56 1.1.1.2 christos } 57 1.1.1.2 christos } 58 1.1.1.2 christos } 59 1.1.1.2 christos } 60 1.1.1.2 christos 61 1.1 christos # The test proper. If COND_BP_TARGET is true, then test with 62 1.1 christos # conditional breakpoints evaluated on the target side, if possible. 63 1.1 christos # DETACH_ON_FORK is used as value for the "set detach-on-fork" 64 1.1 christos # setting. If "on", this exercises GDB explicitly continuing the fork 65 1.1 christos # child until exit. If "off", this exercises GDB detaching the fork 66 1.1.1.2 christos # child. DISPLACED indicates whether to use displaced stepping or 67 1.1.1.2 christos # not. 68 1.1.1.2 christos proc do_test { cond_bp_target detach_on_fork displaced } { 69 1.1 christos global GDBFLAGS 70 1.1 christos global srcfile testfile binfile 71 1.1 christos global decimal gdb_prompt 72 1.1 christos global linenum 73 1.1 christos global is_remote_target 74 1.1 christos 75 1.1.1.7 christos save_vars { GDBFLAGS } { 76 1.1.1.7 christos set GDBFLAGS [concat $GDBFLAGS " -ex \"set non-stop on\""] 77 1.1.1.7 christos clean_restart $binfile 78 1.1.1.7 christos } 79 1.1 christos 80 1.1.1.6 christos if {![runto_main]} { 81 1.1 christos return 0 82 1.1 christos } 83 1.1 christos 84 1.1.1.2 christos if {$cond_bp_target} { 85 1.1.1.2 christos set test "set breakpoint condition-evaluation target" 86 1.1.1.2 christos gdb_test_multiple $test $test { 87 1.1.1.2 christos -re "warning: Target does not support breakpoint condition evaluation.\r\nUsing host evaluation mode instead.\r\n$gdb_prompt $" { 88 1.1.1.2 christos # Target doesn't support breakpoint condition 89 1.1.1.2 christos # evaluation on its side. Skip the test. 90 1.1.1.2 christos return 0 91 1.1.1.2 christos } 92 1.1.1.2 christos -re "^$test\r\n$gdb_prompt $" { 93 1.1.1.2 christos } 94 1.1.1.2 christos } 95 1.1.1.2 christos } else { 96 1.1.1.2 christos gdb_test_no_output "set breakpoint condition-evaluation host" 97 1.1.1.2 christos } 98 1.1.1.2 christos 99 1.1 christos gdb_test_no_output "set detach-on-fork $detach_on_fork" 100 1.1.1.2 christos gdb_test_no_output "set displaced $displaced" 101 1.1 christos 102 1.1 christos gdb_test "break $linenum if zero == 1" \ 103 1.1 christos "Breakpoint .*" \ 104 1.1 christos "set breakpoint that evals false" 105 1.1 christos 106 1.1 christos set test "continue &" 107 1.1 christos gdb_test_multiple $test $test { 108 1.1 christos -re "$gdb_prompt " { 109 1.1 christos pass $test 110 1.1 christos } 111 1.1 christos } 112 1.1 christos 113 1.1 christos set fork_count 0 114 1.1 christos set ok 0 115 1.1 christos 116 1.1.1.2 christos with_timeout_factor 10 { 117 1.1.1.2 christos set test "inferior 1 exited" 118 1.1.1.2 christos gdb_test_multiple "" $test { 119 1.1.1.2 christos -re "Inferior 1 \(\[^\r\n\]+\) exited normally" { 120 1.1.1.2 christos set ok 1 121 1.1.1.2 christos pass $test 122 1.1.1.2 christos } 123 1.1.1.2 christos -re "Inferior $decimal \(\[^\r\n\]+\) exited normally" { 124 1.1.1.2 christos incr fork_count 125 1.1.1.2 christos if {$fork_count <= 100} { 126 1.1.1.2 christos exp_continue 127 1.1.1.2 christos } else { 128 1.1.1.2 christos fail "$test (too many forks)" 129 1.1.1.2 christos } 130 1.1 christos } 131 1.1 christos } 132 1.1 christos } 133 1.1 christos 134 1.1 christos if {!$ok} { 135 1.1 christos # No use testing further. 136 1.1 christos return 137 1.1 christos } 138 1.1 christos 139 1.1 christos gdb_test "info threads" "No threads\." \ 140 1.1 christos "no threads left" 141 1.1 christos 142 1.1 christos gdb_test "info inferiors" \ 143 1.1.1.5 christos "Num\[ \t\]+Description\[ \t\]+Connection\[ \t\]+Executable\[ \t\]+\r\n\\* 1 \[^\r\n\]+" \ 144 1.1 christos "only inferior 1 left" 145 1.1 christos } 146 1.1 christos 147 1.1.1.2 christos probe_displaced_stepping_support 148 1.1 christos 149 1.1 christos foreach_with_prefix cond_bp_target {1 0} { 150 1.1 christos foreach_with_prefix detach_on_fork {"on" "off"} { 151 1.1 christos # Disable "off" for now. The test does pass with 152 1.1 christos # detach-on-fork off (at the time of writing), but gdb seems 153 1.1 christos # to slow down quadratically as inferiors are created, and 154 1.1 christos # then the test takes annoyingly long to complete... 155 1.1.1.2 christos if {$detach_on_fork == "off"} { 156 1.1.1.2 christos continue 157 1.1.1.2 christos } 158 1.1.1.2 christos 159 1.1.1.2 christos foreach_with_prefix displaced {"on" "off"} { 160 1.1.1.2 christos if {$displaced == "on" && !$displaced_stepping_supported} { 161 1.1.1.2 christos continue 162 1.1.1.2 christos } 163 1.1.1.2 christos 164 1.1.1.2 christos do_test $cond_bp_target $detach_on_fork $displaced 165 1.1.1.2 christos } 166 1.1 christos } 167 1.1 christos } 168