]> granicus.if.org Git - strace/blob - defs.h
Linux/MIPS uses syscalls up to >4k, so set MAX_QUALS to 4999
[strace] / defs.h
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
32 #ifdef linux
33 #include <features.h>
34 #endif
35
36 #ifdef HAVE_CONFIG_H
37 #include "config.h"
38 #endif
39
40 /* configuration section */
41 #ifndef MAX_QUALS
42 #if defined(linux) && defined(MIPS)
43 #define MAX_QUALS       4999    /* maximum number of syscalls, signals, etc. */
44 #else
45 #define MAX_QUALS       2048    /* maximum number of syscalls, signals, etc. */
46 #endif
47 #ifndef MAX_PROCS
48 #define MAX_PROCS       64      /* maximum number of processes tracable */
49 #endif
50 #ifndef DEFAULT_STRLEN
51 #define DEFAULT_STRLEN  32      /* default maximum # of bytes printed in
52                                   `printstr', change with `-s' switch */
53 #endif
54 #ifndef DEFAULT_ACOLUMN
55 #define DEFAULT_ACOLUMN 40      /* default alignment column for results */
56 #endif
57 #ifndef MAX_ARGS
58 #define MAX_ARGS        32      /* maximum number of args to a syscall */
59 #endif
60 #ifndef DEFAULT_SORTBY
61 #define DEFAULT_SORTBY "time"   /* default sorting method for call profiling */
62 #endif
63
64 #include <sys/types.h>
65 #include <unistd.h>
66 #include <stdlib.h>
67 #include <stdio.h>
68 #include <ctype.h>
69 #include <string.h>
70 #include <sys/time.h>
71 #include <errno.h>
72
73 #ifdef STDC_HEADERS
74 #include <stddef.h>
75 #endif /* STDC_HEADERS */
76
77 #if defined(LINUX)
78 #  if defined(SPARC)
79 #     define LINUXSPARC
80 #  endif
81 #  if defined(ALPHA)
82 #     define LINUX_64BIT
83 #  endif
84 #endif 
85
86 #ifdef SVR4
87 #include <sys/procfs.h>
88 #ifdef HAVE_MP_PROCFS
89 #include <sys/uio.h>
90 #endif
91 #else /* !SVR4 */
92 #if defined(LINUXSPARC) && defined(__GLIBC__)
93 #include <sys/ptrace.h>
94 #else
95 /* Work around awkward prototype in ptrace.h. */
96 #define ptrace xptrace
97 #include <sys/ptrace.h>
98 #undef ptrace
99 #ifdef POWERPC
100 #define __KERNEL__
101 #include <asm/ptrace.h>
102 #undef __KERNEL__
103 /* TEMP */
104 #define UESP    PT_R1
105 #define EIP     PT_NIP
106 #define EAX     PT_R3
107 #define ORIG_EAX PT_ORIG_R3
108 #endif
109 #ifdef __STDC__
110 #ifdef LINUX
111 extern long ptrace(int, int, char *, long);
112 #else /* !LINUX */
113 extern int ptrace(int, int, char *, int, ...);
114 #endif /* !LINUX */
115 #else /* !__STDC__ */
116 extern int ptrace();
117 #endif /* !__STDC__ */
118 #endif /* !LINUXSPARC */
119 #endif /* !SVR4 */
120
121 #ifdef LINUX
122 #if !defined(__GLIBC__)
123 #define PTRACE_PEEKUSER PTRACE_PEEKUSR
124 #define PTRACE_POKEUSER PTRACE_POKEUSR
125 #endif
126 #ifdef ALPHA
127 #  define REG_R0 0
128 #  define REG_A0 16
129 #  define REG_A3 19
130 #  define REG_FP 30
131 #  define REG_PC 64
132 #endif /* ALPHA */
133 #ifdef MIPS
134 #  define REG_V0 2
135 #  define REG_A0 4
136 #  define REG_A3 7
137 #  define REG_SP 29
138 #  define REG_EPC 64
139 #endif /* MIPS */
140 #endif /* LINUX */
141
142 #define SUPPORTED_PERSONALITIES 1
143 #define DEFAULT_PERSONALITY 0
144
145 #ifdef LINUXSPARC
146 #include <linux/a.out.h>
147 #include <asm/psr.h>
148 #undef  SUPPORTED_PERSONALITIES
149 #define SUPPORTED_PERSONALITIES 2
150 #endif /* LINUXSPARC */
151
152
153 #ifdef SVR4
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 :               \
161          IOCTL_STATUS (t))
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
176 #else
177 #define IOCTL           ioctl
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
184 #endif
185 #endif
186
187 /* Trace Control Block */
188 struct tcb {
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 */
209 #ifdef SVR4
210 #ifdef HAVE_MP_PROCFS
211         int pfd_stat;
212         int pfd_as;
213         pstatus_t status;
214 #else
215         prstatus_t status;      /* procfs status structure */
216 #endif
217 #endif
218 };
219
220 /* TCB flags */
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 */
232 #ifdef LINUX
233 #if defined(ALPHA) || defined(SPARC) || defined(POWERPC)
234 #define TCB_WAITEXECVE  02000   /* ignore SIGTRAP after exceve */
235 #endif /* ALPHA */
236 #endif /* LINUX */
237
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 */
247
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) \
254                 (tcp->parent && \
255                 (tcp->parent->flags & TCB_SUSPENDED) && \
256                 (tcp->parent->waitpid <= 0 || tcp->parent->waitpid == tcp->pid))
257
258 struct xlat {
259         int val;
260         char *str;
261 };
262
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 */
269
270 #define RVAL_STR        010     /* Print `auxstr' field after return val */
271 #define RVAL_NONE       020     /* Print nothing */
272
273 #ifndef offsetof
274 #define offsetof(type, member)  (((char *) &(((type *) NULL)->member)) - \
275                                  ((char *) (type *) NULL))
276 #endif /* !offsetof */
277
278 /* get offset of member within a user struct */
279 #define uoff(member)    offsetof(struct user, member)
280
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. */
286
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;
291 extern int acolumn;
292 extern char *outfname;
293 extern int nprocs;
294 extern int max_strlen;
295 extern struct tcb *tcp_last;
296
297 #ifdef __STDC__
298 #define P(args) args
299 #else
300 #define P(args) ()
301 #endif
302
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 *));
307
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));
341
342 #ifdef LINUX
343 extern int internal_clone P((struct tcb *));
344 #endif
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 *));
349
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));
356
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));
365
366 #ifdef SUNOS4
367 extern int fixvfork P((struct tcb *));
368 #endif
369 #if !(defined(LINUX) && !defined(SPARC))
370 extern long getrval2 P((struct tcb *));
371 #endif
372 #ifdef SVR4
373 extern int proc_open P((struct tcb *tcp, int attaching));
374 #endif
375
376 #define umove(pid, addr, objp)  \
377         umoven((pid), (addr), sizeof *(objp), (char *) (objp))
378
379 #ifdef __STDC__
380 #ifdef __GNUC__
381 extern void tprintf(const char *fmt, ...)
382         __attribute__ ((format (printf, 1, 2)));
383 #else
384 extern void tprintf(const char *fmt, ...);
385 #endif
386 #else
387 extern void tprintf();
388 #endif
389
390 #ifndef HAVE_STRERROR
391 const char *strerror P((int));
392 #endif
393 #ifndef HAVE_STRSIGNAL
394 const char *strsignal P((int));
395 #endif
396
397 extern int current_personality;
398
399 struct sysent {
400         int     nargs;
401         int     sys_flags;
402         int     (*sys_func)();
403         char    *sys_name;
404 };
405
406 extern struct sysent *sysent;
407 extern int nsyscalls;
408
409 extern char **errnoent;
410 extern int nerrnos;
411
412 struct ioctlent {
413         char *doth;
414         char *symbol;
415         unsigned long code;
416 };
417
418 extern struct ioctlent *ioctlent;
419 extern int nioctlent;
420
421 extern char **signalent;
422 extern int nsignals;
423
424 extern struct ioctlent *ioctlent;
425 extern int nioctlents;
426 extern char **signalent;
427 extern int nsignals;
428
429 extern struct ioctlent ioctlent0[];
430 extern int nioctlents0;
431 extern char *signalent0[];
432 extern int nsignals0;
433
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 */
440
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 */