From b738f44a524772498bb08093eb109d38b6510355 Mon Sep 17 00:00:00 2001 From: "Dmitry V. Levin" Date: Fri, 1 Sep 2017 08:41:08 +0000 Subject: [PATCH] rtnl_neightbl: enhance decoding of struct ndt_stats Add support of kernels that operate with older definition of struct ndt_stats than the definition used to build strace. * rtnl_neightbl.c (decode_ndt_stats): Add runtime detection of struct ndt_stats.ndts_table_fulls field, print the field when it is available. --- rtnl_neightbl.c | 16 ++++++++++++---- 1 file changed, 12 insertions(+), 4 deletions(-) diff --git a/rtnl_neightbl.c b/rtnl_neightbl.c index 5db89ceb..9d6cec2d 100644 --- a/rtnl_neightbl.c +++ b/rtnl_neightbl.c @@ -113,10 +113,17 @@ decode_ndt_stats(struct tcb *const tcp, { #ifdef HAVE_STRUCT_NDT_STATS struct ndt_stats ndtst; - - if (len < sizeof(ndtst)) + const unsigned int min_size = + offsetofend(struct ndt_stats, ndts_forced_gc_runs); + const unsigned int def_size = sizeof(ndtst); + const unsigned int size = + (len >= def_size) ? def_size : + ((len == min_size) ? min_size : 0); + + if (!size) return false; - else if (!umove_or_printaddr(tcp, addr, &ndtst)) { + + if (!umoven_or_printaddr(tcp, addr, size, &ndtst)) { PRINT_FIELD_U("{", ndtst, ndts_allocs); PRINT_FIELD_U(", ", ndtst, ndts_destroys); PRINT_FIELD_U(", ", ndtst, ndts_hash_grows); @@ -128,7 +135,8 @@ decode_ndt_stats(struct tcb *const tcp, PRINT_FIELD_U(", ", ndtst, ndts_periodic_gc_runs); PRINT_FIELD_U(", ", ndtst, ndts_forced_gc_runs); #ifdef HAVE_STRUCT_NDT_STATS_NDTS_TABLE_FULLS - PRINT_FIELD_U(", ", ndtst, ndts_table_fulls); + if (len >= def_size) + PRINT_FIELD_U(", ", ndtst, ndts_table_fulls); #endif tprints("}"); } -- 2.50.1