From: Danny Backx <danny.backx@scarlet.be>
To: Pedro Alves <pedro@codesourcery.com>
Cc: gdb-patches@sourceware.org
Subject: Re: Patch : gdbserver get_image_name on CE
Date: Mon, 27 Jul 2009 20:40:00 -0000 [thread overview]
Message-ID: <1248724766.5537.390.camel@pavilion> (raw)
In-Reply-To: <1247052825.3870.47.camel@pavilion>
[-- Attachment #1: Type: text/plain, Size: 1104 bytes --]
Ping ?
On Wed, 2009-07-08 at 13:33 +0200, Danny Backx wrote:
> On Wed, 2009-07-08 at 11:55 +0200, Danny Backx wrote:
> > It looks like ReadProcessMemory refuses to read from an address beyond
> > the pointer, but it does work from the pointer itself.
> >
> > I've changed my code such that it loops, and tries to read a bigger
> > chunk of memory at each iteration.
> >
> > I'm not bothering you with that code or its debug output right now.
> >
> > In that way, the code appears to work, and it complies with the
> > documentation saying not to read more than required.
> >
> > Shall I submit a new patch based on this ?
> >
> > Danny
>
> Ignore that question, here's the patch.
>
> Please comment on its contents and on my adherence to the coding
> standards. Apologies for that, I seem to have a hard time learning that.
>
> Danny
>
> 2009-07-08 Danny Backx <dannybackx@users.sourceforge.net>
>
> * win32-low.c (get_image_name) : Work around ReadProcessMemory
> failure when reading at arbitrary addresses.
>
--
Danny Backx ; danny.backx - at - scarlet.be ; http://danny.backx.info
[-- Attachment #2: x --]
[-- Type: text/plain, Size: 1649 bytes --]
? win32-low.c.ok
? x
Index: win32-low.c
===================================================================
RCS file: /cvs/src/src/gdb/gdbserver/win32-low.c,v
retrieving revision 1.38
diff -u -r1.38 win32-low.c
--- win32-low.c 4 Jul 2009 18:13:28 -0000 1.38
+++ win32-low.c 8 Jul 2009 11:29:25 -0000
@@ -922,7 +922,6 @@
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.
@@ -945,21 +944,23 @@
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;
+ /* ReadProcessMemory sometimes fails when reading a (w)char at a time, but
+ * we can't just read MAX_PATH (w)chars either : msdn says not to cross the
+ * boundary into inaccessible areas.
+ * So we loop, reading more characters each time, until we find the NULL.
+ */
+ WCHAR *wbuf = alloca ((MAX_PATH + 1) * size);
+ while (1)
+ {
+ ReadProcessMemory (h, address_ptr, wbuf, ++len * size, &done);
+ if (wbuf[len - 1] == 0)
+ break;
+ }
if (!unicode)
ReadProcessMemory (h, address_ptr, buf, len, &done);
else
- {
- 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);
- }
+ WideCharToMultiByte (CP_ACP, 0, wbuf, len, buf, len, 0, 0);
return buf;
}
next prev parent reply other threads:[~2009-07-27 19:59 UTC|newest]
Thread overview: 31+ messages / expand[flat|nested] mbox.gz Atom feed top
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 [this message]
2009-07-01 19:31 ` Danny Backx
2009-06-14 14:34 ` Pedro Alves
2009-06-14 14:05 ` Pedro Alves
-- strict thread matches above, loose matches on Subject: below --
2009-06-07 9:18 Danny Backx
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
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=1248724766.5537.390.camel@pavilion \
--to=danny.backx@scarlet.be \
--cc=gdb-patches@sourceware.org \
--cc=pedro@codesourcery.com \
/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