@@ -0,0 +1,2628 @@
+# Copyright (c) 2010 The Chromium Authors. All rights reserved.%0A# Use of this source code is governed by a BSD-style license that can be%0A# found in the LICENSE file.%0A%0A%22%22%22GDB support for WebKit types.%0A%0AAdd this to your gdb by amending your ~/.gdbinit as follows:%0A  python%0A  import sys%0A  sys.path.insert(0, %22/path/to/tools/gdb/%22)%0A  import webkit%0A%22%22%22%0A%0Aimport gdb%0Aimport struct%0A%0Adef ustring_to_string(ptr, length=None):%0A    %22%22%22Convert a pointer to UTF-16 data into a Python Unicode string.%0A%0A    ptr and length are both gdb.Value objects.%0A    If length is unspecified, will guess at the length.%22%22%22%0A    extra = ''%0A    if length is None:%0A        # Try to guess at the length.%0A        for i in xrange(0, 2048):%0A            if int((ptr + i).dereference()) == 0:%0A                length = i%0A                break%0A        if length is None:%0A            length = 256%0A            extra = u' (no trailing NUL found)'%0A    else:%0A        length = int(length)%0A%0A    char_vals = %5Bint((ptr + i).dereference()) for i in xrange(length)%5D%0A    string = struct.pack('H' * length, *char_vals).decode('utf-16', 'replace')%0A%0A    return string + extra%0A%0A%0Aclass StringPrinter:%0A    %22Shared code between different string-printing classes%22%0A    def __init__(self, val):%0A        self.val = val%0A%0A    def display_hint(self):%0A        return 'string'%0A%0A%0Aclass UCharStringPrinter(StringPrinter):%0A    %22Print a UChar*; we must guess at the length%22%0A    def to_string(self):%0A        return ustring_to_string(self.val)%0A%0A%0Aclass WebCoreAtomicStringPrinter(StringPrinter):%0A    %22Print a WebCore::AtomicString%22%0A    def to_string(self):%0A        return self.val%5B'm_string'%5D%0A%0A%0Aclass WebCoreStringPrinter(StringPrinter):%0A    %22Print a WebCore::String%22%0A    def get_length(self):%0A        if not self.val%5B'm_impl'%5D%5B'm_ptr'%5D:%0A            return 0%0A        return self.val%5B'm_impl'%5D%5B'm_ptr'%5D%5B'm_length'%5D%0A%0A    def to_string(self):%0A        if self.get_length() == 0:%0A            return '(null)'%0A%0A        return ustring_to_string(self.val%5B'm_impl'%5D%5B'm_ptr'%5D%5B'm_data'%5D,%0A                                 self.get_length())%0A%0A%0Adef lookup_function(val):%0A    %22%22%22Function used to load pretty printers; will be passed to GDB.%22%22%22%0A    lookup_tag = val.type.tag%0A    printers = %7B%0A        %22WebCore::AtomicString%22: WebCoreAtomicStringPrinter,%0A        %22WebCore::String%22: WebCoreStringPrinter,%0A    %7D%0A    name = val.type.tag%0A    if name in printers:%0A        return printers%5Bname%5D(val)%0A%0A    if val.type.code == gdb.TYPE_CODE_PTR:%0A        name = str(val.type.target().unqualified())%0A        if name == 'UChar':%0A            return UCharStringPrinter(val)%0A%0A    return None%0A%0A%0Agdb.pretty_printers.append(lookup_function)%0A

add a gdb pretty-print module for WebCore types