From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 5978 invoked by alias); 14 Mar 2010 23:40:02 -0000 Received: (qmail 5944 invoked by uid 22791); 14 Mar 2010 23:40:01 -0000 X-SWARE-Spam-Status: No, hits=-1.4 required=5.0 tests=AWL,BAYES_20 X-Spam-Check-By: sourceware.org Received: from nskntmtas06p.mx.bigpond.com (HELO nskntmtas06p.mx.bigpond.com) (61.9.168.152) by sourceware.org (qpsmtpd/0.43rc1) with ESMTP; Sun, 14 Mar 2010 23:39:52 +0000 Received: from nskntotgx02p.mx.bigpond.com ([58.172.130.100]) by nskntmtas06p.mx.bigpond.com (InterMail vM.7.05.02.08 201-2174-114-118-20080528) with ESMTP id <20100314233949.EDIW1917.nskntmtas06p.mx.bigpond.com@nskntotgx02p.mx.bigpond.com>; Sun, 14 Mar 2010 23:39:49 +0000 Received: from kiwi.contemporary.net.au ([58.172.130.100]) by nskntotgx02p.mx.bigpond.com with ESMTP id <20100314233949.ZSWE2010.nskntotgx02p.mx.bigpond.com@kiwi.contemporary.net.au>; Sun, 14 Mar 2010 23:39:49 +0000 Received: from [172.16.100.166] (lapdog.contemporary.net.au [172.16.100.166]) by kiwi.contemporary.net.au (8.14.2/8.14.2) with ESMTP id o2ENdk9v011715; Mon, 15 Mar 2010 10:39:47 +1100 Message-ID: <4B9D73C2.9090307@contemporary.net.au> Date: Sun, 14 Mar 2010 23:40:00 -0000 From: Chris Johns User-Agent: Mozilla/5.0 (Windows; U; Windows NT 5.1; en-GB; rv:1.9.1.8) Gecko/20100227 Thunderbird/3.0.3 MIME-Version: 1.0 To: tromey@redhat.com CC: gdb@sourceware.org Subject: Re: Python Pretty printing a struct References: <4B997F28.4050602@contemporary.net.au> In-Reply-To: Content-Type: text/plain; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: 7bit X-RPD-ScanID: Class unknown; VirusThreatLevel unknown, RefID str=0001.0A150204.4B9D73C5.009A,ss=1,fgs=0 X-SIH-MSG-ID: rRw0GNf+TAD0zmQv0WC2OwV0yArkq3Qt8ZoaRdJjqwQZT0bduMHeU6nmLbM8kMz21TpcNBmPPWgqZ6X0X4/QsuM= 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: 2010-03/txt/msg00088.txt.bz2 On 13/03/2010 7:40 AM, Tom Tromey wrote: >>>>>> "Chris" == Chris Johns writes: > > Chris> (gdb) p the_semaphore->Object.id > Chris> $36 = to_string = { > Chris> id = 436273170, > [...] > Chris> How do I remove the extra "to_string =" ? > > Presumably your printer returns it. Yes. > Could you post the python code? class object_id_printer: """Print an object given the ID. Print using the struct display hint and an iterator.""" class object_id_iterator: """Use an iterator for each field expanded from the id so GDB output is formatted correctly.""" def __init__(self, id): self.id = id self.count = 0 def __iter__(self): return self def next(self): self.count += 1 if self.count == 1: return int(self.id.value()) elif self.count == 2: return self.id.node() elif self.count == 3: return self.id.api() elif self.count == 4: return self.id._class() elif self.count == 5: return self.id.index() raise StopIteration def __init__(self, id): self.id = rtems_object_id(id) def to_string(self): return 'to_string' @staticmethod def key(i): if i == 0: return 'id' elif i == 1: return 'node' elif i == 2: return 'api' elif i == 3: return 'class' elif i == 4: return 'index' return 'bad' def children(self): counter = itertools.imap (self.key, itertools.count()) return itertools.izip (counter, self.object_id_iterator(self.id)) def display_hint (self): return 'struct' > Chris> I have also noticed this: > Chris> (gdb) p /x the_semaphore->Object.id > Chris> $37 = 0x1a010012 > Chris> Is it expected the actual value is shown in hex rather than the > Chris> numeric fields returned by the pretty print iterator ? > > It might be a bug, I am not sure. > Should I raise a bug report ? I have also found: (gdb) p (Object_Id) 0x1a010012 does not invoke the Object_Id pretty printer. In this RTEMS target Object_Id is a typedef to uint32_t which is a typedef to "unsigned long" so GDB looks for a the "unsigned long" pretty printer rather that an Object_Id one. Chris