Closed Bug 1776376 Opened 4 years ago Closed 4 years ago

Assertion failure: dbgFrame->hasGeneratorInfo(), at debugger/Debugger.cpp:6553

Categories

(Core :: JavaScript Engine, defect, P3)

x86_64
Linux
defect

Tracking

()

VERIFIED FIXED
104 Branch
Tracking Status
firefox-esr91 --- wontfix
firefox-esr102 --- wontfix
firefox102 --- wontfix
firefox103 --- wontfix
firefox104 --- verified

People

(Reporter: decoder, Assigned: arai)

References

Details

(Keywords: assertion, regression, testcase, Whiteboard: [bugmon:update,bisected,confirmed])

Attachments

(2 files, 1 external file)

The following testcase crashes on mozilla-central revision 20220623-c05cfc52283c (debug build, run with --fuzzing-safe --ion-offthread-compile=off):

b = newGlobal({ newCompartment: true });
b.eval("function* c() {}");
d = new Debugger;
e = d.addDebuggee(b);
script = e.makeDebuggeeValue(b.c).script;
script.setBreakpoint(1, {});
b.c();

Backtrace:

received signal SIGSEGV, Segmentation fault.
#0  0x000055555731b225 in js::Debugger::suspendGeneratorDebuggerFrames(JSContext*, js::AbstractFramePtr) ()
#1  0x00005555572eb65e in js::DebugAPI::slowPathOnLeaveFrame(JSContext*, js::AbstractFramePtr, unsigned char const*, bool) ()
#2  0x0000555556d0f34c in js::DebugAPI::onLeaveFrame(JSContext*, js::AbstractFramePtr, unsigned char const*, bool) ()
#3  0x0000555556cec05c in Interpret(JSContext*, js::RunState&) ()
#4  0x0000555556cea8ed in js::RunScript(JSContext*, js::RunState&) ()
#5  0x0000555556cfd936 in js::InternalCallOrConstruct(JSContext*, JS::CallArgs const&, js::MaybeConstruct, js::CallReason) ()
#6  0x0000555556cff263 in js::Call(JSContext*, JS::Handle<JS::Value>, JS::Handle<JS::Value>, js::AnyInvokeArgs const&, JS::MutableHandle<JS::Value>, js::CallReason) ()
#7  0x0000555557294eae in js::ForwardingProxyHandler::call(JSContext*, JS::Handle<JSObject*>, JS::CallArgs const&) const ()
#8  0x0000555557279930 in js::CrossCompartmentWrapper::call(JSContext*, JS::Handle<JSObject*>, JS::CallArgs const&) const ()
#9  0x0000555557284419 in js::Proxy::call(JSContext*, JS::Handle<JSObject*>, JS::CallArgs const&) ()
#10 0x0000555556cfdd8c in js::InternalCallOrConstruct(JSContext*, JS::CallArgs const&, js::MaybeConstruct, js::CallReason) ()
#11 0x0000555556cf3039 in Interpret(JSContext*, js::RunState&) ()
[...]
#20 0x0000555556b570e2 in main ()
rax	0x555555823bc1	93824995179457
rbx	0x2e9930d4b128	51235484119336
rcx	0x55555821aad8	93825039182552
rdx	0x0	0
rsi	0x7ffff7105770	140737338431344
rdi	0x7ffff7104540	140737338426688
rbp	0x7fffffffb570	140737488336240
rsp	0x7fffffffb4f0	140737488336112
r8	0x7ffff7105770	140737338431344
r9	0x7ffff7f99840	140737353717824
r10	0x0	0
r11	0x0	0
r12	0x2e9930d4e088	51235484131464
r13	0x7ffff60f5e68	140737321590376
r14	0x0	0
r15	0x7ffff60f5d00	140737321590016
rip	0x55555731b225 <js::Debugger::suspendGeneratorDebuggerFrames(JSContext*, js::AbstractFramePtr)+981>
=> 0x55555731b225 <_ZN2js8Debugger30suspendGeneratorDebuggerFramesEP9JSContextNS_16AbstractFramePtrE+981>:	movl   $0x1999,0x0
   0x55555731b230 <_ZN2js8Debugger30suspendGeneratorDebuggerFramesEP9JSContextNS_16AbstractFramePtrE+992>:	callq  0x555556bee448 <abort>
