Enable dump call stack to a buffer (#1244)
Enable dump call stack to a buffer, use API `wasm_runtime_get_call_stack_buf_size` to get the required buffer size and use API `wasm_runtime_dump_call_stack_to_buf` to dump call stack to a buffer
This commit is contained in:
@ -4527,6 +4527,30 @@ wasm_externref_retain(uint32 externref_idx)
|
||||
#endif /* end of WASM_ENABLE_REF_TYPES */
|
||||
|
||||
#if WASM_ENABLE_DUMP_CALL_STACK != 0
|
||||
uint32
|
||||
wasm_runtime_dump_line_buf_impl(const char *line_buf, bool dump_or_print,
|
||||
char **buf, uint32 *len)
|
||||
{
|
||||
if (dump_or_print) {
|
||||
return (uint32)os_printf("%s", line_buf);
|
||||
}
|
||||
else if (*buf) {
|
||||
uint32 dump_len;
|
||||
|
||||
dump_len = snprintf(*buf, *len, "%s", line_buf);
|
||||
if (dump_len >= *len) {
|
||||
dump_len = *len;
|
||||
}
|
||||
|
||||
*len = *len - dump_len;
|
||||
*buf = *buf + dump_len;
|
||||
return dump_len;
|
||||
}
|
||||
else {
|
||||
return strlen(line_buf);
|
||||
}
|
||||
}
|
||||
|
||||
void
|
||||
wasm_runtime_dump_call_stack(WASMExecEnv *exec_env)
|
||||
{
|
||||
@ -4534,15 +4558,56 @@ wasm_runtime_dump_call_stack(WASMExecEnv *exec_env)
|
||||
wasm_exec_env_get_module_inst(exec_env);
|
||||
#if WASM_ENABLE_INTERP != 0
|
||||
if (module_inst->module_type == Wasm_Module_Bytecode) {
|
||||
wasm_interp_dump_call_stack(exec_env);
|
||||
wasm_interp_dump_call_stack(exec_env, true, NULL, 0);
|
||||
}
|
||||
#endif
|
||||
#if WASM_ENABLE_AOT != 0
|
||||
if (module_inst->module_type == Wasm_Module_AoT) {
|
||||
aot_dump_call_stack(exec_env);
|
||||
aot_dump_call_stack(exec_env, true, NULL, 0);
|
||||
}
|
||||
#endif
|
||||
}
|
||||
|
||||
uint32
|
||||
wasm_runtime_get_call_stack_buf_size(wasm_exec_env_t exec_env)
|
||||
{
|
||||
WASMModuleInstanceCommon *module_inst =
|
||||
wasm_exec_env_get_module_inst(exec_env);
|
||||
|
||||
#if WASM_ENABLE_INTERP != 0
|
||||
if (module_inst->module_type == Wasm_Module_Bytecode) {
|
||||
return wasm_interp_dump_call_stack(exec_env, false, NULL, 0);
|
||||
}
|
||||
#endif
|
||||
#if WASM_ENABLE_AOT != 0
|
||||
if (module_inst->module_type == Wasm_Module_AoT) {
|
||||
return aot_dump_call_stack(exec_env, false, NULL, 0);
|
||||
}
|
||||
#endif
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
uint32
|
||||
wasm_runtime_dump_call_stack_to_buf(wasm_exec_env_t exec_env, char *buf,
|
||||
uint32 len)
|
||||
{
|
||||
WASMModuleInstanceCommon *module_inst =
|
||||
wasm_exec_env_get_module_inst(exec_env);
|
||||
|
||||
#if WASM_ENABLE_INTERP != 0
|
||||
if (module_inst->module_type == Wasm_Module_Bytecode) {
|
||||
return wasm_interp_dump_call_stack(exec_env, false, buf, len);
|
||||
}
|
||||
#endif
|
||||
#if WASM_ENABLE_AOT != 0
|
||||
if (module_inst->module_type == Wasm_Module_AoT) {
|
||||
return aot_dump_call_stack(exec_env, false, buf, len);
|
||||
}
|
||||
#endif
|
||||
|
||||
return 0;
|
||||
}
|
||||
#endif /* end of WASM_ENABLE_DUMP_CALL_STACK */
|
||||
|
||||
bool
|
||||
|
||||
@ -404,6 +404,7 @@ typedef struct wasm_frame_t {
|
||||
uint32 module_offset;
|
||||
uint32 func_index;
|
||||
uint32 func_offset;
|
||||
const char *func_name_wp;
|
||||
} WASMCApiFrame;
|
||||
|
||||
/* See wasm_export.h for description */
|
||||
@ -803,6 +804,28 @@ void
|
||||
wasm_externref_cleanup(WASMModuleInstanceCommon *module_inst);
|
||||
#endif /* end of WASM_ENABLE_REF_TYPES */
|
||||
|
||||
#if WASM_ENABLE_DUMP_CALL_STACK != 0
|
||||
/**
|
||||
* @brief Internal implementation for dumping or printing callstack line
|
||||
*
|
||||
* @note if dump_or_print is true, then print to stdout directly;
|
||||
* if dump_or_print is false, but *buf is NULL, then return the length of the
|
||||
* line;
|
||||
* if dump_or_print is false, and *buf is not NULL, then dump content to
|
||||
* the memory pointed by *buf, and adjust *buf and *len according to actual
|
||||
* bytes dumped, and return the actual dumped length
|
||||
*
|
||||
* @param line_buf current line to dump or print
|
||||
* @param dump_or_print whether to print to stdout or dump to buf
|
||||
* @param buf [INOUT] pointer to the buffer
|
||||
* @param len [INOUT] pointer to remaining length
|
||||
* @return bytes printed to stdout or dumped to buf
|
||||
*/
|
||||
uint32
|
||||
wasm_runtime_dump_line_buf_impl(const char *line_buf, bool dump_or_print,
|
||||
char **buf, uint32 *len);
|
||||
#endif /* end of WASM_ENABLE_DUMP_CALL_STACK != 0 */
|
||||
|
||||
/* Get module of the current exec_env */
|
||||
WASMModuleCommon *
|
||||
wasm_exec_env_get_module(WASMExecEnv *exec_env);
|
||||
|
||||
Reference in New Issue
Block a user