* linux-low.c (linux_write_memory): Bail out early if peeking

memory failed.
This commit is contained in:
Pedro Alves
2010-03-14 19:34:47 +00:00
parent c3adc08c6f
commit 93ae6fdc31
2 changed files with 14 additions and 4 deletions

View File

@ -1,3 +1,8 @@
2010-03-14 Pedro Alves <pedro@codesourcery.com>
* linux-low.c (linux_write_memory): Bail out early if peeking
memory failed.
2010-03-14 Pedro Alves <pedro@codesourcery.com> 2010-03-14 Pedro Alves <pedro@codesourcery.com>
* linux-low.h (struct lwp_info): New fields * linux-low.h (struct lwp_info): New fields

View File

@ -2556,9 +2556,8 @@ linux_read_memory (CORE_ADDR memaddr, unsigned char *myaddr, int len)
return 0; return 0;
} }
/* Copy LEN bytes of data from debugger memory at MYADDR /* Copy LEN bytes of data from debugger memory at MYADDR to inferior's
to inferior's memory at MEMADDR. memory at MEMADDR. On failure (cannot write to the inferior)
On failure (cannot write the inferior)
returns the value of errno. */ returns the value of errno. */
static int static int
@ -2590,13 +2589,17 @@ linux_write_memory (CORE_ADDR memaddr, const unsigned char *myaddr, int len)
/* Fill start and end extra bytes of buffer with existing memory data. */ /* Fill start and end extra bytes of buffer with existing memory data. */
errno = 0;
/* Coerce the 3rd arg to a uintptr_t first to avoid potential gcc warning /* Coerce the 3rd arg to a uintptr_t first to avoid potential gcc warning
about coercing an 8 byte integer to a 4 byte pointer. */ about coercing an 8 byte integer to a 4 byte pointer. */
buffer[0] = ptrace (PTRACE_PEEKTEXT, pid, buffer[0] = ptrace (PTRACE_PEEKTEXT, pid,
(PTRACE_ARG3_TYPE) (uintptr_t) addr, 0); (PTRACE_ARG3_TYPE) (uintptr_t) addr, 0);
if (errno)
return errno;
if (count > 1) if (count > 1)
{ {
errno = 0;
buffer[count - 1] buffer[count - 1]
= ptrace (PTRACE_PEEKTEXT, pid, = ptrace (PTRACE_PEEKTEXT, pid,
/* Coerce to a uintptr_t first to avoid potential gcc warning /* Coerce to a uintptr_t first to avoid potential gcc warning
@ -2604,9 +2607,11 @@ linux_write_memory (CORE_ADDR memaddr, const unsigned char *myaddr, int len)
(PTRACE_ARG3_TYPE) (uintptr_t) (addr + (count - 1) (PTRACE_ARG3_TYPE) (uintptr_t) (addr + (count - 1)
* sizeof (PTRACE_XFER_TYPE)), * sizeof (PTRACE_XFER_TYPE)),
0); 0);
if (errno)
return errno;
} }
/* Copy data to be written over corresponding part of buffer */ /* Copy data to be written over corresponding part of buffer. */
memcpy ((char *) buffer + (memaddr & (sizeof (PTRACE_XFER_TYPE) - 1)), myaddr, len); memcpy ((char *) buffer + (memaddr & (sizeof (PTRACE_XFER_TYPE) - 1)), myaddr, len);