1 /* Machine-dependent hooks for the unix child process stratum. This
2 code is for the HP PA-RISC cpu.
4 Copyright 1986, 1987, 1989, 1990, 1991, 1992, 1993 Free Software Foundation, Inc.
6 Contributed by the Center for Software Science at the
7 University of Utah (pa-gdb-bugs@cs.utah.edu).
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. */
28 #include <sys/ptrace.h>
31 #define PT_ATTACH PTRACE_ATTACH
34 #define PT_DETACH PTRACE_DETACH
37 /* This function simply calls ptrace with the given arguments.
38 It exists so that all calls to ptrace are isolated in this
39 machine-dependent file. */
40 #ifdef WANT_NATIVE_TARGET
42 call_ptrace (request
, pid
, addr
, data
)
44 PTRACE_ARG3_TYPE addr
;
47 return ptrace (request
, pid
, addr
, data
);
49 #endif /* WANT_NATIVE_TARGET */
52 /* For the rest of the file, use an extra level of indirection */
53 /* This lets us breakpoint usefully on call_ptrace. */
54 #define ptrace call_ptrace
60 if (inferior_pid
== 0)
62 ptrace (PT_KILL
, inferior_pid
, (PTRACE_ARG3_TYPE
) 0, 0);
64 target_mourn_inferior ();
69 /* Start debugging the process whose number is PID. */
75 ptrace (PT_ATTACH
, pid
, (PTRACE_ARG3_TYPE
) 0, 0);
77 perror_with_name ("ptrace");
82 /* Stop debugging the process whose number is PID
83 and continue it with signal number SIGNAL.
84 SIGNAL = 0 means just continue it. */
91 ptrace (PT_DETACH
, inferior_pid
, (PTRACE_ARG3_TYPE
) 1, signal
);
93 perror_with_name ("ptrace");
96 #endif /* ATTACH_DETACH */
100 #if !defined (FETCH_INFERIOR_REGISTERS)
102 /* KERNEL_U_ADDR is the amount to subtract from u.u_ar0
103 to get the offset in the core file of the register values. */
104 #if defined (KERNEL_U_ADDR_BSD)
105 /* Get kernel_u_addr using BSD-style nlist(). */
106 CORE_ADDR kernel_u_addr
;
108 #include <a.out.gnu.h> /* For struct nlist */
111 _initialize_kernel_u_addr ()
113 struct nlist names
[2];
115 names
[0].n_un
.n_name
= "_u";
116 names
[1].n_un
.n_name
= NULL
;
117 if (nlist ("/vmunix", names
) == 0)
118 kernel_u_addr
= names
[0].n_value
;
120 fatal ("Unable to get kernel u area address.");
122 #endif /* KERNEL_U_ADDR_BSD. */
124 #if defined (KERNEL_U_ADDR_HPUX)
125 /* Get kernel_u_addr using HPUX-style nlist(). */
126 CORE_ADDR kernel_u_addr
;
131 unsigned char n_type
;
132 unsigned char n_length
;
136 static struct hpnlist nl
[] = {{ "_u", -1, }, { (char *) 0, }};
138 /* read the value of the u area from the hp-ux kernel */
139 void _initialize_kernel_u_addr ()
142 nlist ("/hp-ux", &nl
);
143 kernel_u_addr
= nl
[0].n_value
;
145 #endif /* KERNEL_U_ADDR_HPUX. */
147 #if !defined (offsetof)
148 #define offsetof(TYPE, MEMBER) ((unsigned long) &((TYPE *)0)->MEMBER)
151 /* U_REGS_OFFSET is the offset of the registers within the u area. */
152 #if !defined (U_REGS_OFFSET)
153 #define U_REGS_OFFSET \
154 ptrace (PT_READ_U, inferior_pid, \
155 (PTRACE_ARG3_TYPE) (offsetof (struct user, u_ar0)), 0) \
159 /* Registers we shouldn't try to fetch. */
160 #if !defined (CANNOT_FETCH_REGISTER)
161 #define CANNOT_FETCH_REGISTER(regno) 0
164 /* Fetch one register. */
167 fetch_register (regno
)
170 register unsigned int regaddr
;
171 char buf
[MAX_REGISTER_RAW_SIZE
];
172 char mess
[128]; /* For messages */
175 /* Offset of registers within the u area. */
178 if (CANNOT_FETCH_REGISTER (regno
))
180 bzero (buf
, REGISTER_RAW_SIZE (regno
)); /* Supply zeroes */
181 supply_register (regno
, buf
);
185 offset
= U_REGS_OFFSET
;
187 regaddr
= register_addr (regno
, offset
);
188 for (i
= 0; i
< REGISTER_RAW_SIZE (regno
); i
+= sizeof (int))
191 *(int *) &buf
[i
] = ptrace (PT_RUREGS
, inferior_pid
,
192 (PTRACE_ARG3_TYPE
) regaddr
, 0);
193 regaddr
+= sizeof (int);
196 sprintf (mess
, "reading register %s (#%d)", reg_names
[regno
], regno
);
197 perror_with_name (mess
);
200 supply_register (regno
, buf
);
203 #endif /* !defined (FETCH_INFERIOR_REGISTERS). */
204 /* Fetch all registers, or just one, from the child process. */
206 #ifndef FETCH_INFERIOR_REGISTERS
208 fetch_inferior_registers (regno
)
212 for (regno
= 0; regno
< NUM_REGS
; regno
++)
213 fetch_register (regno
);
215 fetch_register (regno
);
218 /* Registers we shouldn't try to store. */
219 #if !defined (CANNOT_STORE_REGISTER)
220 #define CANNOT_STORE_REGISTER(regno) 0
223 /* Store our register values back into the inferior.
224 If REGNO is -1, do this for all registers.
225 Otherwise, REGNO specifies which register (so we can save time). */
228 store_inferior_registers (regno
)
231 register unsigned int regaddr
;
233 extern char registers
[];
236 unsigned int offset
= U_REGS_OFFSET
;
240 regaddr
= register_addr (regno
, offset
);
241 for (i
= 0; i
< REGISTER_RAW_SIZE (regno
); i
+= sizeof(int))
244 ptrace (PT_WUREGS
, inferior_pid
, (PTRACE_ARG3_TYPE
) regaddr
,
245 *(int *) ®isters
[REGISTER_BYTE (regno
) + i
]);
248 sprintf (buf
, "writing register number %d(%d)", regno
, i
);
249 perror_with_name (buf
);
251 regaddr
+= sizeof(int);
256 for (regno
= 0; regno
< NUM_REGS
; regno
++)
258 if (CANNOT_STORE_REGISTER (regno
))
260 regaddr
= register_addr (regno
, offset
);
261 for (i
= 0; i
< REGISTER_RAW_SIZE (regno
); i
+= sizeof(int))
264 ptrace (PT_WUREGS
, inferior_pid
, (PTRACE_ARG3_TYPE
) regaddr
,
265 *(int *) ®isters
[REGISTER_BYTE (regno
) + i
]);
268 sprintf (buf
, "writing register number %d(%d)", regno
, i
);
269 perror_with_name (buf
);
271 regaddr
+= sizeof(int);
277 #endif /* !defined(FETCH_INFERIOR_REGISTERS) */
279 /* Resume execution of the inferior process.
280 If STEP is nonzero, single-step it.
281 If SIGNAL is nonzero, give it that signal. */
284 child_resume (step
, signal
)
290 /* An address of (PTRACE_ARG3_TYPE) 1 tells ptrace to continue from where
291 it was. (If GDB wanted it to start some other way, we have already
292 written a new PC value to the child.) */
295 ptrace (PT_STEP
, inferior_pid
, (PTRACE_ARG3_TYPE
) 1, signal
);
297 ptrace (PT_CONTINUE
, inferior_pid
, (PTRACE_ARG3_TYPE
) 1, signal
);
300 perror_with_name ("ptrace");
303 /* NOTE! I tried using PTRACE_READDATA, etc., to read and write memory
304 in the NEW_SUN_PTRACE case.
305 It ought to be straightforward. But it appears that writing did
306 not write the data that I specified. I cannot understand where
307 it got the data that it actually did write. */
309 /* Copy LEN bytes to or from inferior's memory starting at MEMADDR
310 to debugger memory starting at MYADDR. Copy to inferior if
313 Returns the length copied, which is either the LEN argument or zero.
314 This xfer function does not do partial moves, since child_ops
315 doesn't allow memory operations to cross below us in the target stack
319 child_xfer_memory (memaddr
, myaddr
, len
, write
, target
)
324 struct target_ops
*target
; /* ignored */
327 /* Round starting address down to longword boundary. */
328 register CORE_ADDR addr
= memaddr
& - sizeof (int);
329 /* Round ending address up; get number of longwords that makes. */
331 = (((memaddr
+ len
) - addr
) + sizeof (int) - 1) / sizeof (int);
332 /* Allocate buffer of that many longwords. */
333 register int *buffer
= (int *) alloca (count
* sizeof (int));
337 /* Fill start and end extra bytes of buffer with existing memory data. */
339 if (addr
!= memaddr
|| len
< (int)sizeof (int)) {
340 /* Need part of initial word -- fetch it. */
341 buffer
[0] = ptrace (PT_READ_I
, inferior_pid
, (PTRACE_ARG3_TYPE
) addr
,
345 if (count
> 1) /* FIXME, avoid if even boundary */
348 = ptrace (PT_READ_I
, inferior_pid
,
349 (PTRACE_ARG3_TYPE
) (addr
+ (count
- 1) * sizeof (int)),
353 /* Copy data to be written over corresponding part of buffer */
355 bcopy (myaddr
, (char *) buffer
+ (memaddr
& (sizeof (int) - 1)), len
);
357 /* Write the entire buffer. */
359 for (i
= 0; i
< count
; i
++, addr
+= sizeof (int))
362 ptrace (PT_WRITE_D
, inferior_pid
, (PTRACE_ARG3_TYPE
) addr
,
366 /* Using the appropriate one (I or D) is necessary for
367 Gould NP1, at least. */
369 ptrace (PT_WRITE_I
, inferior_pid
, (PTRACE_ARG3_TYPE
) addr
,
378 /* Read all the longwords */
379 for (i
= 0; i
< count
; i
++, addr
+= sizeof (int))
382 buffer
[i
] = ptrace (PT_READ_I
, inferior_pid
,
383 (PTRACE_ARG3_TYPE
) addr
, 0);
389 /* Copy appropriate bytes out of the buffer. */
390 bcopy ((char *) buffer
+ (memaddr
& (sizeof (int) - 1)), myaddr
, len
);
This page took 0.03709 seconds and 4 git commands to generate.