From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 978 invoked by alias); 12 Nov 2007 02:08:26 -0000 Received: (qmail 967 invoked by uid 22791); 12 Nov 2007 02:08:25 -0000 X-Spam-Check-By: sourceware.org Received: from ug-out-1314.google.com (HELO ug-out-1314.google.com) (66.249.92.173) by sourceware.org (qpsmtpd/0.31) with ESMTP; Mon, 12 Nov 2007 02:08:22 +0000 Received: by ug-out-1314.google.com with SMTP id o2so756215uge for ; Sun, 11 Nov 2007 18:08:21 -0800 (PST) Received: by 10.67.25.6 with SMTP id c6mr118368ugj.1194833301508; Sun, 11 Nov 2007 18:08:21 -0800 (PST) Received: from ?192.168.0.4? ( [62.169.107.97]) by mx.google.com with ESMTPS id n34sm3938494ugc.2007.11.11.18.08.18 (version=TLSv1/SSLv3 cipher=RC4-MD5); Sun, 11 Nov 2007 18:08:20 -0800 (PST) Message-ID: <4737B596.30603@portugalmail.pt> Date: Mon, 12 Nov 2007 02:08:00 -0000 From: Pedro Alves User-Agent: Mozilla/5.0 (Windows; U; Windows NT 5.1; pt-BR; rv:1.8.1.6) Gecko/20070728 Thunderbird/2.0.0.6 Mnenhy/0.7.5.0 MIME-Version: 1.0 To: gdb-patches@sourceware.org, Lerele Subject: [gdbserver/win32] (8/11) Tweak attach code to also support Windows CE Content-Type: multipart/mixed; boundary="------------040207090408080003010700" 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: 2007-11/txt/msg00221.txt.bz2 This is a multi-part message in MIME format. --------------040207090408080003010700 Content-Type: text/plain; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: 7bit Content-length: 564 Hi, Adding Windows CE attaching support, I saw that the DebugActiveProcess call was failing with "invalid handle". It turns out that on Windows CE, we can only call DebugActiveProcess if we have an open handle to the process we're attaching to. This patch simply reverses the order of the DebugActiveProcess, OpenProcess calls, so that OpenProcess is done first. As a side effect, if OpenProcess fails, we don't need to undo the DebugActiveProcess with DebugActiveProcessStop any more. Tested on i686-pc-cygwin and arm-wince-mingw32ce. Cheers, Pedro Alves --------------040207090408080003010700 Content-Type: text/x-diff; name="win32_attach_reverse.diff" Content-Transfer-Encoding: 7bit Content-Disposition: inline; filename="win32_attach_reverse.diff" Content-length: 2124 2007-11-12 Pedro Alves * win32-low.c (win32_attach): Call OpenProcess before DebugActiveProcess, not after. Add last error output to error call. --- gdb/gdbserver/win32-low.c | 32 +++++++++++++++++--------------- 1 file changed, 17 insertions(+), 15 deletions(-) Index: src/gdb/gdbserver/win32-low.c =================================================================== --- src.orig/gdb/gdbserver/win32-low.c 2007-11-11 23:16:02.000000000 +0000 +++ src/gdb/gdbserver/win32-low.c 2007-11-11 23:16:12.000000000 +0000 @@ -754,34 +754,36 @@ win32_create_inferior (char *program, ch static int win32_attach (unsigned long pid) { - winapi_DebugActiveProcessStop DebugActiveProcessStop = NULL; + HANDLE h; winapi_DebugSetProcessKillOnExit DebugSetProcessKillOnExit = NULL; + DWORD err; #ifdef _WIN32_WCE HMODULE dll = GetModuleHandle (_T("COREDLL.DLL")); #else HMODULE dll = GetModuleHandle (_T("KERNEL32.DLL")); #endif - DebugActiveProcessStop = GETPROCADDRESS (dll, DebugActiveProcessStop); DebugSetProcessKillOnExit = GETPROCADDRESS (dll, DebugSetProcessKillOnExit); - if (DebugActiveProcess (pid)) + h = OpenProcess (PROCESS_ALL_ACCESS, FALSE, pid); + if (h != NULL) { - if (DebugSetProcessKillOnExit != NULL) - DebugSetProcessKillOnExit (FALSE); + if (DebugActiveProcess (pid)) + { + if (DebugSetProcessKillOnExit != NULL) + DebugSetProcessKillOnExit (FALSE); - current_process_handle = OpenProcess (PROCESS_ALL_ACCESS, FALSE, pid); + current_process_handle = h; + current_process_id = pid; + do_initial_child_stuff (pid); + return 0; + } - if (current_process_handle != NULL) - { - current_process_id = pid; - do_initial_child_stuff (pid); - return 0; - } - if (DebugActiveProcessStop != NULL) - DebugActiveProcessStop (current_process_id); + CloseHandle (h); } - error ("Attach to process failed."); + err = GetLastError (); + error ("Attach to process failed (error %d): %s\n", + (int) err, strwinerror (err)); } /* Handle OUTPUT_DEBUG_STRING_EVENT from child process. */ --------------040207090408080003010700--