From: Pedro Alves Date: Tue, 9 May 2023 19:34:50 +0000 (+0100) Subject: Windows gdb: Factor code out of windows_nat_target::windows_continue X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=450761e97ad642f348a5e98867a3279131726a3c;p=thirdparty%2Fbinutils-gdb.git Windows gdb: Factor code out of windows_nat_target::windows_continue This factors some code out of windows_nat_target::windows_continue into a new windows_continue_one function. This will make the following patch easier to read (as well as the resulting code itself). Approved-By: Tom Tromey Change-Id: I14a0386b1b8b03015e86273060af173b5130e375 --- diff --git a/gdb/windows-nat.c b/gdb/windows-nat.c index f3c05067a74..f954048dffe 100644 --- a/gdb/windows-nat.c +++ b/gdb/windows-nat.c @@ -116,6 +116,9 @@ struct windows_per_inferior : public windows_process_info void invalidate_context (windows_thread_info *th); + void continue_one_thread (windows_thread_info *th, + windows_continue_flags cont_flags); + int windows_initialization_done = 0; std::vector> thread_list; @@ -1217,6 +1220,44 @@ windows_per_inferior::handle_access_violation return false; } +void +windows_per_inferior::continue_one_thread (windows_thread_info *th, + windows_continue_flags cont_flags) +{ + struct x86_debug_reg_state *state = x86_debug_reg_state (process_id); + + windows_process.with_context (th, [&] (auto *context) + { + if (th->debug_registers_changed) + { + context->ContextFlags |= WindowsContext::debug; + context->Dr0 = state->dr_mirror[0]; + context->Dr1 = state->dr_mirror[1]; + context->Dr2 = state->dr_mirror[2]; + context->Dr3 = state->dr_mirror[3]; + context->Dr6 = DR6_CLEAR_VALUE; + context->Dr7 = state->dr_control_mirror; + th->debug_registers_changed = false; + } + if (context->ContextFlags) + { + DWORD ec = 0; + + if (GetExitCodeThread (th->h, &ec) + && ec == STILL_ACTIVE) + { + BOOL status = set_thread_context (th->h, context); + + if ((cont_flags & WCONT_KILLED) == 0) + CHECK (status); + } + context->ContextFlags = 0; + } + }); + + th->resume (); +} + /* Resume thread specified by ID, or all artificially suspended threads, if we are continuing execution. See description of windows_continue_flags for CONT_FLAGS. */ @@ -1238,42 +1279,7 @@ windows_nat_target::windows_continue (DWORD continue_status, int id, for (auto &th : windows_process.thread_list) if (id == -1 || id == (int) th->tid) - { - struct x86_debug_reg_state *state - = x86_debug_reg_state (windows_process.process_id); - - windows_process.with_context (th.get (), [&] (auto *context) - { - if (th->debug_registers_changed) - { - context->ContextFlags - |= WindowsContext::debug; - context->Dr0 = state->dr_mirror[0]; - context->Dr1 = state->dr_mirror[1]; - context->Dr2 = state->dr_mirror[2]; - context->Dr3 = state->dr_mirror[3]; - context->Dr6 = DR6_CLEAR_VALUE; - context->Dr7 = state->dr_control_mirror; - th->debug_registers_changed = false; - } - if (context->ContextFlags) - { - DWORD ec = 0; - - if (GetExitCodeThread (th->h, &ec) - && ec == STILL_ACTIVE) - { - BOOL status = set_thread_context (th->h, context); - - if ((cont_flags & WCONT_KILLED) == 0) - CHECK (status); - } - context->ContextFlags = 0; - } - }); - - th->resume (); - } + windows_process.continue_one_thread (th.get (), cont_flags); continue_last_debug_event_main_thread (_("Failed to resume program execution"), continue_status,