This is the mail archive of the
archer@sourceware.org
mailing list for the Archer project.
Re: [python] StdStringPrinter misleading?
- From: Tom Tromey <tromey at redhat dot com>
- To: ppluzhnikov at google dot com (Paul Pluzhnikov)
- Cc: archer at sourceware dot org
- Date: Fri, 27 Mar 2009 19:35:23 -0600
- Subject: Re: [python] StdStringPrinter misleading?
- References: <20090328002208.083A33A6BE4@localhost>
- Reply-to: Tom Tromey <tromey at redhat dot com>
>>>>> "Paul" == Paul Pluzhnikov <ppluzhnikov@google.com> writes:
Paul> std::string could contain embedded NUL characters, and current
Paul> StdStringPrinter hides this (not that the raw printing is any better):
Thanks.
I took a look at this. We can definitely solve it, but it will
require a couple internals changes.
The appended almost does it. However, it doesn't work because
pretty_print_one_value loses the length information. I think this
should not be too hard to deal with... either Phil or I will implement
this soon.
If we go with this patch, we'll need to push the membuf stuff upstream.
Perhaps a better plan would be to add a length argument to Value.string.
Thiago, what do you think?
Tom
diff --git a/gdb/python/lib/gdb/libstdcxx/v6/printers.py b/gdb/python/lib/gdb/libstdcxx/v6/printers.py
index bcc5b28..8a29e81 100644
--- a/gdb/python/lib/gdb/libstdcxx/v6/printers.py
+++ b/gdb/python/lib/gdb/libstdcxx/v6/printers.py
@@ -450,7 +450,14 @@ class StdStringPrinter:
encoding = self.encoding
if encoding[0] is '@':
encoding = gdb.parameter(encoding[1:])
- return self.val['_M_dataplus']['_M_p'].string(encoding)
+ ptr = self.val['_M_dataplus']['_M_p']
+ realtype = self.val.type().unqualified().strip_typedefs()
+ reptype = gdb.Type(str(realtype) + '::_Rep').pointer()
+ header = ptr.cast(reptype) - 1
+ len = header.dereference()['_M_length']
+ charwidth = ptr.type().target().sizeof()
+ data = gdb.read_memory (long (ptr), long (len) * charwidth)
+ return unicode (data, encoding)
def display_hint (self):
return 'string'