1 /* Native-dependent code for BSD Unix running on i386's, for GDB.
2 Copyright 1988, 1989, 1991, 1992, 1994, 1996 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. */
23 #ifdef FETCH_INFERIOR_REGISTERS
24 #include <sys/types.h>
25 #include <sys/ptrace.h>
26 #include <machine/reg.h>
27 #include <machine/frame.h>
29 #include "gdbcore.h" /* for registers_fetched() */
32 fetch_inferior_registers (regno
)
35 struct reg inferior_registers
;
37 ptrace (PT_GETREGS
, inferior_pid
, (PTRACE_ARG3_TYPE
) & inferior_registers
, 0);
38 memcpy (®isters
[REGISTER_BYTE (0)], &inferior_registers
, 4 * NUM_REGS
);
43 store_inferior_registers (regno
)
46 struct reg inferior_registers
;
48 memcpy (&inferior_registers
, ®isters
[REGISTER_BYTE (0)], 4 * NUM_REGS
);
49 ptrace (PT_SETREGS
, inferior_pid
, (PTRACE_ARG3_TYPE
) & inferior_registers
, 0);
59 fetch_core_registers (core_reg_sect
, core_reg_size
, which
, ignore
)
61 unsigned core_reg_size
;
65 struct md_core
*core_reg
= (struct md_core
*) core_reg_sect
;
67 /* integer registers */
68 memcpy (®isters
[REGISTER_BYTE (0)], &core_reg
->intreg
,
70 /* floating point registers */
76 #include <machine/reg.h>
78 /* this table must line up with REGISTER_NAMES in tm-i386.h */
79 /* symbols like 'tEAX' come from <machine/reg.h> */
80 static int tregmap
[] =
82 tEAX
, tECX
, tEDX
, tEBX
,
83 tESP
, tEBP
, tESI
, tEDI
,
84 tEIP
, tEFLAGS
, tCS
, tSS
88 static int sregmap
[] =
90 sEAX
, sECX
, sEDX
, sEBX
,
91 sESP
, sEBP
, sESI
, sEDI
,
92 sEIP
, sEFLAGS
, sCS
, sSS
96 /* FreeBSD has decided to collapse the s* and t* symbols. So if the s*
97 ones aren't around, use the t* ones for sregmap too. */
99 static int sregmap
[] =
101 tEAX
, tECX
, tEDX
, tEBX
,
102 tESP
, tEBP
, tESI
, tEDI
,
103 tEIP
, tEFLAGS
, tCS
, tSS
107 /* blockend is the value of u.u_ar0, and points to the
108 place where ES is stored. */
111 i386_register_u_addr (blockend
, regnum
)
115 /* The following condition is a kludge to get at the proper register map
116 depending upon the state of pcb_flag.
117 The proper condition would be
118 if (u.u_pcb.pcb_flag & FM_TRAP)
119 but that would require a ptrace call here and wouldn't work
122 if (blockend
< 0x1fcc)
123 return (blockend
+ 4 * tregmap
[regnum
]);
125 return (blockend
+ 4 * sregmap
[regnum
]);
128 #endif /* !FETCH_INFERIOR_REGISTERS */
131 #include "expression.h"
132 #include "language.h" /* for local_hex_string */
133 #include "floatformat.h"
135 #include <sys/param.h>
138 #include <sys/ioctl.h>
143 #include <sys/time.h>
144 #include <sys/resource.h>
146 #define curpcb Xcurpcb /* XXX avoid leaking declaration from pcb.h */
147 #include <sys/user.h>
149 #include <sys/file.h>
150 #include "gdb_stat.h"
151 #include <sys/ptrace.h>
153 extern void print_387_control_word (); /* i387-tdep.h */
154 extern void print_387_status_word ();
156 #define fpstate save87
157 #define U_FPSTATE(u) u.u_pcb.pcb_savefpu
161 unsigned short control
;
163 unsigned short status
;
168 unsigned short code_seg
;
169 unsigned short opcode
;
170 unsigned long operand
;
171 unsigned short operand_seg
;
173 unsigned char regs
[8][10];
177 print_387_status (status
, ep
)
178 unsigned short status
;
186 bothstatus
= ((status
!= 0) && (ep
->status
!= 0));
190 printf_unfiltered ("u: ");
191 print_387_status_word ((unsigned int) status
);
197 printf_unfiltered ("e: ");
198 print_387_status_word ((unsigned int) ep
->status
);
201 print_387_control_word ((unsigned int) ep
->control
);
202 printf_unfiltered ("last exception: ");
203 printf_unfiltered ("opcode %s; ", local_hex_string (ep
->opcode
));
204 printf_unfiltered ("pc %s:", local_hex_string (ep
->code_seg
));
205 printf_unfiltered ("%s; ", local_hex_string (ep
->eip
));
206 printf_unfiltered ("operand %s", local_hex_string (ep
->operand_seg
));
207 printf_unfiltered (":%s\n", local_hex_string (ep
->operand
));
209 top
= (ep
->status
>> 11) & 7;
211 printf_unfiltered ("regno tag msb lsb value\n");
212 for (fpreg
= 7; fpreg
>= 0; fpreg
--)
216 printf_unfiltered ("%s %d: ", fpreg
== top
? "=>" : " ", fpreg
);
218 switch ((ep
->tag
>> (fpreg
* 2)) & 3)
221 printf_unfiltered ("valid ");
224 printf_unfiltered ("zero ");
227 printf_unfiltered ("trap ");
230 printf_unfiltered ("empty ");
233 for (i
= 9; i
>= 0; i
--)
234 printf_unfiltered ("%02x", ep
->regs
[fpreg
][i
]);
236 floatformat_to_double (&floatformat_i387_ext
, (char *) ep
->regs
[fpreg
],
238 printf_unfiltered (" %g\n", val
);
244 struct user u
; /* just for address computations */
246 /* fpstate defined in <sys/user.h> */
247 struct fpstate
*fpstatep
;
248 char buf
[sizeof (struct fpstate
) + 2 * sizeof (int)];
251 unsigned int rounded_addr
;
252 unsigned int rounded_size
;
253 /*extern int corechan; */
255 extern int inferior_pid
;
257 uaddr
= (char *) &U_FPSTATE (u
) - (char *) &u
;
262 rounded_addr
= uaddr
& -sizeof (int);
263 rounded_size
= (((uaddr
+ sizeof (struct fpstate
)) - uaddr
) +
264 sizeof (int) - 1) / sizeof (int);
265 skip
= uaddr
- rounded_addr
;
268 for (i
= 0; i
< rounded_size
; i
++)
270 *ip
++ = ptrace (PT_READ_U
, inferior_pid
, (caddr_t
) rounded_addr
, 0);
271 rounded_addr
+= sizeof (int);
276 printf ("float info: can't do a core file (yet)\n");
279 if (lseek (corechan
, uaddr
, 0) < 0)
280 perror_with_name ("seek on core file");
281 if (myread (corechan
, buf
, sizeof (struct fpstate
)) < 0)
282 perror_with_name ("read from core file");
287 print_387_status (0, (struct env387
*) buf
);
293 return (sizeof (struct user
));
This page took 0.036071 seconds and 4 git commands to generate.