Branch: refs/heads/main
  Home:   https://github.com/WebKit/WebKit
  Commit: ca158eb19b753004c61c9405265669ccfdd8557a
      
https://github.com/WebKit/WebKit/commit/ca158eb19b753004c61c9405265669ccfdd8557a
  Author: Jonas Devlieghere <[email protected]>
  Date:   2026-09-04 (Fri, 04 Sep 2026)

  Changed paths:
    M JSTests/wasm/debugger/lib/environment.py
    M JSTests/wasm/debugger/lib/session.py
    M JSTests/wasm/debugger/test-wasm-debugger.py
    M Source/JavaScriptCore/wasm/WasmModule.h
    M Source/JavaScriptCore/wasm/debugger/README.md
    M Source/JavaScriptCore/wasm/debugger/WasmModuleManager.cpp
    M Source/JavaScriptCore/wasm/debugger/WasmModuleManager.h
    M Source/JavaScriptCore/wasm/debugger/WasmQueryHandler.cpp
    M Source/JavaScriptCore/wasm/debugger/WasmQueryHandler.h
    M Source/JavaScriptCore/wasm/debugger/tests/ExecutionHandlerTest.cpp
    M Source/JavaScriptCore/wasm/debugger/tests/TestScripts.cpp
    M Source/JavaScriptCore/wasm/debugger/tests/TestScripts.h

  Log Message:
  -----------
  [JSC] Adopt the instance-scoped qWasmGlobal packet form
https://bugs.webkit.org/show_bug.cgi?id=323123

Reviewed by Yijia Huang.

A Wasm global belongs to a module instance, not to a frame. The global
index space is per instance, and DW_OP_WASM_location's global operand
indexes the index space of the instance whose code is being evaluated.
qWasmGlobal took a frame index and used it as a proxy for that instance,
which left the globals of an instance with no active frame out of reach:
a page loading several modules could only inspect whichever one it
happened to be stopped inside.

LLDB has since landed a form that names the instance directly:

    qWasmGlobal:<global-index>;instance:<instance-id>

    https://github.com/llvm/llvm-project/pull/213176
    resolving https://github.com/llvm/llvm-project/issues/212833

This PR adds support for the new packet variant. The id is the module id
already carried in bits 61:32 of a Wasm virtual address. A stub opts in
by advertising qWasmInstance+ in its qSupported reply, which covers any
Wasm query whose scope is an instance rather than a frame. A client that
does not opt in keeps getting the frame form, and the two are told apart
by the presence of the instance: key.

Besides that, I had to make the following changes:

- Because the id is a module id it cannot distinguish two instances of
  one module, which have separate globals.
  ModuleManager::soleInstanceOfModule() answers only when the module has
  exactly one live instance, and QueryHandler::instanceForModule()
  additionally accepts a module the debuggee is stopped in, where the
  stop itself picks the instance. Anything else replies with an error
  rather than guessing, since a wrong value is indistinguishable from a
  right one on the wire.

- Also stop qWasmLocal from defaulting an unparsable field to zero.
  parseDecimal() returns 0 for a field that is not a number, so a client
  sending a field this packet does not have read local 0 of frame 0 and
  got a plausible wrong answer instead of an error. This matters more
  now that a second packet shape exists.

- Module::debugId() becomes JS_EXPORT_PRIVATE so the new test can link
  against it.

- On the test side, setBreakpointsAtAllFunctionEntries() now visits each
  module once rather than once per instance. Breakpoints patch module
  bytecode, which every instance of a module shares, and patching twice
  records the breakpoint opcode itself as the original bytecode. That
  was unreachable until a script held two instances of one module.

Test: MultiVMMultipleInstancesPerModule exercises both the sole-instance

and ambiguous paths; testSoleInstanceOfModule derives its expectation
from the instances actually registered, so it holds for every script.

* Source/JavaScriptCore/wasm/WasmModule.h:
* Source/JavaScriptCore/wasm/debugger/README.md:
* Source/JavaScriptCore/wasm/debugger/WasmModuleManager.cpp:
(JSC::Wasm::ModuleManager::soleInstanceOfModule):
* Source/JavaScriptCore/wasm/debugger/WasmModuleManager.h:
* Source/JavaScriptCore/wasm/debugger/WasmQueryHandler.cpp:
(JSC::Wasm::QueryHandler::handleSupported):
(JSC::Wasm::QueryHandler::handleWasmLocal):
(JSC::Wasm::QueryHandler::instanceForModule):
(JSC::Wasm::QueryHandler::instanceForFrame):
(JSC::Wasm::QueryHandler::handleWasmGlobal):
* Source/JavaScriptCore/wasm/debugger/WasmQueryHandler.h:
* Source/JavaScriptCore/wasm/debugger/tests/ExecutionHandlerTest.cpp:
(ExecutionHandlerTest::setBreakpointsAtAllFunctionEntries):
(ExecutionHandlerTest::testSoleInstanceOfModule):
(ExecutionHandlerTest::setupScriptAndWaitForVMs):
(ExecutionHandlerTest::runTests):
* Source/JavaScriptCore/wasm/debugger/tests/TestScripts.cpp:
* Source/JavaScriptCore/wasm/debugger/tests/TestScripts.h:
* JSTests/wasm/debugger/lib/environment.py:
(WebKitEnvironment.__init__):
* JSTests/wasm/debugger/lib/session.py:
(_source_map_command):
(DebugSession.__init__):
* JSTests/wasm/debugger/test-wasm-debugger.py:
(main):

Canonical link: https://commits.webkit.org/320536@main



To unsubscribe from these emails, change your notification settings at 
https://github.com/WebKit/WebKit/settings/notifications

Reply via email to