⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 ptrace.2

📁 Unix操作系统minix 2.0源码
💻 2
字号:
.\" Copyright (c) 1980 Regents of the University of California..\" All rights reserved.  The Berkeley software License Agreement.\" specifies the terms and conditions for redistribution..\".\"	@(#)ptrace.2	6.4 (Berkeley) 5/23/86.\".TH PTRACE 2 "May 23, 1986".UC 4.SH NAMEptrace \- process trace.SH SYNOPSIS.nf.ft B#include <sys/types.h>#include <sys/signal.h>#include <sys/ptrace.h>int ptrace(int \fIrequest\fP, pid_t \fIpid\fP, long \fIaddr\fP, long \fIdata\fP).ft R.fi.SH DESCRIPTION.ft BNote: This manual page has no relation to Minix.  Someone who knows ptrace()has to check, or rewrite, this page.  (kjb).ft R.PP.B Ptraceprovides 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.BR sigaction (2)for the list.Then the traced process enters a stopped stateand its parent is notified via.BR  wait (2).When the child is in the stopped state,its core image can be examined and modifiedusing.BR ptrace .If desired, another.B 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 4PT_TRACE_METhis 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 4PT_READ_I, PT_READ_DTheword in the child process's address spaceat.I addris returned.If I and D space are separated (e.g. historicallyon a pdp-11), request PT_READ_I indicates I space,PT_READ_D D space..I Addrmust be even on some machines.The child must be stopped.The input.I datais ignored..TP 4PT_READ_UThe wordof the system's per-process data area corresponding to.I addris returned..I Addrmust be even on some machines 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 4PT_WRITE_I, PT_WRITE_DThegiven.I datais written at the word in the process's address space corresponding to.I addr,which must be even on some machines.No useful value is returned.If I and D space are separated, request PT_WRITE_I indicates I space, PT_WRITE_D D space.Attempts to write in pure procedurefail if another process is executing the same file..TP 4PT_WRITE_UThe process's system data is written,as it is read with request PT_READ_U.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 4PT_CONTINUEThe.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 4PT_KILLThe traced process terminates..TP 4PT_STEPExecution continues as in request PT_CONTINUE;however, as soon as possible after 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 PT_TRACE_ME)can be used only when the subject process has stopped.The.B waitcall is used to determinewhen a process stops;in such a case the \*(lqtermination\*(rq statusreturned by.B waithas the value 0177 to indicate stoppage ratherthan genuine termination..PPTo forestall possible fraud,.B ptraceinhibits the set-user-id and set-group-id facilitieson subsequent.BR  execve (2)calls.If a traced process calls.BR execve ,it will stop before executing the first instruction of the new imageshowing signal SIGTRAP..PPOn a VAX-11, \*(lqword\*(rq also means a 32-bit integer,but the \*(lqeven\*(rqrestriction does not apply..SH "RETURN VALUEA 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 "ERRORS.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 15[EIO]The specified address is out of bounds..TP 15[EPERM]The specified process cannot be traced..SH "SEE ALSO".BR wait (2),.BR sigaction (2),.BR mdb (1)..SH BUGS.B Ptraceis unique and arcane; it should be replaced with a special file thatcan be opened and read and written.  The control functions could thenbe implemented with.BR ioctl (2)calls on this file.  This would be simpler to understand and have muchhigher performance..PPThe request PT_TRACE_ME call should be able to specifysignals that are to be treated normally and not cause a stop.In this way, for example,programs with simulated floating point (whichuse \*(lqillegal instruction\*(rq signals at a very high rate)could be efficiently debugged..PPThe error indication, \-1, is a legitimate function value;.BR errno ,(see.BR intro (2)),can be used to disambiguate..PPIt should be possible to stop a process on occurrence of a systemcall;in this way a completely controlled environment couldbe provided.

⌨️ 快捷键说明

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