]>
Commit | Line | Data |
---|---|---|
e3366964 AM |
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 | |
5 | ||
6 | An x32 gdb always issues this warning: | |
7 | ||
8 | (gdb) start | |
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 | |
12 | ||
13 | Temporary breakpoint 1, main (argc=1, argv=0xffffd544) at foo.c:25 | |
14 | 25 { | |
15 | (gdb) | |
16 | ||
17 | As described in Linux commit 55283e253771 (x32: Add ptrace for x32): | |
18 | ||
19 | [...] PTRACE_PEEKUSR and PTRACE_POKEUSR are only allowed to access | |
20 | segment and debug registers. [...] | |
21 | ||
22 | The fix is to use PTRACE_GETREGS instead. | |
23 | ||
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 | |
28 | @@ -23,6 +23,7 @@ | |
29 | #include "buffer.h" | |
30 | #include "gdb_wait.h" | |
31 | #include "gdb_ptrace.h" | |
32 | +#include "gregset.h" | |
33 | ||
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; | |
38 | long l; | |
39 | int status, kill_status; | |
40 | + elf_gregset_t regs; | |
41 | ||
42 | return_address | |
43 | = (gdb_byte *) mmap (NULL, 2, PROT_READ | PROT_WRITE, | |
44 | @@ -188,23 +190,19 @@ linux_ptrace_test_ret_to_nx (void) | |
45 | return; | |
46 | } | |
47 | ||
48 | - errno = 0; | |
49 | + if (ptrace (PTRACE_GETREGS, child, (PTRACE_TYPE_ARG3) 0, | |
50 | + (PTRACE_TYPE_ARG4) ®s) < 0) | |
51 | + { | |
52 | + warning (_("linux_ptrace_test_ret_to_nx: Cannot PTRACE_GETREGS: %s"), | |
53 | + safe_strerror (errno)); | |
54 | + } | |
55 | #if defined __i386__ | |
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]; | |
63 | #else | |
64 | # error "!__i386__ && !__x86_64__" | |
65 | #endif | |
66 | - if (errno != 0) | |
67 | - { | |
68 | - warning (_("linux_ptrace_test_ret_to_nx: Cannot PTRACE_PEEKUSER: %s"), | |
69 | - safe_strerror (errno)); | |
70 | - return; | |
71 | - } | |
72 | - pc = (gdb_byte *) (uintptr_t) l; | |
73 | ||
74 | kill (child, SIGKILL); | |
75 | ptrace (PTRACE_KILL, child, (PTRACE_TYPE_ARG3) NULL, | |
76 | -- | |
77 | 1.7.1 | |
78 | ||
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) | |
83 | ||
84 | Fixes, on NIOS GNU/Linux: | |
85 | ||
86 | In file included from | |
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 | |
91 | ^ | |
92 | ||
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. | |
95 | ||
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 | |
100 | @@ -23,7 +23,7 @@ | |
101 | #include "buffer.h" | |
102 | #include "gdb_wait.h" | |
103 | #include "gdb_ptrace.h" | |
104 | -#include "gregset.h" | |
105 | +#include <sys/procfs.h> | |
106 | ||
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 | |
109 | -- | |
110 | 1.7.1 | |
111 |