-/* Copyright (C) 2011-2015 Free Software Foundation, Inc.
+/* Copyright (C) 2011-2021 Free Software Foundation, Inc.
This file is part of GDB.
You should have received a copy of the GNU General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>. */
-#ifndef COMMON_LINUX_PTRACE_H
-#define COMMON_LINUX_PTRACE_H
+#ifndef NAT_LINUX_PTRACE_H
+#define NAT_LINUX_PTRACE_H
struct buffer;
-#include <sys/ptrace.h>
+#include "nat/gdb_ptrace.h"
+#include "gdbsupport/gdb_wait.h"
#ifdef __UCLIBC__
#if !(defined(__UCLIBC_HAS_MMU__) || defined(__ARCH_HAS_MMU__))
# define PTRACE_SETSIGINFO 0x4203
#endif /* PTRACE_GETSIGINF */
+#ifndef PTRACE_GETREGSET
+#define PTRACE_GETREGSET 0x4204
+#endif
+
+#ifndef PTRACE_SETREGSET
+#define PTRACE_SETREGSET 0x4205
+#endif
+
/* If the system headers did not provide the constants, hard-code the normal
values. */
#ifndef PTRACE_EVENT_FORK
/* The x86 kernel gets some of the si_code values backwards, like
this:
- | what | si_code |
- |------------------------------------------+------------|
- | software breakpoints (int3) | SI_KERNEL |
- | single-steps | TRAP_TRACE |
- | single-stepping a syscall | TRAP_BRKPT |
- | user sent SIGTRAP | 0 |
- | exec SIGTRAP (when no PTRACE_EVENT_EXEC) | 0 |
- | hardware breakpoints/watchpoints | TRAP_HWBPT |
+ | what | si_code |
+ |------------------------------------------+-------------|
+ | software breakpoints (int3) | SI_KERNEL |
+ | single-steps | TRAP_TRACE |
+ | single-stepping a syscall | TRAP_BRKPT |
+ | user sent SIGTRAP | 0 |
+ | exec SIGTRAP (when no PTRACE_EVENT_EXEC) | 0 |
+ | hardware breakpoints/watchpoints | TRAP_HWBKPT |
That is, it reports SI_KERNEL for software breakpoints (and only
for those), and TRAP_BRKPT for single-stepping a syscall... If the
running to a breakpoint and checking what comes out of
siginfo->si_code.
- The generic Linux target code should use GDB_ARCH_TRAP_BRKPT
- instead of TRAP_BRKPT to abstract out this x86 peculiarity. */
+ The ppc kernel does use TRAP_BRKPT for software breakpoints
+ in PowerPC code, but it uses SI_KERNEL for software breakpoints
+ in SPU code on a Cell/B.E. However, SI_KERNEL is never seen
+ on a SIGTRAP for any other reason.
+
+ The MIPS kernel up until 4.5 used SI_KERNEL for all kernel
+ generated traps. Since:
+
+ - MIPS doesn't do hardware single-step.
+ - We don't need to care about exec SIGTRAPs --- we assume
+ PTRACE_EVENT_EXEC is available.
+ - The MIPS kernel doesn't support hardware breakpoints.
+
+ on MIPS, all we need to care about is distinguishing between
+ software breakpoints and hardware watchpoints, which can be done by
+ peeking the debug registers.
+
+ Beginning with Linux 4.6, the MIPS port reports proper TRAP_BRKPT and
+ TRAP_HWBKPT codes, so we also match them.
+
+ The generic Linux target code should use GDB_ARCH_IS_TRAP_* instead
+ of TRAP_* to abstract out these peculiarities. */
#if defined __i386__ || defined __x86_64__
-# define GDB_ARCH_TRAP_BRKPT SI_KERNEL
+# define GDB_ARCH_IS_TRAP_BRKPT(X) ((X) == SI_KERNEL)
+# define GDB_ARCH_IS_TRAP_HWBKPT(X) ((X) == TRAP_HWBKPT)
+#elif defined __powerpc__
+# define GDB_ARCH_IS_TRAP_BRKPT(X) ((X) == SI_KERNEL || (X) == TRAP_BRKPT)
+# define GDB_ARCH_IS_TRAP_HWBKPT(X) ((X) == TRAP_HWBKPT)
+#elif defined __mips__
+# define GDB_ARCH_IS_TRAP_BRKPT(X) ((X) == SI_KERNEL || (X) == TRAP_BRKPT)
+# define GDB_ARCH_IS_TRAP_HWBKPT(X) ((X) == SI_KERNEL || (X) == TRAP_HWBKPT)
#else
-# define GDB_ARCH_TRAP_BRKPT TRAP_BRKPT
+# define GDB_ARCH_IS_TRAP_BRKPT(X) ((X) == TRAP_BRKPT)
+# define GDB_ARCH_IS_TRAP_HWBKPT(X) ((X) == TRAP_HWBKPT)
#endif
#ifndef TRAP_HWBKPT
# define TRAP_HWBKPT 4
#endif
-extern void linux_ptrace_attach_fail_reason (pid_t pid, struct buffer *buffer);
+extern std::string linux_ptrace_attach_fail_reason (pid_t pid);
/* Find all possible reasons we could have failed to attach to PTID
and return them as a string. ERR is the error PTRACE_ATTACH failed
- with (an errno). The result is stored in a static buffer. This
- string should be copied into a buffer by the client if the string
- will not be immediately used, or if it must persist. */
-extern char *linux_ptrace_attach_fail_reason_string (ptid_t ptid, int err);
+ with (an errno). */
+extern std::string linux_ptrace_attach_fail_reason_string (ptid_t ptid, int err);
extern void linux_ptrace_init_warnings (void);
+extern void linux_check_ptrace_features (void);
extern void linux_enable_event_reporting (pid_t pid, int attached);
extern void linux_disable_event_reporting (pid_t pid);
extern int linux_supports_tracefork (void);
+extern int linux_supports_traceexec (void);
extern int linux_supports_traceclone (void);
extern int linux_supports_tracevforkdone (void);
extern int linux_supports_tracesysgood (void);
-extern void linux_ptrace_set_additional_flags (int);
extern int linux_ptrace_get_extended_event (int wstat);
extern int linux_is_extended_waitstatus (int wstat);
extern int linux_wstatus_maybe_breakpoint (int wstat);
-#endif /* COMMON_LINUX_PTRACE_H */
+#endif /* NAT_LINUX_PTRACE_H */