From: Andreas Schwab Date: Tue, 27 Oct 2009 15:27:13 +0000 (+0100) Subject: Maintain separate print column for each process X-Git-Tag: v4.5.20~39 X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=ccdff481c086611488c5df70550fcf8fe907e7af;p=strace Maintain separate print column for each process * defs.h (struct tcp): Add curcol. * strace.c: (alloc_tcb): Initialize it. (trace): Use curcol from current process and save it before continuing. (tprintf): Don't modify curcol on output error. --- diff --git a/defs.h b/defs.h index e5e920b2..5bcaa070 100644 --- a/defs.h +++ b/defs.h @@ -321,6 +321,7 @@ struct tcb { long long u_lrval; /* long long return value */ #endif FILE *outf; /* Output file for this process */ + int curcol; /* Output column for this process */ const char *auxstr; /* Auxiliary info from syscall (see RVAL_STR) */ struct timeval stime; /* System time usage as of last process wait */ struct timeval dtime; /* Delta for system time usage */ diff --git a/strace.c b/strace.c index 6765ba3c..7294e8ee 100644 --- a/strace.c +++ b/strace.c @@ -113,6 +113,7 @@ int acolumn = DEFAULT_ACOLUMN; int max_strlen = DEFAULT_STRLEN; static char *outfname = NULL; FILE *outf; +static int curcol; struct tcb **tcbtab; unsigned int nprocs, tcbtabsize; char *progname; @@ -1016,6 +1017,7 @@ alloc_tcb(int pid, int command_options_parsed) #endif tcp->flags = TCB_INUSE | TCB_STARTUP; tcp->outf = outf; /* Initialise to current out file */ + tcp->curcol = 0; tcp->stime.tv_sec = 0; tcp->stime.tv_usec = 0; tcp->pfd = -1; @@ -2109,6 +2111,7 @@ trace() /* set current output file */ outf = tcp->outf; + curcol = tcp->curcol; if (cflag) { struct timeval stime; @@ -2185,6 +2188,8 @@ trace() exit(1); break; } + /* Remember current print column before continuing. */ + tcp->curcol = curcol; arg = 0; #ifndef FREEBSD if (IOCTL (tcp->pfd, PIOCRUN, &arg) < 0) { @@ -2375,6 +2380,7 @@ Process %d attached (waiting for parent)\n", } /* set current output file */ outf = tcp->outf; + curcol = tcp->curcol; if (cflag) { #ifdef LINUX tv_sub(&tcp->dtime, &ru.ru_stime, &tcp->stime); @@ -2593,6 +2599,8 @@ Process %d attached (waiting for parent)\n", continue; } tracing: + /* Remember current print column before continuing. */ + tcp->curcol = curcol; if (ptrace_restart(PTRACE_SYSCALL, tcp, 0) < 0) { cleanup(); return -1; @@ -2603,8 +2611,6 @@ Process %d attached (waiting for parent)\n", #endif /* !USE_PROCFS */ -static int curcol; - #ifdef __STDC__ #include #define VA_START(a, b) va_start(a, b) @@ -2627,10 +2633,11 @@ va_dcl VA_START(args, fmt); if (outf) { int n = vfprintf(outf, fmt, args); - if (n < 0 && outf != stderr) - perror(outfname == NULL - ? "" : outfname); - else + if (n < 0) { + if (outf != stderr) + perror(outfname == NULL + ? "" : outfname); + } else curcol += n; } va_end(args);