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