Tidy up order of includes; make bool variables explicit.

Bool variables are more compact in data and (on x86) on code too:

   text	   data	    bss	    dec	    hex	filename
 237950	    676	  19044	 257670	  3ee86	strace.before
 237838	    676	  19012	 257526	  3edf6	strace

* defs.h: Group library includes at the top of the file.
Rename dtime to Tflag, debug to debug_flag.
Change debug_flag,Tflag,qflag,not_failing_only,show_fd_path,tracing_paths
variable declarations from int to bool.
* strace.c: Change corresponding definitions. Do the same for static
variables iflag,rflag,print_pid_pfx.
Rename dtime to Tflag, debug to debug_flag.
* syscall.c: Rename dtime to Tflag, debug to debug_flag.

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
This commit is contained in:
Denys Vlasenko 2012-03-15 12:49:52 +01:00
parent b859e14d20
commit a50d2a87a1
3 changed files with 104 additions and 102 deletions

83
defs.h
View File

@ -32,19 +32,35 @@
#ifdef HAVE_CONFIG_H
# include "config.h"
#endif
#ifdef MIPS
# include <sgidefs.h>
#endif
#include <features.h>
#ifdef _LARGEFILE64_SOURCE
/* This is the macro everything checks before using foo64 names. */
# ifndef _LFS64_LARGEFILE
# define _LFS64_LARGEFILE 1
# endif
#endif
#ifdef MIPS
# include <sgidefs.h>
#endif
#include <features.h>
#include <sys/types.h>
#include <unistd.h>
#include <stdlib.h>
#include <stdio.h>
#include <ctype.h>
#include <string.h>
#include <time.h>
#include <sys/time.h>
#include <errno.h>
#include <sys/syscall.h>
#ifdef HAVE_STDBOOL_H
# include <stdbool.h>
#endif
#ifdef STDC_HEADERS
# include <stddef.h>
#endif
#ifdef HAVE_SIGINFO_T
# include <signal.h>
#endif
/* Configuration section */
#ifndef MAX_QUALS
@ -61,8 +77,8 @@
#ifndef DEFAULT_ACOLUMN
# define DEFAULT_ACOLUMN 40 /* default alignment column for results */
#endif
/* Maximum number of args to a syscall.
/*
* Maximum number of args to a syscall.
*
* Make sure that all entries in all syscallent.h files have nargs <= MAX_ARGS!
* linux/<ARCH>/syscallent.h: all have nargs <= 6.
@ -70,31 +86,9 @@
#ifndef MAX_ARGS
# define MAX_ARGS 6
#endif
/* default sorting method for call profiling */
#ifndef DEFAULT_SORTBY
# define DEFAULT_SORTBY "time" /* default sorting method for call profiling */
#endif
#include <sys/types.h>
#include <unistd.h>
#include <stdlib.h>
#include <stdio.h>
#include <ctype.h>
#include <string.h>
#include <time.h>
#include <sys/time.h>
#include <errno.h>
#ifdef HAVE_STDBOOL_H
# include <stdbool.h>
#endif
#ifdef STDC_HEADERS
# include <stddef.h>
#endif /* STDC_HEADERS */
#ifdef HAVE_SIGINFO_T
# include <signal.h>
# define DEFAULT_SORTBY "time"
#endif
#if defined(SPARC) || defined(SPARC64)
@ -372,7 +366,6 @@ struct tcb {
*/
# define TCB_WAITEXECVE 04000
#endif
#include <sys/syscall.h>
/* qualifier flags */
#define QUAL_TRACE 0001 /* this system call should be traced */
@ -436,13 +429,19 @@ typedef enum {
CFLAG_ONLY_STATS,
CFLAG_BOTH
} cflag_t;
extern int *qual_flags;
extern int debug, followfork;
extern unsigned int ptrace_setoptions;
extern int dtime, xflag, qflag;
extern cflag_t cflag;
extern int max_strlen;
extern int *qual_flags;
extern bool debug_flag;
extern bool Tflag;
extern bool qflag;
extern bool not_failing_only;
extern bool show_fd_path;
extern bool tracing_paths;
extern unsigned int xflag;
extern unsigned int followfork;
extern unsigned int ptrace_setoptions;
extern unsigned int max_strlen;
enum bitness_t { BITNESS_CURRENT = 0, BITNESS_32 };
void error_msg(const char *fmt, ...) __attribute__ ((format(printf, 1, 2)));
@ -644,7 +643,3 @@ extern int printllval(struct tcb *, const char *, int);
#ifdef IA64
extern long ia32;
#endif
extern int not_failing_only;
extern int show_fd_path;
extern int tracing_paths;

View File

@ -46,34 +46,42 @@
#include <string.h>
#include <dirent.h>
#include <sys/utsname.h>
#include <asm/unistd.h>
#if defined(IA64)
# include <asm/ptrace_offsets.h>
#endif
/* In some libc, these aren't declared. Do it ourself: */
extern char **environ;
extern int optind;
extern char *optarg;
# include <asm/unistd.h>
# if defined __NR_tkill
#if defined __NR_tkill
# define my_tkill(tid, sig) syscall(__NR_tkill, (tid), (sig))
# else
#else
/* kill() may choose arbitrarily the target task of the process group
while we later wait on a that specific TID. PID process waits become
TID task specific waits for a process under ptrace(2). */
# warning "Neither tkill(2) nor tgkill(2) available, risk of strace hangs!"
# define my_tkill(tid, sig) kill((tid), (sig))
# endif
#if defined(IA64)
# include <asm/ptrace_offsets.h>
#endif
extern char **environ;
extern int optind;
extern char *optarg;
#undef KERNEL_VERSION
#define KERNEL_VERSION(a,b,c) (((a) << 16) + ((b) << 8) + (c))
int debug = 0, followfork = 0;
cflag_t cflag = CFLAG_NONE;
unsigned int followfork = 0;
unsigned int ptrace_setoptions = 0;
unsigned int xflag = 0;
bool debug_flag = 0;
bool Tflag = 0;
bool qflag = 0;
/* Which WSTOPSIG(status) value marks syscall traps? */
static unsigned int syscall_trap_sig = SIGTRAP;
int dtime = 0, xflag = 0, qflag = 0;
cflag_t cflag = CFLAG_NONE;
static int iflag = 0, rflag = 0, tflag = 0;
static int print_pid_pfx = 0;
static unsigned int tflag = 0;
static bool iflag = 0;
static bool rflag = 0;
static bool print_pid_pfx = 0;
/* -I n */
enum {
@ -111,13 +119,13 @@ static int post_attach_sigstop = TCB_IGNORE_ONE_SIGSTOP;
#endif
/* Sometimes we want to print only succeeding syscalls. */
int not_failing_only = 0;
bool not_failing_only = 0;
/* Show path associated with fd arguments */
int show_fd_path = 0;
bool show_fd_path = 0;
/* are we filtering traces based on paths? */
int tracing_paths = 0;
bool tracing_paths = 0;
static int exit_code = 0;
static int strace_child = 0;
@ -127,13 +135,13 @@ static char *username = NULL;
static uid_t run_uid;
static gid_t run_gid;
int max_strlen = DEFAULT_STRLEN;
static int acolumn = DEFAULT_ACOLUMN;
unsigned int max_strlen = DEFAULT_STRLEN;
static unsigned int acolumn = DEFAULT_ACOLUMN;
static char *acolumn_spaces;
static char *outfname = NULL;
static FILE *outf;
struct tcb *printing_tcp = NULL;
static int curcol;
static unsigned int curcol;
static struct tcb **tcbtab;
static unsigned int nprocs, tcbtabsize;
static const char *progname;
@ -657,11 +665,11 @@ startup_attach(void)
++ntid;
if (ptrace_attach_or_seize(tid) < 0) {
++nerr;
if (debug)
if (debug_flag)
fprintf(stderr, "attach to pid %d failed\n", tid);
continue;
}
if (debug)
if (debug_flag)
fprintf(stderr, "attach to pid %d succeeded\n", tid);
cur_tcp = tcp;
if (tid != tcp->pid)
@ -703,7 +711,7 @@ startup_attach(void)
continue;
}
tcp->flags |= TCB_ATTACHED | TCB_STARTUP | post_attach_sigstop;
if (debug)
if (debug_flag)
fprintf(stderr, "attach to pid %d (main) succeeded\n", tcp->pid);
if (daemonized_tracer) {
@ -1004,7 +1012,7 @@ test_ptrace_setoptions_followfork(void)
}
if (expected_grandchild && expected_grandchild == found_grandchild) {
ptrace_setoptions |= test_options;
if (debug)
if (debug_flag)
fprintf(stderr, "ptrace_setoptions = %#x\n",
ptrace_setoptions);
return;
@ -1099,7 +1107,7 @@ test_ptrace_setoptions_for_all(void)
if (it_worked) {
syscall_trap_sig = (SIGTRAP | 0x80);
ptrace_setoptions |= test_options;
if (debug)
if (debug_flag)
fprintf(stderr, "ptrace_setoptions = %#x\n",
ptrace_setoptions);
return;
@ -1130,7 +1138,7 @@ test_ptrace_seize(void)
*/
if (ptrace(PTRACE_SEIZE, pid, 0, PTRACE_SEIZE_DEVEL) == 0) {
post_attach_sigstop = 0; /* this sets use_seize to 1 */
} else if (debug) {
} else if (debug_flag) {
fprintf(stderr, "PTRACE_SEIZE doesn't work\n");
}
@ -1227,7 +1235,7 @@ init(int argc, char *argv[])
cflag = CFLAG_BOTH;
break;
case 'd':
debug++;
debug_flag = 1;
break;
case 'D':
daemonized_tracer = 1;
@ -1242,20 +1250,19 @@ init(int argc, char *argv[])
usage(stdout, 0);
break;
case 'i':
iflag++;
iflag = 1;
break;
case 'q':
qflag++;
qflag = 1;
break;
case 'r':
rflag++;
tflag++;
break;
rflag = 1;
/* fall through to tflag++ */
case 't':
tflag++;
break;
case 'T':
dtime++;
Tflag = 1;
break;
case 'x':
xflag++;
@ -1508,7 +1515,7 @@ alloc_tcb(int pid, int command_options_parsed)
tcp->currpers = current_personality;
#endif
nprocs++;
if (debug)
if (debug_flag)
fprintf(stderr, "new tcb for pid %d, active tcbs:%d\n", tcp->pid, nprocs);
if (command_options_parsed)
newoutf(tcp);
@ -1542,7 +1549,7 @@ droptcb(struct tcb *tcp)
return;
nprocs--;
if (debug)
if (debug_flag)
fprintf(stderr, "dropped tcb for pid %d, %d remain\n", tcp->pid, nprocs);
if (printing_tcp == tcp)
@ -1680,7 +1687,7 @@ cleanup(void)
tcp = tcbtab[i];
if (!(tcp->flags & TCB_INUSE))
continue;
if (debug)
if (debug_flag)
fprintf(stderr,
"cleanup: looking at pid %u\n", tcp->pid);
if (tcp->flags & TCB_STRACE_CHILD) {
@ -1814,7 +1821,7 @@ trace(void)
}
event = ((unsigned)status >> 16);
if (debug) {
if (debug_flag) {
char buf[sizeof("WIFEXITED,exitcode=%u") + sizeof(int)*3 /*paranoia:*/ + 16];
char evbuf[sizeof(",PTRACE_EVENT_?? (%u)") + sizeof(int)*3 /*paranoia:*/ + 16];
strcpy(buf, "???");
@ -1988,7 +1995,7 @@ trace(void)
/* Is this the very first time we see this tracee stopped? */
if (tcp->flags & TCB_STARTUP) {
if (debug)
if (debug_flag)
fprintf(stderr, "pid %d has TCB_STARTUP, initializing it\n", tcp->pid);
tcp->flags &= ~TCB_STARTUP;
if (tcp->flags & TCB_BPTSET) {
@ -2004,7 +2011,7 @@ trace(void)
}
}
if (ptrace_setoptions) {
if (debug)
if (debug_flag)
fprintf(stderr, "setting opts %x on pid %d\n", ptrace_setoptions, tcp->pid);
if (ptrace(PTRACE_SETOPTIONS, tcp->pid, NULL, ptrace_setoptions) < 0) {
if (errno != ESRCH) {
@ -2045,7 +2052,7 @@ trace(void)
* just before the process takes a signal.
*/
if (sig == SIGSTOP && (tcp->flags & TCB_IGNORE_ONE_SIGSTOP)) {
if (debug)
if (debug_flag)
fprintf(stderr, "ignored SIGSTOP on pid %d\n", tcp->pid);
tcp->flags &= ~TCB_IGNORE_ONE_SIGSTOP;
goto restart_tracee_with_sig_0;

View File

@ -970,7 +970,7 @@ get_scno(struct tcb *tcp)
scno = r2;
if (!SCNO_IN_RANGE(scno)) {
if (a3 == 0 || a3 == -1) {
if (debug)
if (debug_flag)
fprintf(stderr, "stray syscall exit: v0 = %ld\n", scno);
return 0;
}
@ -983,7 +983,7 @@ get_scno(struct tcb *tcp)
if (!SCNO_IN_RANGE(scno)) {
if (a3 == 0 || a3 == -1) {
if (debug)
if (debug_flag)
fprintf(stderr, "stray syscall exit: v0 = %ld\n", scno);
return 0;
}
@ -1000,7 +1000,7 @@ get_scno(struct tcb *tcp)
*/
if (!SCNO_IN_RANGE(scno)) {
if (a3 == 0 || a3 == -1) {
if (debug)
if (debug_flag)
fprintf(stderr, "stray syscall exit: r0 = %ld\n", scno);
return 0;
}
@ -1081,7 +1081,7 @@ get_scno(struct tcb *tcp)
glibc to issue bogus negative syscall numbers. So for
our purposes, make strace print what it *should* have been */
long correct_scno = (scno & 0xff);
if (debug)
if (debug_flag)
fprintf(stderr,
"Detected glibc bug: bogus system call"
" number = %ld, correcting to %ld\n",
@ -1131,7 +1131,7 @@ syscall_fixup_on_sysenter(struct tcb *tcp)
/* A common case of "not a syscall entry" is post-execve SIGTRAP */
#if defined(I386)
if (i386_regs.eax != -ENOSYS) {
if (debug)
if (debug_flag)
fprintf(stderr, "not a syscall entry (eax = %ld)\n", i386_regs.eax);
return 0;
}
@ -1141,7 +1141,7 @@ syscall_fixup_on_sysenter(struct tcb *tcp)
if (current_personality == 1)
rax = (int)rax; /* sign extend from 32 bits */
if (rax != -ENOSYS) {
if (debug)
if (debug_flag)
fprintf(stderr, "not a syscall entry (rax = %ld)\n", rax);
return 0;
}
@ -1156,7 +1156,7 @@ syscall_fixup_on_sysenter(struct tcb *tcp)
if (syscall_mode != -ENOSYS)
syscall_mode = tcp->scno;
if (gpr2 != syscall_mode) {
if (debug)
if (debug_flag)
fprintf(stderr, "not a syscall entry (gpr2 = %ld)\n", gpr2);
return 0;
}
@ -1165,7 +1165,7 @@ syscall_fixup_on_sysenter(struct tcb *tcp)
if (upeek(tcp, 4*PT_D0, &d0) < 0)
return -1;
if (d0 != -ENOSYS) {
if (debug)
if (debug_flag)
fprintf(stderr, "not a syscall entry (d0 = %ld)\n", d0);
return 0;
}
@ -1175,7 +1175,7 @@ syscall_fixup_on_sysenter(struct tcb *tcp)
if (upeek(tcp, PT_R8, &r8) < 0)
return -1;
if (ia32 && r8 != -ENOSYS) {
if (debug)
if (debug_flag)
fprintf(stderr, "not a syscall entry (r8 = %ld)\n", r8);
return 0;
}
@ -1183,7 +1183,7 @@ syscall_fixup_on_sysenter(struct tcb *tcp)
if (upeek(tcp, 4*PT_R10, &r10) < 0)
return -1;
if (r10 != -ENOSYS) {
if (debug)
if (debug_flag)
fprintf(stderr, "not a syscall entry (r10 = %ld)\n", r10);
return 0;
}
@ -1191,7 +1191,7 @@ syscall_fixup_on_sysenter(struct tcb *tcp)
if (upeek(tcp, 3 * 4, &r3) < 0)
return -1;
if (r3 != -ENOSYS) {
if (debug)
if (debug_flag)
fprintf(stderr, "not a syscall entry (r3 = %ld)\n", r3);
return 0;
}
@ -1522,7 +1522,7 @@ trace_syscall_entering(struct tcb *tcp)
ret:
tcp->flags |= TCB_INSYSCALL;
/* Measure the entrance time as late as possible to avoid errors. */
if (dtime || cflag)
if (Tflag || cflag)
gettimeofday(&tcp->etime, NULL);
return res;
}
@ -1890,7 +1890,7 @@ trace_syscall_exiting(struct tcb *tcp)
long u_error;
/* Measure the exit time as early as possible to avoid errors. */
if (dtime || cflag)
if (Tflag || cflag)
gettimeofday(&tv, NULL);
#if SUPPORTED_PERSONALITIES > 1
@ -2088,7 +2088,7 @@ trace_syscall_exiting(struct tcb *tcp)
if ((sys_res & RVAL_STR) && tcp->auxstr)
tprintf(" (%s)", tcp->auxstr);
}
if (dtime) {
if (Tflag) {
tv_sub(&tv, &tv, &tcp->etime);
tprintf(" <%ld.%06ld>",
(long) tv.tv_sec, (long) tv.tv_usec);