From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 25609 invoked by alias); 10 Oct 2014 08:00:47 -0000 Mailing-List: contact gdb-patches-help@sourceware.org; run by ezmlm Precedence: bulk List-Id: List-Subscribe: List-Archive: List-Post: List-Help: , Sender: gdb-patches-owner@sourceware.org Received: (qmail 25374 invoked by uid 89); 10 Oct 2014 08:00:43 -0000 Authentication-Results: sourceware.org; auth=none X-Virus-Found: No X-Spam-SWARE-Status: No, score=-2.9 required=5.0 tests=BAYES_00,RP_MATCHES_RCVD,SPF_HELO_PASS,SPF_PASS autolearn=ham version=3.3.2 X-HELO: mx1.redhat.com Received: from mx1.redhat.com (HELO mx1.redhat.com) (209.132.183.28) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with (AES256-GCM-SHA384 encrypted) ESMTPS; Fri, 10 Oct 2014 08:00:42 +0000 Received: from int-mx09.intmail.prod.int.phx2.redhat.com (int-mx09.intmail.prod.int.phx2.redhat.com [10.5.11.22]) by mx1.redhat.com (8.14.4/8.14.4) with ESMTP id s9A80bOb024413 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=FAIL); Fri, 10 Oct 2014 04:00:37 -0400 Received: from localhost.localdomain (ovpn-112-17.ams2.redhat.com [10.36.112.17]) by int-mx09.intmail.prod.int.phx2.redhat.com (8.14.4/8.14.4) with ESMTP id s9A80Z44016691; Fri, 10 Oct 2014 04:00:36 -0400 Message-ID: <54379223.3080305@redhat.com> Date: Fri, 10 Oct 2014 08:00:00 -0000 From: Phil Muldoon MIME-Version: 1.0 To: Doug Evans , gdb-patches@sourceware.org, eliz@gnu.org Subject: Re: [PATCH, doc RFA] Add ability to set random attributes in python objfiles,progspaces References: In-Reply-To: Content-Type: text/plain; charset=windows-1252 Content-Transfer-Encoding: 7bit X-IsSubscribed: yes X-SW-Source: 2014-10/txt/msg00235.txt.bz2 On 09/10/14 20:08, Doug Evans wrote: > Hi. > > I have a need to do some extra record keeping in progspaces and > objfiles. This patch adds the ability to add random attributes > to objfile and progspace objects using the same mechanism used > for gdb.Fields. > > Regression tested on amd64-linux. > > 2014-10-09 Doug Evans > > * NEWS: Mention ability add attributes to gdb.Objfile and > gdb.Progspace objects. > * python/py-objfile.c (objfile_object): New member dict. > (objfpy_dealloc): Py_XDECREF dict. > (objfpy_initialize): Initialize dict. > (objfile_getset): Add __dict__. > (objfile_object_type): Set tp_dictoffset member. > * python/py-progspace.c (progspace_object): New member dict. > (pspy_dealloc): Py_XDECREF dict. > (pspy_initialize): Initialize dict. > (pspace_getset): Add __dict__. > (pspace_object_type): Set tp_dictoffset member. > > doc/ > * gdb.texinfo (Progspaces In Python): Document ability to add > random attributes to gdb.Progspace objects. > (Objfiles In Python): Document ability to add random attributes to > gdb.objfile objects. > > testsuite/ > * gdb.python/py-objfile.exp: Add tests for setting random attributes > in objfiles. > * gdb.python/py-progspace.exp: Add tests for setting random attributes > in progspaces. > > diff --git a/gdb/NEWS b/gdb/NEWS > index b56fe8e..ec43a22 100644 > --- a/gdb/NEWS > +++ b/gdb/NEWS > @@ -9,6 +9,7 @@ > > ** You can now access frame registers from Python scripts. > ** New attribute 'producer' for gdb.Symtab objects. > + ** You can now add attributes to gdb.Objfile and gdb.Progspace objects. > > * New Python-based convenience functions: > > diff --git a/gdb/doc/python.texi b/gdb/doc/python.texi > index 81ec11b..14a2181 100644 > --- a/gdb/doc/python.texi > +++ b/gdb/doc/python.texi > @@ -3356,6 +3356,10 @@ The @code{frame_filters} attribute is a dictionary of frame filter > objects. @xref{Frame Filter API}, for more information. > @end defvar > > +One may add arbitrary attributes to @code{gdb.Progspace} objects. > +This is useful if for example one needs to do some extra record keeping > +associated with the progspace. Maybe add a small example here as you did with gdb.Objfile? Or maybe an xref. One of my goals in the next year is to add (and backfill in existing documentation) more example led documentation for Python. Sometimes an example speaks (ten) thousand words! > +@smallexample > +(gdb) python > +import datetime > +def new_objfile_handler (event): > + event.new_objfile.time_loaded = datetime.datetime.today () > +gdb.events.new_objfile.connect (new_objfile_handler) > +end > +(gdb) file ./hello > +Reading symbols from ./hello...done. > +(gdb) python print gdb.objfiles()[0].time_loaded > +2014-10-09 11:41:36.770345 > +@end smallexample This is really awesome example. (Linking in from comment above). Thanks for taking the time out to provide a "useful" example that is also simple. > A @code{gdb.Objfile} object has the following methods: > > @defun Objfile.is_valid () > diff --git a/gdb/python/py-objfile.c b/gdb/python/py-objfile.c > index df29691..32bceee 100644 > --- a/gdb/python/py-objfile.c > +++ b/gdb/python/py-objfile.c > @@ -30,6 +30,9 @@ typedef struct > /* The corresponding objfile. */ > struct objfile *objfile; > > + /* Dictionary holding user-added attributes. */ > + PyObject *dict; > + My only nit here is the naming. dict is kind of generic. I know it follows on from the fields code :( Even though you wrote a comment, later use in the code means (say a year from now), I have to remember what this mysterious "dict" is. I'll volunteer to fix up the fields code. Lately I have been writing variable names that at least have an indication of actual usage in GDB beyond a description of what the variable is. So I would write that to be something like, attribute_dict or something along those lines. Anyway just a nit. If you decide not to pursue my comments, it is no show-stopper. > --- a/gdb/python/py-progspace.c > +++ b/gdb/python/py-progspace.c > @@ -32,6 +32,9 @@ typedef struct > /* The corresponding pspace. */ > struct program_space *pspace; > > + /* Dictionary holding user-added attributes. */ > + PyObject *dict; > + > /* The pretty-printer list of functions. */ > PyObject *printers; Same comments as above with the dict name. Thanks for this patch. It seems really useful (and in implementation fairly simple to implement). I wonder if there are other objects in Python that could benefit from the ability to arbitrarily record keep? Cheers Phil