From: Pedro Alves Date: Sun, 14 Mar 2010 19:34:47 +0000 (+0000) Subject: * linux-low.c (linux_write_memory): Bail out early if peeking X-Git-Url: https://git.libre-soc.org/?a=commitdiff_plain;h=93ae6fdc3156825efcb9892b98e81ad4ed83e078;p=binutils-gdb.git * linux-low.c (linux_write_memory): Bail out early if peeking memory failed. --- diff --git a/gdb/gdbserver/ChangeLog b/gdb/gdbserver/ChangeLog index f2e39fd64a9..b8c26faf060 100644 --- a/gdb/gdbserver/ChangeLog +++ b/gdb/gdbserver/ChangeLog @@ -1,3 +1,8 @@ +2010-03-14 Pedro Alves + + * linux-low.c (linux_write_memory): Bail out early if peeking + memory failed. + 2010-03-14 Pedro Alves * linux-low.h (struct lwp_info): New fields diff --git a/gdb/gdbserver/linux-low.c b/gdb/gdbserver/linux-low.c index 31ee6e95a27..1b344844bb1 100644 --- a/gdb/gdbserver/linux-low.c +++ b/gdb/gdbserver/linux-low.c @@ -2556,9 +2556,8 @@ linux_read_memory (CORE_ADDR memaddr, unsigned char *myaddr, int len) return 0; } -/* Copy LEN bytes of data from debugger memory at MYADDR - to inferior's memory at MEMADDR. - On failure (cannot write the inferior) +/* Copy LEN bytes of data from debugger memory at MYADDR to inferior's + memory at MEMADDR. On failure (cannot write to the inferior) returns the value of errno. */ 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. */ + errno = 0; /* 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. */ buffer[0] = ptrace (PTRACE_PEEKTEXT, pid, (PTRACE_ARG3_TYPE) (uintptr_t) addr, 0); + if (errno) + return errno; if (count > 1) { + errno = 0; buffer[count - 1] = ptrace (PTRACE_PEEKTEXT, pid, /* 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) * sizeof (PTRACE_XFER_TYPE)), 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);