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
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
12 changed files with 9750 additions and 9224 deletions

View File

@ -57,7 +57,6 @@ extern "C" {
#define STORE_PTR(addr, ptr) do { \
*(void**)addr = (void*)ptr; \
} while (0)
#define LOAD_PTR(addr) (*(void**)(addr))
#else /* WASM_CPU_SUPPORTS_UNALIGNED_ADDR_ACCESS != 0 */

View File

@ -24,7 +24,7 @@ extern "C" {
#define VALUE_TYPE_EXTERNREF 0x6F
#define VALUE_TYPE_VOID 0x40
/* 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 */
#define VALUE_TYPE_ANY 0x42
@ -66,8 +66,8 @@ extern "C" {
#endif
#define SUB_SECTION_TYPE_MODULE 0
#define SUB_SECTION_TYPE_FUNC 1
#define SUB_SECTION_TYPE_LOCAL 2
#define SUB_SECTION_TYPE_FUNC 1
#define SUB_SECTION_TYPE_LOCAL 2
#define IMPORT_KIND_FUNC 0
#define IMPORT_KIND_TABLE 1
@ -449,7 +449,7 @@ typedef struct WASMBranchBlock {
* @return the aligned value
*/
inline static unsigned
align_uint (unsigned v, unsigned b)
align_uint(unsigned v, unsigned b)
{
unsigned m = b - 1;
return (v + m) & ~m;
@ -462,7 +462,7 @@ inline static uint32
wasm_string_hash(const char *str)
{
unsigned h = (unsigned)strlen(str);
const uint8 *p = (uint8*)str;
const uint8 *p = (uint8 *)str;
const uint8 *end = p + h;
while (p != end)
@ -547,9 +547,10 @@ wasm_type_equal(const WASMType *type1, const WASMType *type2)
return (type1->param_count == type2->param_count
&& type1->result_count == type2->result_count
&& memcmp(type1->types, type2->types,
(uint32)(type1->param_count
+ type1->result_count)) == 0)
? true : false;
(uint32)(type1->param_count + type1->result_count))
== 0)
? true
: false;
}
inline static uint32
@ -566,8 +567,7 @@ wasm_get_smallest_type_idx(WASMType **types, uint32 type_count,
}
static inline uint32
block_type_get_param_types(BlockType *block_type,
uint8 **p_param_types)
block_type_get_param_types(BlockType *block_type, uint8 **p_param_types)
{
uint32 param_count = 0;
if (!block_type->is_value_type) {
@ -577,15 +577,14 @@ block_type_get_param_types(BlockType *block_type,
}
else {
*p_param_types = NULL;
param_count = 0;
param_count = 0;
}
return param_count;
}
static inline uint32
block_type_get_result_types(BlockType *block_type,
uint8 **p_result_types)
block_type_get_result_types(BlockType *block_type, uint8 **p_result_types)
{
uint32 result_count = 0;
if (block_type->is_value_type) {

View File

@ -17,43 +17,43 @@ struct WASMFunctionInstance;
struct WASMExecEnv;
typedef struct WASMInterpFrame {
/* The frame of the caller that are calling the current function. */
struct WASMInterpFrame *prev_frame;
/* The frame of the caller that are calling the current function. */
struct WASMInterpFrame *prev_frame;
/* The current WASM function. */
struct WASMFunctionInstance *function;
/* The current WASM function. */
struct WASMFunctionInstance *function;
/* Instruction pointer of the bytecode array. */
uint8 *ip;
/* Instruction pointer of the bytecode array. */
uint8 *ip;
#if WASM_ENABLE_PERF_PROFILING != 0
uint64 time_started;
uint64 time_started;
#endif
#if WASM_ENABLE_FAST_INTERP != 0
/* return offset of the first return value of current frame.
the callee will put return values here continuously */
uint32 ret_offset;
uint32 *lp;
uint32 operand[1];
/* Return offset of the first return value of current frame,
the callee will put return values here continuously */
uint32 ret_offset;
uint32 *lp;
uint32 operand[1];
#else
/* Operand stack top pointer of the current frame. The bottom of
the stack is the next cell after the last local variable. */
uint32 *sp_bottom;
uint32 *sp_boundary;
uint32 *sp;
/* Operand stack top pointer of the current frame. The bottom of
the stack is the next cell after the last local variable. */
uint32 *sp_bottom;
uint32 *sp_boundary;
uint32 *sp;
WASMBranchBlock *csp_bottom;
WASMBranchBlock *csp_boundary;
WASMBranchBlock *csp;
WASMBranchBlock *csp_bottom;
WASMBranchBlock *csp_boundary;
WASMBranchBlock *csp;
/* Frame data, the layout is:
lp: param_cell_count + local_cell_count
sp_bottom to sp_boundary: stack of data
csp_bottom to csp_boundary: stack of block
ref to frame end: data types of local vairables and stack data
*/
uint32 lp[1];
/* Frame data, the layout is:
lp: param_cell_count + local_cell_count
sp_bottom to sp_boundary: stack of data
csp_bottom to csp_boundary: stack of block
ref to frame end: data types of local vairables and stack data
*/
uint32 lp[1];
#endif
} WASMInterpFrame;
@ -68,15 +68,15 @@ typedef struct WASMInterpFrame {
static inline unsigned
wasm_interp_interp_frame_size(unsigned all_cell_num)
{
return align_uint((uint32)offsetof(WASMInterpFrame, lp)
+ all_cell_num * 5, 4);
return align_uint((uint32)offsetof(WASMInterpFrame, lp) + all_cell_num * 5,
4);
}
void
wasm_interp_call_wasm(struct WASMModuleInstance *module_inst,
struct WASMExecEnv *exec_env,
struct WASMFunctionInstance *function,
uint32 argc, uint32 argv[]);
struct WASMFunctionInstance *function, uint32 argc,
uint32 argv[]);
#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

View File

@ -23,8 +23,9 @@ extern "C" {
*
* @return return module loaded, NULL if failed
*/
WASMModule*
wasm_loader_load(const uint8 *buf, uint32 size, char *error_buf, uint32 error_buf_size);
WASMModule *
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.
@ -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
*/
WASMModule*
wasm_loader_load_from_sections(WASMSection *section_list,
char *error_buf, uint32 error_buf_size);
WASMModule *
wasm_loader_load_from_sections(WASMSection *section_list, char *error_buf,
uint32 error_buf_size);
/**
* Unload a WASM module.
@ -64,12 +65,9 @@ wasm_loader_unload(WASMModule *module);
*/
bool
wasm_loader_find_block_addr(WASMExecEnv *exec_env,
BlockAddr *block_addr_cache,
const uint8 *start_addr,
const uint8 *code_end_addr,
uint8 block_type,
uint8 **p_else_addr,
wasm_loader_find_block_addr(WASMExecEnv *exec_env, BlockAddr *block_addr_cache,
const uint8 *start_addr, const uint8 *code_end_addr,
uint8 block_type, uint8 **p_else_addr,
uint8 **p_end_addr);
#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

View File

@ -247,7 +247,7 @@ typedef struct WASMSubModInstNode {
*
* @return the code block of the function
*/
static inline uint8*
static inline uint8 *
wasm_get_func_code(WASMFunctionInstance *func)
{
#if WASM_ENABLE_FAST_INTERP == 0
@ -264,34 +264,33 @@ wasm_get_func_code(WASMFunctionInstance *func)
*
* @return the code block end of the function
*/
static inline uint8*
static inline uint8 *
wasm_get_func_code_end(WASMFunctionInstance *func)
{
#if WASM_ENABLE_FAST_INTERP == 0
return func->is_import_func
? NULL : func->u.func->code + func->u.func->code_size;
return func->is_import_func ? NULL
: func->u.func->code + func->u.func->code_size;
#else
return func->is_import_func
? NULL
: func->u.func->code_compiled + func->u.func->code_compiled_size;
? NULL
: func->u.func->code_compiled + func->u.func->code_compiled_size;
#endif
}
WASMModule *
wasm_load(const uint8 *buf, uint32 size,
char *error_buf, uint32 error_buf_size);
wasm_load(const uint8 *buf, uint32 size, char *error_buf,
uint32 error_buf_size);
WASMModule *
wasm_load_from_sections(WASMSection *section_list,
char *error_buf, uint32_t error_buf_size);
wasm_load_from_sections(WASMSection *section_list, char *error_buf,
uint32_t error_buf_size);
void
wasm_unload(WASMModule *module);
WASMModuleInstance *
wasm_instantiate(WASMModule *module, bool is_sub_inst,
uint32 stack_size, uint32 heap_size,
char *error_buf, uint32 error_buf_size);
wasm_instantiate(WASMModule *module, bool is_sub_inst, uint32 stack_size,
uint32 heap_size, char *error_buf, uint32 error_buf_size);
void
wasm_dump_perf_profiling(const WASMModuleInstance *module_inst);
@ -300,8 +299,8 @@ void
wasm_deinstantiate(WASMModuleInstance *module_inst, bool is_sub_inst);
WASMFunctionInstance *
wasm_lookup_function(const WASMModuleInstance *module_inst,
const char *name, const char *signature);
wasm_lookup_function(const WASMModuleInstance *module_inst, const char *name,
const char *signature);
#if WASM_ENABLE_MULTI_MODULE != 0
WASMGlobalInstance *
@ -315,8 +314,7 @@ wasm_lookup_table(const WASMModuleInstance *module_inst, const char *name);
#endif
bool
wasm_call_function(WASMExecEnv *exec_env,
WASMFunctionInstance *function,
wasm_call_function(WASMExecEnv *exec_env, WASMFunctionInstance *function,
unsigned argc, uint32 argv[]);
bool
@ -330,7 +328,7 @@ wasm_create_exec_env_singleton(WASMModuleInstance *module_inst);
void
wasm_set_exception(WASMModuleInstance *module, const char *exception);
const char*
const char *
wasm_get_exception(WASMModuleInstance *module);
uint32
@ -345,38 +343,32 @@ void
wasm_module_free(WASMModuleInstance *module_inst, uint32 ptr);
uint32
wasm_module_dup_data(WASMModuleInstance *module_inst,
const char *src, uint32 size);
wasm_module_dup_data(WASMModuleInstance *module_inst, const char *src,
uint32 size);
bool
wasm_validate_app_addr(WASMModuleInstance *module_inst,
uint32 app_offset, uint32 size);
wasm_validate_app_addr(WASMModuleInstance *module_inst, uint32 app_offset,
uint32 size);
bool
wasm_validate_app_str_addr(WASMModuleInstance *module_inst,
uint32 app_offset);
wasm_validate_app_str_addr(WASMModuleInstance *module_inst, uint32 app_offset);
bool
wasm_validate_native_addr(WASMModuleInstance *module_inst,
void *native_ptr, uint32 size);
wasm_validate_native_addr(WASMModuleInstance *module_inst, void *native_ptr,
uint32 size);
void *
wasm_addr_app_to_native(WASMModuleInstance *module_inst,
uint32 app_offset);
wasm_addr_app_to_native(WASMModuleInstance *module_inst, uint32 app_offset);
uint32
wasm_addr_native_to_app(WASMModuleInstance *module_inst,
void *native_ptr);
wasm_addr_native_to_app(WASMModuleInstance *module_inst, void *native_ptr);
bool
wasm_get_app_addr_range(WASMModuleInstance *module_inst,
uint32 app_offset,
uint32 *p_app_start_offset,
uint32 *p_app_end_offset);
wasm_get_app_addr_range(WASMModuleInstance *module_inst, uint32 app_offset,
uint32 *p_app_start_offset, uint32 *p_app_end_offset);
bool
wasm_get_native_addr_range(WASMModuleInstance *module_inst,
uint8_t *native_ptr,
wasm_get_native_addr_range(WASMModuleInstance *module_inst, uint8_t *native_ptr,
uint8_t **p_native_start_addr,
uint8_t **p_native_end_addr);
@ -384,19 +376,15 @@ bool
wasm_enlarge_memory(WASMModuleInstance *module, uint32 inc_page_count);
bool
wasm_call_indirect(WASMExecEnv *exec_env,
uint32_t tbl_idx,
uint32_t element_indices,
uint32_t argc, uint32_t argv[]);
wasm_call_indirect(WASMExecEnv *exec_env, uint32_t tbl_idx,
uint32_t element_indices, uint32_t argc, uint32_t argv[]);
#if WASM_ENABLE_THREAD_MGR != 0
bool
wasm_set_aux_stack(WASMExecEnv *exec_env,
uint32 start_offset, uint32 size);
wasm_set_aux_stack(WASMExecEnv *exec_env, uint32 start_offset, uint32 size);
bool
wasm_get_aux_stack(WASMExecEnv *exec_env,
uint32 *start_offset, uint32 *size);
wasm_get_aux_stack(WASMExecEnv *exec_env, uint32 *start_offset, uint32 *size);
#endif
void
@ -427,13 +415,12 @@ wasm_elem_is_declarative(uint32 mode)
}
bool
wasm_enlarge_table(WASMModuleInstance *module_inst,
uint32 table_idx, uint32 inc_entries, uint32 init_val);
wasm_enlarge_table(WASMModuleInstance *module_inst, uint32 table_idx,
uint32 inc_entries, uint32 init_val);
#endif /* WASM_ENABLE_REF_TYPES != 0 */
static inline WASMTableInstance *
wasm_get_table_inst(const WASMModuleInstance *module_inst,
const uint32 tbl_idx)
wasm_get_table_inst(const WASMModuleInstance *module_inst, const uint32 tbl_idx)
{
/* careful, it might be a table in another module */
WASMTableInstance *tbl_inst = module_inst->tables[tbl_idx];

View File

@ -14,8 +14,12 @@ llvm-dwarfdump-12 test.wasm
```
## 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
cd ${WAMR_ROOT}/product-mini/platforms/linux
mkdir build && cd build
@ -23,21 +27,21 @@ cmake .. -DWAMR_BUILD_DEBUG_INTERP=1
make
```
2. Execute iwasm with debug engine enabled
3. Execute iwasm with debug engine enabled
``` bash
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
cd ${WAMR_ROOT}/core/deps/llvm
git apply ../../../../build-scripts/lldb-wasm.patch
mkdir build && cd build
cmake ../llvm -DLLVM_ENABLE_PROJECTS="clang,lldb" -DLLVM_TARGETS_TO_BUILD:STRING="X86;WebAssembly"
git apply ../../../build-scripts/lldb-wasm.patch
mkdir build_lldb && cd build_lldb
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)
```
4. Launch customized lldb and connect to iwasm
5. Launch customized lldb and connect to iwasm
``` bash
lldb
(lldb) process connect -p wasm connect://127.0.0.1:1234