aboutsummaryrefslogtreecommitdiff
path: root/libstdc++-v3/python
diff options
context:
space:
mode:
authorPhil Muldoon <pmuldoon@redhat.com>2009-07-16 16:33:31 +0000
committerTom Tromey <tromey@gcc.gnu.org>2009-07-16 16:33:31 +0000
commit271167f1135ec6fbaa711a2a72fff1353293ee06 (patch)
tree72268f1502fd51b58f10640a7f7ced55d42f28b3 /libstdc++-v3/python
parentdb87b56d201119dba435f0ad631561ece1bd8fdc (diff)
downloadgcc-271167f1135ec6fbaa711a2a72fff1353293ee06.zip
gcc-271167f1135ec6fbaa711a2a72fff1353293ee06.tar.gz
gcc-271167f1135ec6fbaa711a2a72fff1353293ee06.tar.bz2
printers.py (StdStringPrinter.to_string): Fetch std::string to the given length.
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. Co-Authored-By: Tom Tromey <tromey@redhat.com> From-SVN: r149714
Diffstat (limited to 'libstdc++-v3/python')
-rw-r--r--libstdc++-v3/python/libstdcxx/v6/printers.py16
1 files changed, 15 insertions, 1 deletions
diff --git a/libstdc++-v3/python/libstdcxx/v6/printers.py b/libstdc++-v3/python/libstdcxx/v6/printers.py
index e2bb231..a3d2ef1 100644
--- a/libstdc++-v3/python/libstdcxx/v6/printers.py
+++ b/libstdc++-v3/python/libstdcxx/v6/printers.py
@@ -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'