Mirror of the gdb-patches mailing list
 help / color / mirror / Atom feed
From: Danny Backx <danny.backx@scarlet.be>
To: gdb-patches <gdb-patches@sourceware.org>
Subject: Patch : gdbserver get_image_name on CE
Date: Sun, 07 Jun 2009 09:18:00 -0000	[thread overview]
Message-ID: <1244366297.11918.210.camel@pavilion> (raw)

[-- Attachment #1: Type: text/plain, Size: 487 bytes --]

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  <dannybackx@users.sourceforge.net>

	* 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

[-- Attachment #2: gdbserver-get_image_name.patch --]
[-- Type: text/x-patch, Size: 2974 bytes --]

*** /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 *,

             reply	other threads:[~2009-06-07  9:18 UTC|newest]

Thread overview: 31+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2009-06-07  9:18 Danny Backx [this message]
2009-06-07 17:03 ` Pedro Alves
2009-06-07 18:02   ` Danny Backx
2009-06-07 18:15     ` Pedro Alves
2009-06-07 19:13       ` Danny Backx
2009-06-07 19:28         ` Pedro Alves
2009-06-08 18:13           ` Danny Backx
2009-06-12 22:18       ` Danny Backx
2009-06-13  6:28         ` Johnny Willemsen
2009-06-13 14:29 Danny Backx
2009-06-13 18:05 ` Pedro Alves
2009-06-13 18:08   ` Pedro Alves
2009-06-14  8:35     ` Danny Backx
2009-06-14 13:56       ` Pedro Alves
2009-06-14  8:47   ` Danny Backx
2009-06-14  9:48     ` Danny Backx
2009-06-14 14:23       ` Pedro Alves
2009-06-21  9:50         ` Danny Backx
2009-06-30 21:07           ` Danny Backx
2009-06-30 21:56             ` Pedro Alves
2009-07-01 18:41               ` Danny Backx
2009-07-01 18:52                 ` Pedro Alves
2009-07-01 19:12                   ` Danny Backx
2009-07-01 20:12                 ` Pedro Alves
2009-07-04 18:14                   ` Pedro Alves
2009-07-08  9:55                     ` Danny Backx
2009-07-08 11:34                       ` Danny Backx
2009-07-27 20:40                         ` Danny Backx
2009-07-01 19:31               ` Danny Backx
2009-06-14 14:34       ` Pedro Alves
2009-06-14 14:05     ` Pedro Alves

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=1244366297.11918.210.camel@pavilion \
    --to=danny.backx@scarlet.be \
    --cc=gdb-patches@sourceware.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox