]> granicus.if.org Git - strace/commitdiff
Factor out printing of 64bit syscall argument
authorAndreas Schwab <schwab@redhat.com>
Wed, 4 Nov 2009 16:08:34 +0000 (17:08 +0100)
committerAndreas Schwab <schwab@redhat.com>
Wed, 4 Nov 2009 16:10:25 +0000 (17:10 +0100)
* defs.h (ALIGN64): Remove.
(printllval): Declare.
* util.c (printllval): Define.
* file.c (sys_readahead): Use printllval.
(sys_lseek64): Likewise.
(sys_truncate64): Likewise.
(sys_ftruncate64): Likewise.
(sys_fadvise64): Likewise.
(sys_fadvise64_64): Likewise.
(sys_fallocate): Likewise.
* io.c (sys_pread): Likewise.
(sys_pwrite): Likewise.
(sys_pread64): Likewise.
(sys_pwrite64): Likewise.
* mem.c (sys_mmap64): Likewise.

defs.h
file.c
io.c
mem.c
util.c

diff --git a/defs.h b/defs.h
index 5bcaa070448c03a86bee87c64239a0d25f792e67..dc0d91f3694f5f218a5bb1a99a104699e001e3fa 100644 (file)
--- a/defs.h
+++ b/defs.h
@@ -651,20 +651,6 @@ extern const char *const signalent2[];
 extern const int nsignals2;
 #endif /* SUPPORTED_PERSONALITIES >= 3 */
 
-#if defined(FREEBSD) || (defined(LINUX) \
-                        && defined(POWERPC) && !defined(__powerpc64__)) \
-  || defined (LINUX_MIPSO32)
-/* ARRGH!  off_t args are aligned on 64 bit boundaries! */
-#define ALIGN64(tcp,arg)                                               \
-do {                                                                   \
-       if (arg % 2)                                                    \
-           memmove (&tcp->u_arg[arg], &tcp->u_arg[arg + 1],            \
-                    (tcp->u_nargs - arg - 1) * sizeof tcp->u_arg[0]);  \
-} while (0)
-#else
-#define ALIGN64(tcp,arg) do { } while (0)
-#endif
-
 #if HAVE_LONG_LONG
 
 /* _l refers to the lower numbered u_arg,
@@ -678,6 +664,8 @@ do {                                                                        \
 #define LONG_LONG(_l,_h) \
     ((long long)((unsigned long long)(unsigned)(_h) | ((unsigned long long)(_l)<<32)))
 #endif
+
+extern int printllval(struct tcb *, const char *, int);
 #endif
 
 #ifdef IA64
diff --git a/file.c b/file.c
index 2e462846c8ed10cdc4952b8adeb337ea9258dc25..14df971c8c802130991ab67d6ee51c8e58c8aa9c 100644 (file)
--- a/file.c
+++ b/file.c
@@ -610,16 +610,10 @@ int
 sys_readahead(struct tcb *tcp)
 {
        if (entering(tcp)) {
-               ALIGN64 (tcp, 1);
-               tprintf("%ld, %lld, %ld", tcp->u_arg[0],
-# if defined LINUX_MIPSN32
-                       tcp->ext_arg[1], tcp->u_arg[2]
-# elif defined IA64 || defined X86_64 || defined ALPHA || defined LINUX_MIPSN64 || (defined POWERPC && defined __powerpc64__)
-                       (long long int) tcp->u_arg[1], tcp->u_arg[2]
-# else
-                       LONG_LONG(tcp->u_arg[1], tcp->u_arg[2]), tcp->u_arg[3]
-# endif
-               );
+               int argn;
+               tprintf("%ld, ", tcp->u_arg[0]);
+               argn = printllval(tcp, "%lld", 1);
+               tprintf(", %ld", tcp->u_arg[argn]);
        }
        return 0;
 }
@@ -630,14 +624,13 @@ int
 sys_lseek64(struct tcb *tcp)
 {
        if (entering(tcp)) {
-               long long offset;
-               ALIGN64 (tcp, 1);       /* FreeBSD aligns off_t args */
-               offset = LONG_LONG(tcp->u_arg [1], tcp->u_arg[2]);
+               int argn;
+               tprintf("%ld, ", tcp->u_arg[0]);
                if (tcp->u_arg[3] == SEEK_SET)
-                       tprintf("%ld, %llu, ", tcp->u_arg[0], offset);
+                       argn = printllval(tcp, "%llu, ", 1);
                else
-                       tprintf("%ld, %lld, ", tcp->u_arg[0], offset);
-               printxval(whence, tcp->u_arg[3], "SEEK_???");
+                       argn = printllval(tcp, "%lld, ", 1);
+               printxval(whence, tcp->u_arg[argn], "SEEK_???");
        }
        return RVAL_LUDECIMAL;
 }
@@ -660,9 +653,8 @@ int
 sys_truncate64(struct tcb *tcp)
 {
        if (entering(tcp)) {
-               ALIGN64 (tcp, 1);
                printpath(tcp, tcp->u_arg[0]);
-               tprintf(", %llu", LONG_LONG(tcp->u_arg[1],tcp->u_arg[2]));
+               printllval(tcp, ", %llu", 1);
        }
        return 0;
 }
