Wichert Akkerman | 76baf7c | 1999-02-19 00:21:36 +0000 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (c) 1991, 1992 Paul Kranenburg <pk@cs.few.eur.nl> |
| 3 | * Copyright (c) 1993 Branko Lankester <branko@hacktic.nl> |
| 4 | * Copyright (c) 1993, 1994, 1995, 1996 Rick Sladkey <jrs@world.std.com> |
| 5 | * All rights reserved. |
| 6 | * |
| 7 | * Redistribution and use in source and binary forms, with or without |
| 8 | * modification, are permitted provided that the following conditions |
| 9 | * are met: |
| 10 | * 1. Redistributions of source code must retain the above copyright |
| 11 | * notice, this list of conditions and the following disclaimer. |
| 12 | * 2. Redistributions in binary form must reproduce the above copyright |
| 13 | * notice, this list of conditions and the following disclaimer in the |
| 14 | * documentation and/or other materials provided with the distribution. |
| 15 | * 3. The name of the author may not be used to endorse or promote products |
| 16 | * derived from this software without specific prior written permission. |
| 17 | * |
| 18 | * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR |
| 19 | * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES |
| 20 | * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. |
| 21 | * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, |
| 22 | * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT |
| 23 | * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, |
| 24 | * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY |
| 25 | * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT |
| 26 | * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF |
| 27 | * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
| 28 | * |
| 29 | * $Id$ |
| 30 | */ |
| 31 | |
Wichert Akkerman | b859bea | 1999-04-18 22:50:50 +0000 | [diff] [blame] | 32 | #ifdef linux |
| 33 | #include <features.h> |
| 34 | #endif |
| 35 | |
Roland McGrath | e6d3a29 | 2003-01-14 09:46:18 +0000 | [diff] [blame] | 36 | #ifdef _LARGEFILE64_SOURCE |
| 37 | /* This is the macro everything checks before using foo64 names. */ |
| 38 | # ifndef _LFS64_LARGEFILE |
| 39 | # define _LFS64_LARGEFILE 1 |
| 40 | # endif |
| 41 | #endif |
| 42 | |
Wichert Akkerman | 76baf7c | 1999-02-19 00:21:36 +0000 | [diff] [blame] | 43 | #ifdef HAVE_CONFIG_H |
| 44 | #include "config.h" |
| 45 | #endif |
| 46 | |
| 47 | /* configuration section */ |
| 48 | #ifndef MAX_QUALS |
Roland McGrath | 63d0146 | 2002-12-30 00:25:36 +0000 | [diff] [blame] | 49 | #if defined(LINUX) && defined(MIPS) |
| 50 | #define MAX_QUALS 5000 /* maximum number of syscalls, signals, etc. */ |
Wichert Akkerman | fd89ced | 2000-04-13 17:06:09 +0000 | [diff] [blame] | 51 | #else |
Wichert Akkerman | 8b1b40c | 2000-02-03 21:58:30 +0000 | [diff] [blame] | 52 | #define MAX_QUALS 2048 /* maximum number of syscalls, signals, etc. */ |
Wichert Akkerman | 76baf7c | 1999-02-19 00:21:36 +0000 | [diff] [blame] | 53 | #endif |
Wichert Akkerman | 5ae21ea | 2000-05-01 01:53:59 +0000 | [diff] [blame] | 54 | #endif |
Wichert Akkerman | 76baf7c | 1999-02-19 00:21:36 +0000 | [diff] [blame] | 55 | #ifndef DEFAULT_STRLEN |
| 56 | #define DEFAULT_STRLEN 32 /* default maximum # of bytes printed in |
| 57 | `printstr', change with `-s' switch */ |
| 58 | #endif |
| 59 | #ifndef DEFAULT_ACOLUMN |
| 60 | #define DEFAULT_ACOLUMN 40 /* default alignment column for results */ |
| 61 | #endif |
| 62 | #ifndef MAX_ARGS |
| 63 | #define MAX_ARGS 32 /* maximum number of args to a syscall */ |
| 64 | #endif |
| 65 | #ifndef DEFAULT_SORTBY |
| 66 | #define DEFAULT_SORTBY "time" /* default sorting method for call profiling */ |
| 67 | #endif |
| 68 | |
| 69 | #include <sys/types.h> |
| 70 | #include <unistd.h> |
| 71 | #include <stdlib.h> |
| 72 | #include <stdio.h> |
| 73 | #include <ctype.h> |
| 74 | #include <string.h> |
Wichert Akkerman | 8c7122c | 2001-02-16 19:59:55 +0000 | [diff] [blame] | 75 | #include <time.h> |
Wichert Akkerman | 76baf7c | 1999-02-19 00:21:36 +0000 | [diff] [blame] | 76 | #include <sys/time.h> |
| 77 | #include <errno.h> |
| 78 | |
| 79 | #ifdef STDC_HEADERS |
| 80 | #include <stddef.h> |
| 81 | #endif /* STDC_HEADERS */ |
| 82 | |
John Hughes | 5826589 | 2001-10-18 15:13:53 +0000 | [diff] [blame] | 83 | #ifdef HAVE_SIGINFO_T |
| 84 | #include <signal.h> |
| 85 | #endif |
| 86 | |
Wichert Akkerman | f5eeabb | 1999-11-18 17:09:47 +0000 | [diff] [blame] | 87 | #if defined(LINUX) |
Roland McGrath | 6d1a65c | 2004-07-12 07:44:08 +0000 | [diff] [blame] | 88 | # if defined(SPARC) || defined(SPARC64) |
Wichert Akkerman | f5eeabb | 1999-11-18 17:09:47 +0000 | [diff] [blame] | 89 | # define LINUXSPARC |
| 90 | # endif |
| 91 | # if defined(ALPHA) |
| 92 | # define LINUX_64BIT |
| 93 | # endif |
Michal Ludvig | 0e03550 | 2002-09-23 15:41:01 +0000 | [diff] [blame] | 94 | # if defined(X86_64) |
| 95 | # define LINUX_X86_64 |
| 96 | # endif |
Roland McGrath | ee9d435 | 2002-12-18 04:16:10 +0000 | [diff] [blame] | 97 | #endif |
Wichert Akkerman | 76baf7c | 1999-02-19 00:21:36 +0000 | [diff] [blame] | 98 | |
Wichert Akkerman | bf79f2e | 2000-09-01 21:03:06 +0000 | [diff] [blame] | 99 | #if defined(SVR4) || defined(FREEBSD) |
| 100 | #define USE_PROCFS |
| 101 | #else |
| 102 | #undef USE_PROCFS |
| 103 | #endif |
| 104 | |
| 105 | #ifdef FREEBSD |
| 106 | #ifndef I386 |
| 107 | #error "FreeBSD support is only for i386 arch right now." |
| 108 | #endif |
| 109 | #include <machine/psl.h> |
| 110 | #include <machine/reg.h> |
| 111 | #include <sys/syscall.h> |
| 112 | #endif |
| 113 | |
| 114 | #ifdef USE_PROCFS |
Wichert Akkerman | 76baf7c | 1999-02-19 00:21:36 +0000 | [diff] [blame] | 115 | #include <sys/procfs.h> |
Wichert Akkerman | ea78f0f | 1999-11-29 15:34:02 +0000 | [diff] [blame] | 116 | #ifdef HAVE_MP_PROCFS |
Wichert Akkerman | 9ce1a63 | 1999-08-29 23:15:07 +0000 | [diff] [blame] | 117 | #include <sys/uio.h> |
| 118 | #endif |
Wichert Akkerman | bf79f2e | 2000-09-01 21:03:06 +0000 | [diff] [blame] | 119 | #ifdef FREEBSD |
| 120 | #include <sys/pioctl.h> |
| 121 | #endif /* FREEBSD */ |
| 122 | #else /* !USE_PROCFS */ |
Michal Ludvig | 0e03550 | 2002-09-23 15:41:01 +0000 | [diff] [blame] | 123 | #if (defined(LINUXSPARC) || defined (LINUX_X86_64)) && defined(__GLIBC__) |
Wichert Akkerman | 76baf7c | 1999-02-19 00:21:36 +0000 | [diff] [blame] | 124 | #include <sys/ptrace.h> |
| 125 | #else |
| 126 | /* Work around awkward prototype in ptrace.h. */ |
| 127 | #define ptrace xptrace |
| 128 | #include <sys/ptrace.h> |
| 129 | #undef ptrace |
| 130 | #ifdef POWERPC |
| 131 | #define __KERNEL__ |
| 132 | #include <asm/ptrace.h> |
| 133 | #undef __KERNEL__ |
Wichert Akkerman | 76baf7c | 1999-02-19 00:21:36 +0000 | [diff] [blame] | 134 | #endif |
| 135 | #ifdef __STDC__ |
| 136 | #ifdef LINUX |
| 137 | extern long ptrace(int, int, char *, long); |
| 138 | #else /* !LINUX */ |
| 139 | extern int ptrace(int, int, char *, int, ...); |
| 140 | #endif /* !LINUX */ |
| 141 | #else /* !__STDC__ */ |
| 142 | extern int ptrace(); |
| 143 | #endif /* !__STDC__ */ |
| 144 | #endif /* !LINUXSPARC */ |
| 145 | #endif /* !SVR4 */ |
| 146 | |
| 147 | #ifdef LINUX |
Wichert Akkerman | b859bea | 1999-04-18 22:50:50 +0000 | [diff] [blame] | 148 | #if !defined(__GLIBC__) |
Wichert Akkerman | 76baf7c | 1999-02-19 00:21:36 +0000 | [diff] [blame] | 149 | #define PTRACE_PEEKUSER PTRACE_PEEKUSR |
| 150 | #define PTRACE_POKEUSER PTRACE_POKEUSR |
| 151 | #endif |
| 152 | #ifdef ALPHA |
Wichert Akkerman | f90da01 | 1999-10-31 21:15:38 +0000 | [diff] [blame] | 153 | # define REG_R0 0 |
| 154 | # define REG_A0 16 |
| 155 | # define REG_A3 19 |
| 156 | # define REG_FP 30 |
| 157 | # define REG_PC 64 |
Wichert Akkerman | 76baf7c | 1999-02-19 00:21:36 +0000 | [diff] [blame] | 158 | #endif /* ALPHA */ |
Wichert Akkerman | f90da01 | 1999-10-31 21:15:38 +0000 | [diff] [blame] | 159 | #ifdef MIPS |
| 160 | # define REG_V0 2 |
| 161 | # define REG_A0 4 |
| 162 | # define REG_A3 7 |
| 163 | # define REG_SP 29 |
| 164 | # define REG_EPC 64 |
| 165 | #endif /* MIPS */ |
Wichert Akkerman | c1652e2 | 2001-03-27 12:17:16 +0000 | [diff] [blame] | 166 | #ifdef HPPA |
| 167 | # define PT_GR20 (20*4) |
| 168 | # define PT_GR26 (26*4) |
| 169 | # define PT_GR28 (28*4) |
| 170 | # define PT_IAOQ0 (106*4) |
| 171 | # define PT_IAOQ1 (107*4) |
| 172 | #endif /* HPPA */ |
Roland McGrath | f5a4777 | 2003-06-26 22:40:42 +0000 | [diff] [blame] | 173 | #ifdef SH64 |
| 174 | /* SH64 Linux - this code assumes the following kernel API for system calls: |
Roland McGrath | e1e584b | 2003-06-02 19:18:58 +0000 | [diff] [blame] | 175 | PC Offset 0 |
| 176 | System Call Offset 16 (actually, (syscall no.) | (0x1n << 16), |
| 177 | where n = no. of parameters. |
| 178 | Other regs Offset 24+ |
| 179 | |
| 180 | On entry: R2-7 = parameters 1-6 (as many as necessary) |
| 181 | On return: R9 = result. */ |
| 182 | |
| 183 | /* Offset for peeks of registers */ |
| 184 | # define REG_OFFSET (24) |
| 185 | # define REG_GENERAL(x) (8*(x)+REG_OFFSET) |
| 186 | # define REG_PC (0*8) |
| 187 | # define REG_SYSCALL (2*8) |
Roland McGrath | f5a4777 | 2003-06-26 22:40:42 +0000 | [diff] [blame] | 188 | #endif /* SH64 */ |
Wichert Akkerman | 76baf7c | 1999-02-19 00:21:36 +0000 | [diff] [blame] | 189 | #endif /* LINUX */ |
| 190 | |
| 191 | #define SUPPORTED_PERSONALITIES 1 |
| 192 | #define DEFAULT_PERSONALITY 0 |
| 193 | |
| 194 | #ifdef LINUXSPARC |
| 195 | #include <linux/a.out.h> |
| 196 | #include <asm/psr.h> |
| 197 | #undef SUPPORTED_PERSONALITIES |
Roland McGrath | 6d1a65c | 2004-07-12 07:44:08 +0000 | [diff] [blame] | 198 | #if defined(SPARC64) |
| 199 | #define SUPPORTED_PERSONALITIES 3 |
| 200 | #else |
Wichert Akkerman | b859bea | 1999-04-18 22:50:50 +0000 | [diff] [blame] | 201 | #define SUPPORTED_PERSONALITIES 2 |
Roland McGrath | 6d1a65c | 2004-07-12 07:44:08 +0000 | [diff] [blame] | 202 | #endif /* SPARC64 */ |
Wichert Akkerman | 76baf7c | 1999-02-19 00:21:36 +0000 | [diff] [blame] | 203 | #endif /* LINUXSPARC */ |
| 204 | |
Michal Ludvig | 0e03550 | 2002-09-23 15:41:01 +0000 | [diff] [blame] | 205 | #ifdef X86_64 |
| 206 | #undef SUPPORTED_PERSONALITIES |
| 207 | #define SUPPORTED_PERSONALITIES 2 |
Roland McGrath | ee9d435 | 2002-12-18 04:16:10 +0000 | [diff] [blame] | 208 | #endif |
| 209 | |
Wichert Akkerman | 9ce1a63 | 1999-08-29 23:15:07 +0000 | [diff] [blame] | 210 | #ifdef SVR4 |
Wichert Akkerman | ea78f0f | 1999-11-29 15:34:02 +0000 | [diff] [blame] | 211 | #ifdef HAVE_MP_PROCFS |
Wichert Akkerman | 9ce1a63 | 1999-08-29 23:15:07 +0000 | [diff] [blame] | 212 | extern int mp_ioctl (int f, int c, void *a, int s); |
| 213 | #define IOCTL(f,c,a) mp_ioctl (f, c, a, sizeof *a) |
| 214 | #define IOCTL_STATUS(t) \ |
| 215 | pread (t->pfd_stat, &t->status, sizeof t->status, 0) |
| 216 | #define IOCTL_WSTOP(t) \ |
Wichert Akkerman | 16a03d2 | 2000-08-10 02:14:04 +0000 | [diff] [blame] | 217 | (IOCTL (t->pfd, PCWSTOP, (char *)NULL) < 0 ? -1 : \ |
Wichert Akkerman | 9ce1a63 | 1999-08-29 23:15:07 +0000 | [diff] [blame] | 218 | IOCTL_STATUS (t)) |
| 219 | #define PR_WHY pr_lwp.pr_why |
| 220 | #define PR_WHAT pr_lwp.pr_what |
| 221 | #define PR_REG pr_lwp.pr_context.uc_mcontext.gregs |
| 222 | #define PR_FLAGS pr_lwp.pr_flags |
John Hughes | 2529971 | 2001-03-06 10:10:06 +0000 | [diff] [blame] | 223 | #define PR_SYSCALL pr_lwp.pr_syscall |
John Hughes | 5826589 | 2001-10-18 15:13:53 +0000 | [diff] [blame] | 224 | #define PR_INFO pr_lwp.pr_info |
Wichert Akkerman | 9ce1a63 | 1999-08-29 23:15:07 +0000 | [diff] [blame] | 225 | #define PIOCSTIP PCSTOP |
| 226 | #define PIOCSET PCSET |
| 227 | #define PIOCRESET PCRESET |
| 228 | #define PIOCSTRACE PCSTRACE |
| 229 | #define PIOCSFAULT PCSFAULT |
| 230 | #define PIOCWSTOP PCWSTOP |
| 231 | #define PIOCSTOP PCSTOP |
| 232 | #define PIOCSENTRY PCSENTRY |
| 233 | #define PIOCSEXIT PCSEXIT |
| 234 | #define PIOCRUN PCRUN |
| 235 | #else |
| 236 | #define IOCTL ioctl |
| 237 | #define IOCTL_STATUS(t) ioctl (t->pfd, PIOCSTATUS, &t->status) |
Roland McGrath | ee9d435 | 2002-12-18 04:16:10 +0000 | [diff] [blame] | 238 | #define IOCTL_WSTOP(t) ioctl (t->pfd, PIOCWSTOP, &t->status) |
Wichert Akkerman | 9ce1a63 | 1999-08-29 23:15:07 +0000 | [diff] [blame] | 239 | #define PR_WHY pr_why |
| 240 | #define PR_WHAT pr_what |
| 241 | #define PR_REG pr_reg |
| 242 | #define PR_FLAGS pr_flags |
John Hughes | 2529971 | 2001-03-06 10:10:06 +0000 | [diff] [blame] | 243 | #define PR_SYSCALL pr_syscall |
John Hughes | 5826589 | 2001-10-18 15:13:53 +0000 | [diff] [blame] | 244 | #define PR_INFO pr_info |
Wichert Akkerman | 9ce1a63 | 1999-08-29 23:15:07 +0000 | [diff] [blame] | 245 | #endif |
| 246 | #endif |
Wichert Akkerman | bf79f2e | 2000-09-01 21:03:06 +0000 | [diff] [blame] | 247 | #ifdef FREEBSD |
| 248 | #define IOCTL ioctl |
| 249 | #define IOCTL_STATUS(t) ioctl (t->pfd, PIOCSTATUS, &t->status) |
| 250 | #define IOCTL_WSTOP(t) ioctl (t->pfd, PIOCWAIT, &t->status) |
| 251 | #define PIOCRUN PIOCCONT |
| 252 | #define PIOCWSTOP PIOCWAIT |
| 253 | #define PR_WHY why |
| 254 | #define PR_WHAT val |
Wichert Akkerman | 2e4ffe5 | 2000-09-03 23:57:48 +0000 | [diff] [blame] | 255 | #define PR_FLAGS state |
Wichert Akkerman | bf79f2e | 2000-09-01 21:03:06 +0000 | [diff] [blame] | 256 | /* from /usr/src/sys/miscfs/procfs/procfs_vnops.c, |
| 257 | status.state = 0 for running, 1 for stopped */ |
Wichert Akkerman | 2e4ffe5 | 2000-09-03 23:57:48 +0000 | [diff] [blame] | 258 | #define PR_ASLEEP 1 |
Wichert Akkerman | bf79f2e | 2000-09-01 21:03:06 +0000 | [diff] [blame] | 259 | #define PR_SYSENTRY S_SCE |
| 260 | #define PR_SYSEXIT S_SCX |
| 261 | #define PR_SIGNALLED S_SIG |
| 262 | #define PR_FAULTED S_CORE |
| 263 | #endif |
Wichert Akkerman | 9ce1a63 | 1999-08-29 23:15:07 +0000 | [diff] [blame] | 264 | |
Wichert Akkerman | 76baf7c | 1999-02-19 00:21:36 +0000 | [diff] [blame] | 265 | /* Trace Control Block */ |
| 266 | struct tcb { |
| 267 | short flags; /* See below for TCB_ values */ |
| 268 | int pid; /* Process Id of this entry */ |
| 269 | long scno; /* System call number */ |
| 270 | int u_nargs; /* System call arguments */ |
| 271 | long u_arg[MAX_ARGS]; /* System call arguments */ |
| 272 | int u_error; /* Error code */ |
| 273 | long u_rval; /* (first) return value */ |
Wichert Akkerman | 16a03d2 | 2000-08-10 02:14:04 +0000 | [diff] [blame] | 274 | #ifdef HAVE_LONG_LONG |
| 275 | long long u_lrval; /* long long return value */ |
| 276 | #endif |
Wichert Akkerman | 76baf7c | 1999-02-19 00:21:36 +0000 | [diff] [blame] | 277 | FILE *outf; /* Output file for this process */ |
Wichert Akkerman | 43a7482 | 2000-06-27 17:33:32 +0000 | [diff] [blame] | 278 | const char *auxstr; /* Auxiliary info from syscall (see RVAL_STR) */ |
Wichert Akkerman | 76baf7c | 1999-02-19 00:21:36 +0000 | [diff] [blame] | 279 | struct timeval stime; /* System time usage as of last process wait */ |
| 280 | struct timeval dtime; /* Delta for system time usage */ |
| 281 | struct timeval etime; /* Syscall entry time */ |
| 282 | /* Support for tracing forked processes */ |
| 283 | struct tcb *parent; /* Parent of this process */ |
| 284 | int nchildren; /* # of traced children */ |
| 285 | int waitpid; /* pid(s) this process is waiting for */ |
Roland McGrath | 0962345 | 2003-05-23 02:27:13 +0000 | [diff] [blame] | 286 | int nzombies; /* # of formerly traced children now dead */ |
Roland McGrath | 923f750 | 2003-01-09 06:53:27 +0000 | [diff] [blame] | 287 | #ifdef LINUX |
| 288 | int nclone_threads; /* # of nchildren with CLONE_THREAD */ |
| 289 | int nclone_detached; /* # of nchildren with CLONE_DETACHED */ |
| 290 | int nclone_waiting; /* clone threads in wait4 (TCB_SUSPENDED) */ |
| 291 | #endif |
Wichert Akkerman | 76baf7c | 1999-02-19 00:21:36 +0000 | [diff] [blame] | 292 | /* (1st arg of wait4()) */ |
| 293 | long baddr; /* `Breakpoint' address */ |
| 294 | long inst[2]; /* Instructions on above */ |
| 295 | int pfd; /* proc file descriptor */ |
| 296 | #ifdef SVR4 |
Wichert Akkerman | ea78f0f | 1999-11-29 15:34:02 +0000 | [diff] [blame] | 297 | #ifdef HAVE_MP_PROCFS |
Wichert Akkerman | 9ce1a63 | 1999-08-29 23:15:07 +0000 | [diff] [blame] | 298 | int pfd_stat; |
| 299 | int pfd_as; |
| 300 | pstatus_t status; |
| 301 | #else |
Wichert Akkerman | 76baf7c | 1999-02-19 00:21:36 +0000 | [diff] [blame] | 302 | prstatus_t status; /* procfs status structure */ |
| 303 | #endif |
Wichert Akkerman | 9ce1a63 | 1999-08-29 23:15:07 +0000 | [diff] [blame] | 304 | #endif |
Wichert Akkerman | bf79f2e | 2000-09-01 21:03:06 +0000 | [diff] [blame] | 305 | #ifdef FREEBSD |
| 306 | struct procfs_status status; |
| 307 | int pfd_reg; |
| 308 | int pfd_status; |
| 309 | #endif |
Wichert Akkerman | 76baf7c | 1999-02-19 00:21:36 +0000 | [diff] [blame] | 310 | }; |
| 311 | |
| 312 | /* TCB flags */ |
| 313 | #define TCB_STARTUP 00001 /* We have just begun ptracing this process */ |
| 314 | #define TCB_INUSE 00002 /* This table entry is in use */ |
| 315 | #define TCB_INSYSCALL 00004 /* A system call is in progress */ |
| 316 | #define TCB_ATTACHED 00010 /* Process is not our own child */ |
| 317 | #define TCB_EXITING 00020 /* As far as we know, this process is exiting */ |
| 318 | #define TCB_SUSPENDED 00040 /* Process has done a wait(4), that can |
| 319 | not be allowed to complete just now */ |
| 320 | #define TCB_BPTSET 00100 /* "Breakpoint" set after fork(2) */ |
| 321 | #define TCB_SIGTRAPPED 00200 /* Process wanted to block SIGTRAP */ |
| 322 | #define TCB_FOLLOWFORK 00400 /* Process should have forks followed */ |
| 323 | #define TCB_REPRINT 01000 /* We should reprint this syscall on exit */ |
| 324 | #ifdef LINUX |
Roland McGrath | 6d1a65c | 2004-07-12 07:44:08 +0000 | [diff] [blame] | 325 | # if defined(ALPHA) || defined(SPARC) || defined(SPARC64) || defined(POWERPC) || defined(IA64) || defined(HPPA) || defined(SH) || defined(SH64) || defined(S390) || defined(S390X) || defined(ARM) |
Wichert Akkerman | 7b3346b | 2001-10-09 23:47:38 +0000 | [diff] [blame] | 326 | # define TCB_WAITEXECVE 02000 /* ignore SIGTRAP after exceve */ |
| 327 | # endif |
Roland McGrath | 923f750 | 2003-01-09 06:53:27 +0000 | [diff] [blame] | 328 | # define TCB_CLONE_DETACHED 04000 /* CLONE_DETACHED set in creating syscall */ |
| 329 | # define TCB_CLONE_THREAD 010000 /* CLONE_THREAD set in creating syscall */ |
| 330 | # define TCB_GROUP_EXITING 020000 /* TCB_EXITING was exit_group, not _exit */ |
| 331 | # include <sys/syscall.h> |
| 332 | # ifndef __NR_exit_group |
| 333 | # /* Hack: Most headers around are too old to have __NR_exit_group. */ |
| 334 | # ifdef ALPHA |
| 335 | # define __NR_exit_group 405 |
| 336 | # elif defined I386 |
| 337 | # define __NR_exit_group 252 |
| 338 | # elif defined IA64 |
| 339 | # define __NR_exit_group 1236 |
| 340 | # elif defined POWERPC |
| 341 | # define __NR_exit_group 234 |
| 342 | # elif defined S390 || defined S390X |
| 343 | # define __NR_exit_group 248 |
Roland McGrath | 6d1a65c | 2004-07-12 07:44:08 +0000 | [diff] [blame] | 344 | # elif defined SPARC || defined SPARC64 |
Roland McGrath | 923f750 | 2003-01-09 06:53:27 +0000 | [diff] [blame] | 345 | # define __NR_exit_group 188 |
| 346 | # endif /* ALPHA et al */ |
| 347 | # endif /* !__NR_exit_group */ |
Wichert Akkerman | 76baf7c | 1999-02-19 00:21:36 +0000 | [diff] [blame] | 348 | #endif /* LINUX */ |
| 349 | |
| 350 | /* qualifier flags */ |
| 351 | #define QUAL_TRACE 0001 /* this system call should be traced */ |
| 352 | #define QUAL_ABBREV 0002 /* abbreviate the structures of this syscall */ |
| 353 | #define QUAL_VERBOSE 0004 /* decode the structures of this syscall */ |
| 354 | #define QUAL_RAW 0010 /* print all args in hex for this syscall */ |
| 355 | #define QUAL_SIGNAL 0020 /* report events with this signal */ |
| 356 | #define QUAL_FAULT 0040 /* report events with this fault */ |
| 357 | #define QUAL_READ 0100 /* dump data read on this file descriptor */ |
| 358 | #define QUAL_WRITE 0200 /* dump data written to this file descriptor */ |
| 359 | |
| 360 | #define entering(tcp) (!((tcp)->flags & TCB_INSYSCALL)) |
| 361 | #define exiting(tcp) ((tcp)->flags & TCB_INSYSCALL) |
| 362 | #define syserror(tcp) ((tcp)->u_error != 0) |
| 363 | #define verbose(tcp) (qual_flags[(tcp)->scno] & QUAL_VERBOSE) |
| 364 | #define abbrev(tcp) (qual_flags[(tcp)->scno] & QUAL_ABBREV) |
Wichert Akkerman | 76baf7c | 1999-02-19 00:21:36 +0000 | [diff] [blame] | 365 | |
| 366 | struct xlat { |
| 367 | int val; |
| 368 | char *str; |
| 369 | }; |
| 370 | |
| 371 | /* Format of syscall return values */ |
| 372 | #define RVAL_DECIMAL 000 /* decimal format */ |
| 373 | #define RVAL_HEX 001 /* hex format */ |
| 374 | #define RVAL_OCTAL 002 /* octal format */ |
| 375 | #define RVAL_UDECIMAL 003 /* unsigned decimal format */ |
Wichert Akkerman | bf79f2e | 2000-09-01 21:03:06 +0000 | [diff] [blame] | 376 | #define RVAL_LDECIMAL 004 /* long decimal format */ |
| 377 | #define RVAL_LHEX 005 /* long hex format */ |
| 378 | #define RVAL_LOCTAL 006 /* long octal format */ |
| 379 | #define RVAL_LUDECIMAL 007 /* long unsigned decimal format */ |
Wichert Akkerman | 76baf7c | 1999-02-19 00:21:36 +0000 | [diff] [blame] | 380 | #define RVAL_MASK 007 /* mask for these values */ |
| 381 | |
| 382 | #define RVAL_STR 010 /* Print `auxstr' field after return val */ |
| 383 | #define RVAL_NONE 020 /* Print nothing */ |
| 384 | |
| 385 | #ifndef offsetof |
| 386 | #define offsetof(type, member) (((char *) &(((type *) NULL)->member)) - \ |
| 387 | ((char *) (type *) NULL)) |
| 388 | #endif /* !offsetof */ |
| 389 | |
| 390 | /* get offset of member within a user struct */ |
| 391 | #define uoff(member) offsetof(struct user, member) |
| 392 | |
| 393 | #define TRACE_FILE 001 /* Trace file-related syscalls. */ |
| 394 | #define TRACE_IPC 002 /* Trace IPC-related syscalls. */ |
| 395 | #define TRACE_NETWORK 004 /* Trace network-related syscalls. */ |
| 396 | #define TRACE_PROCESS 010 /* Trace process-related syscalls. */ |
| 397 | #define TRACE_SIGNAL 020 /* Trace signal-related syscalls. */ |
| 398 | |
Roland McGrath | ee9d435 | 2002-12-18 04:16:10 +0000 | [diff] [blame] | 399 | extern struct tcb **tcbtab; |
Wichert Akkerman | 76baf7c | 1999-02-19 00:21:36 +0000 | [diff] [blame] | 400 | extern int qual_flags[]; |
| 401 | extern int debug, followfork, followvfork; |
| 402 | extern int rflag, tflag, dtime, cflag, xflag, qflag; |
| 403 | extern int acolumn; |
| 404 | extern char *outfname; |
Roland McGrath | ee9d435 | 2002-12-18 04:16:10 +0000 | [diff] [blame] | 405 | extern unsigned int nprocs, tcbtabsize; |
Wichert Akkerman | 76baf7c | 1999-02-19 00:21:36 +0000 | [diff] [blame] | 406 | extern int max_strlen; |
| 407 | extern struct tcb *tcp_last; |
| 408 | |
| 409 | #ifdef __STDC__ |
| 410 | #define P(args) args |
| 411 | #else |
| 412 | #define P(args) () |
| 413 | #endif |
| 414 | |
| 415 | extern int set_personality P((int personality)); |
Roland McGrath | d9f816f | 2004-09-04 03:39:20 +0000 | [diff] [blame] | 416 | extern char *xlookup P((const struct xlat *, int)); |
Wichert Akkerman | 76baf7c | 1999-02-19 00:21:36 +0000 | [diff] [blame] | 417 | extern struct tcb *alloctcb P((int)); |
Roland McGrath | 923f750 | 2003-01-09 06:53:27 +0000 | [diff] [blame] | 418 | extern struct tcb *pid2tcb P((int)); |
Wichert Akkerman | 76baf7c | 1999-02-19 00:21:36 +0000 | [diff] [blame] | 419 | extern void droptcb P((struct tcb *)); |
Roland McGrath | 7b54a7a | 2004-06-04 01:50:45 +0000 | [diff] [blame] | 420 | extern int expand_tcbtab P((void)); |
Wichert Akkerman | 76baf7c | 1999-02-19 00:21:36 +0000 | [diff] [blame] | 421 | |
| 422 | extern void set_sortby P((char *)); |
| 423 | extern void set_overhead P((int)); |
| 424 | extern void qualify P((char *)); |
| 425 | extern void newoutf P((struct tcb *)); |
Wichert Akkerman | bf79f2e | 2000-09-01 21:03:06 +0000 | [diff] [blame] | 426 | extern int get_scno P((struct tcb *)); |
Wichert Akkerman | 76baf7c | 1999-02-19 00:21:36 +0000 | [diff] [blame] | 427 | extern int trace_syscall P((struct tcb *)); |
Roland McGrath | d9f816f | 2004-09-04 03:39:20 +0000 | [diff] [blame] | 428 | extern void printxval P((const struct xlat *, int, char *)); |
Wichert Akkerman | 76baf7c | 1999-02-19 00:21:36 +0000 | [diff] [blame] | 429 | extern int printargs P((struct tcb *)); |
Roland McGrath | d9f816f | 2004-09-04 03:39:20 +0000 | [diff] [blame] | 430 | extern int addflags P((const struct xlat *, int)); |
| 431 | extern int printflags P((const struct xlat *, int)); |
Wichert Akkerman | 76baf7c | 1999-02-19 00:21:36 +0000 | [diff] [blame] | 432 | extern int umoven P((struct tcb *, long, int, char *)); |
| 433 | extern int umovestr P((struct tcb *, long, int, char *)); |
| 434 | extern int upeek P((int, long, long *)); |
John Hughes | 1d08dcf | 2001-07-10 13:48:44 +0000 | [diff] [blame] | 435 | extern void dumpiov P((struct tcb *, int, long)); |
Wichert Akkerman | 76baf7c | 1999-02-19 00:21:36 +0000 | [diff] [blame] | 436 | extern void dumpstr P((struct tcb *, long, int)); |
| 437 | extern void string_quote P((char *str)); |
| 438 | extern void printstr P((struct tcb *, long, int)); |
| 439 | extern void printnum P((struct tcb *, long, char *)); |
| 440 | extern void printpath P((struct tcb *, long)); |
| 441 | extern void printpathn P((struct tcb *, long, int)); |
| 442 | extern void printtv P((struct tcb *, long)); |
John Hughes | 5826589 | 2001-10-18 15:13:53 +0000 | [diff] [blame] | 443 | #ifdef HAVE_SIGINFO_T |
| 444 | extern void printsiginfo P((siginfo_t *, int)); |
| 445 | #endif |
Wichert Akkerman | f5eeabb | 1999-11-18 17:09:47 +0000 | [diff] [blame] | 446 | extern void printsock P((struct tcb *, long, int)); |
John Hughes | 38ae88d | 2002-05-23 11:48:58 +0000 | [diff] [blame] | 447 | extern void print_sock_optmgmt P((struct tcb *, long, int)); |
Wichert Akkerman | 76baf7c | 1999-02-19 00:21:36 +0000 | [diff] [blame] | 448 | extern void printrusage P((struct tcb *, long)); |
Roland McGrath | 6bc1220 | 2003-11-13 22:32:27 +0000 | [diff] [blame] | 449 | extern void printuid P((const char *, unsigned long)); |
Wichert Akkerman | 76baf7c | 1999-02-19 00:21:36 +0000 | [diff] [blame] | 450 | extern int clearbpt P((struct tcb *)); |
| 451 | extern int setbpt P((struct tcb *)); |
| 452 | extern int sigishandled P((struct tcb *, int)); |
| 453 | extern void printcall P((struct tcb *)); |
Roland McGrath | ee36ce1 | 2004-09-04 03:53:10 +0000 | [diff] [blame] | 454 | extern const char *signame P((int)); |
Wichert Akkerman | 76baf7c | 1999-02-19 00:21:36 +0000 | [diff] [blame] | 455 | extern void printsignal P((int)); |
| 456 | extern void printleader P((struct tcb *)); |
| 457 | extern void printtrailer P((struct tcb *)); |
| 458 | extern void tabto P((int)); |
| 459 | extern void call_summary P((FILE *)); |
| 460 | extern void fake_execve P((struct tcb *, char *, char *[], char *[])); |
Wichert Akkerman | 221f54f | 1999-11-18 17:26:45 +0000 | [diff] [blame] | 461 | extern void printtv32 P((struct tcb*, long)); |
John Hughes | 1d08dcf | 2001-07-10 13:48:44 +0000 | [diff] [blame] | 462 | extern void tprint_iov P((struct tcb *, int, long)); |
Wichert Akkerman | 76baf7c | 1999-02-19 00:21:36 +0000 | [diff] [blame] | 463 | |
Wichert Akkerman | 7a0b649 | 1999-12-23 15:08:17 +0000 | [diff] [blame] | 464 | #ifdef LINUX |
| 465 | extern int internal_clone P((struct tcb *)); |
| 466 | #endif |
Wichert Akkerman | 76baf7c | 1999-02-19 00:21:36 +0000 | [diff] [blame] | 467 | extern int internal_fork P((struct tcb *)); |
| 468 | extern int internal_exec P((struct tcb *)); |
Roland McGrath | c74c0b7 | 2004-09-01 19:39:46 +0000 | [diff] [blame] | 469 | extern int internal_wait P((struct tcb *, int)); |
Wichert Akkerman | 76baf7c | 1999-02-19 00:21:36 +0000 | [diff] [blame] | 470 | extern int internal_exit P((struct tcb *)); |
| 471 | |
Roland McGrath | ee36ce1 | 2004-09-04 03:53:10 +0000 | [diff] [blame] | 472 | extern const struct ioctlent *ioctl_lookup P((long)); |
| 473 | extern const struct ioctlent *ioctl_next_match P((const struct ioctlent *)); |
Wichert Akkerman | 76baf7c | 1999-02-19 00:21:36 +0000 | [diff] [blame] | 474 | extern int ioctl_decode P((struct tcb *, long, long)); |
| 475 | extern int term_ioctl P((struct tcb *, long, long)); |
| 476 | extern int sock_ioctl P((struct tcb *, long, long)); |
| 477 | extern int proc_ioctl P((struct tcb *, int, int)); |
| 478 | extern int stream_ioctl P((struct tcb *, int, int)); |
| 479 | |
| 480 | extern void tv_tv P((struct timeval *, int, int)); |
| 481 | extern int tv_nz P((struct timeval *)); |
| 482 | extern int tv_cmp P((struct timeval *, struct timeval *)); |
| 483 | extern double tv_float P((struct timeval *)); |
| 484 | extern void tv_add P((struct timeval *, struct timeval *, struct timeval *)); |
| 485 | extern void tv_sub P((struct timeval *, struct timeval *, struct timeval *)); |
| 486 | extern void tv_mul P((struct timeval *, struct timeval *, int)); |
| 487 | extern void tv_div P((struct timeval *, struct timeval *, int)); |
| 488 | |
| 489 | #ifdef SUNOS4 |
| 490 | extern int fixvfork P((struct tcb *)); |
| 491 | #endif |
Roland McGrath | 6d1a65c | 2004-07-12 07:44:08 +0000 | [diff] [blame] | 492 | #if !(defined(LINUX) && !defined(SPARC) && !defined(SPARC64) && !defined(IA64)) |
Wichert Akkerman | 76baf7c | 1999-02-19 00:21:36 +0000 | [diff] [blame] | 493 | extern long getrval2 P((struct tcb *)); |
| 494 | #endif |
Wichert Akkerman | bf79f2e | 2000-09-01 21:03:06 +0000 | [diff] [blame] | 495 | #ifdef USE_PROCFS |
Wichert Akkerman | 76baf7c | 1999-02-19 00:21:36 +0000 | [diff] [blame] | 496 | extern int proc_open P((struct tcb *tcp, int attaching)); |
| 497 | #endif |
| 498 | |
| 499 | #define umove(pid, addr, objp) \ |
| 500 | umoven((pid), (addr), sizeof *(objp), (char *) (objp)) |
| 501 | |
| 502 | #ifdef __STDC__ |
| 503 | #ifdef __GNUC__ |
| 504 | extern void tprintf(const char *fmt, ...) |
| 505 | __attribute__ ((format (printf, 1, 2))); |
| 506 | #else |
| 507 | extern void tprintf(const char *fmt, ...); |
| 508 | #endif |
| 509 | #else |
| 510 | extern void tprintf(); |
| 511 | #endif |
| 512 | |
| 513 | #ifndef HAVE_STRERROR |
| 514 | const char *strerror P((int)); |
| 515 | #endif |
| 516 | #ifndef HAVE_STRSIGNAL |
| 517 | const char *strsignal P((int)); |
| 518 | #endif |
| 519 | |
| 520 | extern int current_personality; |
| 521 | |
| 522 | struct sysent { |
| 523 | int nargs; |
| 524 | int sys_flags; |
| 525 | int (*sys_func)(); |
Roland McGrath | ee36ce1 | 2004-09-04 03:53:10 +0000 | [diff] [blame] | 526 | const char *sys_name; |
Wichert Akkerman | 76baf7c | 1999-02-19 00:21:36 +0000 | [diff] [blame] | 527 | }; |
| 528 | |
Roland McGrath | ee36ce1 | 2004-09-04 03:53:10 +0000 | [diff] [blame] | 529 | extern const struct sysent *sysent; |
Wichert Akkerman | 76baf7c | 1999-02-19 00:21:36 +0000 | [diff] [blame] | 530 | extern int nsyscalls; |
| 531 | |
Roland McGrath | ee36ce1 | 2004-09-04 03:53:10 +0000 | [diff] [blame] | 532 | extern const char *const *errnoent; |
Wichert Akkerman | 76baf7c | 1999-02-19 00:21:36 +0000 | [diff] [blame] | 533 | extern int nerrnos; |
| 534 | |
| 535 | struct ioctlent { |
Roland McGrath | ee36ce1 | 2004-09-04 03:53:10 +0000 | [diff] [blame] | 536 | const char *doth; |
| 537 | const char *symbol; |
Wichert Akkerman | 76baf7c | 1999-02-19 00:21:36 +0000 | [diff] [blame] | 538 | unsigned long code; |
| 539 | }; |
| 540 | |
Roland McGrath | ee36ce1 | 2004-09-04 03:53:10 +0000 | [diff] [blame] | 541 | extern const struct ioctlent *ioctlent; |
Wichert Akkerman | 76baf7c | 1999-02-19 00:21:36 +0000 | [diff] [blame] | 542 | extern int nioctlents; |
Roland McGrath | ee36ce1 | 2004-09-04 03:53:10 +0000 | [diff] [blame] | 543 | |
| 544 | extern const char *const *signalent; |
Wichert Akkerman | 76baf7c | 1999-02-19 00:21:36 +0000 | [diff] [blame] | 545 | extern int nsignals; |
| 546 | |
Roland McGrath | ee36ce1 | 2004-09-04 03:53:10 +0000 | [diff] [blame] | 547 | extern const struct ioctlent ioctlent0[]; |
| 548 | extern const int nioctlents0; |
| 549 | extern const char *const signalent0[]; |
| 550 | extern const int nsignals0; |
Wichert Akkerman | 76baf7c | 1999-02-19 00:21:36 +0000 | [diff] [blame] | 551 | |
| 552 | #if SUPPORTED_PERSONALITIES >= 2 |
Roland McGrath | ee36ce1 | 2004-09-04 03:53:10 +0000 | [diff] [blame] | 553 | extern const struct ioctlent ioctlent1[]; |
| 554 | extern constint nioctlents1; |
| 555 | extern const char *const signalent1[]; |
| 556 | extern const int nsignals1; |
Wichert Akkerman | 76baf7c | 1999-02-19 00:21:36 +0000 | [diff] [blame] | 557 | #endif /* SUPPORTED_PERSONALITIES >= 2 */ |
| 558 | |
| 559 | #if SUPPORTED_PERSONALITIES >= 3 |
Roland McGrath | ee36ce1 | 2004-09-04 03:53:10 +0000 | [diff] [blame] | 560 | extern const struct ioctlent ioctlent2[]; |
| 561 | extern const int nioctlents2; |
| 562 | extern const char *const signalent2[]; |
| 563 | extern constint nsignals2; |
Wichert Akkerman | 76baf7c | 1999-02-19 00:21:36 +0000 | [diff] [blame] | 564 | #endif /* SUPPORTED_PERSONALITIES >= 3 */ |
John Hughes | bdf48f5 | 2001-03-06 15:08:09 +0000 | [diff] [blame] | 565 | |
Roland McGrath | e6d3a29 | 2003-01-14 09:46:18 +0000 | [diff] [blame] | 566 | #if defined(FREEBSD) || (defined(LINUX) \ |
Roland McGrath | c0f8bbd | 2003-08-21 09:58:00 +0000 | [diff] [blame] | 567 | && defined(POWERPC) && !defined(__powerpc64__)) \ |
| 568 | || (defined (LINUX) && defined (MIPS) && !defined(__mips64)) |
John Hughes | 5a826b8 | 2001-03-07 13:21:24 +0000 | [diff] [blame] | 569 | /* ARRGH! off_t args are aligned on 64 bit boundaries! */ |
| 570 | #define ALIGN64(tcp,arg) \ |
| 571 | do { \ |
| 572 | if (arg % 2) \ |
| 573 | memmove (&tcp->u_arg[arg], &tcp->u_arg[arg + 1], \ |
| 574 | (tcp->u_nargs - arg - 1) * sizeof tcp->u_arg[0]); \ |
| 575 | } while (0) |
| 576 | #else |
| 577 | #define ALIGN64(tcp,arg) do { } while (0) |
| 578 | #endif |
| 579 | |
John Hughes | 0c79e01 | 2001-03-08 14:40:06 +0000 | [diff] [blame] | 580 | #if HAVE_LONG_LONG |
John Hughes | 5a826b8 | 2001-03-07 13:21:24 +0000 | [diff] [blame] | 581 | |
John Hughes | bdf48f5 | 2001-03-06 15:08:09 +0000 | [diff] [blame] | 582 | /* _l refers to the lower numbered u_arg, |
| 583 | * _h refers to the higher numbered u_arg |
| 584 | */ |
John Hughes | 5a826b8 | 2001-03-07 13:21:24 +0000 | [diff] [blame] | 585 | |
John Hughes | b8a85a4 | 2001-03-28 08:05:27 +0000 | [diff] [blame] | 586 | #if HAVE_LITTLE_ENDIAN_LONG_LONG |
John Hughes | 0c79e01 | 2001-03-08 14:40:06 +0000 | [diff] [blame] | 587 | #define LONG_LONG(_l,_h) \ |
Wichert Akkerman | 7ab47b6 | 2002-03-31 19:00:02 +0000 | [diff] [blame] | 588 | ((long long)((unsigned long long)(unsigned)(_l) | ((unsigned long long)(_h)<<32))) |
John Hughes | bdf48f5 | 2001-03-06 15:08:09 +0000 | [diff] [blame] | 589 | #else |
John Hughes | 0c79e01 | 2001-03-08 14:40:06 +0000 | [diff] [blame] | 590 | #define LONG_LONG(_l,_h) \ |
Wichert Akkerman | 7ab47b6 | 2002-03-31 19:00:02 +0000 | [diff] [blame] | 591 | ((long long)((unsigned long long)(unsigned)(_h) | ((unsigned long long)(_l)<<32))) |
John Hughes | bdf48f5 | 2001-03-06 15:08:09 +0000 | [diff] [blame] | 592 | #endif |
| 593 | #endif |
Wichert Akkerman | 7b3346b | 2001-10-09 23:47:38 +0000 | [diff] [blame] | 594 | |
| 595 | #ifdef IA64 |
| 596 | extern long ia32; |
| 597 | #endif |
Michal Ludvig | 17f8fb3 | 2002-11-06 13:17:21 +0000 | [diff] [blame] | 598 | |
| 599 | extern int not_failing_only; |