gdb: add target_ops::supports_displaced_step
[deliverable/binutils-gdb.git] / gdb / x86-bsd-nat.c
CommitLineData
a3405d12
JB
1/* Native-dependent code for X86 BSD's.
2
b811d2c2 3 Copyright (C) 2003-2020 Free Software Foundation, Inc.
a3405d12
JB
4
5 This file is part of GDB.
6
7 This program is free software; you can redistribute it and/or modify
8 it under the terms of the GNU General Public License as published by
9 the Free Software Foundation; either version 3 of the License, or
10 (at your option) any later version.
11
12 This program is distributed in the hope that it will be useful,
13 but WITHOUT ANY WARRANTY; without even the implied warranty of
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 GNU General Public License for more details.
16
17 You should have received a copy of the GNU General Public License
18 along with this program. If not, see <http://www.gnu.org/licenses/>. */
19
20#include "defs.h"
21#include "inferior.h"
5077bfff 22#include "gdbthread.h"
a3405d12
JB
23
24/* We include <signal.h> to make sure `struct fxsave64' is defined on
25 NetBSD, since NetBSD's <machine/reg.h> needs it. */
26#include <signal.h>
27#include <sys/types.h>
28#include <sys/ptrace.h>
29#include <machine/reg.h>
30
31#include "x86-nat.h"
03b62bbb 32#include "x86-bsd-nat.h"
a3405d12
JB
33#include "inf-ptrace.h"
34\f
35
1ff700c2 36static PTRACE_TYPE_RET
fcc7376e
KR
37gdb_ptrace (PTRACE_TYPE_ARG1 request, ptid_t ptid, PTRACE_TYPE_ARG3 addr)
38{
39#ifdef __NetBSD__
40 /* Support for NetBSD threads: unlike other ptrace implementations in this
41 file, NetBSD requires that we pass both the pid and lwp. */
42 return ptrace (request, ptid.pid (), addr, ptid.lwp ());
43#else
44 pid_t pid = get_ptrace_pid (ptid);
45 return ptrace (request, pid, addr, 0);
46#endif
47}
48
a3405d12
JB
49#ifdef PT_GETXSTATE_INFO
50size_t x86bsd_xsave_len;
51#endif
52
53/* Support for debug registers. */
54
55#ifdef HAVE_PT_GETDBREGS
a3405d12 56
a379bfd0
JB
57/* Helper macro to access debug register X. FreeBSD/amd64 and modern
58 versions of FreeBSD/i386 provide this macro in system headers. Define
59 a local version for systems that do not provide it. */
a3405d12 60#ifndef DBREG_DRX
a379bfd0
JB
61#ifdef __NetBSD__
62#define DBREG_DRX(d, x) ((d)->dr[x])
63#else
a3405d12
JB
64#define DBREG_DRX(d, x) ((&d->dr0)[x])
65#endif
a379bfd0 66#endif
a3405d12
JB
67
68static unsigned long
69x86bsd_dr_get (ptid_t ptid, int regnum)
70{
71 struct dbreg dbregs;
72
fcc7376e 73 if (gdb_ptrace (PT_GETDBREGS, ptid, (PTRACE_TYPE_ARG3) &dbregs) == -1)
a3405d12
JB
74 perror_with_name (_("Couldn't read debug registers"));
75
76 return DBREG_DRX ((&dbregs), regnum);
77}
78
79static void
fcc7376e 80x86bsd_dr_set (ptid_t ptid, int regnum, unsigned long value)
a3405d12
JB
81{
82 struct dbreg dbregs;
83
fcc7376e 84 if (gdb_ptrace (PT_GETDBREGS, ptid, (PTRACE_TYPE_ARG3) &dbregs) == -1)
a3405d12
JB
85 perror_with_name (_("Couldn't get debug registers"));
86
87 /* For some mysterious reason, some of the reserved bits in the
88 debug control register get set. Mask these off, otherwise the
89 ptrace call below will fail. */
90 DBREG_DRX ((&dbregs), 7) &= ~(0xffffffff0000fc00);
91
92 DBREG_DRX ((&dbregs), regnum) = value;
93
08036331
PA
94 for (thread_info *thread : current_inferior ()->non_exited_threads ())
95 {
fcc7376e
KR
96 if (gdb_ptrace (PT_SETDBREGS, thread->ptid,
97 (PTRACE_TYPE_ARG3) &dbregs) == -1)
08036331
PA
98 perror_with_name (_("Couldn't write debug registers"));
99 }
a3405d12
JB
100}
101
102static void
103x86bsd_dr_set_control (unsigned long control)
104{
fcc7376e 105 x86bsd_dr_set (inferior_ptid, 7, control);
a3405d12
JB
106}
107
108static void
109x86bsd_dr_set_addr (int regnum, CORE_ADDR addr)
110{
111 gdb_assert (regnum >= 0 && regnum <= 4);
112
fcc7376e 113 x86bsd_dr_set (inferior_ptid, regnum, addr);
a3405d12
JB
114}
115
116static CORE_ADDR
117x86bsd_dr_get_addr (int regnum)
118{
119 return x86bsd_dr_get (inferior_ptid, regnum);
120}
121
122static unsigned long
123x86bsd_dr_get_status (void)
124{
125 return x86bsd_dr_get (inferior_ptid, 6);
126}
127
128static unsigned long
129x86bsd_dr_get_control (void)
130{
131 return x86bsd_dr_get (inferior_ptid, 7);
132}
133
134#endif /* PT_GETDBREGS */
135
6c265988 136void _initialize_x86_bsd_nat ();
f6ac5f3d
PA
137void
138_initialize_x86_bsd_nat ()
a3405d12 139{
a3405d12 140#ifdef HAVE_PT_GETDBREGS
a3405d12
JB
141 x86_dr_low.set_control = x86bsd_dr_set_control;
142 x86_dr_low.set_addr = x86bsd_dr_set_addr;
143 x86_dr_low.get_addr = x86bsd_dr_get_addr;
144 x86_dr_low.get_status = x86bsd_dr_get_status;
145 x86_dr_low.get_control = x86bsd_dr_get_control;
146 x86_set_debug_register_length (sizeof (void *));
a3405d12 147#endif /* HAVE_PT_GETDBREGS */
a3405d12 148}
This page took 0.517149 seconds and 4 git commands to generate.