Commit | Line | Data |
---|---|---|
c906108c | 1 | /* Low level Unix child interface to ptrace, for GDB when running under Unix. |
b6ba6518 KB |
2 | Copyright 1988, 1989, 1990, 1991, 1992, 1993, 1994, 1995, 1996, 1998, |
3 | 1999, 2000, 2001 | |
c906108c SS |
4 | Free Software Foundation, Inc. |
5 | ||
c5aa993b | 6 | This file is part of GDB. |
c906108c | 7 | |
c5aa993b JM |
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. | |
c906108c | 12 | |
c5aa993b JM |
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. | |
c906108c | 17 | |
c5aa993b JM |
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., 59 Temple Place - Suite 330, | |
21 | Boston, MA 02111-1307, USA. */ | |
c906108c SS |
22 | |
23 | #include "defs.h" | |
24 | #include "frame.h" | |
25 | #include "inferior.h" | |
26 | #include "target.h" | |
27 | #include "gdb_string.h" | |
4e052eda | 28 | #include "regcache.h" |
ed9a39eb | 29 | |
03f2053f | 30 | #include "gdb_wait.h" |
ed9a39eb | 31 | |
c906108c SS |
32 | #include "command.h" |
33 | ||
34 | #ifdef USG | |
35 | #include <sys/types.h> | |
36 | #endif | |
37 | ||
38 | #include <sys/param.h> | |
4b14d3e4 | 39 | #include "gdb_dirent.h" |
c906108c SS |
40 | #include <signal.h> |
41 | #include <sys/ioctl.h> | |
42 | ||
43 | #ifdef HAVE_PTRACE_H | |
c5aa993b | 44 | #include <ptrace.h> |
c906108c | 45 | #else |
c5aa993b JM |
46 | #ifdef HAVE_SYS_PTRACE_H |
47 | #include <sys/ptrace.h> | |
48 | #endif | |
c906108c SS |
49 | #endif |
50 | ||
51 | #if !defined (PT_READ_I) | |
52 | #define PT_READ_I 1 /* Read word from text space */ | |
53 | #endif | |
54 | #if !defined (PT_READ_D) | |
55 | #define PT_READ_D 2 /* Read word from data space */ | |
56 | #endif | |
57 | #if !defined (PT_READ_U) | |
58 | #define PT_READ_U 3 /* Read word from kernel user struct */ | |
59 | #endif | |
60 | #if !defined (PT_WRITE_I) | |
61 | #define PT_WRITE_I 4 /* Write word to text space */ | |
62 | #endif | |
63 | #if !defined (PT_WRITE_D) | |
64 | #define PT_WRITE_D 5 /* Write word to data space */ | |
65 | #endif | |
66 | #if !defined (PT_WRITE_U) | |
67 | #define PT_WRITE_U 6 /* Write word to kernel user struct */ | |
68 | #endif | |
69 | #if !defined (PT_CONTINUE) | |
70 | #define PT_CONTINUE 7 /* Continue after signal */ | |
71 | #endif | |
72 | #if !defined (PT_STEP) | |
73 | #define PT_STEP 9 /* Set flag for single stepping */ | |
74 | #endif | |
75 | #if !defined (PT_KILL) | |
76 | #define PT_KILL 8 /* Send child a SIGKILL signal */ | |
77 | #endif | |
78 | ||
79 | #ifndef PT_ATTACH | |
80 | #define PT_ATTACH PTRACE_ATTACH | |
81 | #endif | |
82 | #ifndef PT_DETACH | |
83 | #define PT_DETACH PTRACE_DETACH | |
84 | #endif | |
85 | ||
86 | #include "gdbcore.h" | |
87 | #ifndef NO_SYS_FILE | |
88 | #include <sys/file.h> | |
89 | #endif | |
90 | #if 0 | |
91 | /* Don't think this is used anymore. On the sequent (not sure whether it's | |
92 | dynix or ptx or both), it is included unconditionally by sys/user.h and | |
93 | not protected against multiple inclusion. */ | |
94 | #include "gdb_stat.h" | |
95 | #endif | |
96 | ||
97 | #if !defined (FETCH_INFERIOR_REGISTERS) | |
98 | #include <sys/user.h> /* Probably need to poke the user structure */ | |
99 | #if defined (KERNEL_U_ADDR_BSD) | |
100 | #include <a.out.h> /* For struct nlist */ | |
101 | #endif /* KERNEL_U_ADDR_BSD. */ | |
102 | #endif /* !FETCH_INFERIOR_REGISTERS */ | |
103 | ||
104 | #if !defined (CHILD_XFER_MEMORY) | |
a14ed312 | 105 | static void udot_info (char *, int); |
c906108c SS |
106 | #endif |
107 | ||
108 | #if !defined (FETCH_INFERIOR_REGISTERS) | |
a14ed312 KB |
109 | static void fetch_register (int); |
110 | static void store_register (int); | |
c906108c SS |
111 | #endif |
112 | ||
a14ed312 KB |
113 | void _initialize_kernel_u_addr (void); |
114 | void _initialize_infptrace (void); | |
c906108c | 115 | \f |
c5aa993b | 116 | |
c906108c SS |
117 | /* This function simply calls ptrace with the given arguments. |
118 | It exists so that all calls to ptrace are isolated in this | |
119 | machine-dependent file. */ | |
120 | int | |
fba45db2 | 121 | call_ptrace (int request, int pid, PTRACE_ARG3_TYPE addr, int data) |
c906108c SS |
122 | { |
123 | int pt_status = 0; | |
124 | ||
125 | #if 0 | |
126 | int saved_errno; | |
127 | ||
128 | printf ("call_ptrace(request=%d, pid=%d, addr=0x%x, data=0x%x)", | |
129 | request, pid, addr, data); | |
130 | #endif | |
131 | #if defined(PT_SETTRC) | |
132 | /* If the parent can be told to attach to us, try to do it. */ | |
c5aa993b JM |
133 | if (request == PT_SETTRC) |
134 | { | |
135 | errno = 0; | |
ed9a39eb JM |
136 | #if !defined (FIVE_ARG_PTRACE) |
137 | pt_status = ptrace (PT_SETTRC, pid, addr, data); | |
138 | #else | |
c5aa993b JM |
139 | /* Deal with HPUX 8.0 braindamage. We never use the |
140 | calls which require the fifth argument. */ | |
ed9a39eb | 141 | pt_status = ptrace (PT_SETTRC, pid, addr, data, 0); |
c906108c | 142 | #endif |
c5aa993b JM |
143 | if (errno) |
144 | perror_with_name ("ptrace"); | |
c906108c | 145 | #if 0 |
c5aa993b | 146 | printf (" = %d\n", pt_status); |
c906108c | 147 | #endif |
c5aa993b JM |
148 | if (pt_status < 0) |
149 | return pt_status; | |
150 | else | |
151 | return parent_attach_all (pid, addr, data); | |
152 | } | |
c906108c SS |
153 | #endif |
154 | ||
155 | #if defined(PT_CONTIN1) | |
156 | /* On HPUX, PT_CONTIN1 is a form of continue that preserves pending | |
157 | signals. If it's available, use it. */ | |
158 | if (request == PT_CONTINUE) | |
159 | request = PT_CONTIN1; | |
160 | #endif | |
161 | ||
162 | #if defined(PT_SINGLE1) | |
163 | /* On HPUX, PT_SINGLE1 is a form of step that preserves pending | |
164 | signals. If it's available, use it. */ | |
165 | if (request == PT_STEP) | |
166 | request = PT_SINGLE1; | |
167 | #endif | |
168 | ||
169 | #if 0 | |
170 | saved_errno = errno; | |
171 | errno = 0; | |
172 | #endif | |
ed9a39eb JM |
173 | #if !defined (FIVE_ARG_PTRACE) |
174 | pt_status = ptrace (request, pid, addr, data); | |
175 | #else | |
c5aa993b JM |
176 | /* Deal with HPUX 8.0 braindamage. We never use the |
177 | calls which require the fifth argument. */ | |
ed9a39eb | 178 | pt_status = ptrace (request, pid, addr, data, 0); |
c906108c | 179 | #endif |
ed9a39eb | 180 | |
c906108c SS |
181 | #if 0 |
182 | if (errno) | |
183 | printf (" [errno = %d]", errno); | |
184 | ||
185 | errno = saved_errno; | |
186 | printf (" = 0x%x\n", pt_status); | |
187 | #endif | |
188 | return pt_status; | |
189 | } | |
190 | ||
191 | ||
192 | #if defined (DEBUG_PTRACE) || defined (FIVE_ARG_PTRACE) | |
193 | /* For the rest of the file, use an extra level of indirection */ | |
194 | /* This lets us breakpoint usefully on call_ptrace. */ | |
195 | #define ptrace call_ptrace | |
196 | #endif | |
197 | ||
198 | /* Wait for a process to finish, possibly running a target-specific | |
199 | hook before returning. */ | |
200 | ||
201 | int | |
39f77062 | 202 | ptrace_wait (ptid_t ptid, int *status) |
c906108c SS |
203 | { |
204 | int wstate; | |
205 | ||
206 | wstate = wait (status); | |
39f77062 | 207 | target_post_wait (pid_to_ptid (wstate), *status); |
c906108c SS |
208 | return wstate; |
209 | } | |
210 | ||
211 | void | |
fba45db2 | 212 | kill_inferior (void) |
c906108c SS |
213 | { |
214 | int status; | |
39f77062 | 215 | int pid = PIDGET (inferior_ptid); |
c906108c | 216 | |
39f77062 | 217 | if (pid == 0) |
c906108c SS |
218 | return; |
219 | ||
220 | /* This once used to call "kill" to kill the inferior just in case | |
221 | the inferior was still running. As others have noted in the past | |
222 | (kingdon) there shouldn't be any way to get here if the inferior | |
223 | is still running -- else there's a major problem elsewere in gdb | |
224 | and it needs to be fixed. | |
225 | ||
226 | The kill call causes problems under hpux10, so it's been removed; | |
227 | if this causes problems we'll deal with them as they arise. */ | |
39f77062 KB |
228 | ptrace (PT_KILL, pid, (PTRACE_ARG3_TYPE) 0, 0); |
229 | ptrace_wait (null_ptid, &status); | |
c906108c SS |
230 | target_mourn_inferior (); |
231 | } | |
232 | ||
233 | #ifndef CHILD_RESUME | |
234 | ||
235 | /* Resume execution of the inferior process. | |
236 | If STEP is nonzero, single-step it. | |
237 | If SIGNAL is nonzero, give it that signal. */ | |
238 | ||
239 | void | |
39f77062 | 240 | child_resume (ptid_t ptid, int step, enum target_signal signal) |
c906108c | 241 | { |
39f77062 KB |
242 | int pid = PIDGET (ptid); |
243 | ||
c906108c SS |
244 | errno = 0; |
245 | ||
246 | if (pid == -1) | |
247 | /* Resume all threads. */ | |
248 | /* I think this only gets used in the non-threaded case, where "resume | |
39f77062 KB |
249 | all threads" and "resume inferior_ptid" are the same. */ |
250 | pid = PIDGET (inferior_ptid); | |
c906108c SS |
251 | |
252 | /* An address of (PTRACE_ARG3_TYPE)1 tells ptrace to continue from where | |
253 | it was. (If GDB wanted it to start some other way, we have already | |
254 | written a new PC value to the child.) | |
255 | ||
256 | If this system does not support PT_STEP, a higher level function will | |
257 | have called single_step() to transmute the step request into a | |
258 | continue request (by setting breakpoints on all possible successor | |
259 | instructions), so we don't have to worry about that here. */ | |
260 | ||
261 | if (step) | |
262 | { | |
b0ed3589 | 263 | if (SOFTWARE_SINGLE_STEP_P ()) |
e1e9e218 | 264 | internal_error (__FILE__, __LINE__, "failed internal consistency check"); /* Make sure this doesn't happen. */ |
c906108c | 265 | else |
c5aa993b | 266 | ptrace (PT_STEP, pid, (PTRACE_ARG3_TYPE) 1, |
c906108c SS |
267 | target_signal_to_host (signal)); |
268 | } | |
269 | else | |
270 | ptrace (PT_CONTINUE, pid, (PTRACE_ARG3_TYPE) 1, | |
271 | target_signal_to_host (signal)); | |
272 | ||
273 | if (errno) | |
ed9a39eb JM |
274 | { |
275 | perror_with_name ("ptrace"); | |
276 | } | |
c906108c SS |
277 | } |
278 | #endif /* CHILD_RESUME */ | |
c906108c | 279 | \f |
c5aa993b | 280 | |
c906108c SS |
281 | #ifdef ATTACH_DETACH |
282 | /* Start debugging the process whose number is PID. */ | |
283 | int | |
fba45db2 | 284 | attach (int pid) |
c906108c SS |
285 | { |
286 | errno = 0; | |
287 | ptrace (PT_ATTACH, pid, (PTRACE_ARG3_TYPE) 0, 0); | |
288 | if (errno) | |
289 | perror_with_name ("ptrace"); | |
290 | attach_flag = 1; | |
291 | return pid; | |
292 | } | |
293 | ||
294 | /* Stop debugging the process whose number is PID | |
295 | and continue it with signal number SIGNAL. | |
296 | SIGNAL = 0 means just continue it. */ | |
297 | ||
298 | void | |
fba45db2 | 299 | detach (int signal) |
c906108c SS |
300 | { |
301 | errno = 0; | |
39f77062 KB |
302 | ptrace (PT_DETACH, PIDGET (inferior_ptid), (PTRACE_ARG3_TYPE) 1, |
303 | signal); | |
c906108c SS |
304 | if (errno) |
305 | perror_with_name ("ptrace"); | |
306 | attach_flag = 0; | |
307 | } | |
308 | #endif /* ATTACH_DETACH */ | |
309 | \f | |
310 | /* Default the type of the ptrace transfer to int. */ | |
311 | #ifndef PTRACE_XFER_TYPE | |
312 | #define PTRACE_XFER_TYPE int | |
313 | #endif | |
314 | ||
315 | /* KERNEL_U_ADDR is the amount to subtract from u.u_ar0 | |
316 | to get the offset in the core file of the register values. */ | |
317 | #if defined (KERNEL_U_ADDR_BSD) && !defined (FETCH_INFERIOR_REGISTERS) | |
318 | /* Get kernel_u_addr using BSD-style nlist(). */ | |
319 | CORE_ADDR kernel_u_addr; | |
320 | #endif /* KERNEL_U_ADDR_BSD. */ | |
321 | ||
322 | void | |
fba45db2 | 323 | _initialize_kernel_u_addr (void) |
c906108c SS |
324 | { |
325 | #if defined (KERNEL_U_ADDR_BSD) && !defined (FETCH_INFERIOR_REGISTERS) | |
326 | struct nlist names[2]; | |
327 | ||
328 | names[0].n_un.n_name = "_u"; | |
329 | names[1].n_un.n_name = NULL; | |
330 | if (nlist ("/vmunix", names) == 0) | |
331 | kernel_u_addr = names[0].n_value; | |
332 | else | |
8e65ff28 AC |
333 | internal_error (__FILE__, __LINE__, |
334 | "Unable to get kernel u area address."); | |
c906108c SS |
335 | #endif /* KERNEL_U_ADDR_BSD. */ |
336 | } | |
337 | ||
338 | #if !defined (FETCH_INFERIOR_REGISTERS) | |
339 | ||
340 | #if !defined (offsetof) | |
341 | #define offsetof(TYPE, MEMBER) ((unsigned long) &((TYPE *)0)->MEMBER) | |
342 | #endif | |
343 | ||
344 | /* U_REGS_OFFSET is the offset of the registers within the u area. */ | |
345 | #if !defined (U_REGS_OFFSET) | |
346 | #define U_REGS_OFFSET \ | |
39f77062 | 347 | ptrace (PT_READ_U, PIDGET (inferior_ptid), \ |
c906108c SS |
348 | (PTRACE_ARG3_TYPE) (offsetof (struct user, u_ar0)), 0) \ |
349 | - KERNEL_U_ADDR | |
350 | #endif | |
351 | ||
352 | /* Registers we shouldn't try to fetch. */ | |
353 | #if !defined (CANNOT_FETCH_REGISTER) | |
354 | #define CANNOT_FETCH_REGISTER(regno) 0 | |
355 | #endif | |
356 | ||
357 | /* Fetch one register. */ | |
358 | ||
359 | static void | |
fba45db2 | 360 | fetch_register (int regno) |
c906108c SS |
361 | { |
362 | /* This isn't really an address. But ptrace thinks of it as one. */ | |
363 | CORE_ADDR regaddr; | |
c5aa993b | 364 | char mess[128]; /* For messages */ |
c906108c | 365 | register int i; |
c5aa993b | 366 | unsigned int offset; /* Offset of registers within the u area. */ |
c906108c | 367 | char buf[MAX_REGISTER_RAW_SIZE]; |
ed9a39eb | 368 | int tid; |
c906108c SS |
369 | |
370 | if (CANNOT_FETCH_REGISTER (regno)) | |
371 | { | |
372 | memset (buf, '\0', REGISTER_RAW_SIZE (regno)); /* Supply zeroes */ | |
373 | supply_register (regno, buf); | |
374 | return; | |
375 | } | |
376 | ||
ed9a39eb | 377 | /* Overload thread id onto process id */ |
39f77062 KB |
378 | if ((tid = TIDGET (inferior_ptid)) == 0) |
379 | tid = PIDGET (inferior_ptid); /* no thread id, just use process id */ | |
ed9a39eb | 380 | |
c906108c SS |
381 | offset = U_REGS_OFFSET; |
382 | ||
383 | regaddr = register_addr (regno, offset); | |
384 | for (i = 0; i < REGISTER_RAW_SIZE (regno); i += sizeof (PTRACE_XFER_TYPE)) | |
385 | { | |
386 | errno = 0; | |
ed9a39eb JM |
387 | *(PTRACE_XFER_TYPE *) & buf[i] = ptrace (PT_READ_U, tid, |
388 | (PTRACE_ARG3_TYPE) regaddr, 0); | |
c906108c SS |
389 | regaddr += sizeof (PTRACE_XFER_TYPE); |
390 | if (errno != 0) | |
391 | { | |
ed9a39eb JM |
392 | sprintf (mess, "reading register %s (#%d)", |
393 | REGISTER_NAME (regno), regno); | |
c906108c SS |
394 | perror_with_name (mess); |
395 | } | |
396 | } | |
397 | supply_register (regno, buf); | |
398 | } | |
399 | ||
400 | ||
401 | /* Fetch register values from the inferior. | |
402 | If REGNO is negative, do this for all registers. | |
403 | Otherwise, REGNO specifies which register (so we can save time). */ | |
404 | ||
405 | void | |
fba45db2 | 406 | fetch_inferior_registers (int regno) |
c906108c SS |
407 | { |
408 | if (regno >= 0) | |
409 | { | |
410 | fetch_register (regno); | |
411 | } | |
412 | else | |
413 | { | |
a728f042 | 414 | for (regno = 0; regno < NUM_REGS; regno++) |
c906108c SS |
415 | { |
416 | fetch_register (regno); | |
417 | } | |
418 | } | |
419 | } | |
420 | ||
421 | /* Registers we shouldn't try to store. */ | |
422 | #if !defined (CANNOT_STORE_REGISTER) | |
423 | #define CANNOT_STORE_REGISTER(regno) 0 | |
424 | #endif | |
425 | ||
426 | /* Store one register. */ | |
427 | ||
428 | static void | |
fba45db2 | 429 | store_register (int regno) |
c906108c SS |
430 | { |
431 | /* This isn't really an address. But ptrace thinks of it as one. */ | |
432 | CORE_ADDR regaddr; | |
c5aa993b | 433 | char mess[128]; /* For messages */ |
c906108c | 434 | register int i; |
c5aa993b | 435 | unsigned int offset; /* Offset of registers within the u area. */ |
ed9a39eb | 436 | int tid; |
c906108c SS |
437 | |
438 | if (CANNOT_STORE_REGISTER (regno)) | |
439 | { | |
440 | return; | |
441 | } | |
442 | ||
ed9a39eb | 443 | /* Overload thread id onto process id */ |
39f77062 KB |
444 | if ((tid = TIDGET (inferior_ptid)) == 0) |
445 | tid = PIDGET (inferior_ptid); /* no thread id, just use process id */ | |
ed9a39eb | 446 | |
c906108c SS |
447 | offset = U_REGS_OFFSET; |
448 | ||
449 | regaddr = register_addr (regno, offset); | |
c5aa993b | 450 | for (i = 0; i < REGISTER_RAW_SIZE (regno); i += sizeof (PTRACE_XFER_TYPE)) |
c906108c SS |
451 | { |
452 | errno = 0; | |
ed9a39eb | 453 | ptrace (PT_WRITE_U, tid, (PTRACE_ARG3_TYPE) regaddr, |
c5aa993b | 454 | *(PTRACE_XFER_TYPE *) & registers[REGISTER_BYTE (regno) + i]); |
c906108c SS |
455 | regaddr += sizeof (PTRACE_XFER_TYPE); |
456 | if (errno != 0) | |
457 | { | |
ed9a39eb JM |
458 | sprintf (mess, "writing register %s (#%d)", |
459 | REGISTER_NAME (regno), regno); | |
c906108c SS |
460 | perror_with_name (mess); |
461 | } | |
462 | } | |
463 | } | |
464 | ||
465 | /* Store our register values back into the inferior. | |
466 | If REGNO is negative, do this for all registers. | |
467 | Otherwise, REGNO specifies which register (so we can save time). */ | |
468 | ||
469 | void | |
fba45db2 | 470 | store_inferior_registers (int regno) |
c906108c SS |
471 | { |
472 | if (regno >= 0) | |
473 | { | |
474 | store_register (regno); | |
475 | } | |
476 | else | |
477 | { | |
a728f042 | 478 | for (regno = 0; regno < NUM_REGS; regno++) |
c906108c SS |
479 | { |
480 | store_register (regno); | |
481 | } | |
482 | } | |
483 | } | |
484 | #endif /* !defined (FETCH_INFERIOR_REGISTERS). */ | |
485 | \f | |
486 | ||
487 | #if !defined (CHILD_XFER_MEMORY) | |
488 | /* NOTE! I tried using PTRACE_READDATA, etc., to read and write memory | |
489 | in the NEW_SUN_PTRACE case. | |
490 | It ought to be straightforward. But it appears that writing did | |
491 | not write the data that I specified. I cannot understand where | |
492 | it got the data that it actually did write. */ | |
493 | ||
494 | /* Copy LEN bytes to or from inferior's memory starting at MEMADDR | |
495 | to debugger memory starting at MYADDR. Copy to inferior if | |
73186089 | 496 | WRITE is nonzero. TARGET is ignored. |
c5aa993b | 497 | |
c906108c SS |
498 | Returns the length copied, which is either the LEN argument or zero. |
499 | This xfer function does not do partial moves, since child_ops | |
500 | doesn't allow memory operations to cross below us in the target stack | |
501 | anyway. */ | |
502 | ||
503 | int | |
73186089 | 504 | child_xfer_memory (CORE_ADDR memaddr, char *myaddr, int len, int write, |
29e57380 | 505 | struct mem_attrib *attrib ATTRIBUTE_UNUSED, |
73186089 | 506 | struct target_ops *target) |
c906108c SS |
507 | { |
508 | register int i; | |
509 | /* Round starting address down to longword boundary. */ | |
c5aa993b | 510 | register CORE_ADDR addr = memaddr & -sizeof (PTRACE_XFER_TYPE); |
c906108c SS |
511 | /* Round ending address up; get number of longwords that makes. */ |
512 | register int count | |
c5aa993b JM |
513 | = (((memaddr + len) - addr) + sizeof (PTRACE_XFER_TYPE) - 1) |
514 | / sizeof (PTRACE_XFER_TYPE); | |
c906108c SS |
515 | /* Allocate buffer of that many longwords. */ |
516 | register PTRACE_XFER_TYPE *buffer | |
c5aa993b | 517 | = (PTRACE_XFER_TYPE *) alloca (count * sizeof (PTRACE_XFER_TYPE)); |
c906108c SS |
518 | |
519 | if (write) | |
520 | { | |
521 | /* Fill start and end extra bytes of buffer with existing memory data. */ | |
522 | ||
c5aa993b JM |
523 | if (addr != memaddr || len < (int) sizeof (PTRACE_XFER_TYPE)) |
524 | { | |
525 | /* Need part of initial word -- fetch it. */ | |
39f77062 | 526 | buffer[0] = ptrace (PT_READ_I, PIDGET (inferior_ptid), |
ed9a39eb | 527 | (PTRACE_ARG3_TYPE) addr, 0); |
c5aa993b | 528 | } |
c906108c SS |
529 | |
530 | if (count > 1) /* FIXME, avoid if even boundary */ | |
531 | { | |
ed9a39eb | 532 | buffer[count - 1] |
39f77062 | 533 | = ptrace (PT_READ_I, PIDGET (inferior_ptid), |
c906108c SS |
534 | ((PTRACE_ARG3_TYPE) |
535 | (addr + (count - 1) * sizeof (PTRACE_XFER_TYPE))), | |
536 | 0); | |
537 | } | |
538 | ||
539 | /* Copy data to be written over corresponding part of buffer */ | |
540 | ||
541 | memcpy ((char *) buffer + (memaddr & (sizeof (PTRACE_XFER_TYPE) - 1)), | |
542 | myaddr, | |
543 | len); | |
544 | ||
545 | /* Write the entire buffer. */ | |
546 | ||
547 | for (i = 0; i < count; i++, addr += sizeof (PTRACE_XFER_TYPE)) | |
548 | { | |
549 | errno = 0; | |
39f77062 | 550 | ptrace (PT_WRITE_D, PIDGET (inferior_ptid), |
ed9a39eb | 551 | (PTRACE_ARG3_TYPE) addr, buffer[i]); |
c906108c | 552 | if (errno) |
c5aa993b | 553 | { |
c906108c | 554 | /* Using the appropriate one (I or D) is necessary for |
c5aa993b | 555 | Gould NP1, at least. */ |
c906108c | 556 | errno = 0; |
39f77062 | 557 | ptrace (PT_WRITE_I, PIDGET (inferior_ptid), |
ed9a39eb | 558 | (PTRACE_ARG3_TYPE) addr, buffer[i]); |
c906108c SS |
559 | } |
560 | if (errno) | |
561 | return 0; | |
562 | } | |
563 | #ifdef CLEAR_INSN_CACHE | |
c5aa993b | 564 | CLEAR_INSN_CACHE (); |
c906108c SS |
565 | #endif |
566 | } | |
567 | else | |
568 | { | |
569 | /* Read all the longwords */ | |
570 | for (i = 0; i < count; i++, addr += sizeof (PTRACE_XFER_TYPE)) | |
571 | { | |
572 | errno = 0; | |
39f77062 | 573 | buffer[i] = ptrace (PT_READ_I, PIDGET (inferior_ptid), |
c906108c SS |
574 | (PTRACE_ARG3_TYPE) addr, 0); |
575 | if (errno) | |
576 | return 0; | |
577 | QUIT; | |
578 | } | |
579 | ||
580 | /* Copy appropriate bytes out of the buffer. */ | |
581 | memcpy (myaddr, | |
582 | (char *) buffer + (memaddr & (sizeof (PTRACE_XFER_TYPE) - 1)), | |
583 | len); | |
584 | } | |
585 | return len; | |
586 | } | |
c906108c | 587 | \f |
c5aa993b | 588 | |
c906108c | 589 | static void |
fba45db2 | 590 | udot_info (char *dummy1, int dummy2) |
c906108c SS |
591 | { |
592 | #if defined (KERNEL_U_SIZE) | |
c5aa993b JM |
593 | int udot_off; /* Offset into user struct */ |
594 | int udot_val; /* Value from user struct at udot_off */ | |
595 | char mess[128]; /* For messages */ | |
c906108c SS |
596 | #endif |
597 | ||
c5aa993b JM |
598 | if (!target_has_execution) |
599 | { | |
600 | error ("The program is not being run."); | |
601 | } | |
c906108c SS |
602 | |
603 | #if !defined (KERNEL_U_SIZE) | |
604 | ||
605 | /* Adding support for this command is easy. Typically you just add a | |
606 | routine, called "kernel_u_size" that returns the size of the user | |
607 | struct, to the appropriate *-nat.c file and then add to the native | |
608 | config file "#define KERNEL_U_SIZE kernel_u_size()" */ | |
609 | error ("Don't know how large ``struct user'' is in this version of gdb."); | |
610 | ||
611 | #else | |
612 | ||
613 | for (udot_off = 0; udot_off < KERNEL_U_SIZE; udot_off += sizeof (udot_val)) | |
614 | { | |
615 | if ((udot_off % 24) == 0) | |
616 | { | |
617 | if (udot_off > 0) | |
618 | { | |
619 | printf_filtered ("\n"); | |
620 | } | |
621 | printf_filtered ("%04x:", udot_off); | |
622 | } | |
39f77062 | 623 | udot_val = ptrace (PT_READ_U, PIDGET (inferior_ptid), (PTRACE_ARG3_TYPE) udot_off, 0); |
c906108c SS |
624 | if (errno != 0) |
625 | { | |
626 | sprintf (mess, "\nreading user struct at offset 0x%x", udot_off); | |
627 | perror_with_name (mess); | |
628 | } | |
629 | /* Avoid using nonportable (?) "*" in print specs */ | |
630 | printf_filtered (sizeof (int) == 4 ? " 0x%08x" : " 0x%16x", udot_val); | |
631 | } | |
632 | printf_filtered ("\n"); | |
633 | ||
634 | #endif | |
635 | } | |
636 | #endif /* !defined (CHILD_XFER_MEMORY). */ | |
c906108c | 637 | \f |
c5aa993b | 638 | |
c906108c | 639 | void |
fba45db2 | 640 | _initialize_infptrace (void) |
c906108c SS |
641 | { |
642 | #if !defined (CHILD_XFER_MEMORY) | |
643 | add_info ("udot", udot_info, | |
644 | "Print contents of kernel ``struct user'' for current child."); | |
645 | #endif | |
646 | } |