Changeset 102420 in webkit


Ignore:
Timestamp:
Dec 8, 2011 7:24:30 PM (12 years ago)
Author:
hayato@chromium.org
Message:

[gdb] Pretty printer for a 8-bit version of WTF::StringImpl and LChar*.
https://bugs.webkit.org/show_bug.cgi?id=73980

Reviewed by Tony Chang.

  • gdb/webkit.py:

(guess_string_length):
(ustring_to_string):
(lstring_to_string):
(LCharStringPrinter):
(LCharStringPrinter.to_string):
(WTFStringImplPrinter.get_length):
(WTFStringImplPrinter.to_string):
(WTFStringImplPrinter.is_8bit):
(WTFStringPrinter.stringimpl_ptr):
(WTFStringPrinter.get_length):
(WTFStringPrinter.to_string):
(add_pretty_printers.lookup_function):

Location:
trunk/Tools
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • trunk/Tools/ChangeLog

    r102419 r102420  
     12011-12-08  Hayato Ito  <hayato@chromium.org>
     2
     3        [gdb] Pretty printer for a 8-bit version of WTF::StringImpl and LChar*.
     4        https://bugs.webkit.org/show_bug.cgi?id=73980
     5
     6        Reviewed by Tony Chang.
     7
     8        * gdb/webkit.py:
     9        (guess_string_length):
     10        (ustring_to_string):
     11        (lstring_to_string):
     12        (LCharStringPrinter):
     13        (LCharStringPrinter.to_string):
     14        (WTFStringImplPrinter.get_length):
     15        (WTFStringImplPrinter.to_string):
     16        (WTFStringImplPrinter.is_8bit):
     17        (WTFStringPrinter.stringimpl_ptr):
     18        (WTFStringPrinter.get_length):
     19        (WTFStringPrinter.to_string):
     20        (add_pretty_printers.lookup_function):
     21
    1222011-12-08  Pierre Rossi  <pierre.rossi@gmail.com>
    223
  • trunk/Tools/gdb/webkit.py

    r102083 r102420  
    4141
    4242
     43def guess_string_length(ptr):
     44    """Guess length of string pointed by ptr.
     45
     46    Returns a tuple of (length, an error message).
     47    """
     48    # Try to guess at the length.
     49    for i in xrange(0, 2048):
     50        try:
     51            if int((ptr + i).dereference()) == 0:
     52                return i, ''
     53        except RuntimeError:
     54            # We indexed into inaccessible memory; give up.
     55            return i, ' (gdb hit inaccessible memory)'
     56    return 256, ' (gdb found no trailing NUL)'
     57
     58
    4359def ustring_to_string(ptr, length=None):
    44     """Convert a pointer to UTF-16 data into a Python Unicode string.
     60    """Convert a pointer to UTF-16 data into a Python string encoded with utf-8.
    4561
    4662    ptr and length are both gdb.Value objects.
    4763    If length is unspecified, will guess at the length."""
    48     extra = ''
     64    error_message = ''
    4965    if length is None:
    50         # Try to guess at the length.
    51         for i in xrange(0, 2048):
    52             try:
    53                 if int((ptr + i).dereference()) == 0:
    54                     length = i
    55                     break
    56             except RuntimeError:
    57                 # We indexed into inaccessible memory; give up.
    58                 length = i
    59                 extra = u' (gdb hit inaccessible memory)'
    60                 break
    61         if length is None:
    62             length = 256
    63             extra = u' (gdb found no trailing NUL)'
     66        length, error_message = guess_string_length(ptr)
    6467    else:
    6568        length = int(length)
    66 
    6769    char_vals = [int((ptr + i).dereference()) for i in xrange(length)]
    68     string = struct.pack('H' * length, *char_vals).decode('utf-16', 'replace')
    69 
    70     return string + extra
     70    string = struct.pack('H' * length, *char_vals).decode('utf-16', 'replace').encode('utf-8')
     71    return string + error_message
     72
     73
     74def lstring_to_string(ptr, length=None):
     75    """Convert a pointer to LChar* data into a Python (non-Unicode) string.
     76
     77    ptr and length are both gdb.Value objects.
     78    If length is unspecified, will guess at the length."""
     79    error_message = ''
     80    if length is None:
     81        length, error_message = guess_string_length(ptr)
     82    else:
     83        length = int(length)
     84    string = ''.join([chr((ptr + i).dereference()) for i in xrange(length)])
     85    return string + error_message
    7186
    7287
     
    86101
    87102
     103class LCharStringPrinter(StringPrinter):
     104    "Print a LChar*; we must guess at the length"
     105    def to_string(self):
     106        return lstring_to_string(self.val)
     107
     108
    88109class WTFAtomicStringPrinter(StringPrinter):
    89110    "Print a WTF::AtomicString"
     
    101122
    102123
     124class WTFStringImplPrinter(StringPrinter):
     125    "Print a WTF::StringImpl"
     126    def get_length(self):
     127        return self.val['m_length']
     128
     129    def to_string(self):
     130        if self.is_8bit():
     131            return lstring_to_string(self.val['m_data8'], self.get_length())
     132        return ustring_to_string(self.val['m_data16'], self.get_length())
     133
     134    def is_8bit(self):
     135        return self.val['m_hashAndFlags'] & self.val['s_hashFlag8BitBuffer']
     136
     137
    103138class WTFStringPrinter(StringPrinter):
    104139    "Print a WTF::String"
     140    def stringimpl_ptr(self):
     141        return self.val['m_impl']['m_ptr']
     142
    105143    def get_length(self):
    106         if not self.val['m_impl']['m_ptr']:
     144        if not self.stringimpl_ptr():
    107145            return 0
    108         return self.val['m_impl']['m_ptr']['m_length']
    109 
    110     def is_8bit(self):
    111         return self.val['m_impl']['m_ptr']['m_hashAndFlags'] & self.val['m_impl']['m_ptr']['s_hashFlag8BitBuffer']
    112 
    113     def to_string(self):
    114         if self.get_length() == 0:
     146        return WTFStringImplPrinter(self.stringimpl_ptr().dereference()).get_length()
     147
     148    def to_string(self):
     149        if not self.stringimpl_ptr():
    115150            return '(null)'
    116 
    117         if self.is_8bit():
    118             data_member = 'm_data8'
    119         else:
    120             data_member = 'm_data16'
    121 
    122         return ustring_to_string(self.val['m_impl']['m_ptr'][data_member],
    123                                  self.get_length())
    124 
    125 
    126 class JSCUStringPrinter(StringPrinter):
    127     "Print a JSC::UString"
    128     def get_length(self):
    129         if not self.val['m_impl']['m_ptr']:
    130             return 0
    131         return self.val['m_impl']['m_ptr']['m_length']
    132 
    133     def is_8bit(self):
    134         return self.val['m_impl']['m_ptr']['m_hashAndFlags'] & self.val['m_impl']['m_ptr']['s_hashFlag8BitBuffer']
    135 
    136     def to_string(self):
    137         if self.get_length() == 0:
    138             return ''
    139 
    140         if self.is_8bit():
    141             data_member = 'm_data8'
    142         else:
    143             data_member = 'm_data16'
    144 
    145         return ustring_to_string(self.val['m_impl']['m_ptr'][data_member],
    146                                  self.get_length())
     151        return self.stringimpl_ptr().dereference()
     152
     153
     154JSCUStringPrinter = WTFStringImplPrinter
    147155
    148156
     
    272280        (re.compile("^WTF::CString$"), WTFCStringPrinter),
    273281        (re.compile("^WTF::String$"), WTFStringPrinter),
     282        (re.compile("^WTF::StringImpl$"), WTFStringImplPrinter),
    274283        (re.compile("^WebCore::KURLGooglePrivate$"), WebCoreKURLGooglePrivatePrinter),
    275284        (re.compile("^WebCore::QualifiedName$"), WebCoreQualifiedNamePrinter),
     
    295304            if name == 'UChar':
    296305                return UCharStringPrinter(val)
     306            if name == 'LChar':
     307                return LCharStringPrinter(val)
    297308        return None
    298309
Note: See TracChangeset for help on using the changeset viewer.