-
Notifications
You must be signed in to change notification settings - Fork 45
/
Copy pathbtfgen.sh
executable file
·86 lines (68 loc) · 1.97 KB
/
btfgen.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
#!/bin/bash
usage() { echo "Usage: $0 [-a <x86_64|arm64> -o <file01.bpf.o> -o <file02.bpf.o>]" 1>&2; exit 1; }
on=0
while getopts ":a:o:" opt; do
case "${opt}" in
a)
a=${OPTARG}
[[ "${a}" != "x86_64" && "${a}" != "arm64" ]] && usage
;;
o)
[[ ! -f ${OPTARG} ]] && { echo "error: could not find bpf object: ${OPTARG}"; usage; }
o+=("${OPTARG}")
;;
*)
usage
;;
esac
done
shift $((OPTIND-1))
if [ -z "${a}" ] || [ -z "${o}" ]; then
usage
fi
obj_cmdline=""
for ofile in "${o[@]}"; do
obj_cmdline+="${ofile} "
done
basedir=$(dirname ${0})/..
if [ "${basedir}" == "." ]; then
basedir=$(pwd)/..
fi
if [ ! -d ${basedir}/archive ]; then
echo "error: could not find archive directory"
exit 1
fi
cd ${basedir}
btfgen=$(which bpftool)
if [ -z "${btfgen}" ]; then
btfgen=/usr/sbin/bpftool
fi
if [ ! -x "${btfgen}" ]; then
echo "error: could not find bpftool (w/ btfgen patch) tool"
exit 1
fi
function ctrlc ()
{
echo "Exiting due to ctrl-c..."
rm ${basedir}/*.btf
exit 2
}
trap ctrlc SIGINT
trap ctrlc SIGTERM
# clean custom-archive directory
find ./custom-archive -mindepth 1 -maxdepth 1 -type d -exec rm -rf {} \;
for dir in $(find ./archive/ -iregex ".*${a}.*" -type d | sed 's:\.\/archive\/::g'| sort -u); do
# uncompress and process each existing input BTF .tar.xz file
for file in $(find ./archive/${dir} -name *.tar.xz); do
dir=$(dirname $file)
base=$(basename $file)
extracted=$(tar xvfJ $dir/$base); ret=$?
dir=${dir/\.\/archive\/}
out_dir="./custom-archive/${dir}"
[[ ! -d ${out_dir} ]] && mkdir -p ${out_dir}
echo "Processing ${extracted}..."
# generate one output BTF file to each input BTF file given
$btfgen gen min_core_btf ${extracted} ${out_dir}/${extracted} ${obj_cmdline}
[[ $ret -eq 0 ]] && [[ -f ./${extracted} ]] && rm ./${extracted}
done
done