Add memory watchpoint support for source debugger (#1762)
Allow to add watchpoints to variables for source debugging. For instance: `breakpoint set variable var` will pause WAMR execution when the address at var is written to. Can also set read/write watchpoints by passing r/w flags. This will pause execution when the address at var is read: `watchpoint set variable -w read var` Add two linked lists for read/write watchpoints. When the debug message handler receives a watchpoint request, it adds/removes to one/both of these lists. In the interpreter, when an address is read or stored to, check whether the address is in these lists. If so, throw a sigtrap and suspend the process.
This commit is contained in:
committed by
Wenyong Huang
parent
37e9b9c510
commit
ead6478285
@ -70,6 +70,35 @@ typedef float64 CellType_F64;
|
||||
goto unaligned_atomic; \
|
||||
} while (0)
|
||||
|
||||
#if WASM_ENABLE_DEBUG_INTERP != 0
|
||||
#define TRIGGER_WATCHPOINT_SIGTRAP() \
|
||||
do { \
|
||||
wasm_cluster_thread_send_signal(exec_env, WAMR_SIG_TRAP); \
|
||||
CHECK_SUSPEND_FLAGS(); \
|
||||
} while (0)
|
||||
|
||||
#define CHECK_WATCHPOINT(list, current_addr) \
|
||||
do { \
|
||||
WASMDebugWatchPoint *watchpoint = bh_list_first_elem(list); \
|
||||
while (watchpoint) { \
|
||||
WASMDebugWatchPoint *next = bh_list_elem_next(watchpoint); \
|
||||
if (watchpoint->addr <= current_addr \
|
||||
&& watchpoint->addr + watchpoint->length > current_addr) { \
|
||||
TRIGGER_WATCHPOINT_SIGTRAP(); \
|
||||
} \
|
||||
watchpoint = next; \
|
||||
} \
|
||||
} while (0)
|
||||
|
||||
#define CHECK_READ_WATCHPOINT(addr, offset) \
|
||||
CHECK_WATCHPOINT(watch_point_list_read, WASM_ADDR_OFFSET(addr + offset))
|
||||
#define CHECK_WRITE_WATCHPOINT(addr, offset) \
|
||||
CHECK_WATCHPOINT(watch_point_list_write, WASM_ADDR_OFFSET(addr + offset))
|
||||
#else
|
||||
#define CHECK_READ_WATCHPOINT(addr, offset)
|
||||
#define CHECK_WRITE_WATCHPOINT(addr, offset)
|
||||
#endif
|
||||
|
||||
static inline uint32
|
||||
rotl32(uint32 n, uint32 c)
|
||||
{
|
||||
@ -1127,6 +1156,9 @@ wasm_interp_call_func_bytecode(WASMModuleInstance *module,
|
||||
|
||||
#if WASM_ENABLE_DEBUG_INTERP != 0
|
||||
uint8 *frame_ip_orig = NULL;
|
||||
WASMDebugInstance *debug_instance = wasm_exec_env_get_instance(exec_env);
|
||||
bh_list *watch_point_list_read = &debug_instance->watch_point_list_read;
|
||||
bh_list *watch_point_list_write = &debug_instance->watch_point_list_write;
|
||||
#endif
|
||||
|
||||
#if WASM_ENABLE_LABELS_AS_VALUES != 0
|
||||
@ -1792,6 +1824,7 @@ wasm_interp_call_func_bytecode(WASMModuleInstance *module,
|
||||
addr = POP_I32();
|
||||
CHECK_MEMORY_OVERFLOW(4);
|
||||
PUSH_I32(LOAD_I32(maddr));
|
||||
CHECK_READ_WATCHPOINT(addr, offset);
|
||||
(void)flags;
|
||||
HANDLE_OP_END();
|
||||
}
|
||||
@ -1806,6 +1839,7 @@ wasm_interp_call_func_bytecode(WASMModuleInstance *module,
|
||||
addr = POP_I32();
|
||||
CHECK_MEMORY_OVERFLOW(8);
|
||||
PUSH_I64(LOAD_I64(maddr));
|
||||
CHECK_READ_WATCHPOINT(addr, offset);
|
||||
(void)flags;
|
||||
HANDLE_OP_END();
|
||||
}
|
||||
@ -1819,6 +1853,7 @@ wasm_interp_call_func_bytecode(WASMModuleInstance *module,
|
||||
addr = POP_I32();
|
||||
CHECK_MEMORY_OVERFLOW(1);
|
||||
PUSH_I32(sign_ext_8_32(*(int8 *)maddr));
|
||||
CHECK_READ_WATCHPOINT(addr, offset);
|
||||
(void)flags;
|
||||
HANDLE_OP_END();
|
||||
}
|
||||
@ -1832,6 +1867,7 @@ wasm_interp_call_func_bytecode(WASMModuleInstance *module,
|
||||
addr = POP_I32();
|
||||
CHECK_MEMORY_OVERFLOW(1);
|
||||
PUSH_I32((uint32)(*(uint8 *)maddr));
|
||||
CHECK_READ_WATCHPOINT(addr, offset);
|
||||
(void)flags;
|
||||
HANDLE_OP_END();
|
||||
}
|
||||
@ -1845,6 +1881,7 @@ wasm_interp_call_func_bytecode(WASMModuleInstance *module,
|
||||
addr = POP_I32();
|
||||
CHECK_MEMORY_OVERFLOW(2);
|
||||
PUSH_I32(sign_ext_16_32(LOAD_I16(maddr)));
|
||||
CHECK_READ_WATCHPOINT(addr, offset);
|
||||
(void)flags;
|
||||
HANDLE_OP_END();
|
||||
}
|
||||
@ -1858,6 +1895,7 @@ wasm_interp_call_func_bytecode(WASMModuleInstance *module,
|
||||
addr = POP_I32();
|
||||
CHECK_MEMORY_OVERFLOW(2);
|
||||
PUSH_I32((uint32)(LOAD_U16(maddr)));
|
||||
CHECK_READ_WATCHPOINT(addr, offset);
|
||||
(void)flags;
|
||||
HANDLE_OP_END();
|
||||
}
|
||||
@ -1871,6 +1909,7 @@ wasm_interp_call_func_bytecode(WASMModuleInstance *module,
|
||||
addr = POP_I32();
|
||||
CHECK_MEMORY_OVERFLOW(1);
|
||||
PUSH_I64(sign_ext_8_64(*(int8 *)maddr));
|
||||
CHECK_READ_WATCHPOINT(addr, offset);
|
||||
(void)flags;
|
||||
HANDLE_OP_END();
|
||||
}
|
||||
@ -1884,6 +1923,7 @@ wasm_interp_call_func_bytecode(WASMModuleInstance *module,
|
||||
addr = POP_I32();
|
||||
CHECK_MEMORY_OVERFLOW(1);
|
||||
PUSH_I64((uint64)(*(uint8 *)maddr));
|
||||
CHECK_READ_WATCHPOINT(addr, offset);
|
||||
(void)flags;
|
||||
HANDLE_OP_END();
|
||||
}
|
||||
@ -1897,6 +1937,7 @@ wasm_interp_call_func_bytecode(WASMModuleInstance *module,
|
||||
addr = POP_I32();
|
||||
CHECK_MEMORY_OVERFLOW(2);
|
||||
PUSH_I64(sign_ext_16_64(LOAD_I16(maddr)));
|
||||
CHECK_READ_WATCHPOINT(addr, offset);
|
||||
(void)flags;
|
||||
HANDLE_OP_END();
|
||||
}
|
||||
@ -1910,6 +1951,7 @@ wasm_interp_call_func_bytecode(WASMModuleInstance *module,
|
||||
addr = POP_I32();
|
||||
CHECK_MEMORY_OVERFLOW(2);
|
||||
PUSH_I64((uint64)(LOAD_U16(maddr)));
|
||||
CHECK_READ_WATCHPOINT(addr, offset);
|
||||
(void)flags;
|
||||
HANDLE_OP_END();
|
||||
}
|
||||
@ -1924,6 +1966,7 @@ wasm_interp_call_func_bytecode(WASMModuleInstance *module,
|
||||
addr = POP_I32();
|
||||
CHECK_MEMORY_OVERFLOW(4);
|
||||
PUSH_I64(sign_ext_32_64(LOAD_I32(maddr)));
|
||||
CHECK_READ_WATCHPOINT(addr, offset);
|
||||
(void)flags;
|
||||
HANDLE_OP_END();
|
||||
}
|
||||
@ -1937,6 +1980,7 @@ wasm_interp_call_func_bytecode(WASMModuleInstance *module,
|
||||
addr = POP_I32();
|
||||
CHECK_MEMORY_OVERFLOW(4);
|
||||
PUSH_I64((uint64)(LOAD_U32(maddr)));
|
||||
CHECK_READ_WATCHPOINT(addr, offset);
|
||||
(void)flags;
|
||||
HANDLE_OP_END();
|
||||
}
|
||||
@ -1953,6 +1997,7 @@ wasm_interp_call_func_bytecode(WASMModuleInstance *module,
|
||||
addr = POP_I32();
|
||||
CHECK_MEMORY_OVERFLOW(4);
|
||||
STORE_U32(maddr, frame_sp[1]);
|
||||
CHECK_WRITE_WATCHPOINT(addr, offset);
|
||||
(void)flags;
|
||||
HANDLE_OP_END();
|
||||
}
|
||||
@ -1969,6 +2014,7 @@ wasm_interp_call_func_bytecode(WASMModuleInstance *module,
|
||||
CHECK_MEMORY_OVERFLOW(8);
|
||||
PUT_I64_TO_ADDR((uint32 *)maddr,
|
||||
GET_I64_FROM_ADDR(frame_sp + 1));
|
||||
CHECK_WRITE_WATCHPOINT(addr, offset);
|
||||
(void)flags;
|
||||
HANDLE_OP_END();
|
||||
}
|
||||
@ -1993,7 +2039,7 @@ wasm_interp_call_func_bytecode(WASMModuleInstance *module,
|
||||
CHECK_MEMORY_OVERFLOW(2);
|
||||
STORE_U16(maddr, (uint16)sval);
|
||||
}
|
||||
|
||||
CHECK_WRITE_WATCHPOINT(addr, offset);
|
||||
(void)flags;
|
||||
HANDLE_OP_END();
|
||||
}
|
||||
@ -2023,6 +2069,7 @@ wasm_interp_call_func_bytecode(WASMModuleInstance *module,
|
||||
CHECK_MEMORY_OVERFLOW(4);
|
||||
STORE_U32(maddr, (uint32)sval);
|
||||
}
|
||||
CHECK_WRITE_WATCHPOINT(addr, offset);
|
||||
(void)flags;
|
||||
HANDLE_OP_END();
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user