c0c49b8c204962685683bc9223a416b91a6ec0c9
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 ();
67 /* Start debugging the process whose number is PID. */
73 ptrace (PT_ATTACH
, pid
, (PTRACE_ARG3_TYPE
) 0, 0);
75 perror_with_name ("ptrace");
80 /* Stop debugging the process whose number is PID
81 and continue it with signal number SIGNAL.
82 SIGNAL = 0 means just continue it. */
89 ptrace (PT_DETACH
, inferior_pid
, (PTRACE_ARG3_TYPE
) 1, signal
);
91 perror_with_name ("ptrace");
94 #endif /* ATTACH_DETACH */
98 #if !defined (FETCH_INFERIOR_REGISTERS)
100 /* KERNEL_U_ADDR is the amount to subtract from u.u_ar0
101 to get the offset in the core file of the register values. */
102 #if defined (KERNEL_U_ADDR_BSD)
103 /* Get kernel_u_addr using BSD-style nlist(). */
104 CORE_ADDR kernel_u_addr
;
106 #include <a.out.gnu.h> /* For struct nlist */
109 _initialize_kernel_u_addr ()
111 struct nlist names
[2];
113 names
[0].n_un
.n_name
= "_u";
114 names
[1].n_un
.n_name
= NULL
;
115 if (nlist ("/vmunix", names
) == 0)
116 kernel_u_addr
= names
[0].n_value
;
118 fatal ("Unable to get kernel u area address.");
120 #endif /* KERNEL_U_ADDR_BSD. */
122 #if defined (KERNEL_U_ADDR_HPUX)
123 /* Get kernel_u_addr using HPUX-style nlist(). */
124 CORE_ADDR kernel_u_addr
;
129 unsigned char n_type
;
130 unsigned char n_length
;
134 static struct hpnlist nl
[] = {{ "_u", -1, }, { (char *) 0, }};
136 /* read the value of the u area from the hp-ux kernel */
137 void _initialize_kernel_u_addr ()
140 nlist ("/hp-ux", &nl
);
141 kernel_u_addr
= nl
[0].n_value
;
143 #endif /* KERNEL_U_ADDR_HPUX. */
145 #if !defined (offsetof)
146 #define offsetof(TYPE, MEMBER) ((unsigned long) &((TYPE *)0)->MEMBER)
149 /* U_REGS_OFFSET is the offset of the registers within the u area. */
150 #if !defined (U_REGS_OFFSET)
151 #define U_REGS_OFFSET \
152 ptrace (PT_READ_U, inferior_pid, \
153 (PTRACE_ARG3_TYPE) (offsetof (struct user, u_ar0)), 0) \
157 /* Registers we shouldn't try to fetch. */
158 #if !defined (CANNOT_FETCH_REGISTER)
159 #define CANNOT_FETCH_REGISTER(regno) 0
162 /* Fetch one register. */
165 fetch_register (regno
)
168 register unsigned int regaddr
;
169 char buf
[MAX_REGISTER_RAW_SIZE
];
170 char mess
[128]; /* For messages */
173 /* Offset of registers within the u area. */
176 if (CANNOT_FETCH_REGISTER (regno
))
178 bzero (buf
, REGISTER_RAW_SIZE (regno
)); /* Supply zeroes */
179 supply_register (regno
, buf
);
183 offset
= U_REGS_OFFSET
;
185 regaddr
= register_addr (regno
, offset
);
186 for (i
= 0; i
< REGISTER_RAW_SIZE (regno
); i
+= sizeof (int))
189 *(int *) &buf
[i
] = ptrace (PT_RUREGS
, inferior_pid
,
190 (PTRACE_ARG3_TYPE
) regaddr
, 0);
191 regaddr
+= sizeof (int);
194 sprintf (mess
, "reading register %s (#%d)", reg_names
[regno
], regno
);
195 perror_with_name (mess
);
198 supply_register (regno
, buf
);
201 #endif /* !defined (FETCH_INFERIOR_REGISTERS). */
202 /* Fetch all registers, or just one, from the child process. */
204 #ifndef FETCH_INFERIOR_REGISTERS
206 fetch_inferior_registers (regno
)
210 for (regno
= 0; regno
< NUM_REGS
; regno
++)
211 fetch_register (regno
);
213 fetch_register (regno
);
216 /* Registers we shouldn't try to store. */
217 #if !defined (CANNOT_STORE_REGISTER)
218 #define CANNOT_STORE_REGISTER(regno) 0
221 /* Store our register values back into the inferior.
222 If REGNO is -1, do this for all registers.
223 Otherwise, REGNO specifies which register (so we can save time). */
226 store_inferior_registers (regno
)
229 register unsigned int regaddr
;
231 extern char registers
[];
234 unsigned int offset
= U_REGS_OFFSET
;
238 regaddr
= register_addr (regno
, offset
);
239 for (i
= 0; i
< REGISTER_RAW_SIZE (regno
); i
+= sizeof(int))
242 ptrace (PT_WRITE_U
, inferior_pid
, (PTRACE_ARG3_TYPE
) regaddr
,
243 *(int *) ®isters
[REGISTER_BYTE (regno
) + i
]);
246 sprintf (buf
, "writing register number %d(%d)", regno
, i
);
247 perror_with_name (buf
);
249 regaddr
+= sizeof(int);
254 for (regno
= 0; regno
< NUM_REGS
; regno
++)
256 if (CANNOT_STORE_REGISTER (regno
))
258 regaddr
= register_addr (regno
, offset
);
259 for (i
= 0; i
< REGISTER_RAW_SIZE (regno
); i
+= sizeof(int))
262 ptrace (PT_WRITE_U
, inferior_pid
, (PTRACE_ARG3_TYPE
) regaddr
,
263 *(int *) ®isters
[REGISTER_BYTE (regno
) + i
]);
266 sprintf (buf
, "writing register number %d(%d)", regno
, i
);
267 perror_with_name (buf
);
269 regaddr
+= sizeof(int);
275 #endif /* !defined(FETCH_INFERIOR_REGISTERS) */
277 /* Resume execution of the inferior process.
278 If STEP is nonzero, single-step it.
279 If SIGNAL is nonzero, give it that signal. */
282 child_resume (step
, signal
)
288 /* An address of (PTRACE_ARG3_TYPE) 1 tells ptrace to continue from where
289 it was. (If GDB wanted it to start some other way, we have already
290 written a new PC value to the child.) */
293 ptrace (PT_STEP
, inferior_pid
, (PTRACE_ARG3_TYPE
) 1, signal
);
295 ptrace (PT_CONTINUE
, inferior_pid
, (PTRACE_ARG3_TYPE
) 1, signal
);
298 perror_with_name ("ptrace");
301 /* NOTE! I tried using PTRACE_READDATA, etc., to read and write memory
302 in the NEW_SUN_PTRACE case.
303 It ought to be straightforward. But it appears that writing did
304 not write the data that I specified. I cannot understand where
305 it got the data that it actually did write. */
307 /* Copy LEN bytes to or from inferior's memory starting at MEMADDR
308 to debugger memory starting at MYADDR. Copy to inferior if
311 Returns the length copied, which is either the LEN argument or zero.
312 This xfer function does not do partial moves, since child_ops
313 doesn't allow memory operations to cross below us in the target stack
317 child_xfer_memory (memaddr
, myaddr
, len
, write
, target
)
322 struct target_ops
*target
; /* ignored */
325 /* Round starting address down to longword boundary. */
326 register CORE_ADDR addr
= memaddr
& - sizeof (int);
327 /* Round ending address up; get number of longwords that makes. */
329 = (((memaddr
+ len
) - addr
) + sizeof (int) - 1) / sizeof (int);
330 /* Allocate buffer of that many longwords. */
331 register int *buffer
= (int *) alloca (count
* sizeof (int));
335 /* Fill start and end extra bytes of buffer with existing memory data. */
337 if (addr
!= memaddr
|| len
< (int)sizeof (int)) {
338 /* Need part of initial word -- fetch it. */
339 buffer
[0] = ptrace (PT_READ_I
, inferior_pid
, (PTRACE_ARG3_TYPE
) addr
,
343 if (count
> 1) /* FIXME, avoid if even boundary */
346 = ptrace (PT_READ_I
, inferior_pid
,
347 (PTRACE_ARG3_TYPE
) (addr
+ (count
- 1) * sizeof (int)),
351 /* Copy data to be written over corresponding part of buffer */
353 bcopy (myaddr
, (char *) buffer
+ (memaddr
& (sizeof (int) - 1)), len
);
355 /* Write the entire buffer. */
357 for (i
= 0; i
< count
; i
++, addr
+= sizeof (int))
360 ptrace (PT_WRITE_D
, inferior_pid
, (PTRACE_ARG3_TYPE
) addr
,
364 /* Using the appropriate one (I or D) is necessary for
365 Gould NP1, at least. */
367 ptrace (PT_WRITE_I
, inferior_pid
, (PTRACE_ARG3_TYPE
) addr
,
376 /* Read all the longwords */
377 for (i
= 0; i
< count
; i
++, addr
+= sizeof (int))
380 buffer
[i
] = ptrace (PT_READ_I
, inferior_pid
,
381 (PTRACE_ARG3_TYPE
) addr
, 0);
387 /* Copy appropriate bytes out of the buffer. */
388 bcopy ((char *) buffer
+ (memaddr
& (sizeof (int) - 1)), myaddr
, len
);
This page took 0.036649 seconds and 4 git commands to generate.