Skip to content

Commit e696ac3

Browse files
Fix potential block issue in source debugger (#1887)
Fix issue reported in #1860
1 parent 622cdbe commit e696ac3

File tree

3 files changed

+10
-12
lines changed

3 files changed

+10
-12
lines changed

core/iwasm/interpreter/wasm_interp_classic.c

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1041,7 +1041,6 @@ wasm_interp_call_func_import(WASMModuleInstance *module_inst,
10411041
} \
10421042
if (IS_WAMR_STOP_SIG(exec_env->current_status->signal_flag)) { \
10431043
SYNC_ALL_TO_FRAME(); \
1044-
wasm_cluster_thread_stopped(exec_env); \
10451044
wasm_cluster_thread_waiting_run(exec_env); \
10461045
} \
10471046
} while (0)
@@ -1077,7 +1076,6 @@ wasm_interp_call_func_import(WASMModuleInstance *module_inst,
10771076
&& exec_env->current_status->step_count++ == 1) { \
10781077
exec_env->current_status->step_count = 0; \
10791078
SYNC_ALL_TO_FRAME(); \
1080-
wasm_cluster_thread_stopped(exec_env); \
10811079
wasm_cluster_thread_waiting_run(exec_env); \
10821080
} \
10831081
goto *handle_table[*frame_ip++]; \
@@ -1094,7 +1092,6 @@ wasm_interp_call_func_import(WASMModuleInstance *module_inst,
10941092
&& exec_env->current_status->step_count++ == 2) { \
10951093
exec_env->current_status->step_count = 0; \
10961094
SYNC_ALL_TO_FRAME(); \
1097-
wasm_cluster_thread_stopped(exec_env); \
10981095
wasm_cluster_thread_waiting_run(exec_env); \
10991096
} \
11001097
continue

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

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -610,16 +610,16 @@ notify_debug_instance_exit(WASMExecEnv *exec_env)
610610
}
611611

612612
void
613-
wasm_cluster_thread_stopped(WASMExecEnv *exec_env)
613+
wasm_cluster_thread_waiting_run(WASMExecEnv *exec_env)
614614
{
615+
os_mutex_lock(&exec_env->wait_lock);
616+
617+
/* Wake up debugger thread after we get the lock, otherwise we may miss the
618+
* signal from debugger thread, see
619+
* https://github.com/bytecodealliance/wasm-micro-runtime/issues/1860 */
615620
exec_env->current_status->running_status = STATUS_STOP;
616621
notify_debug_instance(exec_env);
617-
}
618622

619-
void
620-
wasm_cluster_thread_waiting_run(WASMExecEnv *exec_env)
621-
{
622-
os_mutex_lock(&exec_env->wait_lock);
623623
while (!wasm_cluster_thread_is_running(exec_env)) {
624624
os_cond_wait(&exec_env->wait_cond, &exec_env->wait_lock);
625625
}
@@ -646,16 +646,20 @@ wasm_cluster_thread_exited(WASMExecEnv *exec_env)
646646
void
647647
wasm_cluster_thread_continue(WASMExecEnv *exec_env)
648648
{
649+
os_mutex_lock(&exec_env->wait_lock);
649650
wasm_cluster_clear_thread_signal(exec_env);
650651
exec_env->current_status->running_status = STATUS_RUNNING;
651652
os_cond_signal(&exec_env->wait_cond);
653+
os_mutex_unlock(&exec_env->wait_lock);
652654
}
653655

654656
void
655657
wasm_cluster_thread_step(WASMExecEnv *exec_env)
656658
{
659+
os_mutex_lock(&exec_env->wait_lock);
657660
exec_env->current_status->running_status = STATUS_STEP;
658661
os_cond_signal(&exec_env->wait_cond);
662+
os_mutex_unlock(&exec_env->wait_lock);
659663
}
660664

661665
void

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

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

169-
void
170-
wasm_cluster_thread_stopped(WASMExecEnv *exec_env);
171-
172169
void
173170
wasm_cluster_thread_waiting_run(WASMExecEnv *exec_env);
174171

0 commit comments

Comments
 (0)