Skip to contentSkip to conversation

libtraceevent: Use BTF_INT_BITS/OFFSET() when parsing int parameters

PATCH New Steven Rostedt 1 participant 1 message Nov 14, 2025

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 libtraceevent: Use BTF_INT_BITS/OFFSET() when parsing int parameters

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.

---
 src/trace-btf.c | 7 +++++++
 1 file changed, 7 insertions(+)
src/trace-btf.c +7 -0
index 742cffd35edc..d0231b49d144 100644
@@ -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);
Signature · 1 line
2.51.0