Skip to content

Commit 0053962

Browse files
authored
Improve stack trace dump and fix coding guideline CI (#2599)
Avoid the stack traces getting mixed up together when multi-threading is enabled by using exception_lock/unlock in dumping the call stacks. And remove duplicated call stack dump in wasm_application.c. Also update coding guideline CI to fix the clang-format-12 not found issue.
1 parent 3c17a36 commit 0053962

File tree

8 files changed

+28
-24
lines changed

8 files changed

+28
-24
lines changed

.github/workflows/coding_guidelines.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ concurrency:
1616

1717
jobs:
1818
compliance_job:
19-
runs-on: ubuntu-latest
19+
runs-on: ubuntu-20.04
2020
steps:
2121
- name: checkout
2222
uses: actions/checkout@v3

core/iwasm/aot/aot_runtime.c

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2807,6 +2807,7 @@ aot_create_call_stack(struct WASMExecEnv *exec_env)
28072807
total_len += \
28082808
wasm_runtime_dump_line_buf_impl(line_buf, print, &buf, &len); \
28092809
if ((!print) && buf && (len == 0)) { \
2810+
exception_unlock(module_inst); \
28102811
return total_len; \
28112812
} \
28122813
} while (0)
@@ -2829,6 +2830,7 @@ aot_dump_call_stack(WASMExecEnv *exec_env, bool print, char *buf, uint32 len)
28292830
return 0;
28302831
}
28312832

2833+
exception_lock(module_inst);
28322834
snprintf(line_buf, sizeof(line_buf), "\n");
28332835
PRINT_OR_DUMP();
28342836

@@ -2837,6 +2839,7 @@ aot_dump_call_stack(WASMExecEnv *exec_env, bool print, char *buf, uint32 len)
28372839
uint32 line_length, i;
28382840

28392841
if (!bh_vector_get(module_inst->frames, n, &frame)) {
2842+
exception_unlock(module_inst);
28402843
return 0;
28412844
}
28422845

@@ -2867,6 +2870,7 @@ aot_dump_call_stack(WASMExecEnv *exec_env, bool print, char *buf, uint32 len)
28672870
}
28682871
snprintf(line_buf, sizeof(line_buf), "\n");
28692872
PRINT_OR_DUMP();
2873+
exception_unlock(module_inst);
28702874

28712875
return total_len + 1;
28722876
}

core/iwasm/common/wasm_application.c

