-
Notifications
You must be signed in to change notification settings - Fork 728
[debugger enhance] don't block gdbserver thread while executing #989
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from 13 commits
Commits
Show all changes
16 commits
Select commit
Hold shift + click to select a range
37bce76
don't block gdbserver thread while executing
xujuntwt95329 21dbc4d
fix some issue about current thread tid
xujuntwt95329 7b1c105
remove unused functions
xujuntwt95329 65ccc26
auto format
xujuntwt95329 02d653d
move mutex lock to debug_engine
xujuntwt95329 b0570cd
remove more unused codes
xujuntwt95329 934bf6a
remove unnecessary comment
xujuntwt95329 5fafce8
add empty line between type declaration
xujuntwt95329 cbaebb6
fix some warning on windows
xujuntwt95329 492f5d5
enable windows platform
xujuntwt95329 80219a6
enhance cmake option check
xujuntwt95329 ba83116
change vendor string
xujuntwt95329 f226bed
auto format
xujuntwt95329 f4c6f10
address PR comments
xujuntwt95329 7aceef7
ignore empty gdb request
xujuntwt95329 a5ab4dd
address PR comment
xujuntwt95329 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -24,6 +24,14 @@ typedef struct WASMDebugEngine { | |
| bool active; | ||
| } WASMDebugEngine; | ||
|
|
||
| void | ||
| on_thread_stop_event(WASMDebugInstance *debug_inst, WASMExecEnv *exec_env) | ||
| { | ||
| os_mutex_lock(&debug_inst->wait_lock); | ||
| debug_inst->stopped_thread = exec_env; | ||
| os_mutex_unlock(&debug_inst->wait_lock); | ||
| } | ||
|
|
||
| static WASMDebugEngine *g_debug_engine; | ||
|
|
||
| static uint32 current_instance_id = 1; | ||
|
|
@@ -104,6 +112,43 @@ control_thread_routine(void *arg) | |
| while (true) { | ||
| os_mutex_lock(&control_thread->wait_lock); | ||
| if (!should_stop(control_thread)) { | ||
| /* send thread stop reply */ | ||
| if (debug_inst->stopped_thread | ||
| && debug_inst->current_state == APP_RUNNING) { | ||
| uint32 status; | ||
| korp_tid tid; | ||
|
|
||
| status = | ||
| (uint32) | ||
| debug_inst->stopped_thread->current_status->signal_flag; | ||
| tid = debug_inst->stopped_thread->handle; | ||
|
|
||
| if (debug_inst->stopped_thread->current_status->running_status | ||
| == STATUS_EXIT) { | ||
| /* If the thread exits, report "W00" if it's the last thread | ||
| * in the cluster, otherwise ignore this event */ | ||
| status = 0; | ||
|
|
||
| /* By design, all the other threads should stopped at this | ||
| * moment, so it is safe to access the exec_env_list.len | ||
| * without lock */ | ||
| if (debug_inst->cluster->exec_env_list.len != 1) { | ||
| debug_inst->stopped_thread = NULL; | ||
| os_mutex_unlock(&control_thread->wait_lock); | ||
| continue; | ||
| } | ||
| } | ||
|
|
||
| wasm_debug_instance_set_cur_thread( | ||
| debug_inst, debug_inst->stopped_thread->handle); | ||
|
|
||
| send_thread_stop_status(control_thread->server, status, tid); | ||
|
|
||
| debug_inst->current_state = APP_STOPPED; | ||
| debug_inst->stopped_thread = NULL; | ||
| } | ||
|
|
||
| /* Processing incoming requests */ | ||
| if (!wasm_gdbserver_handle_packet(control_thread->server)) { | ||
| control_thread->status = STOPPED; | ||
| } | ||
|
|
@@ -148,8 +193,10 @@ wasm_debug_control_thread_create(WASMDebugInstance *debug_instance) | |
| /* wait until the debug control thread ready */ | ||
| os_cond_wait(&debug_instance->wait_cond, &debug_instance->wait_lock); | ||
| os_mutex_unlock(&debug_instance->wait_lock); | ||
| if (!control_thread->server) | ||
| if (!control_thread->server) { | ||
| os_thread_join(control_thread->tid, NULL); | ||
| goto fail1; | ||
| } | ||
|
|
||
| os_mutex_lock(&g_debug_engine->instance_list_lock); | ||
| /* create control thread success, append debug instance to debug engine */ | ||
|
|
@@ -467,46 +514,6 @@ wasm_debug_instance_get_tids(WASMDebugInstance *instance, korp_tid tids[], | |
| return threads_num; | ||
| } | ||
|
|
||
| static WASMExecEnv * | ||
| get_stopped_thread(WASMCluster *cluster) | ||
| { | ||
| WASMExecEnv *exec_env; | ||
|
|
||
| exec_env = bh_list_first_elem(&cluster->exec_env_list); | ||
| while (exec_env) { | ||
| if (exec_env->current_status->running_status != STATUS_RUNNING) { | ||
| return exec_env; | ||
| } | ||
| exec_env = bh_list_elem_next(exec_env); | ||
| } | ||
|
|
||
| return NULL; | ||
| } | ||
|
|
||
| korp_tid | ||
| wasm_debug_instance_wait_thread(WASMDebugInstance *instance, korp_tid tid, | ||
| uint32 *status) | ||
| { | ||
| WASMExecEnv *exec_env = NULL; | ||
|
|
||
| os_mutex_lock(&instance->wait_lock); | ||
| while ((instance->cluster->exec_env_list.len != 0) | ||
| && ((exec_env = get_stopped_thread(instance->cluster)) == NULL)) { | ||
| os_cond_wait(&instance->wait_cond, &instance->wait_lock); | ||
| } | ||
| os_mutex_unlock(&instance->wait_lock); | ||
|
|
||
| /* If cluster has no exec_env, then this whole cluster is exiting */ | ||
| if (instance->cluster->exec_env_list.len == 0) { | ||
| *status = 0; | ||
| return 0; | ||
| } | ||
|
|
||
| instance->current_tid = exec_env->handle; | ||
| *status = (uint32)exec_env->current_status->signal_flag; | ||
| return exec_env->handle; | ||
| } | ||
|
|
||
| uint32 | ||
| wasm_debug_instance_get_thread_status(WASMDebugInstance *instance, korp_tid tid) | ||
| { | ||
|
|
@@ -538,7 +545,8 @@ 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 != NULL) && (exec_env->cur_frame != NULL) | ||
| && (exec_env->cur_frame->ip != NULL)) { | ||
| WASMModuleInstance *module_inst = | ||
| (WASMModuleInstance *)exec_env->module_inst; | ||
| return WASM_ADDR( | ||
|
|
@@ -935,6 +943,11 @@ wasm_debug_instance_continue(WASMDebugInstance *instance) | |
| if (!instance) | ||
| return false; | ||
|
|
||
| if (instance->current_state == APP_RUNNING) { | ||
| LOG_VERBOSE("Already in running state, ignore continue request"); | ||
| return false; | ||
| } | ||
|
|
||
| exec_env = bh_list_first_elem(&instance->cluster->exec_env_list); | ||
| if (!exec_env) | ||
| return false; | ||
|
|
@@ -943,6 +956,28 @@ wasm_debug_instance_continue(WASMDebugInstance *instance) | |
| wasm_cluster_thread_continue(exec_env); | ||
| exec_env = bh_list_elem_next(exec_env); | ||
| } | ||
|
|
||
| instance->current_state = APP_RUNNING; | ||
|
|
||
| return true; | ||
| } | ||
|
|
||
| bool | ||
| wasm_debug_instance_interrupt_all_threads(WASMDebugInstance *instance) | ||
| { | ||
| WASMExecEnv *exec_env; | ||
|
|
||
| if (!instance) | ||
| return false; | ||
|
|
||
| exec_env = bh_list_first_elem(&instance->cluster->exec_env_list); | ||
| if (!exec_env) | ||
| return false; | ||
|
|
||
| while (exec_env) { | ||
| wasm_cluster_thread_send_signal(exec_env, WAMR_SIG_TRAP); | ||
| exec_env = bh_list_elem_next(exec_env); | ||
| } | ||
| return true; | ||
| } | ||
|
|
||
|
|
@@ -960,8 +995,15 @@ wasm_debug_instance_kill(WASMDebugInstance *instance) | |
|
|
||
| while (exec_env) { | ||
| wasm_cluster_thread_send_signal(exec_env, WAMR_SIG_TERM); | ||
| if (instance->current_state == APP_STOPPED) { | ||
| /* Resume all threads so they can receive the TERM signal */ | ||
| exec_env->current_status->running_status = STATUS_RUNNING; | ||
| os_cond_signal(&exec_env->wait_cond); | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Should we wrap os_cond_signal with There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Done |
||
| } | ||
| exec_env = bh_list_elem_next(exec_env); | ||
| } | ||
|
|
||
| instance->current_state = APP_RUNNING; | ||
| return true; | ||
| } | ||
|
|
||
|
|
@@ -973,6 +1015,11 @@ wasm_debug_instance_singlestep(WASMDebugInstance *instance, korp_tid tid) | |
| if (!instance) | ||
| return false; | ||
|
|
||
| if (instance->current_state == APP_RUNNING) { | ||
| LOG_VERBOSE("Already in running state, ignore step request"); | ||
| return false; | ||
| } | ||
|
|
||
| exec_env = bh_list_first_elem(&instance->cluster->exec_env_list); | ||
| if (!exec_env) | ||
| return false; | ||
|
|
@@ -984,6 +1031,9 @@ wasm_debug_instance_singlestep(WASMDebugInstance *instance, korp_tid tid) | |
| } | ||
| exec_env = bh_list_elem_next(exec_env); | ||
| } | ||
|
|
||
| instance->current_state = APP_RUNNING; | ||
|
|
||
| return true; | ||
| } | ||
|
|
||
|
|
||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
should stop or should have been stopped?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done