d1e632c1eabf716875262f3bb259f593ce000405
[deliverable/binutils-gdb.git] / gdb / hppah-nat.c
1 /* Native support code for HPUX PA-RISC.
2 Copyright 1986, 1987, 1989, 1990, 1991, 1992, 1993, 1998, 1999
3 Free Software Foundation, Inc.
4
5 Contributed by the Center for Software Science at the
6 University of Utah (pa-gdb-bugs@cs.utah.edu).
7
8 This file is part of GDB.
9
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.
14
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.
19
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, Boston, MA 02111-1307, USA. */
23
24
25 #include "defs.h"
26 #include "inferior.h"
27 #include "target.h"
28 #include <sys/ptrace.h>
29 #include "gdbcore.h"
30 #include <wait.h>
31 #include <signal.h>
32
33 extern CORE_ADDR text_end;
34
35 static void fetch_register PARAMS ((int));
36
37 void
38 fetch_inferior_registers (regno)
39 int regno;
40 {
41 if (regno == -1)
42 for (regno = 0; regno < NUM_REGS; regno++)
43 fetch_register (regno);
44 else
45 fetch_register (regno);
46 }
47
48 /* Store our register values back into the inferior.
49 If REGNO is -1, do this for all registers.
50 Otherwise, REGNO specifies which register (so we can save time). */
51
52 void
53 store_inferior_registers (regno)
54 int regno;
55 {
56 register unsigned int regaddr;
57 char buf[80];
58 register int i;
59 unsigned int offset = U_REGS_OFFSET;
60 int scratch;
61
62 if (regno >= 0)
63 {
64 if (CANNOT_STORE_REGISTER (regno))
65 return;
66 regaddr = register_addr (regno, offset);
67 errno = 0;
68 if (regno == PCOQ_HEAD_REGNUM || regno == PCOQ_TAIL_REGNUM)
69 {
70 scratch = *(int *) &registers[REGISTER_BYTE (regno)] | 0x3;
71 call_ptrace (PT_WUREGS, inferior_pid, (PTRACE_ARG3_TYPE) regaddr,
72 scratch);
73 if (errno != 0)
74 {
75 /* Error, even if attached. Failing to write these two
76 registers is pretty serious. */
77 sprintf (buf, "writing register number %d", regno);
78 perror_with_name (buf);
79 }
80 }
81 else
82 for (i = 0; i < REGISTER_RAW_SIZE (regno); i += sizeof(int))
83 {
84 errno = 0;
85 call_ptrace (PT_WUREGS, inferior_pid, (PTRACE_ARG3_TYPE) regaddr,
86 *(int *) &registers[REGISTER_BYTE (regno) + i]);
87 if (errno != 0)
88 {
89 /* Warning, not error, in case we are attached; sometimes the
90 kernel doesn't let us at the registers. */
91 char *err = safe_strerror (errno);
92 char *msg = alloca (strlen (err) + 128);
93 sprintf (msg, "writing register %s: %s",
94 REGISTER_NAME (regno), err);
95 warning (msg);
96 return;
97 }
98 regaddr += sizeof(int);
99 }
100 }
101 else
102 for (regno = 0; regno < NUM_REGS; regno++)
103 store_inferior_registers (regno);
104 }
105
106 /* Fetch one register. */
107
108 static void
109 fetch_register (regno)
110 int regno;
111 {
112 register unsigned int regaddr;
113 char buf[MAX_REGISTER_RAW_SIZE];
114 register int i;
115
116 /* Offset of registers within the u area. */
117 unsigned int offset;
118
119 offset = U_REGS_OFFSET;
120
121 regaddr = register_addr (regno, offset);
122 for (i = 0; i < REGISTER_RAW_SIZE (regno); i += sizeof (int))
123 {
124 errno = 0;
125 *(int *) &buf[i] = call_ptrace (PT_RUREGS, inferior_pid,
126 (PTRACE_ARG3_TYPE) regaddr, 0);
127 regaddr += sizeof (int);
128 if (errno != 0)
129 {
130 /* Warning, not error, in case we are attached; sometimes the
131 kernel doesn't let us at the registers. */
132 char *err = safe_strerror (errno);
133 char *msg = alloca (strlen (err) + 128);
134 sprintf (msg, "reading register %s: %s", REGISTER_NAME (regno), err);
135 warning (msg);
136 goto error_exit;
137 }
138 }
139 if (regno == PCOQ_HEAD_REGNUM || regno == PCOQ_TAIL_REGNUM)
140 buf[3] &= ~0x3;
141 supply_register (regno, buf);
142 error_exit:;
143 }
144
145 /* Copy LEN bytes to or from inferior's memory starting at MEMADDR
146 to debugger memory starting at MYADDR. Copy to inferior if
147 WRITE is nonzero.
148
149 Returns the length copied, which is either the LEN argument or zero.
150 This xfer function does not do partial moves, since child_ops
151 doesn't allow memory operations to cross below us in the target stack
152 anyway. */
153
154 int
155 child_xfer_memory (memaddr, myaddr, len, write, target)
156 CORE_ADDR memaddr;
157 char *myaddr;
158 int len;
159 int write;
160 struct target_ops *target; /* ignored */
161 {
162 register int i;
163 /* Round starting address down to longword boundary. */
164 register CORE_ADDR addr = memaddr & - sizeof (int);
165 /* Round ending address up; get number of longwords that makes. */
166 register int count
167 = (((memaddr + len) - addr) + sizeof (int) - 1) / sizeof (int);
168
169 /* Allocate buffer of that many longwords.
170 Note -- do not use alloca to allocate this buffer since there is no
171 guarantee of when the buffer will actually be deallocated.
172
173 This routine can be called over and over with the same call chain;
174 this (in effect) would pile up all those alloca requests until a call
175 to alloca was made from a point higher than this routine in the
176 call chain. */
177 register int *buffer = (int *) xmalloc (count * sizeof (int));
178
179 if (write)
180 {
181 /* Fill start and end extra bytes of buffer with existing memory data. */
182 if (addr != memaddr || len < (int)sizeof (int))
183 {
184 /* Need part of initial word -- fetch it. */
185 buffer[0] = call_ptrace (addr < text_end ? PT_RIUSER : PT_RDUSER,
186 inferior_pid, (PTRACE_ARG3_TYPE) addr, 0);
187 }
188
189 if (count > 1) /* FIXME, avoid if even boundary */
190 {
191 buffer[count - 1]
192 = call_ptrace (addr < text_end ? PT_RIUSER : PT_RDUSER,
193 inferior_pid,
194 (PTRACE_ARG3_TYPE) (addr
195 + (count - 1) * sizeof (int)),
196 0);
197 }
198
199 /* Copy data to be written over corresponding part of buffer */
200 memcpy ((char *) buffer + (memaddr & (sizeof (int) - 1)), myaddr, len);
201
202 /* Write the entire buffer. */
203 for (i = 0; i < count; i++, addr += sizeof (int))
204 {
205 int pt_status;
206 int pt_request;
207 /* The HP-UX kernel crashes if you use PT_WDUSER to write into the
208 text segment. FIXME -- does it work to write into the data
209 segment using WIUSER, or do these idiots really expect us to
210 figure out which segment the address is in, so we can use a
211 separate system call for it??! */
212 errno = 0;
213 pt_request = (addr < text_end) ? PT_WIUSER : PT_WDUSER;
214 pt_status = call_ptrace (pt_request,
215 inferior_pid,
216 (PTRACE_ARG3_TYPE) addr,
217 buffer[i]);
218
219 /* Did we fail? Might we've guessed wrong about which
220 segment this address resides in? Try the other request,
221 and see if that works... */
222 if ((pt_status == -1) && errno)
223 {
224 errno = 0;
225 pt_request = (pt_request == PT_WIUSER) ? PT_WDUSER : PT_WIUSER;
226 pt_status = call_ptrace (pt_request,
227 inferior_pid,
228 (PTRACE_ARG3_TYPE) addr,
229 buffer[i]);
230
231 /* No, we still fail. Okay, time to punt. */
232 if ((pt_status == -1) && errno)
233 {
234 free(buffer);
235 return 0;
236 }
237 }
238 }
239 }
240 else
241 {
242 /* Read all the longwords */
243 for (i = 0; i < count; i++, addr += sizeof (int))
244 {
245 errno = 0;
246 buffer[i] = call_ptrace (addr < text_end ? PT_RIUSER : PT_RDUSER,
247 inferior_pid, (PTRACE_ARG3_TYPE) addr, 0);
248 if (errno)
249 {
250 free(buffer);
251 return 0;
252 }
253 QUIT;
254 }
255
256 /* Copy appropriate bytes out of the buffer. */
257 memcpy (myaddr, (char *) buffer + (memaddr & (sizeof (int) - 1)), len);
258 }
259 free(buffer);
260 return len;
261 }
262
263
264 void
265 child_post_follow_inferior_by_clone ()
266 {
267 int status;
268
269 /* This function is used when following both the parent and child
270 of a fork. In this case, the debugger clones itself. The original
271 debugger follows the parent, the clone follows the child. The
272 original detaches from the child, delivering a SIGSTOP to it to
273 keep it from running away until the clone can attach itself.
274
275 At this point, the clone has attached to the child. Because of
276 the SIGSTOP, we must now deliver a SIGCONT to the child, or it
277 won't behave properly. */
278 status = kill (inferior_pid, SIGCONT);
279 }
280
281
282 void
283 child_post_follow_vfork (parent_pid, followed_parent, child_pid, followed_child)
284 int parent_pid;
285 int followed_parent;
286 int child_pid;
287 int followed_child;
288 {
289 /* Are we a debugger that followed the parent of a vfork? If so,
290 then recall that the child's vfork event was delivered to us
291 first. And, that the parent was suspended by the OS until the
292 child's exec or exit events were received.
293
294 Upon receiving that child vfork, then, we were forced to remove
295 all breakpoints in the child and continue it so that it could
296 reach the exec or exit point.
297
298 But also recall that the parent and child of a vfork share the
299 same address space. Thus, removing bp's in the child also
300 removed them from the parent.
301
302 Now that the child has safely exec'd or exited, we must restore
303 the parent's breakpoints before we continue it. Else, we may
304 cause it run past expected stopping points. */
305 if (followed_parent)
306 {
307 reattach_breakpoints (parent_pid);
308 }
309
310 /* Are we a debugger that followed the child of a vfork? If so,
311 then recall that we don't actually acquire control of the child
312 until after it has exec'd or exited. */
313 if (followed_child)
314 {
315 /* If the child has exited, then there's nothing for us to do.
316 In the case of an exec event, we'll let that be handled by
317 the normal mechanism that notices and handles exec events, in
318 resume(). */
319 }
320 }
321
322 /* Format a process id, given PID. Be sure to terminate
323 this with a null--it's going to be printed via a "%s". */
324 char *
325 hppa_pid_to_str (pid)
326 pid_t pid;
327 {
328 /* Static because address returned */
329 static char buf[30];
330
331 /* Extra NULLs for paranoia's sake */
332 sprintf (buf, "process %d\0\0\0\0", pid);
333
334 return buf;
335 }
336
337 /* Format a thread id, given TID. Be sure to terminate
338 this with a null--it's going to be printed via a "%s".
339
340 Note: This is a core-gdb tid, not the actual system tid.
341 See infttrace.c for details. */
342 char *
343 hppa_tid_to_str (tid)
344 pid_t tid;
345 {
346 /* Static because address returned */
347 static char buf[30];
348
349 /* Extra NULLs for paranoia's sake */
350 sprintf (buf, "system thread %d\0\0\0\0", tid);
351
352 return buf;
353 }
354
355 #if !defined (GDB_NATIVE_HPUX_11)
356
357 /* The following code is a substitute for the infttrace.c versions used
358 with ttrace() in HPUX 11. */
359
360 /* This value is an arbitrary integer. */
361 #define PT_VERSION 123456
362
363 /* This semaphore is used to coordinate the child and parent processes
364 after a fork(), and before an exec() by the child. See
365 parent_attach_all for details. */
366
367 typedef struct {
368 int parent_channel[2]; /* Parent "talks" to [1], child "listens" to [0] */
369 int child_channel[2]; /* Child "talks" to [1], parent "listens" to [0] */
370 } startup_semaphore_t;
371
372 #define SEM_TALK (1)
373 #define SEM_LISTEN (0)
374
375 static startup_semaphore_t startup_semaphore;
376
377 extern int parent_attach_all PARAMS ((int, PTRACE_ARG3_TYPE, int));
378
379 #ifdef PT_SETTRC
380 /* This function causes the caller's process to be traced by its
381 parent. This is intended to be called after GDB forks itself,
382 and before the child execs the target.
383
384 Note that HP-UX ptrace is rather funky in how this is done.
385 If the parent wants to get the initial exec event of a child,
386 it must set the ptrace event mask of the child to include execs.
387 (The child cannot do this itself.) This must be done after the
388 child is forked, but before it execs.
389
390 To coordinate the parent and child, we implement a semaphore using
391 pipes. After SETTRC'ing itself, the child tells the parent that
392 it is now traceable by the parent, and waits for the parent's
393 acknowledgement. The parent can then set the child's event mask,
394 and notify the child that it can now exec.
395
396 (The acknowledgement by parent happens as a result of a call to
397 child_acknowledge_created_inferior.) */
398
399 int
400 parent_attach_all (pid, addr, data)
401 int pid;
402 PTRACE_ARG3_TYPE addr;
403 int data;
404 {
405 int pt_status = 0;
406
407 /* We need a memory home for a constant. */
408 int tc_magic_child = PT_VERSION;
409 int tc_magic_parent = 0;
410
411 /* The remainder of this function is only useful for HPUX 10.0 and
412 later, as it depends upon the ability to request notification
413 of specific kinds of events by the kernel. */
414 #if defined(PT_SET_EVENT_MASK)
415
416 /* Notify the parent that we're potentially ready to exec(). */
417 write (startup_semaphore.child_channel[SEM_TALK],
418 &tc_magic_child,
419 sizeof (tc_magic_child));
420
421 /* Wait for acknowledgement from the parent. */
422 read (startup_semaphore.parent_channel[SEM_LISTEN],
423 &tc_magic_parent,
424 sizeof (tc_magic_parent));
425 if (tc_magic_child != tc_magic_parent)
426 warning ("mismatched semaphore magic");
427
428 /* Discard our copy of the semaphore. */
429 (void) close (startup_semaphore.parent_channel[SEM_LISTEN]);
430 (void) close (startup_semaphore.parent_channel[SEM_TALK]);
431 (void) close (startup_semaphore.child_channel[SEM_LISTEN]);
432 (void) close (startup_semaphore.child_channel[SEM_TALK]);
433 #endif
434
435 return 0;
436 }
437 #endif
438
439 int
440 hppa_require_attach (pid)
441 int pid;
442 {
443 int pt_status;
444 CORE_ADDR pc;
445 CORE_ADDR pc_addr;
446 unsigned int regs_offset;
447
448 /* Are we already attached? There appears to be no explicit way to
449 answer this via ptrace, so we try something which should be
450 innocuous if we are attached. If that fails, then we assume
451 we're not attached, and so attempt to make it so. */
452
453 errno = 0;
454 regs_offset = U_REGS_OFFSET;
455 pc_addr = register_addr (PC_REGNUM, regs_offset);
456 pc = call_ptrace (PT_READ_U, pid, (PTRACE_ARG3_TYPE) pc_addr, 0);
457
458 if (errno)
459 {
460 errno = 0;
461 pt_status = call_ptrace (PT_ATTACH, pid, (PTRACE_ARG3_TYPE) 0, 0);
462
463 if (errno)
464 return -1;
465
466 /* Now we really are attached. */
467 errno = 0;
468 }
469 attach_flag = 1;
470 return pid;
471 }
472
473 int
474 hppa_require_detach (pid, signal)
475 int pid;
476 int signal;
477 {
478 errno = 0;
479 call_ptrace (PT_DETACH, pid, (PTRACE_ARG3_TYPE) 1, signal);
480 errno = 0; /* Ignore any errors. */
481 return pid;
482 }
483
484 /* Since ptrace doesn't support memory page-protection events, which
485 are used to implement "hardware" watchpoints on HP-UX, these are
486 dummy versions, which perform no useful work. */
487
488 void
489 hppa_enable_page_protection_events (pid)
490 int pid;
491 {
492 }
493
494 void
495 hppa_disable_page_protection_events (pid)
496 int pid;
497 {
498 }
499
500 int
501 hppa_insert_hw_watchpoint (pid, start, len, type)
502 int pid;
503 CORE_ADDR start;
504 LONGEST len;
505 int type;
506 {
507 error ("Hardware watchpoints not implemented on this platform.");
508 }
509
510 int
511 hppa_remove_hw_watchpoint (pid, start, len, type)
512 int pid;
513 CORE_ADDR start;
514 LONGEST len;
515 enum bptype type;
516 {
517 error ("Hardware watchpoints not implemented on this platform.");
518 }
519
520 int
521 hppa_can_use_hw_watchpoint (type, cnt, ot)
522 enum bptype type;
523 int cnt;
524 enum bptype ot;
525 {
526 return 0;
527 }
528
529 int
530 hppa_range_profitable_for_hw_watchpoint (pid, start, len)
531 int pid;
532 CORE_ADDR start;
533 LONGEST len;
534 {
535 error ("Hardware watchpoints not implemented on this platform.");
536 }
537
538 char *
539 hppa_pid_or_tid_to_str (id)
540 pid_t id;
541 {
542 /* In the ptrace world, there are only processes. */
543 return hppa_pid_to_str (id);
544 }
545
546 /* This function has no meaning in a non-threaded world. Thus, we
547 return 0 (FALSE). See the use of "hppa_prepare_to_proceed" in
548 hppa-tdep.c. */
549
550 pid_t
551 hppa_switched_threads (pid)
552 pid_t pid;
553 {
554 return (pid_t) 0;
555 }
556
557 void
558 hppa_ensure_vforking_parent_remains_stopped (pid)
559 int pid;
560 {
561 /* This assumes that the vforked parent is presently stopped, and
562 that the vforked child has just delivered its first exec event.
563 Calling kill() this way will cause the SIGTRAP to be delivered as
564 soon as the parent is resumed, which happens as soon as the
565 vforked child is resumed. See wait_for_inferior for the use of
566 this function. */
567 kill (pid, SIGTRAP);
568 }
569
570 int
571 hppa_resume_execd_vforking_child_to_get_parent_vfork ()
572 {
573 return 1; /* Yes, the child must be resumed. */
574 }
575
576 void
577 require_notification_of_events (pid)
578 int pid;
579 {
580 #if defined(PT_SET_EVENT_MASK)
581 int pt_status;
582 ptrace_event_t ptrace_events;
583
584 /* Instruct the kernel as to the set of events we wish to be
585 informed of. (This support does not exist before HPUX 10.0.
586 We'll assume if PT_SET_EVENT_MASK has not been defined by
587 <sys/ptrace.h>, then we're being built on pre-10.0.) */
588 memset (&ptrace_events, 0, sizeof (ptrace_events));
589
590 /* Note: By default, all signals are visible to us. If we wish
591 the kernel to keep certain signals hidden from us, we do it
592 by calling sigdelset (ptrace_events.pe_signals, signal) for
593 each such signal here, before doing PT_SET_EVENT_MASK. */
594 sigemptyset (&ptrace_events.pe_signals);
595
596 ptrace_events.pe_set_event = 0;
597
598 ptrace_events.pe_set_event |= PTRACE_SIGNAL;
599 ptrace_events.pe_set_event |= PTRACE_EXEC;
600 ptrace_events.pe_set_event |= PTRACE_FORK;
601 ptrace_events.pe_set_event |= PTRACE_VFORK;
602 /* ??rehrauer: Add this one when we're prepared to catch it...
603 ptrace_events.pe_set_event |= PTRACE_EXIT;
604 */
605
606 errno = 0;
607 pt_status = call_ptrace (PT_SET_EVENT_MASK,
608 pid,
609 (PTRACE_ARG3_TYPE) &ptrace_events,
610 sizeof (ptrace_events));
611 if (errno)
612 perror_with_name ("ptrace");
613 if (pt_status < 0)
614 return;
615 #endif
616 }
617
618 void
619 require_notification_of_exec_events (pid)
620 int pid;
621 {
622 #if defined(PT_SET_EVENT_MASK)
623 int pt_status;
624 ptrace_event_t ptrace_events;
625
626 /* Instruct the kernel as to the set of events we wish to be
627 informed of. (This support does not exist before HPUX 10.0.
628 We'll assume if PT_SET_EVENT_MASK has not been defined by
629 <sys/ptrace.h>, then we're being built on pre-10.0.) */
630 memset (&ptrace_events, 0, sizeof (ptrace_events));
631
632 /* Note: By default, all signals are visible to us. If we wish
633 the kernel to keep certain signals hidden from us, we do it
634 by calling sigdelset (ptrace_events.pe_signals, signal) for
635 each such signal here, before doing PT_SET_EVENT_MASK. */
636 sigemptyset (&ptrace_events.pe_signals);
637
638 ptrace_events.pe_set_event = 0;
639
640 ptrace_events.pe_set_event |= PTRACE_EXEC;
641 /* ??rehrauer: Add this one when we're prepared to catch it...
642 ptrace_events.pe_set_event |= PTRACE_EXIT;
643 */
644
645 errno = 0;
646 pt_status = call_ptrace (PT_SET_EVENT_MASK,
647 pid,
648 (PTRACE_ARG3_TYPE) &ptrace_events,
649 sizeof (ptrace_events));
650 if (errno)
651 perror_with_name ("ptrace");
652 if (pt_status < 0)
653 return;
654 #endif
655 }
656
657 /* This function is called by the parent process, with pid being the
658 ID of the child process, after the debugger has forked. */
659
660 void
661 child_acknowledge_created_inferior (pid)
662 int pid;
663 {
664 /* We need a memory home for a constant. */
665 int tc_magic_parent = PT_VERSION;
666 int tc_magic_child = 0;
667
668 /* The remainder of this function is only useful for HPUX 10.0 and
669 later, as it depends upon the ability to request notification
670 of specific kinds of events by the kernel. */
671 #if defined(PT_SET_EVENT_MASK)
672 /* Wait for the child to tell us that it has forked. */
673 read (startup_semaphore.child_channel[SEM_LISTEN],
674 &tc_magic_child,
675 sizeof(tc_magic_child));
676
677 /* Notify the child that it can exec.
678
679 In the infttrace.c variant of this function, we set the child's
680 event mask after the fork but before the exec. In the ptrace
681 world, it seems we can't set the event mask until after the exec. */
682 write (startup_semaphore.parent_channel[SEM_TALK],
683 &tc_magic_parent,
684 sizeof (tc_magic_parent));
685
686 /* We'd better pause a bit before trying to set the event mask,
687 though, to ensure that the exec has happened. We don't want to
688 wait() on the child, because that'll screw up the upper layers
689 of gdb's execution control that expect to see the exec event.
690
691 After an exec, the child is no longer executing gdb code. Hence,
692 we can't have yet another synchronization via the pipes. We'll
693 just sleep for a second, and hope that's enough delay... */
694 sleep (1);
695
696 /* Instruct the kernel as to the set of events we wish to be
697 informed of. */
698 require_notification_of_exec_events (pid);
699
700 /* Discard our copy of the semaphore. */
701 (void) close (startup_semaphore.parent_channel[SEM_LISTEN]);
702 (void) close (startup_semaphore.parent_channel[SEM_TALK]);
703 (void) close (startup_semaphore.child_channel[SEM_LISTEN]);
704 (void) close (startup_semaphore.child_channel[SEM_TALK]);
705 #endif
706 }
707
708 void
709 child_post_startup_inferior (pid)
710 int pid;
711 {
712 require_notification_of_events (pid);
713 }
714
715 void
716 child_post_attach (pid)
717 int pid;
718 {
719 require_notification_of_events (pid);
720 }
721
722 int
723 child_insert_fork_catchpoint (pid)
724 int pid;
725 {
726 /* This request is only available on HPUX 10.0 and later. */
727 #if !defined(PT_SET_EVENT_MASK)
728 error ("Unable to catch forks prior to HPUX 10.0");
729 #else
730 /* Enable reporting of fork events from the kernel. */
731 /* ??rehrauer: For the moment, we're always enabling these events,
732 and just ignoring them if there's no catchpoint to catch them. */
733 return 0;
734 #endif
735 }
736
737 int
738 child_remove_fork_catchpoint (pid)
739 int pid;
740 {
741 /* This request is only available on HPUX 10.0 and later. */
742 #if !defined(PT_SET_EVENT_MASK)
743 error ("Unable to catch forks prior to HPUX 10.0");
744 #else
745 /* Disable reporting of fork events from the kernel. */
746 /* ??rehrauer: For the moment, we're always enabling these events,
747 and just ignoring them if there's no catchpoint to catch them. */
748 return 0;
749 #endif
750 }
751
752 int
753 child_insert_vfork_catchpoint (pid)
754 int pid;
755 {
756 /* This request is only available on HPUX 10.0 and later. */
757 #if !defined(PT_SET_EVENT_MASK)
758 error ("Unable to catch vforks prior to HPUX 10.0");
759 #else
760 /* Enable reporting of vfork events from the kernel. */
761 /* ??rehrauer: For the moment, we're always enabling these events,
762 and just ignoring them if there's no catchpoint to catch them. */
763 return 0;
764 #endif
765 }
766
767 int
768 child_remove_vfork_catchpoint (pid)
769 int pid;
770 {
771 /* This request is only available on HPUX 10.0 and later. */
772 #if !defined(PT_SET_EVENT_MASK)
773 error ("Unable to catch vforks prior to HPUX 10.0");
774 #else
775 /* Disable reporting of vfork events from the kernel. */
776 /* ??rehrauer: For the moment, we're always enabling these events,
777 and just ignoring them if there's no catchpoint to catch them. */
778 return 0;
779 #endif
780 }
781
782 int
783 child_has_forked (pid, childpid)
784 int pid;
785 int *childpid;
786 {
787 /* This request is only available on HPUX 10.0 and later. */
788 #if !defined(PT_GET_PROCESS_STATE)
789 *childpid = 0;
790 return 0;
791 #else
792 int pt_status;
793 ptrace_state_t ptrace_state;
794
795 errno = 0;
796 pt_status = call_ptrace (PT_GET_PROCESS_STATE,
797 pid,
798 (PTRACE_ARG3_TYPE) &ptrace_state,
799 sizeof (ptrace_state));
800 if (errno)
801 perror_with_name ("ptrace");
802 if (pt_status < 0)
803 return 0;
804
805 if (ptrace_state.pe_report_event & PTRACE_FORK)
806 {
807 *childpid = ptrace_state.pe_other_pid;
808 return 1;
809 }
810
811 return 0;
812 #endif
813 }
814
815 int
816 child_has_vforked (pid, childpid)
817 int pid;
818 int *childpid;
819 {
820 /* This request is only available on HPUX 10.0 and later. */
821 #if !defined(PT_GET_PROCESS_STATE)
822 *childpid = 0;
823 return 0;
824
825 #else
826 int pt_status;
827 ptrace_state_t ptrace_state;
828
829 errno = 0;
830 pt_status = call_ptrace (PT_GET_PROCESS_STATE,
831 pid,
832 (PTRACE_ARG3_TYPE) &ptrace_state,
833 sizeof (ptrace_state));
834 if (errno)
835 perror_with_name ("ptrace");
836 if (pt_status < 0)
837 return 0;
838
839 if (ptrace_state.pe_report_event & PTRACE_VFORK)
840 {
841 *childpid = ptrace_state.pe_other_pid;
842 return 1;
843 }
844
845 return 0;
846 #endif
847 }
848
849 int
850 child_can_follow_vfork_prior_to_exec ()
851 {
852 /* ptrace doesn't allow this. */
853 return 0;
854 }
855
856 int
857 child_insert_exec_catchpoint (pid)
858 int pid;
859 {
860 /* This request is only available on HPUX 10.0 and later. */
861 #if !defined(PT_SET_EVENT_MASK)
862 error ("Unable to catch execs prior to HPUX 10.0");
863
864 #else
865 /* Enable reporting of exec events from the kernel. */
866 /* ??rehrauer: For the moment, we're always enabling these events,
867 and just ignoring them if there's no catchpoint to catch them. */
868 return 0;
869 #endif
870 }
871
872 int
873 child_remove_exec_catchpoint (pid)
874 int pid;
875 {
876 /* This request is only available on HPUX 10.0 and later. */
877 #if !defined(PT_SET_EVENT_MASK)
878 error ("Unable to catch execs prior to HPUX 10.0");
879
880 #else
881 /* Disable reporting of exec events from the kernel. */
882 /* ??rehrauer: For the moment, we're always enabling these events,
883 and just ignoring them if there's no catchpoint to catch them. */
884 return 0;
885 #endif
886 }
887
888 int
889 child_has_execd (pid, execd_pathname)
890 int pid;
891 char **execd_pathname;
892 {
893 /* This request is only available on HPUX 10.0 and later. */
894 #if !defined(PT_GET_PROCESS_STATE)
895 *execd_pathname = NULL;
896 return 0;
897
898 #else
899 int pt_status;
900 ptrace_state_t ptrace_state;
901
902 errno = 0;
903 pt_status = call_ptrace (PT_GET_PROCESS_STATE,
904 pid,
905 (PTRACE_ARG3_TYPE) &ptrace_state,
906 sizeof (ptrace_state));
907 if (errno)
908 perror_with_name ("ptrace");
909 if (pt_status < 0)
910 return 0;
911
912 if (ptrace_state.pe_report_event & PTRACE_EXEC)
913 {
914 char * exec_file = target_pid_to_exec_file (pid);
915 *execd_pathname = savestring (exec_file, strlen (exec_file));
916 return 1;
917 }
918
919 return 0;
920 #endif
921 }
922
923 int
924 child_reported_exec_events_per_exec_call ()
925 {
926 return 2; /* ptrace reports the event twice per call. */
927 }
928
929 int
930 child_has_syscall_event (pid, kind, syscall_id)
931 int pid;
932 enum target_waitkind *kind;
933 int *syscall_id;
934 {
935 /* This request is only available on HPUX 10.30 and later, via
936 the ttrace interface. */
937
938 *kind = TARGET_WAITKIND_SPURIOUS;
939 *syscall_id = -1;
940 return 0;
941 }
942
943 char *
944 child_pid_to_exec_file (pid)
945 int pid;
946 {
947 static char exec_file_buffer[1024];
948 int pt_status;
949 CORE_ADDR top_of_stack;
950 char four_chars[4];
951 int name_index;
952 int i;
953 int saved_inferior_pid;
954 boolean done;
955
956 #ifdef PT_GET_PROCESS_PATHNAME
957 /* As of 10.x HP-UX, there's an explicit request to get the pathname. */
958 pt_status = call_ptrace (PT_GET_PROCESS_PATHNAME,
959 pid,
960 (PTRACE_ARG3_TYPE) exec_file_buffer,
961 sizeof (exec_file_buffer) - 1);
962 if (pt_status == 0)
963 return exec_file_buffer;
964 #endif
965
966 /* It appears that this request is broken prior to 10.30.
967 If it fails, try a really, truly amazingly gross hack
968 that DDE uses, of pawing through the process' data
969 segment to find the pathname. */
970
971 top_of_stack = 0x7b03a000;
972 name_index = 0;
973 done = 0;
974
975 /* On the chance that pid != inferior_pid, set inferior_pid
976 to pid, so that (grrrr!) implicit uses of inferior_pid get
977 the right id. */
978
979 saved_inferior_pid = inferior_pid;
980 inferior_pid = pid;
981
982 /* Try to grab a null-terminated string. */
983 while (! done)
984 {
985 if (target_read_memory (top_of_stack, four_chars, 4) != 0)
986 {
987 inferior_pid = saved_inferior_pid;
988 return NULL;
989 }
990 for (i = 0; i < 4; i++)
991 {
992 exec_file_buffer[name_index++] = four_chars[i];
993 done = (four_chars[i] == '\0');
994 if (done)
995 break;
996 }
997 top_of_stack += 4;
998 }
999
1000 if (exec_file_buffer[0] == '\0')
1001 {
1002 inferior_pid = saved_inferior_pid;
1003 return NULL;
1004 }
1005
1006 inferior_pid = saved_inferior_pid;
1007 return exec_file_buffer;
1008 }
1009
1010 void
1011 pre_fork_inferior ()
1012 {
1013 int status;
1014
1015 status = pipe (startup_semaphore.parent_channel);
1016 if (status < 0)
1017 {
1018 warning ("error getting parent pipe for startup semaphore");
1019 return;
1020 }
1021
1022 status = pipe (startup_semaphore.child_channel);
1023 if (status < 0)
1024 {
1025 warning ("error getting child pipe for startup semaphore");
1026 return;
1027 }
1028 }
1029
1030 \f
1031 /* Check to see if the given thread is alive.
1032
1033 This is a no-op, as ptrace doesn't support threads, so we just
1034 return "TRUE". */
1035
1036 int
1037 child_thread_alive (pid)
1038 int pid;
1039 {
1040 return 1;
1041 }
1042
1043 #endif /* ! GDB_NATIVE_HPUX_11 */
This page took 0.065715 seconds and 4 git commands to generate.