Implement wasm-c-api frame/trap APIs for AOT mode (#663)

And update CI workflow to build/cache llvm and run wasm-c-api samples.
This commit is contained in:
Wenyong Huang
2021-07-13 09:01:03 +08:00
committed by GitHub
parent b554a9d05d
commit 0f1ce9ef3d
10 changed files with 160 additions and 58 deletions

View File

@ -1061,6 +1061,13 @@ aot_instantiate(AOTModule *module, bool is_sub_inst,
}
#endif
#if WASM_ENABLE_DUMP_CALL_STACK != 0
if (!(module_inst->frames.ptr =
runtime_malloc(sizeof(Vector), error_buf, error_buf_size))) {
goto fail;
}
#endif
/* Execute __post_instantiate function and start function*/
if (!execute_post_inst_function(module_inst)
|| !execute_start_function(module_inst)) {
@ -1130,6 +1137,14 @@ aot_deinstantiate(AOTModuleInstance *module_inst, bool is_sub_inst)
wasm_runtime_free(module_inst->func_perf_profilings.ptr);
#endif
#if WASM_ENABLE_DUMP_CALL_STACK != 0
if (module_inst->frames.ptr) {
bh_vector_destroy(module_inst->frames.ptr);
wasm_runtime_free(module_inst->frames.ptr);
module_inst->frames.ptr = NULL;
}
#endif
if (module_inst->memories.ptr)
memories_deinstantiate(module_inst);
@ -2902,7 +2917,8 @@ aot_free_frame(WASMExecEnv *exec_env)
void
aot_dump_call_stack(WASMExecEnv *exec_env)
{
AOTFrame *cur_frame = (AOTFrame *)exec_env->cur_frame;
AOTFrame *cur_frame = (AOTFrame *)exec_env->cur_frame,
*first_frame = cur_frame;
AOTModuleInstance *module_inst =
(AOTModuleInstance *)exec_env->module_inst;
const char *func_name;
@ -2925,6 +2941,29 @@ aot_dump_call_stack(WASMExecEnv *exec_env)
n++;
}
os_printf("\n");
/* release previous stack frames and create new ones */
if (!bh_vector_destroy(module_inst->frames.ptr)
|| !bh_vector_init(module_inst->frames.ptr, n,
sizeof(WASMCApiFrame))) {
return;
}
cur_frame = first_frame;
while (cur_frame) {
WASMCApiFrame frame = { 0 };
frame.instance = module_inst;
frame.module_offset = 0;
frame.func_index = cur_frame->func_index;
frame.func_offset = 0;
if (!bh_vector_append(module_inst->frames.ptr, &frame)) {
bh_vector_destroy(module_inst->frames.ptr);
return;
}
cur_frame = cur_frame->prev_frame;
}
}
#endif /* end of WASM_ENABLE_DUMP_CALL_STACK */