752b370f40d53e24b9de406ad5025b443bf5c779
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 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. */
29 #define PT_ATTACH PTRACE_ATTACH
32 #define PT_DETACH PTRACE_DETACH
35 /* This function simply calls ptrace with the given arguments.
36 It exists so that all calls to ptrace are isolated in this
37 machine-dependent file. */
38 #ifdef WANT_NATIVE_TARGET
40 call_ptrace (request
, pid
, addr
, data
)
42 PTRACE_ARG3_TYPE addr
;
45 return ptrace (request
, pid
, addr
, data
);
47 #endif /* WANT_NATIVE_TARGET */
50 /* For the rest of the file, use an extra level of indirection */
51 /* This lets us breakpoint usefully on call_ptrace. */
52 #define ptrace call_ptrace
58 if (inferior_pid
== 0)
60 ptrace (PT_KILL
, inferior_pid
, (PTRACE_ARG3_TYPE
) 0, 0);
62 target_mourn_inferior ();
66 /* Nonzero if we are debugging an attached process rather than
68 extern int attach_flag
;
70 /* Start debugging the process whose number is PID. */
76 ptrace (PT_ATTACH
, pid
, (PTRACE_ARG3_TYPE
) 0, 0);
78 perror_with_name ("ptrace");
83 /* Stop debugging the process whose number is PID
84 and continue it with signal number SIGNAL.
85 SIGNAL = 0 means just continue it. */
92 ptrace (PT_DETACH
, inferior_pid
, (PTRACE_ARG3_TYPE
) 1, signal
);
94 perror_with_name ("ptrace");
97 #endif /* ATTACH_DETACH */
101 #if !defined (FETCH_INFERIOR_REGISTERS)
103 /* KERNEL_U_ADDR is the amount to subtract from u.u_ar0
104 to get the offset in the core file of the register values. */
105 #if defined (KERNEL_U_ADDR_BSD)
106 /* Get kernel_u_addr using BSD-style nlist(). */
107 CORE_ADDR kernel_u_addr
;
109 #include <a.out.gnu.h> /* For struct nlist */
112 _initialize_kernel_u_addr ()
114 struct nlist names
[2];
116 names
[0].n_un
.n_name
= "_u";
117 names
[1].n_un
.n_name
= NULL
;
118 if (nlist ("/vmunix", names
) == 0)
119 kernel_u_addr
= names
[0].n_value
;
121 fatal ("Unable to get kernel u area address.");
123 #endif /* KERNEL_U_ADDR_BSD. */
125 #if defined (KERNEL_U_ADDR_HPUX)
126 /* Get kernel_u_addr using HPUX-style nlist(). */
127 CORE_ADDR kernel_u_addr
;
132 unsigned char n_type
;
133 unsigned char n_length
;
137 static struct hpnlist nl
[] = {{ "_u", -1, }, { (char *) 0, }};
139 /* read the value of the u area from the hp-ux kernel */
140 void _initialize_kernel_u_addr ()
143 nlist ("/hp-ux", &nl
);
144 kernel_u_addr
= nl
[0].n_value
;
146 #endif /* KERNEL_U_ADDR_HPUX. */
148 #if !defined (offsetof)
149 #define offsetof(TYPE, MEMBER) ((unsigned long) &((TYPE *)0)->MEMBER)
152 /* U_REGS_OFFSET is the offset of the registers within the u area. */
153 #if !defined (U_REGS_OFFSET)
154 #define U_REGS_OFFSET \
155 ptrace (PT_READ_U, inferior_pid, \
156 (PTRACE_ARG3_TYPE) (offsetof (struct user, u_ar0)), 0) \
160 /* Registers we shouldn't try to fetch. */
161 #if !defined (CANNOT_FETCH_REGISTER)
162 #define CANNOT_FETCH_REGISTER(regno) 0
165 /* Fetch one register. */
168 fetch_register (regno
)
171 register unsigned int regaddr
;
172 char buf
[MAX_REGISTER_RAW_SIZE
];
173 char mess
[128]; /* For messages */
176 /* Offset of registers within the u area. */
179 if (CANNOT_FETCH_REGISTER (regno
))
181 bzero (buf
, REGISTER_RAW_SIZE (regno
)); /* Supply zeroes */
182 supply_register (regno
, buf
);
186 offset
= U_REGS_OFFSET
;
188 regaddr
= register_addr (regno
, offset
);
189 for (i
= 0; i
< REGISTER_RAW_SIZE (regno
); i
+= sizeof (int))
192 *(int *) &buf
[i
] = ptrace (PT_RUREGS
, inferior_pid
,
193 (PTRACE_ARG3_TYPE
) regaddr
, 0);
194 regaddr
+= sizeof (int);
197 sprintf (mess
, "reading register %s (#%d)", reg_names
[regno
], regno
);
198 perror_with_name (mess
);
201 supply_register (regno
, buf
);
204 #endif /* !defined (FETCH_INFERIOR_REGISTERS). */
205 /* Fetch all registers, or just one, from the child process. */
207 #ifndef FETCH_INFERIOR_REGISTERS
209 fetch_inferior_registers (regno
)
213 for (regno
= 0; regno
< NUM_REGS
; regno
++)
214 fetch_register (regno
);
216 fetch_register (regno
);
219 /* Registers we shouldn't try to store. */
220 #if !defined (CANNOT_STORE_REGISTER)
221 #define CANNOT_STORE_REGISTER(regno) 0
224 /* Store our register values back into the inferior.
225 If REGNO is -1, do this for all registers.
226 Otherwise, REGNO specifies which register (so we can save time). */
229 store_inferior_registers (regno
)
232 register unsigned int regaddr
;
234 extern char registers
[];
237 unsigned int offset
= U_REGS_OFFSET
;
241 regaddr
= register_addr (regno
, offset
);
242 for (i
= 0; i
< REGISTER_RAW_SIZE (regno
); i
+= sizeof(int))
245 ptrace (PT_WRITE_U
, inferior_pid
, (PTRACE_ARG3_TYPE
) regaddr
,
246 *(int *) ®isters
[REGISTER_BYTE (regno
) + i
]);
249 sprintf (buf
, "writing register number %d(%d)", regno
, i
);
250 perror_with_name (buf
);
252 regaddr
+= sizeof(int);
257 for (regno
= 0; regno
< NUM_REGS
; regno
++)
259 if (CANNOT_STORE_REGISTER (regno
))
261 regaddr
= register_addr (regno
, offset
);
262 for (i
= 0; i
< REGISTER_RAW_SIZE (regno
); i
+= sizeof(int))
265 ptrace (PT_WRITE_U
, inferior_pid
, (PTRACE_ARG3_TYPE
) regaddr
,
266 *(int *) ®isters
[REGISTER_BYTE (regno
) + i
]);
269 sprintf (buf
, "writing register number %d(%d)", regno
, i
);
270 perror_with_name (buf
);
272 regaddr
+= sizeof(int);
278 #endif /* !defined(FETCH_INFERIOR_REGISTERS) */
280 /* Resume execution of the inferior process.
281 If STEP is nonzero, single-step it.
282 If SIGNAL is nonzero, give it that signal. */
285 child_resume (step
, signal
)
291 /* An address of (PTRACE_ARG3_TYPE) 1 tells ptrace to continue from where
292 it was. (If GDB wanted it to start some other way, we have already
293 written a new PC value to the child.) */
296 ptrace (PT_STEP
, inferior_pid
, (PTRACE_ARG3_TYPE
) 1, signal
);
298 ptrace (PT_CONTINUE
, inferior_pid
, (PTRACE_ARG3_TYPE
) 1, signal
);
301 perror_with_name ("ptrace");
304 /* NOTE! I tried using PTRACE_READDATA, etc., to read and write memory
305 in the NEW_SUN_PTRACE case.
306 It ought to be straightforward. But it appears that writing did
307 not write the data that I specified. I cannot understand where
308 it got the data that it actually did write. */
310 /* Copy LEN bytes to or from inferior's memory starting at MEMADDR
311 to debugger memory starting at MYADDR. Copy to inferior if
314 Returns the length copied, which is either the LEN argument or zero.
315 This xfer function does not do partial moves, since child_ops
316 doesn't allow memory operations to cross below us in the target stack
320 child_xfer_memory (memaddr
, myaddr
, len
, write
, target
)
325 struct target_ops
*target
; /* ignored */
328 /* Round starting address down to longword boundary. */
329 register CORE_ADDR addr
= memaddr
& - sizeof (int);
330 /* Round ending address up; get number of longwords that makes. */
332 = (((memaddr
+ len
) - addr
) + sizeof (int) - 1) / sizeof (int);
333 /* Allocate buffer of that many longwords. */
334 register int *buffer
= (int *) alloca (count
* sizeof (int));
338 /* Fill start and end extra bytes of buffer with existing memory data. */
340 if (addr
!= memaddr
|| len
< (int)sizeof (int)) {
341 /* Need part of initial word -- fetch it. */
342 buffer
[0] = ptrace (PT_READ_I
, inferior_pid
, (PTRACE_ARG3_TYPE
) addr
,
346 if (count
> 1) /* FIXME, avoid if even boundary */
349 = ptrace (PT_READ_I
, inferior_pid
,
350 (PTRACE_ARG3_TYPE
) (addr
+ (count
- 1) * sizeof (int)),
354 /* Copy data to be written over corresponding part of buffer */
356 bcopy (myaddr
, (char *) buffer
+ (memaddr
& (sizeof (int) - 1)), len
);
358 /* Write the entire buffer. */
360 for (i
= 0; i
< count
; i
++, addr
+= sizeof (int))
363 ptrace (PT_WRITE_D
, inferior_pid
, (PTRACE_ARG3_TYPE
) addr
,
367 /* Using the appropriate one (I or D) is necessary for
368 Gould NP1, at least. */
370 ptrace (PT_WRITE_I
, inferior_pid
, (PTRACE_ARG3_TYPE
) addr
,
379 /* Read all the longwords */
380 for (i
= 0; i
< count
; i
++, addr
+= sizeof (int))
383 buffer
[i
] = ptrace (PT_READ_I
, inferior_pid
,
384 (PTRACE_ARG3_TYPE
) addr
, 0);
390 /* Copy appropriate bytes out of the buffer. */
391 bcopy ((char *) buffer
+ (memaddr
& (sizeof (int) - 1)), myaddr
, len
);
This page took 0.059897 seconds and 4 git commands to generate.