From: tromey Date: Thu, 16 Jul 2009 16:33:31 +0000 (+0000) Subject: 2009-07-16 Phil Muldoon X-Git-Url: http://git.sourceforge.jp/view?p=pf3gnuchains%2Fgcc-fork.git;a=commitdiff_plain;h=ffa1c35e7cee6b9fad83752d877647f5d078cd15 2009-07-16 Phil Muldoon Tom Tromey * 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 --- diff --git a/libstdc++-v3/ChangeLog b/libstdc++-v3/ChangeLog index 346349d4212..39b9749553e 100644 --- a/libstdc++-v3/ChangeLog +++ b/libstdc++-v3/ChangeLog @@ -1,3 +1,9 @@ +2009-07-16 Phil Muldoon + Tom Tromey + + * python/libstdcxx/v6/printers.py (StdStringPrinter.to_string): + Fetch std::string to the given length. + 2009-07-16 Paolo Carlini * include/bits/istream.tcc (basic_istream<>::operator>>(short&), diff --git a/libstdc++-v3/python/libstdcxx/v6/printers.py b/libstdc++-v3/python/libstdcxx/v6/printers.py index e2bb231e15a..a3d2ef13991 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'