Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Utility methods for artificial debug types in the generated DWARF #1482

Merged
merged 12 commits into from
Apr 10, 2020

Conversation

yurydelendik
Copy link
Contributor

@yurydelendik yurydelendik commented Apr 7, 2020

Currently, artificial "wrapper" types are created for pointer types. These wrappers display Wasm pointers as i32. To dereference such wrapper/pointer the function's vmctx is needed. This PR is an attempt to provide overrides for artificial type for operator* and operator->.

The runtime/host has to have set_vmctx_memory and resolve_vmctx_memory_ptr builtins. The former sets current context and the former derefernces the Wasm pointer using current context's memory base.

During LLDB session, a user has to call __vmctx.set() to set the current context before calling any dereference operators. It can be automated via e.g. command regex pp 's/(.+)/p __vmctx->set(),%1/'.

Example of the LLDB session (see also gist):

Process 50041 stopped
* thread #1, queue = 'com.apple.main-thread', stop reason = breakpoint 1.1
    frame #0: 0x00000001042ca05d JIT(0x105000600)`check(i=1) at t.c:13:3
   10   
   11   int check(size_t i) {
   12     struct Test *y = t + i;
-> 13     y->i++;
   14     return y->j;
   15   }
   16   
(lldb) p y
(WebAssemblyPtrWrapper<Test>) $0 = (__ptr = 1032)
(lldb) pp *y
(Test) $1 = (i = 3, j = 4)
(lldb) pp y->j
(int) $2 = 4
(lldb) fr v
(WasmtimeVMContext *) __vmctx = 0x0000000103503ba0
(size_t) i = 1
(WebAssemblyPtrWrapper<Test>) y = (__ptr = 1032)

TODO:

@github-actions github-actions bot added the wasmtime:api Related to the API of the `wasmtime` crate itself label Apr 7, 2020
@github-actions
Copy link

github-actions bot commented Apr 7, 2020

Subscribe to Label Action

This issue or pull request has been labeled: "wasmtime:api"

Users Subscribed to "wasmtime:api"

To subscribe or unsubscribe from this label, edit the .github/subscribe-to-label.json configuration file.

Learn more.

Copy link
Member

@fitzgen fitzgen left a comment

Choose a reason for hiding this comment

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

Clever hack :)

/// Ensures that set_vmctx_memory and resolve_vmctx_memory_ptr are linked and
/// exported as symbols. It is a workaround: the executable normally ignores
/// `pub extern "C"`, see rust-lang/rust#25057.
pub fn ensure_exported() {
Copy link
Member

Choose a reason for hiding this comment

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

If this module is pub (can also be #[doc(hidden)] to avoid "really" making it public) then I think we don't need this hack.

Copy link
Contributor

Choose a reason for hiding this comment

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

Or use #[doc(hidden)] pub use crate::debug_builtins::{set_vmctx_memory, resolve_vmctx_memory_ptr}; in the crate root.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

If you are suggesting to remove ensure_exported, then it does not work. See rust-lang/rust#25057

crates/runtime/src/debug_builtins.rs Show resolved Hide resolved
crates/runtime/src/debug_builtins.rs Outdated Show resolved Hide resolved
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