OSDN Git Service

181a465a50863eabd4711e42f9b8a4f1635f5b79
[linuxjm/LDP_man-pages.git] / draft / man2 / ptrace.2
1 .\" Hey Emacs! This file is -*- nroff -*- source.
2 .\"
3 .\" Copyright (c) 1993 Michael Haardt
4 .\" (michael@moria.de),
5 .\" Fri Apr  2 11:32:09 MET DST 1993
6 .\"
7 .\" changes Copyright 1999 Mike Coleman (mkc@acm.org)
8 .\" -- major revision to fully document ptrace semantics per recent Linux
9 .\"    kernel (2.2.10) and glibc (2.1.2)
10 .\" Sun Nov  7 03:18:35 CST 1999
11 .\"
12 .\" This is free documentation; you can redistribute it and/or
13 .\" modify it under the terms of the GNU General Public License as
14 .\" published by the Free Software Foundation; either version 2 of
15 .\" the License, or (at your option) any later version.
16 .\"
17 .\" The GNU General Public License's references to "object code"
18 .\" and "executables" are to be interpreted as the output of any
19 .\" document formatting or typesetting system, including
20 .\" intermediate and printed output.
21 .\"
22 .\" This manual is distributed in the hope that it will be useful,
23 .\" but WITHOUT ANY WARRANTY; without even the implied warranty of
24 .\" MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
25 .\" GNU General Public License for more details.
26 .\"
27 .\" You should have received a copy of the GNU General Public
28 .\" License along with this manual; if not, write to the Free
29 .\" Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111,
30 .\" USA.
31 .\"
32 .\" Modified Fri Jul 23 23:47:18 1993 by Rik Faith <faith@cs.unc.edu>
33 .\" Modified Fri Jan 31 16:46:30 1997 by Eric S. Raymond <esr@thyrsus.com>
34 .\" Modified Thu Oct  7 17:28:49 1999 by Andries Brouwer <aeb@cwi.nl>
35 .\" Modified, 27 May 2004, Michael Kerrisk <mtk.manpages@gmail.com>
36 .\"     Added notes on capability requirements
37 .\"
38 .\" 2006-03-24, Chuck Ebbert <76306.1226@compuserve.com>
39 .\"    Added    PTRACE_SETOPTIONS, PTRACE_GETEVENTMSG, PTRACE_GETSIGINFO,
40 .\"        PTRACE_SETSIGINFO, PTRACE_SYSEMU, PTRACE_SYSEMU_SINGLESTEP
41 .\"    (Thanks to Blaisorblade, Daniel Jacobowitz and others who helped.)
42 .\"
43 .\" FIXME: Linux 3.1 adds PTRACE_SEIZE, PTRACE_INTERRUPT, and PTRACE_LISTEN.
44 .\"
45 .\" Japanese Version Copyright (c) 1997-1999 HANATAKA Shinya
46 .\"         all rights reserved.
47 .\" Translated 1999-11-20, HANATAKA Shinya <hanataka@abyss.rim.or.jp>
48 .\" Updated 2003-10-11, Kentaro Shirakata <argrath@ub32.org>
49 .\" Updated 2006-07-23, Akihiro MOTOKI <amotoki@dd.iij4u.or.jp>, LDP v2.28
50 .\" Updated 2007-01-07, Akihiro MOTOKI, LDP v2.43
51 .\" Updated 2007-05-01, Akihiro MOTOKI, LDP v2.46
52 .\" Updated 2008-08-06, Akihiro MOTOKI, LDP v3.05
53 .\" Updated 2009-04-13, Akihiro MOTOKI, LDP v3.20
54 .\"
55 .\"WORD:        child process           子プロセス
56 .\"WORD:        parent process          親プロセス
57 .\"WORD:        core image              メモリ・イメージ
58 .\"WORD:        break point             ブレーク・ポイント
59 .\"WORD:        single step             シングル・ステップ実行
60 .\"WORD:        trap flag               トラップ・フラグ
61 .\"WORD:        attach                  接続
62 .\"WORD:        detach                  分離
63 .\"WORD:        process ID              プロセスID
64 .\"
65 .TH PTRACE 2 2009-03-30 "Linux" "Linux Programmer's Manual"
66 .SH 名前
67 .\"O ptrace \- process trace
68 ptrace \- プロセスのトレース
69 .SH 書式
70 .nf
71 .B #include <sys/ptrace.h>
72 .sp
73 .BI "long ptrace(enum __ptrace_request " request ", pid_t " pid ", "
74 .BI "            void *" addr ", void *" data );
75 .fi
76 .SH 説明
77 .\"O The
78 .\"O .BR ptrace ()
79 .\"O system call provides a means by which a parent process may observe
80 .\"O and control the execution of another process,
81 .\"O and examine and change its core image and registers.
82 .\"O It is primarily used to implement breakpoint debugging and system
83 .\"O call tracing.
84 .BR ptrace ()
85 システムコールは、親プロセスが、別のプロセスの実行の監視/制御を
86 行ったり、コアイメージ (core image) やレジスタの調査/変更を
87 行ったりする手段を提供する。
88 .BR ptrace ()
89 は、主にブレークポイントによるデバッグやシステムコールのトレースを
90 実装するのに用いられる。
91 .LP
92 .\"O The parent can initiate a trace by calling
93 .\"O .BR fork (2)
94 .\"O and having the resulting child do a
95 .\"O .BR PTRACE_TRACEME ,
96 .\"O followed (typically) by an
97 .\"O .BR exec (3).
98 .\"O Alternatively, the parent may commence trace of an existing process using
99 .\"O .BR PTRACE_ATTACH .
100 トレースを開始するには、まず親プロセスで
101 .BR fork (2)
102 を呼び出す。生成された子プロセスで
103 .B PTRACE_TRACEME
104 を行い、続いて (典型的には)
105 .BR exec (3)
106 を行なう。
107 別の方法としては、
108 親プロセスが既存のプロセスに対して
109 .B PTRACE_ATTACH
110 を使用し、トレースを開始する。
111 .LP
112 .\"O While being traced, the child will stop each time a signal is delivered,
113 .\"O even if the signal is being ignored.
114 .\"O (The exception is
115 .\"O .BR SIGKILL ,
116 .\"O which has its usual effect.)
117 .\"O The parent will be notified at its next
118 .\"O .BR wait (2)
119 .\"O and may inspect and modify the child process while it is stopped.
120 .\"O The parent then causes the child to continue,
121 .\"O optionally ignoring the delivered signal
122 .\"O (or even delivering a different signal instead).
123 トレースの実行中、子プロセスはシグナルが配送されるたびに、
124 たとえそのシグナルが無視すべきものであっても停止する
125 .RB ( SIGKILL
126 は例外で、通常どおりの効果をもたらす)。
127 親プロセスには次の
128 .BR wait (2)
129 で通知され、停止している間に子プロセスを調べたり修正したりすることができる。
130 そして親プロセスは子プロセスの実行を再開させるが、配送された
131 シグナルを無視することもできる (あるいは代わりに別のシグナルを
132 配送することもできる) 。
133 .LP
134 .\"O When the parent is finished tracing, it can terminate the child with
135 .\"O .B PTRACE_KILL
136 .\"O or cause it to continue executing in a normal, untraced mode
137 .\"O via
138 .\"O .BR PTRACE_DETACH .
139 親プロセスがトレースを終了する際には、
140 .B PTRACE_KILL
141 を使用して子プロセスを終了させることもできるし、
142 .B PTRACE_DETACH
143 を用いて通常のトレースなしのモードにして、
144 実行を継続させることもできる。
145 .LP
146 .\"O The value of \fIrequest\fP determines the action to be performed:
147 \fIrequest\fP の値がこのシステムコールの動作を決定する:
148 .TP
149 .B PTRACE_TRACEME
150 .\"O Indicates that this process is to be traced by its parent.
151 .\"O Any signal
152 .\"O (except
153 .\"O .BR SIGKILL )
154 .\"O delivered to this process will cause it to stop and its
155 .\"O parent to be notified via
156 .\"O .BR wait (2).
157 .\"O Also, all subsequent calls to
158 .\"O .BR execve (2)
159 .\"O by this process will cause a
160 .\"O .B SIGTRAP
161 .\"O to be sent to it,
162 .\"O giving the parent a chance to gain control before the new program
163 .\"O begins execution.
164 .\"O A process probably shouldn't make this request if its parent
165 .\"O isn't expecting to trace it.
166 .\"O (\fIpid\fP, \fIaddr\fP, and \fIdata\fP are ignored.)
167 このプロセスが親プロセスによってトレースされることを表す。
168 このプロセスに
169 .RB ( SIGKILL
170 以外の) シグナルが配送されると、
171 プロセスは停止し、親プロセスに
172 .BR wait (2)
173 を通じて通知される。
174 また、これ以降はこのプロセスが
175 .BR execve (2)
176 を呼び出す度に
177 .B SIGTRAP
178 が送信されるようになる。
179 これによって、親プロセスは
180 新しいプログラムが実行を開始する前に制御することができる。
181 親プロセスが自プロセスをトレースするつもりがない場合には、
182 おそらくこのプロセスは本要求を行うべきではないだろう。
183 (\fIpid\fP, \fIaddr\fP, \fIdata\fP は無視される。)
184 .LP
185 .\"O The above request is used only by the child process;
186 .\"O the rest are used only by the parent.
187 .\"O In the following requests, \fIpid\fP specifies the child process
188 .\"O to be acted on.
189 .\"O For requests other than
190 .\"O .BR PTRACE_KILL ,
191 .\"O the child process must
192 .\"O be stopped.
193 上記の要求は子プロセスだけが行なうものである。
194 残りは親プロセスだけが行なうものである。
195 以下の要求では、\fIpid\fP で操作の対象となる
196 子プロセスを指定する。
197 .B PTRACE_KILL
198 を除き、要求を行なうためには
199 子プロセスは停止していなければならない。
200 .TP
201 .BR PTRACE_PEEKTEXT ", " PTRACE_PEEKDATA
202 .\"O Reads a word at the location
203 .\"O .I addr
204 .\"O in the child's memory, returning the word as the result of the
205 .\"O .BR ptrace ()
206 .\"O call.
207 .\"O Linux does not have separate text and data address spaces, so the two
208 .\"O requests are currently equivalent.
209 .\"O (The argument \fIdata\fP is ignored.)
210 子プロセスのメモリの
211 .I addr
212 の位置から 1 ワードを読み出す。読み出したワードは
213 .BR ptrace ()
214 の返り値として返される。 Linux ではテキスト (text) とデータ (data) で
215 同じアドレス空間を使用するため、この 2 つの要求は現在のところ
216 同じものである。 (引き数 \fIdata\fP は無視される。)
217 .TP
218 .B PTRACE_PEEKUSER
219 .\" PTRACE_PEEKUSR in kernel source, but glibc uses PTRACE_PEEKUSER,
220 .\" and that is the name that seems common on other systems.
221 .\"O Reads a word at offset
222 .\"O .I addr
223 .\"O in the child's USER area,
224 .\"O which holds the registers and other information about the process
225 .\"O (see \fI<sys/user.h>\fP).
226 .\"O The word is returned as the result of the
227 .\"O .BR ptrace ()
228 .\"O call.
229 .\"O Typically the offset must be word-aligned, though this might vary by
230 .\"O architecture.
231 .\"O See NOTES.
232 .\"O (\fIdata\fP is ignored.)
233 子プロセスの USER 領域のオフセット
234 .I addr
235 の位置から 1 ワードを読み込む。USER 領域にはそのプロセスの
236 レジスタ (registers) などの情報が保持されている
237 (\fI<sys/user.h>\fP を参照)。読み込んだワードは
238 .BR ptrace ()
239 コールの結果として返される。
240 たいていはオフセットはワード境界になければならないが、
241 アーキテクチャによってはその必要はない。
242 「注意」の節を参照。
243 (\fIdata\fP は無視される。 )
244 .TP
245 .BR PTRACE_POKETEXT ", " PTRACE_POKEDATA
246 .\"O Copies the word
247 .\"O .I data
248 .\"O to location
249 .\"O .I addr
250 .\"O in the child's memory.
251 .\"O As above, the two requests are currently equivalent.
252 ワード
253 .I data
254 を子プロセスのメモリの
255 .I addr
256 の位置へコピーする。上と同様に、現在のところ二つの
257 要求は同じものである。
258 .TP
259 .B PTRACE_POKEUSER
260 .\" PTRACE_POKEUSR in kernel source, but glibc uses PTRACE_POKEUSER,
261 .\" and that is the name that seems common on other systems.
262 .\"O Copies the word
263 .\"O .I data
264 .\"O to offset
265 .\"O .I addr
266 .\"O in the child's USER area.
267 .\"O As above, the offset must typically be word-aligned.
268 .\"O In order to maintain the integrity of the kernel,
269 .\"O some modifications to the USER area are disallowed.
270 ワード
271 .I data
272 を子プロセスの USER 領域のオフセット
273 .I addr
274 の位置にコピーする。
275 上と同様に、通常、オフセットはワード境界になければならない。
276 カーネルの完全性 (integrity) を維持するため、
277 変更内容によっては USER 領域の変更は禁止されている。
278 .TP
279 .BR PTRACE_GETREGS ", " PTRACE_GETFPREGS
280 .\"O Copies the child's general purpose or floating-point registers,
281 .\"O respectively, to location \fIdata\fP in the parent.
282 .\"O See \fI<sys/user.h>\fP for information on
283 .\"O the format of this data.
284 .\"O (\fIaddr\fP is ignored.)
285 それぞれ、子プロセスの汎用レジスタ、浮動小数点レジスタを親プロセスの
286 \fIdata\fP の位置にコピーする。この data の書式に関しては
287 \fI<sys/user.h>\fP を参照すること。(\fIaddr\fP は無視される。)
288 .TP
289 .\"O .BR PTRACE_GETSIGINFO " (since Linux 2.3.99-pre6)"
290 .BR PTRACE_GETSIGINFO " (Linux 2.3.99-pre6 以降)"
291 .\"O Retrieve information about the signal that caused the stop.
292 .\"O Copies a \fIsiginfo_t\fP structure (see
293 .\"O .BR sigaction (2))
294 .\"O from the child to location \fIdata\fP in the parent.
295 .\"O (\fIaddr\fP is ignored.)
296 停止の原因となったシグナルに関する情報を取得する。
297 \fIsiginfo_t\fP 構造体
298 .RB ( sigaction (2)
299 参照) を子プロセスから親プロセスの \fIdata\fP の位置にコピーする。
300 (\fIaddr\fP は無視される。)
301 .TP
302 .BR PTRACE_SETREGS ", " PTRACE_SETFPREGS
303 .\"O Copies the child's general purpose or floating-point registers,
304 .\"O respectively, from location \fIdata\fP in the parent.
305 .\"O As for
306 .\"O .BR PTRACE_POKEUSER ,
307 .\"O some general
308 .\"O purpose register modifications may be disallowed.
309 .\"O (\fIaddr\fP is ignored.)
310 それぞれ、子プロセスの汎用レジスタ、浮動小数点レジスタに
311 親プロセスの \fIdate\fP の位置からコピーする。
312 .B PTRACE_POKEUSER
313 と同様に、汎用レジスタによっては
314 変更が禁止されている場合がある。 (\fIaddr\fP は無視される。)
315 .TP
316 .\"O .BR PTRACE_SETSIGINFO " (since Linux 2.3.99-pre6)"
317 .BR PTRACE_SETSIGINFO " (Linux 2.3.99-pre6 以降)"
318 .\"O Set signal information.
319 .\"O Copies a \fIsiginfo_t\fP structure from location \fIdata\fP in the
320 .\"O parent to the child.
321 .\"O This will only affect signals that would normally be delivered to
322 .\"O the child and were caught by the tracer.
323 .\"O It may be difficult to tell
324 .\"O these normal signals from synthetic signals generated by
325 .\"O .BR ptrace ()
326 .\"O itself.
327 .\"O (\fIaddr\fP is ignored.)
328 シグナル情報を設定する。
329 \fIsiginfo_t\fP 構造体を親プロセスのデータ \fIdata\fP の位置から
330 子プロセスにコピーする。
331 この処理を行うことができるのは、子プロセスに通常は配送されるはずで
332 トレーサに捕捉されたシグナルについてだけである。
333 これらの通常のシグナルと
334 .BR ptrace ()
335 自身が発生するシグナルを見分けるのは難しいかもしれない。
336 (\fIaddr\fP は無視される。)
337 .TP
338 .\"O .BR PTRACE_SETOPTIONS " (since Linux 2.4.6; see BUGS for caveats)"
339 .BR PTRACE_SETOPTIONS " (Linux 2.4.6 以降; バグの章にある警告も参照)"
340 .\"O Sets ptrace options from \fIdata\fP in the parent.
341 .\"O (\fIaddr\fP is ignored.)
342 .\"O \fIdata\fP is interpreted
343 .\"O as a bit mask of options, which are specified by the following flags:
344 親プロセスの \fIdata\fP に基づいて ptrace のオプションを設定する
345 (\fIaddr\fP は無視される)。
346 \fIdata\fP はオプションのビットマスクとして解釈され、
347 オプションには以下のフラグを指定できる:
348 .RS
349 .TP
350 .\"O .BR PTRACE_O_TRACESYSGOOD " (since Linux 2.4.6)"
351 .BR PTRACE_O_TRACESYSGOOD " (Linux 2.4.6 以降)"
352 .\"O When delivering syscall traps, set bit 7 in the signal number
353 .\"O (i.e., deliver \fISIGTRAP | 0x80\fP).
354 .\"O This makes it easy for the tracer to tell the difference
355 .\"O between normal traps and those caused by a syscall.
356 .\"O .RB ( PTRACE_O_TRACESYSGOOD
357 .\"O may not work on all architectures.)
358 システムコールのトラップが配送されたときに、シグナル番号のビット 7
359 を設定する (すなわち、\fISIGTRAP | 0x80\fP を配送する)。
360 これにより、トレーサが通常のトラップとシステムコールによるトラップを
361 区別しやすくなる。
362 .RB ( PTRACE_O_TRACESYSGOOD
363 はどのアーキテクチャでも動作しない可能性がある。)
364 .TP
365 .\"O .BR PTRACE_O_TRACEFORK " (since Linux 2.5.46)"
366 .BR PTRACE_O_TRACEFORK " (Linux 2.5.46 以降)"
367 .\"O Stop the child at the next
368 .\"O .BR fork (2)
369 .\"O call with \fISIGTRAP | PTRACE_EVENT_FORK\ <<\ 8\fP and automatically
370 .\"O start tracing the newly forked process,
371 .\"O which will start with a
372 .\"O .BR SIGSTOP .
373 .\"O The PID for the new process can be retrieved with
374 .\"O .BR PTRACE_GETEVENTMSG .
375 次の
376 .BR fork (2)
377 呼び出し時に \fISIGTRAP | PTRACE_EVENT_FORK\ <<\ 8\fP で
378 子プロセスの動作を停止させ、
379 新たに fork されたプロセスのトレースを自動的に開始し、
380 .B SIGSTOP
381 でそのプロセスの実行を開始する。
382 新しいプロセスの PID は
383 .B PTRACE_GETEVENTMSG
384 で取得できる。
385 .TP
386 .\"O .BR PTRACE_O_TRACEVFORK " (since Linux 2.5.46)"
387 .BR PTRACE_O_TRACEVFORK " (Linux 2.5.46 以降)"
388 .\"O Stop the child at the next
389 .\"O .BR vfork (2)
390 .\"O call with \fISIGTRAP | PTRACE_EVENT_VFORK\ <<\ 8\fP and automatically start
391 .\"O tracing the newly vforked process, which will start with a
392 .\"O .BR SIGSTOP .
393 .\"O The PID for the new process can be retrieved with
394 .\"O .BR PTRACE_GETEVENTMSG .
395 次の
396 .BR vfork (2)
397 呼び出し時に \fISIGTRAP | PTRACE_EVENT_VFORK\ <<\ 8\fP で
398 子プロセスの動作を停止させ、
399 新たに vfork されたプロセスのトレースを自動的に開始し、
400 .B SIGSTOP
401 でそのプロセスの実行を開始する。
402 新しいプロセスの PID は
403 .B PTRACE_GETEVENTMSG
404 で取得できる。
405 .TP
406 .\"O .BR PTRACE_O_TRACECLONE " (since Linux 2.5.46)"
407 .BR PTRACE_O_TRACECLONE " (Linux 2.5.46 以降)"
408 .\"O Stop the child at the next
409 .\"O .BR clone (2)
410 .\"O call with \fISIGTRAP | PTRACE_EVENT_CLONE\ <<\ 8\fP and automatically start
411 .\"O tracing the newly cloned process, which will start with a
412 .\"O .BR SIGSTOP .
413 .\"O The PID for the new process can be retrieved with
414 .\"O .BR PTRACE_GETEVENTMSG .
415 .\"O This option may not catch
416 .\"O .BR clone (2)
417 .\"O calls in all cases.
418 .\"O If the child calls
419 .\"O .BR clone (2)
420 .\"O with the
421 .\"O .B CLONE_VFORK
422 .\"O flag,
423 .\"O .B PTRACE_EVENT_VFORK
424 .\"O will be delivered instead
425 .\"O if
426 .\"O .B PTRACE_O_TRACEVFORK
427 .\"O is set; otherwise if the child calls
428 .\"O .BR clone (2)
429 .\"O with the exit signal set to
430 .\"O .BR SIGCHLD ,
431 .\"O .B PTRACE_EVENT_FORK
432 .\"O will be delivered
433 .\"O if
434 .\"O .B PTRACE_O_TRACEFORK
435 .\"O is set.
436 次の
437 .BR clone (2)
438 呼び出し時に \fISIGTRAP | PTRACE_EVENT_CLONE\ << \8\fP で
439 子プロセスの動作を停止させ、
440 新たに clone で作成されたプロセスのトレースを自動的に開始し、
441 .B SIGSTOP
442 でプロセスの実行を開始する。
443 新しいプロセスの PID は
444 .B PTRACE_GETEVENTMSG
445 で取得できる。
446 このオプションで全ての
447 .BR clone (2)
448 コールを捕まえられるわけではない。
449 子プロセスが
450 .B CLONE_VFORK
451 フラグ付きで
452 .BR clone (2)
453 を呼び出した場合、
454 .B PTRACE_O_TRACEVFORK
455 が設定されていれば代わりに
456 .B PTRACE_EVENT_VFORK
457 が配送される。
458 また、子プロセスが終了シグナルを
459 .B SIGCHLD
460 に設定して
461 .BR clone (2)
462 を呼び出した場合は、
463 .B PTRACE_O_TRACEFORK
464 が設定されていれば
465 .B PTRACE_EVENT_FORK
466 が配送される。
467 .TP
468 .\"O .BR PTRACE_O_TRACEEXEC " (since Linux 2.5.46)"
469 .BR PTRACE_O_TRACEEXEC " (Linux 2.5.46 以降)"
470 .\"O Stop the child at the next
471 .\"O .BR execve (2)
472 .\"O call with \fISIGTRAP | PTRACE_EVENT_EXEC\ <<\ 8\fP.
473 次の
474 .BR execve (2)
475 呼び出し時に
476 \fISIGTRAP | PTRACE_EVENT_EXEC\ <<\ 8\fP
477 で子プロセスの動作を停止させる。
478 .TP
479 .\"O .BR PTRACE_O_TRACEVFORKDONE " (since Linux 2.5.60)"
480 .BR PTRACE_O_TRACEVFORKDONE " (Linux 2.5.60 以降)"
481 .\"O Stop the child at the completion of the next
482 .\"O .BR vfork (2)
483 .\"O call with \fISIGTRAP | PTRACE_EVENT_VFORK_DONE\ <<\ 8\fP.
484 次の
485 .BR vfork (2)
486 呼び出し時に
487 \fISIGTRAP | PTRACE_EVENT_VFORK_DONE\ <<\ 8\fP
488 で子プロセスの動作を停止させる。
489 .TP
490 .\"O .BR PTRACE_O_TRACEEXIT " (since Linux 2.5.60)"
491 .BR PTRACE_O_TRACEEXIT " (Linux 2.5.60 以降)"
492 .\"O Stop the child at exit with \fISIGTRAP | PTRACE_EVENT_EXIT\ <<\ 8\fP.
493 .\"O The child's exit status can be retrieved with
494 .\"O .BR PTRACE_GETEVENTMSG .
495 .\"O This stop will be done early during process exit when registers
496 .\"O are still available, allowing the tracer to see where the exit occurred,
497 .\"O whereas the normal exit notification is done after the process
498 .\"O is finished exiting.
499 .\"O Even though context is available, the tracer cannot prevent the exit from
500 .\"O happening at this point.
501 終了 (exit) 時に \fISIGTRAP | PTRACE_EVENT_EXIT\ <<\ 8\fP
502 で子プロセスの動作を停止させる。子プロセスの終了ステータスは
503 .B PTRACE_GETEVENTMSG
504 で取得できる。
505 この停止はレジスタがまだ参照可能であるプロセス終了処理の初期に行われ、
506 トレーサはどこで終了が発生したかを知ることができる。
507 通常の終了通知 (exit notification) はプロセスの終了処理が完了した後に
508 行われる。コンテキストを参照することはできるにも関わらず、
509 トレーサはこの時点から終了を止めることはできない。
510 .RE
511 .TP
512 .\"O .BR PTRACE_GETEVENTMSG " (since Linux 2.5.46)"
513 .BR PTRACE_GETEVENTMSG " (Linux 2.5.46 以降)"
514 .\"O Retrieve a message (as an
515 .\"O .IR "unsigned long" )
516 .\"O about the ptrace event
517 .\"O that just happened, placing it in the location \fIdata\fP in the parent.
518 .\"O For
519 .\"O .B PTRACE_EVENT_EXIT
520 .\"O this is the child's exit status.
521 .\"O For
522 .\"O .BR PTRACE_EVENT_FORK ,
523 .\"O .B PTRACE_EVENT_VFORK
524 .\"O and
525 .\"O .B PTRACE_EVENT_CLONE
526 .\"O this
527 .\"O is the PID of the new process.
528 .\"O Since Linux 2.6.18, the PID of the new process is also available
529 .\"O for
530 .\"O .BR PTRACE_EVENT_VFORK_DONE .
531 .\"O (\fIaddr\fP is ignored.)
532 発生したばかりの ptrace イベントに関するメッセージを
533 .RI ( "unsigned long"
534 型で) 取得する。
535 取得したメッセージは親プロセスの \fIdata\fP の位置に格納される。
536 得られる内容は、
537 .B PTRACE_EVENT_EXIT
538 の場合は子プロセスの終了ステータスであり、
539 .BR PTRACE_EVENT_FORK ,
540 .BR PTRACE_EVENT_VFORK ,
541 .B PTRACE_EVENT_CLONE
542 の場合は新しいプロセスの PID である。
543 Linux 2.6.18 以降では、新しいプロセスの PID は
544 .B PTRACE_EVENT_VFORK_DONE
545 で入手できる。
546 (\fIaddr\fP は無視される。)
547 .TP
548 .B PTRACE_CONT
549 .\"O Restarts the stopped child process.
550 .\"O If \fIdata\fP is nonzero and not
551 .\"O .BR SIGSTOP ,
552 .\"O it is interpreted as a signal to be delivered to the child;
553 .\"O otherwise, no signal is delivered.
554 .\"O Thus, for example, the parent can control
555 .\"O whether a signal sent to the child is delivered or not.
556 .\"O (\fIaddr\fP is ignored.)
557 停止した子プロセスの実行を再開させる。
558 \fIdata\fP がゼロでなく、
559 .B SIGSTOP
560 でもなければ、
561 子プロセスに配送されるシグナルと解釈される。
562 ゼロや
563 .B SIGSTOP
564 の場合はシグナルは配送されない。
565 これを使うと、例えば、親プロセスは
566 子プロセスに送られたシグナルを実際に配送するかどうかを
567 制御することができる。(\fIaddr\fP は無視される。)
568 .TP
569 .BR PTRACE_SYSCALL ", " PTRACE_SINGLESTEP
570 .\"O Restarts the stopped child as for
571 .\"O .BR PTRACE_CONT ,
572 .\"O but arranges for
573 .\"O the child to be stopped at the next entry to or exit from a system call,
574 .\"O or after execution of a single instruction, respectively.
575 .\"O (The child will also, as usual, be stopped upon receipt of a signal.)
576 .\"O From the parent's perspective, the child will appear to have been
577 .\"O stopped by receipt of a
578 .\"O .BR SIGTRAP .
579 .\"O So, for
580 .\"O .BR PTRACE_SYSCALL ,
581 .\"O for example, the idea is to inspect
582 .\"O the arguments to the system call at the first stop,
583 .\"O then do another
584 .\"O .B PTRACE_SYSCALL
585 .\"O and inspect the return value of
586 .\"O the system call at the second stop.
587 .\"O The
588 .\"O .I data
589 .\"O argument is treated as for
590 .\"O .BR PTRACE_CONT .
591 .\"O (\fIaddr\fP is ignored.)
592 .B PTRACE_CONT
593 と同様に停止した子プロセスを再開する。ただし、
594 .B PTRACE_SYSCALL
595 の場合は子プロセスが
596 次にシステムコールに入るかシステムコールから抜けるかする時に、
597 .B PTRACE_SINGLESTEP
598 の場合は 1 命令 (instruction) 実行した後に停止させる
599 (通常どおり、子プロセスはシグナルを受け取った場合にも停止する)。
600 親プロセスから見ると、子プロセスは
601 .B SIGTRAP
602 を受信して停止したように見える。そのため、例えば
603 .B PTRACE_SYSCALL
604 を使うと、1回目の停止で引き数を調べて
605 .B PTRACE_SYSCALL
606 を実行し、 2回目の停止でシステムコールの返り値を調べる、
607 というようなことができる。
608 引き数
609 .I data
610
611 .B PTRACE_CONT
612 の場合と同じ様に解釈される。
613 (\fIaddr\fP は無視される。)
614 .TP
615 .\"O .BR PTRACE_SYSEMU ", " PTRACE_SYSEMU_SINGLESTEP " (since Linux 2.6.14)"
616 .BR PTRACE_SYSEMU ", " PTRACE_SYSEMU_SINGLESTEP " (Linux 2.6.14 以降)"
617 .\"O For
618 .\"O .BR PTRACE_SYSEMU ,
619 .\"O continue and stop on entry to the next syscall,
620 .\"O which will not be executed.
621 .\"O For
622 .\"O .BR PTRACE_SYSEMU_SINGLESTEP ,
623 .\"O do the same
624 .\"O but also singlestep if not a syscall.
625 .\"O This call is used by programs like
626 .\"O User Mode Linux that want to emulate all the child's syscalls.
627 .\"O The
628 .\"O .I data
629 .\"O argument is treated as for
630 .\"O .BR PTRACE_CONT .
631 .\"O (\fIaddr\fP is ignored;
632 .\"O not supported on all architectures.)
633 .B PTRACE_SYSEMU
634 は、実行を再開し、次のシステムコールに入る時に停止させる。
635 システムコールは実行されない。
636 .B PTRACE_SYSEMU_SINGLESTEP
637 も同様だが、システムコールでない場合には
638 1 命令 (singlestep) だけ実行した時点でも停止させる。
639 このコールは User Mode Linux のように子プロセスのシステムコールを全て
640 エミュレートしようとするプログラムで使用される。
641 引き数
642 .I data
643
644 .B PTRACE_CONT
645 の場合と同じ様に解釈される。
646 (\fIaddr\fP は無視される。
647 全てのアーキテクチャでサポートされているわけではない。)
648 .TP
649 .B PTRACE_KILL
650 .\"O Sends the child a
651 .\"O .B SIGKILL
652 .\"O to terminate it.
653 .\"O (\fIaddr\fP and \fIdata\fP are ignored.)
654 子プロセスに
655 .B SIGKILL
656 を送り終了させる。(\fIaddr\fP と \fIdata\fP は無視される。)
657 .TP
658 .B PTRACE_ATTACH
659 .\"O Attaches to the process specified in
660 .\"O .IR pid ,
661 .\"O making it a traced "child" of the calling process;
662 .\"O the behavior of the child is as if it had done a
663 .\"O .BR PTRACE_TRACEME .
664 .\"O The calling process actually becomes the parent of the child
665 .\"O process for most purposes (e.g., it will receive
666 .\"O notification of child events and appears in
667 .\"O .BR ps (1)
668 .\"O output as the child's parent), but a
669 .\"O .BR getppid (2)
670 .\"O by the child will still return the PID of the original parent.
671 .\"O The child is sent a
672 .\"O .BR SIGSTOP ,
673 .\"O but will not necessarily have stopped
674 .\"O by the completion of this call; use
675 .\"O .BR wait (2)
676 .\"O to wait for the child to stop.
677 .\"O (\fIaddr\fP and \fIdata\fP are ignored.)
678 .I pid
679 で指定されたプロセスに接続 (attach) し、それを呼び出し元のプロセスの
680 子プロセスとしてトレースできるようにする。子プロセスは
681 .B PTRACE_TRACEME
682 したかのように振舞う。呼び出し元のプロセスはそのほとんどの目的において、
683 その子プロセスの実際の親になる (例えば、子プロセスのイベントの
684 通知を受けとったり、
685 .BR ps (1)
686 で親として表示されたりする)。しかし、子プロセスで
687 .BR getppid (2)
688 を実行した場合には元の親プロセスの PID が返される。
689 子プロセスには
690 .B SIGSTOP
691 が送られるが、この呼び出しが完了するまでに
692 必ずしも停止するとは限らない。子プロセスの停止を待つには
693 .BR wait (2)
694 を使用すること。(\fIaddr\fP と \fIdata\fP は無視される。)
695 .TP
696 .B PTRACE_DETACH
697 .\"O Restarts the stopped child as for
698 .\"O .BR PTRACE_CONT ,
699 .\"O but first detaches
700 .\"O from the process, undoing the reparenting effect of
701 .\"O .BR PTRACE_ATTACH ,
702 .\"O and the effects of
703 .\"O .BR PTRACE_TRACEME .
704 .\"O Although perhaps not intended, under Linux a traced child can be
705 .\"O detached in this way regardless of which method was used to initiate
706 .\"O tracing.
707 .\"O (\fIaddr\fP is ignored.)
708 .B PTRACE_CONT
709 と同様に停止した子プロセスを再開する。ただし
710 まずそのプロセスからの分離 (detach) を行い、
711 .B PTRACE_ATTACH
712 での親の切り換えによる効果と
713 .B PTRACE_TRACEME
714 の効果を取り消す。意図したものではないだろうが、
715 Linux では、トレースされている子プロセスはどのような方法でトレースを
716 開始されたとしても、この方法で分離 (detach) することができる。
717 (\fIaddr\fP は無視される。)
718 .\"O .SH "RETURN VALUE"
719 .SH 返り値
720 .\"O On success,
721 .\"O .B PTRACE_PEEK*
722 .\"O requests return the requested data,
723 .\"O while other requests return zero.
724 .\"O On error, all requests return \-1, and
725 .\"O .I errno
726 .\"O is set appropriately.
727 .\"O Since the value returned by a successful
728 .\"O .B PTRACE_PEEK*
729 .\"O request may be \-1, the caller must check
730 .\"O .I errno
731 .\"O after such requests to determine whether or not an error occurred.
732 成功すると、
733 .B PTRACE_PEEK*
734 の場合は要求したデータを返し、
735 それ以外の場合は 0 を返す。
736 エラーの場合は \-1 を返し、
737 .I errno
738 が適切に設定される。
739 .B PTRACE_PEEK*
740 が成功して返す値も \-1 になることがあるため、
741 そのような要求の場合には、呼び出し元は
742 .I errno
743 を調べ、エラーか発生したのかどうかを判断しなければならない。
744 .\"O .SH ERRORS
745 .SH エラー
746 .TP
747 .B EBUSY
748 .\"O (i386 only) There was an error with allocating or freeing a debug
749 .\"O register.
750 (i386 のみ) デバッグレジスタの確保または解放でエラーが発生した。
751 .TP
752 .B EFAULT
753 .\"O There was an attempt to read from or write to an invalid area in
754 .\"O the parent's or child's memory,
755 .\"O probably because the area wasn't mapped or accessible.
756 .\"O Unfortunately, under Linux, different variations of this fault
757 .\"O will return
758 .\"O .B EIO
759 .\"O or
760 .\"O .B EFAULT
761 .\"O more or less arbitrarily.
762 親プロセスまたは子プロセスのメモリの不正な領域に読み書きしようとした。
763 おそらくその領域がマッピングされていないか、
764 その領域へのアクセスが許されていないかである。
765 不運なことに、Linux ではこのようなエラーの場合、多かれ少なかれ
766 恣意的に
767 .B EIO
768 を返したり
769 .B EFAULT
770 を返したりすることがある。
771 .TP
772 .B EINVAL
773 .\"O An attempt was made to set an invalid option.
774 不正なオプションを設定しようとした。
775 .TP
776 .B EIO
777 .\"O \fIrequest\fP is invalid, or an attempt was made to read from or
778 .\"O write to an invalid area in the parent's or child's memory,
779 .\"O or there was a word-alignment violation,
780 .\"O or an invalid signal was specified during a restart request.
781 \fIrequest\fP が不正である。
782 または、親プロセスまたは子プロセスのメモリの
783 不正な領域に読み書きしようとした。
784 または、ワード境界違反があった。
785 または、実行再開の要求で不正なシグナルを指定した。
786 .TP
787 .B EPERM
788 .\"O The specified process cannot be traced.
789 .\"O This could be because the
790 .\"O parent has insufficient privileges (the required capability is
791 .\"O .BR CAP_SYS_PTRACE );
792 .\"O unprivileged processes cannot trace processes that they
793 .\"O cannot send signals to or those running
794 .\"O set-user-ID/set-group-ID programs, for obvious reasons.
795 .\"O Alternatively, the process may already be being traced, or be
796 .\"O .BR init (8)
797 .\"O (PID 1).
798 指定したプロセスをトレースすることができない。これは親プロセスが
799 必要な権限 (必要なケーパビリティは
800 .BR CAP_SYS_PTRACE )
801 を持っていないことが原因の場合がある。
802 分かりやすい理由を挙げるなら、
803 非特権プロセスはシグナルを送ることができないプロセスをトレースできないし、
804 set-user-ID/set-group-ID プログラムを実行しているプロセスはトレースできない。
805 または、プロセスはすでにトレース中である、
806 または
807 .BR init (8)
808 プロセス (PID が 1) である。
809 .TP
810 .B ESRCH
811 .\"O The specified process does not exist, or is not currently being traced
812 .\"O by the caller, or is not stopped (for requests that require that).
813 指定したプロセスが存在しない。
814 または、指定したプロセスは呼び出したプロセスが
815 現在トレース中の子プロセスではない。
816 または、指定したプロセスが停止していない (停止していることが必要な要求の場合)。
817 .\"O .SH "CONFORMING TO"
818 .SH 準拠
819 SVr4, 4.3BSD.
820 .\"O .SH NOTES
821 .SH 注意
822 .\"O Although arguments to
823 .\"O .BR ptrace ()
824 .\"O are interpreted according to the prototype given,
825 .\"O glibc currently declares
826 .\"O .BR ptrace ()
827 .\"O as a variadic function with only the \fIrequest\fP argument fixed.
828 .\"O This means that unneeded trailing arguments may be omitted,
829 .\"O though doing so makes use of undocumented
830 .\"O .BR gcc (1)
831 .\"O behavior.
832 .BR ptrace ()
833 の引き数は上のようなプロトタイプに基づいて解釈されるが、
834 glibc では、現在のところ
835 .BR ptrace ()
836 は \fIrequest\fP 引き数だけが固定の可変長引き数関数として
837 宣言されている。
838 これは必要なければ残りの引き数は省略可能であることを意味するが、
839 それは
840 .BR gcc (1)
841 の明文化されていない動作を利用していることになる。
842 .LP
843 .\"O .BR init (8),
844 .\"O the process with pid 1, may not be traced.
845 .BR init (8)
846 すなわち PID が 1 のプロセスはトレースすることができない。
847 .LP
848 .\"O The layout of the contents of memory and the USER area are quite OS- and
849 .\"O architecture-specific.
850 メモリや USER 領域の内容や配置は OS ごと、アーキテクチャごとに
851 非常に依存する。
852 .\"O The offset supplied, and the data returned,
853 .\"O might not entirely match with the definition of
854 .\"O .IR "struct user" .
855 .\"O .\" See http://lkml.org/lkml/2008/5/8/375
856 オフセットが指定された場合、返されるデータは
857 .I "struct user"
858 の定義と完全に一致しないこともありえる。
859 .\" http://lkml.org/lkml/2008/5/8/375 参照。
860 .LP
861 .\"O The size of a "word" is determined by the OS variant
862 .\"O (e.g., for 32-bit Linux it is 32 bits, etc.).
863 「ワード (word) 」の大きさは OS によって決まる。
864 (例えば、32 ビットの Linux では 32 ビットである、など。)
865 .LP
866 .\"O Tracing causes a few subtle differences in the semantics of
867 .\"O traced processes.
868 .\"O For example, if a process is attached to with
869 .\"O .BR PTRACE_ATTACH ,
870 .\"O its original parent can no longer receive notification via
871 .\"O .BR wait (2)
872 .\"O when it stops, and there is no way for the new parent to
873 .\"O effectively simulate this notification.
874 トレースすることによってトレースされるプロセスの動作に些細な違いが
875 起こることがある。例えば、プロセスが
876 .B PTRACE_ATTACH
877 によって接続された場合には、そのプロセスが停止した時でも本来の親は
878 .BR wait (2)
879 を使って通知を受けることができず、新しい親が効率よく
880 この通知を真似る方法もない。
881 .LP
882 .\"O When the parent receives an event with
883 .\"O .B PTRACE_EVENT_*
884 .\"O set,
885 .\"O the child is not in the normal signal delivery path.
886 .\"O This means the parent cannot do
887 .\"O .BR ptrace (PTRACE_CONT)
888 .\"O with a signal or
889 .\"O .BR ptrace (PTRACE_KILL).
890 .\"O .BR kill (2)
891 .\"O with a
892 .\"O .B SIGKILL
893 .\"O signal can be used instead to kill the child process
894 .\"O after receiving one of these messages.
895 親プロセスが
896 .B PTRACE_EVENT_*
897 がセットされたイベントを受信した場合、
898 子プロセスは通常通りのシグナル配送が行われる状態にない。
899 つまり、親プロセスが、
900 シグナルにより
901 .BR ptrace (PTRACE_CONT)
902 を行ったり、
903 .BR ptrace (PTRACE_KILL)
904 を行ったりできないということである。
905 こららのメッセージの受信後は、子プロセスを終了 (kill) するのに、
906 シグナル
907 .B SIGKILL
908 を指定して
909 .BR kill (2)
910 を行う方法を代わりに使用できる。
911 .LP
912 .\"O This page documents the way the
913 .\"O .BR ptrace ()
914 .\"O call works currently in Linux.
915 .\"O Its behavior differs noticeably on other flavors of UNIX.
916 .\"O In any case, use of
917 .\"O .BR ptrace ()
918 .\"O is highly OS- and architecture-specific.
919 このマニュアルは現在の Linux における
920 .BR ptrace ()
921 コールの動作について記述している。他の UNIX では
922 その動作は著しく異なる。
923 いかなる場合も
924 .BR ptrace ()
925 を使うと OS やアーキテクチャに非常に依存したものになる。
926 .LP
927 .\"O The SunOS man page describes
928 .\"O .BR ptrace ()
929 .\"O as "unique and arcane", which it is.
930 .\"O The proc-based debugging interface
931 .\"O present in Solaris 2 implements a superset of
932 .\"O .BR ptrace ()
933 .\"O functionality in a more powerful and uniform way.
934 SunOS のマニュアル・ページには
935 .BR ptrace ()
936 は「独特で不可解」と記述されており、まさしくそうである。
937 Solaris 2 では proc ベースの
938 デバッグのインターフェースとして
939 .BR ptrace ()
940 の上位互換関数が実装され、より強力で一貫性のあるものとなっている。
941 .\"O .SH BUGS
942 .SH バグ
943 .\"O On hosts with 2.6 kernel headers,
944 .\"O .B PTRACE_SETOPTIONS
945 .\"O is declared
946 .\"O with a different value than the one for 2.4.
947 .\"O This leads to applications compiled with such
948 .\"O headers failing when run on 2.4 kernels.
949 .\"O This can be worked around by redefining
950 .\"O .B PTRACE_SETOPTIONS
951 .\"O to
952 .\"O .BR PTRACE_OLDSETOPTIONS ,
953 .\"O if that is defined.
954 カーネル 2.6 のヘッダがインストールされたホストでは、
955 .B PTRACE_SETOPTIONS
956 はカーネル 2.4 のヘッダとは異なる値で宣言される。
957 このため、カーネル 2.6 のヘッダでコンパイルされたアプリケーションは
958 カーネル 2.4 では正しく動作しない。
959 この問題は、
960 .B PTRACE_SETOPTIONS
961 が定義されていた際は、
962 .B PTRACE_SETOPTIONS
963
964 .B PTRACE_OLDSETOPTIONS
965 に定義し直すことで対処できる。
966 .\"O .SH "SEE ALSO"
967 .SH 関連項目
968 .BR gdb (1),
969 .BR strace (1),
970 .BR execve (2),
971 .BR fork (2),
972 .BR signal (2),
973 .BR wait (2),
974 .BR exec (3),
975 .BR capabilities (7)