Wed Jan 25 17:12:56 2017 UTC ()
Make the PIOD_READ_AUXV operation more clear

Describe how to set piod_offs.

Sponsored by <The NetBSD Foundation>


(kamil)
diff -r1.56 -r1.57 src/lib/libc/sys/ptrace.2

cvs diff -r1.56 -r1.57 src/lib/libc/sys/ptrace.2 (switch to unified diff)

--- src/lib/libc/sys/ptrace.2 2017/01/15 22:18:11 1.56
+++ src/lib/libc/sys/ptrace.2 2017/01/25 17:12:56 1.57
@@ -1,731 +1,738 @@ @@ -1,731 +1,738 @@
1.\" $NetBSD: ptrace.2,v 1.56 2017/01/15 22:18:11 kamil Exp $ 1.\" $NetBSD: ptrace.2,v 1.57 2017/01/25 17:12:56 kamil Exp $
2.\" 2.\"
3.\" This file is in the public domain. 3.\" This file is in the public domain.
4.Dd January 14, 2016 4.Dd January 25, 2016
5.Dt PTRACE 2 5.Dt PTRACE 2
6.Os 6.Os
7.Sh NAME 7.Sh NAME
8.Nm ptrace 8.Nm ptrace
9.Nd process tracing and debugging 9.Nd process tracing and debugging
10.Sh LIBRARY 10.Sh LIBRARY
11.Lb libc 11.Lb libc
12.Sh SYNOPSIS 12.Sh SYNOPSIS
13.In sys/types.h 13.In sys/types.h
14.In sys/ptrace.h 14.In sys/ptrace.h
15.Ft int 15.Ft int
16.Fn ptrace "int request" "pid_t pid" "void *addr" "int data" 16.Fn ptrace "int request" "pid_t pid" "void *addr" "int data"
17.Sh DESCRIPTION 17.Sh DESCRIPTION
18.Fn ptrace 18.Fn ptrace
19provides tracing and debugging facilities. 19provides tracing and debugging facilities.
20It allows one process (the 20It allows one process (the
21.Em tracing 21.Em tracing
22process) to control another (the 22process) to control another (the
23.Em traced 23.Em traced
24process). 24process).
25Most of the time, the traced process runs normally, but when 25Most of the time, the traced process runs normally, but when
26it receives a signal 26it receives a signal
27.Po 27.Po
28see 28see
29.Xr sigaction 2 29.Xr sigaction 2
30.Pc , 30.Pc ,
31it stops. 31it stops.
32The tracing process is expected to notice this via 32The tracing process is expected to notice this via
33.Xr wait 2 33.Xr wait 2
34or the delivery of a 34or the delivery of a
35.Dv SIGCHLD 35.Dv SIGCHLD
36signal 36signal
37.Po 37.Po
38see 38see
39.Xr siginfo 2 39.Xr siginfo 2
40.Pc , 40.Pc ,
41examine the state of the stopped process, and cause it to 41examine the state of the stopped process, and cause it to
42terminate or continue as appropriate. 42terminate or continue as appropriate.
43.Fn ptrace 43.Fn ptrace
44is the mechanism by which all this happens. 44is the mechanism by which all this happens.
45.Pp 45.Pp
46When a process that is traced by a debugger requests and calls 46When a process that is traced by a debugger requests and calls
47.Xr execve 2 47.Xr execve 2
48or any of the routines built on it 48or any of the routines built on it
49.Po 49.Po
50such as 50such as
51.Xr execv 3 51.Xr execv 3
52.Pc , 52.Pc ,
53it will stop before executing the first instruction of the new image and emit 53it will stop before executing the first instruction of the new image and emit
54.Dv SIGRAP 54.Dv SIGRAP
55with 55with
56.Dv si_code 56.Dv si_code
57set to 57set to
58.Dv TRAP_EXEC . 58.Dv TRAP_EXEC .
59If a program is traced with the 59If a program is traced with the
60.Dv PT_SYSCALL 60.Dv PT_SYSCALL
61option enabled, 61option enabled,
62this event notifier is disabled. 62this event notifier is disabled.
63If a traced program calls 63If a traced program calls
64.Xr execve 2 64.Xr execve 2
65any setuid or setgid bits on the executable being executed will be ignored. 65any setuid or setgid bits on the executable being executed will be ignored.
66.Pp 66.Pp
67Program (software) breakpoints are reported with 67Program (software) breakpoints are reported with
68.Dv SIGTRAP 68.Dv SIGTRAP
69and the 69and the
70.Dv si_code 70.Dv si_code
71value set to 71value set to
72.Dv TRAP_BKPT . 72.Dv TRAP_BKPT .
73These breakpoints are machine specific instructions that interrput the process. 73These breakpoints are machine specific instructions that interrput the process.
74In order to put a trap by a tracer into the tracee's program, 74In order to put a trap by a tracer into the tracee's program,
75debugger must violate the 75debugger must violate the
76.Dv PaX MPROTECT 76.Dv PaX MPROTECT
77restrictions. 77restrictions.
78For details check the 78For details check the
79.Dv security.pax.mprotect.ptrace 79.Dv security.pax.mprotect.ptrace
80option described in 80option described in
81.Xr sysctl 7 . 81.Xr sysctl 7 .
82When a tracee is interrputed by a trap, 82When a tracee is interrputed by a trap,
83the trap is not removed by the kernel and it must be handled by a debugger. 83the trap is not removed by the kernel and it must be handled by a debugger.
84.Pp 84.Pp
85If a program is traced with single steps 85If a program is traced with single steps
86.Dv ( PT_STEP ) 86.Dv ( PT_STEP )
87it reports each step with 87it reports each step with
88.Dv SIGTRAP 88.Dv SIGTRAP
89with 89with
90.Dv si_code 90.Dv si_code
91set to 91set to
92.Dv TRAP_TRACE . 92.Dv TRAP_TRACE .
93This event is always enabled and cannot be disabled. 93This event is always enabled and cannot be disabled.
94.Pp 94.Pp
95Child program traps are reported with 95Child program traps are reported with
96.Dv SIGTRAP 96.Dv SIGTRAP
97and the 97and the
98.Dv si_code 98.Dv si_code
99value set to 99value set to
100.Dv TRAP_CHLD . 100.Dv TRAP_CHLD .
101These events are by default disabled and can be configured with 101These events are by default disabled and can be configured with
102.Dv PT_SET_EVENT_MASK . 102.Dv PT_SET_EVENT_MASK .
103If this event occurs, 103If this event occurs,
104check with 104check with
105.Dv PT_GET_PROCESS_STATE 105.Dv PT_GET_PROCESS_STATE
106the details of the process state associated with this event. 106the details of the process state associated with this event.
107.Pp 107.Pp
108A debugger might reuse a port specific symbols, 108A debugger might reuse a port specific symbols,
109to help writing portable code as described in the port specific part of the 109to help writing portable code as described in the port specific part of the
110.In sys/ptrace.h 110.In sys/ptrace.h
111header. 111header.
112Among these symbols, 112Among these symbols,
113there are: 113there are:
114.Bl -dash 114.Bl -dash
115.It 115.It
116.Dv PTRACE_REG_PC 116.Dv PTRACE_REG_PC
117.It 117.It
118.Dv PTRACE_REG_SET_PC 118.Dv PTRACE_REG_SET_PC
119.It 119.It
120.Dv PTRACE_REG_SP 120.Dv PTRACE_REG_SP
121.It 121.It
122.Dv PTRACE_REG_INTRV 122.Dv PTRACE_REG_INTRV
123.It 123.It
124.Dv PTRACE_BREAKPOINT 124.Dv PTRACE_BREAKPOINT
125.It 125.It
126.Dv PTRACE_BREAKPOINT_SIZE 126.Dv PTRACE_BREAKPOINT_SIZE
127.It 127.It
128.Dv PTRACE_BREAKPOINT_ADJ 128.Dv PTRACE_BREAKPOINT_ADJ
129.El 129.El
130.Pp 130.Pp
131The 131The
132.Fa request 132.Fa request
133argument 133argument
134of 134of
135.Nm 135.Nm
136specifies what operation is being performed; the meaning of 136specifies what operation is being performed; the meaning of
137the rest of the arguments depends on the operation, but except for one 137the rest of the arguments depends on the operation, but except for one
138special case noted below, all 138special case noted below, all
139.Nm 139.Nm
140calls are made by the tracing process, and the 140calls are made by the tracing process, and the
141.Fa pid 141.Fa pid
142argument specifies the process ID of the traced process. 142argument specifies the process ID of the traced process.
143.Fa request 143.Fa request
144can be: 144can be:
145.Bl -tag -width 12n 145.Bl -tag -width 12n
146.It Dv PT_TRACE_ME 146.It Dv PT_TRACE_ME
147This request is the only one used by the traced process; it declares 147This request is the only one used by the traced process; it declares
148that the process expects to be traced by its parent. 148that the process expects to be traced by its parent.
149All the other arguments are ignored. 149All the other arguments are ignored.
150If the parent process does not expect to trace 150If the parent process does not expect to trace
151the child, it will probably be rather confused by the results; once the 151the child, it will probably be rather confused by the results; once the
152traced process stops, it cannot be made to continue except via 152traced process stops, it cannot be made to continue except via
153.Fn ptrace . 153.Fn ptrace .
154.Pp 154.Pp
155This call does not stop the process neither emit 155This call does not stop the process neither emit
156.Dv SIGSTOP 156.Dv SIGSTOP
157to parent. 157to parent.
158.It Dv PT_READ_I , Dv PT_READ_D 158.It Dv PT_READ_I , Dv PT_READ_D
159These requests read a single 159These requests read a single
160.Li int 160.Li int
161of data from the traced process' address space. 161of data from the traced process' address space.
162Traditionally, 162Traditionally,
163.Fn ptrace 163.Fn ptrace
164has allowed for machines with distinct address spaces for instruction 164has allowed for machines with distinct address spaces for instruction
165and data, which is why there are two requests: conceptually, 165and data, which is why there are two requests: conceptually,
166.Dv PT_READ_I 166.Dv PT_READ_I
167reads from the instruction space and 167reads from the instruction space and
168.Dv PT_READ_D 168.Dv PT_READ_D
169reads from the data space. 169reads from the data space.
170In the current 170In the current
171.Nx 171.Nx
172implementation, these 172implementation, these
173two requests are completely identical. 173two requests are completely identical.
174The 174The
175.Fa addr 175.Fa addr
176argument specifies the address (in the traced process' virtual address 176argument specifies the address (in the traced process' virtual address
177space) at which the read is to be done. 177space) at which the read is to be done.
178This address does not have to meet any alignment constraints. 178This address does not have to meet any alignment constraints.
179The value read is returned as the return value from 179The value read is returned as the return value from
180.Eo \& 180.Eo \&
181.Fn ptrace 181.Fn ptrace
182.Ec . 182.Ec .
183.It Dv PT_WRITE_I , Dv PT_WRITE_D 183.It Dv PT_WRITE_I , Dv PT_WRITE_D
184These requests parallel 184These requests parallel
185.Dv PT_READ_I 185.Dv PT_READ_I
186and 186and
187.Dv PT_READ_D , 187.Dv PT_READ_D ,
188except that they write rather than read. 188except that they write rather than read.
189The 189The
190.Fa data 190.Fa data
191argument supplies the value to be written. 191argument supplies the value to be written.
192.It Dv PT_CONTINUE 192.It Dv PT_CONTINUE
193The traced process continues execution. 193The traced process continues execution.
194.Fa addr 194.Fa addr
195is an address specifying the place where execution is to be resumed (a 195is an address specifying the place where execution is to be resumed (a
196new value for the program counter), or 196new value for the program counter), or
197.Li (void *)1 197.Li (void *)1
198to indicate that execution is to pick up where it left off. 198to indicate that execution is to pick up where it left off.
199.Fa data 199.Fa data
200provides a signal number to be delivered to the traced process as it 200provides a signal number to be delivered to the traced process as it
201resumes execution, or 0 if no signal is to be sent. 201resumes execution, or 0 if no signal is to be sent.
202If a negative value is supplied, that is the negative of the LWP 202If a negative value is supplied, that is the negative of the LWP
203ID of the thread to be resumed, and only that thread executes. 203ID of the thread to be resumed, and only that thread executes.
204.It Dv PT_KILL 204.It Dv PT_KILL
205The traced process terminates, as if 205The traced process terminates, as if
206.Dv PT_CONTINUE 206.Dv PT_CONTINUE
207had been used with 207had been used with
208.Dv SIGKILL 208.Dv SIGKILL
209given as the signal to be delivered. 209given as the signal to be delivered.
210.It Dv PT_ATTACH 210.It Dv PT_ATTACH
211This request allows a process to gain control of an otherwise unrelated 211This request allows a process to gain control of an otherwise unrelated
212process and begin tracing it. 212process and begin tracing it.
213It does not need any cooperation from the to-be-traced process. 213It does not need any cooperation from the to-be-traced process.
214In this case, 214In this case,
215.Fa pid 215.Fa pid
216specifies the process ID of the to-be-traced process, and the other two 216specifies the process ID of the to-be-traced process, and the other two
217arguments are ignored. 217arguments are ignored.
218This request requires that the target process 218This request requires that the target process
219must have the same real UID as the tracing process, and that it must 219must have the same real UID as the tracing process, and that it must
220not be executing a setuid or setgid executable. 220not be executing a setuid or setgid executable.
221(If the tracing process is running as root, 221(If the tracing process is running as root,
222these restrictions do not apply.) 222these restrictions do not apply.)
223.Pp 223.Pp
224The tracing process will see the newly-traced process stop and may then 224The tracing process will see the newly-traced process stop and may then
225control it as if it had been traced all along. 225control it as if it had been traced all along.
226It means that the 226It means that the
227.Dv SIGSTOP 227.Dv SIGSTOP
228signal is emitted to tracer. 228signal is emitted to tracer.
229It is different behavior to the one from 229It is different behavior to the one from
230.Dv PT_TRACE_ME . 230.Dv PT_TRACE_ME .
231.Pp 231.Pp
232Three other restrictions apply to all tracing processes, even those 232Three other restrictions apply to all tracing processes, even those
233running as root. 233running as root.
234First, no process may trace a system process. 234First, no process may trace a system process.
235Second, no process may trace the process running 235Second, no process may trace the process running
236.Xr init 8 . 236.Xr init 8 .
237Third, if a process has its root directory set with 237Third, if a process has its root directory set with
238.Xr chroot 2 , 238.Xr chroot 2 ,
239it may not trace another process unless that process' root directory 239it may not trace another process unless that process' root directory
240is at or below the tracing process' root. 240is at or below the tracing process' root.
241.It Dv PT_DETACH 241.It Dv PT_DETACH
242This request is like PT_CONTINUE, except that after it 242This request is like PT_CONTINUE, except that after it
243succeeds, the traced process is no longer traced and continues 243succeeds, the traced process is no longer traced and continues
244execution normally. 244execution normally.
245.It Dv PT_IO 245.It Dv PT_IO
246This request is a more general interface that can be used instead of 246This request is a more general interface that can be used instead of
247.Dv PT_READ_D , 247.Dv PT_READ_D ,
248.Dv PT_WRITE_D , 248.Dv PT_WRITE_D ,
249.Dv PT_READ_I , 249.Dv PT_READ_I ,
250and 250and
251.Dv PT_WRITE_I . 251.Dv PT_WRITE_I .
252The I/O request is encoded in a 252The I/O request is encoded in a
253.Dq Li "struct ptrace_io_desc" 253.Dq Li "struct ptrace_io_desc"
254defined as: 254defined as:
255.Bd -literal -offset indent 255.Bd -literal -offset indent
256struct ptrace_io_desc { 256struct ptrace_io_desc {
257 int piod_op; 257 int piod_op;
258 void *piod_offs; 258 void *piod_offs;
259 void *piod_addr; 259 void *piod_addr;
260 size_t piod_len; 260 size_t piod_len;
261}; 261};
262.Ed 262.Ed
263.Pp 263.Pp
264where 264where
265.Fa piod_offs 265.Fa piod_offs
266is the offset within the traced process where the I/O operation should 266is the offset within the traced process where the I/O operation should
267take place, 267take place,
268.Fa piod_addr 268.Fa piod_addr
269is the buffer in the tracing process, and 269is the buffer in the tracing process, and
270.Fa piod_len 270.Fa piod_len
271is the length of the I/O request. 271is the length of the I/O request.
272The 272The
273.Fa piod_op 273.Fa piod_op
274field specifies which type of I/O operation to perform. 274field specifies which type of I/O operation to perform.
275Possible values are: 275Possible values are:
276.Pp 276.Pp
277.Bl -tag -width 18n -offset indent -compact 277.Bl -tag -width 18n -offset indent -compact
278.It Dv PIOD_READ_D 278.It Dv PIOD_READ_D
279.It Dv PIOD_WRITE_D 279.It Dv PIOD_WRITE_D
280.It Dv PIOD_READ_I 280.It Dv PIOD_READ_I
281.It Dv PIOD_WRITE_I 281.It Dv PIOD_WRITE_I
282.It Dv PIOD_READ_AUXV 282.It Dv PIOD_READ_AUXV
283.El 283.El
284.Pp 284.Pp
285See the description of 285See the description of
286.Dv PT_READ_I 286.Dv PT_READ_I
287for the difference between I and D spaces. 287for the difference between I and D spaces.
 288.Pp
