summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorjyasskin@chromium.org <jyasskin@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2013-03-18 23:15:11 +0000
committerjyasskin@chromium.org <jyasskin@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2013-03-18 23:15:11 +0000
commit4f67e4cbd04c91fa1407f532e89fd546b6ebd37f (patch)
treef36935c75795df6d4ef088bd3ac37fd8bb330eb0
parent63179d2950fb42e0e4f059601c7e945ef0821281 (diff)
downloadchromium_src-4f67e4cbd04c91fa1407f532e89fd546b6ebd37f.zip
chromium_src-4f67e4cbd04c91fa1407f532e89fd546b6ebd37f.tar.gz
chromium_src-4f67e4cbd04c91fa1407f532e89fd546b6ebd37f.tar.bz2
Add support for pretty-printing scoped_refptr, SiteInstance and RenderProcessHost.
I switched to gdb.printing.RegexpCollectionPrettyPrinter in order to match against the concrete types of objects and to be able to wildcard scoped_refptr<*>. Review URL: https://codereview.chromium.org/12529023 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@188871 0039d316-1c4b-4281-b951-d872f2087c98
-rw-r--r--tools/gdb/gdb_chrome.py91
1 files changed, 80 insertions, 11 deletions
diff --git a/tools/gdb/gdb_chrome.py b/tools/gdb/gdb_chrome.py
index 7c9284a..299d283 100644
--- a/tools/gdb/gdb_chrome.py
+++ b/tools/gdb/gdb_chrome.py
@@ -17,6 +17,16 @@ your Python path.
import gdb
import webkit
+def typed_ptr(ptr):
+ """Prints a pointer along with its exact type.
+
+ By default, gdb would print just the address, which takes more
+ steps to interpret.
+ """
+ # Returning this as a cast expression surrounded by parentheses
+ # makes it easier to cut+paste inside of gdb.
+ return '((%s)%s)' % (ptr.dynamic_type, ptr)
+
class String16Printer(webkit.StringPrinter):
def to_string(self):
return webkit.ustring_to_string(self.val['_M_dataplus']['_M_p'])
@@ -32,17 +42,76 @@ class FilePathPrinter(object):
def to_string(self):
return self.val['path_']['_M_dataplus']['_M_p']
+class ScopedRefPtrPrinter(object):
+ def __init__(self, val):
+ self.val = val
+
+ def to_string(self):
+ return 'scoped_refptr' + typed_ptr(self.val['ptr_'])
+
+class SiteInstanceImplPrinter(object):
+ def __init__(self, val):
+ self.val = val.cast(val.dynamic_type)
+
+ def to_string(self):
+ return 'SiteInstanceImpl@%s for %s' % (
+ self.val.address, self.val['site_'])
+
+ def children(self):
+ yield ('id_', self.val['id_'])
+ yield ('has_site_', self.val['has_site_'])
+ if self.val['browsing_instance_']['ptr_']:
+ yield ('browsing_instance_', self.val['browsing_instance_']['ptr_'])
+ if self.val['process_']:
+ yield ('process_', typed_ptr(self.val['process_']))
+ if self.val['render_process_host_factory_']:
+ yield ('render_process_host_factory_',
+ self.val['render_process_host_factory_'])
+
+class RenderProcessHostImplPrinter(object):
+ def __init__(self, val):
+ self.val = val.cast(val.dynamic_type)
+
+ def to_string(self):
+ pid = ''
+ child_process_launcher_ptr = (
+ self.val['child_process_launcher_']['impl_']['data_']['ptr'])
+ if child_process_launcher_ptr:
+ context = (child_process_launcher_ptr.dereference()
+ ['context_']['ptr_'])
+ if context:
+ pid = ' PID %s' % str(context.dereference()
+ ['process_']['process_'])
+ return 'RenderProcessHostImpl@%s%s' % (self.val.address, pid)
+
+ def children(self):
+ yield ('id_', self.val['id_'])
+ yield ('render_widget_hosts_',
+ self.val['render_widget_hosts_']['data_'])
+ yield ('fast_shutdown_started_', self.val['fast_shutdown_started_'])
+ yield ('deleting_soon_', self.val['deleting_soon_'])
+ yield ('pending_views_', self.val['pending_views_'])
+ yield ('visible_widgets_', self.val['visible_widgets_'])
+ yield ('backgrounded_', self.val['backgrounded_'])
+ yield ('widget_helper_', self.val['widget_helper_'])
+ yield ('is_initialized_', self.val['is_initialized_'])
+ yield ('browser_context_', typed_ptr(self.val['browser_context_']))
+ yield ('sudden_termination_allowed_',
+ self.val['sudden_termination_allowed_'])
+ yield ('ignore_input_events_', self.val['ignore_input_events_'])
+ yield ('is_guest_', self.val['is_guest_'])
+
-def lookup_function(val):
- type_to_printer = {
- 'string16': String16Printer,
- 'GURL': GURLPrinter,
- 'FilePath': FilePathPrinter,
- }
+pp_set = gdb.printing.RegexpCollectionPrettyPrinter("chromium")
- printer = type_to_printer.get(str(val.type), None)
- if printer:
- return printer(val)
- return None
+pp_set.add_printer('FilePath', '^FilePath$', FilePathPrinter)
+pp_set.add_printer('GURL', '^GURL$', GURLPrinter)
+pp_set.add_printer('content::RenderProcessHostImpl',
+ '^content::RenderProcessHostImpl$',
+ RenderProcessHostImplPrinter)
+pp_set.add_printer('content::SiteInstanceImpl', '^content::SiteInstanceImpl$',
+ SiteInstanceImplPrinter)
+pp_set.add_printer('scoped_refptr', '^scoped_refptr<.*>$', ScopedRefPtrPrinter)
+pp_set.add_printer('string16', '^string16$', String16Printer);
-gdb.pretty_printers.append(lookup_function)
+gdb.printing.register_pretty_printer(gdb, pp_set)