cfallin requested alexcrichton for a review on PR #12367.
cfallin opened PR #12367 from cfallin:debugging-access-private-entities to bytecodealliance:main:
A debugger will need to access all entities (globals, tables, memories), even those that are not exported, in order to provide a full debugging experience: for example, a developer who has a developer attached to a Wasm component will expect to be able to see data in its memory.
Historically we have been very careful in Wasmtime to provide access to Wasm instances' entities only as the Wasm type system allows -- that is, only if they are exported. However, debugging is privileged -- in the same way that a native host debugger has
ptraceand can view everything about the debuggee, we need to provide APIs for seeing through the encapsulation boundary.To ensure that this "violation of encapsulation" is scoped only to the extent needed for the legitimate need (debugging), this API is dynamically available only when
guest_debugis configured true for a given engine. Otherwise, the accessor returnsNone.I opted not to provide a full introspection API that enumerates all of the entities as the debugger should already have access to the debuggee module and be able to enumerate the entities. Thus, the API only provides a host-API handle when asking for an entity by index in a given instance's index space.
<!--
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 ensure all communication follows the code of conduct:
https://github.com/bytecodealliance/wasmtime/blob/main/CODE_OF_CONDUCT.md
-->
cfallin requested wasmtime-core-reviewers for a review on PR #12367.
cfallin edited PR #12367:
A debugger will need to access all entities (globals, tables, memories), even those that are not exported, in order to provide a full debugging experience: for example, a developer who has a debugger attached to a Wasm component will expect to be able to see data in its memory.
Historically we have been very careful in Wasmtime to provide access to Wasm instances' entities only as the Wasm type system allows -- that is, only if they are exported. However, debugging is privileged -- in the same way that a native host debugger has
ptraceand can view everything about the debuggee, we need to provide APIs for seeing through the encapsulation boundary.To ensure that this "violation of encapsulation" is scoped only to the extent needed for the legitimate need (debugging), this API is dynamically available only when
guest_debugis configured true for a given engine. Otherwise, the accessor returnsNone.I opted not to provide a full introspection API that enumerates all of the entities as the debugger should already have access to the debuggee module and be able to enumerate the entities. Thus, the API only provides a host-API handle when asking for an entity by index in a given instance's index space.
<!--
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 ensure all communication follows the code of conduct:
https://github.com/bytecodealliance/wasmtime/blob/main/CODE_OF_CONDUCT.md
-->
cfallin updated PR #12367.
github-actions[bot] added the label wasmtime:api on PR #12367.
alexcrichton submitted PR review.
alexcrichton created PR review comment:
In the limit, this is something we'll want debuggers to do, right? And this in theory would be pretty easy for us to handle internally by using
tunables.debug_guestas a flag to assume that all functions are exported?
alexcrichton created PR review comment:
Instead of duplicating the documentation, could one of the methods with documentation link to the other?
alexcrichton created PR review comment:
Could this function use
vm::Instance::get_export_by_index_mutto avoid duplication? Plus some extra validation ahead of time that the index is valid for the instance-at-hand.
alexcrichton created PR review comment:
Despite being unable to do anything with them at the moment, is there a reason to specifically disallow this? I figure it'd be best to go ahead and fill things out while we can otherwise
alexcrichton created PR review comment:
Right now
FooIndex-style types are all internal to Wasmtime and not present in Wasmtime's public API (or at least that's the intention). Given that it might be best to switch this todebug_get_{global,func,table,memory,tag}perhaps?Also, I might recommend putting the functionality on
Instancesince that seems like a natural place to put the methods. You can still do it in this file withimpl Instance { ... }since this is still in the same crate definingInstance.
fitzgen submitted PR review.
fitzgen created PR review comment:
Yes and yes, IMO.
cfallin submitted PR review.
cfallin created PR review comment:
Unfortunately I want a panic-free interface here (we will expose this method to the debugger guest) so that whole function hierarchy is unusable -- it panics on out-of-bounds.
cfallin submitted PR review.
cfallin created PR review comment:
I guess I just didn't want to think through the implications until needed but it seems tag exports are pretty harmless, so I'll add this!
cfallin created PR review comment:
Yep, I was following precedent here with the bits on
Store/StoreContextMutbut since this API will move toInstancethis won't be an issue anymore.
cfallin submitted PR review.
cfallin submitted PR review.
cfallin created PR review comment:
Fair enough -- I saw the types were public via
wasmtime_environbut I'm happy to stick withu32s!I'll move the API over to
Instance-- was trying to keep the debug API small and localized to a few methods on the store but I agree it makes more sense alongside other accessors per-instance.
cfallin updated PR #12367.
cfallin submitted PR review.
cfallin created PR review comment:
Err, reading again your "extra validation ahead of time" -- once that bit is done, the rest of the logic is pretty trivial (one result expression) and actually a bit simpler than rebuilding an
EntityIndexso I think I'll leave as-is -- happy to tweak if desired though.
cfallin submitted PR review.
cfallin created PR review comment:
Done!
cfallin submitted PR review.
cfallin created PR review comment:
Done! Added the bit to flag all functions as escaping and test cases both for call to unexported module-defined func and unexported import.
cfallin commented on PR #12367:
Reworked now -- a bit more verbose API but seems more in line with what is there already. Thanks!
alexcrichton created PR review comment:
In addition to
CodeSectionEntry, I think this'll need to be done for function imports too
alexcrichton created PR review comment:
Instead of making the field public could this use the
instance.id()method?
alexcrichton submitted PR review:
FWIW we more-or-less consider
wasmtime-environto be a private crate for now. It's "more public" than everything else we have that's not actually public given its history, but we haven't pulled the trigger on making it actually official or anything like that. I think it would need a lot of API cleanups to have the same quality aswasmtime-the-crate.
cfallin submitted PR review.
cfallin created PR review comment:
Unfortunately that returns an
InstanceIdand we need aStoreInstanceIdto index into the store; it appears thatfn id()isn't used anywhere else for this purpose and all other accessors that pull out thevm::Instancefrom the store live ininstance.rsand use the field directly. Happy to refactor all this in followup if you want to push it in a different direction!
cfallin submitted PR review.
cfallin created PR review comment:
Surprisingly this is already done here; and the tests added in this PR already exercise that path as well (I was unsure too!).
cfallin added PR #12367 Debugging: provide access to private (non-exported) entities. to the merge queue
github-merge-queue[bot] removed PR #12367 Debugging: provide access to private (non-exported) entities. from the merge queue
cfallin updated PR #12367.
cfallin has enabled auto merge for PR #12367.
cfallin added PR #12367 Debugging: provide access to private (non-exported) entities. to the merge queue
cfallin merged PR #12367.
cfallin removed PR #12367 Debugging: provide access to private (non-exported) entities. from the merge queue
Last updated: Jan 29 2026 at 13:25 UTC