From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 18755 invoked by alias); 14 Feb 2008 21:09:30 -0000 Received: (qmail 18609 invoked by uid 22791); 14 Feb 2008 21:09:28 -0000 X-Spam-Check-By: sourceware.org Received: from mu-out-0910.google.com (HELO mu-out-0910.google.com) (209.85.134.184) by sourceware.org (qpsmtpd/0.31) with ESMTP; Thu, 14 Feb 2008 21:08:53 +0000 Received: by mu-out-0910.google.com with SMTP id g7so244036muf.0 for ; Thu, 14 Feb 2008 13:08:50 -0800 (PST) Received: by 10.82.168.2 with SMTP id q2mr1719487bue.25.1203023330634; Thu, 14 Feb 2008 13:08:50 -0800 (PST) Received: from pedro-laptop-dell ( [85.240.250.3]) by mx.google.com with ESMTPS id t12sm3734939gvd.2.2008.02.14.13.08.48 (version=TLSv1/SSLv3 cipher=OTHER); Thu, 14 Feb 2008 13:08:48 -0800 (PST) From: Pedro Alves To: gdb-patches@sourceware.org Subject: --multi support for Windows targets (Re: [rfc] Multiple process support in gdbserver) Date: Thu, 14 Feb 2008 21:09:00 -0000 User-Agent: KMail/1.9.6 (enterprise 0.20070907.709405) References: <20071207212352.GB32256@caradoc.them.org> <4797EEC9.10100@portugalmail.pt> <20080130005147.GA25780@caradoc.them.org> In-Reply-To: <20080130005147.GA25780@caradoc.them.org> MIME-Version: 1.0 Content-Disposition: inline Content-Type: Multipart/Mixed; boundary="Boundary-00=_n3KtHvKLkGwn5Y5" Message-Id: <200802142108.55820.pedro_alves@portugalmail.pt> X-IsSubscribed: yes Mailing-List: contact gdb-patches-help@sourceware.org; run by ezmlm Precedence: bulk List-Id: List-Subscribe: List-Archive: List-Post: List-Help: , Sender: gdb-patches-owner@sourceware.org X-SW-Source: 2008-02/txt/msg00237.txt.bz2 --Boundary-00=_n3KtHvKLkGwn5Y5 Content-Type: text/plain; charset="iso-8859-1" Content-Transfer-Encoding: 7bit Content-Disposition: inline Content-length: 710 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 --Boundary-00=_n3KtHvKLkGwn5Y5 Content-Type: text/x-diff; charset="iso-8859-1"; name="win32_gdbserver_multi_process.diff" Content-Transfer-Encoding: 7bit Content-Disposition: attachment; filename="win32_gdbserver_multi_process.diff" Content-length: 5525 2008-02-14 Pedro Alves * 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: --Boundary-00=_n3KtHvKLkGwn5Y5--