v8/test/inspector/regress/regress-crbug-1401674.js
Simon Zünd 3094c4002b [debug] Fix stepping through single statement loops
The debugger utilizes the source position while single stepping
("Step-in") through the source to go from statement to statement and
skipping some expressions along the way. The debugger remembers the
"statement position" of the last stepping action.

This works well in general but falls flat for loops that only have
a single statement in them. Every step lands on the same statement,
just one loop iteration later.

We detect this case by checking if we are in the same frame and have
the exact same bytecode offset as the last step action.

Note that this also fixes "frame restarting" should we have restarted
a function while paused at the beginning of that function.

R=jarin@chromium.org

Bug: chromium:1401674
Change-Id: Id0a5753ed7cc9f23f22d869368d88e1c4b48566d
Reviewed-on: https://chromium-review.googlesource.com/c/v8/v8/+/4135881
Commit-Queue: Simon Zünd <szuend@chromium.org>
Reviewed-by: Jaroslav Sevcik <jarin@chromium.org>
Cr-Commit-Position: refs/heads/main@{#85107}
2023-01-05 07:18:16 +00:00

39 lines
1015 B
JavaScript

// Copyright 2023 the V8 project authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
let {Protocol} = InspectorTest.start('Regression test for crbug.com/1401674. Properly step through single statement loops.');
(async () => {
await Protocol.Debugger.enable();
Protocol.Runtime.evaluate({
expression: `
function f() {
let i = 0;
debugger;
while (true) {i++}
}
f();
`});
await Protocol.Debugger.oncePaused();
Protocol.Debugger.stepInto();
await Protocol.Debugger.oncePaused();
InspectorTest.log('Expecting debugger to pause after the step ...');
Protocol.Debugger.stepInto();
await Protocol.Debugger.oncePaused();
InspectorTest.log('SUCCESS');
InspectorTest.log('Stepping to the same statement but in the next iteration ...');
Protocol.Debugger.stepInto();
await Protocol.Debugger.oncePaused();
InspectorTest.log('SUCCESS');
InspectorTest.completeTest();
})();