* win32-low.c (child_xfer_memory): Check if ReadProcessMemory
[deliverable/binutils-gdb.git] / gdb / gdbserver / win32-low.c
index 4e87a43a4c52a3d1d8ba006058d17204f2c3c53a..549c29f082558ae6ede647efce3c9e36cdcde380 100644 (file)
@@ -278,21 +278,30 @@ static int
 child_xfer_memory (CORE_ADDR memaddr, char *our, int len,
                   int write, struct target_ops *target)
 {
-  SIZE_T done;
+  BOOL success;
+  SIZE_T done = 0;
+  DWORD lasterror = 0;
   uintptr_t addr = (uintptr_t) memaddr;
 
   if (write)
     {
-      WriteProcessMemory (current_process_handle, (LPVOID) addr,
-                         (LPCVOID) our, len, &done);
+      success = WriteProcessMemory (current_process_handle, (LPVOID) addr,
+                                   (LPCVOID) our, len, &done);
+      if (!success)
+       lasterror = GetLastError ();
       FlushInstructionCache (current_process_handle, (LPCVOID) addr, len);
     }
   else
     {
-      ReadProcessMemory (current_process_handle, (LPCVOID) addr, (LPVOID) our,
-                        len, &done);
+      success = ReadProcessMemory (current_process_handle, (LPCVOID) addr,
+                                  (LPVOID) our, len, &done);
+      if (!success)
+       lasterror = GetLastError ();
     }
-  return done;
+  if (!success && lasterror == ERROR_PARTIAL_COPY && done > 0)
+    return done;
+  else
+    return success ? done : -1;
 }
 
 /* Clear out any old thread list and reinitialize it to a pristine
This page took 0.025234 seconds and 4 git commands to generate.