OLD | NEW |
1 # Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 # Copyright (c) 2011 The Chromium Authors. All rights reserved. |
2 # Use of this source code is governed by a BSD-style license that can be | 2 # Use of this source code is governed by a BSD-style license that can be |
3 # found in the LICENSE file. | 3 # found in the LICENSE file. |
4 | 4 |
5 """GDB support for Chrome types. | 5 """GDB support for Chrome types. |
6 | 6 |
7 Add this to your gdb by amending your ~/.gdbinit as follows: | 7 Add this to your gdb by amending your ~/.gdbinit as follows: |
8 python | 8 python |
9 import sys | 9 import sys |
10 sys.path.insert(0, "/path/to/tools/gdb/") | 10 sys.path.insert(0, "/path/to/tools/gdb/") |
11 import gdb_chrome | 11 import gdb_chrome |
12 end | 12 end |
13 | 13 |
14 Use | 14 Use |
15 (gdb) p /r any_variable | 15 (gdb) p /r any_variable |
16 to print |any_variable| without using any printers. | 16 to print |any_variable| without using any printers. |
| 17 |
| 18 To interactively type Python for development of the printers: |
| 19 (gdb) python foo = gdb.parse_and_eval('bar') |
| 20 to put the C++ value 'bar' in the current scope into a Python variable 'foo'. |
| 21 Then you can interact with that variable: |
| 22 (gdb) python print foo['impl_'] |
17 """ | 23 """ |
18 | 24 |
19 import datetime | 25 import datetime |
20 import gdb | 26 import gdb |
21 import gdb.printing | 27 import gdb.printing |
22 import os | 28 import os |
23 import sys | 29 import sys |
24 | 30 |
25 sys.path.insert(0, os.path.join( | 31 sys.path.insert(0, os.path.join( |
26 os.path.dirname(os.path.abspath(__file__)), | 32 os.path.dirname(os.path.abspath(__file__)), |
(...skipping 206 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
233 | 239 |
234 class ManualConstructorPrinter(object): | 240 class ManualConstructorPrinter(object): |
235 def __init__(self, val): | 241 def __init__(self, val): |
236 self.val = val | 242 self.val = val |
237 | 243 |
238 def to_string(self): | 244 def to_string(self): |
239 return self.val['space_'].cast(self.val.type.template_argument(0)) | 245 return self.val['space_'].cast(self.val.type.template_argument(0)) |
240 pp_set.add_printer('base::ManualConstructor', '^base::ManualConstructor<.*>$', M
anualConstructorPrinter) | 246 pp_set.add_printer('base::ManualConstructor', '^base::ManualConstructor<.*>$', M
anualConstructorPrinter) |
241 | 247 |
242 | 248 |
| 249 class FlatMapPrinter(object): |
| 250 def __init__(self, val): |
| 251 self.val = val |
| 252 |
| 253 def to_string(self): |
| 254 # It would be nice to match the output of std::map which is a little |
| 255 # nicer than printing the vector of pairs. But iterating over it in |
| 256 # Python is much more complicated and this output is reasonable. |
| 257 # (Without this printer, a flat_map will output 7 lines of internal |
| 258 # template goop before the vector contents.) |
| 259 return 'base::flat_map with ' + str(self.val['impl_']['body_']) |
| 260 pp_set.add_printer('base::flat_map', '^base::flat_map<.*>$', FlatMapPrinter) |
| 261 |
| 262 |
243 class ValuePrinter(object): | 263 class ValuePrinter(object): |
244 def __init__(self, val): | 264 def __init__(self, val): |
245 self.val = val | 265 self.val = val |
246 | 266 |
247 def get_type(self): | 267 def get_type(self): |
248 return self.val['type_'] | 268 return self.val['type_'] |
249 | 269 |
250 def to_string(self): | 270 def to_string(self): |
251 typestr = str(self.get_type()) | 271 typestr = str(self.get_type()) |
252 # Trim prefix to just get the emum short name. | 272 # Trim prefix to just get the emum short name. |
(...skipping 118 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
371 yield ('sudden_termination_allowed_', | 391 yield ('sudden_termination_allowed_', |
372 self.val['sudden_termination_allowed_']) | 392 self.val['sudden_termination_allowed_']) |
373 yield ('ignore_input_events_', self.val['ignore_input_events_']) | 393 yield ('ignore_input_events_', self.val['ignore_input_events_']) |
374 yield ('is_guest_', self.val['is_guest_']) | 394 yield ('is_guest_', self.val['is_guest_']) |
375 pp_set.add_printer('content::RenderProcessHostImpl', | 395 pp_set.add_printer('content::RenderProcessHostImpl', |
376 '^content::RenderProcessHostImpl$', | 396 '^content::RenderProcessHostImpl$', |
377 RenderProcessHostImplPrinter) | 397 RenderProcessHostImplPrinter) |
378 | 398 |
379 | 399 |
380 gdb.printing.register_pretty_printer(gdb, pp_set, replace=_DEBUGGING) | 400 gdb.printing.register_pretty_printer(gdb, pp_set, replace=_DEBUGGING) |
OLD | NEW |