diff options
author | Eugene Syromyatnikov <evgsyr@gmail.com> | 2021-10-06 16:09:50 +0200 |
---|---|---|
committer | Eugene Syromyatnikov <evgsyr@gmail.com> | 2021-10-09 19:24:40 +0200 |
commit | 9082fd76aa65b3b0fb79eb1b950d0a68dbeeabe3 (patch) | |
tree | 75b0a94f9ebf76bb199cb48ed0eff608bc221b3d | |
parent | b1c0b004635feaea2b85c64e34bfb544602b8c5a (diff) | |
download | strace-9082fd76aa65b3b0fb79eb1b950d0a68dbeeabe3.tar.gz |
nlattr: make xval/flag nlattr printing a bit more structured
Since the only usage for prefix/suffix was to enframe the xval/flag
output in a function call syntax (that is inverse to process_fn),
let's simply provide fn_str and print it using tprints_arg_begin
and tprint_arg_end.
* src/nlattr.h (decode_nla_xlat_opts): Remove prefix and suffix fields,
add fn_str field.
* src/nlattr.c (decode_nla_xval, decode_nla_flags): Output fn_str using
tprints_arg_begin, call tprint_arg_end if fn_str is non-NULL.
(decode_nla_ether_proto): Pass "htons" in fn_str field of the opts
structure instead of "htons(" and ")" as prefix and suffix,
respectively.
-rw-r--r-- | src/nlattr.c | 19 | ||||
-rw-r--r-- | src/nlattr.h | 3 |
2 files changed, 10 insertions, 12 deletions
diff --git a/src/nlattr.c b/src/nlattr.c index f1d8f4fa5..89f00dbfc 100644 --- a/src/nlattr.c +++ b/src/nlattr.c @@ -298,11 +298,11 @@ decode_nla_xval(struct tcb *const tcp, if (!umoven_to_uint64_or_printaddr(tcp, addr, len, &data)) { if (opts->process_fn) data = opts->process_fn(data); - if (opts->prefix) - tprints(opts->prefix); + if (opts->fn_str) + tprints_arg_begin(opts->fn_str); printxval_ex(opts->xlat, data, opts->dflt, opts->style); - if (opts->suffix) - tprints(opts->suffix); + if (opts->fn_str) + tprint_arg_end(); } return true; @@ -323,10 +323,9 @@ decode_nla_ether_proto(struct tcb *const tcp, static const struct decode_nla_xlat_opts opts = { .xlat = ethernet_protocols, .dflt = "ETHER_P_???", - .prefix = "htons(", - .suffix = ")", .size = 2, .process_fn = process_host_order, + .fn_str = "htons", }; return decode_nla_xval(tcp, addr, len, &opts); @@ -417,11 +416,11 @@ decode_nla_flags(struct tcb *const tcp, if (!umoven_to_uint64_or_printaddr(tcp, addr, len, &data)) { if (opts->process_fn) data = opts->process_fn(data); - if (opts->prefix) - tprints(opts->prefix); + if (opts->fn_str) + tprints_arg_begin(opts->fn_str); printflags_ex(data, opts->dflt, opts->style, opts->xlat, NULL); - if (opts->suffix) - tprints(opts->suffix); + if (opts->fn_str) + tprint_arg_end(); } return true; diff --git a/src/nlattr.h b/src/nlattr.h index a4c503008..3f00e2604 100644 --- a/src/nlattr.h +++ b/src/nlattr.h @@ -16,8 +16,7 @@ struct decode_nla_xlat_opts { const struct xlat *xlat; const char *dflt; enum xlat_style style; - const char *prefix; - const char *suffix; + const char *fn_str; uint64_t (*process_fn)(uint64_t val); size_t size; }; |