poll.c \
prctl.c \
print_dev_t.c \
+ print_fields.h \
print_mq_attr.c \
print_msgbuf.c \
print_sg_req_info.c \
#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)
--- /dev/null
+/*
+ * 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 */
*/
#include "defs.h"
+#include "print_fields.h"
#define SUBCMDMASK 0x00ff
#define SUBCMDSHIFT 8
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)
{
*/
#include "defs.h"
+#include "print_fields.h"
#include "statx.h"
#include <sys/stat.h>
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 \
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);
}
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,
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(", ...");
}
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 */
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 */
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 */
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_???");
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("}");
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_???");
# 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 {
*/
#include "tests.h"
+#include "print_fields.h"
#include <stdio.h>
#include <string.h>
} \
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_))
# 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
# include <unistd.h>
# include <sys/sysmacros.h>
+# include "print_fields.h"
# include "statx.h"
# ifndef STRUCT_STAT
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) \
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);
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_???");
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("}");
}