From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 29093 invoked by alias); 10 Oct 2014 17:35:57 -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 29082 invoked by uid 89); 10 Oct 2014 17:35:56 -0000 Authentication-Results: sourceware.org; auth=none X-Virus-Found: No X-Spam-SWARE-Status: No, score=-3.5 required=5.0 tests=AWL,BAYES_00,RCVD_IN_DNSWL_LOW,RP_MATCHES_RCVD,SPF_PASS autolearn=ham version=3.3.2 X-HELO: mail-oi0-f74.google.com Received: from mail-oi0-f74.google.com (HELO mail-oi0-f74.google.com) (209.85.218.74) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with (AES128-SHA encrypted) ESMTPS; Fri, 10 Oct 2014 17:35:55 +0000 Received: by mail-oi0-f74.google.com with SMTP id v63so1323401oia.1 for ; Fri, 10 Oct 2014 10:35:53 -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:cc:subject:in-reply-to :references; bh=6coY4yLz+nHanOCAhcHFiECf40xpnTvkehynSbw2to4=; b=hh2MaVyIVVozYUFOMt7/tnyKlrEn20w96WZX/K8SXu94pOsKPffiF0vcYmmwW42jRT 4RjzuXLPP4veH5T7/OdsGHRC+XtPYEvHTdbORE1SMKRKhp4OQQDdjvGxExd2QbOXOuvt Kl3M5ekk6DtwAJPm3+YZGj/xJMjg4G5EtSmrhm4K2tPUunSUg3nCcJOF+nIrKU31rlFr CXIKiTBBkbf/5jh5Z0nLunbLaEJqJC1+JvbDH3KAQ0A9lKnbk42NEdtXAvzimvsqOb3E CXDXb2ZzNv4vdTPx/yTD28PJ5iiCpaZEXgSmkANHr1i8KBUiNp0Rj/JKqvYu5N8kRHv4 m9Zw== X-Gm-Message-State: ALoCoQlu5fqoFyjRab8YYKdkAmRDwm3ww/oS7kOTIH2aEqXntRAN+QGcV/hXbB/mIT7iapyT1lYb X-Received: by 10.43.126.198 with SMTP id gx6mr9451098icc.28.1412962553649; Fri, 10 Oct 2014 10:35:53 -0700 (PDT) Received: from corpmail-nozzle1-2.hot.corp.google.com ([100.108.1.103]) by gmr-mx.google.com with ESMTPS id n63si359364yho.5.2014.10.10.10.35.52 for (version=TLSv1.2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Fri, 10 Oct 2014 10:35:53 -0700 (PDT) Received: from ruffy2.mtv.corp.google.com ([172.17.128.107]) by corpmail-nozzle1-2.hot.corp.google.com with ESMTP id DolDmlqL.1; Fri, 10 Oct 2014 10:35:53 -0700 From: Doug Evans MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Transfer-Encoding: 7bit Message-ID: <21560.6392.457864.907695@ruffy2.mtv.corp.google.com> Date: Fri, 10 Oct 2014 17:35:00 -0000 To: Phil Muldoon Cc: gdb-patches@sourceware.org, eliz@gnu.org Subject: Re: [PATCH, doc RFA] Add ability to set random attributes in python objfiles,progspaces In-Reply-To: <54379223.3080305@redhat.com> References: <54379223.3080305@redhat.com> X-IsSubscribed: yes X-SW-Source: 2014-10/txt/msg00271.txt.bz2 Phil Muldoon writes: > 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! I couldn't think of a simple one. > > +@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. Yeah, this one was simple enough and educational enough that it was worth the time and effort. > > 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. Note that this is also __dict__ from the Python side. I'd use the name __dict__ here for clarity, but I can't. :-) [compiler's namespace] I can certainly add __dict__ to the comment though. > 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? Like all things in gdb/python, things get added on a demand basis. [This observation extends to more pieces of gdb than just gdb/python. I'm happy to change the rules, but I do insist on there being no double standards. :-)]