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,
19 Boston, MA 02111-1307, USA. */
21 /* FIXME, some 387-specific items of use taken from i387-tdep.c -- ought to be
30 /* FIXME: What is the _INKERNEL define for? */
35 #include <sys/param.h>
39 #include <sys/ioctl.h>
42 #include <sys/ptrace.h>
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
51 #define TERMINAL struct sgttyb
56 store_inferior_registers (int 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
) & regs
, 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
) & regs
, 0);
95 fetch_inferior_registers (int regno
)
98 struct pt_regset regs
;
100 registers_fetched ();
102 mptrace (XPT_RREGS
, inferior_pid
, (PTRACE_ARG3_TYPE
) & regs
, 0);
103 *(int *) ®isters
[REGISTER_BYTE (EAX_REGNUM
)] = regs
.pr_eax
;
104 *(int *) ®isters
[REGISTER_BYTE (EBX_REGNUM
)] = regs
.pr_ebx
;
105 *(int *) ®isters
[REGISTER_BYTE (ECX_REGNUM
)] = regs
.pr_ecx
;
106 *(int *) ®isters
[REGISTER_BYTE (EDX_REGNUM
)] = regs
.pr_edx
;
107 *(int *) ®isters
[REGISTER_BYTE (ESI_REGNUM
)] = regs
.pr_esi
;
108 *(int *) ®isters
[REGISTER_BYTE (EDI_REGNUM
)] = regs
.pr_edi
;
109 *(int *) ®isters
[REGISTER_BYTE (EBP_REGNUM
)] = regs
.pr_ebp
;
110 *(int *) ®isters
[REGISTER_BYTE (ESP_REGNUM
)] = regs
.pr_esp
;
111 *(int *) ®isters
[REGISTER_BYTE (EIP_REGNUM
)] = regs
.pr_eip
;
112 *(int *) ®isters
[REGISTER_BYTE (EFLAGS_REGNUM
)] = regs
.pr_flags
;
113 for (i
= 0; i
< FPA_NREGS
; i
++)
115 *(int *) ®isters
[REGISTER_BYTE (FP1_REGNUM
+ i
)] =
116 regs
.pr_fpa
.fpa_regs
[i
];
118 memcpy (®isters
[REGISTER_BYTE (ST0_REGNUM
)], regs
.pr_fpu
.fpu_stack
[0], 10);
119 memcpy (®isters
[REGISTER_BYTE (ST1_REGNUM
)], regs
.pr_fpu
.fpu_stack
[1], 10);
120 memcpy (®isters
[REGISTER_BYTE (ST2_REGNUM
)], regs
.pr_fpu
.fpu_stack
[2], 10);
121 memcpy (®isters
[REGISTER_BYTE (ST3_REGNUM
)], regs
.pr_fpu
.fpu_stack
[3], 10);
122 memcpy (®isters
[REGISTER_BYTE (ST4_REGNUM
)], regs
.pr_fpu
.fpu_stack
[4], 10);
123 memcpy (®isters
[REGISTER_BYTE (ST5_REGNUM
)], regs
.pr_fpu
.fpu_stack
[5], 10);
124 memcpy (®isters
[REGISTER_BYTE (ST6_REGNUM
)], regs
.pr_fpu
.fpu_stack
[6], 10);
125 memcpy (®isters
[REGISTER_BYTE (ST7_REGNUM
)], regs
.pr_fpu
.fpu_stack
[7], 10);
128 /* FIXME: This should be merged with i387-tdep.c as well. */
130 print_fpu_status (struct pt_regset ep
)
138 printf_unfiltered ("80387:");
139 if (ep
.pr_fpu
.fpu_ip
== 0)
141 printf_unfiltered (" not in use.\n");
146 printf_unfiltered ("\n");
148 if (ep
.pr_fpu
.fpu_status
!= 0)
150 print_387_status_word (ep
.pr_fpu
.fpu_status
);
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
);
158 top
= (ep
.pr_fpu
.fpu_status
>> 11) & 7;
160 printf_unfiltered ("regno tag msb lsb value\n");
161 for (fpreg
= 7; fpreg
>= 0; fpreg
--)
165 printf_unfiltered ("%s %d: ", fpreg
== top
? "=>" : " ", fpreg
);
167 switch ((ep
.pr_fpu
.fpu_tag
>> (fpreg
* 2)) & 3)
170 printf_unfiltered ("valid ");
173 printf_unfiltered ("zero ");
176 printf_unfiltered ("trap ");
179 printf_unfiltered ("empty ");
182 for (i
= 9; i
>= 0; i
--)
183 printf_unfiltered ("%02x", ep
.pr_fpu
.fpu_stack
[fpreg
][i
]);
185 i387_to_double ((char *) ep
.pr_fpu
.fpu_stack
[fpreg
], (char *) &val
);
186 printf_unfiltered (" %g\n", val
);
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
);
199 print_1167_control_word (unsigned int pcr
)
203 pcr_tmp
= pcr
& FPA_PCR_MODE
;
204 printf_unfiltered ("\tMODE= %#x; RND= %#x ", pcr_tmp
, pcr_tmp
& 12);
205 switch (pcr_tmp
& 12)
208 printf_unfiltered ("RN (Nearest Value)");
211 printf_unfiltered ("RZ (Zero)");
214 printf_unfiltered ("RP (Positive Infinity)");
217 printf_unfiltered ("RM (Negative Infinity)");
220 printf_unfiltered ("; IRND= %d ", pcr_tmp
& 2);
221 if (0 == pcr_tmp
& 2)
223 printf_unfiltered ("(same as RND)\n");
227 printf_unfiltered ("(toward zero)\n");
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");
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. */
259 if (pcr_tmp
& FPA_PCR_CC_C1
)
260 printf_unfiltered (" C1");
262 if (pcr_tmp
& FPA_PCR_CC_C0
)
263 printf_unfiltered (" C0");
269 printf_unfiltered (" (Equal)");
276 printf_unfiltered (" (Less than)");
279 printf_unfiltered (" (Greater than)");
288 printf_unfiltered (" (Unordered)");
291 printf_unfiltered (" (Undefined)");
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");
316 print_1167_regs (regs
)
317 long regs
[FPA_NREGS
];
336 for (i
= 0; i
< FPA_NREGS
; i
++)
339 printf_unfiltered ("%%fp%d: raw= %#x, single= %f", i
+ 1, regs
[i
], xf
.f
);
342 printf_unfiltered ("\n");
347 xd
.l
[0] = regs
[i
+ 1];
348 printf_unfiltered (", double= %f\n", xd
.d
);
353 print_fpa_status (struct pt_regset ep
)
356 printf_unfiltered ("WTL 1167:");
357 if (ep
.pr_fpa
.fpa_pcr
!= 0)
359 printf_unfiltered ("\n");
360 print_1167_control_word (ep
.pr_fpa
.fpa_pcr
);
361 print_1167_regs (ep
.pr_fpa
.fpa_regs
);
365 printf_unfiltered (" not in use.\n");
369 #if 0 /* disabled because it doesn't go through the target vector. */
370 i386_float_info (void)
372 char ubuf
[UPAGES
* NBPG
];
373 struct pt_regset regset
;
375 if (have_inferior_p ())
377 PTRACE_READ_REGS (inferior_pid
, (PTRACE_ARG3_TYPE
) & regset
);
381 int corechan
= bfd_cache_lookup (core_bfd
);
382 if (lseek (corechan
, 0, 0) < 0)
384 perror ("seek on core file");
386 if (myread (corechan
, ubuf
, UPAGES
* NBPG
) < 0)
388 perror ("read on core file");
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
;
394 print_fpu_status (regset
);
395 print_fpa_status (regset
);
399 static volatile int got_sigchld
;
402 /* This will eventually be more interesting. */
404 sigchld_handler (int signo
)
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)
415 #define sigmask(s) (1 << ((s) - 1))
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)
424 * Thanks to XPT_MPDEBUGGER, we have to mange child_wait().
427 child_wait (int pid
, struct target_waitstatus
*status
)
429 int save_errno
, rv
, xvaloff
, saoff
, sa_hand
;
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 */
442 set_sigint_trap (); /* Causes SIGINT to be passed on to the
450 while (got_sigchld
== 0)
455 clear_sigint_trap ();
457 rv
= mptrace (XPT_STOPSTAT
, 0, (char *) &pt
, 0);
460 printf ("XPT_STOPSTAT: errno %d\n", errno
); /* DEBUG */
466 if (pid
!= inferior_pid
)
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.
472 /* inferior probably forked; send it on its way */
473 rv
= mptrace (XPT_UNDEBUG
, pid
, 0, 0);
476 printf ("child_wait: XPT_UNDEBUG: pid %d: %s\n", pid
,
477 safe_strerror (errno
));
481 /* FIXME: Do we deal with fork notification correctly? */
482 switch (pt
.ps_reason
)
485 /* multi proc: treat like PTS_EXEC */
487 * Pretend this didn't happen, since gdb isn't set up
488 * to deal with stops on fork.
490 rv
= ptrace (PT_CONTSIG
, pid
, 1, 0);
493 printf ("PTS_FORK: PT_CONTSIG: error %d\n", errno
);
498 * Pretend this is a SIGTRAP.
500 status
->kind
= TARGET_WAITKIND_STOPPED
;
501 status
->value
.sig
= TARGET_SIGNAL_TRAP
;
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.
514 status
->kind
= TARGET_WAITKIND_SIGNALED
;
515 status
->value
.sig
= target_signal_from_host (death_by_signal
);
519 xvaloff
= (unsigned long) &u
.u_ap
[0] - (unsigned long) &u
;
521 rv
= ptrace (PT_RUSER
, pid
, (char *) xvaloff
, 0);
522 status
->kind
= TARGET_WAITKIND_EXITED
;
523 status
->value
.integer
= rv
;
525 * addr & data to mptrace() don't matter here, since
526 * the process is already dead.
528 rv
= mptrace (XPT_UNDEBUG
, pid
, 0, 0);
531 printf ("child_wait: PTS_EXIT: XPT_UNDEBUG: pid %d error %d\n", pid
,
535 case PTS_WATCHPT_HIT
:
536 internal_error ("PTS_WATCHPT_HIT\n");
539 /* stopped by signal */
540 status
->kind
= TARGET_WAITKIND_STOPPED
;
541 status
->value
.sig
= target_signal_from_host (pt
.ps_reason
);
544 if (0 == (SIGNALS_DFL_SAFE
& sigmask (pt
.ps_reason
)))
548 /* else default action of signal is to die */
549 #ifdef SVR4_SHARED_LIBS
550 rv
= ptrace (PT_GET_PRSTATUS
, pid
, (char *) &pstatus
, 0);
552 error ("child_wait: signal %d PT_GET_PRSTATUS: %s\n",
553 pt
.ps_reason
, safe_strerror (errno
));
554 if (pstatus
.pr_cursig
!= pt
.ps_reason
)
556 printf ("pstatus signal %d, pt signal %d\n",
557 pstatus
.pr_cursig
, pt
.ps_reason
);
559 sa_hand
= (int) pstatus
.pr_action
.sa_handler
;
561 saoff
= (unsigned long) &u
.u_sa
[0] - (unsigned long) &u
;
562 saoff
+= sizeof (struct sigaction
) * (pt
.ps_reason
- 1);
564 sa_hand
= ptrace (PT_RUSER
, pid
, (char *) saoff
, 0);
566 error ("child_wait: signal %d: RUSER: %s\n",
567 pt
.ps_reason
, safe_strerror (errno
));
569 if ((int) SIG_DFL
== sa_hand
)
571 /* we will be dying */
572 death_by_signal
= pt
.ps_reason
;
578 while (pid
!= inferior_pid
); /* Some other child died or stopped */
582 #else /* !ATTACH_DETACH */
584 * Simple child_wait() based on inftarg.c child_wait() for use until
585 * the MPDEBUGGER child_wait() works properly. This will go away when
588 child_wait (int pid
, struct target_waitstatus
*ourstatus
)
595 pid
= wait (&status
);
600 if (save_errno
== EINTR
)
602 fprintf (stderr
, "Child process unexpectedly missing: %s.\n",
603 safe_strerror (save_errno
));
604 ourstatus
->kind
= TARGET_WAITKIND_SIGNALLED
;
605 ourstatus
->value
.sig
= TARGET_SIGNAL_UNKNOWN
;
609 while (pid
!= inferior_pid
); /* Some other child died or stopped */
610 store_waitstatus (ourstatus
, status
);
613 #endif /* ATTACH_DETACH */
617 /* This function simply calls ptrace with the given arguments.
618 It exists so that all calls to ptrace are isolated in this
619 machine-dependent file. */
621 call_ptrace (int request
, int pid
, PTRACE_ARG3_TYPE addr
, int data
)
623 return ptrace (request
, pid
, addr
, data
);
627 call_mptrace (int request
, int pid
, PTRACE_ARG3_TYPE addr
, int data
)
629 return mptrace (request
, pid
, addr
, data
);
632 #if defined (DEBUG_PTRACE)
633 /* For the rest of the file, use an extra level of indirection */
634 /* This lets us breakpoint usefully on call_ptrace. */
635 #define ptrace call_ptrace
636 #define mptrace call_mptrace
642 if (inferior_pid
== 0)
645 /* For MPDEBUGGER, don't use PT_KILL, since the child will stop
646 again with a PTS_EXIT. Just hit him with SIGKILL (so he stops)
649 kill (inferior_pid
, SIGKILL
);
652 #else /* ATTACH_DETACH */
653 ptrace (PT_KILL
, inferior_pid
, 0, 0);
655 #endif /* ATTACH_DETACH */
656 target_mourn_inferior ();
659 /* Resume execution of the inferior process.
660 If STEP is nonzero, single-step it.
661 If SIGNAL is nonzero, give it that signal. */
664 child_resume (int pid
, int step
, enum target_signal signal
)
671 /* An address of (PTRACE_ARG3_TYPE)1 tells ptrace to continue from where
672 it was. (If GDB wanted it to start some other way, we have already
673 written a new PC value to the child.)
675 If this system does not support PT_SSTEP, a higher level function will
676 have called single_step() to transmute the step request into a
677 continue request (by setting breakpoints on all possible successor
678 instructions), so we don't have to worry about that here. */
681 ptrace (PT_SSTEP
, pid
, (PTRACE_ARG3_TYPE
) 1, signal
);
683 ptrace (PT_CONTSIG
, pid
, (PTRACE_ARG3_TYPE
) 1, signal
);
686 perror_with_name ("ptrace");
690 /* Start debugging the process whose number is PID. */
697 rv
= mptrace (XPT_DEBUG
, pid
, 0, 0);
700 error ("mptrace(XPT_DEBUG): %s", safe_strerror (errno
));
702 rv
= mptrace (XPT_SIGNAL
, pid
, 0, SIGSTOP
);
705 error ("mptrace(XPT_SIGNAL): %s", safe_strerror (errno
));
716 rv
= mptrace (XPT_UNDEBUG
, inferior_pid
, 1, signo
);
719 error ("mptrace(XPT_UNDEBUG): %s", safe_strerror (errno
));
724 #endif /* ATTACH_DETACH */
726 /* Default the type of the ptrace transfer to int. */
727 #ifndef PTRACE_XFER_TYPE
728 #define PTRACE_XFER_TYPE int
732 /* NOTE! I tried using PTRACE_READDATA, etc., to read and write memory
733 in the NEW_SUN_PTRACE case.
734 It ought to be straightforward. But it appears that writing did
735 not write the data that I specified. I cannot understand where
736 it got the data that it actually did write. */
738 /* Copy LEN bytes to or from inferior's memory starting at MEMADDR
739 to debugger memory starting at MYADDR. Copy to inferior if
742 Returns the length copied, which is either the LEN argument or zero.
743 This xfer function does not do partial moves, since child_ops
744 doesn't allow memory operations to cross below us in the target stack
748 child_xfer_memory (memaddr
, myaddr
, len
, write
, target
)
753 struct target_ops
*target
; /* ignored */
756 /* Round starting address down to longword boundary. */
757 register CORE_ADDR addr
= memaddr
& -sizeof (PTRACE_XFER_TYPE
);
758 /* Round ending address up; get number of longwords that makes. */
760 = (((memaddr
+ len
) - addr
) + sizeof (PTRACE_XFER_TYPE
) - 1)
761 / sizeof (PTRACE_XFER_TYPE
);
762 /* Allocate buffer of that many longwords. */
763 register PTRACE_XFER_TYPE
*buffer
764 = (PTRACE_XFER_TYPE
*) alloca (count
* sizeof (PTRACE_XFER_TYPE
));
768 /* Fill start and end extra bytes of buffer with existing memory data. */
770 if (addr
!= memaddr
|| len
< (int) sizeof (PTRACE_XFER_TYPE
))
772 /* Need part of initial word -- fetch it. */
773 buffer
[0] = ptrace (PT_RTEXT
, inferior_pid
, (PTRACE_ARG3_TYPE
) addr
,
777 if (count
> 1) /* FIXME, avoid if even boundary */
780 = ptrace (PT_RTEXT
, inferior_pid
,
782 (addr
+ (count
- 1) * sizeof (PTRACE_XFER_TYPE
))),
786 /* Copy data to be written over corresponding part of buffer */
788 memcpy ((char *) buffer
+ (memaddr
& (sizeof (PTRACE_XFER_TYPE
) - 1)),
792 /* Write the entire buffer. */
794 for (i
= 0; i
< count
; i
++, addr
+= sizeof (PTRACE_XFER_TYPE
))
797 ptrace (PT_WDATA
, inferior_pid
, (PTRACE_ARG3_TYPE
) addr
,
801 /* Using the appropriate one (I or D) is necessary for
802 Gould NP1, at least. */
804 ptrace (PT_WTEXT
, inferior_pid
, (PTRACE_ARG3_TYPE
) addr
,
813 /* Read all the longwords */
814 for (i
= 0; i
< count
; i
++, addr
+= sizeof (PTRACE_XFER_TYPE
))
817 buffer
[i
] = ptrace (PT_RTEXT
, inferior_pid
,
818 (PTRACE_ARG3_TYPE
) addr
, 0);
824 /* Copy appropriate bytes out of the buffer. */
826 (char *) buffer
+ (memaddr
& (sizeof (PTRACE_XFER_TYPE
) - 1)),
834 _initialize_symm_nat (void)
838 * the MPDEBUGGER is necessary for process tree debugging and attach
839 * to work, but it alters the behavior of debugged processes, so other
840 * things (at least child_wait()) will have to change to accomodate
843 * Note that attach is not implemented in dynix 3, and not in ptx
844 * until version 2.1 of the OS.
848 struct sigaction sact
;
850 rv
= mptrace (XPT_MPDEBUGGER
, 0, 0, 0);
853 internal_error ("_initialize_symm_nat(): mptrace(XPT_MPDEBUGGER): %s",
854 safe_strerror (errno
));
858 * Under MPDEBUGGER, we get SIGCLHD when a traced process does
859 * anything of interest.
863 * Block SIGCHLD. We leave it blocked all the time, and then
864 * call sigsuspend() in child_wait() to wait for the child
865 * to do something. None of these ought to fail, but check anyway.
868 rv
= sigaddset (&set
, SIGCHLD
);
871 internal_error ("_initialize_symm_nat(): sigaddset(SIGCHLD): %s",
872 safe_strerror (errno
));
874 rv
= sigprocmask (SIG_BLOCK
, &set
, (sigset_t
*) NULL
);
877 internal_error ("_initialize_symm_nat(): sigprocmask(SIG_BLOCK): %s",
878 safe_strerror (errno
));
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
);
887 internal_error ("_initialize_symm_nat(): sigaction(SIGCHLD): %s",
888 safe_strerror (errno
));