1 /* Native-dependent code for AMD64 BSD's.
3 Copyright (C) 2003, 2004, 2007 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 2 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, write to the Free Software
19 Foundation, Inc., 51 Franklin Street, Fifth Floor,
20 Boston, MA 02110-1301, USA. */
27 /* We include <signal.h> to make sure `struct fxsave64' is defined on
28 NetBSD, since NetBSD's <machine/reg.h> needs it. */
29 #include "gdb_assert.h"
31 #include <sys/types.h>
32 #include <sys/ptrace.h>
33 #include <machine/reg.h>
35 #include "amd64-tdep.h"
36 #include "amd64-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 (int regnum
)
46 if (regnum
== -1 || amd64_native_gregset_supplies_p (regnum
))
50 if (ptrace (PT_GETREGS
, PIDGET (inferior_ptid
),
51 (PTRACE_TYPE_ARG3
) ®s
, 0) == -1)
52 perror_with_name (_("Couldn't get registers"));
54 amd64_supply_native_gregset (current_regcache
, ®s
, -1);
59 if (regnum
== -1 || !amd64_native_gregset_supplies_p (regnum
))
63 if (ptrace (PT_GETFPREGS
, PIDGET (inferior_ptid
),
64 (PTRACE_TYPE_ARG3
) &fpregs
, 0) == -1)
65 perror_with_name (_("Couldn't get floating point status"));
67 amd64_supply_fxsave (current_regcache
, -1, &fpregs
);
71 /* Store register REGNUM back into the inferior. If REGNUM is -1, do
72 this for all registers (including the floating-point registers). */
75 amd64bsd_store_inferior_registers (int regnum
)
77 if (regnum
== -1 || amd64_native_gregset_supplies_p (regnum
))
81 if (ptrace (PT_GETREGS
, PIDGET (inferior_ptid
),
82 (PTRACE_TYPE_ARG3
) ®s
, 0) == -1)
83 perror_with_name (_("Couldn't get registers"));
85 amd64_collect_native_gregset (current_regcache
, ®s
, regnum
);
87 if (ptrace (PT_SETREGS
, PIDGET (inferior_ptid
),
88 (PTRACE_TYPE_ARG3
) ®s
, 0) == -1)
89 perror_with_name (_("Couldn't write registers"));
95 if (regnum
== -1 || !amd64_native_gregset_supplies_p (regnum
))
99 if (ptrace (PT_GETFPREGS
, PIDGET (inferior_ptid
),
100 (PTRACE_TYPE_ARG3
) &fpregs
, 0) == -1)
101 perror_with_name (_("Couldn't get floating point status"));
103 amd64_collect_fxsave (current_regcache
, regnum
, &fpregs
);
105 if (ptrace (PT_SETFPREGS
, PIDGET (inferior_ptid
),
106 (PTRACE_TYPE_ARG3
) &fpregs
, 0) == -1)
107 perror_with_name (_("Couldn't write floating point status"));
111 /* Create a prototype *BSD/amd64 target. The client can override it
112 with local methods. */
115 amd64bsd_target (void)
117 struct target_ops
*t
;
119 t
= inf_ptrace_target ();
120 t
->to_fetch_registers
= amd64bsd_fetch_inferior_registers
;
121 t
->to_store_registers
= amd64bsd_store_inferior_registers
;