diff options
Diffstat (limited to 'lib/libc/sys/ptrace.2')
-rw-r--r-- | lib/libc/sys/ptrace.2 | 152 |
1 files changed, 25 insertions, 127 deletions
diff --git a/lib/libc/sys/ptrace.2 b/lib/libc/sys/ptrace.2 index 69477e9..37eca05 100644 --- a/lib/libc/sys/ptrace.2 +++ b/lib/libc/sys/ptrace.2 @@ -1,9 +1,10 @@ +.\" $FreeBSD$ .\" $NetBSD: ptrace.2,v 1.2 1995/02/27 12:35:37 cgd Exp $ .\" .\" This file is in the public domain. -.Dd November 7, 1994 +.Dd January 20, 1996 .Dt PTRACE 2 -.Os NetBSD 1.0BETA +.Os FreeBSD 2 .Sh NAME .Nm ptrace .Nd process tracing and debugging @@ -74,7 +75,9 @@ and data, which is why there are two requests: conceptually, .Dv PT_READ_I reads from the instruction space and .Dv PT_READ_D -reads from the data space. In the current NetBSD implementation, these +reads from the data space. In the current +.Tn FreeBSD +implementation, these two requests are completely identical. The .Fa addr argument specifies the address (in the traced process' virtual address @@ -163,7 +166,7 @@ succeeds, the traced process is no longer traced and continues execution normally. .El .Pp -Additionally, machine-specific requests can exist. On the SPARC, these +Additionally, machine-specific requests can exist. On the i386, these are: .Bl -tag -width 12n .It Dv PT_GETREGS @@ -199,114 +202,25 @@ it loads the traced process' floating-point registers from the .Aq Pa machine/reg.h ) pointed to by .Fa addr . -.It Dv PT_SYSCALL -This request is like -.Dv PT_CONTINUE -except that the process will stop next time it executes any system -call. Information about the system call can be examined with -.Dv PT_READ_U -and potentially modified with -.Dv PT_WRITE_U -through the -.Li u_kproc.kp_proc.p_md -element of the user structure (see below). If the process is continued -with another -.Dv PT_SYSCALL -request, it will stop again on exit from the syscall, at which point -the return values can be examined and potentially changed. The -.Li u_kproc.kp_proc.p_md -element is of type -.Dq Li "struct mdproc" , -which should be declared by including -.Aq Pa sys/param.h , -.Aq Pa sys/user.h , -and -.Aq Pa machine/proc.h , -and contains the following fields (among others): -.Bl -item -compact -offset indent -.It -.Li syscall_num -.It -.Li syscall_nargs -.It -.Li syscall_args[8] -.It -.Li syscall_err -.It -.Li syscall_rv[2] -.El -When a process stops on entry to a syscall, -.Li syscall_num -holds the number of the syscall, -.Li syscall_nargs -holds the number of arguments it expects, and -.Li syscall_args -holds the arguments themselves. (Only the first -.Li syscall_nargs -elements of -.Li syscall_args -are guaranteed to be useful.) When a process stops on exit from a -syscall, -.Li syscall_num -is -.Eo \& -.Li -1 -.Ec , -.Li syscall_err -holds the error number -.Po -see -.Xr errno 2 -.Pc , -or 0 if no error occurred, and -.Li syscall_rv -holds the return values. (If the syscall returns only one value, only -.Li syscall_rv[0] -is useful.) The tracing process can modify any of these with -.Dv PT_WRITE_U ; -only some modifications are useful. -.Pp -On entry to a syscall, -.Li syscall_num -can be changed, and the syscall actually performed will correspond to -the new number (it is the responsibility of the tracing process to fill -in -.Li syscall_args -appropriately for the new call, but there is no need to modify -.Eo \& -.Li syscall_nargs -.Ec ). -If the new syscall number is 0, no syscall is actually performed; -instead, -.Li syscall_err -and -.Li syscall_rv -are passed back to the traced process directly (and therefore should be -filled in). If the syscall number is otherwise out of range, a dummy -syscall which simply produces an -.Er ENOSYS -error is effectively performed. -.Pp -On exit from a syscall, only -.Li syscall_err -and -.Li syscall_rv -can usefully be changed; they are set to the values returned by the -syscall and will be passed back to the traced process by the normal -syscall return mechanism. .El -.Sh ERRORS +.Sh RETURN VALUES Some requests can cause .Fn ptrace to return .Li -1 as a non-error value; to disambiguate, .Va errno -can be set to 0 before the call and checked afterwards. The possible -errors are: +can be set to 0 before the call and checked afterwards. +.Sh ERRORS +The +.Fn ptrace +function may fail if: .Bl -tag -width 4n .It Bq Er ESRCH +.Bl -bullet -compact +.It No process having the specified process ID exists. +.El .It Bq Er EINVAL .Bl -bullet -compact .It @@ -331,8 +245,6 @@ The signal number (in .Fa data ) to .Dv PT_CONTINUE -or -.Dv PT_SYSCALL was neither 0 nor a legal signal number. .It .Dv PT_GETREGS , @@ -369,27 +281,13 @@ on a process in violation of the requirements listed under .Dv PT_ATTACH above. .El -.Sh BUGS -On the SPARC, the PC is set to the provided PC value for -.Dv PT_CONTINUE -and similar calls, but the NPC is set willy-nilly to 4 greater than the -PC value. Using -.Dv PT_GETREGS -and -.Dv PT_SETREGS -to modify the PC, passing -.Li (caddr_t)1 -to -.Eo \& +.Sh SEE ALSO +.Xr execve 2 , +.Xr sigaction 2 , +.Xr wait 2 , +.Xr execv 3 +.Sh HISTORY +A .Fn ptrace -.Ec , -should be able to sidestep this. -.Pp -Single-stepping is not available. -.Pp -When using -.Dv PT_SYSCALL , -there is no easy way to tell whether the traced process stopped because -it made a syscall or because a signal was sent at a moment that it just -happened to have valid-looking garbage in its -.Dq Li "struct mdproc" . +function call appeared in +.At v7 . |