mirror of
https://github.com/espressif/binutils-gdb.git
synced 2025-08-06 14:49:38 +08:00
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/
This commit is contained in:
@ -288,11 +288,86 @@ bppy_set_thread (PyObject *self, PyObject *newvalue, void *closure)
|
||||
return -1;
|
||||
}
|
||||
|
||||
if (self_bp->bp->inferior != -1 && id != -1)
|
||||
{
|
||||
PyErr_SetString (PyExc_RuntimeError,
|
||||
_("Cannot have both 'thread' and 'inferior' "
|
||||
"conditions on a breakpoint"));
|
||||
return -1;
|
||||
}
|
||||
|
||||
breakpoint_set_thread (self_bp->bp, id);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
/* Python function to set the inferior of a breakpoint. */
|
||||
|
||||
static int
|
||||
bppy_set_inferior (PyObject *self, PyObject *newvalue, void *closure)
|
||||
{
|
||||
gdbpy_breakpoint_object *self_bp = (gdbpy_breakpoint_object *) self;
|
||||
long id;
|
||||
|
||||
BPPY_SET_REQUIRE_VALID (self_bp);
|
||||
|
||||
if (newvalue == NULL)
|
||||
{
|
||||
PyErr_SetString (PyExc_TypeError,
|
||||
_("Cannot delete 'inferior' attribute."));
|
||||
return -1;
|
||||
}
|
||||
else if (PyLong_Check (newvalue))
|
||||
{
|
||||
if (!gdb_py_int_as_long (newvalue, &id))
|
||||
return -1;
|
||||
|
||||
if (!valid_global_inferior_id (id))
|
||||
{
|
||||
PyErr_SetString (PyExc_RuntimeError,
|
||||
_("Invalid inferior ID."));
|
||||
return -1;
|
||||
}
|
||||
}
|
||||
else if (newvalue == Py_None)
|
||||
id = -1;
|
||||
else
|
||||
{
|
||||
PyErr_SetString (PyExc_TypeError,
|
||||
_("The value of 'inferior' must be an integer or None."));
|
||||
return -1;
|
||||
}
|
||||
|
||||
if (self_bp->bp->type != bp_breakpoint
|
||||
&& self_bp->bp->type != bp_hardware_breakpoint)
|
||||
{
|
||||
PyErr_SetString (PyExc_RuntimeError,
|
||||
_("Cannot set 'inferior' attribute on a gdb.Breakpoint "
|
||||
"of this type"));
|
||||
return -1;
|
||||
}
|
||||
|
||||
if (self_bp->bp->thread != -1 && id != -1)
|
||||
{
|
||||
PyErr_SetString (PyExc_RuntimeError,
|
||||
_("Cannot have both 'thread' and 'inferior' conditions "
|
||||
"on a breakpoint"));
|
||||
return -1;
|
||||
}
|
||||
|
||||
if (self_bp->bp->task != -1 && id != -1)
|
||||
{
|
||||
PyErr_SetString (PyExc_RuntimeError,
|
||||
_("Cannot have both 'task' and 'inferior' conditions "
|
||||
"on a breakpoint"));
|
||||
return -1;
|
||||
}
|
||||
|
||||
breakpoint_set_inferior (self_bp->bp, id);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
/* Python function to set the (Ada) task of a breakpoint. */
|
||||
static int
|
||||
bppy_set_task (PyObject *self, PyObject *newvalue, void *closure)
|
||||
@ -704,6 +779,20 @@ bppy_get_thread (PyObject *self, void *closure)
|
||||
return gdb_py_object_from_longest (self_bp->bp->thread).release ();
|
||||
}
|
||||
|
||||
/* Python function to get the breakpoint's inferior ID. */
|
||||
static PyObject *
|
||||
bppy_get_inferior (PyObject *self, void *closure)
|
||||
{
|
||||
gdbpy_breakpoint_object *self_bp = (gdbpy_breakpoint_object *) self;
|
||||
|
||||
BPPY_REQUIRE_VALID (self_bp);
|
||||
|
||||
if (self_bp->bp->inferior == -1)
|
||||
Py_RETURN_NONE;
|
||||
|
||||
return gdb_py_object_from_longest (self_bp->bp->inferior).release ();
|
||||
}
|
||||
|
||||
/* Python function to get the breakpoint's task ID (in Ada). */
|
||||
static PyObject *
|
||||
bppy_get_task (PyObject *self, void *closure)
|
||||
@ -942,7 +1031,7 @@ bppy_init (PyObject *self, PyObject *args, PyObject *kwargs)
|
||||
= breakpoint_ops_for_location_spec (locspec.get (), false);
|
||||
|
||||
create_breakpoint (gdbpy_enter::get_gdbarch (),
|
||||
locspec.get (), NULL, -1, NULL, false,
|
||||
locspec.get (), NULL, -1, -1, NULL, false,
|
||||
0,
|
||||
temporary_bp, type,
|
||||
0,
|
||||
@ -1376,6 +1465,11 @@ static gdb_PyGetSetDef breakpoint_object_getset[] = {
|
||||
If the value is a thread ID (integer), then this is a thread-specific breakpoint.\n\
|
||||
If the value is None, then this breakpoint is not thread-specific.\n\
|
||||
No other type of value can be used.", NULL },
|
||||
{ "inferior", bppy_get_inferior, bppy_set_inferior,
|
||||
"Inferior ID for the breakpoint.\n\
|
||||
If the value is an inferior ID (integer), then this is an inferior-specific\n\
|
||||
breakpoint. If the value is None, then this breakpoint is not\n\
|
||||
inferior-specific. No other type of value can be used.", NULL },
|
||||
{ "task", bppy_get_task, bppy_set_task,
|
||||
"Thread ID for the breakpoint.\n\
|
||||
If the value is a task ID (integer), then this is an Ada task-specific breakpoint.\n\
|
||||
|
@ -307,7 +307,7 @@ bpfinishpy_init (PyObject *self, PyObject *args, PyObject *kwargs)
|
||||
location_spec_up locspec
|
||||
= new_address_location_spec (get_frame_pc (prev_frame), NULL, 0);
|
||||
create_breakpoint (gdbpy_enter::get_gdbarch (),
|
||||
locspec.get (), NULL, thread, NULL, false,
|
||||
locspec.get (), NULL, thread, -1, NULL, false,
|
||||
0,
|
||||
1 /*temp_flag*/,
|
||||
bp_breakpoint,
|
||||
|
Reference in New Issue
Block a user