Closed Bug 1200832 Opened 10 years ago Closed 10 years ago

Async stacks aren't working in the console or debugger with javascript.options.asyncstack=true

Categories

(DevTools :: General, defect)

defect
Not set
normal

Tracking

(firefox43 affected, firefox44 fixed)

RESOLVED FIXED
Firefox 44
Tracking Status
firefox43 --- affected
firefox44 --- fixed

People

(Reporter: bgrins, Assigned: tromey)

References

(Blocks 1 open bug, )

Details

(Whiteboard: [polish-backlog])

Attachments

(1 file, 5 obsolete files)

STR: * Make sure javascript.options.asyncstack is set to true (Nightly and Dev Edition for now have this as the default) * Open: data:text/html,<script>setTimeout(function foo() {setTimeout(function bar() {console.trace();debugger;}, 100);}, 100);</script> Expected - the trace shows: bar(); foo(); Actual - the trace shows: bar(); I've noticed the same behavior with Promise resolutions too.
Is this still an issue?
(In reply to Florian Bender from comment #1) > Is this still an issue? Yes.
Whiteboard: [polish-backlog]
The debugger part is already filed as bug 1142571.
There are two problems here. First, Console.cpp ignores async parents: https://dxr.mozilla.org/mozilla-central/source/dom/base/Console.cpp#981 Second, Exceptions.cpp has a couple of spots where it makes an empty stack frame rather than return null: https://dxr.mozilla.org/mozilla-central/source/dom/bindings/Exceptions.cpp#681 https://dxr.mozilla.org/mozilla-central/source/dom/bindings/Exceptions.cpp#816 Fixing these gives me an async stack for the original example, but I don't know what other fallout there might be. In particular I get: console.trace(): bar() debugger eval code:1 foo() debugger eval code:1 <anonymous> debugger eval code:1 There may be other spots needing a similar change, but I am not sure. For example, this walks the stack but does not consider async parents: https://dxr.mozilla.org/mozilla-central/source/devtools/shared/Console.jsm#370
Attached patch WIP patch (obsolete) — Splinter Review
Assignee: nobody → ttromey
Status: NEW → ASSIGNED
Now with a test case. One thing I am wondering is whether we should add an async cause field to ConsoleStackEntry.
Attachment #8670856 - Attachment is obsolete: true
I think exposing the async cause is best, and with that plus a small client change I now get: console.trace(): bar() debugger eval code:1 (Async: setTimeout handler) foo() debugger eval code:1 (Async: setTimeout handler) <anonymous> debugger eval code:1
Attachment #8670974 - Attachment is obsolete: true
Attachment #8671387 - Attachment is obsolete: true
Comment on attachment 8672029 [details] [diff] [review] make Console.trace follow async parents This changes console.trace to display async stack parents. This exposes the async cause on ConsoleStackEntry so the console can display async parents more clearly. It changes ReifyStack to follow the async parent when it exists. It also removes a "dummy frame" case from Exceptions.cpp in order to make this work properly -- but note that the corresponding dummy frame case in CreateStack does not need to change (changing this runs into crashes elsewhere; and in any case the CreateStack case corresponds to an empty stack, not a frame without a direct parent). I think the devtools bits are relatively straightforward. The change to Widgets.Stacktrace.render came about because I happened to notice a message about stacktrace being null when playing with the console before the change; that is, it is a fix for a minor latent bug.
Attachment #8672029 - Flags: review?(bgrinstead)
Attachment #8672029 - Flags: review?(amarchesini)
Comment on attachment 8672029 [details] [diff] [review] make Console.trace follow async parents Review of attachment 8672029 [details] [diff] [review]: ----------------------------------------------------------------- ::: dom/webidl/Console.webidl @@ +80,5 @@ > unsigned long lineNumber = 0; > unsigned long columnNumber = 0; > DOMString functionName = ""; > unsigned long language = 0; > + DOMString? asyncCause; what about: DOMString asyncCause = ""; ?
Attachment #8672029 - Flags: review?(amarchesini) → review+
Comment on attachment 8672029 [details] [diff] [review] make Console.trace follow async parents Review of attachment 8672029 [details] [diff] [review]: ----------------------------------------------------------------- Looks great! Should we file a new bug for these async causes to bubble up in the UI when an error is thrown in an async callback? ::: devtools/client/webconsole/test/browser_webconsole_console_trace_async.js @@ +1,1 @@ > +/* vim:set ts=2 sw=2 sts=2 et: */ This test will fail in release builds and other places where the feature is off by default. You can test this locally via: ./mach mochitest devtools/client/webconsole/test/browser_webconsole_console_trace_async.js --setpref javascript.options.asyncstack=false This test could also take advantage of add_task and BrowserTestUtils to be easier to work with and e10s friendly. I made some updates locally to test this so I'll just paste in the work: add_task(function* runTest() { // Async stacks aren't on by default in all builds yield new Promise(resolve => { SpecialPowers.pushPrefEnv({"set": [ ["javascript.options.asyncstack", true] ]}, resolve); }); let {tab} = yield loadTab("data:text/html;charset=utf8,<p>hello"); let hud = yield openConsole(tab); BrowserTestUtils.loadURI(gBrowser.selectedBrowser, TEST_URI); let [result] = yield waitForMessages({ webconsole: hud, messages: [{ name: "console.trace output", consoleTrace: { file: "test-console-trace-async.html", fn: "inner", }, }], }); let node = [...result.matched][0]; ok(node, "found trace log node"); ok(node.textContent.includes("console.trace()"), "trace log node includes console.trace()"); ok(node.textContent.includes("promise callback"), "trace log node includes promise callback"); ok(node.textContent.includes("setTimeout handler"), "trace log node includes setTimeout handler"); // The expected stack trace object. let stacktrace = [ { columnNumber: 3, filename: TEST_URI, functionName: "inner", language: 2, lineNumber: 9 }, { asyncCause: "promise callback", columnNumber: 1, filename: TEST_URI, functionName: "time1", language: 2, lineNumber: 13, }, { asyncCause: "setTimeout handler", columnNumber: 1, filename: TEST_URI, functionName: "", language: 2, lineNumber: 18, } ]; let obj = node._messageObject; ok(obj, "console.trace message object"); ok(obj._stacktrace, "found stacktrace object"); is(obj._stacktrace.toSource(), stacktrace.toSource(), "stacktrace is correct"); });
Attachment #8672029 - Flags: review?(bgrinstead) → review+
(In reply to Andrea Marchesini (:baku) from comment #13) > Comment on attachment 8672029 [details] [diff] [review] > make Console.trace follow async parents > > Review of attachment 8672029 [details] [diff] [review]: > ----------------------------------------------------------------- > > ::: dom/webidl/Console.webidl > @@ +80,5 @@ > > unsigned long lineNumber = 0; > > unsigned long columnNumber = 0; > > DOMString functionName = ""; > > unsigned long language = 0; > > + DOMString? asyncCause; > > what about: DOMString asyncCause = ""; ? I wanted asyncCause not to be present unless it was explicitly set. This approach makes it appear as the empty string.
Use Brian's test case.
Attachment #8672029 - Attachment is obsolete: true
Attachment #8675796 - Flags: review+
(In reply to Brian Grinstead [:bgrins] from comment #14) > Comment on attachment 8672029 [details] [diff] [review] > make Console.trace follow async parents > > Review of attachment 8672029 [details] [diff] [review]: > ----------------------------------------------------------------- > > Looks great! Should we file a new bug for these async causes to bubble up in > the UI when an error is thrown in an async callback? Maybe bug 1141222 is related? I am not sure. I think it doesn't hurt to file another bug.
This makes a trivial change to a test case that was affected by the patch. I'm planning to carry over the r+.
Attachment #8675796 - Attachment is obsolete: true
Attachment #8676900 - Flags: review+
Keywords: checkin-needed
Status: ASSIGNED → RESOLVED
Closed: 10 years ago
Resolution: --- → FIXED
Target Milestone: --- → Firefox 44
Product: Firefox → DevTools
You need to log in before you can comment on or make changes to this bug.

Attachment

General

Created:
Updated:
Size: