Apply clang-format for interpreter source files (#772)

And update source debugging document.
This commit is contained in:
Wenyong Huang
2021-10-08 11:44:39 +08:00
committed by GitHub
parent 8d9bf18ac3
commit 6415e1b006
12 changed files with 9750 additions and 9224 deletions
-1
View File
@@ -57,7 +57,6 @@ extern "C" {
#define STORE_PTR(addr, ptr) do { \ #define STORE_PTR(addr, ptr) do { \
*(void**)addr = (void*)ptr; \ *(void**)addr = (void*)ptr; \
} while (0) } while (0)
#define LOAD_PTR(addr) (*(void**)(addr))
#else /* WASM_CPU_SUPPORTS_UNALIGNED_ADDR_ACCESS != 0 */ #else /* WASM_CPU_SUPPORTS_UNALIGNED_ADDR_ACCESS != 0 */
+12 -13
View File
@@ -24,7 +24,7 @@ extern "C" {
#define VALUE_TYPE_EXTERNREF 0x6F #define VALUE_TYPE_EXTERNREF 0x6F
#define VALUE_TYPE_VOID 0x40 #define VALUE_TYPE_VOID 0x40
/* Used by AOT */ /* Used by AOT */
#define VALUE_TYPE_I1 0x41 #define VALUE_TYPE_I1 0x41
/* Used by loader to represent any type of i32/i64/f32/f64 */ /* Used by loader to represent any type of i32/i64/f32/f64 */
#define VALUE_TYPE_ANY 0x42 #define VALUE_TYPE_ANY 0x42
@@ -66,8 +66,8 @@ extern "C" {
#endif #endif
#define SUB_SECTION_TYPE_MODULE 0 #define SUB_SECTION_TYPE_MODULE 0
#define SUB_SECTION_TYPE_FUNC 1 #define SUB_SECTION_TYPE_FUNC 1
#define SUB_SECTION_TYPE_LOCAL 2 #define SUB_SECTION_TYPE_LOCAL 2
#define IMPORT_KIND_FUNC 0 #define IMPORT_KIND_FUNC 0
#define IMPORT_KIND_TABLE 1 #define IMPORT_KIND_TABLE 1
@@ -449,7 +449,7 @@ typedef struct WASMBranchBlock {
* @return the aligned value * @return the aligned value
*/ */
inline static unsigned inline static unsigned
align_uint (unsigned v, unsigned b) align_uint(unsigned v, unsigned b)
{ {
unsigned m = b - 1; unsigned m = b - 1;
return (v + m) & ~m; return (v + m) & ~m;
@@ -462,7 +462,7 @@ inline static uint32
wasm_string_hash(const char *str) wasm_string_hash(const char *str)
{ {
unsigned h = (unsigned)strlen(str); unsigned h = (unsigned)strlen(str);
const uint8 *p = (uint8*)str; const uint8 *p = (uint8 *)str;
const uint8 *end = p + h; const uint8 *end = p + h;
while (p != end) while (p != end)
@@ -547,9 +547,10 @@ wasm_type_equal(const WASMType *type1, const WASMType *type2)
return (type1->param_count == type2->param_count return (type1->param_count == type2->param_count
&& type1->result_count == type2->result_count && type1->result_count == type2->result_count
&& memcmp(type1->types, type2->types, && memcmp(type1->types, type2->types,
(uint32)(type1->param_count (uint32)(type1->param_count + type1->result_count))
+ type1->result_count)) == 0) == 0)
? true : false; ? true
: false;
} }
inline static uint32 inline static uint32
@@ -566,8 +567,7 @@ wasm_get_smallest_type_idx(WASMType **types, uint32 type_count,
} }
static inline uint32 static inline uint32
block_type_get_param_types(BlockType *block_type, block_type_get_param_types(BlockType *block_type, uint8 **p_param_types)
uint8 **p_param_types)
{ {
uint32 param_count = 0; uint32 param_count = 0;
if (!block_type->is_value_type) { if (!block_type->is_value_type) {
@@ -577,15 +577,14 @@ block_type_get_param_types(BlockType *block_type,
} }
else { else {
*p_param_types = NULL; *p_param_types = NULL;
param_count = 0; param_count = 0;
} }
return param_count; return param_count;
} }
static inline uint32 static inline uint32
block_type_get_result_types(BlockType *block_type, block_type_get_result_types(BlockType *block_type, uint8 **p_result_types)
uint8 **p_result_types)
{ {
uint32 result_count = 0; uint32 result_count = 0;
if (block_type->is_value_type) { if (block_type->is_value_type) {
+31 -31
View File
@@ -17,43 +17,43 @@ struct WASMFunctionInstance;
struct WASMExecEnv; struct WASMExecEnv;
typedef struct WASMInterpFrame { typedef struct WASMInterpFrame {
/* The frame of the caller that are calling the current function. */ /* The frame of the caller that are calling the current function. */
struct WASMInterpFrame *prev_frame; struct WASMInterpFrame *prev_frame;
/* The current WASM function. */ /* The current WASM function. */
struct WASMFunctionInstance *function; struct WASMFunctionInstance *function;
/* Instruction pointer of the bytecode array. */ /* Instruction pointer of the bytecode array. */
uint8 *ip; uint8 *ip;
#if WASM_ENABLE_PERF_PROFILING != 0 #if WASM_ENABLE_PERF_PROFILING != 0
uint64 time_started; uint64 time_started;
#endif #endif
#if WASM_ENABLE_FAST_INTERP != 0 #if WASM_ENABLE_FAST_INTERP != 0
/* return offset of the first return value of current frame. /* Return offset of the first return value of current frame,
the callee will put return values here continuously */ the callee will put return values here continuously */
uint32 ret_offset; uint32 ret_offset;
uint32 *lp; uint32 *lp;
uint32 operand[1]; uint32 operand[1];
#else #else
/* Operand stack top pointer of the current frame. The bottom of /* Operand stack top pointer of the current frame. The bottom of
the stack is the next cell after the last local variable. */ the stack is the next cell after the last local variable. */
uint32 *sp_bottom; uint32 *sp_bottom;
uint32 *sp_boundary; uint32 *sp_boundary;
uint32 *sp; uint32 *sp;
WASMBranchBlock *csp_bottom; WASMBranchBlock *csp_bottom;
WASMBranchBlock *csp_boundary; WASMBranchBlock *csp_boundary;
WASMBranchBlock *csp; WASMBranchBlock *csp;
/* Frame data, the layout is: /* Frame data, the layout is:
lp: param_cell_count + local_cell_count lp: param_cell_count + local_cell_count
sp_bottom to sp_boundary: stack of data sp_bottom to sp_boundary: stack of data
csp_bottom to csp_boundary: stack of block csp_bottom to csp_boundary: stack of block
ref to frame end: data types of local vairables and stack data ref to frame end: data types of local vairables and stack data
*/ */
uint32 lp[1]; uint32 lp[1];
#endif #endif
} WASMInterpFrame; } WASMInterpFrame;
@@ -68,15 +68,15 @@ typedef struct WASMInterpFrame {
static inline unsigned static inline unsigned
wasm_interp_interp_frame_size(unsigned all_cell_num) wasm_interp_interp_frame_size(unsigned all_cell_num)
{ {
return align_uint((uint32)offsetof(WASMInterpFrame, lp) return align_uint((uint32)offsetof(WASMInterpFrame, lp) + all_cell_num * 5,
+ all_cell_num * 5, 4); 4);
} }
void void
wasm_interp_call_wasm(struct WASMModuleInstance *module_inst, wasm_interp_call_wasm(struct WASMModuleInstance *module_inst,
struct WASMExecEnv *exec_env, struct WASMExecEnv *exec_env,
struct WASMFunctionInstance *function, struct WASMFunctionInstance *function, uint32 argc,
uint32 argc, uint32 argv[]); uint32 argv[]);
#ifdef __cplusplus #ifdef __cplusplus
} }
File diff suppressed because it is too large Load Diff
File diff suppressed because it is too large Load Diff
File diff suppressed because it is too large Load Diff
+9 -11
View File
@@ -23,8 +23,9 @@ extern "C" {
* *
* @return return module loaded, NULL if failed * @return return module loaded, NULL if failed
*/ */
WASMModule* WASMModule *
wasm_loader_load(const uint8 *buf, uint32 size, char *error_buf, uint32 error_buf_size); wasm_loader_load(const uint8 *buf, uint32 size, char *error_buf,
uint32 error_buf_size);
/** /**
* Load a WASM module from a specified WASM section list. * Load a WASM module from a specified WASM section list.
@@ -35,9 +36,9 @@ wasm_loader_load(const uint8 *buf, uint32 size, char *error_buf, uint32 error_bu
* *
* @return return WASM module loaded, NULL if failed * @return return WASM module loaded, NULL if failed
*/ */
WASMModule* WASMModule *
wasm_loader_load_from_sections(WASMSection *section_list, wasm_loader_load_from_sections(WASMSection *section_list, char *error_buf,
char *error_buf, uint32 error_buf_size); uint32 error_buf_size);
/** /**
* Unload a WASM module. * Unload a WASM module.
@@ -64,12 +65,9 @@ wasm_loader_unload(WASMModule *module);
*/ */
bool bool
wasm_loader_find_block_addr(WASMExecEnv *exec_env, wasm_loader_find_block_addr(WASMExecEnv *exec_env, BlockAddr *block_addr_cache,
BlockAddr *block_addr_cache, const uint8 *start_addr, const uint8 *code_end_addr,
const uint8 *start_addr, uint8 block_type, uint8 **p_else_addr,
const uint8 *code_end_addr,
uint8 block_type,
uint8 **p_else_addr,
uint8 **p_end_addr); uint8 **p_end_addr);
#if WASM_ENABLE_REF_TYPES != 0 #if WASM_ENABLE_REF_TYPES != 0
File diff suppressed because it is too large Load Diff
File diff suppressed because it is too large Load Diff
File diff suppressed because it is too large Load Diff
+35 -48
View File
@@ -247,7 +247,7 @@ typedef struct WASMSubModInstNode {
* *
* @return the code block of the function * @return the code block of the function
*/ */
static inline uint8* static inline uint8 *
wasm_get_func_code(WASMFunctionInstance *func) wasm_get_func_code(WASMFunctionInstance *func)
{ {
#if WASM_ENABLE_FAST_INTERP == 0 #if WASM_ENABLE_FAST_INTERP == 0
@@ -264,34 +264,33 @@ wasm_get_func_code(WASMFunctionInstance *func)
* *
* @return the code block end of the function * @return the code block end of the function
*/ */
static inline uint8* static inline uint8 *
wasm_get_func_code_end(WASMFunctionInstance *func) wasm_get_func_code_end(WASMFunctionInstance *func)
{ {
#if WASM_ENABLE_FAST_INTERP == 0 #if WASM_ENABLE_FAST_INTERP == 0
return func->is_import_func return func->is_import_func ? NULL
? NULL : func->u.func->code + func->u.func->code_size; : func->u.func->code + func->u.func->code_size;
#else #else
return func->is_import_func return func->is_import_func
? NULL ? NULL
: func->u.func->code_compiled + func->u.func->code_compiled_size; : func->u.func->code_compiled + func->u.func->code_compiled_size;
#endif #endif
} }
WASMModule * WASMModule *
wasm_load(const uint8 *buf, uint32 size, wasm_load(const uint8 *buf, uint32 size, char *error_buf,
char *error_buf, uint32 error_buf_size); uint32 error_buf_size);
WASMModule * WASMModule *
wasm_load_from_sections(WASMSection *section_list, wasm_load_from_sections(WASMSection *section_list, char *error_buf,
char *error_buf, uint32_t error_buf_size); uint32_t error_buf_size);
void void
wasm_unload(WASMModule *module); wasm_unload(WASMModule *module);
WASMModuleInstance * WASMModuleInstance *
wasm_instantiate(WASMModule *module, bool is_sub_inst, wasm_instantiate(WASMModule *module, bool is_sub_inst, uint32 stack_size,
uint32 stack_size, uint32 heap_size, uint32 heap_size, char *error_buf, uint32 error_buf_size);
char *error_buf, uint32 error_buf_size);
void void
wasm_dump_perf_profiling(const WASMModuleInstance *module_inst); wasm_dump_perf_profiling(const WASMModuleInstance *module_inst);
@@ -300,8 +299,8 @@ void
wasm_deinstantiate(WASMModuleInstance *module_inst, bool is_sub_inst); wasm_deinstantiate(WASMModuleInstance *module_inst, bool is_sub_inst);
WASMFunctionInstance * WASMFunctionInstance *
wasm_lookup_function(const WASMModuleInstance *module_inst, wasm_lookup_function(const WASMModuleInstance *module_inst, const char *name,
const char *name, const char *signature); const char *signature);
#if WASM_ENABLE_MULTI_MODULE != 0 #if WASM_ENABLE_MULTI_MODULE != 0
WASMGlobalInstance * WASMGlobalInstance *
@@ -315,8 +314,7 @@ wasm_lookup_table(const WASMModuleInstance *module_inst, const char *name);
#endif #endif
bool bool
wasm_call_function(WASMExecEnv *exec_env, wasm_call_function(WASMExecEnv *exec_env, WASMFunctionInstance *function,
WASMFunctionInstance *function,
unsigned argc, uint32 argv[]); unsigned argc, uint32 argv[]);
bool bool
@@ -330,7 +328,7 @@ wasm_create_exec_env_singleton(WASMModuleInstance *module_inst);
void void
wasm_set_exception(WASMModuleInstance *module, const char *exception); wasm_set_exception(WASMModuleInstance *module, const char *exception);
const char* const char *
wasm_get_exception(WASMModuleInstance *module); wasm_get_exception(WASMModuleInstance *module);
uint32 uint32
@@ -345,38 +343,32 @@ void
wasm_module_free(WASMModuleInstance *module_inst, uint32 ptr); wasm_module_free(WASMModuleInstance *module_inst, uint32 ptr);
uint32 uint32
wasm_module_dup_data(WASMModuleInstance *module_inst, wasm_module_dup_data(WASMModuleInstance *module_inst, const char *src,
const char *src, uint32 size); uint32 size);
bool bool
wasm_validate_app_addr(WASMModuleInstance *module_inst, wasm_validate_app_addr(WASMModuleInstance *module_inst, uint32 app_offset,
uint32 app_offset, uint32 size); uint32 size);
bool bool
wasm_validate_app_str_addr(WASMModuleInstance *module_inst, wasm_validate_app_str_addr(WASMModuleInstance *module_inst, uint32 app_offset);
uint32 app_offset);
bool bool
wasm_validate_native_addr(WASMModuleInstance *module_inst, wasm_validate_native_addr(WASMModuleInstance *module_inst, void *native_ptr,
void *native_ptr, uint32 size); uint32 size);
void * void *
wasm_addr_app_to_native(WASMModuleInstance *module_inst, wasm_addr_app_to_native(WASMModuleInstance *module_inst, uint32 app_offset);
uint32 app_offset);
uint32 uint32
wasm_addr_native_to_app(WASMModuleInstance *module_inst, wasm_addr_native_to_app(WASMModuleInstance *module_inst, void *native_ptr);
void *native_ptr);
bool bool
wasm_get_app_addr_range(WASMModuleInstance *module_inst, wasm_get_app_addr_range(WASMModuleInstance *module_inst, uint32 app_offset,
uint32 app_offset, uint32 *p_app_start_offset, uint32 *p_app_end_offset);
uint32 *p_app_start_offset,
uint32 *p_app_end_offset);
bool bool
wasm_get_native_addr_range(WASMModuleInstance *module_inst, wasm_get_native_addr_range(WASMModuleInstance *module_inst, uint8_t *native_ptr,
uint8_t *native_ptr,
uint8_t **p_native_start_addr, uint8_t **p_native_start_addr,
uint8_t **p_native_end_addr); uint8_t **p_native_end_addr);
@@ -384,19 +376,15 @@ bool
wasm_enlarge_memory(WASMModuleInstance *module, uint32 inc_page_count); wasm_enlarge_memory(WASMModuleInstance *module, uint32 inc_page_count);
bool bool
wasm_call_indirect(WASMExecEnv *exec_env, wasm_call_indirect(WASMExecEnv *exec_env, uint32_t tbl_idx,
uint32_t tbl_idx, uint32_t element_indices, uint32_t argc, uint32_t argv[]);
uint32_t element_indices,
uint32_t argc, uint32_t argv[]);
#if WASM_ENABLE_THREAD_MGR != 0 #if WASM_ENABLE_THREAD_MGR != 0
bool bool
wasm_set_aux_stack(WASMExecEnv *exec_env, wasm_set_aux_stack(WASMExecEnv *exec_env, uint32 start_offset, uint32 size);
uint32 start_offset, uint32 size);
bool bool
wasm_get_aux_stack(WASMExecEnv *exec_env, wasm_get_aux_stack(WASMExecEnv *exec_env, uint32 *start_offset, uint32 *size);
uint32 *start_offset, uint32 *size);
#endif #endif
void void
@@ -427,13 +415,12 @@ wasm_elem_is_declarative(uint32 mode)
} }
bool bool
wasm_enlarge_table(WASMModuleInstance *module_inst, wasm_enlarge_table(WASMModuleInstance *module_inst, uint32 table_idx,
uint32 table_idx, uint32 inc_entries, uint32 init_val); uint32 inc_entries, uint32 init_val);
#endif /* WASM_ENABLE_REF_TYPES != 0 */ #endif /* WASM_ENABLE_REF_TYPES != 0 */
static inline WASMTableInstance * static inline WASMTableInstance *
wasm_get_table_inst(const WASMModuleInstance *module_inst, wasm_get_table_inst(const WASMModuleInstance *module_inst, const uint32 tbl_idx)
const uint32 tbl_idx)
{ {
/* careful, it might be a table in another module */ /* careful, it might be a table in another module */
WASMTableInstance *tbl_inst = module_inst->tables[tbl_idx]; WASMTableInstance *tbl_inst = module_inst->tables[tbl_idx];
+11 -7
View File
@@ -14,8 +14,12 @@ llvm-dwarfdump-12 test.wasm
``` ```
## Debugging with interpreter ## Debugging with interpreter
1. Install dependent libraries
``` bash
apt update && apt install cmake make g++ libxml2-dev -y
```
1. Build iwasm with source debugging feature 2. Build iwasm with source debugging feature
``` bash ``` bash
cd ${WAMR_ROOT}/product-mini/platforms/linux cd ${WAMR_ROOT}/product-mini/platforms/linux
mkdir build && cd build mkdir build && cd build
@@ -23,21 +27,21 @@ cmake .. -DWAMR_BUILD_DEBUG_INTERP=1
make make
``` ```
2. Execute iwasm with debug engine enabled 3. Execute iwasm with debug engine enabled
``` bash ``` bash
iwasm -g=127.0.0.1:1234 test.wasm iwasm -g=127.0.0.1:1234 test.wasm
``` ```
3. Build customized lldb (assume you have already built llvm) 4. Build customized lldb (assume you have already cloned llvm)
``` bash ``` bash
cd ${WAMR_ROOT}/core/deps/llvm cd ${WAMR_ROOT}/core/deps/llvm
git apply ../../../../build-scripts/lldb-wasm.patch git apply ../../../build-scripts/lldb-wasm.patch
mkdir build && cd build mkdir build_lldb && cd build_lldb
cmake ../llvm -DLLVM_ENABLE_PROJECTS="clang,lldb" -DLLVM_TARGETS_TO_BUILD:STRING="X86;WebAssembly" cmake -DCMAKE_BUILD_TYPE:STRING="Release" -DLLVM_ENABLE_PROJECTS="clang;lldb" -DLLVM_TARGETS_TO_BUILD:STRING="X86;WebAssembly" -DLLVM_ENABLE_LIBXML2:BOOL=ON ../llvm
make -j $(nproc) make -j $(nproc)
``` ```
4. Launch customized lldb and connect to iwasm 5. Launch customized lldb and connect to iwasm
``` bash ``` bash
lldb lldb
(lldb) process connect -p wasm connect://127.0.0.1:1234 (lldb) process connect -p wasm connect://127.0.0.1:1234