1 /* Native-dependent code for AMD64 BSD's.
3 Copyright (C) 2003-2019 Free Software Foundation, Inc.
5 This file is part of GDB.
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.
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.
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/>. */
22 /* Local non-gdb includes. */
27 /* We include <signal.h> to make sure `struct fxsave64' is defined on
28 NetBSD, since NetBSD's <machine/reg.h> needs it. */
30 #include <sys/types.h>
31 #include <sys/ptrace.h>
32 #include <machine/reg.h>
34 #include "amd64-tdep.h"
35 #include "amd64-nat.h"
36 #include "x86-bsd-nat.h"
37 #include "inf-ptrace.h"
40 /* Fetch register REGNUM from the inferior. If REGNUM is -1, do this
41 for all registers (including the floating-point registers). */
44 amd64bsd_fetch_inferior_registers (struct regcache
*regcache
, int regnum
)
46 struct gdbarch
*gdbarch
= regcache
->arch ();
47 pid_t pid
= get_ptrace_pid (regcache
->ptid ());
48 #if defined(PT_GETFSBASE) || defined(PT_GETGSBASE)
49 const struct gdbarch_tdep
*tdep
= gdbarch_tdep (gdbarch
);
52 if (regnum
== -1 || amd64_native_gregset_supplies_p (gdbarch
, regnum
))
56 if (ptrace (PT_GETREGS
, pid
, (PTRACE_TYPE_ARG3
) ®s
, 0) == -1)
57 perror_with_name (_("Couldn't get registers"));
59 amd64_supply_native_gregset (regcache
, ®s
, -1);
65 if (regnum
== -1 || regnum
== tdep
->fsbase_regnum
)
69 if (ptrace (PT_GETFSBASE
, pid
, (PTRACE_TYPE_ARG3
) &base
, 0) == -1)
70 perror_with_name (_("Couldn't get segment register fs_base"));
72 regcache
->raw_supply (tdep
->fsbase_regnum
, &base
);
78 if (regnum
== -1 || regnum
== tdep
->fsbase_regnum
+ 1)
82 if (ptrace (PT_GETGSBASE
, pid
, (PTRACE_TYPE_ARG3
) &base
, 0) == -1)
83 perror_with_name (_("Couldn't get segment register gs_base"));
85 regcache
->raw_supply (tdep
->fsbase_regnum
+ 1, &base
);
91 if (regnum
== -1 || !amd64_native_gregset_supplies_p (gdbarch
, regnum
))
94 #ifdef PT_GETXSTATE_INFO
97 if (x86bsd_xsave_len
!= 0)
99 xstateregs
= alloca (x86bsd_xsave_len
);
100 if (ptrace (PT_GETXSTATE
, pid
, (PTRACE_TYPE_ARG3
) xstateregs
, 0)
102 perror_with_name (_("Couldn't get extended state status"));
104 amd64_supply_xsave (regcache
, -1, xstateregs
);
109 if (ptrace (PT_GETFPREGS
, pid
, (PTRACE_TYPE_ARG3
) &fpregs
, 0) == -1)
110 perror_with_name (_("Couldn't get floating point status"));
112 amd64_supply_fxsave (regcache
, -1, &fpregs
);
116 /* Store register REGNUM back into the inferior. If REGNUM is -1, do
117 this for all registers (including the floating-point registers). */
120 amd64bsd_store_inferior_registers (struct regcache
*regcache
, int regnum
)
122 struct gdbarch
*gdbarch
= regcache
->arch ();
123 pid_t pid
= get_ptrace_pid (regcache
->ptid ());
124 #if defined(PT_SETFSBASE) || defined(PT_SETGSBASE)
125 const struct gdbarch_tdep
*tdep
= gdbarch_tdep (gdbarch
);
128 if (regnum
== -1 || amd64_native_gregset_supplies_p (gdbarch
, regnum
))
132 if (ptrace (PT_GETREGS
, pid
, (PTRACE_TYPE_ARG3
) ®s
, 0) == -1)
133 perror_with_name (_("Couldn't get registers"));
135 amd64_collect_native_gregset (regcache
, ®s
, regnum
);
137 if (ptrace (PT_SETREGS
, pid
, (PTRACE_TYPE_ARG3
) ®s
, 0) == -1)
138 perror_with_name (_("Couldn't write registers"));
145 if (regnum
== -1 || regnum
== tdep
->fsbase_regnum
)
149 /* Clear the full base value to support 32-bit targets. */
151 regcache
->raw_collect (tdep
->fsbase_regnum
, &base
);
153 if (ptrace (PT_SETFSBASE
, pid
, (PTRACE_TYPE_ARG3
) &base
, 0) == -1)
154 perror_with_name (_("Couldn't write segment register fs_base"));
160 if (regnum
== -1 || regnum
== tdep
->fsbase_regnum
+ 1)
164 /* Clear the full base value to support 32-bit targets. */
166 regcache
->raw_collect (tdep
->fsbase_regnum
+ 1, &base
);
168 if (ptrace (PT_SETGSBASE
, pid
, (PTRACE_TYPE_ARG3
) &base
, 0) == -1)
169 perror_with_name (_("Couldn't write segment register gs_base"));
175 if (regnum
== -1 || !amd64_native_gregset_supplies_p (gdbarch
, regnum
))
178 #ifdef PT_GETXSTATE_INFO
181 if (x86bsd_xsave_len
!= 0)
183 xstateregs
= alloca (x86bsd_xsave_len
);
184 if (ptrace (PT_GETXSTATE
, pid
, (PTRACE_TYPE_ARG3
) xstateregs
, 0)
186 perror_with_name (_("Couldn't get extended state status"));
188 amd64_collect_xsave (regcache
, regnum
, xstateregs
, 0);
190 if (ptrace (PT_SETXSTATE
, pid
, (PTRACE_TYPE_ARG3
) xstateregs
,
191 x86bsd_xsave_len
) == -1)
192 perror_with_name (_("Couldn't write extended state status"));
197 if (ptrace (PT_GETFPREGS
, pid
, (PTRACE_TYPE_ARG3
) &fpregs
, 0) == -1)
198 perror_with_name (_("Couldn't get floating point status"));
200 amd64_collect_fxsave (regcache
, regnum
, &fpregs
);
202 if (ptrace (PT_SETFPREGS
, pid
, (PTRACE_TYPE_ARG3
) &fpregs
, 0) == -1)
203 perror_with_name (_("Couldn't write floating point status"));
This page took 0.035344 seconds and 5 git commands to generate.