public inbox for linux-trace-devel@vger.kernel.org
 help / color / mirror / Atom feed
From: Steven Rostedt <rostedt@goodmis.org>
To: linux-trace-devel@vger.kernel.org
Cc: "Steven Rostedt (Google)" <rostedt@goodmis.org>
Subject: [PATCH 1/2] libtraceevent: Split out btf func init code from tep_btf_print_args()
Date: Tue, 20 Jan 2026 15:13:36 -0500	[thread overview]
Message-ID: <20260120201543.460979-2-rostedt@goodmis.org> (raw)
In-Reply-To: <20260120201543.460979-1-rostedt@goodmis.org>

From: "Steven Rostedt (Google)" <rostedt@goodmis.org>

In order to use BTF for various other attributes of functions, move out the
btf function initialization from the tp_btf_print_args() and into its own
function.

Signed-off-by: Steven Rostedt (Google) <rostedt@goodmis.org>
---
 src/trace-btf.c | 70 +++++++++++++++++++++++++++++++------------------
 1 file changed, 45 insertions(+), 25 deletions(-)

diff --git a/src/trace-btf.c b/src/trace-btf.c
index d0231b49d144..0b733bf9cb75 100644
--- a/src/trace-btf.c
+++ b/src/trace-btf.c
@@ -330,35 +330,13 @@ static void assign_arg(unsigned long long *arg, void *args, int size, int a)
 		*(unsigned long long *)(args + a * sizeof(long long));
 }
 
-/**
- * tep_btf_print_args - Print function arguments from BTF info
- * @tep: The tep descriptor to use
- * @s: The trace_seq to write the arguments into
- * @args: The array that holds the arguments
- * @nmem: The number of arguments
- * @size: The size of each item in args (4 or 8).
- * @func: The name of the function.
- *
- * Loads up the @s with a list of arguments for the function based on
- * the @args.
- *
- * If there's no BTF loaded or @func is not found, then it just writes
- * the @args as raw numbers. Otherwise it will pretty print the
- * arguments based on the function info in BTF.
- *
- * Returns: 0 on success and -1 on failure.
- */
-int tep_btf_print_args(struct tep_handle *tep, struct trace_seq *s, void *args,
-		       int nmem, int size, const char *func)
+static int init_btf_func(struct tep_btf *btf, struct trace_seq *s,
+			 void *args, int nmem, int size,
+			 const char *func, struct btf_type **p_type)
 {
-	struct tep_btf *btf = tep->btf;
 	struct btf_type *type = tep_btf_find_func(btf, func);
-	struct btf_param *param;
 	unsigned long long arg;
-	unsigned int encode;
-	const char *param_name;
 	const char *fp;
-	int a, p, x, nr;
 
 	if (size != 4 && size != 8)
 		return -1;
@@ -381,6 +359,7 @@ int tep_btf_print_args(struct tep_handle *tep, struct trace_seq *s, void *args,
 			if (i + 1 < nmem)
 				trace_seq_puts(s, ", ");
 		}
+		*p_type = NULL;
 		return 0;
 	}
 
@@ -391,6 +370,47 @@ int tep_btf_print_args(struct tep_handle *tep, struct trace_seq *s, void *args,
 		return -1;
 	}
 
+	*p_type = type;
+
+	return 0;
+}
+
+/**
+ * tep_btf_print_args - Print function arguments from BTF info
+ * @tep: The tep descriptor to use
+ * @s: The trace_seq to write the arguments into
+ * @args: The array that holds the arguments
+ * @nmem: The number of arguments
+ * @size: The size of each item in args (4 or 8).
+ * @func: The name of the function.
+ *
+ * Loads up the @s with a list of arguments for the function based on
+ * the @args.
+ *
+ * If there's no BTF loaded or @func is not found, then it just writes
+ * the @args as raw numbers. Otherwise it will pretty print the
+ * arguments based on the function info in BTF.
+ *
+ * Returns: 0 on success and -1 on failure.
+ */
+int tep_btf_print_args(struct tep_handle *tep, struct trace_seq *s, void *args,
+		       int nmem, int size, const char *func)
+{
+	struct tep_btf *btf = tep->btf;
+	struct btf_type *type = tep_btf_find_func(btf, func);
+	struct btf_param *param;
+	unsigned long long arg;
+	unsigned int encode;
+	const char *param_name;
+	int a, p, x, nr;
+
+	if (init_btf_func(btf, s, args, nmem, size, func, &type) < 0)
+		return -1;
+
+	/* Type is NULL if function wasn't found */
+	if (!type)
+		return 0;
+
 	/* Get the function proto */
 	type = btf_get_type(btf, type->type);
 
-- 
2.51.0


  reply	other threads:[~2026-01-20 20:15 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-01-20 20:13 [PATCH 0/2] libtraceevent: Add way to print function prototype Steven Rostedt
2026-01-20 20:13 ` Steven Rostedt [this message]
2026-01-20 20:13 ` [PATCH 2/2] libtraceevent: Add tep_btf_list_args() Steven Rostedt

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=20260120201543.460979-2-rostedt@goodmis.org \
    --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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox