From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 25629 invoked by alias); 27 Jul 2009 19:59:26 -0000 Received: (qmail 25621 invoked by uid 22791); 27 Jul 2009 19:59:26 -0000 X-SWARE-Spam-Status: No, hits=-2.4 required=5.0 tests=AWL,BAYES_00,J_CHICKENPOX_14,J_CHICKENPOX_55,RCVD_IN_DNSWL_LOW,SPF_PASS X-Spam-Check-By: sourceware.org Received: from sif.is.scarlet.be (HELO sif.is.scarlet.be) (193.74.71.28) by sourceware.org (qpsmtpd/0.43rc1) with ESMTP; Mon, 27 Jul 2009 19:59:17 +0000 Received: from [172.17.1.10] (ip-81-11-238-91.dsl.scarlet.be [81.11.238.91]) by sif.is.scarlet.be (8.14.2/8.14.2) with ESMTP id n6RJwn1O005058; Mon, 27 Jul 2009 21:58:50 +0200 Subject: Re: Patch : gdbserver get_image_name on CE From: Danny Backx Reply-To: danny.backx@scarlet.be To: Pedro Alves Cc: gdb-patches@sourceware.org In-Reply-To: <1247052825.3870.47.camel@pavilion> References: <1244903385.20290.9.camel@pavilion> <1246473648.15871.201.camel@pavilion> <200907012113.06018.pedro@codesourcery.com> <200907041915.32158.pedro@codesourcery.com> <1247046903.3870.43.camel@pavilion> <1247052825.3870.47.camel@pavilion> Content-Type: multipart/mixed; boundary="=-i+md/nOf5MU7nlpgl7iu" Date: Mon, 27 Jul 2009 20:40:00 -0000 Message-Id: <1248724766.5537.390.camel@pavilion> Mime-Version: 1.0 X-DCC-scarlet.be-Metrics: sif 20001; Body=3 Fuz1=3 Fuz2=3 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-07/txt/msg00662.txt.bz2 --=-i+md/nOf5MU7nlpgl7iu Content-Type: text/plain Content-Transfer-Encoding: 7bit Content-length: 1104 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 > > * 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 --=-i+md/nOf5MU7nlpgl7iu Content-Disposition: attachment; filename="x" Content-Type: text/plain; name="x"; charset="UTF-8" Content-Transfer-Encoding: 7bit Content-length: 1649 ? 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; } --=-i+md/nOf5MU7nlpgl7iu--