1 /* Machine-dependent code which would otherwise be in infptrace.c,
2 for GDB, the GNU debugger. This code is for the HP PA-RISC cpu.
3 Copyright 1986, 1987, 1989, 1990, 1991, 1992 Free Software Foundation, Inc.
5 Contributed by the Center for Software Science at the
6 University of Utah (pa-gdb-bugs@cs.utah.edu).
8 /* Low level Unix child interface to ptrace, for GDB when running under Unix.
9 Copyright (C) 1988, 1989, 1990, 1991 Free Software Foundation, Inc.
11 This file is part of GDB.
13 This program is free software; you can redistribute it and/or modify
14 it under the terms of the GNU General Public License as published by
15 the Free Software Foundation; either version 2 of the License, or
16 (at your option) any later version.
18 This program is distributed in the hope that it will be useful,
19 but WITHOUT ANY WARRANTY; without even the implied warranty of
20 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 GNU General Public License for more details.
23 You should have received a copy of the GNU General Public License
24 along with this program; if not, write to the Free Software
25 Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. */
33 #include <sys/types.h>
36 #include <sys/param.h>
39 #include <sys/ioctl.h>
41 #include <sys/ptrace.h>
46 #define PT_ATTACH PTRACE_ATTACH
49 #define PT_DETACH PTRACE_DETACH
53 #include <sys/user.h> /* After a.out.h */
57 /* This function simply calls ptrace with the given arguments.
58 It exists so that all calls to ptrace are isolated in this
59 machine-dependent file. */
61 call_ptrace (request
, pid
, addr
, data
)
63 PTRACE_ARG3_TYPE addr
;
66 return ptrace (request
, pid
, addr
, data
);
70 /* For the rest of the file, use an extra level of indirection */
71 /* This lets us breakpoint usefully on call_ptrace. */
72 #define ptrace call_ptrace
75 /* This is used when GDB is exiting. It gives less chance of error.*/
80 if (inferior_pid
== 0)
82 ptrace (PT_KILL
, inferior_pid
, (PTRACE_ARG3_TYPE
) 0, 0);
89 kill_inferior_fast ();
90 target_mourn_inferior ();
93 /* Resume execution of the inferior process.
94 If STEP is nonzero, single-step it.
95 If SIGNAL is nonzero, give it that signal. */
98 child_resume (step
, signal
)
104 /* An address of (PTRACE_ARG3_TYPE) 1 tells ptrace to continue from where
105 it was. (If GDB wanted it to start some other way, we have already
106 written a new PC value to the child.) */
109 ptrace (PT_STEP
, inferior_pid
, (PTRACE_ARG3_TYPE
) 1, signal
);
111 ptrace (PT_CONTINUE
, inferior_pid
, (PTRACE_ARG3_TYPE
) 1, signal
);
114 perror_with_name ("ptrace");
118 /* Nonzero if we are debugging an attached process rather than
120 extern int attach_flag
;
122 /* Start debugging the process whose number is PID. */
128 ptrace (PT_ATTACH
, pid
, (PTRACE_ARG3_TYPE
) 0, 0);
130 perror_with_name ("ptrace");
135 /* Stop debugging the process whose number is PID
136 and continue it with signal number SIGNAL.
137 SIGNAL = 0 means just continue it. */
144 ptrace (PT_DETACH
, inferior_pid
, (PTRACE_ARG3_TYPE
) 1, signal
);
146 perror_with_name ("ptrace");
149 #endif /* ATTACH_DETACH */
151 #if !defined (FETCH_INFERIOR_REGISTERS)
153 /* KERNEL_U_ADDR is the amount to subtract from u.u_ar0
154 to get the offset in the core file of the register values. */
155 #if defined (KERNEL_U_ADDR_BSD)
156 /* Get kernel_u_addr using BSD-style nlist(). */
157 CORE_ADDR kernel_u_addr
;
159 #include <a.out.gnu.h> /* For struct nlist */
162 _initialize_kernel_u_addr ()
164 struct nlist names
[2];
166 names
[0].n_un
.n_name
= "_u";
167 names
[1].n_un
.n_name
= NULL
;
168 if (nlist ("/vmunix", names
) == 0)
169 kernel_u_addr
= names
[0].n_value
;
171 fatal ("Unable to get kernel u area address.");
173 #endif /* KERNEL_U_ADDR_BSD. */
175 #if defined (KERNEL_U_ADDR_HPUX)
176 /* Get kernel_u_addr using HPUX-style nlist(). */
177 CORE_ADDR kernel_u_addr
;
182 unsigned char n_type
;
183 unsigned char n_length
;
187 static struct hpnlist nl
[] = {{ "_u", -1, }, { (char *) 0, }};
189 /* read the value of the u area from the hp-ux kernel */
190 void _initialize_kernel_u_addr ()
193 nlist ("/hp-ux", &nl
);
194 kernel_u_addr
= nl
[0].n_value
;
196 #endif /* KERNEL_U_ADDR_HPUX. */
198 #if !defined (offsetof)
199 #define offsetof(TYPE, MEMBER) ((unsigned long) &((TYPE *)0)->MEMBER)
202 /* U_REGS_OFFSET is the offset of the registers within the u area. */
203 #if !defined (U_REGS_OFFSET)
204 #define U_REGS_OFFSET \
205 ptrace (PT_READ_U, inferior_pid, \
206 (PTRACE_ARG3_TYPE) (offsetof (struct user, u_ar0)), 0) \
210 /* Registers we shouldn't try to fetch. */
211 #if !defined (CANNOT_FETCH_REGISTER)
212 #define CANNOT_FETCH_REGISTER(regno) 0
215 /* Fetch one register. */
218 fetch_register (regno
)
221 register unsigned int regaddr
;
222 char buf
[MAX_REGISTER_RAW_SIZE
];
223 char mess
[128]; /* For messages */
226 /* Offset of registers within the u area. */
229 if (CANNOT_FETCH_REGISTER (regno
))
231 bzero (buf
, REGISTER_RAW_SIZE (regno
)); /* Supply zeroes */
232 supply_register (regno
, buf
);
236 offset
= U_REGS_OFFSET
;
238 regaddr
= register_addr (regno
, offset
);
239 for (i
= 0; i
< REGISTER_RAW_SIZE (regno
); i
+= sizeof (int))
242 *(int *) &buf
[i
] = ptrace (PT_RUREGS
, inferior_pid
,
243 (PTRACE_ARG3_TYPE
) regaddr
, 0);
244 regaddr
+= sizeof (int);
247 sprintf (mess
, "reading register %s (#%d)", reg_names
[regno
], regno
);
248 perror_with_name (mess
);
251 if (regno
== PCOQ_HEAD_REGNUM
|| regno
== PCOQ_TAIL_REGNUM
)
253 supply_register (regno
, buf
);
257 /* Fetch all registers, or just one, from the child process. */
260 fetch_inferior_registers (regno
)
264 for (regno
= 0; regno
< NUM_REGS
; regno
++)
265 fetch_register (regno
);
267 fetch_register (regno
);
270 /* Registers we shouldn't try to store. */
271 #if !defined (CANNOT_STORE_REGISTER)
272 #define CANNOT_STORE_REGISTER(regno) 0
275 /* Store our register values back into the inferior.
276 If REGNO is -1, do this for all registers.
277 Otherwise, REGNO specifies which register (so we can save time). */
280 store_inferior_registers (regno
)
283 register unsigned int regaddr
;
285 extern char registers
[];
288 unsigned int offset
= U_REGS_OFFSET
;
292 regaddr
= register_addr (regno
, offset
);
293 for (i
= 0; i
< REGISTER_RAW_SIZE (regno
); i
+= sizeof(int))
296 ptrace (PT_WRITE_U
, inferior_pid
, (PTRACE_ARG3_TYPE
) regaddr
,
297 *(int *) ®isters
[REGISTER_BYTE (regno
) + i
]);
300 sprintf (buf
, "writing register number %d(%d)", regno
, i
);
301 perror_with_name (buf
);
303 regaddr
+= sizeof(int);
308 for (regno
= 0; regno
< NUM_REGS
; regno
++)
310 if (CANNOT_STORE_REGISTER (regno
))
312 regaddr
= register_addr (regno
, offset
);
313 for (i
= 0; i
< REGISTER_RAW_SIZE (regno
); i
+= sizeof(int))
316 ptrace (PT_WRITE_U
, inferior_pid
, (PTRACE_ARG3_TYPE
) regaddr
,
317 *(int *) ®isters
[REGISTER_BYTE (regno
) + i
]);
320 sprintf (buf
, "writing register number %d(%d)", regno
, i
);
321 perror_with_name (buf
);
323 regaddr
+= sizeof(int);
329 #endif /* !defined (FETCH_INFERIOR_REGISTERS). */
331 /* NOTE! I tried using PTRACE_READDATA, etc., to read and write memory
332 in the NEW_SUN_PTRACE case.
333 It ought to be straightforward. But it appears that writing did
334 not write the data that I specified. I cannot understand where
335 it got the data that it actually did write. */
337 /* Copy LEN bytes to or from inferior's memory starting at MEMADDR
338 to debugger memory starting at MYADDR. Copy to inferior if
341 Returns the length copied, which is either the LEN argument or zero.
342 This xfer function does not do partial moves, since child_ops
343 doesn't allow memory operations to cross below us in the target stack
347 child_xfer_memory (memaddr
, myaddr
, len
, write
, target
)
352 struct target_ops
*target
; /* ignored */
355 /* Round starting address down to longword boundary. */
356 register CORE_ADDR addr
= memaddr
& - sizeof (int);
357 /* Round ending address up; get number of longwords that makes. */
359 = (((memaddr
+ len
) - addr
) + sizeof (int) - 1) / sizeof (int);
360 /* Allocate buffer of that many longwords. */
361 register int *buffer
= (int *) alloca (count
* sizeof (int));
365 /* Fill start and end extra bytes of buffer with existing memory data. */
367 if (addr
!= memaddr
|| len
< (int)sizeof (int)) {
368 /* Need part of initial word -- fetch it. */
369 buffer
[0] = ptrace (PT_READ_I
, inferior_pid
, (PTRACE_ARG3_TYPE
) addr
,
373 if (count
> 1) /* FIXME, avoid if even boundary */
376 = ptrace (PT_READ_I
, inferior_pid
,
377 (PTRACE_ARG3_TYPE
) (addr
+ (count
- 1) * sizeof (int)),
381 /* Copy data to be written over corresponding part of buffer */
383 bcopy (myaddr
, (char *) buffer
+ (memaddr
& (sizeof (int) - 1)), len
);
385 /* Write the entire buffer. */
387 for (i
= 0; i
< count
; i
++, addr
+= sizeof (int))
390 ptrace (PT_WRITE_D
, inferior_pid
, (PTRACE_ARG3_TYPE
) addr
,
394 /* Using the appropriate one (I or D) is necessary for
395 Gould NP1, at least. */
397 ptrace (PT_WRITE_I
, inferior_pid
, (PTRACE_ARG3_TYPE
) addr
,
406 /* Read all the longwords */
407 for (i
= 0; i
< count
; i
++, addr
+= sizeof (int))
410 buffer
[i
] = ptrace (PT_READ_I
, inferior_pid
,
411 (PTRACE_ARG3_TYPE
) addr
, 0);
417 /* Copy appropriate bytes out of the buffer. */
418 bcopy ((char *) buffer
+ (memaddr
& (sizeof (int) - 1)), myaddr
, len
);
This page took 0.039508 seconds and 4 git commands to generate.