Skip to content

Commit d75cb32

Browse files
Fix dead lock in source debugger (#2040)
1 parent 5c37ddf commit d75cb32

3 files changed

Lines changed: 7 additions & 6 deletions

File tree

core/iwasm/interpreter/wasm_interp_classic.c

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1079,12 +1079,14 @@ wasm_interp_call_func_import(WASMModuleInstance *module_inst,
10791079
/* Record the current frame_ip, so when exception occurs, \
10801080
debugger can know the exact opcode who caused the exception */ \
10811081
frame_ip_orig = frame_ip; \
1082+
os_mutex_lock(&exec_env->wait_lock); \
10821083
while (exec_env->current_status->signal_flag == WAMR_SIG_SINGSTEP \
10831084
&& exec_env->current_status->step_count++ == 1) { \
10841085
exec_env->current_status->step_count = 0; \
10851086
SYNC_ALL_TO_FRAME(); \
10861087
wasm_cluster_thread_waiting_run(exec_env); \
10871088
} \
1089+
os_mutex_unlock(&exec_env->wait_lock); \
10881090
goto *handle_table[*frame_ip++]; \
10891091
} while (0)
10901092
#else
@@ -1095,12 +1097,14 @@ wasm_interp_call_func_import(WASMModuleInstance *module_inst,
10951097
#define HANDLE_OP(opcode) case opcode:
10961098
#if WASM_ENABLE_THREAD_MGR != 0 && WASM_ENABLE_DEBUG_INTERP != 0
10971099
#define HANDLE_OP_END() \
1100+
os_mutex_lock(&exec_env->wait_lock); \
10981101
if (exec_env->current_status->signal_flag == WAMR_SIG_SINGSTEP \
10991102
&& exec_env->current_status->step_count++ == 2) { \
11001103
exec_env->current_status->step_count = 0; \
11011104
SYNC_ALL_TO_FRAME(); \
11021105
wasm_cluster_thread_waiting_run(exec_env); \
11031106
} \
1107+
os_mutex_unlock(&exec_env->wait_lock); \
11041108
continue
11051109
#else
11061110
#define HANDLE_OP_END() continue

core/iwasm/libraries/thread-mgr/thread_manager.c

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -793,18 +793,12 @@ notify_debug_instance_exit(WASMExecEnv *exec_env)
793793
void
794794
wasm_cluster_thread_waiting_run(WASMExecEnv *exec_env)
795795
{
796-
os_mutex_lock(&exec_env->wait_lock);
797-
798-
/* Wake up debugger thread after we get the lock, otherwise we may miss the
799-
* signal from debugger thread, see
800-
* https://github.com/bytecodealliance/wasm-micro-runtime/issues/1860 */
801796
exec_env->current_status->running_status = STATUS_STOP;
802797
notify_debug_instance(exec_env);
803798

804799
while (!wasm_cluster_thread_is_running(exec_env)) {
805800
os_cond_wait(&exec_env->wait_cond, &exec_env->wait_lock);
806801
}
807-
os_mutex_unlock(&exec_env->wait_lock);
808802
}
809803

810804
void

core/iwasm/libraries/thread-mgr/thread_manager.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -180,6 +180,9 @@ wasm_cluster_destroy_exenv_status(WASMCurrentEnvStatus *status);
180180
void
181181
wasm_cluster_send_signal_all(WASMCluster *cluster, uint32 signo);
182182

183+
/* This function must be called with exec_env->wait_lock locked, otherwise we
184+
* may miss the signal from debugger thread, see
185+
* https://github.com/bytecodealliance/wasm-micro-runtime/issues/1860 */
183186
void
184187
wasm_cluster_thread_waiting_run(WASMExecEnv *exec_env);
185188

0 commit comments

Comments
 (0)