Просмотр исходного кода

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.
Enrico Loparco 2 лет назад
Родитель
Сommit
00539620e9

+ 1 - 1
.github/workflows/coding_guidelines.yml

@@ -16,7 +16,7 @@ concurrency:
 
 
 jobs:
 jobs:
   compliance_job:
   compliance_job:
-    runs-on: ubuntu-latest
+    runs-on: ubuntu-20.04
     steps:
     steps:
       - name: checkout
       - name: checkout
         uses: actions/checkout@v3
         uses: actions/checkout@v3

+ 4 - 0
core/iwasm/aot/aot_runtime.c

@@ -2807,6 +2807,7 @@ aot_create_call_stack(struct WASMExecEnv *exec_env)
         total_len +=                                                      \
         total_len +=                                                      \
             wasm_runtime_dump_line_buf_impl(line_buf, print, &buf, &len); \
             wasm_runtime_dump_line_buf_impl(line_buf, print, &buf, &len); \
         if ((!print) && buf && (len == 0)) {                              \
         if ((!print) && buf && (len == 0)) {                              \
+            exception_unlock(module_inst);                                \
             return total_len;                                             \
             return total_len;                                             \
         }                                                                 \
         }                                                                 \
     } while (0)
     } while (0)
@@ -2829,6 +2830,7 @@ aot_dump_call_stack(WASMExecEnv *exec_env, bool print, char *buf, uint32 len)
         return 0;
         return 0;
     }
     }
 
 
+    exception_lock(module_inst);
     snprintf(line_buf, sizeof(line_buf), "\n");
     snprintf(line_buf, sizeof(line_buf), "\n");
     PRINT_OR_DUMP();
     PRINT_OR_DUMP();
 
 
@@ -2837,6 +2839,7 @@ aot_dump_call_stack(WASMExecEnv *exec_env, bool print, char *buf, uint32 len)
         uint32 line_length, i;
         uint32 line_length, i;
 
 
         if (!bh_vector_get(module_inst->frames, n, &frame)) {
         if (!bh_vector_get(module_inst->frames, n, &frame)) {
+            exception_unlock(module_inst);
             return 0;
             return 0;
         }
         }
 
 
@@ -2867,6 +2870,7 @@ aot_dump_call_stack(WASMExecEnv *exec_env, bool print, char *buf, uint32 len)
     }
     }
     snprintf(line_buf, sizeof(line_buf), "\n");
     snprintf(line_buf, sizeof(line_buf), "\n");
     PRINT_OR_DUMP();
     PRINT_OR_DUMP();
+    exception_unlock(module_inst);
 
 
     return total_len + 1;
     return total_len + 1;
 }
 }

+ 1 - 9
core/iwasm/common/wasm_application.c

