]> git.ipfire.org Git - thirdparty/binutils-gdb.git/blame - gdb/nat/linux-ptrace.c
Extended-remote follow-exec
[thirdparty/binutils-gdb.git] / gdb / nat / linux-ptrace.c
CommitLineData
5f572dec 1/* Linux-specific ptrace manipulation routines.
32d0add0 2 Copyright (C) 2012-2015 Free Software Foundation, Inc.
5f572dec
JK
3
4 This file is part of GDB.
5
6 This program is free software; you can redistribute it and/or modify
7 it under the terms of the GNU General Public License as published by
8 the Free Software Foundation; either version 3 of the License, or
9 (at your option) any later version.
10
11 This program is distributed in the hope that it will be useful,
12 but WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 GNU General Public License for more details.
15
16 You should have received a copy of the GNU General Public License
17 along with this program. If not, see <http://www.gnu.org/licenses/>. */
18
727605ca 19#include "common-defs.h"
5f572dec 20#include "linux-ptrace.h"
87b0bb13 21#include "linux-procfs.h"
125f8a3d 22#include "linux-waitpid.h"
87b0bb13 23#include "buffer.h"
8bdce1ff 24#include "gdb_wait.h"
5826e159 25#include "gdb_ptrace.h"
87b0bb13 26
de0d863e
DB
27/* Stores the ptrace options supported by the running kernel.
28 A value of -1 means we did not check for features yet. A value
29 of 0 means there are no supported features. */
30static int supported_ptrace_options = -1;
8009206a 31
7ae1a6a6
PA
32/* Find all possible reasons we could fail to attach PID and append
33 these as strings to the already initialized BUFFER. '\0'
34 termination of BUFFER must be done by the caller. */
87b0bb13
JK
35
36void
7ae1a6a6 37linux_ptrace_attach_fail_reason (pid_t pid, struct buffer *buffer)
87b0bb13
JK
38{
39 pid_t tracerpid;
40
8784d563 41 tracerpid = linux_proc_get_tracerpid_nowarn (pid);
87b0bb13 42 if (tracerpid > 0)
7ae1a6a6
PA
43 buffer_xml_printf (buffer, _("process %d is already traced "
44 "by process %d"),
87b0bb13
JK
45 (int) pid, (int) tracerpid);
46
8784d563 47 if (linux_proc_pid_is_zombie_nowarn (pid))
7ae1a6a6
PA
48 buffer_xml_printf (buffer, _("process %d is a zombie "
49 "- the process has already terminated"),
87b0bb13
JK
50 (int) pid);
51}
aa7c7447 52
8784d563
PA
53/* See linux-ptrace.h. */
54
55char *
56linux_ptrace_attach_fail_reason_string (ptid_t ptid, int err)
57{
58 static char *reason_string;
59 struct buffer buffer;
60 char *warnings;
61 long lwpid = ptid_get_lwp (ptid);
62
63 xfree (reason_string);
64
65 buffer_init (&buffer);
66 linux_ptrace_attach_fail_reason (lwpid, &buffer);
67 buffer_grow_str0 (&buffer, "");
68 warnings = buffer_finish (&buffer);
69 if (warnings[0] != '\0')
70 reason_string = xstrprintf ("%s (%d), %s",
049bb5de 71 safe_strerror (err), err, warnings);
8784d563
PA
72 else
73 reason_string = xstrprintf ("%s (%d)",
049bb5de 74 safe_strerror (err), err);
8784d563
PA
75 xfree (warnings);
76 return reason_string;
77}
78
6e3c039e 79#if defined __i386__ || defined __x86_64__
aa7c7447
JK
80
81/* Address of the 'ret' instruction in asm code block below. */
56000a98 82EXTERN_C void linux_ptrace_test_ret_to_nx_instr (void);
aa7c7447
JK
83
84#include <sys/reg.h>
85#include <sys/mman.h>
86#include <signal.h>
aa7c7447 87
6e3c039e 88#endif /* defined __i386__ || defined __x86_64__ */
aa7c7447
JK
89
90/* Test broken off-trunk Linux kernel patchset for NX support on i386. It was
6e3c039e
JK
91 removed in Fedora kernel 88fa1f0332d188795ed73d7ac2b1564e11a0b4cd.
92
93 Test also x86_64 arch for PaX support. */
aa7c7447
JK
94
95static void
96linux_ptrace_test_ret_to_nx (void)
97{
6e3c039e 98#if defined __i386__ || defined __x86_64__
aa7c7447
JK
99 pid_t child, got_pid;
100 gdb_byte *return_address, *pc;
101 long l;
61a31a67 102 int status, kill_status;
aa7c7447
JK
103
104 return_address = mmap (NULL, 2, PROT_READ | PROT_WRITE,
105 MAP_PRIVATE | MAP_ANONYMOUS, -1, 0);
106 if (return_address == MAP_FAILED)
107 {
108 warning (_("linux_ptrace_test_ret_to_nx: Cannot mmap: %s"),
049bb5de 109 safe_strerror (errno));
aa7c7447
JK
110 return;
111 }
112
113 /* Put there 'int3'. */
114 *return_address = 0xcc;
115
116 child = fork ();
117 switch (child)
118 {
119 case -1:
120 warning (_("linux_ptrace_test_ret_to_nx: Cannot fork: %s"),
049bb5de 121 safe_strerror (errno));
aa7c7447
JK
122 return;
123
124 case 0:
96d7229d
LM
125 l = ptrace (PTRACE_TRACEME, 0, (PTRACE_TYPE_ARG3) NULL,
126 (PTRACE_TYPE_ARG4) NULL);
aa7c7447
JK
127 if (l != 0)
128 warning (_("linux_ptrace_test_ret_to_nx: Cannot PTRACE_TRACEME: %s"),
049bb5de 129 safe_strerror (errno));
aa7c7447
JK
130 else
131 {
6e3c039e 132#if defined __i386__
aa7c7447
JK
133 asm volatile ("pushl %0;"
134 ".globl linux_ptrace_test_ret_to_nx_instr;"
135 "linux_ptrace_test_ret_to_nx_instr:"
136 "ret"
137 : : "r" (return_address) : "%esp", "memory");
6e3c039e
JK
138#elif defined __x86_64__
139 asm volatile ("pushq %0;"
140 ".globl linux_ptrace_test_ret_to_nx_instr;"
141 "linux_ptrace_test_ret_to_nx_instr:"
142 "ret"
bdad4180
MF
143 : : "r" ((uint64_t) (uintptr_t) return_address)
144 : "%rsp", "memory");
6e3c039e
JK
145#else
146# error "!__i386__ && !__x86_64__"
147#endif
aa7c7447
JK
148 gdb_assert_not_reached ("asm block did not terminate");
149 }
150
151 _exit (1);
152 }
153
6e3c039e 154 errno = 0;
aa7c7447 155 got_pid = waitpid (child, &status, 0);
6e3c039e
JK
156 if (got_pid != child)
157 {
158 warning (_("linux_ptrace_test_ret_to_nx: waitpid returned %ld: %s"),
049bb5de 159 (long) got_pid, safe_strerror (errno));
6e3c039e
JK
160 return;
161 }
162
163 if (WIFSIGNALED (status))
164 {
165 if (WTERMSIG (status) != SIGKILL)
166 warning (_("linux_ptrace_test_ret_to_nx: WTERMSIG %d is not SIGKILL!"),
167 (int) WTERMSIG (status));
168 else
169 warning (_("Cannot call inferior functions, Linux kernel PaX "
170 "protection forbids return to non-executable pages!"));
171 return;
172 }
173
174 if (!WIFSTOPPED (status))
175 {
176 warning (_("linux_ptrace_test_ret_to_nx: status %d is not WIFSTOPPED!"),
177 status);
178 return;
179 }
aa7c7447
JK
180
181 /* We may get SIGSEGV due to missing PROT_EXEC of the return_address. */
6e3c039e
JK
182 if (WSTOPSIG (status) != SIGTRAP && WSTOPSIG (status) != SIGSEGV)
183 {
184 warning (_("linux_ptrace_test_ret_to_nx: "
185 "WSTOPSIG %d is neither SIGTRAP nor SIGSEGV!"),
186 (int) WSTOPSIG (status));
187 return;
188 }
aa7c7447
JK
189
190 errno = 0;
6e3c039e 191#if defined __i386__
96d7229d
LM
192 l = ptrace (PTRACE_PEEKUSER, child, (PTRACE_TYPE_ARG3) (uintptr_t) (EIP * 4),
193 (PTRACE_TYPE_ARG4) NULL);
6e3c039e 194#elif defined __x86_64__
96d7229d
LM
195 l = ptrace (PTRACE_PEEKUSER, child, (PTRACE_TYPE_ARG3) (uintptr_t) (RIP * 8),
196 (PTRACE_TYPE_ARG4) NULL);
6e3c039e
JK
197#else
198# error "!__i386__ && !__x86_64__"
199#endif
200 if (errno != 0)
201 {
202 warning (_("linux_ptrace_test_ret_to_nx: Cannot PTRACE_PEEKUSER: %s"),
049bb5de 203 safe_strerror (errno));
6e3c039e
JK
204 return;
205 }
aa7c7447
JK
206 pc = (void *) (uintptr_t) l;
207
61a31a67 208 kill (child, SIGKILL);
96d7229d
LM
209 ptrace (PTRACE_KILL, child, (PTRACE_TYPE_ARG3) NULL,
210 (PTRACE_TYPE_ARG4) NULL);
61a31a67
JK
211
212 errno = 0;
213 got_pid = waitpid (child, &kill_status, 0);
214 if (got_pid != child)
6e3c039e 215 {
61a31a67
JK
216 warning (_("linux_ptrace_test_ret_to_nx: "
217 "PTRACE_KILL waitpid returned %ld: %s"),
049bb5de 218 (long) got_pid, safe_strerror (errno));
6e3c039e
JK
219 return;
220 }
61a31a67 221 if (!WIFSIGNALED (kill_status))
aa7c7447 222 {
61a31a67
JK
223 warning (_("linux_ptrace_test_ret_to_nx: "
224 "PTRACE_KILL status %d is not WIFSIGNALED!"),
225 status);
226 return;
aa7c7447
JK
227 }
228
229 /* + 1 is there as x86* stops after the 'int3' instruction. */
230 if (WSTOPSIG (status) == SIGTRAP && pc == return_address + 1)
231 {
232 /* PASS */
233 return;
234 }
235
236 /* We may get SIGSEGV due to missing PROT_EXEC of the RETURN_ADDRESS page. */
237 if (WSTOPSIG (status) == SIGSEGV && pc == return_address)
238 {
239 /* PASS */
240 return;
241 }
242
6e3c039e
JK
243 if ((void (*) (void)) pc != &linux_ptrace_test_ret_to_nx_instr)
244 warning (_("linux_ptrace_test_ret_to_nx: PC %p is neither near return "
245 "address %p nor is the return instruction %p!"),
246 pc, return_address, &linux_ptrace_test_ret_to_nx_instr);
247 else
025e6dce
PA
248 warning (_("Cannot call inferior functions on this system - "
249 "Linux kernel with broken i386 NX (non-executable pages) "
250 "support detected!"));
6e3c039e 251#endif /* defined __i386__ || defined __x86_64__ */
aa7c7447
JK
252}
253
96d7229d
LM
254/* Helper function to fork a process and make the child process call
255 the function FUNCTION, passing CHILD_STACK as parameter.
256
257 For MMU-less targets, clone is used instead of fork, and
258 CHILD_STACK is used as stack space for the cloned child. If NULL,
259 stack space is allocated via malloc (and subsequently passed to
260 FUNCTION). For MMU targets, CHILD_STACK is ignored. */
261
262static int
263linux_fork_to_function (gdb_byte *child_stack, void (*function) (gdb_byte *))
264{
265 int child_pid;
266
267 /* Sanity check the function pointer. */
268 gdb_assert (function != NULL);
269
270#if defined(__UCLIBC__) && defined(HAS_NOMMU)
271#define STACK_SIZE 4096
272
273 if (child_stack == NULL)
274 child_stack = xmalloc (STACK_SIZE * 4);
275
276 /* Use CLONE_VM instead of fork, to support uClinux (no MMU). */
101158d9 277#ifdef __ia64__
96d7229d
LM
278 child_pid = __clone2 (function, child_stack, STACK_SIZE,
279 CLONE_VM | SIGCHLD, child_stack + STACK_SIZE * 2);
101158d9 280#else /* !__ia64__ */
96d7229d
LM
281 child_pid = clone (function, child_stack + STACK_SIZE,
282 CLONE_VM | SIGCHLD, child_stack + STACK_SIZE * 2);
101158d9 283#endif /* !__ia64__ */
96d7229d
LM
284#else /* !defined(__UCLIBC) && defined(HAS_NOMMU) */
285 child_pid = fork ();
286
287 if (child_pid == 0)
288 function (NULL);
289#endif /* defined(__UCLIBC) && defined(HAS_NOMMU) */
290
291 if (child_pid == -1)
292 perror_with_name (("fork"));
293
294 return child_pid;
295}
296
297/* A helper function for linux_check_ptrace_features, called after
298 the child forks a grandchild. */
299
300static void
301linux_grandchild_function (gdb_byte *child_stack)
302{
303 /* Free any allocated stack. */
304 xfree (child_stack);
305
306 /* This code is only reacheable by the grandchild (child's child)
307 process. */
308 _exit (0);
309}
310
311/* A helper function for linux_check_ptrace_features, called after
312 the parent process forks a child. The child allows itself to
313 be traced by its parent. */
314
315static void
316linux_child_function (gdb_byte *child_stack)
317{
318 ptrace (PTRACE_TRACEME, 0, (PTRACE_TYPE_ARG3) 0, (PTRACE_TYPE_ARG4) 0);
319 kill (getpid (), SIGSTOP);
320
321 /* Fork a grandchild. */
322 linux_fork_to_function (child_stack, linux_grandchild_function);
323
324 /* This code is only reacheable by the child (grandchild's parent)
325 process. */
326 _exit (0);
327}
328
8ae377e8
PA
329static void linux_test_for_tracesysgood (int child_pid);
330static void linux_test_for_tracefork (int child_pid);
beed38b8 331static void linux_test_for_exitkill (int child_pid);
8ae377e8 332
96d7229d
LM
333/* Determine ptrace features available on this target. */
334
89245bc0 335void
96d7229d
LM
336linux_check_ptrace_features (void)
337{
338 int child_pid, ret, status;
96d7229d
LM
339
340 /* Initialize the options. */
de0d863e 341 supported_ptrace_options = 0;
96d7229d
LM
342
343 /* Fork a child so we can do some testing. The child will call
344 linux_child_function and will get traced. The child will
345 eventually fork a grandchild so we can test fork event
346 reporting. */
347 child_pid = linux_fork_to_function (NULL, linux_child_function);
348
349 ret = my_waitpid (child_pid, &status, 0);
350 if (ret == -1)
351 perror_with_name (("waitpid"));
352 else if (ret != child_pid)
353 error (_("linux_check_ptrace_features: waitpid: unexpected result %d."),
354 ret);
355 if (! WIFSTOPPED (status))
356 error (_("linux_check_ptrace_features: waitpid: unexpected status %d."),
357 status);
358
8ae377e8 359 linux_test_for_tracesysgood (child_pid);
96d7229d 360
8ae377e8
PA
361 linux_test_for_tracefork (child_pid);
362
beed38b8
JB
363 linux_test_for_exitkill (child_pid);
364
8ae377e8
PA
365 /* Clean things up and kill any pending children. */
366 do
96d7229d
LM
367 {
368 ret = ptrace (PTRACE_KILL, child_pid, (PTRACE_TYPE_ARG3) 0,
369 (PTRACE_TYPE_ARG4) 0);
370 if (ret != 0)
8ae377e8
PA
371 warning (_("linux_check_ptrace_features: failed to kill child"));
372 my_waitpid (child_pid, &status, 0);
96d7229d 373 }
8ae377e8
PA
374 while (WIFSTOPPED (status));
375}
96d7229d 376
8ae377e8
PA
377/* Determine if PTRACE_O_TRACESYSGOOD can be used to catch
378 syscalls. */
379
380static void
381linux_test_for_tracesysgood (int child_pid)
382{
8ae377e8
PA
383 int ret;
384
96d7229d
LM
385 ret = ptrace (PTRACE_SETOPTIONS, child_pid, (PTRACE_TYPE_ARG3) 0,
386 (PTRACE_TYPE_ARG4) PTRACE_O_TRACESYSGOOD);
8009206a 387
96d7229d 388 if (ret == 0)
de0d863e 389 supported_ptrace_options |= PTRACE_O_TRACESYSGOOD;
8ae377e8 390}
96d7229d 391
8ae377e8
PA
392/* Determine if PTRACE_O_TRACEFORK can be used to follow fork
393 events. */
394
395static void
396linux_test_for_tracefork (int child_pid)
397{
398 int ret, status;
399 long second_pid;
400
401 /* First, set the PTRACE_O_TRACEFORK option. If this fails, we
402 know for sure that it is not supported. */
403 ret = ptrace (PTRACE_SETOPTIONS, child_pid, (PTRACE_TYPE_ARG3) 0,
404 (PTRACE_TYPE_ARG4) PTRACE_O_TRACEFORK);
405
406 if (ret != 0)
407 return;
408
de0d863e
DB
409 /* Check if the target supports PTRACE_O_TRACEVFORKDONE. */
410 ret = ptrace (PTRACE_SETOPTIONS, child_pid, (PTRACE_TYPE_ARG3) 0,
411 (PTRACE_TYPE_ARG4) (PTRACE_O_TRACEFORK
412 | PTRACE_O_TRACEVFORKDONE));
413 if (ret == 0)
414 supported_ptrace_options |= PTRACE_O_TRACEVFORKDONE;
96d7229d
LM
415
416 /* Setting PTRACE_O_TRACEFORK did not cause an error, however we
417 don't know for sure that the feature is available; old
418 versions of PTRACE_SETOPTIONS ignored unknown options.
419 Therefore, we attach to the child process, use PTRACE_SETOPTIONS
420 to enable fork tracing, and let it fork. If the process exits,
421 we assume that we can't use PTRACE_O_TRACEFORK; if we get the
422 fork notification, and we can extract the new child's PID, then
423 we assume that we can.
424
425 We do not explicitly check for vfork tracing here. It is
426 assumed that vfork tracing is available whenever fork tracing
427 is available. */
428 ret = ptrace (PTRACE_CONT, child_pid, (PTRACE_TYPE_ARG3) 0,
429 (PTRACE_TYPE_ARG4) 0);
430 if (ret != 0)
8ae377e8 431 warning (_("linux_test_for_tracefork: failed to resume child"));
96d7229d
LM
432
433 ret = my_waitpid (child_pid, &status, 0);
434
435 /* Check if we received a fork event notification. */
436 if (ret == child_pid && WIFSTOPPED (status)
89a5711c 437 && linux_ptrace_get_extended_event (status) == PTRACE_EVENT_FORK)
96d7229d
LM
438 {
439 /* We did receive a fork event notification. Make sure its PID
440 is reported. */
441 second_pid = 0;
442 ret = ptrace (PTRACE_GETEVENTMSG, child_pid, (PTRACE_TYPE_ARG3) 0,
443 (PTRACE_TYPE_ARG4) &second_pid);
444 if (ret == 0 && second_pid != 0)
445 {
446 int second_status;
447
448 /* We got the PID from the grandchild, which means fork
449 tracing is supported. */
de0d863e
DB
450 supported_ptrace_options |= PTRACE_O_TRACECLONE;
451 supported_ptrace_options |= (PTRACE_O_TRACEFORK
452 | PTRACE_O_TRACEVFORK
453 | PTRACE_O_TRACEEXEC);
96d7229d
LM
454
455 /* Do some cleanup and kill the grandchild. */
456 my_waitpid (second_pid, &second_status, 0);
457 ret = ptrace (PTRACE_KILL, second_pid, (PTRACE_TYPE_ARG3) 0,
458 (PTRACE_TYPE_ARG4) 0);
459 if (ret != 0)
8ae377e8 460 warning (_("linux_test_for_tracefork: "
96d7229d
LM
461 "failed to kill second child"));
462 my_waitpid (second_pid, &status, 0);
463 }
464 }
465 else
8ae377e8 466 warning (_("linux_test_for_tracefork: unexpected result from waitpid "
96d7229d 467 "(%d, status 0x%x)"), ret, status);
96d7229d
LM
468}
469
beed38b8
JB
470/* Determine if PTRACE_O_EXITKILL can be used. */
471
472static void
473linux_test_for_exitkill (int child_pid)
474{
475 int ret;
476
477 ret = ptrace (PTRACE_SETOPTIONS, child_pid, (PTRACE_TYPE_ARG3) 0,
478 (PTRACE_TYPE_ARG4) PTRACE_O_EXITKILL);
479
480 if (ret == 0)
de0d863e 481 supported_ptrace_options |= PTRACE_O_EXITKILL;
beed38b8
JB
482}
483
484/* Enable reporting of all currently supported ptrace events.
de0d863e
DB
485 OPTIONS is a bit mask of extended features we want enabled,
486 if supported by the kernel. PTRACE_O_TRACECLONE is always
487 enabled, if supported. */
96d7229d
LM
488
489void
de0d863e 490linux_enable_event_reporting (pid_t pid, int options)
96d7229d
LM
491{
492 /* Check if we have initialized the ptrace features for this
493 target. If not, do it now. */
de0d863e 494 if (supported_ptrace_options == -1)
96d7229d
LM
495 linux_check_ptrace_features ();
496
de0d863e
DB
497 /* We always want clone events. */
498 options |= PTRACE_O_TRACECLONE;
499
500 /* Filter out unsupported options. */
501 options &= supported_ptrace_options;
beed38b8 502
96d7229d
LM
503 /* Set the options. */
504 ptrace (PTRACE_SETOPTIONS, pid, (PTRACE_TYPE_ARG3) 0,
de0d863e 505 (PTRACE_TYPE_ARG4) (uintptr_t) options);
96d7229d
LM
506}
507
c077881a
HZ
508/* Disable reporting of all currently supported ptrace events. */
509
510void
511linux_disable_event_reporting (pid_t pid)
512{
513 /* Set the options. */
514 ptrace (PTRACE_SETOPTIONS, pid, (PTRACE_TYPE_ARG3) 0, 0);
515}
516
96d7229d 517/* Returns non-zero if PTRACE_OPTIONS is contained within
de0d863e 518 SUPPORTED_PTRACE_OPTIONS, therefore supported. Returns 0
96d7229d
LM
519 otherwise. */
520
521static int
522ptrace_supports_feature (int ptrace_options)
523{
de0d863e 524 if (supported_ptrace_options == -1)
8784d563 525 linux_check_ptrace_features ();
96d7229d 526
de0d863e 527 return ((supported_ptrace_options & ptrace_options) == ptrace_options);
96d7229d
LM
528}
529
530/* Returns non-zero if PTRACE_EVENT_FORK is supported by ptrace,
531 0 otherwise. Note that if PTRACE_EVENT_FORK is supported so is
532 PTRACE_EVENT_CLONE, PTRACE_EVENT_EXEC and PTRACE_EVENT_VFORK,
533 since they were all added to the kernel at the same time. */
534
535int
536linux_supports_tracefork (void)
537{
538 return ptrace_supports_feature (PTRACE_O_TRACEFORK);
539}
540
94585166
DB
541/* Returns non-zero if PTRACE_EVENT_EXEC is supported by ptrace,
542 0 otherwise. Note that if PTRACE_EVENT_FORK is supported so is
543 PTRACE_EVENT_CLONE, PTRACE_EVENT_FORK and PTRACE_EVENT_VFORK,
544 since they were all added to the kernel at the same time. */
545
546int
547linux_supports_traceexec (void)
548{
549 return ptrace_supports_feature (PTRACE_O_TRACEEXEC);
550}
551
96d7229d
LM
552/* Returns non-zero if PTRACE_EVENT_CLONE is supported by ptrace,
553 0 otherwise. Note that if PTRACE_EVENT_CLONE is supported so is
554 PTRACE_EVENT_FORK, PTRACE_EVENT_EXEC and PTRACE_EVENT_VFORK,
555 since they were all added to the kernel at the same time. */
556
557int
558linux_supports_traceclone (void)
559{
560 return ptrace_supports_feature (PTRACE_O_TRACECLONE);
561}
562
563/* Returns non-zero if PTRACE_O_TRACEVFORKDONE is supported by
564 ptrace, 0 otherwise. */
565
566int
567linux_supports_tracevforkdone (void)
568{
569 return ptrace_supports_feature (PTRACE_O_TRACEVFORKDONE);
570}
571
572/* Returns non-zero if PTRACE_O_TRACESYSGOOD is supported by ptrace,
573 0 otherwise. */
574
575int
576linux_supports_tracesysgood (void)
577{
578 return ptrace_supports_feature (PTRACE_O_TRACESYSGOOD);
579}
580
aa7c7447
JK
581/* Display possible problems on this system. Display them only once per GDB
582 execution. */
583
584void
585linux_ptrace_init_warnings (void)
586{
587 static int warned = 0;
588
589 if (warned)
590 return;
591 warned = 1;
592
593 linux_ptrace_test_ret_to_nx ();
594}
8009206a 595
89a5711c
DB
596/* Extract extended ptrace event from wait status. */
597
598int
599linux_ptrace_get_extended_event (int wstat)
600{
601 return (wstat >> 16);
602}
603
604/* Determine whether wait status denotes an extended event. */
605
606int
607linux_is_extended_waitstatus (int wstat)
608{
609 return (linux_ptrace_get_extended_event (wstat) != 0);
610}
c9587f88
AT
611
612/* Return true if the event in LP may be caused by breakpoint. */
613
614int
615linux_wstatus_maybe_breakpoint (int wstat)
616{
617 return (WIFSTOPPED (wstat)
618 && (WSTOPSIG (wstat) == SIGTRAP
619 /* SIGILL and SIGSEGV are also treated as traps in case a
620 breakpoint is inserted at the current PC. */
621 || WSTOPSIG (wstat) == SIGILL
622 || WSTOPSIG (wstat) == SIGSEGV));
623}