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 (C) 1986, 1987, 1989, 1990, 1991 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. */
34 #include <sys/types.h>
37 #include <sys/param.h>
40 #include <sys/ioctl.h>
42 #include <sys/ptrace.h>
47 #define PT_ATTACH PTRACE_ATTACH
50 #define PT_DETACH PTRACE_DETACH
54 #include <sys/user.h> /* After a.out.h */
58 /* This function simply calls ptrace with the given arguments.
59 It exists so that all calls to ptrace are isolated in this
60 machine-dependent file. */
62 call_ptrace (request
, pid
, addr
, data
)
64 PTRACE_ARG3_TYPE addr
;
67 return ptrace (request
, pid
, addr
, data
);
71 /* For the rest of the file, use an extra level of indirection */
72 /* This lets us breakpoint usefully on call_ptrace. */
73 #define ptrace call_ptrace
76 /* This is used when GDB is exiting. It gives less chance of error.*/
81 if (inferior_pid
== 0)
83 ptrace (PT_KILL
, inferior_pid
, (PTRACE_ARG3_TYPE
) 0, 0);
90 kill_inferior_fast ();
91 target_mourn_inferior ();
94 /* Resume execution of the inferior process.
95 If STEP is nonzero, single-step it.
96 If SIGNAL is nonzero, give it that signal. */
99 child_resume (step
, signal
)
105 /* An address of (PTRACE_ARG3_TYPE) 1 tells ptrace to continue from where
106 it was. (If GDB wanted it to start some other way, we have already
107 written a new PC value to the child.) */
110 ptrace (PT_STEP
, inferior_pid
, (PTRACE_ARG3_TYPE
) 1, signal
);
112 ptrace (PT_CONTINUE
, inferior_pid
, (PTRACE_ARG3_TYPE
) 1, signal
);
115 perror_with_name ("ptrace");
119 /* Nonzero if we are debugging an attached process rather than
121 extern int attach_flag
;
123 /* Start debugging the process whose number is PID. */
129 ptrace (PT_ATTACH
, pid
, (PTRACE_ARG3_TYPE
) 0, 0);
131 perror_with_name ("ptrace");
136 /* Stop debugging the process whose number is PID
137 and continue it with signal number SIGNAL.
138 SIGNAL = 0 means just continue it. */
145 ptrace (PT_DETACH
, inferior_pid
, (PTRACE_ARG3_TYPE
) 1, signal
);
147 perror_with_name ("ptrace");
150 #endif /* ATTACH_DETACH */
152 #if !defined (FETCH_INFERIOR_REGISTERS)
154 /* KERNEL_U_ADDR is the amount to subtract from u.u_ar0
155 to get the offset in the core file of the register values. */
156 #if defined (KERNEL_U_ADDR_BSD)
157 /* Get kernel_u_addr using BSD-style nlist(). */
158 CORE_ADDR kernel_u_addr
;
160 #include <a.out.gnu.h> /* For struct nlist */
163 _initialize_kernel_u_addr ()
165 struct nlist names
[2];
167 names
[0].n_un
.n_name
= "_u";
168 names
[1].n_un
.n_name
= NULL
;
169 if (nlist ("/vmunix", names
) == 0)
170 kernel_u_addr
= names
[0].n_value
;
172 fatal ("Unable to get kernel u area address.");
174 #endif /* KERNEL_U_ADDR_BSD. */
176 #if defined (KERNEL_U_ADDR_HPUX)
177 /* Get kernel_u_addr using HPUX-style nlist(). */
178 CORE_ADDR kernel_u_addr
;
183 unsigned char n_type
;
184 unsigned char n_length
;
188 static struct hpnlist nl
[] = {{ "_u", -1, }, { (char *) 0, }};
190 /* read the value of the u area from the hp-ux kernel */
191 void _initialize_kernel_u_addr ()
194 nlist ("/hp-ux", &nl
);
195 kernel_u_addr
= nl
[0].n_value
;
197 #endif /* KERNEL_U_ADDR_HPUX. */
199 #if !defined (offsetof)
200 #define offsetof(TYPE, MEMBER) ((unsigned long) &((TYPE *)0)->MEMBER)
203 /* U_REGS_OFFSET is the offset of the registers within the u area. */
204 #if !defined (U_REGS_OFFSET)
205 #define U_REGS_OFFSET \
206 ptrace (PT_READ_U, inferior_pid, \
207 (PTRACE_ARG3_TYPE) (offsetof (struct user, u_ar0)), 0) \
211 /* Registers we shouldn't try to fetch. */
212 #if !defined (CANNOT_FETCH_REGISTER)
213 #define CANNOT_FETCH_REGISTER(regno) 0
216 /* Fetch one register. */
219 fetch_register (regno
)
222 register unsigned int regaddr
;
223 char buf
[MAX_REGISTER_RAW_SIZE
];
224 char mess
[128]; /* For messages */
227 /* Offset of registers within the u area. */
230 if (CANNOT_FETCH_REGISTER (regno
))
232 bzero (buf
, REGISTER_RAW_SIZE (regno
)); /* Supply zeroes */
233 supply_register (regno
, buf
);
237 offset
= U_REGS_OFFSET
;
239 regaddr
= register_addr (regno
, offset
);
240 for (i
= 0; i
< REGISTER_RAW_SIZE (regno
); i
+= sizeof (int))
243 *(int *) &buf
[i
] = ptrace (PT_RUREGS
, inferior_pid
,
244 (PTRACE_ARG3_TYPE
) regaddr
, 0);
245 regaddr
+= sizeof (int);
248 sprintf (mess
, "reading register %s (#%d)", reg_names
[regno
], regno
);
249 perror_with_name (mess
);
252 if (regno
== PCOQ_HEAD_REGNUM
|| regno
== PCOQ_TAIL_REGNUM
)
254 supply_register (regno
, buf
);
258 /* Fetch all registers, or just one, from the child process. */
261 fetch_inferior_registers (regno
)
265 for (regno
= 0; regno
< NUM_REGS
; regno
++)
266 fetch_register (regno
);
268 fetch_register (regno
);
271 /* Registers we shouldn't try to store. */
272 #if !defined (CANNOT_STORE_REGISTER)
273 #define CANNOT_STORE_REGISTER(regno) 0
276 /* Store our register values back into the inferior.
277 If REGNO is -1, do this for all registers.
278 Otherwise, REGNO specifies which register (so we can save time). */
281 store_inferior_registers (regno
)
284 register unsigned int regaddr
;
286 extern char registers
[];
289 unsigned int offset
= U_REGS_OFFSET
;
293 regaddr
= register_addr (regno
, offset
);
294 for (i
= 0; i
< REGISTER_RAW_SIZE (regno
); i
+= sizeof(int))
297 ptrace (PT_WRITE_U
, inferior_pid
, (PTRACE_ARG3_TYPE
) regaddr
,
298 *(int *) ®isters
[REGISTER_BYTE (regno
) + i
]);
301 sprintf (buf
, "writing register number %d(%d)", regno
, i
);
302 perror_with_name (buf
);
304 regaddr
+= sizeof(int);
309 for (regno
= 0; regno
< NUM_REGS
; regno
++)
311 if (CANNOT_STORE_REGISTER (regno
))
313 regaddr
= register_addr (regno
, offset
);
314 for (i
= 0; i
< REGISTER_RAW_SIZE (regno
); i
+= sizeof(int))
317 ptrace (PT_WRITE_U
, inferior_pid
, (PTRACE_ARG3_TYPE
) regaddr
,
318 *(int *) ®isters
[REGISTER_BYTE (regno
) + i
]);
321 sprintf (buf
, "writing register number %d(%d)", regno
, i
);
322 perror_with_name (buf
);
324 regaddr
+= sizeof(int);
330 #endif /* !defined (FETCH_INFERIOR_REGISTERS). */
332 /* NOTE! I tried using PTRACE_READDATA, etc., to read and write memory
333 in the NEW_SUN_PTRACE case.
334 It ought to be straightforward. But it appears that writing did
335 not write the data that I specified. I cannot understand where
336 it got the data that it actually did write. */
338 /* Copy LEN bytes to or from inferior's memory starting at MEMADDR
339 to debugger memory starting at MYADDR. Copy to inferior if
342 Returns the length copied, which is either the LEN argument or zero.
343 This xfer function does not do partial moves, since child_ops
344 doesn't allow memory operations to cross below us in the target stack
348 child_xfer_memory (memaddr
, myaddr
, len
, write
, target
)
353 struct target_ops
*target
; /* ignored */
356 /* Round starting address down to longword boundary. */
357 register CORE_ADDR addr
= memaddr
& - sizeof (int);
358 /* Round ending address up; get number of longwords that makes. */
360 = (((memaddr
+ len
) - addr
) + sizeof (int) - 1) / sizeof (int);
361 /* Allocate buffer of that many longwords. */
362 register int *buffer
= (int *) alloca (count
* sizeof (int));
366 /* Fill start and end extra bytes of buffer with existing memory data. */
368 if (addr
!= memaddr
|| len
< (int)sizeof (int)) {
369 /* Need part of initial word -- fetch it. */
370 buffer
[0] = ptrace (PT_READ_I
, inferior_pid
, (PTRACE_ARG3_TYPE
) addr
,
374 if (count
> 1) /* FIXME, avoid if even boundary */
377 = ptrace (PT_READ_I
, inferior_pid
,
378 (PTRACE_ARG3_TYPE
) (addr
+ (count
- 1) * sizeof (int)),
382 /* Copy data to be written over corresponding part of buffer */
384 bcopy (myaddr
, (char *) buffer
+ (memaddr
& (sizeof (int) - 1)), len
);
386 /* Write the entire buffer. */
388 for (i
= 0; i
< count
; i
++, addr
+= sizeof (int))
391 ptrace (PT_WRITE_D
, inferior_pid
, (PTRACE_ARG3_TYPE
) addr
,
395 /* Using the appropriate one (I or D) is necessary for
396 Gould NP1, at least. */
398 ptrace (PT_WRITE_I
, inferior_pid
, (PTRACE_ARG3_TYPE
) addr
,
407 /* Read all the longwords */
408 for (i
= 0; i
< count
; i
++, addr
+= sizeof (int))
411 buffer
[i
] = ptrace (PT_READ_I
, inferior_pid
,
412 (PTRACE_ARG3_TYPE
) addr
, 0);
418 /* Copy appropriate bytes out of the buffer. */
419 bcopy ((char *) buffer
+ (memaddr
& (sizeof (int) - 1)), myaddr
, len
);
This page took 0.038316 seconds and 5 git commands to generate.