From: Eugene Syromyatnikov Date: Thu, 10 May 2018 16:29:39 +0000 (+0200) Subject: nlattr: print index names in netlink meminfo array X-Git-Tag: v4.23~89 X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=540d70fcb680228f7ccf58c11370b5f252e4b73e;p=strace nlattr: print index names in netlink meminfo array * xlat/netlink_sk_meminfo_indices.in: New file. * nlattr.c: Include xlat/netlink_sk_meminfo_indices.h. (decode_nla_meminfo): Use print_array_ex, pass netlink_sk_meminfo_indices as index xlat table. * tests/nlattr_inet_diag_msg.c: Update expected output. --- diff --git a/nlattr.c b/nlattr.c index 924e647f..d2ff8413 100644 --- a/nlattr.c +++ b/nlattr.c @@ -36,6 +36,8 @@ #include #include "static_assert.h" +#include "xlat/netlink_sk_meminfo_indices.h" + static bool fetch_nlattr(struct tcb *const tcp, struct nlattr *const nlattr, const kernel_ulong_t addr, const unsigned int len, @@ -199,8 +201,12 @@ decode_nla_meminfo(struct tcb *const tcp, return false; unsigned int count = 0; - print_array(tcp, addr, nmemb, &mem, sizeof(mem), - tfetch_mem, print_uint32_array_member, &count); + print_array_ex(tcp, addr, nmemb, &mem, sizeof(mem), + tfetch_mem, print_uint32_array_member, &count, + PAF_PRINT_INDICES | PAF_INDEX_XLAT_VALUE_INDEXED + | XLAT_STYLE_FMT_U, + ARRSZ_PAIR(netlink_sk_meminfo_indices), + "SK_MEMINFO_???"); return true; } diff --git a/tests/nlattr_inet_diag_msg.c b/tests/nlattr_inet_diag_msg.c index 7360055f..b94034c4 100644 --- a/tests/nlattr_inet_diag_msg.c +++ b/tests/nlattr_inet_diag_msg.c @@ -37,6 +37,18 @@ #include #include +static const char * const sk_meminfo_strs[] = { + "SK_MEMINFO_RMEM_ALLOC", + "SK_MEMINFO_RCVBUF", + "SK_MEMINFO_WMEM_ALLOC", + "SK_MEMINFO_SNDBUF", + "SK_MEMINFO_FWD_ALLOC", + "SK_MEMINFO_WMEM_QUEUED", + "SK_MEMINFO_OPTMEM", + "SK_MEMINFO_BACKLOG", + "SK_MEMINFO_DROPS", +}; + static const char address[] = "10.11.12.13"; static void @@ -79,7 +91,12 @@ print_inet_diag_msg(const unsigned int msg_len) static void print_uint(const unsigned int *p, size_t i) { - printf("%u", *p); + if (i >= ARRAY_SIZE(sk_meminfo_strs)) + printf("[%zu /* SK_MEMINFO_??? */", i); + else + printf("[%s", sk_meminfo_strs[i]); + + printf("] = %u", *p); } int diff --git a/xlat/netlink_sk_meminfo_indices.in b/xlat/netlink_sk_meminfo_indices.in new file mode 100644 index 00000000..1e2f7950 --- /dev/null +++ b/xlat/netlink_sk_meminfo_indices.in @@ -0,0 +1,10 @@ +#value_indexed +SK_MEMINFO_RMEM_ALLOC 0 +SK_MEMINFO_RCVBUF 1 +SK_MEMINFO_WMEM_ALLOC 2 +SK_MEMINFO_SNDBUF 3 +SK_MEMINFO_FWD_ALLOC 4 +SK_MEMINFO_WMEM_QUEUED 5 +SK_MEMINFO_OPTMEM 6 +SK_MEMINFO_BACKLOG 7 +SK_MEMINFO_DROPS 8