summaryrefslogtreecommitdiffstats
path: root/tools/gdb
diff options
context:
space:
mode:
authorevan@chromium.org <evan@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2010-02-17 12:21:53 +0000
committerevan@chromium.org <evan@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2010-02-17 12:21:53 +0000
commit529ff07efb8f07aa5a5ea54a22ce7443f0439a75 (patch)
tree930c12352e1e5b2dadbbbf0aad4a7fe31b8f4049 /tools/gdb
parente37f934991547accccd176d1d57d733eacde21ef (diff)
downloadchromium_src-529ff07efb8f07aa5a5ea54a22ce7443f0439a75.zip
chromium_src-529ff07efb8f07aa5a5ea54a22ce7443f0439a75.tar.gz
chromium_src-529ff07efb8f07aa5a5ea54a22ce7443f0439a75.tar.bz2
Improved debugging python GDB helpers.
Added printing for WebCore::QualifiedName. Added a new command that will print the path from a WebCore::Node to the root. The command is really only half-baked, but hopefully will provide a good starting point for other new commands. (And it did help me track down an SVG bug.) BUG=none TEST=none Patch from Bryan Yeung <bryeung@chromium.org>. Review URL: http://codereview.chromium.org/598051 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@39215 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'tools/gdb')
-rw-r--r--tools/gdb/webkit.py77
1 files changed, 76 insertions, 1 deletions
diff --git a/tools/gdb/webkit.py b/tools/gdb/webkit.py
index 2e1cf12..11dfd06 100644
--- a/tools/gdb/webkit.py
+++ b/tools/gdb/webkit.py
@@ -38,7 +38,7 @@ def ustring_to_string(ptr, length=None):
return string + extra
-class StringPrinter:
+class StringPrinter(object):
"Shared code between different string-printing classes"
def __init__(self, val):
self.val = val
@@ -74,12 +74,47 @@ class WebCoreStringPrinter(StringPrinter):
self.get_length())
+class WebCoreQualifiedNamePrinter(StringPrinter):
+ "Print a WebCore::QualifiedName"
+
+ def __init__(self, val):
+ super(WebCoreQualifiedNamePrinter, self).__init__(val)
+ self.prefix_length = 0
+ self.length = 0
+ if self.val['m_impl']:
+ self.prefix_printer = WebCoreStringPrinter(
+ self.val['m_impl']['m_prefix']['m_string'])
+ self.local_name_printer = WebCoreStringPrinter(
+ self.val['m_impl']['m_localName']['m_string'])
+ self.prefix_length = self.prefix_printer.get_length()
+ if self.prefix_length > 0:
+ self.length = (self.prefix_length + 1 +
+ self.local_name_printer.get_length())
+ else:
+ self.length = self.local_name_printer.get_length()
+
+ def get_length(self):
+ return self.length
+
+ def to_string(self):
+ if self.get_length() == 0:
+ return "(null)"
+ else:
+ if self.prefix_length > 0:
+ return (self.prefix_printer.to_string() + ":" +
+ self.local_name_printer.to_string())
+ else:
+ return self.local_name_printer.to_string()
+
+
+
def lookup_function(val):
"""Function used to load pretty printers; will be passed to GDB."""
lookup_tag = val.type.tag
printers = {
"WebCore::AtomicString": WebCoreAtomicStringPrinter,
"WebCore::String": WebCoreStringPrinter,
+ "WebCore::QualifiedName": WebCoreQualifiedNamePrinter,
}
name = val.type.tag
if name in printers:
@@ -94,3 +129,43 @@ def lookup_function(val):
gdb.pretty_printers.append(lookup_function)
+
+
+
+class PrintPathToRootCommand(gdb.Command):
+ """Command for printing WebKit Node trees.
+Usage: printpathtoroot variable_name
+"""
+
+ def __init__(self):
+ super(PrintPathToRootCommand, self).__init__("printpathtoroot",
+ gdb.COMMAND_SUPPORT,
+ gdb.COMPLETE_NONE)
+
+ def invoke(self, arg, from_tty):
+ element_type = gdb.lookup_type('WebCore::Element')
+ node_type = gdb.lookup_type('WebCore::Node')
+ frame = gdb.selected_frame()
+ try:
+ val = gdb.Frame.read_var(frame, arg)
+ except:
+ print "No such variable, or invalid type"
+ return
+
+ target_type = str(val.type.target().strip_typedefs())
+ if target_type == str(node_type):
+ stack = []
+ while val:
+ stack.append([val,
+ val.cast(element_type.pointer()).dereference()['m_tagName']])
+ val = val.dereference()['m_parent']
+
+ padding = ''
+ while len(stack) > 0:
+ pair = stack.pop()
+ print padding, pair[1], pair[0]
+ padding = padding + ' '
+ else:
+ print 'Sorry: I don\'t know how to deal with %s yet.' % target_type
+
+PrintPathToRootCommand()