aboutsummaryrefslogtreecommitdiff
path: root/gdb/infcmd.c
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/infcmd.c
parent0c9546b152f6b01756475ce259c895d3fa446774 (diff)
downloadfsf-binutils-gdb-b080fe54fb3414b488b8ef323c6c50def061f918.zip
fsf-binutils-gdb-b080fe54fb3414b488b8ef323c6c50def061f918.tar.gz
fsf-binutils-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/infcmd.c')
-rw-r--r--gdb/infcmd.c15
1 files changed, 4 insertions, 11 deletions
diff --git a/gdb/infcmd.c b/gdb/infcmd.c
index 96c5fea..fd85d27 100644
--- a/gdb/infcmd.c
+++ b/gdb/infcmd.c
@@ -416,17 +416,10 @@ run_command_1 (const char *args, int from_tty, enum run_how run_how)
if (run_how == RUN_STOP_AT_MAIN)
{
/* To avoid other inferiors hitting this breakpoint, make it
- inferior-specific using a condition. A better solution would be to
- have proper inferior-specific breakpoint support, in the breakpoint
- machinery. We could then avoid inserting a breakpoint in the program
- spaces unrelated to this inferior. */
- const char *op
- = ((current_language->la_language == language_ada
- || current_language->la_language == language_pascal
- || current_language->la_language == language_m2) ? "=" : "==");
- std::string arg = string_printf
- ("-qualified %s if $_inferior %s %d", main_name (), op,
- current_inferior ()->num);
+ inferior-specific. */
+ std::string arg = string_printf ("-qualified %s inferior %d",
+ main_name (),
+ current_inferior ()->num);
tbreak_command (arg.c_str (), 0);
}