tracing/probes: support '%pD' type for print struct file's name
authorYe Bin <yebin10@huawei.com>
Fri, 22 Mar 2024 06:43:05 +0000 (14:43 +0800)
committerMasami Hiramatsu (Google) <mhiramat@kernel.org>
Wed, 1 May 2024 14:18:47 +0000 (23:18 +0900)
commit20fe4d07bde67ec26716835b61be2c4eeca1c6bc
tree240fd448fd6c2231ccd8a7ce48681d441440ea79
parentd9b15224dd8ff83b2aef87e4cd5ad10c875ef7d6
tracing/probes: support '%pD' type for print struct file's name

As like '%pd' type, this patch supports print type '%pD' for print file's
name. For example "name=$arg1:%pD" casts the `$arg1` as (struct file*),
dereferences the "file.f_path.dentry.d_name.name" field and stores it to
"name" argument as a kernel string.
Here is an example:
[tracing]# echo 'p:testprobe vfs_read name=$arg1:%pD' > kprobe_event
[tracing]# echo 1 > events/kprobes/testprobe/enable
[tracing]# grep -q "1" events/kprobes/testprobe/enable
[tracing]# echo 0 > events/kprobes/testprobe/enable
[tracing]# grep "vfs_read" trace | grep "enable"
            grep-15108   [003] .....  5228.328609: testprobe: (vfs_read+0x4/0xbb0) name="enable"

Note that this expects the given argument (e.g. $arg1) is an address of struct
file. User must ensure it.

Link: https://lore.kernel.org/all/20240322064308.284457-3-yebin10@huawei.com/
[Masami: replaced "previous patch" with '%pd' type]

Signed-off-by: Ye Bin <yebin10@huawei.com>
Acked-by: Masami Hiramatsu (Google) <mhiramat@kernel.org>
Signed-off-by: Masami Hiramatsu (Google) <mhiramat@kernel.org>
kernel/trace/trace.c
kernel/trace/trace_probe.c