[PATCH] Maintain separate print column for each process
Andreas Schwab
schwab at redhat.com
Tue Oct 27 15:32:58 UTC 2009
When the trace output goes to separate files (-ff) each process needs to
maintain its own print column.
Andreas.
>From ccdff481c086611488c5df70550fcf8fe907e7af Mon Sep 17 00:00:00 2001
From: Andreas Schwab <schwab at redhat.com>
Date: Tue, 27 Oct 2009 16:27:13 +0100
Subject: [PATCH] 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.
---
defs.h | 1 +
strace.c | 19 +++++++++++++------
2 files changed, 14 insertions(+), 6 deletions(-)
diff --git a/defs.h b/defs.h
index e5e920b..5bcaa07 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 6765ba3..7294e8e 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 <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);
--
1.6.5.1
--
Andreas Schwab, schwab at redhat.com
GPG Key fingerprint = D4E8 DBE3 3813 BB5D FA84 5EC7 45C6 250E 6F00 984E
"And now for something completely different."
More information about the Strace-devel
mailing list