python: Add Progspace.objfiles method

This patch adds an objfiles method to the Progspace object, which
returns a sequence of the objfiles associated to that program space.  I
chose a method rather than a property for symmetry with gdb.objfiles().

gdb/ChangeLog:

	* python/py-progspace.c (PSPY_REQUIRE_VALID): New macro.
	(pspy_get_objfiles): New function.
	(progspace_object_methods): New.
	(pspace_object_type): Add tp_methods callback.
	* python/python-internal.h (build_objfiles_list): New
	declaration.
	* python/python.c (build_objfiles_list): New function.
	(gdbpy_objfiles): Implement using build_objfiles_list.
	* NEWS: Mention the Progspace.objfiles method.

gdb/doc/ChangeLog:

	* python.texi (Program Spaces In Python): Document the
	Progspace.objfiles method.
	(Objfiles In Python): Mention that gdb.objfiles() is identical
	to gdb.selected_inferior().progspace.objfiles().

gdb/testsuite/ChangeLog:

	* gdb.python/py-progspace.exp: Test the Progspace.objfiles
	method.
This commit is contained in:
Simon Marchi 2018-09-13 15:40:41 -04:00
parent a40bf0c2e9
commit 0ae1a3211a
9 changed files with 122 additions and 14 deletions

View file

@ -51,3 +51,34 @@ gdb_py_test_silent_cmd "python progspace.random_attribute = 42" \
"Set random attribute in progspace" 1
gdb_test "python print (progspace.random_attribute)" "42" \
"Verify set of random attribute in progspace"
if {![runto_main]} {
fail "can't run to main"
return
}
# With a single inferior, progspace.objfiles () and gdb.objfiles () should
# be identical.
gdb_test "python print (progspace.objfiles () == gdb.objfiles ())" "True"
gdb_test "add-inferior"
gdb_test "inferior 2"
gdb_load ${binfile}
# With a second (non-started) inferior, we should have a single objfile - the
# main one.
gdb_test "python print (len (gdb.objfiles ())) == 1"
# And the gdb.objfiles() list should now be different from the objfiles of the
# prog space of inferior 1.
gdb_test "python print (progspace.objfiles () != gdb.objfiles ())" "True"
# Delete inferior 2 (and therefore the second progspace), check that the Python
# object reacts sensibly.
gdb_py_test_silent_cmd "python progspace2 = gdb.current_progspace()" \
"save progspace 2" 1
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.*"