]>
Commit | Line | Data |
---|---|---|
c906108c SS |
1 | /* Sequent Symmetry host interface, for GDB when running under Unix. |
2 | Copyright 1986, 1987, 1989, 1991, 1992, 1994 Free Software Foundation, Inc. | |
3 | ||
c5aa993b | 4 | This file is part of GDB. |
c906108c | 5 | |
c5aa993b JM |
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. | |
c906108c | 10 | |
c5aa993b JM |
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. | |
c906108c | 15 | |
c5aa993b JM |
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. */ | |
c906108c SS |
20 | |
21 | /* FIXME, some 387-specific items of use taken from i387-tdep.c -- ought to be | |
22 | merged back in. */ | |
23 | ||
24 | #include "defs.h" | |
25 | #include "frame.h" | |
26 | #include "inferior.h" | |
27 | #include "symtab.h" | |
28 | #include "target.h" | |
29 | ||
30 | /* FIXME: What is the _INKERNEL define for? */ | |
31 | #define _INKERNEL | |
32 | #include <signal.h> | |
33 | #undef _INKERNEL | |
34 | #include <sys/wait.h> | |
35 | #include <sys/param.h> | |
36 | #include <sys/user.h> | |
37 | #include <sys/proc.h> | |
38 | #include <sys/dir.h> | |
39 | #include <sys/ioctl.h> | |
40 | #include "gdb_stat.h" | |
41 | #ifdef _SEQUENT_ | |
42 | #include <sys/ptrace.h> | |
43 | #else | |
44 | /* Dynix has only machine/ptrace.h, which is already included by sys/user.h */ | |
45 | /* Dynix has no mptrace call */ | |
46 | #define mptrace ptrace | |
47 | #endif | |
48 | #include "gdbcore.h" | |
49 | #include <fcntl.h> | |
50 | #include <sgtty.h> | |
51 | #define TERMINAL struct sgttyb | |
52 | ||
53 | #include "gdbcore.h" | |
54 | ||
55 | void | |
c5aa993b JM |
56 | store_inferior_registers (regno) |
57 | int regno; | |
c906108c SS |
58 | { |
59 | struct pt_regset regs; | |
60 | int i; | |
c906108c SS |
61 | |
62 | /* FIXME: Fetching the registers is a kludge to initialize all elements | |
63 | in the fpu and fpa status. This works for normal debugging, but | |
64 | might cause problems when calling functions in the inferior. | |
65 | At least fpu_control and fpa_pcr (probably more) should be added | |
66 | to the registers array to solve this properly. */ | |
c5aa993b JM |
67 | mptrace (XPT_RREGS, inferior_pid, (PTRACE_ARG3_TYPE) & regs, 0); |
68 | ||
69 | regs.pr_eax = *(int *) ®isters[REGISTER_BYTE (0)]; | |
70 | regs.pr_ebx = *(int *) ®isters[REGISTER_BYTE (5)]; | |
71 | regs.pr_ecx = *(int *) ®isters[REGISTER_BYTE (2)]; | |
72 | regs.pr_edx = *(int *) ®isters[REGISTER_BYTE (1)]; | |
73 | regs.pr_esi = *(int *) ®isters[REGISTER_BYTE (6)]; | |
74 | regs.pr_edi = *(int *) ®isters[REGISTER_BYTE (7)]; | |
75 | regs.pr_esp = *(int *) ®isters[REGISTER_BYTE (14)]; | |
76 | regs.pr_ebp = *(int *) ®isters[REGISTER_BYTE (15)]; | |
77 | regs.pr_eip = *(int *) ®isters[REGISTER_BYTE (16)]; | |
78 | regs.pr_flags = *(int *) ®isters[REGISTER_BYTE (17)]; | |
c906108c SS |
79 | for (i = 0; i < 31; i++) |
80 | { | |
81 | regs.pr_fpa.fpa_regs[i] = | |
c5aa993b | 82 | *(int *) ®isters[REGISTER_BYTE (FP1_REGNUM + i)]; |
c906108c | 83 | } |
c5aa993b JM |
84 | memcpy (regs.pr_fpu.fpu_stack[0], ®isters[REGISTER_BYTE (ST0_REGNUM)], 10); |
85 | memcpy (regs.pr_fpu.fpu_stack[1], ®isters[REGISTER_BYTE (ST1_REGNUM)], 10); | |
86 | memcpy (regs.pr_fpu.fpu_stack[2], ®isters[REGISTER_BYTE (ST2_REGNUM)], 10); | |
87 | memcpy (regs.pr_fpu.fpu_stack[3], ®isters[REGISTER_BYTE (ST3_REGNUM)], 10); | |
88 | memcpy (regs.pr_fpu.fpu_stack[4], ®isters[REGISTER_BYTE (ST4_REGNUM)], 10); | |
89 | memcpy (regs.pr_fpu.fpu_stack[5], ®isters[REGISTER_BYTE (ST5_REGNUM)], 10); | |
90 | memcpy (regs.pr_fpu.fpu_stack[6], ®isters[REGISTER_BYTE (ST6_REGNUM)], 10); | |
91 | memcpy (regs.pr_fpu.fpu_stack[7], ®isters[REGISTER_BYTE (ST7_REGNUM)], 10); | |
92 | mptrace (XPT_WREGS, inferior_pid, (PTRACE_ARG3_TYPE) & regs, 0); | |
c906108c SS |
93 | } |
94 | ||
95 | void | |
96 | fetch_inferior_registers (regno) | |
97 | int regno; | |
98 | { | |
99 | int i; | |
100 | struct pt_regset regs; | |
c906108c SS |
101 | |
102 | registers_fetched (); | |
103 | ||
c5aa993b JM |
104 | mptrace (XPT_RREGS, inferior_pid, (PTRACE_ARG3_TYPE) & regs, 0); |
105 | *(int *) ®isters[REGISTER_BYTE (EAX_REGNUM)] = regs.pr_eax; | |
106 | *(int *) ®isters[REGISTER_BYTE (EBX_REGNUM)] = regs.pr_ebx; | |
107 | *(int *) ®isters[REGISTER_BYTE (ECX_REGNUM)] = regs.pr_ecx; | |
108 | *(int *) ®isters[REGISTER_BYTE (EDX_REGNUM)] = regs.pr_edx; | |
109 | *(int *) ®isters[REGISTER_BYTE (ESI_REGNUM)] = regs.pr_esi; | |
110 | *(int *) ®isters[REGISTER_BYTE (EDI_REGNUM)] = regs.pr_edi; | |
111 | *(int *) ®isters[REGISTER_BYTE (EBP_REGNUM)] = regs.pr_ebp; | |
112 | *(int *) ®isters[REGISTER_BYTE (ESP_REGNUM)] = regs.pr_esp; | |
113 | *(int *) ®isters[REGISTER_BYTE (EIP_REGNUM)] = regs.pr_eip; | |
114 | *(int *) ®isters[REGISTER_BYTE (EFLAGS_REGNUM)] = regs.pr_flags; | |
c906108c SS |
115 | for (i = 0; i < FPA_NREGS; i++) |
116 | { | |
c5aa993b | 117 | *(int *) ®isters[REGISTER_BYTE (FP1_REGNUM + i)] = |
c906108c SS |
118 | regs.pr_fpa.fpa_regs[i]; |
119 | } | |
c5aa993b JM |
120 | memcpy (®isters[REGISTER_BYTE (ST0_REGNUM)], regs.pr_fpu.fpu_stack[0], 10); |
121 | memcpy (®isters[REGISTER_BYTE (ST1_REGNUM)], regs.pr_fpu.fpu_stack[1], 10); | |
122 | memcpy (®isters[REGISTER_BYTE (ST2_REGNUM)], regs.pr_fpu.fpu_stack[2], 10); | |
123 | memcpy (®isters[REGISTER_BYTE (ST3_REGNUM)], regs.pr_fpu.fpu_stack[3], 10); | |
124 | memcpy (®isters[REGISTER_BYTE (ST4_REGNUM)], regs.pr_fpu.fpu_stack[4], 10); | |
125 | memcpy (®isters[REGISTER_BYTE (ST5_REGNUM)], regs.pr_fpu.fpu_stack[5], 10); | |
126 | memcpy (®isters[REGISTER_BYTE (ST6_REGNUM)], regs.pr_fpu.fpu_stack[6], 10); | |
127 | memcpy (®isters[REGISTER_BYTE (ST7_REGNUM)], regs.pr_fpu.fpu_stack[7], 10); | |
c906108c SS |
128 | } |
129 | \f | |
130 | /* FIXME: This should be merged with i387-tdep.c as well. */ | |
131 | static | |
c5aa993b JM |
132 | print_fpu_status (ep) |
133 | struct pt_regset ep; | |
c906108c | 134 | { |
c5aa993b JM |
135 | int i; |
136 | int bothstatus; | |
137 | int top; | |
138 | int fpreg; | |
139 | unsigned char *p; | |
140 | ||
141 | printf_unfiltered ("80387:"); | |
142 | if (ep.pr_fpu.fpu_ip == 0) | |
143 | { | |
144 | printf_unfiltered (" not in use.\n"); | |
145 | return; | |
c906108c | 146 | } |
c5aa993b JM |
147 | else |
148 | { | |
149 | printf_unfiltered ("\n"); | |
150 | } | |
151 | if (ep.pr_fpu.fpu_status != 0) | |
152 | { | |
153 | print_387_status_word (ep.pr_fpu.fpu_status); | |
c906108c | 154 | } |
c5aa993b JM |
155 | print_387_control_word (ep.pr_fpu.fpu_control); |
156 | printf_unfiltered ("last exception: "); | |
157 | printf_unfiltered ("opcode 0x%x; ", ep.pr_fpu.fpu_rsvd4); | |
158 | printf_unfiltered ("pc 0x%x:0x%x; ", ep.pr_fpu.fpu_cs, ep.pr_fpu.fpu_ip); | |
159 | printf_unfiltered ("operand 0x%x:0x%x\n", ep.pr_fpu.fpu_data_offset, ep.pr_fpu.fpu_op_sel); | |
160 | ||
161 | top = (ep.pr_fpu.fpu_status >> 11) & 7; | |
162 | ||
163 | printf_unfiltered ("regno tag msb lsb value\n"); | |
164 | for (fpreg = 7; fpreg >= 0; fpreg--) | |
165 | { | |
166 | double val; | |
167 | ||
168 | printf_unfiltered ("%s %d: ", fpreg == top ? "=>" : " ", fpreg); | |
169 | ||
170 | switch ((ep.pr_fpu.fpu_tag >> (fpreg * 2)) & 3) | |
c906108c | 171 | { |
c5aa993b JM |
172 | case 0: |
173 | printf_unfiltered ("valid "); | |
174 | break; | |
175 | case 1: | |
176 | printf_unfiltered ("zero "); | |
177 | break; | |
178 | case 2: | |
179 | printf_unfiltered ("trap "); | |
180 | break; | |
181 | case 3: | |
182 | printf_unfiltered ("empty "); | |
183 | break; | |
c906108c | 184 | } |
c5aa993b JM |
185 | for (i = 9; i >= 0; i--) |
186 | printf_unfiltered ("%02x", ep.pr_fpu.fpu_stack[fpreg][i]); | |
187 | ||
188 | i387_to_double ((char *) ep.pr_fpu.fpu_stack[fpreg], (char *) &val); | |
189 | printf_unfiltered (" %g\n", val); | |
190 | } | |
191 | if (ep.pr_fpu.fpu_rsvd1) | |
192 | warning ("rsvd1 is 0x%x\n", ep.pr_fpu.fpu_rsvd1); | |
193 | if (ep.pr_fpu.fpu_rsvd2) | |
194 | warning ("rsvd2 is 0x%x\n", ep.pr_fpu.fpu_rsvd2); | |
195 | if (ep.pr_fpu.fpu_rsvd3) | |
196 | warning ("rsvd3 is 0x%x\n", ep.pr_fpu.fpu_rsvd3); | |
197 | if (ep.pr_fpu.fpu_rsvd5) | |
198 | warning ("rsvd5 is 0x%x\n", ep.pr_fpu.fpu_rsvd5); | |
c906108c SS |
199 | } |
200 | ||
201 | ||
c5aa993b JM |
202 | print_1167_control_word (pcr) |
203 | unsigned int pcr; | |
c906108c SS |
204 | |
205 | { | |
c5aa993b | 206 | int pcr_tmp; |
c906108c | 207 | |
c5aa993b JM |
208 | pcr_tmp = pcr & FPA_PCR_MODE; |
209 | printf_unfiltered ("\tMODE= %#x; RND= %#x ", pcr_tmp, pcr_tmp & 12); | |
210 | switch (pcr_tmp & 12) | |
211 | { | |
c906108c | 212 | case 0: |
c5aa993b JM |
213 | printf_unfiltered ("RN (Nearest Value)"); |
214 | break; | |
c906108c | 215 | case 1: |
c5aa993b JM |
216 | printf_unfiltered ("RZ (Zero)"); |
217 | break; | |
c906108c | 218 | case 2: |
c5aa993b JM |
219 | printf_unfiltered ("RP (Positive Infinity)"); |
220 | break; | |
c906108c | 221 | case 3: |
c5aa993b JM |
222 | printf_unfiltered ("RM (Negative Infinity)"); |
223 | break; | |
224 | } | |
225 | printf_unfiltered ("; IRND= %d ", pcr_tmp & 2); | |
226 | if (0 == pcr_tmp & 2) | |
227 | { | |
228 | printf_unfiltered ("(same as RND)\n"); | |
c906108c | 229 | } |
c5aa993b JM |
230 | else |
231 | { | |
232 | printf_unfiltered ("(toward zero)\n"); | |
c906108c | 233 | } |
c5aa993b JM |
234 | pcr_tmp = pcr & FPA_PCR_EM; |
235 | printf_unfiltered ("\tEM= %#x", pcr_tmp); | |
236 | if (pcr_tmp & FPA_PCR_EM_DM) | |
237 | printf_unfiltered (" DM"); | |
238 | if (pcr_tmp & FPA_PCR_EM_UOM) | |
239 | printf_unfiltered (" UOM"); | |
240 | if (pcr_tmp & FPA_PCR_EM_PM) | |
241 | printf_unfiltered (" PM"); | |
242 | if (pcr_tmp & FPA_PCR_EM_UM) | |
243 | printf_unfiltered (" UM"); | |
244 | if (pcr_tmp & FPA_PCR_EM_OM) | |
245 | printf_unfiltered (" OM"); | |
246 | if (pcr_tmp & FPA_PCR_EM_ZM) | |
247 | printf_unfiltered (" ZM"); | |
248 | if (pcr_tmp & FPA_PCR_EM_IM) | |
249 | printf_unfiltered (" IM"); | |
250 | printf_unfiltered ("\n"); | |
251 | pcr_tmp = FPA_PCR_CC; | |
252 | printf_unfiltered ("\tCC= %#x", pcr_tmp); | |
253 | if (pcr_tmp & FPA_PCR_20MHZ) | |
254 | printf_unfiltered (" 20MHZ"); | |
255 | if (pcr_tmp & FPA_PCR_CC_Z) | |
256 | printf_unfiltered (" Z"); | |
257 | if (pcr_tmp & FPA_PCR_CC_C2) | |
258 | printf_unfiltered (" C2"); | |
259 | ||
260 | /* Dynix defines FPA_PCR_CC_C0 to 0x100 and ptx defines | |
261 | FPA_PCR_CC_C1 to 0x100. Use whichever is defined and assume | |
262 | the OS knows what it is doing. */ | |
c906108c | 263 | #ifdef FPA_PCR_CC_C1 |
c5aa993b JM |
264 | if (pcr_tmp & FPA_PCR_CC_C1) |
265 | printf_unfiltered (" C1"); | |
c906108c | 266 | #else |
c5aa993b JM |
267 | if (pcr_tmp & FPA_PCR_CC_C0) |
268 | printf_unfiltered (" C0"); | |
c906108c SS |
269 | #endif |
270 | ||
c5aa993b JM |
271 | switch (pcr_tmp) |
272 | { | |
273 | case FPA_PCR_CC_Z: | |
274 | printf_unfiltered (" (Equal)"); | |
275 | break; | |
c906108c | 276 | #ifdef FPA_PCR_CC_C1 |
c5aa993b | 277 | case FPA_PCR_CC_C1: |
c906108c | 278 | #else |
c5aa993b | 279 | case FPA_PCR_CC_C0: |
c906108c | 280 | #endif |
c5aa993b JM |
281 | printf_unfiltered (" (Less than)"); |
282 | break; | |
283 | case 0: | |
284 | printf_unfiltered (" (Greater than)"); | |
285 | break; | |
286 | case FPA_PCR_CC_Z | | |
c906108c SS |
287 | #ifdef FPA_PCR_CC_C1 |
288 | FPA_PCR_CC_C1 | |
289 | #else | |
290 | FPA_PCR_CC_C0 | |
291 | #endif | |
c5aa993b JM |
292 | | FPA_PCR_CC_C2: |
293 | printf_unfiltered (" (Unordered)"); | |
294 | break; | |
295 | default: | |
296 | printf_unfiltered (" (Undefined)"); | |
297 | break; | |
298 | } | |
299 | printf_unfiltered ("\n"); | |
300 | pcr_tmp = pcr & FPA_PCR_AE; | |
301 | printf_unfiltered ("\tAE= %#x", pcr_tmp); | |
302 | if (pcr_tmp & FPA_PCR_AE_DE) | |
303 | printf_unfiltered (" DE"); | |
304 | if (pcr_tmp & FPA_PCR_AE_UOE) | |
305 | printf_unfiltered (" UOE"); | |
306 | if (pcr_tmp & FPA_PCR_AE_PE) | |
307 | printf_unfiltered (" PE"); | |
308 | if (pcr_tmp & FPA_PCR_AE_UE) | |
309 | printf_unfiltered (" UE"); | |
310 | if (pcr_tmp & FPA_PCR_AE_OE) | |
311 | printf_unfiltered (" OE"); | |
312 | if (pcr_tmp & FPA_PCR_AE_ZE) | |
313 | printf_unfiltered (" ZE"); | |
314 | if (pcr_tmp & FPA_PCR_AE_EE) | |
315 | printf_unfiltered (" EE"); | |
316 | if (pcr_tmp & FPA_PCR_AE_IE) | |
317 | printf_unfiltered (" IE"); | |
318 | printf_unfiltered ("\n"); | |
c906108c SS |
319 | } |
320 | ||
c5aa993b JM |
321 | print_1167_regs (regs) |
322 | long regs[FPA_NREGS]; | |
c906108c SS |
323 | |
324 | { | |
c5aa993b JM |
325 | int i; |
326 | ||
327 | union | |
328 | { | |
329 | double d; | |
330 | long l[2]; | |
331 | } | |
332 | xd; | |
333 | union | |
334 | { | |
335 | float f; | |
336 | long l; | |
337 | } | |
338 | xf; | |
339 | ||
340 | ||
341 | for (i = 0; i < FPA_NREGS; i++) | |
342 | { | |
343 | xf.l = regs[i]; | |
344 | printf_unfiltered ("%%fp%d: raw= %#x, single= %f", i + 1, regs[i], xf.f); | |
345 | if (!(i & 1)) | |
346 | { | |
347 | printf_unfiltered ("\n"); | |
348 | } | |
349 | else | |
350 | { | |
351 | xd.l[1] = regs[i]; | |
352 | xd.l[0] = regs[i + 1]; | |
353 | printf_unfiltered (", double= %f\n", xd.d); | |
c906108c SS |
354 | } |
355 | } | |
356 | } | |
357 | ||
c5aa993b JM |
358 | print_fpa_status (ep) |
359 | struct pt_regset ep; | |
c906108c SS |
360 | |
361 | { | |
362 | ||
c5aa993b JM |
363 | printf_unfiltered ("WTL 1167:"); |
364 | if (ep.pr_fpa.fpa_pcr != 0) | |
365 | { | |
366 | printf_unfiltered ("\n"); | |
367 | print_1167_control_word (ep.pr_fpa.fpa_pcr); | |
368 | print_1167_regs (ep.pr_fpa.fpa_regs); | |
369 | } | |
370 | else | |
371 | { | |
372 | printf_unfiltered (" not in use.\n"); | |
c906108c SS |
373 | } |
374 | } | |
375 | ||
c5aa993b | 376 | #if 0 /* disabled because it doesn't go through the target vector. */ |
c906108c SS |
377 | i386_float_info () |
378 | { | |
c5aa993b | 379 | char ubuf[UPAGES * NBPG]; |
c906108c SS |
380 | struct pt_regset regset; |
381 | ||
c5aa993b | 382 | if (have_inferior_p ()) |
c906108c | 383 | { |
c5aa993b | 384 | PTRACE_READ_REGS (inferior_pid, (PTRACE_ARG3_TYPE) & regset); |
c906108c SS |
385 | } |
386 | else | |
387 | { | |
388 | int corechan = bfd_cache_lookup (core_bfd); | |
389 | if (lseek (corechan, 0, 0) < 0) | |
390 | { | |
391 | perror ("seek on core file"); | |
392 | } | |
c5aa993b | 393 | if (myread (corechan, ubuf, UPAGES * NBPG) < 0) |
c906108c SS |
394 | { |
395 | perror ("read on core file"); | |
396 | } | |
397 | /* only interested in the floating point registers */ | |
398 | regset.pr_fpu = ((struct user *) ubuf)->u_fpusave; | |
399 | regset.pr_fpa = ((struct user *) ubuf)->u_fpasave; | |
400 | } | |
c5aa993b JM |
401 | print_fpu_status (regset); |
402 | print_fpa_status (regset); | |
c906108c SS |
403 | } |
404 | #endif | |
405 | ||
406 | static volatile int got_sigchld; | |
407 | ||
c5aa993b | 408 | /*ARGSUSED */ |
c906108c SS |
409 | /* This will eventually be more interesting. */ |
410 | void | |
c5aa993b JM |
411 | sigchld_handler (signo) |
412 | int signo; | |
c906108c | 413 | { |
c5aa993b | 414 | got_sigchld++; |
c906108c SS |
415 | } |
416 | ||
417 | /* | |
418 | * Signals for which the default action does not cause the process | |
419 | * to die. See <sys/signal.h> for where this came from (alas, we | |
420 | * can't use those macros directly) | |
421 | */ | |
422 | #ifndef sigmask | |
423 | #define sigmask(s) (1 << ((s) - 1)) | |
424 | #endif | |
425 | #define SIGNALS_DFL_SAFE sigmask(SIGSTOP) | sigmask(SIGTSTP) | \ | |
426 | sigmask(SIGTTIN) | sigmask(SIGTTOU) | sigmask(SIGCHLD) | \ | |
427 | sigmask(SIGCONT) | sigmask(SIGWINCH) | sigmask(SIGPWR) | \ | |
428 | sigmask(SIGURG) | sigmask(SIGPOLL) | |
429 | ||
430 | #ifdef ATTACH_DETACH | |
431 | /* | |
432 | * Thanks to XPT_MPDEBUGGER, we have to mange child_wait(). | |
433 | */ | |
434 | int | |
c5aa993b | 435 | child_wait (pid, status) |
c906108c SS |
436 | int pid; |
437 | struct target_waitstatus *status; | |
438 | { | |
439 | int save_errno, rv, xvaloff, saoff, sa_hand; | |
440 | struct pt_stop pt; | |
441 | struct user u; | |
442 | sigset_t set; | |
443 | /* Host signal number for a signal which the inferior terminates with, or | |
444 | 0 if it hasn't terminated due to a signal. */ | |
445 | static int death_by_signal = 0; | |
446 | #ifdef SVR4_SHARED_LIBS /* use this to distinguish ptx 2 vs ptx 4 */ | |
447 | prstatus_t pstatus; | |
448 | #endif | |
449 | ||
c5aa993b JM |
450 | do |
451 | { | |
452 | set_sigint_trap (); /* Causes SIGINT to be passed on to the | |
453 | attached process. */ | |
454 | save_errno = errno; | |
c906108c | 455 | |
c5aa993b | 456 | got_sigchld = 0; |
c906108c | 457 | |
c5aa993b | 458 | sigemptyset (&set); |
c906108c | 459 | |
c5aa993b JM |
460 | while (got_sigchld == 0) |
461 | { | |
462 | sigsuspend (&set); | |
463 | } | |
c906108c | 464 | |
c5aa993b JM |
465 | clear_sigint_trap (); |
466 | ||
467 | rv = mptrace (XPT_STOPSTAT, 0, (char *) &pt, 0); | |
468 | if (-1 == rv) | |
469 | { | |
470 | printf ("XPT_STOPSTAT: errno %d\n", errno); /* DEBUG */ | |
471 | continue; | |
472 | } | |
c906108c | 473 | |
c5aa993b JM |
474 | pid = pt.ps_pid; |
475 | ||
476 | if (pid != inferior_pid) | |
477 | { | |
478 | /* NOTE: the mystery fork in csh/tcsh needs to be ignored. | |
479 | * We should not return new children for the initial run | |
480 | * of a process until it has done the exec. | |
481 | */ | |
482 | /* inferior probably forked; send it on its way */ | |
483 | rv = mptrace (XPT_UNDEBUG, pid, 0, 0); | |
484 | if (-1 == rv) | |
485 | { | |
486 | printf ("child_wait: XPT_UNDEBUG: pid %d: %s\n", pid, | |
487 | safe_strerror (errno)); | |
c906108c | 488 | } |
c5aa993b JM |
489 | continue; |
490 | } | |
491 | /* FIXME: Do we deal with fork notification correctly? */ | |
492 | switch (pt.ps_reason) | |
493 | { | |
494 | case PTS_FORK: | |
495 | /* multi proc: treat like PTS_EXEC */ | |
496 | /* | |
497 | * Pretend this didn't happen, since gdb isn't set up | |
498 | * to deal with stops on fork. | |
499 | */ | |
500 | rv = ptrace (PT_CONTSIG, pid, 1, 0); | |
501 | if (-1 == rv) | |
502 | { | |
503 | printf ("PTS_FORK: PT_CONTSIG: error %d\n", errno); | |
c906108c | 504 | } |
c5aa993b JM |
505 | continue; |
506 | case PTS_EXEC: | |
507 | /* | |
508 | * Pretend this is a SIGTRAP. | |
509 | */ | |
510 | status->kind = TARGET_WAITKIND_STOPPED; | |
511 | status->value.sig = TARGET_SIGNAL_TRAP; | |
512 | break; | |
513 | case PTS_EXIT: | |
514 | /* | |
515 | * Note: we stop before the exit actually occurs. Extract | |
516 | * the exit code from the uarea. If we're stopped in the | |
517 | * exit() system call, the exit code will be in | |
518 | * u.u_ap[0]. An exit due to an uncaught signal will have | |
519 | * something else in here, see the comment in the default: | |
520 | * case, below. Finally,let the process exit. | |
521 | */ | |
522 | if (death_by_signal) | |
523 | { | |
524 | status->kind = TARGET_WAITKIND_SIGNALED; | |
525 | status->value.sig = target_signal_from_host (death_by_signal); | |
526 | death_by_signal = 0; | |
527 | break; | |
c906108c | 528 | } |
c5aa993b JM |
529 | xvaloff = (unsigned long) &u.u_ap[0] - (unsigned long) &u; |
530 | errno = 0; | |
531 | rv = ptrace (PT_RUSER, pid, (char *) xvaloff, 0); | |
532 | status->kind = TARGET_WAITKIND_EXITED; | |
533 | status->value.integer = rv; | |
534 | /* | |
535 | * addr & data to mptrace() don't matter here, since | |
536 | * the process is already dead. | |
537 | */ | |
538 | rv = mptrace (XPT_UNDEBUG, pid, 0, 0); | |
539 | if (-1 == rv) | |
540 | { | |
541 | printf ("child_wait: PTS_EXIT: XPT_UNDEBUG: pid %d error %d\n", pid, | |
542 | errno); | |
543 | } | |
544 | break; | |
545 | case PTS_WATCHPT_HIT: | |
546 | fatal ("PTS_WATCHPT_HIT\n"); | |
547 | break; | |
548 | default: | |
549 | /* stopped by signal */ | |
550 | status->kind = TARGET_WAITKIND_STOPPED; | |
551 | status->value.sig = target_signal_from_host (pt.ps_reason); | |
552 | death_by_signal = 0; | |
553 | ||
554 | if (0 == (SIGNALS_DFL_SAFE & sigmask (pt.ps_reason))) | |
555 | { | |
556 | break; | |
c906108c | 557 | } |
c5aa993b | 558 | /* else default action of signal is to die */ |
c906108c | 559 | #ifdef SVR4_SHARED_LIBS |
c5aa993b JM |
560 | rv = ptrace (PT_GET_PRSTATUS, pid, (char *) &pstatus, 0); |
561 | if (-1 == rv) | |
562 | error ("child_wait: signal %d PT_GET_PRSTATUS: %s\n", | |
563 | pt.ps_reason, safe_strerror (errno)); | |
564 | if (pstatus.pr_cursig != pt.ps_reason) | |
565 | { | |
566 | printf ("pstatus signal %d, pt signal %d\n", | |
567 | pstatus.pr_cursig, pt.ps_reason); | |
c906108c | 568 | } |
c5aa993b | 569 | sa_hand = (int) pstatus.pr_action.sa_handler; |
c906108c | 570 | #else |
c5aa993b JM |
571 | saoff = (unsigned long) &u.u_sa[0] - (unsigned long) &u; |
572 | saoff += sizeof (struct sigaction) * (pt.ps_reason - 1); | |
573 | errno = 0; | |
574 | sa_hand = ptrace (PT_RUSER, pid, (char *) saoff, 0); | |
575 | if (errno) | |
576 | error ("child_wait: signal %d: RUSER: %s\n", | |
577 | pt.ps_reason, safe_strerror (errno)); | |
c906108c | 578 | #endif |
c5aa993b JM |
579 | if ((int) SIG_DFL == sa_hand) |
580 | { | |
581 | /* we will be dying */ | |
582 | death_by_signal = pt.ps_reason; | |
c906108c | 583 | } |
c5aa993b JM |
584 | break; |
585 | } | |
c906108c | 586 | |
c5aa993b JM |
587 | } |
588 | while (pid != inferior_pid); /* Some other child died or stopped */ | |
c906108c SS |
589 | |
590 | return pid; | |
591 | } | |
592 | #else /* !ATTACH_DETACH */ | |
593 | /* | |
594 | * Simple child_wait() based on inftarg.c child_wait() for use until | |
595 | * the MPDEBUGGER child_wait() works properly. This will go away when | |
596 | * that is fixed. | |
597 | */ | |
598 | child_wait (pid, ourstatus) | |
599 | int pid; | |
600 | struct target_waitstatus *ourstatus; | |
601 | { | |
602 | int save_errno; | |
603 | int status; | |
604 | ||
c5aa993b JM |
605 | do |
606 | { | |
607 | pid = wait (&status); | |
608 | save_errno = errno; | |
c906108c | 609 | |
c5aa993b JM |
610 | if (pid == -1) |
611 | { | |
612 | if (save_errno == EINTR) | |
613 | continue; | |
614 | fprintf (stderr, "Child process unexpectedly missing: %s.\n", | |
615 | safe_strerror (save_errno)); | |
616 | ourstatus->kind = TARGET_WAITKIND_SIGNALLED; | |
617 | ourstatus->value.sig = TARGET_SIGNAL_UNKNOWN; | |
618 | return -1; | |
619 | } | |
620 | } | |
621 | while (pid != inferior_pid); /* Some other child died or stopped */ | |
c906108c SS |
622 | store_waitstatus (ourstatus, status); |
623 | return pid; | |
624 | } | |
625 | #endif /* ATTACH_DETACH */ | |
c5aa993b | 626 | \f |
c906108c SS |
627 | |
628 | ||
c906108c SS |
629 | /* This function simply calls ptrace with the given arguments. |
630 | It exists so that all calls to ptrace are isolated in this | |
631 | machine-dependent file. */ | |
632 | int | |
633 | call_ptrace (request, pid, addr, data) | |
634 | int request, pid; | |
635 | PTRACE_ARG3_TYPE addr; | |
636 | int data; | |
637 | { | |
638 | return ptrace (request, pid, addr, data); | |
639 | } | |
640 | ||
641 | int | |
c5aa993b JM |
642 | call_mptrace (request, pid, addr, data) |
643 | int request, pid; | |
644 | PTRACE_ARG3_TYPE addr; | |
645 | int data; | |
c906108c | 646 | { |
c5aa993b | 647 | return mptrace (request, pid, addr, data); |
c906108c SS |
648 | } |
649 | ||
650 | #if defined (DEBUG_PTRACE) | |
651 | /* For the rest of the file, use an extra level of indirection */ | |
652 | /* This lets us breakpoint usefully on call_ptrace. */ | |
653 | #define ptrace call_ptrace | |
654 | #define mptrace call_mptrace | |
655 | #endif | |
656 | ||
657 | void | |
658 | kill_inferior () | |
659 | { | |
660 | if (inferior_pid == 0) | |
661 | return; | |
662 | ||
663 | /* For MPDEBUGGER, don't use PT_KILL, since the child will stop | |
664 | again with a PTS_EXIT. Just hit him with SIGKILL (so he stops) | |
665 | and detach. */ | |
666 | ||
667 | kill (inferior_pid, SIGKILL); | |
668 | #ifdef ATTACH_DETACH | |
c5aa993b | 669 | detach (SIGKILL); |
c906108c | 670 | #else /* ATTACH_DETACH */ |
c5aa993b JM |
671 | ptrace (PT_KILL, inferior_pid, 0, 0); |
672 | wait ((int *) NULL); | |
c906108c SS |
673 | #endif /* ATTACH_DETACH */ |
674 | target_mourn_inferior (); | |
675 | } | |
676 | ||
677 | /* Resume execution of the inferior process. | |
678 | If STEP is nonzero, single-step it. | |
679 | If SIGNAL is nonzero, give it that signal. */ | |
680 | ||
681 | void | |
682 | child_resume (pid, step, signal) | |
683 | int pid; | |
684 | int step; | |
685 | enum target_signal signal; | |
686 | { | |
687 | errno = 0; | |
688 | ||
689 | if (pid == -1) | |
690 | pid = inferior_pid; | |
691 | ||
692 | /* An address of (PTRACE_ARG3_TYPE)1 tells ptrace to continue from where | |
693 | it was. (If GDB wanted it to start some other way, we have already | |
694 | written a new PC value to the child.) | |
695 | ||
696 | If this system does not support PT_SSTEP, a higher level function will | |
697 | have called single_step() to transmute the step request into a | |
698 | continue request (by setting breakpoints on all possible successor | |
699 | instructions), so we don't have to worry about that here. */ | |
700 | ||
701 | if (step) | |
c5aa993b | 702 | ptrace (PT_SSTEP, pid, (PTRACE_ARG3_TYPE) 1, signal); |
c906108c SS |
703 | else |
704 | ptrace (PT_CONTSIG, pid, (PTRACE_ARG3_TYPE) 1, signal); | |
705 | ||
706 | if (errno) | |
707 | perror_with_name ("ptrace"); | |
708 | } | |
709 | \f | |
710 | #ifdef ATTACH_DETACH | |
711 | /* Start debugging the process whose number is PID. */ | |
712 | int | |
713 | attach (pid) | |
714 | int pid; | |
715 | { | |
c5aa993b JM |
716 | sigset_t set; |
717 | int rv; | |
c906108c | 718 | |
c5aa993b JM |
719 | rv = mptrace (XPT_DEBUG, pid, 0, 0); |
720 | if (-1 == rv) | |
721 | { | |
722 | error ("mptrace(XPT_DEBUG): %s", safe_strerror (errno)); | |
723 | } | |
724 | rv = mptrace (XPT_SIGNAL, pid, 0, SIGSTOP); | |
725 | if (-1 == rv) | |
726 | { | |
727 | error ("mptrace(XPT_SIGNAL): %s", safe_strerror (errno)); | |
728 | } | |
729 | attach_flag = 1; | |
730 | return pid; | |
c906108c SS |
731 | } |
732 | ||
733 | void | |
734 | detach (signo) | |
735 | int signo; | |
736 | { | |
c5aa993b | 737 | int rv; |
c906108c | 738 | |
c5aa993b JM |
739 | rv = mptrace (XPT_UNDEBUG, inferior_pid, 1, signo); |
740 | if (-1 == rv) | |
741 | { | |
742 | error ("mptrace(XPT_UNDEBUG): %s", safe_strerror (errno)); | |
743 | } | |
744 | attach_flag = 0; | |
c906108c SS |
745 | } |
746 | ||
747 | #endif /* ATTACH_DETACH */ | |
748 | \f | |
749 | /* Default the type of the ptrace transfer to int. */ | |
750 | #ifndef PTRACE_XFER_TYPE | |
751 | #define PTRACE_XFER_TYPE int | |
752 | #endif | |
c906108c | 753 | \f |
c5aa993b | 754 | |
c906108c SS |
755 | /* NOTE! I tried using PTRACE_READDATA, etc., to read and write memory |
756 | in the NEW_SUN_PTRACE case. | |
757 | It ought to be straightforward. But it appears that writing did | |
758 | not write the data that I specified. I cannot understand where | |
759 | it got the data that it actually did write. */ | |
760 | ||
761 | /* Copy LEN bytes to or from inferior's memory starting at MEMADDR | |
762 | to debugger memory starting at MYADDR. Copy to inferior if | |
763 | WRITE is nonzero. | |
c5aa993b | 764 | |
c906108c SS |
765 | Returns the length copied, which is either the LEN argument or zero. |
766 | This xfer function does not do partial moves, since child_ops | |
767 | doesn't allow memory operations to cross below us in the target stack | |
768 | anyway. */ | |
769 | ||
770 | int | |
771 | child_xfer_memory (memaddr, myaddr, len, write, target) | |
772 | CORE_ADDR memaddr; | |
773 | char *myaddr; | |
774 | int len; | |
775 | int write; | |
c5aa993b | 776 | struct target_ops *target; /* ignored */ |
c906108c SS |
777 | { |
778 | register int i; | |
779 | /* Round starting address down to longword boundary. */ | |
c5aa993b | 780 | register CORE_ADDR addr = memaddr & -sizeof (PTRACE_XFER_TYPE); |
c906108c SS |
781 | /* Round ending address up; get number of longwords that makes. */ |
782 | register int count | |
c5aa993b JM |
783 | = (((memaddr + len) - addr) + sizeof (PTRACE_XFER_TYPE) - 1) |
784 | / sizeof (PTRACE_XFER_TYPE); | |
c906108c SS |
785 | /* Allocate buffer of that many longwords. */ |
786 | register PTRACE_XFER_TYPE *buffer | |
c5aa993b | 787 | = (PTRACE_XFER_TYPE *) alloca (count * sizeof (PTRACE_XFER_TYPE)); |
c906108c SS |
788 | |
789 | if (write) | |
790 | { | |
791 | /* Fill start and end extra bytes of buffer with existing memory data. */ | |
792 | ||
c5aa993b JM |
793 | if (addr != memaddr || len < (int) sizeof (PTRACE_XFER_TYPE)) |
794 | { | |
795 | /* Need part of initial word -- fetch it. */ | |
796 | buffer[0] = ptrace (PT_RTEXT, inferior_pid, (PTRACE_ARG3_TYPE) addr, | |
797 | 0); | |
798 | } | |
c906108c SS |
799 | |
800 | if (count > 1) /* FIXME, avoid if even boundary */ | |
801 | { | |
802 | buffer[count - 1] | |
803 | = ptrace (PT_RTEXT, inferior_pid, | |
804 | ((PTRACE_ARG3_TYPE) | |
805 | (addr + (count - 1) * sizeof (PTRACE_XFER_TYPE))), | |
806 | 0); | |
807 | } | |
808 | ||
809 | /* Copy data to be written over corresponding part of buffer */ | |
810 | ||
811 | memcpy ((char *) buffer + (memaddr & (sizeof (PTRACE_XFER_TYPE) - 1)), | |
812 | myaddr, | |
813 | len); | |
814 | ||
815 | /* Write the entire buffer. */ | |
816 | ||
817 | for (i = 0; i < count; i++, addr += sizeof (PTRACE_XFER_TYPE)) | |
818 | { | |
819 | errno = 0; | |
820 | ptrace (PT_WDATA, inferior_pid, (PTRACE_ARG3_TYPE) addr, | |
821 | buffer[i]); | |
822 | if (errno) | |
823 | { | |
824 | /* Using the appropriate one (I or D) is necessary for | |
c5aa993b | 825 | Gould NP1, at least. */ |
c906108c SS |
826 | errno = 0; |
827 | ptrace (PT_WTEXT, inferior_pid, (PTRACE_ARG3_TYPE) addr, | |
828 | buffer[i]); | |
829 | } | |
830 | if (errno) | |
831 | return 0; | |
832 | } | |
833 | } | |
834 | else | |
835 | { | |
836 | /* Read all the longwords */ | |
837 | for (i = 0; i < count; i++, addr += sizeof (PTRACE_XFER_TYPE)) | |
838 | { | |
839 | errno = 0; | |
840 | buffer[i] = ptrace (PT_RTEXT, inferior_pid, | |
841 | (PTRACE_ARG3_TYPE) addr, 0); | |
842 | if (errno) | |
843 | return 0; | |
844 | QUIT; | |
845 | } | |
846 | ||
847 | /* Copy appropriate bytes out of the buffer. */ | |
848 | memcpy (myaddr, | |
849 | (char *) buffer + (memaddr & (sizeof (PTRACE_XFER_TYPE) - 1)), | |
850 | len); | |
851 | } | |
852 | return len; | |
853 | } | |
854 | ||
855 | ||
856 | void | |
857 | _initialize_symm_nat () | |
858 | { | |
859 | #ifdef ATTACH_DETACH | |
860 | /* | |
861 | * the MPDEBUGGER is necessary for process tree debugging and attach | |
862 | * to work, but it alters the behavior of debugged processes, so other | |
863 | * things (at least child_wait()) will have to change to accomodate | |
864 | * that. | |
865 | * | |
866 | * Note that attach is not implemented in dynix 3, and not in ptx | |
867 | * until version 2.1 of the OS. | |
868 | */ | |
c5aa993b JM |
869 | int rv; |
870 | sigset_t set; | |
871 | struct sigaction sact; | |
c906108c | 872 | |
c5aa993b JM |
873 | rv = mptrace (XPT_MPDEBUGGER, 0, 0, 0); |
874 | if (-1 == rv) | |
875 | { | |
876 | fatal ("_initialize_symm_nat(): mptrace(XPT_MPDEBUGGER): %s", | |
877 | safe_strerror (errno)); | |
878 | } | |
c906108c | 879 | |
c5aa993b JM |
880 | /* |
881 | * Under MPDEBUGGER, we get SIGCLHD when a traced process does | |
882 | * anything of interest. | |
883 | */ | |
884 | ||
885 | /* | |
886 | * Block SIGCHLD. We leave it blocked all the time, and then | |
887 | * call sigsuspend() in child_wait() to wait for the child | |
888 | * to do something. None of these ought to fail, but check anyway. | |
889 | */ | |
890 | sigemptyset (&set); | |
891 | rv = sigaddset (&set, SIGCHLD); | |
892 | if (-1 == rv) | |
893 | { | |
894 | fatal ("_initialize_symm_nat(): sigaddset(SIGCHLD): %s", | |
895 | safe_strerror (errno)); | |
896 | } | |
897 | rv = sigprocmask (SIG_BLOCK, &set, (sigset_t *) NULL); | |
898 | if (-1 == rv) | |
899 | { | |
900 | fatal ("_initialize_symm_nat(): sigprocmask(SIG_BLOCK): %s", | |
901 | safe_strerror (errno)); | |
902 | } | |
903 | ||
904 | sact.sa_handler = sigchld_handler; | |
905 | sigemptyset (&sact.sa_mask); | |
906 | sact.sa_flags = SA_NOCLDWAIT; /* keep the zombies away */ | |
907 | rv = sigaction (SIGCHLD, &sact, (struct sigaction *) NULL); | |
908 | if (-1 == rv) | |
909 | { | |
910 | fatal ("_initialize_symm_nat(): sigaction(SIGCHLD): %s", | |
911 | safe_strerror (errno)); | |
912 | } | |
c906108c SS |
913 | #endif |
914 | } |