truncate function name if too long

This commit is contained in:
Xu Jun 2022-06-23 15:55:42 +08:00
parent 53115b2b37
commit 38fdf917a1
2 changed files with 28 additions and 8 deletions

View File

@ -3106,6 +3106,7 @@ aot_dump_call_stack(WASMExecEnv *exec_env, bool print, char *buf, uint32 len)
while (n < total_frames) {
WASMCApiFrame frame = { 0 };
uint32 line_length, i;
if (!bh_vector_get(module_inst->frames.ptr, n, &frame)) {
return 0;
@ -3113,12 +3114,21 @@ aot_dump_call_stack(WASMExecEnv *exec_env, bool print, char *buf, uint32 len)
/* function name not exported, print number instead */
if (frame.func_name_wp == NULL) {
snprintf(line_buf, sizeof(line_buf), "#%02d $f%d\n", n,
frame.func_index);
line_length = snprintf(line_buf, sizeof(line_buf), "#%02d $f%d\n",
n, frame.func_index);
}
else {
snprintf(line_buf, sizeof(line_buf), "#%02d %s\n", n,
frame.func_name_wp);
line_length = snprintf(line_buf, sizeof(line_buf), "#%02d %s\n", n,
frame.func_name_wp);
}
if (line_length >= sizeof(line_buf)) {
uint32 line_buffer_len = sizeof(line_buf);
/* If line too long, ensure the last character is '\n' */
for (i = line_buffer_len - 5; i < line_buffer_len - 2; i++) {
line_buf[i] = '.';
}
line_buf[line_buffer_len - 2] = '\n';
}
PRINT_OR_DUMP();

View File

@ -2616,6 +2616,7 @@ wasm_interp_dump_call_stack(struct WASMExecEnv *exec_env, bool print, char *buf,
while (n < total_frames) {
WASMCApiFrame frame = { 0 };
uint32 line_length, i;
if (!bh_vector_get(module_inst->frames, n, &frame)) {
return 0;
@ -2623,12 +2624,21 @@ wasm_interp_dump_call_stack(struct WASMExecEnv *exec_env, bool print, char *buf,
/* function name not exported, print number instead */
if (frame.func_name_wp == NULL) {
snprintf(line_buf, sizeof(line_buf), "#%02d $f%d\n", n,
frame.func_index);
line_length = snprintf(line_buf, sizeof(line_buf), "#%02d $f%d\n",
n, frame.func_index);
}
else {
snprintf(line_buf, sizeof(line_buf), "#%02d %s\n", n,
frame.func_name_wp);
line_length = snprintf(line_buf, sizeof(line_buf), "#%02d %s\n", n,
frame.func_name_wp);
}
if (line_length >= sizeof(line_buf)) {
uint32 line_buffer_len = sizeof(line_buf);
/* If line too long, ensure the last character is '\n' */
for (i = line_buffer_len - 5; i < line_buffer_len - 2; i++) {
line_buf[i] = '.';
}
line_buf[line_buffer_len - 2] = '\n';
}
PRINT_OR_DUMP();