Commit 6eceba5
committed
Web Inspector: Debugger: add a way to step over
https://bugs.webkit.org/show_bug.cgi?id=291309
Reviewed by Yusuke Suzuki.
When debugging async code with `await` it's often more desirable to follow what's written in code (i.e. as if the `await` didnt exist) instead of the literal execution flow, especially since it's possible for execution to stop after the `await` if it's the end of sync code.
For example, if the developer is trying to step through code similar to the following
```js
/* 1 */ async function wrap(callback, state) {
/* 2 */ console.log(state, "before");
/* 3 */ await callback();
/* 4 */ console.log(state, "after");
/* 5 */ }
/* 6 */
/* 7 */ wrap(foo, 1);
/* 8 */ debugger;
/* 9 */ wrap(foo, 2);
```
execution should never pause in the flow where `state === 1`, meaning that the debugger will "skip" (i.e. resume and then pause again) between "2 before" and "1 after".
Without this, the developer has to manually create breakpoints after each `await` to ensure that execution pauses after, but even then there's no guarantee that will be in the right flow if the same function is invoked multiple times (i.e. one resolves before the other).
* Source/JavaScriptCore/bytecode/BytecodeList.rb:
* Source/JavaScriptCore/bytecode/BytecodeUseDef.cpp:
(JSC::computeUsesForBytecodeIndexImpl):
* Source/JavaScriptCore/jit/JITOpcodes.cpp:
(JSC::JIT::emit_op_debug):
* Source/JavaScriptCore/jit/JITOperations.h:
* Source/JavaScriptCore/jit/JITOperations.cpp:
(JSC::operationDebug):
* Source/JavaScriptCore/llint/LLIntSlowPaths.cpp:
(JSC::LLInt::slow_path_debug):
Modify `OpDebug` to allow for additional data to be set alongside the `DebugHookType`.
Currently this is only used to pass along the `JSGenerator` instance as a way to link execution from before the `await` to after the `await`.
Drive-by: Remove the unused `hasBreakpoint` member variable.
* Source/JavaScriptCore/interpreter/Interpreter.h:
* Source/JavaScriptCore/interpreter/Interpreter.cpp:
(JSC::Interpreter::debug):
(WTF::printInternal):
* Source/JavaScriptCore/bytecode/UnlinkedCodeBlock.cpp:
(JSC::dumpExpressionInfoDetails):
* Source/JavaScriptCore/debugger/Debugger.h:
* Source/JavaScriptCore/debugger/Debugger.cpp:
(JSC::Debugger::detach):
(JSC::Debugger::pauseIfNeeded):
(JSC::Debugger::handlePause):
(JSC::Debugger::willAwait): Added.
(JSC::Debugger::didAwait): Added.
(JSC::Debugger::resetAsyncPauseState): Added.
Introduce new `WillAwait` and `DidAwait` debug hooks for the `Debugger` to determine what `await` to pause on.
When performing a "Step over" or "Step next", if an `await` is encountered then save the `JSGenerator` instance (which is the additional data set alongside the `DebugHookType`).
Once the `await` is done, if the `JSGenerator` matches what was saved then pause at the next opportunity.
* Source/JavaScriptCore/bytecompiler/BytecodeGenerator.h:
* Source/JavaScriptCore/bytecompiler/BytecodeGenerator.cpp:
(JSC::BytecodeGenerator::emitDebugHook):
(JSC::BytecodeGenerator::emitWillLeaveCallFrameDebugHook):
(JSC::BytecodeGenerator::emitAwait):
(JSC::BytecodeGenerator::emitIteratorGenericNext):
(JSC::BytecodeGenerator::emitIteratorGenericClose):
(JSC::BytecodeGenerator::emitDelegateYield):
* Source/JavaScriptCore/bytecompiler/NodesCodegen.cpp:
(JSC::ReturnNode::emitBytecode):
(JSC::emitProgramNodeBytecode):
(JSC::EvalNode::emitBytecode):
(JSC::FunctionNode::emitBytecode):
(JSC::AwaitExprNode::emitBytecode):
Drive-by: remove unnecessary overrides to make debug hook logic simpler.
* Source/WebKitLegacy/mac/WebView/WebScriptDebugger.h:
* Source/WebKitLegacy/mac/WebView/WebScriptDebugger.mm:
(WebScriptDebugger::handlePause):
Drive-by: no need to pass the `ReasonForPause` since it's already exposed via `Debugger::reasonForPause`.
* LayoutTests/inspector/debugger/resources/stepping-async.js: Added.
* LayoutTests/inspector/debugger/stepping/stepInto-await.html:
* LayoutTests/inspector/debugger/stepping/stepInto-await-expected.txt:
* LayoutTests/inspector/debugger/stepping/stepNext-await.html:
* LayoutTests/inspector/debugger/stepping/stepNext-await-expected.txt:
* LayoutTests/inspector/debugger/stepping/stepOut-await.html:
* LayoutTests/inspector/debugger/stepping/stepOut-await-expected.txt:
* LayoutTests/inspector/debugger/stepping/stepOver-await.html:
* LayoutTests/inspector/debugger/stepping/stepOver-await-expected.txt:
Canonical link: https://commits.webkit.org/293628@mainawait as though it was sync code1 parent 0bab83a commit 6eceba5
25 files changed
Lines changed: 2120 additions & 69 deletions
File tree
- LayoutTests/inspector/debugger
- resources
- stepping
- Source
- JavaScriptCore
- bytecode
- bytecompiler
- debugger
- interpreter
- jit
- llint
- WebKitLegacy/mac/WebView
Lines changed: 195 additions & 0 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
| 1 | + | |
| 2 | + | |
| 3 | + | |
| 4 | + | |
| 5 | + | |
| 6 | + | |
| 7 | + | |
| 8 | + | |
| 9 | + | |
| 10 | + | |
| 11 | + | |
| 12 | + | |
| 13 | + | |
| 14 | + | |
| 15 | + | |
| 16 | + | |
| 17 | + | |
| 18 | + | |
| 19 | + | |
| 20 | + | |
| 21 | + | |
| 22 | + | |
| 23 | + | |
| 24 | + | |
| 25 | + | |
| 26 | + | |
| 27 | + | |
| 28 | + | |
| 29 | + | |
| 30 | + | |
| 31 | + | |
| 32 | + | |
| 33 | + | |
| 34 | + | |
| 35 | + | |
| 36 | + | |
| 37 | + | |
| 38 | + | |
| 39 | + | |
| 40 | + | |
| 41 | + | |
| 42 | + | |
| 43 | + | |
| 44 | + | |
| 45 | + | |
| 46 | + | |
| 47 | + | |
| 48 | + | |
| 49 | + | |
| 50 | + | |
| 51 | + | |
| 52 | + | |
| 53 | + | |
| 54 | + | |
| 55 | + | |
| 56 | + | |
| 57 | + | |
| 58 | + | |
| 59 | + | |
| 60 | + | |
| 61 | + | |
| 62 | + | |
| 63 | + | |
| 64 | + | |
| 65 | + | |
| 66 | + | |
| 67 | + | |
| 68 | + | |
| 69 | + | |
| 70 | + | |
| 71 | + | |
| 72 | + | |
| 73 | + | |
| 74 | + | |
| 75 | + | |
| 76 | + | |
| 77 | + | |
| 78 | + | |
| 79 | + | |
| 80 | + | |
| 81 | + | |
| 82 | + | |
| 83 | + | |
| 84 | + | |
| 85 | + | |
| 86 | + | |
| 87 | + | |
| 88 | + | |
| 89 | + | |
| 90 | + | |
| 91 | + | |
| 92 | + | |
| 93 | + | |
| 94 | + | |
| 95 | + | |
| 96 | + | |
| 97 | + | |
| 98 | + | |
| 99 | + | |
| 100 | + | |
| 101 | + | |
| 102 | + | |
| 103 | + | |
| 104 | + | |
| 105 | + | |
| 106 | + | |
| 107 | + | |
| 108 | + | |
| 109 | + | |
| 110 | + | |
| 111 | + | |
| 112 | + | |
| 113 | + | |
| 114 | + | |
| 115 | + | |
| 116 | + | |
| 117 | + | |
| 118 | + | |
| 119 | + | |
| 120 | + | |
| 121 | + | |
| 122 | + | |
| 123 | + | |
| 124 | + | |
| 125 | + | |
| 126 | + | |
| 127 | + | |
| 128 | + | |
| 129 | + | |
| 130 | + | |
| 131 | + | |
| 132 | + | |
| 133 | + | |
| 134 | + | |
| 135 | + | |
| 136 | + | |
| 137 | + | |
| 138 | + | |
| 139 | + | |
| 140 | + | |
| 141 | + | |
| 142 | + | |
| 143 | + | |
| 144 | + | |
| 145 | + | |
| 146 | + | |
| 147 | + | |
| 148 | + | |
| 149 | + | |
| 150 | + | |
| 151 | + | |
| 152 | + | |
| 153 | + | |
| 154 | + | |
| 155 | + | |
| 156 | + | |
| 157 | + | |
| 158 | + | |
| 159 | + | |
| 160 | + | |
| 161 | + | |
| 162 | + | |
| 163 | + | |
| 164 | + | |
| 165 | + | |
| 166 | + | |
| 167 | + | |
| 168 | + | |
| 169 | + | |
| 170 | + | |
| 171 | + | |
| 172 | + | |
| 173 | + | |
| 174 | + | |
| 175 | + | |
| 176 | + | |
| 177 | + | |
| 178 | + | |
| 179 | + | |
| 180 | + | |
| 181 | + | |
| 182 | + | |
| 183 | + | |
| 184 | + | |
| 185 | + | |
| 186 | + | |
| 187 | + | |
| 188 | + | |
| 189 | + | |
| 190 | + | |
| 191 | + | |
| 192 | + | |
| 193 | + | |
| 194 | + | |
| 195 | + | |
0 commit comments