1 /* Native support code for HPUX PA-RISC.
2 Copyright 1986, 1987, 1989, 1990, 1991, 1992, 1993, 1998, 1999
3 Free Software Foundation, Inc.
5 Contributed by the Center for Software Science at the
6 University of Utah (pa-gdb-bugs@cs.utah.edu).
8 This file is part of GDB.
10 This program is free software; you can redistribute it and/or modify
11 it under the terms of the GNU General Public License as published by
12 the Free Software Foundation; either version 2 of the License, or
13 (at your option) any later version.
15 This program is distributed in the hope that it will be useful,
16 but WITHOUT ANY WARRANTY; without even the implied warranty of
17 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 GNU General Public License for more details.
20 You should have received a copy of the GNU General Public License
21 along with this program; if not, write to the Free Software
22 Foundation, Inc., 59 Temple Place - Suite 330,
23 Boston, MA 02111-1307, USA. */
29 #include <sys/ptrace.h>
34 extern CORE_ADDR text_end
;
36 static void fetch_register
PARAMS ((int));
39 fetch_inferior_registers (regno
)
43 for (regno
= 0; regno
< NUM_REGS
; regno
++)
44 fetch_register (regno
);
46 fetch_register (regno
);
49 /* Our own version of the offsetof macro, since we can't assume ANSI C. */
50 #define HPPAH_OFFSETOF(type, member) ((int) (&((type *) 0)->member))
52 /* Store our register values back into the inferior.
53 If REGNO is -1, do this for all registers.
54 Otherwise, REGNO specifies which register (so we can save time). */
57 store_inferior_registers (regno
)
60 register unsigned int regaddr
;
63 unsigned int offset
= U_REGS_OFFSET
;
68 unsigned int addr
, len
, offset
;
70 if (CANNOT_STORE_REGISTER (regno
))
74 len
= REGISTER_RAW_SIZE (regno
);
76 /* Requests for register zero actually want the save_state's
77 ss_flags member. As RM says: "Oh, what a hack!" */
81 addr
= HPPAH_OFFSETOF (save_state_t
, ss_flags
);
82 len
= sizeof (ss
.ss_flags
);
84 /* Note that ss_flags is always an int, no matter what
85 REGISTER_RAW_SIZE(0) says. Assuming all HP-UX PA machines
86 are big-endian, put it at the least significant end of the
87 value, and zap the rest of the buffer. */
88 offset
= REGISTER_RAW_SIZE (0) - len
;
91 /* Floating-point registers come from the ss_fpblock area. */
92 else if (regno
>= FP0_REGNUM
)
93 addr
= (HPPAH_OFFSETOF (save_state_t
, ss_fpblock
)
94 + (REGISTER_BYTE (regno
) - REGISTER_BYTE (FP0_REGNUM
)));
96 /* Wide registers come from the ss_wide area.
97 I think it's more PC to test (ss_flags & SS_WIDEREGS) to select
98 between ss_wide and ss_narrow than to use the raw register size.
99 But checking ss_flags would require an extra ptrace call for
100 every register reference. Bleah. */
102 addr
= (HPPAH_OFFSETOF (save_state_t
, ss_wide
)
103 + REGISTER_BYTE (regno
));
105 /* Narrow registers come from the ss_narrow area. Note that
106 ss_narrow starts with gr1, not gr0. */
108 addr
= (HPPAH_OFFSETOF (save_state_t
, ss_narrow
)
109 + (REGISTER_BYTE (regno
) - REGISTER_BYTE (1)));
111 internal_error ("hppah-nat.c (write_register): unexpected register size");
113 #ifdef GDB_TARGET_IS_HPPA_20W
114 /* Unbelieveable. The PC head and tail must be written in 64bit hunks
115 or we will get an error. Worse yet, the oddball ptrace/ttrace
116 layering will not allow us to perform a 64bit register store.
119 if (regno
== PCOQ_HEAD_REGNUM
|| regno
== PCOQ_TAIL_REGNUM
&& len
== 8)
123 temp
= *(CORE_ADDR
*)®isters
[REGISTER_BYTE (regno
)];
125 /* Set the priv level (stored in the low two bits of the PC. */
128 ttrace_write_reg_64 (inferior_pid
, (CORE_ADDR
)addr
, (CORE_ADDR
)&temp
);
130 /* If we fail to write the PC, give a true error instead of
134 char *err
= safe_strerror (errno
);
135 char *msg
= alloca (strlen (err
) + 128);
136 sprintf (msg
, "writing `%s' register: %s",
137 REGISTER_NAME (regno
), err
);
138 perror_with_name (msg
);
143 /* Another crock. HPUX complains if you write a nonzero value to
144 the high part of IPSW. What will it take for HP to catch a
145 clue about building sensible interfaces? */
146 if (regno
== IPSW_REGNUM
&& len
== 8)
147 *(int *)®isters
[REGISTER_BYTE (regno
)] = 0;
150 for (i
= 0; i
< len
; i
+= sizeof (int))
153 call_ptrace (PT_WUREGS
, inferior_pid
, (PTRACE_ARG3_TYPE
) addr
+ i
,
154 *(int *) ®isters
[REGISTER_BYTE (regno
) + i
]);
157 /* Warning, not error, in case we are attached; sometimes
158 the kernel doesn't let us at the registers. */
159 char *err
= safe_strerror (errno
);
160 char *msg
= alloca (strlen (err
) + 128);
161 sprintf (msg
, "writing `%s' register: %s",
162 REGISTER_NAME (regno
), err
);
163 /* If we fail to write the PC, give a true error instead of
165 if (regno
== PCOQ_HEAD_REGNUM
|| regno
== PCOQ_TAIL_REGNUM
)
166 perror_with_name (msg
);
174 for (regno
= 0; regno
< NUM_REGS
; regno
++)
175 store_inferior_registers (regno
);
179 /* Fetch a register's value from the process's U area. */
181 fetch_register (regno
)
184 char buf
[MAX_REGISTER_RAW_SIZE
];
185 unsigned int addr
, len
, offset
;
189 len
= REGISTER_RAW_SIZE (regno
);
191 /* Requests for register zero actually want the save_state's
192 ss_flags member. As RM says: "Oh, what a hack!" */
196 addr
= HPPAH_OFFSETOF (save_state_t
, ss_flags
);
197 len
= sizeof (ss
.ss_flags
);
199 /* Note that ss_flags is always an int, no matter what
200 REGISTER_RAW_SIZE(0) says. Assuming all HP-UX PA machines
201 are big-endian, put it at the least significant end of the
202 value, and zap the rest of the buffer. */
203 offset
= REGISTER_RAW_SIZE (0) - len
;
204 memset (buf
, 0, sizeof (buf
));
207 /* Floating-point registers come from the ss_fpblock area. */
208 else if (regno
>= FP0_REGNUM
)
209 addr
= (HPPAH_OFFSETOF (save_state_t
, ss_fpblock
)
210 + (REGISTER_BYTE (regno
) - REGISTER_BYTE (FP0_REGNUM
)));
212 /* Wide registers come from the ss_wide area.
213 I think it's more PC to test (ss_flags & SS_WIDEREGS) to select
214 between ss_wide and ss_narrow than to use the raw register size.
215 But checking ss_flags would require an extra ptrace call for
216 every register reference. Bleah. */
218 addr
= (HPPAH_OFFSETOF (save_state_t
, ss_wide
)
219 + REGISTER_BYTE (regno
));
221 /* Narrow registers come from the ss_narrow area. Note that
222 ss_narrow starts with gr1, not gr0. */
224 addr
= (HPPAH_OFFSETOF (save_state_t
, ss_narrow
)
225 + (REGISTER_BYTE (regno
) - REGISTER_BYTE (1)));
228 internal_error ("hppa-nat.c (fetch_register): unexpected register size");
230 for (i
= 0; i
< len
; i
+= sizeof (int))
233 /* Copy an int from the U area to buf. Fill the least
234 significant end if len != raw_size. */
235 * (int *) &buf
[offset
+ i
] =
236 call_ptrace (PT_RUREGS
, inferior_pid
,
237 (PTRACE_ARG3_TYPE
) addr
+ i
, 0);
240 /* Warning, not error, in case we are attached; sometimes
241 the kernel doesn't let us at the registers. */
242 char *err
= safe_strerror (errno
);
243 char *msg
= alloca (strlen (err
) + 128);
244 sprintf (msg
, "reading `%s' register: %s",
245 REGISTER_NAME (regno
), err
);
251 /* If we're reading an address from the instruction address queue,
252 mask out the bottom two bits --- they contain the privilege
254 if (regno
== PCOQ_HEAD_REGNUM
|| regno
== PCOQ_TAIL_REGNUM
)
255 buf
[len
- 1] &= ~0x3;
257 supply_register (regno
, buf
);
261 /* Copy LEN bytes to or from inferior's memory starting at MEMADDR
262 to debugger memory starting at MYADDR. Copy to inferior if
265 Returns the length copied, which is either the LEN argument or zero.
266 This xfer function does not do partial moves, since child_ops
267 doesn't allow memory operations to cross below us in the target stack
271 child_xfer_memory (memaddr
, myaddr
, len
, write
, target
)
276 struct target_ops
*target
; /* ignored */
279 /* Round starting address down to longword boundary. */
280 register CORE_ADDR addr
= memaddr
& - (CORE_ADDR
)(sizeof (int));
281 /* Round ending address up; get number of longwords that makes. */
283 = (((memaddr
+ len
) - addr
) + sizeof (int) - 1) / sizeof (int);
285 /* Allocate buffer of that many longwords.
286 Note -- do not use alloca to allocate this buffer since there is no
287 guarantee of when the buffer will actually be deallocated.
289 This routine can be called over and over with the same call chain;
290 this (in effect) would pile up all those alloca requests until a call
291 to alloca was made from a point higher than this routine in the
293 register int *buffer
= (int *) xmalloc (count
* sizeof (int));
297 /* Fill start and end extra bytes of buffer with existing memory data. */
298 if (addr
!= memaddr
|| len
< (int) sizeof (int))
300 /* Need part of initial word -- fetch it. */
301 buffer
[0] = call_ptrace (addr
< text_end
? PT_RIUSER
: PT_RDUSER
,
302 inferior_pid
, (PTRACE_ARG3_TYPE
) addr
, 0);
305 if (count
> 1) /* FIXME, avoid if even boundary */
308 = call_ptrace (addr
< text_end
? PT_RIUSER
: PT_RDUSER
,
310 (PTRACE_ARG3_TYPE
) (addr
311 + (count
- 1) * sizeof (int)),
315 /* Copy data to be written over corresponding part of buffer */
316 memcpy ((char *) buffer
+ (memaddr
& (sizeof (int) - 1)), myaddr
, len
);
318 /* Write the entire buffer. */
319 for (i
= 0; i
< count
; i
++, addr
+= sizeof (int))
323 /* The HP-UX kernel crashes if you use PT_WDUSER to write into the
324 text segment. FIXME -- does it work to write into the data
325 segment using WIUSER, or do these idiots really expect us to
326 figure out which segment the address is in, so we can use a
327 separate system call for it??! */
329 pt_request
= (addr
< text_end
) ? PT_WIUSER
: PT_WDUSER
;
330 pt_status
= call_ptrace (pt_request
,
332 (PTRACE_ARG3_TYPE
) addr
,
335 /* Did we fail? Might we've guessed wrong about which
336 segment this address resides in? Try the other request,
337 and see if that works... */
338 if ((pt_status
== -1) && errno
)
341 pt_request
= (pt_request
== PT_WIUSER
) ? PT_WDUSER
: PT_WIUSER
;
342 pt_status
= call_ptrace (pt_request
,
344 (PTRACE_ARG3_TYPE
) addr
,
347 /* No, we still fail. Okay, time to punt. */
348 if ((pt_status
== -1) && errno
)
358 /* Read all the longwords */
359 for (i
= 0; i
< count
; i
++, addr
+= sizeof (int))
362 buffer
[i
] = call_ptrace (addr
< text_end
? PT_RIUSER
: PT_RDUSER
,
363 inferior_pid
, (PTRACE_ARG3_TYPE
) addr
, 0);
372 /* Copy appropriate bytes out of the buffer. */
373 memcpy (myaddr
, (char *) buffer
+ (memaddr
& (sizeof (int) - 1)), len
);
381 child_post_follow_inferior_by_clone ()
385 /* This function is used when following both the parent and child
386 of a fork. In this case, the debugger clones itself. The original
387 debugger follows the parent, the clone follows the child. The
388 original detaches from the child, delivering a SIGSTOP to it to
389 keep it from running away until the clone can attach itself.
391 At this point, the clone has attached to the child. Because of
392 the SIGSTOP, we must now deliver a SIGCONT to the child, or it
393 won't behave properly. */
394 status
= kill (inferior_pid
, SIGCONT
);
399 child_post_follow_vfork (parent_pid
, followed_parent
, child_pid
, followed_child
)
405 /* Are we a debugger that followed the parent of a vfork? If so,
406 then recall that the child's vfork event was delivered to us
407 first. And, that the parent was suspended by the OS until the
408 child's exec or exit events were received.
410 Upon receiving that child vfork, then, we were forced to remove
411 all breakpoints in the child and continue it so that it could
412 reach the exec or exit point.
414 But also recall that the parent and child of a vfork share the
415 same address space. Thus, removing bp's in the child also
416 removed them from the parent.
418 Now that the child has safely exec'd or exited, we must restore
419 the parent's breakpoints before we continue it. Else, we may
420 cause it run past expected stopping points. */
423 reattach_breakpoints (parent_pid
);
426 /* Are we a debugger that followed the child of a vfork? If so,
427 then recall that we don't actually acquire control of the child
428 until after it has exec'd or exited. */
431 /* If the child has exited, then there's nothing for us to do.
432 In the case of an exec event, we'll let that be handled by
433 the normal mechanism that notices and handles exec events, in
438 /* Format a process id, given PID. Be sure to terminate
439 this with a null--it's going to be printed via a "%s". */
441 hppa_pid_to_str (pid
)
444 /* Static because address returned */
447 /* Extra NULLs for paranoia's sake */
448 sprintf (buf
, "process %d\0\0\0\0", pid
);
453 /* Format a thread id, given TID. Be sure to terminate
454 this with a null--it's going to be printed via a "%s".
456 Note: This is a core-gdb tid, not the actual system tid.
457 See infttrace.c for details. */
459 hppa_tid_to_str (tid
)
462 /* Static because address returned */
465 /* Extra NULLs for paranoia's sake */
466 sprintf (buf
, "system thread %d\0\0\0\0", tid
);
471 #if !defined (GDB_NATIVE_HPUX_11)
473 /* The following code is a substitute for the infttrace.c versions used
474 with ttrace() in HPUX 11. */
476 /* This value is an arbitrary integer. */
477 #define PT_VERSION 123456
479 /* This semaphore is used to coordinate the child and parent processes
480 after a fork(), and before an exec() by the child. See
481 parent_attach_all for details. */
485 int parent_channel
[2]; /* Parent "talks" to [1], child "listens" to [0] */
486 int child_channel
[2]; /* Child "talks" to [1], parent "listens" to [0] */
491 #define SEM_LISTEN (0)
493 static startup_semaphore_t startup_semaphore
;
495 extern int parent_attach_all
PARAMS ((int, PTRACE_ARG3_TYPE
, int));
498 /* This function causes the caller's process to be traced by its
499 parent. This is intended to be called after GDB forks itself,
500 and before the child execs the target.
502 Note that HP-UX ptrace is rather funky in how this is done.
503 If the parent wants to get the initial exec event of a child,
504 it must set the ptrace event mask of the child to include execs.
505 (The child cannot do this itself.) This must be done after the
506 child is forked, but before it execs.
508 To coordinate the parent and child, we implement a semaphore using
509 pipes. After SETTRC'ing itself, the child tells the parent that
510 it is now traceable by the parent, and waits for the parent's
511 acknowledgement. The parent can then set the child's event mask,
512 and notify the child that it can now exec.
514 (The acknowledgement by parent happens as a result of a call to
515 child_acknowledge_created_inferior.) */
518 parent_attach_all (pid
, addr
, data
)
520 PTRACE_ARG3_TYPE addr
;
525 /* We need a memory home for a constant. */
526 int tc_magic_child
= PT_VERSION
;
527 int tc_magic_parent
= 0;
529 /* The remainder of this function is only useful for HPUX 10.0 and
530 later, as it depends upon the ability to request notification
531 of specific kinds of events by the kernel. */
532 #if defined(PT_SET_EVENT_MASK)
534 /* Notify the parent that we're potentially ready to exec(). */
535 write (startup_semaphore
.child_channel
[SEM_TALK
],
537 sizeof (tc_magic_child
));
539 /* Wait for acknowledgement from the parent. */
540 read (startup_semaphore
.parent_channel
[SEM_LISTEN
],
542 sizeof (tc_magic_parent
));
543 if (tc_magic_child
!= tc_magic_parent
)
544 warning ("mismatched semaphore magic");
546 /* Discard our copy of the semaphore. */
547 (void) close (startup_semaphore
.parent_channel
[SEM_LISTEN
]);
548 (void) close (startup_semaphore
.parent_channel
[SEM_TALK
]);
549 (void) close (startup_semaphore
.child_channel
[SEM_LISTEN
]);
550 (void) close (startup_semaphore
.child_channel
[SEM_TALK
]);
558 hppa_require_attach (pid
)
564 unsigned int regs_offset
;
566 /* Are we already attached? There appears to be no explicit way to
567 answer this via ptrace, so we try something which should be
568 innocuous if we are attached. If that fails, then we assume
569 we're not attached, and so attempt to make it so. */
572 regs_offset
= U_REGS_OFFSET
;
573 pc_addr
= register_addr (PC_REGNUM
, regs_offset
);
574 pc
= call_ptrace (PT_READ_U
, pid
, (PTRACE_ARG3_TYPE
) pc_addr
, 0);
579 pt_status
= call_ptrace (PT_ATTACH
, pid
, (PTRACE_ARG3_TYPE
) 0, 0);
584 /* Now we really are attached. */
592 hppa_require_detach (pid
, signal
)
597 call_ptrace (PT_DETACH
, pid
, (PTRACE_ARG3_TYPE
) 1, signal
);
598 errno
= 0; /* Ignore any errors. */
602 /* Since ptrace doesn't support memory page-protection events, which
603 are used to implement "hardware" watchpoints on HP-UX, these are
604 dummy versions, which perform no useful work. */
607 hppa_enable_page_protection_events (pid
)
613 hppa_disable_page_protection_events (pid
)
619 hppa_insert_hw_watchpoint (pid
, start
, len
, type
)
625 error ("Hardware watchpoints not implemented on this platform.");
629 hppa_remove_hw_watchpoint (pid
, start
, len
, type
)
635 error ("Hardware watchpoints not implemented on this platform.");
639 hppa_can_use_hw_watchpoint (type
, cnt
, ot
)
648 hppa_range_profitable_for_hw_watchpoint (pid
, start
, len
)
653 error ("Hardware watchpoints not implemented on this platform.");
657 hppa_pid_or_tid_to_str (id
)
660 /* In the ptrace world, there are only processes. */
661 return hppa_pid_to_str (id
);
664 /* This function has no meaning in a non-threaded world. Thus, we
665 return 0 (FALSE). See the use of "hppa_prepare_to_proceed" in
669 hppa_switched_threads (pid
)
676 hppa_ensure_vforking_parent_remains_stopped (pid
)
679 /* This assumes that the vforked parent is presently stopped, and
680 that the vforked child has just delivered its first exec event.
681 Calling kill() this way will cause the SIGTRAP to be delivered as
682 soon as the parent is resumed, which happens as soon as the
683 vforked child is resumed. See wait_for_inferior for the use of
689 hppa_resume_execd_vforking_child_to_get_parent_vfork ()
691 return 1; /* Yes, the child must be resumed. */
695 require_notification_of_events (pid
)
698 #if defined(PT_SET_EVENT_MASK)
700 ptrace_event_t ptrace_events
;
702 /* Instruct the kernel as to the set of events we wish to be
703 informed of. (This support does not exist before HPUX 10.0.
704 We'll assume if PT_SET_EVENT_MASK has not been defined by
705 <sys/ptrace.h>, then we're being built on pre-10.0.) */
706 memset (&ptrace_events
, 0, sizeof (ptrace_events
));
708 /* Note: By default, all signals are visible to us. If we wish
709 the kernel to keep certain signals hidden from us, we do it
710 by calling sigdelset (ptrace_events.pe_signals, signal) for
711 each such signal here, before doing PT_SET_EVENT_MASK. */
712 sigemptyset (&ptrace_events
.pe_signals
);
714 ptrace_events
.pe_set_event
= 0;
716 ptrace_events
.pe_set_event
|= PTRACE_SIGNAL
;
717 ptrace_events
.pe_set_event
|= PTRACE_EXEC
;
718 ptrace_events
.pe_set_event
|= PTRACE_FORK
;
719 ptrace_events
.pe_set_event
|= PTRACE_VFORK
;
720 /* ??rehrauer: Add this one when we're prepared to catch it...
721 ptrace_events.pe_set_event |= PTRACE_EXIT;
725 pt_status
= call_ptrace (PT_SET_EVENT_MASK
,
727 (PTRACE_ARG3_TYPE
) & ptrace_events
,
728 sizeof (ptrace_events
));
730 perror_with_name ("ptrace");
737 require_notification_of_exec_events (pid
)
740 #if defined(PT_SET_EVENT_MASK)
742 ptrace_event_t ptrace_events
;
744 /* Instruct the kernel as to the set of events we wish to be
745 informed of. (This support does not exist before HPUX 10.0.
746 We'll assume if PT_SET_EVENT_MASK has not been defined by
747 <sys/ptrace.h>, then we're being built on pre-10.0.) */
748 memset (&ptrace_events
, 0, sizeof (ptrace_events
));
750 /* Note: By default, all signals are visible to us. If we wish
751 the kernel to keep certain signals hidden from us, we do it
752 by calling sigdelset (ptrace_events.pe_signals, signal) for
753 each such signal here, before doing PT_SET_EVENT_MASK. */
754 sigemptyset (&ptrace_events
.pe_signals
);
756 ptrace_events
.pe_set_event
= 0;
758 ptrace_events
.pe_set_event
|= PTRACE_EXEC
;
759 /* ??rehrauer: Add this one when we're prepared to catch it...
760 ptrace_events.pe_set_event |= PTRACE_EXIT;
764 pt_status
= call_ptrace (PT_SET_EVENT_MASK
,
766 (PTRACE_ARG3_TYPE
) & ptrace_events
,
767 sizeof (ptrace_events
));
769 perror_with_name ("ptrace");
775 /* This function is called by the parent process, with pid being the
776 ID of the child process, after the debugger has forked. */
779 child_acknowledge_created_inferior (pid
)
782 /* We need a memory home for a constant. */
783 int tc_magic_parent
= PT_VERSION
;
784 int tc_magic_child
= 0;
786 /* The remainder of this function is only useful for HPUX 10.0 and
787 later, as it depends upon the ability to request notification
788 of specific kinds of events by the kernel. */
789 #if defined(PT_SET_EVENT_MASK)
790 /* Wait for the child to tell us that it has forked. */
791 read (startup_semaphore
.child_channel
[SEM_LISTEN
],
793 sizeof (tc_magic_child
));
795 /* Notify the child that it can exec.
797 In the infttrace.c variant of this function, we set the child's
798 event mask after the fork but before the exec. In the ptrace
799 world, it seems we can't set the event mask until after the exec. */
800 write (startup_semaphore
.parent_channel
[SEM_TALK
],
802 sizeof (tc_magic_parent
));
804 /* We'd better pause a bit before trying to set the event mask,
805 though, to ensure that the exec has happened. We don't want to
806 wait() on the child, because that'll screw up the upper layers
807 of gdb's execution control that expect to see the exec event.
809 After an exec, the child is no longer executing gdb code. Hence,
810 we can't have yet another synchronization via the pipes. We'll
811 just sleep for a second, and hope that's enough delay... */
814 /* Instruct the kernel as to the set of events we wish to be
816 require_notification_of_exec_events (pid
);
818 /* Discard our copy of the semaphore. */
819 (void) close (startup_semaphore
.parent_channel
[SEM_LISTEN
]);
820 (void) close (startup_semaphore
.parent_channel
[SEM_TALK
]);
821 (void) close (startup_semaphore
.child_channel
[SEM_LISTEN
]);
822 (void) close (startup_semaphore
.child_channel
[SEM_TALK
]);
827 child_post_startup_inferior (pid
)
830 require_notification_of_events (pid
);
834 child_post_attach (pid
)
837 require_notification_of_events (pid
);
841 child_insert_fork_catchpoint (pid
)
844 /* This request is only available on HPUX 10.0 and later. */
845 #if !defined(PT_SET_EVENT_MASK)
846 error ("Unable to catch forks prior to HPUX 10.0");
848 /* Enable reporting of fork events from the kernel. */
849 /* ??rehrauer: For the moment, we're always enabling these events,
850 and just ignoring them if there's no catchpoint to catch them. */
856 child_remove_fork_catchpoint (pid
)
859 /* This request is only available on HPUX 10.0 and later. */
860 #if !defined(PT_SET_EVENT_MASK)
861 error ("Unable to catch forks prior to HPUX 10.0");
863 /* Disable reporting of fork events from the kernel. */
864 /* ??rehrauer: For the moment, we're always enabling these events,
865 and just ignoring them if there's no catchpoint to catch them. */
871 child_insert_vfork_catchpoint (pid
)
874 /* This request is only available on HPUX 10.0 and later. */
875 #if !defined(PT_SET_EVENT_MASK)
876 error ("Unable to catch vforks prior to HPUX 10.0");
878 /* Enable reporting of vfork events from the kernel. */
879 /* ??rehrauer: For the moment, we're always enabling these events,
880 and just ignoring them if there's no catchpoint to catch them. */
886 child_remove_vfork_catchpoint (pid
)
889 /* This request is only available on HPUX 10.0 and later. */
890 #if !defined(PT_SET_EVENT_MASK)
891 error ("Unable to catch vforks prior to HPUX 10.0");
893 /* Disable reporting of vfork events from the kernel. */
894 /* ??rehrauer: For the moment, we're always enabling these events,
895 and just ignoring them if there's no catchpoint to catch them. */
901 child_has_forked (pid
, childpid
)
905 /* This request is only available on HPUX 10.0 and later. */
906 #if !defined(PT_GET_PROCESS_STATE)
911 ptrace_state_t ptrace_state
;
914 pt_status
= call_ptrace (PT_GET_PROCESS_STATE
,
916 (PTRACE_ARG3_TYPE
) & ptrace_state
,
917 sizeof (ptrace_state
));
919 perror_with_name ("ptrace");
923 if (ptrace_state
.pe_report_event
& PTRACE_FORK
)
925 *childpid
= ptrace_state
.pe_other_pid
;
934 child_has_vforked (pid
, childpid
)
938 /* This request is only available on HPUX 10.0 and later. */
939 #if !defined(PT_GET_PROCESS_STATE)
945 ptrace_state_t ptrace_state
;
948 pt_status
= call_ptrace (PT_GET_PROCESS_STATE
,
950 (PTRACE_ARG3_TYPE
) & ptrace_state
,
951 sizeof (ptrace_state
));
953 perror_with_name ("ptrace");
957 if (ptrace_state
.pe_report_event
& PTRACE_VFORK
)
959 *childpid
= ptrace_state
.pe_other_pid
;
968 child_can_follow_vfork_prior_to_exec ()
970 /* ptrace doesn't allow this. */
975 child_insert_exec_catchpoint (pid
)
978 /* This request is only available on HPUX 10.0 and later. */
979 #if !defined(PT_SET_EVENT_MASK)
980 error ("Unable to catch execs prior to HPUX 10.0");
983 /* Enable reporting of exec 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_exec_catchpoint (pid
)
994 /* This request is only available on HPUX 10.0 and later. */
995 #if !defined(PT_SET_EVENT_MASK)
996 error ("Unable to catch execs prior to HPUX 10.0");
999 /* Disable reporting of exec events from the kernel. */
1000 /* ??rehrauer: For the moment, we're always enabling these events,
1001 and just ignoring them if there's no catchpoint to catch them. */
1007 child_has_execd (pid
, execd_pathname
)
1009 char **execd_pathname
;
1011 /* This request is only available on HPUX 10.0 and later. */
1012 #if !defined(PT_GET_PROCESS_STATE)
1013 *execd_pathname
= NULL
;
1018 ptrace_state_t ptrace_state
;
1021 pt_status
= call_ptrace (PT_GET_PROCESS_STATE
,
1023 (PTRACE_ARG3_TYPE
) & ptrace_state
,
1024 sizeof (ptrace_state
));
1026 perror_with_name ("ptrace");
1030 if (ptrace_state
.pe_report_event
& PTRACE_EXEC
)
1032 char *exec_file
= target_pid_to_exec_file (pid
);
1033 *execd_pathname
= savestring (exec_file
, strlen (exec_file
));
1042 child_reported_exec_events_per_exec_call ()
1044 return 2; /* ptrace reports the event twice per call. */
1048 child_has_syscall_event (pid
, kind
, syscall_id
)
1050 enum target_waitkind
*kind
;
1053 /* This request is only available on HPUX 10.30 and later, via
1054 the ttrace interface. */
1056 *kind
= TARGET_WAITKIND_SPURIOUS
;
1062 child_pid_to_exec_file (pid
)
1065 static char exec_file_buffer
[1024];
1067 CORE_ADDR top_of_stack
;
1071 int saved_inferior_pid
;
1074 #ifdef PT_GET_PROCESS_PATHNAME
1075 /* As of 10.x HP-UX, there's an explicit request to get the pathname. */
1076 pt_status
= call_ptrace (PT_GET_PROCESS_PATHNAME
,
1078 (PTRACE_ARG3_TYPE
) exec_file_buffer
,
1079 sizeof (exec_file_buffer
) - 1);
1081 return exec_file_buffer
;
1084 /* It appears that this request is broken prior to 10.30.
1085 If it fails, try a really, truly amazingly gross hack
1086 that DDE uses, of pawing through the process' data
1087 segment to find the pathname. */
1089 top_of_stack
= 0x7b03a000;
1093 /* On the chance that pid != inferior_pid, set inferior_pid
1094 to pid, so that (grrrr!) implicit uses of inferior_pid get
1097 saved_inferior_pid
= inferior_pid
;
1100 /* Try to grab a null-terminated string. */
1103 if (target_read_memory (top_of_stack
, four_chars
, 4) != 0)
1105 inferior_pid
= saved_inferior_pid
;
1108 for (i
= 0; i
< 4; i
++)
1110 exec_file_buffer
[name_index
++] = four_chars
[i
];
1111 done
= (four_chars
[i
] == '\0');
1118 if (exec_file_buffer
[0] == '\0')
1120 inferior_pid
= saved_inferior_pid
;
1124 inferior_pid
= saved_inferior_pid
;
1125 return exec_file_buffer
;
1129 pre_fork_inferior ()
1133 status
= pipe (startup_semaphore
.parent_channel
);
1136 warning ("error getting parent pipe for startup semaphore");
1140 status
= pipe (startup_semaphore
.child_channel
);
1143 warning ("error getting child pipe for startup semaphore");
1149 /* Check to see if the given thread is alive.
1151 This is a no-op, as ptrace doesn't support threads, so we just
1155 child_thread_alive (pid
)
1161 #endif /* ! GDB_NATIVE_HPUX_11 */