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

add basic coredump generation #5868

Merged
merged 1 commit into from
Feb 28, 2023

Conversation

xtuc
Copy link
Contributor

@xtuc xtuc commented Feb 23, 2023

This change adds a basic coredump generation after a WebAssembly trap was entered. The coredump includes rudimentary stack / process debugging information.

A new CLI argument is added to enable coredump generation:

wasmtime --coredump-on-trap=/path/to/coredump/file module.wasm

See ./docs/examples-coredump.md for a working example.

Refs #5732

if let Some(coredump_path) = self.coredump_on_trap.as_ref() {
if coredump_path.contains("%") {
return Err(anyhow!(
"The coredump-on-trap path does not support patterns yet."
Copy link
Contributor Author

@xtuc xtuc Feb 23, 2023

Choose a reason for hiding this comment

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

For context, unix kernels allow to template the coredump path (https://sigquit.wordpress.com/2009/03/13/the-core-pattern/) using variables starting with %. We might want to support them in the future.

@github-actions github-actions bot added the wasmtime:docs Issues related to Wasmtime's documentation label Feb 23, 2023
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.

Thanks!

One thought I have with this is that while placing it in the CLI is perhaps a good starting point we'll likely want this in a more libararified form at some point too because embeddings of Wasmtime don't necessarily all use the CLI. This current integration is also somewhat limited because the native call stack is gone and as a result impossible to ever recover locals and their information. Basically the "ideal" location for a core dump is probably at the place of the trap itself, which means that this wouldn't be possible to do from the CLI but rather would be required to be baked-in as well. Additionally being baked-in I think will be required to get access to non-exported globals/memories/etc.

None of that is to say though that this shouldn't be added here at this time. Moreso that a more "final" integration of core dumps I think will probably look significantly differently architected which isn't a problem but perhaps worth considering.

Cargo.toml Outdated Show resolved Hide resolved
src/commands/run.rs Outdated Show resolved Hide resolved
src/commands/run.rs Outdated Show resolved Hide resolved
src/commands/run.rs Outdated Show resolved Hide resolved
src/commands/run.rs Outdated Show resolved Hide resolved
src/commands/run.rs Outdated Show resolved Hide resolved
@xtuc xtuc force-pushed the sven/basic-coredump branch 2 times, most recently from 3d06eda to 0a1843b Compare February 24, 2023 16:19
@xtuc
Copy link
Contributor Author

xtuc commented Feb 24, 2023

I changed the coredump generation to gracefully handle errors, as you pointed out. The dependencies are now trimmed down.

Could you please have another look @alexcrichton?

src/commands/run.rs Show resolved Hide resolved
supply-chain/audits.toml Outdated Show resolved Hide resolved
src/commands/run.rs Outdated Show resolved Hide resolved
src/commands/run.rs Outdated Show resolved Hide resolved

let coredump = coredump_builder
.serialize()
.map_err(|err| anyhow!("failed to serialize coredump: {}", err))?;
Copy link
Member

Choose a reason for hiding this comment

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

Could the .map_err here become .context(..)?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

The error is from wasm-coredump-builder and is type Box<dyn std::error::Error + Sync + Send> instead of the usual anyhow::Error. Is that a problem?

Copy link
Member

Choose a reason for hiding this comment

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

It's a problem insofar as the error's contexet is all lost here, only displaying one error in a possible chain of errors contained within the trait object. Whether your library exercises that I'm not sure, though.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

It's not a problem for my library, for now, as it doesn't add context to errors.

src/commands/run.rs Outdated Show resolved Hide resolved
src/commands/run.rs Outdated Show resolved Hide resolved
@xtuc xtuc force-pushed the sven/basic-coredump branch 3 times, most recently from db931d7 to 0712e8f Compare February 27, 2023 21:19
alexcrichton added a commit to alexcrichton/wasmtime that referenced this pull request Feb 28, 2023
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.

I've added the new versions to #5894

src/commands/run.rs Show resolved Hide resolved

let coredump = coredump_builder
.serialize()
.map_err(|err| anyhow!("failed to serialize coredump: {}", err))?;
Copy link
Member

Choose a reason for hiding this comment

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

It's a problem insofar as the error's contexet is all lost here, only displaying one error in a possible chain of errors contained within the trait object. Whether your library exercises that I'm not sure, though.

cfallin pushed a commit that referenced this pull request Feb 28, 2023
This change adds a basic coredump generation after a WebAssembly trap
was entered. The coredump includes rudimentary stack / process debugging
information.

A new CLI argument is added to enable coredump generation:
```
wasmtime --coredump-on-trap=/path/to/coredump/file module.wasm
```

See ./docs/examples-coredump.md for a working example.

Refs bytecodealliance#5732
@alexcrichton alexcrichton added this pull request to the merge queue Feb 28, 2023
Merged via the queue into bytecodealliance:main with commit 0e9a48a Feb 28, 2023
@xtuc xtuc deleted the sven/basic-coredump branch February 28, 2023 23:05
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
wasmtime:docs Issues related to Wasmtime's documentation
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants