OSDN Git Service

2009-07-16 Phil Muldoon <pmuldoon@redhat.com>
authortromey <tromey@138bc75d-0d04-0410-961f-82ee72b054a4>
Thu, 16 Jul 2009 16:33:31 +0000 (16:33 +0000)
committertromey <tromey@138bc75d-0d04-0410-961f-82ee72b054a4>
Thu, 16 Jul 2009 16:33:31 +0000 (16:33 +0000)
    Tom Tromey <tromey@redhat.com>

* python/libstdcxx/v6/printers.py (StdStringPrinter.to_string):
Fetch std::string to the given length.

git-svn-id: svn+ssh://gcc.gnu.org/svn/gcc/trunk@149714 138bc75d-0d04-0410-961f-82ee72b054a4

libstdc++-v3/ChangeLog
libstdc++-v3/python/libstdcxx/v6/printers.py

index 346349d..39b9749 100644 (file)
@@ -1,3 +1,9 @@
+2009-07-16  Phil Muldoon <pmuldoon@redhat.com>
+           Tom Tromey <tromey@redhat.com>
+
+       * python/libstdcxx/v6/printers.py (StdStringPrinter.to_string):
+       Fetch std::string to the given length.
+
 2009-07-16  Paolo Carlini  <paolo.carlini@oracle.com>
 
        * include/bits/istream.tcc (basic_istream<>::operator>>(short&),
index e2bb231..a3d2ef1 100644 (file)
@@ -452,7 +452,21 @@ class StdStringPrinter:
             encoding = gdb.parameter('target-charset')
         elif encoding == 1:
             encoding = gdb.parameter('target-wide-charset')
-        return self.val['_M_dataplus']['_M_p'].string(encoding)
+
+        # Make sure &string works, too.
+        type = self.val.type
+        if type.code == gdb.TYPE_CODE_REF:
+            type = type.target ()
+
+        # Calculate the length of the string so that to_string returns
+        # the string according to length, not according to first null
+        # encountered.
+        ptr = self.val ['_M_dataplus']['_M_p']
+        realtype = type.unqualified ().strip_typedefs ()
+        reptype = gdb.lookup_type (str (realtype) + '::_Rep').pointer ()
+        header = ptr.cast(reptype) - 1
+        len = header.dereference ()['_M_length']
+        return self.val['_M_dataplus']['_M_p'].string (encoding, length = len)
 
     def display_hint (self):
         return 'string'