From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 27270 invoked by alias); 20 Jul 2012 12:42:39 -0000 Received: (qmail 27260 invoked by uid 22791); 20 Jul 2012 12:42:37 -0000 X-SWARE-Spam-Status: No, hits=-3.7 required=5.0 tests=AWL,BAYES_00,DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,FREEMAIL_FROM,KHOP_RCVD_TRUST,KHOP_THREADED,RCVD_IN_DNSWL_LOW,RCVD_IN_HOSTKARMA_YE X-Spam-Check-By: sourceware.org Received: from mail-bk0-f41.google.com (HELO mail-bk0-f41.google.com) (209.85.214.41) by sourceware.org (qpsmtpd/0.43rc1) with ESMTP; Fri, 20 Jul 2012 12:42:22 +0000 Received: by bkcjc3 with SMTP id jc3so3330280bkc.0 for ; Fri, 20 Jul 2012 05:42:20 -0700 (PDT) Received: by 10.204.156.69 with SMTP id v5mr2857124bkw.97.1342788140734; Fri, 20 Jul 2012 05:42:20 -0700 (PDT) Received: from [10.0.0.3] (d83-191-103-145.cust.tele2.at. [83.191.103.145]) by mx.google.com with ESMTPS id hg13sm2771600bkc.7.2012.07.20.05.42.18 (version=SSLv3 cipher=OTHER); Fri, 20 Jul 2012 05:42:19 -0700 (PDT) Message-ID: <50095229.3030400@googlemail.com> Date: Fri, 20 Jul 2012 12:42:00 -0000 From: Oliver Buchtala User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:13.0) Gecko/20120615 Thunderbird/13.0.1 MIME-Version: 1.0 To: gdb@sourceware.org Subject: Re: Inconsistency between results of pretty-printing children References: <50092D6B.3040103@googlemail.com> In-Reply-To: <50092D6B.3040103@googlemail.com> Content-Type: text/plain; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: 7bit X-IsSubscribed: yes Mailing-List: contact gdb-help@sourceware.org; run by ezmlm Precedence: bulk List-Id: List-Subscribe: List-Archive: List-Post: List-Help: , Sender: gdb-owner@sourceware.org X-SW-Source: 2012-07/txt/msg00058.txt.bz2 On 20.07.2012 12:05, Oliver Buchtala wrote: > Hi, > > I am facing a problem with the python API for implemenation of > Printer.children(). > > In working examples the metod of a pretty printer looks like that: > > def children(): > return [("key", 1)] > > Usually one returns an iterable here. > > The point is, that it returns tuples with key and value. > This works fine with existing IDEs using the MI interface (kdevelop, > eclipse cdt, nemiver). > > In the API documentation it is described, that this method should > return alternating keys and values. > And that is exactly what is expected by gdb's print command when > printing pretty. > To work with gdb's print method, I would adapt my printer to flatten > the whole list so that keys and values are iterated in an alternating > manner. > > This way it happens, that my pretty printer can not be used in IDEs > and with gdb's print simultanously. > Am I doing something wrong? > > Regards, > Oliver > I have created an iterator that would show the correct result in gdb's print for a children method return (key,value) tuples: class AlternateKeyValueIterator(): def __init__(self, iterable): self.it = iterable.__iter__() self._next = None def __iter__(self): return self def next(self): if self._next == None: key, value = self.it.next() self._next = value return ("", key) else: value = self._next self._next = None return ("", value) It needs also to return tuples of (str, gdb.Value) but only the value is used for printing, where as this value must be set to key and value in an alternating manner. Any hints? Or is it a bug? Regards, Oliver