Эх сурвалжийг харах

Refactor copy callstack feature (#4401)

- Change `WAMR_ENABLE_COPY_CALLSTACK` to `WAMR_BUILD_COPY_CALL_STACK`, as
  `WAMR_BUILD` is the prefix for a command line option.
- Change `WAMR_ENABLE_COPY_CALLSTACK` to `WASM_ENABLE_COPY_CALL_STACK`, as
  `WASM_ENABLE` is the prefix for a macro in the source code.
- Change `CALLSTACK` to `CALL_STACK` to align with the existing
  `DUMP_CALL_STACK` feature.
- Continue using `WASMCApiFrame` instead of `wasm_frame_t` outside of
  *wasm_c_api.xxx* to avoid a typedef redefinition warning, which is
  identified by Clang.
liang.he 6 сар өмнө
parent
commit
e414a327a0

+ 2 - 2
CMakeLists.txt

@@ -99,9 +99,9 @@ if (NOT DEFINED WAMR_BUILD_LIB_WASI_THREADS)
   set (WAMR_BUILD_LIB_WASI_THREADS 0)
 endif ()
 
-if (NOT DEFINED WAMR_ENABLE_COPY_CALLSTACK)
+if (NOT DEFINED WAMR_BUILD_COPY_CALL_STACK)
   # Disable copy callstack by default
-  set (WAMR_ENABLE_COPY_CALLSTACK 0)
+  set (WAMR_BUILD_COPY_CALL_STACK 0)
 endif()
 
 if (NOT DEFINED WAMR_BUILD_MINI_LOADER)

+ 2 - 7
build-scripts/config_common.cmake

@@ -334,15 +334,10 @@ if (WAMR_BUILD_SHARED_HEAP EQUAL 1)
   add_definitions (-DWASM_ENABLE_SHARED_HEAP=1)
   message ("     Shared heap enabled")
 endif()
-
-if (WAMR_ENABLE_COPY_CALLSTACK EQUAL 1)
-  add_definitions (-DWAMR_ENABLE_COPY_CALLSTACK=1)
+if (WAMR_BUILD_COPY_CALL_STACK EQUAL 1)
+  add_definitions (-DWASM_ENABLE_COPY_CALL_STACK=1)
   message("     Copy callstack enabled")
-else ()
-  add_definitions (-DWAMR_ENABLE_COPY_CALLSTACK=0)
-  message("     Copy callstack disabled")
 endif()
-
 if (WAMR_BUILD_MEMORY64 EQUAL 1)
   # if native is 32-bit or cross-compiled to 32-bit
   if (NOT WAMR_BUILD_TARGET MATCHES ".*64.*")

+ 2 - 2
core/config.h

@@ -193,8 +193,8 @@
 #error "Heap aux stack allocation must be enabled for WASI threads"
 #endif
 
-#ifndef WAMR_ENABLE_COPY_CALLSTACK
-#define WAMR_ENABLE_COPY_CALLSTACK 0
+#ifndef WASM_ENABLE_COPY_CALL_STACK
+#define WASM_ENABLE_COPY_CALL_STACK 0
 #endif
 
 #ifndef WASM_ENABLE_BASE_LIB

+ 5 - 5
core/iwasm/aot/aot_runtime.c

@@ -4137,9 +4137,9 @@ aot_frame_update_profile_info(WASMExecEnv *exec_env, bool alloc_frame)
 }
 #endif /* end of WASM_ENABLE_AOT_STACK_FRAME != 0 */
 
-#if WAMR_ENABLE_COPY_CALLSTACK != 0
+#if WASM_ENABLE_COPY_CALL_STACK != 0
 uint32
