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.
This commit is contained in:
parent
7d9247e197
commit
ccdff481c0
1
defs.h
1
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 */
|
||||
|
19
strace.c
19
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);
|
||||
|
Loading…
x
Reference in New Issue
Block a user