This change adds an optional 'scopeNumber' parameter to the
'Debugger.evaluateOnCallFrame' CDP command.
The 'scopeNumber' parameter specifies the 0-based index of the scope
to evaluate in. The index matches the scope chain from the
'Debugger.paused' event. If you do not provide a 'scopeNumber',
the default value is 0 (the innermost scope).
Key changes:
- CDP Protocol: Add optional integer 'scopeNumber' to the
'Debugger.evaluateOnCallFrame' command in js_protocol.pdl.
- Inspector: Validate 'scopeNumber' in 'V8DebuggerAgentImpl'.
If 'scopeNumber' is not valid, the command returns an error:
"Could not find scope with given number".
- Debug Evaluate: Update 'ContextBuilder' to start evaluation from
the specified scope.
- For an inner scope, the builder excludes block scopes that are
deeper than 'scopeNumber'.
- For an outer scope (closure, script, or global), the builder
evaluates in the context of that scope. Variables in inner
scopes are not visible.
- Tests: Add '.evaluate(expression)' to 'Scope' objects in
test-api.js. Add tests in test/inspector/debugger/ and
test/debugger/debug/ to verify evaluation across different scopes.
TAG=agy
CONV=881baa05-e1f7-4dbe-a278-ce57441c77bc
Fixed: 542461144
Change-Id: Ida16237e8418bfc5422f48cad3e6a4052b3b282d
Reviewed-on: https://chromium-review.googlesource.com/c/v8/v8/+/8200344
Commit-Queue: Simon Zünd <szuend@chromium.org>
Reviewed-by: Philip Pfaffe <pfaffe@chromium.org>
Reviewed-by: Eric Leese <leese@chromium.org>
Cr-Commit-Position: refs/heads/main@{#109062}
55 lines
1.2 KiB
JavaScript
55 lines
1.2 KiB
JavaScript
// Copyright 2016 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.
|
|
|
|
// Flags: --turbofan
|
|
|
|
Debug = debug.Debug
|
|
|
|
var exception = null;
|
|
|
|
function f() {
|
|
let a = 0;
|
|
function g() {
|
|
let a = 1;
|
|
{
|
|
let a = 2;
|
|
debugger; // Breakpoint.
|
|
if (a !== 3) {
|
|
// We cannot change stack locals in optimized frames.
|
|
assertEquals(2, a);
|
|
assertOptimized(g);
|
|
}
|
|
}
|
|
assertEquals(1, a);
|
|
}
|
|
g.call(1);
|
|
if (a !== 4) {
|
|
// We cannot change stack locals in optimized frames.
|
|
assertEquals(0, a);
|
|
assertOptimized(f);
|
|
}
|
|
}
|
|
|
|
|
|
function listener(event, exec_state, event_data, data) {
|
|
if (event != Debug.DebugEvent.Break) return;
|
|
try {
|
|
assertEquals(2, exec_state.frame(0).scope(0).evaluate("a").value());
|
|
assertEquals(1, exec_state.frame(0).scope(1).evaluate("a").value());
|
|
exec_state.frame(0).evaluate("a = 3");
|
|
exec_state.frame(1).evaluate("a = 4");
|
|
assertThrows(() => exec_state.frame(0).evaluate("this = 2"));
|
|
} catch (e) {
|
|
exception = e;
|
|
print("Caught something. " + e + " " + e.stack);
|
|
};
|
|
};
|
|
|
|
Debug.setListener(listener);
|
|
|
|
f();
|
|
|
|
Debug.setListener(null);
|
|
assertNull(exception);
|