1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332
|
# Copyright 2023-2024 Free Software Foundation, Inc.
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; either version 3 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
# Tests related to pending breakpoints in a multi-inferior environment.
require allow_shlib_tests !use_gdb_stub
standard_testfile
set libname $testfile-lib
set srcfile_lib $srcdir/$subdir/$libname.c
set binfile_lib [standard_output_file $libname.so]
if { [gdb_compile_shlib $srcfile_lib $binfile_lib {}] != "" } {
untested "failed to compile shared library 1"
return -1
}
set binfile_lib_target [gdb_download_shlib $binfile_lib]
if { [build_executable "failed to prepare" $testfile $srcfile \
[list debug \
additional_flags=-DSHLIB_NAME=\"$binfile_lib_target\" \
shlib_load]] } {
return -1
}
# Start two inferiors, both running the same test binary. The arguments
# INF_1_STOP and INF_2_STOP are source code patterns that are passed to
# gdb_get_line_number to figure out where each inferior should be stopped.
#
# This proc does a clean_restart and leaves inferior 2 selected. Also the
# 'breakpoint pending' flag is enabled, so pending breakpoints can be created
# without GDB prompting the user.
proc do_test_setup { inf_1_stop inf_2_stop } {
clean_restart ${::binfile}
gdb_locate_shlib $::binfile_lib
if {![runto_main]} {
return false
}
gdb_breakpoint [gdb_get_line_number ${inf_1_stop}] temporary
gdb_continue_to_breakpoint "move inferior 1 into position"
gdb_test "add-inferior -exec ${::binfile}" \
"Added inferior 2.*" "add inferior 2"
gdb_test "inferior 2" "Switching to inferior 2 .*" "switch to inferior 2"
if {![runto_main]} {
return false
}
gdb_breakpoint [gdb_get_line_number ${inf_2_stop}] temporary
gdb_continue_to_breakpoint "move inferior 2 into position"
gdb_test_no_output "set breakpoint pending on"
return true
}
# Create a breakpoint on the function 'foo' in THREAD. It is expected
# that the breakpoint created will be pending, this is checked by
# running the 'info breakpoints' command.
#
# Returns the number for the newly created breakpoint.
proc do_create_pending_foo_breakpoint { {thread "1.1"} } {
gdb_test "break foo thread $thread" \
[multi_line \
"Function \"foo\" not defined\\." \
"Breakpoint $::decimal \\(foo\\) pending\."] \
"set pending thread-specific breakpoint"
set bpnum [get_integer_valueof "\$bpnum" "*INVALID*" \
"get number for thread-specific breakpoint on foo"]
gdb_test "info breakpoints $bpnum" \
[multi_line \
"$bpnum\\s+breakpoint\\s+keep\\s+y\\s+<PENDING>\\s+foo" \
"\\s+stop only in thread [string_to_regexp $thread]"] \
"check thread-specific breakpoint is initially pending"
return $bpnum
}
# Create a breakpoint on the function 'foo' in THREAD. It is expected
# that the breakpoint created will not be pending, this is checked by
# running the 'info breakpoints' command.
#
# Returns the number for the newly created breakpoint.
proc do_create_foo_breakpoint { {thread "1.1"} } {
gdb_test "break foo thread $thread" \
"Breakpoint $::decimal at $::hex" \
"set thread-specific breakpoint"
set bpnum [get_integer_valueof "\$bpnum" "*INVALID*" \
"get number for thread-specific breakpoint on foo"]
gdb_test "info breakpoints $bpnum" \
[multi_line \
"$bpnum\\s+breakpoint\\s+keep\\s+y\\s+$::hex\\s+<foo\[^>\]*> inf $::decimal" \
"\\s+stop only in thread [string_to_regexp $thread]"] \
"check thread-specific breakpoint is initially pending"
return $bpnum
}
# Check that when a breakpoint is in the pending state, but that breakpoint
# does have some locations (those locations themselves are pending), GDB
# doesn't display the inferior list in the 'info breakpoints' output.
proc_with_prefix test_no_inf_display {} {
do_test_setup "Break before open" "Break before open"
# Create a breakpoint on 'foo'. As the shared library (that
# contains foo) has not been loaded into any inferior yet, then
# there will be no locations and the breakpoint will be created
# pending. Pass the 'allow-pending' flag so the gdb_breakpoint
# correctly expects the new breakpoint to be pending.
gdb_breakpoint "foo" allow-pending
set bpnum [get_integer_valueof "\$bpnum" "*INVALID*" \
"get foo breakpoint number"]
# Check the 'info breakpoints' output; the breakpoint is pending with
# no 'inf X' appearing at the end of the line.
gdb_test "info breakpoint $bpnum" \
"$bpnum\\s+breakpoint\\s+keep\\s+y\\s+<PENDING>\\s+foo" \
"check info bp before locations have been created"
# Now select inferior 1 and allow the inferior to run forward to the
# point where a breakpoint location for foo will have been created.
gdb_test "inferior 1" "Switching to inferior 1 .*"
gdb_breakpoint [gdb_get_line_number "Break after open"] temporary
gdb_continue_to_breakpoint \
"move inferior 1 until a location has been added"
# Check the 'info breakpoints' output. Notice we display the inferior
# list at the end of the breakpoint line.
gdb_test "info breakpoint $bpnum" \
"$bpnum\\s+breakpoint\\s+keep\\s+y\\s+$::hex\\s+<foo\[^>\]*>\\s+inf 1" \
"check info breakpoints while breakpoint is inserted"
# Continue inferior 1 until the shared library has been unloaded. The
# breakpoint on 'foo' will return to the pending state. We will need to
# 'continue' twice as the first time will hit the 'foo' breakpoint.
gdb_breakpoint [gdb_get_line_number "Break after close"] temporary
gdb_continue_to_breakpoint "hit the breakpoint in foo"
gdb_continue_to_breakpoint "after close library"
# Check the 'info breakpoints' output, check there is no 'inf 1' at the
# end of the breakpoint line.
gdb_test "info breakpoint $bpnum" \
[multi_line \
"$bpnum\\s+breakpoint\\s+keep\\s+y\\s+<PENDING>\\s+foo" \
"\\s+breakpoint already hit 1 time"] \
"check info breakpoints while breakpoint is pending"
}
# Setup two inferiors. In #1 the symbol 'foo' has not yet been
# loaded, while in #2 the symbol 'foo' has been loaded.
#
# Create a thread-specific breakpoint on 'foo' tied to a thread in
# inferior #1, the breakpoint should be pending -- 'foo' is not yet
# loaded in #1.
#
# Now move inferior #1 forward until 'foo' is loaded, check the
# breakpoint is no longer pending.
#
# Move inferior #1 forward more until 'foo' is unloaded, check that
# the breakpoint returns to the pending state.
proc_with_prefix test_pending_toggle { } {
do_test_setup "Break before open" "Break before close"
set bpnum [do_create_pending_foo_breakpoint]
# Now return to inferior 1 and continue until the shared library is
# loaded, the breakpoint should become non-pending.
gdb_test "inferior 1" "Switching to inferior 1 .*" \
"switch back to inferior 1"
gdb_continue_to_breakpoint "stop in foo in inferior 1" "foo \\(\\) .*"
gdb_test "info breakpoint $bpnum" \
[multi_line \
"$bpnum\\s+breakpoint\\s+keep\\s+y\\s+$::hex <foo\[^>\]*> inf 1" \
"\\s+stop only in thread 1\\.1" \
"\\s+breakpoint already hit 1 time"] \
"check thread-specific breakpoint is no longer pending"
gdb_breakpoint [gdb_get_line_number "Break after close"] temporary
gdb_continue_to_breakpoint "close library"
gdb_test "info breakpoints $bpnum" \
[multi_line \
"$bpnum\\s+breakpoint\\s+keep\\s+y\\s+<PENDING>\\s+foo" \
"\\s+stop only in thread 1\\.1" \
"\\s+breakpoint already hit 1 time"] \
"check thread-specific breakpoint is pending again"
}
# Create a Python variable VAR and set it to the gdb.Breakpoint object
# corresponding to the breakpoint numbered BPNUM. If THREAD is not
# the empty string then THREAD should be an integer, check that
# gdb.Breakpoint.thread is set to the value of THREAD. Otherwise, if
# THREAD is the empty string, check that gdb.Breakpoint.thread is set
# to None.
proc py_find_breakpoint { var bpnum {thread ""} } {
gdb_test_no_output \
"python ${var}=\[b for b in gdb.breakpoints() if b.number == $bpnum\]\[0\]" \
"find Python gdb.Breakpoint object"
if { $thread ne "" } {
gdb_test_no_output "python assert(${var}.thread == ${thread})" \
"check thread attribute is currently correct"
} else {
gdb_test_no_output "python assert(${var}.thread is None)" \
"check thread attribute is currently correct"
}
}
# Setup two inferiors. In #1 the symbol 'foo' has not yet been
# loaded, while in #2 the symbol 'foo' has been loaded.
#
# Create a thread-specific breakpoint on 'foo' tied to a thread in
# inferior #1, the breakpoint should be pending -- 'foo' is not yet
# loaded in #1.
#
# Use Python to change the thread of the thread-specific breakpoint to
# a thread in inferior #2, at this point the thread should gain a
# location and become non-pending.
#
# Set the thread back to a thread in inferior #1, the breakpoint
# should return to the pending state.
proc_with_prefix py_test_toggle_thread {} {
do_test_setup "Break before open" "Break after open"
set bpnum [do_create_pending_foo_breakpoint]
py_find_breakpoint "bp" $bpnum 1
gdb_test_no_output "python bp.thread = 2" \
"change thread on thread-specific breakpoint"
gdb_test "info breakpoint $bpnum" \
[multi_line \
"$bpnum\\s+breakpoint\\s+keep\\s+y\\s+$::hex <foo\[^>\]*> inf 2" \
"\\s+stop only in thread 2\\.1"] \
"check thread-specific breakpoint now has a location"
gdb_test_no_output "set call_count = 2" "set call_count in inferior 2"
gdb_continue_to_breakpoint "stop at foo in inferior 2" "foo \\(\\) .*"
gdb_test_no_output "python bp.thread = 1" \
"restore thread on thread-specific breakpoint"
gdb_test "info breakpoints $bpnum" \
[multi_line \
"$bpnum\\s+breakpoint\\s+keep\\s+y\\s+<PENDING>\\s+foo" \
"\\s+stop only in thread 1\\.1" \
"\\s+breakpoint already hit 1 time"] \
"check thread-specific breakpoint has returned to pending"
gdb_breakpoint [gdb_get_line_number "Break after close"] temporary
gdb_continue_to_breakpoint "stop after close in inferior 2" \
".* Break after close\\. .*"
gdb_test "inferior 1" "Switching to inferior 1 .*" \
"switch to inferior 1"
gdb_continue_to_breakpoint "stop at foo in inferior 1" "foo \\(\\) .*"
}
# Setup two inferiors. Both inferiors have the symbol 'foo'
# available.
#
# Create a thread-specific breakpoint on 'foo' tied to a thread in
# inferior #1, the breakpoint should not be pending, but will only
# have a single location, the location in inferior #1.
#
# Use Python to change the thread of the thread-specific breakpoint to
# None. At this point the breakpoint should gain a second location, a
# location in inferior #2.
proc_with_prefix py_test_clear_thread {} {
do_test_setup "Break after open" "Break after open"
set bpnum [do_create_foo_breakpoint]
py_find_breakpoint "bp" $bpnum 1
gdb_test_no_output "python bp.thread = None" \
"clear thread on thread-specific breakpoint"
gdb_test "info breakpoints $bpnum" \
[multi_line \
"${bpnum}\\s+breakpoint\\s+keep y\\s+<MULTIPLE>\\s*" \
"${bpnum}\\.1\\s+y\\s+${::hex}\\s+<foo\[^>\]*> inf $::decimal" \
"${bpnum}\\.2\\s+y\\s+${::hex}\\s+<foo\[^>\]*> inf $::decimal"] \
"check for a location in both inferiors"
gdb_continue_to_breakpoint "stop at foo in inferior 2" "foo \\(\\) .*"
gdb_test_no_output "set call_count = 2" "set call_count in inferior 2"
gdb_test "inferior 1" "Switching to inferior 1 .*" \
"switch to inferior 1"
gdb_continue_to_breakpoint "stop at foo in inferior 1" "foo \\(\\) .*"
gdb_test_no_output "set call_count = 2" "set call_count in inferior 1"
gdb_test_no_output "python bp.thread = 2"
gdb_test "info breakpoints $bpnum" \
[multi_line \
"${bpnum}\\s+breakpoint\\s+keep y\\s+${::hex}\\s+<foo\[^>\]*> inf 2" \
"\\s+stop only in thread 2\\.1" \
"\\s+breakpoint already hit 2 times"] \
"check for a location only in inferior 2"
gdb_breakpoint [gdb_get_line_number "Break after close"] temporary
gdb_continue_to_breakpoint "stop after close in inferior 1" \
".* Break after close\\. .*"
gdb_test "inferior 2" "Switching to inferior 2 .*" \
"switch back to inferior 2"
gdb_continue_to_breakpoint "stop at foo again in inferior 2" \
"foo \\(\\) .*"
}
# Run all the tests.
test_no_inf_display
test_pending_toggle
py_test_toggle_thread
py_test_clear_thread
|