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