address PR comments

This commit is contained in:
Xu Jun 2022-06-24 11:20:31 +08:00
parent 38fdf917a1
commit adfd5ed0c2
7 changed files with 71 additions and 44 deletions

View File

@ -3065,21 +3065,10 @@ aot_create_call_stack(struct WASMExecEnv *exec_env)
#define PRINT_OR_DUMP() \
do { \
if (print) { \
os_printf("%s", line_buf); \
} \
else if (buf) { \
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); \
total_len += \
wasm_runtime_dump_line_buf_impl(line_buf, print, &buf, &len); \
if ((!print) && buf && (len == 0)) { \
return total_len; \
} \
} while (0)

View File

@ -735,17 +735,17 @@ bool
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 print print to stdout
* @param print whether to print to stdout or not
* @param buf buffer to store the dumped content
* @param len length of the buffer
*
* @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
* 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
aot_dump_call_stack(WASMExecEnv *exec_env, bool print, char *buf, uint32 len);

View File

@ -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)
{

View File

@ -804,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);

View File

@ -1076,7 +1076,7 @@ wasm_runtime_get_call_stack_buf_size(wasm_exec_env_t exec_env);
* @param len length of the buffer
*
* @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_dump_call_stack_to_buf(wasm_exec_env_t exec_env, char *buf,

View File

@ -2562,7 +2562,10 @@ wasm_interp_create_call_stack(struct WASMExecEnv *exec_env)
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;
n++;
@ -2573,21 +2576,10 @@ wasm_interp_create_call_stack(struct WASMExecEnv *exec_env)
#define PRINT_OR_DUMP() \
do { \
if (print) { \
os_printf("%s", line_buf); \
} \
else if (buf) { \
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); \
total_len += \
wasm_runtime_dump_line_buf_impl(line_buf, print, &buf, &len); \
if ((!print) && buf && (len == 0)) { \
return total_len; \
} \
} while (0)

View File

@ -436,17 +436,17 @@ bool
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 print print to stdout
* @param print whether to print to stdout or not
* @param buf buffer to store the dumped content
* @param len length of the buffer
*
* @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
* 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
wasm_interp_dump_call_stack(struct WASMExecEnv *exec_env, bool print, char *buf,