* configure.in, dbxread.c, hppa-coredep.c, hppa-pinsn.c,
[deliverable/binutils-gdb.git] / gdb / hppahpux-xdep.c
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.
4
5 Contributed by the Center for Software Science at the
6 University of Utah (pa-gdb-bugs@cs.utah.edu).
7
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.
10
11 This file is part of GDB.
12
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.
17
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.
22
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. */
26
27 #include <stdio.h>
28 #include "defs.h"
29 #include "frame.h"
30 #include "inferior.h"
31 #include "target.h"
32
33 #ifdef USG
34 #include <sys/types.h>
35 #endif
36
37 #include <sys/param.h>
38 #include <sys/dir.h>
39 #include <signal.h>
40 #include <sys/ioctl.h>
41
42 #include <sys/ptrace.h>
43
44
45 #ifndef PT_ATTACH
46 #define PT_ATTACH PTRACE_ATTACH
47 #endif
48 #ifndef PT_DETACH
49 #define PT_DETACH PTRACE_DETACH
50 #endif
51
52 #include "gdbcore.h"
53 #include <sys/user.h> /* After a.out.h */
54 #include <sys/file.h>
55 #include <sys/stat.h>
56 \f
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. */
60 int
61 call_ptrace (request, pid, addr, data)
62 int request, pid, *addr, data;
63 {
64 return ptrace (request, pid, addr, data, 0);
65 }
66
67 #ifdef DEBUG_PTRACE
68 /* For the rest of the file, use an extra level of indirection */
69 /* This lets us breakpoint usefully on call_ptrace. */
70 #define ptrace call_ptrace
71 #endif
72
73 /* This is used when GDB is exiting. It gives less chance of error.*/
74
75 void
76 kill_inferior_fast ()
77 {
78 if (inferior_pid == 0)
79 return;
80 ptrace (PT_EXIT, inferior_pid, 0, 0, 0); /* PT_EXIT = PT_KILL ? */
81 wait ((int *)0);
82 }
83
84 void
85 kill_inferior ()
86 {
87 kill_inferior_fast ();
88 target_mourn_inferior ();
89 }
90
91 /* Resume execution of the inferior process.
92 If STEP is nonzero, single-step it.
93 If SIGNAL is nonzero, give it that signal. */
94
95 void
96 child_resume (step, signal)
97 int step;
98 int signal;
99 {
100 errno = 0;
101
102 /* An address of (int *)1 tells ptrace to continue from where it was.
103 (If GDB wanted it to start some other way, we have already written
104 a new PC value to the child.) */
105
106 if (step)
107 ptrace (PT_SINGLE, inferior_pid, (int *)1, signal, 0);
108 else
109 ptrace (PT_CONTIN, inferior_pid, (int *)1, signal, 0);
110
111 if (errno)
112 perror_with_name ("ptrace");
113 }
114 \f
115 #ifdef ATTACH_DETACH
116 /* Nonzero if we are debugging an attached process rather than
117 an inferior. */
118 extern int attach_flag;
119
120 /* Start debugging the process whose number is PID. */
121 int
122 attach (pid)
123 int pid;
124 {
125 errno = 0;
126 ptrace (PT_ATTACH, pid, 0, 0, 0);
127 if (errno)
128 perror_with_name ("ptrace");
129 attach_flag = 1;
130 return pid;
131 }
132
133 /* Stop debugging the process whose number is PID
134 and continue it with signal number SIGNAL.
135 SIGNAL = 0 means just continue it. */
136
137 void
138 detach (signal)
139 int signal;
140 {
141 errno = 0;
142 ptrace (PT_DETACH, inferior_pid, 1, signal, 0);
143 if (errno)
144 perror_with_name ("ptrace");
145 attach_flag = 0;
146 }
147 #endif /* ATTACH_DETACH */
148 \f
149 #if !defined (FETCH_INFERIOR_REGISTERS)
150
151 /* KERNEL_U_ADDR is the amount to subtract from u.u_ar0
152 to get the offset in the core file of the register values. */
153 #if defined (KERNEL_U_ADDR_BSD)
154 /* Get kernel_u_addr using BSD-style nlist(). */
155 CORE_ADDR kernel_u_addr;
156
157 #include <a.out.gnu.h> /* For struct nlist */
158
159 void
160 _initialize_kernel_u_addr ()
161 {
162 struct nlist names[2];
163
164 names[0].n_un.n_name = "_u";
165 names[1].n_un.n_name = NULL;
166 if (nlist ("/vmunix", names) == 0)
167 kernel_u_addr = names[0].n_value;
168 else
169 fatal ("Unable to get kernel u area address.");
170 }
171 #endif /* KERNEL_U_ADDR_BSD. */
172
173 #if defined (KERNEL_U_ADDR_HPUX)
174 /* Get kernel_u_addr using HPUX-style nlist(). */
175 CORE_ADDR kernel_u_addr;
176
177 struct hpnlist {
178 char * n_name;
179 long n_value;
180 unsigned char n_type;
181 unsigned char n_length;
182 short n_almod;
183 short n_unused;
184 };
185 static struct hpnlist nl[] = {{ "_u", -1, }, { (char *) 0, }};
186
187 /* read the value of the u area from the hp-ux kernel */
188 void _initialize_kernel_u_addr ()
189 {
190 struct user u;
191 nlist ("/hp-ux", &nl);
192 kernel_u_addr = nl[0].n_value;
193 }
194 #endif /* KERNEL_U_ADDR_HPUX. */
195
196 #if !defined (offsetof)
197 #define offsetof(TYPE, MEMBER) ((unsigned long) &((TYPE *)0)->MEMBER)
198 #endif
199
200 /* U_REGS_OFFSET is the offset of the registers within the u area. */
201 #if !defined (U_REGS_OFFSET)
202 #define U_REGS_OFFSET \
203 ptrace (PT_READ_U, inferior_pid, \
204 (int *)(offsetof (struct user, u_ar0)), 0, 0) - KERNEL_U_ADDR
205 #endif
206
207 /* Registers we shouldn't try to fetch. */
208 #if !defined (CANNOT_FETCH_REGISTER)
209 #define CANNOT_FETCH_REGISTER(regno) 0
210 #endif
211
212 /* Fetch one register. */
213
214 static void
215 fetch_register (regno)
216 int regno;
217 {
218 register unsigned int regaddr;
219 char buf[MAX_REGISTER_RAW_SIZE];
220 char mess[128]; /* For messages */
221 register int i;
222
223 /* Offset of registers within the u area. */
224 unsigned int offset;
225
226 if (CANNOT_FETCH_REGISTER (regno))
227 {
228 bzero (buf, REGISTER_RAW_SIZE (regno)); /* Supply zeroes */
229 supply_register (regno, buf);
230 return;
231 }
232
233 offset = U_REGS_OFFSET;
234
235 regaddr = register_addr (regno, offset);
236 for (i = 0; i < REGISTER_RAW_SIZE (regno); i += sizeof (int))
237 {
238 errno = 0;
239 *(int *) &buf[i] = ptrace (PT_RUREGS, inferior_pid, (int *)regaddr, 0, 0);
240 regaddr += sizeof (int);
241 if (errno != 0)
242 {
243 sprintf (mess, "reading register %s (#%d)", reg_names[regno], regno);
244 perror_with_name (mess);
245 }
246 }
247 if (regno == PCOQ_HEAD_REGNUM || regno == PCOQ_TAIL_REGNUM)
248 buf[3] &= ~0x3;
249 supply_register (regno, buf);
250 }
251
252
253 /* Fetch all registers, or just one, from the child process. */
254
255 void
256 fetch_inferior_registers (regno)
257 int regno;
258 {
259 if (regno == -1)
260 for (regno = 0; regno < NUM_REGS; regno++)
261 fetch_register (regno);
262 else
263 fetch_register (regno);
264 }
265
266 /* Registers we shouldn't try to store. */
267 #if !defined (CANNOT_STORE_REGISTER)
268 #define CANNOT_STORE_REGISTER(regno) 0
269 #endif
270
271 /* Store our register values back into the inferior.
272 If REGNO is -1, do this for all registers.
273 Otherwise, REGNO specifies which register (so we can save time). */
274
275 void
276 store_inferior_registers (regno)
277 int regno;
278 {
279 register unsigned int regaddr;
280 char buf[80];
281 extern char registers[];
282 register int i;
283
284 unsigned int offset = U_REGS_OFFSET;
285
286 if (regno >= 0)
287 {
288 regaddr = register_addr (regno, offset);
289 for (i = 0; i < REGISTER_RAW_SIZE (regno); i += sizeof(int))
290 {
291 errno = 0;
292 ptrace (PT_WUAREA, inferior_pid, (int *)regaddr,
293 *(int *) &registers[REGISTER_BYTE (regno) + i], 0);
294 if (errno != 0)
295 {
296 sprintf (buf, "writing register number %d(%d)", regno, i);
297 perror_with_name (buf);
298 }
299 regaddr += sizeof(int);
300 }
301 }
302 else
303 {
304 for (regno = 0; regno < NUM_REGS; regno++)
305 {
306 if (CANNOT_STORE_REGISTER (regno))
307 continue;
308 regaddr = register_addr (regno, offset);
309 for (i = 0; i < REGISTER_RAW_SIZE (regno); i += sizeof(int))
310 {
311 errno = 0;
312 ptrace (PT_WUAREA, inferior_pid, (int *)regaddr,
313 *(int *) &registers[REGISTER_BYTE (regno) + i], 0);
314 if (errno != 0)
315 {
316 sprintf (buf, "writing register number %d(%d)", regno, i);
317 perror_with_name (buf);
318 }
319 regaddr += sizeof(int);
320 }
321 }
322 }
323 return;
324 }
325 #endif /* !defined (FETCH_INFERIOR_REGISTERS). */
326 \f
327 /* NOTE! I tried using PTRACE_READDATA, etc., to read and write memory
328 in the NEW_SUN_PTRACE case.
329 It ought to be straightforward. But it appears that writing did
330 not write the data that I specified. I cannot understand where
331 it got the data that it actually did write. */
332
333 /* Copy LEN bytes to or from inferior's memory starting at MEMADDR
334 to debugger memory starting at MYADDR. Copy to inferior if
335 WRITE is nonzero.
336
337 Returns the length copied, which is either the LEN argument or zero.
338 This xfer function does not do partial moves, since child_ops
339 doesn't allow memory operations to cross below us in the target stack
340 anyway. */
341
342 int
343 child_xfer_memory (memaddr, myaddr, len, write, target)
344 CORE_ADDR memaddr;
345 char *myaddr;
346 int len;
347 int write;
348 struct target_ops *target; /* ignored */
349 {
350 register int i;
351 /* Round starting address down to longword boundary. */
352 register CORE_ADDR addr = memaddr & - sizeof (int);
353 /* Round ending address up; get number of longwords that makes. */
354 register int count
355 = (((memaddr + len) - addr) + sizeof (int) - 1) / sizeof (int);
356 /* Allocate buffer of that many longwords. */
357 register int *buffer = (int *) alloca (count * sizeof (int));
358
359 if (write)
360 {
361 /* Fill start and end extra bytes of buffer with existing memory data. */
362
363 if (addr != memaddr || len < (int)sizeof (int)) {
364 /* Need part of initial word -- fetch it. */
365 buffer[0] = ptrace (PT_RIUSER, inferior_pid, (int *)addr, 0, 0);
366 }
367
368 if (count > 1) /* FIXME, avoid if even boundary */
369 {
370 buffer[count - 1]
371 = ptrace (PT_RIUSER, inferior_pid,
372 (int *)(addr + (count - 1) * sizeof (int)), 0, 0);
373 }
374
375 /* Copy data to be written over corresponding part of buffer */
376
377 bcopy (myaddr, (char *) buffer + (memaddr & (sizeof (int) - 1)), len);
378
379 /* Write the entire buffer. */
380
381 for (i = 0; i < count; i++, addr += sizeof (int))
382 {
383 errno = 0;
384 ptrace (PT_WDUSER, inferior_pid, (int *)addr, buffer[i], 0);
385 if (errno)
386 {
387 /* Using the appropriate one (I or D) is necessary for
388 Gould NP1, at least. */
389 errno = 0;
390 ptrace (PT_WIUSER, inferior_pid, (int *)addr, buffer[i], 0);
391 }
392 if (errno)
393 return 0;
394 }
395 }
396 else
397 {
398 /* Read all the longwords */
399 for (i = 0; i < count; i++, addr += sizeof (int))
400 {
401 errno = 0;
402 buffer[i] = ptrace (PT_RIUSER, inferior_pid, (int *)addr, 0, 0);
403 if (errno)
404 return 0;
405 QUIT;
406 }
407
408 /* Copy appropriate bytes out of the buffer. */
409 bcopy ((char *) buffer + (memaddr & (sizeof (int) - 1)), myaddr, len);
410 }
411 return len;
412 }
413
414
415
416
417 int
418 getpagesize()
419 {
420 return(4096);
421 }
This page took 0.041828 seconds and 5 git commands to generate.