1 # Copyright 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 # Setup two inferiors. Select one inferior and create a pending 17 # thread specific breakpoint in the other inferior. 18 # 19 # Delete the selected inferior (the one for which the thread specific 20 # breakpoint doesn't apply), and check that the breakpoint still exists. 21 # 22 # Repeat this process, but this time, create an inferior specific 23 # breakpoint. 24 25 # The plain remote target can't do multiple inferiors. 26 require !use_gdb_stub 27 28 standard_testfile 29 30 if {[prepare_for_testing "failed to prepare" $testfile $srcfile]} { 31 return -1 32 } 33 34 # Setup for the tests. Create two inferiors, both running the global 35 # BINFILE, and proceed to main in both inferiors. Delete all 36 # breakpoints, and check that we do have two threads. 37 # 38 # Return true after a successful setup, otherwise, return false. 39 proc test_setup {} { 40 clean_restart $::binfile 41 42 if {![runto_main]} { 43 return 0 44 } 45 46 gdb_test "add-inferior -exec ${::binfile}" "Added inferior 2.*" \ 47 "add inferior 2" 48 gdb_test "inferior 2" "Switching to inferior 2 .*" \ 49 "select inferior 2" 50 51 if {![runto_main]} { 52 return 0 53 } 54 55 delete_breakpoints 56 57 gdb_test "info threads" \ 58 [multi_line \ 59 " Id\\s+Target Id\\s+Frame\\s*" \ 60 " 1\\.1\\s+\[^\r\n\]+" \ 61 "\\* 2\\.1\\s+\[^\r\n\]+"] \ 62 "check we have the expected threads" 63 64 return 1 65 } 66 67 # Assuming inferior 2 is already selected, kill the current inferior 68 # (inferior 2), select inferior 1, and then remove inferior 2. 69 proc kill_and_remove_inferior_2 {} { 70 gdb_test "kill" "" "kill inferior 2" \ 71 "Kill the program being debugged.*y or n. $" "y" 72 73 gdb_test "inferior 1" "Switching to inferior 1 .*" \ 74 "select inferior 1" 75 76 gdb_test_no_output "remove-inferiors 2" 77 } 78 79 # Setup two inferiors, then create a breakpoint. If BP_PENDING is 80 # true then the breakpoint will be pending, otherwise, the breakpoint 81 # will be non-pending. 82 # 83 # BP_TYPE is either 'thread' or 'inferior', and indicates if the 84 # created breakpoint should be thread or inferior specific. 85 # 86 # The breakpoint is created while inferior 2 is selected, and the 87 # thread/inferior restriction always identifies inferior 1. 88 # 89 # Then inferior 2 is killed and removed. 90 # 91 # Finally, check that the breakpoint still exists and correctly refers 92 # to inferior 1. 93 proc do_bp_test { bp_type bp_pending } { 94 if {![test_setup]} { 95 return 96 } 97 98 if { $bp_pending } { 99 set bp_func "bar" 100 } else { 101 set bp_func "foo" 102 } 103 104 if { $bp_type eq "thread" } { 105 set bp_restriction "thread 1.1" 106 } else { 107 set bp_restriction "inferior 1" 108 } 109 110 gdb_breakpoint "$bp_func $bp_restriction" allow-pending 111 set bp_number [get_integer_valueof "\$bpnum" "INVALID" \ 112 "get b/p number for previous breakpoint"] 113 114 if { $bp_restriction eq "thread 1.1" } { 115 set bp_after_restriction "thread 1" 116 } else { 117 set bp_after_restriction $bp_restriction 118 } 119 120 if { $bp_pending } { 121 set bp_pattern_before \ 122 [multi_line \ 123 "$bp_number\\s+breakpoint\\s+keep\\s+y\\s+<PENDING>\\s+${bp_func}" \ 124 "\\s+stop only in [string_to_regexp $bp_restriction]"] 125 set bp_pattern_after \ 126 [multi_line \ 127 "$bp_number\\s+breakpoint\\s+keep\\s+y\\s+<PENDING>\\s+${bp_func}" \ 128 "\\s+stop only in [string_to_regexp $bp_after_restriction]"] 129 } else { 130 set bp_pattern_before \ 131 [multi_line \ 132 "$bp_number\\s+breakpoint\\s+keep\\s+y\\s+$::hex in $bp_func at \[^\r\n\]+ inf 1" \ 133 "\\s+stop only in [string_to_regexp $bp_restriction]"] 134 135 set bp_pattern_after \ 136 [multi_line \ 137 "$bp_number\\s+breakpoint\\s+keep\\s+y\\s+$::hex in $bp_func at \[^\r\n\]+" \ 138 "\\s+stop only in [string_to_regexp $bp_after_restriction]"] 139 } 140 141 gdb_test "info breakpoints" $bp_pattern_before \ 142 "info breakpoints before inferior removal" 143 144 kill_and_remove_inferior_2 145 146 gdb_test "info breakpoints" $bp_pattern_after \ 147 "info breakpoints after inferior removal" 148 } 149 150 # Setup two inferiors, then create a dprintf. If BP_PENDING is 151 # true then the dprintf will be pending, otherwise, the dprintf 152 # will be non-pending. 153 # 154 # The dprintf is created while inferior 2 is selected. Then inferior 155 # 2 is killed and removed. 156 # 157 # Finally, check that the dprintf still exists. 158 proc do_dprintf_test { bp_pending } { 159 if {![test_setup]} { 160 return 161 } 162 163 if { $bp_pending } { 164 set bp_func "bar" 165 166 gdb_test "dprintf $bp_func,\"in $bp_func\"" ".*" \ 167 "create dprintf breakpoint" \ 168 "Make dprintf pending on future shared library load\\? \\(y or .n.\\) $" "y" 169 } else { 170 set bp_func "foo" 171 172 gdb_test "dprintf $bp_func,\"in $bp_func\"" ".*" \ 173 "create dprintf breakpoint" 174 } 175 176 set bp_number [get_integer_valueof "\$bpnum" "INVALID" \ 177 "get b/p number for previous breakpoint"] 178 179 if { $bp_pending } { 180 set bp_pattern_before \ 181 [multi_line \ 182 "$bp_number\\s+dprintf\\s+keep\\s+y\\s+<PENDING>\\s+${bp_func}" \ 183 "\\s+printf \"in $bp_func\""] 184 set bp_pattern_after $bp_pattern_before 185 } else { 186 set bp_pattern_before \ 187 [multi_line \ 188 "$bp_number\\s+dprintf\\s+keep\\s+y\\s+<MULTIPLE>\\s*" \ 189 "\\s+printf \"in $bp_func\"" \ 190 "$bp_number\\.1\\s+y\\s+$::hex in $bp_func at \[^\r\n\]+ inf 1" \ 191 "$bp_number\\.2\\s+y\\s+$::hex in $bp_func at \[^\r\n\]+ inf 2"] 192 193 set bp_pattern_after \ 194 [multi_line \ 195 "$bp_number\\s+dprintf\\s+keep\\s+y\\s+$::hex in $bp_func at \[^\r\n\]+" \ 196 "\\s+printf \"in $bp_func\""] 197 } 198 199 gdb_test "info breakpoints" $bp_pattern_before \ 200 "info breakpoints before inferior removal" 201 202 kill_and_remove_inferior_2 203 204 gdb_test "info breakpoints" $bp_pattern_after \ 205 "info breakpoints after inferior removal" 206 } 207 208 foreach_with_prefix bp_pending { true false } { 209 foreach_with_prefix bp_type { thread inferior } { 210 do_bp_test $bp_type $bp_pending 211 } 212 213 do_dprintf_test $bp_pending 214 } 215