debug: fix print stack for wasm

This commit is contained in:
visualfc
2025-07-01 11:28:48 +08:00
parent f0728c4fe0
commit 013f2ef00d
4 changed files with 52 additions and 7 deletions

View File

@@ -0,0 +1,31 @@
#ifdef __EMSCRIPTEN__
//emscripten
#include <emscripten.h>
void llgo_print_stack(int skip) {
EM_ASM({
function getStackTrace() {
var stack;
try {
throw new Error();
} catch (e) {
stack = e.stack;
}
return stack;
}
var stack = getStackTrace();
if (stack) {
var frames = stack.split('\n').slice($0);
frames.forEach(function(frame) {
console.log(frame.trim());
});
}
}, skip);
}
#else
// wasi
void llgo_print_stack(int skip){
}
#endif