]> granicus.if.org Git - strace/commitdiff
nlattr: print index names in netlink meminfo array
authorEugene Syromyatnikov <evgsyr@gmail.com>
Thu, 10 May 2018 16:29:39 +0000 (18:29 +0200)
committerDmitry V. Levin <ldv@altlinux.org>
Wed, 30 May 2018 10:13:06 +0000 (10:13 +0000)
* 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.

nlattr.c
tests/nlattr_inet_diag_msg.c
xlat/netlink_sk_meminfo_indices.in [new file with mode: 0644]

index 924e647fa29fe502a032fd5ffa5c3c7f9fefda75..d2ff8413da00392f3741d0591f72ce79ec9da408 100644 (file)
--- a/nlattr.c
+++ b/nlattr.c
@@ -36,6 +36,8 @@
 #include <linux/sock_diag.h>
 #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;
 }
index 7360055fd6c066e9475f5ca0b44dabb3e4c7a267..b94034c4d2339a032367cc3f6ffcfa5d86252e82 100644 (file)
 #include <linux/inet_diag.h>
 #include <linux/sock_diag.h>
 
+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 (file)
index 0000000..1e2f795
--- /dev/null
@@ -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