1 /* Sequent Symmetry host interface, for GDB when running under Unix.
2 Copyright 1986, 1987, 1989, 1991, 1992, 1994 Free Software Foundation, Inc.
4 This file is part of GDB.
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.
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.
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, Boston, MA 02111-1307, USA. */
20 /* FIXME, some 387-specific items of use taken from i387-tdep.c -- ought to be
29 /* FIXME: What is the _INKERNEL define for? */
34 #include <sys/param.h>
38 #include <sys/ioctl.h>
41 #include <sys/ptrace.h>
43 /* Dynix has only machine/ptrace.h, which is already included by sys/user.h */
44 /* Dynix has no mptrace call */
45 #define mptrace ptrace
50 #define TERMINAL struct sgttyb
55 store_inferior_registers(regno
)
58 struct pt_regset regs
;
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. */
66 mptrace (XPT_RREGS
, inferior_pid
, (PTRACE_ARG3_TYPE
) ®s
, 0);
68 regs
.pr_eax
= *(int *)®isters
[REGISTER_BYTE(0)];
69 regs
.pr_ebx
= *(int *)®isters
[REGISTER_BYTE(5)];
70 regs
.pr_ecx
= *(int *)®isters
[REGISTER_BYTE(2)];
71 regs
.pr_edx
= *(int *)®isters
[REGISTER_BYTE(1)];
72 regs
.pr_esi
= *(int *)®isters
[REGISTER_BYTE(6)];
73 regs
.pr_edi
= *(int *)®isters
[REGISTER_BYTE(7)];
74 regs
.pr_esp
= *(int *)®isters
[REGISTER_BYTE(14)];
75 regs
.pr_ebp
= *(int *)®isters
[REGISTER_BYTE(15)];
76 regs
.pr_eip
= *(int *)®isters
[REGISTER_BYTE(16)];
77 regs
.pr_flags
= *(int *)®isters
[REGISTER_BYTE(17)];
78 for (i
= 0; i
< 31; i
++)
80 regs
.pr_fpa
.fpa_regs
[i
] =
81 *(int *)®isters
[REGISTER_BYTE(FP1_REGNUM
+i
)];
83 memcpy (regs
.pr_fpu
.fpu_stack
[0], ®isters
[REGISTER_BYTE(ST0_REGNUM
)], 10);
84 memcpy (regs
.pr_fpu
.fpu_stack
[1], ®isters
[REGISTER_BYTE(ST1_REGNUM
)], 10);
85 memcpy (regs
.pr_fpu
.fpu_stack
[2], ®isters
[REGISTER_BYTE(ST2_REGNUM
)], 10);
86 memcpy (regs
.pr_fpu
.fpu_stack
[3], ®isters
[REGISTER_BYTE(ST3_REGNUM
)], 10);
87 memcpy (regs
.pr_fpu
.fpu_stack
[4], ®isters
[REGISTER_BYTE(ST4_REGNUM
)], 10);
88 memcpy (regs
.pr_fpu
.fpu_stack
[5], ®isters
[REGISTER_BYTE(ST5_REGNUM
)], 10);
89 memcpy (regs
.pr_fpu
.fpu_stack
[6], ®isters
[REGISTER_BYTE(ST6_REGNUM
)], 10);
90 memcpy (regs
.pr_fpu
.fpu_stack
[7], ®isters
[REGISTER_BYTE(ST7_REGNUM
)], 10);
91 mptrace (XPT_WREGS
, inferior_pid
, (PTRACE_ARG3_TYPE
) ®s
, 0);
95 fetch_inferior_registers (regno
)
99 struct pt_regset regs
;
101 registers_fetched ();
103 mptrace (XPT_RREGS
, inferior_pid
, (PTRACE_ARG3_TYPE
) ®s
, 0);
104 *(int *)®isters
[REGISTER_BYTE(EAX_REGNUM
)] = regs
.pr_eax
;
105 *(int *)®isters
[REGISTER_BYTE(EBX_REGNUM
)] = regs
.pr_ebx
;
106 *(int *)®isters
[REGISTER_BYTE(ECX_REGNUM
)] = regs
.pr_ecx
;
107 *(int *)®isters
[REGISTER_BYTE(EDX_REGNUM
)] = regs
.pr_edx
;
108 *(int *)®isters
[REGISTER_BYTE(ESI_REGNUM
)] = regs
.pr_esi
;
109 *(int *)®isters
[REGISTER_BYTE(EDI_REGNUM
)] = regs
.pr_edi
;
110 *(int *)®isters
[REGISTER_BYTE(EBP_REGNUM
)] = regs
.pr_ebp
;
111 *(int *)®isters
[REGISTER_BYTE(ESP_REGNUM
)] = regs
.pr_esp
;
112 *(int *)®isters
[REGISTER_BYTE(EIP_REGNUM
)] = regs
.pr_eip
;
113 *(int *)®isters
[REGISTER_BYTE(EFLAGS_REGNUM
)] = regs
.pr_flags
;
114 for (i
= 0; i
< FPA_NREGS
; i
++)
116 *(int *)®isters
[REGISTER_BYTE(FP1_REGNUM
+i
)] =
117 regs
.pr_fpa
.fpa_regs
[i
];
119 memcpy (®isters
[REGISTER_BYTE(ST0_REGNUM
)], regs
.pr_fpu
.fpu_stack
[0], 10);
120 memcpy (®isters
[REGISTER_BYTE(ST1_REGNUM
)], regs
.pr_fpu
.fpu_stack
[1], 10);
121 memcpy (®isters
[REGISTER_BYTE(ST2_REGNUM
)], regs
.pr_fpu
.fpu_stack
[2], 10);
122 memcpy (®isters
[REGISTER_BYTE(ST3_REGNUM
)], regs
.pr_fpu
.fpu_stack
[3], 10);
123 memcpy (®isters
[REGISTER_BYTE(ST4_REGNUM
)], regs
.pr_fpu
.fpu_stack
[4], 10);
124 memcpy (®isters
[REGISTER_BYTE(ST5_REGNUM
)], regs
.pr_fpu
.fpu_stack
[5], 10);
125 memcpy (®isters
[REGISTER_BYTE(ST6_REGNUM
)], regs
.pr_fpu
.fpu_stack
[6], 10);
126 memcpy (®isters
[REGISTER_BYTE(ST7_REGNUM
)], regs
.pr_fpu
.fpu_stack
[7], 10);
129 /* FIXME: This should be merged with i387-tdep.c as well. */
140 printf_unfiltered("80387:");
141 if (ep
.pr_fpu
.fpu_ip
== 0) {
142 printf_unfiltered(" not in use.\n");
145 printf_unfiltered("\n");
147 if (ep
.pr_fpu
.fpu_status
!= 0) {
148 print_387_status_word (ep
.pr_fpu
.fpu_status
);
150 print_387_control_word (ep
.pr_fpu
.fpu_control
);
151 printf_unfiltered ("last exception: ");
152 printf_unfiltered ("opcode 0x%x; ", ep
.pr_fpu
.fpu_rsvd4
);
153 printf_unfiltered ("pc 0x%x:0x%x; ", ep
.pr_fpu
.fpu_cs
, ep
.pr_fpu
.fpu_ip
);
154 printf_unfiltered ("operand 0x%x:0x%x\n", ep
.pr_fpu
.fpu_data_offset
, ep
.pr_fpu
.fpu_op_sel
);
156 top
= (ep
.pr_fpu
.fpu_status
>> 11) & 7;
158 printf_unfiltered ("regno tag msb lsb value\n");
159 for (fpreg
= 7; fpreg
>= 0; fpreg
--)
163 printf_unfiltered ("%s %d: ", fpreg
== top
? "=>" : " ", fpreg
);
165 switch ((ep
.pr_fpu
.fpu_tag
>> (fpreg
* 2)) & 3)
167 case 0: printf_unfiltered ("valid "); break;
168 case 1: printf_unfiltered ("zero "); break;
169 case 2: printf_unfiltered ("trap "); break;
170 case 3: printf_unfiltered ("empty "); break;
172 for (i
= 9; i
>= 0; i
--)
173 printf_unfiltered ("%02x", ep
.pr_fpu
.fpu_stack
[fpreg
][i
]);
175 i387_to_double ((char *)ep
.pr_fpu
.fpu_stack
[fpreg
], (char *)&val
);
176 printf_unfiltered (" %g\n", val
);
178 if (ep
.pr_fpu
.fpu_rsvd1
)
179 warning ("rsvd1 is 0x%x\n", ep
.pr_fpu
.fpu_rsvd1
);
180 if (ep
.pr_fpu
.fpu_rsvd2
)
181 warning ("rsvd2 is 0x%x\n", ep
.pr_fpu
.fpu_rsvd2
);
182 if (ep
.pr_fpu
.fpu_rsvd3
)
183 warning ("rsvd3 is 0x%x\n", ep
.pr_fpu
.fpu_rsvd3
);
184 if (ep
.pr_fpu
.fpu_rsvd5
)
185 warning ("rsvd5 is 0x%x\n", ep
.pr_fpu
.fpu_rsvd5
);
189 print_1167_control_word(pcr
)
195 pcr_tmp
= pcr
& FPA_PCR_MODE
;
196 printf_unfiltered("\tMODE= %#x; RND= %#x ", pcr_tmp
, pcr_tmp
& 12);
197 switch (pcr_tmp
& 12) {
199 printf_unfiltered("RN (Nearest Value)");
202 printf_unfiltered("RZ (Zero)");
205 printf_unfiltered("RP (Positive Infinity)");
208 printf_unfiltered("RM (Negative Infinity)");
211 printf_unfiltered("; IRND= %d ", pcr_tmp
& 2);
212 if (0 == pcr_tmp
& 2) {
213 printf_unfiltered("(same as RND)\n");
215 printf_unfiltered("(toward zero)\n");
217 pcr_tmp
= pcr
& FPA_PCR_EM
;
218 printf_unfiltered("\tEM= %#x", pcr_tmp
);
219 if (pcr_tmp
& FPA_PCR_EM_DM
) printf_unfiltered(" DM");
220 if (pcr_tmp
& FPA_PCR_EM_UOM
) printf_unfiltered(" UOM");
221 if (pcr_tmp
& FPA_PCR_EM_PM
) printf_unfiltered(" PM");
222 if (pcr_tmp
& FPA_PCR_EM_UM
) printf_unfiltered(" UM");
223 if (pcr_tmp
& FPA_PCR_EM_OM
) printf_unfiltered(" OM");
224 if (pcr_tmp
& FPA_PCR_EM_ZM
) printf_unfiltered(" ZM");
225 if (pcr_tmp
& FPA_PCR_EM_IM
) printf_unfiltered(" IM");
226 printf_unfiltered("\n");
227 pcr_tmp
= FPA_PCR_CC
;
228 printf_unfiltered("\tCC= %#x", pcr_tmp
);
229 if (pcr_tmp
& FPA_PCR_20MHZ
) printf_unfiltered(" 20MHZ");
230 if (pcr_tmp
& FPA_PCR_CC_Z
) printf_unfiltered(" Z");
231 if (pcr_tmp
& FPA_PCR_CC_C2
) printf_unfiltered(" C2");
233 /* Dynix defines FPA_PCR_CC_C0 to 0x100 and ptx defines
234 FPA_PCR_CC_C1 to 0x100. Use whichever is defined and assume
235 the OS knows what it is doing. */
237 if (pcr_tmp
& FPA_PCR_CC_C1
) printf_unfiltered(" C1");
239 if (pcr_tmp
& FPA_PCR_CC_C0
) printf_unfiltered(" C0");
245 printf_unfiltered(" (Equal)");
252 printf_unfiltered(" (Less than)");
255 printf_unfiltered(" (Greater than)");
264 printf_unfiltered(" (Unordered)");
267 printf_unfiltered(" (Undefined)");
270 printf_unfiltered("\n");
271 pcr_tmp
= pcr
& FPA_PCR_AE
;
272 printf_unfiltered("\tAE= %#x", pcr_tmp
);
273 if (pcr_tmp
& FPA_PCR_AE_DE
) printf_unfiltered(" DE");
274 if (pcr_tmp
& FPA_PCR_AE_UOE
) printf_unfiltered(" UOE");
275 if (pcr_tmp
& FPA_PCR_AE_PE
) printf_unfiltered(" PE");
276 if (pcr_tmp
& FPA_PCR_AE_UE
) printf_unfiltered(" UE");
277 if (pcr_tmp
& FPA_PCR_AE_OE
) printf_unfiltered(" OE");
278 if (pcr_tmp
& FPA_PCR_AE_ZE
) printf_unfiltered(" ZE");
279 if (pcr_tmp
& FPA_PCR_AE_EE
) printf_unfiltered(" EE");
280 if (pcr_tmp
& FPA_PCR_AE_IE
) printf_unfiltered(" IE");
281 printf_unfiltered("\n");
284 print_1167_regs(regs
)
285 long regs
[FPA_NREGS
];
300 for (i
= 0; i
< FPA_NREGS
; i
++) {
302 printf_unfiltered("%%fp%d: raw= %#x, single= %f", i
+1, regs
[i
], xf
.f
);
304 printf_unfiltered("\n");
308 printf_unfiltered(", double= %f\n", xd
.d
);
318 printf_unfiltered("WTL 1167:");
319 if (ep
.pr_fpa
.fpa_pcr
!=0) {
320 printf_unfiltered("\n");
321 print_1167_control_word(ep
.pr_fpa
.fpa_pcr
);
322 print_1167_regs(ep
.pr_fpa
.fpa_regs
);
324 printf_unfiltered(" not in use.\n");
328 #if 0 /* disabled because it doesn't go through the target vector. */
331 char ubuf
[UPAGES
*NBPG
];
332 struct pt_regset regset
;
334 if (have_inferior_p())
336 PTRACE_READ_REGS (inferior_pid
, (PTRACE_ARG3_TYPE
) ®set
);
340 int corechan
= bfd_cache_lookup (core_bfd
);
341 if (lseek (corechan
, 0, 0) < 0)
343 perror ("seek on core file");
345 if (myread (corechan
, ubuf
, UPAGES
*NBPG
) < 0)
347 perror ("read on core file");
349 /* only interested in the floating point registers */
350 regset
.pr_fpu
= ((struct user
*) ubuf
)->u_fpusave
;
351 regset
.pr_fpa
= ((struct user
*) ubuf
)->u_fpasave
;
353 print_fpu_status(regset
);
354 print_fpa_status(regset
);
358 static volatile int got_sigchld
;
361 /* This will eventually be more interesting. */
363 sigchld_handler(signo
)
370 * Signals for which the default action does not cause the process
371 * to die. See <sys/signal.h> for where this came from (alas, we
372 * can't use those macros directly)
375 #define sigmask(s) (1 << ((s) - 1))
377 #define SIGNALS_DFL_SAFE sigmask(SIGSTOP) | sigmask(SIGTSTP) | \
378 sigmask(SIGTTIN) | sigmask(SIGTTOU) | sigmask(SIGCHLD) | \
379 sigmask(SIGCONT) | sigmask(SIGWINCH) | sigmask(SIGPWR) | \
380 sigmask(SIGURG) | sigmask(SIGPOLL)
384 * Thanks to XPT_MPDEBUGGER, we have to mange child_wait().
387 child_wait(pid
, status
)
389 struct target_waitstatus
*status
;
391 int save_errno
, rv
, xvaloff
, saoff
, sa_hand
;
395 /* Host signal number for a signal which the inferior terminates with, or
396 0 if it hasn't terminated due to a signal. */
397 static int death_by_signal
= 0;
398 #ifdef SVR4_SHARED_LIBS /* use this to distinguish ptx 2 vs ptx 4 */
403 set_sigint_trap(); /* Causes SIGINT to be passed on to the
411 while (got_sigchld
== 0) {
417 rv
= mptrace(XPT_STOPSTAT
, 0, (char *)&pt
, 0);
419 printf("XPT_STOPSTAT: errno %d\n", errno
); /* DEBUG */
425 if (pid
!= inferior_pid
) {
426 /* NOTE: the mystery fork in csh/tcsh needs to be ignored.
427 * We should not return new children for the initial run
428 * of a process until it has done the exec.
430 /* inferior probably forked; send it on its way */
431 rv
= mptrace(XPT_UNDEBUG
, pid
, 0, 0);
433 printf("child_wait: XPT_UNDEBUG: pid %d: %s\n", pid
,
434 safe_strerror(errno
));
438 /* FIXME: Do we deal with fork notification correctly? */
439 switch (pt
.ps_reason
) {
441 /* multi proc: treat like PTS_EXEC */
443 * Pretend this didn't happen, since gdb isn't set up
444 * to deal with stops on fork.
446 rv
= ptrace(PT_CONTSIG
, pid
, 1, 0);
448 printf("PTS_FORK: PT_CONTSIG: error %d\n", errno
);
453 * Pretend this is a SIGTRAP.
455 status
->kind
= TARGET_WAITKIND_STOPPED
;
456 status
->value
.sig
= TARGET_SIGNAL_TRAP
;
460 * Note: we stop before the exit actually occurs. Extract
461 * the exit code from the uarea. If we're stopped in the
462 * exit() system call, the exit code will be in
463 * u.u_ap[0]. An exit due to an uncaught signal will have
464 * something else in here, see the comment in the default:
465 * case, below. Finally,let the process exit.
469 status
->kind
= TARGET_WAITKIND_SIGNALED
;
470 status
->value
.sig
= target_signal_from_host (death_by_signal
);
474 xvaloff
= (unsigned long)&u
.u_ap
[0] - (unsigned long)&u
;
476 rv
= ptrace(PT_RUSER
, pid
, (char *)xvaloff
, 0);
477 status
->kind
= TARGET_WAITKIND_EXITED
;
478 status
->value
.integer
= rv
;
480 * addr & data to mptrace() don't matter here, since
481 * the process is already dead.
483 rv
= mptrace(XPT_UNDEBUG
, pid
, 0, 0);
485 printf("child_wait: PTS_EXIT: XPT_UNDEBUG: pid %d error %d\n", pid
,
489 case PTS_WATCHPT_HIT
:
490 fatal("PTS_WATCHPT_HIT\n");
493 /* stopped by signal */
494 status
->kind
= TARGET_WAITKIND_STOPPED
;
495 status
->value
.sig
= target_signal_from_host (pt
.ps_reason
);
498 if (0 == (SIGNALS_DFL_SAFE
& sigmask(pt
.ps_reason
))) {
501 /* else default action of signal is to die */
502 #ifdef SVR4_SHARED_LIBS
503 rv
= ptrace(PT_GET_PRSTATUS
, pid
, (char *)&pstatus
, 0);
505 error("child_wait: signal %d PT_GET_PRSTATUS: %s\n",
506 pt
.ps_reason
, safe_strerror(errno
));
507 if (pstatus
.pr_cursig
!= pt
.ps_reason
) {
508 printf("pstatus signal %d, pt signal %d\n",
509 pstatus
.pr_cursig
, pt
.ps_reason
);
511 sa_hand
= (int)pstatus
.pr_action
.sa_handler
;
513 saoff
= (unsigned long)&u
.u_sa
[0] - (unsigned long)&u
;
514 saoff
+= sizeof(struct sigaction
) * (pt
.ps_reason
- 1);
516 sa_hand
= ptrace(PT_RUSER
, pid
, (char *)saoff
, 0);
518 error("child_wait: signal %d: RUSER: %s\n",
519 pt
.ps_reason
, safe_strerror(errno
));
521 if ((int)SIG_DFL
== sa_hand
) {
522 /* we will be dying */
523 death_by_signal
= pt
.ps_reason
;
528 } while (pid
!= inferior_pid
); /* Some other child died or stopped */
532 #else /* !ATTACH_DETACH */
534 * Simple child_wait() based on inftarg.c child_wait() for use until
535 * the MPDEBUGGER child_wait() works properly. This will go away when
538 child_wait (pid
, ourstatus
)
540 struct target_waitstatus
*ourstatus
;
546 pid
= wait (&status
);
551 if (save_errno
== EINTR
)
553 fprintf (stderr
, "Child process unexpectedly missing: %s.\n",
554 safe_strerror (save_errno
));
555 ourstatus
->kind
= TARGET_WAITKIND_SIGNALLED
;
556 ourstatus
->value
.sig
= TARGET_SIGNAL_UNKNOWN
;
559 } while (pid
!= inferior_pid
); /* Some other child died or stopped */
560 store_waitstatus (ourstatus
, status
);
563 #endif /* ATTACH_DETACH */
567 /* This function simply calls ptrace with the given arguments.
568 It exists so that all calls to ptrace are isolated in this
569 machine-dependent file. */
571 call_ptrace (request
, pid
, addr
, data
)
573 PTRACE_ARG3_TYPE addr
;
576 return ptrace (request
, pid
, addr
, data
);
580 call_mptrace(request
, pid
, addr
, data
)
582 PTRACE_ARG3_TYPE addr
;
585 return mptrace(request
, pid
, addr
, data
);
588 #if defined (DEBUG_PTRACE)
589 /* For the rest of the file, use an extra level of indirection */
590 /* This lets us breakpoint usefully on call_ptrace. */
591 #define ptrace call_ptrace
592 #define mptrace call_mptrace
598 if (inferior_pid
== 0)
601 /* For MPDEBUGGER, don't use PT_KILL, since the child will stop
602 again with a PTS_EXIT. Just hit him with SIGKILL (so he stops)
605 kill (inferior_pid
, SIGKILL
);
608 #else /* ATTACH_DETACH */
609 ptrace(PT_KILL
, inferior_pid
, 0, 0);
611 #endif /* ATTACH_DETACH */
612 target_mourn_inferior ();
615 /* Resume execution of the inferior process.
616 If STEP is nonzero, single-step it.
617 If SIGNAL is nonzero, give it that signal. */
620 child_resume (pid
, step
, signal
)
623 enum target_signal signal
;
630 /* An address of (PTRACE_ARG3_TYPE)1 tells ptrace to continue from where
631 it was. (If GDB wanted it to start some other way, we have already
632 written a new PC value to the child.)
634 If this system does not support PT_SSTEP, a higher level function will
635 have called single_step() to transmute the step request into a
636 continue request (by setting breakpoints on all possible successor
637 instructions), so we don't have to worry about that here. */
640 ptrace (PT_SSTEP
, pid
, (PTRACE_ARG3_TYPE
) 1, signal
);
642 ptrace (PT_CONTSIG
, pid
, (PTRACE_ARG3_TYPE
) 1, signal
);
645 perror_with_name ("ptrace");
649 /* Start debugging the process whose number is PID. */
657 rv
= mptrace(XPT_DEBUG
, pid
, 0, 0);
659 error("mptrace(XPT_DEBUG): %s", safe_strerror(errno
));
661 rv
= mptrace(XPT_SIGNAL
, pid
, 0, SIGSTOP
);
663 error("mptrace(XPT_SIGNAL): %s", safe_strerror(errno
));
675 rv
= mptrace(XPT_UNDEBUG
, inferior_pid
, 1, signo
);
677 error("mptrace(XPT_UNDEBUG): %s", safe_strerror(errno
));
682 #endif /* ATTACH_DETACH */
684 /* Default the type of the ptrace transfer to int. */
685 #ifndef PTRACE_XFER_TYPE
686 #define PTRACE_XFER_TYPE int
690 /* NOTE! I tried using PTRACE_READDATA, etc., to read and write memory
691 in the NEW_SUN_PTRACE case.
692 It ought to be straightforward. But it appears that writing did
693 not write the data that I specified. I cannot understand where
694 it got the data that it actually did write. */
696 /* Copy LEN bytes to or from inferior's memory starting at MEMADDR
697 to debugger memory starting at MYADDR. Copy to inferior if
700 Returns the length copied, which is either the LEN argument or zero.
701 This xfer function does not do partial moves, since child_ops
702 doesn't allow memory operations to cross below us in the target stack
706 child_xfer_memory (memaddr
, myaddr
, len
, write
, target
)
711 struct target_ops
*target
; /* ignored */
714 /* Round starting address down to longword boundary. */
715 register CORE_ADDR addr
= memaddr
& - sizeof (PTRACE_XFER_TYPE
);
716 /* Round ending address up; get number of longwords that makes. */
718 = (((memaddr
+ len
) - addr
) + sizeof (PTRACE_XFER_TYPE
) - 1)
719 / sizeof (PTRACE_XFER_TYPE
);
720 /* Allocate buffer of that many longwords. */
721 register PTRACE_XFER_TYPE
*buffer
722 = (PTRACE_XFER_TYPE
*) alloca (count
* sizeof (PTRACE_XFER_TYPE
));
726 /* Fill start and end extra bytes of buffer with existing memory data. */
728 if (addr
!= memaddr
|| len
< (int) sizeof (PTRACE_XFER_TYPE
)) {
729 /* Need part of initial word -- fetch it. */
730 buffer
[0] = ptrace (PT_RTEXT
, inferior_pid
, (PTRACE_ARG3_TYPE
) addr
,
734 if (count
> 1) /* FIXME, avoid if even boundary */
737 = ptrace (PT_RTEXT
, inferior_pid
,
739 (addr
+ (count
- 1) * sizeof (PTRACE_XFER_TYPE
))),
743 /* Copy data to be written over corresponding part of buffer */
745 memcpy ((char *) buffer
+ (memaddr
& (sizeof (PTRACE_XFER_TYPE
) - 1)),
749 /* Write the entire buffer. */
751 for (i
= 0; i
< count
; i
++, addr
+= sizeof (PTRACE_XFER_TYPE
))
754 ptrace (PT_WDATA
, inferior_pid
, (PTRACE_ARG3_TYPE
) addr
,
758 /* Using the appropriate one (I or D) is necessary for
759 Gould NP1, at least. */
761 ptrace (PT_WTEXT
, inferior_pid
, (PTRACE_ARG3_TYPE
) addr
,
770 /* Read all the longwords */
771 for (i
= 0; i
< count
; i
++, addr
+= sizeof (PTRACE_XFER_TYPE
))
774 buffer
[i
] = ptrace (PT_RTEXT
, inferior_pid
,
775 (PTRACE_ARG3_TYPE
) addr
, 0);
781 /* Copy appropriate bytes out of the buffer. */
783 (char *) buffer
+ (memaddr
& (sizeof (PTRACE_XFER_TYPE
) - 1)),
791 _initialize_symm_nat ()
795 * the MPDEBUGGER is necessary for process tree debugging and attach
796 * to work, but it alters the behavior of debugged processes, so other
797 * things (at least child_wait()) will have to change to accomodate
800 * Note that attach is not implemented in dynix 3, and not in ptx
801 * until version 2.1 of the OS.
805 struct sigaction sact
;
807 rv
= mptrace(XPT_MPDEBUGGER
, 0, 0, 0);
809 fatal("_initialize_symm_nat(): mptrace(XPT_MPDEBUGGER): %s",
810 safe_strerror(errno
));
814 * Under MPDEBUGGER, we get SIGCLHD when a traced process does
815 * anything of interest.
819 * Block SIGCHLD. We leave it blocked all the time, and then
820 * call sigsuspend() in child_wait() to wait for the child
821 * to do something. None of these ought to fail, but check anyway.
824 rv
= sigaddset(&set
, SIGCHLD
);
826 fatal("_initialize_symm_nat(): sigaddset(SIGCHLD): %s",
827 safe_strerror(errno
));
829 rv
= sigprocmask(SIG_BLOCK
, &set
, (sigset_t
*)NULL
);
831 fatal("_initialize_symm_nat(): sigprocmask(SIG_BLOCK): %s",
832 safe_strerror(errno
));
835 sact
.sa_handler
= sigchld_handler
;
836 sigemptyset(&sact
.sa_mask
);
837 sact
.sa_flags
= SA_NOCLDWAIT
; /* keep the zombies away */
838 rv
= sigaction(SIGCHLD
, &sact
, (struct sigaction
*)NULL
);
840 fatal("_initialize_symm_nat(): sigaction(SIGCHLD): %s",
841 safe_strerror(errno
));