Backed out changeset 7637a2a6e365 (bug 1606856) for causing spidermonkey bustages on JSObject.h

This commit is contained in:
Arthur Iakab 2020-01-04 17:25:04 +02:00
parent e5b12e23e3
commit 0c97593623
12 changed files with 12 additions and 217 deletions

View File

@ -148,8 +148,8 @@ are drawn from the list below.
EXECUTABLE to run the tests.
--srcdir=SRCDIR
Find the sources corresponding to OBJDIR/dist/bin/libmozjs.so in SRCDIR.
Without this option, we use the parent of the directory containing
Find the sources corresponding to LIBDIR/libmozjs.so in SRCDIR. Without
this option, we use the parent of the directory containing
'run-tests.py'. Note that SRCDIR must be a complete SpiderMonkey source
directory, as our tests #include internal SpiderMonkey header files (to
test pretty-printers for internal types, like parse nodes.)
@ -161,9 +161,9 @@ are drawn from the list below.
--builddir=BUILDDIR
Build the C++ executable that GDB debugs to run the tests in BUILDDIR.
If omitted, create a 'gdb-tests' subdirectory of OBJDIR/js/src.
If omitted, create a 'gdb-tests' subdirectory of LIBDIR.
(It is safe to use relative paths for OBJDIR, SRCDIR, and so on. They are
(It is safe to use relative paths for LIBDIR, SRCDIR, and so on. They are
always interpreted relative to the directory that was current when
run-tests.py was started.)

View File

@ -16,15 +16,12 @@ SOURCES += [
]
UNIFIED_SOURCES += [
'tests/enum-printers.cpp',
'tests/test-asmjs.cpp',
'tests/test-ExecutableAllocator.cpp',
'tests/test-GCCellPtr.cpp',
'tests/test-Interpreter.cpp',
'tests/test-jsbytecode.cpp',
'tests/test-jsid.cpp',
'tests/test-JSObject.cpp',
'tests/test-jsop.cpp',
'tests/test-JSString.cpp',
'tests/test-JSSymbol.cpp',
'tests/test-jsval.cpp',

View File

@ -16,6 +16,7 @@ class InterpreterTypeCache(object):
# Cache information about the Interpreter types for this objfile.
def __init__(self):
self.tValue = gdb.lookup_type('JS::Value')
self.tJSOp = gdb.lookup_type('JSOp')
self.tScriptFrameIterData = gdb.lookup_type('js::ScriptFrameIter::Data')
self.tInterpreterFrame = gdb.lookup_type('js::InterpreterFrame')
self.tBaselineFrame = gdb.lookup_type('js::jit::BaselineFrame')
@ -39,7 +40,12 @@ class InterpreterRegs(object):
fp_ = 'fp_ = {}'.format(self.value['fp_'])
slots = (self.value['fp_'] + 1).cast(self.itc.tValue.pointer())
sp = 'sp = fp_.slots() + {}'.format(self.value['sp'] - slots)
pc = 'pc = {}'.format(self.value['pc'])
pc = self.value['pc']
try:
opcode = pc.dereference().cast(self.itc.tJSOp)
except Exception:
opcode = 'bad pc'
pc = 'pc = {} ({})'.format(pc.cast(self.cache.void_ptr_t), opcode)
return '{{ {}, {}, {} }}'.format(fp_, sp, pc)

View File

@ -21,7 +21,6 @@ import mozilla.JSString
import mozilla.JSSymbol
import mozilla.Root
import mozilla.jsid
import mozilla.jsop
import mozilla.jsval
import mozilla.unwind

View File

@ -1,64 +0,0 @@
# 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 JSOp and jsbytecode values.
import gdb
import gdb.types
import mozilla.prettyprinters
from mozilla.prettyprinters import pretty_printer, ptr_pretty_printer
# Forget any printers from previous loads of this module.
mozilla.prettyprinters.clear_module_printers(__name__)
class JSOpTypeCache(object):
# Cache information about the JSOp type for this objfile.
def __init__(self, cache):
self.tJSOp = gdb.lookup_type('JSOp')
# Let self.jsop_names be an array whose i'th element is the name of
# the i'th JSOp value.
d = gdb.types.make_enum_dict(self.tJSOp)
self.jsop_names = list(range(max(d.values()) + 1))
for (k, v) in d.items():
self.jsop_names[v] = k
@classmethod
def get_or_create(cls, cache):
if not cache.mod_JSOp:
cache.mod_JSOp = cls(cache)
return cache.mod_JSOp
@pretty_printer('JSOp')
class JSOp(object):
def __init__(self, value, cache):
self.value = value
self.cache = cache
self.jotc = JSOpTypeCache.get_or_create(cache)
def to_string(self):
# JSOp's storage type is |uint8_t|, but gdb uses a signed value.
# Manually convert it to an unsigned value before using it as an
# index into |jsop_names|.
# https://sourceware.org/bugzilla/show_bug.cgi?id=25325
idx = int(self.value) & 0xff
if idx < len(self.jotc.jsop_names):
return self.jotc.jsop_names[idx]
return "JSOP_UNUSED_{}".format(idx)
@ptr_pretty_printer('jsbytecode')
class JSBytecodePtr(mozilla.prettyprinters.Pointer):
def __init__(self, value, cache):
super(JSBytecodePtr, self).__init__(value, cache)
self.jotc = JSOpTypeCache.get_or_create(cache)
def to_string(self):
try:
opcode = str(self.value.dereference().cast(self.jotc.tJSOp))
except Exception:
opcode = 'bad pc'
return '{} ({})'.format(self.value.cast(self.cache.void_ptr_t), opcode)

View File

@ -214,7 +214,6 @@ class TypeCache(object):
self.mod_GCCellPtr = None
self.mod_Interpreter = None
self.mod_JSObject = None
self.mod_JSOp = None
self.mod_JSString = None
self.mod_JS_Value = None
self.mod_ExecutableAllocator = None
@ -266,10 +265,6 @@ template_regexp = re.compile("([\w_:]+)<")
def is_struct_or_union(t):
return t.code in (gdb.TYPE_CODE_STRUCT, gdb.TYPE_CODE_UNION)
def is_struct_or_union_or_enum(t):
return t.code in (gdb.TYPE_CODE_STRUCT, gdb.TYPE_CODE_UNION, gdb.TYPE_CODE_ENUM)
# Construct and return a pretty-printer lookup function for objfile, or
# return None if the objfile doesn't contain SpiderMonkey code
# (specifically, definitions for SpiderMonkey types).
@ -300,7 +295,7 @@ def lookup_for_objfile(objfile):
def check_table_by_type_name(table, t):
if t.code == gdb.TYPE_CODE_TYPEDEF:
return check_table(table, str(t))
elif is_struct_or_union_or_enum(t) and t.tag:
elif is_struct_or_union(t) and t.tag:
return check_table(table, t.tag)
else:
return None

View File

@ -1,25 +0,0 @@
#include "gdb-tests.h"
#include <stdint.h>
enum unscoped_no_storage { EnumValue1 };
enum unscoped_with_storage : uint8_t { EnumValue2 };
enum class scoped_no_storage { EnumValue3 };
enum class scoped_with_storage : uint8_t { EnumValue4 };
FRAGMENT(enum_printers, one) {
unscoped_no_storage i1 = EnumValue1;
unscoped_with_storage i2 = EnumValue2;
scoped_no_storage i3 = scoped_no_storage::EnumValue3;
scoped_with_storage i4 = scoped_with_storage::EnumValue4;
breakpoint();
use(i1);
use(i2);
use(i3);
use(i4);
}

View File

@ -1,47 +0,0 @@
# Test that we can find pretty-printers for enums.
# flake8: noqa: F821
import mozilla.prettyprinters
@mozilla.prettyprinters.pretty_printer('unscoped_no_storage')
class my_typedef(object):
def __init__(self, value, cache):
pass
def to_string(self):
return 'unscoped_no_storage::success'
@mozilla.prettyprinters.pretty_printer('unscoped_with_storage')
class my_typedef(object):
def __init__(self, value, cache):
pass
def to_string(self):
return 'unscoped_with_storage::success'
@mozilla.prettyprinters.pretty_printer('scoped_no_storage')
class my_typedef(object):
def __init__(self, value, cache):
pass
def to_string(self):
return 'scoped_no_storage::success'
@mozilla.prettyprinters.pretty_printer('scoped_with_storage')
class my_typedef(object):
def __init__(self, value, cache):
pass
def to_string(self):
return 'scoped_with_storage::success'
run_fragment('enum_printers.one')
assert_pretty('i1', 'unscoped_no_storage::success')
assert_pretty('i2', 'unscoped_with_storage::success')
assert_pretty('i3', 'scoped_no_storage::success')
assert_pretty('i4', 'scoped_with_storage::success')

View File

@ -1,32 +0,0 @@
#include "gdb-tests.h"
#include "jsapi.h"
#include "js/CompilationAndEvaluation.h"
#include "js/CompileOptions.h"
#include "js/SourceText.h"
#include "vm/JSScript.h"
#include "mozilla/ArrayUtils.h"
#include "mozilla/Utf8.h"
FRAGMENT(jsbytecode, simple) {
constexpr unsigned line0 = __LINE__;
static const char chars[] = R"(
debugger;
)";
JS::CompileOptions opts(cx);
opts.setFileAndLine(__FILE__, line0 + 1);
JS::SourceText<mozilla::Utf8Unit> srcBuf;
JS::Rooted<JS::Value> rval(cx);
bool ok = srcBuf.init(cx, chars, mozilla::ArrayLength(chars) - 1,
JS::SourceOwnership::Borrowed);
JSScript* script = JS::CompileDontInflate(cx, opts, srcBuf);
jsbytecode* code = script->code();
breakpoint();
use(ok);
use(code);
}

View File

@ -1,9 +0,0 @@
# Basic unit tests for jsbytecode* pretty-printer.
# flake8: noqa: F821
assert_subprinter_registered('SpiderMonkey', 'ptr-to-jsbytecode')
run_fragment('jsbytecode.simple')
assert_pretty('ok', 'true')
assert_pretty('code', ' (JSOP_DEBUGGER)')

View File

@ -1,15 +0,0 @@
#include "gdb-tests.h"
#include "vm/BytecodeUtil.h"
FRAGMENT(jsop, simple) {
JSOp undefined = JSOP_UNDEFINED;
JSOp debugger = JSOP_DEBUGGER;
JSOp limit = JSOP_LIMIT;
breakpoint();
use(undefined);
use(debugger);
use(limit);
}

View File

@ -1,10 +0,0 @@
# Basic unit tests for JSOp pretty-printer.
# flake8: noqa: F821
assert_subprinter_registered('SpiderMonkey', 'JSOp')
run_fragment('jsop.simple')
assert_pretty('undefined', 'JSOP_UNDEFINED')
assert_pretty('debugger', 'JSOP_DEBUGGER')
assert_pretty('limit', 'JSOP_LIMIT')