From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: by sourceware.org (Postfix, from userid 2126) id 9BEEC3858C53; Mon, 4 Apr 2022 19:59:21 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 9BEEC3858C53 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable From: Tom Tromey To: gdb-cvs@sourceware.org Subject: [binutils-gdb] Remove some globals from nat/windows-nat.c X-Act-Checkin: binutils-gdb X-Git-Author: Tom Tromey X-Git-Refname: refs/heads/master X-Git-Oldrev: fc0b013e44e5a450631706bc25612b975cfbc692 X-Git-Newrev: 0578e87f93b09e4cc41d3982eb1672bcfc81042d Message-Id: <20220404195921.9BEEC3858C53@sourceware.org> Date: Mon, 4 Apr 2022 19:59:21 +0000 (GMT) X-BeenThere: gdb-cvs@sourceware.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Gdb-cvs mailing list List-Unsubscribe: , List-Archive: List-Help: List-Subscribe: , X-List-Received-Date: Mon, 04 Apr 2022 19:59:21 -0000 https://sourceware.org/git/gitweb.cgi?p=3Dbinutils-gdb.git;h=3D0578e87f93b0= 9e4cc41d3982eb1672bcfc81042d commit 0578e87f93b09e4cc41d3982eb1672bcfc81042d Author: Tom Tromey Date: Thu Mar 31 13:41:02 2022 -0600 Remove some globals from nat/windows-nat.c =20 nat/windows-nat.c has a number of globals that it uses to communicate with its clients (gdb and gdbserver). However, if we ever want the Windows ports to be multi-inferior, globals won't work. =20 This patch takes a step toward that by moving most nat/windows-nat.c globals into a new struct windows_process_info. Many functions are converted to be methods on this object. =20 A couple of globals remain, as they are needed to truly be global due to the way that the Windows debugging APIs work. =20 The clients still have a global for the current process. That is, this patch is a step toward the end goal, but doesn't implement the goal itself. Diff: --- gdb/nat/windows-nat.c | 56 +++----- gdb/nat/windows-nat.h | 217 ++++++++++++++++-------------- gdb/windows-nat.c | 356 +++++++++++++++++++++++++++------------------= ---- gdbserver/win32-low.cc | 245 ++++++++++++++++++---------------- 4 files changed, 463 insertions(+), 411 deletions(-) diff --git a/gdb/nat/windows-nat.c b/gdb/nat/windows-nat.c index 3907286de96..c890ee13c6c 100644 --- a/gdb/nat/windows-nat.c +++ b/gdb/nat/windows-nat.c @@ -23,12 +23,6 @@ namespace windows_nat { =20 -HANDLE current_process_handle; -DWORD current_process_id; -DWORD main_thread_id; -enum gdb_signal last_sig =3D GDB_SIGNAL_0; -DEBUG_EVENT current_event; - /* The most recent event from WaitForDebugEvent. Unlike current_event, this is guaranteed never to come from a pending stop. This is important because only data from the most recent @@ -36,15 +30,6 @@ DEBUG_EVENT current_event; ContinueDebugEvent. */ static DEBUG_EVENT last_wait_event; =20 -DWORD desired_stop_thread_id =3D -1; -std::vector pending_stops; -EXCEPTION_RECORD siginfo_er; - -#ifdef __x86_64__ -bool wow64_process =3D false; -bool ignore_first_breakpoint =3D false; -#endif - AdjustTokenPrivileges_ftype *AdjustTokenPrivileges; DebugActiveProcessStop_ftype *DebugActiveProcessStop; DebugBreakProcess_ftype *DebugBreakProcess; @@ -180,7 +165,8 @@ get_image_name (HANDLE h, void *address, int unicode) #define MS_VC_EXCEPTION 0x406d1388 =20 handle_exception_result -handle_exception (struct target_waitstatus *ourstatus, bool debug_exceptio= ns) +windows_process_info::handle_exception (struct target_waitstatus *ourstatu= s, + bool debug_exceptions) { #define DEBUG_EXCEPTION_SIMPLE(x) if (debug_exceptions) \ debug_printf ("gdb: Target exception %s at %s\n", x, \ @@ -335,15 +321,10 @@ handle_exception (struct target_waitstatus *ourstatus= , bool debug_exceptions) #undef DEBUG_EXCEPTION_SIMPLE } =20 -/* Iterate over all DLLs currently mapped by our inferior, looking for - a DLL which is loaded at LOAD_ADDR. If found, add the DLL to our - list of solibs; otherwise do nothing. LOAD_ADDR NULL means add all - DLLs to the list of solibs; this is used when the inferior finishes - its initialization, and all the DLLs it statically depends on are - presumed loaded. */ +/* See nat/windows-nat.h. */ =20 -static void -windows_add_dll (LPVOID load_addr) +void +windows_process_info::add_dll (LPVOID load_addr) { HMODULE dummy_hmodule; DWORD cb_needed; @@ -353,7 +334,7 @@ windows_add_dll (LPVOID load_addr) #ifdef __x86_64__ if (wow64_process) { - if (EnumProcessModulesEx (current_process_handle, &dummy_hmodule, + if (EnumProcessModulesEx (handle, &dummy_hmodule, sizeof (HMODULE), &cb_needed, LIST_MODULES_32BIT) =3D=3D 0) return; @@ -361,7 +342,7 @@ windows_add_dll (LPVOID load_addr) else #endif { - if (EnumProcessModules (current_process_handle, &dummy_hmodule, + if (EnumProcessModules (handle, &dummy_hmodule, sizeof (HMODULE), &cb_needed) =3D=3D 0) return; } @@ -373,7 +354,7 @@ windows_add_dll (LPVOID load_addr) #ifdef __x86_64__ if (wow64_process) { - if (EnumProcessModulesEx (current_process_handle, hmodules, + if (EnumProcessModulesEx (handle, hmodules, cb_needed, &cb_needed, LIST_MODULES_32BIT) =3D=3D 0) return; @@ -381,7 +362,7 @@ windows_add_dll (LPVOID load_addr) else #endif { - if (EnumProcessModules (current_process_handle, hmodules, + if (EnumProcessModules (handle, hmodules, cb_needed, &cb_needed) =3D=3D 0) return; } @@ -426,11 +407,11 @@ windows_add_dll (LPVOID load_addr) char dll_name[MAX_PATH]; #endif const char *name; - if (GetModuleInformation (current_process_handle, hmodules[i], + if (GetModuleInformation (handle, hmodules[i], &mi, sizeof (mi)) =3D=3D 0) continue; =20 - if (GetModuleFileNameEx (current_process_handle, hmodules[i], + if (GetModuleFileNameEx (handle, hmodules[i], dll_name, sizeof (dll_name)) =3D=3D 0) continue; #ifdef __USEWIDE @@ -466,7 +447,7 @@ windows_add_dll (LPVOID load_addr) /* See nat/windows-nat.h. */ =20 void -dll_loaded_event () +windows_process_info::dll_loaded_event () { gdb_assert (current_event.dwDebugEventCode =3D=3D LOAD_DLL_DEBUG_EVENT); =20 @@ -478,29 +459,28 @@ dll_loaded_event () in the sense that it might be NULL. And the first DLL event in particular is explicitly documented as "likely not pass[ed]" (source: MSDN LOAD_DLL_DEBUG_INFO structure). */ - dll_name =3D get_image_name (current_process_handle, - event->lpImageName, event->fUnicode); + dll_name =3D get_image_name (handle, event->lpImageName, event->fUnicode= ); /* If the DLL name could not be gleaned via lpImageName, try harder by enumerating all the DLLs loaded into the inferior, looking for one that is loaded at base address =3D lpBaseOfDll. */ if (dll_name !=3D nullptr) handle_load_dll (dll_name, event->lpBaseOfDll); else if (event->lpBaseOfDll !=3D nullptr) - windows_add_dll (event->lpBaseOfDll); + add_dll (event->lpBaseOfDll); } =20 /* See nat/windows-nat.h. */ =20 void -windows_add_all_dlls () +windows_process_info::add_all_dlls () { - windows_add_dll (nullptr); + add_dll (nullptr); } =20 /* See nat/windows-nat.h. */ =20 bool -matching_pending_stop (bool debug_events) +windows_process_info::matching_pending_stop (bool debug_events) { /* If there are pending stops, and we might plausibly hit one of them, we don't want to actually continue the inferior -- we just @@ -524,7 +504,7 @@ matching_pending_stop (bool debug_events) /* See nat/windows-nat.h. */ =20 gdb::optional -fetch_pending_stop (bool debug_events) +windows_process_info::fetch_pending_stop (bool debug_events) { gdb::optional result; for (auto iter =3D pending_stops.begin (); diff --git a/gdb/nat/windows-nat.h b/gdb/nat/windows-nat.h index bfb359efbf1..7f76ba0e58f 100644 --- a/gdb/nat/windows-nat.h +++ b/gdb/nat/windows-nat.h @@ -109,145 +109,162 @@ enum thread_disposition_type INVALIDATE_CONTEXT }; =20 -/* Find a thread record given a thread id. THREAD_DISPOSITION - controls whether the thread is suspended, and whether the context - is invalidated. +/* A single pending stop. See "pending_stops" for more + information. */ +struct pending_stop +{ + /* The thread id. */ + DWORD thread_id; =20 - This function must be supplied by the embedding application. */ -extern windows_thread_info *thread_rec (ptid_t ptid, - thread_disposition_type disposition); + /* The target waitstatus we computed. */ + target_waitstatus status; =20 + /* The event. A few fields of this can be referenced after a stop, + and it seemed simplest to store the entire event. */ + DEBUG_EVENT event; +}; =20 -/* Handle OUTPUT_DEBUG_STRING_EVENT from child process. Updates - OURSTATUS and returns the thread id if this represents a thread - change (this is specific to Cygwin), otherwise 0. +typedef enum +{ + HANDLE_EXCEPTION_UNHANDLED =3D 0, + HANDLE_EXCEPTION_HANDLED, + HANDLE_EXCEPTION_IGNORED +} handle_exception_result; =20 - Cygwin prepends its messages with a "cygwin:". Interpret this as - a Cygwin signal. Otherwise just print the string as a warning. +/* A single Windows process. An object of this type (or subclass) is + created by the client. Some methods must be provided by the client + as well. */ =20 - This function must be supplied by the embedding application. */ -extern int handle_output_debug_string (struct target_waitstatus *ourstatus= ); +struct windows_process_info +{ + /* The process handle */ + HANDLE handle =3D 0; + DWORD id =3D 0; + DWORD main_thread_id =3D 0; + enum gdb_signal last_sig =3D GDB_SIGNAL_0; + + /* The current debug event from WaitForDebugEvent or from a pending + stop. */ + DEBUG_EVENT current_event {}; + + /* The ID of the thread for which we anticipate a stop event. + Normally this is -1, meaning we'll accept an event in any + thread. */ + DWORD desired_stop_thread_id =3D -1; + + /* A vector of pending stops. Sometimes, Windows will report a stop + on a thread that has been ostensibly suspended. We believe what + happens here is that two threads hit a breakpoint simultaneously, + and the Windows kernel queues the stop events. However, this can + result in the strange effect of trying to single step thread A -- + leaving all other threads suspended -- and then seeing a stop in + thread B. To handle this scenario, we queue all such "pending" + stops here, and then process them once the step has completed. See + PR gdb/22992. */ + std::vector pending_stops; + + /* Contents of $_siginfo */ + EXCEPTION_RECORD siginfo_er {}; =20 -/* Handle a DLL load event. +#ifdef __x86_64__ + /* The target is a WOW64 process */ + bool wow64_process =3D false; + /* Ignore first breakpoint exception of WOW64 process */ + bool ignore_first_breakpoint =3D false; +#endif =20 - This function assumes that the current event did not occur during - inferior initialization. =20 - DLL_NAME is the name of the library. BASE is the base load - address. + /* Find a thread record given a thread id. THREAD_DISPOSITION + controls whether the thread is suspended, and whether the context + is invalidated. =20 - This function must be supplied by the embedding application. */ + This function must be supplied by the embedding application. */ + windows_thread_info *thread_rec (ptid_t ptid, + thread_disposition_type disposition); =20 -extern void handle_load_dll (const char *dll_name, LPVOID base); + /* Handle OUTPUT_DEBUG_STRING_EVENT from child process. Updates + OURSTATUS and returns the thread id if this represents a thread + change (this is specific to Cygwin), otherwise 0. =20 -/* Handle a DLL unload event. + Cygwin prepends its messages with a "cygwin:". Interpret this as + a Cygwin signal. Otherwise just print the string as a warning. =20 - This function assumes that this event did not occur during inferior - initialization. + This function must be supplied by the embedding application. */ + int handle_output_debug_string (struct target_waitstatus *ourstatus); =20 - This function must be supplied by the embedding application. */ + /* Handle a DLL load event. =20 -extern void handle_unload_dll (); + This function assumes that the current event did not occur during + inferior initialization. =20 -/* Handle MS_VC_EXCEPTION when processing a stop. MS_VC_EXCEPTION is - somewhat undocumented but is used to tell the debugger the name of - a thread. + DLL_NAME is the name of the library. BASE is the base load + address. =20 - Return true if the exception was handled; return false otherwise. + This function must be supplied by the embedding application. */ =20 - This function must be supplied by the embedding application. */ + void handle_load_dll (const char *dll_name, LPVOID base); =20 -extern bool handle_ms_vc_exception (const EXCEPTION_RECORD *rec); + /* Handle a DLL unload event. =20 -/* When EXCEPTION_ACCESS_VIOLATION is processed, we give the embedding - application a chance to change it to be considered "unhandled". - This function must be supplied by the embedding application. If it - returns true, then the exception is "unhandled". */ + This function assumes that this event did not occur during inferior + initialization. =20 -extern bool handle_access_violation (const EXCEPTION_RECORD *rec); + This function must be supplied by the embedding application. */ =20 + void handle_unload_dll (); =20 -/* Currently executing process */ -extern HANDLE current_process_handle; -extern DWORD current_process_id; -extern DWORD main_thread_id; -extern enum gdb_signal last_sig; + /* Handle MS_VC_EXCEPTION when processing a stop. MS_VC_EXCEPTION is + somewhat undocumented but is used to tell the debugger the name of + a thread. =20 -/* The current debug event from WaitForDebugEvent or from a pending - stop. */ -extern DEBUG_EVENT current_event; + Return true if the exception was handled; return false otherwise. =20 -/* The ID of the thread for which we anticipate a stop event. - Normally this is -1, meaning we'll accept an event in any - thread. */ -extern DWORD desired_stop_thread_id; + This function must be supplied by the embedding application. */ =20 -/* A single pending stop. See "pending_stops" for more - information. */ -struct pending_stop -{ - /* The thread id. */ - DWORD thread_id; + bool handle_ms_vc_exception (const EXCEPTION_RECORD *rec); =20 - /* The target waitstatus we computed. */ - target_waitstatus status; - - /* The event. A few fields of this can be referenced after a stop, - and it seemed simplest to store the entire event. */ - DEBUG_EVENT event; -}; + /* When EXCEPTION_ACCESS_VIOLATION is processed, we give the embedding + application a chance to change it to be considered "unhandled". + This function must be supplied by the embedding application. If it + returns true, then the exception is "unhandled". */ =20 -/* A vector of pending stops. Sometimes, Windows will report a stop - on a thread that has been ostensibly suspended. We believe what - happens here is that two threads hit a breakpoint simultaneously, - and the Windows kernel queues the stop events. However, this can - result in the strange effect of trying to single step thread A -- - leaving all other threads suspended -- and then seeing a stop in - thread B. To handle this scenario, we queue all such "pending" - stops here, and then process them once the step has completed. See - PR gdb/22992. */ -extern std::vector pending_stops; + bool handle_access_violation (const EXCEPTION_RECORD *rec); =20 -/* Contents of $_siginfo */ -extern EXCEPTION_RECORD siginfo_er; + handle_exception_result handle_exception + (struct target_waitstatus *ourstatus, bool debug_exceptions); =20 -#ifdef __x86_64__ -/* The target is a WOW64 process */ -extern bool wow64_process; -/* Ignore first breakpoint exception of WOW64 process */ -extern bool ignore_first_breakpoint; -#endif + /* Call to indicate that a DLL was loaded. */ =20 -typedef enum -{ - HANDLE_EXCEPTION_UNHANDLED =3D 0, - HANDLE_EXCEPTION_HANDLED, - HANDLE_EXCEPTION_IGNORED -} handle_exception_result; + void dll_loaded_event (); =20 -extern handle_exception_result handle_exception - (struct target_waitstatus *ourstatus, bool debug_exceptions); + /* Iterate over all DLLs currently mapped by our inferior, and + add them to our list of solibs. */ =20 -/* Call to indicate that a DLL was loaded. */ + void add_all_dlls (); =20 -extern void dll_loaded_event (); + /* Return true if there is a pending stop matching + desired_stop_thread_id. If DEBUG_EVENTS is true, logging will be + enabled. */ =20 -/* Iterate over all DLLs currently mapped by our inferior, and - add them to our list of solibs. */ + bool matching_pending_stop (bool debug_events); =20 -extern void windows_add_all_dlls (); + /* See if a pending stop matches DESIRED_STOP_THREAD_ID. If so, + remove it from the list of pending stops, set 'current_event', and + return it. Otherwise, return an empty optional. */ =20 -/* Return true if there is a pending stop matching - desired_stop_thread_id. If DEBUG_EVENTS is true, logging will be - enabled. */ + gdb::optional fetch_pending_stop (bool debug_events); =20 -extern bool matching_pending_stop (bool debug_events); +private: =20 -/* See if a pending stop matches DESIRED_STOP_THREAD_ID. If so, - remove it from the list of pending stops, set 'current_event', and - return it. Otherwise, return an empty optional. */ + /* Iterate over all DLLs currently mapped by our inferior, looking for + a DLL which is loaded at LOAD_ADDR. If found, add the DLL to our + list of solibs; otherwise do nothing. LOAD_ADDR NULL means add all + DLLs to the list of solibs; this is used when the inferior finishes + its initialization, and all the DLLs it statically depends on are + presumed loaded. */ =20 -extern gdb::optional fetch_pending_stop (bool debug_events); + void add_dll (LPVOID load_addr); +}; =20 /* A simple wrapper for ContinueDebugEvent that continues the last waited-for event. If DEBUG_EVENTS is true, logging will be diff --git a/gdb/windows-nat.c b/gdb/windows-nat.c index e7324878031..44c1950ace9 100644 --- a/gdb/windows-nat.c +++ b/gdb/windows-nat.c @@ -74,6 +74,9 @@ =20 using namespace windows_nat; =20 +/* The current process. */ +static windows_process_info windows_process; + #undef STARTUPINFO #undef CreateProcess #undef GetModuleFileNameEx @@ -242,7 +245,7 @@ struct windows_nat_target final : public x86_nat_target= bool stopped_by_sw_breakpoint () override { windows_thread_info *th - =3D thread_rec (inferior_ptid, DONT_INVALIDATE_CONTEXT); + =3D windows_process.thread_rec (inferior_ptid, DONT_INVALIDATE_CONTE= XT); return th->stopped_at_software_breakpoint; } =20 @@ -317,7 +320,8 @@ check (BOOL ok, const char *file, int line) /* See nat/windows-nat.h. */ =20 windows_thread_info * -windows_nat::thread_rec (ptid_t ptid, thread_disposition_type disposition) +windows_nat::windows_process_info::thread_rec + (ptid_t ptid, thread_disposition_type disposition) { for (auto &th : thread_list) if (th->tid =3D=3D ptid.lwp ()) @@ -361,14 +365,14 @@ windows_add_thread (ptid_t ptid, HANDLE h, void *tlb,= bool main_thread_p) =20 gdb_assert (ptid.lwp () !=3D 0); =20 - if ((th =3D thread_rec (ptid, DONT_INVALIDATE_CONTEXT))) + if ((th =3D windows_process.thread_rec (ptid, DONT_INVALIDATE_CONTEXT))) return th; =20 CORE_ADDR base =3D (CORE_ADDR) (uintptr_t) tlb; #ifdef __x86_64__ /* For WOW64 processes, this is actually the pointer to the 64bit TIB, and the 32bit TIB is exactly 2 pages after it. */ - if (wow64_process) + if (windows_process.wow64_process) base +=3D 0x2000; #endif th =3D new windows_thread_info (ptid.lwp (), h, base); @@ -462,7 +466,7 @@ windows_fetch_one_register (struct regcache *regcache, =20 char *context_ptr =3D (char *) &th->context; #ifdef __x86_64__ - if (wow64_process) + if (windows_process.wow64_process) context_ptr =3D (char *) &th->wow64_context; #endif =20 @@ -524,7 +528,8 @@ windows_fetch_one_register (struct regcache *regcache, void windows_nat_target::fetch_registers (struct regcache *regcache, int r) { - windows_thread_info *th =3D thread_rec (regcache->ptid (), INVALIDATE_CO= NTEXT); + windows_thread_info *th + =3D windows_process.thread_rec (regcache->ptid (), INVALIDATE_CONTEXT); =20 /* Check if TH exists. Windows sometimes uses a non-existent thread id in its events. */ @@ -547,7 +552,7 @@ windows_nat_target::fetch_registers (struct regcache *r= egcache, int r) else #endif #ifdef __x86_64__ - if (wow64_process) + if (windows_process.wow64_process) { th->wow64_context.ContextFlags =3D CONTEXT_DEBUGGER_DR; CHECK (Wow64GetThreadContext (th->h, &th->wow64_context)); @@ -606,7 +611,7 @@ windows_store_one_register (const struct regcache *regc= ache, =20 char *context_ptr =3D (char *) &th->context; #ifdef __x86_64__ - if (wow64_process) + if (windows_process.wow64_process) context_ptr =3D (char *) &th->wow64_context; #endif =20 @@ -619,7 +624,8 @@ windows_store_one_register (const struct regcache *regc= ache, void windows_nat_target::store_registers (struct regcache *regcache, int r) { - windows_thread_info *th =3D thread_rec (regcache->ptid (), INVALIDATE_CO= NTEXT); + windows_thread_info *th + =3D windows_process.thread_rec (regcache->ptid (), INVALIDATE_CONTEXT); =20 /* Check if TH exists. Windows sometimes uses a non-existent thread id in its events. */ @@ -762,7 +768,8 @@ windows_make_so (const char *name, LPVOID load_addr) /* See nat/windows-nat.h. */ =20 void -windows_nat::handle_load_dll (const char *dll_name, LPVOID base) +windows_nat::windows_process_info::handle_load_dll (const char *dll_name, + LPVOID base) { windows_solib *solib =3D windows_make_so (dll_name, base); DEBUG_EVENTS ("Loading dll \"%s\" at %s.", solib->name.c_str (), @@ -772,7 +779,7 @@ windows_nat::handle_load_dll (const char *dll_name, LPV= OID base) /* See nat/windows-nat.h. */ =20 void -windows_nat::handle_unload_dll () +windows_nat::windows_process_info::handle_unload_dll () { LPVOID lpBaseOfDll =3D current_event.u.UnloadDll.lpBaseOfDll; =20 @@ -804,22 +811,6 @@ windows_nat::handle_unload_dll () host_address_to_string (lpBaseOfDll)); } =20 -/* Call FUNC wrapped in a TRY/CATCH that swallows all GDB - exceptions. */ - -static void -catch_errors (void (*func) ()) -{ - try - { - func (); - } - catch (const gdb_exception &ex) - { - exception_print (gdb_stderr, ex); - } -} - /* Clear list of loaded DLLs. */ static void windows_clear_solib (void) @@ -849,7 +840,8 @@ signal_event_command (const char *args, int from_tty) /* See nat/windows-nat.h. */ =20 int -windows_nat::handle_output_debug_string (struct target_waitstatus *ourstat= us) +windows_nat::windows_process_info::handle_output_debug_string + (struct target_waitstatus *ourstatus) { int retval =3D 0; =20 @@ -914,7 +906,7 @@ display_selector (HANDLE thread, DWORD sel) LDT_ENTRY info; BOOL ret; #ifdef __x86_64__ - if (wow64_process) + if (windows_process.wow64_process) ret =3D Wow64GetThreadSelectorEntry (thread, sel, &info); else #endif @@ -1003,12 +995,12 @@ display_selectors (const char * args, int from_tty) } =20 windows_thread_info *current_windows_thread - =3D thread_rec (inferior_ptid, DONT_INVALIDATE_CONTEXT); + =3D windows_process.thread_rec (inferior_ptid, DONT_INVALIDATE_CONTEXT= ); =20 if (!args) { #ifdef __x86_64__ - if (wow64_process) + if (windows_process.wow64_process) { gdb_puts ("Selector $cs\n"); display_selector (current_windows_thread->h, @@ -1064,7 +1056,8 @@ display_selectors (const char * args, int from_tty) /* See nat/windows-nat.h. */ =20 bool -windows_nat::handle_ms_vc_exception (const EXCEPTION_RECORD *rec) +windows_nat::windows_process_info::handle_ms_vc_exception + (const EXCEPTION_RECORD *rec) { if (rec->NumberParameters >=3D 3 && (rec->ExceptionInformation[0] & 0xffffffff) =3D=3D 0x1000) @@ -1103,7 +1096,8 @@ windows_nat::handle_ms_vc_exception (const EXCEPTION_= RECORD *rec) /* See nat/windows-nat.h. */ =20 bool -windows_nat::handle_access_violation (const EXCEPTION_RECORD *rec) +windows_nat::windows_process_info::handle_access_violation + (const EXCEPTION_RECORD *rec) { #ifdef __CYGWIN__ /* See if the access violation happened within the cygwin DLL @@ -1134,16 +1128,16 @@ windows_continue (DWORD continue_status, int id, in= t killed) { BOOL res; =20 - desired_stop_thread_id =3D id; + windows_process.desired_stop_thread_id =3D id; =20 - if (matching_pending_stop (debug_events)) + if (windows_process.matching_pending_stop (debug_events)) return TRUE; =20 for (auto &th : thread_list) if (id =3D=3D -1 || id =3D=3D (int) th->tid) { #ifdef __x86_64__ - if (wow64_process) + if (windows_process.wow64_process) { if (th->debug_registers_changed) { @@ -1225,9 +1219,10 @@ windows_continue (DWORD continue_status, int id, int= killed) static DWORD fake_create_process (void) { - current_process_handle =3D OpenProcess (PROCESS_ALL_ACCESS, FALSE, - current_event.dwProcessId); - if (current_process_handle !=3D NULL) + windows_process.handle + =3D OpenProcess (PROCESS_ALL_ACCESS, FALSE, + windows_process.current_event.dwProcessId); + if (windows_process.handle !=3D NULL) open_process_used =3D 1; else { @@ -1235,12 +1230,12 @@ fake_create_process (void) (unsigned) GetLastError ()); /* We can not debug anything in that case. */ } - windows_add_thread (ptid_t (current_event.dwProcessId, 0, - current_event.dwThreadId), - current_event.u.CreateThread.hThread, - current_event.u.CreateThread.lpThreadLocalBase, + windows_add_thread (ptid_t (windows_process.current_event.dwProcessId, 0, + windows_process.current_event.dwThreadId), + windows_process.current_event.u.CreateThread.hThread, + windows_process.current_event.u.CreateThread.lpThreadLocalBase, true /* main_thread_p */); - return current_event.dwThreadId; + return windows_process.current_event.dwThreadId; } =20 void @@ -1259,11 +1254,12 @@ windows_nat_target::resume (ptid_t ptid, int step, = enum gdb_signal sig) =20 if (sig !=3D GDB_SIGNAL_0) { - if (current_event.dwDebugEventCode !=3D EXCEPTION_DEBUG_EVENT) + if (windows_process.current_event.dwDebugEventCode + !=3D EXCEPTION_DEBUG_EVENT) { DEBUG_EXCEPT ("Cannot continue with signal %d here.", sig); } - else if (sig =3D=3D last_sig) + else if (sig =3D=3D windows_process.last_sig) continue_status =3D DBG_EXCEPTION_NOT_HANDLED; else #if 0 @@ -1287,20 +1283,20 @@ windows_nat_target::resume (ptid_t ptid, int step, = enum gdb_signal sig) } #endif DEBUG_EXCEPT ("Can only continue with received signal %d.", - last_sig); + windows_process.last_sig); } =20 - last_sig =3D GDB_SIGNAL_0; + windows_process.last_sig =3D GDB_SIGNAL_0; =20 DEBUG_EXEC ("pid=3D%d, tid=3D0x%x, step=3D%d, sig=3D%d", ptid.pid (), (unsigned) ptid.lwp (), step, sig); =20 /* Get context for currently selected thread. */ - th =3D thread_rec (inferior_ptid, DONT_INVALIDATE_CONTEXT); + th =3D windows_process.thread_rec (inferior_ptid, DONT_INVALIDATE_CONTEX= T); if (th) { #ifdef __x86_64__ - if (wow64_process) + if (windows_process.wow64_process) { if (step) { @@ -1385,7 +1381,7 @@ ctrl_c_handler (DWORD event_type) return TRUE; =20 #ifdef __x86_64__ - if (wow64_process) + if (windows_process.wow64_process) { /* Call DbgUiRemoteBreakin of the 32bit ntdll.dll in the target proc= ess. DebugBreakProcess would call the one of the 64bit ntdll.dll, which @@ -1400,7 +1396,7 @@ ctrl_c_handler (DWORD event_type) =20 if (wow64_dbgbreak !=3D nullptr) { - HANDLE thread =3D CreateRemoteThread (current_process_handle, NULL, + HANDLE thread =3D CreateRemoteThread (windows_process.handle, NULL, 0, (LPTHREAD_START_ROUTINE) wow64_dbgbreak, NULL, 0, NULL); if (thread) @@ -1410,7 +1406,7 @@ ctrl_c_handler (DWORD event_type) else #endif { - if (!DebugBreakProcess (current_process_handle)) + if (!DebugBreakProcess (windows_process.handle)) warning (_("Could not interrupt program. " "Press Ctrl-c in the program console.")); } @@ -1433,27 +1429,31 @@ windows_nat_target::get_windows_debug_event (int pi= d, /* If there is a relevant pending stop, report it now. See the comment by the definition of "pending_stops" for details on why this is needed. */ - gdb::optional stop =3D fetch_pending_stop (debug_events); + gdb::optional stop + =3D windows_process.fetch_pending_stop (debug_events); if (stop.has_value ()) { thread_id =3D stop->thread_id; *ourstatus =3D stop->status; =20 - ptid_t ptid (current_event.dwProcessId, thread_id); - windows_thread_info *th =3D thread_rec (ptid, INVALIDATE_CONTEXT); + ptid_t ptid (windows_process.current_event.dwProcessId, thread_id); + windows_thread_info *th + =3D windows_process.thread_rec (ptid, INVALIDATE_CONTEXT); th->reload_context =3D true; =20 return thread_id; } =20 - last_sig =3D GDB_SIGNAL_0; + windows_process.last_sig =3D GDB_SIGNAL_0; + DEBUG_EVENT *current_event =3D &windows_process.current_event; =20 - if (!(debug_event =3D wait_for_debug_event (¤t_event, 1000))) + if (!(debug_event =3D wait_for_debug_event (&windows_process.current_eve= nt, + 1000))) goto out; =20 continue_status =3D DBG_CONTINUE; =20 - event_code =3D current_event.dwDebugEventCode; + event_code =3D windows_process.current_event.dwDebugEventCode; ourstatus->set_spurious (); have_saved_context =3D 0; =20 @@ -1461,12 +1461,12 @@ windows_nat_target::get_windows_debug_event (int pi= d, { case CREATE_THREAD_DEBUG_EVENT: DEBUG_EVENTS ("kernel event for pid=3D%u tid=3D0x%x code=3D%s", - (unsigned) current_event.dwProcessId, - (unsigned) current_event.dwThreadId, + (unsigned) current_event->dwProcessId, + (unsigned) current_event->dwThreadId, "CREATE_THREAD_DEBUG_EVENT"); if (saw_create !=3D 1) { - inferior *inf =3D find_inferior_pid (this, current_event.dwProcessId); + inferior *inf =3D find_inferior_pid (this, current_event->dwProcessId); if (!saw_create && inf->attach_flag) { /* Kludge around a Windows bug where first event is a create @@ -1479,64 +1479,64 @@ windows_nat_target::get_windows_debug_event (int pi= d, break; } /* Record the existence of this thread. */ - thread_id =3D current_event.dwThreadId; + thread_id =3D current_event->dwThreadId; windows_add_thread - (ptid_t (current_event.dwProcessId, current_event.dwThreadId, 0), - current_event.u.CreateThread.hThread, - current_event.u.CreateThread.lpThreadLocalBase, + (ptid_t (current_event->dwProcessId, current_event->dwThreadId, 0), + current_event->u.CreateThread.hThread, + current_event->u.CreateThread.lpThreadLocalBase, false /* main_thread_p */); =20 break; =20 case EXIT_THREAD_DEBUG_EVENT: DEBUG_EVENTS ("kernel event for pid=3D%u tid=3D0x%x code=3D%s", - (unsigned) current_event.dwProcessId, - (unsigned) current_event.dwThreadId, + (unsigned) current_event->dwProcessId, + (unsigned) current_event->dwThreadId, "EXIT_THREAD_DEBUG_EVENT"); - windows_delete_thread (ptid_t (current_event.dwProcessId, - current_event.dwThreadId, 0), - current_event.u.ExitThread.dwExitCode, + windows_delete_thread (ptid_t (current_event->dwProcessId, + current_event->dwThreadId, 0), + current_event->u.ExitThread.dwExitCode, false /* main_thread_p */); break; =20 case CREATE_PROCESS_DEBUG_EVENT: DEBUG_EVENTS ("kernel event for pid=3D%u tid=3D0x%x code=3D%s", - (unsigned) current_event.dwProcessId, - (unsigned) current_event.dwThreadId, + (unsigned) current_event->dwProcessId, + (unsigned) current_event->dwThreadId, "CREATE_PROCESS_DEBUG_EVENT"); - CloseHandle (current_event.u.CreateProcessInfo.hFile); + CloseHandle (current_event->u.CreateProcessInfo.hFile); if (++saw_create !=3D 1) break; =20 - current_process_handle =3D current_event.u.CreateProcessInfo.hProces= s; + windows_process.handle =3D current_event->u.CreateProcessInfo.hProce= ss; /* Add the main thread. */ windows_add_thread - (ptid_t (current_event.dwProcessId, - current_event.dwThreadId, 0), - current_event.u.CreateProcessInfo.hThread, - current_event.u.CreateProcessInfo.lpThreadLocalBase, + (ptid_t (current_event->dwProcessId, + current_event->dwThreadId, 0), + current_event->u.CreateProcessInfo.hThread, + current_event->u.CreateProcessInfo.lpThreadLocalBase, true /* main_thread_p */); - thread_id =3D current_event.dwThreadId; + thread_id =3D current_event->dwThreadId; break; =20 case EXIT_PROCESS_DEBUG_EVENT: DEBUG_EVENTS ("kernel event for pid=3D%u tid=3D0x%x code=3D%s", - (unsigned) current_event.dwProcessId, - (unsigned) current_event.dwThreadId, + (unsigned) current_event->dwProcessId, + (unsigned) current_event->dwThreadId, "EXIT_PROCESS_DEBUG_EVENT"); if (!windows_initialization_done) { target_terminal::ours (); target_mourn_inferior (inferior_ptid); error (_("During startup program exited with code 0x%x."), - (unsigned int) current_event.u.ExitProcess.dwExitCode); + (unsigned int) current_event->u.ExitProcess.dwExitCode); } else if (saw_create =3D=3D 1) { - windows_delete_thread (ptid_t (current_event.dwProcessId, - current_event.dwThreadId, 0), + windows_delete_thread (ptid_t (current_event->dwProcessId, + current_event->dwThreadId, 0), 0, true /* main_thread_p */); - DWORD exit_status =3D current_event.u.ExitProcess.dwExitCode; + DWORD exit_status =3D current_event->u.ExitProcess.dwExitCode; /* If the exit status looks like a fatal exception, but we don't recognize the exception's code, make the original exit status value available, to avoid losing @@ -1548,50 +1548,64 @@ windows_nat_target::get_windows_debug_event (int pi= d, else ourstatus->set_signalled (gdb_signal_from_host (exit_signal)); =20 - thread_id =3D current_event.dwThreadId; + thread_id =3D current_event->dwThreadId; } break; =20 case LOAD_DLL_DEBUG_EVENT: DEBUG_EVENTS ("kernel event for pid=3D%u tid=3D0x%x code=3D%s", - (unsigned) current_event.dwProcessId, - (unsigned) current_event.dwThreadId, + (unsigned) current_event->dwProcessId, + (unsigned) current_event->dwThreadId, "LOAD_DLL_DEBUG_EVENT"); - CloseHandle (current_event.u.LoadDll.hFile); + CloseHandle (current_event->u.LoadDll.hFile); if (saw_create !=3D 1 || ! windows_initialization_done) break; - catch_errors (dll_loaded_event); + try + { + windows_process.dll_loaded_event (); + } + catch (const gdb_exception &ex) + { + exception_print (gdb_stderr, ex); + } ourstatus->set_loaded (); - thread_id =3D current_event.dwThreadId; + thread_id =3D current_event->dwThreadId; break; =20 case UNLOAD_DLL_DEBUG_EVENT: DEBUG_EVENTS ("kernel event for pid=3D%u tid=3D0x%x code=3D%s", - (unsigned) current_event.dwProcessId, - (unsigned) current_event.dwThreadId, + (unsigned) current_event->dwProcessId, + (unsigned) current_event->dwThreadId, "UNLOAD_DLL_DEBUG_EVENT"); if (saw_create !=3D 1 || ! windows_initialization_done) break; - catch_errors (handle_unload_dll); + try + { + windows_process.handle_unload_dll (); + } + catch (const gdb_exception &ex) + { + exception_print (gdb_stderr, ex); + } ourstatus->set_loaded (); - thread_id =3D current_event.dwThreadId; + thread_id =3D current_event->dwThreadId; break; =20 case EXCEPTION_DEBUG_EVENT: DEBUG_EVENTS ("kernel event for pid=3D%u tid=3D0x%x code=3D%s", - (unsigned) current_event.dwProcessId, - (unsigned) current_event.dwThreadId, + (unsigned) current_event->dwProcessId, + (unsigned) current_event->dwThreadId, "EXCEPTION_DEBUG_EVENT"); if (saw_create !=3D 1) break; - switch (handle_exception (ourstatus, debug_exceptions)) + switch (windows_process.handle_exception (ourstatus, debug_exception= s)) { case HANDLE_EXCEPTION_UNHANDLED: default: continue_status =3D DBG_EXCEPTION_NOT_HANDLED; break; case HANDLE_EXCEPTION_HANDLED: - thread_id =3D current_event.dwThreadId; + thread_id =3D current_event->dwThreadId; break; case HANDLE_EXCEPTION_IGNORED: continue_status =3D DBG_CONTINUE; @@ -1601,52 +1615,57 @@ windows_nat_target::get_windows_debug_event (int pi= d, =20 case OUTPUT_DEBUG_STRING_EVENT: /* Message from the kernel. */ DEBUG_EVENTS ("kernel event for pid=3D%u tid=3D0x%x code=3D%s", - (unsigned) current_event.dwProcessId, - (unsigned) current_event.dwThreadId, + (unsigned) current_event->dwProcessId, + (unsigned) current_event->dwThreadId, "OUTPUT_DEBUG_STRING_EVENT"); if (saw_create !=3D 1) break; - thread_id =3D handle_output_debug_string (ourstatus); + thread_id =3D windows_process.handle_output_debug_string (ourstatus); break; =20 default: if (saw_create !=3D 1) break; gdb_printf ("gdb: kernel event for pid=3D%u tid=3D0x%x\n", - (unsigned) current_event.dwProcessId, - (unsigned) current_event.dwThreadId); + (unsigned) current_event->dwProcessId, + (unsigned) current_event->dwThreadId); gdb_printf (" unknown event code %u\n", - (unsigned) current_event.dwDebugEventCode); + (unsigned) current_event->dwDebugEventCode); break; } =20 if (!thread_id || saw_create !=3D 1) { - CHECK (windows_continue (continue_status, desired_stop_thread_id, 0)= ); + CHECK (windows_continue (continue_status, + windows_process.desired_stop_thread_id, 0)); } - else if (desired_stop_thread_id !=3D -1 && desired_stop_thread_id !=3D t= hread_id) + else if (windows_process.desired_stop_thread_id !=3D -1 + && windows_process.desired_stop_thread_id !=3D thread_id) { /* Pending stop. See the comment by the definition of "pending_stops" for details on why this is needed. */ DEBUG_EVENTS ("get_windows_debug_event - " "unexpected stop in 0x%x (expecting 0x%x)", - thread_id, desired_stop_thread_id); + thread_id, windows_process.desired_stop_thread_id); =20 - if (current_event.dwDebugEventCode =3D=3D EXCEPTION_DEBUG_EVENT - && ((current_event.u.Exception.ExceptionRecord.ExceptionCode + if (current_event->dwDebugEventCode =3D=3D EXCEPTION_DEBUG_EVENT + && ((current_event->u.Exception.ExceptionRecord.ExceptionCode =3D=3D EXCEPTION_BREAKPOINT) - || (current_event.u.Exception.ExceptionRecord.ExceptionCode + || (current_event->u.Exception.ExceptionRecord.ExceptionCode =3D=3D STATUS_WX86_BREAKPOINT)) && windows_initialization_done) { - ptid_t ptid =3D ptid_t (current_event.dwProcessId, thread_id, 0); - windows_thread_info *th =3D thread_rec (ptid, INVALIDATE_CONTEXT); + ptid_t ptid =3D ptid_t (current_event->dwProcessId, thread_id, 0); + windows_thread_info *th + =3D windows_process.thread_rec (ptid, INVALIDATE_CONTEXT); th->stopped_at_software_breakpoint =3D true; th->pc_adjusted =3D false; } - pending_stops.push_back ({thread_id, *ourstatus, current_event}); + windows_process.pending_stops.push_back + ({thread_id, *ourstatus, windows_process.current_event}); thread_id =3D 0; - CHECK (windows_continue (continue_status, desired_stop_thread_id, 0)= ); + CHECK (windows_continue (continue_status, + windows_process.desired_stop_thread_id, 0)); } =20 out: @@ -1702,20 +1721,23 @@ windows_nat_target::wait (ptid_t ptid, struct targe= t_waitstatus *ourstatus, =20 if (retval) { - ptid_t result =3D ptid_t (current_event.dwProcessId, retval, 0); + ptid_t result =3D ptid_t (windows_process.current_event.dwProcessId, + retval, 0); =20 if (ourstatus->kind () !=3D TARGET_WAITKIND_EXITED && ourstatus->kind () !=3D TARGET_WAITKIND_SIGNALLED) { - windows_thread_info *th =3D thread_rec (result, INVALIDATE_CONTEXT); + windows_thread_info *th + =3D windows_process.thread_rec (result, INVALIDATE_CONTEXT); =20 if (th !=3D nullptr) { th->stopped_at_software_breakpoint =3D false; - if (current_event.dwDebugEventCode =3D=3D EXCEPTION_DEBUG_EVENT - && ((current_event.u.Exception.ExceptionRecord.ExceptionCode + if (windows_process.current_event.dwDebugEventCode + =3D=3D EXCEPTION_DEBUG_EVENT + && ((windows_process.current_event.u.Exception.ExceptionRecord.Exc= eptionCode =3D=3D EXCEPTION_BREAKPOINT) - || (current_event.u.Exception.ExceptionRecord.ExceptionCode + || (windows_process.current_event.u.Exception.ExceptionRecord.Excepti= onCode =3D=3D STATUS_WX86_BREAKPOINT)) && windows_initialization_done) { @@ -1746,15 +1768,16 @@ windows_nat_target::do_initial_windows_stuff (DWORD= pid, bool attaching) int i; struct inferior *inf; =20 - last_sig =3D GDB_SIGNAL_0; + windows_process.last_sig =3D GDB_SIGNAL_0; open_process_used =3D 0; for (i =3D 0; i < sizeof (dr) / sizeof (dr[0]); i++) dr[i] =3D 0; #ifdef __CYGWIN__ cygwin_load_start =3D cygwin_load_end =3D 0; #endif - current_event.dwProcessId =3D pid; - memset (¤t_event, 0, sizeof (current_event)); + windows_process.current_event.dwProcessId =3D pid; + memset (&windows_process.current_event, 0, + sizeof (windows_process.current_event)); inf =3D current_inferior (); if (!inf->target_is_pushed (this)) inf->push_target (this); @@ -1764,9 +1787,10 @@ windows_nat_target::do_initial_windows_stuff (DWORD = pid, bool attaching) init_wait_for_inferior (); =20 #ifdef __x86_64__ - ignore_first_breakpoint =3D !attaching && wow64_process; + windows_process.ignore_first_breakpoint + =3D !attaching && windows_process.wow64_process; =20 - if (!wow64_process) + if (!windows_process.wow64_process) { windows_set_context_register_offsets (amd64_mappings); windows_set_segment_register_p (amd64_windows_segment_register_p); @@ -1820,7 +1844,7 @@ windows_nat_target::do_initial_windows_stuff (DWORD p= id, bool attaching) Rather than try to work around this sort of issue, it is much simpler to just ignore DLL load/unload events during the startup phase, and then process them all in one batch now. */ - windows_add_all_dlls (); + windows_process.add_all_dlls (); =20 windows_initialization_done =3D 1; return; @@ -1918,7 +1942,7 @@ windows_nat_target::attach (const char *args, int fro= m_tty) { BOOL wow64; if (IsWow64Process (h, &wow64)) - wow64_process =3D wow64; + windows_process.wow64_process =3D wow64; CloseHandle (h); } #endif @@ -1935,10 +1959,11 @@ windows_nat_target::detach (inferior *inf, int from= _tty) ptid_t ptid =3D minus_one_ptid; resume (ptid, 0, GDB_SIGNAL_0); =20 - if (!DebugActiveProcessStop (current_event.dwProcessId)) + if (!DebugActiveProcessStop (windows_process.current_event.dwProcessId)) { error (_("Can't detach process %u (error %u)"), - (unsigned) current_event.dwProcessId, (unsigned) GetLastError ()); + (unsigned) windows_process.current_event.dwProcessId, + (unsigned) GetLastError ()); detached =3D 0; } DebugSetProcessKillOnExit (FALSE); @@ -1972,18 +1997,20 @@ windows_get_exec_module_filename (char *exe_name_re= t, size_t exe_name_max_len) =20 cbNeeded =3D 0; #ifdef __x86_64__ - if (wow64_process) + if (windows_process.wow64_process) { - if (!EnumProcessModulesEx (current_process_handle, &dh_buf, - sizeof (HMODULE), &cbNeeded, - LIST_MODULES_32BIT) || !cbNeeded) + if (!EnumProcessModulesEx (windows_process.handle, + &dh_buf, sizeof (HMODULE), &cbNeeded, + LIST_MODULES_32BIT) + || !cbNeeded) return 0; } else #endif { - if (!EnumProcessModules (current_process_handle, &dh_buf, - sizeof (HMODULE), &cbNeeded) || !cbNeeded) + if (!EnumProcessModules (windows_process.handle, + &dh_buf, sizeof (HMODULE), &cbNeeded) + || !cbNeeded) return 0; } =20 @@ -2007,7 +2034,7 @@ windows_get_exec_module_filename (char *exe_name_ret,= size_t exe_name_max_len) error (_("Error converting executable filename to POSIX: %d."), errn= o); } #else - len =3D GetModuleFileNameEx (current_process_handle, + len =3D GetModuleFileNameEx (windows_process.handle, dh_buf, exe_name_ret, exe_name_max_len); if (len =3D=3D 0) error (_("Error getting executable filename: %u."), @@ -2748,7 +2775,7 @@ windows_nat_target::create_inferior (const char *exec= _file, #ifdef __x86_64__ BOOL wow64; if (IsWow64Process (pi.hProcess, &wow64)) - wow64_process =3D wow64; + windows_process.wow64_process =3D wow64; #endif =20 CloseHandle (pi.hThread); @@ -2771,10 +2798,10 @@ windows_nat_target::mourn_inferior () x86_cleanup_dregs(); if (open_process_used) { - CHECK (CloseHandle (current_process_handle)); + CHECK (CloseHandle (windows_process.handle)); open_process_used =3D 0; } - siginfo_er.ExceptionCode =3D 0; + windows_process.siginfo_er.ExceptionCode =3D 0; inf_child_target::mourn_inferior (); } =20 @@ -2785,7 +2812,8 @@ void windows_nat_target::interrupt () { DEBUG_EVENTS ("GenerateConsoleCtrlEvent (CTRLC_EVENT, 0)"); - CHECK (GenerateConsoleCtrlEvent (CTRL_C_EVENT, current_event.dwProcessId= )); + CHECK (GenerateConsoleCtrlEvent (CTRL_C_EVENT, + windows_process.current_event.dwProcessId)); registers_changed (); /* refresh register state */ } =20 @@ -2804,19 +2832,19 @@ windows_xfer_memory (gdb_byte *readbuf, const gdb_b= yte *writebuf, { DEBUG_MEM ("write target memory, %s bytes at %s", pulongest (len), core_addr_to_string (memaddr)); - success =3D WriteProcessMemory (current_process_handle, + success =3D WriteProcessMemory (windows_process.handle, (LPVOID) (uintptr_t) memaddr, writebuf, len, &done); if (!success) lasterror =3D GetLastError (); - FlushInstructionCache (current_process_handle, + FlushInstructionCache (windows_process.handle, (LPCVOID) (uintptr_t) memaddr, len); } else { DEBUG_MEM ("read target memory, %s bytes at %s", pulongest (len), core_addr_to_string (memaddr)); - success =3D ReadProcessMemory (current_process_handle, + success =3D ReadProcessMemory (windows_process.handle, (LPCVOID) (uintptr_t) memaddr, readbuf, len, &done); if (!success) @@ -2832,15 +2860,16 @@ windows_xfer_memory (gdb_byte *readbuf, const gdb_b= yte *writebuf, void windows_nat_target::kill () { - CHECK (TerminateProcess (current_process_handle, 0)); + CHECK (TerminateProcess (windows_process.handle, 0)); =20 for (;;) { if (!windows_continue (DBG_CONTINUE, -1, 1)) break; - if (!wait_for_debug_event (¤t_event, INFINITE)) + if (!wait_for_debug_event (&windows_process.current_event, INFINITE)) break; - if (current_event.dwDebugEventCode =3D=3D EXIT_PROCESS_DEBUG_EVENT) + if (windows_process.current_event.dwDebugEventCode + =3D=3D EXIT_PROCESS_DEBUG_EVENT) break; } =20 @@ -2906,28 +2935,31 @@ static enum target_xfer_status windows_xfer_siginfo (gdb_byte *readbuf, ULONGEST offset, ULONGEST len, ULONGEST *xfered_len) { - char *buf =3D (char *) &siginfo_er; - size_t bufsize =3D sizeof (siginfo_er); + char *buf =3D (char *) &windows_process.siginfo_er; + size_t bufsize =3D sizeof (windows_process.siginfo_er); =20 #ifdef __x86_64__ EXCEPTION_RECORD32 er32; - if (wow64_process) + if (windows_process.wow64_process) { buf =3D (char *) &er32; bufsize =3D sizeof (er32); =20 - er32.ExceptionCode =3D siginfo_er.ExceptionCode; - er32.ExceptionFlags =3D siginfo_er.ExceptionFlags; - er32.ExceptionRecord =3D (uintptr_t) siginfo_er.ExceptionRecord; - er32.ExceptionAddress =3D (uintptr_t) siginfo_er.ExceptionAddress; - er32.NumberParameters =3D siginfo_er.NumberParameters; + er32.ExceptionCode =3D windows_process.siginfo_er.ExceptionCode; + er32.ExceptionFlags =3D windows_process.siginfo_er.ExceptionFlags; + er32.ExceptionRecord + =3D (uintptr_t) windows_process.siginfo_er.ExceptionRecord; + er32.ExceptionAddress + =3D (uintptr_t) windows_process.siginfo_er.ExceptionAddress; + er32.NumberParameters =3D windows_process.siginfo_er.NumberParameter= s; int i; for (i =3D 0; i < EXCEPTION_MAXIMUM_PARAMETERS; i++) - er32.ExceptionInformation[i] =3D siginfo_er.ExceptionInformation[i]; + er32.ExceptionInformation[i] + =3D windows_process.siginfo_er.ExceptionInformation[i]; } #endif =20 - if (siginfo_er.ExceptionCode =3D=3D 0) + if (windows_process.siginfo_er.ExceptionCode =3D=3D 0) return TARGET_XFER_E_IO; =20 if (readbuf =3D=3D nullptr) @@ -2985,7 +3017,7 @@ windows_nat_target::get_tib_address (ptid_t ptid, COR= E_ADDR *addr) { windows_thread_info *th; =20 - th =3D thread_rec (ptid, DONT_INVALIDATE_CONTEXT); + th =3D windows_process.thread_rec (ptid, DONT_INVALIDATE_CONTEXT); if (th =3D=3D NULL) return false; =20 @@ -3006,7 +3038,8 @@ windows_nat_target::get_ada_task_ptid (long lwp, ULON= GEST thread) const char * windows_nat_target::thread_name (struct thread_info *thr) { - return thread_rec (thr->ptid, DONT_INVALIDATE_CONTEXT)->name.get (); + return windows_process.thread_rec (thr->ptid, + DONT_INVALIDATE_CONTEXT)->name.get (); } =20 =20 @@ -3178,8 +3211,9 @@ windows_nat_target::thread_alive (ptid_t ptid) { gdb_assert (ptid.lwp () !=3D 0); =20 - return (WaitForSingleObject (thread_rec (ptid, DONT_INVALIDATE_CONTEXT)-= >h, 0) - !=3D WAIT_OBJECT_0); + windows_thread_info *th + =3D windows_process.thread_rec (ptid, DONT_INVALIDATE_CONTEXT); + return WaitForSingleObject (th->h, 0) !=3D WAIT_OBJECT_0; } =20 void _initialize_check_for_gdb_ini (); diff --git a/gdbserver/win32-low.cc b/gdbserver/win32-low.cc index e19bc2bd6e8..8437c69e1cc 100644 --- a/gdbserver/win32-low.cc +++ b/gdbserver/win32-low.cc @@ -38,6 +38,8 @@ =20 using namespace windows_nat; =20 +static windows_process_info windows_process; + #ifndef USE_WIN32API #include #endif @@ -163,7 +165,8 @@ win32_require_context (windows_thread_info *th) /* See nat/windows-nat.h. */ =20 windows_thread_info * -windows_nat::thread_rec (ptid_t ptid, thread_disposition_type disposition) +windows_nat::windows_process_info::thread_rec + (ptid_t ptid, thread_disposition_type disposition) { thread_info *thread =3D find_thread_ptid (ptid); if (thread =3D=3D NULL) @@ -182,7 +185,7 @@ child_add_thread (DWORD pid, DWORD tid, HANDLE h, void = *tlb) windows_thread_info *th; ptid_t ptid =3D ptid_t (pid, tid, 0); =20 - if ((th =3D thread_rec (ptid, DONT_INVALIDATE_CONTEXT))) + if ((th =3D windows_process.thread_rec (ptid, DONT_INVALIDATE_CONTEXT))) return th; =20 CORE_ADDR base =3D (CORE_ADDR) (uintptr_t) tlb; @@ -295,15 +298,15 @@ child_xfer_memory (CORE_ADDR memaddr, char *our, int = len, =20 if (write) { - success =3D WriteProcessMemory (current_process_handle, (LPVOID) add= r, + success =3D WriteProcessMemory (windows_process.handle, (LPVOID) add= r, (LPCVOID) our, len, &done); if (!success) lasterror =3D GetLastError (); - FlushInstructionCache (current_process_handle, (LPCVOID) addr, len); + FlushInstructionCache (windows_process.handle, (LPCVOID) addr, len); } else { - success =3D ReadProcessMemory (current_process_handle, (LPCVOID) add= r, + success =3D ReadProcessMemory (windows_process.handle, (LPCVOID) add= r, (LPVOID) our, len, &done); if (!success) lasterror =3D GetLastError (); @@ -331,17 +334,17 @@ do_initial_child_stuff (HANDLE proch, DWORD pid, int = attached) { struct process_info *proc; =20 - last_sig =3D GDB_SIGNAL_0; - - current_process_handle =3D proch; - current_process_id =3D pid; - main_thread_id =3D 0; + windows_process.last_sig =3D GDB_SIGNAL_0; + windows_process.handle =3D proch; + windows_process.id =3D pid; + windows_process.main_thread_id =3D 0; =20 soft_interrupt_requested =3D 0; faked_breakpoint =3D 0; open_process_used =3D true; =20 - memset (¤t_event, 0, sizeof (current_event)); + memset (&windows_process.current_event, 0, + sizeof (windows_process.current_event)); =20 #ifdef __x86_64__ BOOL wow64; @@ -417,7 +420,7 @@ do_initial_child_stuff (HANDLE proch, DWORD pid, int at= tached) Rather than try to work around this sort of issue, it is much simpler to just ignore DLL load/unload events during the startup phase, and then process them all in one batch now. */ - windows_add_all_dlls (); + windows_process.add_all_dlls (); =20 child_initialization_done =3D 1; } @@ -456,8 +459,8 @@ continue_one_thread (thread_info *thread, int thread_id) static BOOL child_continue (DWORD continue_status, int thread_id) { - desired_stop_thread_id =3D thread_id; - if (matching_pending_stop (debug_threads)) + windows_process.desired_stop_thread_id =3D thread_id; + if (windows_process.matching_pending_stop (debug_threads)) return TRUE; =20 /* The inferior will only continue after the ContinueDebugEvent @@ -476,8 +479,9 @@ static void child_fetch_inferior_registers (struct regcache *regcache, int r) { int regno; - windows_thread_info *th =3D thread_rec (current_thread_ptid (), - INVALIDATE_CONTEXT); + windows_thread_info *th + =3D windows_process.thread_rec (current_thread_ptid (), + INVALIDATE_CONTEXT); if (r =3D=3D -1 || r > NUM_REGS) child_fetch_inferior_registers (regcache, NUM_REGS); else @@ -491,8 +495,9 @@ static void child_store_inferior_registers (struct regcache *regcache, int r) { int regno; - windows_thread_info *th =3D thread_rec (current_thread_ptid (), - INVALIDATE_CONTEXT); + windows_thread_info *th + =3D windows_process.thread_rec (current_thread_ptid (), + INVALIDATE_CONTEXT); if (r =3D=3D -1 || r =3D=3D 0 || r > NUM_REGS) child_store_inferior_registers (regcache, NUM_REGS); else @@ -671,12 +676,12 @@ win32_process_target::create_inferior (const char *pr= ogram, =20 /* Wait till we are at 1st instruction in program, return new pid (assuming success). */ - cs.last_ptid =3D wait (ptid_t (current_process_id), &cs.last_status, 0); + cs.last_ptid =3D wait (ptid_t (windows_process.id), &cs.last_status, 0); =20 /* Necessary for handle_v_kill. */ - signal_pid =3D current_process_id; + signal_pid =3D windows_process.id; =20 - return current_process_id; + return windows_process.id; } =20 /* Attach to a running process. @@ -712,7 +717,8 @@ win32_process_target::attach (unsigned long pid) /* See nat/windows-nat.h. */ =20 int -windows_nat::handle_output_debug_string (struct target_waitstatus *ourstat= us) +windows_nat::windows_process_info::handle_output_debug_string + (struct target_waitstatus *ourstatus) { #define READ_BUFFER_LEN 1024 CORE_ADDR addr; @@ -762,12 +768,12 @@ win32_clear_inferiors (void) { if (open_process_used) { - CloseHandle (current_process_handle); + CloseHandle (windows_process.handle); open_process_used =3D false; } =20 for_each_thread (delete_thread_info); - siginfo_er.ExceptionCode =3D 0; + windows_process.siginfo_er.ExceptionCode =3D 0; clear_inferiors (); } =20 @@ -776,17 +782,19 @@ win32_clear_inferiors (void) int win32_process_target::kill (process_info *process) { - TerminateProcess (current_process_handle, 0); + TerminateProcess (windows_process.handle, 0); for (;;) { if (!child_continue (DBG_CONTINUE, -1)) break; - if (!wait_for_debug_event (¤t_event, INFINITE)) + if (!wait_for_debug_event (&windows_process.current_event, INFINITE)) break; - if (current_event.dwDebugEventCode =3D=3D EXIT_PROCESS_DEBUG_EVENT) + if (windows_process.current_event.dwDebugEventCode + =3D=3D EXIT_PROCESS_DEBUG_EVENT) break; - else if (current_event.dwDebugEventCode =3D=3D OUTPUT_DEBUG_STRING_E= VENT) - handle_output_debug_string (nullptr); + else if (windows_process.current_event.dwDebugEventCode + =3D=3D OUTPUT_DEBUG_STRING_EVENT) + windows_process.handle_output_debug_string (nullptr); } =20 win32_clear_inferiors (); @@ -806,7 +814,7 @@ win32_process_target::detach (process_info *process) resume.sig =3D 0; this->resume (&resume, 1); =20 - if (!DebugActiveProcessStop (current_process_id)) + if (!DebugActiveProcessStop (windows_process.id)) return -1; =20 DebugSetProcessKillOnExit (FALSE); @@ -866,7 +874,7 @@ win32_process_target::resume (thread_resume *resume_inf= o, size_t n) else /* Yes, we're ignoring resume_info[0].thread. It'd be tricky to make the Windows resume code do the right thing for thread switching. */ - tid =3D current_event.dwThreadId; + tid =3D windows_process.current_event.dwThreadId; =20 if (resume_info[0].thread !=3D minus_one_ptid) { @@ -881,23 +889,24 @@ win32_process_target::resume (thread_resume *resume_i= nfo, size_t n) =20 if (sig !=3D GDB_SIGNAL_0) { - if (current_event.dwDebugEventCode !=3D EXCEPTION_DEBUG_EVENT) + if (windows_process.current_event.dwDebugEventCode + !=3D EXCEPTION_DEBUG_EVENT) { OUTMSG (("Cannot continue with signal %s here.\n", gdb_signal_to_string (sig))); } - else if (sig =3D=3D last_sig) + else if (sig =3D=3D windows_process.last_sig) continue_status =3D DBG_EXCEPTION_NOT_HANDLED; else OUTMSG (("Can only continue with received signal %s.\n", - gdb_signal_to_string (last_sig))); + gdb_signal_to_string (windows_process.last_sig))); } =20 - last_sig =3D GDB_SIGNAL_0; + windows_process.last_sig =3D GDB_SIGNAL_0; =20 /* Get context for the currently selected thread. */ - ptid =3D debug_event_ptid (¤t_event); - th =3D thread_rec (ptid, DONT_INVALIDATE_CONTEXT); + ptid =3D debug_event_ptid (&windows_process.current_event); + th =3D windows_process.thread_rec (ptid, DONT_INVALIDATE_CONTEXT); if (th) { win32_prepare_to_resume (th); @@ -938,7 +947,8 @@ win32_process_target::resume (thread_resume *resume_inf= o, size_t n) /* See nat/windows-nat.h. */ =20 void -windows_nat::handle_load_dll (const char *name, LPVOID base) +windows_nat::windows_process_info::handle_load_dll (const char *name, + LPVOID base) { CORE_ADDR load_addr =3D (CORE_ADDR) (uintptr_t) base; =20 @@ -992,7 +1002,7 @@ windows_nat::handle_load_dll (const char *name, LPVOID= base) /* See nat/windows-nat.h. */ =20 void -windows_nat::handle_unload_dll () +windows_nat::windows_process_info::handle_unload_dll () { CORE_ADDR load_addr =3D (CORE_ADDR) (uintptr_t) current_event.u.UnloadDll.lpBaseOfDll; @@ -1019,10 +1029,11 @@ fake_breakpoint_event (void) =20 faked_breakpoint =3D 1; =20 - memset (¤t_event, 0, sizeof (current_event)); - current_event.dwThreadId =3D main_thread_id; - current_event.dwDebugEventCode =3D EXCEPTION_DEBUG_EVENT; - current_event.u.Exception.ExceptionRecord.ExceptionCode + memset (&windows_process.current_event, 0, + sizeof (windows_process.current_event)); + windows_process.current_event.dwThreadId =3D windows_process.main_thread= _id; + windows_process.current_event.dwDebugEventCode =3D EXCEPTION_DEBUG_EVENT; + windows_process.current_event.u.Exception.ExceptionRecord.ExceptionCode =3D EXCEPTION_BREAKPOINT; =20 for_each_thread (suspend_one_thread); @@ -1031,7 +1042,8 @@ fake_breakpoint_event (void) /* See nat/windows-nat.h. */ =20 bool -windows_nat::handle_ms_vc_exception (const EXCEPTION_RECORD *rec) +windows_nat::windows_process_info::handle_ms_vc_exception + (const EXCEPTION_RECORD *rec) { return false; } @@ -1039,7 +1051,8 @@ windows_nat::handle_ms_vc_exception (const EXCEPTION_= RECORD *rec) /* See nat/windows-nat.h. */ =20 bool -windows_nat::handle_access_violation (const EXCEPTION_RECORD *rec) +windows_nat::windows_process_info::handle_access_violation + (const EXCEPTION_RECORD *rec) { return false; } @@ -1054,14 +1067,15 @@ maybe_adjust_pc () struct regcache *regcache =3D get_thread_regcache (current_thread, 1); child_fetch_inferior_registers (regcache, -1); =20 - windows_thread_info *th =3D thread_rec (current_thread_ptid (), - DONT_INVALIDATE_CONTEXT); + windows_thread_info *th + =3D windows_process.thread_rec (current_thread_ptid (), + DONT_INVALIDATE_CONTEXT); th->stopped_at_software_breakpoint =3D false; =20 - if (current_event.dwDebugEventCode =3D=3D EXCEPTION_DEBUG_EVENT - && ((current_event.u.Exception.ExceptionRecord.ExceptionCode + if (windows_process.current_event.dwDebugEventCode =3D=3D EXCEPTION_DEBU= G_EVENT + && ((windows_process.current_event.u.Exception.ExceptionRecord.Excep= tionCode =3D=3D EXCEPTION_BREAKPOINT) - || (current_event.u.Exception.ExceptionRecord.ExceptionCode + || (windows_process.current_event.u.Exception.ExceptionRecord.Exception= Code =3D=3D STATUS_WX86_BREAKPOINT)) && child_initialization_done) { @@ -1080,13 +1094,15 @@ get_child_debug_event (DWORD *continue_status, { ptid_t ptid; =20 - last_sig =3D GDB_SIGNAL_0; + windows_process.last_sig =3D GDB_SIGNAL_0; ourstatus->set_spurious (); *continue_status =3D DBG_CONTINUE; =20 /* Check if GDB sent us an interrupt request. */ check_remote_input_interrupt_request (); =20 + DEBUG_EVENT *current_event =3D &windows_process.current_event; + if (soft_interrupt_requested) { soft_interrupt_requested =3D 0; @@ -1096,12 +1112,13 @@ get_child_debug_event (DWORD *continue_status, =20 attaching =3D 0; { - gdb::optional stop =3D fetch_pending_stop (debug_threads= ); + gdb::optional stop + =3D windows_process.fetch_pending_stop (debug_threads); if (stop.has_value ()) { *ourstatus =3D stop->status; - current_event =3D stop->event; - ptid =3D debug_event_ptid (¤t_event); + windows_process.current_event =3D stop->event; + ptid =3D debug_event_ptid (&windows_process.current_event); switch_to_thread (find_thread_ptid (ptid)); return 1; } @@ -1109,7 +1126,7 @@ get_child_debug_event (DWORD *continue_status, /* Keep the wait time low enough for comfortable remote interruption, but high enough so gdbserver doesn't become a bottleneck. */ - if (!wait_for_debug_event (¤t_event, 250)) + if (!wait_for_debug_event (&windows_process.current_event, 250)) { DWORD e =3D GetLastError(); =20 @@ -1129,28 +1146,28 @@ get_child_debug_event (DWORD *continue_status, =20 gotevent: =20 - switch (current_event.dwDebugEventCode) + switch (current_event->dwDebugEventCode) { case CREATE_THREAD_DEBUG_EVENT: OUTMSG2 (("gdbserver: kernel event CREATE_THREAD_DEBUG_EVENT " "for pid=3D%u tid=3D%x)\n", - (unsigned) current_event.dwProcessId, - (unsigned) current_event.dwThreadId)); + (unsigned) current_event->dwProcessId, + (unsigned) current_event->dwThreadId)); =20 /* Record the existence of this thread. */ - child_add_thread (current_event.dwProcessId, - current_event.dwThreadId, - current_event.u.CreateThread.hThread, - current_event.u.CreateThread.lpThreadLocalBase); + child_add_thread (current_event->dwProcessId, + current_event->dwThreadId, + current_event->u.CreateThread.hThread, + current_event->u.CreateThread.lpThreadLocalBase); break; =20 case EXIT_THREAD_DEBUG_EVENT: OUTMSG2 (("gdbserver: kernel event EXIT_THREAD_DEBUG_EVENT " "for pid=3D%u tid=3D%x\n", - (unsigned) current_event.dwProcessId, - (unsigned) current_event.dwThreadId)); - child_delete_thread (current_event.dwProcessId, - current_event.dwThreadId); + (unsigned) current_event->dwProcessId, + (unsigned) current_event->dwThreadId)); + child_delete_thread (current_event->dwProcessId, + current_event->dwThreadId); =20 switch_to_thread (get_first_thread ()); return 1; @@ -1158,33 +1175,33 @@ get_child_debug_event (DWORD *continue_status, case CREATE_PROCESS_DEBUG_EVENT: OUTMSG2 (("gdbserver: kernel event CREATE_PROCESS_DEBUG_EVENT " "for pid=3D%u tid=3D%x\n", - (unsigned) current_event.dwProcessId, - (unsigned) current_event.dwThreadId)); - CloseHandle (current_event.u.CreateProcessInfo.hFile); + (unsigned) current_event->dwProcessId, + (unsigned) current_event->dwThreadId)); + CloseHandle (current_event->u.CreateProcessInfo.hFile); =20 if (open_process_used) { - CloseHandle (current_process_handle); + CloseHandle (windows_process.handle); open_process_used =3D false; } =20 - current_process_handle =3D current_event.u.CreateProcessInfo.hProces= s; - main_thread_id =3D current_event.dwThreadId; + windows_process.handle =3D current_event->u.CreateProcessInfo.hProce= ss; + windows_process.main_thread_id =3D current_event->dwThreadId; =20 /* Add the main thread. */ - child_add_thread (current_event.dwProcessId, - main_thread_id, - current_event.u.CreateProcessInfo.hThread, - current_event.u.CreateProcessInfo.lpThreadLocalBase); + child_add_thread (current_event->dwProcessId, + windows_process.main_thread_id, + current_event->u.CreateProcessInfo.hThread, + current_event->u.CreateProcessInfo.lpThreadLocalBase); break; =20 case EXIT_PROCESS_DEBUG_EVENT: OUTMSG2 (("gdbserver: kernel event EXIT_PROCESS_DEBUG_EVENT " "for pid=3D%u tid=3D%x\n", - (unsigned) current_event.dwProcessId, - (unsigned) current_event.dwThreadId)); + (unsigned) current_event->dwProcessId, + (unsigned) current_event->dwThreadId)); { - DWORD exit_status =3D current_event.u.ExitProcess.dwExitCode; + DWORD exit_status =3D current_event->u.ExitProcess.dwExitCode; /* If the exit status looks like a fatal exception, but we don't recognize the exception's code, make the original exit status value available, to avoid losing information. */ @@ -1195,18 +1212,18 @@ get_child_debug_event (DWORD *continue_status, else ourstatus->set_signalled (gdb_signal_from_host (exit_signal)); } - child_continue (DBG_CONTINUE, desired_stop_thread_id); + child_continue (DBG_CONTINUE, windows_process.desired_stop_thread_id= ); break; =20 case LOAD_DLL_DEBUG_EVENT: OUTMSG2 (("gdbserver: kernel event LOAD_DLL_DEBUG_EVENT " "for pid=3D%u tid=3D%x\n", - (unsigned) current_event.dwProcessId, - (unsigned) current_event.dwThreadId)); - CloseHandle (current_event.u.LoadDll.hFile); + (unsigned) current_event->dwProcessId, + (unsigned) current_event->dwThreadId)); + CloseHandle (current_event->u.LoadDll.hFile); if (! child_initialization_done) break; - dll_loaded_event (); + windows_process.dll_loaded_event (); =20 ourstatus->set_loaded (); break; @@ -1214,20 +1231,20 @@ get_child_debug_event (DWORD *continue_status, case UNLOAD_DLL_DEBUG_EVENT: OUTMSG2 (("gdbserver: kernel event UNLOAD_DLL_DEBUG_EVENT " "for pid=3D%u tid=3D%x\n", - (unsigned) current_event.dwProcessId, - (unsigned) current_event.dwThreadId)); + (unsigned) current_event->dwProcessId, + (unsigned) current_event->dwThreadId)); if (! child_initialization_done) break; - handle_unload_dll (); + windows_process.handle_unload_dll (); ourstatus->set_loaded (); break; =20 case EXCEPTION_DEBUG_EVENT: OUTMSG2 (("gdbserver: kernel event EXCEPTION_DEBUG_EVENT " "for pid=3D%u tid=3D%x\n", - (unsigned) current_event.dwProcessId, - (unsigned) current_event.dwThreadId)); - if (handle_exception (ourstatus, debug_threads) + (unsigned) current_event->dwProcessId, + (unsigned) current_event->dwThreadId)); + if (windows_process.handle_exception (ourstatus, debug_threads) =3D=3D HANDLE_EXCEPTION_UNHANDLED) *continue_status =3D DBG_EXCEPTION_NOT_HANDLED; break; @@ -1236,31 +1253,33 @@ get_child_debug_event (DWORD *continue_status, /* A message from the kernel (or Cygwin). */ OUTMSG2 (("gdbserver: kernel event OUTPUT_DEBUG_STRING_EVENT " "for pid=3D%u tid=3D%x\n", - (unsigned) current_event.dwProcessId, - (unsigned) current_event.dwThreadId)); - handle_output_debug_string (nullptr); + (unsigned) current_event->dwProcessId, + (unsigned) current_event->dwThreadId)); + windows_process.handle_output_debug_string (nullptr); break; =20 default: OUTMSG2 (("gdbserver: kernel event unknown " "for pid=3D%u tid=3D%x code=3D%x\n", - (unsigned) current_event.dwProcessId, - (unsigned) current_event.dwThreadId, - (unsigned) current_event.dwDebugEventCode)); + (unsigned) current_event->dwProcessId, + (unsigned) current_event->dwThreadId, + (unsigned) current_event->dwDebugEventCode)); break; } =20 - ptid =3D debug_event_ptid (¤t_event); + ptid =3D debug_event_ptid (&windows_process.current_event); =20 - if (desired_stop_thread_id !=3D -1 && desired_stop_thread_id !=3D ptid.l= wp ()) + if (windows_process.desired_stop_thread_id !=3D -1 + && windows_process.desired_stop_thread_id !=3D ptid.lwp ()) { /* Pending stop. See the comment by the definition of "pending_stops" for details on why this is needed. */ OUTMSG2 (("get_windows_debug_event - " "unexpected stop in 0x%lx (expecting 0x%x)\n", - ptid.lwp (), desired_stop_thread_id)); + ptid.lwp (), windows_process.desired_stop_thread_id)); maybe_adjust_pc (); - pending_stops.push_back ({(DWORD) ptid.lwp (), *ourstatus, current_e= vent}); + windows_process.pending_stops.push_back + ({(DWORD) ptid.lwp (), *ourstatus, *current_event}); ourstatus->set_spurious (); } else @@ -1284,7 +1303,7 @@ win32_process_target::wait (ptid_t ptid, target_waits= tatus *ourstatus, fails). Report it now. */ *ourstatus =3D cached_status; cached_status.set_ignore (); - return debug_event_ptid (¤t_event); + return debug_event_ptid (&windows_process.current_event); } =20 while (1) @@ -1299,7 +1318,7 @@ win32_process_target::wait (ptid_t ptid, target_waits= tatus *ourstatus, OUTMSG2 (("Child exited with retcode =3D %x\n", ourstatus->exit_status ())); win32_clear_inferiors (); - return ptid_t (current_event.dwProcessId); + return ptid_t (windows_process.current_event.dwProcessId); case TARGET_WAITKIND_STOPPED: case TARGET_WAITKIND_SIGNALLED: case TARGET_WAITKIND_LOADED: @@ -1307,7 +1326,7 @@ win32_process_target::wait (ptid_t ptid, target_waits= tatus *ourstatus, OUTMSG2 (("Child Stopped with signal =3D %d \n", ourstatus->sig ())); maybe_adjust_pc (); - return debug_event_ptid (¤t_event); + return debug_event_ptid (&windows_process.current_event); } default: OUTMSG (("Ignoring unknown internal event, %d\n", @@ -1315,7 +1334,8 @@ win32_process_target::wait (ptid_t ptid, target_waits= tatus *ourstatus, /* fall-through */ case TARGET_WAITKIND_SPURIOUS: /* do nothing, just continue */ - child_continue (continue_status, desired_stop_thread_id); + child_continue (continue_status, + windows_process.desired_stop_thread_id); break; } } @@ -1362,7 +1382,7 @@ win32_process_target::write_memory (CORE_ADDR memaddr, void win32_process_target::request_interrupt () { - if (GenerateConsoleCtrlEvent (CTRL_BREAK_EVENT, current_process_id)) + if (GenerateConsoleCtrlEvent (CTRL_BREAK_EVENT, windows_process.id)) return; =20 /* GenerateConsoleCtrlEvent can fail if process id being debugged is @@ -1370,7 +1390,7 @@ win32_process_target::request_interrupt () Fallback to XP/Vista 'DebugBreakProcess', which generates a breakpoint exception in the interior process. */ =20 - if (DebugBreakProcess (current_process_handle)) + if (DebugBreakProcess (windows_process.handle)) return; =20 /* Last resort, suspend all threads manually. */ @@ -1397,14 +1417,14 @@ win32_process_target::qxfer_siginfo (const char *an= nex, unsigned const char *writebuf, CORE_ADDR offset, int len) { - if (siginfo_er.ExceptionCode =3D=3D 0) + if (windows_process.siginfo_er.ExceptionCode =3D=3D 0) return -1; =20 if (readbuf =3D=3D nullptr) return -1; =20 - char *buf =3D (char *) &siginfo_er; - size_t bufsize =3D sizeof (siginfo_er); + char *buf =3D (char *) &windows_process.siginfo_er; + size_t bufsize =3D sizeof (windows_process.siginfo_er); =20 #ifdef __x86_64__ EXCEPTION_RECORD32 er32; @@ -1447,7 +1467,7 @@ int win32_process_target::get_tib_address (ptid_t ptid, CORE_ADDR *addr) { windows_thread_info *th; - th =3D thread_rec (ptid, DONT_INVALIDATE_CONTEXT); + th =3D windows_process.thread_rec (ptid, DONT_INVALIDATE_CONTEXT); if (th =3D=3D NULL) return 0; if (addr !=3D NULL) @@ -1467,8 +1487,9 @@ win32_process_target::sw_breakpoint_from_kind (int ki= nd, int *size) bool win32_process_target::stopped_by_sw_breakpoint () { - windows_thread_info *th =3D thread_rec (current_thread_ptid (), - DONT_INVALIDATE_CONTEXT); + windows_thread_info *th + =3D windows_process.thread_rec (current_thread_ptid (), + DONT_INVALIDATE_CONTEXT); return th =3D=3D nullptr ? false : th->stopped_at_software_breakpoint; }