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 /* Store our register values back into the inferior.
50 If REGNO is -1, do this for all registers.
51 Otherwise, REGNO specifies which register (so we can save time). */
54 store_inferior_registers (regno)
57 register unsigned int regaddr;
60 unsigned int offset = U_REGS_OFFSET;
65 if (CANNOT_STORE_REGISTER (regno))
67 regaddr = register_addr (regno, offset);
69 if (regno == PCOQ_HEAD_REGNUM || regno == PCOQ_TAIL_REGNUM)
71 scratch = *(int *) ®isters[REGISTER_BYTE (regno)] | 0x3;
72 call_ptrace (PT_WUREGS, inferior_pid, (PTRACE_ARG3_TYPE) regaddr,
76 /* Error, even if attached. Failing to write these two
77 registers is pretty serious. */
78 sprintf (buf, "writing register number %d", regno);
79 perror_with_name (buf);
83 for (i = 0; i < REGISTER_RAW_SIZE (regno); i += sizeof (int))
86 call_ptrace (PT_WUREGS, inferior_pid, (PTRACE_ARG3_TYPE) regaddr,
87 *(int *) ®isters[REGISTER_BYTE (regno) + i]);
90 /* Warning, not error, in case we are attached; sometimes the
91 kernel doesn't let us at the registers. */
92 char *err = safe_strerror (errno);
93 char *msg = alloca (strlen (err) + 128);
94 sprintf (msg, "writing register %s: %s",
95 REGISTER_NAME (regno), err);
99 regaddr += sizeof (int);
103 for (regno = 0; regno < NUM_REGS; regno++)
104 store_inferior_registers (regno);
108 /* Our own version of the offsetof macro, since we can't assume ANSI C. */
109 #define HPPAH_OFFSETOF(type, member) ((int) (&((type *) 0)->member))
111 /* Fetch a register's value from the process's U area. */
113 fetch_register (regno)
116 char buf[MAX_REGISTER_RAW_SIZE];
117 unsigned int addr, len, offset;
121 len = REGISTER_RAW_SIZE (regno);
123 /* Requests for register zero actually want the save_state's
124 ss_flags member. As RM says: "Oh, what a hack!" */
128 addr = HPPAH_OFFSETOF (save_state_t, ss_flags);
129 len = sizeof (ss.ss_flags);
131 /* Note that ss_flags is always an int, no matter what
132 REGISTER_RAW_SIZE(0) says. Assuming all HP-UX PA machines
133 are big-endian, put it at the least significant end of the
134 value, and zap the rest of the buffer. */
135 offset = REGISTER_RAW_SIZE (0) - len;
136 memset (buf, 0, sizeof (buf));
139 /* Floating-point registers come from the ss_fpblock area. */
140 else if (regno >= FP0_REGNUM)
141 addr = (HPPAH_OFFSETOF (save_state_t, ss_fpblock)
142 + (REGISTER_BYTE (regno) - REGISTER_BYTE (FP0_REGNUM)));
144 /* Wide registers come from the ss_wide area.
145 I think it's more PC to test (ss_flags & SS_WIDEREGS) to select
146 between ss_wide and ss_narrow than to use the raw register size.
147 But checking ss_flags would require an extra ptrace call for
148 every register reference. Bleah. */
150 addr = (HPPAH_OFFSETOF (save_state_t, ss_wide)
151 + REGISTER_BYTE (regno));
153 /* Narrow registers come from the ss_narrow area. Note that
154 ss_narrow starts with gr1, not gr0. */
156 addr = (HPPAH_OFFSETOF (save_state_t, ss_narrow)
157 + (REGISTER_BYTE (regno) - REGISTER_BYTE (1)));
160 internal_error ("hppa-nat.c (fetch_register): unexpected register size");
162 for (i = 0; i < len; i += sizeof (int))
165 /* Copy an int from the U area to buf. Fill the least
166 significant end if len != raw_size. */
167 * (int *) &buf[offset + i] =
168 call_ptrace (PT_RUREGS, inferior_pid,
169 (PTRACE_ARG3_TYPE) addr + i, 0);
172 /* Warning, not error, in case we are attached; sometimes
173 the kernel doesn't let us at the registers. */
174 char *err = safe_strerror (errno);
175 char *msg = alloca (strlen (err) + 128);
176 sprintf (msg, "reading `%s' register: %s",
177 REGISTER_NAME (regno), err);
183 /* If we're reading an address from the instruction address queue,
184 mask out the bottom two bits --- they contain the privilege
186 if (regno == PCOQ_HEAD_REGNUM || regno == PCOQ_TAIL_REGNUM)
187 buf[len - 1] &= ~0x3;
189 supply_register (regno, buf);
193 /* Copy LEN bytes to or from inferior's memory starting at MEMADDR
194 to debugger memory starting at MYADDR. Copy to inferior if
197 Returns the length copied, which is either the LEN argument or zero.
198 This xfer function does not do partial moves, since child_ops
199 doesn't allow memory operations to cross below us in the target stack
203 child_xfer_memory (memaddr, myaddr, len, write, target)
208 struct target_ops *target; /* ignored */
211 /* Round starting address down to longword boundary. */
212 register CORE_ADDR addr = memaddr & - (CORE_ADDR)(sizeof (int));
213 /* Round ending address up; get number of longwords that makes. */
215 = (((memaddr + len) - addr) + sizeof (int) - 1) / sizeof (int);
217 /* Allocate buffer of that many longwords.
218 Note -- do not use alloca to allocate this buffer since there is no
219 guarantee of when the buffer will actually be deallocated.
221 This routine can be called over and over with the same call chain;
222 this (in effect) would pile up all those alloca requests until a call
223 to alloca was made from a point higher than this routine in the
225 register int *buffer = (int *) xmalloc (count * sizeof (int));
229 /* Fill start and end extra bytes of buffer with existing memory data. */
230 if (addr != memaddr || len < (int) sizeof (int))
232 /* Need part of initial word -- fetch it. */
233 buffer[0] = call_ptrace (addr < text_end ? PT_RIUSER : PT_RDUSER,
234 inferior_pid, (PTRACE_ARG3_TYPE) addr, 0);
237 if (count > 1) /* FIXME, avoid if even boundary */
240 = call_ptrace (addr < text_end ? PT_RIUSER : PT_RDUSER,
242 (PTRACE_ARG3_TYPE) (addr
243 + (count - 1) * sizeof (int)),
247 /* Copy data to be written over corresponding part of buffer */
248 memcpy ((char *) buffer + (memaddr & (sizeof (int) - 1)), myaddr, len);
250 /* Write the entire buffer. */
251 for (i = 0; i < count; i++, addr += sizeof (int))
255 /* The HP-UX kernel crashes if you use PT_WDUSER to write into the
256 text segment. FIXME -- does it work to write into the data
257 segment using WIUSER, or do these idiots really expect us to
258 figure out which segment the address is in, so we can use a
259 separate system call for it??! */
261 pt_request = (addr < text_end) ? PT_WIUSER : PT_WDUSER;
262 pt_status = call_ptrace (pt_request,
264 (PTRACE_ARG3_TYPE) addr,
267 /* Did we fail? Might we've guessed wrong about which
268 segment this address resides in? Try the other request,
269 and see if that works... */
270 if ((pt_status == -1) && errno)
273 pt_request = (pt_request == PT_WIUSER) ? PT_WDUSER : PT_WIUSER;
274 pt_status = call_ptrace (pt_request,
276 (PTRACE_ARG3_TYPE) addr,
279 /* No, we still fail. Okay, time to punt. */
280 if ((pt_status == -1) && errno)
290 /* Read all the longwords */
291 for (i = 0; i < count; i++, addr += sizeof (int))
294 buffer[i] = call_ptrace (addr < text_end ? PT_RIUSER : PT_RDUSER,
295 inferior_pid, (PTRACE_ARG3_TYPE) addr, 0);
304 /* Copy appropriate bytes out of the buffer. */
305 memcpy (myaddr, (char *) buffer + (memaddr & (sizeof (int) - 1)), len);
313 child_post_follow_inferior_by_clone ()
317 /* This function is used when following both the parent and child
318 of a fork. In this case, the debugger clones itself. The original
319 debugger follows the parent, the clone follows the child. The
320 original detaches from the child, delivering a SIGSTOP to it to
321 keep it from running away until the clone can attach itself.
323 At this point, the clone has attached to the child. Because of
324 the SIGSTOP, we must now deliver a SIGCONT to the child, or it
325 won't behave properly. */
326 status = kill (inferior_pid, SIGCONT);
331 child_post_follow_vfork (parent_pid, followed_parent, child_pid, followed_child)
337 /* Are we a debugger that followed the parent of a vfork? If so,
338 then recall that the child's vfork event was delivered to us
339 first. And, that the parent was suspended by the OS until the
340 child's exec or exit events were received.
342 Upon receiving that child vfork, then, we were forced to remove
343 all breakpoints in the child and continue it so that it could
344 reach the exec or exit point.
346 But also recall that the parent and child of a vfork share the
347 same address space. Thus, removing bp's in the child also
348 removed them from the parent.
350 Now that the child has safely exec'd or exited, we must restore
351 the parent's breakpoints before we continue it. Else, we may
352 cause it run past expected stopping points. */
355 reattach_breakpoints (parent_pid);
358 /* Are we a debugger that followed the child of a vfork? If so,
359 then recall that we don't actually acquire control of the child
360 until after it has exec'd or exited. */
363 /* If the child has exited, then there's nothing for us to do.
364 In the case of an exec event, we'll let that be handled by
365 the normal mechanism that notices and handles exec events, in
370 /* Format a process id, given PID. Be sure to terminate
371 this with a null--it's going to be printed via a "%s". */
373 hppa_pid_to_str (pid)
376 /* Static because address returned */
379 /* Extra NULLs for paranoia's sake */
380 sprintf (buf, "process %d\0\0\0\0", pid);
385 /* Format a thread id, given TID. Be sure to terminate
386 this with a null--it's going to be printed via a "%s".
388 Note: This is a core-gdb tid, not the actual system tid.
389 See infttrace.c for details. */
391 hppa_tid_to_str (tid)
394 /* Static because address returned */
397 /* Extra NULLs for paranoia's sake */
398 sprintf (buf, "system thread %d\0\0\0\0", tid);
403 #if !defined (GDB_NATIVE_HPUX_11)
405 /* The following code is a substitute for the infttrace.c versions used
406 with ttrace() in HPUX 11. */
408 /* This value is an arbitrary integer. */
409 #define PT_VERSION 123456
411 /* This semaphore is used to coordinate the child and parent processes
412 after a fork(), and before an exec() by the child. See
413 parent_attach_all for details. */
417 int parent_channel[2]; /* Parent "talks" to [1], child "listens" to [0] */
418 int child_channel[2]; /* Child "talks" to [1], parent "listens" to [0] */
423 #define SEM_LISTEN (0)
425 static startup_semaphore_t startup_semaphore;
427 extern int parent_attach_all PARAMS ((int, PTRACE_ARG3_TYPE, int));
430 /* This function causes the caller's process to be traced by its
431 parent. This is intended to be called after GDB forks itself,
432 and before the child execs the target.
434 Note that HP-UX ptrace is rather funky in how this is done.
435 If the parent wants to get the initial exec event of a child,
436 it must set the ptrace event mask of the child to include execs.
437 (The child cannot do this itself.) This must be done after the
438 child is forked, but before it execs.
440 To coordinate the parent and child, we implement a semaphore using
441 pipes. After SETTRC'ing itself, the child tells the parent that
442 it is now traceable by the parent, and waits for the parent's
443 acknowledgement. The parent can then set the child's event mask,
444 and notify the child that it can now exec.
446 (The acknowledgement by parent happens as a result of a call to
447 child_acknowledge_created_inferior.) */
450 parent_attach_all (pid, addr, data)
452 PTRACE_ARG3_TYPE addr;
457 /* We need a memory home for a constant. */
458 int tc_magic_child = PT_VERSION;
459 int tc_magic_parent = 0;
461 /* The remainder of this function is only useful for HPUX 10.0 and
462 later, as it depends upon the ability to request notification
463 of specific kinds of events by the kernel. */
464 #if defined(PT_SET_EVENT_MASK)
466 /* Notify the parent that we're potentially ready to exec(). */
467 write (startup_semaphore.child_channel[SEM_TALK],
469 sizeof (tc_magic_child));
471 /* Wait for acknowledgement from the parent. */
472 read (startup_semaphore.parent_channel[SEM_LISTEN],
474 sizeof (tc_magic_parent));
475 if (tc_magic_child != tc_magic_parent)
476 warning ("mismatched semaphore magic");
478 /* Discard our copy of the semaphore. */
479 (void) close (startup_semaphore.parent_channel[SEM_LISTEN]);
480 (void) close (startup_semaphore.parent_channel[SEM_TALK]);
481 (void) close (startup_semaphore.child_channel[SEM_LISTEN]);
482 (void) close (startup_semaphore.child_channel[SEM_TALK]);
490 hppa_require_attach (pid)
496 unsigned int regs_offset;
498 /* Are we already attached? There appears to be no explicit way to
499 answer this via ptrace, so we try something which should be
500 innocuous if we are attached. If that fails, then we assume
501 we're not attached, and so attempt to make it so. */
504 regs_offset = U_REGS_OFFSET;
505 pc_addr = register_addr (PC_REGNUM, regs_offset);
506 pc = call_ptrace (PT_READ_U, pid, (PTRACE_ARG3_TYPE) pc_addr, 0);
511 pt_status = call_ptrace (PT_ATTACH, pid, (PTRACE_ARG3_TYPE) 0, 0);
516 /* Now we really are attached. */
524 hppa_require_detach (pid, signal)
529 call_ptrace (PT_DETACH, pid, (PTRACE_ARG3_TYPE) 1, signal);
530 errno = 0; /* Ignore any errors. */
534 /* Since ptrace doesn't support memory page-protection events, which
535 are used to implement "hardware" watchpoints on HP-UX, these are
536 dummy versions, which perform no useful work. */
539 hppa_enable_page_protection_events (pid)
545 hppa_disable_page_protection_events (pid)
551 hppa_insert_hw_watchpoint (pid, start, len, type)
557 error ("Hardware watchpoints not implemented on this platform.");
561 hppa_remove_hw_watchpoint (pid, start, len, type)
567 error ("Hardware watchpoints not implemented on this platform.");
571 hppa_can_use_hw_watchpoint (type, cnt, ot)
580 hppa_range_profitable_for_hw_watchpoint (pid, start, len)
585 error ("Hardware watchpoints not implemented on this platform.");
589 hppa_pid_or_tid_to_str (id)
592 /* In the ptrace world, there are only processes. */
593 return hppa_pid_to_str (id);
596 /* This function has no meaning in a non-threaded world. Thus, we
597 return 0 (FALSE). See the use of "hppa_prepare_to_proceed" in
601 hppa_switched_threads (pid)
608 hppa_ensure_vforking_parent_remains_stopped (pid)
611 /* This assumes that the vforked parent is presently stopped, and
612 that the vforked child has just delivered its first exec event.
613 Calling kill() this way will cause the SIGTRAP to be delivered as
614 soon as the parent is resumed, which happens as soon as the
615 vforked child is resumed. See wait_for_inferior for the use of
621 hppa_resume_execd_vforking_child_to_get_parent_vfork ()
623 return 1; /* Yes, the child must be resumed. */
627 require_notification_of_events (pid)
630 #if defined(PT_SET_EVENT_MASK)
632 ptrace_event_t ptrace_events;
634 /* Instruct the kernel as to the set of events we wish to be
635 informed of. (This support does not exist before HPUX 10.0.
636 We'll assume if PT_SET_EVENT_MASK has not been defined by
637 <sys/ptrace.h>, then we're being built on pre-10.0.) */
638 memset (&ptrace_events, 0, sizeof (ptrace_events));
640 /* Note: By default, all signals are visible to us. If we wish
641 the kernel to keep certain signals hidden from us, we do it
642 by calling sigdelset (ptrace_events.pe_signals, signal) for
643 each such signal here, before doing PT_SET_EVENT_MASK. */
644 sigemptyset (&ptrace_events.pe_signals);
646 ptrace_events.pe_set_event = 0;
648 ptrace_events.pe_set_event |= PTRACE_SIGNAL;
649 ptrace_events.pe_set_event |= PTRACE_EXEC;
650 ptrace_events.pe_set_event |= PTRACE_FORK;
651 ptrace_events.pe_set_event |= PTRACE_VFORK;
652 /* ??rehrauer: Add this one when we're prepared to catch it...
653 ptrace_events.pe_set_event |= PTRACE_EXIT;
657 pt_status = call_ptrace (PT_SET_EVENT_MASK,
659 (PTRACE_ARG3_TYPE) & ptrace_events,
660 sizeof (ptrace_events));
662 perror_with_name ("ptrace");
669 require_notification_of_exec_events (pid)
672 #if defined(PT_SET_EVENT_MASK)
674 ptrace_event_t ptrace_events;
676 /* Instruct the kernel as to the set of events we wish to be
677 informed of. (This support does not exist before HPUX 10.0.
678 We'll assume if PT_SET_EVENT_MASK has not been defined by
679 <sys/ptrace.h>, then we're being built on pre-10.0.) */
680 memset (&ptrace_events, 0, sizeof (ptrace_events));
682 /* Note: By default, all signals are visible to us. If we wish
683 the kernel to keep certain signals hidden from us, we do it
684 by calling sigdelset (ptrace_events.pe_signals, signal) for
685 each such signal here, before doing PT_SET_EVENT_MASK. */
686 sigemptyset (&ptrace_events.pe_signals);
688 ptrace_events.pe_set_event = 0;
690 ptrace_events.pe_set_event |= PTRACE_EXEC;
691 /* ??rehrauer: Add this one when we're prepared to catch it...
692 ptrace_events.pe_set_event |= PTRACE_EXIT;
696 pt_status = call_ptrace (PT_SET_EVENT_MASK,
698 (PTRACE_ARG3_TYPE) & ptrace_events,
699 sizeof (ptrace_events));
701 perror_with_name ("ptrace");
707 /* This function is called by the parent process, with pid being the
708 ID of the child process, after the debugger has forked. */
711 child_acknowledge_created_inferior (pid)
714 /* We need a memory home for a constant. */
715 int tc_magic_parent = PT_VERSION;
716 int tc_magic_child = 0;
718 /* The remainder of this function is only useful for HPUX 10.0 and
719 later, as it depends upon the ability to request notification
720 of specific kinds of events by the kernel. */
721 #if defined(PT_SET_EVENT_MASK)
722 /* Wait for the child to tell us that it has forked. */
723 read (startup_semaphore.child_channel[SEM_LISTEN],
725 sizeof (tc_magic_child));
727 /* Notify the child that it can exec.
729 In the infttrace.c variant of this function, we set the child's
730 event mask after the fork but before the exec. In the ptrace
731 world, it seems we can't set the event mask until after the exec. */
732 write (startup_semaphore.parent_channel[SEM_TALK],
734 sizeof (tc_magic_parent));
736 /* We'd better pause a bit before trying to set the event mask,
737 though, to ensure that the exec has happened. We don't want to
738 wait() on the child, because that'll screw up the upper layers
739 of gdb's execution control that expect to see the exec event.
741 After an exec, the child is no longer executing gdb code. Hence,
742 we can't have yet another synchronization via the pipes. We'll
743 just sleep for a second, and hope that's enough delay... */
746 /* Instruct the kernel as to the set of events we wish to be
748 require_notification_of_exec_events (pid);
750 /* Discard our copy of the semaphore. */
751 (void) close (startup_semaphore.parent_channel[SEM_LISTEN]);
752 (void) close (startup_semaphore.parent_channel[SEM_TALK]);
753 (void) close (startup_semaphore.child_channel[SEM_LISTEN]);
754 (void) close (startup_semaphore.child_channel[SEM_TALK]);
759 child_post_startup_inferior (pid)
762 require_notification_of_events (pid);
766 child_post_attach (pid)
769 require_notification_of_events (pid);
773 child_insert_fork_catchpoint (pid)
776 /* This request is only available on HPUX 10.0 and later. */
777 #if !defined(PT_SET_EVENT_MASK)
778 error ("Unable to catch forks prior to HPUX 10.0");
780 /* Enable reporting of fork events from the kernel. */
781 /* ??rehrauer: For the moment, we're always enabling these events,
782 and just ignoring them if there's no catchpoint to catch them. */
788 child_remove_fork_catchpoint (pid)
791 /* This request is only available on HPUX 10.0 and later. */
792 #if !defined(PT_SET_EVENT_MASK)
793 error ("Unable to catch forks prior to HPUX 10.0");
795 /* Disable reporting of fork events from the kernel. */
796 /* ??rehrauer: For the moment, we're always enabling these events,
797 and just ignoring them if there's no catchpoint to catch them. */
803 child_insert_vfork_catchpoint (pid)
806 /* This request is only available on HPUX 10.0 and later. */
807 #if !defined(PT_SET_EVENT_MASK)
808 error ("Unable to catch vforks prior to HPUX 10.0");
810 /* Enable reporting of vfork events from the kernel. */
811 /* ??rehrauer: For the moment, we're always enabling these events,
812 and just ignoring them if there's no catchpoint to catch them. */
818 child_remove_vfork_catchpoint (pid)
821 /* This request is only available on HPUX 10.0 and later. */
822 #if !defined(PT_SET_EVENT_MASK)
823 error ("Unable to catch vforks prior to HPUX 10.0");
825 /* Disable reporting of vfork events from the kernel. */
826 /* ??rehrauer: For the moment, we're always enabling these events,
827 and just ignoring them if there's no catchpoint to catch them. */
833 child_has_forked (pid, childpid)
837 /* This request is only available on HPUX 10.0 and later. */
838 #if !defined(PT_GET_PROCESS_STATE)
843 ptrace_state_t ptrace_state;
846 pt_status = call_ptrace (PT_GET_PROCESS_STATE,
848 (PTRACE_ARG3_TYPE) & ptrace_state,
849 sizeof (ptrace_state));
851 perror_with_name ("ptrace");
855 if (ptrace_state.pe_report_event & PTRACE_FORK)
857 *childpid = ptrace_state.pe_other_pid;
866 child_has_vforked (pid, childpid)
870 /* This request is only available on HPUX 10.0 and later. */
871 #if !defined(PT_GET_PROCESS_STATE)
877 ptrace_state_t ptrace_state;
880 pt_status = call_ptrace (PT_GET_PROCESS_STATE,
882 (PTRACE_ARG3_TYPE) & ptrace_state,
883 sizeof (ptrace_state));
885 perror_with_name ("ptrace");
889 if (ptrace_state.pe_report_event & PTRACE_VFORK)
891 *childpid = ptrace_state.pe_other_pid;
900 child_can_follow_vfork_prior_to_exec ()
902 /* ptrace doesn't allow this. */
907 child_insert_exec_catchpoint (pid)
910 /* This request is only available on HPUX 10.0 and later. */
911 #if !defined(PT_SET_EVENT_MASK)
912 error ("Unable to catch execs prior to HPUX 10.0");
915 /* Enable reporting of exec events from the kernel. */
916 /* ??rehrauer: For the moment, we're always enabling these events,
917 and just ignoring them if there's no catchpoint to catch them. */
923 child_remove_exec_catchpoint (pid)
926 /* This request is only available on HPUX 10.0 and later. */
927 #if !defined(PT_SET_EVENT_MASK)
928 error ("Unable to catch execs prior to HPUX 10.0");
931 /* Disable reporting of exec events from the kernel. */
932 /* ??rehrauer: For the moment, we're always enabling these events,
933 and just ignoring them if there's no catchpoint to catch them. */
939 child_has_execd (pid, execd_pathname)
941 char **execd_pathname;
943 /* This request is only available on HPUX 10.0 and later. */
944 #if !defined(PT_GET_PROCESS_STATE)
945 *execd_pathname = NULL;
950 ptrace_state_t ptrace_state;
953 pt_status = call_ptrace (PT_GET_PROCESS_STATE,
955 (PTRACE_ARG3_TYPE) & ptrace_state,
956 sizeof (ptrace_state));
958 perror_with_name ("ptrace");
962 if (ptrace_state.pe_report_event & PTRACE_EXEC)
964 char *exec_file = target_pid_to_exec_file (pid);
965 *execd_pathname = savestring (exec_file, strlen (exec_file));
974 child_reported_exec_events_per_exec_call ()
976 return 2; /* ptrace reports the event twice per call. */
980 child_has_syscall_event (pid, kind, syscall_id)
982 enum target_waitkind *kind;
985 /* This request is only available on HPUX 10.30 and later, via
986 the ttrace interface. */
988 *kind = TARGET_WAITKIND_SPURIOUS;
994 child_pid_to_exec_file (pid)
997 static char exec_file_buffer[1024];
999 CORE_ADDR top_of_stack;
1003 int saved_inferior_pid;
1006 #ifdef PT_GET_PROCESS_PATHNAME
1007 /* As of 10.x HP-UX, there's an explicit request to get the pathname. */
1008 pt_status = call_ptrace (PT_GET_PROCESS_PATHNAME,
1010 (PTRACE_ARG3_TYPE) exec_file_buffer,
1011 sizeof (exec_file_buffer) - 1);
1013 return exec_file_buffer;
1016 /* It appears that this request is broken prior to 10.30.
1017 If it fails, try a really, truly amazingly gross hack
1018 that DDE uses, of pawing through the process' data
1019 segment to find the pathname. */
1021 top_of_stack = 0x7b03a000;
1025 /* On the chance that pid != inferior_pid, set inferior_pid
1026 to pid, so that (grrrr!) implicit uses of inferior_pid get
1029 saved_inferior_pid = inferior_pid;
1032 /* Try to grab a null-terminated string. */
1035 if (target_read_memory (top_of_stack, four_chars, 4) != 0)
1037 inferior_pid = saved_inferior_pid;
1040 for (i = 0; i < 4; i++)
1042 exec_file_buffer[name_index++] = four_chars[i];
1043 done = (four_chars[i] == '\0');
1050 if (exec_file_buffer[0] == '\0')
1052 inferior_pid = saved_inferior_pid;
1056 inferior_pid = saved_inferior_pid;
1057 return exec_file_buffer;
1061 pre_fork_inferior ()
1065 status = pipe (startup_semaphore.parent_channel);
1068 warning ("error getting parent pipe for startup semaphore");
1072 status = pipe (startup_semaphore.child_channel);
1075 warning ("error getting child pipe for startup semaphore");
1081 /* Check to see if the given thread is alive.
1083 This is a no-op, as ptrace doesn't support threads, so we just
1087 child_thread_alive (pid)
1093 #endif /* ! GDB_NATIVE_HPUX_11 */