@@ -231,7 +231,7 @@ wasm_application_execute_main(WASMModuleInstanceCommon *module_inst, int32 argc,
                               char *argv[])
                               char *argv[])
 {
 {
     bool ret;
     bool ret;
-#if (WASM_ENABLE_MEMORY_PROFILING != 0) || (WASM_ENABLE_DUMP_CALL_STACK != 0)
+#if (WASM_ENABLE_MEMORY_PROFILING != 0)
     WASMExecEnv *exec_env;
     WASMExecEnv *exec_env;
 #endif
 #endif
 
 
@@ -251,14 +251,6 @@ wasm_application_execute_main(WASMModuleInstanceCommon *module_inst, int32 argc,
     if (ret)
     if (ret)
         ret = wasm_runtime_get_exception(module_inst) == NULL;
         ret = wasm_runtime_get_exception(module_inst) == NULL;
 
 
-#if WASM_ENABLE_DUMP_CALL_STACK != 0
-    if (!ret) {
-        exec_env = wasm_runtime_get_exec_env_singleton(module_inst);
-        if (exec_env)
-            wasm_runtime_dump_call_stack(exec_env);
-    }
-#endif
-
     return ret;
     return ret;
 }
 }
 
 

+ 0 - 3
core/iwasm/interpreter/wasm_interp_classic.c

@@ -4209,7 +4209,6 @@ wasm_interp_call_wasm(WASMModuleInstance *module_inst, WASMExecEnv *exec_env,
     unsigned frame_size = wasm_interp_interp_frame_size(all_cell_num);
     unsigned frame_size = wasm_interp_interp_frame_size(all_cell_num);
     unsigned i;
     unsigned i;
     bool copy_argv_from_frame = true;
     bool copy_argv_from_frame = true;
-    char exception[EXCEPTION_BUF_LEN];
 
 
     if (argc < function->param_cell_num) {
     if (argc < function->param_cell_num) {
         char buf[128];
         char buf[128];
@@ -4342,8 +4341,6 @@ wasm_interp_call_wasm(WASMModuleInstance *module_inst, WASMExecEnv *exec_env,
             wasm_interp_dump_call_stack(exec_env, true, NULL, 0);
             wasm_interp_dump_call_stack(exec_env, true, NULL, 0);
         }
         }
 #endif
 #endif
-        wasm_copy_exception(module_inst, exception);
-        LOG_DEBUG("meet an exception %s", exception);
     }
     }
 
 
     wasm_exec_env_set_cur_frame(exec_env, prev_frame);
     wasm_exec_env_set_cur_frame(exec_env, prev_frame);

+ 0 - 3
core/iwasm/interpreter/wasm_interp_fast.c

@@ -3945,7 +3945,6 @@ wasm_interp_call_wasm(WASMModuleInstance *module_inst, WASMExecEnv *exec_env,
     /* This frame won't be used by JITed code, so only allocate interp
     /* This frame won't be used by JITed code, so only allocate interp
        frame here.  */
        frame here.  */
     unsigned frame_size = wasm_interp_interp_frame_size(all_cell_num);
     unsigned frame_size = wasm_interp_interp_frame_size(all_cell_num);
-    char exception[EXCEPTION_BUF_LEN];
 
 
     if (argc < function->param_cell_num) {
     if (argc < function->param_cell_num) {
         char buf[128];
         char buf[128];
@@ -4030,8 +4029,6 @@ wasm_interp_call_wasm(WASMModuleInstance *module_inst, WASMExecEnv *exec_env,
             wasm_interp_dump_call_stack(exec_env, true, NULL, 0);
             wasm_interp_dump_call_stack(exec_env, true, NULL, 0);
         }
         }
 #endif
 #endif
-        wasm_copy_exception(module_inst, exception);
-        LOG_DEBUG("meet an exception %s", exception);
     }
     }
 
 
     wasm_exec_env_set_cur_frame(exec_env, prev_frame);
     wasm_exec_env_set_cur_frame(exec_env, prev_frame);

+ 4 - 0
core/iwasm/interpreter/wasm_runtime.c

@@ -2915,6 +2915,7 @@ wasm_interp_create_call_stack(struct WASMExecEnv *exec_env)
         total_len +=                                                      \
         total_len +=                                                      \
             wasm_runtime_dump_line_buf_impl(line_buf, print, &buf, &len); \
             wasm_runtime_dump_line_buf_impl(line_buf, print, &buf, &len); \
         if ((!print) && buf && (len == 0)) {                              \
         if ((!print) && buf && (len == 0)) {                              \
+            exception_unlock(module_inst);                                \
             return total_len;                                             \
             return total_len;                                             \
         }                                                                 \
         }                                                                 \
     } while (0)
     } while (0)
@@ -2939,6 +2940,7 @@ wasm_interp_dump_call_stack(struct WASMExecEnv *exec_env, bool print, char *buf,
         return 0;
         return 0;
     }
     }
 
 
+    exception_lock(module_inst);
     snprintf(line_buf, sizeof(line_buf), "\n");
     snprintf(line_buf, sizeof(line_buf), "\n");
     PRINT_OR_DUMP();
     PRINT_OR_DUMP();
 
 
@@ -2947,6 +2949,7 @@ wasm_interp_dump_call_stack(struct WASMExecEnv *exec_env, bool print, char *buf,
         uint32 line_length, i;
         uint32 line_length, i;
 
 
         if (!bh_vector_get(module_inst->frames, n, &frame)) {
         if (!bh_vector_get(module_inst->frames, n, &frame)) {
+            exception_unlock(module_inst);
             return 0;
             return 0;
         }
         }
 
 
@@ -2977,6 +2980,7 @@ wasm_interp_dump_call_stack(struct WASMExecEnv *exec_env, bool print, char *buf,
     }
     }
     snprintf(line_buf, sizeof(line_buf), "\n");
     snprintf(line_buf, sizeof(line_buf), "\n");
     PRINT_OR_DUMP();
     PRINT_OR_DUMP();
