This is the mail archive of the
archer@sourceware.org
mailing list for the Archer project.
[python] Should pretty-printer affect resulting gdb-history value?
- From: ppluzhnikov at google dot com (Paul Pluzhnikov)
- To: archer at sourceware dot org
- Date: Wed, 17 Dec 2008 12:22:04 -0800 (PST)
- Subject: [python] Should pretty-printer affect resulting gdb-history value?
- Dkim-signature: v=1; a=rsa-sha1; c=relaxed/relaxed; d=google.com; s=beta;t=1229545328; bh=Voa9/qsRreKADxgxY/6JfPBUXXk=;h=DomainKey-Signature:To:Subject:Message-Id:Date:From; b=DVyIuy+UpnCPLral2hAD0h7/+TY8KD4vy6RtyNyuFJsWxNyX3wx/qJyYhfYZwI0NU3Ckyo7P1vCNCXmBbvyiJw==
- Domainkey-signature: a=rsa-sha1; s=beta; d=google.com; c=nofws; q=dns;h=to:subject:message-id:date:from;b=enqmTS8TnADK4izuEouaOd3cXXBERxxGUlhGGrjqHnGa7FobsuDPO3w3bsfwktl1HKfvcAdOwDUbFKHvGJvhoA==
Greetings,
Consider this source:
(gdb) list
1 int main()
2 {
3 struct S { int *ptr; } s;
4 int i = 42;
5
6 s.ptr = &i;
7 return 0;
8 }
The 'struct S' is emulating some kind of smart pointer here.
Let's say the user is always interested in s.ptr when he looks at
'struct S', and so installs a pretty-printer for it:
(gdb) shell cat t-gdb.py
class SPrinter:
"Print S struct"
def __init__(self, val):
self.val = val
def to_string(self):
return self.val['ptr'];
gdb.pretty_printers['^struct S$'] = lambda val: SPrinter(val)
(gdb) source t-gdb.py
(gdb) b 7
Breakpoint 1 at 0x40031f: file t.c, line 7.
(gdb) r
Breakpoint 1, main () at t.c:7
7 return 0;
(gdb) print/r s
$1 = {ptr = 0x7fffffffe5dc}
(gdb) print s.ptr
$2 = (int *) 0x7fffffffe5dc
(gdb) print s
$3 = 0x7fffffffe5dc # pretty-printer worked,
# but why didn't it also print "(int *)" ?
(gdb) whatis $3 # not at all what I would have expected...
type = struct S
(gdb) print *$3
Structure has no component named operator*.
The result above is particularly disconcerting (though it makes
sense given the type of $3): if the user wants to dereference the
smart pointer, he now has to go back to raw representation, and
"fish out" the implementation bits.
I think it would make sense for the type of $2 and $3 to match,
though I have no idea whether that's implementable.
Thanks,
--
Paul Pluzhnikov