Lines changed: 1 addition & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -231,7 +231,7 @@ wasm_application_execute_main(WASMModuleInstanceCommon *module_inst, int32 argc,
231231
char *argv[])
232232
{
233233
bool ret;
234-
#if (WASM_ENABLE_MEMORY_PROFILING != 0) || (WASM_ENABLE_DUMP_CALL_STACK != 0)
234+
#if (WASM_ENABLE_MEMORY_PROFILING != 0)
235235
WASMExecEnv *exec_env;
236236
#endif
237237

@@ -251,14 +251,6 @@ wasm_application_execute_main(WASMModuleInstanceCommon *module_inst, int32 argc,
251251
if (ret)
252252
ret = wasm_runtime_get_exception(module_inst) == NULL;
253253

254-
#if WASM_ENABLE_DUMP_CALL_STACK != 0
255-
if (!ret) {
256-
exec_env = wasm_runtime_get_exec_env_singleton(module_inst);
257-
if (exec_env)
258-
wasm_runtime_dump_call_stack(exec_env);
259-
}
260-
#endif
261-
262254
return ret;
263255
}
264256

core/iwasm/interpreter/wasm_interp_classic.c

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4209,7 +4209,6 @@ wasm_interp_call_wasm(WASMModuleInstance *module_inst, WASMExecEnv *exec_env,
42094209
unsigned frame_size = wasm_interp_interp_frame_size(all_cell_num);
42104210
unsigned i;
42114211
bool copy_argv_from_frame = true;
4212-
char exception[EXCEPTION_BUF_LEN];
42134212

42144213
if (argc < function->param_cell_num) {
42154214
char buf[128];
@@ -4342,8 +4341,6 @@ wasm_interp_call_wasm(WASMModuleInstance *module_inst, WASMExecEnv *exec_env,
43424341
wasm_interp_dump_call_stack(exec_env, true, NULL, 0);
43434342
}
43444343
#endif
4345-
wasm_copy_exception(module_inst, exception);
4346-
LOG_DEBUG("meet an exception %s", exception);
43474344
}
43484345

43494346
wasm_exec_env_set_cur_frame(exec_env, prev_frame);

core/iwasm/interpreter/wasm_interp_fast.c

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3945,7 +3945,6 @@ wasm_interp_call_wasm(WASMModuleInstance *module_inst, WASMExecEnv *exec_env,
39453945
/* This frame won't be used by JITed code, so only allocate interp
39463946
frame here. */
39473947
unsigned frame_size = wasm_interp_interp_frame_size(all_cell_num);
3948-
char exception[EXCEPTION_BUF_LEN];
39493948

39503949
if (argc < function->param_cell_num) {
39513950
char buf[128];
@@ -4030,8 +4029,6 @@ wasm_interp_call_wasm(WASMModuleInstance *module_inst, WASMExecEnv *exec_env,
40304029
wasm_interp_dump_call_stack(exec_env, true, NULL, 0);
40314030
}
40324031
#endif
4033-
wasm_copy_exception(module_inst, exception);
4034-
LOG_DEBUG("meet an exception %s", exception);
40354032
}
40364033

40374034
wasm_exec_env_set_cur_frame(exec_env, prev_frame);

core/iwasm/interpreter/wasm_runtime.c

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2915,6 +2915,7 @@ wasm_interp_create_call_stack(struct WASMExecEnv *exec_env)
29152915
total_len += \
29162916
wasm_runtime_dump_line_buf_impl(line_buf, print, &buf, &len); \
29172917
if ((!print) && buf && (len == 0)) { \
2918+
exception_unlock(module_inst); \
29182919
return total_len; \
29192920
} \
29202921
} while (0)
@@ -2939,6 +2940,7 @@ wasm_interp_dump_call_stack(struct WASMExecEnv *exec_env, bool print, char *buf,
29392940
return 0;
29402941
}
29412942

2943+
exception_lock(module_inst);
29422944
snprintf(line_buf, sizeof(line_buf), "\n");
29432945
PRINT_OR_DUMP();
29442946

@@ -2947,6 +2949,7 @@ wasm_interp_dump_call_stack(struct WASMExecEnv *exec_env, bool print, char *buf,
29472949
uint32 line_length, i;
29482950

29492951
if (!bh_vector_get(module_inst->frames, n, &frame)) {
2952+
exception_unlock(module_inst);
29502953
return 0;
29512954
}
29522955

@@ -2977,6 +2980,7 @@ wasm_interp_dump_call_stack(struct WASMExecEnv *exec_env, bool print, char *buf,
29772980
}
29782981
snprintf(line_buf, sizeof(line_buf), "\n");
29792982
PRINT_OR_DUMP();
2983+
exception_unlock(module_inst);
29802984

29812985
return total_len + 1;
29822986
}

product-mini/platforms/posix/main.c

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -120,8 +120,7 @@ app_instance_main(wasm_module_inst_t module_inst)
120120
const char *exception;
121121

122122
wasm_application_execute_main(module_inst, app_argc, app_argv);
123-
if ((exception = wasm_runtime_get_exception(module_inst)))
124-
printf("%s\n", exception);
123+
exception = wasm_runtime_get_exception(module_inst);
125124
return exception;
126125
}
127126

@@ -977,17 +976,20 @@ main(int argc, char *argv[])
977976
#endif
978977

979978
ret = 0;
979+
const char *exception = NULL;
980980
if (is_repl_mode) {
981981
app_instance_repl(wasm_module_inst);
982982
}
983983
else if (func_name) {
984-
if (app_instance_func(wasm_module_inst, func_name)) {
984+
exception = app_instance_func(wasm_module_inst, func_name);
985+
if (exception) {
985986
/* got an exception */
986987
ret = 1;
987988
}
988989
}
989990
else {
990-
if (app_instance_main(wasm_module_inst)) {
991+
exception = app_instance_main(wasm_module_inst);
992+
if (exception) {
991993
/* got an exception */
992994
ret = 1;
993995
}
@@ -1000,6 +1002,9 @@ main(int argc, char *argv[])
10001002
}
10011003
#endif
10021004

1005+
if (exception)
1006+
printf("%s\n", exception);
1007+
10031008
#if WASM_ENABLE_STATIC_PGO != 0 && WASM_ENABLE_AOT != 0
10041009
if (get_package_type(wasm_file_buf, wasm_file_size) == Wasm_Module_AoT
10051010
&& gen_prof_file)

product-mini/platforms/windows/main.c

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -77,8 +77,7 @@ app_instance_main(wasm_module_inst_t module_inst)
7777
const char *exception;
7878

7979
wasm_application_execute_main(module_inst, app_argc, app_argv);
80-
if ((exception = wasm_runtime_get_exception(module_inst)))
81-
printf("%s\n", exception);
80+
exception = wasm_runtime_get_exception(module_inst);
8281
return exception;
8382
}
8483

@@ -545,17 +544,20 @@ main(int argc, char *argv[])
545544
#endif
546545

547546
ret = 0;
547+
const char *exception = NULL;
548548
if (is_repl_mode) {
549549
app_instance_repl(wasm_module_inst);
550550
}
551551
else if (func_name) {
552-
if (app_instance_func(wasm_module_inst, func_name)) {
552+
exception = app_instance_func(wasm_module_inst, func_name);
553+
if (exception) {
553554
/* got an exception */
554555
ret = 1;
555556
}
556557
}
557558
else {
558-
if (app_instance_main(wasm_module_inst)) {
559+
exception = app_instance_main(wasm_module_inst);
560+
if (exception) {
559561
/* got an exception */
560562
ret = 1;
561563
}
@@ -568,6 +570,9 @@ main(int argc, char *argv[])
568570
}
569571
#endif
570572

573+
if (exception)
574+
printf("%s\n", exception);
575+
571576
#if WASM_ENABLE_DEBUG_INTERP != 0
572577
fail4:
573578
#endif

0 commit comments

Comments
 (0)