xref: /freebsd/lib/libsys/ptrace.2 (revision 8269e7673cf033aba67dab8264fe719920c70f87)
1*8269e767SBrooks Davis.\"	$NetBSD: ptrace.2,v 1.2 1995/02/27 12:35:37 cgd Exp $
2*8269e767SBrooks Davis.\"
3*8269e767SBrooks Davis.\" This file is in the public domain.
4*8269e767SBrooks Davis.Dd August 18, 2023
5*8269e767SBrooks Davis.Dt PTRACE 2
6*8269e767SBrooks Davis.Os
7*8269e767SBrooks Davis.Sh NAME
8*8269e767SBrooks Davis.Nm ptrace
9*8269e767SBrooks Davis.Nd process tracing and debugging
10*8269e767SBrooks Davis.Sh LIBRARY
11*8269e767SBrooks Davis.Lb libc
12*8269e767SBrooks Davis.Sh SYNOPSIS
13*8269e767SBrooks Davis.In sys/types.h
14*8269e767SBrooks Davis.In sys/ptrace.h
15*8269e767SBrooks Davis.Ft int
16*8269e767SBrooks Davis.Fn ptrace "int request" "pid_t pid" "caddr_t addr" "int data"
17*8269e767SBrooks Davis.Sh DESCRIPTION
18*8269e767SBrooks DavisThe
19*8269e767SBrooks Davis.Fn ptrace
20*8269e767SBrooks Davissystem call
21*8269e767SBrooks Davisprovides tracing and debugging facilities.
22*8269e767SBrooks DavisIt allows one process
23*8269e767SBrooks Davis(the
24*8269e767SBrooks Davis.Em tracing
25*8269e767SBrooks Davisprocess)
26*8269e767SBrooks Davisto control another
27*8269e767SBrooks Davis(the
28*8269e767SBrooks Davis.Em traced
29*8269e767SBrooks Davisprocess).
30*8269e767SBrooks DavisThe tracing process must first attach to the traced process, and then
31*8269e767SBrooks Davisissue a series of
32*8269e767SBrooks Davis.Fn ptrace
33*8269e767SBrooks Davissystem calls to control the execution of the process, as well as access
34*8269e767SBrooks Davisprocess memory and register state.
35*8269e767SBrooks DavisFor the duration of the tracing session, the traced process will be
36*8269e767SBrooks Davis.Dq re-parented ,
37*8269e767SBrooks Daviswith its parent process ID (and resulting behavior)
38*8269e767SBrooks Davischanged to the tracing process.
39*8269e767SBrooks DavisIt is permissible for a tracing process to attach to more than one
40*8269e767SBrooks Davisother process at a time.
41*8269e767SBrooks DavisWhen the tracing process has completed its work, it must detach the
42*8269e767SBrooks Davistraced process; if a tracing process exits without first detaching all
43*8269e767SBrooks Davisprocesses it has attached, those processes will be killed.
44*8269e767SBrooks Davis.Pp
45*8269e767SBrooks DavisMost of the time, the traced process runs normally, but when it
46*8269e767SBrooks Davisreceives a signal
47*8269e767SBrooks Davis(see
48*8269e767SBrooks Davis.Xr sigaction 2 ) ,
49*8269e767SBrooks Davisit stops.
50*8269e767SBrooks DavisThe tracing process is expected to notice this via
51*8269e767SBrooks Davis.Xr wait 2
52*8269e767SBrooks Davisor the delivery of a
53*8269e767SBrooks Davis.Dv SIGCHLD
54*8269e767SBrooks Davissignal, examine the state of the stopped process, and cause it to
55*8269e767SBrooks Davisterminate or continue as appropriate.
56*8269e767SBrooks DavisThe signal may be a normal process signal, generated as a result of
57*8269e767SBrooks Davistraced process behavior, or use of the
58*8269e767SBrooks Davis.Xr kill 2
59*8269e767SBrooks Davissystem call; alternatively, it may be generated by the tracing facility
60*8269e767SBrooks Davisas a result of attaching, stepping by the tracing
61*8269e767SBrooks Davisprocess,
62*8269e767SBrooks Davisor an event in the traced process.
63*8269e767SBrooks DavisThe tracing process may choose to intercept the signal, using it to
64*8269e767SBrooks Davisobserve process behavior (such as
65*8269e767SBrooks Davis.Dv SIGTRAP ) ,
66*8269e767SBrooks Davisor forward the signal to the process if appropriate.
67*8269e767SBrooks DavisThe
68*8269e767SBrooks Davis.Fn ptrace
69*8269e767SBrooks Davissystem call
70*8269e767SBrooks Davisis the mechanism by which all this happens.
71*8269e767SBrooks Davis.Pp
72*8269e767SBrooks DavisA traced process may report additional signal stops corresponding to
73*8269e767SBrooks Davisevents in the traced process.
74*8269e767SBrooks DavisThese additional signal stops are reported as
75*8269e767SBrooks Davis.Dv SIGTRAP
76*8269e767SBrooks Davisor
77*8269e767SBrooks Davis.Dv SIGSTOP
78*8269e767SBrooks Davissignals.
79*8269e767SBrooks DavisThe tracing process can use the
80*8269e767SBrooks Davis.Dv PT_LWPINFO
81*8269e767SBrooks Davisrequest to determine which events are associated with a
82*8269e767SBrooks Davis.Dv SIGTRAP
83*8269e767SBrooks Davisor
84*8269e767SBrooks Davis.Dv SIGSTOP
85*8269e767SBrooks Davissignal.
86*8269e767SBrooks DavisNote that multiple events may be associated with a single signal.
87*8269e767SBrooks DavisFor example, events indicated by the
88*8269e767SBrooks Davis.Dv PL_FLAG_BORN ,
89*8269e767SBrooks Davis.Dv PL_FLAG_FORKED ,
90*8269e767SBrooks Davisand
91*8269e767SBrooks Davis.Dv PL_FLAG_EXEC
92*8269e767SBrooks Davisflags are also reported as a system call exit event
93*8269e767SBrooks Davis.Pq Dv PL_FLAG_SCX .
94*8269e767SBrooks DavisThe signal stop for a new child process enabled via
95*8269e767SBrooks Davis.Dv PTRACE_FORK
96*8269e767SBrooks Daviswill report a
97*8269e767SBrooks Davis.Dv SIGSTOP
98*8269e767SBrooks Davissignal.
99*8269e767SBrooks DavisAll other additional signal stops use
100*8269e767SBrooks Davis.Dv SIGTRAP .
101*8269e767SBrooks Davis.Sh DETACH AND TERMINATION
102*8269e767SBrooks Davis.Pp
103*8269e767SBrooks DavisNormally, exiting tracing process should wait for all pending
104*8269e767SBrooks Davisdebugging events and then detach from all alive traced processes
105*8269e767SBrooks Davisbefore exiting using
106*8269e767SBrooks Davis.Dv PT_DETACH
107*8269e767SBrooks Davisrequest.
108*8269e767SBrooks DavisIf tracing process exits without detaching, for instance due to abnormal
109*8269e767SBrooks Davistermination, the destiny of the traced children processes is determined
110*8269e767SBrooks Davisby the
111*8269e767SBrooks Davis.Dv kern.kill_on_debugger_exit
112*8269e767SBrooks Davissysctl control.
113*8269e767SBrooks Davis.Pp
114*8269e767SBrooks DavisIf the control is set to the default value 1, such traced processes
115*8269e767SBrooks Davisare terminated.
116*8269e767SBrooks DavisIf set to zero, kernel implicitly detaches traced processes.
117*8269e767SBrooks DavisTraced processes are un-stopped if needed, and then continue the execution
118*8269e767SBrooks Daviswithout tracing.
119*8269e767SBrooks DavisKernel drops any
120*8269e767SBrooks Davis.Dv SIGTRAP
121*8269e767SBrooks Davissignals queued to the traced children, which could be either generated by
122*8269e767SBrooks Davisnot yet consumed debug events, or sent by other means, the later should
123*8269e767SBrooks Davisnot be done anyway.
124*8269e767SBrooks Davis.Sh SELECTING THE TARGET
125*8269e767SBrooks DavisThe
126*8269e767SBrooks Davis.Fa pid
127*8269e767SBrooks Davisargument of the call specifies the target on which to perform
128*8269e767SBrooks Davisthe requested operation.
129*8269e767SBrooks DavisFor operations affecting the global process state, the process ID
130*8269e767SBrooks Davisis typically passed there.
131*8269e767SBrooks DavisSimilarly, for operations affecting only a thread, the thread ID
132*8269e767SBrooks Davisneeds to be passed.
133*8269e767SBrooks Davis.Pp
134*8269e767SBrooks DavisStill, for global operations, the ID of any thread can be used as the
135*8269e767SBrooks Davistarget, and system will perform the request on the process owning
136*8269e767SBrooks Davisthat thread.
137*8269e767SBrooks DavisIf a thread operation got the process ID as
138*8269e767SBrooks Davis.Fa pid ,
139*8269e767SBrooks Davisthe system randomly selects a thread from among the threads owned
140*8269e767SBrooks Davisby the process.
141*8269e767SBrooks DavisFor single-threaded processes there is no difference between specifying
142*8269e767SBrooks Davisprocess or thread ID as the target.
143*8269e767SBrooks Davis.Sh DISABLING PTRACE
144*8269e767SBrooks DavisThe
145*8269e767SBrooks Davis.Nm
146*8269e767SBrooks Davissubsystem provides rich facilities to manipulate other processes state.
147*8269e767SBrooks DavisSometimes it may be desirable to disallow it either completely, or limit
148*8269e767SBrooks Davisits scope.
149*8269e767SBrooks DavisThe following controls are provided for this:
150*8269e767SBrooks Davis.Bl -tag -width security.bsd.unprivileged_proc_debug
151*8269e767SBrooks Davis.It Dv security.bsd.allow_ptrace
152*8269e767SBrooks DavisSetting this sysctl to zero makes
153*8269e767SBrooks Davis.Nm
154*8269e767SBrooks Davisreturn
155*8269e767SBrooks Davis.Er ENOSYS
156*8269e767SBrooks Davisalways as if the syscall is not implemented by the kernel.
157*8269e767SBrooks Davis.It Dv security.bsd.unprivileged_proc_debug
158*8269e767SBrooks DavisSetting this sysctl to zero disallows the use of
159*8269e767SBrooks Davis.Fn ptrace
160*8269e767SBrooks Davisby unprivileged processes.
161*8269e767SBrooks Davis.It Dv security.bsd.see_other_uids
162*8269e767SBrooks DavisSetting this sysctl to zero prevents
163*8269e767SBrooks Davis.Fn ptrace
164*8269e767SBrooks Davisrequests from targeting processes with a real user identifier different
165*8269e767SBrooks Davisfrom the caller's.
166*8269e767SBrooks DavisThese requests will fail with error
167*8269e767SBrooks Davis.Er ESRCH .
168*8269e767SBrooks Davis.It Dv security.bsd.see_other_gids
169*8269e767SBrooks DavisSetting this sysctl to zero disallows
170*8269e767SBrooks Davis.Fn ptrace
171*8269e767SBrooks Davisrequests from processes that have no groups in common with the target process,
172*8269e767SBrooks Davisconsidering their sets of real and supplementary groups.
173*8269e767SBrooks DavisThese requests will fail with error
174*8269e767SBrooks Davis.Er ESRCH .
175*8269e767SBrooks Davis.It Dv security.bsd.see_jail_proc
176*8269e767SBrooks DavisSetting this sysctl to zero disallows
177*8269e767SBrooks Davis.Fn ptrace
178*8269e767SBrooks Davisrequests from processes belonging to a different jail than that of the target
179*8269e767SBrooks Davisprocess, even if the requesting process' jail is an ancestor of the target
180*8269e767SBrooks Davisprocess'.
181*8269e767SBrooks DavisThese requests will fail with error
182*8269e767SBrooks Davis.Er ESRCH .
183*8269e767SBrooks Davis.It Dv securelevel and init
184*8269e767SBrooks DavisThe
185*8269e767SBrooks Davis.Xr init 1
186*8269e767SBrooks Davisprocess can only be traced with
187*8269e767SBrooks Davis.Nm
188*8269e767SBrooks Davisif securelevel is zero.
189*8269e767SBrooks Davis.It Dv procctl(2) PROC_TRACE_CTL
190*8269e767SBrooks DavisProcess can deny attempts to trace itself with
191*8269e767SBrooks Davis.Xr procctl 2
192*8269e767SBrooks Davis.Dv PROC_TRACE_CTL
193*8269e767SBrooks Davisrequest.
194*8269e767SBrooks DavisIn this case requests return
195*8269e767SBrooks Davis.Xr EPERM
196*8269e767SBrooks Daviserror.
197*8269e767SBrooks Davis.El
198*8269e767SBrooks Davis.Sh TRACING EVENTS
199*8269e767SBrooks Davis.Pp
200*8269e767SBrooks DavisEach traced process has a tracing event mask.
201*8269e767SBrooks DavisAn event in the traced process only reports a
202*8269e767SBrooks Davissignal stop if the corresponding flag is set in the tracing event mask.
203*8269e767SBrooks DavisThe current set of tracing event flags include:
204*8269e767SBrooks Davis.Bl -tag -width "Dv PTRACE_SYSCALL"
205*8269e767SBrooks Davis.It Dv PTRACE_EXEC
206*8269e767SBrooks DavisReport a stop for a successful invocation of
207*8269e767SBrooks Davis.Xr execve 2 .
208*8269e767SBrooks DavisThis event is indicated by the
209*8269e767SBrooks Davis.Dv PL_FLAG_EXEC
210*8269e767SBrooks Davisflag in the
211*8269e767SBrooks Davis.Va pl_flags
212*8269e767SBrooks Davismember of
213*8269e767SBrooks Davis.Vt "struct ptrace_lwpinfo" .
214*8269e767SBrooks Davis.It Dv PTRACE_SCE
215*8269e767SBrooks DavisReport a stop on each system call entry.
216*8269e767SBrooks DavisThis event is indicated by the
217*8269e767SBrooks Davis.Dv PL_FLAG_SCE
218*8269e767SBrooks Davisflag in the
219*8269e767SBrooks Davis.Va pl_flags
220*8269e767SBrooks Davismember of
221*8269e767SBrooks Davis.Vt "struct ptrace_lwpinfo" .
222*8269e767SBrooks Davis.It Dv PTRACE_SCX
223*8269e767SBrooks DavisReport a stop on each system call exit.
224*8269e767SBrooks DavisThis event is indicated by the
225*8269e767SBrooks Davis.Dv PL_FLAG_SCX
226*8269e767SBrooks Davisflag in the
227*8269e767SBrooks Davis.Va pl_flags
228*8269e767SBrooks Davismember of
229*8269e767SBrooks Davis.Vt "struct ptrace_lwpinfo" .
230*8269e767SBrooks Davis.It Dv PTRACE_SYSCALL
231*8269e767SBrooks DavisReport stops for both system call entry and exit.
232*8269e767SBrooks Davis.It Dv PTRACE_FORK
233*8269e767SBrooks DavisThis event flag controls tracing for new child processes of a traced process.
234*8269e767SBrooks Davis.Pp
235*8269e767SBrooks DavisWhen this event flag is enabled,
236*8269e767SBrooks Davisnew child processes will enable tracing and stop before executing their
237*8269e767SBrooks Davisfirst instruction.
238*8269e767SBrooks DavisThe new child process will include the
239*8269e767SBrooks Davis.Dv PL_FLAG_CHILD
240*8269e767SBrooks Davisflag in the
241*8269e767SBrooks Davis.Va pl_flags
242*8269e767SBrooks Davismember of
243*8269e767SBrooks Davis.Vt "struct ptrace_lwpinfo" .
244*8269e767SBrooks DavisThe traced process will report a stop that includes the
245*8269e767SBrooks Davis.Dv PL_FLAG_FORKED
246*8269e767SBrooks Davisflag.
247*8269e767SBrooks DavisThe process ID of the new child process will also be present in the
248*8269e767SBrooks Davis.Va pl_child_pid
249*8269e767SBrooks Davismember of
250*8269e767SBrooks Davis.Vt "struct ptrace_lwpinfo" .
251*8269e767SBrooks DavisIf the new child process was created via
252*8269e767SBrooks Davis.Xr vfork 2 ,
253*8269e767SBrooks Davisthe traced process's stop will also include the
254*8269e767SBrooks Davis.Dv PL_FLAG_VFORKED
255*8269e767SBrooks Davisflag.
256*8269e767SBrooks DavisNote that new child processes will be attached with the default
257*8269e767SBrooks Davistracing event mask;
258*8269e767SBrooks Davisthey do not inherit the event mask of the traced process.
259*8269e767SBrooks Davis.Pp
260*8269e767SBrooks DavisWhen this event flag is not enabled,
261*8269e767SBrooks Davisnew child processes will execute without tracing enabled.
262*8269e767SBrooks Davis.It Dv PTRACE_LWP
263*8269e767SBrooks DavisThis event flag controls tracing of LWP
264*8269e767SBrooks Davis.Pq kernel thread
265*8269e767SBrooks Daviscreation and destruction.
266*8269e767SBrooks DavisWhen this event is enabled,
267*8269e767SBrooks Davisnew LWPs will stop and report an event with
268*8269e767SBrooks Davis.Dv PL_FLAG_BORN
269*8269e767SBrooks Davisset before executing their first instruction,
270*8269e767SBrooks Davisand exiting LWPs will stop and report an event with
271*8269e767SBrooks Davis.Dv PL_FLAG_EXITED
272*8269e767SBrooks Davisset before completing their termination.
273*8269e767SBrooks Davis.Pp
274*8269e767SBrooks DavisNote that new processes do not report an event for the creation of their
275*8269e767SBrooks Davisinitial thread,
276*8269e767SBrooks Davisand exiting processes do not report an event for the termination of the
277*8269e767SBrooks Davislast thread.
278*8269e767SBrooks Davis.It Dv PTRACE_VFORK
279*8269e767SBrooks DavisReport a stop event when a parent process resumes after a
280*8269e767SBrooks Davis.Xr vfork 2 .
281*8269e767SBrooks Davis.Pp
282*8269e767SBrooks DavisWhen a thread in the traced process creates a new child process via
283*8269e767SBrooks Davis.Xr vfork 2 ,
284*8269e767SBrooks Davisthe stop that reports
285*8269e767SBrooks Davis.Dv PL_FLAG_FORKED
286*8269e767SBrooks Davisand
287*8269e767SBrooks Davis.Dv PL_FLAG_SCX
288*8269e767SBrooks Davisoccurs just after the child process is created,
289*8269e767SBrooks Davisbut before the thread waits for the child process to stop sharing process
290*8269e767SBrooks Davismemory.
291*8269e767SBrooks DavisIf a debugger is not tracing the new child process,
292*8269e767SBrooks Davisit must ensure that no breakpoints are enabled in the shared process
293*8269e767SBrooks Davismemory before detaching from the new child process.
294*8269e767SBrooks DavisThis means that no breakpoints are enabled in the parent process either.
295*8269e767SBrooks Davis.Pp
296*8269e767SBrooks DavisThe
297*8269e767SBrooks Davis.Dv PTRACE_VFORK
298*8269e767SBrooks Davisflag enables a new stop that indicates when the new child process stops
299*8269e767SBrooks Davissharing the process memory of the parent process.
300*8269e767SBrooks DavisA debugger can reinsert breakpoints in the parent process and resume it
301*8269e767SBrooks Davisin response to this event.
302*8269e767SBrooks DavisThis event is indicated by setting the
303*8269e767SBrooks Davis.Dv PL_FLAG_VFORK_DONE
304*8269e767SBrooks Davisflag.
305*8269e767SBrooks Davis.El
306*8269e767SBrooks Davis.Pp
307*8269e767SBrooks DavisThe default tracing event mask when attaching to a process via
308*8269e767SBrooks Davis.Dv PT_ATTACH ,
309*8269e767SBrooks Davis.Dv PT_TRACE_ME ,
310*8269e767SBrooks Davisor
311*8269e767SBrooks Davis.Dv PTRACE_FORK
312*8269e767SBrooks Davisincludes only
313*8269e767SBrooks Davis.Dv PTRACE_EXEC
314*8269e767SBrooks Davisevents.
315*8269e767SBrooks DavisAll other event flags are disabled.
316*8269e767SBrooks Davis.Sh PTRACE REQUESTS
317*8269e767SBrooks Davis.Pp
318*8269e767SBrooks DavisThe
319*8269e767SBrooks Davis.Fa request
320*8269e767SBrooks Davisargument specifies what operation is being performed; the meaning of
321*8269e767SBrooks Davisthe rest of the arguments depends on the operation, but except for one
322*8269e767SBrooks Davisspecial case noted below, all
323*8269e767SBrooks Davis.Fn ptrace
324*8269e767SBrooks Daviscalls are made by the tracing process, and the
325*8269e767SBrooks Davis.Fa pid
326*8269e767SBrooks Davisargument specifies the process ID of the traced process
327*8269e767SBrooks Davisor a corresponding thread ID.
328*8269e767SBrooks DavisThe
329*8269e767SBrooks Davis.Fa request
330*8269e767SBrooks Davisargument
331*8269e767SBrooks Daviscan be:
332*8269e767SBrooks Davis.Bl -tag -width "Dv PT_GET_EVENT_MASK"
333*8269e767SBrooks Davis.It Dv PT_TRACE_ME
334*8269e767SBrooks DavisThis request is the only one used by the traced process; it declares
335*8269e767SBrooks Davisthat the process expects to be traced by its parent.
336*8269e767SBrooks DavisAll the other arguments are ignored.
337*8269e767SBrooks Davis(If the parent process does not expect to trace the child, it will
338*8269e767SBrooks Davisprobably be rather confused by the results; once the traced process
339*8269e767SBrooks Davisstops, it cannot be made to continue except via
340*8269e767SBrooks Davis.Fn ptrace . )
341*8269e767SBrooks DavisWhen a process has used this request and calls
342*8269e767SBrooks Davis.Xr execve 2
343*8269e767SBrooks Davisor any of the routines built on it
344*8269e767SBrooks Davis(such as
345*8269e767SBrooks Davis.Xr execv 3 ) ,
346*8269e767SBrooks Davisit will stop before executing the first instruction of the new image.
347*8269e767SBrooks DavisAlso, any setuid or setgid bits on the executable being executed will
348*8269e767SBrooks Davisbe ignored.
349*8269e767SBrooks DavisIf the child was created by
350*8269e767SBrooks Davis.Xr vfork 2
351*8269e767SBrooks Davissystem call or
352*8269e767SBrooks Davis.Xr rfork 2
353*8269e767SBrooks Daviscall with the
354*8269e767SBrooks Davis.Dv RFMEM
355*8269e767SBrooks Davisflag specified, the debugging events are reported to the parent
356*8269e767SBrooks Davisonly after the
357*8269e767SBrooks Davis.Xr execve 2
358*8269e767SBrooks Davisis executed.
359*8269e767SBrooks Davis.It Dv PT_READ_I , Dv PT_READ_D
360*8269e767SBrooks DavisThese requests read a single
361*8269e767SBrooks Davis.Vt int
362*8269e767SBrooks Davisof data from the traced process's address space.
363*8269e767SBrooks DavisTraditionally,
364*8269e767SBrooks Davis.Fn ptrace
365*8269e767SBrooks Davishas allowed for machines with distinct address spaces for instruction
366*8269e767SBrooks Davisand data, which is why there are two requests: conceptually,
367*8269e767SBrooks Davis.Dv PT_READ_I
368*8269e767SBrooks Davisreads from the instruction space and
369*8269e767SBrooks Davis.Dv PT_READ_D
370*8269e767SBrooks Davisreads from the data space.
371*8269e767SBrooks DavisIn the current
372*8269e767SBrooks Davis.Fx
373*8269e767SBrooks Davisimplementation, these two requests are completely identical.
374*8269e767SBrooks DavisThe
375*8269e767SBrooks Davis.Fa addr
376*8269e767SBrooks Davisargument specifies the address
377*8269e767SBrooks Davis(in the traced process's virtual address space)
378*8269e767SBrooks Davisat which the read is to be done.
379*8269e767SBrooks DavisThis address does not have to meet any alignment constraints.
380*8269e767SBrooks DavisThe value read is returned as the return value from
381*8269e767SBrooks Davis.Fn ptrace .
382*8269e767SBrooks Davis.It Dv PT_WRITE_I , Dv PT_WRITE_D
383*8269e767SBrooks DavisThese requests parallel
384*8269e767SBrooks Davis.Dv PT_READ_I
385*8269e767SBrooks Davisand
386*8269e767SBrooks Davis.Dv PT_READ_D ,
387*8269e767SBrooks Davisexcept that they write rather than read.
388*8269e767SBrooks DavisThe
389*8269e767SBrooks Davis.Fa data
390*8269e767SBrooks Davisargument supplies the value to be written.
391*8269e767SBrooks Davis.It Dv PT_IO
392*8269e767SBrooks DavisThis request allows reading and writing arbitrary amounts of data in
393*8269e767SBrooks Davisthe traced process's address space.
394*8269e767SBrooks DavisThe
395*8269e767SBrooks Davis.Fa addr
396*8269e767SBrooks Davisargument specifies a pointer to a
397*8269e767SBrooks Davis.Vt "struct ptrace_io_desc" ,
398*8269e767SBrooks Daviswhich is defined as follows:
399*8269e767SBrooks Davis.Bd -literal
400*8269e767SBrooks Davisstruct ptrace_io_desc {
401*8269e767SBrooks Davis	int	piod_op;	/* I/O operation */
402*8269e767SBrooks Davis	void	*piod_offs;	/* child offset */
403*8269e767SBrooks Davis	void	*piod_addr;	/* parent offset */
404*8269e767SBrooks Davis	size_t	piod_len;	/* request length */
405*8269e767SBrooks Davis};
406*8269e767SBrooks Davis
407*8269e767SBrooks Davis/*
408*8269e767SBrooks Davis * Operations in piod_op.
409*8269e767SBrooks Davis */
410*8269e767SBrooks Davis#define PIOD_READ_D	1	/* Read from D space */
411*8269e767SBrooks Davis#define PIOD_WRITE_D	2	/* Write to D space */
412*8269e767SBrooks Davis#define PIOD_READ_I	3	/* Read from I space */
413*8269e767SBrooks Davis#define PIOD_WRITE_I	4	/* Write to I space */
414*8269e767SBrooks Davis.Ed
415*8269e767SBrooks Davis.Pp
416*8269e767SBrooks DavisThe
417*8269e767SBrooks Davis.Fa data
418*8269e767SBrooks Davisargument is ignored.
419*8269e767SBrooks DavisThe actual number of bytes read or written is stored in
420*8269e767SBrooks Davis.Va piod_len
421*8269e767SBrooks Davisupon return.
422*8269e767SBrooks Davis.It Dv PT_CONTINUE
423*8269e767SBrooks DavisThe traced process continues execution.
424*8269e767SBrooks DavisThe
425*8269e767SBrooks Davis.Fa addr
426*8269e767SBrooks Davisargument
427*8269e767SBrooks Davisis an address specifying the place where execution is to be resumed
428*8269e767SBrooks Davis(a new value for the program counter),
429*8269e767SBrooks Davisor
430*8269e767SBrooks Davis.Po Vt caddr_t Pc Ns 1
431*8269e767SBrooks Davisto indicate that execution is to pick up where it left off.
432*8269e767SBrooks DavisThe
433*8269e767SBrooks Davis.Fa data
434*8269e767SBrooks Davisargument
435*8269e767SBrooks Davisprovides a signal number to be delivered to the traced process as it
436*8269e767SBrooks Davisresumes execution, or 0 if no signal is to be sent.
437*8269e767SBrooks Davis.It Dv PT_STEP
438*8269e767SBrooks DavisThe traced process is single stepped one instruction.
439*8269e767SBrooks DavisThe
440*8269e767SBrooks Davis.Fa addr
441*8269e767SBrooks Davisargument
442*8269e767SBrooks Davisshould be passed
443*8269e767SBrooks Davis.Po Vt caddr_t Pc Ns 1 .
444*8269e767SBrooks DavisThe
445*8269e767SBrooks Davis.Fa data
446*8269e767SBrooks Davisargument
447*8269e767SBrooks Davisprovides a signal number to be delivered to the traced process as it
448*8269e767SBrooks Davisresumes execution, or 0 if no signal is to be sent.
449*8269e767SBrooks Davis.It Dv PT_KILL
450*8269e767SBrooks DavisThe traced process terminates, as if
451*8269e767SBrooks Davis.Dv PT_CONTINUE
452*8269e767SBrooks Davishad been used with
453*8269e767SBrooks Davis.Dv SIGKILL
454*8269e767SBrooks Davisgiven as the signal to be delivered.
455*8269e767SBrooks Davis.It Dv PT_ATTACH
456*8269e767SBrooks DavisThis request allows a process to gain control of an otherwise
457*8269e767SBrooks Davisunrelated process and begin tracing it.
458*8269e767SBrooks DavisIt does not need any cooperation from the process to trace.
459*8269e767SBrooks DavisIn
460*8269e767SBrooks Davisthis case,
461*8269e767SBrooks Davis.Fa pid
462*8269e767SBrooks Davisspecifies the process ID of the process to trace, and the other
463*8269e767SBrooks Davistwo arguments are ignored.
464*8269e767SBrooks DavisThis request requires that the target process must have the same real
465*8269e767SBrooks DavisUID as the tracing process, and that it must not be executing a setuid
466*8269e767SBrooks Davisor setgid executable.
467*8269e767SBrooks Davis(If the tracing process is running as root, these restrictions do not
468*8269e767SBrooks Davisapply.)
469*8269e767SBrooks DavisThe tracing process will see the newly-traced process stop and may
470*8269e767SBrooks Davisthen control it as if it had been traced all along.
471*8269e767SBrooks Davis.It Dv PT_DETACH
472*8269e767SBrooks DavisThis request is like PT_CONTINUE, except that it does not allow
473*8269e767SBrooks Davisspecifying an alternate place to continue execution, and after it
474*8269e767SBrooks Davissucceeds, the traced process is no longer traced and continues
475*8269e767SBrooks Davisexecution normally.
476*8269e767SBrooks Davis.It Dv PT_GETREGS
477*8269e767SBrooks DavisThis request reads the traced process's machine registers into the
478*8269e767SBrooks Davis.Do
479*8269e767SBrooks Davis.Vt "struct reg"
480*8269e767SBrooks Davis.Dc
481*8269e767SBrooks Davis(defined in
482*8269e767SBrooks Davis.In machine/reg.h )
483*8269e767SBrooks Davispointed to by
484*8269e767SBrooks Davis.Fa addr .
485*8269e767SBrooks Davis.It Dv PT_SETREGS
486*8269e767SBrooks DavisThis request is the converse of
487*8269e767SBrooks Davis.Dv PT_GETREGS ;
488*8269e767SBrooks Davisit loads the traced process's machine registers from the
489*8269e767SBrooks Davis.Do
490*8269e767SBrooks Davis.Vt "struct reg"
491*8269e767SBrooks Davis.Dc
492*8269e767SBrooks Davis(defined in
493*8269e767SBrooks Davis.In machine/reg.h )
494*8269e767SBrooks Davispointed to by
495*8269e767SBrooks Davis.Fa addr .
496*8269e767SBrooks Davis.It Dv PT_GETFPREGS
497*8269e767SBrooks DavisThis request reads the traced process's floating-point registers into
498*8269e767SBrooks Davisthe
499*8269e767SBrooks Davis.Do
500*8269e767SBrooks Davis.Vt "struct fpreg"
501*8269e767SBrooks Davis.Dc
502*8269e767SBrooks Davis(defined in
503*8269e767SBrooks Davis.In machine/reg.h )
504*8269e767SBrooks Davispointed to by
505*8269e767SBrooks Davis.Fa addr .
506*8269e767SBrooks Davis.It Dv PT_SETFPREGS
507*8269e767SBrooks DavisThis request is the converse of
508*8269e767SBrooks Davis.Dv PT_GETFPREGS ;
509*8269e767SBrooks Davisit loads the traced process's floating-point registers from the
510*8269e767SBrooks Davis.Do
511*8269e767SBrooks Davis.Vt "struct fpreg"
512*8269e767SBrooks Davis.Dc
513*8269e767SBrooks Davis(defined in
514*8269e767SBrooks Davis.In machine/reg.h )
515*8269e767SBrooks Davispointed to by
516*8269e767SBrooks Davis.Fa addr .
517*8269e767SBrooks Davis.It Dv PT_GETDBREGS
518*8269e767SBrooks DavisThis request reads the traced process's debug registers into
519*8269e767SBrooks Davisthe
520*8269e767SBrooks Davis.Do
521*8269e767SBrooks Davis.Vt "struct dbreg"
522*8269e767SBrooks Davis.Dc
523*8269e767SBrooks Davis(defined in
524*8269e767SBrooks Davis.In machine/reg.h )
525*8269e767SBrooks Davispointed to by
526*8269e767SBrooks Davis.Fa addr .
527*8269e767SBrooks Davis.It Dv PT_SETDBREGS
528*8269e767SBrooks DavisThis request is the converse of
529*8269e767SBrooks Davis.Dv PT_GETDBREGS ;
530*8269e767SBrooks Davisit loads the traced process's debug registers from the
531*8269e767SBrooks Davis.Do
532*8269e767SBrooks Davis.Vt "struct dbreg"
533*8269e767SBrooks Davis.Dc
534*8269e767SBrooks Davis(defined in
535*8269e767SBrooks Davis.In machine/reg.h )
536*8269e767SBrooks Davispointed to by
537*8269e767SBrooks Davis.Fa addr .
538*8269e767SBrooks Davis.It Dv PT_GETREGSET
539*8269e767SBrooks DavisThis request reads the registers from the traced process.
540*8269e767SBrooks DavisThe
541*8269e767SBrooks Davis.Fa data
542*8269e767SBrooks Davisargument specifies the register set to read, with the
543*8269e767SBrooks Davis.Fa addr
544*8269e767SBrooks Davisargument pointing at a
545*8269e767SBrooks Davis.Vt "struct iovec"
546*8269e767SBrooks Daviswhere the
547*8269e767SBrooks Davis.Va iov_base
548*8269e767SBrooks Davisfield points to a register set specific structure to hold the registers,
549*8269e767SBrooks Davisand the
550*8269e767SBrooks Davis.Va iov_len
551*8269e767SBrooks Davisfield holds the length of the structure.
552*8269e767SBrooks Davis.It Dv PT_SETREGSET
553*8269e767SBrooks DavisThis request writes to the registers of the traced process.
554*8269e767SBrooks DavisThe
555*8269e767SBrooks Davis.Fa data
556*8269e767SBrooks Davisargument specifies the register set to write to, with the
557*8269e767SBrooks Davis.Fa addr
558*8269e767SBrooks Davisargument pointing at a
559*8269e767SBrooks Davis.Vt "struct iovec"
560*8269e767SBrooks Daviswhere the
561*8269e767SBrooks Davis.Va iov_base
562*8269e767SBrooks Davisfield points to a register set specific structure to hold the registers,
563*8269e767SBrooks Davisand the
564*8269e767SBrooks Davis.Va iov_len
565*8269e767SBrooks Davisfield holds the length of the structure.
566*8269e767SBrooks DavisIf
567*8269e767SBrooks Davis.Va iov_base
568*8269e767SBrooks Davisis NULL the kernel will return the expected length of the register set
569*8269e767SBrooks Davisspecific structure in the
570*8269e767SBrooks Davis.Va iov_len
571*8269e767SBrooks Davisfield and not change the target register set.
572*8269e767SBrooks Davis.It Dv PT_LWPINFO
573*8269e767SBrooks DavisThis request can be used to obtain information about the kernel thread,
574*8269e767SBrooks Davisalso known as light-weight process, that caused the traced process to stop.
575*8269e767SBrooks DavisThe
576*8269e767SBrooks Davis.Fa addr
577*8269e767SBrooks Davisargument specifies a pointer to a
578*8269e767SBrooks Davis.Vt "struct ptrace_lwpinfo" ,
579*8269e767SBrooks Daviswhich is defined as follows:
580*8269e767SBrooks Davis.Bd -literal
581*8269e767SBrooks Davisstruct ptrace_lwpinfo {
582*8269e767SBrooks Davis	lwpid_t pl_lwpid;
583*8269e767SBrooks Davis	int	pl_event;
584*8269e767SBrooks Davis	int	pl_flags;
585*8269e767SBrooks Davis	sigset_t pl_sigmask;
586*8269e767SBrooks Davis	sigset_t pl_siglist;
587*8269e767SBrooks Davis	siginfo_t pl_siginfo;
588*8269e767SBrooks Davis	char	pl_tdname[MAXCOMLEN + 1];
589*8269e767SBrooks Davis	pid_t	pl_child_pid;
590*8269e767SBrooks Davis	u_int	pl_syscall_code;
591*8269e767SBrooks Davis	u_int	pl_syscall_narg;
592*8269e767SBrooks Davis};
593*8269e767SBrooks Davis.Ed
594*8269e767SBrooks Davis.Pp
595*8269e767SBrooks DavisThe
596*8269e767SBrooks Davis.Fa data
597*8269e767SBrooks Davisargument is to be set to the size of the structure known to the caller.
598*8269e767SBrooks DavisThis allows the structure to grow without affecting older programs.
599*8269e767SBrooks Davis.Pp
600*8269e767SBrooks DavisThe fields in the
601*8269e767SBrooks Davis.Vt "struct ptrace_lwpinfo"
602*8269e767SBrooks Davishave the following meaning:
603*8269e767SBrooks Davis.Bl -tag -width indent -compact
604*8269e767SBrooks Davis.It Va pl_lwpid
605*8269e767SBrooks DavisLWP id of the thread
606*8269e767SBrooks Davis.It Va pl_event
607*8269e767SBrooks DavisEvent that caused the stop.
608*8269e767SBrooks DavisCurrently defined events are:
609*8269e767SBrooks Davis.Bl -tag -width "Dv PL_EVENT_SIGNAL" -compact
610*8269e767SBrooks Davis.It Dv PL_EVENT_NONE
611*8269e767SBrooks DavisNo reason given
612*8269e767SBrooks Davis.It Dv PL_EVENT_SIGNAL
613*8269e767SBrooks DavisThread stopped due to the pending signal
614*8269e767SBrooks Davis.El
615*8269e767SBrooks Davis.It Va pl_flags
616*8269e767SBrooks DavisFlags that specify additional details about observed stop.
617*8269e767SBrooks DavisCurrently defined flags are:
618*8269e767SBrooks Davis.Bl -tag -width indent -compact
619*8269e767SBrooks Davis.It Dv PL_FLAG_SCE
620*8269e767SBrooks DavisThe thread stopped due to system call entry, right after the kernel is entered.
621*8269e767SBrooks DavisThe debugger may examine syscall arguments that are stored in memory and
622*8269e767SBrooks Davisregisters according to the ABI of the current process, and modify them,
623*8269e767SBrooks Davisif needed.
624*8269e767SBrooks Davis.It Dv PL_FLAG_SCX
625*8269e767SBrooks DavisThe thread is stopped immediately before syscall is returning to the usermode.
626*8269e767SBrooks DavisThe debugger may examine system call return values in the ABI-defined registers
627*8269e767SBrooks Davisand/or memory.
628*8269e767SBrooks Davis.It Dv PL_FLAG_EXEC
629*8269e767SBrooks DavisWhen
630*8269e767SBrooks Davis.Dv PL_FLAG_SCX
631*8269e767SBrooks Davisis set, this flag may be additionally specified to inform that the
632*8269e767SBrooks Davisprogram being executed by debuggee process has been changed by successful
633*8269e767SBrooks Davisexecution of a system call from the
634*8269e767SBrooks Davis.Fn execve 2
635*8269e767SBrooks Davisfamily.
636*8269e767SBrooks Davis.It Dv PL_FLAG_SI
637*8269e767SBrooks DavisIndicates that
638*8269e767SBrooks Davis.Va pl_siginfo
639*8269e767SBrooks Davismember of
640*8269e767SBrooks Davis.Vt "struct ptrace_lwpinfo"
641*8269e767SBrooks Daviscontains valid information.
642*8269e767SBrooks Davis.It Dv PL_FLAG_FORKED
643*8269e767SBrooks DavisIndicates that the process is returning from a call to
644*8269e767SBrooks Davis.Fn fork 2
645*8269e767SBrooks Davisthat created a new child process.
646*8269e767SBrooks DavisThe process identifier of the new process is available in the
647*8269e767SBrooks Davis.Va pl_child_pid
648*8269e767SBrooks Davismember of
649*8269e767SBrooks Davis.Vt "struct ptrace_lwpinfo" .
650*8269e767SBrooks Davis.It Dv PL_FLAG_CHILD
651*8269e767SBrooks DavisThe flag is set for first event reported from a new child which is
652*8269e767SBrooks Davisautomatically attached when
653*8269e767SBrooks Davis.Dv PTRACE_FORK
654*8269e767SBrooks Davisis enabled.
655*8269e767SBrooks Davis.It Dv PL_FLAG_BORN
656*8269e767SBrooks DavisThis flag is set for the first event reported from a new LWP when
657*8269e767SBrooks Davis.Dv PTRACE_LWP
658*8269e767SBrooks Davisis enabled.
659*8269e767SBrooks DavisIt is reported along with
660*8269e767SBrooks Davis.Dv PL_FLAG_SCX .
661*8269e767SBrooks Davis.It Dv PL_FLAG_EXITED
662*8269e767SBrooks DavisThis flag is set for the last event reported by an exiting LWP when
663*8269e767SBrooks Davis.Dv PTRACE_LWP
664*8269e767SBrooks Davisis enabled.
665*8269e767SBrooks DavisNote that this event is not reported when the last LWP in a process exits.
666*8269e767SBrooks DavisThe termination of the last thread is reported via a normal process exit
667*8269e767SBrooks Davisevent.
668*8269e767SBrooks Davis.It Dv PL_FLAG_VFORKED
669*8269e767SBrooks DavisIndicates that the thread is returning from a call to
670*8269e767SBrooks Davis.Xr vfork 2
671*8269e767SBrooks Davisthat created a new child process.
672*8269e767SBrooks DavisThis flag is set in addition to
673*8269e767SBrooks Davis.Dv PL_FLAG_FORKED .
674*8269e767SBrooks Davis.It Dv PL_FLAG_VFORK_DONE
675*8269e767SBrooks DavisIndicates that the thread has resumed after a child process created via
676*8269e767SBrooks Davis.Xr vfork 2
677*8269e767SBrooks Davishas stopped sharing its address space with the traced process.
678*8269e767SBrooks Davis.El
679*8269e767SBrooks Davis.It Va pl_sigmask
680*8269e767SBrooks DavisThe current signal mask of the LWP
681*8269e767SBrooks Davis.It Va pl_siglist
682*8269e767SBrooks DavisThe current pending set of signals for the LWP.
683*8269e767SBrooks DavisNote that signals that are delivered to the process would not appear
684*8269e767SBrooks Davison an LWP siglist until the thread is selected for delivery.
685*8269e767SBrooks Davis.It Va pl_siginfo
686*8269e767SBrooks DavisThe siginfo that accompanies the signal pending.
687*8269e767SBrooks DavisOnly valid for
688*8269e767SBrooks Davis.Dv PL_EVENT_SIGNAL
689*8269e767SBrooks Davisstop when
690*8269e767SBrooks Davis.Dv PL_FLAG_SI
691*8269e767SBrooks Davisis set in
692*8269e767SBrooks Davis.Va pl_flags .
693*8269e767SBrooks Davis.It Va pl_tdname
694*8269e767SBrooks DavisThe name of the thread.
695*8269e767SBrooks Davis.It Va pl_child_pid
696*8269e767SBrooks DavisThe process identifier of the new child process.
697*8269e767SBrooks DavisOnly valid for a
698*8269e767SBrooks Davis.Dv PL_EVENT_SIGNAL
699*8269e767SBrooks Davisstop when
700*8269e767SBrooks Davis.Dv PL_FLAG_FORKED
701*8269e767SBrooks Davisis set in
702*8269e767SBrooks Davis.Va pl_flags .
703*8269e767SBrooks Davis.It Va pl_syscall_code
704*8269e767SBrooks DavisThe ABI-specific identifier of the current system call.
705*8269e767SBrooks DavisNote that for indirect system calls this field reports the indirected
706*8269e767SBrooks Davissystem call.
707*8269e767SBrooks DavisOnly valid when
708*8269e767SBrooks Davis.Dv PL_FLAG_SCE
709*8269e767SBrooks Davisor
710*8269e767SBrooks Davis.Dv PL_FLAG_SCX
711*8269e767SBrooks Davisis set in
712*8269e767SBrooks Davis.Va pl_flags .
713*8269e767SBrooks Davis.It Va pl_syscall_narg
714*8269e767SBrooks DavisThe number of arguments passed to the current system call not counting
715*8269e767SBrooks Davisthe system call identifier.
716*8269e767SBrooks DavisNote that for indirect system calls this field reports the arguments
717*8269e767SBrooks Davispassed to the indirected system call.
718*8269e767SBrooks DavisOnly valid when
719*8269e767SBrooks Davis.Dv PL_FLAG_SCE
720*8269e767SBrooks Davisor
721*8269e767SBrooks Davis.Dv PL_FLAG_SCX
722*8269e767SBrooks Davisis set in
723*8269e767SBrooks Davis.Va pl_flags .
724*8269e767SBrooks Davis.El
725*8269e767SBrooks Davis.It Dv PT_GETNUMLWPS
726*8269e767SBrooks DavisThis request returns the number of kernel threads associated with the
727*8269e767SBrooks Davistraced process.
728*8269e767SBrooks Davis.It Dv PT_GETLWPLIST
729*8269e767SBrooks DavisThis request can be used to get the current thread list.
730*8269e767SBrooks DavisA pointer to an array of type
731*8269e767SBrooks Davis.Vt lwpid_t
732*8269e767SBrooks Davisshould be passed in
733*8269e767SBrooks Davis.Fa addr ,
734*8269e767SBrooks Daviswith the array size specified by
735*8269e767SBrooks Davis.Fa data .
736*8269e767SBrooks DavisThe return value from
737*8269e767SBrooks Davis.Fn ptrace
738*8269e767SBrooks Davisis the count of array entries filled in.
739*8269e767SBrooks Davis.It Dv PT_SETSTEP
740*8269e767SBrooks DavisThis request will turn on single stepping of the specified process.
741*8269e767SBrooks DavisStepping is automatically disabled when a single step trap is caught.
742*8269e767SBrooks Davis.It Dv PT_CLEARSTEP
743*8269e767SBrooks DavisThis request will turn off single stepping of the specified process.
744*8269e767SBrooks Davis.It Dv PT_SUSPEND
745*8269e767SBrooks DavisThis request will suspend the specified thread.
746*8269e767SBrooks Davis.It Dv PT_RESUME
747*8269e767SBrooks DavisThis request will resume the specified thread.
748*8269e767SBrooks Davis.It Dv PT_TO_SCE
749*8269e767SBrooks DavisThis request will set the
750*8269e767SBrooks Davis.Dv PTRACE_SCE
751*8269e767SBrooks Davisevent flag to trace all future system call entries and continue the process.
752*8269e767SBrooks DavisThe
753*8269e767SBrooks Davis.Fa addr
754*8269e767SBrooks Davisand
755*8269e767SBrooks Davis.Fa data
756*8269e767SBrooks Davisarguments are used the same as for
757*8269e767SBrooks Davis.Dv PT_CONTINUE .
758*8269e767SBrooks Davis.It Dv PT_TO_SCX
759*8269e767SBrooks DavisThis request will set the
760*8269e767SBrooks Davis.Dv PTRACE_SCX
761*8269e767SBrooks Davisevent flag to trace all future system call exits and continue the process.
762*8269e767SBrooks DavisThe
763*8269e767SBrooks Davis.Fa addr
764*8269e767SBrooks Davisand
765*8269e767SBrooks Davis.Fa data
766*8269e767SBrooks Davisarguments are used the same as for
767*8269e767SBrooks Davis.Dv PT_CONTINUE .
768*8269e767SBrooks Davis.It Dv PT_SYSCALL
769*8269e767SBrooks DavisThis request will set the
770*8269e767SBrooks Davis.Dv PTRACE_SYSCALL
771*8269e767SBrooks Davisevent flag to trace all future system call entries and exits and continue
772*8269e767SBrooks Davisthe process.
773*8269e767SBrooks DavisThe
774*8269e767SBrooks Davis.Fa addr
775*8269e767SBrooks Davisand
776*8269e767SBrooks Davis.Fa data
777*8269e767SBrooks Davisarguments are used the same as for
778*8269e767SBrooks Davis.Dv PT_CONTINUE .
779*8269e767SBrooks Davis.It Dv PT_GET_SC_ARGS
780*8269e767SBrooks DavisFor the thread which is stopped in either
781*8269e767SBrooks Davis.Dv PL_FLAG_SCE
782*8269e767SBrooks Davisor
783*8269e767SBrooks Davis.Dv PL_FLAG_SCX
784*8269e767SBrooks Davisstate, that is, on entry or exit to a syscall,
785*8269e767SBrooks Davisthis request fetches the syscall arguments.
786*8269e767SBrooks Davis.Pp
787*8269e767SBrooks DavisThe arguments are copied out into the buffer pointed to by the
788*8269e767SBrooks Davis.Fa addr
789*8269e767SBrooks Davispointer, sequentially.
790*8269e767SBrooks DavisEach syscall argument is stored as the machine word.
791*8269e767SBrooks DavisKernel copies out as many arguments as the syscall accepts,
792*8269e767SBrooks Davissee the
793*8269e767SBrooks Davis.Va pl_syscall_narg
794*8269e767SBrooks Davismember of the
795*8269e767SBrooks Davis.Vt struct ptrace_lwpinfo ,
796*8269e767SBrooks Davisbut not more than the
797*8269e767SBrooks Davis.Fa data
798*8269e767SBrooks Davisbytes in total are copied.
799*8269e767SBrooks Davis.It Dv PT_GET_SC_RET
800*8269e767SBrooks DavisFetch the system call return values on exit from a syscall.
801*8269e767SBrooks DavisThis request is only valid for threads stopped in a syscall
802*8269e767SBrooks Davisexit (the
803*8269e767SBrooks Davis.Dv PL_FLAG_SCX
804*8269e767SBrooks Davisstate).
805*8269e767SBrooks DavisThe
806*8269e767SBrooks Davis.Fa addr
807*8269e767SBrooks Davisargument specifies a pointer to a
808*8269e767SBrooks Davis.Vt "struct ptrace_sc_ret" ,
809*8269e767SBrooks Daviswhich is defined as follows:
810*8269e767SBrooks Davis.Bd -literal
811*8269e767SBrooks Davisstruct ptrace_sc_ret {
812*8269e767SBrooks Davis	register_t	sr_retval[2];
813*8269e767SBrooks Davis	int		sr_error;
814*8269e767SBrooks Davis};
815*8269e767SBrooks Davis.Ed
816*8269e767SBrooks Davis.Pp
817*8269e767SBrooks DavisThe
818*8269e767SBrooks Davis.Fa data
819*8269e767SBrooks Davisargument is set to the size of the structure.
820*8269e767SBrooks Davis.Pp
821*8269e767SBrooks DavisIf the system call completed successfully,
822*8269e767SBrooks Davis.Va sr_error
823*8269e767SBrooks Davisis set to zero and the return values of the system call are saved in
824*8269e767SBrooks Davis.Va sr_retval .
825*8269e767SBrooks DavisIf the system call failed to execute,
826*8269e767SBrooks Davis.Va sr_error
827*8269e767SBrooks Davisfield is set to a positive
828*8269e767SBrooks Davis.Xr errno 2
829*8269e767SBrooks Davisvalue.
830*8269e767SBrooks DavisIf the system call completed in an unusual fashion,
831*8269e767SBrooks Davis.Va sr_error
832*8269e767SBrooks Davisis set to a negative value:
833*8269e767SBrooks Davis.Bl -tag -width Dv EJUSTRETURN -compact
834*8269e767SBrooks Davis.It Dv ERESTART
835*8269e767SBrooks DavisSystem call will be restarted.
836*8269e767SBrooks Davis.It Dv EJUSTRETURN
837*8269e767SBrooks DavisSystem call completed sucessfully but did not set a return value
838*8269e767SBrooks Davis.Po for example,
839*8269e767SBrooks Davis.Xr setcontext 2
840*8269e767SBrooks Davisand
841*8269e767SBrooks Davis.Xr sigreturn 2
842*8269e767SBrooks Davis.Pc .
843*8269e767SBrooks Davis.El
844*8269e767SBrooks Davis.It Dv PT_FOLLOW_FORK
845*8269e767SBrooks DavisThis request controls tracing for new child processes of a traced process.
846*8269e767SBrooks DavisIf
847*8269e767SBrooks Davis.Fa data
848*8269e767SBrooks Davisis non-zero,
849*8269e767SBrooks Davis.Dv PTRACE_FORK
850*8269e767SBrooks Davisis set in the traced process's event tracing mask.
851*8269e767SBrooks DavisIf
852*8269e767SBrooks Davis.Fa data
853*8269e767SBrooks Davisis zero,
854*8269e767SBrooks Davis.Dv PTRACE_FORK
855*8269e767SBrooks Davisis cleared from the traced process's event tracing mask.
856*8269e767SBrooks Davis.It Dv PT_LWP_EVENTS
857*8269e767SBrooks DavisThis request controls tracing of LWP creation and destruction.
858*8269e767SBrooks DavisIf
859*8269e767SBrooks Davis.Fa data
860*8269e767SBrooks Davisis non-zero,
861*8269e767SBrooks Davis.Dv PTRACE_LWP
862*8269e767SBrooks Davisis set in the traced process's event tracing mask.
863*8269e767SBrooks DavisIf
864*8269e767SBrooks Davis.Fa data
865*8269e767SBrooks Davisis zero,
866*8269e767SBrooks Davis.Dv PTRACE_LWP
867*8269e767SBrooks Davisis cleared from the traced process's event tracing mask.
868*8269e767SBrooks Davis.It Dv PT_GET_EVENT_MASK
869*8269e767SBrooks DavisThis request reads the traced process's event tracing mask into the
870*8269e767SBrooks Davisinteger pointed to by
871*8269e767SBrooks Davis.Fa addr .
872*8269e767SBrooks DavisThe size of the integer must be passed in
873*8269e767SBrooks Davis.Fa data .
874*8269e767SBrooks Davis.It Dv PT_SET_EVENT_MASK
875*8269e767SBrooks DavisThis request sets the traced process's event tracing mask from the
876*8269e767SBrooks Davisinteger pointed to by
877*8269e767SBrooks Davis.Fa addr .
878*8269e767SBrooks DavisThe size of the integer must be passed in
879*8269e767SBrooks Davis.Fa data .
880*8269e767SBrooks Davis.It Dv PT_VM_TIMESTAMP
881*8269e767SBrooks DavisThis request returns the generation number or timestamp of the memory map of
882*8269e767SBrooks Davisthe traced process as the return value from
883*8269e767SBrooks Davis.Fn ptrace .
884*8269e767SBrooks DavisThis provides a low-cost way for the tracing process to determine if the
885*8269e767SBrooks DavisVM map changed since the last time this request was made.
886*8269e767SBrooks Davis.It Dv PT_VM_ENTRY
887*8269e767SBrooks DavisThis request is used to iterate over the entries of the VM map of the traced
888*8269e767SBrooks Davisprocess.
889*8269e767SBrooks DavisThe
890*8269e767SBrooks Davis.Fa addr
891*8269e767SBrooks Davisargument specifies a pointer to a
892*8269e767SBrooks Davis.Vt "struct ptrace_vm_entry" ,
893*8269e767SBrooks Daviswhich is defined as follows:
894*8269e767SBrooks Davis.Bd -literal
895*8269e767SBrooks Davisstruct ptrace_vm_entry {
896*8269e767SBrooks Davis	int		pve_entry;
897*8269e767SBrooks Davis	int		pve_timestamp;
898*8269e767SBrooks Davis	u_long		pve_start;
899*8269e767SBrooks Davis	u_long		pve_end;
900*8269e767SBrooks Davis	u_long		pve_offset;
901*8269e767SBrooks Davis	u_int		pve_prot;
902*8269e767SBrooks Davis	u_int		pve_pathlen;
903*8269e767SBrooks Davis	long		pve_fileid;
904*8269e767SBrooks Davis	uint32_t	pve_fsid;
905*8269e767SBrooks Davis	char		*pve_path;
906*8269e767SBrooks Davis};
907*8269e767SBrooks Davis.Ed
908*8269e767SBrooks Davis.Pp
909*8269e767SBrooks DavisThe first entry is returned by setting
910*8269e767SBrooks Davis.Va pve_entry
911*8269e767SBrooks Davisto zero.
912*8269e767SBrooks DavisSubsequent entries are returned by leaving
913*8269e767SBrooks Davis.Va pve_entry
914*8269e767SBrooks Davisunmodified from the value returned by previous requests.
915*8269e767SBrooks DavisThe
916*8269e767SBrooks Davis.Va pve_timestamp
917*8269e767SBrooks Davisfield can be used to detect changes to the VM map while iterating over the
918*8269e767SBrooks Davisentries.
919*8269e767SBrooks DavisThe tracing process can then take appropriate action, such as restarting.
920*8269e767SBrooks DavisBy setting
921*8269e767SBrooks Davis.Va pve_pathlen
922*8269e767SBrooks Davisto a non-zero value on entry, the pathname of the backing object is returned
923*8269e767SBrooks Davisin the buffer pointed to by
924*8269e767SBrooks Davis.Va pve_path ,
925*8269e767SBrooks Davisprovided the entry is backed by a vnode.
926*8269e767SBrooks DavisThe
927*8269e767SBrooks Davis.Va pve_pathlen
928*8269e767SBrooks Davisfield is updated with the actual length of the pathname (including the
929*8269e767SBrooks Davisterminating null character).
930*8269e767SBrooks DavisThe
931*8269e767SBrooks Davis.Va pve_offset
932*8269e767SBrooks Davisfield is the offset within the backing object at which the range starts.
933*8269e767SBrooks DavisThe range is located in the VM space at
934*8269e767SBrooks Davis.Va pve_start
935*8269e767SBrooks Davisand extends up to
936*8269e767SBrooks Davis.Va pve_end
937*8269e767SBrooks Davis(inclusive).
938*8269e767SBrooks Davis.Pp
939*8269e767SBrooks DavisThe
940*8269e767SBrooks Davis.Fa data
941*8269e767SBrooks Davisargument is ignored.
942*8269e767SBrooks Davis.It Dv PT_COREDUMP
943*8269e767SBrooks DavisThis request creates a coredump for the stopped program.
944*8269e767SBrooks DavisThe
945*8269e767SBrooks Davis.Fa addr
946*8269e767SBrooks Davisargument specifies a pointer to a
947*8269e767SBrooks Davis.Vt "struct ptrace_coredump" ,
948*8269e767SBrooks Daviswhich is defined as follows:
949*8269e767SBrooks Davis.Bd -literal
950*8269e767SBrooks Davisstruct ptrace_coredump {
951*8269e767SBrooks Davis	int		pc_fd;
952*8269e767SBrooks Davis	uint32_t	pc_flags;
953*8269e767SBrooks Davis	off_t		pc_limit;
954*8269e767SBrooks Davis};
955*8269e767SBrooks Davis.Ed
956*8269e767SBrooks DavisThe fields of the structure are:
957*8269e767SBrooks Davis.Bl -tag -width pc_flags
958*8269e767SBrooks Davis.It Dv pc_fd
959*8269e767SBrooks DavisFile descriptor to write the dump to.
960*8269e767SBrooks DavisIt must refer to a regular file, opened for writing.
961*8269e767SBrooks Davis.It Dv pc_flags
962*8269e767SBrooks DavisFlags.
963*8269e767SBrooks DavisThe following flags are defined:
964*8269e767SBrooks Davis.Bl -tag -width PC_COMPRESS
965*8269e767SBrooks Davis.It Dv PC_COMPRESS
966*8269e767SBrooks DavisRequest compression of the dump.
967*8269e767SBrooks Davis.It Dv PC_ALL
968*8269e767SBrooks DavisInclude non-dumpable entries into the dump.
969*8269e767SBrooks DavisThe dumper ignores
970*8269e767SBrooks Davis.Dv MAP_NOCORE
971*8269e767SBrooks Davisflag of the process map entry, but device mappings are not dumped even with
972*8269e767SBrooks Davis.Dv PC_ALL
973*8269e767SBrooks Davisset.
974*8269e767SBrooks Davis.El
975*8269e767SBrooks Davis.It Dv pc_limit
976*8269e767SBrooks DavisMaximum size of the coredump.
977*8269e767SBrooks DavisSpecify zero for no limit.
978*8269e767SBrooks Davis.El
979*8269e767SBrooks Davis.Pp
980*8269e767SBrooks DavisThe size of
981*8269e767SBrooks Davis.Vt "struct ptrace_coredump"
982*8269e767SBrooks Davismust be passed in
983*8269e767SBrooks Davis.Fa data .
984*8269e767SBrooks Davis.It Dv PT_SC_REMOTE
985*8269e767SBrooks DavisRequest to execute a syscall in the context of the traced process,
986*8269e767SBrooks Davisin the specified thread.
987*8269e767SBrooks DavisThe
988*8269e767SBrooks Davis.Fa addr
989*8269e767SBrooks Davisargument must point to the
990*8269e767SBrooks Davis.Vt "struct ptrace_sc_remote" ,
991*8269e767SBrooks Daviswhich describes the requested syscall and its arguments, and receives
992*8269e767SBrooks Davisthe result.
993*8269e767SBrooks DavisThe size of
994*8269e767SBrooks Davis.Vt "struct ptrace_sc_remote"
995*8269e767SBrooks Davismust be passed in
996*8269e767SBrooks Davis.Fa data.
997*8269e767SBrooks Davis.Bd -literal
998*8269e767SBrooks Davisstruct ptrace_sc_remote {
999*8269e767SBrooks Davis	struct ptrace_sc_ret pscr_ret;
1000*8269e767SBrooks Davis	u_int	pscr_syscall;
1001*8269e767SBrooks Davis	u_int	pscr_nargs;
1002*8269e767SBrooks Davis	u_long	*pscr_args;
1003*8269e767SBrooks Davis};
1004*8269e767SBrooks Davis.Ed
1005*8269e767SBrooks DavisThe
1006*8269e767SBrooks Davis.Dv pscr_syscall
1007*8269e767SBrooks Daviscontains the syscall number to execute, the
1008*8269e767SBrooks Davis.Dv pscr_nargs
1009*8269e767SBrooks Davisis the number of supplied arguments, which are supplied in the
1010*8269e767SBrooks Davis.Dv pscr_args
1011*8269e767SBrooks Davisarray.
1012*8269e767SBrooks DavisResult of the execution is returned in the
1013*8269e767SBrooks Davis.Dv pscr_ret
1014*8269e767SBrooks Davismember.
1015*8269e767SBrooks DavisNote that the request and its result do not affect the returned value from
1016*8269e767SBrooks Davisthe currently executed syscall, if any.
1017*8269e767SBrooks Davis.El
1018*8269e767SBrooks Davis.Sh PT_COREDUMP and PT_SC_REMOTE usage
1019*8269e767SBrooks DavisThe process must be stopped before dumping or initiating a remote system call.
1020*8269e767SBrooks DavisA single thread in the target process is temporarily unsuspended
1021*8269e767SBrooks Davisin the kernel to perform the action.
1022*8269e767SBrooks DavisIf the
1023*8269e767SBrooks Davis.Nm
1024*8269e767SBrooks Daviscall fails before a thread is unsuspended, there is no event to
1025*8269e767SBrooks Davis.Xr waitpid 2
1026*8269e767SBrooks Davisfor.
1027*8269e767SBrooks DavisIf a thread was unsuspended, it will stop again before the
1028*8269e767SBrooks Davis.Nm
1029*8269e767SBrooks Daviscall returns, and the process must be waited upon using
1030*8269e767SBrooks Davis.Xr waitpid 2
1031*8269e767SBrooks Davisto consume the new stop event.
1032*8269e767SBrooks DavisSince it is hard to deduce whether a thread was unsuspended before
1033*8269e767SBrooks Davisan error occurred, it is recommended to unconditionally perform
1034*8269e767SBrooks Davis.Xr waitpid 2
1035*8269e767SBrooks Daviswith
1036*8269e767SBrooks Davis.Dv WNOHANG
1037*8269e767SBrooks Davisflag after
1038*8269e767SBrooks Davis.Dv PT_COREDUMP
1039*8269e767SBrooks Davisand
1040*8269e767SBrooks Davis.Dv PT_SC_REMOTE ,
1041*8269e767SBrooks Davisand silently accept zero result from it.
1042*8269e767SBrooks Davis.Pp
1043*8269e767SBrooks DavisFor
1044*8269e767SBrooks Davis.Dv PT_SC_REMOTE ,
1045*8269e767SBrooks Davisthe selected thread must be stopped in the safe place, which is
1046*8269e767SBrooks Daviscurrently defined as a syscall exit, or a return from kernel to
1047*8269e767SBrooks Davisuser mode (basically, a signal handler call place).
1048*8269e767SBrooks DavisKernel returns
1049*8269e767SBrooks Davis.Er EBUSY
1050*8269e767SBrooks Davisstatus if attempt is made to execute remote syscall at unsafe stop.
1051*8269e767SBrooks Davis.Pp
1052*8269e767SBrooks DavisNote that neither
1053*8269e767SBrooks Davis.Dv kern.trap_enotcap
1054*8269e767SBrooks Davissysctl setting, nor the corresponding
1055*8269e767SBrooks Davis.Xr procctl 2
1056*8269e767SBrooks Davisflag
1057*8269e767SBrooks Davis.Dv PROC_TRAPCAP_CTL_ENABLE
1058*8269e767SBrooks Davisare obeyed during the execution of the syscall by
1059*8269e767SBrooks Davis.Dv PT_SC_REMOTE .
1060*8269e767SBrooks DavisIn other words,
1061*8269e767SBrooks Davis.Dv SIGTRAP
1062*8269e767SBrooks Davissignal is not sent to a process executing in capability mode,
1063*8269e767SBrooks Daviswhich violated a mode access restriction.
1064*8269e767SBrooks Davis.Pp
1065*8269e767SBrooks DavisNote that due to the mode of execution for the remote syscall, in
1066*8269e767SBrooks Davisparticular, the setting where only one thread is allowed to run,
1067*8269e767SBrooks Davisthe syscall might block on resources owned by suspended threads.
1068*8269e767SBrooks DavisThis might result in the target process deadlock.
1069*8269e767SBrooks DavisIn this situation, the only way out is to kill the target.
1070*8269e767SBrooks Davis.Sh ARM MACHINE-SPECIFIC REQUESTS
1071*8269e767SBrooks Davis.Bl -tag -width "Dv PT_SETVFPREGS"
1072*8269e767SBrooks Davis.It Dv PT_GETVFPREGS
1073*8269e767SBrooks DavisReturn the thread's
1074*8269e767SBrooks Davis.Dv VFP
1075*8269e767SBrooks Davismachine state in the buffer pointed to by
1076*8269e767SBrooks Davis.Fa addr .
1077*8269e767SBrooks Davis.Pp
1078*8269e767SBrooks DavisThe
1079*8269e767SBrooks Davis.Fa data
1080*8269e767SBrooks Davisargument is ignored.
1081*8269e767SBrooks Davis.It Dv PT_SETVFPREGS
1082*8269e767SBrooks DavisSet the thread's
1083*8269e767SBrooks Davis.Dv VFP
1084*8269e767SBrooks Davismachine state from the buffer pointed to by
1085*8269e767SBrooks Davis.Fa addr .
1086*8269e767SBrooks Davis.Pp
1087*8269e767SBrooks DavisThe
1088*8269e767SBrooks Davis.Fa data
1089*8269e767SBrooks Davisargument is ignored.
1090*8269e767SBrooks Davis.El
1091*8269e767SBrooks Davis.Sh x86 MACHINE-SPECIFIC REQUESTS
1092*8269e767SBrooks Davis.Bl -tag -width "Dv PT_GETXSTATE_INFO"
1093*8269e767SBrooks Davis.It Dv PT_GETXMMREGS
1094*8269e767SBrooks DavisCopy the XMM FPU state into the buffer pointed to by the
1095*8269e767SBrooks Davisargument
1096*8269e767SBrooks Davis.Fa addr .
1097*8269e767SBrooks DavisThe buffer has the same layout as the 32-bit save buffer for the
1098*8269e767SBrooks Davismachine instruction
1099*8269e767SBrooks Davis.Dv FXSAVE .
1100*8269e767SBrooks Davis.Pp
1101*8269e767SBrooks DavisThis request is only valid for i386 programs, both on native 32-bit
1102*8269e767SBrooks Davissystems and on amd64 kernels.
1103*8269e767SBrooks DavisFor 64-bit amd64 programs, the XMM state is reported as part of
1104*8269e767SBrooks Davisthe FPU state returned by the
1105*8269e767SBrooks Davis.Dv PT_GETFPREGS
1106*8269e767SBrooks Davisrequest.
1107*8269e767SBrooks Davis.Pp
1108*8269e767SBrooks DavisThe
1109*8269e767SBrooks Davis.Fa data
1110*8269e767SBrooks Davisargument is ignored.
1111*8269e767SBrooks Davis.It Dv PT_SETXMMREGS
1112*8269e767SBrooks DavisLoad the XMM FPU state for the thread from the buffer pointed to
1113*8269e767SBrooks Davisby the argument
1114*8269e767SBrooks Davis.Fa addr .
1115*8269e767SBrooks DavisThe buffer has the same layout as the 32-bit load buffer for the
1116*8269e767SBrooks Davismachine instruction
1117*8269e767SBrooks Davis.Dv FXRSTOR .
1118*8269e767SBrooks Davis.Pp
1119*8269e767SBrooks DavisAs with
1120*8269e767SBrooks Davis.Dv PT_GETXMMREGS ,
1121*8269e767SBrooks Davisthis request is only valid for i386 programs.
1122*8269e767SBrooks Davis.Pp
1123*8269e767SBrooks DavisThe
1124*8269e767SBrooks Davis.Fa data
1125*8269e767SBrooks Davisargument is ignored.
1126*8269e767SBrooks Davis.It Dv PT_GETXSTATE_INFO
1127*8269e767SBrooks DavisReport which XSAVE FPU extensions are supported by the CPU
1128*8269e767SBrooks Davisand allowed in userspace programs.
1129*8269e767SBrooks DavisThe
1130*8269e767SBrooks Davis.Fa addr
1131*8269e767SBrooks Davisargument must point to a variable of type
1132*8269e767SBrooks Davis.Vt struct ptrace_xstate_info ,
1133*8269e767SBrooks Daviswhich contains the information on the request return.
1134*8269e767SBrooks Davis.Vt struct ptrace_xstate_info
1135*8269e767SBrooks Davisis defined as follows:
1136*8269e767SBrooks Davis.Bd -literal
1137*8269e767SBrooks Davisstruct ptrace_xstate_info {
1138*8269e767SBrooks Davis	uint64_t	xsave_mask;
1139*8269e767SBrooks Davis	uint32_t	xsave_len;
1140*8269e767SBrooks Davis};
1141*8269e767SBrooks Davis.Ed
1142*8269e767SBrooks DavisThe
1143*8269e767SBrooks Davis.Dv xsave_mask
1144*8269e767SBrooks Davisfield is a bitmask of the currently enabled extensions.
1145*8269e767SBrooks DavisThe meaning of the bits is defined in the Intel and AMD
1146*8269e767SBrooks Davisprocessor documentation.
1147*8269e767SBrooks DavisThe
1148*8269e767SBrooks Davis.Dv xsave_len
1149*8269e767SBrooks Davisfield reports the length of the XSAVE area for storing the hardware
1150*8269e767SBrooks Davisstate for currently enabled extensions in the format defined by the x86
1151*8269e767SBrooks Davis.Dv XSAVE
1152*8269e767SBrooks Davismachine instruction.
1153*8269e767SBrooks Davis.Pp
1154*8269e767SBrooks DavisThe
1155*8269e767SBrooks Davis.Fa data
1156*8269e767SBrooks Davisargument value must be equal to the size of the
1157*8269e767SBrooks Davis.Vt struct ptrace_xstate_info .
1158*8269e767SBrooks Davis.It Dv PT_GETXSTATE
1159*8269e767SBrooks DavisReturn the content of the XSAVE area for the thread.
1160*8269e767SBrooks DavisThe
1161*8269e767SBrooks Davis.Fa addr
1162*8269e767SBrooks Davisargument points to the buffer where the content is copied, and the
1163*8269e767SBrooks Davis.Fa data
1164*8269e767SBrooks Davisargument specifies the size of the buffer.
1165*8269e767SBrooks DavisThe kernel copies out as much content as allowed by the buffer size.
1166*8269e767SBrooks DavisThe buffer layout is specified by the layout of the save area for the
1167*8269e767SBrooks Davis.Dv XSAVE
1168*8269e767SBrooks Davismachine instruction.
1169*8269e767SBrooks Davis.It Dv PT_SETXSTATE
1170*8269e767SBrooks DavisLoad the XSAVE state for the thread from the buffer specified by the
1171*8269e767SBrooks Davis.Fa addr
1172*8269e767SBrooks Davispointer.
1173*8269e767SBrooks DavisThe buffer size is passed in the
1174*8269e767SBrooks Davis.Fa data
1175*8269e767SBrooks Davisargument.
1176*8269e767SBrooks DavisThe buffer must be at least as large as the
1177*8269e767SBrooks Davis.Vt struct savefpu
1178*8269e767SBrooks Davis(defined in
1179*8269e767SBrooks Davis.Pa x86/fpu.h )
1180*8269e767SBrooks Davisto allow the complete x87 FPU and XMM state load.
1181*8269e767SBrooks DavisIt must not be larger than the XSAVE state length, as reported by the
1182*8269e767SBrooks Davis.Dv xsave_len
1183*8269e767SBrooks Davisfield from the
1184*8269e767SBrooks Davis.Vt struct ptrace_xstate_info
1185*8269e767SBrooks Davisof the
1186*8269e767SBrooks Davis.Dv PT_GETXSTATE_INFO
1187*8269e767SBrooks Davisrequest.
1188*8269e767SBrooks DavisLayout of the buffer is identical to the layout of the load area for the
1189*8269e767SBrooks Davis.Dv XRSTOR
1190*8269e767SBrooks Davismachine instruction.
1191*8269e767SBrooks Davis.It Dv PT_GETFSBASE
1192*8269e767SBrooks DavisReturn the value of the base used when doing segmented
1193*8269e767SBrooks Davismemory addressing using the %fs segment register.
1194*8269e767SBrooks DavisThe
1195*8269e767SBrooks Davis.Fa addr
1196*8269e767SBrooks Davisargument points to an
1197*8269e767SBrooks Davis.Vt unsigned long
1198*8269e767SBrooks Davisvariable where the base value is stored.
1199*8269e767SBrooks Davis.Pp
1200*8269e767SBrooks DavisThe
1201*8269e767SBrooks Davis.Fa data
1202*8269e767SBrooks Davisargument is ignored.
1203*8269e767SBrooks Davis.It Dv PT_GETGSBASE
1204*8269e767SBrooks DavisLike the
1205*8269e767SBrooks Davis.Dv PT_GETFSBASE
1206*8269e767SBrooks Davisrequest, but returns the base for the %gs segment register.
1207*8269e767SBrooks Davis.It Dv PT_SETFSBASE
1208*8269e767SBrooks DavisSet the base for the %fs segment register to the value pointed to
1209*8269e767SBrooks Davisby the
1210*8269e767SBrooks Davis.Fa addr
1211*8269e767SBrooks Davisargument.
1212*8269e767SBrooks Davis.Fa addr
1213*8269e767SBrooks Davismust point to the
1214*8269e767SBrooks Davis.Vt unsigned long
1215*8269e767SBrooks Davisvariable containing the new base.
1216*8269e767SBrooks Davis.Pp
1217*8269e767SBrooks DavisThe
1218*8269e767SBrooks Davis.Fa data
1219*8269e767SBrooks Davisargument is ignored.
1220*8269e767SBrooks Davis.It Dv PT_SETGSBASE
1221*8269e767SBrooks DavisLike the
1222*8269e767SBrooks Davis.Dv PT_SETFSBASE
1223*8269e767SBrooks Davisrequest, but sets the base for the %gs segment register.
1224*8269e767SBrooks Davis.El
1225*8269e767SBrooks Davis.Sh PowerPC MACHINE-SPECIFIC REQUESTS
1226*8269e767SBrooks Davis.Bl -tag -width "Dv PT_SETVRREGS"
1227*8269e767SBrooks Davis.It Dv PT_GETVRREGS
1228*8269e767SBrooks DavisReturn the thread's
1229*8269e767SBrooks Davis.Dv ALTIVEC
1230*8269e767SBrooks Davismachine state in the buffer pointed to by
1231*8269e767SBrooks Davis.Fa addr .
1232*8269e767SBrooks Davis.Pp
1233*8269e767SBrooks DavisThe
1234*8269e767SBrooks Davis.Fa data
1235*8269e767SBrooks Davisargument is ignored.
1236*8269e767SBrooks Davis.It Dv PT_SETVRREGS
1237*8269e767SBrooks DavisSet the thread's
1238*8269e767SBrooks Davis.Dv ALTIVEC
1239*8269e767SBrooks Davismachine state from the buffer pointed to by
1240*8269e767SBrooks Davis.Fa addr .
1241*8269e767SBrooks Davis.Pp
1242*8269e767SBrooks DavisThe
1243*8269e767SBrooks Davis.Fa data
1244*8269e767SBrooks Davisargument is ignored.
1245*8269e767SBrooks Davis.It Dv PT_GETVSRREGS
1246*8269e767SBrooks DavisReturn doubleword 1 of the thread's
1247*8269e767SBrooks Davis.Dv VSX
1248*8269e767SBrooks Davisregisters VSR0-VSR31 in the buffer pointed to by
1249*8269e767SBrooks Davis.Fa addr .
1250*8269e767SBrooks Davis.Pp
1251*8269e767SBrooks DavisThe
1252*8269e767SBrooks Davis.Fa data
1253*8269e767SBrooks Davisargument is ignored.
1254*8269e767SBrooks Davis.It Dv PT_SETVSRREGS
1255*8269e767SBrooks DavisSet doubleword 1 of the thread's
1256*8269e767SBrooks Davis.Dv VSX
1257*8269e767SBrooks Davisregisters VSR0-VSR31 from the buffer pointed to by
1258*8269e767SBrooks Davis.Fa addr .
1259*8269e767SBrooks Davis.Pp
1260*8269e767SBrooks DavisThe
1261*8269e767SBrooks Davis.Fa data
1262*8269e767SBrooks Davisargument is ignored.
1263*8269e767SBrooks Davis.El
1264*8269e767SBrooks Davis.Pp
1265*8269e767SBrooks DavisAdditionally, other machine-specific requests can exist.
1266*8269e767SBrooks Davis.Sh RETURN VALUES
1267*8269e767SBrooks DavisMost requests return 0 on success and \-1 on error.
1268*8269e767SBrooks DavisSome requests can cause
1269*8269e767SBrooks Davis.Fn ptrace
1270*8269e767SBrooks Davisto return
1271*8269e767SBrooks Davis\-1
1272*8269e767SBrooks Davisas a non-error value, among them are
1273*8269e767SBrooks Davis.Dv PT_READ_I
1274*8269e767SBrooks Davisand
1275*8269e767SBrooks Davis.Dv PT_READ_D ,
1276*8269e767SBrooks Daviswhich return the value read from the process memory on success.
1277*8269e767SBrooks DavisTo disambiguate,
1278*8269e767SBrooks Davis.Va errno
1279*8269e767SBrooks Daviscan be set to 0 before the call and checked afterwards.
1280*8269e767SBrooks Davis.Pp
1281*8269e767SBrooks DavisThe current
1282*8269e767SBrooks Davis.Fn ptrace
1283*8269e767SBrooks Davisimplementation always sets
1284*8269e767SBrooks Davis.Va errno
1285*8269e767SBrooks Davisto 0 before calling into the kernel, both for historic reasons and for
1286*8269e767SBrooks Davisconsistency with other operating systems.
1287*8269e767SBrooks DavisIt is recommended to assign zero to
1288*8269e767SBrooks Davis.Va errno
1289*8269e767SBrooks Davisexplicitly for forward compatibility.
1290*8269e767SBrooks Davis.Sh ERRORS
1291*8269e767SBrooks DavisThe
1292*8269e767SBrooks Davis.Fn ptrace
1293*8269e767SBrooks Davissystem call may fail if:
1294*8269e767SBrooks Davis.Bl -tag -width Er
1295*8269e767SBrooks Davis.It Bq Er ESRCH
1296*8269e767SBrooks Davis.Bl -bullet -compact
1297*8269e767SBrooks Davis.It
1298*8269e767SBrooks DavisNo process having the specified process ID exists.
1299*8269e767SBrooks Davis.El
1300*8269e767SBrooks Davis.It Bq Er EINVAL
1301*8269e767SBrooks Davis.Bl -bullet -compact
1302*8269e767SBrooks Davis.It
1303*8269e767SBrooks DavisA process attempted to use
1304*8269e767SBrooks Davis.Dv PT_ATTACH
1305*8269e767SBrooks Davison itself.
1306*8269e767SBrooks Davis.It
1307*8269e767SBrooks DavisThe
1308*8269e767SBrooks Davis.Fa request
1309*8269e767SBrooks Davisargument
1310*8269e767SBrooks Daviswas not one of the legal requests.
1311*8269e767SBrooks Davis.It
1312*8269e767SBrooks DavisThe signal number
1313*8269e767SBrooks Davis(in
1314*8269e767SBrooks Davis.Fa data )
1315*8269e767SBrooks Davisto
1316*8269e767SBrooks Davis.Dv PT_CONTINUE
1317*8269e767SBrooks Daviswas neither 0 nor a legal signal number.
1318*8269e767SBrooks Davis.It
1319*8269e767SBrooks Davis.Dv PT_GETREGS ,
1320*8269e767SBrooks Davis.Dv PT_SETREGS ,
1321*8269e767SBrooks Davis.Dv PT_GETFPREGS ,
1322*8269e767SBrooks Davis.Dv PT_SETFPREGS ,
1323*8269e767SBrooks Davis.Dv PT_GETDBREGS ,
1324*8269e767SBrooks Davisor
1325*8269e767SBrooks Davis.Dv PT_SETDBREGS
1326*8269e767SBrooks Daviswas attempted on a process with no valid register set.
1327*8269e767SBrooks Davis(This is normally true only of system processes.)
1328*8269e767SBrooks Davis.It
1329*8269e767SBrooks Davis.Dv PT_VM_ENTRY
1330*8269e767SBrooks Daviswas given an invalid value for
1331*8269e767SBrooks Davis.Fa pve_entry .
1332*8269e767SBrooks DavisThis can also be caused by changes to the VM map of the process.
1333*8269e767SBrooks Davis.It
1334*8269e767SBrooks DavisThe size (in
1335*8269e767SBrooks Davis.Fa data )
1336*8269e767SBrooks Davisprovided to
1337*8269e767SBrooks Davis.Dv PT_LWPINFO
1338*8269e767SBrooks Daviswas less than or equal to zero, or larger than the
1339*8269e767SBrooks Davis.Vt ptrace_lwpinfo
1340*8269e767SBrooks Davisstructure known to the kernel.
1341*8269e767SBrooks Davis.It
1342*8269e767SBrooks DavisThe size (in
1343*8269e767SBrooks Davis.Fa data )
1344*8269e767SBrooks Davisprovided to the x86-specific
1345*8269e767SBrooks Davis.Dv PT_GETXSTATE_INFO
1346*8269e767SBrooks Davisrequest was not equal to the size of the
1347*8269e767SBrooks Davis.Vt struct ptrace_xstate_info .
1348*8269e767SBrooks Davis.It
1349*8269e767SBrooks DavisThe size (in
1350*8269e767SBrooks Davis.Fa data )
1351*8269e767SBrooks Davisprovided to the x86-specific
1352*8269e767SBrooks Davis.Dv PT_SETXSTATE
1353*8269e767SBrooks Davisrequest was less than the size of the x87 plus the XMM save area.
1354*8269e767SBrooks Davis.It
1355*8269e767SBrooks DavisThe size (in
1356*8269e767SBrooks Davis.Fa data )
1357*8269e767SBrooks Davisprovided to the x86-specific
1358*8269e767SBrooks Davis.Dv PT_SETXSTATE
1359*8269e767SBrooks Davisrequest was larger than returned in the
1360*8269e767SBrooks Davis.Dv xsave_len
1361*8269e767SBrooks Davismember of the
1362*8269e767SBrooks Davis.Vt struct ptrace_xstate_info
1363*8269e767SBrooks Davisfrom the
1364*8269e767SBrooks Davis.Dv PT_GETXSTATE_INFO
1365*8269e767SBrooks Davisrequest.
1366*8269e767SBrooks Davis.It
1367*8269e767SBrooks DavisThe base value, provided to the amd64-specific requests
1368*8269e767SBrooks Davis.Dv PT_SETFSBASE
1369*8269e767SBrooks Davisor
1370*8269e767SBrooks Davis.Dv PT_SETGSBASE ,
1371*8269e767SBrooks Davispointed outside of the valid user address space.
1372*8269e767SBrooks DavisThis error will not occur in 32-bit programs.
1373*8269e767SBrooks Davis.El
1374*8269e767SBrooks Davis.It Bq Er EBUSY
1375*8269e767SBrooks Davis.Bl -bullet -compact
1376*8269e767SBrooks Davis.It
1377*8269e767SBrooks Davis.Dv PT_ATTACH
1378*8269e767SBrooks Daviswas attempted on a process that was already being traced.
1379*8269e767SBrooks Davis.It
1380*8269e767SBrooks DavisA request attempted to manipulate a process that was being traced by
1381*8269e767SBrooks Davissome process other than the one making the request.
1382*8269e767SBrooks Davis.It
1383*8269e767SBrooks DavisA request
1384*8269e767SBrooks Davis(other than
1385*8269e767SBrooks Davis.Dv PT_ATTACH )
1386*8269e767SBrooks Davisspecified a process that was not stopped.
1387*8269e767SBrooks Davis.El
1388*8269e767SBrooks Davis.It Bq Er EPERM
1389*8269e767SBrooks Davis.Bl -bullet -compact
1390*8269e767SBrooks Davis.It
1391*8269e767SBrooks DavisA request
1392*8269e767SBrooks Davis(other than
1393*8269e767SBrooks Davis.Dv PT_ATTACH )
1394*8269e767SBrooks Davisattempted to manipulate a process that was not being traced at all.
1395*8269e767SBrooks Davis.It
1396*8269e767SBrooks DavisAn attempt was made to use
1397*8269e767SBrooks Davis.Dv PT_ATTACH
1398*8269e767SBrooks Davison a process in violation of the requirements listed under
1399*8269e767SBrooks Davis.Dv PT_ATTACH
1400*8269e767SBrooks Davisabove.
1401*8269e767SBrooks Davis.El
1402*8269e767SBrooks Davis.It Bq Er ENOENT
1403*8269e767SBrooks Davis.Bl -bullet -compact
1404*8269e767SBrooks Davis.It
1405*8269e767SBrooks Davis.Dv PT_VM_ENTRY
1406*8269e767SBrooks Davispreviously returned the last entry of the memory map.
1407*8269e767SBrooks DavisNo more entries exist.
1408*8269e767SBrooks Davis.El
1409*8269e767SBrooks Davis.It Bq Er ENOMEM
1410*8269e767SBrooks Davis.Bl -bullet -compact
1411*8269e767SBrooks Davis.It
1412*8269e767SBrooks DavisA
1413*8269e767SBrooks Davis.Dv PT_READ_I,
1414*8269e767SBrooks Davis.Dv PT_READ_D,
1415*8269e767SBrooks Davis.Dv PT_WRITE_I, or
1416*8269e767SBrooks Davis.Dv PT_WRITE_D
1417*8269e767SBrooks Davisrequest attempted to access an invalid address, or a memory allocation failure
1418*8269e767SBrooks Davisoccurred when accessing process memory.
1419*8269e767SBrooks Davis.El
1420*8269e767SBrooks Davis.It Bq Er ENAMETOOLONG
1421*8269e767SBrooks Davis.Bl -bullet -compact
1422*8269e767SBrooks Davis.It
1423*8269e767SBrooks Davis.Dv PT_VM_ENTRY
1424*8269e767SBrooks Daviscannot return the pathname of the backing object because the buffer is not big
1425*8269e767SBrooks Davisenough.
1426*8269e767SBrooks Davis.Fa pve_pathlen
1427*8269e767SBrooks Davisholds the minimum buffer size required on return.
1428*8269e767SBrooks Davis.El
1429*8269e767SBrooks Davis.El
1430*8269e767SBrooks Davis.Sh SEE ALSO
1431*8269e767SBrooks Davis.Xr execve 2 ,
1432*8269e767SBrooks Davis.Xr sigaction 2 ,
1433*8269e767SBrooks Davis.Xr wait 2 ,
1434*8269e767SBrooks Davis.Xr execv 3 ,
1435*8269e767SBrooks Davis.Xr i386_clr_watch 3 ,
1436*8269e767SBrooks Davis.Xr i386_set_watch 3
1437*8269e767SBrooks Davis.Sh HISTORY
1438*8269e767SBrooks DavisThe
1439*8269e767SBrooks Davis.Fn ptrace
1440*8269e767SBrooks Davisfunction appeared in
1441*8269e767SBrooks Davis.At v6 .
1442