Attached file Testcase —

Bugmon Analysis
Verified bug as reproducible on mozilla-central 20220624093542-8137cac7aaeb.
Unable to bisect testcase (Testcase reproduces on start build!):

Start: 531323de1a48ea8a49a329fb22f08373e46df620 (20210625093436)
End: c05cfc52283cce26816b49934cd3890e4b61b0b5 (20220623155748)
BuildFlags: BuildFlags(asan=False, tsan=False, debug=True, fuzzing=False, coverage=False, valgrind=False, no_opt=False, fuzzilli=False, nyx=False)

Whiteboard: [bugmon:update,bisect] → [bugmon:update,bisected,confirmed]

My cursory investigation didn't clarify what's going on here -- not sure how this is supposed to work.

Arai, any thoughts?

Severity: -- → S3
Flags: needinfo?(arai.unmht)
Priority: -- → P3

so far, it seems like a mismatch around the expectation for the condition when the debug info is created or stored.

it doesn't crash if:

  • put d.onEnterFrame = function () {};, or
  • move the breakpoint to script.setBreakpoint(0, {}); or script.setBreakpoint(6, {});

the bytecode for the generator is

00000:  Generator                       # GENERATOR
00001:  SetAliasedVar ".generator" (hops = 0, slot = 2) # GENERATOR
00006:  InitialYield 0                  # RVAL GENERATOR RESUMEKIND
...

offset 1 is after Generator, but not yet setting the .generator slot, so I guess it's in some unexpected or unstable state.
I'll look into this next week.

sorry, I'm busy right now and it might take 1-2 weeks before I look into the details.

