Skip to content

Emit backtrace in runtime error message. #54

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

Merged
merged 3 commits into from
Nov 18, 2021
Merged

Emit backtrace in runtime error message. #54

merged 3 commits into from
Nov 18, 2021

Conversation

mathetake
Copy link
Member

@mathetake mathetake commented Nov 18, 2021

This commit adds the parser of the "name" custom section[1],
and starts emitting the backtrace of the program into the runtime error message
by leveraging the function name informations stored in "name" custom section.

Note that this is the minimal implementation -- the trace doesn't contain the
original Wasm instruction address nor the source code info. The former
can be implemented easily but the latter requires us to implement the Wasm
DWARF format parser of .debug_* custom sections[2].

[1] https://webassembly.github.io/spec/core/appendix/custom.html#name-section
[2] https://yurydelendik.github.io/webassembly-dwarf/

This is similar to what I did to Proxy-Wasm C++ host: proxy-wasm/proxy-wasm-cpp-host#66

The following is the output from examples/trap_test.go:

=== RUN   Test_trap
panic: causing panic!!!!!!!!!!
wasm runtime error: unreachable
wasm backtrace:
	0: runtime._panic
	1: main.three
	2: main.two
	3: main.one
	4: cause_panic

As a comparison wasmtime emits like this:

wasmtime run examples/wasm/trap.wasm --invoke cause_panic
panic: causing panic!!!!!!!!!!
Error: failed to run main module `examples/wasm/trap.wasm`

Caused by:
    0: failed to invoke `cause_panic`
    1: wasm trap: unreachable
       wasm backtrace:
           0:  0x39d - <unknown>!runtime._panic
           1:  0x657 - <unknown>!main.three
           2:  0x64d - <unknown>!main.two
           3:  0x643 - <unknown>!main.one
           4:  0x639 - <unknown>!cause_panic
       note: run with `WASMTIME_BACKTRACE_DETAILS=1` environment variable to display more information

Signed-off-by: Takeshi Yoneda <takeshi@tetrate.io>
Copy link
Contributor

@codefromthecrypt codefromthecrypt left a comment

Choose a reason for hiding this comment

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

Ack some of my comments imply work possibly more than the code here, but I have to be Jiminy Cricket.

Signed-off-by: Takeshi Yoneda <takeshi@tetrate.io>
Signed-off-by: Takeshi Yoneda <takeshi@tetrate.io>
@mathetake mathetake merged commit 4fda76e into main Nov 18, 2021
@mathetake mathetake deleted the stacktrace branch November 18, 2021 06:29
@mathetake
Copy link
Member Author

@codefromthecrypt thanks for the help!!

@mathetake mathetake changed the title wazeroir: emit backtrace in runtime error message. Emit backtrace in runtime error message. Nov 18, 2021
@@ -28,4 +28,13 @@ func Test_trap(t *testing.T) {

_, _, err = store.CallFunction("test", "cause_panic")
require.Error(t, err)

const expErrMsg = `wasm runtime error: unreachable
Copy link
Contributor

Choose a reason for hiding this comment

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

I ❤️ this

@codefromthecrypt
Copy link
Contributor

great work

mathetake added a commit that referenced this pull request Nov 18, 2021
This commit adds the parser of the "name" custom section[1],
and starts emitting the backtrace of the program into the runtime error message
by leveraging the function name informations stored in "name" custom section.

Note that this is the minimal implementation -- the trace doesn't contain the
original Wasm instruction address nor the source code info. The former
can be implemented easily but the latter requires us to implement the Wasm
DWARF format parser of .debug_* custom sections[2].

[1] https://webassembly.github.io/spec/core/appendix/custom.html#name-section
[2] https://yurydelendik.github.io/webassembly-dwarf/

The following is the output from examples/trap_test.go:

=== RUN   Test_trap
panic: causing panic!!!!!!!!!!
wasm runtime error: unreachable
wasm backtrace:
	0: runtime._panic
	1: main.three
	2: main.two
	3: main.one
	4: cause_panic
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants