Mirror of the gdb mailing list
 help / color / mirror / Atom feed
* Python Pretty printing a struct
@ 2010-03-11 23:39 Chris Johns
  2010-03-12 20:40 ` Tom Tromey
  0 siblings, 1 reply; 7+ messages in thread
From: Chris Johns @ 2010-03-11 23:39 UTC (permalink / raw)
  To: gdb

Hello,

I have progressed so I can take a "unsigned long" value which is bit 
encoded and display it using the display hint 'struct' and a pretty 
print iterator. For example:

(gdb) p the_semaphore->Object.id
$36 = to_string = {
   id = 436273170,
   node = 1,
   api = classic,
   class = semaphores,
   index = 18
}

How do I remove the extra "to_string =" ?

I have also noticed this:

(gdb) p /x the_semaphore->Object.id
$37 = 0x1a010012

Is it expected the actual value is shown in hex rather than the numeric 
fields returned by the pretty print iterator ?

Chris


^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: Python Pretty printing a struct
  2010-03-11 23:39 Python Pretty printing a struct Chris Johns
@ 2010-03-12 20:40 ` Tom Tromey
  2010-03-14 23:40   ` Chris Johns
  0 siblings, 1 reply; 7+ messages in thread
From: Tom Tromey @ 2010-03-12 20:40 UTC (permalink / raw)
  To: Chris Johns; +Cc: gdb

>>>>> "Chris" == Chris Johns <chris@contemporary.net.au> 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.
Could you post the python code?

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.

Tom


^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: Python Pretty printing a struct
  2010-03-12 20:40 ` Tom Tromey
@ 2010-03-14 23:40   ` Chris Johns
  2010-03-15 16:39     ` Tom Tromey
  0 siblings, 1 reply; 7+ messages in thread
From: Chris Johns @ 2010-03-14 23:40 UTC (permalink / raw)
  To: tromey; +Cc: gdb

On 13/03/2010 7:40 AM, Tom Tromey wrote:
>>>>>> "Chris" == Chris Johns<chris@contemporary.net.au>  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


^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: Python Pretty printing a struct
  2010-03-14 23:40   ` Chris Johns
@ 2010-03-15 16:39     ` Tom Tromey
  2010-03-15 22:52       ` Chris Johns
  0 siblings, 1 reply; 7+ messages in thread
From: Tom Tromey @ 2010-03-15 16:39 UTC (permalink / raw)
  To: Chris Johns; +Cc: gdb

>>>>> "Chris" == Chris Johns <chris@contemporary.net.au> writes:

Chris>     def to_string(self):
Chris>         return 'to_string'

This seems like a strange definition for this method.
Try removing it.

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 ?

Tom> It might be a bug, I am not sure.

Chris> Should I raise a bug report ?

Sure.

Chris> I have also found:
Chris> (gdb) p (Object_Id) 0x1a010012
Chris> does not invoke the Object_Id pretty printer. In this RTEMS target
Chris> Object_Id is a typedef to uint32_t which is a typedef to "unsigned
Chris> long" so GDB looks for a the "unsigned long" pretty printer rather
Chris> that an Object_Id one.

This is probably due to http://sourceware.org/bugzilla/show_bug.cgi?id=10660

Tom


^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: Python Pretty printing a struct
  2010-03-15 16:39     ` Tom Tromey
@ 2010-03-15 22:52       ` Chris Johns
  2010-03-16  2:18         ` Tom Tromey
  0 siblings, 1 reply; 7+ messages in thread
From: Chris Johns @ 2010-03-15 22:52 UTC (permalink / raw)
  To: Tom Tromey; +Cc: gdb

On 16/03/2010 3:38 AM, Tom Tromey wrote:
>>>>>> "Chris" == Chris Johns<chris@contemporary.net.au>  writes:
>
> Chris>      def to_string(self):
> Chris>          return 'to_string'
>
> This seems like a strange definition for this method.

I am not sure I follow. The 'to_string' text was just to show where the 
output appeared.

> Try removing it.

Commenting out the function produced:

(gdb) p the_semaphore->Object.id
$4 = AttributeError: object_id_printer instance has no attribute 'to_string'
  = {
   id = 436273170,
   node = 1,
   api = classic,
   class = semaphores,
   index = 18
}

Trying:

     def to_string(self):
         return None

and

     def to_string(self):
         pass

gave:

(gdb) p the_semaphore->Object.id
$5 = TypeError: Could not convert Python object: None
  = {
   id = 436273170,
   node = 1,
   api = classic,
   class = semaphores,
   index = 18
}

>
> Chris>  Should I raise a bug report ?
>
> Sure.
>

Bug #11380.

>
> This is probably due to http://sourceware.org/bugzilla/show_bug.cgi?id=10660
>

Agreed.

Chris


^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: Python Pretty printing a struct
  2010-03-15 22:52       ` Chris Johns
@ 2010-03-16  2:18         ` Tom Tromey
  2010-03-16  5:10           ` Chris Johns
  0 siblings, 1 reply; 7+ messages in thread
From: Tom Tromey @ 2010-03-16  2:18 UTC (permalink / raw)
  To: Chris Johns; +Cc: gdb

>>>>> "Chris" == Chris Johns <chris@contemporary.net.au> writes:

Chris> def to_string(self):
Chris> return 'to_string'
Tom> 
Tom> This seems like a strange definition for this method.

Chris> I am not sure I follow. The 'to_string' text was just to show where
Chris> the output appeared.

Oh, I think I see now.  I didn't understand clearly before.

Chris> Commenting out the function produced:
[...]

I think we should at least look at, and probably support, both the case
where this method is missing, and the case where this method returns
None.  Could you file a PR for that?

Tom


^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: Python Pretty printing a struct
  2010-03-16  2:18         ` Tom Tromey
@ 2010-03-16  5:10           ` Chris Johns
  0 siblings, 0 replies; 7+ messages in thread
From: Chris Johns @ 2010-03-16  5:10 UTC (permalink / raw)
  To: tromey; +Cc: gdb

On 16/03/2010 1:17 PM, Tom Tromey wrote:
> I think we should at least look at, and probably support, both the case
> where this method is missing, and the case where this method returns
> None.  Could you file a PR for that?

Bug #1181.

Thanks
Chris


^ permalink raw reply	[flat|nested] 7+ messages in thread

end of thread, other threads:[~2010-03-16  5:10 UTC | newest]

Thread overview: 7+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2010-03-11 23:39 Python Pretty printing a struct Chris Johns
2010-03-12 20:40 ` Tom Tromey
2010-03-14 23:40   ` Chris Johns
2010-03-15 16:39     ` Tom Tromey
2010-03-15 22:52       ` Chris Johns
2010-03-16  2:18         ` Tom Tromey
2010-03-16  5:10           ` Chris Johns

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox