This is the mail archive of the gdb@sourceware.org mailing list for the GDB 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: Robustifying pretty-printers


On Monday 15 June 2009 Phil Muldoon wrote:


> --- a/gdb/python/lib/gdb/libstdcxx/v6/printers.py
> +++ b/gdb/python/lib/gdb/libstdcxx/v6/printers.py
> @@ -468,7 +468,17 @@ class StdStringPrinter:
> encoding = gdb.parameter('target-charset')
> elif isinstance(encoding, WideEncoding):
> encoding = encoding.value
> - return self.val['_M_dataplus']['_M_p'].string(encoding)
> + type = self.val.type
> + if type.code == gdb.TYPE_CODE_REF:
> + type = type.target ()
> +
> + 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)

Great, this is exactly what I was looking for.

Thanks,
Volodya


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