I believe that the breakpoint for offset 1 cannot be set from the UI (it's not listed in getPossibleBreakpoints()), and this can be hit only when the debugger API is directly called,
so not something critical.

There are 2 modes for calling DebuggerFrame::setGeneratorInfo.

If the debugger frame is created before JSOp::SetAliasedVar ".generator" (e.g. breakpoint at 0, for JSOp::Generator),
DebugAPI::slowPathOnNewGenerator for JSOp::Generator calls DebuggerFrame::setGeneratorInfo:

https://searchfox.org/mozilla-central/rev/a9e776193401900a8ceffa478ae6e9930e895ca1/js/src/vm/Interpreter.cpp#4240,4243

CASE(Generator) {
...
  JSObject* obj = AbstractGeneratorObject::createFromFrame(cx, REGS.fp());

https://searchfox.org/mozilla-central/rev/a9e776193401900a8ceffa478ae6e9930e895ca1/js/src/vm/GeneratorObject.cpp#63-64,85

JSObject* AbstractGeneratorObject::createFromFrame(JSContext* cx,
                                                   AbstractFramePtr frame) {
...
  if (!DebugAPI::onNewGenerator(cx, frame, genObj)) {

https://searchfox.org/mozilla-central/rev/a9e776193401900a8ceffa478ae6e9930e895ca1/js/src/debugger/DebugAPI-inl.h#85-88

bool DebugAPI::onNewGenerator(JSContext* cx, AbstractFramePtr frame,
                              Handle<AbstractGeneratorObject*> genObj) {
  if (frame.isDebuggee()) {
    return slowPathOnNewGenerator(cx, frame, genObj);

https://searchfox.org/mozilla-central/rev/a9e776193401900a8ceffa478ae6e9930e895ca1/js/src/debugger/Debugger.cpp#1251-1252,1266-1267,1276

bool DebugAPI::slowPathOnNewGenerator(JSContext* cx, AbstractFramePtr frame,
                                      Handle<AbstractGeneratorObject*> genObj) {
...
  Debugger::forEachOnStackDebuggerFrame(
      frame, [&](Debugger* dbg, DebuggerFrame* frameObjPtr) {
...
        if (!DebuggerFrame::setGeneratorInfo(cx, frameObj, genObj)) {

If the debugger frame is not created before JSOp::SetAlliasedVar ".generator" (e.g. breakpoint at 6, for JSOp::InitialYield 0),
DebuggerFrame::create during handling the breakpoint calls DebuggerFrame::setGeneratorInfo:

https://searchfox.org/mozilla-central/rev/a9e776193401900a8ceffa478ae6e9930e895ca1/js/src/debugger/Debugger.cpp#2491,2531,2540,2556,2559-2561

bool DebugAPI::onTrap(JSContext* cx) {
...
  if (triggered.length() > 0) {
...
    for (Breakpoint* bp : triggered) {
...
      if (dbg->debuggees.has(global)) {
...
        bool result = dbg->enterDebuggerHook(cx, [&]() -> bool {
          RootedValue scriptFrame(cx);
          if (!dbg->getFrame(cx, iter, &scriptFrame)) {

https://searchfox.org/mozilla-central/rev/a9e776193401900a8ceffa478ae6e9930e895ca1/js/src/debugger/Debugger.cpp#614-615,617

bool Debugger::getFrame(JSContext* cx, const FrameIter& iter,
                        MutableHandleValue vp) {
...
  if (!Debugger::getFrame(cx, iter, &result)) {

https://searchfox.org/mozilla-central/rev/a9e776193401900a8ceffa478ae6e9930e895ca1/js/src/debugger/Debugger.cpp#641-642,646-647,683-684

bool Debugger::getFrame(JSContext* cx, const FrameIter& iter,
                        MutableHandle<DebuggerFrame*> result) {
...
  FrameMap::AddPtr p = frames.lookupForAdd(referent);
  if (!p) {
...
    Rooted<DebuggerFrame*> frame(
        cx, DebuggerFrame::create(cx, proto, debugger, &iter, genObj));

https://searchfox.org/mozilla-central/rev/a9e776193401900a8ceffa478ae6e9930e895ca1/js/src/debugger/Frame.cpp#234-237,255-256

DebuggerFrame* DebuggerFrame::create(
    JSContext* cx, HandleObject proto, Handle<NativeObject*> debugger,
    const FrameIter* maybeIter,
    Handle<AbstractGeneratorObject*> maybeGenerator) {
...
  if (maybeGenerator) {
    if (!DebuggerFrame::setGeneratorInfo(cx, frame, maybeGenerator)) {

Then, if a breakpoint is set at JSOp::SetAliasedVar ".generator", neither of them cover it.

  • DebugAPI::slowPathOnNewGenerator doesn't call DebuggerFrame::setGeneratorInfo because there's no debugger frame that doesn't have generator info
  • DebuggerFrame::create doesn't call DebuggerFrame::setGeneratorInfo because maybeGenerator is nullptr, because .generator binding is not yet set to the generator object

To my understanding, JSOp::Generator and JSOP::SetAliasedVar ".generator" should be atomic operation, and setting breakpoint for JSOP::SetAliasedVar ".generator" should be disallowed.

Flags: needinfo?(arai.unmht)
Assignee: nobody → arai.unmht
Status: NEW → ASSIGNED
Pushed by arai_a@mac.com: https://hg.mozilla.org/integration/autoland/rev/70ac8aae36c7 Disallow setting a breakpoint for JSOp::SetAliasedVar ".generator". r=mgaudet
Status: ASSIGNED → RESOLVED
Closed: 4 years ago
Resolution: --- → FIXED
Target Milestone: --- → 104 Branch

Bugmon Analysis
Verified bug as fixed on rev mozilla-central 20220715095545-59134b451eec.
Removing bugmon keyword as no further action possible. Please review the bug and re-add the keyword for further analysis.

Status: RESOLVED → VERIFIED
Keywords: bugmon
Regressions: 1780134
Blocks: 1780152
Regressions: 1780158
Regressions: 1815152
You need to log in before you can comment on or make changes to this bug.

Attachment

General

Created:
Updated:
Size: