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