From patchwork Tue Oct 14 16:17:50 2014 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Doug Evans X-Patchwork-Id: 3222 Received: (qmail 24830 invoked by alias); 14 Oct 2014 16:17:55 -0000 Mailing-List: contact gdb-patches-help@sourceware.org; run by ezmlm Precedence: bulk List-Id: List-Unsubscribe: List-Subscribe: List-Archive: List-Post: List-Help: , Sender: gdb-patches-owner@sourceware.org Delivered-To: mailing list gdb-patches@sourceware.org Received: (qmail 24821 invoked by uid 89); 14 Oct 2014 16:17:55 -0000 Authentication-Results: sourceware.org; auth=none X-Virus-Found: No X-Spam-SWARE-Status: No, score=-2.9 required=5.0 tests=AWL, BAYES_00, RCVD_IN_DNSWL_LOW, SPF_PASS, T_RP_MATCHES_RCVD autolearn=ham version=3.3.2 X-HELO: mail-ig0-f201.google.com Received: from mail-ig0-f201.google.com (HELO mail-ig0-f201.google.com) (209.85.213.201) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with (AES128-SHA encrypted) ESMTPS; Tue, 14 Oct 2014 16:17:53 +0000 Received: by mail-ig0-f201.google.com with SMTP id h15so2406633igd.0 for ; Tue, 14 Oct 2014 09:17:51 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:from:mime-version:content-type :content-transfer-encoding:message-id:date:to:subject:in-reply-to :references; bh=5uxzrcb+1qIKcP4UGBloiox2Yj8ApJfKmJ1D/ZrZhow=; b=kMevZpbz4kVALFlgg4qzWPlnnqRBdnPfmQzMoRdoViNbcFnwXGpi8/2gbEEz3COVHv ofnCeH2egKT6z9bocqWDuCBj/xsK7SFwx7/tG8NPJc8htHQXkksgazx6hXOcIYXLDgqA aTkyvELxFIShD6p/C18mrIHx8656FoxIErRyDh61c9qn1i2Ae/2Wue3XCXArJyuCxcVx NPSOty2lvUe3ZsXc3F9ROEHxoq4B+LkqsLjpgN3e8Kn6ZJv73561XWrGQyrWBLLi/gLD wd5XMov2DDDAjYl0Apsjf+Pxw5+NK1Oae8eH5GCfUsdJ2UwVLAa4miqAkjkZeJYY0Xai +J1Q== X-Gm-Message-State: ALoCoQlYUdibK7JTt7jrymUdQLWNIFvtTRhxZhRC/uNOt+KIQcCX8zoAnoVvlXCyo5RQpFh7302DoAkQ0KybE7vpLcmFaXPv1ZqgBVs+zEiNnXshiSR5/CHBZjEaWce0vpaI6OAUBkWhJ+DeZDt5KsQKJGotthXDzNxfM6LJS56PrIEMUGSXkbE= X-Received: by 10.50.47.51 with SMTP id a19mr4481712ign.7.1413303471736; Tue, 14 Oct 2014 09:17:51 -0700 (PDT) Received: from corpmail-nozzle1-1.hot.corp.google.com ([100.108.1.104]) by gmr-mx.google.com with ESMTPS id bo10si1372258qcb.2.2014.10.14.09.17.51 for (version=TLSv1.2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Tue, 14 Oct 2014 09:17:51 -0700 (PDT) Received: from ruffy2.mtv.corp.google.com ([172.17.128.107]) by corpmail-nozzle1-1.hot.corp.google.com with ESMTP id h7p8tLxA.1; Tue, 14 Oct 2014 09:17:51 -0700 From: Doug Evans MIME-Version: 1.0 Message-ID: <21565.19630.653536.736463@ruffy2.mtv.corp.google.com> Date: Tue, 14 Oct 2014 09:17:50 -0700 To: Eli Zaretskii , gdb-patches@sourceware.org Subject: Re: [PATCH, doc RFA] New attribute "progspace" for python gdb.Objfile objects In-Reply-To: <83a94z6uzu.fsf@gnu.org> References: <83a94z6uzu.fsf@gnu.org> X-IsSubscribed: yes Eli Zaretskii writes: > > From: Doug Evans > > 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 > > > > * 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 * 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. diff --git a/gdb/NEWS b/gdb/NEWS index 5de0a33..9d056b9 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/python.texi b/gdb/doc/python.texi index 81ec11b..84d6637 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 df29691..e868223 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/gdb.python/py-objfile.exp b/gdb/testsuite/gdb.python/py-objfile.exp index 1d2f550..8796170 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