@@ -4103,11 +4103,11 @@ aot_frame_update_profile_info(WASMExecEnv *exec_env, bool alloc_frame)
41034103}
41044104#endif /* end of WASM_ENABLE_AOT_STACK_FRAME != 0 */
41054105
4106- #if WASM_ENABLE_DUMP_CALL_STACK != 0
4107- void
4108- aot_iterate_callstack_tiny_frame (WASMExecEnv * exec_env ,
4109- const wasm_frame_callback frame_handler ,
4110- void * user_data )
4106+ #if WAMR_ENABLE_COPY_CALLSTACK != 0
4107+ uint32
4108+ aot_copy_callstack_tiny_frame (WASMExecEnv * exec_env , wasm_frame_ptr_t buffer ,
4109+ const uint32 length ,
4110+ const uint32 skip_n )
41114111{
41124112 /*
41134113 * Note for devs: please refrain from such modifications inside of
@@ -4122,35 +4122,43 @@ aot_iterate_callstack_tiny_frame(WASMExecEnv *exec_env,
41224122 uint8 * top = exec_env -> wasm_stack .top ;
41234123 uint8 * bottom = exec_env -> wasm_stack .bottom ;
41244124
4125+ uint32 count = 0 ;
4126+
41254127 bool is_top_index_in_range =
41264128 top_boundary >= top && top >= (bottom + sizeof (AOTTinyFrame ));
41274129 if (!is_top_index_in_range ) {
4128- return ;
4130+ return count ;
41294131 }
41304132 bool is_top_aligned_with_bottom =
41314133 (unsigned long )(top - bottom ) % sizeof (AOTTinyFrame ) == 0 ;
41324134 if (!is_top_aligned_with_bottom ) {
4133- return ;
4135+ return count ;
41344136 }
41354137
41364138 AOTTinyFrame * frame = (AOTTinyFrame * )(top - sizeof (AOTTinyFrame ));
41374139 WASMCApiFrame record_frame ;
4138- while (frame && (uint8_t * )frame >= bottom ) {
4140+ while (frame && (uint8_t * )frame >= bottom
4141+ && count < (skip_n + length )) {
4142+ if (count < skip_n ) {
4143+ ++ count ;
4144+ frame -= 1 ;
4145+ continue ;
4146+ }
41394147 record_frame .instance = exec_env -> module_inst ;
41404148 record_frame .module_offset = 0 ;
41414149 record_frame .func_index = frame -> func_index ;
41424150 record_frame .func_offset = frame -> ip_offset ;
4143- if (!frame_handler (user_data , & record_frame )) {
4144- break ;
4145- }
4151+ buffer [count - skip_n ] = record_frame ;
41464152 frame -= 1 ;
4153+ ++ count ;
41474154 }
4155+ return count ;
41484156}
41494157
4150- void
4151- aot_iterate_callstack_standard_frame (WASMExecEnv * exec_env ,
4152- const wasm_frame_callback frame_handler ,
4153- void * user_data )
4158+ uint32
4159+ aot_copy_callstack_standard_frame (WASMExecEnv * exec_env , wasm_frame_ptr_t buffer ,
4160+ const uint32 length ,
4161+ const uint32 skip_n )
41544162{
41554163 /*
41564164 * Note for devs: please refrain from such modifications inside of
@@ -4169,17 +4177,24 @@ aot_iterate_callstack_standard_frame(WASMExecEnv *exec_env,
41694177 uint8 * bottom = exec_env -> wasm_stack .bottom ;
41704178 uint32 frame_size = (uint32 )offsetof(AOTFrame , lp );
41714179
4180+ uint32 count = 0 ;
4181+
41724182 WASMCApiFrame record_frame ;
41734183 while (cur_frame && (uint8_t * )cur_frame >= bottom
4174- && (uint8_t * )cur_frame + frame_size <= top_boundary ) {
4184+ && (uint8_t * )cur_frame + frame_size <= top_boundary
4185+ && count < (skip_n + length )) {
4186+ if (count < skip_n ) {
4187+ ++ count ;
4188+ cur_frame = cur_frame -> prev_frame ;
4189+ continue ;
4190+ }
41754191 record_frame .instance = module_inst ;
41764192 record_frame .module_offset = 0 ;
41774193 record_frame .func_index = (uint32 )cur_frame -> func_index ;
41784194 record_frame .func_offset = (uint32 )cur_frame -> ip_offset ;
4179- if (!frame_handler (user_data , & record_frame )) {
4180- break ;
4181- }
4195+ buffer [count - skip_n ] = record_frame ;
41824196 cur_frame = cur_frame -> prev_frame ;
4197+ ++ count ;
41834198 }
41844199#else
41854200/*
@@ -4189,9 +4204,11 @@ aot_iterate_callstack_standard_frame(WASMExecEnv *exec_env,
41894204#endif
41904205}
41914206
4192- void
4193- aot_iterate_callstack (WASMExecEnv * exec_env ,
4194- const wasm_frame_callback frame_handler , void * user_data )
4207+
4208+ uint32
4209+ aot_copy_callstack (WASMExecEnv * exec_env , wasm_frame_ptr_t buffer ,
4210+ const uint32 length ,
4211+ const uint32 skip_n )
41954212{
41964213 /*
41974214 * Note for devs: please refrain from such modifications inside of
@@ -4203,14 +4220,15 @@ aot_iterate_callstack(WASMExecEnv *exec_env,
42034220 * wasm_export.h
42044221 */
42054222 if (!is_tiny_frame (exec_env )) {
4206- aot_iterate_callstack_standard_frame (exec_env , frame_handler ,
4207- user_data );
4223+ return aot_copy_callstack_standard_frame (exec_env , buffer , length , skip_n );
42084224 }
42094225 else {
4210- aot_iterate_callstack_tiny_frame (exec_env , frame_handler , user_data );
4226+ return aot_copy_callstack_tiny_frame (exec_env , buffer , length , skip_n );
42114227 }
42124228}
4229+ #endif // WAMR_ENABLE_COPY_CALLSTACK
42134230
4231+ #if WASM_ENABLE_DUMP_CALL_STACK != 0
42144232bool
42154233aot_create_call_stack (struct WASMExecEnv * exec_env )
42164234{
@@ -4391,7 +4409,7 @@ aot_dump_call_stack(WASMExecEnv *exec_env, bool print, char *buf, uint32 len)
43914409
43924410 return total_len + 1 ;
43934411}
4394- #endif /* end of WASM_ENABLE_DUMP_CALL_STACK != 0 */
4412+ #endif /* end of WASM_ENABLE_DUMP_CALL_STACK != 0 && WASM_ENABLE_AOT_STACK_FRAME != 0 */
43954413
43964414#if WASM_ENABLE_PERF_PROFILING != 0
43974415void
0 commit comments