This is the mail archive of the mailing list for the Archer project.

Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Re: [python] StdStringPrinter misleading?

>>>>> "Paul" == Paul Pluzhnikov <> writes:

Paul> std::string could contain embedded NUL characters, and current
Paul> StdStringPrinter hides this (not that the raw printing is any better):


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?


diff --git a/gdb/python/lib/gdb/libstdcxx/v6/ b/gdb/python/lib/gdb/libstdcxx/v6/
index bcc5b28..8a29e81 100644
--- a/gdb/python/lib/gdb/libstdcxx/v6/
+++ b/gdb/python/lib/gdb/libstdcxx/v6/
@@ -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'

Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]