Skip to content

Instantly share code, notes, and snippets.

@ivyl
Created November 29, 2012 19:08
Show Gist options
  • Save ivyl/4171173 to your computer and use it in GitHub Desktop.
Save ivyl/4171173 to your computer and use it in GitHub Desktop.
Kernel Debugging
#!/bin/bash
KERNEL_SRC=~/src/linux
MODULE=ahwfs
SSH_HOST=dm
TMP=/tmp/gdb-init
case "$1" in
socat)
COM_FIFO="$2"
if [ -z "$COM_FIFO" ]; then
echo "$0 socat FIFO"
exit 1
fi
sudo socat -d -d "$COM_FIFO" pty
;;
remote-init)
ssh "$SSH_HOST" "echo ttyS0,115200 | sudo tee /sys/module/kgdboc/parameters/kgdboc"
;;
freeze)
ssh "$SSH_HOST" "echo g | sudo tee /proc/sysrq-trigger"
;;
gdb-prepare)
SECTION=`ssh "$SSH_HOST" "cat /sys/module/$MODULE/sections/.text"`
MODULE_SYMBOLS="`pwd`/$2"
PTY="$3"
if [ -z "$PTY" ]; then
echo "$0 gdb-prepare MODULE_SYMBOLS PTY_ID"
exit 1
fi
cat << EOF > $TMP
add-symbol-file "$MODULE_SYMBOLS" "$SECTION"
set remotebaud 115200
target remote /dev/pts/$PTY
EOF
;;
gdb)
VMLINUX="`pwd`/$2"
if [ -z "$2" ]; then
echo "$0 gdb VMLINUX"
exit 1
fi
ssh "$SSH_HOST" "echo g | sudo tee /proc/sysrq-trigger" &
sleep 2
cd "$KERNEL_SRC"
sudo gdb -x "$TMP" "$VMLINUX"
;;
*)
echo "$0 [socat|remote-init|freeze|gdb|gdb-prepare]"
esac
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment