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>
30 #ifdef FIVE_ARG_PTRACE
32 /* Deal with HPUX 8.0 braindamage. */
33 #define ptrace(a,b,c,d) ptrace(a,b,c,d,0)
38 #define PT_ATTACH PTRACE_ATTACH
42 #define PT_DETACH PTRACE_DETACH
45 /* This function simply calls ptrace with the given arguments.
46 It exists so that all calls to ptrace are isolated in this
47 machine-dependent file. */
50 call_ptrace (request
, pid
, addr
, data
)
52 PTRACE_ARG3_TYPE addr
;
55 return ptrace (request
, pid
, addr
, data
);
59 /* For the rest of the file, use an extra level of indirection */
60 /* This lets us breakpoint usefully on call_ptrace. */
61 #define ptrace call_ptrace
67 if (inferior_pid
== 0)
69 ptrace (PT_KILL
, inferior_pid
, (PTRACE_ARG3_TYPE
) 0, 0);
71 target_mourn_inferior ();
76 /* Start debugging the process whose number is PID. */
82 ptrace (PT_ATTACH
, pid
, (PTRACE_ARG3_TYPE
) 0, 0);
84 perror_with_name ("ptrace");
89 /* Stop debugging the process whose number is PID
90 and continue it with signal number SIGNAL.
91 SIGNAL = 0 means just continue it. */
98 ptrace (PT_DETACH
, inferior_pid
, (PTRACE_ARG3_TYPE
) 1, signal
);
100 perror_with_name ("ptrace");
103 #endif /* ATTACH_DETACH */
107 /* KERNEL_U_ADDR is the amount to subtract from u.u_ar0
108 to get the offset in the core file of the register values. */
109 #if defined (KERNEL_U_ADDR_BSD)
110 /* Get kernel_u_addr using BSD-style nlist(). */
111 CORE_ADDR kernel_u_addr
;
113 #include <a.out.gnu.h> /* For struct nlist */
116 _initialize_kernel_u_addr ()
118 struct nlist names
[2];
120 names
[0].n_un
.n_name
= "_u";
121 names
[1].n_un
.n_name
= NULL
;
122 if (nlist ("/vmunix", names
) == 0)
123 kernel_u_addr
= names
[0].n_value
;
125 fatal ("Unable to get kernel u area address.");
127 #endif /* KERNEL_U_ADDR_BSD. */
129 #if defined (KERNEL_U_ADDR_HPUX)
130 /* Get kernel_u_addr using HPUX-style nlist(). */
131 CORE_ADDR kernel_u_addr
;
136 unsigned char n_type
;
137 unsigned char n_length
;
141 static struct hpnlist nl
[] = {{ "_u", -1, }, { (char *) 0, }};
143 /* read the value of the u area from the hp-ux kernel */
144 void _initialize_kernel_u_addr ()
147 nlist ("/hp-ux", &nl
);
148 kernel_u_addr
= nl
[0].n_value
;
150 #endif /* KERNEL_U_ADDR_HPUX. */
152 #if !defined (offsetof)
153 #define offsetof(TYPE, MEMBER) ((unsigned long) &((TYPE *)0)->MEMBER)
156 /* U_REGS_OFFSET is the offset of the registers within the u area. */
157 #if !defined (U_REGS_OFFSET)
158 #define U_REGS_OFFSET \
159 ptrace (PT_READ_U, inferior_pid, \
160 (PTRACE_ARG3_TYPE) (offsetof (struct user, u_ar0)), 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 offset
= U_REGS_OFFSET
;
180 regaddr
= register_addr (regno
, offset
);
181 for (i
= 0; i
< REGISTER_RAW_SIZE (regno
); i
+= sizeof (int))
184 *(int *) &buf
[i
] = ptrace (PT_RUREGS
, inferior_pid
,
185 (PTRACE_ARG3_TYPE
) regaddr
, 0);
186 regaddr
+= sizeof (int);
189 sprintf (mess
, "reading register %s (#%d)", reg_names
[regno
], regno
);
190 perror_with_name (mess
);
193 supply_register (regno
, buf
);
196 /* Fetch all registers, or just one, from the child process. */
199 fetch_inferior_registers (regno
)
203 for (regno
= 0; regno
< NUM_REGS
; regno
++)
204 fetch_register (regno
);
206 fetch_register (regno
);
209 /* Store our register values back into the inferior.
210 If REGNO is -1, do this for all registers.
211 Otherwise, REGNO specifies which register (so we can save time). */
214 store_inferior_registers (regno
)
217 register unsigned int regaddr
;
219 extern char registers
[];
222 unsigned int offset
= U_REGS_OFFSET
;
226 regaddr
= register_addr (regno
, offset
);
227 for (i
= 0; i
< REGISTER_RAW_SIZE (regno
); i
+= sizeof(int))
230 ptrace (PT_WUREGS
, inferior_pid
, (PTRACE_ARG3_TYPE
) regaddr
,
231 *(int *) ®isters
[REGISTER_BYTE (regno
) + i
]);
234 sprintf (buf
, "writing register number %d(%d)", regno
, i
);
235 perror_with_name (buf
);
237 regaddr
+= sizeof(int);
242 for (regno
= 0; regno
< NUM_REGS
; regno
++)
244 if (CANNOT_STORE_REGISTER (regno
))
246 regaddr
= register_addr (regno
, offset
);
247 for (i
= 0; i
< REGISTER_RAW_SIZE (regno
); i
+= sizeof(int))
250 ptrace (PT_WUREGS
, inferior_pid
, (PTRACE_ARG3_TYPE
) regaddr
,
251 *(int *) ®isters
[REGISTER_BYTE (regno
) + i
]);
254 sprintf (buf
, "writing register number %d(%d)", regno
, i
);
255 perror_with_name (buf
);
257 regaddr
+= sizeof(int);
264 /* Resume execution of the inferior process.
265 If STEP is nonzero, single-step it.
266 If SIGNAL is nonzero, give it that signal. */
269 child_resume (step
, signal
)
275 /* An address of (PTRACE_ARG3_TYPE) 1 tells ptrace to continue from where
276 it was. (If GDB wanted it to start some other way, we have already
277 written a new PC value to the child.) */
280 ptrace (PT_STEP
, inferior_pid
, (PTRACE_ARG3_TYPE
) 1, signal
);
282 ptrace (PT_CONTINUE
, inferior_pid
, (PTRACE_ARG3_TYPE
) 1, signal
);
285 perror_with_name ("ptrace");
288 /* NOTE! I tried using PTRACE_READDATA, etc., to read and write memory
289 in the NEW_SUN_PTRACE case.
290 It ought to be straightforward. But it appears that writing did
291 not write the data that I specified. I cannot understand where
292 it got the data that it actually did write. */
294 /* Copy LEN bytes to or from inferior's memory starting at MEMADDR
295 to debugger memory starting at MYADDR. Copy to inferior if
298 Returns the length copied, which is either the LEN argument or zero.
299 This xfer function does not do partial moves, since child_ops
300 doesn't allow memory operations to cross below us in the target stack
304 child_xfer_memory (memaddr
, myaddr
, len
, write
, target
)
309 struct target_ops
*target
; /* ignored */
312 /* Round starting address down to longword boundary. */
313 register CORE_ADDR addr
= memaddr
& - sizeof (int);
314 /* Round ending address up; get number of longwords that makes. */
316 = (((memaddr
+ len
) - addr
) + sizeof (int) - 1) / sizeof (int);
317 /* Allocate buffer of that many longwords. */
318 register int *buffer
= (int *) alloca (count
* sizeof (int));
322 /* Fill start and end extra bytes of buffer with existing memory data. */
324 if (addr
!= memaddr
|| len
< (int)sizeof (int)) {
325 /* Need part of initial word -- fetch it. */
326 buffer
[0] = ptrace (PT_READ_I
, inferior_pid
, (PTRACE_ARG3_TYPE
) addr
,
330 if (count
> 1) /* FIXME, avoid if even boundary */
333 = ptrace (PT_READ_I
, inferior_pid
,
334 (PTRACE_ARG3_TYPE
) (addr
+ (count
- 1) * sizeof (int)),
338 /* Copy data to be written over corresponding part of buffer */
340 bcopy (myaddr
, (char *) buffer
+ (memaddr
& (sizeof (int) - 1)), len
);
342 /* Write the entire buffer. */
344 for (i
= 0; i
< count
; i
++, addr
+= sizeof (int))
347 ptrace (PT_WRITE_D
, inferior_pid
, (PTRACE_ARG3_TYPE
) addr
,
351 /* Using the appropriate one (I or D) is necessary for
352 Gould NP1, at least. */
354 ptrace (PT_WRITE_I
, inferior_pid
, (PTRACE_ARG3_TYPE
) addr
,
363 /* Read all the longwords */
364 for (i
= 0; i
< count
; i
++, addr
+= sizeof (int))
367 buffer
[i
] = ptrace (PT_READ_I
, inferior_pid
,
368 (PTRACE_ARG3_TYPE
) addr
, 0);
374 /* Copy appropriate bytes out of the buffer. */
375 bcopy ((char *) buffer
+ (memaddr
& (sizeof (int) - 1)), myaddr
, len
);
This page took 0.03734 seconds and 4 git commands to generate.