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>
7 * Redistribution and use in source and binary forms, with or without
8 * modification, are permitted provided that the following conditions
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.
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.
40 /* configuration section */
42 #if defined(linux) && defined(MIPS)
43 #define MAX_QUALS 4999 /* maximum number of syscalls, signals, etc. */
45 #define MAX_QUALS 2048 /* maximum number of syscalls, signals, etc. */
48 #define MAX_PROCS 64 /* maximum number of processes tracable */
50 #ifndef DEFAULT_STRLEN
51 #define DEFAULT_STRLEN 32 /* default maximum # of bytes printed in
52 `printstr', change with `-s' switch */
54 #ifndef DEFAULT_ACOLUMN
55 #define DEFAULT_ACOLUMN 40 /* default alignment column for results */
58 #define MAX_ARGS 32 /* maximum number of args to a syscall */
60 #ifndef DEFAULT_SORTBY
61 #define DEFAULT_SORTBY "time" /* default sorting method for call profiling */
64 #include <sys/types.h>
75 #endif /* STDC_HEADERS */
87 #include <sys/procfs.h>
92 #if defined(LINUXSPARC) && defined(__GLIBC__)
93 #include <sys/ptrace.h>
95 /* Work around awkward prototype in ptrace.h. */
96 #define ptrace xptrace
97 #include <sys/ptrace.h>
101 #include <asm/ptrace.h>
107 #define ORIG_EAX PT_ORIG_R3
111 extern long ptrace(int, int, char *, long);
113 extern int ptrace(int, int, char *, int, ...);
115 #else /* !__STDC__ */
117 #endif /* !__STDC__ */
118 #endif /* !LINUXSPARC */
122 #if !defined(__GLIBC__)
123 #define PTRACE_PEEKUSER PTRACE_PEEKUSR
124 #define PTRACE_POKEUSER PTRACE_POKEUSR
142 #define SUPPORTED_PERSONALITIES 1
143 #define DEFAULT_PERSONALITY 0
146 #include <linux/a.out.h>
148 #undef SUPPORTED_PERSONALITIES
149 #define SUPPORTED_PERSONALITIES 2
150 #endif /* LINUXSPARC */
154 #ifdef HAVE_MP_PROCFS
155 extern int mp_ioctl (int f, int c, void *a, int s);
156 #define IOCTL(f,c,a) mp_ioctl (f, c, a, sizeof *a)
157 #define IOCTL_STATUS(t) \
158 pread (t->pfd_stat, &t->status, sizeof t->status, 0)
159 #define IOCTL_WSTOP(t) \
160 (IOCTL (t->pfd, PCWSTOP, NULL) < 0 ? -1 : \
162 #define PR_WHY pr_lwp.pr_why
163 #define PR_WHAT pr_lwp.pr_what
164 #define PR_REG pr_lwp.pr_context.uc_mcontext.gregs
165 #define PR_FLAGS pr_lwp.pr_flags
166 #define PIOCSTIP PCSTOP
167 #define PIOCSET PCSET
168 #define PIOCRESET PCRESET
169 #define PIOCSTRACE PCSTRACE
170 #define PIOCSFAULT PCSFAULT
171 #define PIOCWSTOP PCWSTOP
172 #define PIOCSTOP PCSTOP
173 #define PIOCSENTRY PCSENTRY
174 #define PIOCSEXIT PCSEXIT
175 #define PIOCRUN PCRUN
178 #define IOCTL_STATUS(t) ioctl (t->pfd, PIOCSTATUS, &t->status)
179 #define IOCTL_WSTOP(t) ioctl (t->pfd, PIOCWSTOP, &t->status)
180 #define PR_WHY pr_why
181 #define PR_WHAT pr_what
182 #define PR_REG pr_reg
183 #define PR_FLAGS pr_flags
187 /* Trace Control Block */
189 short flags; /* See below for TCB_ values */
190 int pid; /* Process Id of this entry */
191 long scno; /* System call number */
192 int u_nargs; /* System call arguments */
193 long u_arg[MAX_ARGS]; /* System call arguments */
194 int u_error; /* Error code */
195 long u_rval; /* (first) return value */
196 FILE *outf; /* Output file for this process */
197 char *auxstr; /* Auxiliary info from syscall (see RVAL_STR) */
198 struct timeval stime; /* System time usage as of last process wait */
199 struct timeval dtime; /* Delta for system time usage */
200 struct timeval etime; /* Syscall entry time */
201 /* Support for tracing forked processes */
202 struct tcb *parent; /* Parent of this process */
203 int nchildren; /* # of traced children */
204 int waitpid; /* pid(s) this process is waiting for */
205 /* (1st arg of wait4()) */
206 long baddr; /* `Breakpoint' address */
207 long inst[2]; /* Instructions on above */
208 int pfd; /* proc file descriptor */
210 #ifdef HAVE_MP_PROCFS
215 prstatus_t status; /* procfs status structure */
221 #define TCB_STARTUP 00001 /* We have just begun ptracing this process */
222 #define TCB_INUSE 00002 /* This table entry is in use */
223 #define TCB_INSYSCALL 00004 /* A system call is in progress */
224 #define TCB_ATTACHED 00010 /* Process is not our own child */
225 #define TCB_EXITING 00020 /* As far as we know, this process is exiting */
226 #define TCB_SUSPENDED 00040 /* Process has done a wait(4), that can
227 not be allowed to complete just now */
228 #define TCB_BPTSET 00100 /* "Breakpoint" set after fork(2) */
229 #define TCB_SIGTRAPPED 00200 /* Process wanted to block SIGTRAP */
230 #define TCB_FOLLOWFORK 00400 /* Process should have forks followed */
231 #define TCB_REPRINT 01000 /* We should reprint this syscall on exit */
233 #if defined(ALPHA) || defined(SPARC) || defined(POWERPC)
234 #define TCB_WAITEXECVE 02000 /* ignore SIGTRAP after exceve */
238 /* qualifier flags */
239 #define QUAL_TRACE 0001 /* this system call should be traced */
240 #define QUAL_ABBREV 0002 /* abbreviate the structures of this syscall */
241 #define QUAL_VERBOSE 0004 /* decode the structures of this syscall */
242 #define QUAL_RAW 0010 /* print all args in hex for this syscall */
243 #define QUAL_SIGNAL 0020 /* report events with this signal */
244 #define QUAL_FAULT 0040 /* report events with this fault */
245 #define QUAL_READ 0100 /* dump data read on this file descriptor */
246 #define QUAL_WRITE 0200 /* dump data written to this file descriptor */
248 #define entering(tcp) (!((tcp)->flags & TCB_INSYSCALL))
249 #define exiting(tcp) ((tcp)->flags & TCB_INSYSCALL)
250 #define syserror(tcp) ((tcp)->u_error != 0)
251 #define verbose(tcp) (qual_flags[(tcp)->scno] & QUAL_VERBOSE)
252 #define abbrev(tcp) (qual_flags[(tcp)->scno] & QUAL_ABBREV)
253 #define waiting_parent(tcp) \
255 (tcp->parent->flags & TCB_SUSPENDED) && \
256 (tcp->parent->waitpid <= 0 || tcp->parent->waitpid == tcp->pid))
263 /* Format of syscall return values */
264 #define RVAL_DECIMAL 000 /* decimal format */
265 #define RVAL_HEX 001 /* hex format */
266 #define RVAL_OCTAL 002 /* octal format */
267 #define RVAL_UDECIMAL 003 /* unsigned decimal format */
268 #define RVAL_MASK 007 /* mask for these values */
270 #define RVAL_STR 010 /* Print `auxstr' field after return val */
271 #define RVAL_NONE 020 /* Print nothing */
274 #define offsetof(type, member) (((char *) &(((type *) NULL)->member)) - \
275 ((char *) (type *) NULL))
276 #endif /* !offsetof */
278 /* get offset of member within a user struct */
279 #define uoff(member) offsetof(struct user, member)
281 #define TRACE_FILE 001 /* Trace file-related syscalls. */
282 #define TRACE_IPC 002 /* Trace IPC-related syscalls. */
283 #define TRACE_NETWORK 004 /* Trace network-related syscalls. */
284 #define TRACE_PROCESS 010 /* Trace process-related syscalls. */
285 #define TRACE_SIGNAL 020 /* Trace signal-related syscalls. */
287 extern struct tcb tcbtab[];
288 extern int qual_flags[];
289 extern int debug, followfork, followvfork;
290 extern int rflag, tflag, dtime, cflag, xflag, qflag;
292 extern char *outfname;
294 extern int max_strlen;
295 extern struct tcb *tcp_last;
303 extern int set_personality P((int personality));
304 extern char *xlookup P((struct xlat *, int));
305 extern struct tcb *alloctcb P((int));
306 extern void droptcb P((struct tcb *));
308 extern void set_sortby P((char *));
309 extern void set_overhead P((int));
310 extern void qualify P((char *));
311 extern void newoutf P((struct tcb *));
312 extern int trace_syscall P((struct tcb *));
313 extern void printxval P((struct xlat *, int, char *));
314 extern int printargs P((struct tcb *));
315 extern int addflags P((struct xlat *, int));
316 extern int printflags P((struct xlat *, int));
317 extern int umoven P((struct tcb *, long, int, char *));
318 extern int umovestr P((struct tcb *, long, int, char *));
319 extern int upeek P((int, long, long *));
320 extern void dumpstr P((struct tcb *, long, int));
321 extern void string_quote P((char *str));
322 extern void printstr P((struct tcb *, long, int));
323 extern void printnum P((struct tcb *, long, char *));
324 extern void printpath P((struct tcb *, long));
325 extern void printpathn P((struct tcb *, long, int));
326 extern void printtv P((struct tcb *, long));
327 extern void printsock P((struct tcb *, long, int));
328 extern void printrusage P((struct tcb *, long));
329 extern int clearbpt P((struct tcb *));
330 extern int setbpt P((struct tcb *));
331 extern int sigishandled P((struct tcb *, int));
332 extern void printcall P((struct tcb *));
333 extern char *signame P((int));
334 extern void printsignal P((int));
335 extern void printleader P((struct tcb *));
336 extern void printtrailer P((struct tcb *));
337 extern void tabto P((int));
338 extern void call_summary P((FILE *));
339 extern void fake_execve P((struct tcb *, char *, char *[], char *[]));
340 extern void printtv32 P((struct tcb*, long));
343 extern int internal_clone P((struct tcb *));
345 extern int internal_fork P((struct tcb *));
346 extern int internal_exec P((struct tcb *));
347 extern int internal_wait P((struct tcb *));
348 extern int internal_exit P((struct tcb *));
350 extern char *ioctl_lookup P((long));
351 extern int ioctl_decode P((struct tcb *, long, long));
352 extern int term_ioctl P((struct tcb *, long, long));
353 extern int sock_ioctl P((struct tcb *, long, long));
354 extern int proc_ioctl P((struct tcb *, int, int));
355 extern int stream_ioctl P((struct tcb *, int, int));
357 extern void tv_tv P((struct timeval *, int, int));
358 extern int tv_nz P((struct timeval *));
359 extern int tv_cmp P((struct timeval *, struct timeval *));
360 extern double tv_float P((struct timeval *));
361 extern void tv_add P((struct timeval *, struct timeval *, struct timeval *));
362 extern void tv_sub P((struct timeval *, struct timeval *, struct timeval *));
363 extern void tv_mul P((struct timeval *, struct timeval *, int));
364 extern void tv_div P((struct timeval *, struct timeval *, int));
367 extern int fixvfork P((struct tcb *));
369 #if !(defined(LINUX) && !defined(SPARC))
370 extern long getrval2 P((struct tcb *));
373 extern int proc_open P((struct tcb *tcp, int attaching));
376 #define umove(pid, addr, objp) \
377 umoven((pid), (addr), sizeof *(objp), (char *) (objp))
381 extern void tprintf(const char *fmt, ...)
382 __attribute__ ((format (printf, 1, 2)));
384 extern void tprintf(const char *fmt, ...);
387 extern void tprintf();
390 #ifndef HAVE_STRERROR
391 const char *strerror P((int));
393 #ifndef HAVE_STRSIGNAL
394 const char *strsignal P((int));
397 extern int current_personality;
406 extern struct sysent *sysent;
407 extern int nsyscalls;
409 extern char **errnoent;
418 extern struct ioctlent *ioctlent;
419 extern int nioctlent;
421 extern char **signalent;
424 extern struct ioctlent *ioctlent;
425 extern int nioctlents;
426 extern char **signalent;
429 extern struct ioctlent ioctlent0[];
430 extern int nioctlents0;
431 extern char *signalent0[];
432 extern int nsignals0;
434 #if SUPPORTED_PERSONALITIES >= 2
435 extern struct ioctlent ioctlent1[];
436 extern int nioctlents1;
437 extern char *signalent1[];
438 extern int nsignals1;
439 #endif /* SUPPORTED_PERSONALITIES >= 2 */
441 #if SUPPORTED_PERSONALITIES >= 3
442 extern struct ioctlent ioctlent2[];
443 extern int nioctlents2;
444 extern char *signalent2[];
445 extern int nsignals2;
446 #endif /* SUPPORTED_PERSONALITIES >= 3 */