[doc,RFA] New attribute "progspace" for python gdb.Objfile objects
Commit Message
Eli Zaretskii writes:
> > From: Doug Evans <dje@google.com>
> > Date: Mon, 13 Oct 2014 15:10:17 -0700
> >
> > This patch adds a new attribute "progspace" for python gdb.Objfile objects.
> >
> > While one could just always use gdb.current_progspace(), having to refer
> > to global state is generally a no-no in an API. The progspace is
> > recorded with the objfile, this patch exposes it.
> >
> > Regression tested on amd64-linux.
> >
> > 2014-10-13 Doug Evans <dje@google.com>
> >
> > * NEWS: Mention new gdb.Objfile.progspace attribute.
> > * python/py-objfile.c (objfpy_get_progspace): New function.
> > (objfile_getset): New entry for "progspace".
> >
> > doc/
> > * python.texi (Objfiles In Python): Document new progspace attribute.
> >
> > testsuite/
> > * gdb.python/py-objfile.exp: Test progspace attribute.
>
> OK for the documentation parts.
>
> Thanks.
Thanks.
Here's an updated version, I forgot to increment the reference count
of the pspace object. Doh!
[No doc changes.]
2014-10-13 Doug Evans <dje@google.com>
* NEWS: Mention new gdb.Objfile.progspace attribute.
* python/py-objfile.c (objfpy_get_progspace): New function.
(objfile_getset): New entry for "progspace".
doc/
* python.texi (Objfiles In Python): Document new progspace attribute.
testsuite/
* gdb.python/py-objfile.exp: Test progspace attribute.
Comments
Doug Evans writes:
> Eli Zaretskii writes:
> > > From: Doug Evans <dje@google.com>
> > > Date: Mon, 13 Oct 2014 15:10:17 -0700
> > >
> > > This patch adds a new attribute "progspace" for python gdb.Objfile objects.
> > >
> > > While one could just always use gdb.current_progspace(), having to refer
> > > to global state is generally a no-no in an API. The progspace is
> > > recorded with the objfile, this patch exposes it.
> > >
> > > Regression tested on amd64-linux.
> > >
> > > 2014-10-13 Doug Evans <dje@google.com>
> > >
> > > * NEWS: Mention new gdb.Objfile.progspace attribute.
> > > * python/py-objfile.c (objfpy_get_progspace): New function.
> > > (objfile_getset): New entry for "progspace".
> > >
> > > doc/
> > > * python.texi (Objfiles In Python): Document new progspace attribute.
> > >
> > > testsuite/
> > > * gdb.python/py-objfile.exp: Test progspace attribute.
> >
> > OK for the documentation parts.
> >
> > Thanks.
>
> Thanks.
>
> Here's an updated version, I forgot to increment the reference count
> of the pspace object. Doh!
>
> [No doc changes.]
>
> 2014-10-13 Doug Evans <dje@google.com>
>
> * NEWS: Mention new gdb.Objfile.progspace attribute.
> * python/py-objfile.c (objfpy_get_progspace): New function.
> (objfile_getset): New entry for "progspace".
>
> doc/
> * python.texi (Objfiles In Python): Document new progspace attribute.
>
> testsuite/
> * gdb.python/py-objfile.exp: Test progspace attribute.
I have committed this.
@@ -9,6 +9,8 @@
** You can now access frame registers from Python scripts.
** New attribute 'producer' for gdb.Symtab objects.
+ ** gdb.Objfile objects have a new attribute "progspace",
+ which is the gdb.Progspace object of the containing program space.
* New Python-based convenience functions:
@@ -3392,6 +3392,11 @@ class.
The file name of the objfile as a string.
@end defvar
+@defvar Objfile.progspace
+The containing program space of the objfile as a @code{gdb.Progspace}
+object. @xref{Progspaces In Python}.
+@end defvar
+
@defvar Objfile.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
@@ -62,6 +62,24 @@ objfpy_get_filename (PyObject *self, void *closure)
Py_RETURN_NONE;
}
+/* An Objfile method which returns the objfile's progspace, or None. */
+
+static PyObject *
+objfpy_get_progspace (PyObject *self, void *closure)
+{
+ objfile_object *obj = (objfile_object *) self;
+
+ if (obj->objfile)
+ {
+ PyObject *pspace = pspace_to_pspace_object (obj->objfile->pspace);
+
+ Py_XINCREF (pspace);
+ return pspace;
+ }
+
+ Py_RETURN_NONE;
+}
+
static void
objfpy_dealloc (PyObject *o)
{
@@ -338,6 +356,8 @@ static PyGetSetDef objfile_getset[] =
{
{ "filename", objfpy_get_filename, NULL,
"The objfile's filename, or None.", NULL },
+ { "progspace", objfpy_get_progspace, NULL,
+ "The objfile's progspace, or None.", NULL },
{ "pretty_printers", objfpy_get_printers, objfpy_set_printers,
"Pretty printers.", NULL },
{ "frame_filters", objfpy_get_frame_filters,
@@ -39,6 +39,8 @@ gdb_py_test_silent_cmd "python objfile = sym\[0\].symtab.objfile" \
gdb_test "python print (objfile.filename)" ".*py-objfile.*" \
"Get objfile file name"
+gdb_test "python print (objfile.progspace)" "<gdb\.Progspace object at .*>" \
+ "Get objfile program space"
gdb_test "python print (objfile.is_valid())" "True" \
"Get objfile validity"
gdb_unload