10 Commits
Author SHA1 Message Date
Benedikt Meurer dfed06567f [test] Migrate 5 debug-evaluate debugger tests to inspector
Migrate debug/debug-evaluate-repl-mode-optimized.js, debug/debug-evaluate-repl-mode.js, debug/debug-evaluate-shadowed-context-reuse.js, debug/debug-evaluate-shadowed-context.js, and debug/debug-evaluate-with.js from test/debugger to test/inspector.

Bug: 573042262
Change-Id: If63a894cb99d8bc6a207085d0a3d0262130c80df
Reviewed-on: https://chromium-review.googlesource.com/c/v8/v8/+/8688380
Auto-Submit: Benedikt Meurer <bmeurer@chromium.org>
Reviewed-by: Yang Guo <yangguo@chromium.org>
Commit-Queue: Yang Guo <yangguo@chromium.org>
Cr-Commit-Position: refs/heads/main@{#111446}
2026-10-30 11:57:32 -07:00
Simon Zünd e58e145c8c [debug] Walk outer lexical scopes via DebugScriptScope
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}
2026-10-06 21:52:25 -07:00
Simon Zünd 2f6d9fb4b8 [debug] Switch DebugEvaluate::ContextBuilder to EnsureLocalsBlockList
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}
2026-09-22 22:21:33 -07:00
Simon Zünd a817808e4a [debugger] Fix stack blocklist for outer closure scopes
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}
2026-08-05 07:33:05 -07:00
Simon Zünd 3f6e810067 [inspector] Add 'scopeNumber' to 'Debugger.evaluateOnCallFrame'
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}
2026-08-05 04:35:02 -07:00
Erik Corry 448689f3b2 [spelling] Re-use to reuse
Change-Id: I9ee5130dd2b7f778c85210090f9ce3fb2ef233ca
Reviewed-on: https://chromium-review.googlesource.com/c/v8/v8/+/6191011
Reviewed-by: Toon Verwaest <verwaest@chromium.org>
Commit-Queue: Toon Verwaest <verwaest@chromium.org>
Cr-Commit-Position: refs/heads/main@{#98304}
2025-01-24 04:37:29 -08:00
Simon Zünd 07cc86889c [debug] Re-use block lists across multiple local debug-evaluates
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}
2022-10-13 07:44:59 +00:00
Simon Zünd bf28ec635b [debug] Add new debug-evaluate block list test
This CL adds a test that checks the block list for outer functions is
also correctly calculated when pausing in inner functions.

R=kimanh@chromium.org

Bug: chromium:1363561
Change-Id: I2d7c1671475759b977e4e41c7e09856b3b2e7daf
Reviewed-on: https://chromium-review.googlesource.com/c/v8/v8/+/3904308
Reviewed-by: Kim-Anh Tran <kimanh@chromium.org>
Commit-Queue: Simon Zünd <szuend@chromium.org>
Cr-Commit-Position: refs/heads/main@{#83319}
2022-09-20 09:17:31 +00:00
Simon Zünd 354f4f0858 [debug] Refactor 'shadowing' tests for debug-evaluate
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}
2022-09-20 08:18:52 +00:00
jgruber facd6b9a4a [debug-wrapper] Migrate more tests
* 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}
2016-11-22 12:44:18 +00:00