From: Dmitry V. Levin Date: Sat, 1 Jul 2017 13:14:49 +0000 (+0000) Subject: Unify different generic PRINT_FIELD_* implementations X-Git-Tag: v4.18~13 X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=26954f775380c11eecd486f0959a222a61a51454;p=strace Unify different generic PRINT_FIELD_* implementations 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. --- diff --git a/Makefile.am b/Makefile.am index 76be3ca3..7c0658d5 100644 --- a/Makefile.am +++ b/Makefile.am @@ -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 \ diff --git a/netlink_sock_diag.c b/netlink_sock_diag.c index cd49e7d4..38889349 100644 --- a/netlink_sock_diag.c +++ b/netlink_sock_diag.c @@ -30,6 +30,7 @@ #include "defs.h" #include "netlink.h" #include "nlattr.h" +#include "print_fields.h" #include #include @@ -65,31 +66,6 @@ #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 index 00000000..92b8a8a1 --- /dev/null +++ b/print_fields.h @@ -0,0 +1,68 @@ +/* + * Copyright (c) 2016-2017 Dmitry V. Levin + * 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 ef151662..ab2f1cec 100644 --- 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 6e913878..c78b173d 100644 --- a/statx.c +++ b/statx.c @@ -26,6 +26,7 @@ */ #include "defs.h" +#include "print_fields.h" #include "statx.h" #include @@ -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(", ..."); } diff --git a/tests/quotactl-xfs.c b/tests/quotactl-xfs.c index 1c7d07e3..fab451e2 100644 --- a/tests/quotactl-xfs.c +++ b/tests/quotactl-xfs.c @@ -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 */ diff --git a/tests/quotactl.c b/tests/quotactl.c index 88c3fdac..f1648d94 100644 --- a/tests/quotactl.c +++ b/tests/quotactl.c @@ -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_???"); diff --git a/tests/quotactl.h b/tests/quotactl.h index 31eaec58..d3cf53bf 100644 --- a/tests/quotactl.h +++ b/tests/quotactl.h @@ -34,6 +34,7 @@ # include # include # include +# include "print_fields.h" # ifdef HAVE_LINUX_QUOTA_H /* Broken in CentOS 5: has extern spinlock_t dq_data_lock; declaration */ @@ -57,18 +58,6 @@ # 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 { diff --git a/tests/test_nlattr.h b/tests/test_nlattr.h index fb23f347..097e637f 100644 --- a/tests/test_nlattr.h +++ b/tests/test_nlattr.h @@ -26,6 +26,7 @@ */ #include "tests.h" +#include "print_fields.h" #include #include @@ -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_)) diff --git a/tests/tests.h b/tests/tests.h index 395cd1f6..199d21a6 100644 --- a/tests/tests.h +++ b/tests/tests.h @@ -37,6 +37,14 @@ # 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 diff --git a/tests/xstatx.c b/tests/xstatx.c index 305a7262..7fb93265 100644 --- a/tests/xstatx.c +++ b/tests/xstatx.c @@ -48,6 +48,7 @@ # include # include +# 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("}"); }