18269e767SBrooks Davis.\" $NetBSD: ptrace.2,v 1.2 1995/02/27 12:35:37 cgd Exp $ 28269e767SBrooks Davis.\" 38269e767SBrooks Davis.\" This file is in the public domain. 48269e767SBrooks Davis.Dd August 18, 2023 58269e767SBrooks Davis.Dt PTRACE 2 68269e767SBrooks Davis.Os 78269e767SBrooks Davis.Sh NAME 88269e767SBrooks Davis.Nm ptrace 98269e767SBrooks Davis.Nd process tracing and debugging 108269e767SBrooks Davis.Sh LIBRARY 118269e767SBrooks Davis.Lb libc 128269e767SBrooks Davis.Sh SYNOPSIS 138269e767SBrooks Davis.In sys/types.h 148269e767SBrooks Davis.In sys/ptrace.h 158269e767SBrooks Davis.Ft int 168269e767SBrooks Davis.Fn ptrace "int request" "pid_t pid" "caddr_t addr" "int data" 178269e767SBrooks Davis.Sh DESCRIPTION 188269e767SBrooks DavisThe 198269e767SBrooks Davis.Fn ptrace 208269e767SBrooks Davissystem call 218269e767SBrooks Davisprovides tracing and debugging facilities. 228269e767SBrooks DavisIt allows one process 238269e767SBrooks Davis(the 248269e767SBrooks Davis.Em tracing 258269e767SBrooks Davisprocess) 268269e767SBrooks Davisto control another 278269e767SBrooks Davis(the 288269e767SBrooks Davis.Em traced 298269e767SBrooks Davisprocess). 308269e767SBrooks DavisThe tracing process must first attach to the traced process, and then 318269e767SBrooks Davisissue a series of 328269e767SBrooks Davis.Fn ptrace 338269e767SBrooks Davissystem calls to control the execution of the process, as well as access 348269e767SBrooks Davisprocess memory and register state. 358269e767SBrooks DavisFor the duration of the tracing session, the traced process will be 368269e767SBrooks Davis.Dq re-parented , 378269e767SBrooks Daviswith its parent process ID (and resulting behavior) 388269e767SBrooks Davischanged to the tracing process. 398269e767SBrooks DavisIt is permissible for a tracing process to attach to more than one 408269e767SBrooks Davisother process at a time. 418269e767SBrooks DavisWhen the tracing process has completed its work, it must detach the 428269e767SBrooks Davistraced process; if a tracing process exits without first detaching all 438269e767SBrooks Davisprocesses it has attached, those processes will be killed. 448269e767SBrooks Davis.Pp 458269e767SBrooks DavisMost of the time, the traced process runs normally, but when it 468269e767SBrooks Davisreceives a signal 478269e767SBrooks Davis(see 488269e767SBrooks Davis.Xr sigaction 2 ) , 498269e767SBrooks Davisit stops. 508269e767SBrooks DavisThe tracing process is expected to notice this via 518269e767SBrooks Davis.Xr wait 2 528269e767SBrooks Davisor the delivery of a 538269e767SBrooks Davis.Dv SIGCHLD 548269e767SBrooks Davissignal, examine the state of the stopped process, and cause it to 558269e767SBrooks Davisterminate or continue as appropriate. 568269e767SBrooks DavisThe signal may be a normal process signal, generated as a result of 578269e767SBrooks Davistraced process behavior, or use of the 588269e767SBrooks Davis.Xr kill 2 598269e767SBrooks Davissystem call; alternatively, it may be generated by the tracing facility 608269e767SBrooks Davisas a result of attaching, stepping by the tracing 618269e767SBrooks Davisprocess, 628269e767SBrooks Davisor an event in the traced process. 638269e767SBrooks DavisThe tracing process may choose to intercept the signal, using it to 648269e767SBrooks Davisobserve process behavior (such as 658269e767SBrooks Davis.Dv SIGTRAP ) , 668269e767SBrooks Davisor forward the signal to the process if appropriate. 678269e767SBrooks DavisThe 688269e767SBrooks Davis.Fn ptrace 698269e767SBrooks Davissystem call 708269e767SBrooks Davisis the mechanism by which all this happens. 718269e767SBrooks Davis.Pp 728269e767SBrooks DavisA traced process may report additional signal stops corresponding to 738269e767SBrooks Davisevents in the traced process. 748269e767SBrooks DavisThese additional signal stops are reported as 758269e767SBrooks Davis.Dv SIGTRAP 768269e767SBrooks Davisor 778269e767SBrooks Davis.Dv SIGSTOP 788269e767SBrooks Davissignals. 798269e767SBrooks DavisThe tracing process can use the 808269e767SBrooks Davis.Dv PT_LWPINFO 818269e767SBrooks Davisrequest to determine which events are associated with a 828269e767SBrooks Davis.Dv SIGTRAP 838269e767SBrooks Davisor 848269e767SBrooks Davis.Dv SIGSTOP 858269e767SBrooks Davissignal. 868269e767SBrooks DavisNote that multiple events may be associated with a single signal. 878269e767SBrooks DavisFor example, events indicated by the 888269e767SBrooks Davis.Dv PL_FLAG_BORN , 898269e767SBrooks Davis.Dv PL_FLAG_FORKED , 908269e767SBrooks Davisand 918269e767SBrooks Davis.Dv PL_FLAG_EXEC 928269e767SBrooks Davisflags are also reported as a system call exit event 938269e767SBrooks Davis.Pq Dv PL_FLAG_SCX . 948269e767SBrooks DavisThe signal stop for a new child process enabled via 958269e767SBrooks Davis.Dv PTRACE_FORK 968269e767SBrooks Daviswill report a 978269e767SBrooks Davis.Dv SIGSTOP 988269e767SBrooks Davissignal. 998269e767SBrooks DavisAll other additional signal stops use 1008269e767SBrooks Davis.Dv SIGTRAP . 1018269e767SBrooks Davis.Sh DETACH AND TERMINATION 1028269e767SBrooks Davis.Pp 1038269e767SBrooks DavisNormally, exiting tracing process should wait for all pending 1048269e767SBrooks Davisdebugging events and then detach from all alive traced processes 1058269e767SBrooks Davisbefore exiting using 1068269e767SBrooks Davis.Dv PT_DETACH 1078269e767SBrooks Davisrequest. 1088269e767SBrooks DavisIf tracing process exits without detaching, for instance due to abnormal 1098269e767SBrooks Davistermination, the destiny of the traced children processes is determined 1108269e767SBrooks Davisby the 1118269e767SBrooks Davis.Dv kern.kill_on_debugger_exit 1128269e767SBrooks Davissysctl control. 1138269e767SBrooks Davis.Pp 1148269e767SBrooks DavisIf the control is set to the default value 1, such traced processes 1158269e767SBrooks Davisare terminated. 1168269e767SBrooks DavisIf set to zero, kernel implicitly detaches traced processes. 1178269e767SBrooks DavisTraced processes are un-stopped if needed, and then continue the execution 1188269e767SBrooks Daviswithout tracing. 1198269e767SBrooks DavisKernel drops any 1208269e767SBrooks Davis.Dv SIGTRAP 1218269e767SBrooks Davissignals queued to the traced children, which could be either generated by 1228269e767SBrooks Davisnot yet consumed debug events, or sent by other means, the later should 1238269e767SBrooks Davisnot be done anyway. 1248269e767SBrooks Davis.Sh SELECTING THE TARGET 1258269e767SBrooks DavisThe 1268269e767SBrooks Davis.Fa pid 1278269e767SBrooks Davisargument of the call specifies the target on which to perform 1288269e767SBrooks Davisthe requested operation. 1298269e767SBrooks DavisFor operations affecting the global process state, the process ID 1308269e767SBrooks Davisis typically passed there. 1318269e767SBrooks DavisSimilarly, for operations affecting only a thread, the thread ID 1328269e767SBrooks Davisneeds to be passed. 1338269e767SBrooks Davis.Pp 1348269e767SBrooks DavisStill, for global operations, the ID of any thread can be used as the 1358269e767SBrooks Davistarget, and system will perform the request on the process owning 1368269e767SBrooks Davisthat thread. 1378269e767SBrooks DavisIf a thread operation got the process ID as 1388269e767SBrooks Davis.Fa pid , 1398269e767SBrooks Davisthe system randomly selects a thread from among the threads owned 1408269e767SBrooks Davisby the process. 1418269e767SBrooks DavisFor single-threaded processes there is no difference between specifying 1428269e767SBrooks Davisprocess or thread ID as the target. 1438269e767SBrooks Davis.Sh DISABLING PTRACE 1448269e767SBrooks DavisThe 1458269e767SBrooks Davis.Nm 1468269e767SBrooks Davissubsystem provides rich facilities to manipulate other processes state. 1478269e767SBrooks DavisSometimes it may be desirable to disallow it either completely, or limit 1488269e767SBrooks Davisits scope. 1498269e767SBrooks DavisThe following controls are provided for this: 1508269e767SBrooks Davis.Bl -tag -width security.bsd.unprivileged_proc_debug 1518269e767SBrooks Davis.It Dv security.bsd.allow_ptrace 1528269e767SBrooks DavisSetting this sysctl to zero makes 1538269e767SBrooks Davis.Nm 1548269e767SBrooks Davisreturn 1558269e767SBrooks Davis.Er ENOSYS 1568269e767SBrooks Davisalways as if the syscall is not implemented by the kernel. 1578269e767SBrooks Davis.It Dv security.bsd.unprivileged_proc_debug 1588269e767SBrooks DavisSetting this sysctl to zero disallows the use of 1598269e767SBrooks Davis.Fn ptrace 1608269e767SBrooks Davisby unprivileged processes. 1618269e767SBrooks Davis.It Dv security.bsd.see_other_uids 1628269e767SBrooks DavisSetting this sysctl to zero prevents 1638269e767SBrooks Davis.Fn ptrace 1648269e767SBrooks Davisrequests from targeting processes with a real user identifier different 1658269e767SBrooks Davisfrom the caller's. 1668269e767SBrooks DavisThese requests will fail with error 1678269e767SBrooks Davis.Er ESRCH . 1688269e767SBrooks Davis.It Dv security.bsd.see_other_gids 1698269e767SBrooks DavisSetting this sysctl to zero disallows 1708269e767SBrooks Davis.Fn ptrace 1718269e767SBrooks Davisrequests from processes that have no groups in common with the target process, 1728269e767SBrooks Davisconsidering their sets of real and supplementary groups. 1738269e767SBrooks DavisThese requests will fail with error 1748269e767SBrooks Davis.Er ESRCH . 1758269e767SBrooks Davis.It Dv security.bsd.see_jail_proc 1768269e767SBrooks DavisSetting this sysctl to zero disallows 1778269e767SBrooks Davis.Fn ptrace 1788269e767SBrooks Davisrequests from processes belonging to a different jail than that of the target 1798269e767SBrooks Davisprocess, even if the requesting process' jail is an ancestor of the target 1808269e767SBrooks Davisprocess'. 1818269e767SBrooks DavisThese requests will fail with error 1828269e767SBrooks Davis.Er ESRCH . 1838269e767SBrooks Davis.It Dv securelevel and init 1848269e767SBrooks DavisThe 1858269e767SBrooks Davis.Xr init 1 1868269e767SBrooks Davisprocess can only be traced with 1878269e767SBrooks Davis.Nm 1888269e767SBrooks Davisif securelevel is zero. 1898269e767SBrooks Davis.It Dv procctl(2) PROC_TRACE_CTL 1908269e767SBrooks DavisProcess can deny attempts to trace itself with 1918269e767SBrooks Davis.Xr procctl 2 1928269e767SBrooks Davis.Dv PROC_TRACE_CTL 1938269e767SBrooks Davisrequest. 1948269e767SBrooks DavisIn this case requests return 1958269e767SBrooks Davis.Xr EPERM 1968269e767SBrooks Daviserror. 1978269e767SBrooks Davis.El 1988269e767SBrooks Davis.Sh TRACING EVENTS 1998269e767SBrooks Davis.Pp 2008269e767SBrooks DavisEach traced process has a tracing event mask. 2018269e767SBrooks DavisAn event in the traced process only reports a 2028269e767SBrooks Davissignal stop if the corresponding flag is set in the tracing event mask. 2038269e767SBrooks DavisThe current set of tracing event flags include: 2048269e767SBrooks Davis.Bl -tag -width "Dv PTRACE_SYSCALL" 2058269e767SBrooks Davis.It Dv PTRACE_EXEC 2068269e767SBrooks DavisReport a stop for a successful invocation of 2078269e767SBrooks Davis.Xr execve 2 . 2088269e767SBrooks DavisThis event is indicated by the 2098269e767SBrooks Davis.Dv PL_FLAG_EXEC 2108269e767SBrooks Davisflag in the 2118269e767SBrooks Davis.Va pl_flags 2128269e767SBrooks Davismember of 2138269e767SBrooks Davis.Vt "struct ptrace_lwpinfo" . 2148269e767SBrooks Davis.It Dv PTRACE_SCE 2158269e767SBrooks DavisReport a stop on each system call entry. 2168269e767SBrooks DavisThis event is indicated by the 2178269e767SBrooks Davis.Dv PL_FLAG_SCE 2188269e767SBrooks Davisflag in the 2198269e767SBrooks Davis.Va pl_flags 2208269e767SBrooks Davismember of 2218269e767SBrooks Davis.Vt "struct ptrace_lwpinfo" . 2228269e767SBrooks Davis.It Dv PTRACE_SCX 2238269e767SBrooks DavisReport a stop on each system call exit. 2248269e767SBrooks DavisThis event is indicated by the 2258269e767SBrooks Davis.Dv PL_FLAG_SCX 2268269e767SBrooks Davisflag in the 2278269e767SBrooks Davis.Va pl_flags 2288269e767SBrooks Davismember of 2298269e767SBrooks Davis.Vt "struct ptrace_lwpinfo" . 2308269e767SBrooks Davis.It Dv PTRACE_SYSCALL 2318269e767SBrooks DavisReport stops for both system call entry and exit. 2328269e767SBrooks Davis.It Dv PTRACE_FORK 2338269e767SBrooks DavisThis event flag controls tracing for new child processes of a traced process. 2348269e767SBrooks Davis.Pp 2358269e767SBrooks DavisWhen this event flag is enabled, 2368269e767SBrooks Davisnew child processes will enable tracing and stop before executing their 2378269e767SBrooks Davisfirst instruction. 2388269e767SBrooks DavisThe new child process will include the 2398269e767SBrooks Davis.Dv PL_FLAG_CHILD 2408269e767SBrooks Davisflag in the 2418269e767SBrooks Davis.Va pl_flags 2428269e767SBrooks Davismember of 2438269e767SBrooks Davis.Vt "struct ptrace_lwpinfo" . 2448269e767SBrooks DavisThe traced process will report a stop that includes the 2458269e767SBrooks Davis.Dv PL_FLAG_FORKED 2468269e767SBrooks Davisflag. 2478269e767SBrooks DavisThe process ID of the new child process will also be present in the 2488269e767SBrooks Davis.Va pl_child_pid 2498269e767SBrooks Davismember of 2508269e767SBrooks Davis.Vt "struct ptrace_lwpinfo" . 2518269e767SBrooks DavisIf the new child process was created via 2528269e767SBrooks Davis.Xr vfork 2 , 2538269e767SBrooks Davisthe traced process's stop will also include the 2548269e767SBrooks Davis.Dv PL_FLAG_VFORKED 2558269e767SBrooks Davisflag. 2568269e767SBrooks DavisNote that new child processes will be attached with the default 2578269e767SBrooks Davistracing event mask; 2588269e767SBrooks Davisthey do not inherit the event mask of the traced process. 2598269e767SBrooks Davis.Pp 2608269e767SBrooks DavisWhen this event flag is not enabled, 2618269e767SBrooks Davisnew child processes will execute without tracing enabled. 2628269e767SBrooks Davis.It Dv PTRACE_LWP 2638269e767SBrooks DavisThis event flag controls tracing of LWP 2648269e767SBrooks Davis.Pq kernel thread 2658269e767SBrooks Daviscreation and destruction. 2668269e767SBrooks DavisWhen this event is enabled, 2678269e767SBrooks Davisnew LWPs will stop and report an event with 2688269e767SBrooks Davis.Dv PL_FLAG_BORN 2698269e767SBrooks Davisset before executing their first instruction, 2708269e767SBrooks Davisand exiting LWPs will stop and report an event with 2718269e767SBrooks Davis.Dv PL_FLAG_EXITED 2728269e767SBrooks Davisset before completing their termination. 2738269e767SBrooks Davis.Pp 2748269e767SBrooks DavisNote that new processes do not report an event for the creation of their 2758269e767SBrooks Davisinitial thread, 2768269e767SBrooks Davisand exiting processes do not report an event for the termination of the 2778269e767SBrooks Davislast thread. 2788269e767SBrooks Davis.It Dv PTRACE_VFORK 2798269e767SBrooks DavisReport a stop event when a parent process resumes after a 2808269e767SBrooks Davis.Xr vfork 2 . 2818269e767SBrooks Davis.Pp 2828269e767SBrooks DavisWhen a thread in the traced process creates a new child process via 2838269e767SBrooks Davis.Xr vfork 2 , 2848269e767SBrooks Davisthe stop that reports 2858269e767SBrooks Davis.Dv PL_FLAG_FORKED 2868269e767SBrooks Davisand 2878269e767SBrooks Davis.Dv PL_FLAG_SCX 2888269e767SBrooks Davisoccurs just after the child process is created, 2898269e767SBrooks Davisbut before the thread waits for the child process to stop sharing process 2908269e767SBrooks Davismemory. 2918269e767SBrooks DavisIf a debugger is not tracing the new child process, 2928269e767SBrooks Davisit must ensure that no breakpoints are enabled in the shared process 2938269e767SBrooks Davismemory before detaching from the new child process. 2948269e767SBrooks DavisThis means that no breakpoints are enabled in the parent process either. 2958269e767SBrooks Davis.Pp 2968269e767SBrooks DavisThe 2978269e767SBrooks Davis.Dv PTRACE_VFORK 2988269e767SBrooks Davisflag enables a new stop that indicates when the new child process stops 2998269e767SBrooks Davissharing the process memory of the parent process. 3008269e767SBrooks DavisA debugger can reinsert breakpoints in the parent process and resume it 3018269e767SBrooks Davisin response to this event. 3028269e767SBrooks DavisThis event is indicated by setting the 3038269e767SBrooks Davis.Dv PL_FLAG_VFORK_DONE 3048269e767SBrooks Davisflag. 3058269e767SBrooks Davis.El 3068269e767SBrooks Davis.Pp 3078269e767SBrooks DavisThe default tracing event mask when attaching to a process via 3088269e767SBrooks Davis.Dv PT_ATTACH , 3098269e767SBrooks Davis.Dv PT_TRACE_ME , 3108269e767SBrooks Davisor 3118269e767SBrooks Davis.Dv PTRACE_FORK 3128269e767SBrooks Davisincludes only 3138269e767SBrooks Davis.Dv PTRACE_EXEC 3148269e767SBrooks Davisevents. 3158269e767SBrooks DavisAll other event flags are disabled. 3168269e767SBrooks Davis.Sh PTRACE REQUESTS 3178269e767SBrooks Davis.Pp 3188269e767SBrooks DavisThe 3198269e767SBrooks Davis.Fa request 3208269e767SBrooks Davisargument specifies what operation is being performed; the meaning of 3218269e767SBrooks Davisthe rest of the arguments depends on the operation, but except for one 3228269e767SBrooks Davisspecial case noted below, all 3238269e767SBrooks Davis.Fn ptrace 3248269e767SBrooks Daviscalls are made by the tracing process, and the 3258269e767SBrooks Davis.Fa pid 3268269e767SBrooks Davisargument specifies the process ID of the traced process 3278269e767SBrooks Davisor a corresponding thread ID. 3288269e767SBrooks DavisThe 3298269e767SBrooks Davis.Fa request 3308269e767SBrooks Davisargument 3318269e767SBrooks Daviscan be: 3328269e767SBrooks Davis.Bl -tag -width "Dv PT_GET_EVENT_MASK" 3338269e767SBrooks Davis.It Dv PT_TRACE_ME 3348269e767SBrooks DavisThis request is the only one used by the traced process; it declares 3358269e767SBrooks Davisthat the process expects to be traced by its parent. 3368269e767SBrooks DavisAll the other arguments are ignored. 3378269e767SBrooks Davis(If the parent process does not expect to trace the child, it will 3388269e767SBrooks Davisprobably be rather confused by the results; once the traced process 3398269e767SBrooks Davisstops, it cannot be made to continue except via 3408269e767SBrooks Davis.Fn ptrace . ) 3418269e767SBrooks DavisWhen a process has used this request and calls 3428269e767SBrooks Davis.Xr execve 2 3438269e767SBrooks Davisor any of the routines built on it 3448269e767SBrooks Davis(such as 3458269e767SBrooks Davis.Xr execv 3 ) , 3468269e767SBrooks Davisit will stop before executing the first instruction of the new image. 3478269e767SBrooks DavisAlso, any setuid or setgid bits on the executable being executed will 3488269e767SBrooks Davisbe ignored. 3498269e767SBrooks DavisIf the child was created by 3508269e767SBrooks Davis.Xr vfork 2 3518269e767SBrooks Davissystem call or 3528269e767SBrooks Davis.Xr rfork 2 3538269e767SBrooks Daviscall with the 3548269e767SBrooks Davis.Dv RFMEM 3558269e767SBrooks Davisflag specified, the debugging events are reported to the parent 3568269e767SBrooks Davisonly after the 3578269e767SBrooks Davis.Xr execve 2 3588269e767SBrooks Davisis executed. 3598269e767SBrooks Davis.It Dv PT_READ_I , Dv PT_READ_D 3608269e767SBrooks DavisThese requests read a single 3618269e767SBrooks Davis.Vt int 3628269e767SBrooks Davisof data from the traced process's address space. 3638269e767SBrooks DavisTraditionally, 3648269e767SBrooks Davis.Fn ptrace 3658269e767SBrooks Davishas allowed for machines with distinct address spaces for instruction 3668269e767SBrooks Davisand data, which is why there are two requests: conceptually, 3678269e767SBrooks Davis.Dv PT_READ_I 3688269e767SBrooks Davisreads from the instruction space and 3698269e767SBrooks Davis.Dv PT_READ_D 3708269e767SBrooks Davisreads from the data space. 3718269e767SBrooks DavisIn the current 3728269e767SBrooks Davis.Fx 3738269e767SBrooks Davisimplementation, these two requests are completely identical. 3748269e767SBrooks DavisThe 3758269e767SBrooks Davis.Fa addr 3768269e767SBrooks Davisargument specifies the address 3778269e767SBrooks Davis(in the traced process's virtual address space) 3788269e767SBrooks Davisat which the read is to be done. 3798269e767SBrooks DavisThis address does not have to meet any alignment constraints. 3808269e767SBrooks DavisThe value read is returned as the return value from 3818269e767SBrooks Davis.Fn ptrace . 3828269e767SBrooks Davis.It Dv PT_WRITE_I , Dv PT_WRITE_D 3838269e767SBrooks DavisThese requests parallel 3848269e767SBrooks Davis.Dv PT_READ_I 3858269e767SBrooks Davisand 3868269e767SBrooks Davis.Dv PT_READ_D , 3878269e767SBrooks Davisexcept that they write rather than read. 3888269e767SBrooks DavisThe 3898269e767SBrooks Davis.Fa data 3908269e767SBrooks Davisargument supplies the value to be written. 3918269e767SBrooks Davis.It Dv PT_IO 3928269e767SBrooks DavisThis request allows reading and writing arbitrary amounts of data in 3938269e767SBrooks Davisthe traced process's address space. 3948269e767SBrooks DavisThe 3958269e767SBrooks Davis.Fa addr 3968269e767SBrooks Davisargument specifies a pointer to a 3978269e767SBrooks Davis.Vt "struct ptrace_io_desc" , 3988269e767SBrooks Daviswhich is defined as follows: 3998269e767SBrooks Davis.Bd -literal 4008269e767SBrooks Davisstruct ptrace_io_desc { 4018269e767SBrooks Davis int piod_op; /* I/O operation */ 4028269e767SBrooks Davis void *piod_offs; /* child offset */ 4038269e767SBrooks Davis void *piod_addr; /* parent offset */ 4048269e767SBrooks Davis size_t piod_len; /* request length */ 4058269e767SBrooks Davis}; 4068269e767SBrooks Davis 4078269e767SBrooks Davis/* 4088269e767SBrooks Davis * Operations in piod_op. 4098269e767SBrooks Davis */ 4108269e767SBrooks Davis#define PIOD_READ_D 1 /* Read from D space */ 4118269e767SBrooks Davis#define PIOD_WRITE_D 2 /* Write to D space */ 4128269e767SBrooks Davis#define PIOD_READ_I 3 /* Read from I space */ 4138269e767SBrooks Davis#define PIOD_WRITE_I 4 /* Write to I space */ 4148269e767SBrooks Davis.Ed 4158269e767SBrooks Davis.Pp 4168269e767SBrooks DavisThe 4178269e767SBrooks Davis.Fa data 4188269e767SBrooks Davisargument is ignored. 4198269e767SBrooks DavisThe actual number of bytes read or written is stored in 4208269e767SBrooks Davis.Va piod_len 4218269e767SBrooks Davisupon return. 4228269e767SBrooks Davis.It Dv PT_CONTINUE 4238269e767SBrooks DavisThe traced process continues execution. 4248269e767SBrooks DavisThe 4258269e767SBrooks Davis.Fa addr 4268269e767SBrooks Davisargument 4278269e767SBrooks Davisis an address specifying the place where execution is to be resumed 4288269e767SBrooks Davis(a new value for the program counter), 4298269e767SBrooks Davisor 4308269e767SBrooks Davis.Po Vt caddr_t Pc Ns 1 4318269e767SBrooks Davisto indicate that execution is to pick up where it left off. 4328269e767SBrooks DavisThe 4338269e767SBrooks Davis.Fa data 4348269e767SBrooks Davisargument 4358269e767SBrooks Davisprovides a signal number to be delivered to the traced process as it 4368269e767SBrooks Davisresumes execution, or 0 if no signal is to be sent. 4378269e767SBrooks Davis.It Dv PT_STEP 4388269e767SBrooks DavisThe traced process is single stepped one instruction. 4398269e767SBrooks DavisThe 4408269e767SBrooks Davis.Fa addr 4418269e767SBrooks Davisargument 4428269e767SBrooks Davisshould be passed 4438269e767SBrooks Davis.Po Vt caddr_t Pc Ns 1 . 4448269e767SBrooks DavisThe 4458269e767SBrooks Davis.Fa data 4468269e767SBrooks Davisargument 4478269e767SBrooks Davisprovides a signal number to be delivered to the traced process as it 4488269e767SBrooks Davisresumes execution, or 0 if no signal is to be sent. 4498269e767SBrooks Davis.It Dv PT_KILL 4508269e767SBrooks DavisThe traced process terminates, as if 4518269e767SBrooks Davis.Dv PT_CONTINUE 4528269e767SBrooks Davishad been used with 4538269e767SBrooks Davis.Dv SIGKILL 4548269e767SBrooks Davisgiven as the signal to be delivered. 4558269e767SBrooks Davis.It Dv PT_ATTACH 4568269e767SBrooks DavisThis request allows a process to gain control of an otherwise 4578269e767SBrooks Davisunrelated process and begin tracing it. 4588269e767SBrooks DavisIt does not need any cooperation from the process to trace. 4598269e767SBrooks DavisIn 4608269e767SBrooks Davisthis case, 4618269e767SBrooks Davis.Fa pid 4628269e767SBrooks Davisspecifies the process ID of the process to trace, and the other 4638269e767SBrooks Davistwo arguments are ignored. 4648269e767SBrooks DavisThis request requires that the target process must have the same real 4658269e767SBrooks DavisUID as the tracing process, and that it must not be executing a setuid 4668269e767SBrooks Davisor setgid executable. 4678269e767SBrooks Davis(If the tracing process is running as root, these restrictions do not 4688269e767SBrooks Davisapply.) 4698269e767SBrooks DavisThe tracing process will see the newly-traced process stop and may 4708269e767SBrooks Davisthen control it as if it had been traced all along. 4718269e767SBrooks Davis.It Dv PT_DETACH 4728269e767SBrooks DavisThis request is like PT_CONTINUE, except that it does not allow 4738269e767SBrooks Davisspecifying an alternate place to continue execution, and after it 4748269e767SBrooks Davissucceeds, the traced process is no longer traced and continues 4758269e767SBrooks Davisexecution normally. 4768269e767SBrooks Davis.It Dv PT_GETREGS 4778269e767SBrooks DavisThis request reads the traced process's machine registers into the 4788269e767SBrooks Davis.Do 4798269e767SBrooks Davis.Vt "struct reg" 4808269e767SBrooks Davis.Dc 4818269e767SBrooks Davis(defined in 4828269e767SBrooks Davis.In machine/reg.h ) 4838269e767SBrooks Davispointed to by 4848269e767SBrooks Davis.Fa addr . 4858269e767SBrooks Davis.It Dv PT_SETREGS 4868269e767SBrooks DavisThis request is the converse of 4878269e767SBrooks Davis.Dv PT_GETREGS ; 4888269e767SBrooks Davisit loads the traced process's machine registers from the 4898269e767SBrooks Davis.Do 4908269e767SBrooks Davis.Vt "struct reg" 4918269e767SBrooks Davis.Dc 4928269e767SBrooks Davis(defined in 4938269e767SBrooks Davis.In machine/reg.h ) 4948269e767SBrooks Davispointed to by 4958269e767SBrooks Davis.Fa addr . 4968269e767SBrooks Davis.It Dv PT_GETFPREGS 4978269e767SBrooks DavisThis request reads the traced process's floating-point registers into 4988269e767SBrooks Davisthe 4998269e767SBrooks Davis.Do 5008269e767SBrooks Davis.Vt "struct fpreg" 5018269e767SBrooks Davis.Dc 5028269e767SBrooks Davis(defined in 5038269e767SBrooks Davis.In machine/reg.h ) 5048269e767SBrooks Davispointed to by 5058269e767SBrooks Davis.Fa addr . 5068269e767SBrooks Davis.It Dv PT_SETFPREGS 5078269e767SBrooks DavisThis request is the converse of 5088269e767SBrooks Davis.Dv PT_GETFPREGS ; 5098269e767SBrooks Davisit loads the traced process's floating-point registers from the 5108269e767SBrooks Davis.Do 5118269e767SBrooks Davis.Vt "struct fpreg" 5128269e767SBrooks Davis.Dc 5138269e767SBrooks Davis(defined in 5148269e767SBrooks Davis.In machine/reg.h ) 5158269e767SBrooks Davispointed to by 5168269e767SBrooks Davis.Fa addr . 5178269e767SBrooks Davis.It Dv PT_GETDBREGS 5188269e767SBrooks DavisThis request reads the traced process's debug registers into 5198269e767SBrooks Davisthe 5208269e767SBrooks Davis.Do 5218269e767SBrooks Davis.Vt "struct dbreg" 5228269e767SBrooks Davis.Dc 5238269e767SBrooks Davis(defined in 5248269e767SBrooks Davis.In machine/reg.h ) 5258269e767SBrooks Davispointed to by 5268269e767SBrooks Davis.Fa addr . 5278269e767SBrooks Davis.It Dv PT_SETDBREGS 5288269e767SBrooks DavisThis request is the converse of 5298269e767SBrooks Davis.Dv PT_GETDBREGS ; 5308269e767SBrooks Davisit loads the traced process's debug registers from the 5318269e767SBrooks Davis.Do 5328269e767SBrooks Davis.Vt "struct dbreg" 5338269e767SBrooks Davis.Dc 5348269e767SBrooks Davis(defined in 5358269e767SBrooks Davis.In machine/reg.h ) 5368269e767SBrooks Davispointed to by 5378269e767SBrooks Davis.Fa addr . 5388269e767SBrooks Davis.It Dv PT_GETREGSET 5398269e767SBrooks DavisThis request reads the registers from the traced process. 5408269e767SBrooks DavisThe 5418269e767SBrooks Davis.Fa data 5428269e767SBrooks Davisargument specifies the register set to read, with the 5438269e767SBrooks Davis.Fa addr 5448269e767SBrooks Davisargument pointing at a 5458269e767SBrooks Davis.Vt "struct iovec" 5468269e767SBrooks Daviswhere the 5478269e767SBrooks Davis.Va iov_base 5488269e767SBrooks Davisfield points to a register set specific structure to hold the registers, 5498269e767SBrooks Davisand the 5508269e767SBrooks Davis.Va iov_len 5518269e767SBrooks Davisfield holds the length of the structure. 5528269e767SBrooks Davis.It Dv PT_SETREGSET 5538269e767SBrooks DavisThis request writes to the registers of the traced process. 5548269e767SBrooks DavisThe 5558269e767SBrooks Davis.Fa data 5568269e767SBrooks Davisargument specifies the register set to write to, with the 5578269e767SBrooks Davis.Fa addr 5588269e767SBrooks Davisargument pointing at a 5598269e767SBrooks Davis.Vt "struct iovec" 5608269e767SBrooks Daviswhere the 5618269e767SBrooks Davis.Va iov_base 5628269e767SBrooks Davisfield points to a register set specific structure to hold the registers, 5638269e767SBrooks Davisand the 5648269e767SBrooks Davis.Va iov_len 5658269e767SBrooks Davisfield holds the length of the structure. 5668269e767SBrooks DavisIf 5678269e767SBrooks Davis.Va iov_base 5688269e767SBrooks Davisis NULL the kernel will return the expected length of the register set 5698269e767SBrooks Davisspecific structure in the 5708269e767SBrooks Davis.Va iov_len 5718269e767SBrooks Davisfield and not change the target register set. 5728269e767SBrooks Davis.It Dv PT_LWPINFO 5738269e767SBrooks DavisThis request can be used to obtain information about the kernel thread, 5748269e767SBrooks Davisalso known as light-weight process, that caused the traced process to stop. 5758269e767SBrooks DavisThe 5768269e767SBrooks Davis.Fa addr 5778269e767SBrooks Davisargument specifies a pointer to a 5788269e767SBrooks Davis.Vt "struct ptrace_lwpinfo" , 5798269e767SBrooks Daviswhich is defined as follows: 5808269e767SBrooks Davis.Bd -literal 5818269e767SBrooks Davisstruct ptrace_lwpinfo { 5828269e767SBrooks Davis lwpid_t pl_lwpid; 5838269e767SBrooks Davis int pl_event; 5848269e767SBrooks Davis int pl_flags; 5858269e767SBrooks Davis sigset_t pl_sigmask; 5868269e767SBrooks Davis sigset_t pl_siglist; 5878269e767SBrooks Davis siginfo_t pl_siginfo; 5888269e767SBrooks Davis char pl_tdname[MAXCOMLEN + 1]; 5898269e767SBrooks Davis pid_t pl_child_pid; 5908269e767SBrooks Davis u_int pl_syscall_code; 5918269e767SBrooks Davis u_int pl_syscall_narg; 5928269e767SBrooks Davis}; 5938269e767SBrooks Davis.Ed 5948269e767SBrooks Davis.Pp 5958269e767SBrooks DavisThe 5968269e767SBrooks Davis.Fa data 5978269e767SBrooks Davisargument is to be set to the size of the structure known to the caller. 5988269e767SBrooks DavisThis allows the structure to grow without affecting older programs. 5998269e767SBrooks Davis.Pp 6008269e767SBrooks DavisThe fields in the 6018269e767SBrooks Davis.Vt "struct ptrace_lwpinfo" 6028269e767SBrooks Davishave the following meaning: 6038269e767SBrooks Davis.Bl -tag -width indent -compact 6048269e767SBrooks Davis.It Va pl_lwpid 6058269e767SBrooks DavisLWP id of the thread 6068269e767SBrooks Davis.It Va pl_event 6078269e767SBrooks DavisEvent that caused the stop. 6088269e767SBrooks DavisCurrently defined events are: 6098269e767SBrooks Davis.Bl -tag -width "Dv PL_EVENT_SIGNAL" -compact 6108269e767SBrooks Davis.It Dv PL_EVENT_NONE 6118269e767SBrooks DavisNo reason given 6128269e767SBrooks Davis.It Dv PL_EVENT_SIGNAL 6138269e767SBrooks DavisThread stopped due to the pending signal 6148269e767SBrooks Davis.El 6158269e767SBrooks Davis.It Va pl_flags 6168269e767SBrooks DavisFlags that specify additional details about observed stop. 6178269e767SBrooks DavisCurrently defined flags are: 6188269e767SBrooks Davis.Bl -tag -width indent -compact 6198269e767SBrooks Davis.It Dv PL_FLAG_SCE 6208269e767SBrooks DavisThe thread stopped due to system call entry, right after the kernel is entered. 6218269e767SBrooks DavisThe debugger may examine syscall arguments that are stored in memory and 6228269e767SBrooks Davisregisters according to the ABI of the current process, and modify them, 6238269e767SBrooks Davisif needed. 6248269e767SBrooks Davis.It Dv PL_FLAG_SCX 6258269e767SBrooks DavisThe thread is stopped immediately before syscall is returning to the usermode. 6268269e767SBrooks DavisThe debugger may examine system call return values in the ABI-defined registers 6278269e767SBrooks Davisand/or memory. 6288269e767SBrooks Davis.It Dv PL_FLAG_EXEC 6298269e767SBrooks DavisWhen 6308269e767SBrooks Davis.Dv PL_FLAG_SCX 6318269e767SBrooks Davisis set, this flag may be additionally specified to inform that the 6328269e767SBrooks Davisprogram being executed by debuggee process has been changed by successful 6338269e767SBrooks Davisexecution of a system call from the 6348269e767SBrooks Davis.Fn execve 2 6358269e767SBrooks Davisfamily. 6368269e767SBrooks Davis.It Dv PL_FLAG_SI 6378269e767SBrooks DavisIndicates that 6388269e767SBrooks Davis.Va pl_siginfo 6398269e767SBrooks Davismember of 6408269e767SBrooks Davis.Vt "struct ptrace_lwpinfo" 6418269e767SBrooks Daviscontains valid information. 6428269e767SBrooks Davis.It Dv PL_FLAG_FORKED 6438269e767SBrooks DavisIndicates that the process is returning from a call to 6448269e767SBrooks Davis.Fn fork 2 6458269e767SBrooks Davisthat created a new child process. 6468269e767SBrooks DavisThe process identifier of the new process is available in the 6478269e767SBrooks Davis.Va pl_child_pid 6488269e767SBrooks Davismember of 6498269e767SBrooks Davis.Vt "struct ptrace_lwpinfo" . 6508269e767SBrooks Davis.It Dv PL_FLAG_CHILD 6518269e767SBrooks DavisThe flag is set for first event reported from a new child which is 6528269e767SBrooks Davisautomatically attached when 6538269e767SBrooks Davis.Dv PTRACE_FORK 6548269e767SBrooks Davisis enabled. 6558269e767SBrooks Davis.It Dv PL_FLAG_BORN 6568269e767SBrooks DavisThis flag is set for the first event reported from a new LWP when 6578269e767SBrooks Davis.Dv PTRACE_LWP 6588269e767SBrooks Davisis enabled. 6598269e767SBrooks DavisIt is reported along with 6608269e767SBrooks Davis.Dv PL_FLAG_SCX . 6618269e767SBrooks Davis.It Dv PL_FLAG_EXITED 6628269e767SBrooks DavisThis flag is set for the last event reported by an exiting LWP when 6638269e767SBrooks Davis.Dv PTRACE_LWP 6648269e767SBrooks Davisis enabled. 6658269e767SBrooks DavisNote that this event is not reported when the last LWP in a process exits. 6668269e767SBrooks DavisThe termination of the last thread is reported via a normal process exit 6678269e767SBrooks Davisevent. 6688269e767SBrooks Davis.It Dv PL_FLAG_VFORKED 6698269e767SBrooks DavisIndicates that the thread is returning from a call to 6708269e767SBrooks Davis.Xr vfork 2 6718269e767SBrooks Davisthat created a new child process. 6728269e767SBrooks DavisThis flag is set in addition to 6738269e767SBrooks Davis.Dv PL_FLAG_FORKED . 6748269e767SBrooks Davis.It Dv PL_FLAG_VFORK_DONE 6758269e767SBrooks DavisIndicates that the thread has resumed after a child process created via 6768269e767SBrooks Davis.Xr vfork 2 6778269e767SBrooks Davishas stopped sharing its address space with the traced process. 6788269e767SBrooks Davis.El 6798269e767SBrooks Davis.It Va pl_sigmask 6808269e767SBrooks DavisThe current signal mask of the LWP 6818269e767SBrooks Davis.It Va pl_siglist 6828269e767SBrooks DavisThe current pending set of signals for the LWP. 6838269e767SBrooks DavisNote that signals that are delivered to the process would not appear 6848269e767SBrooks Davison an LWP siglist until the thread is selected for delivery. 6858269e767SBrooks Davis.It Va pl_siginfo 6868269e767SBrooks DavisThe siginfo that accompanies the signal pending. 6878269e767SBrooks DavisOnly valid for 6888269e767SBrooks Davis.Dv PL_EVENT_SIGNAL 6898269e767SBrooks Davisstop when 6908269e767SBrooks Davis.Dv PL_FLAG_SI 6918269e767SBrooks Davisis set in 6928269e767SBrooks Davis.Va pl_flags . 6938269e767SBrooks Davis.It Va pl_tdname 6948269e767SBrooks DavisThe name of the thread. 6958269e767SBrooks Davis.It Va pl_child_pid 6968269e767SBrooks DavisThe process identifier of the new child process. 6978269e767SBrooks DavisOnly valid for a 6988269e767SBrooks Davis.Dv PL_EVENT_SIGNAL 6998269e767SBrooks Davisstop when 7008269e767SBrooks Davis.Dv PL_FLAG_FORKED 7018269e767SBrooks Davisis set in 7028269e767SBrooks Davis.Va pl_flags . 7038269e767SBrooks Davis.It Va pl_syscall_code 7048269e767SBrooks DavisThe ABI-specific identifier of the current system call. 7058269e767SBrooks DavisNote that for indirect system calls this field reports the indirected 7068269e767SBrooks Davissystem call. 7078269e767SBrooks DavisOnly valid when 7088269e767SBrooks Davis.Dv PL_FLAG_SCE 7098269e767SBrooks Davisor 7108269e767SBrooks Davis.Dv PL_FLAG_SCX 7118269e767SBrooks Davisis set in 7128269e767SBrooks Davis.Va pl_flags . 7138269e767SBrooks Davis.It Va pl_syscall_narg 7148269e767SBrooks DavisThe number of arguments passed to the current system call not counting 7158269e767SBrooks Davisthe system call identifier. 7168269e767SBrooks DavisNote that for indirect system calls this field reports the arguments 7178269e767SBrooks Davispassed to the indirected system call. 7188269e767SBrooks DavisOnly valid when 7198269e767SBrooks Davis.Dv PL_FLAG_SCE 7208269e767SBrooks Davisor 7218269e767SBrooks Davis.Dv PL_FLAG_SCX 7228269e767SBrooks Davisis set in 7238269e767SBrooks Davis.Va pl_flags . 7248269e767SBrooks Davis.El 7258269e767SBrooks Davis.It Dv PT_GETNUMLWPS 7268269e767SBrooks DavisThis request returns the number of kernel threads associated with the 7278269e767SBrooks Davistraced process. 7288269e767SBrooks Davis.It Dv PT_GETLWPLIST 7298269e767SBrooks DavisThis request can be used to get the current thread list. 7308269e767SBrooks DavisA pointer to an array of type 7318269e767SBrooks Davis.Vt lwpid_t 7328269e767SBrooks Davisshould be passed in 7338269e767SBrooks Davis.Fa addr , 7348269e767SBrooks Daviswith the array size specified by 7358269e767SBrooks Davis.Fa data . 7368269e767SBrooks DavisThe return value from 7378269e767SBrooks Davis.Fn ptrace 7388269e767SBrooks Davisis the count of array entries filled in. 7398269e767SBrooks Davis.It Dv PT_SETSTEP 7408269e767SBrooks DavisThis request will turn on single stepping of the specified process. 7418269e767SBrooks DavisStepping is automatically disabled when a single step trap is caught. 7428269e767SBrooks Davis.It Dv PT_CLEARSTEP 7438269e767SBrooks DavisThis request will turn off single stepping of the specified process. 7448269e767SBrooks Davis.It Dv PT_SUSPEND 7458269e767SBrooks DavisThis request will suspend the specified thread. 7468269e767SBrooks Davis.It Dv PT_RESUME 7478269e767SBrooks DavisThis request will resume the specified thread. 7488269e767SBrooks Davis.It Dv PT_TO_SCE 7498269e767SBrooks DavisThis request will set the 7508269e767SBrooks Davis.Dv PTRACE_SCE 7518269e767SBrooks Davisevent flag to trace all future system call entries and continue the process. 7528269e767SBrooks DavisThe 7538269e767SBrooks Davis.Fa addr 7548269e767SBrooks Davisand 7558269e767SBrooks Davis.Fa data 7568269e767SBrooks Davisarguments are used the same as for 7578269e767SBrooks Davis.Dv PT_CONTINUE . 7588269e767SBrooks Davis.It Dv PT_TO_SCX 7598269e767SBrooks DavisThis request will set the 7608269e767SBrooks Davis.Dv PTRACE_SCX 7618269e767SBrooks Davisevent flag to trace all future system call exits and continue the process. 7628269e767SBrooks DavisThe 7638269e767SBrooks Davis.Fa addr 7648269e767SBrooks Davisand 7658269e767SBrooks Davis.Fa data 7668269e767SBrooks Davisarguments are used the same as for 7678269e767SBrooks Davis.Dv PT_CONTINUE . 7688269e767SBrooks Davis.It Dv PT_SYSCALL 7698269e767SBrooks DavisThis request will set the 7708269e767SBrooks Davis.Dv PTRACE_SYSCALL 7718269e767SBrooks Davisevent flag to trace all future system call entries and exits and continue 7728269e767SBrooks Davisthe process. 7738269e767SBrooks DavisThe 7748269e767SBrooks Davis.Fa addr 7758269e767SBrooks Davisand 7768269e767SBrooks Davis.Fa data 7778269e767SBrooks Davisarguments are used the same as for 7788269e767SBrooks Davis.Dv PT_CONTINUE . 7798269e767SBrooks Davis.It Dv PT_GET_SC_ARGS 7808269e767SBrooks DavisFor the thread which is stopped in either 7818269e767SBrooks Davis.Dv PL_FLAG_SCE 7828269e767SBrooks Davisor 7838269e767SBrooks Davis.Dv PL_FLAG_SCX 7848269e767SBrooks Davisstate, that is, on entry or exit to a syscall, 7858269e767SBrooks Davisthis request fetches the syscall arguments. 7868269e767SBrooks Davis.Pp 7878269e767SBrooks DavisThe arguments are copied out into the buffer pointed to by the 7888269e767SBrooks Davis.Fa addr 7898269e767SBrooks Davispointer, sequentially. 7908269e767SBrooks DavisEach syscall argument is stored as the machine word. 7918269e767SBrooks DavisKernel copies out as many arguments as the syscall accepts, 7928269e767SBrooks Davissee the 7938269e767SBrooks Davis.Va pl_syscall_narg 7948269e767SBrooks Davismember of the 7958269e767SBrooks Davis.Vt struct ptrace_lwpinfo , 7968269e767SBrooks Davisbut not more than the 7978269e767SBrooks Davis.Fa data 7988269e767SBrooks Davisbytes in total are copied. 7998269e767SBrooks Davis.It Dv PT_GET_SC_RET 8008269e767SBrooks DavisFetch the system call return values on exit from a syscall. 8018269e767SBrooks DavisThis request is only valid for threads stopped in a syscall 8028269e767SBrooks Davisexit (the 8038269e767SBrooks Davis.Dv PL_FLAG_SCX 8048269e767SBrooks Davisstate). 8058269e767SBrooks DavisThe 8068269e767SBrooks Davis.Fa addr 8078269e767SBrooks Davisargument specifies a pointer to a 8088269e767SBrooks Davis.Vt "struct ptrace_sc_ret" , 8098269e767SBrooks Daviswhich is defined as follows: 8108269e767SBrooks Davis.Bd -literal 8118269e767SBrooks Davisstruct ptrace_sc_ret { 8128269e767SBrooks Davis register_t sr_retval[2]; 8138269e767SBrooks Davis int sr_error; 8148269e767SBrooks Davis}; 8158269e767SBrooks Davis.Ed 8168269e767SBrooks Davis.Pp 8178269e767SBrooks DavisThe 8188269e767SBrooks Davis.Fa data 8198269e767SBrooks Davisargument is set to the size of the structure. 8208269e767SBrooks Davis.Pp 8218269e767SBrooks DavisIf the system call completed successfully, 8228269e767SBrooks Davis.Va sr_error 8238269e767SBrooks Davisis set to zero and the return values of the system call are saved in 8248269e767SBrooks Davis.Va sr_retval . 8258269e767SBrooks DavisIf the system call failed to execute, 8268269e767SBrooks Davis.Va sr_error 8278269e767SBrooks Davisfield is set to a positive 8288269e767SBrooks Davis.Xr errno 2 8298269e767SBrooks Davisvalue. 8308269e767SBrooks DavisIf the system call completed in an unusual fashion, 8318269e767SBrooks Davis.Va sr_error 8328269e767SBrooks Davisis set to a negative value: 833*65005636SGraham Percival.Bl -tag -width EJUSTRETURN -compact 8348269e767SBrooks Davis.It Dv ERESTART 8358269e767SBrooks DavisSystem call will be restarted. 8368269e767SBrooks Davis.It Dv EJUSTRETURN 8378269e767SBrooks DavisSystem call completed sucessfully but did not set a return value 8388269e767SBrooks Davis.Po for example, 8398269e767SBrooks Davis.Xr setcontext 2 8408269e767SBrooks Davisand 8418269e767SBrooks Davis.Xr sigreturn 2 8428269e767SBrooks Davis.Pc . 8438269e767SBrooks Davis.El 8448269e767SBrooks Davis.It Dv PT_FOLLOW_FORK 8458269e767SBrooks DavisThis request controls tracing for new child processes of a traced process. 8468269e767SBrooks DavisIf 8478269e767SBrooks Davis.Fa data 8488269e767SBrooks Davisis non-zero, 8498269e767SBrooks Davis.Dv PTRACE_FORK 8508269e767SBrooks Davisis set in the traced process's event tracing mask. 8518269e767SBrooks DavisIf 8528269e767SBrooks Davis.Fa data 8538269e767SBrooks Davisis zero, 8548269e767SBrooks Davis.Dv PTRACE_FORK 8558269e767SBrooks Davisis cleared from the traced process's event tracing mask. 8568269e767SBrooks Davis.It Dv PT_LWP_EVENTS 8578269e767SBrooks DavisThis request controls tracing of LWP creation and destruction. 8588269e767SBrooks DavisIf 8598269e767SBrooks Davis.Fa data 8608269e767SBrooks Davisis non-zero, 8618269e767SBrooks Davis.Dv PTRACE_LWP 8628269e767SBrooks Davisis set in the traced process's event tracing mask. 8638269e767SBrooks DavisIf 8648269e767SBrooks Davis.Fa data 8658269e767SBrooks Davisis zero, 8668269e767SBrooks Davis.Dv PTRACE_LWP 8678269e767SBrooks Davisis cleared from the traced process's event tracing mask. 8688269e767SBrooks Davis.It Dv PT_GET_EVENT_MASK 8698269e767SBrooks DavisThis request reads the traced process's event tracing mask into the 8708269e767SBrooks Davisinteger pointed to by 8718269e767SBrooks Davis.Fa addr . 8728269e767SBrooks DavisThe size of the integer must be passed in 8738269e767SBrooks Davis.Fa data . 8748269e767SBrooks Davis.It Dv PT_SET_EVENT_MASK 8758269e767SBrooks DavisThis request sets the traced process's event tracing mask from the 8768269e767SBrooks Davisinteger pointed to by 8778269e767SBrooks Davis.Fa addr . 8788269e767SBrooks DavisThe size of the integer must be passed in 8798269e767SBrooks Davis.Fa data . 8808269e767SBrooks Davis.It Dv PT_VM_TIMESTAMP 8818269e767SBrooks DavisThis request returns the generation number or timestamp of the memory map of 8828269e767SBrooks Davisthe traced process as the return value from 8838269e767SBrooks Davis.Fn ptrace . 8848269e767SBrooks DavisThis provides a low-cost way for the tracing process to determine if the 8858269e767SBrooks DavisVM map changed since the last time this request was made. 8868269e767SBrooks Davis.It Dv PT_VM_ENTRY 8878269e767SBrooks DavisThis request is used to iterate over the entries of the VM map of the traced 8888269e767SBrooks Davisprocess. 8898269e767SBrooks DavisThe 8908269e767SBrooks Davis.Fa addr 8918269e767SBrooks Davisargument specifies a pointer to a 8928269e767SBrooks Davis.Vt "struct ptrace_vm_entry" , 8938269e767SBrooks Daviswhich is defined as follows: 8948269e767SBrooks Davis.Bd -literal 8958269e767SBrooks Davisstruct ptrace_vm_entry { 8968269e767SBrooks Davis int pve_entry; 8978269e767SBrooks Davis int pve_timestamp; 8988269e767SBrooks Davis u_long pve_start; 8998269e767SBrooks Davis u_long pve_end; 9008269e767SBrooks Davis u_long pve_offset; 9018269e767SBrooks Davis u_int pve_prot; 9028269e767SBrooks Davis u_int pve_pathlen; 9038269e767SBrooks Davis long pve_fileid; 9048269e767SBrooks Davis uint32_t pve_fsid; 9058269e767SBrooks Davis char *pve_path; 9068269e767SBrooks Davis}; 9078269e767SBrooks Davis.Ed 9088269e767SBrooks Davis.Pp 9098269e767SBrooks DavisThe first entry is returned by setting 9108269e767SBrooks Davis.Va pve_entry 9118269e767SBrooks Davisto zero. 9128269e767SBrooks DavisSubsequent entries are returned by leaving 9138269e767SBrooks Davis.Va pve_entry 9148269e767SBrooks Davisunmodified from the value returned by previous requests. 9158269e767SBrooks DavisThe 9168269e767SBrooks Davis.Va pve_timestamp 9178269e767SBrooks Davisfield can be used to detect changes to the VM map while iterating over the 9188269e767SBrooks Davisentries. 9198269e767SBrooks DavisThe tracing process can then take appropriate action, such as restarting. 9208269e767SBrooks DavisBy setting 9218269e767SBrooks Davis.Va pve_pathlen 9228269e767SBrooks Davisto a non-zero value on entry, the pathname of the backing object is returned 9238269e767SBrooks Davisin the buffer pointed to by 9248269e767SBrooks Davis.Va pve_path , 9258269e767SBrooks Davisprovided the entry is backed by a vnode. 9268269e767SBrooks DavisThe 9278269e767SBrooks Davis.Va pve_pathlen 9288269e767SBrooks Davisfield is updated with the actual length of the pathname (including the 9298269e767SBrooks Davisterminating null character). 9308269e767SBrooks DavisThe 9318269e767SBrooks Davis.Va pve_offset 9328269e767SBrooks Davisfield is the offset within the backing object at which the range starts. 9338269e767SBrooks DavisThe range is located in the VM space at 9348269e767SBrooks Davis.Va pve_start 9358269e767SBrooks Davisand extends up to 9368269e767SBrooks Davis.Va pve_end 9378269e767SBrooks Davis(inclusive). 9388269e767SBrooks Davis.Pp 9398269e767SBrooks DavisThe 9408269e767SBrooks Davis.Fa data 9418269e767SBrooks Davisargument is ignored. 9428269e767SBrooks Davis.It Dv PT_COREDUMP 9438269e767SBrooks DavisThis request creates a coredump for the stopped program. 9448269e767SBrooks DavisThe 9458269e767SBrooks Davis.Fa addr 9468269e767SBrooks Davisargument specifies a pointer to a 9478269e767SBrooks Davis.Vt "struct ptrace_coredump" , 9488269e767SBrooks Daviswhich is defined as follows: 9498269e767SBrooks Davis.Bd -literal 9508269e767SBrooks Davisstruct ptrace_coredump { 9518269e767SBrooks Davis int pc_fd; 9528269e767SBrooks Davis uint32_t pc_flags; 9538269e767SBrooks Davis off_t pc_limit; 9548269e767SBrooks Davis}; 9558269e767SBrooks Davis.Ed 9568269e767SBrooks DavisThe fields of the structure are: 9578269e767SBrooks Davis.Bl -tag -width pc_flags 9588269e767SBrooks Davis.It Dv pc_fd 9598269e767SBrooks DavisFile descriptor to write the dump to. 9608269e767SBrooks DavisIt must refer to a regular file, opened for writing. 9618269e767SBrooks Davis.It Dv pc_flags 9628269e767SBrooks DavisFlags. 9638269e767SBrooks DavisThe following flags are defined: 9648269e767SBrooks Davis.Bl -tag -width PC_COMPRESS 9658269e767SBrooks Davis.It Dv PC_COMPRESS 9668269e767SBrooks DavisRequest compression of the dump. 9678269e767SBrooks Davis.It Dv PC_ALL 9688269e767SBrooks DavisInclude non-dumpable entries into the dump. 9698269e767SBrooks DavisThe dumper ignores 9708269e767SBrooks Davis.Dv MAP_NOCORE 9718269e767SBrooks Davisflag of the process map entry, but device mappings are not dumped even with 9728269e767SBrooks Davis.Dv PC_ALL 9738269e767SBrooks Davisset. 9748269e767SBrooks Davis.El 9758269e767SBrooks Davis.It Dv pc_limit 9768269e767SBrooks DavisMaximum size of the coredump. 9778269e767SBrooks DavisSpecify zero for no limit. 9788269e767SBrooks Davis.El 9798269e767SBrooks Davis.Pp 9808269e767SBrooks DavisThe size of 9818269e767SBrooks Davis.Vt "struct ptrace_coredump" 9828269e767SBrooks Davismust be passed in 9838269e767SBrooks Davis.Fa data . 9848269e767SBrooks Davis.It Dv PT_SC_REMOTE 9858269e767SBrooks DavisRequest to execute a syscall in the context of the traced process, 9868269e767SBrooks Davisin the specified thread. 9878269e767SBrooks DavisThe 9888269e767SBrooks Davis.Fa addr 9898269e767SBrooks Davisargument must point to the 9908269e767SBrooks Davis.Vt "struct ptrace_sc_remote" , 9918269e767SBrooks Daviswhich describes the requested syscall and its arguments, and receives 9928269e767SBrooks Davisthe result. 9938269e767SBrooks DavisThe size of 9948269e767SBrooks Davis.Vt "struct ptrace_sc_remote" 9958269e767SBrooks Davismust be passed in 9968269e767SBrooks Davis.Fa data. 9978269e767SBrooks Davis.Bd -literal 9988269e767SBrooks Davisstruct ptrace_sc_remote { 9998269e767SBrooks Davis struct ptrace_sc_ret pscr_ret; 10008269e767SBrooks Davis u_int pscr_syscall; 10018269e767SBrooks Davis u_int pscr_nargs; 10028269e767SBrooks Davis u_long *pscr_args; 10038269e767SBrooks Davis}; 10048269e767SBrooks Davis.Ed 10058269e767SBrooks DavisThe 10068269e767SBrooks Davis.Dv pscr_syscall 10078269e767SBrooks Daviscontains the syscall number to execute, the 10088269e767SBrooks Davis.Dv pscr_nargs 10098269e767SBrooks Davisis the number of supplied arguments, which are supplied in the 10108269e767SBrooks Davis.Dv pscr_args 10118269e767SBrooks Davisarray. 10128269e767SBrooks DavisResult of the execution is returned in the 10138269e767SBrooks Davis.Dv pscr_ret 10148269e767SBrooks Davismember. 10158269e767SBrooks DavisNote that the request and its result do not affect the returned value from 10168269e767SBrooks Davisthe currently executed syscall, if any. 10178269e767SBrooks Davis.El 10188269e767SBrooks Davis.Sh PT_COREDUMP and PT_SC_REMOTE usage 10198269e767SBrooks DavisThe process must be stopped before dumping or initiating a remote system call. 10208269e767SBrooks DavisA single thread in the target process is temporarily unsuspended 10218269e767SBrooks Davisin the kernel to perform the action. 10228269e767SBrooks DavisIf the 10238269e767SBrooks Davis.Nm 10248269e767SBrooks Daviscall fails before a thread is unsuspended, there is no event to 10258269e767SBrooks Davis.Xr waitpid 2 10268269e767SBrooks Davisfor. 10278269e767SBrooks DavisIf a thread was unsuspended, it will stop again before the 10288269e767SBrooks Davis.Nm 10298269e767SBrooks Daviscall returns, and the process must be waited upon using 10308269e767SBrooks Davis.Xr waitpid 2 10318269e767SBrooks Davisto consume the new stop event. 10328269e767SBrooks DavisSince it is hard to deduce whether a thread was unsuspended before 10338269e767SBrooks Davisan error occurred, it is recommended to unconditionally perform 10348269e767SBrooks Davis.Xr waitpid 2 10358269e767SBrooks Daviswith 10368269e767SBrooks Davis.Dv WNOHANG 10378269e767SBrooks Davisflag after 10388269e767SBrooks Davis.Dv PT_COREDUMP 10398269e767SBrooks Davisand 10408269e767SBrooks Davis.Dv PT_SC_REMOTE , 10418269e767SBrooks Davisand silently accept zero result from it. 10428269e767SBrooks Davis.Pp 10438269e767SBrooks DavisFor 10448269e767SBrooks Davis.Dv PT_SC_REMOTE , 10458269e767SBrooks Davisthe selected thread must be stopped in the safe place, which is 10468269e767SBrooks Daviscurrently defined as a syscall exit, or a return from kernel to 10478269e767SBrooks Davisuser mode (basically, a signal handler call place). 10488269e767SBrooks DavisKernel returns 10498269e767SBrooks Davis.Er EBUSY 10508269e767SBrooks Davisstatus if attempt is made to execute remote syscall at unsafe stop. 10518269e767SBrooks Davis.Pp 10528269e767SBrooks DavisNote that neither 10538269e767SBrooks Davis.Dv kern.trap_enotcap 10548269e767SBrooks Davissysctl setting, nor the corresponding 10558269e767SBrooks Davis.Xr procctl 2 10568269e767SBrooks Davisflag 10578269e767SBrooks Davis.Dv PROC_TRAPCAP_CTL_ENABLE 10588269e767SBrooks Davisare obeyed during the execution of the syscall by 10598269e767SBrooks Davis.Dv PT_SC_REMOTE . 10608269e767SBrooks DavisIn other words, 10618269e767SBrooks Davis.Dv SIGTRAP 10628269e767SBrooks Davissignal is not sent to a process executing in capability mode, 10638269e767SBrooks Daviswhich violated a mode access restriction. 10648269e767SBrooks Davis.Pp 10658269e767SBrooks DavisNote that due to the mode of execution for the remote syscall, in 10668269e767SBrooks Davisparticular, the setting where only one thread is allowed to run, 10678269e767SBrooks Davisthe syscall might block on resources owned by suspended threads. 10688269e767SBrooks DavisThis might result in the target process deadlock. 10698269e767SBrooks DavisIn this situation, the only way out is to kill the target. 10708269e767SBrooks Davis.Sh ARM MACHINE-SPECIFIC REQUESTS 10718269e767SBrooks Davis.Bl -tag -width "Dv PT_SETVFPREGS" 10728269e767SBrooks Davis.It Dv PT_GETVFPREGS 10738269e767SBrooks DavisReturn the thread's 10748269e767SBrooks Davis.Dv VFP 10758269e767SBrooks Davismachine state in the buffer pointed to by 10768269e767SBrooks Davis.Fa addr . 10778269e767SBrooks Davis.Pp 10788269e767SBrooks DavisThe 10798269e767SBrooks Davis.Fa data 10808269e767SBrooks Davisargument is ignored. 10818269e767SBrooks Davis.It Dv PT_SETVFPREGS 10828269e767SBrooks DavisSet the thread's 10838269e767SBrooks Davis.Dv VFP 10848269e767SBrooks Davismachine state from the buffer pointed to by 10858269e767SBrooks Davis.Fa addr . 10868269e767SBrooks Davis.Pp 10878269e767SBrooks DavisThe 10888269e767SBrooks Davis.Fa data 10898269e767SBrooks Davisargument is ignored. 10908269e767SBrooks Davis.El 10918269e767SBrooks Davis.Sh x86 MACHINE-SPECIFIC REQUESTS 10928269e767SBrooks Davis.Bl -tag -width "Dv PT_GETXSTATE_INFO" 10938269e767SBrooks Davis.It Dv PT_GETXMMREGS 10948269e767SBrooks DavisCopy the XMM FPU state into the buffer pointed to by the 10958269e767SBrooks Davisargument 10968269e767SBrooks Davis.Fa addr . 10978269e767SBrooks DavisThe buffer has the same layout as the 32-bit save buffer for the 10988269e767SBrooks Davismachine instruction 10998269e767SBrooks Davis.Dv FXSAVE . 11008269e767SBrooks Davis.Pp 11018269e767SBrooks DavisThis request is only valid for i386 programs, both on native 32-bit 11028269e767SBrooks Davissystems and on amd64 kernels. 11038269e767SBrooks DavisFor 64-bit amd64 programs, the XMM state is reported as part of 11048269e767SBrooks Davisthe FPU state returned by the 11058269e767SBrooks Davis.Dv PT_GETFPREGS 11068269e767SBrooks Davisrequest. 11078269e767SBrooks Davis.Pp 11088269e767SBrooks DavisThe 11098269e767SBrooks Davis.Fa data 11108269e767SBrooks Davisargument is ignored. 11118269e767SBrooks Davis.It Dv PT_SETXMMREGS 11128269e767SBrooks DavisLoad the XMM FPU state for the thread from the buffer pointed to 11138269e767SBrooks Davisby the argument 11148269e767SBrooks Davis.Fa addr . 11158269e767SBrooks DavisThe buffer has the same layout as the 32-bit load buffer for the 11168269e767SBrooks Davismachine instruction 11178269e767SBrooks Davis.Dv FXRSTOR . 11188269e767SBrooks Davis.Pp 11198269e767SBrooks DavisAs with 11208269e767SBrooks Davis.Dv PT_GETXMMREGS , 11218269e767SBrooks Davisthis request is only valid for i386 programs. 11228269e767SBrooks Davis.Pp 11238269e767SBrooks DavisThe 11248269e767SBrooks Davis.Fa data 11258269e767SBrooks Davisargument is ignored. 11268269e767SBrooks Davis.It Dv PT_GETXSTATE_INFO 11278269e767SBrooks DavisReport which XSAVE FPU extensions are supported by the CPU 11288269e767SBrooks Davisand allowed in userspace programs. 11298269e767SBrooks DavisThe 11308269e767SBrooks Davis.Fa addr 11318269e767SBrooks Davisargument must point to a variable of type 11328269e767SBrooks Davis.Vt struct ptrace_xstate_info , 11338269e767SBrooks Daviswhich contains the information on the request return. 11348269e767SBrooks Davis.Vt struct ptrace_xstate_info 11358269e767SBrooks Davisis defined as follows: 11368269e767SBrooks Davis.Bd -literal 11378269e767SBrooks Davisstruct ptrace_xstate_info { 11388269e767SBrooks Davis uint64_t xsave_mask; 11398269e767SBrooks Davis uint32_t xsave_len; 11408269e767SBrooks Davis}; 11418269e767SBrooks Davis.Ed 11428269e767SBrooks DavisThe 11438269e767SBrooks Davis.Dv xsave_mask 11448269e767SBrooks Davisfield is a bitmask of the currently enabled extensions. 11458269e767SBrooks DavisThe meaning of the bits is defined in the Intel and AMD 11468269e767SBrooks Davisprocessor documentation. 11478269e767SBrooks DavisThe 11488269e767SBrooks Davis.Dv xsave_len 11498269e767SBrooks Davisfield reports the length of the XSAVE area for storing the hardware 11508269e767SBrooks Davisstate for currently enabled extensions in the format defined by the x86 11518269e767SBrooks Davis.Dv XSAVE 11528269e767SBrooks Davismachine instruction. 11538269e767SBrooks Davis.Pp 11548269e767SBrooks DavisThe 11558269e767SBrooks Davis.Fa data 11568269e767SBrooks Davisargument value must be equal to the size of the 11578269e767SBrooks Davis.Vt struct ptrace_xstate_info . 11588269e767SBrooks Davis.It Dv PT_GETXSTATE 11598269e767SBrooks DavisReturn the content of the XSAVE area for the thread. 11608269e767SBrooks DavisThe 11618269e767SBrooks Davis.Fa addr 11628269e767SBrooks Davisargument points to the buffer where the content is copied, and the 11638269e767SBrooks Davis.Fa data 11648269e767SBrooks Davisargument specifies the size of the buffer. 11658269e767SBrooks DavisThe kernel copies out as much content as allowed by the buffer size. 11668269e767SBrooks DavisThe buffer layout is specified by the layout of the save area for the 11678269e767SBrooks Davis.Dv XSAVE 11688269e767SBrooks Davismachine instruction. 11698269e767SBrooks Davis.It Dv PT_SETXSTATE 11708269e767SBrooks DavisLoad the XSAVE state for the thread from the buffer specified by the 11718269e767SBrooks Davis.Fa addr 11728269e767SBrooks Davispointer. 11738269e767SBrooks DavisThe buffer size is passed in the 11748269e767SBrooks Davis.Fa data 11758269e767SBrooks Davisargument. 11768269e767SBrooks DavisThe buffer must be at least as large as the 11778269e767SBrooks Davis.Vt struct savefpu 11788269e767SBrooks Davis(defined in 11798269e767SBrooks Davis.Pa x86/fpu.h ) 11808269e767SBrooks Davisto allow the complete x87 FPU and XMM state load. 11818269e767SBrooks DavisIt must not be larger than the XSAVE state length, as reported by the 11828269e767SBrooks Davis.Dv xsave_len 11838269e767SBrooks Davisfield from the 11848269e767SBrooks Davis.Vt struct ptrace_xstate_info 11858269e767SBrooks Davisof the 11868269e767SBrooks Davis.Dv PT_GETXSTATE_INFO 11878269e767SBrooks Davisrequest. 11888269e767SBrooks DavisLayout of the buffer is identical to the layout of the load area for the 11898269e767SBrooks Davis.Dv XRSTOR 11908269e767SBrooks Davismachine instruction. 11918269e767SBrooks Davis.It Dv PT_GETFSBASE 11928269e767SBrooks DavisReturn the value of the base used when doing segmented 11938269e767SBrooks Davismemory addressing using the %fs segment register. 11948269e767SBrooks DavisThe 11958269e767SBrooks Davis.Fa addr 11968269e767SBrooks Davisargument points to an 11978269e767SBrooks Davis.Vt unsigned long 11988269e767SBrooks Davisvariable where the base value is stored. 11998269e767SBrooks Davis.Pp 12008269e767SBrooks DavisThe 12018269e767SBrooks Davis.Fa data 12028269e767SBrooks Davisargument is ignored. 12038269e767SBrooks Davis.It Dv PT_GETGSBASE 12048269e767SBrooks DavisLike the 12058269e767SBrooks Davis.Dv PT_GETFSBASE 12068269e767SBrooks Davisrequest, but returns the base for the %gs segment register. 12078269e767SBrooks Davis.It Dv PT_SETFSBASE 12088269e767SBrooks DavisSet the base for the %fs segment register to the value pointed to 12098269e767SBrooks Davisby the 12108269e767SBrooks Davis.Fa addr 12118269e767SBrooks Davisargument. 12128269e767SBrooks Davis.Fa addr 12138269e767SBrooks Davismust point to the 12148269e767SBrooks Davis.Vt unsigned long 12158269e767SBrooks Davisvariable containing the new base. 12168269e767SBrooks Davis.Pp 12178269e767SBrooks DavisThe 12188269e767SBrooks Davis.Fa data 12198269e767SBrooks Davisargument is ignored. 12208269e767SBrooks Davis.It Dv PT_SETGSBASE 12218269e767SBrooks DavisLike the 12228269e767SBrooks Davis.Dv PT_SETFSBASE 12238269e767SBrooks Davisrequest, but sets the base for the %gs segment register. 12248269e767SBrooks Davis.El 12258269e767SBrooks Davis.Sh PowerPC MACHINE-SPECIFIC REQUESTS 12268269e767SBrooks Davis.Bl -tag -width "Dv PT_SETVRREGS" 12278269e767SBrooks Davis.It Dv PT_GETVRREGS 12288269e767SBrooks DavisReturn the thread's 12298269e767SBrooks Davis.Dv ALTIVEC 12308269e767SBrooks Davismachine state in the buffer pointed to by 12318269e767SBrooks Davis.Fa addr . 12328269e767SBrooks Davis.Pp 12338269e767SBrooks DavisThe 12348269e767SBrooks Davis.Fa data 12358269e767SBrooks Davisargument is ignored. 12368269e767SBrooks Davis.It Dv PT_SETVRREGS 12378269e767SBrooks DavisSet the thread's 12388269e767SBrooks Davis.Dv ALTIVEC 12398269e767SBrooks Davismachine state from the buffer pointed to by 12408269e767SBrooks Davis.Fa addr . 12418269e767SBrooks Davis.Pp 12428269e767SBrooks DavisThe 12438269e767SBrooks Davis.Fa data 12448269e767SBrooks Davisargument is ignored. 12458269e767SBrooks Davis.It Dv PT_GETVSRREGS 12468269e767SBrooks DavisReturn doubleword 1 of the thread's 12478269e767SBrooks Davis.Dv VSX 12488269e767SBrooks Davisregisters VSR0-VSR31 in the buffer pointed to by 12498269e767SBrooks Davis.Fa addr . 12508269e767SBrooks Davis.Pp 12518269e767SBrooks DavisThe 12528269e767SBrooks Davis.Fa data 12538269e767SBrooks Davisargument is ignored. 12548269e767SBrooks Davis.It Dv PT_SETVSRREGS 12558269e767SBrooks DavisSet doubleword 1 of the thread's 12568269e767SBrooks Davis.Dv VSX 12578269e767SBrooks Davisregisters VSR0-VSR31 from the buffer pointed to by 12588269e767SBrooks Davis.Fa addr . 12598269e767SBrooks Davis.Pp 12608269e767SBrooks DavisThe 12618269e767SBrooks Davis.Fa data 12628269e767SBrooks Davisargument is ignored. 12638269e767SBrooks Davis.El 12648269e767SBrooks Davis.Pp 12658269e767SBrooks DavisAdditionally, other machine-specific requests can exist. 12668269e767SBrooks Davis.Sh RETURN VALUES 12678269e767SBrooks DavisMost requests return 0 on success and \-1 on error. 12688269e767SBrooks DavisSome requests can cause 12698269e767SBrooks Davis.Fn ptrace 12708269e767SBrooks Davisto return 12718269e767SBrooks Davis\-1 12728269e767SBrooks Davisas a non-error value, among them are 12738269e767SBrooks Davis.Dv PT_READ_I 12748269e767SBrooks Davisand 12758269e767SBrooks Davis.Dv PT_READ_D , 12768269e767SBrooks Daviswhich return the value read from the process memory on success. 12778269e767SBrooks DavisTo disambiguate, 12788269e767SBrooks Davis.Va errno 12798269e767SBrooks Daviscan be set to 0 before the call and checked afterwards. 12808269e767SBrooks Davis.Pp 12818269e767SBrooks DavisThe current 12828269e767SBrooks Davis.Fn ptrace 12838269e767SBrooks Davisimplementation always sets 12848269e767SBrooks Davis.Va errno 12858269e767SBrooks Davisto 0 before calling into the kernel, both for historic reasons and for 12868269e767SBrooks Davisconsistency with other operating systems. 12878269e767SBrooks DavisIt is recommended to assign zero to 12888269e767SBrooks Davis.Va errno 12898269e767SBrooks Davisexplicitly for forward compatibility. 12908269e767SBrooks Davis.Sh ERRORS 12918269e767SBrooks DavisThe 12928269e767SBrooks Davis.Fn ptrace 12938269e767SBrooks Davissystem call may fail if: 12948269e767SBrooks Davis.Bl -tag -width Er 12958269e767SBrooks Davis.It Bq Er ESRCH 12968269e767SBrooks Davis.Bl -bullet -compact 12978269e767SBrooks Davis.It 12988269e767SBrooks DavisNo process having the specified process ID exists. 12998269e767SBrooks Davis.El 13008269e767SBrooks Davis.It Bq Er EINVAL 13018269e767SBrooks Davis.Bl -bullet -compact 13028269e767SBrooks Davis.It 13038269e767SBrooks DavisA process attempted to use 13048269e767SBrooks Davis.Dv PT_ATTACH 13058269e767SBrooks Davison itself. 13068269e767SBrooks Davis.It 13078269e767SBrooks DavisThe 13088269e767SBrooks Davis.Fa request 13098269e767SBrooks Davisargument 13108269e767SBrooks Daviswas not one of the legal requests. 13118269e767SBrooks Davis.It 13128269e767SBrooks DavisThe signal number 13138269e767SBrooks Davis(in 13148269e767SBrooks Davis.Fa data ) 13158269e767SBrooks Davisto 13168269e767SBrooks Davis.Dv PT_CONTINUE 13178269e767SBrooks Daviswas neither 0 nor a legal signal number. 13188269e767SBrooks Davis.It 13198269e767SBrooks Davis.Dv PT_GETREGS , 13208269e767SBrooks Davis.Dv PT_SETREGS , 13218269e767SBrooks Davis.Dv PT_GETFPREGS , 13228269e767SBrooks Davis.Dv PT_SETFPREGS , 13238269e767SBrooks Davis.Dv PT_GETDBREGS , 13248269e767SBrooks Davisor 13258269e767SBrooks Davis.Dv PT_SETDBREGS 13268269e767SBrooks Daviswas attempted on a process with no valid register set. 13278269e767SBrooks Davis(This is normally true only of system processes.) 13288269e767SBrooks Davis.It 13298269e767SBrooks Davis.Dv PT_VM_ENTRY 13308269e767SBrooks Daviswas given an invalid value for 13318269e767SBrooks Davis.Fa pve_entry . 13328269e767SBrooks DavisThis can also be caused by changes to the VM map of the process. 13338269e767SBrooks Davis.It 13348269e767SBrooks DavisThe size (in 13358269e767SBrooks Davis.Fa data ) 13368269e767SBrooks Davisprovided to 13378269e767SBrooks Davis.Dv PT_LWPINFO 13388269e767SBrooks Daviswas less than or equal to zero, or larger than the 13398269e767SBrooks Davis.Vt ptrace_lwpinfo 13408269e767SBrooks Davisstructure known to the kernel. 13418269e767SBrooks Davis.It 13428269e767SBrooks DavisThe size (in 13438269e767SBrooks Davis.Fa data ) 13448269e767SBrooks Davisprovided to the x86-specific 13458269e767SBrooks Davis.Dv PT_GETXSTATE_INFO 13468269e767SBrooks Davisrequest was not equal to the size of the 13478269e767SBrooks Davis.Vt struct ptrace_xstate_info . 13488269e767SBrooks Davis.It 13498269e767SBrooks DavisThe size (in 13508269e767SBrooks Davis.Fa data ) 13518269e767SBrooks Davisprovided to the x86-specific 13528269e767SBrooks Davis.Dv PT_SETXSTATE 13538269e767SBrooks Davisrequest was less than the size of the x87 plus the XMM save area. 13548269e767SBrooks Davis.It 13558269e767SBrooks DavisThe size (in 13568269e767SBrooks Davis.Fa data ) 13578269e767SBrooks Davisprovided to the x86-specific 13588269e767SBrooks Davis.Dv PT_SETXSTATE 13598269e767SBrooks Davisrequest was larger than returned in the 13608269e767SBrooks Davis.Dv xsave_len 13618269e767SBrooks Davismember of the 13628269e767SBrooks Davis.Vt struct ptrace_xstate_info 13638269e767SBrooks Davisfrom the 13648269e767SBrooks Davis.Dv PT_GETXSTATE_INFO 13658269e767SBrooks Davisrequest. 13668269e767SBrooks Davis.It 13678269e767SBrooks DavisThe base value, provided to the amd64-specific requests 13688269e767SBrooks Davis.Dv PT_SETFSBASE 13698269e767SBrooks Davisor 13708269e767SBrooks Davis.Dv PT_SETGSBASE , 13718269e767SBrooks Davispointed outside of the valid user address space. 13728269e767SBrooks DavisThis error will not occur in 32-bit programs. 13738269e767SBrooks Davis.El 13748269e767SBrooks Davis.It Bq Er EBUSY 13758269e767SBrooks Davis.Bl -bullet -compact 13768269e767SBrooks Davis.It 13778269e767SBrooks Davis.Dv PT_ATTACH 13788269e767SBrooks Daviswas attempted on a process that was already being traced. 13798269e767SBrooks Davis.It 13808269e767SBrooks DavisA request attempted to manipulate a process that was being traced by 13818269e767SBrooks Davissome process other than the one making the request. 13828269e767SBrooks Davis.It 13838269e767SBrooks DavisA request 13848269e767SBrooks Davis(other than 13858269e767SBrooks Davis.Dv PT_ATTACH ) 13868269e767SBrooks Davisspecified a process that was not stopped. 13878269e767SBrooks Davis.El 13888269e767SBrooks Davis.It Bq Er EPERM 13898269e767SBrooks Davis.Bl -bullet -compact 13908269e767SBrooks Davis.It 13918269e767SBrooks DavisA request 13928269e767SBrooks Davis(other than 13938269e767SBrooks Davis.Dv PT_ATTACH ) 13948269e767SBrooks Davisattempted to manipulate a process that was not being traced at all. 13958269e767SBrooks Davis.It 13968269e767SBrooks DavisAn attempt was made to use 13978269e767SBrooks Davis.Dv PT_ATTACH 13988269e767SBrooks Davison a process in violation of the requirements listed under 13998269e767SBrooks Davis.Dv PT_ATTACH 14008269e767SBrooks Davisabove. 14018269e767SBrooks Davis.El 14028269e767SBrooks Davis.It Bq Er ENOENT 14038269e767SBrooks Davis.Bl -bullet -compact 14048269e767SBrooks Davis.It 14058269e767SBrooks Davis.Dv PT_VM_ENTRY 14068269e767SBrooks Davispreviously returned the last entry of the memory map. 14078269e767SBrooks DavisNo more entries exist. 14088269e767SBrooks Davis.El 14098269e767SBrooks Davis.It Bq Er ENOMEM 14108269e767SBrooks Davis.Bl -bullet -compact 14118269e767SBrooks Davis.It 14128269e767SBrooks DavisA 14138269e767SBrooks Davis.Dv PT_READ_I, 14148269e767SBrooks Davis.Dv PT_READ_D, 14158269e767SBrooks Davis.Dv PT_WRITE_I, or 14168269e767SBrooks Davis.Dv PT_WRITE_D 14178269e767SBrooks Davisrequest attempted to access an invalid address, or a memory allocation failure 14188269e767SBrooks Davisoccurred when accessing process memory. 14198269e767SBrooks Davis.El 14208269e767SBrooks Davis.It Bq Er ENAMETOOLONG 14218269e767SBrooks Davis.Bl -bullet -compact 14228269e767SBrooks Davis.It 14238269e767SBrooks Davis.Dv PT_VM_ENTRY 14248269e767SBrooks Daviscannot return the pathname of the backing object because the buffer is not big 14258269e767SBrooks Davisenough. 14268269e767SBrooks Davis.Fa pve_pathlen 14278269e767SBrooks Davisholds the minimum buffer size required on return. 14288269e767SBrooks Davis.El 14298269e767SBrooks Davis.El 14308269e767SBrooks Davis.Sh SEE ALSO 14318269e767SBrooks Davis.Xr execve 2 , 14328269e767SBrooks Davis.Xr sigaction 2 , 14338269e767SBrooks Davis.Xr wait 2 , 14348269e767SBrooks Davis.Xr execv 3 , 14358269e767SBrooks Davis.Xr i386_clr_watch 3 , 14368269e767SBrooks Davis.Xr i386_set_watch 3 14378269e767SBrooks Davis.Sh HISTORY 14388269e767SBrooks DavisThe 14398269e767SBrooks Davis.Fn ptrace 14408269e767SBrooks Davisfunction appeared in 14418269e767SBrooks Davis.At v6 . 1442