This is the mail archive of the
gdb-prs@sourceware.org
mailing list for the GDB project.
[Bug python/11381] New: pretty print display hint struct format problems
- From: "chrisj at rtems dot org" <sourceware-bugzilla at sourceware dot org>
- To: gdb-prs at sourceware dot org
- Date: 16 Mar 2010 05:08:46 -0000
- Subject: [Bug python/11381] New: pretty print display hint struct format problems
- Reply-to: sourceware-bugzilla at sourceware dot org
A pretty print iterator with a display hint of 'struct' prints the result of the
'to_string' call when it should not or is not needed. The problem can be shown
with a pretty print iterator for the Object_Id type in RTEMS. Stripping this
type reduces it to an "unsigned long" that is a series of bit fields. The pretty
print iterator displays the bit fields in a struct format so GDB formats the
output correctly. For example:
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'
The output is:
(gdb) p the_semaphore->Object.id
$36 = to_string = {
id = 436273170,
node = 1,
api = classic,
class = semaphores,
index = 18
}
Note the "to_string = " after the $36 should not be there.
Removing the "to_string" function from the class results in:
(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
}
Removing this function or returning None should be allowed and result in no
related output.
--
Summary: pretty print display hint struct format problems
Product: gdb
Version: 7.1
Status: UNCONFIRMED
Severity: normal
Priority: P2
Component: python
AssignedTo: unassigned at sourceware dot org
ReportedBy: chrisj at rtems dot org
CC: gdb-prs at sourceware dot org
http://sourceware.org/bugzilla/show_bug.cgi?id=11381
------- You are receiving this mail because: -------
You are on the CC list for the bug, or are watching someone who is.