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

How to get a call stack when wasm-ctor-eval stops? #7255

Open
rdb opened this issue Jan 30, 2025 · 6 comments
Open

How to get a call stack when wasm-ctor-eval stops? #7255

rdb opened this issue Jan 30, 2025 · 6 comments

Comments

@rdb
Copy link

rdb commented Jan 30, 2025

Hello,

Apologies if this is already documented somewhere, but I was unable to find it. I'm trying to find out how I can easily find where a particular call to an import is being made when wasm-ctor-eval hits something it can't eval. I was hoping to find some debug option so that I could see something like a traceback.

At the moment I am manually searching through the wasm disassembly, which is quite a painstaking process given that this is a huge binary. Any suggestions for making this process easier would be very helpful.

@kripken
Copy link
Member

kripken commented Jan 30, 2025

We don't have an option for this atm. You can approximate it by running in a debugger and stopping on any FailToEvalException, then inspecting the stack. We eval in an interpreter that will have a stack frame for each function called, and includes the function name in the arguments, so the information is there (at least in a debug build).

Supporting this "properly" would require a shadow stack of some sort. Adding a basic version, that notes functions as it enters and leaves them, would at least give a basic stack trace, and shouldn't be too hard to add. Adding precise binary offsets would be possible but harder.

@rdb
Copy link
Author

rdb commented Jan 30, 2025

Even just the function names would be very helpful already.

Would it be easier to ask for a spammy debug log feature that just prints an indented name of the function as it enters it? Then I can just work upward from the last bit before it stopped.

@kripken
Copy link
Member

kripken commented Jan 30, 2025

Oh, we do have a spammy option already I believe. Add

#define WASM_INTERPRETER_DEBUG 1

at the top of src/wasm-interpreter.h.

@tlively
Copy link
Member

tlively commented Jan 30, 2025

The new interpreter will make it much easier to support this use case.

@rdb
Copy link
Author

rdb commented Jan 31, 2025

Thanks! I'm looking forward to the new interpreter. I've managed to achieve what I need using wizer in the meantime, which gives a stack trace when it encounters an external call. On top of that, wizer lets me pass in external data (via a wasi call), which I need for my use case while there does not seem to be a way to do this with wasm-ctor-eval.

Are the plans for the new interpreter documented somewhere?

@tlively
Copy link
Member

tlively commented Jan 31, 2025

The only documentation so far is this PR/commit description: #7227

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants