1 /* Host-dependent code for HP PA-RISC running BSD Unix, for GDB.
2 Copyright 1986, 1987, 1989, 1990, 1991, 1992 Free Software Foundation, Inc.
3 Contributed by the Center for Software Science at the
4 University of Utah (pa-gdb-bugs@cs.utah.edu).
6 This file is part of GDB.
8 This program is free software; you can redistribute it and/or modify
9 it under the terms of the GNU General Public License as published by
10 the Free Software Foundation; either version 2 of the License, or
11 (at your option) any later version.
13 This program is distributed in the hope that it will be useful,
14 but WITHOUT ANY WARRANTY; without even the implied warranty of
15 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 GNU General Public License for more details.
18 You should have received a copy of the GNU General Public License
19 along with this program; if not, write to the Free Software
20 Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. */
28 #include <sys/types.h>
31 #include <sys/param.h>
34 #include <sys/ioctl.h>
36 #include <sys/ptrace.h>
41 #define PT_ATTACH PTRACE_ATTACH
44 #define PT_DETACH PTRACE_DETACH
48 #include <sys/user.h> /* After a.out.h */
52 /* This function simply calls ptrace with the given arguments.
53 It exists so that all calls to ptrace are isolated in this
54 machine-dependent file. */
56 call_ptrace (request
, pid
, addr
, data
)
58 PTRACE_ARG3_TYPE addr
;
61 return ptrace (request
, pid
, addr
, data
);
65 /* For the rest of the file, use an extra level of indirection */
66 /* This lets us breakpoint usefully on call_ptrace. */
67 #define ptrace call_ptrace
73 if (inferior_pid
== 0)
75 ptrace (PT_KILL
, inferior_pid
, (PTRACE_ARG3_TYPE
) 0, 0);
77 target_mourn_inferior ();
80 /* Resume execution of the inferior process.
81 If STEP is nonzero, single-step it.
82 If SIGNAL is nonzero, give it that signal. */
85 child_resume (step
, signal
)
91 /* An address of (PTRACE_ARG3_TYPE) 1 tells ptrace to continue from where
92 it was. (If GDB wanted it to start some other way, we have already
93 written a new PC value to the child.) */
96 ptrace (PT_STEP
, inferior_pid
, (PTRACE_ARG3_TYPE
) 1, signal
);
98 ptrace (PT_CONTINUE
, inferior_pid
, (PTRACE_ARG3_TYPE
) 1, signal
);
101 perror_with_name ("ptrace");
105 /* Nonzero if we are debugging an attached process rather than
107 extern int attach_flag
;
109 /* Start debugging the process whose number is PID. */
115 ptrace (PT_ATTACH
, pid
, (PTRACE_ARG3_TYPE
) 0, 0);
117 perror_with_name ("ptrace");
122 /* Stop debugging the process whose number is PID
123 and continue it with signal number SIGNAL.
124 SIGNAL = 0 means just continue it. */
131 ptrace (PT_DETACH
, inferior_pid
, (PTRACE_ARG3_TYPE
) 1, signal
);
133 perror_with_name ("ptrace");
136 #endif /* ATTACH_DETACH */
138 #if !defined (FETCH_INFERIOR_REGISTERS)
140 /* KERNEL_U_ADDR is the amount to subtract from u.u_ar0
141 to get the offset in the core file of the register values. */
142 #if defined (KERNEL_U_ADDR_BSD)
143 /* Get kernel_u_addr using BSD-style nlist(). */
144 CORE_ADDR kernel_u_addr
;
146 #include <a.out.gnu.h> /* For struct nlist */
149 _initialize_kernel_u_addr ()
151 struct nlist names
[2];
153 names
[0].n_un
.n_name
= "_u";
154 names
[1].n_un
.n_name
= NULL
;
155 if (nlist ("/vmunix", names
) == 0)
156 kernel_u_addr
= names
[0].n_value
;
158 fatal ("Unable to get kernel u area address.");
160 #endif /* KERNEL_U_ADDR_BSD. */
162 #if defined (KERNEL_U_ADDR_HPUX)
163 /* Get kernel_u_addr using HPUX-style nlist(). */
164 CORE_ADDR kernel_u_addr
;
169 unsigned char n_type
;
170 unsigned char n_length
;
174 static struct hpnlist nl
[] = {{ "_u", -1, }, { (char *) 0, }};
176 /* read the value of the u area from the hp-ux kernel */
177 void _initialize_kernel_u_addr ()
180 nlist ("/hp-ux", &nl
);
181 kernel_u_addr
= nl
[0].n_value
;
183 #endif /* KERNEL_U_ADDR_HPUX. */
185 #if !defined (offsetof)
186 #define offsetof(TYPE, MEMBER) ((unsigned long) &((TYPE *)0)->MEMBER)
189 /* U_REGS_OFFSET is the offset of the registers within the u area. */
190 #if !defined (U_REGS_OFFSET)
191 #define U_REGS_OFFSET \
192 ptrace (PT_READ_U, inferior_pid, \
193 (PTRACE_ARG3_TYPE) (offsetof (struct user, u_ar0)), 0) \
197 /* Registers we shouldn't try to fetch. */
198 #if !defined (CANNOT_FETCH_REGISTER)
199 #define CANNOT_FETCH_REGISTER(regno) 0
202 /* Fetch one register. */
205 fetch_register (regno
)
208 register unsigned int regaddr
;
209 char buf
[MAX_REGISTER_RAW_SIZE
];
210 char mess
[128]; /* For messages */
213 /* Offset of registers within the u area. */
216 if (CANNOT_FETCH_REGISTER (regno
))
218 bzero (buf
, REGISTER_RAW_SIZE (regno
)); /* Supply zeroes */
219 supply_register (regno
, buf
);
223 offset
= U_REGS_OFFSET
;
225 regaddr
= register_addr (regno
, offset
);
226 for (i
= 0; i
< REGISTER_RAW_SIZE (regno
); i
+= sizeof (int))
229 *(int *) &buf
[i
] = ptrace (PT_RUREGS
, inferior_pid
,
230 (PTRACE_ARG3_TYPE
) regaddr
, 0);
231 regaddr
+= sizeof (int);
234 sprintf (mess
, "reading register %s (#%d)", reg_names
[regno
], regno
);
235 perror_with_name (mess
);
238 supply_register (regno
, buf
);
242 /* Fetch all registers, or just one, from the child process. */
245 fetch_inferior_registers (regno
)
249 for (regno
= 0; regno
< NUM_REGS
; regno
++)
250 fetch_register (regno
);
252 fetch_register (regno
);
255 /* Registers we shouldn't try to store. */
256 #if !defined (CANNOT_STORE_REGISTER)
257 #define CANNOT_STORE_REGISTER(regno) 0
260 /* Store our register values back into the inferior.
261 If REGNO is -1, do this for all registers.
262 Otherwise, REGNO specifies which register (so we can save time). */
265 store_inferior_registers (regno
)
268 register unsigned int regaddr
;
270 extern char registers
[];
273 unsigned int offset
= U_REGS_OFFSET
;
277 regaddr
= register_addr (regno
, offset
);
278 for (i
= 0; i
< REGISTER_RAW_SIZE (regno
); i
+= sizeof(int))
281 ptrace (PT_WRITE_U
, inferior_pid
, (PTRACE_ARG3_TYPE
) regaddr
,
282 *(int *) ®isters
[REGISTER_BYTE (regno
) + i
]);
285 sprintf (buf
, "writing register number %d(%d)", regno
, i
);
286 perror_with_name (buf
);
288 regaddr
+= sizeof(int);
293 for (regno
= 0; regno
< NUM_REGS
; regno
++)
295 if (CANNOT_STORE_REGISTER (regno
))
297 regaddr
= register_addr (regno
, offset
);
298 for (i
= 0; i
< REGISTER_RAW_SIZE (regno
); i
+= sizeof(int))
301 ptrace (PT_WRITE_U
, inferior_pid
, (PTRACE_ARG3_TYPE
) regaddr
,
302 *(int *) ®isters
[REGISTER_BYTE (regno
) + i
]);
305 sprintf (buf
, "writing register number %d(%d)", regno
, i
);
306 perror_with_name (buf
);
308 regaddr
+= sizeof(int);
314 #endif /* !defined (FETCH_INFERIOR_REGISTERS). */
316 /* NOTE! I tried using PTRACE_READDATA, etc., to read and write memory
317 in the NEW_SUN_PTRACE case.
318 It ought to be straightforward. But it appears that writing did
319 not write the data that I specified. I cannot understand where
320 it got the data that it actually did write. */
322 /* Copy LEN bytes to or from inferior's memory starting at MEMADDR
323 to debugger memory starting at MYADDR. Copy to inferior if
326 Returns the length copied, which is either the LEN argument or zero.
327 This xfer function does not do partial moves, since child_ops
328 doesn't allow memory operations to cross below us in the target stack
332 child_xfer_memory (memaddr
, myaddr
, len
, write
, target
)
337 struct target_ops
*target
; /* ignored */
340 /* Round starting address down to longword boundary. */
341 register CORE_ADDR addr
= memaddr
& - sizeof (int);
342 /* Round ending address up; get number of longwords that makes. */
344 = (((memaddr
+ len
) - addr
) + sizeof (int) - 1) / sizeof (int);
345 /* Allocate buffer of that many longwords. */
346 register int *buffer
= (int *) alloca (count
* sizeof (int));
350 /* Fill start and end extra bytes of buffer with existing memory data. */
352 if (addr
!= memaddr
|| len
< (int)sizeof (int)) {
353 /* Need part of initial word -- fetch it. */
354 buffer
[0] = ptrace (PT_READ_I
, inferior_pid
, (PTRACE_ARG3_TYPE
) addr
,
358 if (count
> 1) /* FIXME, avoid if even boundary */
361 = ptrace (PT_READ_I
, inferior_pid
,
362 (PTRACE_ARG3_TYPE
) (addr
+ (count
- 1) * sizeof (int)),
366 /* Copy data to be written over corresponding part of buffer */
368 bcopy (myaddr
, (char *) buffer
+ (memaddr
& (sizeof (int) - 1)), len
);
370 /* Write the entire buffer. */
372 for (i
= 0; i
< count
; i
++, addr
+= sizeof (int))
375 ptrace (PT_WRITE_D
, inferior_pid
, (PTRACE_ARG3_TYPE
) addr
,
379 /* Using the appropriate one (I or D) is necessary for
380 Gould NP1, at least. */
382 ptrace (PT_WRITE_I
, inferior_pid
, (PTRACE_ARG3_TYPE
) addr
,
391 /* Read all the longwords */
392 for (i
= 0; i
< count
; i
++, addr
+= sizeof (int))
395 buffer
[i
] = ptrace (PT_READ_I
, inferior_pid
,
396 (PTRACE_ARG3_TYPE
) addr
, 0);
402 /* Copy appropriate bytes out of the buffer. */
403 bcopy ((char *) buffer
+ (memaddr
& (sizeof (int) - 1)), myaddr
, len
);
This page took 0.038205 seconds and 5 git commands to generate.