Version: v6.8.1
Platform: Windows 10 64 bit
function exception_function() {
try {
throw 'error';
} catch (err) {
console.log(err);
}
}
console.log('Starting script.');
exception_function();
console.log('Stopping script.');
When i am inside the exception_function in the debugger and execute the out function, it does not stop any more. If i do single step or step over all the way then it works fine.
< Debugger listening on [::]:5858
connecting to 127.0.0.1:5858 ... ok
break in C:\Users\xxxx\Desktop\exception.js:10
8 }
9
>10 console.log('Starting script.');
11 exception_function();
12 console.log('Stopping script.');
debug> next
< Starting script.
break in C:\Users\xxxx\Desktop\exception.js:11
9
10 console.log('Starting script.');
>11 exception_function();
12 console.log('Stopping script.');
13
debug> step
break in C:\Users\xxxx\Desktop\exception.js:4
2 function exception_function() {
3 try {
> 4 throw 'error';
5 } catch (err) {
6 console.log(err);
debug> out
< error
< Stopping script.
debug> quit
I can confirm the issue and it also happens with master.
It works when you run breakOnException before out. You end up in the catch block and can then run out again to step out of the function.
It seems V8 clears the one-shot breakpoints that out adds when an exception is thrown. This patch should fix it:
diff --git a/deps/v8/src/debug/debug.cc b/deps/v8/src/debug/debug.cc
index e046957..803fd4a 100644
--- a/deps/v8/src/debug/debug.cc
+++ b/deps/v8/src/debug/debug.cc
@@ -920,17 +920,17 @@ void Debug::PrepareStepInSuspendedGenerator() {
clear_suspended_generator();
}
void Debug::PrepareStepOnThrow() {
if (!is_active()) return;
if (last_step_action() == StepNone) return;
if (in_debug_scope()) return;
- ClearOneShot();
+ if (last_step_action() != StepOut) ClearOneShot();
// Iterate through the JavaScript stack looking for handlers.
JavaScriptFrameIterator it(isolate_);
while (!it.done()) {
JavaScriptFrame* frame = it.frame();
if (frame->LookupExceptionHandlerInTable(nullptr, nullptr) > 0) break;
it.Advance();
}
cc @nodejs/v8-inspector - I know the old debugger is being subsumed by the V8 inspector. Is it still useful to send this upstream and if so, how should I approach regression tests?
/cc @hashseed.
Corresponding V8 bug: https://bugs.chromium.org/p/v8/issues/detail?id=5559
Fix: https://codereview.chromium.org/2445233004
@ofrobots please label the V8 bug accordingly if you plan to merge.
Cherry-pick to v7.x: https://github.com/nodejs/node/pull/10688
Cherry-pick to v6.x: https://github.com/nodejs/node/pull/10689
@ofrobots it seems the fix has not been merged in 5.5. Is it still possible to do it?
Merge CL for 5.5 here: https://codereview.chromium.org/2621883003. Will land it upstream once approved.
Merged as 5.5.372.39 upstream.
Closing, fixed and released.
Most helpful comment
Merged as 5.5.372.39 upstream.