OLD | NEW |
1 #!/usr/bin/python | 1 #!/usr/bin/python |
2 # Copyright (c) 2011 The Chromium Authors. All rights reserved. | 2 # Copyright (c) 2011 The Chromium Authors. All rights reserved. |
3 # Use of this source code is governed by a BSD-style license that can be | 3 # Use of this source code is governed by a BSD-style license that can be |
4 # found in the LICENSE file. | 4 # found in the LICENSE file. |
5 | 5 |
6 """GDB support for Chrome types. | 6 """GDB support for Chrome types. |
7 | 7 |
8 Add this to your gdb by amending your ~/.gdbinit as follows: | 8 Add this to your gdb by amending your ~/.gdbinit as follows: |
9 python | 9 python |
10 import sys | 10 import sys |
11 sys.path.insert(0, "/path/to/tools/gdb/") | 11 sys.path.insert(0, "/path/to/tools/gdb/") |
12 import gdb_chrome | 12 import gdb_chrome |
13 | 13 |
14 This module relies on the WebKit gdb module already existing in | 14 This module relies on the WebKit gdb module already existing in |
15 your Python path. | 15 your Python path. |
16 """ | 16 """ |
17 | 17 |
18 import gdb | 18 import gdb |
19 import webkit | 19 import webkit |
20 | 20 |
21 class String16Printer(webkit.StringPrinter): | 21 class String16Printer(webkit.StringPrinter): |
22 def to_string(self): | 22 def to_string(self): |
23 return webkit.ustring_to_string(self.val['_M_dataplus']['_M_p']) | 23 return webkit.ustring_to_string(self.val['_M_dataplus']['_M_p']) |
24 | 24 |
25 class GURLPrinter(webkit.StringPrinter): | 25 class GURLPrinter(webkit.StringPrinter): |
26 def to_string(self): | 26 def to_string(self): |
27 return self.val['spec_'] | 27 return self.val['spec_'] |
28 | 28 |
| 29 class FilePathPrinter(object): |
| 30 def __init__(self, val): |
| 31 self.val = val |
| 32 |
| 33 def to_string(self): |
| 34 return self.val['path_']['_M_dataplus']['_M_p'] |
| 35 |
| 36 |
29 def lookup_function(val): | 37 def lookup_function(val): |
30 typ = str(val.type) | 38 type_to_printer = { |
31 if typ == 'string16': | 39 'string16': String16Printer, |
32 return String16Printer(val) | 40 'GURL': GURLPrinter, |
33 elif typ == 'GURL': | 41 'FilePath': FilePathPrinter, |
34 return GURLPrinter(val) | 42 } |
| 43 |
| 44 printer = type_to_printer.get(str(val.type), None) |
| 45 if printer: |
| 46 return printer(val) |
35 return None | 47 return None |
36 | 48 |
37 gdb.pretty_printers.append(lookup_function) | 49 gdb.pretty_printers.append(lookup_function) |
OLD | NEW |