]> granicus.if.org Git - strace/commitdiff
Maintain separate print column for each process
authorAndreas Schwab <schwab@redhat.com>
Tue, 27 Oct 2009 15:27:13 +0000 (16:27 +0100)
committerAndreas Schwab <schwab@redhat.com>
Tue, 27 Oct 2009 15:30:41 +0000 (16:30 +0100)
* 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.

defs.h
strace.c

diff --git a/defs.h b/defs.h
index e5e920b239b131253304e0b34f821a8db1e8e9b5..5bcaa070448c03a86bee87c64239a0d25f792e67 100644 (file)
--- 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 */
index 6765ba3cce390cc334386dcd6fa7c8fd11c4e871..7294e8ee1ef5572059c8a79cfc5edb77438c0aae 100644 (file)
--- 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 <stdarg.h>
 #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
-                              ? "<writing to pipe>" : outfname);
-               else
+               if (n < 0) {
+                       if (outf != stderr)
+                               perror(outfname == NULL
+                                      ? "<writing to pipe>" : outfname);
+               } else
                        curcol += n;
        }
        va_end(args);