Linux Trace Development
 help / color / mirror / Atom feed
* [PATCH] libtraceveent: Add printable characters
@ 2026-05-29 18:53 Steven Rostedt
  0 siblings, 0 replies; only message in thread
From: Steven Rostedt @ 2026-05-29 18:53 UTC (permalink / raw)
  To: Linux Trace Devel

From: Steven Rostedt <rostedt@goodmis.org>

If an array of characters are all printable, print the string it represents.

Signed-off-by: Steven Rostedt <rostedt@goodmis.org>
---
 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


^ permalink raw reply related	[flat|nested] only message in thread

only message in thread, other threads:[~2026-05-29 18:53 UTC | newest]

Thread overview: (only message) (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-05-29 18:53 [PATCH] libtraceveent: Add printable characters Steven Rostedt

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox