Eliminate code duplication in time printing, reduce a few static buffers
text data bss dec hex filename 238454 664 28772 267890 41672 strace.before 238106 664 28676 267446 414b6 strace * defs.h: Add TIMESPEC_TEXT_BUFSIZE and TIMEVAL_TEXT_BUFSIZE defines. Add 'int special' parameter to sprinttv(). * time.c (sprinttv): Add 'int special' parameter, and use it similarly to 'int special' parameter of printtv_bitness(). (printtv_bitness): Use sprinttv() instead of duplicating its code. (print_timespec): Use sprint_timespec() instead of duplicating its code. * desc.c (decode_select): Use TIMEVAL_TEXT_BUFSIZE instead of 128 when checking remaining buffer size. * net.c (sys_recvmsg): Use TIMESPEC_TEXT_BUFSIZE instead of 128 for static buffer size. * stream.c (decode_poll): Use TIMESPEC_TEXT_BUFSIZE instead of 128 when checking remaining buffer size. Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
This commit is contained in:
parent
b3c52cf02a
commit
a1d541ec56
4
defs.h
4
defs.h
@ -628,8 +628,10 @@ extern void printnum(struct tcb *, long, const char *);
|
|||||||
extern void printnum_int(struct tcb *, long, const char *);
|
extern void printnum_int(struct tcb *, long, const char *);
|
||||||
extern void printpath(struct tcb *, long);
|
extern void printpath(struct tcb *, long);
|
||||||
extern void printpathn(struct tcb *, long, int);
|
extern void printpathn(struct tcb *, long, int);
|
||||||
|
#define TIMESPEC_TEXT_BUFSIZE (sizeof(long)*3 * 2 + sizeof("{%u, %u}"))
|
||||||
|
#define TIMEVAL_TEXT_BUFSIZE TIMESPEC_TEXT_BUFSIZE
|
||||||
extern void printtv_bitness(struct tcb *, long, enum bitness_t, int);
|
extern void printtv_bitness(struct tcb *, long, enum bitness_t, int);
|
||||||
extern char *sprinttv(struct tcb *, long, enum bitness_t, char *);
|
extern char *sprinttv(char *, struct tcb *, long, enum bitness_t, int special);
|
||||||
extern void print_timespec(struct tcb *, long);
|
extern void print_timespec(struct tcb *, long);
|
||||||
extern void sprint_timespec(char *, struct tcb *, long);
|
extern void sprint_timespec(char *, struct tcb *, long);
|
||||||
#ifdef HAVE_SIGINFO_T
|
#ifdef HAVE_SIGINFO_T
|
||||||
|
4
desc.c
4
desc.c
@ -584,9 +584,9 @@ decode_select(struct tcb *tcp, long *args, enum bitness_t bitness)
|
|||||||
#ifdef LINUX
|
#ifdef LINUX
|
||||||
/* This contains no useful information on SunOS. */
|
/* This contains no useful information on SunOS. */
|
||||||
if (args[4]) {
|
if (args[4]) {
|
||||||
if (outptr < end_outstr - 128) {
|
if (outptr < end_outstr - (10 + TIMEVAL_TEXT_BUFSIZE)) {
|
||||||
outptr += sprintf(outptr, "%sleft ", sep);
|
outptr += sprintf(outptr, "%sleft ", sep);
|
||||||
outptr = sprinttv(tcp, args[4], bitness, outptr);
|
outptr = sprinttv(outptr, tcp, args[4], bitness, /*special:*/ 0);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
#endif /* LINUX */
|
#endif /* LINUX */
|
||||||
|
11
net.c
11
net.c
@ -1753,12 +1753,16 @@ sys_recvmsg(struct tcb *tcp)
|
|||||||
int
|
int
|
||||||
sys_recvmmsg(struct tcb *tcp)
|
sys_recvmmsg(struct tcb *tcp)
|
||||||
{
|
{
|
||||||
static char str[128];
|
/* +5 chars are for "left " prefix */
|
||||||
if (entering(tcp)) {
|
static char str[5 + TIMESPEC_TEXT_BUFSIZE];
|
||||||
|
|
||||||
|
if (entering(tcp)) {
|
||||||
tprintf("%ld, ", tcp->u_arg[0]);
|
tprintf("%ld, ", tcp->u_arg[0]);
|
||||||
if (verbose(tcp)) {
|
if (verbose(tcp)) {
|
||||||
sprint_timespec(str, tcp, tcp->u_arg[4]);
|
sprint_timespec(str, tcp, tcp->u_arg[4]);
|
||||||
|
/* Abusing tcp->auxstr as temp storage.
|
||||||
|
* Will be used and freed on syscall exit.
|
||||||
|
*/
|
||||||
tcp->auxstr = strdup(str);
|
tcp->auxstr = strdup(str);
|
||||||
} else {
|
} else {
|
||||||
tprintf("%#lx, %ld, ", tcp->u_arg[1], tcp->u_arg[2]);
|
tprintf("%#lx, %ld, ", tcp->u_arg[1], tcp->u_arg[2]);
|
||||||
@ -1790,8 +1794,7 @@ sys_recvmmsg(struct tcb *tcp)
|
|||||||
if (!verbose(tcp))
|
if (!verbose(tcp))
|
||||||
return 0;
|
return 0;
|
||||||
/* timeout on exit */
|
/* timeout on exit */
|
||||||
strcpy(str, "left ");
|
sprint_timespec(stpcpy(str, "left "), tcp, tcp->u_arg[4]);
|
||||||
sprint_timespec(str + strlen(str), tcp, tcp->u_arg[4]);
|
|
||||||
tcp->auxstr = str;
|
tcp->auxstr = str;
|
||||||
return RVAL_STR;
|
return RVAL_STR;
|
||||||
}
|
}
|
||||||
|
2
stream.c
2
stream.c
@ -404,7 +404,7 @@ decode_poll(struct tcb *tcp, long pts)
|
|||||||
|
|
||||||
*outptr = '\0';
|
*outptr = '\0';
|
||||||
if (pts) {
|
if (pts) {
|
||||||
if (outptr < end_outstr - 128) {
|
if (outptr < end_outstr - (10 + TIMESPEC_TEXT_BUFSIZE)) {
|
||||||
outptr = stpcpy(outptr, outptr == outstr ? "left " : ", left ");
|
outptr = stpcpy(outptr, outptr == outstr ? "left " : ", left ");
|
||||||
sprint_timespec(outptr, tcp, pts);
|
sprint_timespec(outptr, tcp, pts);
|
||||||
}
|
}
|
||||||
|
105
time.c
105
time.c
@ -66,54 +66,13 @@ tprint_timeval(struct tcb *tcp, const struct timeval *tv)
|
|||||||
void
|
void
|
||||||
printtv_bitness(struct tcb *tcp, long addr, enum bitness_t bitness, int special)
|
printtv_bitness(struct tcb *tcp, long addr, enum bitness_t bitness, int special)
|
||||||
{
|
{
|
||||||
if (addr == 0)
|
char buf[TIMEVAL_TEXT_BUFSIZE];
|
||||||
tprints("NULL");
|
sprinttv(buf, tcp, addr, bitness, special);
|
||||||
else if (!verbose(tcp))
|
tprints(buf);
|
||||||
tprintf("%#lx", addr);
|
|
||||||
else {
|
|
||||||
int rc;
|
|
||||||
|
|
||||||
if (bitness == BITNESS_32
|
|
||||||
#if defined(LINUX) && SUPPORTED_PERSONALITIES > 1
|
|
||||||
|| personality_wordsize[current_personality] == 4
|
|
||||||
#endif
|
|
||||||
)
|
|
||||||
{
|
|
||||||
struct timeval32 tv;
|
|
||||||
|
|
||||||
rc = umove(tcp, addr, &tv);
|
|
||||||
if (rc >= 0) {
|
|
||||||
if (special && tv.tv_sec == 0 &&
|
|
||||||
tv.tv_usec == UTIME_NOW)
|
|
||||||
tprints("UTIME_NOW");
|
|
||||||
else if (special && tv.tv_sec == 0 &&
|
|
||||||
tv.tv_usec == UTIME_OMIT)
|
|
||||||
tprints("UTIME_OMIT");
|
|
||||||
else
|
|
||||||
tprint_timeval32(tcp, &tv);
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
struct timeval tv;
|
|
||||||
|
|
||||||
rc = umove(tcp, addr, &tv);
|
|
||||||
if (rc >= 0) {
|
|
||||||
if (special && tv.tv_sec == 0 &&
|
|
||||||
tv.tv_usec == UTIME_NOW)
|
|
||||||
tprints("UTIME_NOW");
|
|
||||||
else if (special && tv.tv_sec == 0 &&
|
|
||||||
tv.tv_usec == UTIME_OMIT)
|
|
||||||
tprints("UTIME_OMIT");
|
|
||||||
else
|
|
||||||
tprint_timeval(tcp, &tv);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
if (rc < 0)
|
|
||||||
tprints("{...}");
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
char *
|
char *
|
||||||
sprinttv(struct tcb *tcp, long addr, enum bitness_t bitness, char *buf)
|
sprinttv(char *buf, struct tcb *tcp, long addr, enum bitness_t bitness, int special)
|
||||||
{
|
{
|
||||||
int rc;
|
int rc;
|
||||||
|
|
||||||
@ -132,56 +91,46 @@ sprinttv(struct tcb *tcp, long addr, enum bitness_t bitness, char *buf)
|
|||||||
struct timeval32 tv;
|
struct timeval32 tv;
|
||||||
|
|
||||||
rc = umove(tcp, addr, &tv);
|
rc = umove(tcp, addr, &tv);
|
||||||
if (rc >= 0)
|
if (rc >= 0) {
|
||||||
|
if (special && tv.tv_sec == 0) {
|
||||||
|
if (tv.tv_usec == UTIME_NOW)
|
||||||
|
return stpcpy(buf, "UTIME_NOW");
|
||||||
|
if (tv.tv_usec == UTIME_OMIT)
|
||||||
|
return stpcpy(buf, "UTIME_OMIT");
|
||||||
|
}
|
||||||
return buf + sprintf(buf, "{%u, %u}",
|
return buf + sprintf(buf, "{%u, %u}",
|
||||||
tv.tv_sec, tv.tv_usec);
|
tv.tv_sec, tv.tv_usec);
|
||||||
|
}
|
||||||
} else {
|
} else {
|
||||||
struct timeval tv;
|
struct timeval tv;
|
||||||
|
|
||||||
rc = umove(tcp, addr, &tv);
|
rc = umove(tcp, addr, &tv);
|
||||||
if (rc >= 0)
|
if (rc >= 0) {
|
||||||
|
if (special && tv.tv_sec == 0) {
|
||||||
|
if (tv.tv_usec == UTIME_NOW)
|
||||||
|
return stpcpy(buf, "UTIME_NOW");
|
||||||
|
if (tv.tv_usec == UTIME_OMIT)
|
||||||
|
return stpcpy(buf, "UTIME_OMIT");
|
||||||
|
}
|
||||||
return buf + sprintf(buf, "{%lu, %lu}",
|
return buf + sprintf(buf, "{%lu, %lu}",
|
||||||
(unsigned long) tv.tv_sec,
|
(unsigned long) tv.tv_sec,
|
||||||
(unsigned long) tv.tv_usec);
|
(unsigned long) tv.tv_usec);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return stpcpy(buf, "{...}");
|
return stpcpy(buf, "{...}");
|
||||||
}
|
}
|
||||||
|
|
||||||
void print_timespec(struct tcb *tcp, long addr)
|
void
|
||||||
|
print_timespec(struct tcb *tcp, long addr)
|
||||||
{
|
{
|
||||||
if (addr == 0)
|
char buf[TIMESPEC_TEXT_BUFSIZE];
|
||||||
tprints("NULL");
|
sprint_timespec(buf, tcp, addr);
|
||||||
else if (!verbose(tcp))
|
tprints(buf);
|
||||||
tprintf("%#lx", addr);
|
|
||||||
else {
|
|
||||||
int rc;
|
|
||||||
|
|
||||||
#if defined(LINUX) && SUPPORTED_PERSONALITIES > 1
|
|
||||||
if (personality_wordsize[current_personality] == 4) {
|
|
||||||
struct timeval32 tv;
|
|
||||||
|
|
||||||
rc = umove(tcp, addr, &tv);
|
|
||||||
if (rc >= 0)
|
|
||||||
tprintf("{%u, %u}",
|
|
||||||
tv.tv_sec, tv.tv_usec);
|
|
||||||
} else
|
|
||||||
#endif
|
|
||||||
{
|
|
||||||
struct timespec ts;
|
|
||||||
|
|
||||||
rc = umove(tcp, addr, &ts);
|
|
||||||
if (rc >= 0)
|
|
||||||
tprintf("{%lu, %lu}",
|
|
||||||
(unsigned long) ts.tv_sec,
|
|
||||||
(unsigned long) ts.tv_nsec);
|
|
||||||
}
|
|
||||||
if (rc < 0)
|
|
||||||
tprints("{...}");
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void sprint_timespec(char *buf, struct tcb *tcp, long addr)
|
void
|
||||||
|
sprint_timespec(char *buf, struct tcb *tcp, long addr)
|
||||||
{
|
{
|
||||||
if (addr == 0)
|
if (addr == 0)
|
||||||
strcpy(buf, "NULL");
|
strcpy(buf, "NULL");
|
||||||
|
Loading…
Reference in New Issue
Block a user