From: Masami Hiramatsu (Google) <mhiramat@kernel.org>
To: Sven Schnelle <svens@linux.ibm.com>
Cc: Steven Rostedt <rostedt@goodmis.org>,
Mark Rutland <mark.rutland@arm.com>,
Mathieu Desnoyers <mathieu.desnoyers@efficios.com>,
linux-kernel@vger.kernel.org, linux-trace-kernel@vger.kernel.org,
bpf@vger.kernel.org
Subject: Re: [PATCH 4/7] Add print_function_args()
Date: Mon, 9 Sep 2024 00:17:18 +0900 [thread overview]
Message-ID: <20240909001718.ffbfc2ac8b7888a94735720f@kernel.org> (raw)
In-Reply-To: <20240904065908.1009086-5-svens@linux.ibm.com>
On Wed, 4 Sep 2024 08:58:58 +0200
Sven Schnelle <svens@linux.ibm.com> wrote:
> Add a function to decode argument types with the help of BTF. Will
> be used to display arguments in the function and function graph
> tracer.
>
> Signed-off-by: Sven Schnelle <svens@linux.ibm.com>
> ---
> kernel/trace/trace_output.c | 68 +++++++++++++++++++++++++++++++++++++
> kernel/trace/trace_output.h | 9 +++++
> 2 files changed, 77 insertions(+)
>
> diff --git a/kernel/trace/trace_output.c b/kernel/trace/trace_output.c
> index d8b302d01083..70405c4cceb6 100644
> --- a/kernel/trace/trace_output.c
> +++ b/kernel/trace/trace_output.c
> @@ -12,8 +12,11 @@
> #include <linux/sched/clock.h>
> #include <linux/sched/mm.h>
> #include <linux/idr.h>
> +#include <linux/btf.h>
> +#include <linux/bpf.h>
>
> #include "trace_output.h"
> +#include "trace_btf.h"
>
> /* must be a power of 2 */
> #define EVENT_HASHSIZE 128
> @@ -669,6 +672,71 @@ int trace_print_lat_context(struct trace_iterator *iter)
> return !trace_seq_has_overflowed(s);
> }
>
> +#ifdef CONFIG_FUNCTION_TRACE_ARGS
> +void print_function_args(struct trace_seq *s, struct ftrace_regs *fregs,
> + unsigned long func)
> +{
> + const struct btf_param *param;
> + const struct btf_type *t;
> + const char *param_name;
> + char name[KSYM_NAME_LEN];
> + unsigned long arg;
> + struct btf *btf;
> + s32 tid, nr = 0;
> + int i;
> +
> + trace_seq_printf(s, "(");
> +
> + if (!ftrace_regs_has_args(fregs))
> + goto out;
> + if (lookup_symbol_name(func, name))
> + goto out;
> +
> + btf = bpf_get_btf_vmlinux();
> + if (IS_ERR_OR_NULL(btf))
> + goto out;
> +
> + t = btf_find_func_proto(name, &btf);
> + if (IS_ERR_OR_NULL(t))
> + goto out;
> +
> + param = btf_get_func_param(t, &nr);
> + if (!param)
> + goto out_put;
> +
> + for (i = 0; i < nr; i++) {
> + arg = ftrace_regs_get_argument(fregs, i);
> +
> + param_name = btf_name_by_offset(btf, param[i].name_off);
> + if (param_name)
> + trace_seq_printf(s, "%s = ", param_name);
> + t = btf_type_skip_modifiers(btf, param[i].type, &tid);
> + if (!t)
> + continue;
> + switch (BTF_INFO_KIND(t->info)) {
> + case BTF_KIND_PTR:
> + trace_seq_printf(s, "0x%lx", arg);
> + break;
> + case BTF_KIND_INT:
> + trace_seq_printf(s, "%ld", arg);
Don't we check the size and signed? :)
> + break;
> + case BTF_KIND_ENUM:
> + trace_seq_printf(s, "%ld", arg);
nit: %d? (enum is equal to the int type)
BTW, this series splits the patches by coding, not functionality.
For the first review, it is OK. But eventually those should be merged.
Thank you,
> + break;
> + default:
> + trace_seq_printf(s, "0x%lx (%d)", arg, BTF_INFO_KIND(param[i].type));
> + break;
> + }
> + if (i < nr - 1)
> + trace_seq_printf(s, ", ");
> + }
> +out_put:
> + btf_put(btf);
> +out:
> + trace_seq_printf(s, ")");
> +}
> +#endif
> +
> /**
> * ftrace_find_event - find a registered event
> * @type: the type of event to look for
> diff --git a/kernel/trace/trace_output.h b/kernel/trace/trace_output.h
> index dca40f1f1da4..a21d8ce606f7 100644
> --- a/kernel/trace/trace_output.h
> +++ b/kernel/trace/trace_output.h
> @@ -41,5 +41,14 @@ extern struct rw_semaphore trace_event_sem;
> #define SEQ_PUT_HEX_FIELD(s, x) \
> trace_seq_putmem_hex(s, &(x), sizeof(x))
>
> +#ifdef CONFIG_FUNCTION_TRACE_ARGS
> +void print_function_args(struct trace_seq *s, struct ftrace_regs *fregs,
> + unsigned long func);
> +#else
> +static inline void print_function_args(struct trace_seq *s, struct ftrace_regs *fregs,
> + unsigned long func) {
> + trace_seq_puts(s, "()");
> +}
> +#endif
> #endif
>
> --
> 2.43.0
>
--
Masami Hiramatsu (Google) <mhiramat@kernel.org>
next prev parent reply other threads:[~2024-09-08 15:17 UTC|newest]
Thread overview: 8+ messages / expand[flat|nested] mbox.gz Atom feed top
[not found] <20240904065908.1009086-1-svens@linux.ibm.com>
2024-09-04 6:58 ` [PATCH 4/7] Add print_function_args() Sven Schnelle
2024-09-08 15:17 ` Masami Hiramatsu [this message]
2024-09-09 3:13 ` Donglin Peng
2024-09-04 6:59 ` [PATCH 6/7] tracing: add support for function argument to graph tracer Sven Schnelle
2024-09-05 8:05 ` kernel test robot
2024-09-05 8:36 ` kernel test robot
2024-10-04 22:40 ` Steven Rostedt
2024-10-07 6:37 ` Sven Schnelle
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=20240909001718.ffbfc2ac8b7888a94735720f@kernel.org \
--to=mhiramat@kernel.org \
--cc=bpf@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-trace-kernel@vger.kernel.org \
--cc=mark.rutland@arm.com \
--cc=mathieu.desnoyers@efficios.com \
--cc=rostedt@goodmis.org \
--cc=svens@linux.ibm.com \
/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