Skip to content

Instantly share code, notes, and snippets.

@xiangchu0
Created February 7, 2023 15:09
Show Gist options
  • Save xiangchu0/028ddf4021ee60570a7728d636eb8e5e to your computer and use it in GitHub Desktop.
Save xiangchu0/028ddf4021ee60570a7728d636eb8e5e to your computer and use it in GitHub Desktop.
simple script to add symbol file information for kernel debug
#!/bin/sh
function getsym() {
KMOD=$1
KDIR=/lib/modules/$(uname -r)/kernel/
KSYS=/sys/module/${KMOD}
KPATH=$(find ${KDIR} -name ${KMOD}.ko -o -name ${KMOD/_/-}.ko)
KFILE=${KPATH/$KDIR/./}
echo -n "add-symbol-file $KFILE"
for SEC in .text .bss .data .rodata
do
if [ -f $KSYS/sections/$SEC ]; then
echo -en " \\\\\\n-s $SEC $(cat $KSYS/sections/$SEC)"
fi
done
echo -e "\n"
}
lsmod | awk "{print $1}" | while read kmod
do
getsym $kmod
done
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment