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

Recommend -O opt-level=0 when debugging wasm #8755

Merged
merged 2 commits into from
Jun 7, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 3 additions & 2 deletions docs/examples-debugging-native-debugger.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,15 +13,16 @@ the same time:

2. Run Wasmtime with the debug info enabled; this is `-D debug-info` from the
CLI and `Config::debug_info(true)` in an embedding (e.g. see [debugging in a
Rust embedding](./examples-rust-debugging.md))
Rust embedding](./examples-rust-debugging.md)). It's also recommended to use
`-O opt-level=0` for better inspection of local variables if desired.

3. Use a supported debugger:

```sh
lldb -- wasmtime run -D debug-info foo.wasm
```
```sh
gdb --args wasmtime run -D debug-info foo.wasm
gdb --args wasmtime run -D debug-info -O opt-level=0 foo.wasm
```

If you run into trouble, the following discussions might help:
Expand Down
1 change: 1 addition & 0 deletions examples/fib-debug/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ int main(int argc, const char *argv[]) {
// original fib-wasm.c source code and variables.
wasm_config_t *config = wasm_config_new();
wasmtime_config_debug_info_set(config, true);
wasmtime_config_cranelift_opt_level_set(config, WASMTIME_OPT_LEVEL_NONE);

// Initialize.
printf("Initializing...\n");
Expand Down
6 changes: 5 additions & 1 deletion examples/fib-debug/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,11 @@ fn main() -> Result<()> {
// Load our previously compiled wasm file (built previously with Cargo) and
// also ensure that we generate debuginfo so this executable can be
// debugged in GDB.
let engine = Engine::new(Config::new().debug_info(true))?;
let engine = Engine::new(
Config::new()
.debug_info(true)
.cranelift_opt_level(OptLevel::None),
)?;
let mut store = Store::new(&engine, ());
let module = Module::from_file(&engine, "target/wasm32-unknown-unknown/debug/fib.wasm")?;
let instance = Instance::new(&mut store, &module, &[])?;
Expand Down