Printing of strings with special characters

Tom Tromey tromey@redhat.com
Mon Mar 8 19:41:00 GMT 2010


>>>>> "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'])

... though I have never really used Qt, so take with a grain of salt.

Use lazy_string if you have a newer gdb.

Tom



More information about the Gdb mailing list