From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 28447 invoked by alias); 30 Jul 2007 23:34:51 -0000 Received: (qmail 28437 invoked by uid 22791); 30 Jul 2007 23:34:50 -0000 X-Spam-Check-By: sourceware.org Received: from mu-out-0910.google.com (HELO mu-out-0910.google.com) (209.85.134.187) by sourceware.org (qpsmtpd/0.31) with ESMTP; Mon, 30 Jul 2007 23:34:47 +0000 Received: by mu-out-0910.google.com with SMTP id g7so1831951muf for ; Mon, 30 Jul 2007 16:34:44 -0700 (PDT) Received: by 10.86.77.5 with SMTP id z5mr4255338fga.1185838484516; Mon, 30 Jul 2007 16:34:44 -0700 (PDT) Received: from ?88.210.66.21? ( [88.210.66.21]) by mx.google.com with ESMTPS id k9sm15366891nfh.2007.07.30.16.34.41 (version=TLSv1/SSLv3 cipher=RC4-MD5); Mon, 30 Jul 2007 16:34:43 -0700 (PDT) Message-ID: <46AE7420.2020300@portugalmail.pt> Date: Mon, 30 Jul 2007 23:34:00 -0000 From: Pedro Alves User-Agent: Mozilla/5.0 (Windows; U; Windows NT 5.1; pt-BR; rv:1.8.0.12) Gecko/20070509 Thunderbird/1.5.0.12 Mnenhy/0.7.4.0 MIME-Version: 1.0 To: gdb-patches@sourceware.org Subject: [gdbserver] Fix toolhelp usage on Windows CE Content-Type: multipart/mixed; boundary="------------060706020405020208010009" 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-07/txt/msg00317.txt.bz2 This is a multi-part message in MIME format. --------------060706020405020208010009 Content-Type: text/plain; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: 7bit Content-length: 518 Hi, On Windows CE, the toolhelp functionality is implemented on its own dll. Additionally, (and because of the former), the snapshots must be closed with a special close function - CloseToolhelp32Snapshot - unlike the "desktop" Windows versions, which use the standard CloseHandle. The current code isn't doing it right. This patch fixes it. (in case the toolhelp_get_dll_name hunk isn't clear in the diff, I'm just 'reorganizing a bit'/'removing the goto' to minimize the #ifdefery.) OK? Cheers, Pedro Alves --------------060706020405020208010009 Content-Type: text/x-diff; name="toolhelp_wince.diff" Content-Transfer-Encoding: 7bit Content-Disposition: inline; filename="toolhelp_wince.diff" Content-length: 3270 2007-07-31 Pedro Alves * win32-low.c (winapi_CloseToolhelp32Snapshot) [_WIN32_WCE]: New typedef. (win32_CloseToolhelp32Snapshot) [_WIN32_WCE]: New global var. (load_toolhelp) [_WIN32_WCE]: Load TOOLHELP.DLL. Get CloseToolhelp32Snapshot. (toolhelp_get_dll_name) [_WIN32_WCE]: Close the snapshot with CloseToolhelp32Snapshot. --- gdb/gdbserver/win32-low.c | 44 +++++++++++++++++++++++++++++--------------- 1 file changed, 29 insertions(+), 15 deletions(-) Index: src/gdb/gdbserver/win32-low.c =================================================================== --- src.orig/gdb/gdbserver/win32-low.c 2007-07-18 13:47:14.000000000 +0100 +++ src/gdb/gdbserver/win32-low.c 2007-07-18 13:56:44.000000000 +0100 @@ -980,6 +980,10 @@ typedef BOOL (WINAPI *winapi_Module32Nex static winapi_CreateToolhelp32Snapshot win32_CreateToolhelp32Snapshot; static winapi_Module32First win32_Module32First; static winapi_Module32Next win32_Module32Next; +#ifdef _WIN32_WCE +typedef BOOL (WINAPI *winapi_CloseToolhelp32Snapshot) (HANDLE); +static winapi_CloseToolhelp32Snapshot win32_CloseToolhelp32Snapshot; +#endif static BOOL load_toolhelp (void) @@ -993,7 +997,7 @@ load_toolhelp (void) #ifndef _WIN32_WCE dll = GetModuleHandle (_T("KERNEL32.DLL")); #else - dll = GetModuleHandle (_T("COREDLL.DLL")); + dll = LoadLibrary (L"TOOLHELP.DLL"); #endif if (!dll) return FALSE; @@ -1002,11 +1006,19 @@ load_toolhelp (void) GETPROCADDRESS (dll, CreateToolhelp32Snapshot); win32_Module32First = GETPROCADDRESS (dll, Module32First); win32_Module32Next = GETPROCADDRESS (dll, Module32Next); +#ifdef _WIN32_WCE + win32_CloseToolhelp32Snapshot = + GETPROCADDRESS (dll, CloseToolhelp32Snapshot); +#endif } return (win32_CreateToolhelp32Snapshot != NULL && win32_Module32First != NULL - && win32_Module32Next != NULL); + && win32_Module32Next != NULL +#ifdef _WIN32_WCE + && win32_CloseToolhelp32Snapshot != NULL +#endif + ); } static int @@ -1014,6 +1026,7 @@ toolhelp_get_dll_name (DWORD BaseAddress { HANDLE snapshot_module; MODULEENTRY32 modEntry = { sizeof (MODULEENTRY32) }; + int found = 0; if (!load_toolhelp ()) return 0; @@ -1024,24 +1037,25 @@ toolhelp_get_dll_name (DWORD BaseAddress return 0; /* Ignore the first module, which is the exe. */ - if (!win32_Module32First (snapshot_module, &modEntry)) - goto failed; - - while (win32_Module32Next (snapshot_module, &modEntry)) - if ((DWORD) modEntry.modBaseAddr == BaseAddress) - { + if (win32_Module32First (snapshot_module, &modEntry)) + while (win32_Module32Next (snapshot_module, &modEntry)) + if ((DWORD) modEntry.modBaseAddr == BaseAddress) + { #ifdef UNICODE - wcstombs (dll_name_ret, modEntry.szExePath, MAX_PATH + 1); + wcstombs (dll_name_ret, modEntry.szExePath, MAX_PATH + 1); #else - strcpy (dll_name_ret, modEntry.szExePath); + strcpy (dll_name_ret, modEntry.szExePath); #endif - CloseHandle (snapshot_module); - return 1; - } + found = 1; + break; + } -failed: +#ifdef _WIN32_WCE + win32_CloseToolhelp32Snapshot (snapshot_module); +#else CloseHandle (snapshot_module); - return 0; +#endif + return found; } static void --------------060706020405020208010009--