1 .\" $FreeBSD: src/lib/libc/sys/ptrace.2,v 1.12.2.12 2001/12/14 18:34:01 ru Exp $
2 .\" $DragonFly: src/lib/libc/sys/ptrace.2,v 1.4 2006/05/26 19:39:37 swildner Exp $
3 .\" $NetBSD: ptrace.2,v 1.2 1995/02/27 12:35:37 cgd Exp $
5 .\" This file is in the public domain.
11 .Nd process tracing and debugging
18 .Fn ptrace "int request" "pid_t pid" "caddr_t addr" "int data"
21 provides tracing and debugging facilities. It allows one process (the
23 process) to control another (the
25 process). Most of the time, the traced process runs normally, but when
29 it stops. The tracing process is expected to notice this via
33 signal, examine the state of the stopped process, and cause it to
34 terminate or continue as appropriate.
36 is the mechanism by which all this happens.
40 argument specifies what operation is being performed; the meaning of
41 the rest of the arguments depends on the operation, but except for one
42 special case noted below, all
44 calls are made by the tracing process, and the
46 argument specifies the process ID of the traced process.
51 This request is the only one used by the traced process; it declares
52 that the process expects to be traced by its parent. All the other
53 arguments are ignored. (If the parent process does not expect to trace
54 the child, it will probably be rather confused by the results; once the
55 traced process stops, it cannot be made to continue except via
57 When a process has used this request and calls
59 or any of the routines built on it
62 it will stop before executing the first instruction of the new image.
63 Also, any setuid or setgid bits on the executable being executed will
65 .It Dv PT_READ_I , Dv PT_READ_D
66 These requests read a single
68 of data from the traced process' address space. Traditionally,
70 has allowed for machines with distinct address spaces for instruction
71 and data, which is why there are two requests: conceptually,
73 reads from the instruction space and
75 reads from the data space. In the current
78 two requests are completely identical. The
80 argument specifies the address (in the traced process' virtual address
81 space) at which the read is to be done. This address does not have to
82 meet any alignment constraints. The value read is returned as the
87 .It Dv PT_WRITE_I , Dv PT_WRITE_D
88 These requests parallel
92 except that they write rather than read. The
94 argument supplies the value to be written.
96 The traced process continues execution.
98 is an address specifying the place where execution is to be resumed (a
99 new value for the program counter), or
100 .Po Vt caddr_t Pc Ns 1
101 to indicate that execution is to pick up where it left off.
103 provides a signal number to be delivered to the traced process as it
104 resumes execution, or 0 if no signal is to be sent.
106 The traced process is single stepped one instruction.
109 .Po Vt caddr_t Pc Ns 1 .
113 The traced process terminates, as if
117 given as the signal to be delivered.
119 This request allows a process to gain control of an otherwise unrelated
120 process and begin tracing it. It does not need any cooperation from
121 the to-be-traced process. In this case,
123 specifies the process ID of the to-be-traced process, and the other two
124 arguments are ignored. This request requires that the target process
125 must have the same real UID as the tracing process, and that it must
126 not be executing a setuid or setgid executable. (If the tracing
127 process is running as root, these restrictions do not apply.) The
128 tracing process will see the newly-traced process stop and may then
129 control it as if it had been traced all along.
131 This request is like PT_CONTINUE, except that it does not allow
132 specifying an alternate place to continue execution, and after it
133 succeeds, the traced process is no longer traced and continues
137 Additionally, machine-specific requests can exist. On the i386, these
141 This request reads the traced process' machine registers into the
150 This request is the converse of
152 it loads the traced process' machine registers from the
161 This request reads the traced process' floating-point registers into
171 This request is the converse of
173 it loads the traced process' floating-point registers from the
182 This request reads the traced process' debug registers into
192 This request is the converse of
194 it loads the traced process' debug registers from the
204 Some requests can cause
208 as a non-error value; to disambiguate,
210 can be set to 0 before the call and checked afterwards.
214 function may fail if:
219 No process having the specified process ID exists.
224 A process attempted to use
230 was not one of the legal requests.
232 The signal number (in
236 was neither 0 nor a legal signal number.
245 was attempted on a process with no valid register set. (This is
246 normally true only of system processes.)
252 was attempted on a process that was already being traced.
254 A request attempted to manipulate a process that was being traced by
255 some process other than the one making the request.
257 A request (other than
259 specified a process that wasn't stopped.
264 A request (other than
266 attempted to manipulate a process that wasn't being traced at all.
268 An attempt was made to use
270 on a process in violation of the requirements listed under
280 .Xr i386_clr_watch 3 ,
285 function call appeared in