1 From 40c31709c6a51926fcb409611caa52b2da6515c0 Mon Sep 17 00:00:00 2001
2 From: Pedro Alves <palves@redhat.com>
3 Date: Tue, 26 Jul 2016 19:35:40 +0100
4 Subject: [PATCH] Fix PR gdb/20413 - x32: linux_ptrace_test_ret_to_nx: Cannot PTRACE_PEEKUSER
6 An x32 gdb always issues this warning:
9 Temporary breakpoint 1 at 0x4043e9: file foo.c, line 25.
10 Starting program: a.out
11 warning: linux_ptrace_test_ret_to_nx: Cannot PTRACE_PEEKUSER: Input/output error
13 Temporary breakpoint 1, main (argc=1, argv=0xffffd544) at foo.c:25
17 As described in Linux commit 55283e253771 (x32: Add ptrace for x32):
19 [...] PTRACE_PEEKUSR and PTRACE_POKEUSR are only allowed to access
20 segment and debug registers. [...]
22 The fix is to use PTRACE_GETREGS instead.
24 diff --git a/gdb/nat/linux-ptrace.c b/gdb/nat/linux-ptrace.c
25 index 0eaf9a3..980ed53 100644
26 --- a/gdb/nat/linux-ptrace.c
27 +++ b/gdb/nat/linux-ptrace.c
31 #include "gdb_ptrace.h"
34 /* Stores the ptrace options supported by the running kernel.
35 A value of -1 means we did not check for features yet. A value
36 @@ -100,6 +101,7 @@ linux_ptrace_test_ret_to_nx (void)
37 gdb_byte *return_address, *pc;
39 int status, kill_status;
43 = (gdb_byte *) mmap (NULL, 2, PROT_READ | PROT_WRITE,
44 @@ -188,23 +190,19 @@ linux_ptrace_test_ret_to_nx (void)
49 + if (ptrace (PTRACE_GETREGS, child, (PTRACE_TYPE_ARG3) 0,
50 + (PTRACE_TYPE_ARG4) ®s) < 0)
52 + warning (_("linux_ptrace_test_ret_to_nx: Cannot PTRACE_GETREGS: %s"),
53 + safe_strerror (errno));
56 - l = ptrace (PTRACE_PEEKUSER, child, (PTRACE_TYPE_ARG3) (uintptr_t) (EIP * 4),
57 - (PTRACE_TYPE_ARG4) NULL);
58 + pc = (gdb_byte *) (uintptr_t) regs[EIP];
59 #elif defined __x86_64__
60 - l = ptrace (PTRACE_PEEKUSER, child, (PTRACE_TYPE_ARG3) (uintptr_t) (RIP * 8),
61 - (PTRACE_TYPE_ARG4) NULL);
62 + pc = (gdb_byte *) (uintptr_t) regs[RIP];
64 # error "!__i386__ && !__x86_64__"
68 - warning (_("linux_ptrace_test_ret_to_nx: Cannot PTRACE_PEEKUSER: %s"),
69 - safe_strerror (errno));
72 - pc = (gdb_byte *) (uintptr_t) l;
74 kill (child, SIGKILL);
75 ptrace (PTRACE_KILL, child, (PTRACE_TYPE_ARG3) NULL,
79 From e565c44e294111fdc2b84396917b0c4ffed916fb Mon Sep 17 00:00:00 2001
80 From: Pedro Alves <palves@redhat.com>
81 Date: Thu, 11 Aug 2016 12:03:18 +0100
82 Subject: [PATCH] Fix fallout from gdb/20413's fix (x32: linux_ptrace_test_ret_to_nx: Cannot PTRACE_PEEKUSER)
84 Fixes, on NIOS GNU/Linux:
87 /scratch/mbilal/nois-lite/src/gdb-trunk/gdb/gdbserver/../nat/linux-ptrace.c:26:0:
88 /scratch/mbilal/nois-lite/src/gdb-trunk/gdb/gdbserver/../gregset.h:27:23:
89 error: unknown type name 'gregset_t'
90 #define GDB_GREGSET_T gregset_t
93 Fix this by including sys/procfs.h directly. We shouldn't really be
94 including a gdb-only header in a gdb/nat/ file, anyway. Whoops.
96 diff --git a/gdb/nat/linux-ptrace.c b/gdb/nat/linux-ptrace.c
97 index 980ed53..f00f179 100644
98 --- a/gdb/nat/linux-ptrace.c
99 +++ b/gdb/nat/linux-ptrace.c
102 #include "gdb_wait.h"
103 #include "gdb_ptrace.h"
104 -#include "gregset.h"
105 +#include <sys/procfs.h>
107 /* Stores the ptrace options supported by the running kernel.
108 A value of -1 means we did not check for features yet. A value