@@ -684,9 +676,8 @@ int
 sys_ftruncate64(struct tcb *tcp)
 {
        if (entering(tcp)) {
-               ALIGN64 (tcp, 1);
-               tprintf("%ld, %llu", tcp->u_arg[0],
-                       LONG_LONG(tcp->u_arg[1] ,tcp->u_arg[2]));
+               tprintf("%ld, ", tcp->u_arg[0]);
+               printllval(tcp, "%llu", 1);
        }
        return 0;
 }
@@ -2816,16 +2807,11 @@ int
 sys_fadvise64(struct tcb *tcp)
 {
        if (entering(tcp)) {
-               ALIGN64(tcp, 1);
-               tprintf("%ld, %lld, %ld, ",
-                       tcp->u_arg[0],
-# if defined IA64 || defined X86_64 || defined ALPHA || (defined POWERPC && defined __powerpc64__)
-                       (long long int) tcp->u_arg[1], tcp->u_arg[2]);
-               printxval(advise, tcp->u_arg[3], "POSIX_FADV_???");
-#else
-                       LONG_LONG(tcp->u_arg[1], tcp->u_arg[2]), tcp->u_arg[3]);
-               printxval(advise, tcp->u_arg[4], "POSIX_FADV_???");
-#endif
+               int argn;
+               tprintf("%ld, ", tcp->u_arg[0]);
+               argn = printllval(tcp, "%lld", 1);
+               tprintf(", %ld, ", tcp->u_arg[argn++]);
+               printxval(advise, tcp->u_arg[argn], "POSIX_FADV_???");
        }
        return 0;
 }
@@ -2836,22 +2822,18 @@ int
 sys_fadvise64_64(struct tcb *tcp)
 {
        if (entering(tcp)) {
-               tprintf("%ld, %lld, %lld, ",
-                       tcp->u_arg[0],
-#if defined LINUX_MIPSN32
-                       tcp->ext_arg[1], tcp->ext_arg[2]);
-               printxval(advise, tcp->u_arg[3], "POSIX_FADV_???");
-#elif defined IA64 || defined X86_64 || defined ALPHA || defined LINUX_MIPSN64
-                       (long long int) tcp->u_arg[1], (long long int) tcp->u_arg[2]);
-               printxval(advise, tcp->u_arg[3], "POSIX_FADV_???");
-#elif defined ARM || defined POWERPC
-                       LONG_LONG(tcp->u_arg[2], tcp->u_arg[3]),
-                       LONG_LONG(tcp->u_arg[4], tcp->u_arg[5]));
+               int argn;
+               tprintf("%ld, ", tcp->u_arg[0]);
+#if defined ARM || defined POWERPC
+               argn = printllval(tcp, "%lld, ", 2);
+#else
+               argn = printllval(tcp, "%lld, ", 1);
+#endif
+               argn = printllval(tcp, "%lld, ", argn);
+#if defined ARM || defined POWERPC
                printxval(advise, tcp->u_arg[1], "POSIX_FADV_???");
 #else
-                       LONG_LONG(tcp->u_arg[1], tcp->u_arg[2]),
-                       LONG_LONG(tcp->u_arg[3], tcp->u_arg[4]));
-               printxval(advise, tcp->u_arg[5], "POSIX_FADV_???");
+               printxval(advise, tcp->u_arg[argn], "POSIX_FADV_???");
 #endif
        }
        return 0;
@@ -2906,12 +2888,11 @@ int
 sys_fallocate(struct tcb *tcp)
 {
        if (entering(tcp)) {
+               int argn;
                tprintf("%ld, ", tcp->u_arg[0]);        /* fd */
                tprintf("%#lo, ", tcp->u_arg[1]);       /* mode */
-               tprintf("%llu, ", LONG_LONG(tcp->u_arg[2],
-                       tcp->u_arg[3]));                /* offset */
-               tprintf("%llu", LONG_LONG(tcp->u_arg[4],
-                       tcp->u_arg[5]));                /* len */
+               argn = printllval(tcp, "%llu, ", 2);    /* offset */
+               printllval(tcp, "%llu", argn);          /* len */
        }
        return 0;
 }
diff --git a/io.c b/io.c
index add3fb60a80f08025d806ff4023f4db55187e80f..3d2970c157fdffa99d249d780f63d16e6d444c7e 100644 (file)
--- a/io.c
+++ b/io.c
@@ -286,9 +286,8 @@ struct tcb *tcp;
                        tprintf("%#lx", tcp->u_arg[1]);
                else
                        printstr(tcp, tcp->u_arg[1], tcp->u_rval);
-               ALIGN64 (tcp, PREAD_OFFSET_ARG); /* PowerPC alignment restriction */
-               tprintf(", %lu, %llu", tcp->u_arg[2],
-                       *(unsigned long long *)&tcp->u_arg[PREAD_OFFSET_ARG]);
+               tprintf(", %lu, ", tcp->u_arg[2]);
+               printllval(tcp, "%llu", PREAD_OFFSET_ARG);
        }
        return 0;
 }
