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>
34 #include "gdb_string.h"
37 extern int hpux_has_forked (int pid
, int *childpid
);
38 extern int hpux_has_vforked (int pid
, int *childpid
);
39 extern int hpux_has_execd (int pid
, char **execd_pathname
);
40 extern int hpux_has_syscall_event (int pid
, enum target_waitkind
*kind
,
43 static CORE_ADDR text_end
;
46 deprecated_hpux_text_end (struct target_ops
*exec_ops
)
48 struct section_table
*p
;
50 /* Set text_end to the highest address of the end of any readonly
52 /* FIXME: The comment above does not match the code. The code
53 checks for sections with are either code *or* readonly. */
54 text_end
= (CORE_ADDR
) 0;
55 for (p
= exec_ops
->to_sections
; p
< exec_ops
->to_sections_end
; p
++)
56 if (bfd_get_section_flags (p
->bfd
, p
->the_bfd_section
)
57 & (SEC_CODE
| SEC_READONLY
))
59 if (text_end
< p
->endaddr
)
60 text_end
= p
->endaddr
;
65 static void fetch_register (int);
68 fetch_inferior_registers (int regno
)
71 for (regno
= 0; regno
< NUM_REGS
; regno
++)
72 fetch_register (regno
);
74 fetch_register (regno
);
77 /* Our own version of the offsetof macro, since we can't assume ANSI C. */
78 #define HPPAH_OFFSETOF(type, member) ((int) (&((type *) 0)->member))
80 /* Store our register values back into the inferior.
81 If REGNO is -1, do this for all registers.
82 Otherwise, REGNO specifies which register (so we can save time). */
85 store_inferior_registers (int regno
)
90 unsigned int offset
= U_REGS_OFFSET
;
95 unsigned int addr
, len
, offset
;
97 if (CANNOT_STORE_REGISTER (regno
))
101 len
= REGISTER_RAW_SIZE (regno
);
103 /* Requests for register zero actually want the save_state's
104 ss_flags member. As RM says: "Oh, what a hack!" */
108 addr
= HPPAH_OFFSETOF (save_state_t
, ss_flags
);
109 len
= sizeof (ss
.ss_flags
);
111 /* Note that ss_flags is always an int, no matter what
112 REGISTER_RAW_SIZE(0) says. Assuming all HP-UX PA machines
113 are big-endian, put it at the least significant end of the
114 value, and zap the rest of the buffer. */
115 offset
= REGISTER_RAW_SIZE (0) - len
;
118 /* Floating-point registers come from the ss_fpblock area. */
119 else if (regno
>= FP0_REGNUM
)
120 addr
= (HPPAH_OFFSETOF (save_state_t
, ss_fpblock
)
121 + (DEPRECATED_REGISTER_BYTE (regno
) - DEPRECATED_REGISTER_BYTE (FP0_REGNUM
)));
123 /* Wide registers come from the ss_wide area.
124 I think it's more PC to test (ss_flags & SS_WIDEREGS) to select
125 between ss_wide and ss_narrow than to use the raw register size.
126 But checking ss_flags would require an extra ptrace call for
127 every register reference. Bleah. */
129 addr
= (HPPAH_OFFSETOF (save_state_t
, ss_wide
)
130 + DEPRECATED_REGISTER_BYTE (regno
));
132 /* Narrow registers come from the ss_narrow area. Note that
133 ss_narrow starts with gr1, not gr0. */
135 addr
= (HPPAH_OFFSETOF (save_state_t
, ss_narrow
)
136 + (DEPRECATED_REGISTER_BYTE (regno
) - DEPRECATED_REGISTER_BYTE (1)));
138 internal_error (__FILE__
, __LINE__
,
139 "hppah-nat.c (write_register): unexpected register size");
141 #ifdef GDB_TARGET_IS_HPPA_20W
142 /* Unbelieveable. The PC head and tail must be written in 64bit hunks
143 or we will get an error. Worse yet, the oddball ptrace/ttrace
144 layering will not allow us to perform a 64bit register store.
147 if (regno
== PCOQ_HEAD_REGNUM
|| regno
== PCOQ_TAIL_REGNUM
&& len
== 8)
151 temp
= *(CORE_ADDR
*)&deprecated_registers
[DEPRECATED_REGISTER_BYTE (regno
)];
153 /* Set the priv level (stored in the low two bits of the PC. */
156 ttrace_write_reg_64 (PIDGET (inferior_ptid
), (CORE_ADDR
)addr
,
159 /* If we fail to write the PC, give a true error instead of
163 char *err
= safe_strerror (errno
);
164 char *msg
= alloca (strlen (err
) + 128);
165 sprintf (msg
, "writing `%s' register: %s",
166 REGISTER_NAME (regno
), err
);
167 perror_with_name (msg
);
172 /* Another crock. HPUX complains if you write a nonzero value to
173 the high part of IPSW. What will it take for HP to catch a
174 clue about building sensible interfaces? */
175 if (regno
== IPSW_REGNUM
&& len
== 8)
176 *(int *)&deprecated_registers
[DEPRECATED_REGISTER_BYTE (regno
)] = 0;
179 for (i
= 0; i
< len
; i
+= sizeof (int))
182 call_ptrace (PT_WUREGS
, PIDGET (inferior_ptid
),
183 (PTRACE_ARG3_TYPE
) addr
+ i
,
184 *(int *) &deprecated_registers
[DEPRECATED_REGISTER_BYTE (regno
) + i
]);
187 /* Warning, not error, in case we are attached; sometimes
188 the kernel doesn't let us at the registers. */
189 char *err
= safe_strerror (errno
);
190 char *msg
= alloca (strlen (err
) + 128);
191 sprintf (msg
, "writing `%s' register: %s",
192 REGISTER_NAME (regno
), err
);
193 /* If we fail to write the PC, give a true error instead of
195 if (regno
== PCOQ_HEAD_REGNUM
|| regno
== PCOQ_TAIL_REGNUM
)
196 perror_with_name (msg
);
204 for (regno
= 0; regno
< NUM_REGS
; regno
++)
205 store_inferior_registers (regno
);
209 /* Fetch a register's value from the process's U area. */
211 fetch_register (int regno
)
213 char buf
[MAX_REGISTER_SIZE
];
214 unsigned int addr
, len
, offset
;
218 len
= REGISTER_RAW_SIZE (regno
);
220 /* Requests for register zero actually want the save_state's
221 ss_flags member. As RM says: "Oh, what a hack!" */
225 addr
= HPPAH_OFFSETOF (save_state_t
, ss_flags
);
226 len
= sizeof (ss
.ss_flags
);
228 /* Note that ss_flags is always an int, no matter what
229 REGISTER_RAW_SIZE(0) says. Assuming all HP-UX PA machines
230 are big-endian, put it at the least significant end of the
231 value, and zap the rest of the buffer. */
232 offset
= REGISTER_RAW_SIZE (0) - len
;
233 memset (buf
, 0, sizeof (buf
));
236 /* Floating-point registers come from the ss_fpblock area. */
237 else if (regno
>= FP0_REGNUM
)
238 addr
= (HPPAH_OFFSETOF (save_state_t
, ss_fpblock
)
239 + (DEPRECATED_REGISTER_BYTE (regno
) - DEPRECATED_REGISTER_BYTE (FP0_REGNUM
)));
241 /* Wide registers come from the ss_wide area.
242 I think it's more PC to test (ss_flags & SS_WIDEREGS) to select
243 between ss_wide and ss_narrow than to use the raw register size.
244 But checking ss_flags would require an extra ptrace call for
245 every register reference. Bleah. */
247 addr
= (HPPAH_OFFSETOF (save_state_t
, ss_wide
)
248 + DEPRECATED_REGISTER_BYTE (regno
));
250 /* Narrow registers come from the ss_narrow area. Note that
251 ss_narrow starts with gr1, not gr0. */
253 addr
= (HPPAH_OFFSETOF (save_state_t
, ss_narrow
)
254 + (DEPRECATED_REGISTER_BYTE (regno
) - DEPRECATED_REGISTER_BYTE (1)));
257 internal_error (__FILE__
, __LINE__
,
258 "hppa-nat.c (fetch_register): unexpected register size");
260 for (i
= 0; i
< len
; i
+= sizeof (int))
263 /* Copy an int from the U area to buf. Fill the least
264 significant end if len != raw_size. */
265 * (int *) &buf
[offset
+ i
] =
266 call_ptrace (PT_RUREGS
, PIDGET (inferior_ptid
),
267 (PTRACE_ARG3_TYPE
) addr
+ i
, 0);
270 /* Warning, not error, in case we are attached; sometimes
271 the kernel doesn't let us at the registers. */
272 char *err
= safe_strerror (errno
);
273 char *msg
= alloca (strlen (err
) + 128);
274 sprintf (msg
, "reading `%s' register: %s",
275 REGISTER_NAME (regno
), err
);
281 /* If we're reading an address from the instruction address queue,
282 mask out the bottom two bits --- they contain the privilege
284 if (regno
== PCOQ_HEAD_REGNUM
|| regno
== PCOQ_TAIL_REGNUM
)
285 buf
[len
- 1] &= ~0x3;
287 supply_register (regno
, buf
);
291 /* Copy LEN bytes to or from inferior's memory starting at MEMADDR
292 to debugger memory starting at MYADDR. Copy to inferior if
295 Returns the length copied, which is either the LEN argument or zero.
296 This xfer function does not do partial moves, since child_ops
297 doesn't allow memory operations to cross below us in the target stack
298 anyway. TARGET is ignored. */
301 child_xfer_memory (CORE_ADDR memaddr
, char *myaddr
, int len
, int write
,
302 struct mem_attrib
*mem
,
303 struct target_ops
*target
)
306 /* Round starting address down to longword boundary. */
307 CORE_ADDR addr
= memaddr
& - (CORE_ADDR
)(sizeof (int));
308 /* Round ending address up; get number of longwords that makes. */
310 = (((memaddr
+ len
) - addr
) + sizeof (int) - 1) / sizeof (int);
312 /* Allocate buffer of that many longwords.
313 Note -- do not use alloca to allocate this buffer since there is no
314 guarantee of when the buffer will actually be deallocated.
316 This routine can be called over and over with the same call chain;
317 this (in effect) would pile up all those alloca requests until a call
318 to alloca was made from a point higher than this routine in the
320 int *buffer
= (int *) xmalloc (count
* sizeof (int));
324 /* Fill start and end extra bytes of buffer with existing memory data. */
325 if (addr
!= memaddr
|| len
< (int) sizeof (int))
327 /* Need part of initial word -- fetch it. */
328 buffer
[0] = call_ptrace (addr
< text_end
? PT_RIUSER
: PT_RDUSER
,
329 PIDGET (inferior_ptid
),
330 (PTRACE_ARG3_TYPE
) addr
, 0);
333 if (count
> 1) /* FIXME, avoid if even boundary */
336 = call_ptrace (addr
< text_end
? PT_RIUSER
: PT_RDUSER
,
337 PIDGET (inferior_ptid
),
338 (PTRACE_ARG3_TYPE
) (addr
339 + (count
- 1) * sizeof (int)),
343 /* Copy data to be written over corresponding part of buffer */
344 memcpy ((char *) buffer
+ (memaddr
& (sizeof (int) - 1)), myaddr
, len
);
346 /* Write the entire buffer. */
347 for (i
= 0; i
< count
; i
++, addr
+= sizeof (int))
351 /* The HP-UX kernel crashes if you use PT_WDUSER to write into the
352 text segment. FIXME -- does it work to write into the data
353 segment using WIUSER, or do these idiots really expect us to
354 figure out which segment the address is in, so we can use a
355 separate system call for it??! */
357 pt_request
= (addr
< text_end
) ? PT_WIUSER
: PT_WDUSER
;
358 pt_status
= call_ptrace (pt_request
,
359 PIDGET (inferior_ptid
),
360 (PTRACE_ARG3_TYPE
) addr
,
363 /* Did we fail? Might we've guessed wrong about which
364 segment this address resides in? Try the other request,
365 and see if that works... */
366 if ((pt_status
== -1) && errno
)
369 pt_request
= (pt_request
== PT_WIUSER
) ? PT_WDUSER
: PT_WIUSER
;
370 pt_status
= call_ptrace (pt_request
,
371 PIDGET (inferior_ptid
),
372 (PTRACE_ARG3_TYPE
) addr
,
375 /* No, we still fail. Okay, time to punt. */
376 if ((pt_status
== -1) && errno
)
386 /* Read all the longwords */
387 for (i
= 0; i
< count
; i
++, addr
+= sizeof (int))
390 buffer
[i
] = call_ptrace (addr
< text_end
? PT_RIUSER
: PT_RDUSER
,
391 PIDGET (inferior_ptid
),
392 (PTRACE_ARG3_TYPE
) addr
, 0);
401 /* Copy appropriate bytes out of the buffer. */
402 memcpy (myaddr
, (char *) buffer
+ (memaddr
& (sizeof (int) - 1)), len
);
408 char *saved_child_execd_pathname
= NULL
;
416 } saved_vfork_state
= STATE_NONE
;
419 child_follow_fork (int follow_child
)
422 struct target_waitstatus last_status
;
424 int parent_pid
, child_pid
;
426 get_last_target_status (&last_ptid
, &last_status
);
427 has_vforked
= (last_status
.kind
== TARGET_WAITKIND_VFORKED
);
428 parent_pid
= ptid_get_pid (last_ptid
);
429 child_pid
= last_status
.value
.related_pid
;
431 /* At this point, if we are vforking, breakpoints were already
432 detached from the child in child_wait; and the child has already
433 called execve(). If we are forking, both the parent and child
434 have breakpoints inserted. */
440 detach_breakpoints (child_pid
);
441 #ifdef SOLIB_REMOVE_INFERIOR_HOOK
442 SOLIB_REMOVE_INFERIOR_HOOK (child_pid
);
446 /* Detach from the child. */
447 printf_unfiltered ("Detaching after fork from %s\n",
448 target_pid_to_str (pid_to_ptid (child_pid
)));
449 hppa_require_detach (child_pid
, 0);
451 /* The parent and child of a vfork share the same address space.
452 Also, on some targets the order in which vfork and exec events
453 are received for parent in child requires some delicate handling
456 For instance, on ptrace-based HPUX we receive the child's vfork
457 event first, at which time the parent has been suspended by the
458 OS and is essentially untouchable until the child's exit or second
459 exec event arrives. At that time, the parent's vfork event is
460 delivered to us, and that's when we see and decide how to follow
461 the vfork. But to get to that point, we must continue the child
462 until it execs or exits. To do that smoothly, all breakpoints
463 must be removed from the child, in case there are any set between
464 the vfork() and exec() calls. But removing them from the child
465 also removes them from the parent, due to the shared-address-space
466 nature of a vfork'd parent and child. On HPUX, therefore, we must
467 take care to restore the bp's to the parent before we continue it.
468 Else, it's likely that we may not stop in the expected place. (The
469 worst scenario is when the user tries to step over a vfork() call;
470 the step-resume bp must be restored for the step to properly stop
471 in the parent after the call completes!)
473 Sequence of events, as reported to gdb from HPUX:
475 Parent Child Action for gdb to take
476 -------------------------------------------------------
477 1 VFORK Continue child
482 Now that the child has safely exec'd or exited, we must restore
483 the parent's breakpoints before we continue it. Else, we may
484 cause it run past expected stopping points. */
487 reattach_breakpoints (parent_pid
);
491 /* Needed to keep the breakpoint lists in sync. */
493 detach_breakpoints (child_pid
);
495 /* Before detaching from the parent, remove all breakpoints from it. */
496 remove_breakpoints ();
498 /* Also reset the solib inferior hook from the parent. */
499 #ifdef SOLIB_REMOVE_INFERIOR_HOOK
500 SOLIB_REMOVE_INFERIOR_HOOK (PIDGET (inferior_ptid
));
503 /* Detach from the parent. */
504 target_detach (NULL
, 1);
506 /* Attach to the child. */
507 printf_unfiltered ("Attaching after fork to %s\n",
508 target_pid_to_str (pid_to_ptid (child_pid
)));
509 hppa_require_attach (child_pid
);
510 inferior_ptid
= pid_to_ptid (child_pid
);
512 /* If we vforked, then we've also execed by now. The exec will be
513 reported momentarily. follow_exec () will handle breakpoints, so
514 we don't have to.. */
516 follow_inferior_reset_breakpoints ();
521 /* If we followed the parent, don't try to follow the child's exec. */
522 if (saved_vfork_state
!= STATE_GOT_PARENT
523 && saved_vfork_state
!= STATE_FAKE_EXEC
)
524 fprintf_unfiltered (gdb_stdout
,
525 "hppa: post follow vfork: confused state\n");
527 if (! follow_child
|| saved_vfork_state
== STATE_GOT_PARENT
)
528 saved_vfork_state
= STATE_NONE
;
535 /* Format a process id, given PID. Be sure to terminate
536 this with a null--it's going to be printed via a "%s". */
538 child_pid_to_str (ptid_t ptid
)
540 /* Static because address returned */
542 pid_t pid
= PIDGET (ptid
);
544 /* Extra NUL for paranoia's sake */
545 sprintf (buf
, "process %d%c", pid
, '\0');
550 /* Format a thread id, given TID. Be sure to terminate
551 this with a null--it's going to be printed via a "%s".
553 Note: This is a core-gdb tid, not the actual system tid.
554 See infttrace.c for details. */
556 hppa_tid_to_str (ptid_t ptid
)
558 /* Static because address returned */
560 /* This seems strange, but when I did the ptid conversion, it looked
561 as though a pid was always being passed. - Kevin Buettner */
562 pid_t tid
= PIDGET (ptid
);
564 /* Extra NULLs for paranoia's sake */
565 sprintf (buf
, "system thread %d%c", tid
, '\0');
571 /* Enable HACK for ttrace work. In
572 * infttrace.c/require_notification_of_events,
573 * this is set to 0 so that the loop in child_wait
576 int not_same_real_pid
= 1;
579 /* Wait for child to do something. Return pid of child, or -1 in case
580 of error; store status through argument pointer OURSTATUS. */
583 child_wait (ptid_t ptid
, struct target_waitstatus
*ourstatus
)
587 char *execd_pathname
= NULL
;
591 enum target_waitkind kind
;
594 if (saved_vfork_state
== STATE_FAKE_EXEC
)
596 saved_vfork_state
= STATE_NONE
;
597 ourstatus
->kind
= TARGET_WAITKIND_EXECD
;
598 ourstatus
->value
.execd_pathname
= saved_child_execd_pathname
;
599 return inferior_ptid
;
604 set_sigint_trap (); /* Causes SIGINT to be passed on to the
608 pid
= ptrace_wait (inferior_ptid
, &status
);
614 clear_sigint_trap ();
618 if (save_errno
== EINTR
)
621 fprintf_unfiltered (gdb_stderr
, "Child process unexpectedly missing: %s.\n",
622 safe_strerror (save_errno
));
624 /* Claim it exited with unknown signal. */
625 ourstatus
->kind
= TARGET_WAITKIND_SIGNALLED
;
626 ourstatus
->value
.sig
= TARGET_SIGNAL_UNKNOWN
;
627 return pid_to_ptid (-1);
632 if (target_has_exited (pid
, status
, &exit_status
))
634 /* ??rehrauer: For now, ignore this. */
638 if (!target_thread_alive (pid_to_ptid (pid
)))
640 ourstatus
->kind
= TARGET_WAITKIND_SPURIOUS
;
641 return pid_to_ptid (pid
);
644 if (hpux_has_forked (pid
, &related_pid
))
646 /* Ignore the parent's fork event. */
647 if (pid
== PIDGET (inferior_ptid
))
649 ourstatus
->kind
= TARGET_WAITKIND_IGNORE
;
650 return inferior_ptid
;
653 /* If this is the child's fork event, report that the
654 process has forked. */
655 if (related_pid
== PIDGET (inferior_ptid
))
657 ourstatus
->kind
= TARGET_WAITKIND_FORKED
;
658 ourstatus
->value
.related_pid
= pid
;
659 return inferior_ptid
;
663 if (hpux_has_vforked (pid
, &related_pid
))
665 if (pid
== PIDGET (inferior_ptid
))
667 if (saved_vfork_state
== STATE_GOT_CHILD
)
668 saved_vfork_state
= STATE_GOT_PARENT
;
669 else if (saved_vfork_state
== STATE_GOT_EXEC
)
670 saved_vfork_state
= STATE_FAKE_EXEC
;
672 fprintf_unfiltered (gdb_stdout
,
673 "hppah: parent vfork: confused\n");
675 else if (related_pid
== PIDGET (inferior_ptid
))
677 if (saved_vfork_state
== STATE_NONE
)
678 saved_vfork_state
= STATE_GOT_CHILD
;
680 fprintf_unfiltered (gdb_stdout
,
681 "hppah: child vfork: confused\n");
684 fprintf_unfiltered (gdb_stdout
,
685 "hppah: unknown vfork: confused\n");
687 if (saved_vfork_state
== STATE_GOT_CHILD
)
689 child_post_startup_inferior (pid_to_ptid (pid
));
690 detach_breakpoints (pid
);
691 #ifdef SOLIB_REMOVE_INFERIOR_HOOK
692 SOLIB_REMOVE_INFERIOR_HOOK (pid
);
694 child_resume (pid_to_ptid (pid
), 0, TARGET_SIGNAL_0
);
695 ourstatus
->kind
= TARGET_WAITKIND_IGNORE
;
696 return pid_to_ptid (related_pid
);
698 else if (saved_vfork_state
== STATE_FAKE_EXEC
)
700 ourstatus
->kind
= TARGET_WAITKIND_VFORKED
;
701 ourstatus
->value
.related_pid
= related_pid
;
702 return pid_to_ptid (pid
);
706 /* We saw the parent's vfork, but we haven't seen the exec yet.
707 Wait for it, for simplicity's sake. It should be pending. */
708 saved_vfork_pid
= related_pid
;
709 ourstatus
->kind
= TARGET_WAITKIND_IGNORE
;
710 return pid_to_ptid (pid
);
714 if (hpux_has_execd (pid
, &execd_pathname
))
716 /* On HP-UX, events associated with a vforking inferior come in
717 threes: a vfork event for the child (always first), followed
718 a vfork event for the parent and an exec event for the child.
719 The latter two can come in either order. Make sure we get
721 if (saved_vfork_state
!= STATE_NONE
)
723 if (saved_vfork_state
== STATE_GOT_CHILD
)
725 saved_vfork_state
= STATE_GOT_EXEC
;
726 /* On HP/UX with ptrace, the child must be resumed before
727 the parent vfork event is delivered. A single-step
729 if (RESUME_EXECD_VFORKING_CHILD_TO_GET_PARENT_VFORK ())
730 target_resume (pid_to_ptid (pid
), 1, TARGET_SIGNAL_0
);
731 ourstatus
->kind
= TARGET_WAITKIND_IGNORE
;
733 else if (saved_vfork_state
== STATE_GOT_PARENT
)
735 saved_vfork_state
= STATE_FAKE_EXEC
;
736 ourstatus
->kind
= TARGET_WAITKIND_VFORKED
;
737 ourstatus
->value
.related_pid
= saved_vfork_pid
;
740 fprintf_unfiltered (gdb_stdout
,
741 "hppa: exec: unexpected state\n");
743 saved_child_execd_pathname
= execd_pathname
;
745 return inferior_ptid
;
748 /* Are we ignoring initial exec events? (This is likely because
749 we're in the process of starting up the inferior, and another
750 (older) mechanism handles those.) If so, we'll report this
751 as a regular stop, not an exec.
753 if (inferior_ignoring_startup_exec_events
)
755 inferior_ignoring_startup_exec_events
--;
759 ourstatus
->kind
= TARGET_WAITKIND_EXECD
;
760 ourstatus
->value
.execd_pathname
= execd_pathname
;
761 return pid_to_ptid (pid
);
765 /* All we must do with these is communicate their occurrence
766 to wait_for_inferior...
768 if (hpux_has_syscall_event (pid
, &kind
, &syscall_id
))
770 ourstatus
->kind
= kind
;
771 ourstatus
->value
.syscall_id
= syscall_id
;
772 return pid_to_ptid (pid
);
775 /*## } while (pid != PIDGET (inferior_ptid)); ## *//* Some other child died or stopped */
776 /* hack for thread testing */
778 while ((pid
!= PIDGET (inferior_ptid
)) && not_same_real_pid
);
781 store_waitstatus (ourstatus
, status
);
782 return pid_to_ptid (pid
);
785 #if !defined (GDB_NATIVE_HPUX_11)
787 /* The following code is a substitute for the infttrace.c versions used
788 with ttrace() in HPUX 11. */
790 /* This value is an arbitrary integer. */
791 #define PT_VERSION 123456
793 /* This semaphore is used to coordinate the child and parent processes
794 after a fork(), and before an exec() by the child. See
795 parent_attach_all for details. */
799 int parent_channel
[2]; /* Parent "talks" to [1], child "listens" to [0] */
800 int child_channel
[2]; /* Child "talks" to [1], parent "listens" to [0] */
805 #define SEM_LISTEN (0)
807 static startup_semaphore_t startup_semaphore
;
810 /* This function causes the caller's process to be traced by its
811 parent. This is intended to be called after GDB forks itself,
812 and before the child execs the target.
814 Note that HP-UX ptrace is rather funky in how this is done.
815 If the parent wants to get the initial exec event of a child,
816 it must set the ptrace event mask of the child to include execs.
817 (The child cannot do this itself.) This must be done after the
818 child is forked, but before it execs.
820 To coordinate the parent and child, we implement a semaphore using
821 pipes. After SETTRC'ing itself, the child tells the parent that
822 it is now traceable by the parent, and waits for the parent's
823 acknowledgement. The parent can then set the child's event mask,
824 and notify the child that it can now exec.
826 (The acknowledgement by parent happens as a result of a call to
827 child_acknowledge_created_inferior.) */
830 parent_attach_all (int pid
, PTRACE_ARG3_TYPE addr
, int data
)
834 /* We need a memory home for a constant. */
835 int tc_magic_child
= PT_VERSION
;
836 int tc_magic_parent
= 0;
838 /* The remainder of this function is only useful for HPUX 10.0 and
839 later, as it depends upon the ability to request notification
840 of specific kinds of events by the kernel. */
841 #if defined(PT_SET_EVENT_MASK)
843 /* Notify the parent that we're potentially ready to exec(). */
844 write (startup_semaphore
.child_channel
[SEM_TALK
],
846 sizeof (tc_magic_child
));
848 /* Wait for acknowledgement from the parent. */
849 read (startup_semaphore
.parent_channel
[SEM_LISTEN
],
851 sizeof (tc_magic_parent
));
852 if (tc_magic_child
!= tc_magic_parent
)
853 warning ("mismatched semaphore magic");
855 /* Discard our copy of the semaphore. */
856 (void) close (startup_semaphore
.parent_channel
[SEM_LISTEN
]);
857 (void) close (startup_semaphore
.parent_channel
[SEM_TALK
]);
858 (void) close (startup_semaphore
.child_channel
[SEM_LISTEN
]);
859 (void) close (startup_semaphore
.child_channel
[SEM_TALK
]);
867 hppa_require_attach (int pid
)
872 unsigned int regs_offset
;
874 /* Are we already attached? There appears to be no explicit way to
875 answer this via ptrace, so we try something which should be
876 innocuous if we are attached. If that fails, then we assume
877 we're not attached, and so attempt to make it so. */
880 regs_offset
= U_REGS_OFFSET
;
881 pc_addr
= register_addr (PC_REGNUM
, regs_offset
);
882 pc
= call_ptrace (PT_READ_U
, pid
, (PTRACE_ARG3_TYPE
) pc_addr
, 0);
887 pt_status
= call_ptrace (PT_ATTACH
, pid
, (PTRACE_ARG3_TYPE
) 0, 0);
892 /* Now we really are attached. */
900 hppa_require_detach (int pid
, int signal
)
903 call_ptrace (PT_DETACH
, pid
, (PTRACE_ARG3_TYPE
) 1, signal
);
904 errno
= 0; /* Ignore any errors. */
908 /* Since ptrace doesn't support memory page-protection events, which
909 are used to implement "hardware" watchpoints on HP-UX, these are
910 dummy versions, which perform no useful work. */
913 hppa_enable_page_protection_events (int pid
)
918 hppa_disable_page_protection_events (int pid
)
923 hppa_insert_hw_watchpoint (int pid
, CORE_ADDR start
, LONGEST len
, int type
)
925 error ("Hardware watchpoints not implemented on this platform.");
929 hppa_remove_hw_watchpoint (int pid
, CORE_ADDR start
, LONGEST len
, int type
)
931 error ("Hardware watchpoints not implemented on this platform.");
935 hppa_can_use_hw_watchpoint (int type
, int cnt
, int ot
)
941 hppa_range_profitable_for_hw_watchpoint (int pid
, CORE_ADDR start
, LONGEST len
)
943 error ("Hardware watchpoints not implemented on this platform.");
947 hppa_pid_or_tid_to_str (ptid_t id
)
949 /* In the ptrace world, there are only processes. */
950 return child_pid_to_str (id
);
954 hppa_ensure_vforking_parent_remains_stopped (int pid
)
956 /* This assumes that the vforked parent is presently stopped, and
957 that the vforked child has just delivered its first exec event.
958 Calling kill() this way will cause the SIGTRAP to be delivered as
959 soon as the parent is resumed, which happens as soon as the
960 vforked child is resumed. See wait_for_inferior for the use of
966 hppa_resume_execd_vforking_child_to_get_parent_vfork (void)
968 return 1; /* Yes, the child must be resumed. */
972 require_notification_of_events (int pid
)
974 #if defined(PT_SET_EVENT_MASK)
976 ptrace_event_t ptrace_events
;
980 /* Instruct the kernel as to the set of events we wish to be
981 informed of. (This support does not exist before HPUX 10.0.
982 We'll assume if PT_SET_EVENT_MASK has not been defined by
983 <sys/ptrace.h>, then we're being built on pre-10.0.) */
984 memset (&ptrace_events
, 0, sizeof (ptrace_events
));
986 /* Note: By default, all signals are visible to us. If we wish
987 the kernel to keep certain signals hidden from us, we do it
988 by calling sigdelset (ptrace_events.pe_signals, signal) for
989 each such signal here, before doing PT_SET_EVENT_MASK. */
990 /* RM: The above comment is no longer true. We start with ignoring
991 all signals, and then add the ones we are interested in. We could
992 do it the other way: start by looking at all signals and then
993 deleting the ones that we aren't interested in, except that
994 multiple gdb signals may be mapped to the same host signal
995 (eg. TARGET_SIGNAL_IO and TARGET_SIGNAL_POLL both get mapped to
996 signal 22 on HPUX 10.20) We want to be notified if we are
997 interested in either signal. */
998 sigfillset (&ptrace_events
.pe_signals
);
1000 /* RM: Let's not bother with signals we don't care about */
1001 nsigs
= (int) TARGET_SIGNAL_LAST
;
1002 for (signum
= nsigs
; signum
> 0; signum
--)
1004 if ((signal_stop_state (signum
)) ||
1005 (signal_print_state (signum
)) ||
1006 (!signal_pass_state (signum
)))
1008 if (target_signal_to_host_p (signum
))
1009 sigdelset (&ptrace_events
.pe_signals
,
1010 target_signal_to_host (signum
));
1014 ptrace_events
.pe_set_event
= 0;
1016 ptrace_events
.pe_set_event
|= PTRACE_SIGNAL
;
1017 ptrace_events
.pe_set_event
|= PTRACE_EXEC
;
1018 ptrace_events
.pe_set_event
|= PTRACE_FORK
;
1019 ptrace_events
.pe_set_event
|= PTRACE_VFORK
;
1020 /* ??rehrauer: Add this one when we're prepared to catch it...
1021 ptrace_events.pe_set_event |= PTRACE_EXIT;
1025 pt_status
= call_ptrace (PT_SET_EVENT_MASK
,
1027 (PTRACE_ARG3_TYPE
) & ptrace_events
,
1028 sizeof (ptrace_events
));
1030 perror_with_name ("ptrace");
1037 require_notification_of_exec_events (int pid
)
1039 #if defined(PT_SET_EVENT_MASK)
1041 ptrace_event_t ptrace_events
;
1043 /* Instruct the kernel as to the set of events we wish to be
1044 informed of. (This support does not exist before HPUX 10.0.
1045 We'll assume if PT_SET_EVENT_MASK has not been defined by
1046 <sys/ptrace.h>, then we're being built on pre-10.0.) */
1047 memset (&ptrace_events
, 0, sizeof (ptrace_events
));
1049 /* Note: By default, all signals are visible to us. If we wish
1050 the kernel to keep certain signals hidden from us, we do it
1051 by calling sigdelset (ptrace_events.pe_signals, signal) for
1052 each such signal here, before doing PT_SET_EVENT_MASK. */
1053 sigemptyset (&ptrace_events
.pe_signals
);
1055 ptrace_events
.pe_set_event
= 0;
1057 ptrace_events
.pe_set_event
|= PTRACE_EXEC
;
1058 /* ??rehrauer: Add this one when we're prepared to catch it...
1059 ptrace_events.pe_set_event |= PTRACE_EXIT;
1063 pt_status
= call_ptrace (PT_SET_EVENT_MASK
,
1065 (PTRACE_ARG3_TYPE
) & ptrace_events
,
1066 sizeof (ptrace_events
));
1068 perror_with_name ("ptrace");
1074 /* This function is called by the parent process, with pid being the
1075 ID of the child process, after the debugger has forked. */
1078 child_acknowledge_created_inferior (int pid
)
1080 /* We need a memory home for a constant. */
1081 int tc_magic_parent
= PT_VERSION
;
1082 int tc_magic_child
= 0;
1084 /* The remainder of this function is only useful for HPUX 10.0 and
1085 later, as it depends upon the ability to request notification
1086 of specific kinds of events by the kernel. */
1087 #if defined(PT_SET_EVENT_MASK)
1088 /* Wait for the child to tell us that it has forked. */
1089 read (startup_semaphore
.child_channel
[SEM_LISTEN
],
1091 sizeof (tc_magic_child
));
1093 /* Notify the child that it can exec.
1095 In the infttrace.c variant of this function, we set the child's
1096 event mask after the fork but before the exec. In the ptrace
1097 world, it seems we can't set the event mask until after the exec. */
1098 write (startup_semaphore
.parent_channel
[SEM_TALK
],
1100 sizeof (tc_magic_parent
));
1102 /* We'd better pause a bit before trying to set the event mask,
1103 though, to ensure that the exec has happened. We don't want to
1104 wait() on the child, because that'll screw up the upper layers
1105 of gdb's execution control that expect to see the exec event.
1107 After an exec, the child is no longer executing gdb code. Hence,
1108 we can't have yet another synchronization via the pipes. We'll
1109 just sleep for a second, and hope that's enough delay... */
1112 /* Instruct the kernel as to the set of events we wish to be
1114 require_notification_of_exec_events (pid
);
1116 /* Discard our copy of the semaphore. */
1117 (void) close (startup_semaphore
.parent_channel
[SEM_LISTEN
]);
1118 (void) close (startup_semaphore
.parent_channel
[SEM_TALK
]);
1119 (void) close (startup_semaphore
.child_channel
[SEM_LISTEN
]);
1120 (void) close (startup_semaphore
.child_channel
[SEM_TALK
]);
1125 child_post_startup_inferior (ptid_t ptid
)
1127 require_notification_of_events (PIDGET (ptid
));
1131 child_post_attach (int pid
)
1133 require_notification_of_events (pid
);
1137 child_insert_fork_catchpoint (int pid
)
1139 /* This request is only available on HPUX 10.0 and later. */
1140 #if !defined(PT_SET_EVENT_MASK)
1141 error ("Unable to catch forks prior to HPUX 10.0");
1143 /* Enable reporting of fork events from the kernel. */
1144 /* ??rehrauer: For the moment, we're always enabling these events,
1145 and just ignoring them if there's no catchpoint to catch them. */
1151 child_remove_fork_catchpoint (int pid
)
1153 /* This request is only available on HPUX 10.0 and later. */
1154 #if !defined(PT_SET_EVENT_MASK)
1155 error ("Unable to catch forks prior to HPUX 10.0");
1157 /* Disable reporting of fork events from the kernel. */
1158 /* ??rehrauer: For the moment, we're always enabling these events,
1159 and just ignoring them if there's no catchpoint to catch them. */
1165 child_insert_vfork_catchpoint (int pid
)
1167 /* This request is only available on HPUX 10.0 and later. */
1168 #if !defined(PT_SET_EVENT_MASK)
1169 error ("Unable to catch vforks prior to HPUX 10.0");
1171 /* Enable reporting of vfork events from the kernel. */
1172 /* ??rehrauer: For the moment, we're always enabling these events,
1173 and just ignoring them if there's no catchpoint to catch them. */
1179 child_remove_vfork_catchpoint (int pid
)
1181 /* This request is only available on HPUX 10.0 and later. */
1182 #if !defined(PT_SET_EVENT_MASK)
1183 error ("Unable to catch vforks prior to HPUX 10.0");
1185 /* Disable reporting of vfork events from the kernel. */
1186 /* ??rehrauer: For the moment, we're always enabling these events,
1187 and just ignoring them if there's no catchpoint to catch them. */
1193 hpux_has_forked (int pid
, int *childpid
)
1195 /* This request is only available on HPUX 10.0 and later. */
1196 #if !defined(PT_GET_PROCESS_STATE)
1201 ptrace_state_t ptrace_state
;
1204 pt_status
= call_ptrace (PT_GET_PROCESS_STATE
,
1206 (PTRACE_ARG3_TYPE
) & ptrace_state
,
1207 sizeof (ptrace_state
));
1209 perror_with_name ("ptrace");
1213 if (ptrace_state
.pe_report_event
& PTRACE_FORK
)
1215 *childpid
= ptrace_state
.pe_other_pid
;
1224 hpux_has_vforked (int pid
, int *childpid
)
1226 /* This request is only available on HPUX 10.0 and later. */
1227 #if !defined(PT_GET_PROCESS_STATE)
1233 ptrace_state_t ptrace_state
;
1236 pt_status
= call_ptrace (PT_GET_PROCESS_STATE
,
1238 (PTRACE_ARG3_TYPE
) & ptrace_state
,
1239 sizeof (ptrace_state
));
1241 perror_with_name ("ptrace");
1245 if (ptrace_state
.pe_report_event
& PTRACE_VFORK
)
1247 *childpid
= ptrace_state
.pe_other_pid
;
1256 child_insert_exec_catchpoint (int pid
)
1258 /* This request is only available on HPUX 10.0 and later. */
1259 #if !defined(PT_SET_EVENT_MASK)
1260 error ("Unable to catch execs prior to HPUX 10.0");
1263 /* Enable reporting of exec events from the kernel. */
1264 /* ??rehrauer: For the moment, we're always enabling these events,
1265 and just ignoring them if there's no catchpoint to catch them. */
1271 child_remove_exec_catchpoint (int pid
)
1273 /* This request is only available on HPUX 10.0 and later. */
1274 #if !defined(PT_SET_EVENT_MASK)
1275 error ("Unable to catch execs prior to HPUX 10.0");
1278 /* Disable reporting of exec events from the kernel. */
1279 /* ??rehrauer: For the moment, we're always enabling these events,
1280 and just ignoring them if there's no catchpoint to catch them. */
1286 hpux_has_execd (int pid
, char **execd_pathname
)
1288 /* This request is only available on HPUX 10.0 and later. */
1289 #if !defined(PT_GET_PROCESS_STATE)
1290 *execd_pathname
= NULL
;
1295 ptrace_state_t ptrace_state
;
1298 pt_status
= call_ptrace (PT_GET_PROCESS_STATE
,
1300 (PTRACE_ARG3_TYPE
) & ptrace_state
,
1301 sizeof (ptrace_state
));
1303 perror_with_name ("ptrace");
1307 if (ptrace_state
.pe_report_event
& PTRACE_EXEC
)
1309 char *exec_file
= target_pid_to_exec_file (pid
);
1310 *execd_pathname
= savestring (exec_file
, strlen (exec_file
));
1319 child_reported_exec_events_per_exec_call (void)
1321 return 2; /* ptrace reports the event twice per call. */
1325 hpux_has_syscall_event (int pid
, enum target_waitkind
*kind
, int *syscall_id
)
1327 /* This request is only available on HPUX 10.30 and later, via
1328 the ttrace interface. */
1330 *kind
= TARGET_WAITKIND_SPURIOUS
;
1336 child_pid_to_exec_file (int pid
)
1338 static char exec_file_buffer
[1024];
1340 CORE_ADDR top_of_stack
;
1344 ptid_t saved_inferior_ptid
;
1347 #ifdef PT_GET_PROCESS_PATHNAME
1348 /* As of 10.x HP-UX, there's an explicit request to get the pathname. */
1349 pt_status
= call_ptrace (PT_GET_PROCESS_PATHNAME
,
1351 (PTRACE_ARG3_TYPE
) exec_file_buffer
,
1352 sizeof (exec_file_buffer
) - 1);
1354 return exec_file_buffer
;
1357 /* It appears that this request is broken prior to 10.30.
1358 If it fails, try a really, truly amazingly gross hack
1359 that DDE uses, of pawing through the process' data
1360 segment to find the pathname. */
1362 top_of_stack
= 0x7b03a000;
1366 /* On the chance that pid != inferior_ptid, set inferior_ptid
1367 to pid, so that (grrrr!) implicit uses of inferior_ptid get
1370 saved_inferior_ptid
= inferior_ptid
;
1371 inferior_ptid
= pid_to_ptid (pid
);
1373 /* Try to grab a null-terminated string. */
1376 if (target_read_memory (top_of_stack
, four_chars
, 4) != 0)
1378 inferior_ptid
= saved_inferior_ptid
;
1381 for (i
= 0; i
< 4; i
++)
1383 exec_file_buffer
[name_index
++] = four_chars
[i
];
1384 done
= (four_chars
[i
] == '\0');
1391 if (exec_file_buffer
[0] == '\0')
1393 inferior_ptid
= saved_inferior_ptid
;
1397 inferior_ptid
= saved_inferior_ptid
;
1398 return exec_file_buffer
;
1402 pre_fork_inferior (void)
1406 status
= pipe (startup_semaphore
.parent_channel
);
1409 warning ("error getting parent pipe for startup semaphore");
1413 status
= pipe (startup_semaphore
.child_channel
);
1416 warning ("error getting child pipe for startup semaphore");
1422 /* Check to see if the given thread is alive.
1424 This is a no-op, as ptrace doesn't support threads, so we just
1428 child_thread_alive (ptid_t ptid
)
1433 #endif /* ! GDB_NATIVE_HPUX_11 */