On Tue, 17 Dec 2024 14:24:08 -0800 Linus Torvalds torvalds@linux-foundation.org wrote:
(Aside: are those binary buffers actually exported to user space (that "u32 *bin_buf, size_t size" thing), or could we fix the binary printf code to really use a whole word for char/short values? The difference between '%hhd' and '%d' should be how it's printed out, not how the data is accessed)
libtraceevent is able to parse the raw trace_printk() events:
https://git.kernel.org/pub/scm/libs/libtrace/libtraceevent.git/tree/src/even...
The format it reads is from /sys/kernel/tracing/events/ftrace/bprint/format:
name: bprint ID: 6 format: field:unsigned short common_type; offset:0; size:2; signed:0; field:unsigned char common_flags; offset:2; size:1; signed:0; field:unsigned char common_preempt_count; offset:3; size:1; signed:0; field:int common_pid; offset:4; size:4; signed:1;
field:unsigned long ip; offset:8; size:8; signed:0; field:const char * fmt; offset:16; size:8; signed:0; field:u32 buf[]; offset:24; size:0; signed:0;
print fmt: "%ps: %s", (void *)REC->ip, REC->fmt
In this case, the "print fmt" is ignored.
Where the buf value holds the binary storage from vbin_printf() and written in trace_vbprintk(). Yeah, it looks like it does depend on the arguments being word aligned.
-- Steve