diff options
author | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-04-28 14:29:10 +0000 |
---|---|---|
committer | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-04-28 14:29:10 +0000 |
commit | 2aa4a82499d4becd2284cdb482213d541b8804dd (patch) | |
tree | b80bf8bf13c3766139fbacc530efd0dd9d54394c /js/src/gdb/mozilla/JSObject.py | |
parent | Initial commit. (diff) | |
download | firefox-2aa4a82499d4becd2284cdb482213d541b8804dd.tar.xz firefox-2aa4a82499d4becd2284cdb482213d541b8804dd.zip |
Adding upstream version 86.0.1.upstream/86.0.1upstream
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'js/src/gdb/mozilla/JSObject.py')
-rw-r--r-- | js/src/gdb/mozilla/JSObject.py | 86 |
1 files changed, 86 insertions, 0 deletions
diff --git a/js/src/gdb/mozilla/JSObject.py b/js/src/gdb/mozilla/JSObject.py new file mode 100644 index 0000000000..282b47a5d1 --- /dev/null +++ b/js/src/gdb/mozilla/JSObject.py @@ -0,0 +1,86 @@ +# This Source Code Form is subject to the terms of the Mozilla Public +# License, v. 2.0. If a copy of the MPL was not distributed with this file, +# You can obtain one at http://mozilla.org/MPL/2.0/. + +# Pretty-printers for SpiderMonkey JSObjects. + +import re +import gdb +import mozilla.prettyprinters as prettyprinters +from mozilla.prettyprinters import ptr_pretty_printer, ref_pretty_printer +from mozilla.Root import deref +from mozilla.CellHeader import get_header_ptr + +prettyprinters.clear_module_printers(__name__) + + +class JSObjectTypeCache(object): + def __init__(self, value, cache): + baseshape_flags = gdb.lookup_type("js::BaseShape::Flag") + self.flag_DELEGATE = prettyprinters.enum_value( + baseshape_flags, "js::BaseShape::DELEGATE" + ) + self.func_ptr_type = gdb.lookup_type("JSFunction").pointer() + self.class_NON_NATIVE = gdb.parse_and_eval("JSClass::NON_NATIVE") + self.NativeObject_ptr_t = gdb.lookup_type("js::NativeObject").pointer() + self.BaseShape_ptr_t = gdb.lookup_type("js::BaseShape").pointer() + self.Shape_ptr_t = gdb.lookup_type("js::Shape").pointer() + self.ObjectGroup_ptr_t = gdb.lookup_type("js::ObjectGroup").pointer() + self.JSClass_ptr_t = gdb.lookup_type("JSClass").pointer() + + +# There should be no need to register this for JSFunction as well, since we +# search for pretty-printers under the names of base classes, and +# JSFunction has JSObject as a base class. + + +gdb_string_regexp = re.compile(r'(?:0x[0-9a-z]+ )?(?:<.*> )?"(.*)"', re.I) + + +@ptr_pretty_printer("JSObject") +class JSObjectPtrOrRef(prettyprinters.Pointer): + def __init__(self, value, cache): + super(JSObjectPtrOrRef, self).__init__(value, cache) + if not cache.mod_JSObject: + cache.mod_JSObject = JSObjectTypeCache(value, cache) + self.otc = cache.mod_JSObject + + def summary(self): + group = get_header_ptr(self.value, self.otc.ObjectGroup_ptr_t) + classp = get_header_ptr(group, self.otc.JSClass_ptr_t) + non_native = classp["flags"] & self.otc.class_NON_NATIVE + + # Use GDB to format the class name, but then strip off the address + # and the quotes. + class_name = str(classp["name"]) + m = gdb_string_regexp.match(class_name) + if m: + class_name = m.group(1) + + if non_native: + return "[object {}]".format(class_name) + else: + native = self.value.cast(self.otc.NativeObject_ptr_t) + shape = deref(native["shape_"]) + baseshape = get_header_ptr(shape, self.otc.BaseShape_ptr_t) + flags = baseshape["flags"] + is_delegate = bool(flags & self.otc.flag_DELEGATE) + name = None + if class_name == "Function": + function = self.value + concrete_type = function.type.strip_typedefs() + if concrete_type.code == gdb.TYPE_CODE_REF: + function = function.address + function = function.cast(self.otc.func_ptr_type) + atom = deref(function["atom_"]) + name = str(atom) if atom else "<unnamed>" + return "[object {}{}]{}".format( + class_name, + " " + name if name else "", + " delegate" if is_delegate else "", + ) + + +@ref_pretty_printer("JSObject") +def JSObjectRef(value, cache): + return JSObjectPtrOrRef(value, cache) |