]> granicus.if.org Git - strace/commitdiff
Unify different generic PRINT_FIELD_* implementations
authorDmitry V. Levin <ldv@altlinux.org>
Sat, 1 Jul 2017 13:14:49 +0000 (13:14 +0000)
committerDmitry V. Levin <ldv@altlinux.org>
Sat, 1 Jul 2017 13:14:49 +0000 (13:14 +0000)
Create a new header print_fields.h and move generic PRINT_FIELD_*
macros there.

* print_fields.h: New file.
* Makefile.am (strace_SOURCES): Add it.
* netlink_sock_diag.c: Include "print_fields.h".
(PRINT_FIELD_U, PRINT_FIELD_X, PRINT_FIELD_COOKIE, PRINT_FIELD_FLAGS,
PRINT_FIELD_XVAL): Move to print_fields.h file.
* quota.c: Include "print_fields.h".
(PRINT_FIELD_D): Move to print_fields.h file.
(PRINT_FIELD_U, PRINT_FIELD_X): Remove.
* statx.c: Include "print_fields.h".
(PRINT_FIELD_U): Remove.
(SYS_FUNC(statx)): Update PRINT_FIELD_U callers.
* tests/quotactl.h: Include "print_fields.h".
* tests/quotactl-xfs.c: Update callers of PRINT_FIELD_* macros.
* tests/quotactl.c: Likewise.
(PRINT_FIELD_D, PRINT_FIELD_U, PRINT_FIELD_X): Remove.
* tests/test_nlattr.h: Include "print_fields.h".
(PRINT_FIELD_U, PRINT_FIELD_X): Remove.
* tests/xstatx.c: Include "print_fields.h".
(PRINT_FIELD_U): Remove.
(print_stat): Update PRINT_FIELD_U callers.
* tests/tests.h [!STRACE_PRINTF] (STRACE_PRINTF): Define to printf.

Makefile.am
netlink_sock_diag.c
print_fields.h [new file with mode: 0644]
quota.c
statx.c
tests/quotactl-xfs.c
tests/quotactl.c
tests/quotactl.h
tests/test_nlattr.h
tests/tests.h
tests/xstatx.c

index 76be3ca3d3128988735b8424c98760bba9ebe694..7c0658d5babdaa48c9cc9eb39b3dbddf341f85af 100644 (file)
@@ -192,6 +192,7 @@ strace_SOURCES =    \
        poll.c          \
        prctl.c         \
        print_dev_t.c   \
+       print_fields.h  \
        print_mq_attr.c \
        print_msgbuf.c  \
        print_sg_req_info.c \
index cd49e7d485e44cffc923653346b4e9afa43eae75..3888934974051c50bb601fd57798bafceb66ac81 100644 (file)
@@ -30,6 +30,7 @@
 #include "defs.h"
 #include "netlink.h"
 #include "nlattr.h"
+#include "print_fields.h"
 
 #include <arpa/inet.h>
 #include <linux/inet_diag.h>
 #include "xlat/unix_diag_attrs.h"
 #include "xlat/unix_diag_show.h"
 
