1 /* Native-dependent code for modern i386 BSD's.
2 Copyright 2000, 2001 Free Software Foundation, Inc.
4 This file is part of GDB.
6 This program is free software; you can redistribute it and/or modify
7 it under the terms of the GNU General Public License as published by
8 the Free Software Foundation; either version 2 of the License, or
9 (at your option) any later version.
11 This program is distributed in the hope that it will be useful,
12 but WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 GNU General Public License for more details.
16 You should have received a copy of the GNU General Public License
17 along with this program; if not, write to the Free Software
18 Foundation, Inc., 59 Temple Place - Suite 330,
19 Boston, MA 02111-1307, USA. */
25 #include "gdb_assert.h"
26 #include <sys/types.h>
27 #include <sys/ptrace.h>
28 #include <machine/reg.h>
29 #include <machine/frame.h>
31 #ifdef HAVE_SYS_PROCFS_H
32 #include <sys/procfs.h>
35 #ifndef HAVE_GREGSET_T
36 typedef struct reg gregset_t
;
39 #ifndef HAVE_FPREGSET_T
40 typedef struct fpreg fpregset_t
;
46 /* In older BSD versions we cannot get at some of the segment
47 registers. FreeBSD for example didn't support the %fs and %gs
48 registers until the 3.0 release. We have autoconf checks for their
49 presence, and deal gracefully with their absence. */
51 /* Registers we shouldn't try to fetch. */
52 #if !defined (CANNOT_FETCH_REGISTER)
53 #define CANNOT_FETCH_REGISTER(regno) cannot_fetch_register (regno)
56 /* Registers we shouldn't try to store. */
57 #if !defined (CANNOT_STORE_REGISTER)
58 #define CANNOT_STORE_REGISTER(regno) cannot_fetch_register (regno)
61 /* Offset to the gregset_t location where REG is stored. */
62 #define REG_OFFSET(reg) offsetof (gregset_t, reg)
64 /* At reg_offset[REGNO] you'll find the offset to the gregset_t
65 location where the GDB register REGNO is stored. Unsupported
66 registers are marked with `-1'. */
67 static int reg_offset
[] =
78 REG_OFFSET (r_eflags
),
83 #ifdef HAVE_STRUCT_REG_R_FS
88 #ifdef HAVE_STRUCT_REG_R_GS
95 #define REG_ADDR(regset, regno) ((char *) (regset) + reg_offset[regno])
97 /* Return nonzero if we shouldn't try to fetch register REGNO. */
100 cannot_fetch_register (int regno
)
102 return (reg_offset
[regno
] == -1);
106 /* Transfering the registers between GDB, inferiors and core files. */
108 /* Fill GDB's register array with the general-purpose register values
112 supply_gregset (gregset_t
*gregsetp
)
116 for (i
= 0; i
< NUM_GREGS
; i
++)
118 if (CANNOT_FETCH_REGISTER (i
))
119 supply_register (i
, NULL
);
121 supply_register (i
, REG_ADDR (gregsetp
, i
));
125 /* Fill register REGNO (if it is a general-purpose register) in
126 *GREGSETPS with the value in GDB's register array. If REGNO is -1,
127 do this for all registers. */
130 fill_gregset (gregset_t
*gregsetp
, int regno
)
134 for (i
= 0; i
< NUM_GREGS
; i
++)
135 if ((regno
== -1 || regno
== i
) && ! CANNOT_STORE_REGISTER (i
))
136 memcpy (REG_ADDR (gregsetp
, i
), ®isters
[REGISTER_BYTE (i
)],
137 REGISTER_RAW_SIZE (i
));
140 #include "i387-nat.h"
142 /* Fill GDB's register array with the floating-point register values
146 supply_fpregset (fpregset_t
*fpregsetp
)
148 i387_supply_fsave ((char *) fpregsetp
);
151 /* Fill register REGNO (if it is a floating-point register) in
152 *FPREGSETP with the value in GDB's register array. If REGNO is -1,
153 do this for all registers. */
156 fill_fpregset (fpregset_t
*fpregsetp
, int regno
)
158 i387_fill_fsave ((char *) fpregsetp
, regno
);
161 /* Fetch register REGNO from the inferior. If REGNO is -1, do this
162 for all registers (including the floating point registers). */
165 fetch_inferior_registers (int regno
)
169 if (ptrace (PT_GETREGS
, PIDGET (inferior_ptid
),
170 (PTRACE_ARG3_TYPE
) &gregs
, 0) == -1)
171 perror_with_name ("Couldn't get registers");
173 supply_gregset (&gregs
);
175 if (regno
== -1 || regno
>= FP0_REGNUM
)
179 if (ptrace (PT_GETFPREGS
, PIDGET (inferior_ptid
),
180 (PTRACE_ARG3_TYPE
) &fpregs
, 0) == -1)
181 perror_with_name ("Couldn't get floating point status");
183 supply_fpregset (&fpregs
);
187 /* Store register REGNO back into the inferior. If REGNO is -1, do
188 this for all registers (including the floating point registers). */
191 store_inferior_registers (int regno
)
195 if (ptrace (PT_GETREGS
, PIDGET (inferior_ptid
),
196 (PTRACE_ARG3_TYPE
) &gregs
, 0) == -1)
197 perror_with_name ("Couldn't get registers");
199 fill_gregset (&gregs
, regno
);
201 if (ptrace (PT_SETREGS
, PIDGET (inferior_ptid
), (PTRACE_ARG3_TYPE
) &gregs
, 0) == -1)
202 perror_with_name ("Couldn't write registers");
204 if (regno
== -1 || regno
>= FP0_REGNUM
)
208 if (ptrace (PT_GETFPREGS
, PIDGET (inferior_ptid
),
209 (PTRACE_ARG3_TYPE
) &fpregs
, 0) == -1)
210 perror_with_name ("Couldn't get floating point status");
212 fill_fpregset (&fpregs
, regno
);
214 if (ptrace (PT_SETFPREGS
, PIDGET (inferior_ptid
),
215 (PTRACE_ARG3_TYPE
) &fpregs
, 0) == -1)
216 perror_with_name ("Couldn't write floating point status");
221 /* Support for debug registers. */
223 #ifdef HAVE_PT_GETDBREGS
225 /* Not all versions of FreeBSD/i386 that support the debug registers
228 #define DBREG_DRX(d, x) ((&d->dr0)[x])
232 i386bsd_dr_set (int regnum
, unsigned int value
)
236 if (ptrace (PT_GETDBREGS
, PIDGET (inferior_ptid
),
237 (PTRACE_ARG3_TYPE
) &dbregs
, 0) == -1)
238 perror_with_name ("Couldn't get debug registers");
240 /* For some mysterious reason, some of the reserved bits in the
241 debug control register get set. Mask these off, otherwise the
242 ptrace call below will fail. */
243 dbregs
.dr7
&= ~(0x0000fc00);
245 DBREG_DRX ((&dbregs
), regnum
) = value
;
247 if (ptrace (PT_SETDBREGS
, PIDGET (inferior_ptid
),
248 (PTRACE_ARG3_TYPE
) &dbregs
, 0) == -1)
249 perror_with_name ("Couldn't write debug registers");
253 i386bsd_dr_set_control (unsigned long control
)
255 i386bsd_dr_set (7, control
);
259 i386bsd_dr_set_addr (int regnum
, CORE_ADDR addr
)
261 gdb_assert (regnum
>= 0 && regnum
<= 4);
263 i386bsd_dr_set (regnum
, addr
);
267 i386bsd_dr_reset_addr (int regnum
)
269 gdb_assert (regnum
>= 0 && regnum
<= 4);
271 i386bsd_dr_set (regnum
, 0);
275 i386bsd_dr_get_status (void)
279 /* FIXME: kettenis/2001-03-31: Calling perror_with_name if the
280 ptrace call fails breaks debugging remote targets. The correct
281 way to fix this is to add the hardware breakpoint and watchpoint
282 stuff to the target vectore. For now, just return zero if the
283 ptrace call fails. */
284 if (ptrace (PT_GETDBREGS
, PIDGET (inferior_ptid
),
285 (PTRACE_ARG3_TYPE
) & dbregs
, 0) == -1)
287 perror_with_name ("Couldn't read debug registers");
295 #endif /* PT_GETDBREGS */
298 /* Support for the user struct. */
300 /* Return the address register REGNO. BLOCKEND is the value of
301 u.u_ar0, which should point to the registers. */
304 register_u_addr (CORE_ADDR blockend
, int regno
)
306 return (CORE_ADDR
) REG_ADDR (blockend
, regno
);
309 #include <sys/param.h>
310 #include <sys/user.h>
312 /* Return the size of the user struct. */
317 return (sizeof (struct user
));
This page took 0.037115 seconds and 4 git commands to generate.