From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 18781 invoked by alias); 28 May 2014 06:10:32 -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 18765 invoked by uid 89); 28 May 2014 06:10:30 -0000 Authentication-Results: sourceware.org; auth=none X-Virus-Found: No X-Spam-SWARE-Status: No, score=-1.9 required=5.0 tests=AWL,BAYES_00,FREEMAIL_ENVFROM_END_DIGIT,FREEMAIL_FROM,RCVD_IN_DNSWL_LOW,SPF_PASS autolearn=ham version=3.3.2 X-HELO: mail-pb0-f47.google.com Received: from mail-pb0-f47.google.com (HELO mail-pb0-f47.google.com) (209.85.160.47) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with (AES128-SHA encrypted) ESMTPS; Wed, 28 May 2014 06:10:29 +0000 Received: by mail-pb0-f47.google.com with SMTP id rp16so10586441pbb.34 for ; Tue, 27 May 2014 23:10:26 -0700 (PDT) X-Received: by 10.66.218.36 with SMTP id pd4mr42977797pac.141.1401257426867; Tue, 27 May 2014 23:10:26 -0700 (PDT) Received: from seba.sebabeach.org.gmail.com (173-13-178-50-sfba.hfc.comcastbusiness.net. [173.13.178.50]) by mx.google.com with ESMTPSA id fk4sm83791972pab.23.2014.05.27.23.10.25 for (version=TLSv1.2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Tue, 27 May 2014 23:10:26 -0700 (PDT) From: Doug Evans To: Siva Chandra Cc: gdb-patches Subject: Re: [PATCH 1/4 v18] Add xmethod documentation and NEWS entry References: Date: Wed, 28 May 2014 06:10:00 -0000 In-Reply-To: (Doug Evans's message of "Sun, 25 May 2014 15:59:41 -0700") Message-ID: User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/24.3 (gnu/linux) MIME-Version: 1.0 Content-Type: text/plain X-IsSubscribed: yes X-SW-Source: 2014-05/txt/msg00689.txt.bz2 Doug Evans writes: > Siva Chandra writes: > [...] > diff --git a/gdb/doc/python.texi b/gdb/doc/python.texi > index 72d58ad..026790f 100644 > --- a/gdb/doc/python.texi > +++ b/gdb/doc/python.texi > @@ -2327,8 +2327,8 @@ existing matcher with the same name as @code{matcher} if > globally. > @end defun > > -@node Writing a Xmethod > -@subsubsection Writing a Xmethod > +@node Writing an Xmethod > +@subsubsection Writing an Xmethod > @cindex writing xmethods in Python > > Implementing xmethods in Python will require implementing xmethod > @@ -2372,6 +2372,11 @@ class MyClassMatcher(gdb.xmethod.XMethodMatcher): > def match(self, class_type, method_name): > if class_type.tag != 'MyClass': > return None > + # FIXME: User code shouldn't have to check the enabled flag. > + # py-xmethods.c checks it, so can this check just be removed? > + # If user code wants to add this enabled check, e.g., should a perf > + # concern arise, then ok; but we shouldn't encourage it as the default > + # mode of writing xmethods. > if method_name == 'geta' and self.methods[0].enabled: > return MyClassWorker_geta() > elif method_name == 'operator+' and self.methods[1].enabled: > @@ -2386,6 +2391,7 @@ a worker object of type @code{MyClassWorker_geta} for the @code{geta} > method, and a worker object of type @code{MyClassWorker_plus} for the > @code{operator+} method. Also, a worker object is returned only if the > corresponding entry in the @code{methods} attribute is enabled. > +@c FIXME: See above: User code shouldn't check enabled flag, gdb should. > > The implementation of the worker classes returned by the matcher above > is as follows: Ok, I was wrong here. What's going on here is equivalent to what python/lib/gdb/printing.y:RegexpCollectionPrettyPrinter is doing here: # Iterate over table of type regexps to determine # if a printer is registered for that type. # Return an instantiation of the printer if found. for printer in self.subprinters: if printer.enabled and printer.compiled_re.search(typename): return printer.gen_printer(val) However, note that in the pretty-printer case the result is obtained by invoking a method on the subprinter: return printer.gen_printer(val) whereas in the MyClassMatcher case all self.methods is used for is the enabled flag: if method_name == 'geta' and self.methods[0].enabled: return MyClassWorker_geta() elif method_name == 'operator+' and self.methods[1].enabled: return MyClassWorker_plus() else: return None It would be cleaner to have an example where this code looked something like the pretty-printer case: for method in self.methods: if method.enabled and method.name == method_name return method.gen_worker() return None Maybe something like: class MyClassMatcher(gdb.xmethod.XMethodMatcher): class MyClassMethod(gdb.xmethod.XMethod): def __init(self, name, worker): gdb.xmethod.XMethod.__init__(self, name) self.worker = worker def __init__(self): gdb.xmethod.XMethodMatcher.__init__(self, 'MyMatcher') # List of methods 'managed' by this matcher self.methods = [MyClassMethod('geta', MyClassWorker_geta()), MyClassXMethod('operator+', MyClassWorker_plus())] def __call__(self, class_type, method_name): if class_type.tag != 'MyClass': return None for method in self.methods: if method.enabled and method.name == method_name return method.worker return None ?