Bug 20413 - x32: linux_ptrace_test_ret_to_nx: Cannot PTRACE_PEEKUSER
Summary: x32: linux_ptrace_test_ret_to_nx: Cannot PTRACE_PEEKUSER
Status: RESOLVED FIXED
Alias: None
Product: gdb
Classification: Unclassified
Component: gdb (show other bugs)
Version: HEAD
: P2 normal
Target Milestone: 7.12
Assignee: Not yet assigned to anyone
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2016-07-26 14:59 UTC by Pedro Alves
Modified: 2016-08-11 11:05 UTC (History)
1 user (show)

See Also:
Host:
Target:
Build:
Last reconfirmed:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Pedro Alves 2016-07-26 14:59:33 UTC
A x32 gdb always issues this warning:

 (gdb) start
 Temporary breakpoint 1 at 0x4043e9: file foo.c, line 25.
 Starting program: a.bout
 warning: linux_ptrace_test_ret_to_nx: Cannot PTRACE_PEEKUSER: Input/output error

 Temporary breakpoint 1, main (argc=1, argv=0xffffd544) at foo.c:25
 25      {
 (gdb)

This is just a warning, and shouldn't affect debugging in any way.  Still, it's annoying.
Comment 1 Sourceware Commits 2016-07-26 18:40:41 UTC
The master branch has been updated by Pedro Alves <palves@sourceware.org>:

https://sourceware.org/git/gitweb.cgi?p=binutils-gdb.git;h=40c31709c6a51926fcb409611caa52b2da6515c0

commit 40c31709c6a51926fcb409611caa52b2da6515c0
Author: Pedro Alves <palves@redhat.com>
Date:   Tue Jul 26 19:35:40 2016 +0100

    Fix PR gdb/20413 - x32: linux_ptrace_test_ret_to_nx: Cannot PTRACE_PEEKUSER
    
    An x32 gdb always issues this warning:
    
     (gdb) start
     Temporary breakpoint 1 at 0x4043e9: file foo.c, line 25.
     Starting program: a.out
     warning: linux_ptrace_test_ret_to_nx: Cannot PTRACE_PEEKUSER: Input/output error
    
     Temporary breakpoint 1, main (argc=1, argv=0xffffd544) at foo.c:25
     25      {
     (gdb)
    
    As described in Linux commit 55283e253771 (x32: Add ptrace for x32):
    
        [...] PTRACE_PEEKUSR and PTRACE_POKEUSR are only allowed to access
        segment and debug registers. [...]
    
    The fix is to use PTRACE_GETREGS instead.
    
    gdb/ChangeLog:
    2016-07-26  Pedro Alves  <palves@redhat.com>
    
    	* nat/linux-ptrace.c: Include "gregset.h".
    	(linux_ptrace_test_ret_to_nx): Use PTRACE_GETREGS instead of
    	PTRACE_PEEKUSER.
Comment 2 Pedro Alves 2016-07-26 18:42:28 UTC
Fixed in master.
Comment 3 hmb 2016-07-27 11:11:25 UTC
Thanks Pedro for doing that.
Comment 4 hmb 2016-08-11 10:07:07 UTC
This fix breaks NIOS GNU/Linux build.



In file included from /scratch/mbilal/nois-lite/src/gdb-trunk/gdb/gdbserver/../nat/linux-ptrace.c:26:0:
/scratch/mbilal/nois-lite/src/gdb-trunk/gdb/gdbserver/../gregset.h:27:23: error: unknown type name 'gregset_t'
 #define GDB_GREGSET_T gregset_t
                       ^
/scratch/mbilal/nois-lite/src/gdb-trunk/gdb/gdbserver/../gregset.h:34:9: note: in expansion of macro 'GDB_GREGSET_T'
 typedef GDB_GREGSET_T gdb_gregset_t;
         ^~~~~~~~~~~~~
/scratch/mbilal/nois-lite/src/gdb-trunk/gdb/gdbserver/../gregset.h:31:24: error: unknown type name 'fpregset_t'
 #define GDB_FPREGSET_T fpregset_t
                        ^
/scratch/mbilal/nois-lite/src/gdb-trunk/gdb/gdbserver/../gregset.h:35:9: note: in expansion of macro 'GDB_FPREGSET_T'
 typedef GDB_FPREGSET_T gdb_fpregset_t;
         ^~~~~~~~~~~~~~
Makefile:624: recipe for target 'linux-ptrace.o' failed
make: *** [linux-ptrace.o] Error 1
make: *** Waiting for unfinished jobs....
Comment 5 Pedro Alves 2016-08-11 10:29:48 UTC
Does this fix it?

diff --git c/gdb/nat/linux-ptrace.c w/gdb/nat/linux-ptrace.c
index 980ed53..f00f179 100644
--- c/gdb/nat/linux-ptrace.c
+++ w/gdb/nat/linux-ptrace.c
@@ -23,7 +23,7 @@
 #include "buffer.h"
 #include "gdb_wait.h"
 #include "gdb_ptrace.h"
-#include "gregset.h"
+#include <sys/procfs.h>
 
 /* Stores the ptrace options supported by the running kernel.
    A value of -1 means we did not check for features yet.  A value
Comment 6 hmb 2016-08-11 10:56:26 UTC
Hi Pedro,

Yes, it fixes Nios GNU/Linux build as well as no regression found for x32 gdb server build also :)
Comment 7 Sourceware Commits 2016-08-11 11:03:36 UTC
The master branch has been updated by Pedro Alves <palves@sourceware.org>:

https://sourceware.org/git/gitweb.cgi?p=binutils-gdb.git;h=39b22471578843019026c50fcdbe0483a6045970

commit 39b22471578843019026c50fcdbe0483a6045970
Author: Pedro Alves <palves@redhat.com>
Date:   Thu Aug 11 12:01:22 2016 +0100

    Fix fallout from gdb/20413's fix (x32: linux_ptrace_test_ret_to_nx: Cannot PTRACE_PEEKUSER)
    
    Fixes, on NIOS GNU/Linux:
    
      In file included from
      /scratch/mbilal/nois-lite/src/gdb-trunk/gdb/gdbserver/../nat/linux-ptrace.c:26:0:
      /scratch/mbilal/nois-lite/src/gdb-trunk/gdb/gdbserver/../gregset.h:27:23:
      error: unknown type name 'gregset_t'
       #define GDB_GREGSET_T gregset_t
    			 ^
    
    Fix this by including sys/procfs.h directly.  We shouldn't really be
    including a gdb-only header in a gdb/nat/ file, anyway.  Whoops.
    
    gdb/ChangeLog:
    2016-08-11  Pedro Alves  <palves@redhat.com>
    
    	PR gdb/20413
    	* nat/linux-ptrace.c: Include <sys/procfs.h> instead of
    	"gregset.h".
Comment 8 Sourceware Commits 2016-08-11 11:04:54 UTC
The gdb-7.12-branch branch has been updated by Pedro Alves <palves@sourceware.org>:

https://sourceware.org/git/gitweb.cgi?p=binutils-gdb.git;h=e565c44e294111fdc2b84396917b0c4ffed916fb

commit e565c44e294111fdc2b84396917b0c4ffed916fb
Author: Pedro Alves <palves@redhat.com>
Date:   Thu Aug 11 12:03:18 2016 +0100

    Fix fallout from gdb/20413's fix (x32: linux_ptrace_test_ret_to_nx: Cannot PTRACE_PEEKUSER)
    
    Fixes, on NIOS GNU/Linux:
    
      In file included from
      /scratch/mbilal/nois-lite/src/gdb-trunk/gdb/gdbserver/../nat/linux-ptrace.c:26:0:
      /scratch/mbilal/nois-lite/src/gdb-trunk/gdb/gdbserver/../gregset.h:27:23:
      error: unknown type name 'gregset_t'
       #define GDB_GREGSET_T gregset_t
    			 ^
    
    Fix this by including sys/procfs.h directly.  We shouldn't really be
    including a gdb-only header in a gdb/nat/ file, anyway.  Whoops.
    
    gdb/ChangeLog:
    2016-08-11  Pedro Alves  <palves@redhat.com>
    
    	PR gdb/20413
    	* nat/linux-ptrace.c: Include <sys/procfs.h> instead of
    	"gregset.h".
Comment 9 Pedro Alves 2016-08-11 11:05:39 UTC
Fixed.  Thanks!