aboutsummaryrefslogtreecommitdiff
path: root/gdb/testsuite/gdb.python/py-breakpoint.exp
diff options
context:
space:
mode:
authorAndrew Burgess <aburgess@redhat.com>2022-11-08 12:32:51 +0000
committerAndrew Burgess <aburgess@redhat.com>2023-08-17 16:42:39 +0100
commitb080fe54fb3414b488b8ef323c6c50def061f918 (patch)
tree7b0b54ca4a9a44fb37e3838fb68a01b572380b3d /gdb/testsuite/gdb.python/py-breakpoint.exp
parent0c9546b152f6b01756475ce259c895d3fa446774 (diff)
downloadgdb-b080fe54fb3414b488b8ef323c6c50def061f918.zip
gdb-b080fe54fb3414b488b8ef323c6c50def061f918.tar.gz
gdb-b080fe54fb3414b488b8ef323c6c50def061f918.tar.bz2
gdb: add inferior-specific breakpoints
This commit extends the breakpoint mechanism to allow for inferior specific breakpoints (but not watchpoints in this commit). As GDB gains better support for multiple connections, and so for running multiple (possibly unrelated) inferiors, then it is not hard to imagine that a user might wish to create breakpoints that apply to any thread in a single inferior. To achieve this currently, the user would need to create a condition possibly making use of the $_inferior convenience variable, which, though functional, isn't the most user friendly. This commit adds a new 'inferior' keyword that allows for the creation of inferior specific breakpoints. Inferior specific breakpoints are automatically deleted when the associated inferior is removed from GDB, this is similar to how thread-specific breakpoints are deleted when the associated thread is deleted. Watchpoints are already per-program-space, which in most cases mean watchpoints are already inferior specific. There is a small window where inferior-specific watchpoints might make sense, which is after a vfork, when two processes are sharing the same address space. However, I'm leaving that as an exercise for another day. For now, attempting to use the inferior keyword with a watchpoint will give an error, like this: (gdb) watch a8 inferior 1 Cannot use 'inferior' keyword with watchpoints A final note on the implementation: currently, inferior specific breakpoints, like thread-specific breakpoints, are inserted into every inferior, GDB then checks once the inferior stops if we are in the correct thread or inferior, and resumes automatically if we stopped in the wrong thread/inferior. An obvious optimisation here is to only insert breakpoint locations into the specific program space (which mostly means inferior) that contains either the inferior or thread we are interested in. This would reduce the number times GDB has to stop and then resume again in a multi-inferior setup. I have a series on the mailing list[1] that implements this optimisation for thread-specific breakpoints. Once this series has landed I'll update that series to also handle inferior specific breakpoints in the same way. For now, inferior specific breakpoints are just slightly less optimal, but this is no different to thread-specific breakpoints in a multi-inferior debug session, so I don't see this as a huge problem. [1] https://inbox.sourceware.org/gdb-patches/cover.1685479504.git.aburgess@redhat.com/
Diffstat (limited to 'gdb/testsuite/gdb.python/py-breakpoint.exp')
-rw-r--r--gdb/testsuite/gdb.python/py-breakpoint.exp43
1 files changed, 43 insertions, 0 deletions
diff --git a/gdb/testsuite/gdb.python/py-breakpoint.exp b/gdb/testsuite/gdb.python/py-breakpoint.exp
index df17d64..b2c39d7 100644
--- a/gdb/testsuite/gdb.python/py-breakpoint.exp
+++ b/gdb/testsuite/gdb.python/py-breakpoint.exp
@@ -153,6 +153,8 @@ proc_with_prefix test_bkpt_basic { } {
"Check repr for a thread breakpoint"
gdb_py_test_silent_cmd "python blist\[1\].thread = None" \
"clear breakpoint thread" 0
+ gdb_test "python print (blist\[1\].inferior)" \
+ "None" "Check breakpoint inferior"
gdb_test "python print (blist\[1\].type == gdb.BP_BREAKPOINT)" \
"True" "Check breakpoint type"
gdb_test "python print (blist\[0\].number)" \
@@ -255,6 +257,46 @@ proc_with_prefix test_bkpt_cond_and_cmds { } {
"check number of lines in commands"
}
+# Test breakpoint thread and inferior attributes.
+proc_with_prefix test_bkpt_thread_and_inferior { } {
+ global srcfile testfile hex decimal
+
+ # Start with a fresh gdb.
+ clean_restart ${testfile}
+
+ if {![runto_main]} {
+ return 0
+ }
+
+ with_test_prefix "thread" {
+ delete_breakpoints
+ gdb_test "break multiply thread 1"
+ gdb_test "python bp = gdb.breakpoints ()\[0\]"
+ gdb_test "python print(bp.thread)" "1"
+ gdb_test "python print(bp.inferior)" "None"
+ gdb_test "python bp.inferior = 1" \
+ "RuntimeError: Cannot have both 'thread' and 'inferior' conditions on a breakpoint.*"
+ gdb_test_no_output "python bp.thread = None"
+ gdb_test_no_output "python bp.inferior = 1" \
+ "set the inferior now the thread has been cleared"
+ gdb_test "info breakpoints" "stop only in inferior 1\r\n.*"
+ }
+
+ with_test_prefix "inferior" {
+ delete_breakpoints
+ gdb_test "break multiply inferior 1"
+ gdb_test "python bp = gdb.breakpoints ()\[0\]"
+ gdb_test "python print(bp.thread)" "None"
+ gdb_test "python print(bp.inferior)" "1"
+ gdb_test "python bp.thread = 1" \
+ "RuntimeError: Cannot have both 'thread' and 'inferior' conditions on a breakpoint.*"
+ gdb_test_no_output "python bp.inferior = None"
+ gdb_test_no_output "python bp.thread = 1" \
+ "set the thread now the inferior has been cleared"
+ gdb_test "info breakpoints" "stop only in thread 1\r\n.*"
+ }
+}
+
proc_with_prefix test_bkpt_invisible { } {
global srcfile testfile hex decimal
@@ -900,6 +942,7 @@ proc_with_prefix test_bkpt_auto_disable { } {
test_bkpt_basic
test_bkpt_deletion
test_bkpt_cond_and_cmds
+test_bkpt_thread_and_inferior
test_bkpt_invisible
test_hardware_breakpoints
test_catchpoints