|
10 | 10 | #include "../common/wasm_runtime_common.h" |
11 | 11 | #include "../common/wasm_memory.h" |
12 | 12 | #include "../interpreter/wasm_runtime.h" |
| 13 | +#include <stdbool.h> |
13 | 14 | #if WASM_ENABLE_SHARED_MEMORY != 0 |
14 | 15 | #include "../common/wasm_shared_memory.h" |
15 | 16 | #endif |
@@ -4104,6 +4105,48 @@ aot_frame_update_profile_info(WASMExecEnv *exec_env, bool alloc_frame) |
4104 | 4105 | #endif /* end of WASM_ENABLE_AOT_STACK_FRAME != 0 */ |
4105 | 4106 |
|
4106 | 4107 | #if WASM_ENABLE_DUMP_CALL_STACK != 0 |
| 4108 | +void |
| 4109 | +aot_iterate_callstack(WASMExecEnv *exec_env, const wasm_frame_callback frame_handler, void* user_data) |
| 4110 | +{ |
| 4111 | +/* |
| 4112 | +* Note for devs: please refrain from such modifications inside of aot_iterate_callstack |
| 4113 | + * - any allocations/freeing memory |
| 4114 | + * - dereferencing any pointers other than: exec_env, exec_env->module_inst, |
| 4115 | + * exec_env->module_inst->module, pointers between stack's bottom and top_boundary |
| 4116 | + * For more details check wasm_iterate_callstack in wasm_export.h |
| 4117 | +*/ |
| 4118 | + if (!is_tiny_frame(exec_env)) { |
| 4119 | + //TODO: support standard frames |
| 4120 | + return; |
| 4121 | + } |
| 4122 | + uint8* top_boundary = exec_env->wasm_stack.top_boundary; |
| 4123 | + uint8* top = exec_env->wasm_stack.top; |
| 4124 | + uint8* bottom = exec_env->wasm_stack.bottom; |
| 4125 | + |
| 4126 | + bool is_top_index_in_range = top_boundary >= top && top >= (bottom + sizeof(AOTTinyFrame)); |
| 4127 | + if (!is_top_index_in_range) { |
| 4128 | + return; |
| 4129 | + } |
| 4130 | + bool is_top_aligned_with_bottom = (unsigned long)(top - bottom) % sizeof(AOTTinyFrame) == 0; |
| 4131 | + if (!is_top_aligned_with_bottom) { |
| 4132 | + return; |
| 4133 | + } |
| 4134 | + |
| 4135 | + AOTTinyFrame* frame = (AOTTinyFrame*)(top - sizeof(AOTTinyFrame)); |
| 4136 | + WASMCApiFrame record_frame; |
| 4137 | + while (frame && |
| 4138 | + (uint8_t*)frame >= bottom) { |
| 4139 | + record_frame.instance = exec_env->module_inst; |
| 4140 | + record_frame.module_offset = 0; |
| 4141 | + record_frame.func_index = frame->func_index; |
| 4142 | + record_frame.func_offset = frame->ip_offset; |
| 4143 | + if (!frame_handler(user_data, &record_frame)) { |
| 4144 | + break; |
| 4145 | + } |
| 4146 | + frame -= 1; |
| 4147 | + } |
| 4148 | +} |
| 4149 | + |
4107 | 4150 | bool |
4108 | 4151 | aot_create_call_stack(struct WASMExecEnv *exec_env) |
4109 | 4152 | { |
|
0 commit comments