]> CyberLeo.Net >> Repos - FreeBSD/stable/10.git/blob - lib/libc/sys/ptrace.2
MFC 302900,302902,302921,303461,304009:
[FreeBSD/stable/10.git] / lib / libc / sys / ptrace.2
1 .\" $FreeBSD$
2 .\"     $NetBSD: ptrace.2,v 1.2 1995/02/27 12:35:37 cgd Exp $
3 .\"
4 .\" This file is in the public domain.
5 .Dd July 28, 2016
6 .Dt PTRACE 2
7 .Os
8 .Sh NAME
9 .Nm ptrace
10 .Nd process tracing and debugging
11 .Sh LIBRARY
12 .Lb libc
13 .Sh SYNOPSIS
14 .In sys/types.h
15 .In sys/ptrace.h
16 .Ft int
17 .Fn ptrace "int request" "pid_t pid" "caddr_t addr" "int data"
18 .Sh DESCRIPTION
19 The
20 .Fn ptrace
21 system call
22 provides tracing and debugging facilities.
23 It allows one process
24 (the
25 .Em tracing
26 process)
27 to control another
28 (the
29 .Em traced
30 process).
31 The tracing process must first attach to the traced process, and then
32 issue a series of
33 .Fn ptrace
34 system calls to control the execution of the process, as well as access
35 process memory and register state.
36 For the duration of the tracing session, the traced process will be
37 .Dq re-parented ,
38 with its parent process ID (and resulting behavior)
39 changed to the tracing process.
40 It is permissible for a tracing process to attach to more than one
41 other process at a time.
42 When the tracing process has completed its work, it must detach the
43 traced process; if a tracing process exits without first detaching all
44 processes it has attached, those processes will be killed.
45 .Pp
46 Most of the time, the traced process runs normally, but when it
47 receives a signal
48 (see
49 .Xr sigaction 2 ) ,
50 it stops.
51 The tracing process is expected to notice this via
52 .Xr wait 2
53 or the delivery of a
54 .Dv SIGCHLD
55 signal, examine the state of the stopped process, and cause it to
56 terminate or continue as appropriate.
57 The signal may be a normal process signal, generated as a result of
58 traced process behavior, or use of the
59 .Xr kill 2
60 system call; alternatively, it may be generated by the tracing facility
61 as a result of attaching, stepping by the tracing
62 process,
63 or an event in the traced process.
64 The tracing process may choose to intercept the signal, using it to
65 observe process behavior (such as
66 .Dv SIGTRAP ) ,
67 or forward the signal to the process if appropriate.
68 The
69 .Fn ptrace
70 system call
71 is the mechanism by which all this happens.
72 .Pp
73 A traced process may report additional signal stops corresponding to
74 events in the traced process.
75 These additional signal stops are reported as
76 .Dv SIGTRAP
77 or
78 .Dv SIGSTOP
79 signals.
80 The tracing process can use the
81 .Dv PT_LWPINFO
82 request to determine which events are associated with a
83 .Dv SIGTRAP
84 or
85 .Dv SIGSTOP
86 signal.
87 Note that multiple events may be associated with a single signal.
88 For example, events indicated by the
89 .Dv PL_FLAG_BORN ,
90 .Dv PL_FLAG_FORKED ,
91 and
92 .Dv PL_FLAG_EXEC
93 flags are also reported as a system call exit event
94 .Pq Dv PL_FLAG_SCX .
95 The signal stop for a new child process enabled via
96 .Dv PTRACE_FORK
97 will report a
98 .Dv SIGSTOP
99 signal.
100 All other additional signal stops use
101 .Dv SIGTRAP .
102 .Pp
103 Each traced process has a tracing event mask.
104 An event in the traced process only reports a
105 signal stop if the corresponding flag is set in the tracing event mask.
106 The current set of tracing event flags include:
107 .Bl -tag -width ".Dv PTRACE_SYSCALL"
108 .It Dv PTRACE_EXEC
109 Report a stop for a successful invocation of
110 .Xr execve 2 .
111 This event is indicated by the
112 .Dv PL_FLAG_EXEC
113 flag in the
114 .Va pl_flags
115 member of
116 .Vt "struct ptrace_lwpinfo" .
117 .It Dv PTRACE_SCE
118 Report a stop on each system call entry.
119 This event is indicated by the
120 .Dv PL_FLAG_SCE
121 flag in the
122 .Va pl_flags
123 member of
124 .Vt "struct ptrace_lwpinfo" .
125 .It Dv PTRACE_SCX
126 Report a stop on each system call exit.
127 This event is indicated by the
128 .Dv PL_FLAG_SCX
129 flag in the
130 .Va pl_flags
131 member of
132 .Vt "struct ptrace_lwpinfo" .
133 .It Dv PTRACE_SYSCALL
134 Report stops for both system call entry and exit.
135 .It Dv PTRACE_FORK
136 This event flag controls tracing for new child processes of a traced process.
137 .Pp
138 When this event flag is enabled,
139 new child processes will enable tracing and stop before executing their
140 first instruction.
141 The new child process will include the
142 .Dv PL_FLAG_CHILD
143 flag in the
144 .Va pl_flags
145 member of
146 .Vt "struct ptrace_lwpinfo" .
147 The traced process will report a stop that includes the
148 .Dv PL_FLAG_FORKED
149 flag.
150 The process ID of the new child process will also be present in the
151 .Va pl_child_pid
152 member of
153 .Vt "struct ptrace_lwpinfo" .
154 Note that new child processes will be attached with the default
155 tracing event mask;
156 they do not inherit the event mask of the traced process.
157 .Pp
158 When this event flag is not enabled,
159 new child processes will execute without tracing enabled.
160 .It Dv PTRACE_LWP
161 This event flag controls tracing of LWP
162 .Pq kernel thread
163 creation and destruction.
164 When this event is enabled, 
165 new LWPs will stop and report an event with
166 .Dv PL_FLAG_BORN
167 set before executing their first instruction,
168 and exiting LWPs will stop and report an event with
169 .Dv PL_FLAG_EXITED
170 set before completing their termination.
171 .Pp
172 Note that new processes do not report an event for the creation of their
173 initial thread,
174 and exiting processes do not report an event for the termination of the
175 last thread.
176 .El
177 .Pp
178 The default tracing event mask when attaching to a process via
179 .Dv PT_ATTACH ,
180 .Dv PT_TRACE_ME ,
181 or
182 .Dv PTRACE_FORK
183 includes only
184 .Dv PTRACE_EXEC
185 events.
186 All other event flags are disabled. 
187 .Pp
188 The
189 .Fa request
190 argument specifies what operation is being performed; the meaning of
191 the rest of the arguments depends on the operation, but except for one
192 special case noted below, all
193 .Fn ptrace
194 calls are made by the tracing process, and the
195 .Fa pid
196 argument specifies the process ID of the traced process
197 or a corresponding thread ID.
198 The
199 .Fa request
200 argument
201 can be:
202 .Bl -tag -width 12n
203 .It Dv PT_TRACE_ME
204 This request is the only one used by the traced process; it declares
205 that the process expects to be traced by its parent.
206 All the other arguments are ignored.
207 (If the parent process does not expect to trace the child, it will
208 probably be rather confused by the results; once the traced process
209 stops, it cannot be made to continue except via
210 .Fn ptrace . )
211 When a process has used this request and calls
212 .Xr execve 2
213 or any of the routines built on it
214 (such as
215 .Xr execv 3 ) ,
216 it will stop before executing the first instruction of the new image.
217 Also, any setuid or setgid bits on the executable being executed will
218 be ignored.
219 If the child was created by
220 .Xr vfork 2
221 system call or
222 .Xr rfork(2)
223 call with the
224 .Dv RFMEM
225 flag specified, the debugging events are reported to the parent
226 only after the
227 .Xr execve 2
228 is executed.
229 .It Dv PT_READ_I , Dv PT_READ_D
230 These requests read a single
231 .Vt int
232 of data from the traced process's address space.
233 Traditionally,
234 .Fn ptrace
235 has allowed for machines with distinct address spaces for instruction
236 and data, which is why there are two requests: conceptually,
237 .Dv PT_READ_I
238 reads from the instruction space and
239 .Dv PT_READ_D
240 reads from the data space.
241 In the current
242 .Fx
243 implementation, these two requests are completely identical.
244 The
245 .Fa addr
246 argument specifies the address
247 (in the traced process's virtual address space)
248 at which the read is to be done.
249 This address does not have to meet any alignment constraints.
250 The value read is returned as the return value from
251 .Fn ptrace .
252 .It Dv PT_WRITE_I , Dv PT_WRITE_D
253 These requests parallel
254 .Dv PT_READ_I
255 and
256 .Dv PT_READ_D ,
257 except that they write rather than read.
258 The
259 .Fa data
260 argument supplies the value to be written.
261 .It Dv PT_IO
262 This request allows reading and writing arbitrary amounts of data in
263 the traced process's address space.
264 The
265 .Fa addr
266 argument specifies a pointer to a
267 .Vt "struct ptrace_io_desc" ,
268 which is defined as follows:
269 .Bd -literal
270 struct ptrace_io_desc {
271         int     piod_op;        /* I/O operation */
272         void    *piod_offs;     /* child offset */
273         void    *piod_addr;     /* parent offset */
274         size_t  piod_len;       /* request length */
275 };
276
277 /*
278  * Operations in piod_op.
279  */
280 #define PIOD_READ_D     1       /* Read from D space */
281 #define PIOD_WRITE_D    2       /* Write to D space */
282 #define PIOD_READ_I     3       /* Read from I space */
283 #define PIOD_WRITE_I    4       /* Write to I space */
284 .Ed
285 .Pp
286 The
287 .Fa data
288 argument is ignored.
289 The actual number of bytes read or written is stored in
290 .Va piod_len
291 upon return.
292 .It Dv PT_CONTINUE
293 The traced process continues execution.
294 The
295 .Fa addr
296 argument
297 is an address specifying the place where execution is to be resumed
298 (a new value for the program counter),
299 or
300 .Po Vt caddr_t Pc Ns 1
301 to indicate that execution is to pick up where it left off.
302 The
303 .Fa data
304 argument
305 provides a signal number to be delivered to the traced process as it
306 resumes execution, or 0 if no signal is to be sent.
307 .It Dv PT_STEP
308 The traced process is single stepped one instruction.
309 The
310 .Fa addr
311 argument
312 should be passed
313 .Po Vt caddr_t Pc Ns 1 .
314 The
315 .Fa data
316 argument
317 provides a signal number to be delivered to the traced process as it
318 resumes execution, or 0 if no signal is to be sent.
319 .It Dv PT_KILL
320 The traced process terminates, as if
321 .Dv PT_CONTINUE
322 had been used with
323 .Dv SIGKILL
324 given as the signal to be delivered.
325 .It Dv PT_ATTACH
326 This request allows a process to gain control of an otherwise
327 unrelated process and begin tracing it.
328 It does not need any cooperation from the to-be-traced process.
329 In
330 this case,
331 .Fa pid
332 specifies the process ID of the to-be-traced process, and the other
333 two arguments are ignored.
334 This request requires that the target process must have the same real
335 UID as the tracing process, and that it must not be executing a setuid
336 or setgid executable.
337 (If the tracing process is running as root, these restrictions do not
338 apply.)
339 The tracing process will see the newly-traced process stop and may
340 then control it as if it had been traced all along.
341 .It Dv PT_DETACH
342 This request is like PT_CONTINUE, except that it does not allow
343 specifying an alternate place to continue execution, and after it
344 succeeds, the traced process is no longer traced and continues
345 execution normally.
346 .It Dv PT_GETREGS
347 This request reads the traced process's machine registers into the
348 .Do
349 .Vt "struct reg"
350 .Dc
351 (defined in
352 .In machine/reg.h )
353 pointed to by
354 .Fa addr .
355 .It Dv PT_SETREGS
356 This request is the converse of
357 .Dv PT_GETREGS ;
358 it loads the traced process's machine registers from the
359 .Do
360 .Vt "struct reg"
361 .Dc
362 (defined in
363 .In machine/reg.h )
364 pointed to by
365 .Fa addr .
366 .It Dv PT_GETFPREGS
367 This request reads the traced process's floating-point registers into
368 the
369 .Do
370 .Vt "struct fpreg"
371 .Dc
372 (defined in
373 .In machine/reg.h )
374 pointed to by
375 .Fa addr .
376 .It Dv PT_SETFPREGS
377 This request is the converse of
378 .Dv PT_GETFPREGS ;
379 it loads the traced process's floating-point registers from the
380 .Do
381 .Vt "struct fpreg"
382 .Dc
383 (defined in
384 .In machine/reg.h )
385 pointed to by
386 .Fa addr .
387 .It Dv PT_GETDBREGS
388 This request reads the traced process's debug registers into
389 the
390 .Do
391 .Vt "struct dbreg"
392 .Dc
393 (defined in
394 .In machine/reg.h )
395 pointed to by
396 .Fa addr .
397 .It Dv PT_SETDBREGS
398 This request is the converse of
399 .Dv PT_GETDBREGS ;
400 it loads the traced process's debug registers from the
401 .Do
402 .Vt "struct dbreg"
403 .Dc
404 (defined in
405 .In machine/reg.h )
406 pointed to by
407 .Fa addr .
408 .It Dv PT_LWPINFO
409 This request can be used to obtain information about the kernel thread,
410 also known as light-weight process, that caused the traced process to stop.
411 The
412 .Fa addr
413 argument specifies a pointer to a
414 .Vt "struct ptrace_lwpinfo" ,
415 which is defined as follows:
416 .Bd -literal
417 struct ptrace_lwpinfo {
418         lwpid_t pl_lwpid;
419         int     pl_event;
420         int     pl_flags;
421         sigset_t pl_sigmask;
422         sigset_t pl_siglist;
423         siginfo_t pl_siginfo;
424         char    pl_tdname[MAXCOMLEN + 1];
425         pid_t   pl_child_pid;
426         u_int   pl_syscall_code;
427         u_int   pl_syscall_narg;
428 };
429 .Ed
430 .Pp
431 The
432 .Fa data
433 argument is to be set to the size of the structure known to the caller.
434 This allows the structure to grow without affecting older programs.
435 .Pp
436 The fields in the
437 .Vt "struct ptrace_lwpinfo"
438 have the following meaning:
439 .Bl -tag -width indent -compact
440 .It pl_lwpid
441 LWP id of the thread
442 .It pl_event
443 Event that caused the stop.
444 Currently defined events are
445 .Bl -tag -width indent -compact
446 .It PL_EVENT_NONE
447 No reason given
448 .It PL_EVENT_SIGNAL
449 Thread stopped due to the pending signal
450 .El
451 .It pl_flags
452 Flags that specify additional details about observed stop.
453 Currently defined flags are:
454 .Bl -tag -width indent -compact
455 .It PL_FLAG_SCE
456 The thread stopped due to system call entry, right after the kernel is entered.
457 The debugger may examine syscall arguments that are stored in memory and
458 registers according to the ABI of the current process, and modify them,
459 if needed.
460 .It PL_FLAG_SCX
461 The thread is stopped immediately before syscall is returning to the usermode.
462 The debugger may examine system call return values in the ABI-defined registers
463 and/or memory.
464 .It PL_FLAG_EXEC
465 When
466 .Dv PL_FLAG_SCX
467 is set, this flag may be additionally specified to inform that the
468 program being executed by debuggee process has been changed by successful
469 execution of a system call from the
470 .Fn execve 2
471 family.
472 .It PL_FLAG_SI
473 Indicates that
474 .Va pl_siginfo
475 member of
476 .Vt "struct ptrace_lwpinfo"
477 contains valid information.
478 .It PL_FLAG_FORKED
479 Indicates that the process is returning from a call to
480 .Fn fork 2
481 that created a new child process.
482 The process identifier of the new process is available in the
483 .Va pl_child_pid
484 member of
485 .Vt "struct ptrace_lwpinfo" .
486 .It PL_FLAG_CHILD
487 The flag is set for first event reported from a new child which is
488 automatically attached when
489 .Dv PTRACE_FORK
490 is enabled.
491 .It PL_FLAG_BORN
492 This flag is set for the first event reported from a new LWP when
493 .Dv PTRACE_LWP
494 is enabled.
495 It is reported along with
496 .Dv PL_FLAG_SCX .
497 .It PL_FLAG_EXITED
498 This flag is set for the last event reported by an exiting LWP when
499 .Dv PTRACE_LWP
500 is enabled.
501 Note that this event is not reported when the last LWP in a process exits.
502 The termination of the last thread is reported via a normal process exit
503 event.
504 .El
505 .It pl_sigmask
506 The current signal mask of the LWP
507 .It pl_siglist
508 The current pending set of signals for the LWP.
509 Note that signals that are delivered to the process would not appear
510 on an LWP siglist until the thread is selected for delivery.
511 .It pl_siginfo
512 The siginfo that accompanies the signal pending.
513 Only valid for
514 .Dv PL_EVENT_SIGNAL
515 stop when
516 .Dv PL_FLAG_SI
517 is set in
518 .Va pl_flags .
519 .It pl_tdname
520 The name of the thread.
521 .It pl_child_pid
522 The process identifier of the new child process.
523 Only valid for a
524 .Dv PL_EVENT_SIGNAL
525 stop when
526 .Dv PL_FLAG_FORKED
527 is set in
528 .Va pl_flags .
529 .It pl_syscall_code
530 The ABI-specific identifier of the current system call.
531 Note that for indirect system calls this field reports the indirected
532 system call.
533 Only valid when
534 .Dv PL_FLAG_SCE
535 or
536 .Dv PL_FLAG_SCX
537 is set in
538 .Va pl_flags.
539 .It pl_syscall_narg
540 The number of arguments passed to the current system call not counting
541 the system call identifier.
542 Note that for indirect system calls this field reports the arguments
543 passed to the indirected system call.
544 Only valid when
545 .Dv PL_FLAG_SCE
546 or
547 .Dv PL_FLAG_SCX
548 is set in
549 .Va pl_flags.
550 .El
551 .It PT_GETNUMLWPS
552 This request returns the number of kernel threads associated with the
553 traced process.
554 .It PT_GETLWPLIST
555 This request can be used to get the current thread list.
556 A pointer to an array of type
557 .Vt lwpid_t
558 should be passed in
559 .Fa addr ,
560 with the array size specified by
561 .Fa data .
562 The return value from
563 .Fn ptrace
564 is the count of array entries filled in.
565 .It PT_SETSTEP
566 This request will turn on single stepping of the specified process.
567 .It PT_CLEARSTEP
568 This request will turn off single stepping of the specified process.
569 .It PT_SUSPEND
570 This request will suspend the specified thread.
571 .It PT_RESUME
572 This request will resume the specified thread.
573 .It PT_TO_SCE
574 This request will set the
575 .Dv PTRACE_SCE
576 event flag to trace all future system call entries and continue the process.
577 The
578 .Fa addr
579 and
580 .Fa data
581 arguments are used the same as for
582 .Dv PT_CONTINUE.
583 .It PT_TO_SCX
584 This request will set the
585 .Dv PTRACE_SCX
586 event flag to trace all future system call exits and continue the process.
587 The
588 .Fa addr
589 and
590 .Fa data
591 arguments are used the same as for
592 .Dv PT_CONTINUE.
593 .It PT_SYSCALL
594 This request will set the
595 .Dv PTRACE_SYSCALL
596 event flag to trace all future system call entries and exits and continue
597 the process.
598 The
599 .Fa addr
600 and
601 .Fa data
602 arguments are used the same as for
603 .Dv PT_CONTINUE.
604 .It PT_FOLLOW_FORK
605 This request controls tracing for new child processes of a traced process.
606 If
607 .Fa data
608 is non-zero,
609 .Dv PTRACE_FORK
610 is set in the traced process's event tracing mask.
611 If
612 .Fa data
613 is zero,
614 .Dv PTRACE_FORK
615 is cleared from the traced process's event tracing mask.
616 .It PT_LWP_EVENTS
617 This request controls tracing of LWP creation and destruction.
618 If
619 .Fa data
620 is non-zero,
621 .Dv PTRACE_LWP
622 is set in the traced process's event tracing mask.
623 If
624 .Fa data
625 is zero,
626 .Dv PTRACE_LWP
627 is cleared from the traced process's event tracing mask.
628 .It PT_GET_EVENT_MASK
629 This request reads the traced process's event tracing mask into the
630 integer pointed to by
631 .Fa addr .
632 The size of the integer must be passed in
633 .Fa data .
634 .It PT_SET_EVENT_MASK
635 This request sets the traced process's event tracing mask from the
636 integer pointed to by
637 .Fa addr .
638 The size of the integer must be passed in
639 .Fa data .
640 .It PT_VM_TIMESTAMP
641 This request returns the generation number or timestamp of the memory map of
642 the traced process as the return value from
643 .Fn ptrace .
644 This provides a low-cost way for the tracing process to determine if the
645 VM map changed since the last time this request was made.
646 .It PT_VM_ENTRY
647 This request is used to iterate over the entries of the VM map of the traced
648 process.
649 The
650 .Fa addr
651 argument specifies a pointer to a
652 .Vt "struct ptrace_vm_entry" ,
653 which is defined as follows:
654 .Bd -literal
655 struct ptrace_vm_entry {
656         int             pve_entry;
657         int             pve_timestamp;
658         u_long          pve_start;
659         u_long          pve_end;
660         u_long          pve_offset;
661         u_int           pve_prot;
662         u_int           pve_pathlen;
663         long            pve_fileid;
664         uint32_t        pve_fsid;
665         char            *pve_path;
666 };
667 .Ed
668 .Pp
669 The first entry is returned by setting
670 .Va pve_entry
671 to zero.
672 Subsequent entries are returned by leaving
673 .Va pve_entry
674 unmodified from the value returned by previous requests.
675 The
676 .Va pve_timestamp
677 field can be used to detect changes to the VM map while iterating over the
678 entries.
679 The tracing process can then take appropriate action, such as restarting.
680 By setting
681 .Va pve_pathlen
682 to a non-zero value on entry, the pathname of the backing object is returned
683 in the buffer pointed to by
684 .Va pve_path ,
685 provided the entry is backed by a vnode.
686 The
687 .Va pve_pathlen
688 field is updated with the actual length of the pathname (including the
689 terminating null character).
690 The
691 .Va pve_offset
692 field is the offset within the backing object at which the range starts.
693 The range is located in the VM space at
694 .Va pve_start
695 and extends up to
696 .Va pve_end
697 (inclusive).
698 .Pp
699 The
700 .Fa data
701 argument is ignored.
702 .El
703 .Sh x86 MACHINE-SPECIFIC REQUESTS
704 .Bl -tag -width "Dv PT_GETXSTATE_INFO"
705 .It Dv PT_GETXMMREGS
706 Copy the XMM FPU state into the buffer pointed to by the
707 argument
708 .Fa addr .
709 The buffer has the same layout as the 32-bit save buffer for the
710 machine instruction
711 .Dv FXSAVE .
712 .Pp
713 This request is only valid for i386 programs, both on native 32-bit
714 systems and on amd64 kernels.
715 For 64-bit amd64 programs, the XMM state is reported as part of
716 the FPU state returned by the
717 .Dv PT_GETFPREGS
718 request.
719 .Pp
720 The
721 .Fa data
722 argument is ignored.
723 .It Dv PT_SETXMMREGS
724 Load the XMM FPU state for the thread from the buffer pointed to
725 by the argument
726 .Fa addr .
727 The buffer has the same layout as the 32-bit load buffer for the
728 machine instruction
729 .Dv FXRSTOR .
730 .Pp
731 As with
732 .Dv PT_GETXMMREGS,
733 this request is only valid for i386 programs.
734 .Pp
735 The
736 .Fa data
737 argument is ignored.
738 .It Dv PT_GETXSTATE_INFO
739 Report which XSAVE FPU extensions are supported by the CPU
740 and allowed in userspace programs.
741 The
742 .Fa addr
743 argument must point to a variable of type
744 .Vt struct ptrace_xstate_info ,
745 which contains the information on the request return.
746 .Vt struct ptrace_xstate_info
747 is defined as follows:
748 .Bd -literal
749 struct ptrace_xstate_info {
750         uint64_t        xsave_mask;
751         uint32_t        xsave_len;
752 };
753 .Ed
754 The
755 .Dv xsave_mask
756 field is a bitmask of the currently enabled extensions.
757 The meaning of the bits is defined in the Intel and AMD
758 processor documentation.
759 The
760 .Dv xsave_len
761 field reports the length of the XSAVE area for storing the hardware
762 state for currently enabled extensions in the format defined by the x86
763 .Dv XSAVE
764 machine instruction.
765 .Pp
766 The
767 .Fa data
768 argument value must be equal to the size of the
769 .Vt struct ptrace_xstate_info .
770 .It Dv PT_GETXSTATE
771 Return the content of the XSAVE area for the thread.
772 The
773 .Fa addr
774 argument points to the buffer where the content is copied, and the
775 .Fa data
776 argument specifies the size of the buffer.
777 The kernel copies out as much content as allowed by the buffer size.
778 The buffer layout is specified by the layout of the save area for the
779 .Dv XSAVE
780 machine instruction.
781 .It Dv PT_SETXSTATE
782 Load the XSAVE state for the thread from the buffer specified by the
783 .Fa addr
784 pointer.
785 The buffer size is passed in the
786 .Fa data
787 argument.
788 The buffer must be at least as large as the
789 .Vt struct savefpu
790 (defined in
791 .Pa x86/fpu.h )
792 to allow the complete x87 FPU and XMM state load.
793 It must not be larger than the XSAVE state length, as reported by the
794 .Dv xsave_len
795 field from the
796 .Vt struct ptrace_xstate_info
797 of the
798 .Dv PT_GETXSTATE_INFO
799 request.
800 Layout of the buffer is identical to the layout of the load area for the
801 .Dv XRSTOR
802 machine instruction.
803 .It Dv PT_GETFSBASE
804 Return the value of the base used when doing segmented
805 memory addressing using the %fs segment register.
806 The
807 .Fa addr
808 argument points to an
809 .Vt unsigned long
810 variable where the base value is stored.
811 .Pp
812 The
813 .Fa data
814 argument is ignored.
815 .It Dv PT_GETGSBASE
816 Like the
817 .Dv PT_GETFSBASE
818 request, but returns the base for the %gs segment register.
819 .It Dv PT_SETFSBASE
820 Set the base for the %fs segment register to the value pointed to
821 by the
822 .Fa addr
823 argument.
824 .Fa addr
825 must point to the
826 .Vt unsigned long
827 variable containing the new base.
828 .Pp
829 The
830 .Fa data
831 argument is ignored.
832 .It Dv PT_SETGSBASE
833 Like the
834 .Dv PT_SETFSBASE
835 request, but sets the base for the %gs segment register.
836 .El
837 .Sh PowerPC MACHINE-SPECIFIC REQUESTS
838 .Bl -tag -width "Dv PT_SETVRREGS"
839 .It Dv PT_GETVRREGS
840 Return the thread's
841 .Dv ALTIVEC
842 machine state in the buffer pointed to by
843 .Fa addr .
844 .Pp
845 The
846 .Fa data
847 argument is ignored.
848 .It Dv PT_SETVRREGS
849 Set the thread's
850 .Dv ALTIVEC
851 machine state from the buffer pointed to by
852 .Fa addr .
853 .Pp
854 The
855 .Fa data
856 argument is ignored.
857 .El
858 .Pp
859 Additionally, other machine-specific requests can exist.
860 .Sh RETURN VALUES
861 Some requests can cause
862 .Fn ptrace
863 to return
864 \-1
865 as a non-error value; to disambiguate,
866 .Va errno
867 can be set to 0 before the call and checked afterwards.
868 .Sh ERRORS
869 The
870 .Fn ptrace
871 system call may fail if:
872 .Bl -tag -width Er
873 .It Bq Er ESRCH
874 .Bl -bullet -compact
875 .It
876 No process having the specified process ID exists.
877 .El
878 .It Bq Er EINVAL
879 .Bl -bullet -compact
880 .It
881 A process attempted to use
882 .Dv PT_ATTACH
883 on itself.
884 .It
885 The
886 .Fa request
887 argument
888 was not one of the legal requests.
889 .It
890 The signal number
891 (in
892 .Fa data )
893 to
894 .Dv PT_CONTINUE
895 was neither 0 nor a legal signal number.
896 .It
897 .Dv PT_GETREGS ,
898 .Dv PT_SETREGS ,
899 .Dv PT_GETFPREGS ,
900 .Dv PT_SETFPREGS ,
901 .Dv PT_GETDBREGS ,
902 or
903 .Dv PT_SETDBREGS
904 was attempted on a process with no valid register set.
905 (This is normally true only of system processes.)
906 .It
907 .Dv PT_VM_ENTRY
908 was given an invalid value for
909 .Fa pve_entry .
910 This can also be caused by changes to the VM map of the process.
911 .It
912 The size (in
913 .Fa data )
914 provided to
915 .Dv PT_LWPINFO
916 was less than or equal to zero, or larger than the
917 .Vt ptrace_lwpinfo
918 structure known to the kernel.
919 .It
920 The size (in
921 .Fa data )
922 provided to the x86-specific
923 .Dv PT_GETXSTATE_INFO
924 request was not equal to the size of the
925 .Vt struct ptrace_xstate_info .
926 .It
927 The size (in
928 .Fa data )
929 provided to the x86-specific
930 .Dv PT_SETXSTATE
931 request was less than the size of the x87 plus the XMM save area.
932 .It
933 The size (in
934 .Fa data )
935 provided to the x86-specific
936 .Dv PT_SETXSTATE
937 request was larger than returned in the
938 .Dv xsave_len
939 member of the
940 .Vt struct ptrace_xstate_info
941 from the
942 .Dv PT_GETXSTATE_INFO
943 request.
944 .It
945 The base value, provided to the amd64-specific requests
946 .Dv PT_SETFSBASE
947 or
948 .Dv PT_SETGSBASE ,
949 pointed outside of the valid user address space.
950 This error will not occur in 32-bit programs.
951 .El
952 .It Bq Er EBUSY
953 .Bl -bullet -compact
954 .It
955 .Dv PT_ATTACH
956 was attempted on a process that was already being traced.
957 .It
958 A request attempted to manipulate a process that was being traced by
959 some process other than the one making the request.
960 .It
961 A request
962 (other than
963 .Dv PT_ATTACH )
964 specified a process that was not stopped.
965 .El
966 .It Bq Er EPERM
967 .Bl -bullet -compact
968 .It
969 A request
970 (other than
971 .Dv PT_ATTACH )
972 attempted to manipulate a process that was not being traced at all.
973 .It
974 An attempt was made to use
975 .Dv PT_ATTACH
976 on a process in violation of the requirements listed under
977 .Dv PT_ATTACH
978 above.
979 .El
980 .It Bq Er ENOENT
981 .Bl -bullet -compact
982 .It
983 .Dv PT_VM_ENTRY
984 previously returned the last entry of the memory map.
985 No more entries exist.
986 .El
987 .It Bq Er ENAMETOOLONG
988 .Bl -bullet -compact
989 .It
990 .Dv PT_VM_ENTRY
991 cannot return the pathname of the backing object because the buffer is not big
992 enough.
993 .Fa pve_pathlen
994 holds the minimum buffer size required on return.
995 .El
996 .El
997 .Sh SEE ALSO
998 .Xr execve 2 ,
999 .Xr sigaction 2 ,
1000 .Xr wait 2 ,
1001 .Xr execv 3 ,
1002 .Xr i386_clr_watch 3 ,
1003 .Xr i386_set_watch 3
1004 .Sh HISTORY
1005 The
1006 .Fn ptrace
1007 function appeared in
1008 .At v7 .