gdb/python: Add architecture method to gdb.PendingFrame

It could be useful to determine the architecture of a frame being
unwound during the frame unwind process, that is, before we have a
gdb.Frame, but when we only have a gdb.PendingFrame.

The PendingFrame already has a pointer to the gdbarch internally, this
commit just exposes an 'architecture' method to Python, and has this
return a gdb.Architecture object (list gdb.Frame.architecture does).

gdb/ChangeLog:

	* NEWS: Mention new Python API method.
	* python/py-unwind.c (pending_framepy_architecture): New function.
	(pending_frame_object_methods): Add architecture method.

gdb/testsuite/ChangeLog:

	* gdb.python/py-unwind.py (TestUnwinder::__call__): Add test for
	gdb.PendingFrame.architecture method.

gdb/doc/ChangeLog:

	* python.texi (Unwinding Frames in Python): Document
	PendingFrame.architecture method.
This commit is contained in:
Andrew Burgess
2020-06-07 23:07:52 +01:00
parent 3bc98c0c83
commit 87dbc77459
7 changed files with 54 additions and 1 deletions

View File

@ -441,6 +441,22 @@ pending_framepy_create_unwind_info (PyObject *self, PyObject *args)
frame_id_build_special (sp, pc, special));
}
/* Implementation of PendingFrame.architecture (self) -> gdb.Architecture. */
static PyObject *
pending_framepy_architecture (PyObject *self, PyObject *args)
{
pending_frame_object *pending_frame = (pending_frame_object *) self;
if (pending_frame->frame_info == NULL)
{
PyErr_SetString (PyExc_ValueError,
"Attempting to read register from stale PendingFrame");
return NULL;
}
return gdbarch_to_arch_object (pending_frame->gdbarch);
}
/* frame_unwind.this_id method. */
static void
@ -671,6 +687,10 @@ static PyMethodDef pending_frame_object_methods[] =
"create_unwind_info (FRAME_ID) -> gdb.UnwindInfo\n"
"Construct UnwindInfo for this PendingFrame, using FRAME_ID\n"
"to identify it." },
{ "architecture",
pending_framepy_architecture, METH_NOARGS,
"architecture () -> gdb.Architecture\n"
"The architecture for this PendingFrame." },
{NULL} /* Sentinel */
};