cfallin opened PR #15365 from cfallin:fix-15332 to bytecodealliance:main:
When guest debugging is enabled, a module used within a given store gets a private copy of the code. We call the original code "engine code" and the maybe-private copy "store code". We have newtypes around PCs for both (
EngineCodePCandStoreCodePC). When guest debugging is disabled, we still call the actually executing copy the "store code"; it just happens to alias the engine code instead (no private copy).Various parts of the runtime do lookups based on observed PCs in frames (e.g., trap code loop, GC stackmap lookup, and exception-handler lookup).
I wrote most of this code when the invariant was still that all code actually running in a given store would be "store code". Late in the implementation of guest debugging, I discovered it would not be easily possible to have a private copy of some trampolines, but that they were "store-invariant" (no breakpoint patching was possible since no guest Wasm program points were present in the trampolines), so it was fine to run the canonical/shared engine copy.
Unfortunately, the idea that we look up "store PCs" only is in conflict with this, and we thus would not find e.g. exception handlers in store-invariant trampolines (see #15332 for an example).
This PR generalizes things a bit: we can look up both engine PCs and store PCs in the per-store registry, and we can get a sum-type result that can represent a PC found in either kind of copy. We can look up metadata and derive exception-handler PCs from either kind of hit. We then use this in all the relevant places that we do PC lookups.
Fixes #15332.
<!--
Please make sure you include the following information:
If this work has been discussed elsewhere, please include a link to that
conversation. If it was discussed in an issue, just mention "issue #...".Explain why this change is needed. If the details are in an issue already,
this can be brief.Our development process is documented in the Wasmtime book:
https://docs.wasmtime.dev/contributing-development-process.htmlPlease review the Bytecode Alliance's AI tool usage policy at
https://github.com/bytecodealliance/governance/blob/main/AI_TOOL_POLICY.mdPlease ensure all communication follows the code of conduct:
https://github.com/bytecodealliance/wasmtime/blob/main/CODE_OF_CONDUCT.md
-->
cfallin requested dicej for a review on PR #15365.
cfallin removed the review request for wasmtime-core-reviewers from PR #15365.
cfallin requested wasmtime-core-reviewers for a review on PR #15365.
cfallin removed the review request for dicej from PR #15365.
cfallin requested alexcrichton for a review on PR #15365.
github-actions[bot] added the label wasmtime:api on PR #15365.
:memo: alexcrichton submitted PR review.
:speech_balloon: alexcrichton created PR review comment:
Could it make sense to maybe return
(&CodeMemory, usize)here instead ofStoreOrEngineCodeAndOffset? It naively seems like all the queries basically bottom out in&CodeMemory
:speech_balloon: alexcrichton created PR review comment:
Alternatively, would it make sense to maybe call this
code_memory_by_pc?And, additionally, could
store_code_by_pcbe made private? it seems like all users of it are now gone with the migration to using this function. (maybe this means the preexisting function could be replaced bycode_memory_by_pc?)
:speech_balloon: alexcrichton created PR review comment:
I'm always wary of adding more storage here since this is on the hot path for instantiation. Cloning this in a multi-tenant situation could be a hotly-contended clone of an
Arcwhich has historically been able to show up in profiles (and this is a secondclonewith the one above). I'm also wary of adding always-on functionality which is only needed when debugging.Would it make sense to maybe have this be
Option<Arc<EngineCode>>and only set this ifStoreCodeabove is a store-local copy?
Last updated: Nov 19 2026 at 20:05 UTC