1#!/bin/sh
2# SPDX-License-Identifier: GPL-2.0
3# description: Kprobe event auto/manual naming
4
5[ -f kprobe_events ] || exit_unsupported # this is configurable
6
7:;: "Add an event on function without name" ;:
8
9FUNC=`grep " [tT] .*vfs_read$" /proc/kallsyms | tail -n 1 | cut -f 3 -d " "`
10[ "x" != "x$FUNC" ] || exit_unresolved
11echo "p $FUNC" > kprobe_events
12PROBE_NAME=`echo $FUNC | tr ".:" "_"`
13test -d events/kprobes/p_${PROBE_NAME}_0 || exit_failure
14
15:;: "Add an event on function with new name" ;:
16
17echo "p:event1 $FUNC" > kprobe_events
18test -d events/kprobes/event1 || exit_failure
19
20:;: "Add an event on function with new name and group" ;:
21
22echo "p:kprobes2/event2 $FUNC" > kprobe_events
23test -d events/kprobes2/event2 || exit_failure
24
25:;: "Add an event on dot function without name" ;:
26
27find_dot_func() {
28	if [ ! -f available_filter_functions ]; then
29		grep -m 10 " [tT] .*\.isra\..*$" /proc/kallsyms | tail -n 1 | cut -f 3 -d " "
30		return;
31	fi
32
33	grep " [tT] .*\.isra\..*" /proc/kallsyms | cut -f 3 -d " " | while read f; do
34		if grep -s $f available_filter_functions; then
35			echo $f
36			break
37		fi
38	done
39}
40
41FUNC=`find_dot_func | tail -n 1`
42[ "x" != "x$FUNC" ] || exit_unresolved
43echo "p $FUNC" > kprobe_events
44EVENT=`grep $FUNC kprobe_events | cut -f 1 -d " " | cut -f 2 -d:`
45[ "x" != "x$EVENT" ] || exit_failure
46test -d events/$EVENT || exit_failure
47