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