[PATCH] libtraceevent: Use BTF_INT_BITS/OFFSET() when parsing int parameters
Steven Rostedt <[email protected]> Fri, 14 Nov 2025 14:09:25 -0500
| Newsgroups | org.kernel.vger.linux-trace-devel |
|---|---|
| Message-ID | <[email protected]> |
From: "Steven Rostedt (Google)" <[email protected]> The BTF_KIND_INT can be less than 64 bits in size and the BTF_INT_BITS(encode) will express that. Also process BTF_INT_OFFSET() even though it is likely to be zero every time, but it follows the specification. Link: https://lore.kernel.org/all/[email protected]/ Suggested-by: Douglas Raillard <[email protected]> Signed-off-by: Steven Rostedt (Google) <[email protected]> --- src/trace-btf.c | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/src/trace-btf.c b/src/trace-btf.c index 742cffd35edc..d0231b49d144 100644 --- a/src/trace-btf.c +++ b/src/trace-btf.c @@ -413,6 +413,8 @@ int tep_btf_print_args(struct tep_handle *tep, struct trace_seq *s, void *args, for (a = 0, p = 0; p < nr; a++, p++) { struct btf_type *t; + int offset; + int bits; if (p) trace_seq_puts(s, ", "); @@ -440,6 +442,11 @@ int tep_btf_print_args(struct tep_handle *tep, struct trace_seq *s, void *args, break; case BTF_KIND_INT: encode = *(int *)((void *)t + sizeof(*t)); + bits = BTF_INT_BITS(encode); + offset = BTF_INT_OFFSET(encode); + arg >>= offset; + if (bits < 64) + arg &= (1ULL << bits) - 1; /* Print unsigned ints as hex */ if (BTF_INT_ENCODING(encode) & BTF_INT_SIGNED) trace_seq_printf(s, "%lld", arg); -- 2.51.0