]> granicus.if.org Git - strace/commitdiff
Convert another parser of struct timeval to new mpers infrastructure
authorDmitry V. Levin <ldv@altlinux.org>
Fri, 18 Sep 2015 18:02:50 +0000 (18:02 +0000)
committerDmitry V. Levin <ldv@altlinux.org>
Sat, 19 Sep 2015 01:04:49 +0000 (04:04 +0300)
* print_time.c (sprint_timeval): New mpers printer.
[ALPHA] (sprint_timeval32): New function.
* defs.h [ALPHA] (sprint_timeval32): New prototype.
(bitness_t, TIMEVAL_TEXT_BUFSIZE, printtv_bitness, sprinttv): Remove.
* desc.c (decode_select): Replace bitness parameter with two printers.
Use them instead of printtv_bitness and sprinttv.
(sys_oldselect, sys_select): Pass print_timeval and sprint_timeval
to decode_select.
[ALPHA] (sys_osf_select): Pass print_timeval32 and sprint_timeval32
to decode_select.
(pselect6): Pass print_timespec and sprint_timespec to decode_select.
* time.c (UTIME_NOW, UTIME_OMIT, current_time_t_is_compat,
struct timeval32, printtv_bitness, do_sprinttv, sprinttv): Remove.

defs.h
desc.c
print_time.c
time.c

diff --git a/defs.h b/defs.h
index 9b9a105d723cef3b7297604826df1f6447ff9082..1fe5975a804a1473342a080f1d2619c035b5c87c 100644 (file)
--- a/defs.h
+++ b/defs.h
@@ -498,8 +498,6 @@ extern unsigned os_release;
 #undef KERNEL_VERSION
 #define KERNEL_VERSION(a,b,c) (((a) << 16) + ((b) << 8) + (c))
 
-enum bitness_t { BITNESS_CURRENT = 0, BITNESS_32 };
-
 void error_msg(const char *fmt, ...) ATTRIBUTE_FORMAT((printf, 1, 2));
 void perror_msg(const char *fmt, ...) ATTRIBUTE_FORMAT((printf, 1, 2));
 void error_msg_and_die(const char *fmt, ...)
@@ -649,9 +647,6 @@ extern void printpath(struct tcb *, long);
 extern void printpathn(struct tcb *, long, unsigned int);
 #define TIMESPEC_TEXT_BUFSIZE \
                (sizeof(intmax_t)*3 * 2 + sizeof("{tv_sec=%jd, tv_nsec=%jd}"))
-#define TIMEVAL_TEXT_BUFSIZE  TIMESPEC_TEXT_BUFSIZE
-extern void printtv_bitness(struct tcb *, long, enum bitness_t, int);
-extern char *sprinttv(char *, struct tcb *, long, enum bitness_t, int special);
 extern void printfd(struct tcb *, int);
 extern bool print_sockaddr_by_inode(const unsigned long, const char *);
 extern void print_dirfd(struct tcb *, int);
@@ -659,6 +654,7 @@ extern void printsock(struct tcb *, long, int);
 extern void print_sock_optmgmt(struct tcb *, long, int);
 #ifdef ALPHA
 extern void printrusage32(struct tcb *, long);
+extern const char *sprint_timeval32(struct tcb *tcp, long);
 extern void print_timeval32(struct tcb *tcp, long);
 extern void print_timeval32_pair(struct tcb *tcp, long);
 extern void print_itimerval32(struct tcb *tcp, long);
diff --git a/desc.c b/desc.c
index ea9f3bd598029f4672c068d5b3195e604c956ca8..0093538ee8aa85502dc120715a55ae62c9eca2a3 100644 (file)
--- a/desc.c
+++ b/desc.c
@@ -282,7 +282,9 @@ SYS_FUNC(getdtablesize)
 #endif
 
 static int
-decode_select(struct tcb *tcp, long *args, enum bitness_t bitness)
+decode_select(struct tcb *tcp, long *args,
+             void (*print_tv_ts) (struct tcb *, const long),
+             const char * (*sprint_tv_ts) (struct tcb *, const long))
 {
        int i, j;
        int nfds, fdsize;
@@ -334,7 +336,7 @@ decode_select(struct tcb *tcp, long *args, enum bitness_t bitness)
                }
                free(fds);
                tprints(", ");
