1 /* Machine-dependent hooks for the unix child process stratum, for HPUX PA-RISC.
3 Copyright 1986, 1987, 1989, 1990, 1991, 1992, 1993
4 Free Software Foundation, Inc.
6 Contributed by the Center for Software Science at the
9 This file is part of GDB.
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.
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.
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., 675 Mass Ave, Cambridge, MA 02139, USA. */
29 #include <sys/ptrace.h>
31 extern CORE_ADDR text_end;
33 static void fetch_register ();
35 /* This function simply calls ptrace with the given arguments.
36 It exists so that all calls to ptrace are isolated in this
37 machine-dependent file. */
39 call_ptrace (request, pid, addr, data)
41 PTRACE_ARG3_TYPE addr;
44 return ptrace (request, pid, addr, data, 0);
50 if (inferior_pid == 0)
52 ptrace (PT_EXIT, inferior_pid, (PTRACE_ARG3_TYPE) 0, 0, 0);
54 target_mourn_inferior ();
57 /* Start debugging the process whose number is PID. */
63 ptrace (PT_ATTACH, pid, (PTRACE_ARG3_TYPE) 0, 0, 0);
65 perror_with_name ("ptrace");
70 /* Stop debugging the process whose number is PID
71 and continue it with signal number SIGNAL.
72 SIGNAL = 0 means just continue it. */
79 ptrace (PT_DETACH, inferior_pid, (PTRACE_ARG3_TYPE) 1, signal, 0);
81 perror_with_name ("ptrace");
85 /* Fetch all registers, or just one, from the child process. */
88 fetch_inferior_registers (regno)
92 for (regno = 0; regno < NUM_REGS; regno++)
93 fetch_register (regno);
95 fetch_register (regno);
98 /* Store our register values back into the inferior.
99 If REGNO is -1, do this for all registers.
100 Otherwise, REGNO specifies which register (so we can save time). */
103 store_inferior_registers (regno)
106 register unsigned int regaddr;
108 extern char registers[];
110 unsigned int offset = U_REGS_OFFSET;
115 regaddr = register_addr (regno, offset);
117 if (regno == PCOQ_HEAD_REGNUM || regno == PCOQ_TAIL_REGNUM)
119 scratch = *(int *) ®isters[REGISTER_BYTE (regno)] | 0x3;
120 ptrace (PT_WUREGS, inferior_pid, (PTRACE_ARG3_TYPE) regaddr,
124 sprintf (buf, "writing register number %d(%d)", regno, i);
125 perror_with_name (buf);
129 for (i = 0; i < REGISTER_RAW_SIZE (regno); i += sizeof(int))
132 ptrace (PT_WUREGS, inferior_pid, (PTRACE_ARG3_TYPE) regaddr,
133 *(int *) ®isters[REGISTER_BYTE (regno) + i], 0);
136 sprintf (buf, "writing register number %d(%d)", regno, i);
137 perror_with_name (buf);
139 regaddr += sizeof(int);
144 for (regno = 0; regno < NUM_REGS; regno++)
146 if (CANNOT_STORE_REGISTER (regno))
148 regaddr = register_addr (regno, offset);
150 if (regno == PCOQ_HEAD_REGNUM || regno == PCOQ_TAIL_REGNUM)
152 scratch = *(int *) ®isters[REGISTER_BYTE (regno)] | 0x3;
153 ptrace (PT_WUREGS, inferior_pid, (PTRACE_ARG3_TYPE) regaddr,
157 sprintf (buf, "writing register number %d(%d)", regno, i);
158 perror_with_name (buf);
162 for (i = 0; i < REGISTER_RAW_SIZE (regno); i += sizeof(int))
165 ptrace (PT_WUREGS, inferior_pid, (PTRACE_ARG3_TYPE) regaddr,
166 *(int *) ®isters[REGISTER_BYTE (regno) + i], 0);
169 sprintf (buf, "writing register number %d(%d)", regno, i);
170 perror_with_name (buf);
172 regaddr += sizeof(int);
179 /* Fetch one register. */
182 fetch_register (regno)
185 register unsigned int regaddr;
186 char buf[MAX_REGISTER_RAW_SIZE];
187 char mess[128]; /* For messages */
190 /* Offset of registers within the u area. */
193 offset = U_REGS_OFFSET;
195 regaddr = register_addr (regno, offset);
196 for (i = 0; i < REGISTER_RAW_SIZE (regno); i += sizeof (int))
199 *(int *) &buf[i] = ptrace (PT_RUREGS, inferior_pid,
200 (PTRACE_ARG3_TYPE) regaddr, 0, 0);
201 regaddr += sizeof (int);
204 sprintf (mess, "reading register %s (#%d)", reg_names[regno], regno);
205 perror_with_name (mess);
208 if (regno == PCOQ_HEAD_REGNUM || regno == PCOQ_TAIL_REGNUM)
210 supply_register (regno, buf);
213 /* Resume execution of the inferior process.
214 If STEP is nonzero, single-step it.
215 If SIGNAL is nonzero, give it that signal. */
218 child_resume (step, signal)
224 /* An address of (PTRACE_ARG3_TYPE) 1 tells ptrace to continue from where
225 it was. (If GDB wanted it to start some other way, we have already
226 written a new PC value to the child.) */
229 ptrace (PT_SINGLE, inferior_pid, (PTRACE_ARG3_TYPE) 1, signal, 0);
231 ptrace (PT_CONTIN, inferior_pid, (PTRACE_ARG3_TYPE) 1, signal, 0);
234 perror_with_name ("ptrace");
237 /* Copy LEN bytes to or from inferior's memory starting at MEMADDR
238 to debugger memory starting at MYADDR. Copy to inferior if
241 Returns the length copied, which is either the LEN argument or zero.
242 This xfer function does not do partial moves, since child_ops
243 doesn't allow memory operations to cross below us in the target stack
247 child_xfer_memory (memaddr, myaddr, len, write, target)
252 struct target_ops *target; /* ignored */
255 /* Round starting address down to longword boundary. */
256 register CORE_ADDR addr = memaddr & - sizeof (int);
257 /* Round ending address up; get number of longwords that makes. */
259 = (((memaddr + len) - addr) + sizeof (int) - 1) / sizeof (int);
260 /* Allocate buffer of that many longwords. */
261 register int *buffer = (int *) alloca (count * sizeof (int));
265 /* Fill start and end extra bytes of buffer with existing memory data. */
267 if (addr != memaddr || len < (int)sizeof (int)) {
268 /* Need part of initial word -- fetch it. */
269 buffer[0] = ptrace (addr < text_end ? PT_RIUSER : PT_RDUSER,
270 inferior_pid, (PTRACE_ARG3_TYPE) addr, 0, 0);
273 if (count > 1) /* FIXME, avoid if even boundary */
276 = ptrace (addr < text_end ? PT_RIUSER : PT_RDUSER, inferior_pid,
277 (PTRACE_ARG3_TYPE) (addr + (count - 1) * sizeof (int)),
281 /* Copy data to be written over corresponding part of buffer */
283 bcopy (myaddr, (char *) buffer + (memaddr & (sizeof (int) - 1)), len);
285 /* Write the entire buffer. */
287 for (i = 0; i < count; i++, addr += sizeof (int))
289 /* The HP-UX kernel crashes if you use PT_WDUSER to write into the text
290 segment. FIXME -- does it work to write into the data segment using
291 WIUSER, or do these idiots really expect us to figure out which segment
292 the address is in, so we can use a separate system call for it??! */
294 ptrace (addr < text_end ? PT_WIUSER : PT_WDUSER, inferior_pid,
295 (PTRACE_ARG3_TYPE) addr,
303 /* Read all the longwords */
304 for (i = 0; i < count; i++, addr += sizeof (int))
307 buffer[i] = ptrace (addr < text_end ? PT_RIUSER : PT_RDUSER,
308 inferior_pid, (PTRACE_ARG3_TYPE) addr, 0, 0);
314 /* Copy appropriate bytes out of the buffer. */
315 bcopy ((char *) buffer + (memaddr & (sizeof (int) - 1)), myaddr, len);