From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 2211 invoked by alias); 23 Aug 2013 21:37:16 -0000 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 Received: (qmail 2197 invoked by uid 89); 23 Aug 2013 21:37:15 -0000 X-Spam-SWARE-Status: No, score=-1.6 required=5.0 tests=AWL,BAYES_00,KHOP_THREADED,MSGID_MULTIPLE_AT autolearn=no version=3.3.2 Received: from mailhost.u-strasbg.fr (HELO mr3.u-strasbg.fr) (130.79.222.213) by sourceware.org (qpsmtpd/0.84/v0.84-167-ge50287c) with ESMTP; Fri, 23 Aug 2013 21:37:14 +0000 Received: from mr3.u-strasbg.fr (localhost [127.0.0.1]) by antispam (Postfix) with ESMTP id 53B95A78; Fri, 23 Aug 2013 23:37:10 +0200 (CEST) Received: from mr3.u-strasbg.fr (localhost [127.0.0.1]) by antivirus (Postfix) with ESMTP id A1C177D9; Fri, 23 Aug 2013 23:37:01 +0200 (CEST) Received: from md14.u-strasbg.fr (md14.u-strasbg.fr [130.79.200.249]) by mr3.u-strasbg.fr (Postfix) with ESMTP id 7FDABACC; Fri, 23 Aug 2013 23:36:59 +0200 (CEST) Received: from ms11.u-strasbg.fr (ms11.u-strasbg.fr [130.79.204.111]) by md14.u-strasbg.fr (8.14.3/jtpda-5.5pre1) with ESMTP id r7NLawEv004390 ; Fri, 23 Aug 2013 23:36:59 +0200 Received: from E6510Muller (lec67-4-82-230-53-140.fbx.proxad.net [82.230.53.140]) (Authenticated sender: mullerp) by ms11.u-strasbg.fr (Postfix) with ESMTPSA id 15F501FD90; Fri, 23 Aug 2013 23:36:56 +0200 (CEST) From: "Pierre Muller" To: "'Pedro Alves'" , References: <20130823181245.4023.25651.stgit@brno.lan> In-Reply-To: <20130823181245.4023.25651.stgit@brno.lan> Subject: RE: [PATCH] windows-nat.c: Don't install a deprecated_xfer_memory method. Date: Fri, 23 Aug 2013 21:37:00 -0000 Message-ID: <001201cea048$e2f17ed0$a8d47c70$@muller@ics-cnrs.unistra.fr> MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable X-SW-Source: 2013-08/txt/msg00710.txt.bz2 Hi Pedro, I think that your patch can be further enhanced by this change: ReadProcessMemory and WriteProcessMemory=20 function both fail and report ERROR_PARTIAL_COPY in GetLastError if only a part of the requested memory was read/written. Adding partial memory read/writes to windows native allows for instance to get the true location at which a=20 memory chuck is not available anymore instead of the start position of the read/write attempt if it crosses over to region not readable or not writable. Pierre @@ -2315,20 +2364,23 @@ windows_stop (ptid_t ptid) registers_changed (); /* refresh register state */ } -static int -windows_xfer_memory (CORE_ADDR memaddr, gdb_byte *our, int len, - int write, struct mem_attrib *mem, - struct target_ops *target) +static LONGEST +windows_xfer_memory (gdb_byte *readbuf, const gdb_byte *writebuf, + ULONGEST memaddr, LONGEST len) { SIZE_T done =3D 0; - if (write) + BOOL success; + DWORD lasterror =3D 0; + + if (writebuf !=3D NULL) { DEBUG_MEM (("gdb: write target memory, %d bytes at %s\n", len, core_addr_to_string (memaddr))); - if (!WriteProcessMemory (current_process_handle, - (LPVOID) (uintptr_t) memaddr, our, - len, &done)) - done =3D 0; + success =3D WriteProcessMemory (current_process_handle, + (LPVOID) (uintptr_t) memaddr, writebuf, + len, &done); + if (!success) + lasterror =3D GetLastError (); FlushInstructionCache (current_process_handle, (LPCVOID) (uintptr_t) memaddr, len); } @@ -2336,12 +2388,17 @@ windows_xfer_memory (CORE_ADDR memaddr, { DEBUG_MEM (("gdb: read target memory, %d bytes at %s\n", len, core_addr_to_string (memaddr))); - if (!ReadProcessMemory (current_process_handle, - (LPCVOID) (uintptr_t) memaddr, our, - len, &done)) - done =3D 0; + success =3D ReadProcessMemory (current_process_handle, + (LPCVOID) (uintptr_t) memaddr, readbuf, + len, &done); + if (!success) + lasterror =3D GetLastError (); } - return done; + if (!success && lasterror =3D=3D ERROR_PARTIAL_COPY && done > 0) + return done; + else + return success ? done : TARGET_XFER_E_IO; + } static void > -----Message d'origine----- > De : gdb-patches-owner@sourceware.org [mailto:gdb-patches- > owner@sourceware.org] De la part de Pedro Alves > Envoy=C3=A9 : vendredi 23 ao=C3=BBt 2013 20:13 > =C3=80 : gdb-patches@sourceware.org > Objet : [PATCH] windows-nat.c: Don't install a deprecated_xfer_memory > method. >=20 > This stops another target from installing a > target_ops->deprecated_xfer_memory method. >=20 > I'm not setup for proper Cygwin/Windows testing, but I managed to > cross build gdb from GNU/Linux, and copy the resulting binary to a > Windows box. Running that gdb on itself worked well enough to run to > main, so I can't imagine any regression from this. Does anyone want > (and is willing) to run this through the testsuite? >=20 > gdb/ > 2013-08-23 Pedro Alves >=20 > * windows-nat.c (windows_xfer_memory): Adjust prototype to follow > xfer_partial's interface. Return TARGET_XFER_E_IO on error. > (windows_xfer_partial): Defer TARGET_OBJECT_MEMORY handling to > windows_xfer_memory directly. > (init_windows_ops): Don't install a deprecated_xfer_memory method. > --- > gdb/windows-nat.c | 36 ++++++++++++++---------------------- > 1 file changed, 14 insertions(+), 22 deletions(-) >=20 > diff --git a/gdb/windows-nat.c b/gdb/windows-nat.c > index 9a0241b..a4e7107 100644 > --- a/gdb/windows-nat.c > +++ b/gdb/windows-nat.c > @@ -2315,20 +2315,20 @@ windows_stop (ptid_t ptid) > registers_changed (); /* refresh register state */ > } >=20 > -static int > -windows_xfer_memory (CORE_ADDR memaddr, gdb_byte *our, int len, > - int write, struct mem_attrib *mem, > - struct target_ops *target) > +static LONGEST > +windows_xfer_memory (gdb_byte *readbuf, const gdb_byte *writebuf, > + ULONGEST memaddr, LONGEST len) > { > SIZE_T done =3D 0; > - if (write) > + BOOL success; > + > + if (writebuf !=3D NULL) > { > DEBUG_MEM (("gdb: write target memory, %d bytes at %s\n", > len, core_addr_to_string (memaddr))); > - if (!WriteProcessMemory (current_process_handle, > - (LPVOID) (uintptr_t) memaddr, our, > - len, &done)) > - done =3D 0; > + success =3D WriteProcessMemory (current_process_handle, > + (LPVOID) (uintptr_t) memaddr, writebuf, > + len, &done); > FlushInstructionCache (current_process_handle, > (LPCVOID) (uintptr_t) memaddr, len); > } > @@ -2336,12 +2336,11 @@ windows_xfer_memory (CORE_ADDR memaddr, gdb_byte > *our, int len, > { > DEBUG_MEM (("gdb: read target memory, %d bytes at %s\n", > len, core_addr_to_string (memaddr))); > - if (!ReadProcessMemory (current_process_handle, > - (LPCVOID) (uintptr_t) memaddr, our, > - len, &done)) > - done =3D 0; > + success =3D ReadProcessMemory (current_process_handle, > + (LPCVOID) (uintptr_t) memaddr, readbuf, > + len, &done); > } > - return done; > + return success ? done : TARGET_XFER_E_IO; > } >=20 > static void > @@ -2442,13 +2441,7 @@ windows_xfer_partial (struct target_ops *ops, enum > target_object object, > switch (object) > { > case TARGET_OBJECT_MEMORY: > - if (readbuf) > - return (*ops->deprecated_xfer_memory) (offset, readbuf, > - len, 0/*read*/, NULL, ops); > - if (writebuf) > - return (*ops->deprecated_xfer_memory) (offset, (gdb_byte *) writebuf, > - len, 1/*write*/, NULL, ops); > - return -1; > + return windows_xfer_memory (readbuf, writebuf, offset, len); >=20 > case TARGET_OBJECT_LIBRARIES: > return windows_xfer_shared_libraries (ops, object, annex, readbuf, > @@ -2502,7 +2495,6 @@ init_windows_ops (void) > windows_ops.to_fetch_registers =3D windows_fetch_inferior_registers; > windows_ops.to_store_registers =3D windows_store_inferior_registers; > windows_ops.to_prepare_to_store =3D windows_prepare_to_store; > - windows_ops.deprecated_xfer_memory =3D windows_xfer_memory; > windows_ops.to_xfer_partial =3D windows_xfer_partial; > windows_ops.to_files_info =3D windows_files_info; > windows_ops.to_insert_breakpoint =3D memory_insert_breakpoint;