Reset errno before PTRACE_PEEKUSER for MIPS DSP_CONTROL

Message ID 1409588996-14779-1-git-send-email-james.hogan@imgtec.com
State Superseded
Delegated to: Maciej W. Rozycki
Headers

Commit Message

James Hogan Sept. 1, 2014, 4:29 p.m. UTC
  PTRACE_PEEKUSER can return -1, which is usually used to determine whether a
system call has reported an error, so errno must be used alone to determine
whether an error occurred. However errno isn't modified by a successful system
call so it must be reset to a known value (0) before the syscall call.

Add the missing errno reset when reading the DSP_CONTROL register in the native
MIPS Linux backend and the MIPS gdbserver backend.

gdb/:
	* mips-linux-nat.c (mips_linux_read_description): Reset errno to 0 prior
	to reading DSP_CONTROL with PTRACE_PEEKUSER ptrace call.

gdb/gdbserver/:
	* linux-mips-low.c (mips_read_description): Reset errno to 0 prior to
	reading DSP_CONTROL with PTRACE_PEEKUSER ptrace call.
---
 gdb/ChangeLog                  | 5 +++++
 gdb/gdbserver/ChangeLog        | 5 +++++
 gdb/gdbserver/linux-mips-low.c | 1 +
 gdb/mips-linux-nat.c           | 1 +
 4 files changed, 12 insertions(+)
  

Comments

Maciej W. Rozycki Sept. 1, 2014, 5:06 p.m. UTC | #1
On Mon, 1 Sep 2014, James Hogan wrote:

> PTRACE_PEEKUSER can return -1, which is usually used to determine whether a
> system call has reported an error, so errno must be used alone to determine
> whether an error occurred. However errno isn't modified by a successful system
> call so it must be reset to a known value (0) before the syscall call.
> 
> Add the missing errno reset when reading the DSP_CONTROL register in the native
> MIPS Linux backend and the MIPS gdbserver backend.
> 
> gdb/:
> 	* mips-linux-nat.c (mips_linux_read_description): Reset errno to 0 prior
> 	to reading DSP_CONTROL with PTRACE_PEEKUSER ptrace call.
> 
> gdb/gdbserver/:
> 	* linux-mips-low.c (mips_read_description): Reset errno to 0 prior to
> 	reading DSP_CONTROL with PTRACE_PEEKUSER ptrace call.

 Please reformat your ChangeLog entries to stay within 74 columns as per 
GDB coding standards:

http://sourceware.org/gdb/wiki/Internals%20GDB-C-Coding-Standards
http://sourceware.org/ml/gdb-patches/2014-01/msg00216.html

OK with these updates, thanks.

  Maciej
  
James Hogan Sept. 1, 2014, 9:31 p.m. UTC | #2
On Mon, Sep 01, 2014 at 06:06:18PM +0100, Maciej W. Rozycki wrote:
> On Mon, 1 Sep 2014, James Hogan wrote:
> 
> > PTRACE_PEEKUSER can return -1, which is usually used to determine whether a
> > system call has reported an error, so errno must be used alone to determine
> > whether an error occurred. However errno isn't modified by a successful system
> > call so it must be reset to a known value (0) before the syscall call.
> > 
> > Add the missing errno reset when reading the DSP_CONTROL register in the native
> > MIPS Linux backend and the MIPS gdbserver backend.
> > 
> > gdb/:
> > 	* mips-linux-nat.c (mips_linux_read_description): Reset errno to 0 prior
> > 	to reading DSP_CONTROL with PTRACE_PEEKUSER ptrace call.
> > 
> > gdb/gdbserver/:
> > 	* linux-mips-low.c (mips_read_description): Reset errno to 0 prior to
> > 	reading DSP_CONTROL with PTRACE_PEEKUSER ptrace call.
> 
>  Please reformat your ChangeLog entries to stay within 74 columns as per 
> GDB coding standards:
> 
> http://sourceware.org/gdb/wiki/Internals%20GDB-C-Coding-Standards
> http://sourceware.org/ml/gdb-patches/2014-01/msg00216.html

Yes, sorry about that, and thanks for the links. I'll fix and resend.

> 
> OK with these updates, thanks.
> 
>   Maciej

Thanks
James
  

Patch

diff --git a/gdb/ChangeLog b/gdb/ChangeLog
index 8963878eb8ca..e4004d96cac8 100644
--- a/gdb/ChangeLog
+++ b/gdb/ChangeLog
@@ -1,3 +1,8 @@ 
+2014-09-01  James Hogan  <james.hogan@imgtec.com>
+
+	* mips-linux-nat.c (mips_linux_read_description): Reset errno to 0 prior
+	to reading DSP_CONTROL with PTRACE_PEEKUSER ptrace call.
+
 2014-09-01  Maciej W. Rozycki  <macro@codesourcery.com>
 
 	* varobj.c (_initialize_varobj): Move to the end of file.
diff --git a/gdb/gdbserver/ChangeLog b/gdb/gdbserver/ChangeLog
index caa243da5d7d..2d292b92875f 100644
--- a/gdb/gdbserver/ChangeLog
+++ b/gdb/gdbserver/ChangeLog
@@ -1,3 +1,8 @@ 
+2014-09-01  James Hogan  <james.hogan@imgtec.com>
+
+	* linux-mips-low.c (mips_read_description): Reset errno to 0 prior to
+	reading DSP_CONTROL with PTRACE_PEEKUSER ptrace call.
+
 2014-08-29  Gary Benson  <gbenson@redhat.com>
 
 	* server.h (setjmp.h): Do not include.
diff --git a/gdb/gdbserver/linux-mips-low.c b/gdb/gdbserver/linux-mips-low.c
index 1b2160b35371..377284be5422 100644
--- a/gdb/gdbserver/linux-mips-low.c
+++ b/gdb/gdbserver/linux-mips-low.c
@@ -128,6 +128,7 @@  mips_read_description (void)
     {
       int pid = lwpid_of (current_inferior);
 
+      errno = 0;
       ptrace (PTRACE_PEEKUSER, pid, DSP_CONTROL, 0);
       switch (errno)
 	{
diff --git a/gdb/mips-linux-nat.c b/gdb/mips-linux-nat.c
index 88faa1edf692..ffc8411ca3bc 100644
--- a/gdb/mips-linux-nat.c
+++ b/gdb/mips-linux-nat.c
@@ -439,6 +439,7 @@  mips_linux_read_description (struct target_ops *ops)
       if (tid == 0)
 	tid = ptid_get_pid (inferior_ptid);
 
+      errno = 0;
       ptrace (PTRACE_PEEKUSER, tid, DSP_CONTROL, 0);
       switch (errno)
 	{