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