mirror of
https://github.com/bytecodealliance/wasm-micro-runtime.git
synced 2025-07-15 16:58:34 +00:00
address PR comments
This commit is contained in:
parent
38fdf917a1
commit
adfd5ed0c2
|
@ -3063,24 +3063,13 @@ aot_create_call_stack(struct WASMExecEnv *exec_env)
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
#define PRINT_OR_DUMP() \
|
#define PRINT_OR_DUMP() \
|
||||||
do { \
|
do { \
|
||||||
if (print) { \
|
total_len += \
|
||||||
os_printf("%s", line_buf); \
|
wasm_runtime_dump_line_buf_impl(line_buf, print, &buf, &len); \
|
||||||
} \
|
if ((!print) && buf && (len == 0)) { \
|
||||||
else if (buf) { \
|
return total_len; \
|
||||||
uint32 remain_len = len - total_len; \
|
} \
|
||||||
uint32 string_len = \
|
|
||||||
snprintf(buf + total_len, remain_len, "%s", line_buf); \
|
|
||||||
if (string_len >= remain_len) { \
|
|
||||||
/* Buffer full */ \
|
|
||||||
return len; \
|
|
||||||
} \
|
|
||||||
total_len += string_len; \
|
|
||||||
} \
|
|
||||||
else { \
|
|
||||||
total_len += strlen(line_buf); \
|
|
||||||
} \
|
|
||||||
} while (0)
|
} while (0)
|
||||||
|
|
||||||
uint32
|
uint32
|
||||||
|
|
|
@ -735,17 +735,17 @@ bool
|
||||||
aot_create_call_stack(struct WASMExecEnv *exec_env);
|
aot_create_call_stack(struct WASMExecEnv *exec_env);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @brief dump aot call stack or get the size
|
* @brief Dump wasm call stack or get the size
|
||||||
*
|
*
|
||||||
* @param exec_env the execution environment
|
* @param exec_env the execution environment
|
||||||
* @param print print to stdout
|
* @param print whether to print to stdout or not
|
||||||
* @param buf buffer to store the dumped content
|
* @param buf buffer to store the dumped content
|
||||||
* @param len length of the buffer
|
* @param len length of the buffer
|
||||||
*
|
*
|
||||||
* @return when print is true, return the bytes printed out to stdout; when
|
* @return when print is true, return the bytes printed out to stdout; when
|
||||||
* print is false and buf is NULL, return the size required to store the
|
* print is false and buf is NULL, return the size required to store the
|
||||||
* callstack content; when print is false and buf is not NULL, return the size
|
* callstack content; when print is false and buf is not NULL, return the size
|
||||||
* dumped to the buffer
|
* dumped to the buffer, 0 means error and data in buf may be invalid
|
||||||
*/
|
*/
|
||||||
uint32
|
uint32
|
||||||
aot_dump_call_stack(WASMExecEnv *exec_env, bool print, char *buf, uint32 len);
|
aot_dump_call_stack(WASMExecEnv *exec_env, bool print, char *buf, uint32 len);
|
||||||
|
|
|
@ -4527,6 +4527,30 @@ wasm_externref_retain(uint32 externref_idx)
|
||||||
#endif /* end of WASM_ENABLE_REF_TYPES */
|
#endif /* end of WASM_ENABLE_REF_TYPES */
|
||||||
|
|
||||||
#if WASM_ENABLE_DUMP_CALL_STACK != 0
|
#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
|
void
|
||||||
wasm_runtime_dump_call_stack(WASMExecEnv *exec_env)
|
wasm_runtime_dump_call_stack(WASMExecEnv *exec_env)
|
||||||
{
|
{
|
||||||
|
|
|
@ -804,6 +804,28 @@ void
|
||||||
wasm_externref_cleanup(WASMModuleInstanceCommon *module_inst);
|
wasm_externref_cleanup(WASMModuleInstanceCommon *module_inst);
|
||||||
#endif /* end of WASM_ENABLE_REF_TYPES */
|
#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 */
|
/* Get module of the current exec_env */
|
||||||
WASMModuleCommon *
|
WASMModuleCommon *
|
||||||
wasm_exec_env_get_module(WASMExecEnv *exec_env);
|
wasm_exec_env_get_module(WASMExecEnv *exec_env);
|
||||||
|
|
|
@ -1076,7 +1076,7 @@ wasm_runtime_get_call_stack_buf_size(wasm_exec_env_t exec_env);
|
||||||
* @param len length of the buffer
|
* @param len length of the buffer
|
||||||
*
|
*
|
||||||
* @return bytes dumped to the buffer, including the terminating null
|
* @return bytes dumped to the buffer, including the terminating null
|
||||||
* byte ('\0'), 0 means error and buf may remain untouched
|
* byte ('\0'), 0 means error and data in buf may be invalid
|
||||||
*/
|
*/
|
||||||
WASM_RUNTIME_API_EXTERN uint32_t
|
WASM_RUNTIME_API_EXTERN uint32_t
|
||||||
wasm_runtime_dump_call_stack_to_buf(wasm_exec_env_t exec_env, char *buf,
|
wasm_runtime_dump_call_stack_to_buf(wasm_exec_env_t exec_env, char *buf,
|
||||||
|
|
|
@ -2562,7 +2562,10 @@ wasm_interp_create_call_stack(struct WASMExecEnv *exec_env)
|
||||||
|
|
||||||
frame.func_name_wp = func_name;
|
frame.func_name_wp = func_name;
|
||||||
|
|
||||||
bh_vector_append(module_inst->frames, &frame);
|
if (!bh_vector_append(module_inst->frames, &frame)) {
|
||||||
|
bh_vector_destroy(module_inst->frames);
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
cur_frame = cur_frame->prev_frame;
|
cur_frame = cur_frame->prev_frame;
|
||||||
n++;
|
n++;
|
||||||
|
@ -2571,24 +2574,13 @@ wasm_interp_create_call_stack(struct WASMExecEnv *exec_env)
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
#define PRINT_OR_DUMP() \
|
#define PRINT_OR_DUMP() \
|
||||||
do { \
|
do { \
|
||||||
if (print) { \
|
total_len += \
|
||||||
os_printf("%s", line_buf); \
|
wasm_runtime_dump_line_buf_impl(line_buf, print, &buf, &len); \
|
||||||
} \
|
if ((!print) && buf && (len == 0)) { \
|
||||||
else if (buf) { \
|
return total_len; \
|
||||||
uint32 remain_len = len - total_len; \
|
} \
|
||||||
uint32 string_len = \
|
|
||||||
snprintf(buf + total_len, remain_len, "%s", line_buf); \
|
|
||||||
if (string_len >= remain_len) { \
|
|
||||||
/* Buffer full */ \
|
|
||||||
return len; \
|
|
||||||
} \
|
|
||||||
total_len += string_len; \
|
|
||||||
} \
|
|
||||||
else { \
|
|
||||||
total_len += strlen(line_buf); \
|
|
||||||
} \
|
|
||||||
} while (0)
|
} while (0)
|
||||||
|
|
||||||
uint32
|
uint32
|
||||||
|
|
|
@ -436,17 +436,17 @@ bool
|
||||||
wasm_interp_create_call_stack(struct WASMExecEnv *exec_env);
|
wasm_interp_create_call_stack(struct WASMExecEnv *exec_env);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @brief dump wasm call stack or get the size
|
* @brief Dump wasm call stack or get the size
|
||||||
*
|
*
|
||||||
* @param exec_env the execution environment
|
* @param exec_env the execution environment
|
||||||
* @param print print to stdout
|
* @param print whether to print to stdout or not
|
||||||
* @param buf buffer to store the dumped content
|
* @param buf buffer to store the dumped content
|
||||||
* @param len length of the buffer
|
* @param len length of the buffer
|
||||||
*
|
*
|
||||||
* @return when print is true, return the bytes printed out to stdout; when
|
* @return when print is true, return the bytes printed out to stdout; when
|
||||||
* print is false and buf is NULL, return the size required to store the
|
* print is false and buf is NULL, return the size required to store the
|
||||||
* callstack content; when print is false and buf is not NULL, return the size
|
* callstack content; when print is false and buf is not NULL, return the size
|
||||||
* dumped to the buffer
|
* dumped to the buffer, 0 means error and data in buf may be invalid
|
||||||
*/
|
*/
|
||||||
uint32
|
uint32
|
||||||
wasm_interp_dump_call_stack(struct WASMExecEnv *exec_env, bool print, char *buf,
|
wasm_interp_dump_call_stack(struct WASMExecEnv *exec_env, bool print, char *buf,
|
||||||
|
|
Loading…
Reference in New Issue
Block a user