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