source: trunk/minix/man/man2/ptrace.2@ 15

Last change on this file since 15 was 9, checked in by Mattia Monga, 14 years ago

Minix 3.1.2a

File size: 5.9 KB
Line 
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.
4.\"
5.\" @(#)ptrace.2 6.4 (Berkeley) 5/23/86
6.\"
7.TH PTRACE 2 "May 23, 1986"
8.UC 4
9.SH NAME
10ptrace \- process trace
11.SH SYNOPSIS
12.nf
13.ft B
14#include <sys/types.h>
15#include <sys/signal.h>
16#include <sys/ptrace.h>
17
18int ptrace(int \fIrequest\fP, pid_t \fIpid\fP, long \fIaddr\fP, long \fIdata\fP)
19.ft R
20.fi
21.SH DESCRIPTION
22.ft B
23Note: This manual page has no relation to MINIX 3. Someone who knows ptrace()
24has to check, or rewrite, this page. (kjb)
25.ft R
26.PP
27.B Ptrace
28provides a means by which a parent process
29may control the execution of a child process,
30and examine and change its core image.
31Its primary use is for the implementation of breakpoint debugging.
32There are four arguments whose interpretation
33depends on a
34.I request
35argument.
36Generally,
37.I pid
38is the process ID of the traced process,
39which must be a child (no more distant descendant)
40of the tracing process.
41A process being traced
42behaves normally until it encounters some signal
43whether internally generated
44like \*(lqillegal instruction\*(rq or externally
45generated like \*(lqinterrupt\*(rq.
46See
47.BR sigaction (2)
48for the list.
49Then the traced process enters a stopped state
50and its parent is notified via
51.BR wait (2).
52When the child is in the stopped state,
53its core image can be examined and modified
54using
55.BR ptrace .
56If desired, another
57.B ptrace
58request can then cause the child either to terminate
59or to continue, possibly ignoring the signal.
60.PP
61The value of the
62.I request
63argument determines the precise
64action of the call:
65.TP 4
66PT_TRACE_ME
67This request is the only one used by the child process;
68it declares that the process is to be traced by its parent.
69All the other arguments are ignored.
70Peculiar results will ensue
71if the parent does not expect to trace the child.
72.TP 4
73PT_READ_I, PT_READ_D
74The
75word in the child process's address space
76at
77.I addr
78is returned.
79If I and D space are separated (e.g. historically
80on a pdp-11), request PT_READ_I indicates I space,
81PT_READ_D D space.
82.I Addr
83must be even on some machines.
84The child must be stopped.
85The input
86.I data
87is ignored.
88.TP 4
89PT_READ_U
90The word
91of the system's per-process data area corresponding to
92.I addr
93is returned.
94.I Addr
95must be even on some machines and less than 512.
96This space contains the registers and other information about
97the process;
98its layout corresponds to the
99.I user
100structure in the system.
101.TP 4
102PT_WRITE_I, PT_WRITE_D
103The
104given
105.I data
106is written at the word in the process's address space corresponding to
107.I addr,
108which must be even on some machines.
109No useful value is returned.
110If I and D space are separated, request PT_WRITE_I indicates I space,
111PT_WRITE_D D space.
112Attempts to write in pure procedure
113fail if another process is executing the same file.
114.TP 4
115PT_WRITE_U
116The process's system data is written,
117as it is read with request PT_READ_U.
118Only a few locations can be written in this way:
119the general registers,
120the floating point status and registers,
121and certain bits of the processor status word.
122.TP 4
123PT_CONTINUE
124The
125.I data
126argument is taken as a signal number
127and the child's execution continues
128at location
129.I addr
130as if it had incurred that signal.
131Normally the signal number will be
132either 0 to indicate that the signal that caused the stop
133should be ignored,
134or that value fetched out of the
135process's image indicating which signal caused
136the stop.
137If
138.I addr
139is (int *)1 then execution continues from where it stopped.
140.TP 4
141PT_KILL
142The traced process terminates.
143.TP 4
144PT_STEP
145Execution continues as in request PT_CONTINUE;
146however, as soon as possible after execution of at least one instruction,
147execution stops again.
148The signal number from the stop is
149SIGTRAP.
150(On the VAX-11 the T-bit is used and just one instruction
151is executed.)
152This is part of the mechanism for implementing breakpoints.
153.PP
154As indicated,
155these calls
156(except for request PT_TRACE_ME)
157can be used only when the subject process has stopped.
158The
159.B wait
160call is used to determine
161when a process stops;
162in such a case the \*(lqtermination\*(rq status
163returned by
164.B wait
165has the value 0177 to indicate stoppage rather
166than genuine termination.
167.PP
168To forestall possible fraud,
169.B ptrace
170inhibits the set-user-id and set-group-id facilities
171on subsequent
172.BR execve (2)
173calls.
174If a traced process calls
175.BR execve ,
176it will stop before executing the first instruction of the new image
177showing signal SIGTRAP.
178.PP
179On a VAX-11, \*(lqword\*(rq also means a 32-bit integer,
180but the \*(lqeven\*(rq
181restriction does not apply.
182.SH "RETURN VALUE
183A 0 value is returned if the call succeeds. If the call fails
184then a \-1 is returned and the global variable \fIerrno\fP is
185set to indicate the error.
186.SH "ERRORS
187.TP 15
188[EIO]
189The request code is invalid.
190.TP 15
191[ESRCH]
192The specified process does not exist.
193.TP 15
194[EIO]
195The given signal number is invalid.
196.TP 15
197[EIO]
198The specified address is out of bounds.
199.TP 15
200[EPERM]
201The specified process cannot be traced.
202.SH "SEE ALSO"
203.BR wait (2),
204.BR sigaction (2),
205.BR mdb (1).
206.SH BUGS
207.B Ptrace
208is unique and arcane; it should be replaced with a special file that
209can be opened and read and written. The control functions could then
210be implemented with
211.BR ioctl (2)
212calls on this file. This would be simpler to understand and have much
213higher performance.
214.PP
215The request PT_TRACE_ME call should be able to specify
216signals that are to be treated normally and not cause a stop.
217In this way, for example,
218programs with simulated floating point (which
219use \*(lqillegal instruction\*(rq signals at a very high rate)
220could be efficiently debugged.
221.PP
222The error indication, \-1, is a legitimate function value;
223.BR errno ,
224(see
225.BR intro (2)),
226can be used to disambiguate.
227.PP
228It should be possible to stop a process on occurrence of a system
229call;
230in this way a completely controlled environment could
231be provided.
Note: See TracBrowser for help on using the repository browser.