+    exception_unlock(module_inst);
 
 
     return total_len + 1;
     return total_len + 1;
 }
 }

+ 9 - 4
product-mini/platforms/posix/main.c

@@ -120,8 +120,7 @@ app_instance_main(wasm_module_inst_t module_inst)
     const char *exception;
     const char *exception;
 
 
     wasm_application_execute_main(module_inst, app_argc, app_argv);
     wasm_application_execute_main(module_inst, app_argc, app_argv);
-    if ((exception = wasm_runtime_get_exception(module_inst)))
-        printf("%s\n", exception);
+    exception = wasm_runtime_get_exception(module_inst);
     return exception;
     return exception;
 }
 }
 
 
@@ -977,17 +976,20 @@ main(int argc, char *argv[])
 #endif
 #endif
 
 
     ret = 0;
     ret = 0;
+    const char *exception = NULL;
     if (is_repl_mode) {
     if (is_repl_mode) {
         app_instance_repl(wasm_module_inst);
         app_instance_repl(wasm_module_inst);
     }
     }
     else if (func_name) {
     else if (func_name) {
-        if (app_instance_func(wasm_module_inst, func_name)) {
+        exception = app_instance_func(wasm_module_inst, func_name);
+        if (exception) {
             /* got an exception */
             /* got an exception */
             ret = 1;
             ret = 1;
         }
         }
     }
     }
     else {
     else {
-        if (app_instance_main(wasm_module_inst)) {
+        exception = app_instance_main(wasm_module_inst);
+        if (exception) {
             /* got an exception */
             /* got an exception */
             ret = 1;
             ret = 1;
         }
         }
@@ -1000,6 +1002,9 @@ main(int argc, char *argv[])
     }
     }
 #endif
 #endif
 
 
+    if (exception)
+        printf("%s\n", exception);
+
 #if WASM_ENABLE_STATIC_PGO != 0 && WASM_ENABLE_AOT != 0
 #if WASM_ENABLE_STATIC_PGO != 0 && WASM_ENABLE_AOT != 0
     if (get_package_type(wasm_file_buf, wasm_file_size) == Wasm_Module_AoT
     if (get_package_type(wasm_file_buf, wasm_file_size) == Wasm_Module_AoT
         && gen_prof_file)
         && gen_prof_file)

+ 9 - 4
product-mini/platforms/windows/main.c

@@ -77,8 +77,7 @@ app_instance_main(wasm_module_inst_t module_inst)
     const char *exception;
     const char *exception;
 
 
     wasm_application_execute_main(module_inst, app_argc, app_argv);
     wasm_application_execute_main(module_inst, app_argc, app_argv);
-    if ((exception = wasm_runtime_get_exception(module_inst)))
-        printf("%s\n", exception);
+    exception = wasm_runtime_get_exception(module_inst);
     return exception;
     return exception;
 }
 }
 
 
@@ -545,17 +544,20 @@ main(int argc, char *argv[])
 #endif
 #endif
 
 
     ret = 0;
     ret = 0;
+    const char *exception = NULL;
     if (is_repl_mode) {
     if (is_repl_mode) {
         app_instance_repl(wasm_module_inst);
         app_instance_repl(wasm_module_inst);
     }
     }
     else if (func_name) {
     else if (func_name) {
-        if (app_instance_func(wasm_module_inst, func_name)) {
+        exception = app_instance_func(wasm_module_inst, func_name);
+        if (exception) {
             /* got an exception */
             /* got an exception */
             ret = 1;
             ret = 1;
         }
         }
     }
     }
     else {
     else {
-        if (app_instance_main(wasm_module_inst)) {
+        exception = app_instance_main(wasm_module_inst);
+        if (exception) {
             /* got an exception */
             /* got an exception */
             ret = 1;
             ret = 1;
         }
         }
@@ -568,6 +570,9 @@ main(int argc, char *argv[])
     }
     }
 #endif
 #endif
 
 
+    if (exception)
+        printf("%s\n", exception);
+
 #if WASM_ENABLE_DEBUG_INTERP != 0
 #if WASM_ENABLE_DEBUG_INTERP != 0
 fail4:
 fail4:
 #endif
 #endif