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

  Changed paths:
    A JSTests/wasm/debugger/resources/swift-wasm/test/multi-instance.js
    A JSTests/wasm/debugger/resources/wasm/multi-instance-both-running.js
    A JSTests/wasm/debugger/resources/wasm/multi-instance-caller-frame.js
    A JSTests/wasm/debugger/resources/wasm/multi-instance-same-module.js
    A JSTests/wasm/debugger/resources/wasm/multi-instance-three.js
    A JSTests/wasm/debugger/resources/wasm/multi-instance-unreachable.js
    M JSTests/wasm/debugger/tests/tests.py
    M Source/JavaScriptCore/wasm/WasmModule.cpp
    M Source/JavaScriptCore/wasm/WasmModule.h
    M Source/JavaScriptCore/wasm/debugger/README.md
    M Source/JavaScriptCore/wasm/debugger/RWI_ARCHITECTURE.md
    M Source/JavaScriptCore/wasm/debugger/WasmBreakpointManager.cpp
    M Source/JavaScriptCore/wasm/debugger/WasmBreakpointManager.h
    M Source/JavaScriptCore/wasm/debugger/WasmDebugServer.cpp
    M Source/JavaScriptCore/wasm/debugger/WasmDebugServer.h
    M Source/JavaScriptCore/wasm/debugger/WasmDebugServerUtilities.h
    M Source/JavaScriptCore/wasm/debugger/WasmExecutionHandler.cpp
    M Source/JavaScriptCore/wasm/debugger/WasmExecutionHandler.h
    M Source/JavaScriptCore/wasm/debugger/WasmMemoryHandler.cpp
    M Source/JavaScriptCore/wasm/debugger/WasmMemoryHandler.h
    M Source/JavaScriptCore/wasm/debugger/WasmModuleDebugInfo.cpp
    M Source/JavaScriptCore/wasm/debugger/WasmModuleDebugInfo.h
    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/WasmVirtualAddress.cpp
    M Source/JavaScriptCore/wasm/debugger/WasmVirtualAddress.h
    M Source/JavaScriptCore/wasm/debugger/tests/ExecutionHandlerTest.cpp
    M Source/JavaScriptCore/wasm/debugger/testwasmdebugger.cpp

  Log Message:
  -----------
  [JSC] Use instance IDs for Wasm debugger virtual addresses
https://bugs.webkit.org/show_bug.cgi?id=323479
rdar://186722231

Reviewed by Yijia Huang.

Wasm scopes linear memory, globals, tables, and data segments to an
instance rather than a module. The debugger used the module ID to
identify the module in its virtual address space.

Use the instance ID in both halves of the address space. Every live
instance now gets its own library entry, module image, and linear memory
region, which removes the workaround `qWasmGlobal` needed to map a
unique module ID back to an instance. LLDB assumes libraries have unique
names, so every named library is suffixed with its instance id
(`<name>@<id>`).

A breakpoint patches module bytecode, which every instance of a module
shares, so the patch stays keyed by physical PC. A site, though, belongs
to the instance its address names: LLDB gives every instance its own
library and installs one site in each, so a site says "stop this
instance here", not "stop this bytecode". A sibling reaching the same
patched byte resumes through it, dispatching the opcode the patch
displaced, without reporting a stop. Setting a breakpoint by symbol name
still covers every instance, because the symbol resolves once per
library. The patch is lifted only once the last site referring to it and
any step in flight are both gone.

Collecting an instance drops its sites. LLDB unloads the library without
sending z0 for what was in it, so nothing else would release the patch
they keep alive. Tearing down an instance is also treated as a library
change, prompting LLDB to requery the library list in the stop reply.

Stepping off a trap now arms the trapping function's entry. LLDB pulls
its site before stepping over it and restores it only once the step
reports a stop, so a program that catches the trap and loops straight
back would run past the user's breakpoint every time.

