From d096d8c11e4ab306d45e8dca811db2fa33e933a8 Mon Sep 17 00:00:00 2001 From: Doug Evans Date: Fri, 17 Oct 2014 10:57:26 -0700 Subject: [PATCH] Add gdb.Objfile.progspace attribute. gdb/ChangeLog: * NEWS: Mention new gdb.Objfile.progspace attribute. * python/py-objfile.c (objfpy_get_progspace): New function. (objfile_getset): New entry for "progspace". gdb/doc/ChangeLog: * python.texi (Objfiles In Python): Document new progspace attribute. gdb/testsuite/ChangeLog: * gdb.python/py-objfile.exp: Test progspace attribute. --- gdb/ChangeLog | 6 ++++++ gdb/NEWS | 2 ++ gdb/doc/ChangeLog | 4 ++++ gdb/doc/python.texi | 5 +++++ gdb/python/py-objfile.c | 20 ++++++++++++++++++++ gdb/testsuite/ChangeLog | 4 ++++ gdb/testsuite/gdb.python/py-objfile.exp | 2 ++ 7 files changed, 43 insertions(+) diff --git a/gdb/ChangeLog b/gdb/ChangeLog index f1a85deea16..4122ad0dd5f 100644 --- a/gdb/ChangeLog +++ b/gdb/ChangeLog @@ -1,3 +1,9 @@ +2014-10-17 Doug Evans + + * NEWS: Mention new gdb.Objfile.progspace attribute. + * python/py-objfile.c (objfpy_get_progspace): New function. + (objfile_getset): New entry for "progspace". + 2014-10-17 Pedro Alves PR gdb/17471 diff --git a/gdb/NEWS b/gdb/NEWS index 5a2292621af..76b44e83db4 100644 --- a/gdb/NEWS +++ b/gdb/NEWS @@ -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: diff --git a/gdb/doc/ChangeLog b/gdb/doc/ChangeLog index 432899b6da4..8c00c3233ff 100644 --- a/gdb/doc/ChangeLog +++ b/gdb/doc/ChangeLog @@ -1,3 +1,7 @@ +2014-10-17 Doug Evans + + * python.texi (Objfiles In Python): Document new progspace attribute. + 2014-10-17 Pedro Alves * gdb.texinfo (Ada Tasks and Core Files): Delete mention of Tru64. diff --git a/gdb/doc/python.texi b/gdb/doc/python.texi index 81ec11bc6a1..84d66378da2 100644 --- a/gdb/doc/python.texi +++ b/gdb/doc/python.texi @@ -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 diff --git a/gdb/python/py-objfile.c b/gdb/python/py-objfile.c index df296918d70..e8682230882 100644 --- a/gdb/python/py-objfile.c +++ b/gdb/python/py-objfile.c @@ -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, diff --git a/gdb/testsuite/ChangeLog b/gdb/testsuite/ChangeLog index 6a1d42ec731..129cd7a113f 100644 --- a/gdb/testsuite/ChangeLog +++ b/gdb/testsuite/ChangeLog @@ -1,3 +1,7 @@ +2014-10-17 Doug Evans + + * gdb.python/py-objfile.exp: Test progspace attribute. + 2014-10-17 Luis Machado * gdb.guile/scm-breakpoint.exp: Do not assume any diff --git a/gdb/testsuite/gdb.python/py-objfile.exp b/gdb/testsuite/gdb.python/py-objfile.exp index 1d2f5502935..87961703f09 100644 --- a/gdb/testsuite/gdb.python/py-objfile.exp +++ b/gdb/testsuite/gdb.python/py-objfile.exp @@ -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)" "" \ + "Get objfile program space" gdb_test "python print (objfile.is_valid())" "True" \ "Get objfile validity" gdb_unload -- 2.39.2