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"
35 #include "infttrace.h"
38 #include "hppa-tdep.h"
40 static CORE_ADDR text_end
;
43 deprecated_hpux_text_end (struct target_ops
*exec_ops
)
45 struct section_table
*p
;
47 /* Set text_end to the highest address of the end of any readonly
49 /* FIXME: The comment above does not match the code. The code
50 checks for sections with are either code *or* readonly. */
51 text_end
= (CORE_ADDR
) 0;
52 for (p
= exec_ops
->to_sections
; p
< exec_ops
->to_sections_end
; p
++)
53 if (bfd_get_section_flags (p
->bfd
, p
->the_bfd_section
)
54 & (SEC_CODE
| SEC_READONLY
))
56 if (text_end
< p
->endaddr
)
57 text_end
= p
->endaddr
;
62 static void fetch_register (int);
65 fetch_inferior_registers (int regno
)
68 for (regno
= 0; regno
< NUM_REGS
; regno
++)
69 fetch_register (regno
);
71 fetch_register (regno
);
74 /* Our own version of the offsetof macro, since we can't assume ANSI C. */
75 #define HPPAH_OFFSETOF(type, member) ((int) (&((type *) 0)->member))
77 /* Store our register values back into the inferior.
78 If REGNO is -1, do this for all registers.
79 Otherwise, REGNO specifies which register (so we can save time). */
82 store_inferior_registers (int regno
)
87 unsigned int offset
= U_REGS_OFFSET
;
92 unsigned int addr
, len
, offset
;
94 if (CANNOT_STORE_REGISTER (regno
))
98 len
= DEPRECATED_REGISTER_RAW_SIZE (regno
);
100 /* Requests for register zero actually want the save_state's
101 ss_flags member. As RM says: "Oh, what a hack!" */
105 addr
= HPPAH_OFFSETOF (save_state_t
, ss_flags
);
106 len
= sizeof (ss
.ss_flags
);
108 /* Note that ss_flags is always an int, no matter what
109 DEPRECATED_REGISTER_RAW_SIZE(0) says. Assuming all HP-UX
110 PA machines are big-endian, put it at the least
111 significant end of the value, and zap the rest of the
113 offset
= DEPRECATED_REGISTER_RAW_SIZE (0) - len
;
116 /* Floating-point registers come from the ss_fpblock area. */
117 else if (regno
>= HPPA_FP0_REGNUM
)
118 addr
= (HPPAH_OFFSETOF (save_state_t
, ss_fpblock
)
119 + (DEPRECATED_REGISTER_BYTE (regno
) - DEPRECATED_REGISTER_BYTE (HPPA_FP0_REGNUM
)));
121 /* Wide registers come from the ss_wide area.
122 I think it's more PC to test (ss_flags & SS_WIDEREGS) to select
123 between ss_wide and ss_narrow than to use the raw register size.
124 But checking ss_flags would require an extra ptrace call for
125 every register reference. Bleah. */
127 addr
= (HPPAH_OFFSETOF (save_state_t
, ss_wide
)
128 + DEPRECATED_REGISTER_BYTE (regno
));
130 /* Narrow registers come from the ss_narrow area. Note that
131 ss_narrow starts with gr1, not gr0. */
133 addr
= (HPPAH_OFFSETOF (save_state_t
, ss_narrow
)
134 + (DEPRECATED_REGISTER_BYTE (regno
) - DEPRECATED_REGISTER_BYTE (1)));
136 internal_error (__FILE__
, __LINE__
,
137 "hppah-nat.c (write_register): unexpected register size");
139 #ifdef GDB_TARGET_IS_HPPA_20W
140 /* Unbelieveable. The PC head and tail must be written in 64bit hunks
141 or we will get an error. Worse yet, the oddball ptrace/ttrace
142 layering will not allow us to perform a 64bit register store.
145 if (regno
== HPPA_PCOQ_HEAD_REGNUM
|| regno
== HPPA_PCOQ_TAIL_REGNUM
&& len
== 8)
149 temp
= *(CORE_ADDR
*)&deprecated_registers
[DEPRECATED_REGISTER_BYTE (regno
)];
151 /* Set the priv level (stored in the low two bits of the PC. */
154 ttrace_write_reg_64 (PIDGET (inferior_ptid
), (CORE_ADDR
)addr
,
157 /* If we fail to write the PC, give a true error instead of
161 char *err
= safe_strerror (errno
);
162 char *msg
= alloca (strlen (err
) + 128);
163 sprintf (msg
, "writing `%s' register: %s",
164 REGISTER_NAME (regno
), err
);
165 perror_with_name (msg
);
170 /* Another crock. HPUX complains if you write a nonzero value to
171 the high part of IPSW. What will it take for HP to catch a
172 clue about building sensible interfaces? */
173 if (regno
== HPPA_IPSW_REGNUM
&& len
== 8)
174 *(int *)&deprecated_registers
[DEPRECATED_REGISTER_BYTE (regno
)] = 0;
177 for (i
= 0; i
< len
; i
+= sizeof (int))
180 call_ptrace (PT_WUREGS
, PIDGET (inferior_ptid
),
181 (PTRACE_ARG3_TYPE
) addr
+ i
,
182 *(int *) &deprecated_registers
[DEPRECATED_REGISTER_BYTE (regno
) + i
]);
185 /* Warning, not error, in case we are attached; sometimes
186 the kernel doesn't let us at the registers. */
187 char *err
= safe_strerror (errno
);
188 char *msg
= alloca (strlen (err
) + 128);
189 sprintf (msg
, "writing `%s' register: %s",
190 REGISTER_NAME (regno
), err
);
191 /* If we fail to write the PC, give a true error instead of
193 if (regno
== HPPA_PCOQ_HEAD_REGNUM
|| regno
== HPPA_PCOQ_TAIL_REGNUM
)
194 perror_with_name (msg
);
202 for (regno
= 0; regno
< NUM_REGS
; regno
++)
203 store_inferior_registers (regno
);
207 /* Fetch a register's value from the process's U area. */
209 fetch_register (int regno
)
211 char buf
[MAX_REGISTER_SIZE
];
212 unsigned int addr
, len
, offset
;
216 len
= DEPRECATED_REGISTER_RAW_SIZE (regno
);
218 /* Requests for register zero actually want the save_state's
219 ss_flags member. As RM says: "Oh, what a hack!" */
223 addr
= HPPAH_OFFSETOF (save_state_t
, ss_flags
);
224 len
= sizeof (ss
.ss_flags
);
226 /* Note that ss_flags is always an int, no matter what
227 DEPRECATED_REGISTER_RAW_SIZE(0) says. Assuming all HP-UX PA
228 machines are big-endian, put it at the least significant end
229 of the value, and zap the rest of the buffer. */
230 offset
= DEPRECATED_REGISTER_RAW_SIZE (0) - len
;
231 memset (buf
, 0, sizeof (buf
));
234 /* Floating-point registers come from the ss_fpblock area. */
235 else if (regno
>= HPPA_FP0_REGNUM
)
236 addr
= (HPPAH_OFFSETOF (save_state_t
, ss_fpblock
)
237 + (DEPRECATED_REGISTER_BYTE (regno
) - DEPRECATED_REGISTER_BYTE (HPPA_FP0_REGNUM
)));
239 /* Wide registers come from the ss_wide area.
240 I think it's more PC to test (ss_flags & SS_WIDEREGS) to select
241 between ss_wide and ss_narrow than to use the raw register size.
242 But checking ss_flags would require an extra ptrace call for
243 every register reference. Bleah. */
245 addr
= (HPPAH_OFFSETOF (save_state_t
, ss_wide
)
246 + DEPRECATED_REGISTER_BYTE (regno
));
248 /* Narrow registers come from the ss_narrow area. Note that
249 ss_narrow starts with gr1, not gr0. */
251 addr
= (HPPAH_OFFSETOF (save_state_t
, ss_narrow
)
252 + (DEPRECATED_REGISTER_BYTE (regno
) - DEPRECATED_REGISTER_BYTE (1)));
255 internal_error (__FILE__
, __LINE__
,
256 "hppa-nat.c (fetch_register): unexpected register size");
258 for (i
= 0; i
< len
; i
+= sizeof (int))
261 /* Copy an int from the U area to buf. Fill the least
262 significant end if len != raw_size. */
263 * (int *) &buf
[offset
+ i
] =
264 call_ptrace (PT_RUREGS
, PIDGET (inferior_ptid
),
265 (PTRACE_ARG3_TYPE
) addr
+ i
, 0);
268 /* Warning, not error, in case we are attached; sometimes
269 the kernel doesn't let us at the registers. */
270 char *err
= safe_strerror (errno
);
271 char *msg
= alloca (strlen (err
) + 128);
272 sprintf (msg
, "reading `%s' register: %s",
273 REGISTER_NAME (regno
), err
);
279 /* If we're reading an address from the instruction address queue,
280 mask out the bottom two bits --- they contain the privilege
282 if (regno
== HPPA_PCOQ_HEAD_REGNUM
|| regno
== HPPA_PCOQ_TAIL_REGNUM
)
283 buf
[len
- 1] &= ~0x3;
285 regcache_raw_supply (current_regcache
, regno
, buf
);
289 /* Copy LEN bytes to or from inferior's memory starting at MEMADDR
290 to debugger memory starting at MYADDR. Copy to inferior if
293 Returns the length copied, which is either the LEN argument or zero.
294 This xfer function does not do partial moves, since child_ops
295 doesn't allow memory operations to cross below us in the target stack
296 anyway. TARGET is ignored. */
299 child_xfer_memory (CORE_ADDR memaddr
, char *myaddr
, int len
, int write
,
300 struct mem_attrib
*mem
,
301 struct target_ops
*target
)
304 /* Round starting address down to longword boundary. */
305 CORE_ADDR addr
= memaddr
& - (CORE_ADDR
)(sizeof (int));
306 /* Round ending address up; get number of longwords that makes. */
308 = (((memaddr
+ len
) - addr
) + sizeof (int) - 1) / sizeof (int);
310 /* Allocate buffer of that many longwords.
311 Note -- do not use alloca to allocate this buffer since there is no
312 guarantee of when the buffer will actually be deallocated.
314 This routine can be called over and over with the same call chain;
315 this (in effect) would pile up all those alloca requests until a call
316 to alloca was made from a point higher than this routine in the
318 int *buffer
= (int *) xmalloc (count
* sizeof (int));
322 /* Fill start and end extra bytes of buffer with existing memory data. */
323 if (addr
!= memaddr
|| len
< (int) sizeof (int))
325 /* Need part of initial word -- fetch it. */
326 buffer
[0] = call_ptrace (addr
< text_end
? PT_RIUSER
: PT_RDUSER
,
327 PIDGET (inferior_ptid
),
328 (PTRACE_ARG3_TYPE
) addr
, 0);
331 if (count
> 1) /* FIXME, avoid if even boundary */
334 = call_ptrace (addr
< text_end
? PT_RIUSER
: PT_RDUSER
,
335 PIDGET (inferior_ptid
),
336 (PTRACE_ARG3_TYPE
) (addr
337 + (count
- 1) * sizeof (int)),
341 /* Copy data to be written over corresponding part of buffer */
342 memcpy ((char *) buffer
+ (memaddr
& (sizeof (int) - 1)), myaddr
, len
);
344 /* Write the entire buffer. */
345 for (i
= 0; i
< count
; i
++, addr
+= sizeof (int))
349 /* The HP-UX kernel crashes if you use PT_WDUSER to write into the
350 text segment. FIXME -- does it work to write into the data
351 segment using WIUSER, or do these idiots really expect us to
352 figure out which segment the address is in, so we can use a
353 separate system call for it??! */
355 pt_request
= (addr
< text_end
) ? PT_WIUSER
: PT_WDUSER
;
356 pt_status
= call_ptrace (pt_request
,
357 PIDGET (inferior_ptid
),
358 (PTRACE_ARG3_TYPE
) addr
,
361 /* Did we fail? Might we've guessed wrong about which
362 segment this address resides in? Try the other request,
363 and see if that works... */
364 if ((pt_status
== -1) && errno
)
367 pt_request
= (pt_request
== PT_WIUSER
) ? PT_WDUSER
: PT_WIUSER
;
368 pt_status
= call_ptrace (pt_request
,
369 PIDGET (inferior_ptid
),
370 (PTRACE_ARG3_TYPE
) addr
,
373 /* No, we still fail. Okay, time to punt. */
374 if ((pt_status
== -1) && errno
)
384 /* Read all the longwords */
385 for (i
= 0; i
< count
; i
++, addr
+= sizeof (int))
388 buffer
[i
] = call_ptrace (addr
< text_end
? PT_RIUSER
: PT_RDUSER
,
389 PIDGET (inferior_ptid
),
390 (PTRACE_ARG3_TYPE
) addr
, 0);
399 /* Copy appropriate bytes out of the buffer. */
400 memcpy (myaddr
, (char *) buffer
+ (memaddr
& (sizeof (int) - 1)), len
);
406 char *saved_child_execd_pathname
= NULL
;
414 } saved_vfork_state
= STATE_NONE
;
417 child_follow_fork (int follow_child
)
420 struct target_waitstatus last_status
;
422 int parent_pid
, child_pid
;
424 get_last_target_status (&last_ptid
, &last_status
);
425 has_vforked
= (last_status
.kind
== TARGET_WAITKIND_VFORKED
);
426 parent_pid
= ptid_get_pid (last_ptid
);
427 child_pid
= last_status
.value
.related_pid
;
429 /* At this point, if we are vforking, breakpoints were already
430 detached from the child in child_wait; and the child has already
431 called execve(). If we are forking, both the parent and child
432 have breakpoints inserted. */
438 detach_breakpoints (child_pid
);
439 #ifdef SOLIB_REMOVE_INFERIOR_HOOK
440 SOLIB_REMOVE_INFERIOR_HOOK (child_pid
);
444 /* Detach from the child. */
445 printf_unfiltered ("Detaching after fork from %s\n",
446 target_pid_to_str (pid_to_ptid (child_pid
)));
447 hppa_require_detach (child_pid
, 0);
449 /* The parent and child of a vfork share the same address space.
450 Also, on some targets the order in which vfork and exec events
451 are received for parent in child requires some delicate handling
454 For instance, on ptrace-based HPUX we receive the child's vfork
455 event first, at which time the parent has been suspended by the
456 OS and is essentially untouchable until the child's exit or second
457 exec event arrives. At that time, the parent's vfork event is
458 delivered to us, and that's when we see and decide how to follow
459 the vfork. But to get to that point, we must continue the child
460 until it execs or exits. To do that smoothly, all breakpoints
461 must be removed from the child, in case there are any set between
462 the vfork() and exec() calls. But removing them from the child
463 also removes them from the parent, due to the shared-address-space
464 nature of a vfork'd parent and child. On HPUX, therefore, we must
465 take care to restore the bp's to the parent before we continue it.
466 Else, it's likely that we may not stop in the expected place. (The
467 worst scenario is when the user tries to step over a vfork() call;
468 the step-resume bp must be restored for the step to properly stop
469 in the parent after the call completes!)
471 Sequence of events, as reported to gdb from HPUX:
473 Parent Child Action for gdb to take
474 -------------------------------------------------------
475 1 VFORK Continue child
480 Now that the child has safely exec'd or exited, we must restore
481 the parent's breakpoints before we continue it. Else, we may
482 cause it run past expected stopping points. */
485 reattach_breakpoints (parent_pid
);
489 /* Needed to keep the breakpoint lists in sync. */
491 detach_breakpoints (child_pid
);
493 /* Before detaching from the parent, remove all breakpoints from it. */
494 remove_breakpoints ();
496 /* Also reset the solib inferior hook from the parent. */
497 #ifdef SOLIB_REMOVE_INFERIOR_HOOK
498 SOLIB_REMOVE_INFERIOR_HOOK (PIDGET (inferior_ptid
));
501 /* Detach from the parent. */
502 target_detach (NULL
, 1);
504 /* Attach to the child. */
505 printf_unfiltered ("Attaching after fork to %s\n",
506 target_pid_to_str (pid_to_ptid (child_pid
)));
507 hppa_require_attach (child_pid
);
508 inferior_ptid
= pid_to_ptid (child_pid
);
510 /* If we vforked, then we've also execed by now. The exec will be
511 reported momentarily. follow_exec () will handle breakpoints, so
512 we don't have to.. */
514 follow_inferior_reset_breakpoints ();
519 /* If we followed the parent, don't try to follow the child's exec. */
520 if (saved_vfork_state
!= STATE_GOT_PARENT
521 && saved_vfork_state
!= STATE_FAKE_EXEC
)
522 fprintf_unfiltered (gdb_stdout
,
523 "hppa: post follow vfork: confused state\n");
525 if (! follow_child
|| saved_vfork_state
== STATE_GOT_PARENT
)
526 saved_vfork_state
= STATE_NONE
;
533 /* Format a process id, given PID. Be sure to terminate
534 this with a null--it's going to be printed via a "%s". */
536 child_pid_to_str (ptid_t ptid
)
538 /* Static because address returned */
540 pid_t pid
= PIDGET (ptid
);
542 /* Extra NUL for paranoia's sake */
543 sprintf (buf
, "process %d%c", pid
, '\0');
548 /* Format a thread id, given TID. Be sure to terminate
549 this with a null--it's going to be printed via a "%s".
551 Note: This is a core-gdb tid, not the actual system tid.
552 See infttrace.c for details. */
554 hppa_tid_to_str (ptid_t ptid
)
556 /* Static because address returned */
558 /* This seems strange, but when I did the ptid conversion, it looked
559 as though a pid was always being passed. - Kevin Buettner */
560 pid_t tid
= PIDGET (ptid
);
562 /* Extra NULLs for paranoia's sake */
563 sprintf (buf
, "system thread %d%c", tid
, '\0');
569 /* Enable HACK for ttrace work. In
570 * infttrace.c/require_notification_of_events,
571 * this is set to 0 so that the loop in child_wait
574 int not_same_real_pid
= 1;
577 /* Wait for child to do something. Return pid of child, or -1 in case
578 of error; store status through argument pointer OURSTATUS. */
581 child_wait (ptid_t ptid
, struct target_waitstatus
*ourstatus
)
585 char *execd_pathname
= NULL
;
589 enum target_waitkind kind
;
592 if (saved_vfork_state
== STATE_FAKE_EXEC
)
594 saved_vfork_state
= STATE_NONE
;
595 ourstatus
->kind
= TARGET_WAITKIND_EXECD
;
596 ourstatus
->value
.execd_pathname
= saved_child_execd_pathname
;
597 return inferior_ptid
;
602 set_sigint_trap (); /* Causes SIGINT to be passed on to the
606 pid
= ptrace_wait (inferior_ptid
, &status
);
612 clear_sigint_trap ();
616 if (save_errno
== EINTR
)
619 fprintf_unfiltered (gdb_stderr
, "Child process unexpectedly missing: %s.\n",
620 safe_strerror (save_errno
));
622 /* Claim it exited with unknown signal. */
623 ourstatus
->kind
= TARGET_WAITKIND_SIGNALLED
;
624 ourstatus
->value
.sig
= TARGET_SIGNAL_UNKNOWN
;
625 return pid_to_ptid (-1);
630 if (target_has_exited (pid
, status
, &exit_status
))
632 /* ??rehrauer: For now, ignore this. */
636 if (!target_thread_alive (pid_to_ptid (pid
)))
638 ourstatus
->kind
= TARGET_WAITKIND_SPURIOUS
;
639 return pid_to_ptid (pid
);
642 if (hpux_has_forked (pid
, &related_pid
))
644 /* Ignore the parent's fork event. */
645 if (pid
== PIDGET (inferior_ptid
))
647 ourstatus
->kind
= TARGET_WAITKIND_IGNORE
;
648 return inferior_ptid
;
651 /* If this is the child's fork event, report that the
652 process has forked. */
653 if (related_pid
== PIDGET (inferior_ptid
))
655 ourstatus
->kind
= TARGET_WAITKIND_FORKED
;
656 ourstatus
->value
.related_pid
= pid
;
657 return inferior_ptid
;
661 if (hpux_has_vforked (pid
, &related_pid
))
663 if (pid
== PIDGET (inferior_ptid
))
665 if (saved_vfork_state
== STATE_GOT_CHILD
)
666 saved_vfork_state
= STATE_GOT_PARENT
;
667 else if (saved_vfork_state
== STATE_GOT_EXEC
)
668 saved_vfork_state
= STATE_FAKE_EXEC
;
670 fprintf_unfiltered (gdb_stdout
,
671 "hppah: parent vfork: confused\n");
673 else if (related_pid
== PIDGET (inferior_ptid
))
675 if (saved_vfork_state
== STATE_NONE
)
676 saved_vfork_state
= STATE_GOT_CHILD
;
678 fprintf_unfiltered (gdb_stdout
,
679 "hppah: child vfork: confused\n");
682 fprintf_unfiltered (gdb_stdout
,
683 "hppah: unknown vfork: confused\n");
685 if (saved_vfork_state
== STATE_GOT_CHILD
)
687 child_post_startup_inferior (pid_to_ptid (pid
));
688 detach_breakpoints (pid
);
689 #ifdef SOLIB_REMOVE_INFERIOR_HOOK
690 SOLIB_REMOVE_INFERIOR_HOOK (pid
);
692 child_resume (pid_to_ptid (pid
), 0, TARGET_SIGNAL_0
);
693 ourstatus
->kind
= TARGET_WAITKIND_IGNORE
;
694 return pid_to_ptid (related_pid
);
696 else if (saved_vfork_state
== STATE_FAKE_EXEC
)
698 ourstatus
->kind
= TARGET_WAITKIND_VFORKED
;
699 ourstatus
->value
.related_pid
= related_pid
;
700 return pid_to_ptid (pid
);
704 /* We saw the parent's vfork, but we haven't seen the exec yet.
705 Wait for it, for simplicity's sake. It should be pending. */
706 saved_vfork_pid
= related_pid
;
707 ourstatus
->kind
= TARGET_WAITKIND_IGNORE
;
708 return pid_to_ptid (pid
);
712 if (hpux_has_execd (pid
, &execd_pathname
))
714 /* On HP-UX, events associated with a vforking inferior come in
715 threes: a vfork event for the child (always first), followed
716 a vfork event for the parent and an exec event for the child.
717 The latter two can come in either order. Make sure we get
719 if (saved_vfork_state
!= STATE_NONE
)
721 if (saved_vfork_state
== STATE_GOT_CHILD
)
723 saved_vfork_state
= STATE_GOT_EXEC
;
724 /* On HP/UX with ptrace, the child must be resumed before
725 the parent vfork event is delivered. A single-step
727 if (RESUME_EXECD_VFORKING_CHILD_TO_GET_PARENT_VFORK ())
728 target_resume (pid_to_ptid (pid
), 1, TARGET_SIGNAL_0
);
729 ourstatus
->kind
= TARGET_WAITKIND_IGNORE
;
731 else if (saved_vfork_state
== STATE_GOT_PARENT
)
733 saved_vfork_state
= STATE_FAKE_EXEC
;
734 ourstatus
->kind
= TARGET_WAITKIND_VFORKED
;
735 ourstatus
->value
.related_pid
= saved_vfork_pid
;
738 fprintf_unfiltered (gdb_stdout
,
739 "hppa: exec: unexpected state\n");
741 saved_child_execd_pathname
= execd_pathname
;
743 return inferior_ptid
;
746 /* Are we ignoring initial exec events? (This is likely because
747 we're in the process of starting up the inferior, and another
748 (older) mechanism handles those.) If so, we'll report this
749 as a regular stop, not an exec.
751 if (inferior_ignoring_startup_exec_events
)
753 inferior_ignoring_startup_exec_events
--;
757 ourstatus
->kind
= TARGET_WAITKIND_EXECD
;
758 ourstatus
->value
.execd_pathname
= execd_pathname
;
759 return pid_to_ptid (pid
);
763 /* All we must do with these is communicate their occurrence
764 to wait_for_inferior...
766 if (hpux_has_syscall_event (pid
, &kind
, &syscall_id
))
768 ourstatus
->kind
= kind
;
769 ourstatus
->value
.syscall_id
= syscall_id
;
770 return pid_to_ptid (pid
);
773 /*## } while (pid != PIDGET (inferior_ptid)); ## *//* Some other child died or stopped */
774 /* hack for thread testing */
776 while ((pid
!= PIDGET (inferior_ptid
)) && not_same_real_pid
);
779 store_waitstatus (ourstatus
, status
);
780 return pid_to_ptid (pid
);
783 #if !defined (GDB_NATIVE_HPUX_11)
785 /* The following code is a substitute for the infttrace.c versions used
786 with ttrace() in HPUX 11. */
788 /* This value is an arbitrary integer. */
789 #define PT_VERSION 123456
791 /* This semaphore is used to coordinate the child and parent processes
792 after a fork(), and before an exec() by the child. See
793 parent_attach_all for details. */
797 int parent_channel
[2]; /* Parent "talks" to [1], child "listens" to [0] */
798 int child_channel
[2]; /* Child "talks" to [1], parent "listens" to [0] */
803 #define SEM_LISTEN (0)
805 static startup_semaphore_t startup_semaphore
;
808 /* This function causes the caller's process to be traced by its
809 parent. This is intended to be called after GDB forks itself,
810 and before the child execs the target.
812 Note that HP-UX ptrace is rather funky in how this is done.
813 If the parent wants to get the initial exec event of a child,
814 it must set the ptrace event mask of the child to include execs.
815 (The child cannot do this itself.) This must be done after the
816 child is forked, but before it execs.
818 To coordinate the parent and child, we implement a semaphore using
819 pipes. After SETTRC'ing itself, the child tells the parent that
820 it is now traceable by the parent, and waits for the parent's
821 acknowledgement. The parent can then set the child's event mask,
822 and notify the child that it can now exec.
824 (The acknowledgement by parent happens as a result of a call to
825 child_acknowledge_created_inferior.) */
828 parent_attach_all (int pid
, PTRACE_ARG3_TYPE addr
, int data
)
832 /* We need a memory home for a constant. */
833 int tc_magic_child
= PT_VERSION
;
834 int tc_magic_parent
= 0;
836 /* The remainder of this function is only useful for HPUX 10.0 and
837 later, as it depends upon the ability to request notification
838 of specific kinds of events by the kernel. */
839 #if defined(PT_SET_EVENT_MASK)
841 /* Notify the parent that we're potentially ready to exec(). */
842 write (startup_semaphore
.child_channel
[SEM_TALK
],
844 sizeof (tc_magic_child
));
846 /* Wait for acknowledgement from the parent. */
847 read (startup_semaphore
.parent_channel
[SEM_LISTEN
],
849 sizeof (tc_magic_parent
));
850 if (tc_magic_child
!= tc_magic_parent
)
851 warning ("mismatched semaphore magic");
853 /* Discard our copy of the semaphore. */
854 (void) close (startup_semaphore
.parent_channel
[SEM_LISTEN
]);
855 (void) close (startup_semaphore
.parent_channel
[SEM_TALK
]);
856 (void) close (startup_semaphore
.child_channel
[SEM_LISTEN
]);
857 (void) close (startup_semaphore
.child_channel
[SEM_TALK
]);
865 hppa_require_attach (int pid
)
870 unsigned int regs_offset
;
872 /* Are we already attached? There appears to be no explicit way to
873 answer this via ptrace, so we try something which should be
874 innocuous if we are attached. If that fails, then we assume
875 we're not attached, and so attempt to make it so. */
878 regs_offset
= U_REGS_OFFSET
;
879 pc_addr
= register_addr (PC_REGNUM
, regs_offset
);
880 pc
= call_ptrace (PT_READ_U
, pid
, (PTRACE_ARG3_TYPE
) pc_addr
, 0);
885 pt_status
= call_ptrace (PT_ATTACH
, pid
, (PTRACE_ARG3_TYPE
) 0, 0);
890 /* Now we really are attached. */
898 hppa_require_detach (int pid
, int signal
)
901 call_ptrace (PT_DETACH
, pid
, (PTRACE_ARG3_TYPE
) 1, signal
);
902 errno
= 0; /* Ignore any errors. */
906 /* Since ptrace doesn't support memory page-protection events, which
907 are used to implement "hardware" watchpoints on HP-UX, these are
908 dummy versions, which perform no useful work. */
911 hppa_enable_page_protection_events (int pid
)
916 hppa_disable_page_protection_events (int pid
)
921 hppa_insert_hw_watchpoint (int pid
, CORE_ADDR start
, LONGEST len
, int type
)
923 error ("Hardware watchpoints not implemented on this platform.");
927 hppa_remove_hw_watchpoint (int pid
, CORE_ADDR start
, LONGEST len
, int type
)
929 error ("Hardware watchpoints not implemented on this platform.");
933 hppa_can_use_hw_watchpoint (int type
, int cnt
, int ot
)
939 hppa_range_profitable_for_hw_watchpoint (int pid
, CORE_ADDR start
, LONGEST len
)
941 error ("Hardware watchpoints not implemented on this platform.");
945 hppa_pid_or_tid_to_str (ptid_t id
)
947 /* In the ptrace world, there are only processes. */
948 return child_pid_to_str (id
);
952 hppa_ensure_vforking_parent_remains_stopped (int pid
)
954 /* This assumes that the vforked parent is presently stopped, and
955 that the vforked child has just delivered its first exec event.
956 Calling kill() this way will cause the SIGTRAP to be delivered as
957 soon as the parent is resumed, which happens as soon as the
958 vforked child is resumed. See wait_for_inferior for the use of
964 hppa_resume_execd_vforking_child_to_get_parent_vfork (void)
966 return 1; /* Yes, the child must be resumed. */
970 require_notification_of_events (int pid
)
972 #if defined(PT_SET_EVENT_MASK)
974 ptrace_event_t ptrace_events
;
978 /* Instruct the kernel as to the set of events we wish to be
979 informed of. (This support does not exist before HPUX 10.0.
980 We'll assume if PT_SET_EVENT_MASK has not been defined by
981 <sys/ptrace.h>, then we're being built on pre-10.0.) */
982 memset (&ptrace_events
, 0, sizeof (ptrace_events
));
984 /* Note: By default, all signals are visible to us. If we wish
985 the kernel to keep certain signals hidden from us, we do it
986 by calling sigdelset (ptrace_events.pe_signals, signal) for
987 each such signal here, before doing PT_SET_EVENT_MASK. */
988 /* RM: The above comment is no longer true. We start with ignoring
989 all signals, and then add the ones we are interested in. We could
990 do it the other way: start by looking at all signals and then
991 deleting the ones that we aren't interested in, except that
992 multiple gdb signals may be mapped to the same host signal
993 (eg. TARGET_SIGNAL_IO and TARGET_SIGNAL_POLL both get mapped to
994 signal 22 on HPUX 10.20) We want to be notified if we are
995 interested in either signal. */
996 sigfillset (&ptrace_events
.pe_signals
);
998 /* RM: Let's not bother with signals we don't care about */
999 nsigs
= (int) TARGET_SIGNAL_LAST
;
1000 for (signum
= nsigs
; signum
> 0; signum
--)
1002 if ((signal_stop_state (signum
)) ||
1003 (signal_print_state (signum
)) ||
1004 (!signal_pass_state (signum
)))
1006 if (target_signal_to_host_p (signum
))
1007 sigdelset (&ptrace_events
.pe_signals
,
1008 target_signal_to_host (signum
));
1012 ptrace_events
.pe_set_event
= 0;
1014 ptrace_events
.pe_set_event
|= PTRACE_SIGNAL
;
1015 ptrace_events
.pe_set_event
|= PTRACE_EXEC
;
1016 ptrace_events
.pe_set_event
|= PTRACE_FORK
;
1017 ptrace_events
.pe_set_event
|= PTRACE_VFORK
;
1018 /* ??rehrauer: Add this one when we're prepared to catch it...
1019 ptrace_events.pe_set_event |= PTRACE_EXIT;
1023 pt_status
= call_ptrace (PT_SET_EVENT_MASK
,
1025 (PTRACE_ARG3_TYPE
) & ptrace_events
,
1026 sizeof (ptrace_events
));
1028 perror_with_name ("ptrace");
1035 require_notification_of_exec_events (int pid
)
1037 #if defined(PT_SET_EVENT_MASK)
1039 ptrace_event_t ptrace_events
;
1041 /* Instruct the kernel as to the set of events we wish to be
1042 informed of. (This support does not exist before HPUX 10.0.
1043 We'll assume if PT_SET_EVENT_MASK has not been defined by
1044 <sys/ptrace.h>, then we're being built on pre-10.0.) */
1045 memset (&ptrace_events
, 0, sizeof (ptrace_events
));
1047 /* Note: By default, all signals are visible to us. If we wish
1048 the kernel to keep certain signals hidden from us, we do it
1049 by calling sigdelset (ptrace_events.pe_signals, signal) for
1050 each such signal here, before doing PT_SET_EVENT_MASK. */
1051 sigemptyset (&ptrace_events
.pe_signals
);
1053 ptrace_events
.pe_set_event
= 0;
1055 ptrace_events
.pe_set_event
|= PTRACE_EXEC
;
1056 /* ??rehrauer: Add this one when we're prepared to catch it...
1057 ptrace_events.pe_set_event |= PTRACE_EXIT;
1061 pt_status
= call_ptrace (PT_SET_EVENT_MASK
,
1063 (PTRACE_ARG3_TYPE
) & ptrace_events
,
1064 sizeof (ptrace_events
));
1066 perror_with_name ("ptrace");
1072 /* This function is called by the parent process, with pid being the
1073 ID of the child process, after the debugger has forked. */
1076 child_acknowledge_created_inferior (int pid
)
1078 /* We need a memory home for a constant. */
1079 int tc_magic_parent
= PT_VERSION
;
1080 int tc_magic_child
= 0;
1082 /* The remainder of this function is only useful for HPUX 10.0 and
1083 later, as it depends upon the ability to request notification
1084 of specific kinds of events by the kernel. */
1085 #if defined(PT_SET_EVENT_MASK)
1086 /* Wait for the child to tell us that it has forked. */
1087 read (startup_semaphore
.child_channel
[SEM_LISTEN
],
1089 sizeof (tc_magic_child
));
1091 /* Notify the child that it can exec.
1093 In the infttrace.c variant of this function, we set the child's
1094 event mask after the fork but before the exec. In the ptrace
1095 world, it seems we can't set the event mask until after the exec. */
1096 write (startup_semaphore
.parent_channel
[SEM_TALK
],
1098 sizeof (tc_magic_parent
));
1100 /* We'd better pause a bit before trying to set the event mask,
1101 though, to ensure that the exec has happened. We don't want to
1102 wait() on the child, because that'll screw up the upper layers
1103 of gdb's execution control that expect to see the exec event.
1105 After an exec, the child is no longer executing gdb code. Hence,
1106 we can't have yet another synchronization via the pipes. We'll
1107 just sleep for a second, and hope that's enough delay... */
1110 /* Instruct the kernel as to the set of events we wish to be
1112 require_notification_of_exec_events (pid
);
1114 /* Discard our copy of the semaphore. */
1115 (void) close (startup_semaphore
.parent_channel
[SEM_LISTEN
]);
1116 (void) close (startup_semaphore
.parent_channel
[SEM_TALK
]);
1117 (void) close (startup_semaphore
.child_channel
[SEM_LISTEN
]);
1118 (void) close (startup_semaphore
.child_channel
[SEM_TALK
]);
1123 child_post_startup_inferior (ptid_t ptid
)
1125 require_notification_of_events (PIDGET (ptid
));
1129 child_post_attach (int pid
)
1131 require_notification_of_events (pid
);
1135 child_insert_fork_catchpoint (int pid
)
1137 /* This request is only available on HPUX 10.0 and later. */
1138 #if !defined(PT_SET_EVENT_MASK)
1139 error ("Unable to catch forks prior to HPUX 10.0");
1141 /* Enable reporting of fork events from the kernel. */
1142 /* ??rehrauer: For the moment, we're always enabling these events,
1143 and just ignoring them if there's no catchpoint to catch them. */
1149 child_remove_fork_catchpoint (int pid
)
1151 /* This request is only available on HPUX 10.0 and later. */
1152 #if !defined(PT_SET_EVENT_MASK)
1153 error ("Unable to catch forks prior to HPUX 10.0");
1155 /* Disable reporting of fork events from the kernel. */
1156 /* ??rehrauer: For the moment, we're always enabling these events,
1157 and just ignoring them if there's no catchpoint to catch them. */
1163 child_insert_vfork_catchpoint (int pid
)
1165 /* This request is only available on HPUX 10.0 and later. */
1166 #if !defined(PT_SET_EVENT_MASK)
1167 error ("Unable to catch vforks prior to HPUX 10.0");
1169 /* Enable reporting of vfork events from the kernel. */
1170 /* ??rehrauer: For the moment, we're always enabling these events,
1171 and just ignoring them if there's no catchpoint to catch them. */
1177 child_remove_vfork_catchpoint (int pid
)
1179 /* This request is only available on HPUX 10.0 and later. */
1180 #if !defined(PT_SET_EVENT_MASK)
1181 error ("Unable to catch vforks prior to HPUX 10.0");
1183 /* Disable reporting of vfork events from the kernel. */
1184 /* ??rehrauer: For the moment, we're always enabling these events,
1185 and just ignoring them if there's no catchpoint to catch them. */
1191 hpux_has_forked (int pid
, int *childpid
)
1193 /* This request is only available on HPUX 10.0 and later. */
1194 #if !defined(PT_GET_PROCESS_STATE)
1199 ptrace_state_t ptrace_state
;
1202 pt_status
= call_ptrace (PT_GET_PROCESS_STATE
,
1204 (PTRACE_ARG3_TYPE
) & ptrace_state
,
1205 sizeof (ptrace_state
));
1207 perror_with_name ("ptrace");
1211 if (ptrace_state
.pe_report_event
& PTRACE_FORK
)
1213 *childpid
= ptrace_state
.pe_other_pid
;
1222 hpux_has_vforked (int pid
, int *childpid
)
1224 /* This request is only available on HPUX 10.0 and later. */
1225 #if !defined(PT_GET_PROCESS_STATE)
1231 ptrace_state_t ptrace_state
;
1234 pt_status
= call_ptrace (PT_GET_PROCESS_STATE
,
1236 (PTRACE_ARG3_TYPE
) & ptrace_state
,
1237 sizeof (ptrace_state
));
1239 perror_with_name ("ptrace");
1243 if (ptrace_state
.pe_report_event
& PTRACE_VFORK
)
1245 *childpid
= ptrace_state
.pe_other_pid
;
1254 child_insert_exec_catchpoint (int pid
)
1256 /* This request is only available on HPUX 10.0 and later. */
1257 #if !defined(PT_SET_EVENT_MASK)
1258 error ("Unable to catch execs prior to HPUX 10.0");
1261 /* Enable reporting of exec events from the kernel. */
1262 /* ??rehrauer: For the moment, we're always enabling these events,
1263 and just ignoring them if there's no catchpoint to catch them. */
1269 child_remove_exec_catchpoint (int pid
)
1271 /* This request is only available on HPUX 10.0 and later. */
1272 #if !defined(PT_SET_EVENT_MASK)
1273 error ("Unable to catch execs prior to HPUX 10.0");
1276 /* Disable reporting of exec events from the kernel. */
1277 /* ??rehrauer: For the moment, we're always enabling these events,
1278 and just ignoring them if there's no catchpoint to catch them. */
1284 hpux_has_execd (int pid
, char **execd_pathname
)
1286 /* This request is only available on HPUX 10.0 and later. */
1287 #if !defined(PT_GET_PROCESS_STATE)
1288 *execd_pathname
= NULL
;
1293 ptrace_state_t ptrace_state
;
1296 pt_status
= call_ptrace (PT_GET_PROCESS_STATE
,
1298 (PTRACE_ARG3_TYPE
) & ptrace_state
,
1299 sizeof (ptrace_state
));
1301 perror_with_name ("ptrace");
1305 if (ptrace_state
.pe_report_event
& PTRACE_EXEC
)
1307 char *exec_file
= target_pid_to_exec_file (pid
);
1308 *execd_pathname
= savestring (exec_file
, strlen (exec_file
));
1317 child_reported_exec_events_per_exec_call (void)
1319 return 2; /* ptrace reports the event twice per call. */
1323 hpux_has_syscall_event (int pid
, enum target_waitkind
*kind
, int *syscall_id
)
1325 /* This request is only available on HPUX 10.30 and later, via
1326 the ttrace interface. */
1328 *kind
= TARGET_WAITKIND_SPURIOUS
;
1334 child_pid_to_exec_file (int pid
)
1336 static char exec_file_buffer
[1024];
1338 CORE_ADDR top_of_stack
;
1342 ptid_t saved_inferior_ptid
;
1345 #ifdef PT_GET_PROCESS_PATHNAME
1346 /* As of 10.x HP-UX, there's an explicit request to get the pathname. */
1347 pt_status
= call_ptrace (PT_GET_PROCESS_PATHNAME
,
1349 (PTRACE_ARG3_TYPE
) exec_file_buffer
,
1350 sizeof (exec_file_buffer
) - 1);
1352 return exec_file_buffer
;
1355 /* It appears that this request is broken prior to 10.30.
1356 If it fails, try a really, truly amazingly gross hack
1357 that DDE uses, of pawing through the process' data
1358 segment to find the pathname. */
1360 top_of_stack
= 0x7b03a000;
1364 /* On the chance that pid != inferior_ptid, set inferior_ptid
1365 to pid, so that (grrrr!) implicit uses of inferior_ptid get
1368 saved_inferior_ptid
= inferior_ptid
;
1369 inferior_ptid
= pid_to_ptid (pid
);
1371 /* Try to grab a null-terminated string. */
1374 if (target_read_memory (top_of_stack
, four_chars
, 4) != 0)
1376 inferior_ptid
= saved_inferior_ptid
;
1379 for (i
= 0; i
< 4; i
++)
1381 exec_file_buffer
[name_index
++] = four_chars
[i
];
1382 done
= (four_chars
[i
] == '\0');
1389 if (exec_file_buffer
[0] == '\0')
1391 inferior_ptid
= saved_inferior_ptid
;
1395 inferior_ptid
= saved_inferior_ptid
;
1396 return exec_file_buffer
;
1400 pre_fork_inferior (void)
1404 status
= pipe (startup_semaphore
.parent_channel
);
1407 warning ("error getting parent pipe for startup semaphore");
1411 status
= pipe (startup_semaphore
.child_channel
);
1414 warning ("error getting child pipe for startup semaphore");
1420 /* Check to see if the given thread is alive.
1422 This is a no-op, as ptrace doesn't support threads, so we just
1426 child_thread_alive (ptid_t ptid
)
1431 #endif /* ! GDB_NATIVE_HPUX_11 */