This is the mail archive of the
gdb-patches@sourceware.org
mailing list for the GDB project.
--multi support for Windows targets (Re: [rfc] Multiple process support in gdbserver)
- From: Pedro Alves <pedro_alves at portugalmail dot pt>
- To: gdb-patches at sourceware dot org
- Date: Thu, 14 Feb 2008 21:08:55 +0000
- Subject: --multi support for Windows targets (Re: [rfc] Multiple process support in gdbserver)
- References: <20071207212352.GB32256@caradoc.them.org> <4797EEC9.10100@portugalmail.pt> <20080130005147.GA25780@caradoc.them.org>
A Wednesday 30 January 2008 00:51:47, Daniel Jacobowitz wrote:
> On Thu, Jan 24, 2008 at 01:50:01AM +0000, Pedro Alves wrote:
> > In addition to that, this almost works on Windows targets, we just
> > need to clean up the state when the inferiors are detached or
> > killed, like you're doing on linux. If you prefer, I can post a
> > patch once this goes in.
>
> Great! Yes, please do.
Here it is. Basically, it's just clearing state and freeing heap
objects, since without --multi we didn't care much. Tested on
i686-pc-cygwin with a local gdbserver, no regressions. Without
this patch, --multi will only work the first run, the following
runs trip on variables with garbage on them.
--
Pedro Alves
2008-02-14 Pedro Alves <pedro_alves@portugalmail.pt>
* win32-low.c (do_initial_child_stuff): Add process handle
parameter. Set current_process_handle and current_process_id from the
parameters. Clear globals.
(win32_create_inferior): Don't set current_process_handle and
current_process_id here. Instead pass them on the call to
do_initial_child_stuff.
(win32_attach): Likewise.
(win32_clear_inferiors): New.
(win32_kill): Don't close the current process handle or the
current thread handle here. Instead call win32_clear_inferiors.
(win32_detach): Don't open a new handle to the process. Call
win32_clear_inferiors.
(win32_join): Don't rely on current_process_handle; open a new
handle using the process id.
(win32_wait): Call win32_clear_inferiors when the inferior process
has exited.
---
gdb/gdbserver/win32-low.c | 78 +++++++++++++++++++---------------------------
1 file changed, 33 insertions(+), 45 deletions(-)
Index: src/gdb/gdbserver/win32-low.c
===================================================================
--- src.orig/gdb/gdbserver/win32-low.c 2008-02-08 01:02:18.000000000 +0000
+++ src/gdb/gdbserver/win32-low.c 2008-02-14 20:53:56.000000000 +0000
@@ -69,6 +69,7 @@ int using_threads = 1;
static int attaching = 0;
static HANDLE current_process_handle = NULL;
static DWORD current_process_id = 0;
+static DWORD main_thread_id = 0;
static enum target_signal last_sig = TARGET_SIGNAL_0;
/* The current debug event from WaitForDebugEvent. */
@@ -89,8 +90,6 @@ typedef BOOL WINAPI (*winapi_DebugSetPro
typedef BOOL WINAPI (*winapi_DebugBreakProcess) (HANDLE);
typedef BOOL WINAPI (*winapi_GenerateConsoleCtrlEvent) (DWORD, DWORD);
-static DWORD main_thread_id = 0;
-
static void win32_resume (struct thread_resume *resume_info);
/* Get the thread ID from the current selected inferior (the current
@@ -290,10 +289,17 @@ child_init_thread_list (void)
}
static void
-do_initial_child_stuff (DWORD pid)
+do_initial_child_stuff (HANDLE proch, DWORD pid)
{
last_sig = TARGET_SIGNAL_0;
+ current_process_handle = proch;
+ current_process_id = pid;
+ main_thread_id = 0;
+
+ soft_interrupt_requested = 0;
+ faked_breakpoint = 0;
+
memset (¤t_event, 0, sizeof (current_event));
child_init_thread_list ();
@@ -573,10 +579,7 @@ win32_create_inferior (char *program, ch
CloseHandle (pi.hThread);
#endif
- current_process_handle = pi.hProcess;
- current_process_id = pi.dwProcessId;
-
- do_initial_child_stuff (current_process_id);
+ do_initial_child_stuff (pi.hProcess, pi.dwProcessId);
return current_process_id;
}
@@ -607,9 +610,7 @@ win32_attach (unsigned long pid)
/* win32_wait needs to know we're attaching. */
attaching = 1;
- current_process_handle = h;
- current_process_id = pid;
- do_initial_child_stuff (pid);
+ do_initial_child_stuff (h, pid);
return 0;
}
@@ -666,12 +667,20 @@ handle_output_debug_string (struct targe
#undef READ_BUFFER_LEN
}
+static void
+win32_clear_inferiors (void)
+{
+ if (current_process_handle != NULL)
+ CloseHandle (current_process_handle);
+
+ for_each_inferior (&all_threads, delete_thread_info);
+ clear_inferiors ();
+}
+
/* Kill all inferiors. */
static void
win32_kill (void)
{
- win32_thread_info *current_thread;
-
if (current_process_handle == NULL)
return;
@@ -691,22 +700,13 @@ win32_kill (void)
}
}
- CloseHandle (current_process_handle);
-
- current_thread = inferior_target_data (current_inferior);
- if (current_thread && current_thread->h)
- {
- /* This may fail in an attached process, so don't check. */
- (void) CloseHandle (current_thread->h);
- }
+ win32_clear_inferiors ();
}
/* Detach from all inferiors. */
static int
win32_detach (void)
{
- HANDLE h;
-
winapi_DebugActiveProcessStop DebugActiveProcessStop = NULL;
winapi_DebugSetProcessKillOnExit DebugSetProcessKillOnExit = NULL;
#ifdef _WIN32_WCE
@@ -721,16 +721,6 @@ win32_detach (void)
|| DebugActiveProcessStop == NULL)
return -1;
- /* We need a new handle, since DebugActiveProcessStop
- closes all the ones that came through the events. */
- if ((h = OpenProcess (PROCESS_ALL_ACCESS,
- FALSE,
- current_process_id)) == NULL)
- {
- /* The process died. */
- return -1;
- }
-
{
struct thread_resume resume;
resume.thread = -1;
@@ -741,13 +731,11 @@ win32_detach (void)
}
if (!DebugActiveProcessStop (current_process_id))
- {
- CloseHandle (h);
- return -1;
- }
+ return -1;
+
DebugSetProcessKillOnExit (FALSE);
- current_process_handle = h;
+ win32_clear_inferiors ();
return 0;
}
@@ -755,15 +743,14 @@ win32_detach (void)
static void
win32_join (void)
{
- if (current_process_id == 0
- || current_process_handle == NULL)
- return;
-
- WaitForSingleObject (current_process_handle, INFINITE);
- CloseHandle (current_process_handle);
+ extern unsigned long signal_pid;
- current_process_handle = NULL;
- current_process_id = 0;
+ HANDLE h = OpenProcess (PROCESS_ALL_ACCESS, FALSE, signal_pid);
+ if (h != NULL)
+ {
+ WaitForSingleObject (h, INFINITE);
+ CloseHandle (h);
+ }
}
/* Return 1 iff the thread with thread ID TID is alive. */
@@ -1546,6 +1533,7 @@ win32_wait (char *status)
our_status.value.integer));
*status = 'W';
+ win32_clear_inferiors ();
return our_status.value.integer;
case TARGET_WAITKIND_STOPPED:
case TARGET_WAITKIND_LOADED: