Make a bunch of functions static
[deliverable/binutils-gdb.git] / gdb / x86-bsd-nat.c
CommitLineData
a3405d12
JB
1/* Native-dependent code for X86 BSD's.
2
42a4f53d 3 Copyright (C) 2003-2019 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
36#ifdef PT_GETXSTATE_INFO
37size_t x86bsd_xsave_len;
38#endif
39
40/* Support for debug registers. */
41
42#ifdef HAVE_PT_GETDBREGS
a3405d12 43
a379bfd0
JB
44/* Helper macro to access debug register X. FreeBSD/amd64 and modern
45 versions of FreeBSD/i386 provide this macro in system headers. Define
46 a local version for systems that do not provide it. */
a3405d12 47#ifndef DBREG_DRX
a379bfd0
JB
48#ifdef __NetBSD__
49#define DBREG_DRX(d, x) ((d)->dr[x])
50#else
a3405d12
JB
51#define DBREG_DRX(d, x) ((&d->dr0)[x])
52#endif
a379bfd0 53#endif
a3405d12
JB
54
55static unsigned long
56x86bsd_dr_get (ptid_t ptid, int regnum)
57{
58 struct dbreg dbregs;
59
60 if (ptrace (PT_GETDBREGS, get_ptrace_pid (inferior_ptid),
61 (PTRACE_TYPE_ARG3) &dbregs, 0) == -1)
62 perror_with_name (_("Couldn't read debug registers"));
63
64 return DBREG_DRX ((&dbregs), regnum);
65}
66
67static void
68x86bsd_dr_set (int regnum, unsigned long value)
69{
70 struct dbreg dbregs;
71
72 if (ptrace (PT_GETDBREGS, get_ptrace_pid (inferior_ptid),
73 (PTRACE_TYPE_ARG3) &dbregs, 0) == -1)
74 perror_with_name (_("Couldn't get debug registers"));
75
76 /* For some mysterious reason, some of the reserved bits in the
77 debug control register get set. Mask these off, otherwise the
78 ptrace call below will fail. */
79 DBREG_DRX ((&dbregs), 7) &= ~(0xffffffff0000fc00);
80
81 DBREG_DRX ((&dbregs), regnum) = value;
82
08036331
PA
83 for (thread_info *thread : current_inferior ()->non_exited_threads ())
84 {
85 if (ptrace (PT_SETDBREGS, get_ptrace_pid (thread->ptid),
86 (PTRACE_TYPE_ARG3) &dbregs, 0) == -1)
87 perror_with_name (_("Couldn't write debug registers"));
88 }
a3405d12
JB
89}
90
91static void
92x86bsd_dr_set_control (unsigned long control)
93{
94 x86bsd_dr_set (7, control);
95}
96
97static void
98x86bsd_dr_set_addr (int regnum, CORE_ADDR addr)
99{
100 gdb_assert (regnum >= 0 && regnum <= 4);
101
102 x86bsd_dr_set (regnum, addr);
103}
104
105static CORE_ADDR
106x86bsd_dr_get_addr (int regnum)
107{
108 return x86bsd_dr_get (inferior_ptid, regnum);
109}
110
111static unsigned long
112x86bsd_dr_get_status (void)
113{
114 return x86bsd_dr_get (inferior_ptid, 6);
115}
116
117static unsigned long
118x86bsd_dr_get_control (void)
119{
120 return x86bsd_dr_get (inferior_ptid, 7);
121}
122
123#endif /* PT_GETDBREGS */
124
f6ac5f3d
PA
125void
126_initialize_x86_bsd_nat ()
a3405d12 127{
a3405d12 128#ifdef HAVE_PT_GETDBREGS
a3405d12
JB
129 x86_dr_low.set_control = x86bsd_dr_set_control;
130 x86_dr_low.set_addr = x86bsd_dr_set_addr;
131 x86_dr_low.get_addr = x86bsd_dr_get_addr;
132 x86_dr_low.get_status = x86bsd_dr_get_status;
133 x86_dr_low.get_control = x86bsd_dr_get_control;
134 x86_set_debug_register_length (sizeof (void *));
a3405d12 135#endif /* HAVE_PT_GETDBREGS */
a3405d12 136}
This page took 0.894204 seconds and 4 git commands to generate.