ptrace.2

来自「<B>Digital的Unix操作系统VAX 4.2源码</B>」· 2 代码 · 共 214 行

2
214
字号
.\" SCCSID: @(#)ptrace.2	8.1	9/11/90.TH ptrace 2 VAX.SH Nameptrace \- process trace.SH Syntax.nf.ft B#include <signal.h>.PP.ft Bptrace(request, pid, addr, data)int request, pid, *addr, data;.fi.SH Description.NXB "ptrace system call".NXB "process" "tracing"The.PN ptracesystem callprovides a means by which a parent processmay control the execution of a child process,and examine and change its core image.Its primary use is for the implementation of breakpoint debugging.There are four arguments whose interpretationdepends on a.I requestargument.Generally,.I pidis the process ID of the traced process,which must be a child (no more distant descendant)of the tracing process.A process being tracedbehaves normally until it encounters some signalwhether internally generatedlike \*(lqillegal instruction\*(rq or externallygenerated like \*(lqinterrupt\*(rq.See .MS sigvec 2for the list.Then the traced process enters a stopped stateand its parent is notified via .MS wait 2 .When the child is in the stopped state,its core image can be examined and modifiedusing.PN ptrace .If desired, another.PN ptracerequest can then cause the child either to terminateor to continue, possibly ignoring the signal..PPThe value of the.I requestargument determines the preciseaction of the call:.TP 40This request is the only one used by the child process;it declares that the process is to be traced by its parent.All the other arguments are ignored.Peculiar results will ensueif the parent does not expect to trace the child..TP 41,2Theword in the child process's address spaceat.I addris returned.If I and D space are separated (for example, historicallyon a pdp-11), request 1 indicates I space,2 D space.The.I addrmust be even.The child must be stopped.The input.I datais ignored..TP 43The wordof the system's per-process data area corresponding to.I addris returned.The.I addrmust be even and less than 512.This space contains the registers and other information aboutthe process;its layout corresponds to the.I userstructure in the system..TP 44,5Thegiven.I datais written at the word in the process's address space corresponding to.I addr,which must be even.No useful value is returned.If I and D space are separated, request 4 indicates I space, 5 D space.Attempts to write in pure procedurefail if another process is executing the same file..TP 46The process's system data is written,as it is read with request 3.Only a few locations can be written in this way:the general registers,the floating point status and registers,and certain bits of the processor status word..TP 47The.I dataargument is taken as a signal numberand the child's execution continuesat location.I addras if it had incurred that signal.Normally the signal number will beeither 0 to indicate that the signal that caused the stopshould be ignored,or that value fetched out of theprocess's image indicating which signal causedthe stop.If.I addris (int *)1 then execution continues from where it stopped..TP 48The traced process terminates..TP 49Execution continues as in request 7;however, as soon as possibleafter execution of at least one instruction,execution stops again.The signal number from the stop isSIGTRAP.(On the VAX-11 the T-bit is used and just one instructionis executed.)This is part of the mechanism for implementing breakpoints..PPAs indicated,these calls(except for request 0)can be used only when the subject process has stopped.The.PN waitcall is used to determinewhen a process stops;in such a case the \*(lqtermination\*(rq statusreturned by.PN waithas the value 0177 to indicate stoppage ratherthan genuine termination..PPTo forestall possible fraud,.PN ptraceinhibits the set-user-id and set-group-id facilitieson subsequent .MS execve 2calls.If a traced process calls.PN execve ,it will stop before executing the first instruction of the new imageshowing signal SIGTRAP..PPOn a VAX, \*(lqword\*(rq also means a 32-bit integer,but the \*(lqeven\*(rqrestriction does not apply..SH Environment.NXR "ptrace system call" "System V and"When your program is compiled using the System V environment,requests 7 and 9 return the value of the data argumenton success, errno is set to ESRCH if the piddoes not exist, \fBEIO\fP if the address is out of bounds..SH Return ValuesA 0 value is returned if the call succeeds.  If the call failsthen a \-1 is returned and the global variable \fIerrno\fP isset to indicate the error..SH Restrictions.NXR "ptrace system call" "restricted"In ULTRIX, the .PN ptracesystem call will only succeed ifthe user owns the binary being traced or if the user is root. .SH Diagnostics.NXR "ptrace system call" "diagnostics".TP 15[EIO]The request code is invalid..TP 15[ESRCH]The specified process does not exist..TP 15[EIO]The given signal number is invalid..TP[EIO]The specified address is out of bounds..TP 15[EPERM]The specified process cannot be traced..SH See Alsoadb(1), sigvec(2), wait(2).NXE "process" "tracing".NXE "ptrace system call"

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?