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
78 if (inferior_pid
== 0)
80 ptrace (PT_KILL
, inferior_pid
, (PTRACE_ARG3_TYPE
) 0, 0);
82 target_mourn_inferior ();
85 /* Resume execution of the inferior process.
86 If STEP is nonzero, single-step it.
87 If SIGNAL is nonzero, give it that signal. */
90 child_resume (step
, signal
)
96 /* An address of (PTRACE_ARG3_TYPE) 1 tells ptrace to continue from where
97 it was. (If GDB wanted it to start some other way, we have already
98 written a new PC value to the child.) */
101 ptrace (PT_STEP
, inferior_pid
, (PTRACE_ARG3_TYPE
) 1, signal
);
103 ptrace (PT_CONTINUE
, inferior_pid
, (PTRACE_ARG3_TYPE
) 1, signal
);
106 perror_with_name ("ptrace");
110 /* Nonzero if we are debugging an attached process rather than
112 extern int attach_flag
;
114 /* Start debugging the process whose number is PID. */
120 ptrace (PT_ATTACH
, pid
, (PTRACE_ARG3_TYPE
) 0, 0);
122 perror_with_name ("ptrace");
127 /* Stop debugging the process whose number is PID
128 and continue it with signal number SIGNAL.
129 SIGNAL = 0 means just continue it. */
136 ptrace (PT_DETACH
, inferior_pid
, (PTRACE_ARG3_TYPE
) 1, signal
);
138 perror_with_name ("ptrace");
141 #endif /* ATTACH_DETACH */
143 #if !defined (FETCH_INFERIOR_REGISTERS)
145 /* KERNEL_U_ADDR is the amount to subtract from u.u_ar0
146 to get the offset in the core file of the register values. */
147 #if defined (KERNEL_U_ADDR_BSD)
148 /* Get kernel_u_addr using BSD-style nlist(). */
149 CORE_ADDR kernel_u_addr
;
151 #include <a.out.gnu.h> /* For struct nlist */
154 _initialize_kernel_u_addr ()
156 struct nlist names
[2];
158 names
[0].n_un
.n_name
= "_u";
159 names
[1].n_un
.n_name
= NULL
;
160 if (nlist ("/vmunix", names
) == 0)
161 kernel_u_addr
= names
[0].n_value
;
163 fatal ("Unable to get kernel u area address.");
165 #endif /* KERNEL_U_ADDR_BSD. */
167 #if defined (KERNEL_U_ADDR_HPUX)
168 /* Get kernel_u_addr using HPUX-style nlist(). */
169 CORE_ADDR kernel_u_addr
;
174 unsigned char n_type
;
175 unsigned char n_length
;
179 static struct hpnlist nl
[] = {{ "_u", -1, }, { (char *) 0, }};
181 /* read the value of the u area from the hp-ux kernel */
182 void _initialize_kernel_u_addr ()
185 nlist ("/hp-ux", &nl
);
186 kernel_u_addr
= nl
[0].n_value
;
188 #endif /* KERNEL_U_ADDR_HPUX. */
190 #if !defined (offsetof)
191 #define offsetof(TYPE, MEMBER) ((unsigned long) &((TYPE *)0)->MEMBER)
194 /* U_REGS_OFFSET is the offset of the registers within the u area. */
195 #if !defined (U_REGS_OFFSET)
196 #define U_REGS_OFFSET \
197 ptrace (PT_READ_U, inferior_pid, \
198 (PTRACE_ARG3_TYPE) (offsetof (struct user, u_ar0)), 0) \
202 /* Registers we shouldn't try to fetch. */
203 #if !defined (CANNOT_FETCH_REGISTER)
204 #define CANNOT_FETCH_REGISTER(regno) 0
207 /* Fetch one register. */
210 fetch_register (regno
)
213 register unsigned int regaddr
;
214 char buf
[MAX_REGISTER_RAW_SIZE
];
215 char mess
[128]; /* For messages */
218 /* Offset of registers within the u area. */
221 if (CANNOT_FETCH_REGISTER (regno
))
223 bzero (buf
, REGISTER_RAW_SIZE (regno
)); /* Supply zeroes */
224 supply_register (regno
, buf
);
228 offset
= U_REGS_OFFSET
;
230 regaddr
= register_addr (regno
, offset
);
231 for (i
= 0; i
< REGISTER_RAW_SIZE (regno
); i
+= sizeof (int))
234 *(int *) &buf
[i
] = ptrace (PT_RUREGS
, inferior_pid
,
235 (PTRACE_ARG3_TYPE
) regaddr
, 0);
236 regaddr
+= sizeof (int);
239 sprintf (mess
, "reading register %s (#%d)", reg_names
[regno
], regno
);
240 perror_with_name (mess
);
243 if (regno
== PCOQ_HEAD_REGNUM
|| regno
== PCOQ_TAIL_REGNUM
)
245 supply_register (regno
, buf
);
249 /* Fetch all registers, or just one, from the child process. */
252 fetch_inferior_registers (regno
)
256 for (regno
= 0; regno
< NUM_REGS
; regno
++)
257 fetch_register (regno
);
259 fetch_register (regno
);
262 /* Registers we shouldn't try to store. */
263 #if !defined (CANNOT_STORE_REGISTER)
264 #define CANNOT_STORE_REGISTER(regno) 0
267 /* Store our register values back into the inferior.
268 If REGNO is -1, do this for all registers.
269 Otherwise, REGNO specifies which register (so we can save time). */
272 store_inferior_registers (regno
)
275 register unsigned int regaddr
;
277 extern char registers
[];
280 unsigned int offset
= U_REGS_OFFSET
;
284 regaddr
= register_addr (regno
, offset
);
285 for (i
= 0; i
< REGISTER_RAW_SIZE (regno
); i
+= sizeof(int))
288 ptrace (PT_WRITE_U
, inferior_pid
, (PTRACE_ARG3_TYPE
) regaddr
,
289 *(int *) ®isters
[REGISTER_BYTE (regno
) + i
]);
292 sprintf (buf
, "writing register number %d(%d)", regno
, i
);
293 perror_with_name (buf
);
295 regaddr
+= sizeof(int);
300 for (regno
= 0; regno
< NUM_REGS
; regno
++)
302 if (CANNOT_STORE_REGISTER (regno
))
304 regaddr
= register_addr (regno
, offset
);
305 for (i
= 0; i
< REGISTER_RAW_SIZE (regno
); i
+= sizeof(int))
308 ptrace (PT_WRITE_U
, inferior_pid
, (PTRACE_ARG3_TYPE
) regaddr
,
309 *(int *) ®isters
[REGISTER_BYTE (regno
) + i
]);
312 sprintf (buf
, "writing register number %d(%d)", regno
, i
);
313 perror_with_name (buf
);
315 regaddr
+= sizeof(int);
321 #endif /* !defined (FETCH_INFERIOR_REGISTERS). */
323 /* NOTE! I tried using PTRACE_READDATA, etc., to read and write memory
324 in the NEW_SUN_PTRACE case.
325 It ought to be straightforward. But it appears that writing did
326 not write the data that I specified. I cannot understand where
327 it got the data that it actually did write. */
329 /* Copy LEN bytes to or from inferior's memory starting at MEMADDR
330 to debugger memory starting at MYADDR. Copy to inferior if
333 Returns the length copied, which is either the LEN argument or zero.
334 This xfer function does not do partial moves, since child_ops
335 doesn't allow memory operations to cross below us in the target stack
339 child_xfer_memory (memaddr
, myaddr
, len
, write
, target
)
344 struct target_ops
*target
; /* ignored */
347 /* Round starting address down to longword boundary. */
348 register CORE_ADDR addr
= memaddr
& - sizeof (int);
349 /* Round ending address up; get number of longwords that makes. */
351 = (((memaddr
+ len
) - addr
) + sizeof (int) - 1) / sizeof (int);
352 /* Allocate buffer of that many longwords. */
353 register int *buffer
= (int *) alloca (count
* sizeof (int));
357 /* Fill start and end extra bytes of buffer with existing memory data. */
359 if (addr
!= memaddr
|| len
< (int)sizeof (int)) {
360 /* Need part of initial word -- fetch it. */
361 buffer
[0] = ptrace (PT_READ_I
, inferior_pid
, (PTRACE_ARG3_TYPE
) addr
,
365 if (count
> 1) /* FIXME, avoid if even boundary */
368 = ptrace (PT_READ_I
, inferior_pid
,
369 (PTRACE_ARG3_TYPE
) (addr
+ (count
- 1) * sizeof (int)),
373 /* Copy data to be written over corresponding part of buffer */
375 bcopy (myaddr
, (char *) buffer
+ (memaddr
& (sizeof (int) - 1)), len
);
377 /* Write the entire buffer. */
379 for (i
= 0; i
< count
; i
++, addr
+= sizeof (int))
382 ptrace (PT_WRITE_D
, inferior_pid
, (PTRACE_ARG3_TYPE
) addr
,
386 /* Using the appropriate one (I or D) is necessary for
387 Gould NP1, at least. */
389 ptrace (PT_WRITE_I
, inferior_pid
, (PTRACE_ARG3_TYPE
) addr
,
398 /* Read all the longwords */
399 for (i
= 0; i
< count
; i
++, addr
+= sizeof (int))
402 buffer
[i
] = ptrace (PT_READ_I
, inferior_pid
,
403 (PTRACE_ARG3_TYPE
) addr
, 0);
409 /* Copy appropriate bytes out of the buffer. */
410 bcopy ((char *) buffer
+ (memaddr
& (sizeof (int) - 1)), myaddr
, len
);
This page took 0.038475 seconds and 4 git commands to generate.