xref: /OK3568_Linux_fs/kernel/tools/testing/selftests/ftrace/test.d/kprobe/probepoint.tc (revision 4882a59341e53eb6f0b4789bf948001014eff981)
1*4882a593Smuzhiyun#!/bin/sh
2*4882a593Smuzhiyun# SPDX-License-Identifier: GPL-2.0
3*4882a593Smuzhiyun# description: Kprobe events - probe points
4*4882a593Smuzhiyun# requires: kprobe_events
5*4882a593Smuzhiyun
6*4882a593SmuzhiyunTARGET_FUNC=tracefs_create_dir
7*4882a593Smuzhiyun
8*4882a593Smuzhiyundec_addr() { # hexaddr
9*4882a593Smuzhiyun  printf "%d" "0x"`echo $1 | tail -c 8`
10*4882a593Smuzhiyun}
11*4882a593Smuzhiyun
12*4882a593Smuzhiyunset_offs() { # prev target next
13*4882a593Smuzhiyun  A1=`dec_addr $1`
14*4882a593Smuzhiyun  A2=`dec_addr $2`
15*4882a593Smuzhiyun  A3=`dec_addr $3`
16*4882a593Smuzhiyun  TARGET="0x$2" # an address
17*4882a593Smuzhiyun  PREV=`expr $A1 - $A2` # offset to previous symbol
18*4882a593Smuzhiyun  NEXT=+`expr $A3 - $A2` # offset to next symbol
19*4882a593Smuzhiyun  OVERFLOW=+`printf "0x%x" ${PREV}` # overflow offset to previous symbol
20*4882a593Smuzhiyun}
21*4882a593Smuzhiyun
22*4882a593Smuzhiyun# We have to decode symbol addresses to get correct offsets.
23*4882a593Smuzhiyun# If the offset is not an instruction boundary, it cause -EILSEQ.
24*4882a593Smuzhiyunset_offs `grep -A1 -B1 ${TARGET_FUNC} /proc/kallsyms | cut -f 1 -d " " | xargs`
25*4882a593Smuzhiyun
26*4882a593SmuzhiyunUINT_TEST=no
27*4882a593Smuzhiyun# printf "%x" -1 returns (unsigned long)-1.
28*4882a593Smuzhiyunif [ `printf "%x" -1 | wc -c` != 9 ]; then
29*4882a593Smuzhiyun  UINT_TEST=yes
30*4882a593Smuzhiyunfi
31*4882a593Smuzhiyun
32*4882a593Smuzhiyunecho "p:testprobe ${TARGET_FUNC}" > kprobe_events
33*4882a593Smuzhiyunecho "p:testprobe ${TARGET}" > kprobe_events
34*4882a593Smuzhiyunecho "p:testprobe ${TARGET_FUNC}${NEXT}" > kprobe_events
35*4882a593Smuzhiyun! echo "p:testprobe ${TARGET_FUNC}${PREV}" > kprobe_events
36*4882a593Smuzhiyunif [ "${UINT_TEST}" = yes ]; then
37*4882a593Smuzhiyun! echo "p:testprobe ${TARGET_FUNC}${OVERFLOW}" > kprobe_events
38*4882a593Smuzhiyunfi
39