Back to index

glibc  2.9
ptrace.c
Go to the documentation of this file.
00001 /* Copyright (C) 1991, 92, 93, 95, 96, 97 Free Software Foundation, Inc.
00002    This file is part of the GNU C Library.
00003 
00004    The GNU C Library is free software; you can redistribute it and/or
00005    modify it under the terms of the GNU Lesser General Public
00006    License as published by the Free Software Foundation; either
00007    version 2.1 of the License, or (at your option) any later version.
00008 
00009    The GNU C Library is distributed in the hope that it will be useful,
00010    but WITHOUT ANY WARRANTY; without even the implied warranty of
00011    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00012    Lesser General Public License for more details.
00013 
00014    You should have received a copy of the GNU Lesser General Public
00015    License along with the GNU C Library; if not, write to the Free
00016    Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
00017    02111-1307 USA.  */
00018 
00019 #include <errno.h>
00020 #include <sys/ptrace.h>
00021 #include <sys/types.h>
00022 #include <stdarg.h>
00023 
00024 /* Perform process tracing functions.  REQUEST is one of the values
00025    in <sys/ptrace.h>, and determines the action to be taken.
00026    For all requests except PTRACE_TRACEME, PID specifies the process to be
00027    traced.
00028 
00029    PID and the other arguments described above for the various requests should
00030    appear (those that are used for the particular request) as:
00031      pid_t PID, void *ADDR, int DATA, void *ADDR2
00032    after PID.  */
00033 int
00034 ptrace (request)
00035      enum __ptrace_request request;
00036 {
00037   pid_t pid;
00038   void *addr;
00039   void *addr2;
00040   int data;
00041   va_list ap;
00042 
00043   switch (request)
00044     {
00045     case PTRACE_TRACEME:
00046     case PTRACE_CONT:
00047     case PTRACE_KILL:
00048     case PTRACE_SINGLESTEP:
00049     case PTRACE_ATTACH:
00050     case PTRACE_DETACH:
00051       break;
00052 
00053     case PTRACE_PEEKTEXT:
00054     case PTRACE_PEEKDATA:
00055     case PTRACE_PEEKUSER:
00056     case PTRACE_GETREGS:
00057     case PTRACE_SETREGS:
00058 #ifdef PTRACE_GETFPREGS
00059     case PTRACE_GETFPGEGS:
00060 #endif
00061     case PTRACE_SETFPREGS:
00062     case PTRACE_GETFPAREGS:
00063     case PTRACE_SETFPAREGS:
00064       va_start(ap, request);
00065       pid = va_arg(ap, pid_t);
00066       addr = va_arg(ap, void *);
00067       va_end(ap);
00068       break;
00069 
00070     case PTRACE_POKETEXT:
00071     case PTRACE_POKEDATA:
00072     case PTRACE_POKEUSER:
00073       va_start(ap, request);
00074       pid = va_arg(ap, pid_t);
00075       addr = va_arg(ap, void *);
00076       data = va_arg(ap, int);
00077       va_end(ap);
00078       break;
00079 
00080     case PTRACE_READDATA:
00081     case PTRACE_WRITEDATA:
00082     case PTRACE_READTEXT:
00083     case PTRACE_WRITETEXT:
00084       va_start(ap, request);
00085       pid = va_arg(ap, pid_t);
00086       addr = va_arg(ap, void *);
00087       data = va_arg(ap, int);
00088       addr2 = va_arg(ap, void *);
00089       va_end(ap);
00090       break;
00091 
00092     default:
00093       __set_errno (EINVAL);
00094       return -1;
00095     }
00096 
00097   __set_errno (ENOSYS);
00098   return -1;
00099 }
00100 
00101 
00102 stub_warning (ptrace)
00103 #include <stub-tag.h>