# 遍历所有参数
for arg in "$@"
do
    # 分割参数名和值
    key="${arg%%=*}"
    value="${arg#*=}"

    # 检查参数名并根据需要处理参数值
    case "$key" in
        pid)
            pid="$value"
            ;;
        debug)
            debug="$value"
            ;;
        *)
            echo "Unknown parameter: $key"
            ;;
    esac
done

# 打印解析的参数值
echo "pid: $pid"
echo "debug: $debug"

#clang -isystem/usr/src/linux-headers-5.15.0-89-generic/arch/x86/include -isystem/usr/src/linux-headers-5.15.0-89-generic/arch/x86/include/generated -isystem/usr/src/linux-headers-5.15.0-89-generic/include -isystem/usr/src/linux-headers-5.15.0-89-generic/arch/x86/include/uapi -isystem/usr/src/linux-headers-5.15.0-89-generic/arch/x86/include/generated/uapi -isystem/usr/src/linux-headers-5.15.0-89-generic/include/uapi -isystem/usr/src/linux-headers-5.15.0-89-generic/include/generated/uapi -include linux/kconfig.h -I./ebpf/c/common -include asm_goto_workaround.h -D__KERNEL__ -D__BPF_TRACING__ "" -fno-stack-protector -g -Wno-unused-value -Wno-pointer-sign -Wno-compare-distinct-pointer-types -Wno-gnu-variable-sized-type-not-at-end -Wno-address-of-packed-member -Wno-tautological-compare -Wno-unknown-warning-option -O2 -target bpf -D__KERNEL_FROM=512 -D__TARGET_ARCH_x86 -c ./ebpf/ebpf.c -o ./ebpf512x86.o
#clang -isystem/usr/src/linux-headers-5.15.0-89-generic/arch/x86/include -isystem/usr/src/linux-headers-5.15.0-89-generic/arch/x86/include/generated -isystem/usr/src/linux-headers-5.15.0-89-generic/include -isystem/usr/src/linux-headers-5.15.0-89-generic/arch/x86/include/uapi -isystem/usr/src/linux-headers-5.15.0-89-generic/arch/x86/include/generated/uapi -isystem/usr/src/linux-headers-5.15.0-89-generic/include/uapi -isystem/usr/src/linux-headers-5.15.0-89-generic/include/generated/uapi -include linux/kconfig.h -g -O2 -target bpf -D__KERNEL_FROM=512 -D__TARGET_ARCH_x86 -c ./ebpf/ebpf.c -o ebpf512x86.o
#clang -g -O2 -target bpf -D__KERNEL_FROM=512 -D__TARGET_ARCH_x86 -D__x86_64__ $debug $TAG -c ./ebpf/ebpf.c -o ebpf512x86.o && llvm-strip --strip-debug ebpf512x86.o
#llvm-strip --strip-debug ./ebpf512x86.o
#chown 501:dialout ./ebpf512x86.o
/usr/bin/clang -I. -Ivmlinux -Iinclude -Iebpf/include -Iebpf/utrace/go/include -Iebpf/utrace/java/include -Iebpf/utrace/netcore/include -D__BPF_TRACING__ -D GROUP_LEADER_OFFSET_OVERRIDE=0 -DSTART_BOOTTIME_OFFSET_OVERRIDE=0 -DSTART_BOOTTIME_VARNAME=real_start_time  -std=gnu99 -Wimplicit-function-declaration \
	-ffreestanding -fno-builtin -Wall \
	-Wno-deprecated-declarations \
	-Wno-gnu-variable-sized-type-not-at-end \
	-Wno-pragma-once-outside-header \
	-Wno-address-of-packed-member \
	-Wno-unknown-warning-option \
	-fno-color-diagnostics \
	-fno-unwind-tables \
	-fno-stack-protector \
	-fno-asynchronous-unwind-tables -g -O2 -emit-llvm -D__KERNEL_FROM=416 -D__TARGET_ARCH_arm64 -D__aarch64__  -D__AARCH64EB__ $debug -o ebpf.ll -c ./ebpf/ebpf.c && /usr/bin/llc -march=bpf -filetype=obj -mcpu=v2 -o ebpf.elf ebpf.ll

/usr/bin/llvm-strip -g ebpf.elf  && mv ebpf.elf ebpf416arm64.o

echo -en '// generated - do not edit\npackage ebpftracer\n\nvar ebpfProg = map[string][]struct {\n' > ebpf.go \
	&& echo -en '\tv string\n' >> ebpf.go \
	&& echo -en '\tp []byte\n' >> ebpf.go \
	&& echo -en '}{\n' >> ebpf.go \
	&& echo -en '\t"amd64": {\n' >> ebpf.go \
	&& echo -en '\t\t{"v4.16", []byte("' >> ebpf.go && hexdump -v -e '"\\\x" 1/1 "%02x"' ebpf416arm64.o >> ebpf.go && echo '")},' >> ebpf.go \
	&& echo -en '\t},\n'>> ebpf.go \
	&& echo -en '\t"arm64": {\n' >> ebpf.go \
	&& echo -en '\t\t{"v4.16", []byte("' >> ebpf.go && hexdump -v -e '"\\\x" 1/1 "%02x"' ebpf416arm64.o >> ebpf.go && echo '")},' >> ebpf.go \
	&& echo -en '\t},\n'>> ebpf.go \
	&& echo -en '}\n'>> ebpf.go
if [ $? -ne 0 ]; then
  echo "error!"
  exit 1
fi
echo "success!"


#apk add bcc-dev
#apk add musl-dev