1 /* Native support code for HPUX PA-RISC.
2 Copyright 1986, 1987, 1989, 1990, 1991, 1992, 1993, 1994, 1995, 1996,
4 Free Software Foundation, Inc.
6 Contributed by the Center for Software Science at the
7 University of Utah (pa-gdb-bugs@cs.utah.edu).
9 This file is part of GDB.
11 This program is free software; you can redistribute it and/or modify
12 it under the terms of the GNU General Public License as published by
13 the Free Software Foundation; either version 2 of the License, or
14 (at your option) any later version.
16 This program is distributed in the hope that it will be useful,
17 but WITHOUT ANY WARRANTY; without even the implied warranty of
18 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19 GNU General Public License for more details.
21 You should have received a copy of the GNU General Public License
22 along with this program; if not, write to the Free Software
23 Foundation, Inc., 59 Temple Place - Suite 330,
24 Boston, MA 02111-1307, USA. */
30 #include <sys/ptrace.h>
36 extern CORE_ADDR text_end
;
38 extern int hpux_has_forked (int pid
, int *childpid
);
39 extern int hpux_has_vforked (int pid
, int *childpid
);
40 extern int hpux_has_execd (int pid
, char **execd_pathname
);
41 extern int hpux_has_syscall_event (int pid
, enum target_waitkind
*kind
,
44 static void fetch_register (int);
47 fetch_inferior_registers (int regno
)
50 for (regno
= 0; regno
< NUM_REGS
; regno
++)
51 fetch_register (regno
);
53 fetch_register (regno
);
56 /* Our own version of the offsetof macro, since we can't assume ANSI C. */
57 #define HPPAH_OFFSETOF(type, member) ((int) (&((type *) 0)->member))
59 /* Store our register values back into the inferior.
60 If REGNO is -1, do this for all registers.
61 Otherwise, REGNO specifies which register (so we can save time). */
64 store_inferior_registers (int regno
)
66 register unsigned int regaddr
;
69 unsigned int offset
= U_REGS_OFFSET
;
74 unsigned int addr
, len
, offset
;
76 if (CANNOT_STORE_REGISTER (regno
))
80 len
= REGISTER_RAW_SIZE (regno
);
82 /* Requests for register zero actually want the save_state's
83 ss_flags member. As RM says: "Oh, what a hack!" */
87 addr
= HPPAH_OFFSETOF (save_state_t
, ss_flags
);
88 len
= sizeof (ss
.ss_flags
);
90 /* Note that ss_flags is always an int, no matter what
91 REGISTER_RAW_SIZE(0) says. Assuming all HP-UX PA machines
92 are big-endian, put it at the least significant end of the
93 value, and zap the rest of the buffer. */
94 offset
= REGISTER_RAW_SIZE (0) - len
;
97 /* Floating-point registers come from the ss_fpblock area. */
98 else if (regno
>= FP0_REGNUM
)
99 addr
= (HPPAH_OFFSETOF (save_state_t
, ss_fpblock
)
100 + (REGISTER_BYTE (regno
) - REGISTER_BYTE (FP0_REGNUM
)));
102 /* Wide registers come from the ss_wide area.
103 I think it's more PC to test (ss_flags & SS_WIDEREGS) to select
104 between ss_wide and ss_narrow than to use the raw register size.
105 But checking ss_flags would require an extra ptrace call for
106 every register reference. Bleah. */
108 addr
= (HPPAH_OFFSETOF (save_state_t
, ss_wide
)
109 + REGISTER_BYTE (regno
));
111 /* Narrow registers come from the ss_narrow area. Note that
112 ss_narrow starts with gr1, not gr0. */
114 addr
= (HPPAH_OFFSETOF (save_state_t
, ss_narrow
)
115 + (REGISTER_BYTE (regno
) - REGISTER_BYTE (1)));
117 internal_error (__FILE__
, __LINE__
,
118 "hppah-nat.c (write_register): unexpected register size");
120 #ifdef GDB_TARGET_IS_HPPA_20W
121 /* Unbelieveable. The PC head and tail must be written in 64bit hunks
122 or we will get an error. Worse yet, the oddball ptrace/ttrace
123 layering will not allow us to perform a 64bit register store.
126 if (regno
== PCOQ_HEAD_REGNUM
|| regno
== PCOQ_TAIL_REGNUM
&& len
== 8)
130 temp
= *(CORE_ADDR
*)&deprecated_registers
[REGISTER_BYTE (regno
)];
132 /* Set the priv level (stored in the low two bits of the PC. */
135 ttrace_write_reg_64 (PIDGET (inferior_ptid
), (CORE_ADDR
)addr
,
138 /* If we fail to write the PC, give a true error instead of
142 char *err
= safe_strerror (errno
);
143 char *msg
= alloca (strlen (err
) + 128);
144 sprintf (msg
, "writing `%s' register: %s",
145 REGISTER_NAME (regno
), err
);
146 perror_with_name (msg
);
151 /* Another crock. HPUX complains if you write a nonzero value to
152 the high part of IPSW. What will it take for HP to catch a
153 clue about building sensible interfaces? */
154 if (regno
== IPSW_REGNUM
&& len
== 8)
155 *(int *)&deprecated_registers
[REGISTER_BYTE (regno
)] = 0;
158 for (i
= 0; i
< len
; i
+= sizeof (int))
161 call_ptrace (PT_WUREGS
, PIDGET (inferior_ptid
),
162 (PTRACE_ARG3_TYPE
) addr
+ i
,
163 *(int *) &deprecated_registers
[REGISTER_BYTE (regno
) + i
]);
166 /* Warning, not error, in case we are attached; sometimes
167 the kernel doesn't let us at the registers. */
168 char *err
= safe_strerror (errno
);
169 char *msg
= alloca (strlen (err
) + 128);
170 sprintf (msg
, "writing `%s' register: %s",
171 REGISTER_NAME (regno
), err
);
172 /* If we fail to write the PC, give a true error instead of
174 if (regno
== PCOQ_HEAD_REGNUM
|| regno
== PCOQ_TAIL_REGNUM
)
175 perror_with_name (msg
);
183 for (regno
= 0; regno
< NUM_REGS
; regno
++)
184 store_inferior_registers (regno
);
188 /* Fetch a register's value from the process's U area. */
190 fetch_register (int regno
)
192 char buf
[MAX_REGISTER_RAW_SIZE
];
193 unsigned int addr
, len
, offset
;
197 len
= REGISTER_RAW_SIZE (regno
);
199 /* Requests for register zero actually want the save_state's
200 ss_flags member. As RM says: "Oh, what a hack!" */
204 addr
= HPPAH_OFFSETOF (save_state_t
, ss_flags
);
205 len
= sizeof (ss
.ss_flags
);
207 /* Note that ss_flags is always an int, no matter what
208 REGISTER_RAW_SIZE(0) says. Assuming all HP-UX PA machines
209 are big-endian, put it at the least significant end of the
210 value, and zap the rest of the buffer. */
211 offset
= REGISTER_RAW_SIZE (0) - len
;
212 memset (buf
, 0, sizeof (buf
));
215 /* Floating-point registers come from the ss_fpblock area. */
216 else if (regno
>= FP0_REGNUM
)
217 addr
= (HPPAH_OFFSETOF (save_state_t
, ss_fpblock
)
218 + (REGISTER_BYTE (regno
) - REGISTER_BYTE (FP0_REGNUM
)));
220 /* Wide registers come from the ss_wide area.
221 I think it's more PC to test (ss_flags & SS_WIDEREGS) to select
222 between ss_wide and ss_narrow than to use the raw register size.
223 But checking ss_flags would require an extra ptrace call for
224 every register reference. Bleah. */
226 addr
= (HPPAH_OFFSETOF (save_state_t
, ss_wide
)
227 + REGISTER_BYTE (regno
));
229 /* Narrow registers come from the ss_narrow area. Note that
230 ss_narrow starts with gr1, not gr0. */
232 addr
= (HPPAH_OFFSETOF (save_state_t
, ss_narrow
)
233 + (REGISTER_BYTE (regno
) - REGISTER_BYTE (1)));
236 internal_error (__FILE__
, __LINE__
,
237 "hppa-nat.c (fetch_register): unexpected register size");
239 for (i
= 0; i
< len
; i
+= sizeof (int))
242 /* Copy an int from the U area to buf. Fill the least
243 significant end if len != raw_size. */
244 * (int *) &buf
[offset
+ i
] =
245 call_ptrace (PT_RUREGS
, PIDGET (inferior_ptid
),
246 (PTRACE_ARG3_TYPE
) addr
+ i
, 0);
249 /* Warning, not error, in case we are attached; sometimes
250 the kernel doesn't let us at the registers. */
251 char *err
= safe_strerror (errno
);
252 char *msg
= alloca (strlen (err
) + 128);
253 sprintf (msg
, "reading `%s' register: %s",
254 REGISTER_NAME (regno
), err
);
260 /* If we're reading an address from the instruction address queue,
261 mask out the bottom two bits --- they contain the privilege
263 if (regno
== PCOQ_HEAD_REGNUM
|| regno
== PCOQ_TAIL_REGNUM
)
264 buf
[len
- 1] &= ~0x3;
266 supply_register (regno
, buf
);
270 /* Copy LEN bytes to or from inferior's memory starting at MEMADDR
271 to debugger memory starting at MYADDR. Copy to inferior if
274 Returns the length copied, which is either the LEN argument or zero.
275 This xfer function does not do partial moves, since child_ops
276 doesn't allow memory operations to cross below us in the target stack
277 anyway. TARGET is ignored. */
280 child_xfer_memory (CORE_ADDR memaddr
, char *myaddr
, int len
, int write
,
281 struct mem_attrib
*mem
,
282 struct target_ops
*target
)
285 /* Round starting address down to longword boundary. */
286 register CORE_ADDR addr
= memaddr
& - (CORE_ADDR
)(sizeof (int));
287 /* Round ending address up; get number of longwords that makes. */
289 = (((memaddr
+ len
) - addr
) + sizeof (int) - 1) / sizeof (int);
291 /* Allocate buffer of that many longwords.
292 Note -- do not use alloca to allocate this buffer since there is no
293 guarantee of when the buffer will actually be deallocated.
295 This routine can be called over and over with the same call chain;
296 this (in effect) would pile up all those alloca requests until a call
297 to alloca was made from a point higher than this routine in the
299 register int *buffer
= (int *) xmalloc (count
* sizeof (int));
303 /* Fill start and end extra bytes of buffer with existing memory data. */
304 if (addr
!= memaddr
|| len
< (int) sizeof (int))
306 /* Need part of initial word -- fetch it. */
307 buffer
[0] = call_ptrace (addr
< text_end
? PT_RIUSER
: PT_RDUSER
,
308 PIDGET (inferior_ptid
),
309 (PTRACE_ARG3_TYPE
) addr
, 0);
312 if (count
> 1) /* FIXME, avoid if even boundary */
315 = call_ptrace (addr
< text_end
? PT_RIUSER
: PT_RDUSER
,
316 PIDGET (inferior_ptid
),
317 (PTRACE_ARG3_TYPE
) (addr
318 + (count
- 1) * sizeof (int)),
322 /* Copy data to be written over corresponding part of buffer */
323 memcpy ((char *) buffer
+ (memaddr
& (sizeof (int) - 1)), myaddr
, len
);
325 /* Write the entire buffer. */
326 for (i
= 0; i
< count
; i
++, addr
+= sizeof (int))
330 /* The HP-UX kernel crashes if you use PT_WDUSER to write into the
331 text segment. FIXME -- does it work to write into the data
332 segment using WIUSER, or do these idiots really expect us to
333 figure out which segment the address is in, so we can use a
334 separate system call for it??! */
336 pt_request
= (addr
< text_end
) ? PT_WIUSER
: PT_WDUSER
;
337 pt_status
= call_ptrace (pt_request
,
338 PIDGET (inferior_ptid
),
339 (PTRACE_ARG3_TYPE
) addr
,
342 /* Did we fail? Might we've guessed wrong about which
343 segment this address resides in? Try the other request,
344 and see if that works... */
345 if ((pt_status
== -1) && errno
)
348 pt_request
= (pt_request
== PT_WIUSER
) ? PT_WDUSER
: PT_WIUSER
;
349 pt_status
= call_ptrace (pt_request
,
350 PIDGET (inferior_ptid
),
351 (PTRACE_ARG3_TYPE
) addr
,
354 /* No, we still fail. Okay, time to punt. */
355 if ((pt_status
== -1) && errno
)
365 /* Read all the longwords */
366 for (i
= 0; i
< count
; i
++, addr
+= sizeof (int))
369 buffer
[i
] = call_ptrace (addr
< text_end
? PT_RIUSER
: PT_RDUSER
,
370 PIDGET (inferior_ptid
),
371 (PTRACE_ARG3_TYPE
) addr
, 0);
380 /* Copy appropriate bytes out of the buffer. */
381 memcpy (myaddr
, (char *) buffer
+ (memaddr
& (sizeof (int) - 1)), len
);
389 child_post_follow_vfork (int parent_pid
, int followed_parent
, int child_pid
,
392 /* Are we a debugger that followed the parent of a vfork? If so,
393 then recall that the child's vfork event was delivered to us
394 first. And, that the parent was suspended by the OS until the
395 child's exec or exit events were received.
397 Upon receiving that child vfork, then, we were forced to remove
398 all breakpoints in the child and continue it so that it could
399 reach the exec or exit point.
401 But also recall that the parent and child of a vfork share the
402 same address space. Thus, removing bp's in the child also
403 removed them from the parent.
405 Now that the child has safely exec'd or exited, we must restore
406 the parent's breakpoints before we continue it. Else, we may
407 cause it run past expected stopping points. */
410 reattach_breakpoints (parent_pid
);
413 /* Are we a debugger that followed the child of a vfork? If so,
414 then recall that we don't actually acquire control of the child
415 until after it has exec'd or exited. */
418 /* If the child has exited, then there's nothing for us to do.
419 In the case of an exec event, we'll let that be handled by
420 the normal mechanism that notices and handles exec events, in
425 /* Format a process id, given PID. Be sure to terminate
426 this with a null--it's going to be printed via a "%s". */
428 child_pid_to_str (ptid_t ptid
)
430 /* Static because address returned */
432 pid_t pid
= PIDGET (ptid
);
434 /* Extra NUL for paranoia's sake */
435 sprintf (buf
, "process %d%c", pid
, '\0');
440 /* Format a thread id, given TID. Be sure to terminate
441 this with a null--it's going to be printed via a "%s".
443 Note: This is a core-gdb tid, not the actual system tid.
444 See infttrace.c for details. */
446 hppa_tid_to_str (ptid_t ptid
)
448 /* Static because address returned */
450 /* This seems strange, but when I did the ptid conversion, it looked
451 as though a pid was always being passed. - Kevin Buettner */
452 pid_t tid
= PIDGET (ptid
);
454 /* Extra NULLs for paranoia's sake */
455 sprintf (buf
, "system thread %d%c", tid
, '\0');
461 /* Enable HACK for ttrace work. In
462 * infttrace.c/require_notification_of_events,
463 * this is set to 0 so that the loop in child_wait
466 int not_same_real_pid
= 1;
470 /* Wait for child to do something. Return pid of child, or -1 in case
471 of error; store status through argument pointer OURSTATUS. */
474 child_wait (ptid_t ptid
, struct target_waitstatus
*ourstatus
)
478 char *execd_pathname
= NULL
;
482 enum target_waitkind kind
;
487 set_sigint_trap (); /* Causes SIGINT to be passed on to the
491 pid
= ptrace_wait (inferior_ptid
, &status
);
497 clear_sigint_trap ();
501 if (save_errno
== EINTR
)
504 fprintf_unfiltered (gdb_stderr
, "Child process unexpectedly missing: %s.\n",
505 safe_strerror (save_errno
));
507 /* Claim it exited with unknown signal. */
508 ourstatus
->kind
= TARGET_WAITKIND_SIGNALLED
;
509 ourstatus
->value
.sig
= TARGET_SIGNAL_UNKNOWN
;
510 return pid_to_ptid (-1);
515 if (target_has_exited (pid
, status
, &exit_status
))
517 /* ??rehrauer: For now, ignore this. */
521 if (!target_thread_alive (pid_to_ptid (pid
)))
523 ourstatus
->kind
= TARGET_WAITKIND_SPURIOUS
;
524 return pid_to_ptid (pid
);
527 if (hpux_has_forked (pid
, &related_pid
)
528 && ((pid
== PIDGET (inferior_ptid
))
529 || (related_pid
== PIDGET (inferior_ptid
))))
531 ourstatus
->kind
= TARGET_WAITKIND_FORKED
;
532 ourstatus
->value
.related_pid
= related_pid
;
533 return pid_to_ptid (pid
);
536 if (hpux_has_vforked (pid
, &related_pid
)
537 && ((pid
== PIDGET (inferior_ptid
))
538 || (related_pid
== PIDGET (inferior_ptid
))))
540 ourstatus
->kind
= TARGET_WAITKIND_VFORKED
;
541 ourstatus
->value
.related_pid
= related_pid
;
542 return pid_to_ptid (pid
);
545 if (hpux_has_execd (pid
, &execd_pathname
))
547 /* Are we ignoring initial exec events? (This is likely because
548 we're in the process of starting up the inferior, and another
549 (older) mechanism handles those.) If so, we'll report this
550 as a regular stop, not an exec.
552 if (inferior_ignoring_startup_exec_events
)
554 inferior_ignoring_startup_exec_events
--;
558 ourstatus
->kind
= TARGET_WAITKIND_EXECD
;
559 ourstatus
->value
.execd_pathname
= execd_pathname
;
560 return pid_to_ptid (pid
);
564 /* All we must do with these is communicate their occurrence
565 to wait_for_inferior...
567 if (hpux_has_syscall_event (pid
, &kind
, &syscall_id
))
569 ourstatus
->kind
= kind
;
570 ourstatus
->value
.syscall_id
= syscall_id
;
571 return pid_to_ptid (pid
);
574 /*## } while (pid != PIDGET (inferior_ptid)); ## *//* Some other child died or stopped */
575 /* hack for thread testing */
577 while ((pid
!= PIDGET (inferior_ptid
)) && not_same_real_pid
);
580 store_waitstatus (ourstatus
, status
);
581 return pid_to_ptid (pid
);
584 #if !defined (GDB_NATIVE_HPUX_11)
586 /* The following code is a substitute for the infttrace.c versions used
587 with ttrace() in HPUX 11. */
589 /* This value is an arbitrary integer. */
590 #define PT_VERSION 123456
592 /* This semaphore is used to coordinate the child and parent processes
593 after a fork(), and before an exec() by the child. See
594 parent_attach_all for details. */
598 int parent_channel
[2]; /* Parent "talks" to [1], child "listens" to [0] */
599 int child_channel
[2]; /* Child "talks" to [1], parent "listens" to [0] */
604 #define SEM_LISTEN (0)
606 static startup_semaphore_t startup_semaphore
;
608 extern int parent_attach_all (int, PTRACE_ARG3_TYPE
, int);
611 /* This function causes the caller's process to be traced by its
612 parent. This is intended to be called after GDB forks itself,
613 and before the child execs the target.
615 Note that HP-UX ptrace is rather funky in how this is done.
616 If the parent wants to get the initial exec event of a child,
617 it must set the ptrace event mask of the child to include execs.
618 (The child cannot do this itself.) This must be done after the
619 child is forked, but before it execs.
621 To coordinate the parent and child, we implement a semaphore using
622 pipes. After SETTRC'ing itself, the child tells the parent that
623 it is now traceable by the parent, and waits for the parent's
624 acknowledgement. The parent can then set the child's event mask,
625 and notify the child that it can now exec.
627 (The acknowledgement by parent happens as a result of a call to
628 child_acknowledge_created_inferior.) */
631 parent_attach_all (int pid
, PTRACE_ARG3_TYPE addr
, int data
)
635 /* We need a memory home for a constant. */
636 int tc_magic_child
= PT_VERSION
;
637 int tc_magic_parent
= 0;
639 /* The remainder of this function is only useful for HPUX 10.0 and
640 later, as it depends upon the ability to request notification
641 of specific kinds of events by the kernel. */
642 #if defined(PT_SET_EVENT_MASK)
644 /* Notify the parent that we're potentially ready to exec(). */
645 write (startup_semaphore
.child_channel
[SEM_TALK
],
647 sizeof (tc_magic_child
));
649 /* Wait for acknowledgement from the parent. */
650 read (startup_semaphore
.parent_channel
[SEM_LISTEN
],
652 sizeof (tc_magic_parent
));
653 if (tc_magic_child
!= tc_magic_parent
)
654 warning ("mismatched semaphore magic");
656 /* Discard our copy of the semaphore. */
657 (void) close (startup_semaphore
.parent_channel
[SEM_LISTEN
]);
658 (void) close (startup_semaphore
.parent_channel
[SEM_TALK
]);
659 (void) close (startup_semaphore
.child_channel
[SEM_LISTEN
]);
660 (void) close (startup_semaphore
.child_channel
[SEM_TALK
]);
668 hppa_require_attach (int pid
)
673 unsigned int regs_offset
;
675 /* Are we already attached? There appears to be no explicit way to
676 answer this via ptrace, so we try something which should be
677 innocuous if we are attached. If that fails, then we assume
678 we're not attached, and so attempt to make it so. */
681 regs_offset
= U_REGS_OFFSET
;
682 pc_addr
= register_addr (PC_REGNUM
, regs_offset
);
683 pc
= call_ptrace (PT_READ_U
, pid
, (PTRACE_ARG3_TYPE
) pc_addr
, 0);
688 pt_status
= call_ptrace (PT_ATTACH
, pid
, (PTRACE_ARG3_TYPE
) 0, 0);
693 /* Now we really are attached. */
701 hppa_require_detach (int pid
, int signal
)
704 call_ptrace (PT_DETACH
, pid
, (PTRACE_ARG3_TYPE
) 1, signal
);
705 errno
= 0; /* Ignore any errors. */
709 /* Since ptrace doesn't support memory page-protection events, which
710 are used to implement "hardware" watchpoints on HP-UX, these are
711 dummy versions, which perform no useful work. */
714 hppa_enable_page_protection_events (int pid
)
719 hppa_disable_page_protection_events (int pid
)
724 hppa_insert_hw_watchpoint (int pid
, CORE_ADDR start
, LONGEST len
, int type
)
726 error ("Hardware watchpoints not implemented on this platform.");
730 hppa_remove_hw_watchpoint (int pid
, CORE_ADDR start
, LONGEST len
,
733 error ("Hardware watchpoints not implemented on this platform.");
737 hppa_can_use_hw_watchpoint (enum bptype type
, int cnt
, enum bptype ot
)
743 hppa_range_profitable_for_hw_watchpoint (int pid
, CORE_ADDR start
, LONGEST len
)
745 error ("Hardware watchpoints not implemented on this platform.");
749 hppa_pid_or_tid_to_str (ptid_t id
)
751 /* In the ptrace world, there are only processes. */
752 return child_pid_to_str (id
);
755 /* This function has no meaning in a non-threaded world. Thus, we
756 return 0 (FALSE). See the use of "hppa_prepare_to_proceed" in
760 hppa_switched_threads (pid_t pid
)
766 hppa_ensure_vforking_parent_remains_stopped (int pid
)
768 /* This assumes that the vforked parent is presently stopped, and
769 that the vforked child has just delivered its first exec event.
770 Calling kill() this way will cause the SIGTRAP to be delivered as
771 soon as the parent is resumed, which happens as soon as the
772 vforked child is resumed. See wait_for_inferior for the use of
778 hppa_resume_execd_vforking_child_to_get_parent_vfork (void)
780 return 1; /* Yes, the child must be resumed. */
784 require_notification_of_events (int pid
)
786 #if defined(PT_SET_EVENT_MASK)
788 ptrace_event_t ptrace_events
;
792 /* Instruct the kernel as to the set of events we wish to be
793 informed of. (This support does not exist before HPUX 10.0.
794 We'll assume if PT_SET_EVENT_MASK has not been defined by
795 <sys/ptrace.h>, then we're being built on pre-10.0.) */
796 memset (&ptrace_events
, 0, sizeof (ptrace_events
));
798 /* Note: By default, all signals are visible to us. If we wish
799 the kernel to keep certain signals hidden from us, we do it
800 by calling sigdelset (ptrace_events.pe_signals, signal) for
801 each such signal here, before doing PT_SET_EVENT_MASK. */
802 /* RM: The above comment is no longer true. We start with ignoring
803 all signals, and then add the ones we are interested in. We could
804 do it the other way: start by looking at all signals and then
805 deleting the ones that we aren't interested in, except that
806 multiple gdb signals may be mapped to the same host signal
807 (eg. TARGET_SIGNAL_IO and TARGET_SIGNAL_POLL both get mapped to
808 signal 22 on HPUX 10.20) We want to be notified if we are
809 interested in either signal. */
810 sigfillset (&ptrace_events
.pe_signals
);
812 /* RM: Let's not bother with signals we don't care about */
813 nsigs
= (int) TARGET_SIGNAL_LAST
;
814 for (signum
= nsigs
; signum
> 0; signum
--)
816 if ((signal_stop_state (signum
)) ||
817 (signal_print_state (signum
)) ||
818 (!signal_pass_state (signum
)))
820 if (target_signal_to_host_p (signum
))
821 sigdelset (&ptrace_events
.pe_signals
,
822 target_signal_to_host (signum
));
826 ptrace_events
.pe_set_event
= 0;
828 ptrace_events
.pe_set_event
|= PTRACE_SIGNAL
;
829 ptrace_events
.pe_set_event
|= PTRACE_EXEC
;
830 ptrace_events
.pe_set_event
|= PTRACE_FORK
;
831 ptrace_events
.pe_set_event
|= PTRACE_VFORK
;
832 /* ??rehrauer: Add this one when we're prepared to catch it...
833 ptrace_events.pe_set_event |= PTRACE_EXIT;
837 pt_status
= call_ptrace (PT_SET_EVENT_MASK
,
839 (PTRACE_ARG3_TYPE
) & ptrace_events
,
840 sizeof (ptrace_events
));
842 perror_with_name ("ptrace");
849 require_notification_of_exec_events (int pid
)
851 #if defined(PT_SET_EVENT_MASK)
853 ptrace_event_t ptrace_events
;
855 /* Instruct the kernel as to the set of events we wish to be
856 informed of. (This support does not exist before HPUX 10.0.
857 We'll assume if PT_SET_EVENT_MASK has not been defined by
858 <sys/ptrace.h>, then we're being built on pre-10.0.) */
859 memset (&ptrace_events
, 0, sizeof (ptrace_events
));
861 /* Note: By default, all signals are visible to us. If we wish
862 the kernel to keep certain signals hidden from us, we do it
863 by calling sigdelset (ptrace_events.pe_signals, signal) for
864 each such signal here, before doing PT_SET_EVENT_MASK. */
865 sigemptyset (&ptrace_events
.pe_signals
);
867 ptrace_events
.pe_set_event
= 0;
869 ptrace_events
.pe_set_event
|= PTRACE_EXEC
;
870 /* ??rehrauer: Add this one when we're prepared to catch it...
871 ptrace_events.pe_set_event |= PTRACE_EXIT;
875 pt_status
= call_ptrace (PT_SET_EVENT_MASK
,
877 (PTRACE_ARG3_TYPE
) & ptrace_events
,
878 sizeof (ptrace_events
));
880 perror_with_name ("ptrace");
886 /* This function is called by the parent process, with pid being the
887 ID of the child process, after the debugger has forked. */
890 child_acknowledge_created_inferior (int pid
)
892 /* We need a memory home for a constant. */
893 int tc_magic_parent
= PT_VERSION
;
894 int tc_magic_child
= 0;
896 /* The remainder of this function is only useful for HPUX 10.0 and
897 later, as it depends upon the ability to request notification
898 of specific kinds of events by the kernel. */
899 #if defined(PT_SET_EVENT_MASK)
900 /* Wait for the child to tell us that it has forked. */
901 read (startup_semaphore
.child_channel
[SEM_LISTEN
],
903 sizeof (tc_magic_child
));
905 /* Notify the child that it can exec.
907 In the infttrace.c variant of this function, we set the child's
908 event mask after the fork but before the exec. In the ptrace
909 world, it seems we can't set the event mask until after the exec. */
910 write (startup_semaphore
.parent_channel
[SEM_TALK
],
912 sizeof (tc_magic_parent
));
914 /* We'd better pause a bit before trying to set the event mask,
915 though, to ensure that the exec has happened. We don't want to
916 wait() on the child, because that'll screw up the upper layers
917 of gdb's execution control that expect to see the exec event.
919 After an exec, the child is no longer executing gdb code. Hence,
920 we can't have yet another synchronization via the pipes. We'll
921 just sleep for a second, and hope that's enough delay... */
924 /* Instruct the kernel as to the set of events we wish to be
926 require_notification_of_exec_events (pid
);
928 /* Discard our copy of the semaphore. */
929 (void) close (startup_semaphore
.parent_channel
[SEM_LISTEN
]);
930 (void) close (startup_semaphore
.parent_channel
[SEM_TALK
]);
931 (void) close (startup_semaphore
.child_channel
[SEM_LISTEN
]);
932 (void) close (startup_semaphore
.child_channel
[SEM_TALK
]);
937 child_post_startup_inferior (ptid_t ptid
)
939 require_notification_of_events (PIDGET (ptid
));
943 child_post_attach (int pid
)
945 require_notification_of_events (pid
);
949 child_insert_fork_catchpoint (int pid
)
951 /* This request is only available on HPUX 10.0 and later. */
952 #if !defined(PT_SET_EVENT_MASK)
953 error ("Unable to catch forks prior to HPUX 10.0");
955 /* Enable reporting of fork events from the kernel. */
956 /* ??rehrauer: For the moment, we're always enabling these events,
957 and just ignoring them if there's no catchpoint to catch them. */
963 child_remove_fork_catchpoint (int pid
)
965 /* This request is only available on HPUX 10.0 and later. */
966 #if !defined(PT_SET_EVENT_MASK)
967 error ("Unable to catch forks prior to HPUX 10.0");
969 /* Disable reporting of fork events from the kernel. */
970 /* ??rehrauer: For the moment, we're always enabling these events,
971 and just ignoring them if there's no catchpoint to catch them. */
977 child_insert_vfork_catchpoint (int pid
)
979 /* This request is only available on HPUX 10.0 and later. */
980 #if !defined(PT_SET_EVENT_MASK)
981 error ("Unable to catch vforks prior to HPUX 10.0");
983 /* Enable reporting of vfork events from the kernel. */
984 /* ??rehrauer: For the moment, we're always enabling these events,
985 and just ignoring them if there's no catchpoint to catch them. */
991 child_remove_vfork_catchpoint (int pid
)
993 /* This request is only available on HPUX 10.0 and later. */
994 #if !defined(PT_SET_EVENT_MASK)
995 error ("Unable to catch vforks prior to HPUX 10.0");
997 /* Disable reporting of vfork events from the kernel. */
998 /* ??rehrauer: For the moment, we're always enabling these events,
999 and just ignoring them if there's no catchpoint to catch them. */
1005 hpux_has_forked (int pid
, int *childpid
)
1007 /* This request is only available on HPUX 10.0 and later. */
1008 #if !defined(PT_GET_PROCESS_STATE)
1013 ptrace_state_t ptrace_state
;
1016 pt_status
= call_ptrace (PT_GET_PROCESS_STATE
,
1018 (PTRACE_ARG3_TYPE
) & ptrace_state
,
1019 sizeof (ptrace_state
));
1021 perror_with_name ("ptrace");
1025 if (ptrace_state
.pe_report_event
& PTRACE_FORK
)
1027 *childpid
= ptrace_state
.pe_other_pid
;
1036 hpux_has_vforked (int pid
, int *childpid
)
1038 /* This request is only available on HPUX 10.0 and later. */
1039 #if !defined(PT_GET_PROCESS_STATE)
1045 ptrace_state_t ptrace_state
;
1048 pt_status
= call_ptrace (PT_GET_PROCESS_STATE
,
1050 (PTRACE_ARG3_TYPE
) & ptrace_state
,
1051 sizeof (ptrace_state
));
1053 perror_with_name ("ptrace");
1057 if (ptrace_state
.pe_report_event
& PTRACE_VFORK
)
1059 *childpid
= ptrace_state
.pe_other_pid
;
1068 child_insert_exec_catchpoint (int pid
)
1070 /* This request is only available on HPUX 10.0 and later. */
1071 #if !defined(PT_SET_EVENT_MASK)
1072 error ("Unable to catch execs prior to HPUX 10.0");
1075 /* Enable reporting of exec events from the kernel. */
1076 /* ??rehrauer: For the moment, we're always enabling these events,
1077 and just ignoring them if there's no catchpoint to catch them. */
1083 child_remove_exec_catchpoint (int pid
)
1085 /* This request is only available on HPUX 10.0 and later. */
1086 #if !defined(PT_SET_EVENT_MASK)
1087 error ("Unable to catch execs prior to HPUX 10.0");
1090 /* Disable reporting of exec events from the kernel. */
1091 /* ??rehrauer: For the moment, we're always enabling these events,
1092 and just ignoring them if there's no catchpoint to catch them. */
1098 hpux_has_execd (int pid
, char **execd_pathname
)
1100 /* This request is only available on HPUX 10.0 and later. */
1101 #if !defined(PT_GET_PROCESS_STATE)
1102 *execd_pathname
= NULL
;
1107 ptrace_state_t ptrace_state
;
1110 pt_status
= call_ptrace (PT_GET_PROCESS_STATE
,
1112 (PTRACE_ARG3_TYPE
) & ptrace_state
,
1113 sizeof (ptrace_state
));
1115 perror_with_name ("ptrace");
1119 if (ptrace_state
.pe_report_event
& PTRACE_EXEC
)
1121 char *exec_file
= target_pid_to_exec_file (pid
);
1122 *execd_pathname
= savestring (exec_file
, strlen (exec_file
));
1131 child_reported_exec_events_per_exec_call (void)
1133 return 2; /* ptrace reports the event twice per call. */
1137 hpux_has_syscall_event (int pid
, enum target_waitkind
*kind
, int *syscall_id
)
1139 /* This request is only available on HPUX 10.30 and later, via
1140 the ttrace interface. */
1142 *kind
= TARGET_WAITKIND_SPURIOUS
;
1148 child_pid_to_exec_file (int pid
)
1150 static char exec_file_buffer
[1024];
1152 CORE_ADDR top_of_stack
;
1156 ptid_t saved_inferior_ptid
;
1159 #ifdef PT_GET_PROCESS_PATHNAME
1160 /* As of 10.x HP-UX, there's an explicit request to get the pathname. */
1161 pt_status
= call_ptrace (PT_GET_PROCESS_PATHNAME
,
1163 (PTRACE_ARG3_TYPE
) exec_file_buffer
,
1164 sizeof (exec_file_buffer
) - 1);
1166 return exec_file_buffer
;
1169 /* It appears that this request is broken prior to 10.30.
1170 If it fails, try a really, truly amazingly gross hack
1171 that DDE uses, of pawing through the process' data
1172 segment to find the pathname. */
1174 top_of_stack
= 0x7b03a000;
1178 /* On the chance that pid != inferior_ptid, set inferior_ptid
1179 to pid, so that (grrrr!) implicit uses of inferior_ptid get
1182 saved_inferior_ptid
= inferior_ptid
;
1183 inferior_ptid
= pid_to_ptid (pid
);
1185 /* Try to grab a null-terminated string. */
1188 if (target_read_memory (top_of_stack
, four_chars
, 4) != 0)
1190 inferior_ptid
= saved_inferior_ptid
;
1193 for (i
= 0; i
< 4; i
++)
1195 exec_file_buffer
[name_index
++] = four_chars
[i
];
1196 done
= (four_chars
[i
] == '\0');
1203 if (exec_file_buffer
[0] == '\0')
1205 inferior_ptid
= saved_inferior_ptid
;
1209 inferior_ptid
= saved_inferior_ptid
;
1210 return exec_file_buffer
;
1214 pre_fork_inferior (void)
1218 status
= pipe (startup_semaphore
.parent_channel
);
1221 warning ("error getting parent pipe for startup semaphore");
1225 status
= pipe (startup_semaphore
.child_channel
);
1228 warning ("error getting child pipe for startup semaphore");
1234 /* Check to see if the given thread is alive.
1236 This is a no-op, as ptrace doesn't support threads, so we just
1240 child_thread_alive (ptid_t ptid
)
1245 #endif /* ! GDB_NATIVE_HPUX_11 */