Changeset 102420 in webkit
- Timestamp:
- Dec 8, 2011 7:24:30 PM (12 years ago)
- Location:
- trunk/Tools
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/Tools/ChangeLog
r102419 r102420 1 2011-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 1 22 2011-12-08 Pierre Rossi <pierre.rossi@gmail.com> 2 23 -
trunk/Tools/gdb/webkit.py
r102083 r102420 41 41 42 42 43 def 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 43 59 def 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. 45 61 46 62 ptr and length are both gdb.Value objects. 47 63 If length is unspecified, will guess at the length.""" 48 e xtra= ''64 error_message = '' 49 65 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) 64 67 else: 65 68 length = int(length) 66 67 69 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 74 def 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 71 86 72 87 … … 86 101 87 102 103 class 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 88 109 class WTFAtomicStringPrinter(StringPrinter): 89 110 "Print a WTF::AtomicString" … … 101 122 102 123 124 class 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 103 138 class WTFStringPrinter(StringPrinter): 104 139 "Print a WTF::String" 140 def stringimpl_ptr(self): 141 return self.val['m_impl']['m_ptr'] 142 105 143 def get_length(self): 106 if not self. val['m_impl']['m_ptr']:144 if not self.stringimpl_ptr(): 107 145 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(): 115 150 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 154 JSCUStringPrinter = WTFStringImplPrinter 147 155 148 156 … … 272 280 (re.compile("^WTF::CString$"), WTFCStringPrinter), 273 281 (re.compile("^WTF::String$"), WTFStringPrinter), 282 (re.compile("^WTF::StringImpl$"), WTFStringImplPrinter), 274 283 (re.compile("^WebCore::KURLGooglePrivate$"), WebCoreKURLGooglePrivatePrinter), 275 284 (re.compile("^WebCore::QualifiedName$"), WebCoreQualifiedNamePrinter), … … 295 304 if name == 'UChar': 296 305 return UCharStringPrinter(val) 306 if name == 'LChar': 307 return LCharStringPrinter(val) 297 308 return None 298 309
Note: See TracChangeset
for help on using the changeset viewer.