18c2ecf20Sopenharmony_ci#!/bin/sh
28c2ecf20Sopenharmony_ci# SPDX-License-Identifier: GPL-2.0
38c2ecf20Sopenharmony_ci# description: Kprobe events - probe points
48c2ecf20Sopenharmony_ci# requires: kprobe_events
58c2ecf20Sopenharmony_ci
68c2ecf20Sopenharmony_ciTARGET_FUNC=tracefs_create_dir
78c2ecf20Sopenharmony_ci
88c2ecf20Sopenharmony_cidec_addr() { # hexaddr
98c2ecf20Sopenharmony_ci  printf "%d" "0x"`echo $1 | tail -c 8`
108c2ecf20Sopenharmony_ci}
118c2ecf20Sopenharmony_ci
128c2ecf20Sopenharmony_ciset_offs() { # prev target next
138c2ecf20Sopenharmony_ci  A1=`dec_addr $1`
148c2ecf20Sopenharmony_ci  A2=`dec_addr $2`
158c2ecf20Sopenharmony_ci  A3=`dec_addr $3`
168c2ecf20Sopenharmony_ci  TARGET="0x$2" # an address
178c2ecf20Sopenharmony_ci  PREV=`expr $A1 - $A2` # offset to previous symbol
188c2ecf20Sopenharmony_ci  NEXT=+`expr $A3 - $A2` # offset to next symbol
198c2ecf20Sopenharmony_ci  OVERFLOW=+`printf "0x%x" ${PREV}` # overflow offset to previous symbol
208c2ecf20Sopenharmony_ci}
218c2ecf20Sopenharmony_ci
228c2ecf20Sopenharmony_ci# We have to decode symbol addresses to get correct offsets.
238c2ecf20Sopenharmony_ci# If the offset is not an instruction boundary, it cause -EILSEQ.
248c2ecf20Sopenharmony_ciset_offs `grep -A1 -B1 ${TARGET_FUNC} /proc/kallsyms | cut -f 1 -d " " | xargs`
258c2ecf20Sopenharmony_ci
268c2ecf20Sopenharmony_ciUINT_TEST=no
278c2ecf20Sopenharmony_ci# printf "%x" -1 returns (unsigned long)-1.
288c2ecf20Sopenharmony_ciif [ `printf "%x" -1 | wc -c` != 9 ]; then
298c2ecf20Sopenharmony_ci  UINT_TEST=yes
308c2ecf20Sopenharmony_cifi
318c2ecf20Sopenharmony_ci
328c2ecf20Sopenharmony_ciecho "p:testprobe ${TARGET_FUNC}" > kprobe_events
338c2ecf20Sopenharmony_ciecho "p:testprobe ${TARGET}" > kprobe_events
348c2ecf20Sopenharmony_ciecho "p:testprobe ${TARGET_FUNC}${NEXT}" > kprobe_events
358c2ecf20Sopenharmony_ci! echo "p:testprobe ${TARGET_FUNC}${PREV}" > kprobe_events
368c2ecf20Sopenharmony_ciif [ "${UINT_TEST}" = yes ]; then
378c2ecf20Sopenharmony_ci! echo "p:testprobe ${TARGET_FUNC}${OVERFLOW}" > kprobe_events
388c2ecf20Sopenharmony_cifi
39