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 | |
Wichert Akkerman | 76baf7c | 1999-02-19 00:21:36 +0000 | [diff] [blame] | 36 | #ifdef HAVE_CONFIG_H |
| 37 | #include "config.h" |
| 38 | #endif |
| 39 | |
| 40 | /* configuration section */ |
| 41 | #ifndef MAX_QUALS |
Wichert Akkerman | fd89ced | 2000-04-13 17:06:09 +0000 | [diff] [blame] | 42 | #if defined(linux) && defined(MIPS) |
| 43 | #define MAX_QUALS 4999 /* maximum number of syscalls, signals, etc. */ |
| 44 | #else |
Wichert Akkerman | 8b1b40c | 2000-02-03 21:58:30 +0000 | [diff] [blame] | 45 | #define MAX_QUALS 2048 /* maximum number of syscalls, signals, etc. */ |
Wichert Akkerman | 76baf7c | 1999-02-19 00:21:36 +0000 | [diff] [blame] | 46 | #endif |
Wichert Akkerman | 5ae21ea | 2000-05-01 01:53:59 +0000 | [diff] [blame] | 47 | #endif |
Wichert Akkerman | 76baf7c | 1999-02-19 00:21:36 +0000 | [diff] [blame] | 48 | #ifndef MAX_PROCS |
Wichert Akkerman | faf7222 | 2000-02-19 23:59:03 +0000 | [diff] [blame] | 49 | #define MAX_PROCS 64 /* maximum number of processes tracable */ |
Wichert Akkerman | 76baf7c | 1999-02-19 00:21:36 +0000 | [diff] [blame] | 50 | #endif |
| 51 | #ifndef DEFAULT_STRLEN |
| 52 | #define DEFAULT_STRLEN 32 /* default maximum # of bytes printed in |
| 53 | `printstr', change with `-s' switch */ |
| 54 | #endif |
| 55 | #ifndef DEFAULT_ACOLUMN |
| 56 | #define DEFAULT_ACOLUMN 40 /* default alignment column for results */ |
| 57 | #endif |
| 58 | #ifndef MAX_ARGS |
| 59 | #define MAX_ARGS 32 /* maximum number of args to a syscall */ |
| 60 | #endif |
| 61 | #ifndef DEFAULT_SORTBY |
| 62 | #define DEFAULT_SORTBY "time" /* default sorting method for call profiling */ |
| 63 | #endif |
| 64 | |
| 65 | #include <sys/types.h> |
| 66 | #include <unistd.h> |
| 67 | #include <stdlib.h> |
| 68 | #include <stdio.h> |
| 69 | #include <ctype.h> |
| 70 | #include <string.h> |
Wichert Akkerman | 8c7122c | 2001-02-16 19:59:55 +0000 | [diff] [blame] | 71 | #include <time.h> |
Wichert Akkerman | 76baf7c | 1999-02-19 00:21:36 +0000 | [diff] [blame] | 72 | #include <sys/time.h> |
| 73 | #include <errno.h> |
| 74 | |
| 75 | #ifdef STDC_HEADERS |
| 76 | #include <stddef.h> |
| 77 | #endif /* STDC_HEADERS */ |
| 78 | |
John Hughes | 5826589 | 2001-10-18 15:13:53 +0000 | [diff] [blame] | 79 | #ifdef HAVE_SIGINFO_T |
| 80 | #include <signal.h> |
| 81 | #endif |
| 82 | |
Wichert Akkerman | f5eeabb | 1999-11-18 17:09:47 +0000 | [diff] [blame] | 83 | #if defined(LINUX) |
| 84 | # if defined(SPARC) |
| 85 | # define LINUXSPARC |
| 86 | # endif |
| 87 | # if defined(ALPHA) |
| 88 | # define LINUX_64BIT |
| 89 | # endif |
| 90 | #endif |
Wichert Akkerman | 76baf7c | 1999-02-19 00:21:36 +0000 | [diff] [blame] | 91 | |
Wichert Akkerman | bf79f2e | 2000-09-01 21:03:06 +0000 | [diff] [blame] | 92 | #if defined(SVR4) || defined(FREEBSD) |
| 93 | #define USE_PROCFS |
| 94 | #else |
| 95 | #undef USE_PROCFS |
| 96 | #endif |
| 97 | |
| 98 | #ifdef FREEBSD |
| 99 | #ifndef I386 |
| 100 | #error "FreeBSD support is only for i386 arch right now." |
| 101 | #endif |
| 102 | #include <machine/psl.h> |
| 103 | #include <machine/reg.h> |
| 104 | #include <sys/syscall.h> |
| 105 | #endif |
| 106 | |
| 107 | #ifdef USE_PROCFS |
Wichert Akkerman | 76baf7c | 1999-02-19 00:21:36 +0000 | [diff] [blame] | 108 | #include <sys/procfs.h> |
Wichert Akkerman | ea78f0f | 1999-11-29 15:34:02 +0000 | [diff] [blame] | 109 | #ifdef HAVE_MP_PROCFS |
Wichert Akkerman | 9ce1a63 | 1999-08-29 23:15:07 +0000 | [diff] [blame] | 110 | #include <sys/uio.h> |
| 111 | #endif |
Wichert Akkerman | bf79f2e | 2000-09-01 21:03:06 +0000 | [diff] [blame] | 112 | #ifdef FREEBSD |
| 113 | #include <sys/pioctl.h> |
| 114 | #endif /* FREEBSD */ |
| 115 | #else /* !USE_PROCFS */ |
Wichert Akkerman | 76baf7c | 1999-02-19 00:21:36 +0000 | [diff] [blame] | 116 | #if defined(LINUXSPARC) && defined(__GLIBC__) |
| 117 | #include <sys/ptrace.h> |
| 118 | #else |
| 119 | /* Work around awkward prototype in ptrace.h. */ |
| 120 | #define ptrace xptrace |
| 121 | #include <sys/ptrace.h> |
| 122 | #undef ptrace |
| 123 | #ifdef POWERPC |
| 124 | #define __KERNEL__ |
| 125 | #include <asm/ptrace.h> |
| 126 | #undef __KERNEL__ |
| 127 | /* TEMP */ |
| 128 | #define UESP PT_R1 |
| 129 | #define EIP PT_NIP |
| 130 | #define EAX PT_R3 |
| 131 | #define ORIG_EAX PT_ORIG_R3 |
| 132 | #endif |
| 133 | #ifdef __STDC__ |
| 134 | #ifdef LINUX |
| 135 | extern long ptrace(int, int, char *, long); |
| 136 | #else /* !LINUX */ |
| 137 | extern int ptrace(int, int, char *, int, ...); |
| 138 | #endif /* !LINUX */ |
| 139 | #else /* !__STDC__ */ |
| 140 | extern int ptrace(); |
| 141 | #endif /* !__STDC__ */ |
| 142 | #endif /* !LINUXSPARC */ |
| 143 | #endif /* !SVR4 */ |
| 144 | |
| 145 | #ifdef LINUX |
Wichert Akkerman | b859bea | 1999-04-18 22:50:50 +0000 | [diff] [blame] | 146 | #if !defined(__GLIBC__) |
Wichert Akkerman | 76baf7c | 1999-02-19 00:21:36 +0000 | [diff] [blame] | 147 | #define PTRACE_PEEKUSER PTRACE_PEEKUSR |
| 148 | #define PTRACE_POKEUSER PTRACE_POKEUSR |
| 149 | #endif |
| 150 | #ifdef ALPHA |
Wichert Akkerman | f90da01 | 1999-10-31 21:15:38 +0000 | [diff] [blame] | 151 | # define REG_R0 0 |
| 152 | # define REG_A0 16 |
| 153 | # define REG_A3 19 |
| 154 | # define REG_FP 30 |
| 155 | # define REG_PC 64 |
Wichert Akkerman | 76baf7c | 1999-02-19 00:21:36 +0000 | [diff] [blame] | 156 | #endif /* ALPHA */ |
Wichert Akkerman | f90da01 | 1999-10-31 21:15:38 +0000 | [diff] [blame] | 157 | #ifdef MIPS |
| 158 | # define REG_V0 2 |
| 159 | # define REG_A0 4 |
| 160 | # define REG_A3 7 |
| 161 | # define REG_SP 29 |
| 162 | # define REG_EPC 64 |
| 163 | #endif /* MIPS */ |
Wichert Akkerman | c1652e2 | 2001-03-27 12:17:16 +0000 | [diff] [blame] | 164 | #ifdef HPPA |
| 165 | # define PT_GR20 (20*4) |
| 166 | # define PT_GR26 (26*4) |
| 167 | # define PT_GR28 (28*4) |
| 168 | # define PT_IAOQ0 (106*4) |
| 169 | # define PT_IAOQ1 (107*4) |
| 170 | #endif /* HPPA */ |
Wichert Akkerman | 76baf7c | 1999-02-19 00:21:36 +0000 | [diff] [blame] | 171 | #endif /* LINUX */ |
| 172 | |
| 173 | #define SUPPORTED_PERSONALITIES 1 |
| 174 | #define DEFAULT_PERSONALITY 0 |
| 175 | |
| 176 | #ifdef LINUXSPARC |
| 177 | #include <linux/a.out.h> |
| 178 | #include <asm/psr.h> |
| 179 | #undef SUPPORTED_PERSONALITIES |
Wichert Akkerman | b859bea | 1999-04-18 22:50:50 +0000 | [diff] [blame] | 180 | #define SUPPORTED_PERSONALITIES 2 |
Wichert Akkerman | 76baf7c | 1999-02-19 00:21:36 +0000 | [diff] [blame] | 181 | #endif /* LINUXSPARC */ |
| 182 | |
Wichert Akkerman | 9ce1a63 | 1999-08-29 23:15:07 +0000 | [diff] [blame] | 183 | #ifdef SVR4 |
Wichert Akkerman | ea78f0f | 1999-11-29 15:34:02 +0000 | [diff] [blame] | 184 | #ifdef HAVE_MP_PROCFS |
Wichert Akkerman | 9ce1a63 | 1999-08-29 23:15:07 +0000 | [diff] [blame] | 185 | extern int mp_ioctl (int f, int c, void *a, int s); |
| 186 | #define IOCTL(f,c,a) mp_ioctl (f, c, a, sizeof *a) |
| 187 | #define IOCTL_STATUS(t) \ |
| 188 | pread (t->pfd_stat, &t->status, sizeof t->status, 0) |
| 189 | #define IOCTL_WSTOP(t) \ |
Wichert Akkerman | 16a03d2 | 2000-08-10 02:14:04 +0000 | [diff] [blame] | 190 | (IOCTL (t->pfd, PCWSTOP, (char *)NULL) < 0 ? -1 : \ |
Wichert Akkerman | 9ce1a63 | 1999-08-29 23:15:07 +0000 | [diff] [blame] | 191 | IOCTL_STATUS (t)) |
| 192 | #define PR_WHY pr_lwp.pr_why |
| 193 | #define PR_WHAT pr_lwp.pr_what |
| 194 | #define PR_REG pr_lwp.pr_context.uc_mcontext.gregs |
| 195 | #define PR_FLAGS pr_lwp.pr_flags |
John Hughes | 2529971 | 2001-03-06 10:10:06 +0000 | [diff] [blame] | 196 | #define PR_SYSCALL pr_lwp.pr_syscall |
John Hughes | 5826589 | 2001-10-18 15:13:53 +0000 | [diff] [blame] | 197 | #define PR_INFO pr_lwp.pr_info |
Wichert Akkerman | 9ce1a63 | 1999-08-29 23:15:07 +0000 | [diff] [blame] | 198 | #define PIOCSTIP PCSTOP |
| 199 | #define PIOCSET PCSET |
| 200 | #define PIOCRESET PCRESET |
| 201 | #define PIOCSTRACE PCSTRACE |
| 202 | #define PIOCSFAULT PCSFAULT |
| 203 | #define PIOCWSTOP PCWSTOP |
| 204 | #define PIOCSTOP PCSTOP |
| 205 | #define PIOCSENTRY PCSENTRY |
| 206 | #define PIOCSEXIT PCSEXIT |
| 207 | #define PIOCRUN PCRUN |
| 208 | #else |
| 209 | #define IOCTL ioctl |
| 210 | #define IOCTL_STATUS(t) ioctl (t->pfd, PIOCSTATUS, &t->status) |
| 211 | #define IOCTL_WSTOP(t) ioctl (t->pfd, PIOCWSTOP, &t->status) |
| 212 | #define PR_WHY pr_why |
| 213 | #define PR_WHAT pr_what |
| 214 | #define PR_REG pr_reg |
| 215 | #define PR_FLAGS pr_flags |
John Hughes | 2529971 | 2001-03-06 10:10:06 +0000 | [diff] [blame] | 216 | #define PR_SYSCALL pr_syscall |
John Hughes | 5826589 | 2001-10-18 15:13:53 +0000 | [diff] [blame] | 217 | #define PR_INFO pr_info |
Wichert Akkerman | 9ce1a63 | 1999-08-29 23:15:07 +0000 | [diff] [blame] | 218 | #endif |
| 219 | #endif |
Wichert Akkerman | bf79f2e | 2000-09-01 21:03:06 +0000 | [diff] [blame] | 220 | #ifdef FREEBSD |
| 221 | #define IOCTL ioctl |
| 222 | #define IOCTL_STATUS(t) ioctl (t->pfd, PIOCSTATUS, &t->status) |
| 223 | #define IOCTL_WSTOP(t) ioctl (t->pfd, PIOCWAIT, &t->status) |
| 224 | #define PIOCRUN PIOCCONT |
| 225 | #define PIOCWSTOP PIOCWAIT |
| 226 | #define PR_WHY why |
| 227 | #define PR_WHAT val |
Wichert Akkerman | 2e4ffe5 | 2000-09-03 23:57:48 +0000 | [diff] [blame] | 228 | #define PR_FLAGS state |
Wichert Akkerman | bf79f2e | 2000-09-01 21:03:06 +0000 | [diff] [blame] | 229 | /* from /usr/src/sys/miscfs/procfs/procfs_vnops.c, |
| 230 | status.state = 0 for running, 1 for stopped */ |
Wichert Akkerman | 2e4ffe5 | 2000-09-03 23:57:48 +0000 | [diff] [blame] | 231 | #define PR_ASLEEP 1 |
Wichert Akkerman | bf79f2e | 2000-09-01 21:03:06 +0000 | [diff] [blame] | 232 | #define PR_SYSENTRY S_SCE |
| 233 | #define PR_SYSEXIT S_SCX |
| 234 | #define PR_SIGNALLED S_SIG |
| 235 | #define PR_FAULTED S_CORE |
| 236 | #endif |
Wichert Akkerman | 9ce1a63 | 1999-08-29 23:15:07 +0000 | [diff] [blame] | 237 | |
Wichert Akkerman | 76baf7c | 1999-02-19 00:21:36 +0000 | [diff] [blame] | 238 | /* Trace Control Block */ |
| 239 | struct tcb { |
| 240 | short flags; /* See below for TCB_ values */ |
| 241 | int pid; /* Process Id of this entry */ |
| 242 | long scno; /* System call number */ |
| 243 | int u_nargs; /* System call arguments */ |
| 244 | long u_arg[MAX_ARGS]; /* System call arguments */ |
| 245 | int u_error; /* Error code */ |
| 246 | long u_rval; /* (first) return value */ |
Wichert Akkerman | 16a03d2 | 2000-08-10 02:14:04 +0000 | [diff] [blame] | 247 | #ifdef HAVE_LONG_LONG |
| 248 | long long u_lrval; /* long long return value */ |
| 249 | #endif |
Wichert Akkerman | 76baf7c | 1999-02-19 00:21:36 +0000 | [diff] [blame] | 250 | FILE *outf; /* Output file for this process */ |
Wichert Akkerman | 43a7482 | 2000-06-27 17:33:32 +0000 | [diff] [blame] | 251 | const char *auxstr; /* Auxiliary info from syscall (see RVAL_STR) */ |
Wichert Akkerman | 76baf7c | 1999-02-19 00:21:36 +0000 | [diff] [blame] | 252 | struct timeval stime; /* System time usage as of last process wait */ |
| 253 | struct timeval dtime; /* Delta for system time usage */ |
| 254 | struct timeval etime; /* Syscall entry time */ |
| 255 | /* Support for tracing forked processes */ |
| 256 | struct tcb *parent; /* Parent of this process */ |
| 257 | int nchildren; /* # of traced children */ |
| 258 | int waitpid; /* pid(s) this process is waiting for */ |
| 259 | /* (1st arg of wait4()) */ |
| 260 | long baddr; /* `Breakpoint' address */ |
| 261 | long inst[2]; /* Instructions on above */ |
| 262 | int pfd; /* proc file descriptor */ |
| 263 | #ifdef SVR4 |
Wichert Akkerman | ea78f0f | 1999-11-29 15:34:02 +0000 | [diff] [blame] | 264 | #ifdef HAVE_MP_PROCFS |
Wichert Akkerman | 9ce1a63 | 1999-08-29 23:15:07 +0000 | [diff] [blame] | 265 | int pfd_stat; |
| 266 | int pfd_as; |
| 267 | pstatus_t status; |
| 268 | #else |
Wichert Akkerman | 76baf7c | 1999-02-19 00:21:36 +0000 | [diff] [blame] | 269 | prstatus_t status; /* procfs status structure */ |
| 270 | #endif |
Wichert Akkerman | 9ce1a63 | 1999-08-29 23:15:07 +0000 | [diff] [blame] | 271 | #endif |
Wichert Akkerman | bf79f2e | 2000-09-01 21:03:06 +0000 | [diff] [blame] | 272 | #ifdef FREEBSD |
| 273 | struct procfs_status status; |
| 274 | int pfd_reg; |
| 275 | int pfd_status; |
| 276 | #endif |
Wichert Akkerman | 76baf7c | 1999-02-19 00:21:36 +0000 | [diff] [blame] | 277 | }; |
| 278 | |
| 279 | /* TCB flags */ |
| 280 | #define TCB_STARTUP 00001 /* We have just begun ptracing this process */ |
| 281 | #define TCB_INUSE 00002 /* This table entry is in use */ |
| 282 | #define TCB_INSYSCALL 00004 /* A system call is in progress */ |
| 283 | #define TCB_ATTACHED 00010 /* Process is not our own child */ |
| 284 | #define TCB_EXITING 00020 /* As far as we know, this process is exiting */ |
| 285 | #define TCB_SUSPENDED 00040 /* Process has done a wait(4), that can |
| 286 | not be allowed to complete just now */ |
| 287 | #define TCB_BPTSET 00100 /* "Breakpoint" set after fork(2) */ |
| 288 | #define TCB_SIGTRAPPED 00200 /* Process wanted to block SIGTRAP */ |
| 289 | #define TCB_FOLLOWFORK 00400 /* Process should have forks followed */ |
| 290 | #define TCB_REPRINT 01000 /* We should reprint this syscall on exit */ |
| 291 | #ifdef LINUX |
Wichert Akkerman | ccef637 | 2002-05-01 16:39:22 +0000 | [diff] [blame^] | 292 | # if defined(ALPHA) || defined(SPARC) || defined(POWERPC) || defined(IA64) || defined(HPPA) || defined(SH) |
Wichert Akkerman | 7b3346b | 2001-10-09 23:47:38 +0000 | [diff] [blame] | 293 | # define TCB_WAITEXECVE 02000 /* ignore SIGTRAP after exceve */ |
| 294 | # endif |
Wichert Akkerman | 76baf7c | 1999-02-19 00:21:36 +0000 | [diff] [blame] | 295 | #endif /* LINUX */ |
| 296 | |
| 297 | /* qualifier flags */ |
| 298 | #define QUAL_TRACE 0001 /* this system call should be traced */ |
| 299 | #define QUAL_ABBREV 0002 /* abbreviate the structures of this syscall */ |
| 300 | #define QUAL_VERBOSE 0004 /* decode the structures of this syscall */ |
| 301 | #define QUAL_RAW 0010 /* print all args in hex for this syscall */ |
| 302 | #define QUAL_SIGNAL 0020 /* report events with this signal */ |
| 303 | #define QUAL_FAULT 0040 /* report events with this fault */ |
| 304 | #define QUAL_READ 0100 /* dump data read on this file descriptor */ |
| 305 | #define QUAL_WRITE 0200 /* dump data written to this file descriptor */ |
| 306 | |
| 307 | #define entering(tcp) (!((tcp)->flags & TCB_INSYSCALL)) |
| 308 | #define exiting(tcp) ((tcp)->flags & TCB_INSYSCALL) |
| 309 | #define syserror(tcp) ((tcp)->u_error != 0) |
| 310 | #define verbose(tcp) (qual_flags[(tcp)->scno] & QUAL_VERBOSE) |
| 311 | #define abbrev(tcp) (qual_flags[(tcp)->scno] & QUAL_ABBREV) |
| 312 | #define waiting_parent(tcp) \ |
| 313 | (tcp->parent && \ |
| 314 | (tcp->parent->flags & TCB_SUSPENDED) && \ |
| 315 | (tcp->parent->waitpid <= 0 || tcp->parent->waitpid == tcp->pid)) |
| 316 | |
| 317 | struct xlat { |
| 318 | int val; |
| 319 | char *str; |
| 320 | }; |
| 321 | |
| 322 | /* Format of syscall return values */ |
| 323 | #define RVAL_DECIMAL 000 /* decimal format */ |
| 324 | #define RVAL_HEX 001 /* hex format */ |
| 325 | #define RVAL_OCTAL 002 /* octal format */ |
| 326 | #define RVAL_UDECIMAL 003 /* unsigned decimal format */ |
Wichert Akkerman | bf79f2e | 2000-09-01 21:03:06 +0000 | [diff] [blame] | 327 | #define RVAL_LDECIMAL 004 /* long decimal format */ |
| 328 | #define RVAL_LHEX 005 /* long hex format */ |
| 329 | #define RVAL_LOCTAL 006 /* long octal format */ |
| 330 | #define RVAL_LUDECIMAL 007 /* long unsigned decimal format */ |
Wichert Akkerman | 76baf7c | 1999-02-19 00:21:36 +0000 | [diff] [blame] | 331 | #define RVAL_MASK 007 /* mask for these values */ |
| 332 | |
| 333 | #define RVAL_STR 010 /* Print `auxstr' field after return val */ |
| 334 | #define RVAL_NONE 020 /* Print nothing */ |
| 335 | |
| 336 | #ifndef offsetof |
| 337 | #define offsetof(type, member) (((char *) &(((type *) NULL)->member)) - \ |
| 338 | ((char *) (type *) NULL)) |
| 339 | #endif /* !offsetof */ |
| 340 | |
| 341 | /* get offset of member within a user struct */ |
| 342 | #define uoff(member) offsetof(struct user, member) |
| 343 | |
| 344 | #define TRACE_FILE 001 /* Trace file-related syscalls. */ |
| 345 | #define TRACE_IPC 002 /* Trace IPC-related syscalls. */ |
| 346 | #define TRACE_NETWORK 004 /* Trace network-related syscalls. */ |
| 347 | #define TRACE_PROCESS 010 /* Trace process-related syscalls. */ |
| 348 | #define TRACE_SIGNAL 020 /* Trace signal-related syscalls. */ |
| 349 | |
| 350 | extern struct tcb tcbtab[]; |
| 351 | extern int qual_flags[]; |
| 352 | extern int debug, followfork, followvfork; |
| 353 | extern int rflag, tflag, dtime, cflag, xflag, qflag; |
| 354 | extern int acolumn; |
| 355 | extern char *outfname; |
| 356 | extern int nprocs; |
| 357 | extern int max_strlen; |
| 358 | extern struct tcb *tcp_last; |
| 359 | |
| 360 | #ifdef __STDC__ |
| 361 | #define P(args) args |
| 362 | #else |
| 363 | #define P(args) () |
| 364 | #endif |
| 365 | |
| 366 | extern int set_personality P((int personality)); |
| 367 | extern char *xlookup P((struct xlat *, int)); |
| 368 | extern struct tcb *alloctcb P((int)); |
| 369 | extern void droptcb P((struct tcb *)); |
| 370 | |
| 371 | extern void set_sortby P((char *)); |
| 372 | extern void set_overhead P((int)); |
| 373 | extern void qualify P((char *)); |
| 374 | extern void newoutf P((struct tcb *)); |
Wichert Akkerman | bf79f2e | 2000-09-01 21:03:06 +0000 | [diff] [blame] | 375 | extern int get_scno P((struct tcb *)); |
Wichert Akkerman | 76baf7c | 1999-02-19 00:21:36 +0000 | [diff] [blame] | 376 | extern int trace_syscall P((struct tcb *)); |
| 377 | extern void printxval P((struct xlat *, int, char *)); |
| 378 | extern int printargs P((struct tcb *)); |
| 379 | extern int addflags P((struct xlat *, int)); |
| 380 | extern int printflags P((struct xlat *, int)); |
| 381 | extern int umoven P((struct tcb *, long, int, char *)); |
| 382 | extern int umovestr P((struct tcb *, long, int, char *)); |
| 383 | extern int upeek P((int, long, long *)); |
John Hughes | 1d08dcf | 2001-07-10 13:48:44 +0000 | [diff] [blame] | 384 | extern void dumpiov P((struct tcb *, int, long)); |
Wichert Akkerman | 76baf7c | 1999-02-19 00:21:36 +0000 | [diff] [blame] | 385 | extern void dumpstr P((struct tcb *, long, int)); |
| 386 | extern void string_quote P((char *str)); |
| 387 | extern void printstr P((struct tcb *, long, int)); |
| 388 | extern void printnum P((struct tcb *, long, char *)); |
| 389 | extern void printpath P((struct tcb *, long)); |
| 390 | extern void printpathn P((struct tcb *, long, int)); |
| 391 | extern void printtv P((struct tcb *, long)); |
John Hughes | 5826589 | 2001-10-18 15:13:53 +0000 | [diff] [blame] | 392 | #ifdef HAVE_SIGINFO_T |
| 393 | extern void printsiginfo P((siginfo_t *, int)); |
| 394 | #endif |
Wichert Akkerman | f5eeabb | 1999-11-18 17:09:47 +0000 | [diff] [blame] | 395 | extern void printsock P((struct tcb *, long, int)); |
Wichert Akkerman | 76baf7c | 1999-02-19 00:21:36 +0000 | [diff] [blame] | 396 | extern void printrusage P((struct tcb *, long)); |
| 397 | extern int clearbpt P((struct tcb *)); |
| 398 | extern int setbpt P((struct tcb *)); |
| 399 | extern int sigishandled P((struct tcb *, int)); |
| 400 | extern void printcall P((struct tcb *)); |
Nate Sammons | ce780fc | 1999-03-29 23:23:13 +0000 | [diff] [blame] | 401 | extern char *signame P((int)); |
Wichert Akkerman | 76baf7c | 1999-02-19 00:21:36 +0000 | [diff] [blame] | 402 | extern void printsignal P((int)); |
| 403 | extern void printleader P((struct tcb *)); |
| 404 | extern void printtrailer P((struct tcb *)); |
| 405 | extern void tabto P((int)); |
| 406 | extern void call_summary P((FILE *)); |
| 407 | extern void fake_execve P((struct tcb *, char *, char *[], char *[])); |
Wichert Akkerman | 221f54f | 1999-11-18 17:26:45 +0000 | [diff] [blame] | 408 | extern void printtv32 P((struct tcb*, long)); |
John Hughes | 1d08dcf | 2001-07-10 13:48:44 +0000 | [diff] [blame] | 409 | extern void tprint_iov P((struct tcb *, int, long)); |
Wichert Akkerman | 76baf7c | 1999-02-19 00:21:36 +0000 | [diff] [blame] | 410 | |
Wichert Akkerman | 7a0b649 | 1999-12-23 15:08:17 +0000 | [diff] [blame] | 411 | #ifdef LINUX |
| 412 | extern int internal_clone P((struct tcb *)); |
| 413 | #endif |
Wichert Akkerman | 76baf7c | 1999-02-19 00:21:36 +0000 | [diff] [blame] | 414 | extern int internal_fork P((struct tcb *)); |
| 415 | extern int internal_exec P((struct tcb *)); |
| 416 | extern int internal_wait P((struct tcb *)); |
| 417 | extern int internal_exit P((struct tcb *)); |
| 418 | |
| 419 | extern char *ioctl_lookup P((long)); |
| 420 | extern int ioctl_decode P((struct tcb *, long, long)); |
| 421 | extern int term_ioctl P((struct tcb *, long, long)); |
| 422 | extern int sock_ioctl P((struct tcb *, long, long)); |
| 423 | extern int proc_ioctl P((struct tcb *, int, int)); |
| 424 | extern int stream_ioctl P((struct tcb *, int, int)); |
| 425 | |
| 426 | extern void tv_tv P((struct timeval *, int, int)); |
| 427 | extern int tv_nz P((struct timeval *)); |
| 428 | extern int tv_cmp P((struct timeval *, struct timeval *)); |
| 429 | extern double tv_float P((struct timeval *)); |
| 430 | extern void tv_add P((struct timeval *, struct timeval *, struct timeval *)); |
| 431 | extern void tv_sub P((struct timeval *, struct timeval *, struct timeval *)); |
| 432 | extern void tv_mul P((struct timeval *, struct timeval *, int)); |
| 433 | extern void tv_div P((struct timeval *, struct timeval *, int)); |
| 434 | |
| 435 | #ifdef SUNOS4 |
| 436 | extern int fixvfork P((struct tcb *)); |
| 437 | #endif |
| 438 | #if !(defined(LINUX) && !defined(SPARC)) |
| 439 | extern long getrval2 P((struct tcb *)); |
| 440 | #endif |
Wichert Akkerman | bf79f2e | 2000-09-01 21:03:06 +0000 | [diff] [blame] | 441 | #ifdef USE_PROCFS |
Wichert Akkerman | 76baf7c | 1999-02-19 00:21:36 +0000 | [diff] [blame] | 442 | extern int proc_open P((struct tcb *tcp, int attaching)); |
| 443 | #endif |
| 444 | |
| 445 | #define umove(pid, addr, objp) \ |
| 446 | umoven((pid), (addr), sizeof *(objp), (char *) (objp)) |
| 447 | |
| 448 | #ifdef __STDC__ |
| 449 | #ifdef __GNUC__ |
| 450 | extern void tprintf(const char *fmt, ...) |
| 451 | __attribute__ ((format (printf, 1, 2))); |
| 452 | #else |
| 453 | extern void tprintf(const char *fmt, ...); |
| 454 | #endif |
| 455 | #else |
| 456 | extern void tprintf(); |
| 457 | #endif |
| 458 | |
| 459 | #ifndef HAVE_STRERROR |
| 460 | const char *strerror P((int)); |
| 461 | #endif |
| 462 | #ifndef HAVE_STRSIGNAL |
| 463 | const char *strsignal P((int)); |
| 464 | #endif |
| 465 | |
| 466 | extern int current_personality; |
| 467 | |
| 468 | struct sysent { |
| 469 | int nargs; |
| 470 | int sys_flags; |
| 471 | int (*sys_func)(); |
| 472 | char *sys_name; |
| 473 | }; |
| 474 | |
| 475 | extern struct sysent *sysent; |
| 476 | extern int nsyscalls; |
| 477 | |
| 478 | extern char **errnoent; |
| 479 | extern int nerrnos; |
| 480 | |
| 481 | struct ioctlent { |
| 482 | char *doth; |
| 483 | char *symbol; |
| 484 | unsigned long code; |
| 485 | }; |
| 486 | |
| 487 | extern struct ioctlent *ioctlent; |
| 488 | extern int nioctlent; |
| 489 | |
| 490 | extern char **signalent; |
| 491 | extern int nsignals; |
| 492 | |
| 493 | extern struct ioctlent *ioctlent; |
| 494 | extern int nioctlents; |
| 495 | extern char **signalent; |
| 496 | extern int nsignals; |
| 497 | |
| 498 | extern struct ioctlent ioctlent0[]; |
| 499 | extern int nioctlents0; |
| 500 | extern char *signalent0[]; |
| 501 | extern int nsignals0; |
| 502 | |
| 503 | #if SUPPORTED_PERSONALITIES >= 2 |
| 504 | extern struct ioctlent ioctlent1[]; |
| 505 | extern int nioctlents1; |
| 506 | extern char *signalent1[]; |
| 507 | extern int nsignals1; |
| 508 | #endif /* SUPPORTED_PERSONALITIES >= 2 */ |
| 509 | |
| 510 | #if SUPPORTED_PERSONALITIES >= 3 |
| 511 | extern struct ioctlent ioctlent2[]; |
| 512 | extern int nioctlents2; |
| 513 | extern char *signalent2[]; |
| 514 | extern int nsignals2; |
| 515 | #endif /* SUPPORTED_PERSONALITIES >= 3 */ |
John Hughes | bdf48f5 | 2001-03-06 15:08:09 +0000 | [diff] [blame] | 516 | |
John Hughes | 5a826b8 | 2001-03-07 13:21:24 +0000 | [diff] [blame] | 517 | #if FREEBSD |
| 518 | /* ARRGH! off_t args are aligned on 64 bit boundaries! */ |
| 519 | #define ALIGN64(tcp,arg) \ |
| 520 | do { \ |
| 521 | if (arg % 2) \ |
| 522 | memmove (&tcp->u_arg[arg], &tcp->u_arg[arg + 1], \ |
| 523 | (tcp->u_nargs - arg - 1) * sizeof tcp->u_arg[0]); \ |
| 524 | } while (0) |
| 525 | #else |
| 526 | #define ALIGN64(tcp,arg) do { } while (0) |
| 527 | #endif |
| 528 | |
John Hughes | 0c79e01 | 2001-03-08 14:40:06 +0000 | [diff] [blame] | 529 | #if HAVE_LONG_LONG |
John Hughes | 5a826b8 | 2001-03-07 13:21:24 +0000 | [diff] [blame] | 530 | |
John Hughes | bdf48f5 | 2001-03-06 15:08:09 +0000 | [diff] [blame] | 531 | /* _l refers to the lower numbered u_arg, |
| 532 | * _h refers to the higher numbered u_arg |
| 533 | */ |
John Hughes | 5a826b8 | 2001-03-07 13:21:24 +0000 | [diff] [blame] | 534 | |
John Hughes | b8a85a4 | 2001-03-28 08:05:27 +0000 | [diff] [blame] | 535 | #if HAVE_LITTLE_ENDIAN_LONG_LONG |
John Hughes | 0c79e01 | 2001-03-08 14:40:06 +0000 | [diff] [blame] | 536 | #define LONG_LONG(_l,_h) \ |
Wichert Akkerman | 7ab47b6 | 2002-03-31 19:00:02 +0000 | [diff] [blame] | 537 | ((long long)((unsigned long long)(unsigned)(_l) | ((unsigned long long)(_h)<<32))) |
John Hughes | bdf48f5 | 2001-03-06 15:08:09 +0000 | [diff] [blame] | 538 | #else |
John Hughes | 0c79e01 | 2001-03-08 14:40:06 +0000 | [diff] [blame] | 539 | #define LONG_LONG(_l,_h) \ |
Wichert Akkerman | 7ab47b6 | 2002-03-31 19:00:02 +0000 | [diff] [blame] | 540 | ((long long)((unsigned long long)(unsigned)(_h) | ((unsigned long long)(_l)<<32))) |
John Hughes | bdf48f5 | 2001-03-06 15:08:09 +0000 | [diff] [blame] | 541 | #endif |
| 542 | #endif |
Wichert Akkerman | 7b3346b | 2001-10-09 23:47:38 +0000 | [diff] [blame] | 543 | |
| 544 | #ifdef IA64 |
| 545 | extern long ia32; |
| 546 | #endif |