@@ -300,9 +299,8 @@ struct tcb *tcp;
        if (entering(tcp)) {
                tprintf("%ld, ", tcp->u_arg[0]);
                printstr(tcp, tcp->u_arg[1], tcp->u_arg[2]);
-               ALIGN64 (tcp, PREAD_OFFSET_ARG); /* PowerPC alignment restriction */
-               tprintf(", %lu, %llu", tcp->u_arg[2],
-                       *(unsigned long long *)&tcp->u_arg[PREAD_OFFSET_ARG]);
+               tprintf(", %lu, ", tcp->u_arg[2]);
+               printllval(tcp, "%llu", PREAD_OFFSET_ARG);
        }
        return 0;
 }
@@ -355,17 +353,12 @@ struct tcb *tcp;
        if (entering(tcp)) {
                tprintf("%ld, ", tcp->u_arg[0]);
        } else {
-               ALIGN64 (tcp, 3);
                if (syserror(tcp))
                        tprintf("%#lx", tcp->u_arg[1]);
                else
                        printstr(tcp, tcp->u_arg[1], tcp->u_rval);
-#ifdef MIPS_LINUXN32
-               tprintf(", %lu, %#llx", tcp->u_arg[2], tcp->ext_arg[3]);
-#else
-               tprintf(", %lu, %#llx", tcp->u_arg[2],
-                       LONG_LONG(tcp->u_arg[3], tcp->u_arg[4]));
-#endif
+               tprintf(", %lu, ", tcp->u_arg[2]);
+               printllval(tcp, "%#llx", 3);
        }
        return 0;
 }
@@ -375,15 +368,10 @@ sys_pwrite64(tcp)
 struct tcb *tcp;
 {
        if (entering(tcp)) {
-               ALIGN64 (tcp, 3);
                tprintf("%ld, ", tcp->u_arg[0]);
                printstr(tcp, tcp->u_arg[1], tcp->u_arg[2]);
-#ifdef MIPS_LINUXN32
-               tprintf(", %lu, %#llx", tcp->u_arg[2], tcp->ext_arg[3]);
-#else
-               tprintf(", %lu, %#llx", tcp->u_arg[2],
-                       LONG_LONG(tcp->u_arg[3], tcp->u_arg[4]));
-#endif
+               tprintf(", %lu, ", tcp->u_arg[2]);
+               printllval(tcp, "%#llx", 3);
        }
        return 0;
 }
diff --git a/mem.c b/mem.c
index c922f074d614bb8beb4f02c5f386abd17585dc2f..9335217821a022dfb44931b0ff42e13f0a397f23 100644 (file)
--- a/mem.c
+++ b/mem.c
@@ -318,7 +318,6 @@ struct tcb *tcp;
                        return 0;
 #endif /* ALPHA */
 #endif /* linux */
-               ALIGN64 (tcp, 5);       /* FreeBSD wierdies */
 
                /* addr */
                tprintf("%#lx, ", u_arg[0]);
@@ -337,7 +336,7 @@ struct tcb *tcp;
                /* fd */
                tprintf(", %ld, ", u_arg[4]);
                /* offset */
-               tprintf("%#llx", LONG_LONG(u_arg[5], u_arg[6]));
+               printllval(tcp, "%#llx", 5);
        }
        return RVAL_HEX;
 }
diff --git a/util.c b/util.c
index 84baf7a194c13404cec7d6f2a5d665004625e193..a471590c76c3e88542afa069c6a4d11f90a53d5e 100644 (file)
--- a/util.c
+++ b/util.c
@@ -254,6 +254,42 @@ printxval(const struct xlat *xlat, int val, const char *dflt)
                tprintf("%#x /* %s */", val, dflt);
 }
 
+#if HAVE_LONG_LONG
+/*
+ * Print 64bit argument at position llarg and return the index of the next
+ * argument.
+ */
+int
+printllval(struct tcb *tcp, const char *format, int llarg)
+{
+# if defined(FREEBSD) \
+     || (defined(LINUX) && defined(POWERPC) && !defined(__powerpc64__)) \
+     || defined (LINUX_MIPSO32)
+       /* Align 64bit argument to 64bit boundary.  */
+       if (llarg % 2) llarg++;
+# endif
+# if defined LINUX && defined X86_64
+       if (current_personality == 0) {
+               tprintf(format, tcp->u_arg[llarg]);
+               llarg++;
+       } else {
+               tprintf(format, LONG_LONG(tcp->u_arg[llarg], tcp->u_arg[llarg + 1]));
+               llarg += 2;
+       }
+# elif defined IA64 || defined ALPHA || (defined POWERPC && defined __powerpc64__)
+       tprintf(format, tcp->u_arg[llarg]);
+       llarg++;
+# elif defined LINUX_MIPSN32
+       tprintf(format, tcp->ext_arg[llarg]);
+       llarg++;
+# else
+       tprintf(format, LONG_LONG(tcp->u_arg[llarg], tcp->u_arg[llarg + 1]));
+       llarg += 2;
+# endif
+       return llarg;
+}
+#endif
+
 /*
  * Interpret `xlat' as an array of flags
  * print the entries whose bits are on in `flags'