protoverse

A metaverse protocol
git clone git://jb55.com/protoverse
Log | Files | Refs | README | LICENSE

commit 45e611a89ce65ada4eea978bab827cef3623a3bd
parent 4ae260e3738cca9e0df757b5235be8c280233545
Author: William Casarin <jb55@jb55.com>
Date:   Thu,  5 Aug 2021 07:01:40 -0700

print callstack

Diffstat:
Msrc/wasm.c | 19+++++++++++++++++--
Msrc/wasm.h | 1+
2 files changed, 18 insertions(+), 2 deletions(-)

diff --git a/src/wasm.c b/src/wasm.c @@ -41,12 +41,10 @@ struct expr_parser { struct cursor *stack; // optional }; -#ifdef DEBUG static INLINE struct callframe *top_callframes(struct cursor *cur, int top) { return (struct callframe*)cursor_topn(cur, sizeof(struct callframe), top); } -#endif static INLINE struct callframe *top_callframe(struct cursor *cur) { @@ -429,6 +427,22 @@ static void print_stack(struct cursor *stack) stack->p = p; } +void print_callstack(struct wasm_interp *interp) +{ + int i = 0; + struct callframe *frame; + struct func *func; + + printf("callstack:\n"); + while ((frame = top_callframes(&interp->callframes, i++))) { + func = get_fn(interp->module, frame->fn); + if (!func) + printf("??\n"); + else + printf("%d %s:%d\n", i, func->name, frame->fn); + } +} + static INLINE int cursor_pushval(struct cursor *cur, struct val *val) { return cursor_push(cur, (u8*)val, sizeof(*val)); @@ -7035,6 +7049,7 @@ int run_wasm(unsigned char *wasm, unsigned long len, setup_wasi(&interp, argc, argv, env); if (!interp_wasm_module(&interp, retval)) { + print_callstack(&interp); print_error_backtrace(&interp.errors); } diff --git a/src/wasm.h b/src/wasm.h @@ -724,5 +724,6 @@ void wasm_interp_free(struct wasm_interp *interp); int interp_wasm_module(struct wasm_interp *interp, int *retval); void print_error_backtrace(struct errors *errors); void setup_wasi(struct wasm_interp *interp, int argc, const char **argv, char **env); +void print_callstack(struct wasm_interp *interp); #endif /* PROTOVERSE_WASM_H */