@@ -1061,6 +1061,13 @@ aot_instantiate(AOTModule *module, bool is_sub_inst,
10611061 }
10621062#endif
10631063
1064+ #if WASM_ENABLE_DUMP_CALL_STACK != 0
1065+ if (!(module_inst -> frames .ptr =
1066+ runtime_malloc (sizeof (Vector ), error_buf , error_buf_size ))) {
1067+ goto fail ;
1068+ }
1069+ #endif
1070+
10641071 /* Execute __post_instantiate function and start function*/
10651072 if (!execute_post_inst_function (module_inst )
10661073 || !execute_start_function (module_inst )) {
@@ -1130,6 +1137,14 @@ aot_deinstantiate(AOTModuleInstance *module_inst, bool is_sub_inst)
11301137 wasm_runtime_free (module_inst -> func_perf_profilings .ptr );
11311138#endif
11321139
1140+ #if WASM_ENABLE_DUMP_CALL_STACK != 0
1141+ if (module_inst -> frames .ptr ) {
1142+ bh_vector_destroy (module_inst -> frames .ptr );
1143+ wasm_runtime_free (module_inst -> frames .ptr );
1144+ module_inst -> frames .ptr = NULL ;
1145+ }
1146+ #endif
1147+
11331148 if (module_inst -> memories .ptr )
11341149 memories_deinstantiate (module_inst );
11351150
@@ -2902,7 +2917,8 @@ aot_free_frame(WASMExecEnv *exec_env)
29022917void
29032918aot_dump_call_stack (WASMExecEnv * exec_env )
29042919{
2905- AOTFrame * cur_frame = (AOTFrame * )exec_env -> cur_frame ;
2920+ AOTFrame * cur_frame = (AOTFrame * )exec_env -> cur_frame ,
2921+ * first_frame = cur_frame ;
29062922 AOTModuleInstance * module_inst =
29072923 (AOTModuleInstance * )exec_env -> module_inst ;
29082924 const char * func_name ;
@@ -2925,6 +2941,29 @@ aot_dump_call_stack(WASMExecEnv *exec_env)
29252941 n ++ ;
29262942 }
29272943 os_printf ("\n" );
2944+
2945+ /* release previous stack frames and create new ones */
2946+ if (!bh_vector_destroy (module_inst -> frames .ptr )
2947+ || !bh_vector_init (module_inst -> frames .ptr , n ,
2948+ sizeof (WASMCApiFrame ))) {
2949+ return ;
2950+ }
2951+
2952+ cur_frame = first_frame ;
2953+ while (cur_frame ) {
2954+ WASMCApiFrame frame = { 0 };
2955+ frame .instance = module_inst ;
2956+ frame .module_offset = 0 ;
2957+ frame .func_index = cur_frame -> func_index ;
2958+ frame .func_offset = 0 ;
2959+
2960+ if (!bh_vector_append (module_inst -> frames .ptr , & frame )) {
2961+ bh_vector_destroy (module_inst -> frames .ptr );
2962+ return ;
2963+ }
2964+
2965+ cur_frame = cur_frame -> prev_frame ;
2966+ }
29282967}
29292968#endif /* end of WASM_ENABLE_DUMP_CALL_STACK */
29302969
0 commit comments