This is the mail archive of the
gdb@sourceware.org
mailing list for the GDB project.
Re: Printing of strings with special characters
On Monday 08 March 2010 20:41:00 Tom Tromey wrote:
> >>>>> "Anton" == Anton Kunze <ak@technosis.de> writes:
>
> Anton> http://websvn.kde.org/trunk/extragear/sdk/kdevelop/debuggers/gdb/printers/
>
> Also, the QStringPrinter code seems suspect to me:
>
> class QStringPrinter:
>
> def __init__(self, val):
> self.val = val
>
> def to_string(self):
> ret = ""
> i = 0
> while i < self.val['d']['size']:
> if self.val['d']['data'][i] > 256:
> #TODO: fix this properly
> ret += '?'
> else:
> ret += chr(self.val['d']['data'][i])
> i = i + 1
> return ret
>
> This is constructing a string by hand, and using '?' to replace some
> characters.
>
> It is better to use Value.string or Value.lazy_string. From the
> qstring.h in code search, I gather that this is UTF-16-encoded, so this
> should probably read:
>
> return self.val['d']['data'].string(encoding = 'UTF-16', length = self.val['d']['size'])
I think I tried something like that when I started to use gdb/python and it
did not really work for corrupted data (like uninitialized objects or "real"
corruption).
At least I ended up transferring the raw data to the frontend and let that
decide on how to present it.
Andre'