1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 1.2 +++ b/js/src/gdb/mozilla/JSObject.py Wed Dec 31 06:09:35 2014 +0100 1.3 @@ -0,0 +1,55 @@ 1.4 +# Pretty-printers for SpiderMonkey JSObjects. 1.5 + 1.6 +import gdb 1.7 +import mozilla.JSString 1.8 +import mozilla.prettyprinters as prettyprinters 1.9 +from mozilla.prettyprinters import ptr_pretty_printer, ref_pretty_printer 1.10 +from mozilla.Root import deref 1.11 + 1.12 +prettyprinters.clear_module_printers(__name__) 1.13 + 1.14 +class JSObjectTypeCache(object): 1.15 + def __init__(self, value, cache): 1.16 + # In GDB 7.4.50, with some programs, this first dummy gdb.lookup_type 1.17 + # call is required to make the second lookup_type call succeed. A GDB 1.18 + # built from the public sources as of 2012-12-12 did not require the 1.19 + # dummy lookup. 1.20 + gdb.lookup_type('js::BaseShape') 1.21 + baseshape_flags = gdb.lookup_type('js::BaseShape::Flag') 1.22 + self.flag_DELEGATE = prettyprinters.enum_value(baseshape_flags, 'js::BaseShape::DELEGATE') 1.23 + self.func_ptr_type = gdb.lookup_type('JSFunction').pointer() 1.24 + 1.25 +# There should be no need to register this for JSFunction as well, since we 1.26 +# search for pretty-printers under the names of base classes, and 1.27 +# JSFunction has JSObject as a base class. 1.28 + 1.29 +@ptr_pretty_printer('JSObject') 1.30 +class JSObjectPtrOrRef(prettyprinters.Pointer): 1.31 + def __init__(self, value, cache): 1.32 + super(JSObjectPtrOrRef, self).__init__(value, cache) 1.33 + if not cache.mod_JSObject: 1.34 + cache.mod_JSObject = JSObjectTypeCache(value, cache) 1.35 + self.otc = cache.mod_JSObject 1.36 + 1.37 + def summary(self): 1.38 + shape = deref(self.value['shape_']) 1.39 + baseshape = deref(shape['base_']) 1.40 + otype = deref(self.value['type_']) 1.41 + class_name = otype['clasp_']['name'].string() 1.42 + flags = baseshape['flags'] 1.43 + is_delegate = bool(flags & self.otc.flag_DELEGATE) 1.44 + name = None 1.45 + if class_name == 'Function': 1.46 + function = self.value 1.47 + concrete_type = function.type.strip_typedefs() 1.48 + if concrete_type.code == gdb.TYPE_CODE_REF: 1.49 + function = function.address 1.50 + function = function.cast(self.otc.func_ptr_type) 1.51 + atom = deref(function['atom_']) 1.52 + name = str(atom) if atom else '<unnamed>' 1.53 + return '[object %s%s]%s' % (class_name, 1.54 + ' ' + name if name else '', 1.55 + ' delegate' if is_delegate else '') 1.56 + 1.57 +@ref_pretty_printer('JSObject') 1.58 +def JSObjectRef(value, cache): return JSObjectPtrOrRef(value, cache)