1 /* Low-level child interface to ptrace.
3 Copyright (C) 1988-2016 Free Software Foundation, Inc.
5 This file is part of GDB.
7 This program is free software; you can redistribute it and/or modify
8 it under the terms of the GNU General Public License as published by
9 the Free Software Foundation; either version 3 of the License, or
10 (at your option) any later version.
12 This program is distributed in the hope that it will be useful,
13 but WITHOUT ANY WARRANTY; without even the implied warranty of
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 GNU General Public License for more details.
17 You should have received a copy of the GNU General Public License
18 along with this program. If not, see <http://www.gnu.org/licenses/>. */
27 #include "nat/gdb_ptrace.h"
31 #include "inf-ptrace.h"
32 #include "inf-child.h"
33 #include "gdbthread.h"
37 #ifdef PT_GET_PROCESS_STATE
39 /* Target hook for follow_fork. On entry and at return inferior_ptid is
40 the ptid of the followed inferior. */
43 inf_ptrace_follow_fork (struct target_ops
*ops
, int follow_child
,
48 struct thread_info
*tp
= inferior_thread ();
49 pid_t child_pid
= ptid_get_pid (tp
->pending_follow
.value
.related_pid
);
51 /* Breakpoints have already been detached from the child by
54 if (ptrace (PT_DETACH
, child_pid
, (PTRACE_TYPE_ARG3
)1, 0) == -1)
55 perror_with_name (("ptrace"));
62 inf_ptrace_insert_fork_catchpoint (struct target_ops
*self
, int pid
)
68 inf_ptrace_remove_fork_catchpoint (struct target_ops
*self
, int pid
)
73 #endif /* PT_GET_PROCESS_STATE */
76 /* Prepare to be traced. */
81 /* "Trace me, Dr. Memory!" */
82 ptrace (PT_TRACE_ME
, 0, (PTRACE_TYPE_ARG3
)0, 0);
85 /* Start a new inferior Unix child process. EXEC_FILE is the file to
86 run, ALLARGS is a string containing the arguments to the program.
87 ENV is the environment vector to pass. If FROM_TTY is non-zero, be
91 inf_ptrace_create_inferior (struct target_ops
*ops
,
92 char *exec_file
, char *allargs
, char **env
,
97 /* Do not change either targets above or the same target if already present.
98 The reason is the target stack is shared across multiple inferiors. */
99 int ops_already_pushed
= target_is_pushed (ops
);
100 struct cleanup
*back_to
= make_cleanup (null_cleanup
, NULL
);
102 if (! ops_already_pushed
)
104 /* Clear possible core file with its process_stratum. */
106 make_cleanup_unpush_target (ops
);
109 pid
= fork_inferior (exec_file
, allargs
, env
, inf_ptrace_me
, NULL
,
112 discard_cleanups (back_to
);
114 startup_inferior (START_INFERIOR_TRAPS_EXPECTED
);
116 /* On some targets, there must be some explicit actions taken after
117 the inferior has been started up. */
118 target_post_startup_inferior (pid_to_ptid (pid
));
121 #ifdef PT_GET_PROCESS_STATE
124 inf_ptrace_post_startup_inferior (struct target_ops
*self
, ptid_t pid
)
128 /* Set the initial event mask. */
129 memset (&pe
, 0, sizeof pe
);
130 pe
.pe_set_event
|= PTRACE_FORK
;
131 if (ptrace (PT_SET_EVENT_MASK
, ptid_get_pid (pid
),
132 (PTRACE_TYPE_ARG3
)&pe
, sizeof pe
) == -1)
133 perror_with_name (("ptrace"));
138 /* Clean up a rotting corpse of an inferior after it died. */
141 inf_ptrace_mourn_inferior (struct target_ops
*ops
)
145 /* Wait just one more time to collect the inferior's exit status.
146 Do not check whether this succeeds though, since we may be
147 dealing with a process that we attached to. Such a process will
148 only report its exit status to its original parent. */
149 waitpid (ptid_get_pid (inferior_ptid
), &status
, 0);
151 inf_child_mourn_inferior (ops
);
154 /* Attach to the process specified by ARGS. If FROM_TTY is non-zero,
155 be chatty about it. */
158 inf_ptrace_attach (struct target_ops
*ops
, const char *args
, int from_tty
)
162 struct inferior
*inf
;
164 /* Do not change either targets above or the same target if already present.
165 The reason is the target stack is shared across multiple inferiors. */
166 int ops_already_pushed
= target_is_pushed (ops
);
167 struct cleanup
*back_to
= make_cleanup (null_cleanup
, NULL
);
169 pid
= parse_pid_to_attach (args
);
171 if (pid
== getpid ()) /* Trying to masturbate? */
172 error (_("I refuse to debug myself!"));
174 if (! ops_already_pushed
)
176 /* target_pid_to_str already uses the target. Also clear possible core
177 file with its process_stratum. */
179 make_cleanup_unpush_target (ops
);
184 exec_file
= get_exec_file (0);
187 printf_unfiltered (_("Attaching to program: %s, %s\n"), exec_file
,
188 target_pid_to_str (pid_to_ptid (pid
)));
190 printf_unfiltered (_("Attaching to %s\n"),
191 target_pid_to_str (pid_to_ptid (pid
)));
193 gdb_flush (gdb_stdout
);
198 ptrace (PT_ATTACH
, pid
, (PTRACE_TYPE_ARG3
)0, 0);
200 perror_with_name (("ptrace"));
202 error (_("This system does not support attaching to a process"));
205 inf
= current_inferior ();
206 inferior_appeared (inf
, pid
);
207 inf
->attach_flag
= 1;
208 inferior_ptid
= pid_to_ptid (pid
);
210 /* Always add a main thread. If some target extends the ptrace
211 target, it should decorate the ptid later with more info. */
212 add_thread_silent (inferior_ptid
);
214 discard_cleanups (back_to
);
217 #ifdef PT_GET_PROCESS_STATE
220 inf_ptrace_post_attach (struct target_ops
*self
, int pid
)
224 /* Set the initial event mask. */
225 memset (&pe
, 0, sizeof pe
);
226 pe
.pe_set_event
|= PTRACE_FORK
;
227 if (ptrace (PT_SET_EVENT_MASK
, pid
,
228 (PTRACE_TYPE_ARG3
)&pe
, sizeof pe
) == -1)
229 perror_with_name (("ptrace"));
234 /* Detach from the inferior, optionally passing it the signal
235 specified by ARGS. If FROM_TTY is non-zero, be chatty about it. */
238 inf_ptrace_detach (struct target_ops
*ops
, const char *args
, int from_tty
)
240 pid_t pid
= ptid_get_pid (inferior_ptid
);
243 target_announce_detach (from_tty
);
248 /* We'd better not have left any breakpoints in the program or it'll
249 die when it hits one. Also note that this may only work if we
250 previously attached to the inferior. It *might* work if we
251 started the process ourselves. */
253 ptrace (PT_DETACH
, pid
, (PTRACE_TYPE_ARG3
)1, sig
);
255 perror_with_name (("ptrace"));
257 error (_("This system does not support detaching from a process"));
260 inferior_ptid
= null_ptid
;
261 detach_inferior (pid
);
263 inf_child_maybe_unpush_target (ops
);
266 /* Kill the inferior. */
269 inf_ptrace_kill (struct target_ops
*ops
)
271 pid_t pid
= ptid_get_pid (inferior_ptid
);
277 ptrace (PT_KILL
, pid
, (PTRACE_TYPE_ARG3
)0, 0);
278 waitpid (pid
, &status
, 0);
280 target_mourn_inferior ();
283 /* Interrupt the inferior. */
286 inf_ptrace_interrupt (struct target_ops
*self
, ptid_t ptid
)
288 /* Send a SIGINT to the process group. This acts just like the user
289 typed a ^C on the controlling terminal. Note that using a
290 negative process number in kill() is a System V-ism. The proper
291 BSD interface is killpg(). However, all modern BSDs support the
292 System V interface too. */
293 kill (-inferior_process_group (), SIGINT
);
296 /* Return which PID to pass to ptrace in order to observe/control the
297 tracee identified by PTID. */
300 get_ptrace_pid (ptid_t ptid
)
304 /* If we have an LWPID to work with, use it. Otherwise, we're
305 dealing with a non-threaded program/target. */
306 pid
= ptid_get_lwp (ptid
);
308 pid
= ptid_get_pid (ptid
);
312 /* Resume execution of thread PTID, or all threads if PTID is -1. If
313 STEP is nonzero, single-step it. If SIGNAL is nonzero, give it
317 inf_ptrace_resume (struct target_ops
*ops
,
318 ptid_t ptid
, int step
, enum gdb_signal signal
)
323 if (ptid_equal (minus_one_ptid
, ptid
))
324 /* Resume all threads. Traditionally ptrace() only supports
325 single-threaded processes, so simply resume the inferior. */
326 pid
= ptid_get_pid (inferior_ptid
);
328 pid
= get_ptrace_pid (ptid
);
330 if (catch_syscall_enabled () > 0)
331 request
= PT_SYSCALL
;
333 request
= PT_CONTINUE
;
337 /* If this system does not support PT_STEP, a higher level
338 function will have called single_step() to transmute the step
339 request into a continue request (by setting breakpoints on
340 all possible successor instructions), so we don't have to
341 worry about that here. */
345 /* An address of (PTRACE_TYPE_ARG3)1 tells ptrace to continue from
346 where it was. If GDB wanted it to start some other way, we have
347 already written a new program counter value to the child. */
349 ptrace (request
, pid
, (PTRACE_TYPE_ARG3
)1, gdb_signal_to_host (signal
));
351 perror_with_name (("ptrace"));
354 /* Wait for the child specified by PTID to do something. Return the
355 process ID of the child, or MINUS_ONE_PTID in case of error; store
356 the status in *OURSTATUS. */
359 inf_ptrace_wait (struct target_ops
*ops
,
360 ptid_t ptid
, struct target_waitstatus
*ourstatus
, int options
)
363 int status
, save_errno
;
371 pid
= waitpid (ptid_get_pid (ptid
), &status
, 0);
374 while (pid
== -1 && errno
== EINTR
);
376 clear_sigint_trap ();
380 fprintf_unfiltered (gdb_stderr
,
381 _("Child process unexpectedly missing: %s.\n"),
382 safe_strerror (save_errno
));
384 /* Claim it exited with unknown signal. */
385 ourstatus
->kind
= TARGET_WAITKIND_SIGNALLED
;
386 ourstatus
->value
.sig
= GDB_SIGNAL_UNKNOWN
;
387 return inferior_ptid
;
390 /* Ignore terminated detached child processes. */
391 if (!WIFSTOPPED (status
) && pid
!= ptid_get_pid (inferior_ptid
))
396 #ifdef PT_GET_PROCESS_STATE
397 if (WIFSTOPPED (status
))
402 if (ptrace (PT_GET_PROCESS_STATE
, pid
,
403 (PTRACE_TYPE_ARG3
)&pe
, sizeof pe
) == -1)
404 perror_with_name (("ptrace"));
406 switch (pe
.pe_report_event
)
409 ourstatus
->kind
= TARGET_WAITKIND_FORKED
;
410 ourstatus
->value
.related_pid
= pid_to_ptid (pe
.pe_other_pid
);
412 /* Make sure the other end of the fork is stopped too. */
413 fpid
= waitpid (pe
.pe_other_pid
, &status
, 0);
415 perror_with_name (("waitpid"));
417 if (ptrace (PT_GET_PROCESS_STATE
, fpid
,
418 (PTRACE_TYPE_ARG3
)&pe
, sizeof pe
) == -1)
419 perror_with_name (("ptrace"));
421 gdb_assert (pe
.pe_report_event
== PTRACE_FORK
);
422 gdb_assert (pe
.pe_other_pid
== pid
);
423 if (fpid
== ptid_get_pid (inferior_ptid
))
425 ourstatus
->value
.related_pid
= pid_to_ptid (pe
.pe_other_pid
);
426 return pid_to_ptid (fpid
);
429 return pid_to_ptid (pid
);
434 store_waitstatus (ourstatus
, status
);
435 return pid_to_ptid (pid
);
438 /* Implement the to_xfer_partial target_ops method. */
440 static enum target_xfer_status
441 inf_ptrace_xfer_partial (struct target_ops
*ops
, enum target_object object
,
442 const char *annex
, gdb_byte
*readbuf
,
443 const gdb_byte
*writebuf
,
444 ULONGEST offset
, ULONGEST len
, ULONGEST
*xfered_len
)
446 pid_t pid
= ptid_get_pid (inferior_ptid
);
450 case TARGET_OBJECT_MEMORY
:
452 /* OpenBSD 3.1, NetBSD 1.6 and FreeBSD 5.0 have a new PT_IO
453 request that promises to be much more efficient in reading
454 and writing data in the traced process's address space. */
456 struct ptrace_io_desc piod
;
458 /* NOTE: We assume that there are no distinct address spaces
459 for instruction and data. However, on OpenBSD 3.9 and
460 later, PIOD_WRITE_D doesn't allow changing memory that's
461 mapped read-only. Since most code segments will be
462 read-only, using PIOD_WRITE_D will prevent us from
463 inserting breakpoints, so we use PIOD_WRITE_I instead. */
464 piod
.piod_op
= writebuf
? PIOD_WRITE_I
: PIOD_READ_D
;
465 piod
.piod_addr
= writebuf
? (void *) writebuf
: readbuf
;
466 piod
.piod_offs
= (void *) (long) offset
;
470 if (ptrace (PT_IO
, pid
, (caddr_t
)&piod
, 0) == 0)
472 /* Return the actual number of bytes read or written. */
473 *xfered_len
= piod
.piod_len
;
474 return (piod
.piod_len
== 0) ? TARGET_XFER_EOF
: TARGET_XFER_OK
;
476 /* If the PT_IO request is somehow not supported, fallback on
477 using PT_WRITE_D/PT_READ_D. Otherwise we will return zero
478 to indicate failure. */
480 return TARGET_XFER_EOF
;
486 PTRACE_TYPE_RET word
;
487 gdb_byte byte
[sizeof (PTRACE_TYPE_RET
)];
489 ULONGEST rounded_offset
;
490 ULONGEST partial_len
;
492 /* Round the start offset down to the next long word
494 rounded_offset
= offset
& -(ULONGEST
) sizeof (PTRACE_TYPE_RET
);
496 /* Since ptrace will transfer a single word starting at that
497 rounded_offset the partial_len needs to be adjusted down to
498 that (remember this function only does a single transfer).
499 Should the required length be even less, adjust it down
501 partial_len
= (rounded_offset
+ sizeof (PTRACE_TYPE_RET
)) - offset
;
502 if (partial_len
> len
)
507 /* If OFFSET:PARTIAL_LEN is smaller than
508 ROUNDED_OFFSET:WORDSIZE then a read/modify write will
509 be needed. Read in the entire word. */
510 if (rounded_offset
< offset
511 || (offset
+ partial_len
512 < rounded_offset
+ sizeof (PTRACE_TYPE_RET
)))
513 /* Need part of initial word -- fetch it. */
514 buffer
.word
= ptrace (PT_READ_I
, pid
,
515 (PTRACE_TYPE_ARG3
)(uintptr_t)
518 /* Copy data to be written over corresponding part of
520 memcpy (buffer
.byte
+ (offset
- rounded_offset
),
521 writebuf
, partial_len
);
524 ptrace (PT_WRITE_D
, pid
,
525 (PTRACE_TYPE_ARG3
)(uintptr_t)rounded_offset
,
529 /* Using the appropriate one (I or D) is necessary for
530 Gould NP1, at least. */
532 ptrace (PT_WRITE_I
, pid
,
533 (PTRACE_TYPE_ARG3
)(uintptr_t)rounded_offset
,
536 return TARGET_XFER_EOF
;
543 buffer
.word
= ptrace (PT_READ_I
, pid
,
544 (PTRACE_TYPE_ARG3
)(uintptr_t)rounded_offset
,
547 return TARGET_XFER_EOF
;
548 /* Copy appropriate bytes out of the buffer. */
549 memcpy (readbuf
, buffer
.byte
+ (offset
- rounded_offset
),
553 *xfered_len
= partial_len
;
554 return TARGET_XFER_OK
;
557 case TARGET_OBJECT_UNWIND_TABLE
:
558 return TARGET_XFER_E_IO
;
560 case TARGET_OBJECT_AUXV
:
561 #if defined (PT_IO) && defined (PIOD_READ_AUXV)
562 /* OpenBSD 4.5 has a new PIOD_READ_AUXV operation for the PT_IO
563 request that allows us to read the auxilliary vector. Other
564 BSD's may follow if they feel the need to support PIE. */
566 struct ptrace_io_desc piod
;
569 return TARGET_XFER_E_IO
;
570 piod
.piod_op
= PIOD_READ_AUXV
;
571 piod
.piod_addr
= readbuf
;
572 piod
.piod_offs
= (void *) (long) offset
;
576 if (ptrace (PT_IO
, pid
, (caddr_t
)&piod
, 0) == 0)
578 /* Return the actual number of bytes read or written. */
579 *xfered_len
= piod
.piod_len
;
580 return (piod
.piod_len
== 0) ? TARGET_XFER_EOF
: TARGET_XFER_OK
;
584 return TARGET_XFER_E_IO
;
586 case TARGET_OBJECT_WCOOKIE
:
587 return TARGET_XFER_E_IO
;
590 return TARGET_XFER_E_IO
;
594 /* Return non-zero if the thread specified by PTID is alive. */
597 inf_ptrace_thread_alive (struct target_ops
*ops
, ptid_t ptid
)
599 /* ??? Is kill the right way to do this? */
600 return (kill (ptid_get_pid (ptid
), 0) != -1);
603 /* Print status information about what we're accessing. */
606 inf_ptrace_files_info (struct target_ops
*ignore
)
608 struct inferior
*inf
= current_inferior ();
610 printf_filtered (_("\tUsing the running image of %s %s.\n"),
611 inf
->attach_flag
? "attached" : "child",
612 target_pid_to_str (inferior_ptid
));
616 inf_ptrace_pid_to_str (struct target_ops
*ops
, ptid_t ptid
)
618 return normal_pid_to_str (ptid
);
621 #if defined (PT_IO) && defined (PIOD_READ_AUXV)
623 /* Read one auxv entry from *READPTR, not reading locations >= ENDPTR.
624 Return 0 if *READPTR is already at the end of the buffer.
625 Return -1 if there is insufficient buffer for a whole entry.
626 Return 1 if an entry was read into *TYPEP and *VALP. */
629 inf_ptrace_auxv_parse (struct target_ops
*ops
, gdb_byte
**readptr
,
630 gdb_byte
*endptr
, CORE_ADDR
*typep
, CORE_ADDR
*valp
)
632 struct type
*int_type
= builtin_type (target_gdbarch ())->builtin_int
;
633 struct type
*ptr_type
= builtin_type (target_gdbarch ())->builtin_data_ptr
;
634 const int sizeof_auxv_type
= TYPE_LENGTH (int_type
);
635 const int sizeof_auxv_val
= TYPE_LENGTH (ptr_type
);
636 enum bfd_endian byte_order
= gdbarch_byte_order (target_gdbarch ());
637 gdb_byte
*ptr
= *readptr
;
642 if (endptr
- ptr
< 2 * sizeof_auxv_val
)
645 *typep
= extract_unsigned_integer (ptr
, sizeof_auxv_type
, byte_order
);
646 ptr
+= sizeof_auxv_val
; /* Alignment. */
647 *valp
= extract_unsigned_integer (ptr
, sizeof_auxv_val
, byte_order
);
648 ptr
+= sizeof_auxv_val
;
656 /* Create a prototype ptrace target. The client can override it with
660 inf_ptrace_target (void)
662 struct target_ops
*t
= inf_child_target ();
664 t
->to_attach
= inf_ptrace_attach
;
665 t
->to_detach
= inf_ptrace_detach
;
666 t
->to_resume
= inf_ptrace_resume
;
667 t
->to_wait
= inf_ptrace_wait
;
668 t
->to_files_info
= inf_ptrace_files_info
;
669 t
->to_kill
= inf_ptrace_kill
;
670 t
->to_create_inferior
= inf_ptrace_create_inferior
;
671 #ifdef PT_GET_PROCESS_STATE
672 t
->to_follow_fork
= inf_ptrace_follow_fork
;
673 t
->to_insert_fork_catchpoint
= inf_ptrace_insert_fork_catchpoint
;
674 t
->to_remove_fork_catchpoint
= inf_ptrace_remove_fork_catchpoint
;
675 t
->to_post_startup_inferior
= inf_ptrace_post_startup_inferior
;
676 t
->to_post_attach
= inf_ptrace_post_attach
;
678 t
->to_mourn_inferior
= inf_ptrace_mourn_inferior
;
679 t
->to_thread_alive
= inf_ptrace_thread_alive
;
680 t
->to_pid_to_str
= inf_ptrace_pid_to_str
;
681 t
->to_interrupt
= inf_ptrace_interrupt
;
682 t
->to_xfer_partial
= inf_ptrace_xfer_partial
;
683 #if defined (PT_IO) && defined (PIOD_READ_AUXV)
684 t
->to_auxv_parse
= inf_ptrace_auxv_parse
;
691 /* Pointer to a function that returns the offset within the user area
692 where a particular register is stored. */
693 static CORE_ADDR (*inf_ptrace_register_u_offset
)(struct gdbarch
*, int, int);
695 /* Fetch register REGNUM from the inferior. */
698 inf_ptrace_fetch_register (struct regcache
*regcache
, int regnum
)
700 struct gdbarch
*gdbarch
= get_regcache_arch (regcache
);
703 PTRACE_TYPE_RET
*buf
;
706 /* This isn't really an address, but ptrace thinks of it as one. */
707 addr
= inf_ptrace_register_u_offset (gdbarch
, regnum
, 0);
708 if (addr
== (CORE_ADDR
)-1
709 || gdbarch_cannot_fetch_register (gdbarch
, regnum
))
711 regcache_raw_supply (regcache
, regnum
, NULL
);
715 /* Cater for systems like GNU/Linux, that implement threads as
716 separate processes. */
717 pid
= ptid_get_lwp (inferior_ptid
);
719 pid
= ptid_get_pid (inferior_ptid
);
721 size
= register_size (gdbarch
, regnum
);
722 gdb_assert ((size
% sizeof (PTRACE_TYPE_RET
)) == 0);
723 buf
= (PTRACE_TYPE_RET
*) alloca (size
);
725 /* Read the register contents from the inferior a chunk at a time. */
726 for (i
= 0; i
< size
/ sizeof (PTRACE_TYPE_RET
); i
++)
729 buf
[i
] = ptrace (PT_READ_U
, pid
, (PTRACE_TYPE_ARG3
)(uintptr_t)addr
, 0);
731 error (_("Couldn't read register %s (#%d): %s."),
732 gdbarch_register_name (gdbarch
, regnum
),
733 regnum
, safe_strerror (errno
));
735 addr
+= sizeof (PTRACE_TYPE_RET
);
737 regcache_raw_supply (regcache
, regnum
, buf
);
740 /* Fetch register REGNUM from the inferior. If REGNUM is -1, do this
741 for all registers. */
744 inf_ptrace_fetch_registers (struct target_ops
*ops
,
745 struct regcache
*regcache
, int regnum
)
749 regnum
< gdbarch_num_regs (get_regcache_arch (regcache
));
751 inf_ptrace_fetch_register (regcache
, regnum
);
753 inf_ptrace_fetch_register (regcache
, regnum
);
756 /* Store register REGNUM into the inferior. */
759 inf_ptrace_store_register (const struct regcache
*regcache
, int regnum
)
761 struct gdbarch
*gdbarch
= get_regcache_arch (regcache
);
764 PTRACE_TYPE_RET
*buf
;
767 /* This isn't really an address, but ptrace thinks of it as one. */
768 addr
= inf_ptrace_register_u_offset (gdbarch
, regnum
, 1);
769 if (addr
== (CORE_ADDR
)-1
770 || gdbarch_cannot_store_register (gdbarch
, regnum
))
773 /* Cater for systems like GNU/Linux, that implement threads as
774 separate processes. */
775 pid
= ptid_get_lwp (inferior_ptid
);
777 pid
= ptid_get_pid (inferior_ptid
);
779 size
= register_size (gdbarch
, regnum
);
780 gdb_assert ((size
% sizeof (PTRACE_TYPE_RET
)) == 0);
781 buf
= (PTRACE_TYPE_RET
*) alloca (size
);
783 /* Write the register contents into the inferior a chunk at a time. */
784 regcache_raw_collect (regcache
, regnum
, buf
);
785 for (i
= 0; i
< size
/ sizeof (PTRACE_TYPE_RET
); i
++)
788 ptrace (PT_WRITE_U
, pid
, (PTRACE_TYPE_ARG3
)(uintptr_t)addr
, buf
[i
]);
790 error (_("Couldn't write register %s (#%d): %s."),
791 gdbarch_register_name (gdbarch
, regnum
),
792 regnum
, safe_strerror (errno
));
794 addr
+= sizeof (PTRACE_TYPE_RET
);
798 /* Store register REGNUM back into the inferior. If REGNUM is -1, do
799 this for all registers. */
802 inf_ptrace_store_registers (struct target_ops
*ops
,
803 struct regcache
*regcache
, int regnum
)
807 regnum
< gdbarch_num_regs (get_regcache_arch (regcache
));
809 inf_ptrace_store_register (regcache
, regnum
);
811 inf_ptrace_store_register (regcache
, regnum
);
814 /* Create a "traditional" ptrace target. REGISTER_U_OFFSET should be
815 a function returning the offset within the user area where a
816 particular register is stored. */
819 inf_ptrace_trad_target (CORE_ADDR (*register_u_offset
)
820 (struct gdbarch
*, int, int))
822 struct target_ops
*t
= inf_ptrace_target();
824 gdb_assert (register_u_offset
);
825 inf_ptrace_register_u_offset
= register_u_offset
;
826 t
->to_fetch_registers
= inf_ptrace_fetch_registers
;
827 t
->to_store_registers
= inf_ptrace_store_registers
;