js/src/gdb/mozilla/JSObject.py

Sat, 03 Jan 2015 20:18:00 +0100

author
Michael Schloh von Bennewitz <michael@schloh.com>
date
Sat, 03 Jan 2015 20:18:00 +0100
branch
TOR_BUG_3246
changeset 7
129ffea94266
permissions
-rw-r--r--

Conditionally enable double key logic according to:
private browsing mode or privacy.thirdparty.isolate preference and
implement in GetCookieStringCommon and FindCookie where it counts...
With some reservations of how to convince FindCookie users to test
condition and pass a nullptr when disabling double key logic.

michael@0 1 # Pretty-printers for SpiderMonkey JSObjects.
michael@0 2
michael@0 3 import gdb
michael@0 4 import mozilla.JSString
michael@0 5 import mozilla.prettyprinters as prettyprinters
michael@0 6 from mozilla.prettyprinters import ptr_pretty_printer, ref_pretty_printer
michael@0 7 from mozilla.Root import deref
michael@0 8
michael@0 9 prettyprinters.clear_module_printers(__name__)
michael@0 10
michael@0 11 class JSObjectTypeCache(object):
michael@0 12 def __init__(self, value, cache):
michael@0 13 # In GDB 7.4.50, with some programs, this first dummy gdb.lookup_type
michael@0 14 # call is required to make the second lookup_type call succeed. A GDB
michael@0 15 # built from the public sources as of 2012-12-12 did not require the
michael@0 16 # dummy lookup.
michael@0 17 gdb.lookup_type('js::BaseShape')
michael@0 18 baseshape_flags = gdb.lookup_type('js::BaseShape::Flag')
michael@0 19 self.flag_DELEGATE = prettyprinters.enum_value(baseshape_flags, 'js::BaseShape::DELEGATE')
michael@0 20 self.func_ptr_type = gdb.lookup_type('JSFunction').pointer()
michael@0 21
michael@0 22 # There should be no need to register this for JSFunction as well, since we
michael@0 23 # search for pretty-printers under the names of base classes, and
michael@0 24 # JSFunction has JSObject as a base class.
michael@0 25
michael@0 26 @ptr_pretty_printer('JSObject')
michael@0 27 class JSObjectPtrOrRef(prettyprinters.Pointer):
michael@0 28 def __init__(self, value, cache):
michael@0 29 super(JSObjectPtrOrRef, self).__init__(value, cache)
michael@0 30 if not cache.mod_JSObject:
michael@0 31 cache.mod_JSObject = JSObjectTypeCache(value, cache)
michael@0 32 self.otc = cache.mod_JSObject
michael@0 33
michael@0 34 def summary(self):
michael@0 35 shape = deref(self.value['shape_'])
michael@0 36 baseshape = deref(shape['base_'])
michael@0 37 otype = deref(self.value['type_'])
michael@0 38 class_name = otype['clasp_']['name'].string()
michael@0 39 flags = baseshape['flags']
michael@0 40 is_delegate = bool(flags & self.otc.flag_DELEGATE)
michael@0 41 name = None
michael@0 42 if class_name == 'Function':
michael@0 43 function = self.value
michael@0 44 concrete_type = function.type.strip_typedefs()
michael@0 45 if concrete_type.code == gdb.TYPE_CODE_REF:
michael@0 46 function = function.address
michael@0 47 function = function.cast(self.otc.func_ptr_type)
michael@0 48 atom = deref(function['atom_'])
michael@0 49 name = str(atom) if atom else '<unnamed>'
michael@0 50 return '[object %s%s]%s' % (class_name,
michael@0 51 ' ' + name if name else '',
michael@0 52 ' delegate' if is_delegate else '')
michael@0 53
michael@0 54 @ref_pretty_printer('JSObject')
michael@0 55 def JSObjectRef(value, cache): return JSObjectPtrOrRef(value, cache)

mercurial