1 .\" Copyright (c) 1980 Regents of the University of California.
2 .\" All rights reserved. The Berkeley software License Agreement
3 .\" specifies the terms and conditions for redistribution.
5 .\" @(#)ptrace.2 6.4 (Berkeley) 5/23/86
7 .TH PTRACE 2 "May 23, 1986"
10 ptrace \- process trace
14 #include <sys/types.h>
15 #include <sys/signal.h>
16 #include <sys/ptrace.h>
18 int ptrace(int \fIrequest\fP, pid_t \fIpid\fP, long \fIaddr\fP, long \fIdata\fP)
23 Note: This manual page has no relation to MINIX 3. Someone who knows ptrace()
24 has to check, or rewrite, this page. (kjb)
28 provides a means by which a parent process
29 may control the execution of a child process,
30 and examine and change its core image.
31 Its primary use is for the implementation of breakpoint debugging.
32 There are four arguments whose interpretation
38 is the process ID of the traced process,
39 which must be a child (no more distant descendant)
40 of the tracing process.
41 A process being traced
42 behaves normally until it encounters some signal
43 whether internally generated
44 like \*(lqillegal instruction\*(rq or externally
45 generated like \*(lqinterrupt\*(rq.
49 Then the traced process enters a stopped state
50 and its parent is notified via
52 When the child is in the stopped state,
53 its core image can be examined and modified
58 request can then cause the child either to terminate
59 or to continue, possibly ignoring the signal.
63 argument determines the precise
67 This request is the only one used by the child process;
68 it declares that the process is to be traced by its parent.
69 All the other arguments are ignored.
70 Peculiar results will ensue
71 if the parent does not expect to trace the child.
75 word in the child process's address space
79 If I and D space are separated (e.g. historically
80 on a pdp-11), request PT_READ_I indicates I space,
83 must be even on some machines.
84 The child must be stopped.
91 of the system's per-process data area corresponding to
95 must be even on some machines and less than 512.
96 This space contains the registers and other information about
98 its layout corresponds to the
100 structure in the system.
102 PT_WRITE_I, PT_WRITE_D
106 is written at the word in the process's address space corresponding to
108 which must be even on some machines.
109 No useful value is returned.
110 If I and D space are separated, request PT_WRITE_I indicates I space,
112 Attempts to write in pure procedure
113 fail if another process is executing the same file.
116 The process's system data is written,
117 as it is read with request PT_READ_U.
118 Only a few locations can be written in this way:
119 the general registers,
120 the floating point status and registers,
121 and certain bits of the processor status word.
126 argument is taken as a signal number
127 and the child's execution continues
130 as if it had incurred that signal.
131 Normally the signal number will be
132 either 0 to indicate that the signal that caused the stop
134 or that value fetched out of the
135 process's image indicating which signal caused
139 is (int *)1 then execution continues from where it stopped.
142 The traced process terminates.
145 Execution continues as in request PT_CONTINUE;
146 however, as soon as possible after execution of at least one instruction,
147 execution stops again.
148 The signal number from the stop is
150 (On the VAX-11 the T-bit is used and just one instruction
152 This is part of the mechanism for implementing breakpoints.
156 (except for request PT_TRACE_ME)
157 can be used only when the subject process has stopped.
160 call is used to determine
161 when a process stops;
162 in such a case the \*(lqtermination\*(rq status
165 has the value 0177 to indicate stoppage rather
166 than genuine termination.
168 To forestall possible fraud,
170 inhibits the set-user-id and set-group-id facilities
174 If a traced process calls
176 it will stop before executing the first instruction of the new image
177 showing signal SIGTRAP.
179 On a VAX-11, \*(lqword\*(rq also means a 32-bit integer,
180 but the \*(lqeven\*(rq
181 restriction does not apply.
183 A 0 value is returned if the call succeeds. If the call fails
184 then a \-1 is returned and the global variable \fIerrno\fP is
185 set to indicate the error.
189 The request code is invalid.
192 The specified process does not exist.
195 The given signal number is invalid.
198 The specified address is out of bounds.
201 The specified process cannot be traced.
208 is unique and arcane; it should be replaced with a special file that
209 can be opened and read and written. The control functions could then
212 calls on this file. This would be simpler to understand and have much
215 The request PT_TRACE_ME call should be able to specify
216 signals that are to be treated normally and not cause a stop.
217 In this way, for example,
218 programs with simulated floating point (which
219 use \*(lqillegal instruction\*(rq signals at a very high rate)
220 could be efficiently debugged.
222 The error indication, \-1, is a legitimate function value;
226 can be used to disambiguate.
228 It should be possible to stop a process on occurrence of a system
230 in this way a completely controlled environment could