| OLD | NEW |
| 1 # Copyright (C) 2010, Google Inc. All rights reserved. | 1 # Copyright (C) 2010, Google Inc. All rights reserved. |
| 2 # | 2 # |
| 3 # Redistribution and use in source and binary forms, with or without | 3 # Redistribution and use in source and binary forms, with or without |
| 4 # modification, are permitted provided that the following conditions are | 4 # modification, are permitted provided that the following conditions are |
| 5 # met: | 5 # met: |
| 6 # | 6 # |
| 7 # * Redistributions of source code must retain the above copyright | 7 # * Redistributions of source code must retain the above copyright |
| 8 # notice, this list of conditions and the following disclaimer. | 8 # notice, this list of conditions and the following disclaimer. |
| 9 # * Redistributions in binary form must reproduce the above | 9 # * Redistributions in binary form must reproduce the above |
| 10 # copyright notice, this list of conditions and the following disclaimer | 10 # copyright notice, this list of conditions and the following disclaimer |
| (...skipping 92 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 103 | 103 |
| 104 class LCharStringPrinter(StringPrinter): | 104 class LCharStringPrinter(StringPrinter): |
| 105 "Print a LChar*; we must guess at the length" | 105 "Print a LChar*; we must guess at the length" |
| 106 def to_string(self): | 106 def to_string(self): |
| 107 return lstring_to_string(self.val) | 107 return lstring_to_string(self.val) |
| 108 | 108 |
| 109 | 109 |
| 110 class WTFAtomicStringPrinter(StringPrinter): | 110 class WTFAtomicStringPrinter(StringPrinter): |
| 111 "Print a WTF::AtomicString" | 111 "Print a WTF::AtomicString" |
| 112 def to_string(self): | 112 def to_string(self): |
| 113 return self.val['m_string'] | 113 return self.val['string_'] |
| 114 | 114 |
| 115 | 115 |
| 116 class WTFCStringPrinter(StringPrinter): | 116 class WTFCStringPrinter(StringPrinter): |
| 117 "Print a WTF::CString" | 117 "Print a WTF::CString" |
| 118 def to_string(self): | 118 def to_string(self): |
| 119 # The CString holds a buffer, which is a refptr to a WTF::CStringBuffer. | 119 # The CString holds a buffer, which is a refptr to a WTF::CStringBuffer. |
| 120 buf_ptr = self.val['m_buffer']['m_ptr'] | 120 buf_ptr = self.val['buffer_']['ptr_'] |
| 121 if not buf_ptr: | 121 if not buf_ptr: |
| 122 return 0 | 122 return 0 |
| 123 data = (buf_ptr + 1).cast(gdb.lookup_type('char').pointer()) | 123 data = (buf_ptr + 1).cast(gdb.lookup_type('char').pointer()) |
| 124 length = self.val['m_buffer']['m_ptr']['m_length'] | 124 length = self.val['buffer_']['ptr_']['length_'] |
| 125 return ''.join([chr((data + i).dereference()) for i in range(length)]) | 125 return ''.join([chr((data + i).dereference()) for i in range(length)]) |
| 126 | 126 |
| 127 | 127 |
| 128 class WTFStringImplPrinter(StringPrinter): | 128 class WTFStringImplPrinter(StringPrinter): |
| 129 "Print a WTF::StringImpl" | 129 "Print a WTF::StringImpl" |
| 130 def get_length(self): | 130 def get_length(self): |
| 131 return self.val['m_length'] | 131 return self.val['length_'] |
| 132 | 132 |
| 133 def to_string(self): | 133 def to_string(self): |
| 134 chars_start = self.val.address + 1 | 134 chars_start = self.val.address + 1 |
| 135 if self.is_8bit(): | 135 if self.is_8bit(): |
| 136 return lstring_to_string(chars_start.cast(gdb.lookup_type('char').po
inter()), | 136 return lstring_to_string(chars_start.cast(gdb.lookup_type('char').po
inter()), |
| 137 self.get_length()) | 137 self.get_length()) |
| 138 return ustring_to_string(chars_start.cast(gdb.lookup_type('UChar').point
er()), | 138 return ustring_to_string(chars_start.cast(gdb.lookup_type('UChar').point
er()), |
| 139 self.get_length()) | 139 self.get_length()) |
| 140 | 140 |
| 141 def is_8bit(self): | 141 def is_8bit(self): |
| 142 return self.val['m_is8Bit'] | 142 return self.val['is8_bit_'] |
| 143 | 143 |
| 144 | 144 |
| 145 class WTFStringPrinter(StringPrinter): | 145 class WTFStringPrinter(StringPrinter): |
| 146 "Print a WTF::String" | 146 "Print a WTF::String" |
| 147 def stringimpl_ptr(self): | 147 def stringimpl_ptr(self): |
| 148 return self.val['m_impl']['m_ptr'] | 148 return self.val['impl_']['ptr_'] |
| 149 | 149 |
| 150 def get_length(self): | 150 def get_length(self): |
| 151 if not self.stringimpl_ptr(): | 151 if not self.stringimpl_ptr(): |
| 152 return 0 | 152 return 0 |
| 153 return WTFStringImplPrinter(self.stringimpl_ptr().dereference()).get_len
gth() | 153 return WTFStringImplPrinter(self.stringimpl_ptr().dereference()).get_len
gth() |
| 154 | 154 |
| 155 def to_string(self): | 155 def to_string(self): |
| 156 if not self.stringimpl_ptr(): | 156 if not self.stringimpl_ptr(): |
| 157 return '(null)' | 157 return '(null)' |
| 158 return self.stringimpl_ptr().dereference() | 158 return self.stringimpl_ptr().dereference() |
| 159 | 159 |
| 160 | 160 |
| 161 | 161 |
| 162 class blinkKURLPrinter(StringPrinter): | 162 class blinkKURLPrinter(StringPrinter): |
| 163 "Print a blink::KURL" | 163 "Print a blink::KURL" |
| 164 def to_string(self): | 164 def to_string(self): |
| 165 return WTFStringPrinter(self.val['m_string']).to_string() | 165 return WTFStringPrinter(self.val['string_']).to_string() |
| 166 | 166 |
| 167 | 167 |
| 168 class blinkLayoutUnitPrinter: | 168 class blinkLayoutUnitPrinter: |
| 169 "Print a blink::LayoutUnit" | 169 "Print a blink::LayoutUnit" |
| 170 def __init__(self, val): | 170 def __init__(self, val): |
| 171 self.val = val | 171 self.val = val |
| 172 | 172 |
| 173 def to_string(self): | 173 def to_string(self): |
| 174 return "%.14gpx" % (self.val['m_value'] / 64.0) | 174 return "%.14gpx" % (self.val['value_'] / 64.0) |
| 175 | 175 |
| 176 | 176 |
| 177 class blinkLayoutSizePrinter: | 177 class blinkLayoutSizePrinter: |
| 178 "Print a blink::LayoutSize" | 178 "Print a blink::LayoutSize" |
| 179 def __init__(self, val): | 179 def __init__(self, val): |
| 180 self.val = val | 180 self.val = val |
| 181 | 181 |
| 182 def to_string(self): | 182 def to_string(self): |
| 183 return 'LayoutSize(%s, %s)' % (blinkLayoutUnitPrinter(self.val['m_width'
]).to_string(), blinkLayoutUnitPrinter(self.val['m_height']).to_string()) | 183 return 'LayoutSize(%s, %s)' % ( |
| 184 blinkLayoutUnitPrinter(self.val['width_']).to_string(), |
| 185 blinkLayoutUnitPrinter(self.val['height_']).to_string()) |
| 184 | 186 |
| 185 | 187 |
| 186 class blinkLayoutPointPrinter: | 188 class blinkLayoutPointPrinter: |
| 187 "Print a blink::LayoutPoint" | 189 "Print a blink::LayoutPoint" |
| 188 def __init__(self, val): | 190 def __init__(self, val): |
| 189 self.val = val | 191 self.val = val |
| 190 | 192 |
| 191 def to_string(self): | 193 def to_string(self): |
| 192 return 'LayoutPoint(%s, %s)' % (blinkLayoutUnitPrinter(self.val['m_x']).
to_string(), blinkLayoutUnitPrinter(self.val['m_y']).to_string()) | 194 return 'LayoutPoint(%s, %s)' % ( |
| 195 blinkLayoutUnitPrinter(self.val['x_']).to_string(), |
| 196 blinkLayoutUnitPrinter(self.val['y_']).to_string()) |
| 193 | 197 |
| 194 | 198 |
| 195 class blinkQualifiedNamePrinter(StringPrinter): | 199 class blinkQualifiedNamePrinter(StringPrinter): |
| 196 "Print a blink::QualifiedName" | 200 "Print a blink::QualifiedName" |
| 197 | 201 |
| 198 def __init__(self, val): | 202 def __init__(self, val): |
| 199 super(blinkQualifiedNamePrinter, self).__init__(val) | 203 super(blinkQualifiedNamePrinter, self).__init__(val) |
| 200 self.prefix_length = 0 | 204 self.prefix_length = 0 |
| 201 self.length = 0 | 205 self.length = 0 |
| 202 if self.val['m_impl']: | 206 if self.val['impl_']: |
| 203 self.prefix_printer = WTFStringPrinter( | 207 self.prefix_printer = WTFStringPrinter( |
| 204 self.val['m_impl']['m_ptr']['m_prefix']['m_string']) | 208 self.val['impl_']['ptr_']['prefix_']['string_']) |
| 205 self.local_name_printer = WTFStringPrinter( | 209 self.local_name_printer = WTFStringPrinter( |
| 206 self.val['m_impl']['m_ptr']['m_localName']['m_string']) | 210 self.val['impl_']['ptr_']['local_name_']['string_']) |
| 207 self.prefix_length = self.prefix_printer.get_length() | 211 self.prefix_length = self.prefix_printer.get_length() |
| 208 if self.prefix_length > 0: | 212 if self.prefix_length > 0: |
| 209 self.length = (self.prefix_length + 1 + | 213 self.length = (self.prefix_length + 1 + |
| 210 self.local_name_printer.get_length()) | 214 self.local_name_printer.get_length()) |
| 211 else: | 215 else: |
| 212 self.length = self.local_name_printer.get_length() | 216 self.length = self.local_name_printer.get_length() |
| 213 | 217 |
| 214 def get_length(self): | 218 def get_length(self): |
| 215 return self.length | 219 return self.length |
| 216 | 220 |
| (...skipping 16 matching lines...) Expand all Loading... |
| 233 def to_string(self): | 237 def to_string(self): |
| 234 return "(%gpx, %g%%)" % (self.val['pixels'], self.val['percent']) | 238 return "(%gpx, %g%%)" % (self.val['pixels'], self.val['percent']) |
| 235 | 239 |
| 236 | 240 |
| 237 class BlinkLengthPrinter: | 241 class BlinkLengthPrinter: |
| 238 """Print a blink::Length.""" | 242 """Print a blink::Length.""" |
| 239 def __init__(self, val): | 243 def __init__(self, val): |
| 240 self.val = val | 244 self.val = val |
| 241 | 245 |
| 242 def to_string(self): | 246 def to_string(self): |
| 243 ltype = self.val['m_type'] | 247 ltype = self.val['type_'] |
| 244 if self.val['m_isFloat']: | 248 if self.val['is_float_']: |
| 245 val = self.val['m_floatValue'] | 249 val = self.val['float_value_'] |
| 246 else: | 250 else: |
| 247 val = int(self.val['m_intValue']) | 251 val = int(self.val['int_value_']) |
| 248 | 252 |
| 249 quirk = '' | 253 quirk = '' |
| 250 if self.val['m_quirk']: | 254 if self.val['quirk_']: |
| 251 quirk = ', quirk=true' | 255 quirk = ', quirk=true' |
| 252 | 256 |
| 253 if ltype == 0: | 257 if ltype == 0: |
| 254 return 'Length(Auto)' | 258 return 'Length(Auto)' |
| 255 if ltype == 1: | 259 if ltype == 1: |
| 256 return 'Length(%g%%, Percent%s)' % (val, quirk) | 260 return 'Length(%g%%, Percent%s)' % (val, quirk) |
| 257 if ltype == 2: | 261 if ltype == 2: |
| 258 return 'Length(%g, Fixed%s)' % (val, quirk) | 262 return 'Length(%g, Fixed%s)' % (val, quirk) |
| 259 if ltype == 3: | 263 if ltype == 3: |
| 260 return 'Length(Intrinsic)' | 264 return 'Length(Intrinsic)' |
| (...skipping 74 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 335 return ('[%d]' % count, element) | 339 return ('[%d]' % count, element) |
| 336 | 340 |
| 337 # Python version < 3 compatibility: | 341 # Python version < 3 compatibility: |
| 338 def next(self): | 342 def next(self): |
| 339 return self.__next__() | 343 return self.__next__() |
| 340 | 344 |
| 341 def __init__(self, val): | 345 def __init__(self, val): |
| 342 self.val = val | 346 self.val = val |
| 343 | 347 |
| 344 def children(self): | 348 def children(self): |
| 345 start = self.val['m_buffer'] | 349 start = self.val['buffer_'] |
| 346 return self.Iterator(start, start + self.val['m_size']) | 350 return self.Iterator(start, start + self.val['size_']) |
| 347 | 351 |
| 348 def to_string(self): | 352 def to_string(self): |
| 349 return ('%s of length %d, capacity %d' | 353 return ('%s of length %d, capacity %d' |
| 350 % ('WTF::Vector', self.val['m_size'], self.val['m_capacity'])) | 354 % ('WTF::Vector', self.val['size_'], self.val['capacity_'])) |
| 351 | 355 |
| 352 def display_hint(self): | 356 def display_hint(self): |
| 353 return 'array' | 357 return 'array' |
| 354 | 358 |
| 355 | 359 |
| 356 # Copied from //tools/gdb/gdb_chrome.py | 360 # Copied from //tools/gdb/gdb_chrome.py |
| 357 def typed_ptr(ptr): | 361 def typed_ptr(ptr): |
| 358 """Prints a pointer along with its exact type. | 362 """Prints a pointer along with its exact type. |
| 359 | 363 |
| 360 By default, gdb would print just the address, which takes more | 364 By default, gdb would print just the address, which takes more |
| 361 steps to interpret. | 365 steps to interpret. |
| 362 """ | 366 """ |
| 363 # Returning this as a cast expression surrounded by parentheses | 367 # Returning this as a cast expression surrounded by parentheses |
| 364 # makes it easier to cut+paste inside of gdb. | 368 # makes it easier to cut+paste inside of gdb. |
| 365 return '((%s)%s)' % (ptr.dynamic_type, ptr) | 369 return '((%s)%s)' % (ptr.dynamic_type, ptr) |
| 366 | 370 |
| 367 | 371 |
| 368 class WTFRefOrOwnPtrPrinter: | 372 class WTFRefOrOwnPtrPrinter: |
| 369 def __init__(self, val): | 373 def __init__(self, val): |
| 370 self.val = val | 374 self.val = val |
| 371 | 375 |
| 372 def to_string(self): | 376 def to_string(self): |
| 373 type_without_param = re.sub(r'<.*>', '', self.val.type.name) | 377 type_without_param = re.sub(r'<.*>', '', self.val.type.name) |
| 374 return '%s%s' % (type_without_param, typed_ptr(self.val['m_ptr'])) | 378 return '%s%s' % (type_without_param, typed_ptr(self.val['ptr_'])) |
| 375 | 379 |
| 376 | 380 |
| 377 class BlinkDataRefPrinter: | 381 class BlinkDataRefPrinter: |
| 378 def __init__(self, val): | 382 def __init__(self, val): |
| 379 self.val = val | 383 self.val = val |
| 380 | 384 |
| 381 def to_string(self): | 385 def to_string(self): |
| 382 return 'DataRef(%s)' % ( | 386 return 'DataRef(%s)' % ( |
| 383 WTFRefOrOwnPtrPrinter(self.val['m_data']).to_string()) | 387 WTFRefOrOwnPtrPrinter(self.val['data_']).to_string()) |
| 384 | 388 |
| 385 | 389 |
| 386 def add_pretty_printers(): | 390 def add_pretty_printers(): |
| 387 pretty_printers = ( | 391 pretty_printers = ( |
| 388 (re.compile("^WTF::Vector<.*>$"), WTFVectorPrinter), | 392 (re.compile("^WTF::Vector<.*>$"), WTFVectorPrinter), |
| 389 (re.compile("^WTF::AtomicString$"), WTFAtomicStringPrinter), | 393 (re.compile("^WTF::AtomicString$"), WTFAtomicStringPrinter), |
| 390 (re.compile("^WTF::CString$"), WTFCStringPrinter), | 394 (re.compile("^WTF::CString$"), WTFCStringPrinter), |
| 391 (re.compile("^WTF::String$"), WTFStringPrinter), | 395 (re.compile("^WTF::String$"), WTFStringPrinter), |
| 392 (re.compile("^WTF::StringImpl$"), WTFStringImplPrinter), | 396 (re.compile("^WTF::StringImpl$"), WTFStringImplPrinter), |
| 393 (re.compile("^blink::KURL$"), blinkKURLPrinter), | 397 (re.compile("^blink::KURL$"), blinkKURLPrinter), |
| (...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 445 val = gdb.Frame.read_var(frame, arg) | 449 val = gdb.Frame.read_var(frame, arg) |
| 446 except: | 450 except: |
| 447 print("No such variable, or invalid type") | 451 print("No such variable, or invalid type") |
| 448 return | 452 return |
| 449 | 453 |
| 450 target_type = str(val.type.target().strip_typedefs()) | 454 target_type = str(val.type.target().strip_typedefs()) |
| 451 if target_type == str(node_type): | 455 if target_type == str(node_type): |
| 452 stack = [] | 456 stack = [] |
| 453 while val: | 457 while val: |
| 454 stack.append([val, | 458 stack.append([val, |
| 455 val.cast(element_type.pointer()).dereference()['m_tagName']]
) | 459 val.cast(element_type.pointer()).dereference()[ |
| 456 val = val.dereference()['m_parent'] | 460 'tag_name_']]) |
| 461 val = val.dereference()['parent_'] |
| 457 | 462 |
| 458 padding = '' | 463 padding = '' |
| 459 while len(stack) > 0: | 464 while len(stack) > 0: |
| 460 pair = stack.pop() | 465 pair = stack.pop() |
| 461 print(padding, pair[1], pair[0]) | 466 print(padding, pair[1], pair[0]) |
| 462 padding = padding + ' ' | 467 padding = padding + ' ' |
| 463 else: | 468 else: |
| 464 print('Sorry: I don\'t know how to deal with %s yet.' % target_type) | 469 print('Sorry: I don\'t know how to deal with %s yet.' % target_type) |
| 465 | 470 |
| 466 | 471 |
| 467 PrintPathToRootCommand() | 472 PrintPathToRootCommand() |
| OLD | NEW |