Apply clang-format for core/iwasm compilation and libraries (#784)

Apply clang-format for core/iwasm/compilation and core/iwasm/libraries files.
Add wasm-c-api empty_imports sample to workflow test.
And enable triggering workflow when core/config.h changes.
This commit is contained in:
Wenyong Huang
2021-10-13 15:13:00 +08:00
committed by GitHub
parent dc65d2910a
commit fb4afc7ca4
87 changed files with 9321 additions and 9829 deletions

View File

@ -59,14 +59,13 @@ control_thread_routine(void *arg)
control_thread->debug_engine = g_debug_engine;
control_thread->debug_instance = debug_inst;
strcpy(control_thread->ip_addr, g_debug_engine->ip_addr);
control_thread->port =
g_debug_engine->process_base_port + debug_inst->id;
control_thread->port = g_debug_engine->process_base_port + debug_inst->id;
LOG_WARNING("control thread of debug object %p start at %s:%d\n",
debug_inst, control_thread->ip_addr, control_thread->port);
control_thread->server =
wasm_launch_gdbserver(control_thread->ip_addr, control_thread->port);
wasm_launch_gdbserver(control_thread->ip_addr, control_thread->port);
if (!control_thread->server) {
LOG_ERROR("Failed to create debug server\n");
os_cond_signal(&exec_env->wait_cond);
@ -110,7 +109,7 @@ wasm_debug_control_thread_create(WASMDebugInstance *debug_instance)
bh_assert(exec_env);
if (!(control_thread =
wasm_runtime_malloc(sizeof(WASMDebugControlThread)))) {
wasm_runtime_malloc(sizeof(WASMDebugControlThread)))) {
LOG_ERROR("WASM Debug Engine error: failed to allocate memory");
return NULL;
}
@ -123,8 +122,9 @@ wasm_debug_control_thread_create(WASMDebugInstance *debug_instance)
os_mutex_lock(&exec_env->wait_lock);
if (0 != os_thread_create(&control_thread->tid, control_thread_routine,
debug_instance, APP_THREAD_STACK_SIZE_MAX)) {
if (0
!= os_thread_create(&control_thread->tid, control_thread_routine,
debug_instance, APP_THREAD_STACK_SIZE_MAX)) {
os_mutex_unlock(&control_thread->wait_lock);
goto fail1;
}
@ -153,8 +153,7 @@ wasm_debug_control_thread_destroy(WASMDebugInstance *debug_instance)
{
WASMDebugControlThread *control_thread = debug_instance->control_thread;
LOG_VERBOSE("control thread of debug object %p stop at %s:%d\n",
debug_instance, control_thread->ip_addr,
control_thread->port);
debug_instance, control_thread->ip_addr, control_thread->port);
control_thread->status = STOPPED;
os_mutex_lock(&control_thread->wait_lock);
wasm_close_gdbserver(control_thread->server);
@ -200,9 +199,9 @@ wasm_debug_engine_init(char *ip_addr, int platform_port, int process_port)
if (g_debug_engine) {
process_port -= 1;
g_debug_engine->platform_port =
platform_port > 0 ? platform_port : 1234;
platform_port > 0 ? platform_port : 1234;
g_debug_engine->process_base_port =
process_port > 0 ? process_port : 6169;
process_port > 0 ? process_port : 6169;
if (ip_addr)
sprintf(g_debug_engine->ip_addr, "%s", ip_addr);
else
@ -277,7 +276,7 @@ static WASMDebugInstance *
wasm_cluster_get_debug_instance(WASMDebugEngine *engine, WASMCluster *cluster)
{
WASMDebugInstance *instance =
bh_list_first_elem(&engine->debug_instance_list);
bh_list_first_elem(&engine->debug_instance_list);
while (instance) {
if (instance->cluster == cluster)
return instance;
@ -343,8 +342,7 @@ wasm_debug_instance_get_current_env(WASMDebugInstance *instance)
#if WASM_ENABLE_LIBC_WASI != 0
bool
wasm_debug_instance_get_current_object_name(WASMDebugInstance *instance,
char name_buffer[],
int len)
char name_buffer[], int len)
{
WASMExecEnv *exec_env;
WASIArguments *wasi_args;
@ -392,8 +390,8 @@ wasm_debug_instance_get_tid(WASMDebugInstance *instance)
}
int
wasm_debug_instance_get_tids(WASMDebugInstance *instance,
uint64 tids[], int len)
wasm_debug_instance_get_tids(WASMDebugInstance *instance, uint64 tids[],
int len)
{
WASMExecEnv *exec_env;
int i = 0;
@ -411,8 +409,8 @@ wasm_debug_instance_get_tids(WASMDebugInstance *instance,
}
uint64
wasm_debug_instance_wait_thread(WASMDebugInstance *instance,
uint64 tid, uint32 *status)
wasm_debug_instance_wait_thread(WASMDebugInstance *instance, uint64 tid,
uint32 *status)
{
WASMExecEnv *exec_env;
WASMExecEnv *last_exec_env = NULL;
@ -454,13 +452,12 @@ wasm_debug_instance_get_pc(WASMDebugInstance *instance)
return 0;
exec_env = wasm_debug_instance_get_current_env(instance);
if ((exec_env->cur_frame != NULL)
&& (exec_env->cur_frame->ip != NULL)) {
if ((exec_env->cur_frame != NULL) && (exec_env->cur_frame->ip != NULL)) {
WASMModuleInstance *module_inst =
(WASMModuleInstance *)exec_env->module_inst;
(WASMModuleInstance *)exec_env->module_inst;
return WASM_ADDR(
WasmObj, instance->id,
(exec_env->cur_frame->ip - module_inst->module->load_addr));
WasmObj, instance->id,
(exec_env->cur_frame->ip - module_inst->module->load_addr));
}
return 0;
}
@ -519,7 +516,8 @@ wasm_debug_instance_get_memregion(WASMDebugInstance *instance, uint64 addr)
sprintf(mem_info->permisson, "%s", "rx");
}
break;
case WasmMemory: {
case WasmMemory:
{
memory = module_inst->default_memory;
if (memory) {
@ -549,8 +547,8 @@ wasm_debug_instance_destroy_memregion(WASMDebugInstance *instance,
}
bool
wasm_debug_instance_get_obj_mem(WASMDebugInstance *instance,
uint64 offset, char *buf, uint64 *size)
wasm_debug_instance_get_obj_mem(WASMDebugInstance *instance, uint64 offset,
char *buf, uint64 *size)
{
WASMExecEnv *exec_env;
WASMModuleInstance *module_inst;
@ -567,14 +565,14 @@ wasm_debug_instance_get_obj_mem(WASMDebugInstance *instance,
if (offset + *size > module_inst->module->load_size) {
LOG_VERBOSE("wasm_debug_instance_get_data_mem size over flow!\n");
*size = module_inst->module->load_size >= offset
? module_inst->module->load_size - offset
: 0;
? module_inst->module->load_size - offset
: 0;
}
bh_memcpy_s(buf, *size, module_inst->module->load_addr + offset, *size);
WASMDebugBreakPoint *breakpoint =
bh_list_first_elem(&instance->break_point_list);
bh_list_first_elem(&instance->break_point_list);
while (breakpoint) {
if (offset <= breakpoint->addr && breakpoint->addr < offset + *size) {
@ -585,12 +583,12 @@ wasm_debug_instance_get_obj_mem(WASMDebugInstance *instance,
}
WASMFastOPCodeNode *fast_opcode =
bh_list_first_elem(&module_inst->module->fast_opcode_list);
bh_list_first_elem(&module_inst->module->fast_opcode_list);
while (fast_opcode) {
if (offset <= fast_opcode->offset
&& fast_opcode->offset < offset + *size) {
*(uint8 *)(buf + (fast_opcode->offset - offset)) =
fast_opcode->orig_op;
fast_opcode->orig_op;
}
fast_opcode = bh_list_elem_next(fast_opcode);
}
@ -599,8 +597,8 @@ wasm_debug_instance_get_obj_mem(WASMDebugInstance *instance,
}
bool
wasm_debug_instance_get_linear_mem(WASMDebugInstance *instance,
uint64 offset, char *buf, uint64 *size)
wasm_debug_instance_get_linear_mem(WASMDebugInstance *instance, uint64 offset,
char *buf, uint64 *size)
{
WASMExecEnv *exec_env;
WASMModuleInstance *module_inst;
@ -621,8 +619,7 @@ wasm_debug_instance_get_linear_mem(WASMDebugInstance *instance,
num_bytes_per_page = memory->num_bytes_per_page;
linear_mem_size = num_bytes_per_page * memory->cur_page_count;
if (offset + *size > linear_mem_size) {
LOG_VERBOSE(
"wasm_debug_instance_get_linear_mem size over flow!\n");
LOG_VERBOSE("wasm_debug_instance_get_linear_mem size over flow!\n");
*size = linear_mem_size >= offset ? linear_mem_size - offset : 0;
}
bh_memcpy_s(buf, *size, memory->memory_data + offset, *size);
@ -632,8 +629,8 @@ wasm_debug_instance_get_linear_mem(WASMDebugInstance *instance,
}
bool
wasm_debug_instance_set_linear_mem(WASMDebugInstance *instance,
uint64 offset, char *buf, uint64 *size)
wasm_debug_instance_set_linear_mem(WASMDebugInstance *instance, uint64 offset,
char *buf, uint64 *size)
{
WASMExecEnv *exec_env;
WASMModuleInstance *module_inst;
@ -654,8 +651,7 @@ wasm_debug_instance_set_linear_mem(WASMDebugInstance *instance,
num_bytes_per_page = memory->num_bytes_per_page;
linear_mem_size = num_bytes_per_page * memory->cur_page_count;
if (offset + *size > linear_mem_size) {
LOG_VERBOSE(
"wasm_debug_instance_get_linear_mem size over flow!\n");
LOG_VERBOSE("wasm_debug_instance_get_linear_mem size over flow!\n");
*size = linear_mem_size >= offset ? linear_mem_size - offset : 0;
}
bh_memcpy_s(memory->memory_data + offset, *size, buf, *size);
@ -665,17 +661,17 @@ wasm_debug_instance_set_linear_mem(WASMDebugInstance *instance,
}
bool
wasm_debug_instance_get_mem(WASMDebugInstance *instance,
uint64 addr, char *buf, uint64 *size)
wasm_debug_instance_get_mem(WASMDebugInstance *instance, uint64 addr, char *buf,
uint64 *size)
{
switch (WASM_ADDR_TYPE(addr)) {
case WasmMemory:
return wasm_debug_instance_get_linear_mem(
instance, WASM_ADDR_OFFSET(addr), buf, size);
instance, WASM_ADDR_OFFSET(addr), buf, size);
break;
case WasmObj:
return wasm_debug_instance_get_obj_mem(
instance, WASM_ADDR_OFFSET(addr), buf, size);
instance, WASM_ADDR_OFFSET(addr), buf, size);
break;
default:
return false;
@ -683,13 +679,13 @@ wasm_debug_instance_get_mem(WASMDebugInstance *instance,
}
bool
wasm_debug_instance_set_mem(WASMDebugInstance *instance,
uint64 addr, char *buf, uint64 *size)
wasm_debug_instance_set_mem(WASMDebugInstance *instance, uint64 addr, char *buf,
uint64 *size)
{
switch (WASM_ADDR_TYPE(addr)) {
case WasmMemory:
return wasm_debug_instance_set_linear_mem(
instance, WASM_ADDR_OFFSET(addr), buf, size);
instance, WASM_ADDR_OFFSET(addr), buf, size);
break;
case WasmObj:
default:
@ -713,8 +709,8 @@ wasm_exec_env_get_instance(WASMExecEnv *exec_env)
}
int
wasm_debug_instance_get_call_stack_pcs(WASMDebugInstance *instance,
uint64 tid, uint64 buf[], uint64 size)
wasm_debug_instance_get_call_stack_pcs(WASMDebugInstance *instance, uint64 tid,
uint64 buf[], uint64 size)
{
WASMExecEnv *exec_env;
struct WASMInterpFrame *frame;
@ -727,13 +723,13 @@ wasm_debug_instance_get_call_stack_pcs(WASMDebugInstance *instance,
while (exec_env) {
if (exec_env->handle == tid) {
WASMModuleInstance *module_inst =
(WASMModuleInstance *)exec_env->module_inst;
(WASMModuleInstance *)exec_env->module_inst;
frame = exec_env->cur_frame;
while (frame && i < size) {
if (frame->ip != NULL) {
buf[i++] =
WASM_ADDR(WasmObj, instance->id,
(frame->ip - module_inst->module->load_addr));
WASM_ADDR(WasmObj, instance->id,
(frame->ip - module_inst->module->load_addr));
}
frame = frame->prev_frame;
}
@ -745,8 +741,8 @@ wasm_debug_instance_get_call_stack_pcs(WASMDebugInstance *instance,
}
bool
wasm_debug_instance_add_breakpoint(WASMDebugInstance *instance,
uint64 addr, uint64 length)
wasm_debug_instance_add_breakpoint(WASMDebugInstance *instance, uint64 addr,
uint64 length)
{
WASMExecEnv *exec_env;
WASMModuleInstance *module_inst;
@ -769,23 +765,20 @@ wasm_debug_instance_add_breakpoint(WASMDebugInstance *instance,
if (offset + sizeof(break_instr) <= module_inst->module->load_size) {
WASMDebugBreakPoint *breakpoint;
if (!(breakpoint =
wasm_runtime_malloc(sizeof(WASMDebugBreakPoint)))) {
LOG_ERROR(
"WASM Debug Engine error: failed to allocate memory");
wasm_runtime_malloc(sizeof(WASMDebugBreakPoint)))) {
LOG_ERROR("WASM Debug Engine error: failed to allocate memory");
return false;
}
memset(breakpoint, 0, sizeof(WASMDebugBreakPoint));
breakpoint->addr = offset;
/* TODO: how to if more than one breakpoints are set
at the same addr? */
bh_memcpy_s(&breakpoint->orignal_data,
(uint32)sizeof(break_instr),
bh_memcpy_s(&breakpoint->orignal_data, (uint32)sizeof(break_instr),
module_inst->module->load_addr + offset,
(uint32)sizeof(break_instr));
bh_memcpy_s(module_inst->module->load_addr + offset,
(uint32)sizeof(break_instr),
break_instr,
(uint32)sizeof(break_instr), break_instr,
(uint32)sizeof(break_instr));
bh_list_insert(&instance->break_point_list, breakpoint);
@ -796,8 +789,8 @@ wasm_debug_instance_add_breakpoint(WASMDebugInstance *instance,
}
bool
wasm_debug_instance_remove_breakpoint(WASMDebugInstance *instance,
uint64 addr, uint64 length)
wasm_debug_instance_remove_breakpoint(WASMDebugInstance *instance, uint64 addr,
uint64 length)
{
WASMExecEnv *exec_env;
WASMModuleInstance *module_inst;
@ -819,10 +812,9 @@ wasm_debug_instance_remove_breakpoint(WASMDebugInstance *instance,
if (length >= sizeof(break_instr)) {
if (offset + sizeof(break_instr) <= module_inst->module->load_size) {
WASMDebugBreakPoint *breakpoint =
bh_list_first_elem(&instance->break_point_list);
bh_list_first_elem(&instance->break_point_list);
while (breakpoint) {
WASMDebugBreakPoint *next_break =
bh_list_elem_next(breakpoint);
WASMDebugBreakPoint *next_break = bh_list_elem_next(breakpoint);
if (breakpoint->addr == offset) {
/* TODO: how to if more than one breakpoints are set
at the same addr? */
@ -901,9 +893,8 @@ wasm_debug_instance_singlestep(WASMDebugInstance *instance, uint64 tid)
}
bool
wasm_debug_instance_get_local(WASMDebugInstance *instance,
int frame_index, int local_index,
char buf[], int *size)
wasm_debug_instance_get_local(WASMDebugInstance *instance, int frame_index,
int local_index, char buf[], int *size)
{
WASMExecEnv *exec_env;
struct WASMInterpFrame *frame;
@ -961,9 +952,8 @@ wasm_debug_instance_get_local(WASMDebugInstance *instance,
}
bool
wasm_debug_instance_get_global(WASMDebugInstance *instance,
int frame_index, int global_index,
char buf[], int *size)
wasm_debug_instance_get_global(WASMDebugInstance *instance, int frame_index,
int global_index, char buf[], int *size)
{
WASMExecEnv *exec_env;
struct WASMInterpFrame *frame;
@ -1003,9 +993,9 @@ wasm_debug_instance_get_global(WASMDebugInstance *instance,
global_addr = global_data + global->data_offset;
#else
global_addr = global->import_global_inst
? global->import_module_inst->global_data
+ global->import_global_inst->data_offset
: global_data + global->data_offset;
? global->import_module_inst->global_data
+ global->import_global_inst->data_offset
: global_data + global->data_offset;
#endif
global_type = global->type;
@ -1028,8 +1018,7 @@ wasm_debug_instance_get_global(WASMDebugInstance *instance,
}
uint64
wasm_debug_instance_mmap(WASMDebugInstance *instance,
uint32 size, int map_port)
wasm_debug_instance_mmap(WASMDebugInstance *instance, uint32 size, int map_port)
{
WASMExecEnv *exec_env;
WASMModuleInstance *module_inst;

View File

@ -67,10 +67,10 @@ typedef enum WasmAddressType {
WasmInvalid = 0x03
} WasmAddressType;
#define WASM_ADDR(type, id, offset) \
#define WASM_ADDR(type, id, offset) \
(((uint64)type << 62) | ((uint64)0 << 32) | ((uint64)offset << 0))
#define WASM_ADDR_TYPE(addr) (((addr)&0xC000000000000000) >> 62)
#define WASM_ADDR_TYPE(addr) (((addr)&0xC000000000000000) >> 62)
#define WASM_ADDR_OFFSET(addr) (((addr)&0x00000000FFFFFFFF))
#define INVALIED_ADDR (0xFFFFFFFFFFFFFFFF)
@ -96,7 +96,6 @@ wasm_debug_set_engine_active(bool active);
bool
wasm_debug_get_engine_active(void);
uint64
wasm_debug_instance_get_pid(WASMDebugInstance *instance);
@ -104,8 +103,8 @@ uint64
wasm_debug_instance_get_tid(WASMDebugInstance *instance);
int
wasm_debug_instance_get_tids(WASMDebugInstance *instance,
uint64 tids[], int len);
wasm_debug_instance_get_tids(WASMDebugInstance *instance, uint64 tids[],
int len);
void
wasm_debug_instance_set_cur_thread(WASMDebugInstance *instance, uint64 tid);
@ -124,32 +123,32 @@ wasm_debug_instance_destroy_memregion(WASMDebugInstance *instance,
WASMDebugMemoryInfo *mem_info);
bool
wasm_debug_instance_get_obj_mem(WASMDebugInstance *instance,
uint64 addr, char *buf, uint64 *size);
wasm_debug_instance_get_obj_mem(WASMDebugInstance *instance, uint64 addr,
char *buf, uint64 *size);
bool
wasm_debug_instance_get_linear_mem(WASMDebugInstance *instance,
uint64 addr, char *buf, uint64 *size);
wasm_debug_instance_get_linear_mem(WASMDebugInstance *instance, uint64 addr,
char *buf, uint64 *size);
bool
wasm_debug_instance_get_mem(WASMDebugInstance *instance,
uint64 addr, char *buf, uint64 *size);
wasm_debug_instance_get_mem(WASMDebugInstance *instance, uint64 addr, char *buf,
uint64 *size);
bool
wasm_debug_instance_set_mem(WASMDebugInstance *instance,
uint64 addr, char *buf, uint64 *size);
wasm_debug_instance_set_mem(WASMDebugInstance *instance, uint64 addr, char *buf,
uint64 *size);
int
wasm_debug_instance_get_call_stack_pcs(WASMDebugInstance *instance,
uint64 tid, uint64 buf[], uint64 size);
wasm_debug_instance_get_call_stack_pcs(WASMDebugInstance *instance, uint64 tid,
uint64 buf[], uint64 size);
bool
wasm_debug_instance_add_breakpoint(WASMDebugInstance *instance,
uint64 addr, uint64 length);
wasm_debug_instance_add_breakpoint(WASMDebugInstance *instance, uint64 addr,
uint64 length);
bool
wasm_debug_instance_remove_breakpoint(WASMDebugInstance *instance,
uint64 addr, uint64 length);
wasm_debug_instance_remove_breakpoint(WASMDebugInstance *instance, uint64 addr,
uint64 length);
bool
wasm_debug_instance_continue(WASMDebugInstance *instance);
@ -158,21 +157,19 @@ bool
wasm_debug_instance_kill(WASMDebugInstance *instance);
uint64
wasm_debug_instance_wait_thread(WASMDebugInstance *instance,
uint64 tid, uint32 *status);
wasm_debug_instance_wait_thread(WASMDebugInstance *instance, uint64 tid,
uint32 *status);
bool
wasm_debug_instance_singlestep(WASMDebugInstance *instance, uint64 tid);
bool
wasm_debug_instance_get_local(WASMDebugInstance *instance,
int frame_index, int local_index,
char buf[], int *size);
wasm_debug_instance_get_local(WASMDebugInstance *instance, int frame_index,
int local_index, char buf[], int *size);
bool
wasm_debug_instance_get_global(WASMDebugInstance *instance,
int frame_index, int global_index,
char buf[], int *size);
wasm_debug_instance_get_global(WASMDebugInstance *instance, int frame_index,
int global_index, char buf[], int *size);
#if WASM_ENABLE_LIBC_WASI != 0
bool
@ -181,8 +178,8 @@ wasm_debug_instance_get_current_object_name(WASMDebugInstance *instance,
#endif
uint64
wasm_debug_instance_mmap(WASMDebugInstance *instance,
uint32 size, int map_port);
wasm_debug_instance_mmap(WASMDebugInstance *instance, uint32 size,
int map_port);
bool
wasm_debug_instance_ummap(WASMDebugInstance *instance, uint64 addr);

View File

@ -75,8 +75,9 @@ wasm_launch_gdbserver(char *host, int port)
}
ret = fcntl(listen_fd, F_SETFD, FD_CLOEXEC);
if(ret < 0) {
LOG_ERROR("wasm gdb server error: fcntl() failed on setting FD_CLOEXEC");
if (ret < 0) {
LOG_ERROR(
"wasm gdb server error: fcntl() failed on setting FD_CLOEXEC");
goto fail;
}

View File

@ -55,13 +55,13 @@ process_xfer(WASMGDBServer *server, const char *name, char *args)
*args++ = '\0';
if (!strcmp(name, "libraries") && !strcmp(mode, "read")) {
//TODO: how to get current wasm file name?
// TODO: how to get current wasm file name?
uint64_t addr = wasm_debug_instance_get_load_addr(
(WASMDebugInstance *)server->thread->debug_instance);
(WASMDebugInstance *)server->thread->debug_instance);
#if WASM_ENABLE_LIBC_WASI != 0
char objname[128];
wasm_debug_instance_get_current_object_name(
(WASMDebugInstance *)server->thread->debug_instance, objname, 128);
(WASMDebugInstance *)server->thread->debug_instance, objname, 128);
sprintf(tmpbuf,
"l<library-list><library name=\"%s\"><section "
"address=\"0x%lx\"/></library></library-list>",
@ -88,8 +88,8 @@ porcess_wasm_local(WASMGDBServer *server, char *args)
sprintf(tmpbuf, "E01");
if (sscanf(args, "%d;%d", &frame_index, &local_index) == 2) {
ret = wasm_debug_instance_get_local(
(WASMDebugInstance *)server->thread->debug_instance, frame_index,
local_index, buf, &size);
(WASMDebugInstance *)server->thread->debug_instance, frame_index,
local_index, buf, &size);
if (ret && size > 0) {
mem2hex(buf, tmpbuf, size);
}
@ -109,8 +109,8 @@ porcess_wasm_global(WASMGDBServer *server, char *args)
sprintf(tmpbuf, "E01");
if (sscanf(args, "%d;%d", &frame_index, &global_index) == 2) {
ret = wasm_debug_instance_get_global(
(WASMDebugInstance *)server->thread->debug_instance, frame_index,
global_index, buf, &size);
(WASMDebugInstance *)server->thread->debug_instance, frame_index,
global_index, buf, &size);
if (ret && size > 0) {
mem2hex(buf, tmpbuf, size);
}
@ -133,14 +133,15 @@ handle_generay_query(WASMGDBServer *server, char *payload)
if (!strcmp(name, "C")) {
uint64_t pid, tid;
pid = wasm_debug_instance_get_pid(
(WASMDebugInstance *)server->thread->debug_instance);
(WASMDebugInstance *)server->thread->debug_instance);
tid = wasm_debug_instance_get_tid(
(WASMDebugInstance *)server->thread->debug_instance);
(WASMDebugInstance *)server->thread->debug_instance);
snprintf(tmpbuf, sizeof(tmpbuf), "QCp%lx.%lx", pid, tid);
write_packet(server, tmpbuf);
}
if (!strcmp(name, "Supported")) {
sprintf(tmpbuf, "qXfer:libraries:read+;PacketSize=%x;", MAX_PACKET_SIZE);
sprintf(tmpbuf, "qXfer:libraries:read+;PacketSize=%x;",
MAX_PACKET_SIZE);
write_packet(server, tmpbuf);
}
@ -161,10 +162,9 @@ handle_generay_query(WASMGDBServer *server, char *payload)
}
if (!strcmp(name, "HostInfo")) {
//Todo: change vendor to Intel for outside tree
// Todo: change vendor to Intel for outside tree
char triple[256];
mem2hex("wasm32-Ant-wasi-wasm", triple,
strlen("wasm32-Ant-wasi-wasm"));
mem2hex("wasm32-Ant-wasi-wasm", triple, strlen("wasm32-Ant-wasi-wasm"));
sprintf(tmpbuf,
"vendor:Ant;ostype:wasi;arch:wasm32;"
"triple:%s;endian:little;ptrsize:4;",
@ -183,14 +183,13 @@ handle_generay_query(WASMGDBServer *server, char *payload)
write_packet(server, "");
}
if (!strcmp(name, "ProcessInfo")) {
//Todo: process id parent-pid
// Todo: process id parent-pid
uint64_t pid;
pid = wasm_debug_instance_get_pid(
(WASMDebugInstance *)server->thread->debug_instance);
(WASMDebugInstance *)server->thread->debug_instance);
char triple[256];
//arch-vendor-os-env(format)
mem2hex("wasm32-Ant-wasi-wasm", triple,
strlen("wasm32-Ant-wasi-wasm"));
// arch-vendor-os-env(format)
mem2hex("wasm32-Ant-wasi-wasm", triple, strlen("wasm32-Ant-wasi-wasm"));
sprintf(tmpbuf,
"pid:%lx;parent-pid:%lx;vendor:Ant;ostype:wasi;arch:wasm32;"
"triple:%s;endian:little;ptrsize:4;",
@ -200,9 +199,9 @@ handle_generay_query(WASMGDBServer *server, char *payload)
}
if (!strcmp(name, "RegisterInfo0")) {
sprintf(
tmpbuf,
"name:pc;alt-name:pc;bitsize:64;offset:0;encoding:uint;format:hex;"
"set:General Purpose Registers;gcc:16;dwarf:16;generic:pc;");
tmpbuf,
"name:pc;alt-name:pc;bitsize:64;offset:0;encoding:uint;format:hex;"
"set:General Purpose Registers;gcc:16;dwarf:16;generic:pc;");
write_packet(server, tmpbuf);
}
else if (!strncmp(name, "RegisterInfo", strlen("RegisterInfo"))) {
@ -215,24 +214,23 @@ handle_generay_query(WASMGDBServer *server, char *payload)
if (args && (!strcmp(name, "MemoryRegionInfo"))) {
uint64_t addr = strtol(args, NULL, 16);
WASMDebugMemoryInfo *mem_info = wasm_debug_instance_get_memregion(
(WASMDebugInstance *)server->thread->debug_instance, addr);
(WASMDebugInstance *)server->thread->debug_instance, addr);
if (mem_info) {
char name[256];
mem2hex(mem_info->name, name, strlen(mem_info->name));
sprintf(tmpbuf, "start:%lx;size:%lx;permissions:%s;name:%s;",
(uint64)mem_info->start, mem_info->size, mem_info->permisson, name);
(uint64)mem_info->start, mem_info->size,
mem_info->permisson, name);
write_packet(server, tmpbuf);
wasm_debug_instance_destroy_memregion(
(WASMDebugInstance *)server->thread->debug_instance, mem_info);
(WASMDebugInstance *)server->thread->debug_instance, mem_info);
}
}
if (!strcmp(name, "WasmData")) {
}
if (!strcmp(name, "WasmMem")) {
}
if (!strcmp(name, "Symbol")) {
@ -243,8 +241,8 @@ handle_generay_query(WASMGDBServer *server, char *payload)
uint64_t tid = strtol(args, NULL, 16);
uint64_t buf[1024 / sizeof(uint64_t)];
uint64_t count = wasm_debug_instance_get_call_stack_pcs(
(WASMDebugInstance *)server->thread->debug_instance, tid, buf,
1024 / sizeof(uint64_t));
(WASMDebugInstance *)server->thread->debug_instance, tid, buf,
1024 / sizeof(uint64_t));
if (count > 0) {
mem2hex((char *)buf, tmpbuf, count * sizeof(uint64_t));
write_packet(server, tmpbuf);
@ -276,16 +274,17 @@ send_thread_stop_status(WASMGDBServer *server, uint32_t status, uint64_t tid)
return;
}
tids_number = wasm_debug_instance_get_tids(
(WASMDebugInstance *)server->thread->debug_instance, tids, 20);
(WASMDebugInstance *)server->thread->debug_instance, tids, 20);
uint64_t pc = wasm_debug_instance_get_pc(
(WASMDebugInstance *)server->thread->debug_instance);
(WASMDebugInstance *)server->thread->debug_instance);
if (status == WAMR_SIG_SINGSTEP) {
gdb_status = WAMR_SIG_TRAP;
}
//TODO: how name a wasm thread?
len += sprintf(tmpbuf, "T%02xthread:%lx;name:%s;", gdb_status, tid, "nobody");
// TODO: how name a wasm thread?
len +=
sprintf(tmpbuf, "T%02xthread:%lx;name:%s;", gdb_status, tid, "nobody");
if (tids_number > 0) {
len += sprintf(tmpbuf + len, "threads:");
while (i < tids_number) {
@ -336,12 +335,12 @@ handle_v_packet(WASMGDBServer *server, char *payload)
*numstring++ = '\0';
uint64_t tid = strtol(numstring, NULL, 16);
wasm_debug_instance_set_cur_thread(
(WASMDebugInstance *)server->thread->debug_instance, tid);
(WASMDebugInstance *)server->thread->debug_instance, tid);
wasm_debug_instance_singlestep(
(WASMDebugInstance *)server->thread->debug_instance, tid);
(WASMDebugInstance *)server->thread->debug_instance, tid);
tid = wasm_debug_instance_wait_thread(
(WASMDebugInstance *)server->thread->debug_instance, tid,
&status);
(WASMDebugInstance *)server->thread->debug_instance, tid,
&status);
send_thread_stop_status(server, status, tid);
}
}
@ -352,11 +351,11 @@ void
handle_threadstop_request(WASMGDBServer *server, char *payload)
{
uint64_t tid = wasm_debug_instance_get_tid(
(WASMDebugInstance *)server->thread->debug_instance);
(WASMDebugInstance *)server->thread->debug_instance);
uint32_t status;
tid = wasm_debug_instance_wait_thread(
(WASMDebugInstance *)server->thread->debug_instance, tid, &status);
(WASMDebugInstance *)server->thread->debug_instance, tid, &status);
send_thread_stop_status(server, status, tid);
}
@ -370,7 +369,7 @@ handle_set_current_thread(WASMGDBServer *server, char *payload)
tid = strtol(payload, NULL, 16);
if (tid > 0)
wasm_debug_instance_set_cur_thread(
(WASMDebugInstance *)server->thread->debug_instance, tid);
(WASMDebugInstance *)server->thread->debug_instance, tid);
}
write_packet(server, "OK");
}
@ -385,7 +384,7 @@ handle_get_register(WASMGDBServer *server, char *payload)
return;
}
uint64_t regdata = wasm_debug_instance_get_pc(
(WASMDebugInstance *)server->thread->debug_instance);
(WASMDebugInstance *)server->thread->debug_instance);
mem2hex((void *)&regdata, tmpbuf, 8);
tmpbuf[8 * 2] = '\0';
write_packet(server, tmpbuf);
@ -423,8 +422,8 @@ handle_get_read_memory(WASMGDBServer *server, char *payload)
char *buff = wasm_runtime_malloc(mlen);
if (buff) {
ret = wasm_debug_instance_get_mem(
(WASMDebugInstance *)server->thread->debug_instance, maddr, buff,
&mlen);
(WASMDebugInstance *)server->thread->debug_instance, maddr,
buff, &mlen);
if (ret) {
mem2hex(buff, tmpbuf, mlen);
}
@ -451,8 +450,8 @@ handle_get_write_memory(WASMGDBServer *server, char *payload)
if (buff) {
hex2mem(payload, buff, act_len);
ret = wasm_debug_instance_set_mem(
(WASMDebugInstance *)server->thread->debug_instance, maddr, buff,
&mlen);
(WASMDebugInstance *)server->thread->debug_instance, maddr,
buff, &mlen);
if (ret) {
sprintf(tmpbuf, "%s", "OK");
}
@ -470,8 +469,8 @@ handle_add_break(WASMGDBServer *server, char *payload)
if (sscanf(payload, "%zx,%zx,%zx", &type, &addr, &length) == 3) {
if (type == eBreakpointSoftware) {
bool ret = wasm_debug_instance_add_breakpoint(
(WASMDebugInstance *)server->thread->debug_instance, addr,
length);
(WASMDebugInstance *)server->thread->debug_instance, addr,
length);
if (ret)
write_packet(server, "OK");
else
@ -490,8 +489,8 @@ handle_remove_break(WASMGDBServer *server, char *payload)
if (sscanf(payload, "%zx,%zx,%zx", &type, &addr, &length) == 3) {
if (type == eBreakpointSoftware) {
bool ret = wasm_debug_instance_remove_breakpoint(
(WASMDebugInstance *)server->thread->debug_instance, addr,
length);
(WASMDebugInstance *)server->thread->debug_instance, addr,
length);
if (ret)
write_packet(server, "OK");
else
@ -509,13 +508,13 @@ handle_continue_request(WASMGDBServer *server, char *payload)
uint32_t status;
wasm_debug_instance_continue(
(WASMDebugInstance *)server->thread->debug_instance);
(WASMDebugInstance *)server->thread->debug_instance);
tid = wasm_debug_instance_get_tid(
(WASMDebugInstance *)server->thread->debug_instance);
(WASMDebugInstance *)server->thread->debug_instance);
tid = wasm_debug_instance_wait_thread(
(WASMDebugInstance *)server->thread->debug_instance, tid, &status);
(WASMDebugInstance *)server->thread->debug_instance, tid, &status);
send_thread_stop_status(server, status, tid);
}
@ -527,13 +526,13 @@ handle_kill_request(WASMGDBServer *server, char *payload)
uint32_t status;
wasm_debug_instance_kill(
(WASMDebugInstance *)server->thread->debug_instance);
(WASMDebugInstance *)server->thread->debug_instance);
tid = wasm_debug_instance_get_tid(
(WASMDebugInstance *)server->thread->debug_instance);
(WASMDebugInstance *)server->thread->debug_instance);
tid = wasm_debug_instance_wait_thread(
(WASMDebugInstance *)server->thread->debug_instance, tid, &status);
(WASMDebugInstance *)server->thread->debug_instance, tid, &status);
send_thread_stop_status(server, status, tid);
}
@ -572,7 +571,8 @@ handle_malloc(WASMGDBServer *server, char *payload)
args++;
}
addr = wasm_debug_instance_mmap(
(WASMDebugInstance *)server->thread->debug_instance, size, map_port);
(WASMDebugInstance *)server->thread->debug_instance, size,
map_port);
if (addr) {
sprintf(tmpbuf, "%lx", addr);
}
@ -590,7 +590,7 @@ handle_free(WASMGDBServer *server, char *payload)
addr = strtol(payload, NULL, 16);
ret = wasm_debug_instance_ummap(
(WASMDebugInstance *)server->thread->debug_instance, addr);
(WASMDebugInstance *)server->thread->debug_instance, addr);
if (ret) {
sprintf(tmpbuf, "%s", "OK");
}

View File

@ -83,8 +83,7 @@ write_hex(WASMGDBServer *gdbserver, unsigned long hex)
}
void
write_packet_bytes(WASMGDBServer *gdbserver,
const uint8_t *data,
write_packet_bytes(WASMGDBServer *gdbserver, const uint8_t *data,
size_t num_bytes)
{
uint8_t checksum;
@ -106,10 +105,8 @@ write_packet(WASMGDBServer *gdbserver, const char *data)
}
void
write_binary_packet(WASMGDBServer *gdbserver,
const char *pfx,
const uint8_t *data,
ssize_t num_bytes)
write_binary_packet(WASMGDBServer *gdbserver, const char *pfx,
const uint8_t *data, ssize_t num_bytes)
{
uint8_t *buf;
ssize_t pfx_num_chars = strlen(pfx);