Skip to content

Commit c8b8731

Browse files
author
Georgii Rylov
committed
support standard frames as well
1 parent bf6b155 commit c8b8731

1 file changed

Lines changed: 64 additions & 25 deletions

File tree

core/iwasm/aot/aot_runtime.c

Lines changed: 64 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -4105,40 +4105,32 @@ aot_frame_update_profile_info(WASMExecEnv *exec_env, bool alloc_frame)
41054105

41064106
#if WASM_ENABLE_DUMP_CALL_STACK != 0
41074107
void
4108-
aot_iterate_callstack(WASMExecEnv *exec_env,
4109-
const wasm_frame_callback frame_handler, void *user_data)
4108+
aot_iterate_callstack_tiny_frame(WASMExecEnv *exec_env, const wasm_frame_callback frame_handler, void* user_data)
41104109
{
4111-
/*
4112-
* Note for devs: please refrain from such modifications inside of
4113-
* aot_iterate_callstack
4114-
* - any allocations/freeing memory
4115-
* - dereferencing any pointers other than: exec_env, exec_env->module_inst,
4116-
* exec_env->module_inst->module, pointers between stack's bottom and
4117-
* top_boundary For more details check wasm_iterate_callstack in
4118-
* wasm_export.h
4119-
*/
4120-
if (!is_tiny_frame(exec_env)) {
4121-
// TODO: support standard frames
4122-
return;
4123-
}
4124-
uint8 *top_boundary = exec_env->wasm_stack.top_boundary;
4125-
uint8 *top = exec_env->wasm_stack.top;
4126-
uint8 *bottom = exec_env->wasm_stack.bottom;
4127-
4128-
bool is_top_index_in_range =
4129-
top_boundary >= top && top >= (bottom + sizeof(AOTTinyFrame));
4110+
/*
4111+
* Note for devs: please refrain from such modifications inside of aot_iterate_callstack
4112+
* - any allocations/freeing memory
4113+
* - dereferencing any pointers other than: exec_env, exec_env->module_inst,
4114+
* exec_env->module_inst->module, pointers between stack's bottom and top_boundary
4115+
* For more details check wasm_iterate_callstack in wasm_export.h
4116+
*/
4117+
uint8* top_boundary = exec_env->wasm_stack.top_boundary;
4118+
uint8* top = exec_env->wasm_stack.top;
4119+
uint8* bottom = exec_env->wasm_stack.bottom;
4120+
4121+
bool is_top_index_in_range = top_boundary >= top && top >= (bottom + sizeof(AOTTinyFrame));
41304122
if (!is_top_index_in_range) {
41314123
return;
41324124
}
4133-
bool is_top_aligned_with_bottom =
4134-
(unsigned long)(top - bottom) % sizeof(AOTTinyFrame) == 0;
4125+
bool is_top_aligned_with_bottom = (unsigned long)(top - bottom) % sizeof(AOTTinyFrame) == 0;
41354126
if (!is_top_aligned_with_bottom) {
41364127
return;
41374128
}
41384129

4139-
AOTTinyFrame *frame = (AOTTinyFrame *)(top - sizeof(AOTTinyFrame));
4130+
AOTTinyFrame* frame = (AOTTinyFrame*)(top - sizeof(AOTTinyFrame));
41404131
WASMCApiFrame record_frame;
4141-
while (frame && (uint8_t *)frame >= bottom) {
4132+
while (frame &&
4133+
(uint8_t*)frame >= bottom) {
41424134
record_frame.instance = exec_env->module_inst;
41434135
record_frame.module_offset = 0;
41444136
record_frame.func_index = frame->func_index;
@@ -4150,6 +4142,53 @@ aot_iterate_callstack(WASMExecEnv *exec_env,
41504142
}
41514143
}
41524144

4145+
void
4146+
aot_iterate_callstack_standard_frame(WASMExecEnv *exec_env, const wasm_frame_callback frame_handler, void* user_data)
4147+
{
4148+
/*
4149+
* Note for devs: please refrain from such modifications inside of aot_iterate_callstack
4150+
* - any allocations/freeing memory
4151+
* - dereferencing any pointers other than: exec_env, exec_env->module_inst,
4152+
* exec_env->module_inst->module, pointers between stack's bottom and top_boundary
4153+
* For more details check wasm_iterate_callstack in wasm_export.h
4154+
*/
4155+
WASMModuleInstance *module_inst = (WASMModuleInstance *)wasm_exec_env_get_module_inst(exec_env);
4156+
AOTFrame* cur_frame = (AOTFrame *)wasm_exec_env_get_cur_frame(exec_env);
4157+
uint8* top_boundary = exec_env->wasm_stack.top_boundary;
4158+
uint8* bottom = exec_env->wasm_stack.bottom;
4159+
4160+
WASMCApiFrame record_frame;
4161+
while (cur_frame &&
4162+
(uint8_t*)cur_frame >= bottom &&
4163+
(uint8_t*)cur_frame + sizeof(AOTFrame) <= top_boundary) {
4164+
record_frame.instance = module_inst;
4165+
record_frame.module_offset = 0;
4166+
record_frame.func_index = (uint32)cur_frame->func_index;
4167+
record_frame.func_offset = (uint32)cur_frame->ip_offset;
4168+
if (!frame_handler(user_data, &record_frame)) {
4169+
break;
4170+
}
4171+
cur_frame = cur_frame->prev_frame;
4172+
}
4173+
}
4174+
4175+
void
4176+
aot_iterate_callstack(WASMExecEnv *exec_env, const wasm_frame_callback frame_handler, void* user_data)
4177+
{
4178+
/*
4179+
* Note for devs: please refrain from such modifications inside of aot_iterate_callstack
4180+
* - any allocations/freeing memory
4181+
* - dereferencing any pointers other than: exec_env, exec_env->module_inst,
4182+
* exec_env->module_inst->module, pointers between stack's bottom and top_boundary
4183+
* For more details check wasm_iterate_callstack in wasm_export.h
4184+
*/
4185+
if (!is_tiny_frame(exec_env)) {
4186+
aot_iterate_callstack_standard_frame(exec_env, frame_handler, user_data);
4187+
} else {
4188+
aot_iterate_callstack_tiny_frame(exec_env, frame_handler, user_data);
4189+
}
4190+
}
4191+
41534192
bool
41544193
aot_create_call_stack(struct WASMExecEnv *exec_env)
41554194
{

0 commit comments

Comments
 (0)