* JSTests/wasm/debugger/resources/swift-wasm/test/multi-instance.js: Added.
(imports.wasi_snapshot_preview1.proc_exit):
(imports.wasi_snapshot_preview1.args_get):
(imports.wasi_snapshot_preview1.args_sizes_get):
(imports.wasi_snapshot_preview1.environ_get):
(imports.wasi_snapshot_preview1.environ_sizes_get):
(imports.wasi_snapshot_preview1.fd_write):
(imports.wasi_snapshot_preview1.fd_read):
(imports.wasi_snapshot_preview1.fd_close):
(imports.wasi_snapshot_preview1.fd_seek):
(imports.wasi_snapshot_preview1.fd_fdstat_get):
(imports.wasi_snapshot_preview1.fd_prestat_get):
(imports.wasi_snapshot_preview1.fd_prestat_dir_name):
(imports.wasi_snapshot_preview1.path_open):
(imports.wasi_snapshot_preview1.random_get):
(imports.wasi_snapshot_preview1.clock_time_get):
* JSTests/wasm/debugger/resources/wasm/multi-instance-both-running.js: Added.
* JSTests/wasm/debugger/resources/wasm/multi-instance-caller-frame.js: Added.
* JSTests/wasm/debugger/resources/wasm/multi-instance-same-module.js: Added.
* JSTests/wasm/debugger/resources/wasm/multi-instance-three.js: Added.
* JSTests/wasm/debugger/resources/wasm/multi-instance-unreachable.js: Added.
(catch):
* JSTests/wasm/debugger/tests/tests.py:
(DynamicModuleLoadTestCase.execute):
(SwiftWasmDynamicModuleLoadTestCase.execute):
(MultiInstanceCallerFrameTestCase):
(MultiInstanceCallerFrameTestCase.execute):
(MultiInstanceSameModuleTestCase):
(MultiInstanceSameModuleTestCase.execute):
(MultiInstanceForeignSiteIgnoredTestCase):
(MultiInstanceForeignSiteIgnoredTestCase.execute):
(MultiInstanceStepOverSharedPatchTestCase):
(MultiInstanceStepOverSharedPatchTestCase.execute):
(MultiInstanceBreakpointDisableTestCase):
(MultiInstanceBreakpointDisableTestCase.execute):
(MultiInstanceBreakpointDeleteTestCase):
(MultiInstanceBreakpointDeleteTestCase.execute):
(MultiInstanceUnreachableOwnSiteTestCase):
(MultiInstanceUnreachableOwnSiteTestCase.execute):
(MultiInstanceUnreachableForeignSiteTestCase):
(MultiInstanceUnreachableForeignSiteTestCase.execute):
(MultiInstanceUnreachableBothSitesTestCase):
(MultiInstanceUnreachableBothSitesTestCase.execute):
(MultiInstanceUnreachableStepTestCase):
(MultiInstanceUnreachableStepTestCase.execute):
(MultiInstanceBothRunningTestCase):
(MultiInstanceBothRunningTestCase.execute):
(MultiInstanceForeignSiteOpcodeShapesTestCase):
(MultiInstanceForeignSiteOpcodeShapesTestCase.execute):
(MultiInstanceThreeInstancesTestCase):
(MultiInstanceThreeInstancesTestCase.execute):
(CWasmTestCase.memoryTest):
(SwiftWasmTestCase.memoryTest):
(ModuleNamingFromNameSectionTestCase.execute):
(StreamingModuleSourceURLTestCase.execute):
(SwiftWasmMultiInstanceTestCase):
(SwiftWasmMultiInstanceTestCase.execute):
* Source/JavaScriptCore/wasm/WasmModule.cpp:
(JSC::Wasm::Module::Module):
(JSC::Wasm::Module::~Module):
(JSC::Wasm::Module::debugId const): Deleted.
(JSC::Wasm::Module::setDebugId): Deleted.
* Source/JavaScriptCore/wasm/WasmModule.h:
* Source/JavaScriptCore/wasm/debugger/README.md:
* Source/JavaScriptCore/wasm/debugger/RWI_ARCHITECTURE.md:
* Source/JavaScriptCore/wasm/debugger/WasmBreakpointManager.cpp:
(JSC::Wasm::BreakpointManager::releasePatchIfUnused):
(JSC::Wasm::BreakpointManager::breakpointAt):
(JSC::Wasm::BreakpointManager::setBreakpointAt):
(JSC::Wasm::BreakpointManager::removeSiteImpl):
(JSC::Wasm::BreakpointManager::removeBreakpointAt):
(JSC::Wasm::BreakpointManager::removeSitesForInstance):
(JSC::Wasm::BreakpointManager::trapActionFor):
* Source/JavaScriptCore/wasm/debugger/WasmBreakpointManager.h:
* Source/JavaScriptCore/wasm/debugger/WasmDebugServer.cpp:
(JSC::Wasm::DebugServer::trackInstance):
(JSC::Wasm::DebugServer::trackModule): Deleted.
(JSC::Wasm::DebugServer::untrackModule): Deleted.
* Source/JavaScriptCore/wasm/debugger/WasmDebugServer.h:
* Source/JavaScriptCore/wasm/debugger/WasmDebugServerUtilities.h:
(JSC::Wasm::Breakpoint::dump const):
* Source/JavaScriptCore/wasm/debugger/WasmExecutionHandler.cpp:
(JSC::Wasm::ExecutionHandler::handleDebuggerTrapIfNeeded):
(JSC::Wasm::ExecutionHandler::step):
(JSC::Wasm::ExecutionHandler::notifyDebuggerOfNewInstance):
(JSC::Wasm::ExecutionHandler::setBreakpoint):
(JSC::Wasm::ExecutionHandler::removeBreakpoint):
(JSC::Wasm::ExecutionHandler::sendStopReplyForThread):
(JSC::Wasm::ExecutionHandler::notifyDebuggerOfNewModule): Deleted.
(JSC::Wasm::WTF_REQUIRES_LOCK):
(JSC::Wasm::ExecutionHandler::callStackStringFor):
* Source/JavaScriptCore/wasm/debugger/WasmExecutionHandler.h:
* Source/JavaScriptCore/wasm/debugger/WasmMemoryHandler.cpp:
(JSC::Wasm::MemoryHandler::readMemory):
(JSC::Wasm::MemoryHandler::readModuleData):
(JSC::Wasm::MemoryHandler::readMemoryData):
(JSC::Wasm::MemoryHandler::handleMemoryRegionInfo):
(JSC::Wasm::MemoryHandler::handleWasmMemoryRegionInfo):
(JSC::Wasm::MemoryHandler::handleWasmModuleRegionInfo):
(JSC::Wasm::MemoryHandler::write):
* Source/JavaScriptCore/wasm/debugger/WasmMemoryHandler.h:
* Source/JavaScriptCore/wasm/debugger/WasmModuleDebugInfo.cpp:
(JSC::Wasm::ModuleDebugInfo::declaredName const):
(JSC::Wasm::ModuleDebugInfo::debugName const): Deleted.
* Source/JavaScriptCore/wasm/debugger/WasmModuleDebugInfo.h:
(): Deleted.
* Source/JavaScriptCore/wasm/debugger/WasmModuleManager.cpp:
(JSC::Wasm::ModuleManager::registerInstance):
(JSC::Wasm::ModuleManager::needsLibraryRequery):
(JSC::Wasm::ModuleManager::unnotifiedInstanceIds const):
(JSC::Wasm::ModuleManager::takeCollectedInstanceIds):
(JSC::Wasm::ModuleManager::generateLibrariesXML const):
(JSC::Wasm::ModuleManager::sweepDeadInstances):
(JSC::Wasm::ModuleManager::registerModule): Deleted.
(JSC::Wasm::ModuleManager::unregisterModule): Deleted.
(JSC::Wasm::ModuleManager::needsNewModuleNotification): Deleted.
(JSC::Wasm::ModuleManager::unnotifiedModuleIds const): Deleted.
(JSC::Wasm::ModuleManager::soleInstanceOfModule): Deleted.
(JSC::Wasm::ModuleManager::notifyLibraryRequeryComplete):
(JSC::Wasm::ModuleManager::amortizedCleanupIfNeeded):
(JSC::Wasm::ModuleManager::needsLibraryRequery const): Deleted.
(JSC::Wasm::ModuleManager::module const): Deleted.
* Source/JavaScriptCore/wasm/debugger/WasmModuleManager.h:
* Source/JavaScriptCore/wasm/debugger/WasmQueryHandler.cpp:
(JSC::Wasm::QueryHandler::handleWasmGlobal):
(JSC::Wasm::QueryHandler::instanceForModule): Deleted.
* Source/JavaScriptCore/wasm/debugger/WasmQueryHandler.h:
* Source/JavaScriptCore/wasm/debugger/WasmVirtualAddress.cpp:
(JSC::Wasm::VirtualAddress::toPhysicalPC):
(JSC::Wasm::VirtualAddress::dump const):
(JSC::Wasm::VirtualAddress::toVirtual):
* Source/JavaScriptCore/wasm/debugger/WasmVirtualAddress.h:
(JSC::Wasm::VirtualAddress::instanceId const):
(JSC::Wasm::VirtualAddress::createModule):
(JSC::Wasm::VirtualAddress::encode):
(JSC::Wasm::VirtualAddress::id const): Deleted.
* Source/JavaScriptCore/wasm/debugger/tests/ExecutionHandlerTest.cpp:
(ExecutionHandlerTest::entryAddress):
(ExecutionHandlerTest::setBreakpointsAtAllFunctionEntries):
(ExecutionHandlerTest::testBreakpointSingleStepping):
(ExecutionHandlerTest::testInstanceScopedAddressing):
(ExecutionHandlerTest::testSharedBytecodeBreakpoints):
(ExecutionHandlerTest::runTests):
(ExecutionHandlerTest::testSoleInstanceOfModule): Deleted.
(ExecutionHandlerTest::liveInstancesByModule):
* Source/JavaScriptCore/wasm/debugger/testwasmdebugger.cpp:
(testWASMVirtualAddressConstants):
(testWASMVirtualAddressEncoding):
(testWASMVirtualAddressLLDBEnumeration):
(testWASMVirtualAddressEdgeCases):

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



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

Reply via email to