Added
Link Here
|
1 |
/* FreeBSD/x86 specific debug register support based on i386bsd-nat.c: */ |
2 |
/* Native-dependent code for modern i386 BSD's. |
3 |
|
4 |
Copyright (C) 2000-2016 Free Software Foundation, Inc. |
5 |
|
6 |
This file is part of GDB. |
7 |
|
8 |
This program is free software; you can redistribute it and/or modify |
9 |
it under the terms of the GNU General Public License as published by |
10 |
the Free Software Foundation; either version 3 of the License, or |
11 |
(at your option) any later version. |
12 |
|
13 |
This program is distributed in the hope that it will be useful, |
14 |
but WITHOUT ANY WARRANTY; without even the implied warranty of |
15 |
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
16 |
GNU General Public License for more details. |
17 |
|
18 |
You should have received a copy of the GNU General Public License |
19 |
along with this program. If not, see <http://www.gnu.org/licenses/>. */ |
20 |
|
21 |
#include "defs.h" |
22 |
#include "gdbthread.h" |
23 |
#include "inferior.h" |
24 |
#include "regcache.h" |
25 |
|
26 |
#include <signal.h> |
27 |
#include <sys/types.h> |
28 |
#include <sys/ptrace.h> |
29 |
#include <machine/reg.h> |
30 |
#include "x86fbsd-nat.h" |
31 |
#include "inf-ptrace.h" |
32 |
|
33 |
#ifdef HAVE_PT_GETDBREGS |
34 |
|
35 |
#ifndef DBREG_DRX |
36 |
#define DBREG_DRX(d, x) ((&d->dr0)[x]) |
37 |
#endif |
38 |
|
39 |
static unsigned long |
40 |
x86fbsd_dr_get (ptid_t ptid, int regnum) |
41 |
{ |
42 |
struct dbreg dbregs; |
43 |
|
44 |
if (ptrace (PT_GETDBREGS, get_ptrace_pid (ptid), |
45 |
(PTRACE_TYPE_ARG3) &dbregs, 0) == -1) |
46 |
perror_with_name (_("Couldn't read debug registers")); |
47 |
|
48 |
return DBREG_DRX ((&dbregs), regnum); |
49 |
} |
50 |
|
51 |
static void |
52 |
x86fbsd_dr_set (ptid_t ptid, int regnum, unsigned long value) |
53 |
{ |
54 |
struct dbreg dbregs; |
55 |
|
56 |
if (ptrace (PT_GETDBREGS, get_ptrace_pid (ptid), |
57 |
(PTRACE_TYPE_ARG3) &dbregs, 0) == -1) |
58 |
perror_with_name (_("Couldn't get debug registers")); |
59 |
|
60 |
/* For some mysterious reason, some of the reserved bits in the |
61 |
debug control register get set. Mask these off, otherwise the |
62 |
ptrace call below will fail. */ |
63 |
#if defined(__i386__) |
64 |
DBREG_DRX ((&dbregs), 7) &= ~(0x0000fc00); |
65 |
#elif defined(__amd64__) |
66 |
DBREG_DRX ((&dbregs), 7) &= ~(0xffffffff0000fc00); |
67 |
#endif |
68 |
|
69 |
DBREG_DRX ((&dbregs), regnum) = value; |
70 |
|
71 |
if (ptrace (PT_SETDBREGS, get_ptrace_pid (ptid), |
72 |
(PTRACE_TYPE_ARG3) &dbregs, 0) == -1) |
73 |
perror_with_name (_("Couldn't write debug registers")); |
74 |
} |
75 |
|
76 |
struct x86fbsd_dr_set_arg { |
77 |
int regnum; |
78 |
unsigned long value; |
79 |
}; |
80 |
|
81 |
static int |
82 |
x86fbsd_dr_set_cb(struct thread_info *thread, void *arg) |
83 |
{ |
84 |
struct x86fbsd_dr_set_arg *dsp = arg; |
85 |
x86fbsd_dr_set (thread->ptid, dsp->regnum, dsp->value); |
86 |
return 0; |
87 |
} |
88 |
|
89 |
void |
90 |
x86fbsd_dr_set_control (unsigned long control) |
91 |
{ |
92 |
struct x86fbsd_dr_set_arg ds; |
93 |
|
94 |
ds.regnum = 7; |
95 |
ds.value = control; |
96 |
iterate_over_threads (x86fbsd_dr_set_cb, &ds); |
97 |
} |
98 |
|
99 |
void |
100 |
x86fbsd_dr_set_addr (int regnum, CORE_ADDR addr) |
101 |
{ |
102 |
struct x86fbsd_dr_set_arg ds; |
103 |
|
104 |
gdb_assert (regnum >= 0 && regnum <= 4); |
105 |
ds.regnum = regnum; |
106 |
ds.value = addr; |
107 |
iterate_over_threads (x86fbsd_dr_set_cb, &ds); |
108 |
} |
109 |
|
110 |
CORE_ADDR |
111 |
x86fbsd_dr_get_addr (int regnum) |
112 |
{ |
113 |
return x86fbsd_dr_get (inferior_ptid, regnum); |
114 |
} |
115 |
|
116 |
unsigned long |
117 |
x86fbsd_dr_get_status (void) |
118 |
{ |
119 |
return x86fbsd_dr_get (inferior_ptid, 6); |
120 |
} |
121 |
|
122 |
unsigned long |
123 |
x86fbsd_dr_get_control (void) |
124 |
{ |
125 |
return x86fbsd_dr_get (inferior_ptid, 7); |
126 |
} |
127 |
|
128 |
#endif /* HAVE_PT_GETDBREGS */ |