aboutsummaryrefslogtreecommitdiff
path: root/gdb/mi
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/mi
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/mi')
-rw-r--r--gdb/mi/mi-cmd-break.c11
-rw-r--r--gdb/mi/mi-main.c18
-rw-r--r--gdb/mi/mi-main.h6
3 files changed, 31 insertions, 4 deletions
diff --git a/gdb/mi/mi-cmd-break.c b/gdb/mi/mi-cmd-break.c
index 0777fcb..975bc1c 100644
--- a/gdb/mi/mi-cmd-break.c
+++ b/gdb/mi/mi-cmd-break.c
@@ -173,6 +173,7 @@ mi_cmd_break_insert_1 (int dprintf, const char *command,
int hardware = 0;
int temp_p = 0;
int thread = -1;
+ int thread_group = -1;
int ignore_count = 0;
const char *condition = NULL;
int pending = 0;
@@ -191,7 +192,8 @@ mi_cmd_break_insert_1 (int dprintf, const char *command,
enum opt
{
HARDWARE_OPT, TEMP_OPT, CONDITION_OPT,
- IGNORE_COUNT_OPT, THREAD_OPT, PENDING_OPT, DISABLE_OPT,
+ IGNORE_COUNT_OPT, THREAD_OPT, THREAD_GROUP_OPT,
+ PENDING_OPT, DISABLE_OPT,
TRACEPOINT_OPT,
FORCE_CONDITION_OPT,
QUALIFIED_OPT,
@@ -205,6 +207,7 @@ mi_cmd_break_insert_1 (int dprintf, const char *command,
{"c", CONDITION_OPT, 1},
{"i", IGNORE_COUNT_OPT, 1},
{"p", THREAD_OPT, 1},
+ {"g", THREAD_GROUP_OPT, 1},
{"f", PENDING_OPT, 0},
{"d", DISABLE_OPT, 0},
{"a", TRACEPOINT_OPT, 0},
@@ -247,6 +250,9 @@ mi_cmd_break_insert_1 (int dprintf, const char *command,
if (!valid_global_thread_id (thread))
error (_("Unknown thread %d."), thread);
break;
+ case THREAD_GROUP_OPT:
+ thread_group = mi_parse_thread_group_id (oarg);
+ break;
case PENDING_OPT:
pending = 1;
break;
@@ -360,7 +366,8 @@ mi_cmd_break_insert_1 (int dprintf, const char *command,
error (_("Garbage '%s' at end of location"), address);
}
- create_breakpoint (get_current_arch (), locspec.get (), condition, thread,
+ create_breakpoint (get_current_arch (), locspec.get (), condition,
+ thread, thread_group,
extra_string.c_str (),
force_condition,
0 /* condition and thread are valid. */,
diff --git a/gdb/mi/mi-main.c b/gdb/mi/mi-main.c
index 0ac2c74..b76940e 100644
--- a/gdb/mi/mi-main.c
+++ b/gdb/mi/mi-main.c
@@ -1762,8 +1762,7 @@ mi_cmd_remove_inferior (const char *command, const char *const *argv, int argc)
if (argc != 1)
error (_("-remove-inferior should be passed a single argument"));
- if (sscanf (argv[0], "i%d", &id) != 1)
- error (_("the thread group id is syntactically invalid"));
+ id = mi_parse_thread_group_id (argv[0]);
inf_to_remove = find_inferior_id (id);
if (inf_to_remove == NULL)
@@ -2796,6 +2795,21 @@ mi_cmd_complete (const char *command, const char *const *argv, int argc)
result.number_matches == max_completions ? "1" : "0");
}
+/* See mi-main.h. */
+int
+mi_parse_thread_group_id (const char *id)
+{
+ if (*id != 'i')
+ error (_("thread group id should start with an 'i'"));
+
+ char *end;
+ long num = strtol (id + 1, &end, 10);
+
+ if (*end != '\0' || num > INT_MAX)
+ error (_("invalid thread group id '%s'"), id);
+
+ return (int) num;
+}
void _initialize_mi_main ();
void
diff --git a/gdb/mi/mi-main.h b/gdb/mi/mi-main.h
index cb17921..b35544b 100644
--- a/gdb/mi/mi-main.h
+++ b/gdb/mi/mi-main.h
@@ -75,4 +75,10 @@ extern void mi_cmd_fix_breakpoint_script_output (const char *command,
const char *const *argv,
int argc);
+/* Parse a thread-group-id from ID, and return the integer part of the
+ ID. A valid thread-group-id is the character 'i' followed by an
+ integer that is greater than zero. */
+
+extern int mi_parse_thread_group_id (const char *id);
+
#endif /* MI_MI_MAIN_H */