Skip to content

Debugging: provide access to private (non-exported) entities.#12367

Merged
cfallin merged 3 commits intobytecodealliance:mainfrom
cfallin:debugging-access-private-entities
Jan 21, 2026
Merged

Debugging: provide access to private (non-exported) entities.#12367
cfallin merged 3 commits intobytecodealliance:mainfrom
cfallin:debugging-access-private-entities

Conversation

@cfallin
Copy link
Member

@cfallin cfallin commented Jan 17, 2026

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 ptrace and 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_debug is configured true for a given engine. Otherwise, the accessor returns None.

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.

@cfallin cfallin requested a review from alexcrichton January 17, 2026 03:25
@cfallin cfallin requested a review from a team as a code owner January 17, 2026 03:25
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 `ptrace` and 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_debug` is configured true for a
given engine. Otherwise, the accessor returns `None`.

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.
@cfallin cfallin force-pushed the debugging-access-private-entities branch from c70a0cb to 7c835c6 Compare January 17, 2026 03:26
@github-actions github-actions bot added the wasmtime:api Related to the API of the `wasmtime` crate itself label Jan 17, 2026
@cfallin
Copy link
Member Author

cfallin commented Jan 21, 2026

Reworked now -- a bit more verbose API but seems more in line with what is there already. Thanks!

Copy link
Member

@alexcrichton alexcrichton left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

FWIW we more-or-less consider wasmtime-environ to 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 as wasmtime-the-crate.

@cfallin cfallin added this pull request to the merge queue Jan 21, 2026
@github-merge-queue github-merge-queue bot removed this pull request from the merge queue due to failed status checks Jan 21, 2026
@cfallin cfallin enabled auto-merge January 21, 2026 16:48
@cfallin cfallin added this pull request to the merge queue Jan 21, 2026
Merged via the queue into bytecodealliance:main with commit 2326d65 Jan 21, 2026
45 checks passed
@cfallin cfallin deleted the debugging-access-private-entities branch January 21, 2026 17:23
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

wasmtime:api Related to the API of the `wasmtime` crate itself

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants