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 e5e920b..5bcaa07 100644
--- a/defs.h
+++ b/defs.h
@@ -321,6 +321,7 @@
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 6765ba3..7294e8e 100644
--- a/strace.c
+++ b/strace.c
@@ -113,6 +113,7 @@
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 @@
#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 @@
/* set current output file */
outf = tcp->outf;
+ curcol = tcp->curcol;
if (cflag) {
struct timeval stime;
@@ -2185,6 +2188,8 @@
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 @@
}
/* 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 @@
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 @@
#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_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);