From 2d727ee3d29798ea544b7a1a28f88baa60e2e2b6 Mon Sep 17 00:00:00 2001 From: "Dmitry V. Levin" Date: Mon, 10 Jul 2017 02:23:00 +0000 Subject: [PATCH] Intorduce PRINT_FIELD_0X * print_fields.h (PRINT_FIELD_0X): New macro. * sockaddr.c (print_sockaddr_data_ipx, print_sockaddr_data_nl): Use it instead of manual tprintf statements. * netlink_sock_diag.c (PRINT_FIELD_SMC_DIAG_CONNINFO_FLAGS): Remove. (decode_smc_diag_conninfo): Replace it with PRINT_FIELD_0X. --- netlink_sock_diag.c | 13 ++++--------- print_fields.h | 5 +++++ sockaddr.c | 6 +++--- 3 files changed, 12 insertions(+), 12 deletions(-) diff --git a/netlink_sock_diag.c b/netlink_sock_diag.c index d162fbd9..1bb832e7 100644 --- a/netlink_sock_diag.c +++ b/netlink_sock_diag.c @@ -916,11 +916,6 @@ print_smc_diag_cursor(const struct smc_diag_cursor *const cursor) print_smc_diag_cursor(&(where_).field_); \ } while (0) -#define PRINT_FIELD_SMC_DIAG_CONNINFO_FLAGS(prefix_, where_, field_) \ - tprintf("%s%s=%#0*x", \ - (prefix_), #field_, \ - (int) sizeof(where_).field_, (where_).field_) - static bool decode_smc_diag_conninfo(struct tcb *const tcp, const kernel_ulong_t addr, @@ -942,10 +937,10 @@ decode_smc_diag_conninfo(struct tcb *const tcp, PRINT_FIELD_SMC_DIAG_CURSOR(", ", cinfo, rx_cons); PRINT_FIELD_SMC_DIAG_CURSOR(", ", cinfo, tx_prod); PRINT_FIELD_SMC_DIAG_CURSOR(", ", cinfo, tx_cons); - PRINT_FIELD_SMC_DIAG_CONNINFO_FLAGS(", ", cinfo, rx_prod_flags); - PRINT_FIELD_SMC_DIAG_CONNINFO_FLAGS(", ", cinfo, rx_conn_state_flags); - PRINT_FIELD_SMC_DIAG_CONNINFO_FLAGS(", ", cinfo, tx_prod_flags); - PRINT_FIELD_SMC_DIAG_CONNINFO_FLAGS(", ", cinfo, tx_conn_state_flags); + PRINT_FIELD_0X(", ", cinfo, rx_prod_flags); + PRINT_FIELD_0X(", ", cinfo, rx_conn_state_flags); + PRINT_FIELD_0X(", ", cinfo, tx_prod_flags); + PRINT_FIELD_0X(", ", cinfo, tx_conn_state_flags); PRINT_FIELD_SMC_DIAG_CURSOR(", ", cinfo, tx_prep); PRINT_FIELD_SMC_DIAG_CURSOR(", ", cinfo, tx_sent); PRINT_FIELD_SMC_DIAG_CURSOR(", ", cinfo, tx_fin); diff --git a/print_fields.h b/print_fields.h index e7bf5d8d..49e5def0 100644 --- a/print_fields.h +++ b/print_fields.h @@ -48,6 +48,11 @@ STRACE_PRINTF("%s%s=%#llx", (prefix_), #field_, \ zero_extend_signed_to_ull((where_).field_)) +#define PRINT_FIELD_0X(prefix_, where_, field_) \ + STRACE_PRINTF("%s%s=%#0*llx", (prefix_), #field_, \ + (int) sizeof((where_).field_) * 2, \ + 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]), \ diff --git a/sockaddr.c b/sockaddr.c index 1e8fbdc1..875b22df 100644 --- a/sockaddr.c +++ b/sockaddr.c @@ -158,7 +158,7 @@ print_sockaddr_data_ipx(const void *const buf, const int addrlen) tprintf("%s%#02x", i ? ", " : "", sa_ipx->sipx_node[i]); } - tprintf("], sipx_type=%#02x", sa_ipx->sipx_type); + PRINT_FIELD_0X("], ", *sa_ipx, sipx_type); } static void @@ -166,8 +166,8 @@ print_sockaddr_data_nl(const void *const buf, const int addrlen) { const struct sockaddr_nl *const sa_nl = buf; - tprintf("nl_pid=%d, nl_groups=%#08x", - sa_nl->nl_pid, sa_nl->nl_groups); + PRINT_FIELD_D("", *sa_nl, nl_pid); + PRINT_FIELD_0X(", ", *sa_nl, nl_groups); } static void -- 2.40.0