Now that DebugScriptScopeInfo provides the full lexical scope tree for
every script, ScopeIterator no longer switches to context-only
iteration when it leaves the paused closure. Instead it keeps walking
DebugScriptScope into outer lexical scopes, including outer scopes
that don't need a context. Stack-allocated variables of such scopes
are reported as unavailable. Iteration falls back to the context chain
once it leaves the root of the scope tree (e.g. for eval and wrapped
functions).
Empty outer scopes are still skipped for now; a follow-up changes that.
[[Scopes]] is unaffected, since the inspector builds it from the runtime
context chain.
- GetFunctionDebugName() returns undefined for outer scopes whose
enclosing function has no context, instead of using the name of an
unrelated closure context.
- DebugEvaluate uses the closest runtime context when targeting an
outer scope without a context (EvaluationContext()), and always wraps
it for contextless target scopes so the scope's blocklist applies,
even if the closest context is the native context. Otherwise
evaluating `x` in a contextless scope that declares `x` would find a
global `x`.
R=pfaffe@chromium.org
Bug: 545412300
Change-Id: Iaee6cfb7e1bee13c0bd6c3ff61d7e9c82a9b8491
Reviewed-on: https://chromium-review.googlesource.com/c/v8/v8/+/8460005
Reviewed-by: Philip Pfaffe <pfaffe@chromium.org>
Commit-Queue: Simon Zünd <szuend@chromium.org>
Cr-Commit-Position: refs/heads/main@{#110376}
Update DebugEvaluate::ContextBuilder to populate and look up locals
block-lists via EnsureLocalsBlockList and CalculateScopeBlockList
instead of relying on ScopeIterator's CalculateBlocklists::kIfNeeded.
When evaluating in an outer scope without its own runtime Context,
calculate its [S_eval, K) block-list on the fly and attach it to the
synthetic DebugEvaluateContext ScopeInfo with an empty wrapped_context.
R=pfaffe@chromium.org
Bug: 545412300
Change-Id: I962c95f797c2d73730278fc3a017763794b5b0ad
Reviewed-on: https://chromium-review.googlesource.com/c/v8/v8/+/8437698
Reviewed-by: Philip Pfaffe <pfaffe@chromium.org>
Commit-Queue: Simon Zünd <szuend@chromium.org>
Cr-Commit-Position: refs/heads/main@{#110022}
A recent change added support to evaluate expressions outside the paused function.
Because of this change, Context::Lookup must now check blocklists when it inspects outer closure scopes.
Before this change, Debugger.evaluateOnCallFrame did not check blocklists for outer closure scopes.
Lookups for stack-allocated variables in an outer closure scope did not throw a ReferenceError.
This occurred for two reasons:
1. ContextBuilder did not wrap outer closure evaluation contexts in a DebugEvaluateContext to trigger the blocklist check in Context::Lookup.
2. LocalBlocklistsCollector did not store the blocklist for the outermost closure context in the cache.
This change fixes both issues:
- ContextBuilder now wraps outer closure evaluation contexts in a DebugEvaluateContext.
- LocalBlocklistsCollector now collects locals for outer closure scopes and caches the blocklist for the outermost closure context.
Test coverage is added to debugger/debug/debug-evaluate-shadowed-context and debugger/debug/debug-evaluate-shadowed-context-reuse.
TAG=agy
CONV=068e94d1-a67a-4e1b-99dc-4d6cc055acdd
R=pfaffe@chromium.org
Bug: 542461144
Change-Id: If2f070aa0dc2aa7f201a34105a31639aeba96e1e
Reviewed-on: https://chromium-review.googlesource.com/c/v8/v8/+/8202625
Reviewed-by: Philip Pfaffe <pfaffe@chromium.org>
Commit-Queue: Simon Zünd <szuend@chromium.org>
Cr-Commit-Position: refs/heads/main@{#109072}
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}
This CL implements the heavy lifting for re-using block lists:
- On local debug-evaluate, we check if the paused function already
has a block list. If not, we do a full re-parse, calculate the
block lists and stash them in the global map.
- On a context lookup, we do the lookup slightly differently. The
block lists now store "outer" locals, so we need to check the
block list before we advance to the next context, not before we
do the lookup in the current context.
The CL also duplicates the debugger test that checks most of these
shadowing edge cases. While we keep working on the new feature
we still want to check both configurations, but the feature is too
small to warrant a separate bot. Note that the file with the flag
enabled has one additional test case that fails with the old
implementation. Unfortunately it's non-trivial to fix in the old
implementation.
This CL drastically improves performance for conditional breakpoints
as they use local debug-evaluate under the hood. The worst case
example (https://crbug.com/1072939#c15) improves from 6.5 seconds
to 100ms.
R=jarin@chromium.org
Bug: chromium:1363561
Change-Id: I85f3d908d246f0d2e31ed272f4db6a852b9dbc39
Reviewed-on: https://chromium-review.googlesource.com/c/v8/v8/+/3941584
Commit-Queue: Simon Zünd <szuend@chromium.org>
Reviewed-by: Jaroslav Sevcik <jarin@chromium.org>
Reviewed-by: Leszek Swirski <leszeks@chromium.org>
Cr-Commit-Position: refs/heads/main@{#83665}
We currently use 1 test case per file for tests that check that
debug-evaluate correctly blocks the lookup of stack-allocated
variables.
This CL adapts a similar approach to `debug-scopes.js`, making it
easier to add new test cases in the future.
R=kimanh@chromium.org
Bug: chromium:1363561
Change-Id: I8ff8cfe7d59f0b9808dc02c5579e058f490553eb
Reviewed-on: https://chromium-review.googlesource.com/c/v8/v8/+/3904544
Commit-Queue: Simon Zünd <szuend@chromium.org>
Reviewed-by: Kim-Anh Tran <kimanh@chromium.org>
Cr-Commit-Position: refs/heads/main@{#83315}
* Fix setting script-scope variables through inspector by internalizing
their names.
* Reconstruct values of Number, String, and Boolean classes.
* Adapt a couple of tests for API restrictions.
BUG=v8:5530
Review-Url: https://codereview.chromium.org/2512963002
Cr-Commit-Position: refs/heads/master@{#41175}