2003-11-22 Andrew Cagney <cagney@redhat.com>
[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, 1994, 1995, 1996,
3 1998, 1999, 2000, 2001
4 Free Software Foundation, Inc.
5
6 Contributed by the Center for Software Science at the
7 University of Utah (pa-gdb-bugs@cs.utah.edu).
8
9 This file is part of GDB.
10
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.
15
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.
20
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. */
25
26
27 #include "defs.h"
28 #include "inferior.h"
29 #include "target.h"
30 #include <sys/ptrace.h>
31 #include "gdbcore.h"
32 #include "gdb_wait.h"
33 #include "regcache.h"
34 #include "gdb_string.h"
35 #include <signal.h>
36
37 extern int hpux_has_forked (int pid, int *childpid);
38 extern int hpux_has_vforked (int pid, int *childpid);
39 extern int hpux_has_execd (int pid, char **execd_pathname);
40 extern int hpux_has_syscall_event (int pid, enum target_waitkind *kind,
41 int *syscall_id);
42
43 static CORE_ADDR text_end;
44
45 void
46 deprecated_hpux_text_end (struct target_ops *exec_ops)
47 {
48 struct section_table *p;
49
50 /* Set text_end to the highest address of the end of any readonly
51 code section. */
52 /* FIXME: The comment above does not match the code. The code
53 checks for sections with are either code *or* readonly. */
54 text_end = (CORE_ADDR) 0;
55 for (p = exec_ops->to_sections; p < exec_ops->to_sections_end; p++)
56 if (bfd_get_section_flags (p->bfd, p->the_bfd_section)
57 & (SEC_CODE | SEC_READONLY))
58 {
59 if (text_end < p->endaddr)
60 text_end = p->endaddr;
61 }
62 }
63
64
65 static void fetch_register (int);
66
67 void
68 fetch_inferior_registers (int regno)
69 {
70 if (regno == -1)
71 for (regno = 0; regno < NUM_REGS; regno++)
72 fetch_register (regno);
73 else
74 fetch_register (regno);
75 }
76
77 /* Our own version of the offsetof macro, since we can't assume ANSI C. */
78 #define HPPAH_OFFSETOF(type, member) ((int) (&((type *) 0)->member))
79
80 /* Store our register values back into the inferior.
81 If REGNO is -1, do this for all registers.
82 Otherwise, REGNO specifies which register (so we can save time). */
83
84 void
85 store_inferior_registers (int regno)
86 {
87 unsigned int regaddr;
88 char buf[80];
89 int i;
90 unsigned int offset = U_REGS_OFFSET;
91 int scratch;
92
93 if (regno >= 0)
94 {
95 unsigned int addr, len, offset;
96
97 if (CANNOT_STORE_REGISTER (regno))
98 return;
99
100 offset = 0;
101 len = DEPRECATED_REGISTER_RAW_SIZE (regno);
102
103 /* Requests for register zero actually want the save_state's
104 ss_flags member. As RM says: "Oh, what a hack!" */
105 if (regno == 0)
106 {
107 save_state_t ss;
108 addr = HPPAH_OFFSETOF (save_state_t, ss_flags);
109 len = sizeof (ss.ss_flags);
110
111 /* Note that ss_flags is always an int, no matter what
112 DEPRECATED_REGISTER_RAW_SIZE(0) says. Assuming all HP-UX
113 PA machines are big-endian, put it at the least
114 significant end of the value, and zap the rest of the
115 buffer. */
116 offset = DEPRECATED_REGISTER_RAW_SIZE (0) - len;
117 }
118
119 /* Floating-point registers come from the ss_fpblock area. */
120 else if (regno >= FP0_REGNUM)
121 addr = (HPPAH_OFFSETOF (save_state_t, ss_fpblock)
122 + (DEPRECATED_REGISTER_BYTE (regno) - DEPRECATED_REGISTER_BYTE (FP0_REGNUM)));
123
124 /* Wide registers come from the ss_wide area.
125 I think it's more PC to test (ss_flags & SS_WIDEREGS) to select
126 between ss_wide and ss_narrow than to use the raw register size.
127 But checking ss_flags would require an extra ptrace call for
128 every register reference. Bleah. */
129 else if (len == 8)
130 addr = (HPPAH_OFFSETOF (save_state_t, ss_wide)
131 + DEPRECATED_REGISTER_BYTE (regno));
132
133 /* Narrow registers come from the ss_narrow area. Note that
134 ss_narrow starts with gr1, not gr0. */
135 else if (len == 4)
136 addr = (HPPAH_OFFSETOF (save_state_t, ss_narrow)
137 + (DEPRECATED_REGISTER_BYTE (regno) - DEPRECATED_REGISTER_BYTE (1)));
138 else
139 internal_error (__FILE__, __LINE__,
140 "hppah-nat.c (write_register): unexpected register size");
141
142 #ifdef GDB_TARGET_IS_HPPA_20W
143 /* Unbelieveable. The PC head and tail must be written in 64bit hunks
144 or we will get an error. Worse yet, the oddball ptrace/ttrace
145 layering will not allow us to perform a 64bit register store.
146
147 What a crock. */
148 if (regno == PCOQ_HEAD_REGNUM || regno == PCOQ_TAIL_REGNUM && len == 8)
149 {
150 CORE_ADDR temp;
151
152 temp = *(CORE_ADDR *)&deprecated_registers[DEPRECATED_REGISTER_BYTE (regno)];
153
154 /* Set the priv level (stored in the low two bits of the PC. */
155 temp |= 0x3;
156
157 ttrace_write_reg_64 (PIDGET (inferior_ptid), (CORE_ADDR)addr,
158 (CORE_ADDR)&temp);
159
160 /* If we fail to write the PC, give a true error instead of
161 just a warning. */
162 if (errno != 0)
163 {
164 char *err = safe_strerror (errno);
165 char *msg = alloca (strlen (err) + 128);
166 sprintf (msg, "writing `%s' register: %s",
167 REGISTER_NAME (regno), err);
168 perror_with_name (msg);
169 }
170 return;
171 }
172
173 /* Another crock. HPUX complains if you write a nonzero value to
174 the high part of IPSW. What will it take for HP to catch a
175 clue about building sensible interfaces? */
176 if (regno == IPSW_REGNUM && len == 8)
177 *(int *)&deprecated_registers[DEPRECATED_REGISTER_BYTE (regno)] = 0;
178 #endif
179
180 for (i = 0; i < len; i += sizeof (int))
181 {
182 errno = 0;
183 call_ptrace (PT_WUREGS, PIDGET (inferior_ptid),
184 (PTRACE_ARG3_TYPE) addr + i,
185 *(int *) &deprecated_registers[DEPRECATED_REGISTER_BYTE (regno) + i]);
186 if (errno != 0)
187 {
188 /* Warning, not error, in case we are attached; sometimes
189 the kernel doesn't let us at the registers. */
190 char *err = safe_strerror (errno);
191 char *msg = alloca (strlen (err) + 128);
192 sprintf (msg, "writing `%s' register: %s",
193 REGISTER_NAME (regno), err);
194 /* If we fail to write the PC, give a true error instead of
195 just a warning. */
196 if (regno == PCOQ_HEAD_REGNUM || regno == PCOQ_TAIL_REGNUM)
197 perror_with_name (msg);
198 else
199 warning (msg);
200 return;
201 }
202 }
203 }
204 else
205 for (regno = 0; regno < NUM_REGS; regno++)
206 store_inferior_registers (regno);
207 }
208
209
210 /* Fetch a register's value from the process's U area. */
211 static void
212 fetch_register (int regno)
213 {
214 char buf[MAX_REGISTER_SIZE];
215 unsigned int addr, len, offset;
216 int i;
217
218 offset = 0;
219 len = DEPRECATED_REGISTER_RAW_SIZE (regno);
220
221 /* Requests for register zero actually want the save_state's
222 ss_flags member. As RM says: "Oh, what a hack!" */
223 if (regno == 0)
224 {
225 save_state_t ss;
226 addr = HPPAH_OFFSETOF (save_state_t, ss_flags);
227 len = sizeof (ss.ss_flags);
228
229 /* Note that ss_flags is always an int, no matter what
230 DEPRECATED_REGISTER_RAW_SIZE(0) says. Assuming all HP-UX PA
231 machines are big-endian, put it at the least significant end
232 of the value, and zap the rest of the buffer. */
233 offset = DEPRECATED_REGISTER_RAW_SIZE (0) - len;
234 memset (buf, 0, sizeof (buf));
235 }
236
237 /* Floating-point registers come from the ss_fpblock area. */
238 else if (regno >= FP0_REGNUM)
239 addr = (HPPAH_OFFSETOF (save_state_t, ss_fpblock)
240 + (DEPRECATED_REGISTER_BYTE (regno) - DEPRECATED_REGISTER_BYTE (FP0_REGNUM)));
241
242 /* Wide registers come from the ss_wide area.
243 I think it's more PC to test (ss_flags & SS_WIDEREGS) to select
244 between ss_wide and ss_narrow than to use the raw register size.
245 But checking ss_flags would require an extra ptrace call for
246 every register reference. Bleah. */
247 else if (len == 8)
248 addr = (HPPAH_OFFSETOF (save_state_t, ss_wide)
249 + DEPRECATED_REGISTER_BYTE (regno));
250
251 /* Narrow registers come from the ss_narrow area. Note that
252 ss_narrow starts with gr1, not gr0. */
253 else if (len == 4)
254 addr = (HPPAH_OFFSETOF (save_state_t, ss_narrow)
255 + (DEPRECATED_REGISTER_BYTE (regno) - DEPRECATED_REGISTER_BYTE (1)));
256
257 else
258 internal_error (__FILE__, __LINE__,
259 "hppa-nat.c (fetch_register): unexpected register size");
260
261 for (i = 0; i < len; i += sizeof (int))
262 {
263 errno = 0;
264 /* Copy an int from the U area to buf. Fill the least
265 significant end if len != raw_size. */
266 * (int *) &buf[offset + i] =
267 call_ptrace (PT_RUREGS, PIDGET (inferior_ptid),
268 (PTRACE_ARG3_TYPE) addr + i, 0);
269 if (errno != 0)
270 {
271 /* Warning, not error, in case we are attached; sometimes
272 the kernel doesn't let us at the registers. */
273 char *err = safe_strerror (errno);
274 char *msg = alloca (strlen (err) + 128);
275 sprintf (msg, "reading `%s' register: %s",
276 REGISTER_NAME (regno), err);
277 warning (msg);
278 return;
279 }
280 }
281
282 /* If we're reading an address from the instruction address queue,
283 mask out the bottom two bits --- they contain the privilege
284 level. */
285 if (regno == PCOQ_HEAD_REGNUM || regno == PCOQ_TAIL_REGNUM)
286 buf[len - 1] &= ~0x3;
287
288 supply_register (regno, buf);
289 }
290
291
292 /* Copy LEN bytes to or from inferior's memory starting at MEMADDR
293 to debugger memory starting at MYADDR. Copy to inferior if
294 WRITE is nonzero.
295
296 Returns the length copied, which is either the LEN argument or zero.
297 This xfer function does not do partial moves, since child_ops
298 doesn't allow memory operations to cross below us in the target stack
299 anyway. TARGET is ignored. */
300
301 int
302 child_xfer_memory (CORE_ADDR memaddr, char *myaddr, int len, int write,
303 struct mem_attrib *mem,
304 struct target_ops *target)
305 {
306 int i;
307 /* Round starting address down to longword boundary. */
308 CORE_ADDR addr = memaddr & - (CORE_ADDR)(sizeof (int));
309 /* Round ending address up; get number of longwords that makes. */
310 int count
311 = (((memaddr + len) - addr) + sizeof (int) - 1) / sizeof (int);
312
313 /* Allocate buffer of that many longwords.
314 Note -- do not use alloca to allocate this buffer since there is no
315 guarantee of when the buffer will actually be deallocated.
316
317 This routine can be called over and over with the same call chain;
318 this (in effect) would pile up all those alloca requests until a call
319 to alloca was made from a point higher than this routine in the
320 call chain. */
321 int *buffer = (int *) xmalloc (count * sizeof (int));
322
323 if (write)
324 {
325 /* Fill start and end extra bytes of buffer with existing memory data. */
326 if (addr != memaddr || len < (int) sizeof (int))
327 {
328 /* Need part of initial word -- fetch it. */
329 buffer[0] = call_ptrace (addr < text_end ? PT_RIUSER : PT_RDUSER,
330 PIDGET (inferior_ptid),
331 (PTRACE_ARG3_TYPE) addr, 0);
332 }
333
334 if (count > 1) /* FIXME, avoid if even boundary */
335 {
336 buffer[count - 1]
337 = call_ptrace (addr < text_end ? PT_RIUSER : PT_RDUSER,
338 PIDGET (inferior_ptid),
339 (PTRACE_ARG3_TYPE) (addr
340 + (count - 1) * sizeof (int)),
341 0);
342 }
343
344 /* Copy data to be written over corresponding part of buffer */
345 memcpy ((char *) buffer + (memaddr & (sizeof (int) - 1)), myaddr, len);
346
347 /* Write the entire buffer. */
348 for (i = 0; i < count; i++, addr += sizeof (int))
349 {
350 int pt_status;
351 int pt_request;
352 /* The HP-UX kernel crashes if you use PT_WDUSER to write into the
353 text segment. FIXME -- does it work to write into the data
354 segment using WIUSER, or do these idiots really expect us to
355 figure out which segment the address is in, so we can use a
356 separate system call for it??! */
357 errno = 0;
358 pt_request = (addr < text_end) ? PT_WIUSER : PT_WDUSER;
359 pt_status = call_ptrace (pt_request,
360 PIDGET (inferior_ptid),
361 (PTRACE_ARG3_TYPE) addr,
362 buffer[i]);
363
364 /* Did we fail? Might we've guessed wrong about which
365 segment this address resides in? Try the other request,
366 and see if that works... */
367 if ((pt_status == -1) && errno)
368 {
369 errno = 0;
370 pt_request = (pt_request == PT_WIUSER) ? PT_WDUSER : PT_WIUSER;
371 pt_status = call_ptrace (pt_request,
372 PIDGET (inferior_ptid),
373 (PTRACE_ARG3_TYPE) addr,
374 buffer[i]);
375
376 /* No, we still fail. Okay, time to punt. */
377 if ((pt_status == -1) && errno)
378 {
379 xfree (buffer);
380 return 0;
381 }
382 }
383 }
384 }
385 else
386 {
387 /* Read all the longwords */
388 for (i = 0; i < count; i++, addr += sizeof (int))
389 {
390 errno = 0;
391 buffer[i] = call_ptrace (addr < text_end ? PT_RIUSER : PT_RDUSER,
392 PIDGET (inferior_ptid),
393 (PTRACE_ARG3_TYPE) addr, 0);
394 if (errno)
395 {
396 xfree (buffer);
397 return 0;
398 }
399 QUIT;
400 }
401
402 /* Copy appropriate bytes out of the buffer. */
403 memcpy (myaddr, (char *) buffer + (memaddr & (sizeof (int) - 1)), len);
404 }
405 xfree (buffer);
406 return len;
407 }
408
409 char *saved_child_execd_pathname = NULL;
410 int saved_vfork_pid;
411 enum {
412 STATE_NONE,
413 STATE_GOT_CHILD,
414 STATE_GOT_EXEC,
415 STATE_GOT_PARENT,
416 STATE_FAKE_EXEC
417 } saved_vfork_state = STATE_NONE;
418
419 int
420 child_follow_fork (int follow_child)
421 {
422 ptid_t last_ptid;
423 struct target_waitstatus last_status;
424 int has_vforked;
425 int parent_pid, child_pid;
426
427 get_last_target_status (&last_ptid, &last_status);
428 has_vforked = (last_status.kind == TARGET_WAITKIND_VFORKED);
429 parent_pid = ptid_get_pid (last_ptid);
430 child_pid = last_status.value.related_pid;
431
432 /* At this point, if we are vforking, breakpoints were already
433 detached from the child in child_wait; and the child has already
434 called execve(). If we are forking, both the parent and child
435 have breakpoints inserted. */
436
437 if (! follow_child)
438 {
439 if (! has_vforked)
440 {
441 detach_breakpoints (child_pid);
442 #ifdef SOLIB_REMOVE_INFERIOR_HOOK
443 SOLIB_REMOVE_INFERIOR_HOOK (child_pid);
444 #endif
445 }
446
447 /* Detach from the child. */
448 printf_unfiltered ("Detaching after fork from %s\n",
449 target_pid_to_str (pid_to_ptid (child_pid)));
450 hppa_require_detach (child_pid, 0);
451
452 /* The parent and child of a vfork share the same address space.
453 Also, on some targets the order in which vfork and exec events
454 are received for parent in child requires some delicate handling
455 of the events.
456
457 For instance, on ptrace-based HPUX we receive the child's vfork
458 event first, at which time the parent has been suspended by the
459 OS and is essentially untouchable until the child's exit or second
460 exec event arrives. At that time, the parent's vfork event is
461 delivered to us, and that's when we see and decide how to follow
462 the vfork. But to get to that point, we must continue the child
463 until it execs or exits. To do that smoothly, all breakpoints
464 must be removed from the child, in case there are any set between
465 the vfork() and exec() calls. But removing them from the child
466 also removes them from the parent, due to the shared-address-space
467 nature of a vfork'd parent and child. On HPUX, therefore, we must
468 take care to restore the bp's to the parent before we continue it.
469 Else, it's likely that we may not stop in the expected place. (The
470 worst scenario is when the user tries to step over a vfork() call;
471 the step-resume bp must be restored for the step to properly stop
472 in the parent after the call completes!)
473
474 Sequence of events, as reported to gdb from HPUX:
475
476 Parent Child Action for gdb to take
477 -------------------------------------------------------
478 1 VFORK Continue child
479 2 EXEC
480 3 EXEC or EXIT
481 4 VFORK
482
483 Now that the child has safely exec'd or exited, we must restore
484 the parent's breakpoints before we continue it. Else, we may
485 cause it run past expected stopping points. */
486
487 if (has_vforked)
488 reattach_breakpoints (parent_pid);
489 }
490 else
491 {
492 /* Needed to keep the breakpoint lists in sync. */
493 if (! has_vforked)
494 detach_breakpoints (child_pid);
495
496 /* Before detaching from the parent, remove all breakpoints from it. */
497 remove_breakpoints ();
498
499 /* Also reset the solib inferior hook from the parent. */
500 #ifdef SOLIB_REMOVE_INFERIOR_HOOK
501 SOLIB_REMOVE_INFERIOR_HOOK (PIDGET (inferior_ptid));
502 #endif
503
504 /* Detach from the parent. */
505 target_detach (NULL, 1);
506
507 /* Attach to the child. */
508 printf_unfiltered ("Attaching after fork to %s\n",
509 target_pid_to_str (pid_to_ptid (child_pid)));
510 hppa_require_attach (child_pid);
511 inferior_ptid = pid_to_ptid (child_pid);
512
513 /* If we vforked, then we've also execed by now. The exec will be
514 reported momentarily. follow_exec () will handle breakpoints, so
515 we don't have to.. */
516 if (!has_vforked)
517 follow_inferior_reset_breakpoints ();
518 }
519
520 if (has_vforked)
521 {
522 /* If we followed the parent, don't try to follow the child's exec. */
523 if (saved_vfork_state != STATE_GOT_PARENT
524 && saved_vfork_state != STATE_FAKE_EXEC)
525 fprintf_unfiltered (gdb_stdout,
526 "hppa: post follow vfork: confused state\n");
527
528 if (! follow_child || saved_vfork_state == STATE_GOT_PARENT)
529 saved_vfork_state = STATE_NONE;
530 else
531 return 1;
532 }
533 return 0;
534 }
535
536 /* Format a process id, given PID. Be sure to terminate
537 this with a null--it's going to be printed via a "%s". */
538 char *
539 child_pid_to_str (ptid_t ptid)
540 {
541 /* Static because address returned */
542 static char buf[30];
543 pid_t pid = PIDGET (ptid);
544
545 /* Extra NUL for paranoia's sake */
546 sprintf (buf, "process %d%c", pid, '\0');
547
548 return buf;
549 }
550
551 /* Format a thread id, given TID. Be sure to terminate
552 this with a null--it's going to be printed via a "%s".
553
554 Note: This is a core-gdb tid, not the actual system tid.
555 See infttrace.c for details. */
556 char *
557 hppa_tid_to_str (ptid_t ptid)
558 {
559 /* Static because address returned */
560 static char buf[30];
561 /* This seems strange, but when I did the ptid conversion, it looked
562 as though a pid was always being passed. - Kevin Buettner */
563 pid_t tid = PIDGET (ptid);
564
565 /* Extra NULLs for paranoia's sake */
566 sprintf (buf, "system thread %d%c", tid, '\0');
567
568 return buf;
569 }
570
571 /*## */
572 /* Enable HACK for ttrace work. In
573 * infttrace.c/require_notification_of_events,
574 * this is set to 0 so that the loop in child_wait
575 * won't loop.
576 */
577 int not_same_real_pid = 1;
578 /*## */
579
580 /* Wait for child to do something. Return pid of child, or -1 in case
581 of error; store status through argument pointer OURSTATUS. */
582
583 ptid_t
584 child_wait (ptid_t ptid, struct target_waitstatus *ourstatus)
585 {
586 int save_errno;
587 int status;
588 char *execd_pathname = NULL;
589 int exit_status;
590 int related_pid;
591 int syscall_id;
592 enum target_waitkind kind;
593 int pid;
594
595 if (saved_vfork_state == STATE_FAKE_EXEC)
596 {
597 saved_vfork_state = STATE_NONE;
598 ourstatus->kind = TARGET_WAITKIND_EXECD;
599 ourstatus->value.execd_pathname = saved_child_execd_pathname;
600 return inferior_ptid;
601 }
602
603 do
604 {
605 set_sigint_trap (); /* Causes SIGINT to be passed on to the
606 attached process. */
607 set_sigio_trap ();
608
609 pid = ptrace_wait (inferior_ptid, &status);
610
611 save_errno = errno;
612
613 clear_sigio_trap ();
614
615 clear_sigint_trap ();
616
617 if (pid == -1)
618 {
619 if (save_errno == EINTR)
620 continue;
621
622 fprintf_unfiltered (gdb_stderr, "Child process unexpectedly missing: %s.\n",
623 safe_strerror (save_errno));
624
625 /* Claim it exited with unknown signal. */
626 ourstatus->kind = TARGET_WAITKIND_SIGNALLED;
627 ourstatus->value.sig = TARGET_SIGNAL_UNKNOWN;
628 return pid_to_ptid (-1);
629 }
630
631 /* Did it exit?
632 */
633 if (target_has_exited (pid, status, &exit_status))
634 {
635 /* ??rehrauer: For now, ignore this. */
636 continue;
637 }
638
639 if (!target_thread_alive (pid_to_ptid (pid)))
640 {
641 ourstatus->kind = TARGET_WAITKIND_SPURIOUS;
642 return pid_to_ptid (pid);
643 }
644
645 if (hpux_has_forked (pid, &related_pid))
646 {
647 /* Ignore the parent's fork event. */
648 if (pid == PIDGET (inferior_ptid))
649 {
650 ourstatus->kind = TARGET_WAITKIND_IGNORE;
651 return inferior_ptid;
652 }
653
654 /* If this is the child's fork event, report that the
655 process has forked. */
656 if (related_pid == PIDGET (inferior_ptid))
657 {
658 ourstatus->kind = TARGET_WAITKIND_FORKED;
659 ourstatus->value.related_pid = pid;
660 return inferior_ptid;
661 }
662 }
663
664 if (hpux_has_vforked (pid, &related_pid))
665 {
666 if (pid == PIDGET (inferior_ptid))
667 {
668 if (saved_vfork_state == STATE_GOT_CHILD)
669 saved_vfork_state = STATE_GOT_PARENT;
670 else if (saved_vfork_state == STATE_GOT_EXEC)
671 saved_vfork_state = STATE_FAKE_EXEC;
672 else
673 fprintf_unfiltered (gdb_stdout,
674 "hppah: parent vfork: confused\n");
675 }
676 else if (related_pid == PIDGET (inferior_ptid))
677 {
678 if (saved_vfork_state == STATE_NONE)
679 saved_vfork_state = STATE_GOT_CHILD;
680 else
681 fprintf_unfiltered (gdb_stdout,
682 "hppah: child vfork: confused\n");
683 }
684 else
685 fprintf_unfiltered (gdb_stdout,
686 "hppah: unknown vfork: confused\n");
687
688 if (saved_vfork_state == STATE_GOT_CHILD)
689 {
690 child_post_startup_inferior (pid_to_ptid (pid));
691 detach_breakpoints (pid);
692 #ifdef SOLIB_REMOVE_INFERIOR_HOOK
693 SOLIB_REMOVE_INFERIOR_HOOK (pid);
694 #endif
695 child_resume (pid_to_ptid (pid), 0, TARGET_SIGNAL_0);
696 ourstatus->kind = TARGET_WAITKIND_IGNORE;
697 return pid_to_ptid (related_pid);
698 }
699 else if (saved_vfork_state == STATE_FAKE_EXEC)
700 {
701 ourstatus->kind = TARGET_WAITKIND_VFORKED;
702 ourstatus->value.related_pid = related_pid;
703 return pid_to_ptid (pid);
704 }
705 else
706 {
707 /* We saw the parent's vfork, but we haven't seen the exec yet.
708 Wait for it, for simplicity's sake. It should be pending. */
709 saved_vfork_pid = related_pid;
710 ourstatus->kind = TARGET_WAITKIND_IGNORE;
711 return pid_to_ptid (pid);
712 }
713 }
714
715 if (hpux_has_execd (pid, &execd_pathname))
716 {
717 /* On HP-UX, events associated with a vforking inferior come in
718 threes: a vfork event for the child (always first), followed
719 a vfork event for the parent and an exec event for the child.
720 The latter two can come in either order. Make sure we get
721 both. */
722 if (saved_vfork_state != STATE_NONE)
723 {
724 if (saved_vfork_state == STATE_GOT_CHILD)
725 {
726 saved_vfork_state = STATE_GOT_EXEC;
727 /* On HP/UX with ptrace, the child must be resumed before
728 the parent vfork event is delivered. A single-step
729 suffices. */
730 if (RESUME_EXECD_VFORKING_CHILD_TO_GET_PARENT_VFORK ())
731 target_resume (pid_to_ptid (pid), 1, TARGET_SIGNAL_0);
732 ourstatus->kind = TARGET_WAITKIND_IGNORE;
733 }
734 else if (saved_vfork_state == STATE_GOT_PARENT)
735 {
736 saved_vfork_state = STATE_FAKE_EXEC;
737 ourstatus->kind = TARGET_WAITKIND_VFORKED;
738 ourstatus->value.related_pid = saved_vfork_pid;
739 }
740 else
741 fprintf_unfiltered (gdb_stdout,
742 "hppa: exec: unexpected state\n");
743
744 saved_child_execd_pathname = execd_pathname;
745
746 return inferior_ptid;
747 }
748
749 /* Are we ignoring initial exec events? (This is likely because
750 we're in the process of starting up the inferior, and another
751 (older) mechanism handles those.) If so, we'll report this
752 as a regular stop, not an exec.
753 */
754 if (inferior_ignoring_startup_exec_events)
755 {
756 inferior_ignoring_startup_exec_events--;
757 }
758 else
759 {
760 ourstatus->kind = TARGET_WAITKIND_EXECD;
761 ourstatus->value.execd_pathname = execd_pathname;
762 return pid_to_ptid (pid);
763 }
764 }
765
766 /* All we must do with these is communicate their occurrence
767 to wait_for_inferior...
768 */
769 if (hpux_has_syscall_event (pid, &kind, &syscall_id))
770 {
771 ourstatus->kind = kind;
772 ourstatus->value.syscall_id = syscall_id;
773 return pid_to_ptid (pid);
774 }
775
776 /*## } while (pid != PIDGET (inferior_ptid)); ## *//* Some other child died or stopped */
777 /* hack for thread testing */
778 }
779 while ((pid != PIDGET (inferior_ptid)) && not_same_real_pid);
780 /*## */
781
782 store_waitstatus (ourstatus, status);
783 return pid_to_ptid (pid);
784 }
785
786 #if !defined (GDB_NATIVE_HPUX_11)
787
788 /* The following code is a substitute for the infttrace.c versions used
789 with ttrace() in HPUX 11. */
790
791 /* This value is an arbitrary integer. */
792 #define PT_VERSION 123456
793
794 /* This semaphore is used to coordinate the child and parent processes
795 after a fork(), and before an exec() by the child. See
796 parent_attach_all for details. */
797
798 typedef struct
799 {
800 int parent_channel[2]; /* Parent "talks" to [1], child "listens" to [0] */
801 int child_channel[2]; /* Child "talks" to [1], parent "listens" to [0] */
802 }
803 startup_semaphore_t;
804
805 #define SEM_TALK (1)
806 #define SEM_LISTEN (0)
807
808 static startup_semaphore_t startup_semaphore;
809
810 #ifdef PT_SETTRC
811 /* This function causes the caller's process to be traced by its
812 parent. This is intended to be called after GDB forks itself,
813 and before the child execs the target.
814
815 Note that HP-UX ptrace is rather funky in how this is done.
816 If the parent wants to get the initial exec event of a child,
817 it must set the ptrace event mask of the child to include execs.
818 (The child cannot do this itself.) This must be done after the
819 child is forked, but before it execs.
820
821 To coordinate the parent and child, we implement a semaphore using
822 pipes. After SETTRC'ing itself, the child tells the parent that
823 it is now traceable by the parent, and waits for the parent's
824 acknowledgement. The parent can then set the child's event mask,
825 and notify the child that it can now exec.
826
827 (The acknowledgement by parent happens as a result of a call to
828 child_acknowledge_created_inferior.) */
829
830 int
831 parent_attach_all (int pid, PTRACE_ARG3_TYPE addr, int data)
832 {
833 int pt_status = 0;
834
835 /* We need a memory home for a constant. */
836 int tc_magic_child = PT_VERSION;
837 int tc_magic_parent = 0;
838
839 /* The remainder of this function is only useful for HPUX 10.0 and
840 later, as it depends upon the ability to request notification
841 of specific kinds of events by the kernel. */
842 #if defined(PT_SET_EVENT_MASK)
843
844 /* Notify the parent that we're potentially ready to exec(). */
845 write (startup_semaphore.child_channel[SEM_TALK],
846 &tc_magic_child,
847 sizeof (tc_magic_child));
848
849 /* Wait for acknowledgement from the parent. */
850 read (startup_semaphore.parent_channel[SEM_LISTEN],
851 &tc_magic_parent,
852 sizeof (tc_magic_parent));
853 if (tc_magic_child != tc_magic_parent)
854 warning ("mismatched semaphore magic");
855
856 /* Discard our copy of the semaphore. */
857 (void) close (startup_semaphore.parent_channel[SEM_LISTEN]);
858 (void) close (startup_semaphore.parent_channel[SEM_TALK]);
859 (void) close (startup_semaphore.child_channel[SEM_LISTEN]);
860 (void) close (startup_semaphore.child_channel[SEM_TALK]);
861 #endif
862
863 return 0;
864 }
865 #endif
866
867 int
868 hppa_require_attach (int pid)
869 {
870 int pt_status;
871 CORE_ADDR pc;
872 CORE_ADDR pc_addr;
873 unsigned int regs_offset;
874
875 /* Are we already attached? There appears to be no explicit way to
876 answer this via ptrace, so we try something which should be
877 innocuous if we are attached. If that fails, then we assume
878 we're not attached, and so attempt to make it so. */
879
880 errno = 0;
881 regs_offset = U_REGS_OFFSET;
882 pc_addr = register_addr (PC_REGNUM, regs_offset);
883 pc = call_ptrace (PT_READ_U, pid, (PTRACE_ARG3_TYPE) pc_addr, 0);
884
885 if (errno)
886 {
887 errno = 0;
888 pt_status = call_ptrace (PT_ATTACH, pid, (PTRACE_ARG3_TYPE) 0, 0);
889
890 if (errno)
891 return -1;
892
893 /* Now we really are attached. */
894 errno = 0;
895 }
896 attach_flag = 1;
897 return pid;
898 }
899
900 int
901 hppa_require_detach (int pid, int signal)
902 {
903 errno = 0;
904 call_ptrace (PT_DETACH, pid, (PTRACE_ARG3_TYPE) 1, signal);
905 errno = 0; /* Ignore any errors. */
906 return pid;
907 }
908
909 /* Since ptrace doesn't support memory page-protection events, which
910 are used to implement "hardware" watchpoints on HP-UX, these are
911 dummy versions, which perform no useful work. */
912
913 void
914 hppa_enable_page_protection_events (int pid)
915 {
916 }
917
918 void
919 hppa_disable_page_protection_events (int pid)
920 {
921 }
922
923 int
924 hppa_insert_hw_watchpoint (int pid, CORE_ADDR start, LONGEST len, int type)
925 {
926 error ("Hardware watchpoints not implemented on this platform.");
927 }
928
929 int
930 hppa_remove_hw_watchpoint (int pid, CORE_ADDR start, LONGEST len, int type)
931 {
932 error ("Hardware watchpoints not implemented on this platform.");
933 }
934
935 int
936 hppa_can_use_hw_watchpoint (int type, int cnt, int ot)
937 {
938 return 0;
939 }
940
941 int
942 hppa_range_profitable_for_hw_watchpoint (int pid, CORE_ADDR start, LONGEST len)
943 {
944 error ("Hardware watchpoints not implemented on this platform.");
945 }
946
947 char *
948 hppa_pid_or_tid_to_str (ptid_t id)
949 {
950 /* In the ptrace world, there are only processes. */
951 return child_pid_to_str (id);
952 }
953
954 void
955 hppa_ensure_vforking_parent_remains_stopped (int pid)
956 {
957 /* This assumes that the vforked parent is presently stopped, and
958 that the vforked child has just delivered its first exec event.
959 Calling kill() this way will cause the SIGTRAP to be delivered as
960 soon as the parent is resumed, which happens as soon as the
961 vforked child is resumed. See wait_for_inferior for the use of
962 this function. */
963 kill (pid, SIGTRAP);
964 }
965
966 int
967 hppa_resume_execd_vforking_child_to_get_parent_vfork (void)
968 {
969 return 1; /* Yes, the child must be resumed. */
970 }
971
972 void
973 require_notification_of_events (int pid)
974 {
975 #if defined(PT_SET_EVENT_MASK)
976 int pt_status;
977 ptrace_event_t ptrace_events;
978 int nsigs;
979 int signum;
980
981 /* Instruct the kernel as to the set of events we wish to be
982 informed of. (This support does not exist before HPUX 10.0.
983 We'll assume if PT_SET_EVENT_MASK has not been defined by
984 <sys/ptrace.h>, then we're being built on pre-10.0.) */
985 memset (&ptrace_events, 0, sizeof (ptrace_events));
986
987 /* Note: By default, all signals are visible to us. If we wish
988 the kernel to keep certain signals hidden from us, we do it
989 by calling sigdelset (ptrace_events.pe_signals, signal) for
990 each such signal here, before doing PT_SET_EVENT_MASK. */
991 /* RM: The above comment is no longer true. We start with ignoring
992 all signals, and then add the ones we are interested in. We could
993 do it the other way: start by looking at all signals and then
994 deleting the ones that we aren't interested in, except that
995 multiple gdb signals may be mapped to the same host signal
996 (eg. TARGET_SIGNAL_IO and TARGET_SIGNAL_POLL both get mapped to
997 signal 22 on HPUX 10.20) We want to be notified if we are
998 interested in either signal. */
999 sigfillset (&ptrace_events.pe_signals);
1000
1001 /* RM: Let's not bother with signals we don't care about */
1002 nsigs = (int) TARGET_SIGNAL_LAST;
1003 for (signum = nsigs; signum > 0; signum--)
1004 {
1005 if ((signal_stop_state (signum)) ||
1006 (signal_print_state (signum)) ||
1007 (!signal_pass_state (signum)))
1008 {
1009 if (target_signal_to_host_p (signum))
1010 sigdelset (&ptrace_events.pe_signals,
1011 target_signal_to_host (signum));
1012 }
1013 }
1014
1015 ptrace_events.pe_set_event = 0;
1016
1017 ptrace_events.pe_set_event |= PTRACE_SIGNAL;
1018 ptrace_events.pe_set_event |= PTRACE_EXEC;
1019 ptrace_events.pe_set_event |= PTRACE_FORK;
1020 ptrace_events.pe_set_event |= PTRACE_VFORK;
1021 /* ??rehrauer: Add this one when we're prepared to catch it...
1022 ptrace_events.pe_set_event |= PTRACE_EXIT;
1023 */
1024
1025 errno = 0;
1026 pt_status = call_ptrace (PT_SET_EVENT_MASK,
1027 pid,
1028 (PTRACE_ARG3_TYPE) & ptrace_events,
1029 sizeof (ptrace_events));
1030 if (errno)
1031 perror_with_name ("ptrace");
1032 if (pt_status < 0)
1033 return;
1034 #endif
1035 }
1036
1037 void
1038 require_notification_of_exec_events (int pid)
1039 {
1040 #if defined(PT_SET_EVENT_MASK)
1041 int pt_status;
1042 ptrace_event_t ptrace_events;
1043
1044 /* Instruct the kernel as to the set of events we wish to be
1045 informed of. (This support does not exist before HPUX 10.0.
1046 We'll assume if PT_SET_EVENT_MASK has not been defined by
1047 <sys/ptrace.h>, then we're being built on pre-10.0.) */
1048 memset (&ptrace_events, 0, sizeof (ptrace_events));
1049
1050 /* Note: By default, all signals are visible to us. If we wish
1051 the kernel to keep certain signals hidden from us, we do it
1052 by calling sigdelset (ptrace_events.pe_signals, signal) for
1053 each such signal here, before doing PT_SET_EVENT_MASK. */
1054 sigemptyset (&ptrace_events.pe_signals);
1055
1056 ptrace_events.pe_set_event = 0;
1057
1058 ptrace_events.pe_set_event |= PTRACE_EXEC;
1059 /* ??rehrauer: Add this one when we're prepared to catch it...
1060 ptrace_events.pe_set_event |= PTRACE_EXIT;
1061 */
1062
1063 errno = 0;
1064 pt_status = call_ptrace (PT_SET_EVENT_MASK,
1065 pid,
1066 (PTRACE_ARG3_TYPE) & ptrace_events,
1067 sizeof (ptrace_events));
1068 if (errno)
1069 perror_with_name ("ptrace");
1070 if (pt_status < 0)
1071 return;
1072 #endif
1073 }
1074
1075 /* This function is called by the parent process, with pid being the
1076 ID of the child process, after the debugger has forked. */
1077
1078 void
1079 child_acknowledge_created_inferior (int pid)
1080 {
1081 /* We need a memory home for a constant. */
1082 int tc_magic_parent = PT_VERSION;
1083 int tc_magic_child = 0;
1084
1085 /* The remainder of this function is only useful for HPUX 10.0 and
1086 later, as it depends upon the ability to request notification
1087 of specific kinds of events by the kernel. */
1088 #if defined(PT_SET_EVENT_MASK)
1089 /* Wait for the child to tell us that it has forked. */
1090 read (startup_semaphore.child_channel[SEM_LISTEN],
1091 &tc_magic_child,
1092 sizeof (tc_magic_child));
1093
1094 /* Notify the child that it can exec.
1095
1096 In the infttrace.c variant of this function, we set the child's
1097 event mask after the fork but before the exec. In the ptrace
1098 world, it seems we can't set the event mask until after the exec. */
1099 write (startup_semaphore.parent_channel[SEM_TALK],
1100 &tc_magic_parent,
1101 sizeof (tc_magic_parent));
1102
1103 /* We'd better pause a bit before trying to set the event mask,
1104 though, to ensure that the exec has happened. We don't want to
1105 wait() on the child, because that'll screw up the upper layers
1106 of gdb's execution control that expect to see the exec event.
1107
1108 After an exec, the child is no longer executing gdb code. Hence,
1109 we can't have yet another synchronization via the pipes. We'll
1110 just sleep for a second, and hope that's enough delay... */
1111 sleep (1);
1112
1113 /* Instruct the kernel as to the set of events we wish to be
1114 informed of. */
1115 require_notification_of_exec_events (pid);
1116
1117 /* Discard our copy of the semaphore. */
1118 (void) close (startup_semaphore.parent_channel[SEM_LISTEN]);
1119 (void) close (startup_semaphore.parent_channel[SEM_TALK]);
1120 (void) close (startup_semaphore.child_channel[SEM_LISTEN]);
1121 (void) close (startup_semaphore.child_channel[SEM_TALK]);
1122 #endif
1123 }
1124
1125 void
1126 child_post_startup_inferior (ptid_t ptid)
1127 {
1128 require_notification_of_events (PIDGET (ptid));
1129 }
1130
1131 void
1132 child_post_attach (int pid)
1133 {
1134 require_notification_of_events (pid);
1135 }
1136
1137 int
1138 child_insert_fork_catchpoint (int pid)
1139 {
1140 /* This request is only available on HPUX 10.0 and later. */
1141 #if !defined(PT_SET_EVENT_MASK)
1142 error ("Unable to catch forks prior to HPUX 10.0");
1143 #else
1144 /* Enable reporting of fork events from the kernel. */
1145 /* ??rehrauer: For the moment, we're always enabling these events,
1146 and just ignoring them if there's no catchpoint to catch them. */
1147 return 0;
1148 #endif
1149 }
1150
1151 int
1152 child_remove_fork_catchpoint (int pid)
1153 {
1154 /* This request is only available on HPUX 10.0 and later. */
1155 #if !defined(PT_SET_EVENT_MASK)
1156 error ("Unable to catch forks prior to HPUX 10.0");
1157 #else
1158 /* Disable reporting of fork events from the kernel. */
1159 /* ??rehrauer: For the moment, we're always enabling these events,
1160 and just ignoring them if there's no catchpoint to catch them. */
1161 return 0;
1162 #endif
1163 }
1164
1165 int
1166 child_insert_vfork_catchpoint (int pid)
1167 {
1168 /* This request is only available on HPUX 10.0 and later. */
1169 #if !defined(PT_SET_EVENT_MASK)
1170 error ("Unable to catch vforks prior to HPUX 10.0");
1171 #else
1172 /* Enable reporting of vfork events from the kernel. */
1173 /* ??rehrauer: For the moment, we're always enabling these events,
1174 and just ignoring them if there's no catchpoint to catch them. */
1175 return 0;
1176 #endif
1177 }
1178
1179 int
1180 child_remove_vfork_catchpoint (int pid)
1181 {
1182 /* This request is only available on HPUX 10.0 and later. */
1183 #if !defined(PT_SET_EVENT_MASK)
1184 error ("Unable to catch vforks prior to HPUX 10.0");
1185 #else
1186 /* Disable reporting of vfork events from the kernel. */
1187 /* ??rehrauer: For the moment, we're always enabling these events,
1188 and just ignoring them if there's no catchpoint to catch them. */
1189 return 0;
1190 #endif
1191 }
1192
1193 int
1194 hpux_has_forked (int pid, int *childpid)
1195 {
1196 /* This request is only available on HPUX 10.0 and later. */
1197 #if !defined(PT_GET_PROCESS_STATE)
1198 *childpid = 0;
1199 return 0;
1200 #else
1201 int pt_status;
1202 ptrace_state_t ptrace_state;
1203
1204 errno = 0;
1205 pt_status = call_ptrace (PT_GET_PROCESS_STATE,
1206 pid,
1207 (PTRACE_ARG3_TYPE) & ptrace_state,
1208 sizeof (ptrace_state));
1209 if (errno)
1210 perror_with_name ("ptrace");
1211 if (pt_status < 0)
1212 return 0;
1213
1214 if (ptrace_state.pe_report_event & PTRACE_FORK)
1215 {
1216 *childpid = ptrace_state.pe_other_pid;
1217 return 1;
1218 }
1219
1220 return 0;
1221 #endif
1222 }
1223
1224 int
1225 hpux_has_vforked (int pid, int *childpid)
1226 {
1227 /* This request is only available on HPUX 10.0 and later. */
1228 #if !defined(PT_GET_PROCESS_STATE)
1229 *childpid = 0;
1230 return 0;
1231
1232 #else
1233 int pt_status;
1234 ptrace_state_t ptrace_state;
1235
1236 errno = 0;
1237 pt_status = call_ptrace (PT_GET_PROCESS_STATE,
1238 pid,
1239 (PTRACE_ARG3_TYPE) & ptrace_state,
1240 sizeof (ptrace_state));
1241 if (errno)
1242 perror_with_name ("ptrace");
1243 if (pt_status < 0)
1244 return 0;
1245
1246 if (ptrace_state.pe_report_event & PTRACE_VFORK)
1247 {
1248 *childpid = ptrace_state.pe_other_pid;
1249 return 1;
1250 }
1251
1252 return 0;
1253 #endif
1254 }
1255
1256 int
1257 child_insert_exec_catchpoint (int pid)
1258 {
1259 /* This request is only available on HPUX 10.0 and later. */
1260 #if !defined(PT_SET_EVENT_MASK)
1261 error ("Unable to catch execs prior to HPUX 10.0");
1262
1263 #else
1264 /* Enable reporting of exec events from the kernel. */
1265 /* ??rehrauer: For the moment, we're always enabling these events,
1266 and just ignoring them if there's no catchpoint to catch them. */
1267 return 0;
1268 #endif
1269 }
1270
1271 int
1272 child_remove_exec_catchpoint (int pid)
1273 {
1274 /* This request is only available on HPUX 10.0 and later. */
1275 #if !defined(PT_SET_EVENT_MASK)
1276 error ("Unable to catch execs prior to HPUX 10.0");
1277
1278 #else
1279 /* Disable reporting of exec events from the kernel. */
1280 /* ??rehrauer: For the moment, we're always enabling these events,
1281 and just ignoring them if there's no catchpoint to catch them. */
1282 return 0;
1283 #endif
1284 }
1285
1286 int
1287 hpux_has_execd (int pid, char **execd_pathname)
1288 {
1289 /* This request is only available on HPUX 10.0 and later. */
1290 #if !defined(PT_GET_PROCESS_STATE)
1291 *execd_pathname = NULL;
1292 return 0;
1293
1294 #else
1295 int pt_status;
1296 ptrace_state_t ptrace_state;
1297
1298 errno = 0;
1299 pt_status = call_ptrace (PT_GET_PROCESS_STATE,
1300 pid,
1301 (PTRACE_ARG3_TYPE) & ptrace_state,
1302 sizeof (ptrace_state));
1303 if (errno)
1304 perror_with_name ("ptrace");
1305 if (pt_status < 0)
1306 return 0;
1307
1308 if (ptrace_state.pe_report_event & PTRACE_EXEC)
1309 {
1310 char *exec_file = target_pid_to_exec_file (pid);
1311 *execd_pathname = savestring (exec_file, strlen (exec_file));
1312 return 1;
1313 }
1314
1315 return 0;
1316 #endif
1317 }
1318
1319 int
1320 child_reported_exec_events_per_exec_call (void)
1321 {
1322 return 2; /* ptrace reports the event twice per call. */
1323 }
1324
1325 int
1326 hpux_has_syscall_event (int pid, enum target_waitkind *kind, int *syscall_id)
1327 {
1328 /* This request is only available on HPUX 10.30 and later, via
1329 the ttrace interface. */
1330
1331 *kind = TARGET_WAITKIND_SPURIOUS;
1332 *syscall_id = -1;
1333 return 0;
1334 }
1335
1336 char *
1337 child_pid_to_exec_file (int pid)
1338 {
1339 static char exec_file_buffer[1024];
1340 int pt_status;
1341 CORE_ADDR top_of_stack;
1342 char four_chars[4];
1343 int name_index;
1344 int i;
1345 ptid_t saved_inferior_ptid;
1346 int done;
1347
1348 #ifdef PT_GET_PROCESS_PATHNAME
1349 /* As of 10.x HP-UX, there's an explicit request to get the pathname. */
1350 pt_status = call_ptrace (PT_GET_PROCESS_PATHNAME,
1351 pid,
1352 (PTRACE_ARG3_TYPE) exec_file_buffer,
1353 sizeof (exec_file_buffer) - 1);
1354 if (pt_status == 0)
1355 return exec_file_buffer;
1356 #endif
1357
1358 /* It appears that this request is broken prior to 10.30.
1359 If it fails, try a really, truly amazingly gross hack
1360 that DDE uses, of pawing through the process' data
1361 segment to find the pathname. */
1362
1363 top_of_stack = 0x7b03a000;
1364 name_index = 0;
1365 done = 0;
1366
1367 /* On the chance that pid != inferior_ptid, set inferior_ptid
1368 to pid, so that (grrrr!) implicit uses of inferior_ptid get
1369 the right id. */
1370
1371 saved_inferior_ptid = inferior_ptid;
1372 inferior_ptid = pid_to_ptid (pid);
1373
1374 /* Try to grab a null-terminated string. */
1375 while (!done)
1376 {
1377 if (target_read_memory (top_of_stack, four_chars, 4) != 0)
1378 {
1379 inferior_ptid = saved_inferior_ptid;
1380 return NULL;
1381 }
1382 for (i = 0; i < 4; i++)
1383 {
1384 exec_file_buffer[name_index++] = four_chars[i];
1385 done = (four_chars[i] == '\0');
1386 if (done)
1387 break;
1388 }
1389 top_of_stack += 4;
1390 }
1391
1392 if (exec_file_buffer[0] == '\0')
1393 {
1394 inferior_ptid = saved_inferior_ptid;
1395 return NULL;
1396 }
1397
1398 inferior_ptid = saved_inferior_ptid;
1399 return exec_file_buffer;
1400 }
1401
1402 void
1403 pre_fork_inferior (void)
1404 {
1405 int status;
1406
1407 status = pipe (startup_semaphore.parent_channel);
1408 if (status < 0)
1409 {
1410 warning ("error getting parent pipe for startup semaphore");
1411 return;
1412 }
1413
1414 status = pipe (startup_semaphore.child_channel);
1415 if (status < 0)
1416 {
1417 warning ("error getting child pipe for startup semaphore");
1418 return;
1419 }
1420 }
1421 \f
1422
1423 /* Check to see if the given thread is alive.
1424
1425 This is a no-op, as ptrace doesn't support threads, so we just
1426 return "TRUE". */
1427
1428 int
1429 child_thread_alive (ptid_t ptid)
1430 {
1431 return 1;
1432 }
1433
1434 #endif /* ! GDB_NATIVE_HPUX_11 */
This page took 0.06172 seconds and 4 git commands to generate.