From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 27859 invoked by alias); 7 Jun 2009 09:18:35 -0000 Received: (qmail 27850 invoked by uid 22791); 7 Jun 2009 09:18:34 -0000 X-SWARE-Spam-Status: No, hits=-2.4 required=5.0 tests=BAYES_00,J_CHICKENPOX_14,J_CHICKENPOX_55,RCVD_IN_DNSWL_LOW,SPF_PASS X-Spam-Check-By: sourceware.org Received: from hel.is.scarlet.be (HELO hel.is.scarlet.be) (193.74.71.26) by sourceware.org (qpsmtpd/0.43rc1) with ESMTP; Sun, 07 Jun 2009 09:18:23 +0000 Received: from [172.17.1.10] (ip-81-11-254-176.dsl.scarlet.be [81.11.254.176]) by hel.is.scarlet.be (8.14.2/8.14.2) with ESMTP id n579IF3t006653; Sun, 7 Jun 2009 11:18:16 +0200 Subject: Patch : gdbserver get_image_name on CE From: Danny Backx Reply-To: danny.backx@scarlet.be To: gdb-patches Content-Type: multipart/mixed; boundary="=-/wgoTncOPkSKTBtzWLRl" Date: Sun, 07 Jun 2009 09:18:00 -0000 Message-Id: <1244366297.11918.210.camel@pavilion> Mime-Version: 1.0 X-DCC-scarlet.be-Metrics: hel 20001; Body=2 Fuz1=2 Fuz2=2 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: 2009-06/txt/msg00152.txt.bz2 --=-/wgoTncOPkSKTBtzWLRl Content-Type: text/plain Content-Transfer-Encoding: 7bit Content-length: 487 Hi, gdbserver doesn't work well yet on WinCE on x86. I'll send more fixes when they are ready. This one fixes obtaining the names of DLLs loaded by the inferior. The patched code also still works on WinCE on ARM. Danny 2009-06-07 Danny Backx * win32-low.c (get_image_name) : Fix code to obtain DLL names, and document that the other code relies on sizeof(WCHAR) == 2. -- Danny Backx ; danny.backx - at - scarlet.be ; http://danny.backx.info --=-/wgoTncOPkSKTBtzWLRl Content-Disposition: attachment; filename="gdbserver-get_image_name.patch" Content-Type: text/x-patch; name="gdbserver-get_image_name.patch"; charset="UTF-8" Content-Transfer-Encoding: 7bit Content-length: 2974 *** /home/danny/src/gdb/gdb/gdb-6.8.orig/gdb/gdbserver/win32-low.c 2008-02-14 23:41:39.000000000 +0100 --- win32-low.c 2009-06-07 11:12:30.000000000 +0200 *************** *** 894,907 **** loaded_dll (buf2, load_addr); } static char * get_image_name (HANDLE h, void *address, int unicode) { ! static char buf[(2 * MAX_PATH) + 1]; DWORD size = unicode ? sizeof (WCHAR) : sizeof (char); char *address_ptr; int len = 0; ! char b[2]; DWORD done; /* Attempt to read the name of the dll that was detected. --- 894,912 ---- loaded_dll (buf2, load_addr); } + /* + * Warning : some parts of this function rely on sizeof(WCHAR) == 2 + */ static char * get_image_name (HANDLE h, void *address, int unicode) { ! static char buf[(2 * MAX_PATH) + 1]; /* here */ DWORD size = unicode ? sizeof (WCHAR) : sizeof (char); char *address_ptr; + #ifndef _WIN32_WCE int len = 0; ! char b[2]; /* here */ ! #endif DWORD done; /* Attempt to read the name of the dll that was detected. *************** *** 924,932 **** return NULL; #endif /* Find the length of the string */ while (ReadProcessMemory (h, address_ptr + len++ * size, &b, size, &done) ! && (b[0] != 0 || b[size - 1] != 0) && done == size) continue; if (!unicode) --- 929,956 ---- return NULL; #endif + #ifdef _WIN32_WCE + /* Always unicode */ + /* Assume you can read it all in one go, or otherwise the done variable will + * tell you how far you've read. + */ + WCHAR *wbuf = alloca ((MAX_PATH + 1) * size); + ReadProcessMemory (h, address_ptr, wbuf, MAX_PATH * size, &done); + if (done < 0 || done > MAX_PATH * size) + buf[0] = '\0'; + else { + int n; + n = wcstombs (buf, wbuf, done); + if (n == (size_t)-1) + buf[0] = '\0'; + /* No need to address the length limit case of the wcstombs call, + * buf has been allocated large enough. */ + } + return buf; + #else /* Find the length of the string */ while (ReadProcessMemory (h, address_ptr + len++ * size, &b, size, &done) ! && (b[0] != 0 || b[size - 1] != 0) && done == size) /* here */ continue; if (!unicode) *************** *** 936,946 **** WCHAR *unicode_address = (WCHAR *) alloca (len * sizeof (WCHAR)); ReadProcessMemory (h, address_ptr, unicode_address, len * sizeof (WCHAR), &done); - WideCharToMultiByte (CP_ACP, 0, unicode_address, len, buf, len, 0, 0); } - return buf; } typedef BOOL (WINAPI *winapi_EnumProcessModules) (HANDLE, HMODULE *, --- 960,969 ---- WCHAR *unicode_address = (WCHAR *) alloca (len * sizeof (WCHAR)); ReadProcessMemory (h, address_ptr, unicode_address, len * sizeof (WCHAR), &done); WideCharToMultiByte (CP_ACP, 0, unicode_address, len, buf, len, 0, 0); } return buf; + #endif } typedef BOOL (WINAPI *winapi_EnumProcessModules) (HANDLE, HMODULE *, --=-/wgoTncOPkSKTBtzWLRl--