From 0ae1a3211adcb8e7518b0b656b2309ebbc45e9ae Mon Sep 17 00:00:00 2001 From: Simon Marchi Date: Thu, 13 Sep 2018 15:40:41 -0400 Subject: 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. --- gdb/python/python.c | 28 ++++++++++++++++++---------- 1 file changed, 18 insertions(+), 10 deletions(-) (limited to 'gdb/python/python.c') diff --git a/gdb/python/python.c b/gdb/python/python.c index 6f798a0..371f4a5 100644 --- a/gdb/python/python.c +++ b/gdb/python/python.c @@ -1437,10 +1437,10 @@ gdbpy_get_current_objfile (PyObject *unused1, PyObject *unused2) return result; } -/* Return a sequence holding all the Objfiles. */ +/* See python-internal.h. */ -static PyObject * -gdbpy_objfiles (PyObject *unused1, PyObject *unused2) +gdbpy_ref<> +build_objfiles_list (program_space *pspace) { struct objfile *objf; @@ -1448,15 +1448,23 @@ gdbpy_objfiles (PyObject *unused1, PyObject *unused2) if (list == NULL) return NULL; - ALL_OBJFILES (objf) - { - PyObject *item = objfile_to_objfile_object (objf); + ALL_PSPACE_OBJFILES (pspace, objf) + { + PyObject *item = objfile_to_objfile_object (objf); - if (!item || PyList_Append (list.get (), item) == -1) - return NULL; - } + if (item == nullptr || PyList_Append (list.get (), item) == -1) + return NULL; + } - return list.release (); + return list; +} + +/* Return a sequence holding all the Objfiles. */ + +static PyObject * +gdbpy_objfiles (PyObject *unused1, PyObject *unused2) +{ + return build_objfiles_list (current_program_space).release (); } /* Compute the list of active python type printers and store them in -- cgit v1.1