[PATCH] libtraceveent: Add printable characters
Steven Rostedt <[email protected]> Fri, 29 May 2026 14:53:19 -0400
| Newsgroups | org.kernel.vger.linux-trace-devel |
|---|---|
| Message-ID | <20260529145319.49b0acd4@fedora> |
From: Steven Rostedt <[email protected]> If an array of characters are all printable, print the string it represents. Signed-off-by: Steven Rostedt <[email protected]> --- src/event-parse.c | 29 ++++++++++++++++++++++++++++- 1 file changed, 28 insertions(+), 1 deletion(-) diff --git a/src/event-parse.c b/src/event-parse.c index 0427e29..4ba2686 100644 --- a/src/event-parse.c +++ b/src/event-parse.c @@ -5416,6 +5416,7 @@ static void print_str_arg(struct trace_seq *s, void *data, int size, case TEP_PRINT_INT_ARRAY: { void *num; int el_size; + int is_print = 0; len = 0; @@ -5450,7 +5451,20 @@ static void print_str_arg(struct trace_seq *s, void *data, int size, trace_seq_putc(s, ','); if (el_size == 1) { - trace_seq_printf(s, "0x%x", *(uint8_t *)num); + int ch = *(uint8_t *)num; + + trace_seq_printf(s, "0x%x", ch); + + if (!is_print) + is_print = 1; + + /* + * Only print string if all characters are + * printable + */ + if (is_print && !isprint(ch) && !isspace(ch)) + is_print = -1; + } else if (el_size == 2) { trace_seq_printf(s, "0x%x", *(uint16_t *)num); } else if (el_size == 4) { @@ -5466,6 +5480,19 @@ static void print_str_arg(struct trace_seq *s, void *data, int size, num += el_size; } trace_seq_putc(s, '}'); + + if (is_print == 1) { + char *p = data + offset; + + trace_seq_puts(s, " \""); + for (i = 0; i < len; i++) { + if (p[i] == '\n') + trace_seq_puts(s, "\\n"); + else + trace_seq_putc(s, p[i]); + } + trace_seq_putc(s, '"'); + } break; } case TEP_PRINT_TYPE: -- 2.51.0