From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: by sourceware.org (Postfix, from userid 2126) id 9C8D5395253F; Tue, 7 Jun 2022 18:21:51 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 9C8D5395253F 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] Use subclasses of windows_process_info X-Act-Checkin: binutils-gdb X-Git-Author: Tom Tromey X-Git-Refname: refs/heads/master X-Git-Oldrev: 551765020680c23de7641577e72d88083c50194d X-Git-Newrev: 20489cca9058f4823ee1c913ab1fbaabea4d4f8d Message-Id: <20220607182151.9C8D5395253F@sourceware.org> Date: Tue, 7 Jun 2022 18:21:51 +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: Tue, 07 Jun 2022 18:21:51 -0000 https://sourceware.org/git/gitweb.cgi?p=3Dbinutils-gdb.git;h=3D20489cca9058= f4823ee1c913ab1fbaabea4d4f8d commit 20489cca9058f4823ee1c913ab1fbaabea4d4f8d Author: Tom Tromey Date: Tue Apr 5 13:22:16 2022 -0600 Use subclasses of windows_process_info =20 This changes windows_process_info to use virtual methods for its callbacks, and then changes the two clients of this code to subclass this class to implement the methods. =20 I considered using CRTP here, but that would require making the new structures visible to the compilation of of nat/windows-nat.c. This seemed like a bit of a pain, so I didn't do it. =20 This change then lets us change all the per-inferior globals to be members of the new subclass. Note that there can still only be a single inferior -- currently there's a single global of the new type. This is just another step toward possibly implementing multi-inferior for Windows. =20 It's possible this could be cleaned up further... ideally I'd like to move more of the data into the base class. However, because gdb supports Cygwin and gdbserver does not, and because I don't have a way to build or test Cygwin, larger refactorings are difficult. Diff: --- gdb/nat/windows-nat.h | 12 +- gdb/windows-nat.c | 348 ++++++++++++++++++++++++---------------------= ---- gdbserver/win32-low.cc | 86 +++++------- gdbserver/win32-low.h | 35 ++++- 4 files changed, 245 insertions(+), 236 deletions(-) diff --git a/gdb/nat/windows-nat.h b/gdb/nat/windows-nat.h index 65b789fa593..e4c89953d69 100644 --- a/gdb/nat/windows-nat.h +++ b/gdb/nat/windows-nat.h @@ -183,8 +183,8 @@ struct windows_process_info is invalidated. =20 This function must be supplied by the embedding application. */ - windows_thread_info *thread_rec (ptid_t ptid, - thread_disposition_type disposition); + virtual windows_thread_info *thread_rec (ptid_t ptid, + thread_disposition_type disposition) =3D 0; =20 /* Handle OUTPUT_DEBUG_STRING_EVENT from child process. Updates OURSTATUS and returns the thread id if this represents a thread @@ -194,7 +194,7 @@ struct windows_process_info a Cygwin signal. Otherwise just print the string as a warning. =20 This function must be supplied by the embedding application. */ - int handle_output_debug_string (struct target_waitstatus *ourstatus); + virtual int handle_output_debug_string (struct target_waitstatus *oursta= tus) =3D 0; =20 /* Handle a DLL load event. =20 @@ -206,7 +206,7 @@ struct windows_process_info =20 This function must be supplied by the embedding application. */ =20 - void handle_load_dll (const char *dll_name, LPVOID base); + virtual void handle_load_dll (const char *dll_name, LPVOID base) =3D 0; =20 /* Handle a DLL unload event. =20 @@ -215,14 +215,14 @@ struct windows_process_info =20 This function must be supplied by the embedding application. */ =20 - void handle_unload_dll (); + virtual void handle_unload_dll () =3D 0; =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". */ =20 - bool handle_access_violation (const EXCEPTION_RECORD *rec); + virtual bool handle_access_violation (const EXCEPTION_RECORD *rec) =3D 0; =20 handle_exception_result handle_exception (struct target_waitstatus *ourstatus, bool debug_exceptions); diff --git a/gdb/windows-nat.c b/gdb/windows-nat.c index 586671b1902..277507ddf09 100644 --- a/gdb/windows-nat.c +++ b/gdb/windows-nat.c @@ -74,8 +74,80 @@ =20 using namespace windows_nat; =20 +/* Maintain a linked list of "so" information. */ +struct windows_solib +{ + LPVOID load_addr =3D 0; + CORE_ADDR text_offset =3D 0; + + /* Original name. */ + std::string original_name; + /* Expanded form of the name. */ + std::string name; +}; + +struct windows_per_inferior : public windows_process_info +{ + windows_thread_info *thread_rec (ptid_t ptid, + thread_disposition_type disposition) override; + int handle_output_debug_string (struct target_waitstatus *ourstatus) ove= rride; + void handle_load_dll (const char *dll_name, LPVOID base) override; + void handle_unload_dll () override; + bool handle_access_violation (const EXCEPTION_RECORD *rec) override; + + + int have_saved_context =3D 0; /* True if we've saved context from a + cygwin signal. */ + + uintptr_t dr[8] {}; + + int windows_initialization_done =3D 0; + + std::vector> thread_list; + + /* Counts of things. */ + int saw_create =3D 0; + int open_process_used =3D 0; +#ifdef __x86_64__ + void *wow64_dbgbreak =3D nullptr; +#endif + + /* This vector maps GDB's idea of a register's number into an offset + in the windows exception context vector. + + It also contains the bit mask needed to load the register in question. + + The contents of this table can only be computed by the units + that provide CPU-specific support for Windows native debugging. + + One day we could read a reg, we could inspect the context we + already have loaded, if it doesn't have the bit set that we need, + we read that set of registers in using GetThreadContext. If the + context already contains what we need, we just unpack it. Then to + write a register, first we have to ensure that the context contains + the other regs of the group, and then we copy the info in and set + out bit. */ + + const int *mappings =3D nullptr; + + /* The function to use in order to determine whether a register is + a segment register or not. */ + segment_register_p_ftype *segment_register_p =3D nullptr; + + std::vector solibs; + +#ifdef __CYGWIN__ + CONTEXT saved_context {}; /* Contains the saved context from a + cygwin signal. */ + + /* The starting and ending address of the cygwin1.dll text segment. */ + CORE_ADDR cygwin_load_start =3D 0; + CORE_ADDR cygwin_load_end =3D 0; +#endif /* __CYGWIN__ */ +}; + /* The current process. */ -static windows_process_info windows_process; +static windows_per_inferior windows_process; =20 #undef STARTUPINFO =20 @@ -84,21 +156,11 @@ static windows_process_info windows_process; # define STARTUPINFO STARTUPINFOA #else # define __PMAX PATH_MAX -/* The starting and ending address of the cygwin1.dll text segment. */ - static CORE_ADDR cygwin_load_start; - static CORE_ADDR cygwin_load_end; # define __USEWIDE typedef wchar_t cygwin_buf_t; # define STARTUPINFO STARTUPINFOW #endif =20 -static int have_saved_context; /* True if we've saved context from a - cygwin signal. */ -#ifdef __CYGWIN__ -static CONTEXT saved_context; /* Contains the saved context from a - cygwin signal. */ -#endif - /* If we're not using the old Cygwin header file set, define the following which never should have been in the generic Win32 API headers in the first place since they were our own invention... */ @@ -119,9 +181,6 @@ enum | CONTEXT_SEGMENTS | CONTEXT_DEBUG_REGISTERS \ | CONTEXT_EXTENDED_REGISTERS =20 -static uintptr_t dr[8]; - -static int windows_initialization_done; #define DR6_CLEAR_VALUE 0xffff0ff0 =20 /* The string sent by cygwin when it processes a signal. @@ -149,15 +208,6 @@ static CORE_ADDR cygwin_get_dr (int i); static unsigned long cygwin_get_dr6 (void); static unsigned long cygwin_get_dr7 (void); =20 -static std::vector> thread_list; - -/* Counts of things. */ -static int saw_create; -static int open_process_used =3D 0; -#ifdef __x86_64__ -static void *wow64_dbgbreak; -#endif - /* User options. */ static bool new_console =3D false; #ifdef __CYGWIN__ @@ -170,30 +220,6 @@ static bool debug_memory =3D false; /* show target mem= ory accesses */ static bool debug_exceptions =3D false; /* show target exceptions */ static bool useshell =3D false; /* use shell for subprocesses */ =20 -/* This vector maps GDB's idea of a register's number into an offset - in the windows exception context vector. - - It also contains the bit mask needed to load the register in question. - - The contents of this table can only be computed by the units - that provide CPU-specific support for Windows native debugging. - These units should set the table by calling - windows_set_context_register_offsets. - - One day we could read a reg, we could inspect the context we - already have loaded, if it doesn't have the bit set that we need, - we read that set of registers in using GetThreadContext. If the - context already contains what we need, we just unpack it. Then to - write a register, first we have to ensure that the context contains - the other regs of the group, and then we copy the info in and set - out bit. */ - -static const int *mappings; - -/* The function to use in order to determine whether a register is - a segment register or not. */ -static segment_register_p_ftype *segment_register_p; - /* See windows_nat_target::resume to understand why this is commented out. */ #if 0 @@ -297,24 +323,6 @@ private: =20 static windows_nat_target the_windows_nat_target; =20 -/* Set the MAPPINGS static global to OFFSETS. - See the description of MAPPINGS for more details. */ - -static void -windows_set_context_register_offsets (const int *offsets) -{ - mappings =3D offsets; -} - -/* Set the function that should be used by this module to determine - whether a given register is a segment register or not. */ - -static void -windows_set_segment_register_p (segment_register_p_ftype *fun) -{ - segment_register_p =3D fun; -} - static void check (BOOL ok, const char *file, int line) { @@ -326,7 +334,7 @@ check (BOOL ok, const char *file, int line) /* See nat/windows-nat.h. */ =20 windows_thread_info * -windows_nat::windows_process_info::thread_rec +windows_per_inferior::thread_rec (ptid_t ptid, thread_disposition_type disposition) { for (auto &th : thread_list) @@ -383,7 +391,7 @@ windows_nat_target::add_thread (ptid_t ptid, HANDLE h, = void *tlb, base +=3D 0x2000; #endif th =3D new windows_thread_info (ptid.lwp (), h, base); - thread_list.emplace_back (th); + windows_process.thread_list.emplace_back (th); =20 /* Add this new thread to the list of threads. =20 @@ -408,7 +416,7 @@ static void windows_init_thread_list (void) { DEBUG_EVENTS ("called"); - thread_list.clear (); + windows_process.thread_list.clear (); } =20 /* Delete a thread from the list of threads. @@ -444,14 +452,15 @@ windows_nat_target::delete_thread (ptid_t ptid, DWORD= exit_code, =20 ::delete_thread (find_thread_ptid (&the_windows_nat_target, ptid)); =20 - auto iter =3D std::find_if (thread_list.begin (), thread_list.end (), + auto iter =3D std::find_if (windows_process.thread_list.begin (), + windows_process.thread_list.end (), [=3D] (auto &th) { return th->tid =3D=3D id; }); =20 - if (iter !=3D thread_list.end ()) - thread_list.erase (iter); + if (iter !=3D windows_process.thread_list.end ()) + windows_process.thread_list.erase (iter); } =20 /* Fetches register number R from the given windows_thread_info, @@ -477,7 +486,7 @@ windows_fetch_one_register (struct regcache *regcache, context_ptr =3D (char *) &th->wow64_context; #endif =20 - char *context_offset =3D context_ptr + mappings[r]; + char *context_offset =3D context_ptr + windows_process.mappings[r]; struct gdbarch *gdbarch =3D regcache->arch (); i386_gdbarch_tdep *tdep =3D (i386_gdbarch_tdep *) gdbarch_tdep (gdbarch); =20 @@ -495,7 +504,7 @@ windows_fetch_one_register (struct regcache *regcache, long l =3D (*((long *) context_offset) >> 16) & ((1 << 11) - 1); regcache->raw_supply (r, (char *) &l); } - else if (segment_register_p (r)) + else if (windows_process.segment_register_p (r)) { /* GDB treats segment registers as 32bit registers, but they are in fact only 16 bits long. Make sure we do not read extra @@ -568,12 +577,12 @@ windows_nat_target::fetch_registers (struct regcache = *regcache, int r) PR gdb/2388 */ if (!th->debug_registers_changed) { - dr[0] =3D th->wow64_context.Dr0; - dr[1] =3D th->wow64_context.Dr1; - dr[2] =3D th->wow64_context.Dr2; - dr[3] =3D th->wow64_context.Dr3; - dr[6] =3D th->wow64_context.Dr6; - dr[7] =3D th->wow64_context.Dr7; + windows_process.dr[0] =3D th->wow64_context.Dr0; + windows_process.dr[1] =3D th->wow64_context.Dr1; + windows_process.dr[2] =3D th->wow64_context.Dr2; + windows_process.dr[3] =3D th->wow64_context.Dr3; + windows_process.dr[6] =3D th->wow64_context.Dr6; + windows_process.dr[7] =3D th->wow64_context.Dr7; } } else @@ -586,12 +595,12 @@ windows_nat_target::fetch_registers (struct regcache = *regcache, int r) PR gdb/2388 */ if (!th->debug_registers_changed) { - dr[0] =3D th->context.Dr0; - dr[1] =3D th->context.Dr1; - dr[2] =3D th->context.Dr2; - dr[3] =3D th->context.Dr3; - dr[6] =3D th->context.Dr6; - dr[7] =3D th->context.Dr7; + windows_process.dr[0] =3D th->context.Dr0; + windows_process.dr[1] =3D th->context.Dr1; + windows_process.dr[2] =3D th->context.Dr2; + windows_process.dr[3] =3D th->context.Dr3; + windows_process.dr[6] =3D th->context.Dr6; + windows_process.dr[7] =3D th->context.Dr7; } } th->reload_context =3D false; @@ -622,7 +631,7 @@ windows_store_one_register (const struct regcache *regc= ache, context_ptr =3D (char *) &th->wow64_context; #endif =20 - regcache->raw_collect (r, context_ptr + mappings[r]); + regcache->raw_collect (r, context_ptr + windows_process.mappings[r]); } =20 /* Store a new register value into the context of the thread tied to @@ -646,20 +655,6 @@ windows_nat_target::store_registers (struct regcache *= regcache, int r) windows_store_one_register (regcache, th, r); } =20 -/* Maintain a linked list of "so" information. */ -struct windows_solib -{ - LPVOID load_addr =3D 0; - CORE_ADDR text_offset =3D 0; - - /* Original name. */ - std::string original_name; - /* Expanded form of the name. */ - std::string name; -}; - -static std::vector solibs; - /* See nat/windows-nat.h. */ =20 static windows_solib * @@ -713,8 +708,8 @@ windows_make_so (const char *name, LPVOID load_addr) #endif } #endif - solibs.emplace_back (); - windows_solib *so =3D &solibs.back (); + windows_process.solibs.emplace_back (); + windows_solib *so =3D &windows_process.solibs.back (); so->load_addr =3D load_addr; so->original_name =3D name; #ifndef __CYGWIN__ @@ -775,8 +770,7 @@ windows_make_so (const char *name, LPVOID load_addr) /* See nat/windows-nat.h. */ =20 void -windows_nat::windows_process_info::handle_load_dll (const char *dll_name, - LPVOID base) +windows_per_inferior::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 (), @@ -786,11 +780,12 @@ windows_nat::windows_process_info::handle_load_dll (c= onst char *dll_name, /* See nat/windows-nat.h. */ =20 void -windows_nat::windows_process_info::handle_unload_dll () +windows_per_inferior::handle_unload_dll () { LPVOID lpBaseOfDll =3D current_event.u.UnloadDll.lpBaseOfDll; =20 - auto iter =3D std::remove_if (solibs.begin (), solibs.end (), + auto iter =3D std::remove_if (windows_process.solibs.begin (), + windows_process.solibs.end (), [&] (windows_solib &lib) { if (lib.load_addr =3D=3D lpBaseOfDll) @@ -801,9 +796,9 @@ windows_nat::windows_process_info::handle_unload_dll () return false; }); =20 - if (iter !=3D solibs.end ()) + if (iter !=3D windows_process.solibs.end ()) { - solibs.erase (iter, solibs.end ()); + windows_process.solibs.erase (iter, windows_process.solibs.end ()); return; } =20 @@ -822,7 +817,7 @@ windows_nat::windows_process_info::handle_unload_dll () static void windows_clear_solib (void) { - solibs.clear (); + windows_process.solibs.clear (); } =20 static void @@ -847,7 +842,7 @@ signal_event_command (const char *args, int from_tty) /* See nat/windows-nat.h. */ =20 int -windows_nat::windows_process_info::handle_output_debug_string +windows_per_inferior::handle_output_debug_string (struct target_waitstatus *ourstatus) { int retval =3D 0; @@ -1063,7 +1058,7 @@ display_selectors (const char * args, int from_tty) /* See nat/windows-nat.h. */ =20 bool -windows_nat::windows_process_info::handle_access_violation +windows_per_inferior::handle_access_violation (const EXCEPTION_RECORD *rec) { #ifdef __CYGWIN__ @@ -1100,7 +1095,7 @@ windows_continue (DWORD continue_status, int id, int = killed) if (windows_process.matching_pending_stop (debug_events)) return TRUE; =20 - for (auto &th : thread_list) + for (auto &th : windows_process.thread_list) if (id =3D=3D -1 || id =3D=3D (int) th->tid) { #ifdef __x86_64__ @@ -1109,12 +1104,12 @@ windows_continue (DWORD continue_status, int id, in= t killed) if (th->debug_registers_changed) { th->wow64_context.ContextFlags |=3D CONTEXT_DEBUG_REGISTERS; - th->wow64_context.Dr0 =3D dr[0]; - th->wow64_context.Dr1 =3D dr[1]; - th->wow64_context.Dr2 =3D dr[2]; - th->wow64_context.Dr3 =3D dr[3]; + th->wow64_context.Dr0 =3D windows_process.dr[0]; + th->wow64_context.Dr1 =3D windows_process.dr[1]; + th->wow64_context.Dr2 =3D windows_process.dr[2]; + th->wow64_context.Dr3 =3D windows_process.dr[3]; th->wow64_context.Dr6 =3D DR6_CLEAR_VALUE; - th->wow64_context.Dr7 =3D dr[7]; + th->wow64_context.Dr7 =3D windows_process.dr[7]; th->debug_registers_changed =3D false; } if (th->wow64_context.ContextFlags) @@ -1139,12 +1134,12 @@ windows_continue (DWORD continue_status, int id, in= t killed) if (th->debug_registers_changed) { th->context.ContextFlags |=3D CONTEXT_DEBUG_REGISTERS; - th->context.Dr0 =3D dr[0]; - th->context.Dr1 =3D dr[1]; - th->context.Dr2 =3D dr[2]; - th->context.Dr3 =3D dr[3]; + th->context.Dr0 =3D windows_process.dr[0]; + th->context.Dr1 =3D windows_process.dr[1]; + th->context.Dr2 =3D windows_process.dr[2]; + th->context.Dr3 =3D windows_process.dr[3]; th->context.Dr6 =3D DR6_CLEAR_VALUE; - th->context.Dr7 =3D dr[7]; + th->context.Dr7 =3D windows_process.dr[7]; th->debug_registers_changed =3D false; } if (th->context.ContextFlags) @@ -1190,7 +1185,7 @@ windows_nat_target::fake_create_process () =3D OpenProcess (PROCESS_ALL_ACCESS, FALSE, windows_process.current_event.dwProcessId); if (windows_process.handle !=3D NULL) - open_process_used =3D 1; + windows_process.open_process_used =3D 1; else { error (_("OpenProcess call failed, GetLastError =3D %u"), @@ -1278,12 +1273,12 @@ windows_nat_target::resume (ptid_t ptid, int step, = enum gdb_signal sig) { if (th->debug_registers_changed) { - th->wow64_context.Dr0 =3D dr[0]; - th->wow64_context.Dr1 =3D dr[1]; - th->wow64_context.Dr2 =3D dr[2]; - th->wow64_context.Dr3 =3D dr[3]; + th->wow64_context.Dr0 =3D windows_process.dr[0]; + th->wow64_context.Dr1 =3D windows_process.dr[1]; + th->wow64_context.Dr2 =3D windows_process.dr[2]; + th->wow64_context.Dr3 =3D windows_process.dr[3]; th->wow64_context.Dr6 =3D DR6_CLEAR_VALUE; - th->wow64_context.Dr7 =3D dr[7]; + th->wow64_context.Dr7 =3D windows_process.dr[7]; th->debug_registers_changed =3D false; } CHECK (Wow64SetThreadContext (th->h, &th->wow64_context)); @@ -1306,12 +1301,12 @@ windows_nat_target::resume (ptid_t ptid, int step, = enum gdb_signal sig) { if (th->debug_registers_changed) { - th->context.Dr0 =3D dr[0]; - th->context.Dr1 =3D dr[1]; - th->context.Dr2 =3D dr[2]; - th->context.Dr3 =3D dr[3]; + th->context.Dr0 =3D windows_process.dr[0]; + th->context.Dr1 =3D windows_process.dr[1]; + th->context.Dr2 =3D windows_process.dr[2]; + th->context.Dr3 =3D windows_process.dr[3]; th->context.Dr6 =3D DR6_CLEAR_VALUE; - th->context.Dr7 =3D dr[7]; + th->context.Dr7 =3D windows_process.dr[7]; th->debug_registers_changed =3D false; } CHECK (SetThreadContext (th->h, &th->context)); @@ -1353,19 +1348,20 @@ ctrl_c_handler (DWORD event_type) /* Call DbgUiRemoteBreakin of the 32bit ntdll.dll in the target proc= ess. DebugBreakProcess would call the one of the 64bit ntdll.dll, which can't be correctly handled by gdb. */ - if (wow64_dbgbreak =3D=3D nullptr) + if (windows_process.wow64_dbgbreak =3D=3D nullptr) { CORE_ADDR addr; if (!find_minimal_symbol_address ("ntdll!DbgUiRemoteBreakin", &addr, 0)) - wow64_dbgbreak =3D (void *) addr; + windows_process.wow64_dbgbreak =3D (void *) addr; } =20 - if (wow64_dbgbreak !=3D nullptr) + if (windows_process.wow64_dbgbreak !=3D nullptr) { HANDLE thread =3D CreateRemoteThread (windows_process.handle, NULL, 0, (LPTHREAD_START_ROUTINE) - wow64_dbgbreak, NULL, 0, NULL); + windows_process.wow64_dbgbreak, + NULL, 0, NULL); if (thread) CloseHandle (thread); } @@ -1422,7 +1418,7 @@ windows_nat_target::get_windows_debug_event (int pid, =20 event_code =3D windows_process.current_event.dwDebugEventCode; ourstatus->set_spurious (); - have_saved_context =3D 0; + windows_process.have_saved_context =3D 0; =20 switch (event_code) { @@ -1431,17 +1427,17 @@ windows_nat_target::get_windows_debug_event (int pi= d, (unsigned) current_event->dwProcessId, (unsigned) current_event->dwThreadId, "CREATE_THREAD_DEBUG_EVENT"); - if (saw_create !=3D 1) + if (windows_process.saw_create !=3D 1) { inferior *inf =3D find_inferior_pid (this, current_event->dwProcessId); - if (!saw_create && inf->attach_flag) + if (!windows_process.saw_create && inf->attach_flag) { /* Kludge around a Windows bug where first event is a create thread event. Caused when attached process does not have a main thread. */ thread_id =3D fake_create_process (); if (thread_id) - saw_create++; + windows_process.saw_create++; } break; } @@ -1472,7 +1468,7 @@ windows_nat_target::get_windows_debug_event (int pid, (unsigned) current_event->dwThreadId, "CREATE_PROCESS_DEBUG_EVENT"); CloseHandle (current_event->u.CreateProcessInfo.hFile); - if (++saw_create !=3D 1) + if (++windows_process.saw_create !=3D 1) break; =20 windows_process.handle =3D current_event->u.CreateProcessInfo.hProce= ss; @@ -1491,14 +1487,14 @@ windows_nat_target::get_windows_debug_event (int pi= d, (unsigned) current_event->dwProcessId, (unsigned) current_event->dwThreadId, "EXIT_PROCESS_DEBUG_EVENT"); - if (!windows_initialization_done) + if (!windows_process.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); } - else if (saw_create =3D=3D 1) + else if (windows_process.saw_create =3D=3D 1) { delete_thread (ptid_t (current_event->dwProcessId, current_event->dwThreadId, 0), @@ -1525,7 +1521,8 @@ windows_nat_target::get_windows_debug_event (int pid, (unsigned) current_event->dwThreadId, "LOAD_DLL_DEBUG_EVENT"); CloseHandle (current_event->u.LoadDll.hFile); - if (saw_create !=3D 1 || ! windows_initialization_done) + if (windows_process.saw_create !=3D 1 + || ! windows_process.windows_initialization_done) break; try { @@ -1544,7 +1541,8 @@ windows_nat_target::get_windows_debug_event (int pid, (unsigned) current_event->dwProcessId, (unsigned) current_event->dwThreadId, "UNLOAD_DLL_DEBUG_EVENT"); - if (saw_create !=3D 1 || ! windows_initialization_done) + if (windows_process.saw_create !=3D 1 + || ! windows_process.windows_initialization_done) break; try { @@ -1563,7 +1561,7 @@ windows_nat_target::get_windows_debug_event (int pid, (unsigned) current_event->dwProcessId, (unsigned) current_event->dwThreadId, "EXCEPTION_DEBUG_EVENT"); - if (saw_create !=3D 1) + if (windows_process.saw_create !=3D 1) break; switch (windows_process.handle_exception (ourstatus, debug_exception= s)) { @@ -1585,13 +1583,13 @@ windows_nat_target::get_windows_debug_event (int pi= d, (unsigned) current_event->dwProcessId, (unsigned) current_event->dwThreadId, "OUTPUT_DEBUG_STRING_EVENT"); - if (saw_create !=3D 1) + if (windows_process.saw_create !=3D 1) break; thread_id =3D windows_process.handle_output_debug_string (ourstatus); break; =20 default: - if (saw_create !=3D 1) + if (windows_process.saw_create !=3D 1) break; gdb_printf ("gdb: kernel event for pid=3D%u tid=3D0x%x\n", (unsigned) current_event->dwProcessId, @@ -1601,7 +1599,7 @@ windows_nat_target::get_windows_debug_event (int pid, break; } =20 - if (!thread_id || saw_create !=3D 1) + if (!thread_id || windows_process.saw_create !=3D 1) { CHECK (windows_continue (continue_status, windows_process.desired_stop_thread_id, 0)); @@ -1620,7 +1618,7 @@ windows_nat_target::get_windows_debug_event (int pid, =3D=3D EXCEPTION_BREAKPOINT) || (current_event->u.Exception.ExceptionRecord.ExceptionCode =3D=3D STATUS_WX86_BREAKPOINT)) - && windows_initialization_done) + && windows_process.windows_initialization_done) { ptid_t ptid =3D ptid_t (current_event->dwProcessId, thread_id, 0); windows_thread_info *th @@ -1706,7 +1704,7 @@ windows_nat_target::wait (ptid_t ptid, struct target_= waitstatus *ourstatus, =3D=3D EXCEPTION_BREAKPOINT) || (windows_process.current_event.u.Exception.ExceptionRecord.Excepti= onCode =3D=3D STATUS_WX86_BREAKPOINT)) - && windows_initialization_done) + && windows_process.windows_initialization_done) { th->stopped_at_software_breakpoint =3D true; th->pc_adjusted =3D false; @@ -1736,9 +1734,11 @@ windows_nat_target::do_initial_windows_stuff (DWORD = pid, bool attaching) struct inferior *inf; =20 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; + windows_process.open_process_used =3D 0; + for (i =3D 0; + i < sizeof (windows_process.dr) / sizeof (windows_process.dr[0]); + i++) + windows_process.dr[i] =3D 0; #ifdef __CYGWIN__ cygwin_load_start =3D cygwin_load_end =3D 0; #endif @@ -1759,14 +1759,14 @@ windows_nat_target::do_initial_windows_stuff (DWORD= pid, bool attaching) =20 if (!windows_process.wow64_process) { - windows_set_context_register_offsets (amd64_mappings); - windows_set_segment_register_p (amd64_windows_segment_register_p); + windows_process.mappings =3D amd64_mappings; + windows_process.segment_register_p =3D amd64_windows_segment_registe= r_p; } else #endif { - windows_set_context_register_offsets (i386_mappings); - windows_set_segment_register_p (i386_windows_segment_register_p); + windows_process.mappings =3D i386_mappings; + windows_process.segment_register_p =3D i386_windows_segment_register= _p; } =20 inferior_appeared (inf, pid); @@ -1775,7 +1775,7 @@ windows_nat_target::do_initial_windows_stuff (DWORD p= id, bool attaching) target_terminal::init (); target_terminal::inferior (); =20 - windows_initialization_done =3D 0; + windows_process.windows_initialization_done =3D 0; =20 ptid_t last_ptid; =20 @@ -1813,7 +1813,7 @@ windows_nat_target::do_initial_windows_stuff (DWORD p= id, bool attaching) phase, and then process them all in one batch now. */ windows_process.add_all_dlls (); =20 - windows_initialization_done =3D 1; + windows_process.windows_initialization_done =3D 1; return; } =20 @@ -1882,7 +1882,7 @@ windows_nat_target::attach (const char *args, int fro= m_tty) =20 windows_init_thread_list (); ok =3D DebugActiveProcess (pid); - saw_create =3D 0; + windows_process.saw_create =3D 0; =20 #ifdef __CYGWIN__ if (!ok) @@ -2654,9 +2654,9 @@ windows_nat_target::create_inferior (const char *exec= _file, CloseHandle (pi.hProcess); =20 if (useshell && shell[0] !=3D '\0') - saw_create =3D -1; + windows_process.saw_create =3D -1; else - saw_create =3D 0; + windows_process.saw_create =3D 0; =20 do_initial_windows_stuff (pi.dwProcessId, 0); =20 @@ -2668,10 +2668,10 @@ windows_nat_target::mourn_inferior () { (void) windows_continue (DBG_CONTINUE, -1, 0); x86_cleanup_dregs(); - if (open_process_used) + if (windows_process.open_process_used) { CHECK (CloseHandle (windows_process.handle)); - open_process_used =3D 0; + windows_process.open_process_used =3D 0; } windows_process.siginfo_er.ExceptionCode =3D 0; inf_child_target::mourn_inferior (); @@ -2779,7 +2779,7 @@ windows_xfer_shared_libraries (struct target_ops *ops, return TARGET_XFER_E_IO; =20 obstack_grow_str (&obstack, "\n"); - for (windows_solib &so : solibs) + for (windows_solib &so : windows_process.solibs) windows_xfer_shared_library (so.name.c_str (), (CORE_ADDR) (uintptr_t) so.load_addr, &so.text_offset, @@ -3031,9 +3031,9 @@ cygwin_set_dr (int i, CORE_ADDR addr) if (i < 0 || i > 3) internal_error (__FILE__, __LINE__, _("Invalid register %d in cygwin_set_dr.\n"), i); - dr[i] =3D addr; + windows_process.dr[i] =3D addr; =20 - for (auto &th : thread_list) + for (auto &th : windows_process.thread_list) th->debug_registers_changed =3D true; } =20 @@ -3043,9 +3043,9 @@ cygwin_set_dr (int i, CORE_ADDR addr) static void cygwin_set_dr7 (unsigned long val) { - dr[7] =3D (CORE_ADDR) val; + windows_process.dr[7] =3D (CORE_ADDR) val; =20 - for (auto &th : thread_list) + for (auto &th : windows_process.thread_list) th->debug_registers_changed =3D true; } =20 @@ -3054,7 +3054,7 @@ cygwin_set_dr7 (unsigned long val) static CORE_ADDR cygwin_get_dr (int i) { - return dr[i]; + return windows_process.dr[i]; } =20 /* Get the value of the DR6 debug status register from the inferior. @@ -3063,7 +3063,7 @@ cygwin_get_dr (int i) static unsigned long cygwin_get_dr6 (void) { - return (unsigned long) dr[6]; + return (unsigned long) windows_process.dr[6]; } =20 /* Get the value of the DR7 debug status register from the inferior. @@ -3073,7 +3073,7 @@ cygwin_get_dr6 (void) static unsigned long cygwin_get_dr7 (void) { - return (unsigned long) dr[7]; + return (unsigned long) windows_process.dr[7]; } =20 /* Determine if the thread referenced by "ptid" is alive diff --git a/gdbserver/win32-low.cc b/gdbserver/win32-low.cc index a9af6467d7c..27224077cea 100644 --- a/gdbserver/win32-low.cc +++ b/gdbserver/win32-low.cc @@ -39,7 +39,7 @@ using namespace windows_nat; =20 /* See win32-low.h. */ -windows_process_info windows_process; +gdbserver_windows_process windows_process; =20 #ifndef USE_WIN32API #include @@ -67,25 +67,6 @@ windows_process_info windows_process; =20 int using_threads =3D 1; =20 -/* Globals. */ -static int attaching =3D 0; - -/* A status that hasn't been reported to the core yet, and so - win32_wait should return it next, instead of fetching the next - debug event off the win32 API. */ -static struct target_waitstatus cached_status; - -/* Non zero if an interrupt request is to be satisfied by suspending - all threads. */ -static int soft_interrupt_requested =3D 0; - -/* Non zero if the inferior is stopped in a simulated breakpoint done - by suspending all the threads. */ -static int faked_breakpoint =3D 0; - -/* True if current_process_handle needs to be closed. */ -static bool open_process_used =3D false; - const struct target_desc *win32_tdesc; #ifdef __x86_64__ const struct target_desc *wow64_win32_tdesc; @@ -166,7 +147,7 @@ win32_require_context (windows_thread_info *th) /* See nat/windows-nat.h. */ =20 windows_thread_info * -windows_nat::windows_process_info::thread_rec +gdbserver_windows_process::thread_rec (ptid_t ptid, thread_disposition_type disposition) { thread_info *thread =3D find_thread_ptid (ptid); @@ -326,10 +307,6 @@ child_init_thread_list (void) for_each_thread (delete_thread_info); } =20 -/* Zero during the child initialization phase, and nonzero otherwise. */ - -static int child_initialization_done =3D 0; - static void do_initial_child_stuff (HANDLE proch, DWORD pid, int attached) { @@ -339,9 +316,9 @@ do_initial_child_stuff (HANDLE proch, DWORD pid, int at= tached) windows_process.handle =3D proch; windows_process.main_thread_id =3D 0; =20 - soft_interrupt_requested =3D 0; - faked_breakpoint =3D 0; - open_process_used =3D true; + windows_process.soft_interrupt_requested =3D 0; + windows_process.faked_breakpoint =3D 0; + windows_process.open_process_used =3D true; =20 memset (&windows_process.current_event, 0, sizeof (windows_process.current_event)); @@ -373,12 +350,12 @@ do_initial_child_stuff (HANDLE proch, DWORD pid, int = attached) #endif proc->tdesc =3D win32_tdesc; child_init_thread_list (); - child_initialization_done =3D 0; + windows_process.child_initialization_done =3D 0; =20 if (the_low_target.initial_stuff !=3D NULL) (*the_low_target.initial_stuff) (); =20 - cached_status.set_ignore (); + windows_process.cached_status.set_ignore (); =20 /* Flush all currently pending debug events (thread and dll list) up to the initial breakpoint. */ @@ -391,7 +368,7 @@ do_initial_child_stuff (HANDLE proch, DWORD pid, int at= tached) /* Note win32_wait doesn't return thread events. */ if (status.kind () !=3D TARGET_WAITKIND_LOADED) { - cached_status =3D status; + windows_process.cached_status =3D status; break; } =20 @@ -423,7 +400,7 @@ do_initial_child_stuff (HANDLE proch, DWORD pid, int at= tached) phase, and then process them all in one batch now. */ windows_process.add_all_dlls (); =20 - child_initialization_done =3D 1; + windows_process.child_initialization_done =3D 1; } =20 /* Resume all artificially suspended threads if we are continuing @@ -470,7 +447,7 @@ child_continue (DWORD continue_status, int thread_id) { continue_one_thread (thread, thread_id); }); - faked_breakpoint =3D 0; + windows_process.faked_breakpoint =3D 0; =20 return continue_last_debug_event (continue_status, debug_threads); } @@ -615,7 +592,7 @@ win32_process_target::create_inferior (const char *prog= ram, char *args =3D (char *) str_program_args.c_str (); =20 /* win32_wait needs to know we're not attaching. */ - attaching =3D 0; + windows_process.attaching =3D 0; =20 if (!program) error ("No executable specified, specify executable to debug.\n"); @@ -700,7 +677,7 @@ win32_process_target::attach (unsigned long pid) DebugSetProcessKillOnExit (FALSE); =20 /* win32_wait needs to know we're attaching. */ - attaching =3D 1; + windows_process.attaching =3D 1; do_initial_child_stuff (h, pid, 1); return 0; } @@ -716,7 +693,7 @@ win32_process_target::attach (unsigned long pid) /* See nat/windows-nat.h. */ =20 int -windows_nat::windows_process_info::handle_output_debug_string +gdbserver_windows_process::handle_output_debug_string (struct target_waitstatus *ourstatus) { #define READ_BUFFER_LEN 1024 @@ -765,10 +742,10 @@ windows_nat::windows_process_info::handle_output_debu= g_string static void win32_clear_inferiors (void) { - if (open_process_used) + if (windows_process.open_process_used) { CloseHandle (windows_process.handle); - open_process_used =3D false; + windows_process.open_process_used =3D false; } =20 for_each_thread (delete_thread_info); @@ -946,8 +923,7 @@ win32_process_target::resume (thread_resume *resume_inf= o, size_t n) /* See nat/windows-nat.h. */ =20 void -windows_nat::windows_process_info::handle_load_dll (const char *name, - LPVOID base) +gdbserver_windows_process::handle_load_dll (const char *name, LPVOID base) { CORE_ADDR load_addr =3D (CORE_ADDR) (uintptr_t) base; =20 @@ -1001,7 +977,7 @@ windows_nat::windows_process_info::handle_load_dll (co= nst char *name, /* See nat/windows-nat.h. */ =20 void -windows_nat::windows_process_info::handle_unload_dll () +gdbserver_windows_process::handle_unload_dll () { CORE_ADDR load_addr =3D (CORE_ADDR) (uintptr_t) current_event.u.UnloadDll.lpBaseOfDll; @@ -1026,7 +1002,7 @@ fake_breakpoint_event (void) { OUTMSG2(("fake_breakpoint_event\n")); =20 - faked_breakpoint =3D 1; + windows_process.faked_breakpoint =3D 1; =20 memset (&windows_process.current_event, 0, sizeof (windows_process.current_event)); @@ -1041,7 +1017,7 @@ fake_breakpoint_event (void) /* See nat/windows-nat.h. */ =20 bool -windows_nat::windows_process_info::handle_access_violation +gdbserver_windows_process::handle_access_violation (const EXCEPTION_RECORD *rec) { return false; @@ -1067,7 +1043,7 @@ maybe_adjust_pc () =3D=3D EXCEPTION_BREAKPOINT) || (windows_process.current_event.u.Exception.ExceptionRecord.Exception= Code =3D=3D STATUS_WX86_BREAKPOINT)) - && child_initialization_done) + && windows_process.child_initialization_done) { th->stopped_at_software_breakpoint =3D true; CORE_ADDR pc =3D regcache_read_pc (regcache); @@ -1093,14 +1069,14 @@ get_child_debug_event (DWORD *continue_status, =20 DEBUG_EVENT *current_event =3D &windows_process.current_event; =20 - if (soft_interrupt_requested) + if (windows_process.soft_interrupt_requested) { - soft_interrupt_requested =3D 0; + windows_process.soft_interrupt_requested =3D 0; fake_breakpoint_event (); goto gotevent; } =20 - attaching =3D 0; + windows_process.attaching =3D 0; { gdb::optional stop =3D windows_process.fetch_pending_stop (debug_threads); @@ -1169,10 +1145,10 @@ get_child_debug_event (DWORD *continue_status, (unsigned) current_event->dwThreadId)); CloseHandle (current_event->u.CreateProcessInfo.hFile); =20 - if (open_process_used) + if (windows_process.open_process_used) { CloseHandle (windows_process.handle); - open_process_used =3D false; + windows_process.open_process_used =3D false; } =20 windows_process.handle =3D current_event->u.CreateProcessInfo.hProce= ss; @@ -1211,7 +1187,7 @@ get_child_debug_event (DWORD *continue_status, (unsigned) current_event->dwProcessId, (unsigned) current_event->dwThreadId)); CloseHandle (current_event->u.LoadDll.hFile); - if (! child_initialization_done) + if (! windows_process.child_initialization_done) break; windows_process.dll_loaded_event (); =20 @@ -1223,7 +1199,7 @@ get_child_debug_event (DWORD *continue_status, "for pid=3D%u tid=3D%x\n", (unsigned) current_event->dwProcessId, (unsigned) current_event->dwThreadId)); - if (! child_initialization_done) + if (! windows_process.child_initialization_done) break; windows_process.handle_unload_dll (); ourstatus->set_loaded (); @@ -1285,14 +1261,14 @@ ptid_t win32_process_target::wait (ptid_t ptid, target_waitstatus *ourstatus, target_wait_flags options) { - if (cached_status.kind () !=3D TARGET_WAITKIND_IGNORE) + if (windows_process.cached_status.kind () !=3D TARGET_WAITKIND_IGNORE) { /* The core always does a wait after creating the inferior, and do_initial_child_stuff already ran the inferior to the initial breakpoint (or an exit, if creating the process fails). Report it now. */ - *ourstatus =3D cached_status; - cached_status.set_ignore (); + *ourstatus =3D windows_process.cached_status; + windows_process.cached_status.set_ignore (); return debug_event_ptid (&windows_process.current_event); } =20 @@ -1384,7 +1360,7 @@ win32_process_target::request_interrupt () return; =20 /* Last resort, suspend all threads manually. */ - soft_interrupt_requested =3D 1; + windows_process.soft_interrupt_requested =3D 1; } =20 bool diff --git a/gdbserver/win32-low.h b/gdbserver/win32-low.h index b29e8b3a10a..58bb105b283 100644 --- a/gdbserver/win32-low.h +++ b/gdbserver/win32-low.h @@ -172,8 +172,41 @@ public: } }; =20 +struct gdbserver_windows_process : public windows_nat::windows_process_info +{ + windows_nat::windows_thread_info *thread_rec + (ptid_t ptid, + windows_nat::thread_disposition_type disposition) override; + int handle_output_debug_string (struct target_waitstatus *ourstatus) ove= rride; + void handle_load_dll (const char *dll_name, LPVOID base) override; + void handle_unload_dll () override; + bool handle_access_violation (const EXCEPTION_RECORD *rec) override; + + int attaching =3D 0; + + /* A status that hasn't been reported to the core yet, and so + win32_wait should return it next, instead of fetching the next + debug event off the win32 API. */ + struct target_waitstatus cached_status; + + /* Non zero if an interrupt request is to be satisfied by suspending + all threads. */ + int soft_interrupt_requested =3D 0; + + /* Non zero if the inferior is stopped in a simulated breakpoint done + by suspending all the threads. */ + int faked_breakpoint =3D 0; + + /* True if current_process_handle needs to be closed. */ + bool open_process_used =3D false; + + /* Zero during the child initialization phase, and nonzero + otherwise. */ + int child_initialization_done =3D 0; +}; + /* The sole Windows process. */ -extern windows_nat::windows_process_info windows_process; +extern gdbserver_windows_process windows_process; =20 /* Retrieve the context for this thread, if not already retrieved. */ extern void win32_require_context (windows_nat::windows_thread_info *th);