-               printtv_bitness(tcp, args[4], bitness, 0);
+               print_tv_ts(tcp, args[4]);
        } else {
                static char outstr[1024];
                char *outptr;
@@ -388,9 +390,9 @@ decode_select(struct tcb *tcp, long *args, enum bitness_t bitness)
                free(fds);
                /* This contains no useful information on SunOS.  */
                if (args[4]) {
-                       if (outptr < end_outstr - (10 + TIMEVAL_TEXT_BUFSIZE)) {
-                               outptr += sprintf(outptr, "%sleft ", sep);
-                               outptr = sprinttv(outptr, tcp, args[4], bitness, /*special:*/ 0);
+                       const char *str = sprint_tv_ts(tcp, args[4]);
+                       if (outptr + sizeof("left ") + strlen(sep) + strlen(str) < end_outstr) {
+                               outptr += sprintf(outptr, "%sleft %s", sep, str);
                        }
                }
                *outptr = '\0';
@@ -421,25 +423,25 @@ SYS_FUNC(oldselect)
                long_args[i] = oldselect_args[i];
        }
 #endif
-       return decode_select(tcp, long_args, BITNESS_CURRENT);
+       return decode_select(tcp, long_args, print_timeval, sprint_timeval);
 #undef oldselect_args
 }
 
 #ifdef ALPHA
 SYS_FUNC(osf_select)
 {
-       return decode_select(tcp, tcp->u_arg, BITNESS_32);
+       return decode_select(tcp, tcp->u_arg, print_timeval32, sprint_timeval32);
 }
 #endif
 
 SYS_FUNC(select)
 {
-       return decode_select(tcp, tcp->u_arg, BITNESS_CURRENT);
+       return decode_select(tcp, tcp->u_arg, print_timeval, sprint_timeval);
 }
 
 SYS_FUNC(pselect6)
 {
-       int rc = decode_select(tcp, tcp->u_arg, BITNESS_CURRENT);
+       int rc = decode_select(tcp, tcp->u_arg, print_timespec, sprint_timespec);
        if (entering(tcp)) {
                unsigned long data[2];
 
index 1e6aa76001cb9dfed33a64f638ba35bd6d9d7f2c..4d387669df8a6669786c1d7bab21ed05db0b2527 100644 (file)
@@ -126,6 +126,24 @@ MPERS_PRINTER_DECL(void, print_timeval_pair)(struct tcb *tcp, const long addr)
        tprints("]");
 }
 
+MPERS_PRINTER_DECL(const char *, sprint_timeval)(struct tcb *tcp, const long addr)
+{
+       timeval_t t;
+       static char buf[sizeof(time_fmt) + 3 * sizeof(t)];
+
+       if (!addr) {
+               strcpy(buf, "NULL");
+       } else if (!verbose(tcp) || (exiting(tcp) && syserror(tcp)) ||
+                  umove(tcp, addr, &t)) {
+               snprintf(buf, sizeof(buf), "%#lx", addr);
+       } else {
+               snprintf(buf, sizeof(buf), time_fmt,
+                        (intmax_t) t.tv_sec, (intmax_t) t.tv_usec);
+       }
+
+       return buf;
+}
+
 MPERS_PRINTER_DECL(void, print_itimerval)(struct tcb *tcp, const long addr)
 {
        timeval_t t[2];
@@ -205,4 +223,23 @@ print_itimerval32(struct tcb *tcp, const long addr)
        tprints("}");
 }
 
+const char *
+sprint_timeval32(struct tcb *tcp, const long addr)
+{
+       timeval32_t t;
+       static char buf[sizeof(time_fmt) + 3 * sizeof(t)];
+
+       if (!addr) {
+               strcpy(buf, "NULL");
+       } else if (!verbose(tcp) || (exiting(tcp) && syserror(tcp)) ||
+                  umove(tcp, addr, &t)) {
+               snprintf(buf, sizeof(buf), "%#lx", addr);
+       } else {
+               snprintf(buf, sizeof(buf), time_fmt,
+                        (intmax_t) t.tv_sec, (intmax_t) t.tv_usec);
+       }
+
+       return buf;
+}
+
 #endif /* ALPHA */
diff --git a/time.c b/time.c
index 9a955251013ac9f33bc79a7383feeacf72221916..c98862d8cf2453df0c97eda4f8fc0161f5a22e77 100644 (file)
--- a/time.c
+++ b/time.c
 #include <signal.h>
 #include <sys/timex.h>
 
-#ifndef UTIME_NOW
-#define UTIME_NOW ((1l << 30) - 1l)
-#endif
-#ifndef UTIME_OMIT
-#define UTIME_OMIT ((1l << 30) - 2l)
-#endif
-
-#if SUPPORTED_PERSONALITIES > 1
-# if defined X86_64 || defined X32
-#  define current_time_t_is_compat (current_personality == 1)
-# else
-#  define current_time_t_is_compat (current_wordsize == 4)
-# endif
-#else
-# define current_time_t_is_compat 0
-#endif
-
-struct timeval32
-{
-       u_int32_t tv_sec, tv_usec;
-};
-
-void
-printtv_bitness(struct tcb *tcp, long addr, enum bitness_t bitness, int special)
-{
-       char buf[TIMEVAL_TEXT_BUFSIZE];
-       sprinttv(buf, tcp, addr, bitness, special);
-       tprints(buf);
-}
-
-static char *
-do_sprinttv(char *buf, const uintmax_t sec, const uintmax_t usec,
-           const int special)
-{
-       if (special) {
-               switch (usec) {
-                       case UTIME_NOW:
-                               return stpcpy(buf, "UTIME_NOW");
-                       case UTIME_OMIT:
-                               return stpcpy(buf, "UTIME_OMIT");
-               }
-       }
-       return buf + sprintf(buf, "{%ju, %ju}", sec, usec);
-}
-
-char *
-sprinttv(char *buf, struct tcb *tcp, long addr, enum bitness_t bitness, int special)
-{
-       if (addr == 0)
-               return stpcpy(buf, "NULL");
-
-       if (!verbose(tcp) || (exiting(tcp) && syserror(tcp)))
-               return buf + sprintf(buf, "%#lx", addr);
-
-       if (bitness == BITNESS_32 || current_time_t_is_compat)
-       {
-               struct timeval32 tv;
-
-               if (umove(tcp, addr, &tv) >= 0)
-                       return do_sprinttv(buf, tv.tv_sec, tv.tv_usec, special);
-       } else {
-               struct timeval tv;
-
-               if (umove(tcp, addr, &tv) >= 0)
-                       return do_sprinttv(buf, tv.tv_sec, tv.tv_usec, special);
-       }
-
-       return buf + sprintf(buf, "%#lx", addr);
-}
-
 static void
 print_timezone(struct tcb *tcp, const long addr)
 {