288The 289The
289.Dv PIOD_READ_AUXV 290.Dv PIOD_READ_AUXV
290operation can be used to read from the ELF auxiliary vector. 291operation can be used to read from the ELF auxiliary vector.
 292The
 293.Fa piod_offs
 294argument sets offset withing the tracee's vector.
 295To read from the beginning of it, this value must be set to 0 and casted to
 296.Dv (void *) .
 297.Pp
291A pointer to the I/O descriptor is passed in the 298A pointer to the I/O descriptor is passed in the
292.Fa addr 299.Fa addr
293argument to 300argument to
294.Fn ptrace . 301.Fn ptrace .
295On return, the 302On return, the
296.Fa piod_len 303.Fa piod_len
297field in the I/O descriptor will be updated with the actual number of 304field in the I/O descriptor will be updated with the actual number of
298bytes transferred. 305bytes transferred.
299If the requested I/O could not be successfully performed, 306If the requested I/O could not be successfully performed,
300.Fn ptrace 307.Fn ptrace
301will return 308will return
302.Li \-1 309.Li \-1
303and set 310and set
304.Va errno . 311.Va errno .
305.It Dv PT_DUMPCORE 312.It Dv PT_DUMPCORE
306Makes the process specified in the 313Makes the process specified in the
307.Fa pid 314.Fa pid
308pid generate a core dump. 315pid generate a core dump.
309The 316The
310.Fa addr 317.Fa addr
311argument should contain the name of the core file to be generated 318argument should contain the name of the core file to be generated
312and the 319and the
313.Fa data 320.Fa data
314argument should contain the length of the core filename. 321argument should contain the length of the core filename.
315.It Dv PT_LWPINFO 322.It Dv PT_LWPINFO
316Returns information about a thread from the list of threads for the 323Returns information about a thread from the list of threads for the
317process specified in the 324process specified in the
318.Fa pid 325.Fa pid
319argument. 326argument.
320The 327The
321.Fa addr 328.Fa addr
322argument should contain a 329argument should contain a
323.Dq Li "struct ptrace_lwpinfo" 330.Dq Li "struct ptrace_lwpinfo"
324defined as: 331defined as:
325.Bd -literal -offset indent 332.Bd -literal -offset indent
326struct ptrace_lwpinfo { 333struct ptrace_lwpinfo {
327 lwpid_t pl_lwpid; 334 lwpid_t pl_lwpid;
328 int pl_event; 335 int pl_event;
329}; 336};
330.Ed 337.Ed
331.Pp 338.Pp
332where 339where
333.Fa pl_lwpid 340.Fa pl_lwpid
334contains a thread LWP ID. 341contains a thread LWP ID.
335Information is returned for the thread following the one with the 342Information is returned for the thread following the one with the
336specified ID in the process thread list, or for the first thread 343specified ID in the process thread list, or for the first thread
337if 344if
338.Fa pl_lwpid 345.Fa pl_lwpid
339is 0. 346is 0.
340Upon return 347Upon return
341.Fa pl_lwpid 348.Fa pl_lwpid
342contains the LWP ID of the thread that was found, or 0 if there is 349contains the LWP ID of the thread that was found, or 0 if there is
343no thread after the one whose LWP ID was supplied in the call. 350no thread after the one whose LWP ID was supplied in the call.
344.Fa pl_event 351.Fa pl_event
345contains the event that stopped the thread. 352contains the event that stopped the thread.
346Possible values are: 353Possible values are:
347.Pp 354.Pp
348.Bl -tag -width 30n -offset indent -compact 355.Bl -tag -width 30n -offset indent -compact
349.It Dv PL_EVENT_NONE 356.It Dv PL_EVENT_NONE
350.It Dv PL_EVENT_SIGNAL 357.It Dv PL_EVENT_SIGNAL
351.El 358.El
352.Pp 359.Pp
353The 360The
354.Fa data 361.Fa data
355argument should contain 362argument should contain
356.Dq Li "sizeof(struct ptrace_lwpinfo)" . 363.Dq Li "sizeof(struct ptrace_lwpinfo)" .
357.It Dv PT_SYSCALL 364.It Dv PT_SYSCALL
358Stops a process before and after executing each system call. 365Stops a process before and after executing each system call.
359.It Dv PT_SYSCALLEMU 366.It Dv PT_SYSCALLEMU
360Intercept and ignore a system call before it has been executed, for use with 367Intercept and ignore a system call before it has been executed, for use with
361.Dv PT_SYSCALL . 368.Dv PT_SYSCALL .
362.It Dv PT_SET_EVENT_MASK 369.It Dv PT_SET_EVENT_MASK
363This request can be used to specify which events in the traced process 370This request can be used to specify which events in the traced process
364should be reported to the tracing process. 371should be reported to the tracing process.
365These events are specified in a 372These events are specified in a
366.Dq Li "struct ptrace_event" 373.Dq Li "struct ptrace_event"
367defined as: 374defined as:
368.Bd -literal -offset indent 375.Bd -literal -offset indent
369typedef struct ptrace_event { 376typedef struct ptrace_event {
370 int pe_set_event; 377 int pe_set_event;
371} ptrace_event_t; 378} ptrace_event_t;
372.Ed 379.Ed
373.Pp 380.Pp
374Where 381Where
375.Fa pe_set_event 382.Fa pe_set_event
376is the set of events to be reported. 383is the set of events to be reported.
377This set is formed by OR'ing together the following values: 384This set is formed by OR'ing together the following values:
378.Bl -tag -width 18n 385.Bl -tag -width 18n
379.It PTRACE_FORK 386.It PTRACE_FORK
380Report 387Report
381.Xr fork 2 . 388.Xr fork 2 .
382.It PTRACE_VFORK 389.It PTRACE_VFORK
383Report 390Report
384.Xr vfork 2 . 391.Xr vfork 2 .
385.It PTRACE_VFORK_DONE 392.It PTRACE_VFORK_DONE
386Report parent resumed after 393Report parent resumed after
387.Xr vfork 2 . 394.Xr vfork 2 .
388.It PTRACE_LWP_CREATE 395.It PTRACE_LWP_CREATE
389Report thread birth. 396Report thread birth.
390.It PTRACE_LWP_EXIT 397.It PTRACE_LWP_EXIT
391Report thread termination. 398Report thread termination.
392.El 399.El
393.Pp 400.Pp
394The 401The
395.Xr fork 2 402.Xr fork 2
396and 403and
397.Xr vfork 2 404.Xr vfork 2
398events can occur with similar operations, 405events can occur with similar operations,
399like 406like
400.Xr clone 2 407.Xr clone 2
401or 408or
402.Xr posix_spawn 3 . 409.Xr posix_spawn 3 .
403The 410The
404.Dv PTRACE_FORK 411.Dv PTRACE_FORK
405value means that process gives birth to its child 412value means that process gives birth to its child
406without pending on its termination or 413without pending on its termination or
407.Xr execve 2 414.Xr execve 2
408operation. 415operation.
409If enabled, 416If enabled,
410the child is also traced by the debugger and 417the child is also traced by the debugger and
411.Dv SIGRAP 418.Dv SIGRAP
412is generated twice, 419is generated twice,
413first for the parent and second for the child. 420first for the parent and second for the child.
414The 421The
415.Dv PTRACE_VFORK 422.Dv PTRACE_VFORK
416event is the same as 423event is the same as
417.Dv PTRACE_FORK , 424.Dv PTRACE_FORK ,
418but the parent blocks after giving birth to the child. 425but the parent blocks after giving birth to the child.
419The 426The
420.Dv PTRACE_VFORK_DONE 427.Dv PTRACE_VFORK_DONE
421event can be used to report unblocking of the parent. 428event can be used to report unblocking of the parent.
422.Pp 429.Pp
423A pointer to this structure is passed in 430A pointer to this structure is passed in
424.Fa addr . 431.Fa addr .
425The 432The
426.Fa data 433.Fa data
427argument should be set to 434argument should be set to
428.Li sizeof(struct ptrace_event) . 435.Li sizeof(struct ptrace_event) .
429.It Dv PT_GET_EVENT_MASK 436.It Dv PT_GET_EVENT_MASK
430This request can be used to determine which events in the traced 437This request can be used to determine which events in the traced
431process will be reported. 438process will be reported.
432The information is read into the 439The information is read into the
433.Dq Li struct ptrace_event 440.Dq Li struct ptrace_event
434pointed to by 441pointed to by
435.Fa addr . 442.Fa addr .
436The 443The
437.Fa data 444.Fa data
438argument should be set to 445argument should be set to
439.Li sizeof(struct ptrace_event) . 446.Li sizeof(struct ptrace_event) .
440.It Dv PT_GET_PROCESS_STATE 447.It Dv PT_GET_PROCESS_STATE
441This request reads the state information associated with the event 448This request reads the state information associated with the event
442that stopped the traced process. 449that stopped the traced process.
443The information is reported in a 450The information is reported in a
444.Dq Li "struct ptrace_state" 451.Dq Li "struct ptrace_state"
445defined as: 452defined as:
446.Bd -literal -offset indent 453.Bd -literal -offset indent
447typedef struct ptrace_state { 454typedef struct ptrace_state {
448 int pe_report_event; 455 int pe_report_event;
449 pid_t pe_other_pid; 456 pid_t pe_other_pid;
450} ptrace_state_t; 457} ptrace_state_t;
451.Ed 458.Ed
452.Pp 459.Pp
453A pointer to this structure is passed in 460A pointer to this structure is passed in
454.Fa addr . 461.Fa addr .
455The 462The
456.Fa data 463.Fa data
457argument should be set to 464argument should be set to
458.Li sizeof(struct ptrace_state) . 465.Li sizeof(struct ptrace_state) .
459.It Dv PT_SET_SIGINFO 466.It Dv PT_SET_SIGINFO
460This request can be used to specify signal information emitted to tracee. 467This request can be used to specify signal information emitted to tracee.
461This signal information is specified in 468This signal information is specified in
462.Dq Li "struct ptrace_siginfo" 469.Dq Li "struct ptrace_siginfo"
463defined as: 470defined as:
464.Bd -literal -offset indentq 471.Bd -literal -offset indentq
465typedef struct ptrace_siginfo { 472typedef struct ptrace_siginfo {
466 siginfo_t psi_siginfo; 473 siginfo_t psi_siginfo;
467 lwpid_t psi_lwpid; 474 lwpid_t psi_lwpid;
468} ptrace_siginfo_t; 475} ptrace_siginfo_t;
469.Ed 476.Ed
470.Pp 477.Pp
471Where 478Where
472.Fa psi_siginfo 479.Fa psi_siginfo
473is the set to signal information structure. 480is the set to signal information structure.
474The 481The
475.Fa psi_lwpid 482.Fa psi_lwpid
476field describes LWP address of the signal. 483field describes LWP address of the signal.
477Value 484Value
478.Dv 0 485.Dv 0
479means the whole process 486means the whole process
480(route signal to all LWPs). 487(route signal to all LWPs).
481.Pp 488.Pp
482A pointer to this structure is passed in 489A pointer to this structure is passed in
483.Fa addr . 490.Fa addr .
484The 491The
485.Fa data 492.Fa data
486argument should be set to 493argument should be set to
487.Li sizeof(struct ptrace_siginfo) . 494.Li sizeof(struct ptrace_siginfo) .
488.Pp 495.Pp
489In order to pass faked signal to the tracee, 496In order to pass faked signal to the tracee,
490the signal type must match the signal passed to process with 497the signal type must match the signal passed to process with
491.Dv PT_CONTINUE , 498.Dv PT_CONTINUE ,
492.Dv PT_DETACH 499.Dv PT_DETACH
493or 500or
494.Dv PT_STEP . 501.Dv PT_STEP .
495.It Dv PT_GET_SIGINFO 502.It Dv PT_GET_SIGINFO
496This request can be used to determine signal information that was received by 503This request can be used to determine signal information that was received by
497a debugger 504a debugger
498.Po 505.Po
499see 506see
500.Xr siginfo 2 507.Xr siginfo 2
501.Pc . 508.Pc .
502The information is read into the 509The information is read into the
503.Dq Li struct ptrace_siginfo 510.Dq Li struct ptrace_siginfo
504pointed to by 511pointed to by
505.Fa addr . 512.Fa addr .
506The 513The
507.Fa data 514.Fa data
508argument should be set to 515argument should be set to
509.Li sizeof(struct ptrace_siginfo) . 516.Li sizeof(struct ptrace_siginfo) .
510.El 517.El
511.Pp 518.Pp
512Additionally, the following requests exist but are 519Additionally, the following requests exist but are
513not available on all machine architectures. 520not available on all machine architectures.
514The file 521The file
515.In machine/ptrace.h 522.In machine/ptrace.h
516lists which requests exist on a given machine. 523lists which requests exist on a given machine.
517.Bl -tag -width 12n 524.Bl -tag -width 12n
518.It Dv PT_STEP 525.It Dv PT_STEP
519Execution continues as in request PT_CONTINUE; however 526Execution continues as in request PT_CONTINUE; however
520as soon as possible after execution of at least one 527as soon as possible after execution of at least one
521instruction, execution stops again. 528instruction, execution stops again.
522If the 529If the
523.Fa data 530.Fa data
524argument is greater than 0, it contains the LWP ID of the thread to be 531argument is greater than 0, it contains the LWP ID of the thread to be
525stepped, and any other threads are continued. 532stepped, and any other threads are continued.
526If the 533If the
527.Fa data 534.Fa data
528argument is less than zero, it contains the negative of the LWP ID of 535argument is less than zero, it contains the negative of the LWP ID of
529the thread to be stepped, and only that thread executes. 536the thread to be stepped, and only that thread executes.
530.It Dv PT_GETREGS 537.It Dv PT_GETREGS
531This request reads the traced process' machine registers into the 538This request reads the traced process' machine registers into the
532.Dq Li "struct reg" 539.Dq Li "struct reg"
533(defined in 540(defined in
534.In machine/reg.h ) 541.In machine/reg.h )
535pointed to by 542pointed to by
536.Fa addr . 543.Fa addr .
537The 544The
538.Fa data 545.Fa data
539argument contains the LWP ID of the thread whose registers are to 546argument contains the LWP ID of the thread whose registers are to
540be read. 547be read.
541If zero is supplied, the first thread of the process is read. 548If zero is supplied, the first thread of the process is read.
542.It Dv PT_SETREGS 549.It Dv PT_SETREGS
543This request is the converse of 550This request is the converse of
544.Dv PT_GETREGS ; 551.Dv PT_GETREGS ;
545it loads the traced process' machine registers from the 552it loads the traced process' machine registers from the
546.Dq Li "struct reg" 553.Dq Li "struct reg"
547(defined in 554(defined in
548.In machine/reg.h ) 555.In machine/reg.h )
549pointed to by 556pointed to by
550.Fa addr . 557.Fa addr .
551The 558The
552.Fa data 559.Fa data
553argument contains the LWP ID of the thread whose registers are to 560argument contains the LWP ID of the thread whose registers are to
554be written. 561be written.
555If zero is supplied, the first thread of the process is written. 562If zero is supplied, the first thread of the process is written.
556.It Dv PT_GETFPREGS 563.It Dv PT_GETFPREGS
557This request reads the traced process' floating-point registers into 564This request reads the traced process' floating-point registers into
558the 565the
559.Dq Li "struct fpreg" 566.Dq Li "struct fpreg"
560(defined in 567(defined in
561.In machine/reg.h ) 568.In machine/reg.h )
562pointed to by 569pointed to by
563.Fa addr . 570.Fa addr .
564The 571The
565.Fa data 572.Fa data
566argument contains the LWP ID of the thread whose registers are to 573argument contains the LWP ID of the thread whose registers are to
567be read. 574be read.
568If zero is supplied, the first thread of the process is read. 575If zero is supplied, the first thread of the process is read.
569.It Dv PT_SETFPREGS 576.It Dv PT_SETFPREGS
570This request is the converse of 577This request is the converse of
571.Dv PT_GETFPREGS ; 578.Dv PT_GETFPREGS ;
572it loads the traced process' floating-point registers from the 579it loads the traced process' floating-point registers from the
573.Dq Li "struct fpreg" 580.Dq Li "struct fpreg"
574(defined in 581(defined in
575.In machine/reg.h ) 582.In machine/reg.h )
576pointed to by 583pointed to by
577.Fa addr . 584.Fa addr .
578The 585The
579.Fa data 586.Fa data
580argument contains the LWP ID of the thread whose registers are to 587argument contains the LWP ID of the thread whose registers are to
581be written. 588be written.
582If zero is supplied, the first thread of the process is written. 589If zero is supplied, the first thread of the process is written.
583.It Dv PT_GETXMMREGS 590.It Dv PT_GETXMMREGS
584This request reads the traced process' XMM registers into 591This request reads the traced process' XMM registers into
585the 592the
586.Dq Li "struct xmmregs" 593.Dq Li "struct xmmregs"
587(defined in 594(defined in
588.In machine/reg.h ) 595.In machine/reg.h )
589pointed to by 596pointed to by
590.Fa addr . 597.Fa addr .
591The 598The
592.Fa data 599.Fa data
593argument contains the LWP ID of the thread whose registers are to 600argument contains the LWP ID of the thread whose registers are to
594be read. 601be read.
595If zero is supplied, the first thread of the process is read. 602If zero is supplied, the first thread of the process is read.
596.It Dv PT_SETXMMREGS 603.It Dv PT_SETXMMREGS
597This request is the converse of 604This request is the converse of
598.Dv PT_GETXMMREGS ; 605.Dv PT_GETXMMREGS ;
599it loads the traced process' XMM registers from the 606it loads the traced process' XMM registers from the
600.Dq Li "struct xmmregs" 607.Dq Li "struct xmmregs"
601(defined in 608(defined in
602.In machine/reg.h ) 609.In machine/reg.h )
603pointed to by 610pointed to by
604.Fa addr . 611.Fa addr .
605The 612The
606.Fa data 613.Fa data
607argument contains the LWP ID of the thread whose registers are to 614argument contains the LWP ID of the thread whose registers are to
608be written. 615be written.
609If zero is supplied, the first thread of the process is written. 616If zero is supplied, the first thread of the process is written.
610.It Dv PT_GETVECREGS 617.It Dv PT_GETVECREGS
611This request reads the traced process' vector registers into 618This request reads the traced process' vector registers into
612the 619the
613.Dq Li "struct vreg" 620.Dq Li "struct vreg"
614(defined in 621(defined in
615.In machine/reg.h ) 622.In machine/reg.h )
616pointed to by 623pointed to by
617.Fa addr . 624.Fa addr .
618The 625The
619.Fa data 626.Fa data
620argument contains the LWP ID of the thread whose registers are to 627argument contains the LWP ID of the thread whose registers are to
621be read. 628be read.
622If zero is supplied, the first thread of the process is read. 629If zero is supplied, the first thread of the process is read.
623.It Dv PT_SETVECREGS 630.It Dv PT_SETVECREGS
624This request is the converse of 631This request is the converse of
625.Dv PT_GETVECREGS ; 632.Dv PT_GETVECREGS ;
626it loads the traced process' vector registers from the 633it loads the traced process' vector registers from the
627.Dq Li "struct vreg" 634.Dq Li "struct vreg"
628(defined in 635(defined in
629.In machine/reg.h ) 636.In machine/reg.h )
630pointed to by 637pointed to by
631.Fa addr . 638.Fa addr .
632The 639The
633.Fa data 640.Fa data
634argument contains the LWP ID of the thread whose registers are to 641argument contains the LWP ID of the thread whose registers are to
635be written. 642be written.
636If zero is supplied, the first thread of the process is written. 643If zero is supplied, the first thread of the process is written.
637.El 644.El
638.Sh ERRORS 645.Sh ERRORS
639Some requests can cause 646Some requests can cause
640.Fn ptrace 647.Fn ptrace
641to return 648to return
642.Li \-1 649.Li \-1
643as a non-error value; to disambiguate, 650as a non-error value; to disambiguate,
644.Va errno 651.Va errno
645can be set to 0 before the call and checked afterwards. 652can be set to 0 before the call and checked afterwards.
646The possible errors are: 653The possible errors are:
647.Bl -tag -width "[EINVAL]" 654.Bl -tag -width "[EINVAL]"
648.It Bq Er EAGAIN 655.It Bq Er EAGAIN
649Process is currently exec'ing and cannot be traced. 656Process is currently exec'ing and cannot be traced.
650.It Bq Er EBUSY 657.It Bq Er EBUSY
651.Bl -bullet -compact 658.Bl -bullet -compact
652.It 659.It
653.Dv PT_ATTACH 660.Dv PT_ATTACH
654was attempted on a process that was already being traced. 661was attempted on a process that was already being traced.
655.It 662.It
656A request attempted to manipulate a process that was being traced by 663A request attempted to manipulate a process that was being traced by
657some process other than the one making the request. 664some process other than the one making the request.
658.It 665.It
659A request (other than 666A request (other than
660.Dv PT_ATTACH ) 667.Dv PT_ATTACH )
661specified a process that wasn't stopped. 668specified a process that wasn't stopped.
662.El 669.El
663.It Bq Er EINVAL 670.It Bq Er EINVAL
664.Bl -bullet -compact 671.Bl -bullet -compact
665.It 672.It
666A process attempted to use 673A process attempted to use
667.Dv PT_ATTACH 674.Dv PT_ATTACH
668on itself. 675on itself.
669.It 676.It
670The 677The
671.Fa request 678.Fa request
672was not a legal request on this machine architecture. 679was not a legal request on this machine architecture.
673.It 680.It
674The signal number (in 681The signal number (in
675.Fa data ) 682.Fa data )
676to 683to
677.Dv PT_CONTINUE 684.Dv PT_CONTINUE
678was neither 0 nor a legal signal number. 685was neither 0 nor a legal signal number.
679.It 686.It
680.Dv PT_GETREGS , 687.Dv PT_GETREGS ,
681.Dv PT_SETREGS , 688.Dv PT_SETREGS ,
682.Dv PT_GETFPREGS , 689.Dv PT_GETFPREGS ,
683or 690or
684.Dv PT_SETFPREGS 691.Dv PT_SETFPREGS
685was attempted on a process with no valid register set. 692was attempted on a process with no valid register set.
686(This is normally true only of system processes.) 693(This is normally true only of system processes.)
687.El 694.El
688.It Bq Er EPERM 695.It Bq Er EPERM
689.Bl -bullet -compact 696.Bl -bullet -compact
690.It 697.It
691A request (other than 698A request (other than
692.Dv PT_ATTACH ) 699.Dv PT_ATTACH )
693attempted to manipulate a process that wasn't being traced at all. 700attempted to manipulate a process that wasn't being traced at all.
694.It 701.It
695An attempt was made to use 702An attempt was made to use
696.Dv PT_ATTACH 703.Dv PT_ATTACH
697on a process in violation of the requirements listed under 704on a process in violation of the requirements listed under
698.Dv PT_ATTACH 705.Dv PT_ATTACH
699above. 706above.
700.El 707.El
701.It Bq Er ESRCH 708.It Bq Er ESRCH
702No process having the specified process ID exists. 709No process having the specified process ID exists.
703.El 710.El
704.Sh SEE ALSO 711.Sh SEE ALSO
705.Xr sigaction 2 , 712.Xr sigaction 2 ,
706.Xr signal 7 713.Xr signal 7
707.Sh HISTORY 714.Sh HISTORY
708The 715The
709.Fn ptrace 716.Fn ptrace
710function appeared in 717function appeared in
711.At v7 . 718.At v7 .
712.Sh BUGS 719.Sh BUGS
713On the SPARC, the PC is set to the provided PC value for 720On the SPARC, the PC is set to the provided PC value for
714.Dv PT_CONTINUE 721.Dv PT_CONTINUE
715and similar calls, 722and similar calls,
716but the NPC is set willy-nilly to 4 greater than the PC value. 723but the NPC is set willy-nilly to 4 greater than the PC value.
717Using 724Using
718.Dv PT_GETREGS 725.Dv PT_GETREGS
719and 726and
720.Dv PT_SETREGS 727.Dv PT_SETREGS
721to modify the PC, passing 728to modify the PC, passing
722.Li (void *)1 729.Li (void *)1
723to 730to
724.Eo \& 731.Eo \&
725.Fn ptrace 732.Fn ptrace
726.Ec , 733.Ec ,
727should be able to sidestep this. 734should be able to sidestep this.
728.Pp 735.Pp
729.Dv PTRACE_VFORK 736.Dv PTRACE_VFORK
730is currently unimplemented and it will return 737is currently unimplemented and it will return
731.Er ENOTSUP . 738.Er ENOTSUP .