-aot_copy_callstack_tiny_frame(WASMExecEnv *exec_env, wasm_frame_t *buffer,
+aot_copy_callstack_tiny_frame(WASMExecEnv *exec_env, WASMCApiFrame *buffer,
                               const uint32 length, const uint32 skip_n,
                               char *error_buf, uint32 error_buf_size)
 {
@@ -4193,7 +4193,7 @@ aot_copy_callstack_tiny_frame(WASMExecEnv *exec_env, wasm_frame_t *buffer,
 }
 
 uint32
-aot_copy_callstack_standard_frame(WASMExecEnv *exec_env, wasm_frame_t *buffer,
+aot_copy_callstack_standard_frame(WASMExecEnv *exec_env, WASMCApiFrame *buffer,
                                   const uint32 length, const uint32 skip_n,
                                   char *error_buf, uint32_t error_buf_size)
 {
@@ -4243,7 +4243,7 @@ aot_copy_callstack_standard_frame(WASMExecEnv *exec_env, wasm_frame_t *buffer,
 }
 
 uint32
-aot_copy_callstack(WASMExecEnv *exec_env, wasm_frame_t *buffer,
+aot_copy_callstack(WASMExecEnv *exec_env, WASMCApiFrame *buffer,
                    const uint32 length, const uint32 skip_n, char *error_buf,
                    uint32_t error_buf_size)
 {
@@ -4265,7 +4265,7 @@ aot_copy_callstack(WASMExecEnv *exec_env, wasm_frame_t *buffer,
                                              error_buf, error_buf_size);
     }
 }
-#endif // WAMR_ENABLE_COPY_CALLSTACK
+#endif // WASM_ENABLE_COPY_CALL_STACK
 
 #if WASM_ENABLE_DUMP_CALL_STACK != 0
 bool

+ 3 - 3
core/iwasm/aot/aot_runtime.h

@@ -787,12 +787,12 @@ aot_frame_update_profile_info(WASMExecEnv *exec_env, bool alloc_frame);
 bool
 aot_create_call_stack(struct WASMExecEnv *exec_env);
 
-#if WAMR_ENABLE_COPY_CALLSTACK != 0
+#if WASM_ENABLE_COPY_CALL_STACK != 0
 uint32
-aot_copy_callstack(WASMExecEnv *exec_env, wasm_frame_t *buffer,
+aot_copy_callstack(WASMExecEnv *exec_env, WASMCApiFrame *buffer,
                    const uint32 length, const uint32 skip_n, char *error_buf,
                    uint32_t error_buf_size);
-#endif // WAMR_ENABLE_COPY_CALLSTACK
+#endif // WASM_ENABLE_COPY_CALL_STACK
 
 /**
  * @brief Dump wasm call stack or get the size

+ 3 - 3
core/iwasm/common/wasm_runtime_common.c

@@ -1743,9 +1743,9 @@ wasm_runtime_destroy_exec_env(WASMExecEnv *exec_env)
     wasm_exec_env_destroy(exec_env);
 }
 
-#if WAMR_ENABLE_COPY_CALLSTACK != 0
+#if WASM_ENABLE_COPY_CALL_STACK != 0
 uint32
-wasm_copy_callstack(const wasm_exec_env_t exec_env, wasm_frame_t *buffer,
+wasm_copy_callstack(const wasm_exec_env_t exec_env, WASMCApiFrame *buffer,
                     const uint32 length, const uint32 skip_n, char *error_buf,
                     uint32_t error_buf_size)
 {
@@ -1780,7 +1780,7 @@ wasm_copy_callstack(const wasm_exec_env_t exec_env, wasm_frame_t *buffer,
     strncpy(error_buf, err_msg, error_buf_size);
     return 0;
 }
-#endif // WAMR_ENABLE_COPY_CALLSTACK
+#endif // WASM_ENABLE_COPY_CALL_STACK
 
 bool
 wasm_runtime_init_thread_env(void)

+ 3 - 3
core/iwasm/common/wasm_runtime_common.h

@@ -758,12 +758,12 @@ wasm_runtime_create_exec_env(WASMModuleInstanceCommon *module_inst,
 WASM_RUNTIME_API_EXTERN void
 wasm_runtime_destroy_exec_env(WASMExecEnv *exec_env);
 
-#if WAMR_ENABLE_COPY_CALLSTACK != 0
+#if WASM_ENABLE_COPY_CALL_STACK != 0
 WASM_RUNTIME_API_EXTERN uint32_t
-wasm_copy_callstack(const wasm_exec_env_t exec_env, wasm_frame_t *buffer,
+wasm_copy_callstack(const wasm_exec_env_t exec_env, WASMCApiFrame *buffer,
                     const uint32 length, const uint32 skip_n, char *error_buf,
                     uint32 error_buf_size);
-#endif // WAMR_ENABLE_COPY_CALLSTACK
+#endif // WASM_ENABLE_COPY_CALL_STACK
 
 /* See wasm_export.h for description */
 WASM_RUNTIME_API_EXTERN WASMModuleInstanceCommon *

+ 1 - 3
core/iwasm/include/wasm_export.h

@@ -139,8 +139,6 @@ typedef struct wasm_frame_t {
     uint32_t *lp;
 } WASMCApiFrame;
 
-typedef WASMCApiFrame wasm_frame_t;
-
 /* WASM section */
 typedef struct wasm_section_t {
     struct wasm_section_t *next;
@@ -904,7 +902,7 @@ wasm_runtime_destroy_exec_env(wasm_exec_env_t exec_env);
  * @return number of copied frames
  */
 WASM_RUNTIME_API_EXTERN uint32_t
-wasm_copy_callstack(const wasm_exec_env_t exec_env, wasm_frame_t *buffer,
+wasm_copy_callstack(const wasm_exec_env_t exec_env, WASMCApiFrame *buffer,
                     const uint32_t length, const uint32_t skip_n,
                     char *error_buf, uint32_t error_buf_size);
 

+ 3 - 3
core/iwasm/interpreter/wasm_runtime.c

@@ -4195,9 +4195,9 @@ wasm_get_module_inst_mem_consumption(const WASMModuleInstance *module_inst,
 #endif /* end of (WASM_ENABLE_MEMORY_PROFILING != 0) \
                  || (WASM_ENABLE_MEMORY_TRACING != 0) */
 
-#if WAMR_ENABLE_COPY_CALLSTACK != 0
+#if WASM_ENABLE_COPY_CALL_STACK != 0
 uint32
-wasm_interp_copy_callstack(WASMExecEnv *exec_env, wasm_frame_t *buffer,
+wasm_interp_copy_callstack(WASMExecEnv *exec_env, WASMCApiFrame *buffer,
                            uint32 length, uint32 skip_n, char *error_buf,
                            uint32_t error_buf_size)
 {
@@ -4242,7 +4242,7 @@ wasm_interp_copy_callstack(WASMExecEnv *exec_env, wasm_frame_t *buffer,
     }
     return count >= skip_n ? count - skip_n : 0;
 }
-#endif // WAMR_ENABLE_COPY_CALLSTACK
+#endif // WASM_ENABLE_COPY_CALL_STACK
 
 #if WASM_ENABLE_DUMP_CALL_STACK != 0
 bool

+ 3 - 3
core/iwasm/interpreter/wasm_runtime.h

@@ -731,12 +731,12 @@ wasm_get_table_inst(const WASMModuleInstance *module_inst, uint32 tbl_idx)
 
 #if WASM_ENABLE_DUMP_CALL_STACK != 0
 
-#if WAMR_ENABLE_COPY_CALLSTACK != 0
+#if WASM_ENABLE_COPY_CALL_STACK != 0
 uint32
-wasm_interp_copy_callstack(WASMExecEnv *exec_env, wasm_frame_t *buffer,
+wasm_interp_copy_callstack(WASMExecEnv *exec_env, WASMCApiFrame *buffer,
                            uint32 length, uint32 skip_n, char *error_buf,
                            uint32_t error_buf_size);
-#endif // WAMR_ENABLE_COPY_CALLSTACK
+#endif // WASM_ENABLE_COPY_CALL_STACK
 
 bool
 wasm_interp_create_call_stack(struct WASMExecEnv *exec_env);