** gdb.Value now has the 'assign' method.
+ ** gdb.Progspace now has the new method "objfile_for_address". This
+ returns the gdb.Objfile, if any, that covers a given address.
+
*** Changes in GDB 13
* MI version 1 is deprecated, and will be removed in GDB 14.
as a string, or @code{None}.
@end defun
+@defun Progspace.objfile_for_address (address)
+Return the @code{gdb.Objfile} holding the given address, or
+@code{None} if no objfile covers it.
+@end defun
+
One may add arbitrary attributes to @code{gdb.Progspace} objects
in the usual Python way.
This is useful if, for example, one needs to do some extra record keeping
/* See progspace.h. */
+struct objfile *
+program_space::objfile_for_address (CORE_ADDR address)
+{
+ for (auto iter : objfiles ())
+ {
+ /* Don't check separate debug objfiles. */
+ if (iter->separate_debug_objfile_backlink != nullptr)
+ continue;
+ if (is_addr_in_objfile (address, iter))
+ return iter;
+ }
+ return nullptr;
+}
+
+/* See progspace.h. */
+
void
program_space::exec_close ()
{
/* Free all the objfiles associated with this program space. */
void free_all_objfiles ();
+ /* Return the objfile containing ADDRESS, or nullptr if the address
+ is outside all objfiles in this progspace. */
+ struct objfile *objfile_for_address (CORE_ADDR address);
+
/* Return a range adapter for iterating over all the solibs in this
program space. Use it like:
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 *
{ "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,
gdb_test "python print (gdb.current_progspace ().block_for_pc (0))" "None"
}
+gdb_test "python print(gdb.current_progspace().objfile_for_address(${pc_val}).username)" \
+ ".*py-progspace" \
+ "objfile for pc"
+gdb_test "python print(gdb.current_progspace().objfile_for_address(0))" \
+ "None" \
+ "no objfile for 0"
+
# With a single inferior, progspace.objfiles () and gdb.objfiles () should
# be identical.
gdb_test "python print (progspace.objfiles () == gdb.objfiles ())" "True"