1 /* Native-dependent code for BSD Unix running on i386's, for GDB.
2 Copyright 1988, 1989, 1991, 1992, 1994, 1995, 1996, 1998, 1999, 2000,
3 2001 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., 59 Temple Place - Suite 330,
20 Boston, MA 02111-1307, USA. */
24 #ifdef FETCH_INFERIOR_REGISTERS
25 #include <sys/types.h>
26 #include <sys/ptrace.h>
27 #include <machine/reg.h>
28 #include <machine/frame.h>
30 #include "gdbcore.h" /* for registers_fetched() */
34 fetch_inferior_registers (int regno
)
36 struct reg inferior_registers
;
38 ptrace (PT_GETREGS
, inferior_pid
, (PTRACE_ARG3_TYPE
) & inferior_registers
, 0);
39 memcpy (®isters
[REGISTER_BYTE (0)], &inferior_registers
, 4 * NUM_REGS
);
44 store_inferior_registers (int 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 (char *core_reg_sect
, unsigned core_reg_size
, int which
,
62 struct md_core
*core_reg
= (struct md_core
*) core_reg_sect
;
64 /* integer registers */
65 memcpy (®isters
[REGISTER_BYTE (0)], &core_reg
->intreg
,
67 /* floating point registers */
73 #include <machine/reg.h>
75 /* this table must line up with REGISTER_NAMES in tm-i386.h */
76 /* symbols like 'tEAX' come from <machine/reg.h> */
77 static int tregmap
[] =
79 tEAX
, tECX
, tEDX
, tEBX
,
80 tESP
, tEBP
, tESI
, tEDI
,
81 tEIP
, tEFLAGS
, tCS
, tSS
85 static int sregmap
[] =
87 sEAX
, sECX
, sEDX
, sEBX
,
88 sESP
, sEBP
, sESI
, sEDI
,
89 sEIP
, sEFLAGS
, sCS
, sSS
93 /* FreeBSD has decided to collapse the s* and t* symbols. So if the s*
94 ones aren't around, use the t* ones for sregmap too. */
96 static int sregmap
[] =
98 tEAX
, tECX
, tEDX
, tEBX
,
99 tESP
, tEBP
, tESI
, tEDI
,
100 tEIP
, tEFLAGS
, tCS
, tSS
104 /* blockend is the value of u.u_ar0, and points to the
105 place where ES is stored. */
108 i386_register_u_addr (int blockend
, int regnum
)
110 /* The following condition is a kludge to get at the proper register map
111 depending upon the state of pcb_flag.
112 The proper condition would be
113 if (u.u_pcb.pcb_flag & FM_TRAP)
114 but that would require a ptrace call here and wouldn't work
117 if (blockend
< 0x1fcc)
118 return (blockend
+ 4 * tregmap
[regnum
]);
120 return (blockend
+ 4 * sregmap
[regnum
]);
123 #endif /* !FETCH_INFERIOR_REGISTERS */
126 #include "expression.h"
127 #include "language.h" /* for local_hex_string */
128 #include "floatformat.h"
130 #include <sys/param.h>
133 #include <sys/ioctl.h>
138 #include <sys/time.h>
139 #include <sys/resource.h>
141 #define curpcb Xcurpcb /* XXX avoid leaking declaration from pcb.h */
142 #include <sys/user.h>
144 #include <sys/file.h>
145 #include "gdb_stat.h"
146 #include <sys/ptrace.h>
148 extern void print_387_control_word (); /* i387-tdep.h */
149 extern void print_387_status_word ();
151 #define fpstate save87
152 #define U_FPSTATE(u) u.u_pcb.pcb_savefpu
156 unsigned short control
;
158 unsigned short status
;
163 unsigned short code_seg
;
164 unsigned short opcode
;
165 unsigned long operand
;
166 unsigned short operand_seg
;
168 unsigned char regs
[8][10];
172 print_387_status (unsigned short status
, struct env387
*ep
)
179 bothstatus
= ((status
!= 0) && (ep
->status
!= 0));
183 printf_unfiltered ("u: ");
184 print_387_status_word ((unsigned int) status
);
190 printf_unfiltered ("e: ");
191 print_387_status_word ((unsigned int) ep
->status
);
194 print_387_control_word ((unsigned int) ep
->control
);
195 printf_unfiltered ("last exception: ");
196 printf_unfiltered ("opcode %s; ", local_hex_string (ep
->opcode
));
197 printf_unfiltered ("pc %s:", local_hex_string (ep
->code_seg
));
198 printf_unfiltered ("%s; ", local_hex_string (ep
->eip
));
199 printf_unfiltered ("operand %s", local_hex_string (ep
->operand_seg
));
200 printf_unfiltered (":%s\n", local_hex_string (ep
->operand
));
202 top
= (ep
->status
>> 11) & 7;
204 printf_unfiltered ("regno tag msb lsb value\n");
205 for (fpreg
= 7; fpreg
>= 0; fpreg
--)
209 printf_unfiltered ("%s %d: ", fpreg
== top
? "=>" : " ", fpreg
);
211 switch ((ep
->tag
>> (fpreg
* 2)) & 3)
214 printf_unfiltered ("valid ");
217 printf_unfiltered ("zero ");
220 printf_unfiltered ("trap ");
223 printf_unfiltered ("empty ");
226 for (i
= 9; i
>= 0; i
--)
227 printf_unfiltered ("%02x", ep
->regs
[fpreg
][i
]);
229 floatformat_to_double (&floatformat_i387_ext
, (char *) ep
->regs
[fpreg
],
231 printf_unfiltered (" %g\n", val
);
235 i386_float_info (void)
237 struct user u
; /* just for address computations */
239 /* fpstate defined in <sys/user.h> */
240 struct fpstate
*fpstatep
;
241 char buf
[sizeof (struct fpstate
) + 2 * sizeof (int)];
244 unsigned int rounded_addr
;
245 unsigned int rounded_size
;
246 /*extern int corechan; */
248 extern int inferior_pid
;
250 uaddr
= (char *) &U_FPSTATE (u
) - (char *) &u
;
255 rounded_addr
= uaddr
& -sizeof (int);
256 rounded_size
= (((uaddr
+ sizeof (struct fpstate
)) - uaddr
) +
257 sizeof (int) - 1) / sizeof (int);
258 skip
= uaddr
- rounded_addr
;
261 for (i
= 0; i
< rounded_size
; i
++)
263 *ip
++ = ptrace (PT_READ_U
, inferior_pid
, (caddr_t
) rounded_addr
, 0);
264 rounded_addr
+= sizeof (int);
269 printf ("float info: can't do a core file (yet)\n");
272 if (lseek (corechan
, uaddr
, 0) < 0)
273 perror_with_name ("seek on core file");
274 if (myread (corechan
, buf
, sizeof (struct fpstate
)) < 0)
275 perror_with_name ("read from core file");
280 print_387_status (0, (struct env387
*) buf
);
286 return (sizeof (struct user
));
This page took 0.036437 seconds and 4 git commands to generate.