mirror of
https://github.com/espressif/binutils-gdb.git
synced 2025-08-06 14:49:38 +08:00
Add Progspace.objfile_for_address
This adds a new objfile_for_address method to gdb.Progspace. This makes it easy to find the objfile for a given address. There's a related PR; and while this change would have been sufficient for my original need, it's not clear to me whether I should close the bug. Nevertheless I think it makes sense to at least mention it here. Bug: https://sourceware.org/bugzilla/show_bug.cgi?id=19288 Reviewed-By: Eli Zaretskii <eliz@gnu.org>
This commit is contained in:
@ -392,6 +392,30 @@ pspy_solib_name (PyObject *o, PyObject *args)
|
||||
return host_string_to_python_string (soname).release ();
|
||||
}
|
||||
|
||||
/* Implement objfile_for_address. */
|
||||
|
||||
static PyObject *
|
||||
pspy_objfile_for_address (PyObject *o, PyObject *args)
|
||||
{
|
||||
CORE_ADDR addr;
|
||||
PyObject *addr_obj;
|
||||
|
||||
pspace_object *self = (pspace_object *) o;
|
||||
|
||||
PSPY_REQUIRE_VALID (self);
|
||||
|
||||
if (!PyArg_ParseTuple (args, "O", &addr_obj))
|
||||
return nullptr;
|
||||
if (get_addr_from_python (addr_obj, &addr) < 0)
|
||||
return nullptr;
|
||||
|
||||
struct objfile *objf = self->pspace->objfile_for_address (addr);
|
||||
if (objf == nullptr)
|
||||
Py_RETURN_NONE;
|
||||
|
||||
return objfile_to_objfile_object (objf).release ();
|
||||
}
|
||||
|
||||
/* Return the innermost lexical block containing the specified pc value,
|
||||
or 0 if there is none. */
|
||||
static PyObject *
|
||||
@ -569,6 +593,9 @@ static PyMethodDef progspace_object_methods[] =
|
||||
{ "solib_name", pspy_solib_name, METH_VARARGS,
|
||||
"solib_name (Long) -> String.\n\
|
||||
Return the name of the shared library holding a given address, or None." },
|
||||
{ "objfile_for_address", pspy_objfile_for_address, METH_VARARGS,
|
||||
"objfile_for_address (int) -> gdb.Objfile\n\
|
||||
Return the objfile containing the given address, or None." },
|
||||
{ "block_for_pc", pspy_block_for_pc, METH_VARARGS,
|
||||
"Return the block containing the given pc value, or None." },
|
||||
{ "find_pc_line", pspy_find_pc_line, METH_VARARGS,
|
||||
|
Reference in New Issue
Block a user