In addition to the
add-module macro, the followin example GDB
startup file contains a few other useful settings and macros, which
you may want to adjust to your local environment:
set output-radix 16
target remote bdi:2001
define reset
detach
target remote bdi:2001
end
define add-module
shell ~/add-symbol-file.sh $arg0
source ~/add-symbol-file.gdb
end
document add-module
Usage: add-module <module>
Do add-symbol-file for module <module> automatically.
Note: A map file with the extension ".map" must have
been created with "insmod -m <module> > <module>.map"
in advance.
end
The following shell script
~/add-symbol-file.sh is used to run the
GDB
add-symbol-file command automatically:
#!/bin/sh
#
# Constructs the GDB "add-symbol-file" command string
# from the map file of the specified kernel module.
add_sect() {
ADDR=`awk '/^'$1' / {print $3}' $MAPFILE`
if [ "$ADDR" != "" ]; then
echo "-s $1 0x`awk '/^'$1' / {print $3}' $MAPFILE`"
fi
}
[ $# == 1 ] && [ -r "$1" ] || { echo "Usage: $0 <module>" >&2 ; exit 1 ; }
MAPFILE=$1.map
ARGS="0x`awk '/^.text / {print $3}' $MAPFILE`\
`add_sect .rodata`\
`add_sect .data`\
`add_sect .sdata`\
`add_sect .bss`\
`add_sect .sbss`\
"
echo "add-symbol-file $1 $ARGS" > ~/add-symbol-file.gdb