-#define PRINT_FIELD_U(prefix_, where_, field_)                         \
-       tprintf("%s%s=%llu", (prefix_), #field_,                        \
-               zero_extend_signed_to_ull((where_).field_))
-
-#define PRINT_FIELD_X(prefix_, where_, field_)                         \
-       tprintf("%s%s=%#llx", (prefix_), #field_,                       \
-               zero_extend_signed_to_ull((where_).field_))
-
-#define PRINT_FIELD_COOKIE(prefix_, where_, field_)                    \
-       tprintf("%s%s=[%llu, %llu]", (prefix_), #field_,                \
-               zero_extend_signed_to_ull((where_).field_[0]),          \
-               zero_extend_signed_to_ull((where_).field_[1]))
-
-#define PRINT_FIELD_FLAGS(prefix_, where_, field_, xlat_, dflt_)       \
-       do {                                                            \
-               tprintf("%s%s=", (prefix_), #field_);                   \
-               printflags((xlat_), (where_).field_, (dflt_));          \
-       } while (0)
-
-#define PRINT_FIELD_XVAL(prefix_, where_, field_, xlat_, dflt_)                \
-       do {                                                            \
-               tprintf("%s%s=", (prefix_), #field_);                   \
-               printxval((xlat_), (where_).field_, (dflt_));           \
-       } while (0)
-
 static void
 decode_family(struct tcb *const tcp, const uint8_t family,
              const kernel_ulong_t addr, const kernel_ulong_t len)
diff --git a/print_fields.h b/print_fields.h
new file mode 100644 (file)
index 0000000..92b8a8a
--- /dev/null
@@ -0,0 +1,68 @@
+/*
+ * Copyright (c) 2016-2017 Dmitry V. Levin <ldv@altlinux.org>
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ *    notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ *    notice, this list of conditions and the following disclaimer in the
+ *    documentation and/or other materials provided with the distribution.
+ * 3. The name of the author may not be used to endorse or promote products
+ *    derived from this software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
+ * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
+ * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
+ * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
+ * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
+ * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+ * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+ * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
+ * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+#ifndef STRACE_PRINT_FIELDS_H
+#define STRACE_PRINT_FIELDS_H
+
+/*
+ * The printf-like function to use in header files
+ * shared between strace and its tests.
+ */
+#ifndef STRACE_PRINTF
+# define STRACE_PRINTF tprintf
+#endif
+
+#define PRINT_FIELD_D(prefix_, where_, field_)                         \
+       STRACE_PRINTF("%s%s=%lld", (prefix_), #field_,                  \
+                     sign_extend_unsigned_to_ll((where_).field_))
+
+#define PRINT_FIELD_U(prefix_, where_, field_)                         \
+       STRACE_PRINTF("%s%s=%llu", (prefix_), #field_,                  \
+                     zero_extend_signed_to_ull((where_).field_))
+
+#define PRINT_FIELD_X(prefix_, where_, field_)                         \
+       STRACE_PRINTF("%s%s=%#llx", (prefix_), #field_,                 \
+                     zero_extend_signed_to_ull((where_).field_))
+
+#define PRINT_FIELD_COOKIE(prefix_, where_, field_)                    \
+       STRACE_PRINTF("%s%s=[%llu, %llu]", (prefix_), #field_,          \
+                     zero_extend_signed_to_ull((where_).field_[0]),    \
+                     zero_extend_signed_to_ull((where_).field_[1]))
+
+#define PRINT_FIELD_FLAGS(prefix_, where_, field_, xlat_, dflt_)       \
+       do {                                                            \
+               STRACE_PRINTF("%s%s=", (prefix_), #field_);             \
+               printflags((xlat_), (where_).field_, (dflt_));          \
+       } while (0)
+
+#define PRINT_FIELD_XVAL(prefix_, where_, field_, xlat_, dflt_)                \
+       do {                                                            \
+               STRACE_PRINTF("%s%s=", (prefix_), #field_);             \
+               printxval((xlat_), (where_).field_, (dflt_));           \
+       } while (0)
+
+#endif /* !STRACE_PRINT_FIELDS_H */
diff --git a/quota.c b/quota.c
index ef151662ac9a277ed917ed985244e30b0e01b139..ab2f1cec90ca81f4498752afa932f042e60453bb 100644 (file)
--- a/quota.c
+++ b/quota.c
@@ -30,6 +30,7 @@
  */
 
 #include "defs.h"
+#include "print_fields.h"
 
 #define SUBCMDMASK  0x00ff
 #define SUBCMDSHIFT 8
@@ -153,18 +154,6 @@ struct fs_quota_statv {
        uint64_t qs_pad2[8];
 };
 
-#define PRINT_FIELD_D(prefix, where, field)    \
-       tprintf("%s%s=%lld", (prefix), #field,  \
-               sign_extend_unsigned_to_ll((where).field))
-
-#define PRINT_FIELD_U(prefix, where, field)    \
-       tprintf("%s%s=%llu", (prefix), #field,  \
-               zero_extend_signed_to_ull((where).field))
-
-#define PRINT_FIELD_X(prefix, where, field)    \
-       tprintf("%s%s=%#llx", (prefix), #field, \
-               zero_extend_signed_to_ull((where).field))
-
 static int
 decode_cmd_data(struct tcb *tcp, uint32_t id, uint32_t cmd, kernel_ulong_t data)
 {
diff --git a/statx.c b/statx.c
index 6e9138782a5c80078b6542eb4314766fb7eacbc0..c78b173d4be43007c73e206be6068cda59929244 100644 (file)
--- a/statx.c
+++ b/statx.c
@@ -26,6 +26,7 @@
  */
 
 #include "defs.h"
+#include "print_fields.h"
 #include "statx.h"
 
 #include <sys/stat.h>
@@ -54,9 +55,6 @@ SYS_FUNC(statx)
                printflags(statx_masks, tcp->u_arg[3], "STATX_???");
                tprints(", ");
        } else {
-#define PRINT_FIELD_U(field) \
-       tprintf(", %s=%llu", #field, (unsigned long long) stx.field)
-
 #define PRINT_FIELD_TIME(field)                                                \
        do {                                                            \
                tprintf(", " #field "={tv_sec=%" PRId64                 \
@@ -74,13 +72,13 @@ SYS_FUNC(statx)
                printflags(statx_masks, stx.stx_mask, "STATX_???");
 
                if (!abbrev(tcp))
-                       PRINT_FIELD_U(stx_blksize);
+                       PRINT_FIELD_U(", ", stx, stx_blksize);
 
                tprints(", stx_attributes=");
                printflags(statx_attrs, stx.stx_attributes, "STATX_ATTR_???");
 
                if (!abbrev(tcp)) {
-                       PRINT_FIELD_U(stx_nlink);
+                       PRINT_FIELD_U(", ", stx, stx_nlink);
                        printuid(", stx_uid=", stx.stx_uid);
                        printuid(", stx_gid=", stx.stx_gid);
                }
@@ -89,12 +87,12 @@ SYS_FUNC(statx)
                print_symbolic_mode_t(stx.stx_mode);
 
                if (!abbrev(tcp))
-                       PRINT_FIELD_U(stx_ino);
+                       PRINT_FIELD_U(", ", stx, stx_ino);
 
-               PRINT_FIELD_U(stx_size);
+               PRINT_FIELD_U(", ", stx, stx_size);
 
                if (!abbrev(tcp)) {
-                       PRINT_FIELD_U(stx_blocks);
+                       PRINT_FIELD_U(", ", stx, stx_blocks);
 
                        tprints(", stx_attributes_mask=");
                        printflags(statx_attrs, stx.stx_attributes_mask,
@@ -104,10 +102,10 @@ SYS_FUNC(statx)
                        PRINT_FIELD_TIME(stx_btime);
                        PRINT_FIELD_TIME(stx_ctime);
                        PRINT_FIELD_TIME(stx_mtime);
-                       PRINT_FIELD_U(stx_rdev_major);
-                       PRINT_FIELD_U(stx_rdev_minor);
-                       PRINT_FIELD_U(stx_dev_major);
-                       PRINT_FIELD_U(stx_dev_minor);
+                       PRINT_FIELD_U(", ", stx, stx_rdev_major);
+                       PRINT_FIELD_U(", ", stx, stx_rdev_minor);
+                       PRINT_FIELD_U(", ", stx, stx_dev_major);
+                       PRINT_FIELD_U(", ", stx, stx_dev_minor);
                } else {
                        tprints(", ...");
                }
index 1c7d07e36a58bdc38b9596dc3663d9fa48d48648..fab451e22820e904189bf7c281dc39d5493611e1 100644 (file)
@@ -97,29 +97,29 @@ print_xdisk_quota(int rc, void *ptr, void *arg)
                return;
        }
 
-       PRINT_FIELD_D("{", dq, d_version);
+       PRINT_FIELD_D("{", *dq, d_version);
        printf(", d_flags=");
        printflags(xfs_dqblk_flags, (uint8_t) dq->d_flags, "XFS_???_QUOTA");
 
-       PRINT_FIELD_X(", ", dq, d_fieldmask);
-       PRINT_FIELD_U(", ", dq, d_id);
-       PRINT_FIELD_U(", ", dq, d_blk_hardlimit);
-       PRINT_FIELD_U(", ", dq, d_blk_softlimit);
-       PRINT_FIELD_U(", ", dq, d_ino_hardlimit);
-       PRINT_FIELD_U(", ", dq, d_ino_softlimit);
-       PRINT_FIELD_U(", ", dq, d_bcount);
-       PRINT_FIELD_U(", ", dq, d_icount);
+       PRINT_FIELD_X(", ", *dq, d_fieldmask);
+       PRINT_FIELD_U(", ", *dq, d_id);
+       PRINT_FIELD_U(", ", *dq, d_blk_hardlimit);
+       PRINT_FIELD_U(", ", *dq, d_blk_softlimit);
+       PRINT_FIELD_U(", ", *dq, d_ino_hardlimit);
+       PRINT_FIELD_U(", ", *dq, d_ino_softlimit);
+       PRINT_FIELD_U(", ", *dq, d_bcount);
+       PRINT_FIELD_U(", ", *dq, d_icount);
 
 # if VERBOSE
-       PRINT_FIELD_D(", ", dq, d_itimer);
-       PRINT_FIELD_D(", ", dq, d_btimer);
-       PRINT_FIELD_U(", ", dq, d_iwarns);
-       PRINT_FIELD_U(", ", dq, d_bwarns);
-       PRINT_FIELD_U(", ", dq, d_rtb_hardlimit);
-       PRINT_FIELD_U(", ", dq, d_rtb_softlimit);
-       PRINT_FIELD_U(", ", dq, d_rtbcount);
-       PRINT_FIELD_D(", ", dq, d_rtbtimer);
-       PRINT_FIELD_U(", ", dq, d_rtbwarns);
+       PRINT_FIELD_D(", ", *dq, d_itimer);
+       PRINT_FIELD_D(", ", *dq, d_btimer);
+       PRINT_FIELD_U(", ", *dq, d_iwarns);
+       PRINT_FIELD_U(", ", *dq, d_bwarns);
+       PRINT_FIELD_U(", ", *dq, d_rtb_hardlimit);
+       PRINT_FIELD_U(", ", *dq, d_rtb_softlimit);
+       PRINT_FIELD_U(", ", *dq, d_rtbcount);
+       PRINT_FIELD_D(", ", *dq, d_rtbtimer);
+       PRINT_FIELD_U(", ", *dq, d_rtbwarns);
 # else
        printf(", ...");
 # endif /* !VERBOSE */
@@ -137,23 +137,23 @@ print_xquota_stat(int rc, void *ptr, void *arg)
                return;
        }
 
-       PRINT_FIELD_D("{", qs, qs_version);
+       PRINT_FIELD_D("{", *qs, qs_version);
 
 # if VERBOSE
        printf(", qs_flags=");
        printflags(xfs_quota_flags, qs->qs_flags, "XFS_QUOTA_???");
-       PRINT_FIELD_U(", qs_uquota={", &qs->qs_uquota, qfs_ino);
-       PRINT_FIELD_U(", ", &qs->qs_uquota, qfs_nblks);
-       PRINT_FIELD_U(", ", &qs->qs_uquota, qfs_nextents);
-       PRINT_FIELD_U("}, qs_gquota={", &qs->qs_gquota, qfs_ino);
-       PRINT_FIELD_U(", ", &qs->qs_gquota, qfs_nblks);
-       PRINT_FIELD_U(", ", &qs->qs_gquota, qfs_nextents);
-       PRINT_FIELD_U("}, ", qs, qs_incoredqs);
-       PRINT_FIELD_D(", ", qs, qs_btimelimit);
-       PRINT_FIELD_D(", ", qs, qs_itimelimit);
-       PRINT_FIELD_D(", ", qs, qs_rtbtimelimit);
-       PRINT_FIELD_U(", ", qs, qs_bwarnlimit);
-       PRINT_FIELD_U(", ", qs, qs_iwarnlimit);
+       PRINT_FIELD_U(", qs_uquota={", qs->qs_uquota, qfs_ino);
+       PRINT_FIELD_U(", ", qs->qs_uquota, qfs_nblks);
+       PRINT_FIELD_U(", ", qs->qs_uquota, qfs_nextents);
+       PRINT_FIELD_U("}, qs_gquota={", qs->qs_gquota, qfs_ino);
+       PRINT_FIELD_U(", ", qs->qs_gquota, qfs_nblks);
+       PRINT_FIELD_U(", ", qs->qs_gquota, qfs_nextents);
+       PRINT_FIELD_U("}, ", *qs, qs_incoredqs);
+       PRINT_FIELD_D(", ", *qs, qs_btimelimit);
+       PRINT_FIELD_D(", ", *qs, qs_itimelimit);
+       PRINT_FIELD_D(", ", *qs, qs_rtbtimelimit);
+       PRINT_FIELD_U(", ", *qs, qs_bwarnlimit);
+       PRINT_FIELD_U(", ", *qs, qs_iwarnlimit);
 # else
        printf(", ...");
 # endif /* !VERBOSE */
@@ -171,26 +171,26 @@ print_xquota_statv(int rc, void *ptr, void *arg)
                return;
        }
 
-       PRINT_FIELD_D("{", qs, qs_version);
+       PRINT_FIELD_D("{", *qs, qs_version);
 
 # if VERBOSE
        printf(", qs_flags=");
        printflags(xfs_quota_flags, qs->qs_flags, "XFS_QUOTA_???");
-       PRINT_FIELD_U(", ", qs, qs_incoredqs);
-       PRINT_FIELD_U(", qs_uquota={", &qs->qs_uquota, qfs_ino);
-       PRINT_FIELD_U(", ", &qs->qs_uquota, qfs_nblks);
-       PRINT_FIELD_U(", ", &qs->qs_uquota, qfs_nextents);
-       PRINT_FIELD_U("}, qs_gquota={", &qs->qs_gquota, qfs_ino);
-       PRINT_FIELD_U(", ", &qs->qs_gquota, qfs_nblks);
-       PRINT_FIELD_U(", ", &qs->qs_gquota, qfs_nextents);
-       PRINT_FIELD_U("}, qs_pquota={", &qs->qs_pquota, qfs_ino);
-       PRINT_FIELD_U(", ", &qs->qs_pquota, qfs_nblks);
-       PRINT_FIELD_U(", ", &qs->qs_pquota, qfs_nextents);
-       PRINT_FIELD_D("}, ", qs, qs_btimelimit);
-       PRINT_FIELD_D(", ", qs, qs_itimelimit);
-       PRINT_FIELD_D(", ", qs, qs_rtbtimelimit);
-       PRINT_FIELD_U(", ", qs, qs_bwarnlimit);
-       PRINT_FIELD_U(", ", qs, qs_iwarnlimit);
+       PRINT_FIELD_U(", ", *qs, qs_incoredqs);
+       PRINT_FIELD_U(", qs_uquota={", qs->qs_uquota, qfs_ino);
+       PRINT_FIELD_U(", ", qs->qs_uquota, qfs_nblks);
+       PRINT_FIELD_U(", ", qs->qs_uquota, qfs_nextents);
+       PRINT_FIELD_U("}, qs_gquota={", qs->qs_gquota, qfs_ino);
+       PRINT_FIELD_U(", ", qs->qs_gquota, qfs_nblks);
+       PRINT_FIELD_U(", ", qs->qs_gquota, qfs_nextents);
+       PRINT_FIELD_U("}, qs_pquota={", qs->qs_pquota, qfs_ino);
+       PRINT_FIELD_U(", ", qs->qs_pquota, qfs_nblks);
+       PRINT_FIELD_U(", ", qs->qs_pquota, qfs_nextents);
+       PRINT_FIELD_D("}, ", *qs, qs_btimelimit);
+       PRINT_FIELD_D(", ", *qs, qs_itimelimit);
+       PRINT_FIELD_D(", ", *qs, qs_rtbtimelimit);
+       PRINT_FIELD_U(", ", *qs, qs_bwarnlimit);
+       PRINT_FIELD_U(", ", *qs, qs_iwarnlimit);
 # else
        printf(", ...");
 # endif /* !VERBOSE */
index 88c3fdac6beb409ff3e3825f0e6c71ac8e359591..f1648d94eb25ba6e52e01809490eb6c2afe40af3 100644 (file)
@@ -88,16 +88,16 @@ print_dqblk(long rc, void *ptr, void *arg)
                return;
        }
 
-       PRINT_FIELD_U("{", db, dqb_bhardlimit);
-       PRINT_FIELD_U(", ", db, dqb_bsoftlimit);
-       PRINT_FIELD_U(", ", db, dqb_curspace);
-       PRINT_FIELD_U(", ", db, dqb_ihardlimit);
-       PRINT_FIELD_U(", ", db, dqb_isoftlimit);
-       PRINT_FIELD_U(", ", db, dqb_curinodes);
+       PRINT_FIELD_U("{", *db, dqb_bhardlimit);
+       PRINT_FIELD_U(", ", *db, dqb_bsoftlimit);
+       PRINT_FIELD_U(", ", *db, dqb_curspace);
+       PRINT_FIELD_U(", ", *db, dqb_ihardlimit);
+       PRINT_FIELD_U(", ", *db, dqb_isoftlimit);
+       PRINT_FIELD_U(", ", *db, dqb_curinodes);
 
 # if VERBOSE
-       PRINT_FIELD_U(", ", db, dqb_btime);
-       PRINT_FIELD_U(", ", db, dqb_itime);
+       PRINT_FIELD_U(", ", *db, dqb_btime);
+       PRINT_FIELD_U(", ", *db, dqb_itime);
 
        printf(", dqb_valid=");
        printflags(if_dqblk_valid, db->dqb_valid, "QIF_???");
@@ -118,23 +118,23 @@ print_nextdqblk(long rc, void *ptr, void *arg)
                return;
        }
 
-       PRINT_FIELD_U("{", db, dqb_bhardlimit);
-       PRINT_FIELD_U(", ", db, dqb_bsoftlimit);
-       PRINT_FIELD_U(", ", db, dqb_curspace);
-       PRINT_FIELD_U(", ", db, dqb_ihardlimit);
-       PRINT_FIELD_U(", ", db, dqb_isoftlimit);
-       PRINT_FIELD_U(", ", db, dqb_curinodes);
+       PRINT_FIELD_U("{", *db, dqb_bhardlimit);
+       PRINT_FIELD_U(", ", *db, dqb_bsoftlimit);
+       PRINT_FIELD_U(", ", *db, dqb_curspace);
+       PRINT_FIELD_U(", ", *db, dqb_ihardlimit);
+       PRINT_FIELD_U(", ", *db, dqb_isoftlimit);
+       PRINT_FIELD_U(", ", *db, dqb_curinodes);
 
 # if VERBOSE
-       PRINT_FIELD_U(", ", db, dqb_btime);
-       PRINT_FIELD_U(", ", db, dqb_itime);
+       PRINT_FIELD_U(", ", *db, dqb_btime);
+       PRINT_FIELD_U(", ", *db, dqb_itime);
 
        printf(", dqb_valid=");
        printflags(if_dqblk_valid, db->dqb_valid, "QIF_???");
 
-       PRINT_FIELD_U(", ", db, dqb_id);
+       PRINT_FIELD_U(", ", *db, dqb_id);
 # else
-       PRINT_FIELD_U(", ", db, dqb_id);
+       PRINT_FIELD_U(", ", *db, dqb_id);
        printf(", ...");
 # endif /* !VERBOSE */
        printf("}");
@@ -151,8 +151,8 @@ print_dqinfo(long rc, void *ptr, void *arg)
                return;
        }
 
-       PRINT_FIELD_U("{", di, dqi_bgrace);
-       PRINT_FIELD_U(", ", di, dqi_igrace);
+       PRINT_FIELD_U("{", *di, dqi_bgrace);
+       PRINT_FIELD_U(", ", *di, dqi_igrace);
 
        printf(", dqi_flags=");
        printflags(if_dqinfo_flags, di->dqi_flags, "DQF_???");
index 31eaec58605c1e2e673ce44aef4f4483a53ed115..d3cf53bf2df4d11bf5446df0ccc13b2c0b47d815 100644 (file)
@@ -34,6 +34,7 @@
 # include <inttypes.h>
 # include <stdarg.h>
 # include <stdio.h>
+# include "print_fields.h"
 
 # ifdef HAVE_LINUX_QUOTA_H
 /* Broken in CentOS 5: has extern spinlock_t dq_data_lock; declaration */
 #  define PRJQUOTA 2
 # endif
 
-# define PRINT_FIELD_D(prefix, where, field)   \
-       printf("%s%s=%lld", (prefix), #field,   \
-              sign_extend_unsigned_to_ll((where)->field))
-
-# define PRINT_FIELD_U(prefix, where, field)   \
-       printf("%s%s=%llu", (prefix), #field,   \
-              zero_extend_signed_to_ull((where)->field))
-
-# define PRINT_FIELD_X(prefix, where, field)   \
-       printf("%s%s=%#llx", (prefix), #field,  \
-              zero_extend_signed_to_ull((where)->field))
-
 typedef void (*print_cb)(long rc, void *addr, void *arg);
 
 enum check_quotactl_flag_bits {
index fb23f3471350d6e5515f84c23b4107dca84c4b7a..097e637f1ca2702d099514deed1c141a77b9fda0 100644 (file)
@@ -26,6 +26,7 @@
  */
 
 #include "tests.h"
+#include "print_fields.h"
 
 #include <stdio.h>
 #include <string.h>
@@ -178,9 +179,3 @@ print_nlattr(const unsigned int nla_len, const char *const nla_type)
                        }                                               \
                        printf("]"));                                   \
        } while (0)
-
-#define PRINT_FIELD_U(prefix_, where_, field_)                         \
-       printf("%s%s=%u", (prefix_), #field_, ((where_).field_))
-
-#define PRINT_FIELD_X(prefix_, where_, field_)                         \
-       printf("%s%s=%#x", (prefix_), #field_, ((where_).field_))
index 395cd1f6d6cca252f124d7aedf0b6d03fb308a82..199d21a603e3b5dde34a8709e57d88e847bdde1f 100644 (file)
 # include "kernel_types.h"
 # include "gcc_compat.h"
 
+/*
+ * The printf-like function to use in header files
+ * shared between strace and its tests.
+ */
+#ifndef STRACE_PRINTF
+# define STRACE_PRINTF printf
+#endif
+
 /* Tests of "strace -v" are expected to define VERBOSE to 1. */
 #ifndef VERBOSE
 # define VERBOSE 0
index 305a7262390af4238bae84fe2f45c9545afe822d..7fb93265897c26417d5fe0e699fdb92e8d94e54d 100644 (file)
@@ -48,6 +48,7 @@
 # include <unistd.h>
 # include <sys/sysmacros.h>
 
+# include "print_fields.h"
 # include "statx.h"
 
 # ifndef STRUCT_STAT
@@ -200,9 +201,6 @@ print_stat(const STRUCT_STAT *st)
 static void
 print_stat(const STRUCT_STAT *st)
 {
-#  define PRINT_FIELD_U(field) \
-       printf(", %s=%llu", #field, (unsigned long long) st->field)
-
 #  define PRINT_FIELD_U32_UID(field)                                   \
        do {                                                            \
                if (st->field == (uint32_t) -1)                         \
@@ -225,12 +223,12 @@ print_stat(const STRUCT_STAT *st)
        printf("{stx_mask=");
        printflags(statx_masks, st->stx_mask, "STATX_???");
 
-       PRINT_FIELD_U(stx_blksize);
+       PRINT_FIELD_U(", ", *st, stx_blksize);
 
        printf(", stx_attributes=");
        printflags(statx_attrs, st->stx_attributes, "STATX_ATTR_???");
 
-       PRINT_FIELD_U(stx_nlink);
+       PRINT_FIELD_U(", ", *st, stx_nlink);
        PRINT_FIELD_U32_UID(stx_uid);
        PRINT_FIELD_U32_UID(stx_gid);
 
@@ -239,9 +237,9 @@ print_stat(const STRUCT_STAT *st)
        printf("|");
        print_perms(st->stx_mode);
 
-       PRINT_FIELD_U(stx_ino);
-       PRINT_FIELD_U(stx_size);
-       PRINT_FIELD_U(stx_blocks);
+       PRINT_FIELD_U(", ", *st, stx_ino);
+       PRINT_FIELD_U(", ", *st, stx_size);
+       PRINT_FIELD_U(", ", *st, stx_blocks);
 
        printf(", stx_attributes_mask=");
        printflags(statx_attrs, st->stx_attributes_mask, "STATX_ATTR_???");
@@ -250,10 +248,10 @@ print_stat(const STRUCT_STAT *st)
        PRINT_FIELD_TIME(stx_btime);
        PRINT_FIELD_TIME(stx_ctime);
        PRINT_FIELD_TIME(stx_mtime);
-       PRINT_FIELD_U(stx_rdev_major);
-       PRINT_FIELD_U(stx_rdev_minor);
-       PRINT_FIELD_U(stx_dev_major);
-       PRINT_FIELD_U(stx_dev_minor);
+       PRINT_FIELD_U(", ", *st, stx_rdev_major);
+       PRINT_FIELD_U(", ", *st, stx_rdev_minor);
+       PRINT_FIELD_U(", ", *st, stx_dev_major);
+       PRINT_FIELD_U(", ", *st, stx_dev_minor);
        printf("}");
 }