diff options
author | Andrew Burgess <aburgess@redhat.com> | 2023-09-07 11:18:16 +0100 |
---|---|---|
committer | Andrew Burgess <aburgess@redhat.com> | 2023-09-28 15:33:13 +0100 |
commit | 5ce85461a143e0d564b6dfa6407374851899d491 (patch) | |
tree | b3491a93a686d78c5d00090781ccc450abff6d4d | |
parent | ce65386db6653171334434ae488a0c0e10a60871 (diff) | |
download | binutils-5ce85461a143e0d564b6dfa6407374851899d491.zip binutils-5ce85461a143e0d564b6dfa6407374851899d491.tar.gz binutils-5ce85461a143e0d564b6dfa6407374851899d491.tar.bz2 |
gdb/python: new Progspace.symbol_file attribute
Add a new Progspace.symbol_file attribute. This attribute holds the
gdb.Objfile object that corresponds to Progspace.filename, or None if
there is no main symbol file currently set.
Currently, to get this gdb.Objfile, a user would need to use
Progspace.objfiles, and then search for the objfile with a name that
matches Progspace.filename -- which should work just fine, but having
direct access seems a little nicer.
Reviewed-By: Eli Zaretskii <eliz@gnu.org>
Approved-By: Tom Tromey <tom@tromey.com>
-rw-r--r-- | gdb/NEWS | 5 | ||||
-rw-r--r-- | gdb/doc/python.texi | 17 | ||||
-rw-r--r-- | gdb/python/py-progspace.c | 23 | ||||
-rw-r--r-- | gdb/testsuite/gdb.python/py-progspace.exp | 9 |
4 files changed, 54 insertions, 0 deletions
@@ -298,6 +298,11 @@ show tui mouse-events class, it signals to gdb that the printer may implement new pretty-printer methods. + ** New attribute Progspace.symbol_file. This attribute holds the + gdb.Objfile that corresponds to Progspace.filename (when + Progspace.filename is not None), otherwise, this attribute is + itself None. + *** Changes in GDB 13 * MI version 1 is deprecated, and will be removed in GDB 14. diff --git a/gdb/doc/python.texi b/gdb/doc/python.texi index 1b4b8a3..6510a83 100644 --- a/gdb/doc/python.texi +++ b/gdb/doc/python.texi @@ -5078,6 +5078,23 @@ If there is no main symbol table currently loaded, then this attribute will be @code{None}. @end defvar +@defvar Progspace.symbol_file +The @code{gdb.Objfile} representing the main symbol file (from which +debug symbols have been loaded) for the @code{gdb.Progspace}. This is +the symbol file set by the @kbd{symbol-file} or @kbd{file} commands. + +This will be the @code{gdb.Objfile} representing +@code{Progspace.filename} when @code{Progspace.filename} is not +@code{None}. + +If there is no main symbol table currently loaded, then this attribute +will be @code{None}. + +If the @code{Progspace} is invalid, i.e.@:, when +@code{Progspace.is_valid()} returns @code{False}, then attempting to +access this attribute will raise a @code{RuntimeError} exception. +@end defvar + @defvar Progspace.pretty_printers The @code{pretty_printers} attribute is a list of functions. It is used to look up pretty-printers. A @code{Value} is passed to each diff --git a/gdb/python/py-progspace.c b/gdb/python/py-progspace.c index 2b1d160..929c5f4 100644 --- a/gdb/python/py-progspace.c +++ b/gdb/python/py-progspace.c @@ -111,6 +111,26 @@ pspy_get_filename (PyObject *self, void *closure) Py_RETURN_NONE; } +/* Implement the gdb.Progspace.symbol_file attribute. Retun the + gdb.Objfile corresponding to the currently loaded symbol-file, or None + if no symbol-file is loaded. If the Progspace is invalid then raise an + exception. */ + +static PyObject * +pspy_get_symbol_file (PyObject *self, void *closure) +{ + pspace_object *obj = (pspace_object *) self; + + PSPY_REQUIRE_VALID (obj); + + struct objfile *objfile = obj->pspace->symfile_object_file; + + if (objfile != nullptr) + return objfile_to_objfile_object (objfile).release (); + + Py_RETURN_NONE; +} + static void pspy_dealloc (PyObject *self) { @@ -573,6 +593,9 @@ static gdb_PyGetSetDef pspace_getset[] = "The __dict__ for this progspace.", &pspace_object_type }, { "filename", pspy_get_filename, NULL, "The filename of the progspace's main symbol file, or None.", nullptr }, + { "symbol_file", pspy_get_symbol_file, nullptr, + "The gdb.Objfile for the progspace's main symbol file, or None.", + nullptr}, { "pretty_printers", pspy_get_printers, pspy_set_printers, "Pretty printers.", NULL }, { "frame_filters", pspy_get_frame_filters, pspy_set_frame_filters, diff --git a/gdb/testsuite/gdb.python/py-progspace.exp b/gdb/testsuite/gdb.python/py-progspace.exp index f0dc208..befd643 100644 --- a/gdb/testsuite/gdb.python/py-progspace.exp +++ b/gdb/testsuite/gdb.python/py-progspace.exp @@ -30,6 +30,8 @@ clean_restart gdb_test "python print (gdb.current_progspace().filename)" "None" \ "current progspace filename (None)" +gdb_test "python print (gdb.current_progspace().symbol_file)" "None" \ + "current progspace symbol_file is None" gdb_test "python print (gdb.progspaces())" "\\\[<gdb.Progspace object at $hex>\\\]" gdb_test_no_output "python dir(gdb.current_progspace())" @@ -42,6 +44,10 @@ gdb_py_test_silent_cmd "python progspace = gdb.current_progspace()" \ gdb_test "python print (progspace.filename)" "py-progspace" \ "current progspace filename (py-progspace)" +gdb_test "python print (gdb.current_progspace().symbol_file)" \ + "<gdb.Objfile filename=.*/py-progspace>" \ + "current progspace symbol_file is set correctly" + gdb_py_test_silent_cmd "python progspace.random_attribute = 42" \ "Set random attribute in progspace" 1 gdb_test "python print (progspace.random_attribute)" "42" \ @@ -100,3 +106,6 @@ gdb_test "inferior 1" "Switching to inferior 1.*" gdb_test_no_output "remove-inferiors 2" gdb_test "python print (progspace2.objfiles ())" \ "RuntimeError: Program space no longer exists.*" + +gdb_test "python print (progspace2.symbol_file)" \ + "RuntimeError: Program space no longer exists.*" |