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