diff mbox series

libtraceevent: If function has arguments print them

Message ID 20250404153032.2ec27f47@gandalf.local.home (mailing list archive)
State Accepted
Commit e798103c0815e6642e74d9317c325b2c62681f2e
Headers show
Series libtraceevent: If function has arguments print them | expand

Commit Message

Steven Rostedt April 4, 2025, 7:30 p.m. UTC
From: "Steven Rostedt (Google)" <rostedt@goodmis.org>

Starting with v6.15, function tracer can hold arguments. If the event has them,
then print them.

Signed-off-by: Steven Rostedt (Google) <rostedt@goodmis.org>
---
 plugins/plugin_function.c | 35 +++++++++++++++++++++++++++++++++++
 1 file changed, 35 insertions(+)
diff mbox series

Patch

diff --git a/plugins/plugin_function.c b/plugins/plugin_function.c
index 2d6509b..a337446 100644
--- a/plugins/plugin_function.c
+++ b/plugins/plugin_function.c
@@ -133,6 +133,39 @@  static void show_function(struct trace_seq *s, struct tep_handle *tep,
 	}
 }
 
+/* Returns true if it printed args, otherwise it returns false */
+static bool print_args(struct trace_seq *s, struct tep_event *event,
+		       struct tep_record *record)
+{
+	struct tep_format_field *field;
+	unsigned long arg;
+	void *args;
+	int len;
+
+	field = tep_find_field(event, "args");
+	if (!field)
+		return false;
+
+	len = record->size - field->offset;
+
+	/* todo make this tep long size */
+	if (len < 3 * sizeof(long))
+		return false;
+
+	args = record->data + field->offset;
+
+	trace_seq_putc(s, '(');
+
+	for (int i = 0; i < len; i += sizeof(long), args += sizeof(long)) {
+		memcpy(&arg, args, sizeof(long));
+		trace_seq_printf(s, "%lx", arg);
+		if (i + sizeof(long) < len)
+			trace_seq_puts(s, ", ");
+	}
+	trace_seq_putc(s, ')');
+	return true;
+}
+
 static int function_handler(struct trace_seq *s, struct tep_record *record,
 			    struct tep_event *event, void *context)
 {
@@ -163,6 +196,8 @@  static int function_handler(struct trace_seq *s, struct tep_record *record,
 	else
 		trace_seq_printf(s, "0x%llx", function);
 
+	print_args(s, event, record);
+
 	if (ftrace_parent->set) {
 		trace_seq_printf(s, " <-- ");
 		if (parent)