Re: Robustifying pretty-printers

Vladimir Prus
2009-06-15T12:39:12Z

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