#!/bin/bash
#set -x
IP=${1:-"192.168.1.100"}
GDB_FILE=/usr/src/kernels/linux/.gdbinit
remote_module_path=/.../module/
local_module_path=/.../kernel
module_list=()
CUR_DIR=$PWD
WORK_DIR=$(dirname $0)
cd ${WORK_DIR}
remote_module_path=${remote_module_path%/}
local_module_path=${local_module_path%/}
echo "copy modules to gdb client ..."
for module in ${module_list[*]}
do
scp ${local_module_path}/${module}.ko root@${IP}:${remote_module_path}/ >/dev/null 2>&1
done
echo "copy modules to gdb client done"
echo "make .gdbinit file ..."
echo > .gdbinit
for module in ${module_list[*]}
do
if [ ! -d /sys/module/$module ]
then
echo "module $module hasn't intalled yet."
continue
fi
echo -n "add-symbol-file ${remote_module_path}/${module}.ko $(cat /sys/module/$module/sections/.text)" >> .gdbinit
if [ -e /sys/module/$module/sections/.bss ];
then
echo -n " -s .bss $(cat /sys/module/$module/sections/.bss)" >> .gdbinit
fi
if [ -e /sys/module/$module/sections/.data ];
then
echo -n " -s .data $(cat /sys/module/$module/sections/.data)" >> .gdbinit
fi
echo "" >> .gdbinit
done
echo "set remotebaud 115200" >> .gdbinit
echo "target remote /dev/ttyS0" >> .gdbinit
scp .gdbinit root@${IP}:${GDB_FILE} >/dev/null 2>&1
echo "make .gdbinit file done"
cd $CUR_DIR