All of lore.kernel.org
 help / color / mirror / Atom feed
From: Steven Rostedt <rostedt@goodmis.org>
To: Linux Trace Devel <linux-trace-devel@vger.kernel.org>
Subject: [PATCH] libtraceveent: Add printable characters
Date: Fri, 29 May 2026 14:53:19 -0400	[thread overview]
Message-ID: <20260529145319.49b0acd4@fedora> (raw)

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


                 reply	other threads:[~2026-05-29 18:53 UTC|newest]

Thread overview: [no followups] expand[flat|nested]  mbox.gz  Atom feed

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20260529145319.49b0acd4@fedora \
    --to=rostedt@goodmis.org \
    --cc=linux-trace-devel@vger.kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.