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