Skip to content

Commit e8c32f2

Browse files
committed
Documentation: tracing: Add entry argument access at function exit
Add a notes about the entry argument access at function exit probes for kprobes and fprobe trace event. Link: https://lore.kernel.org/all/170952367549.229804.8843506960483577062.stgit@devnote2/ Signed-off-by: Masami Hiramatsu (Google) <[email protected]>
1 parent f6e2253 commit e8c32f2

File tree

2 files changed

+40
-0
lines changed

2 files changed

+40
-0
lines changed

Documentation/trace/fprobetrace.rst

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,14 @@ Synopsis of fprobe-events
7070

7171
For the details of TYPE, see :ref:`kprobetrace documentation <kprobetrace_types>`.
7272

73+
Function arguments at exit
74+
--------------------------
75+
Function arguments can be accessed at exit probe using $arg<N> fetcharg. This
76+
is useful to record the function parameter and return value at once, and
77+
trace the difference of structure fields (for debuging a function whether it
78+
correctly updates the given data structure or not)
79+
See the :ref:`sample<fprobetrace_exit_args_sample>` below for how it works.
80+
7381
BTF arguments
7482
-------------
7583
BTF (BPF Type Format) argument allows user to trace function and tracepoint
@@ -218,3 +226,26 @@ traceprobe event, you can trace that field as below.
218226
<idle>-0 [000] d..3. 5606.690317: sched_switch: (__probestub_sched_switch+0x4/0x10) comm="kworker/0:1" usage=1 start_time=137000000
219227
kworker/0:1-14 [000] d..3. 5606.690339: sched_switch: (__probestub_sched_switch+0x4/0x10) comm="swapper/0" usage=2 start_time=0
220228
<idle>-0 [000] d..3. 5606.692368: sched_switch: (__probestub_sched_switch+0x4/0x10) comm="kworker/0:1" usage=1 start_time=137000000
229+
230+
.. _fprobetrace_exit_args_sample:
231+
232+
The return probe allows us to access the results of some functions, which returns
233+
the error code and its results are passed via function parameter, such as an
234+
structure-initialization function.
235+
236+
For example, vfs_open() will link the file structure to the inode and update
237+
mode. You can trace that changes with return probe.
238+
::
239+
240+
# echo 'f vfs_open mode=file->f_mode:x32 inode=file->f_inode:x64' >> dynamic_events
241+
# echo 'f vfs_open%%return mode=file->f_mode:x32 inode=file->f_inode:x64' >> dynamic_events
242+
# echo 1 > events/fprobes/enable
243+
# cat trace
244+
sh-131 [006] ...1. 1945.714346: vfs_open__entry: (vfs_open+0x4/0x40) mode=0x2 inode=0x0
245+
sh-131 [006] ...1. 1945.714358: vfs_open__exit: (do_open+0x274/0x3d0 <- vfs_open) mode=0x4d801e inode=0xffff888008470168
246+
cat-143 [007] ...1. 1945.717949: vfs_open__entry: (vfs_open+0x4/0x40) mode=0x1 inode=0x0
247+
cat-143 [007] ...1. 1945.717956: vfs_open__exit: (do_open+0x274/0x3d0 <- vfs_open) mode=0x4a801d inode=0xffff888005f78d28
248+
cat-143 [007] ...1. 1945.720616: vfs_open__entry: (vfs_open+0x4/0x40) mode=0x1 inode=0x0
249+
cat-143 [007] ...1. 1945.728263: vfs_open__exit: (do_open+0x274/0x3d0 <- vfs_open) mode=0xa800d inode=0xffff888004ada8d8
250+
251+
You can see the `file::f_mode` and `file::f_inode` are upated in `vfs_open()`.

Documentation/trace/kprobetrace.rst

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,15 @@ Synopsis of kprobe_events
7070
(\*3) this is useful for fetching a field of data structures.
7171
(\*4) "u" means user-space dereference. See :ref:`user_mem_access`.
7272

73+
Function arguments at kretprobe
74+
-------------------------------
75+
Function arguments can be accessed at kretprobe using $arg<N> fetcharg. This
76+
is useful to record the function parameter and return value at once, and
77+
trace the difference of structure fields (for debuging a function whether it
78+
correctly updates the given data structure or not).
79+
See the :ref:`sample<fprobetrace_exit_args_sample>` in fprobe event for how
80+
it works.
81+
7382
.. _kprobetrace_types:
7483

7584
Types

0 commit comments

Comments
 (0)