分类: LINUX
2009-08-15 15:18:48
qemu ${QEMU_ARGS} \
-kernel "$VMLINUZ" \
-append "${KERNEL_CMDLINE} kgdboc=ttyS0,115200 kgdbwait" \
-serial tcp::${KGDB_TCPPORT},server \
-hda "${QEMU_HDA}" >/dev/null &
Remote debugging using tcp:localhost:4555
kgdb_register_io_module (new_kgdb_io_ops=)
at /data/home/hellwolf/mydoc/prog/linux/linux-2.6/kernel/kgdb.c:1674
(gdb)
echo -e "\003" > /dev/ttyS1
Program received signal SIGTRAP, Trace/breakpoint trap.
[Switching to Thread -1]
sysrq_handle_gdb (key=103, tty=0xc7869800)
at /data/home/hellwolf/mydoc/prog/linux/linux-2.6/kernel/kgdb.c:1674
(gdb)
# echo g > /proc/sysrq-trigger
(gdb) c
(gdb) b sys_open
Breakpoint 1 at 0xc046d268: file /data/home/hellwolf/mydoc/prog/linux/linux-2.6/
fs/open.c, line 1107.
(gdb) c
Continuing.
[New Thread 612]
[Switching to Thread 612]
Breakpoint 1, sys_open (filename=0xb7f68a9c "/etc/ld.so.cache", flags=0,
mode=0) at /data/home/hellwolf/mydoc/prog/linux/linux-2.6/fs/open.c:1107
(gdb) p filename
$1 = 0xb7f68a9c "/etc/ld.so.cache"
(gdb)n
(gdb)bt
#0 sys_open (filename=0xb7f68a9c "/etc/ld.so.cache", flags=0, mode=0)
at /data/home/hellwolf/mydoc/prog/linux/linux-2.6/fs/open.c:1113
#1 0xc0403976 in system_call ()
at /data/home/hellwolf/mydoc/prog/linux/linux-2.6/arch/x86/kernel/entry_32.S
:377
#2 0x00000000 in ?? ()
set $_lsmod_modules = modules->next
# 1 10 15
printf "Module Size\n"
while $_lsmod_modules != &modules
set $_lsmod_module = (struct module*)((unsigned char*)$_lsmod_modules-(unsigned int)&(((struct module*)0)->list))
printf "%-15s %d\n", $_lsmod_module->name, $_lsmod_module->init_size + $_lsmod_module->core_size
set $_lsmod_modules = $_lsmod_modules->next
end
define xsrun
if $argc == 0
printf "Usage : xsrun xsourcecmd args...\n"
else
shell rm -f /tmp/*.xsource
shell echo 0 > /tmp/seq.xsource
if $argc == 1
xsource '$arg0'
end
if $argc == 2
xsource '$arg0' '$arg1'
end
if $argc == 3
xsource '$arg0' '$arg1' '$arg2'
end
if $argc == 4
xsource '$arg0' '$arg1' '$arg2' '$arg3'
end
if $argc == 5
xsource '$arg0' '$arg1' '$arg2' '$arg3' '$arg4'
end
if $argc == 6
xsource '$arg0' '$arg1' '$arg2' '$arg3' '$arg4' '$arg5'
end
if $argc == 7
xsource '$arg0' '$arg1' '$arg2' '$arg3' '$arg4' '$arg5' '$arg6'
end
if $argc == 8
xsource '$arg0' '$arg1' '$arg2' '$arg3' '$arg4' '$arg5' '$arg6' '$arg7'
end
if $argc == 9
xsource '$arg0' '$arg1' '$arg2' '$arg3' '$arg4' '$arg5' '$arg6' '$arg7' '$arg8'
end
if $argc == 10
xsource '$arg0' '$arg1' '$arg2' '$arg3' '$arg4' '$arg5' '$arg6' '$arg7' '$arg8' '$arg9'
end
end
end
define xsource
if $argc == 1
shell $TOOLSDIR/kgdb-xsource '$arg0'
end
if $argc == 2
shell $TOOLSDIR/kgdb-xsource '$arg0' '$arg1'
end
if $argc == 3
shell $TOOLSDIR/kgdb-xsource '$arg0' '$arg1' '$arg2'
end
if $argc == 4
shell $TOOLSDIR/kgdb-xsource '$arg0' '$arg1' '$arg2' '$arg3'
end
if $argc == 5
shell $TOOLSDIR/kgdb-xsource '$arg0' '$arg1' '$arg2' '$arg3' '$arg4'
end
if $argc == 6
shell $TOOLSDIR/kgdb-xsource '$arg0' '$arg1' '$arg2' '$arg3' '$arg4' '$arg5'
end
if $argc == 7
shell $TOOLSDIR/kgdb-xsource '$arg0' '$arg1' '$arg2' '$arg3' '$arg4' '$arg5' '$arg6'
end
if $argc == 8
shell $TOOLSDIR/kgdb-xsource '$arg0' '$arg1' '$arg2' '$arg3' '$arg4' '$arg5' '$arg6' '$arg7'
end
if $argc == 9
shell $TOOLSDIR/kgdb-xsource '$arg0' '$arg1' '$arg2' '$arg3' '$arg4' '$arg5' '$arg6' '$arg7' '$arg8'
end
if $argc == 10
shell $TOOLSDIR/kgdb-xsource '$arg0' '$arg1' '$arg2' '$arg3' '$arg4' '$arg5' '$arg6' '$arg7' '$arg8' '$arg9'
end
if $argc > 0
source /tmp/current.xsource
end
end
$ cat tools/kgdb-xsource
#!/bin/bash
. $(dirname "$0")/common.sh
if [ "$#" == 0 ];then
echo "kgdb-xsource xsourcecmd args...\\n\"" > /tmp/current.xsource
else
XSOURCECMD=$1
shift
XSOURCESEQ=$(cat /tmp/seq.xsource)
XSOURCESEQ=$((${XSOURCESEQ}+1))
echo ${XSOURCESEQ} > /tmp/seq.xsource
XSOURCEOFILE=/tmp/${XSOURCESEQ}-${XSOURCECMD}.xsource
if [ -f "$XSOURCEDIR/$XSOURCECMD" ] && [ -x "$XSOURCEDIR/$XSOURCECMD" ];then
$XSOURCEDIR/$XSOURCECMD "$@" > ${XSOURCEOFILE}
rm -f /tmp/current.xsource
ln -s ${XSOURCEOFILE} /tmp/current.xsource
else
echo "printf \"No such xsource command : $XSOURCECMD\\n\"" > /tmp/current.xsource
fi
fi
$ cat tools/xsource.d/strcmp_vs
#!/usr/bin/perl
if (@ARGV != 3) {
print "printf \"Usage : strcmp result var str\\n\"";
exit 1
}
($result, $var, $str) = @ARGV;
print 'if ';
$i = 0;
for (0..length($str)-1) {
$i = $_;
$c = substr($str, $i, 1);
print ' && ' if $i;
print "${var}[$i] == '$c'";
}
++$i;
print " && ${var}[$i] == '\\0'
set \$$result = 0
else
set \$$result = -1
end
";
$ cat tools/xsource.d/getmod
#!/bin/sh
[ $# != 2 ] && echo "printf \"Usage : getmod modvar modname\n\"" && exit 1
MODVAR=$1
MODNAME=$2
cat <set \$_getmod_modules = modules->next
set \$_getmod_modfound = 0
while \$_getmod_modules != &modules
set \$_getmod_module = (struct module*)((unsigned char*)\$_getmod_modules-(unsigned int)&(((struct module*)0)->list))
xsource strcmp_vs _getmod_modfound \$_getmod_module->name $MODNAME
if \$_getmod_modfound == 0
set \$$MODVAR = \$_getmod_module
set \$_getmod_modfound = 1
loop_break
end
set \$_getmod_modules = \$_getmod_modules->next
end
if \$_getmod_modfound != 1
printf "Module \\"$MODNAME\\" cannot be found\\n"
set \$$MODVAR = 0
end
EOF
(gdb) xsource getmod modvar hello
(gdb) print $modvar->sect_attrs->attrs[0]->name
$9 = 0xc7855b40 ".note.gnu.build-id"
add-symbol-file $MODFILE \\
$TEXT_ADDR \\
-s .data $DATA_ADDR \\
-s .bss $BSS_ADDR
$ cat /sys/module/snd/sections/.text
0xf8f83000
$ cat /sys/module/snd/sections/.data
0xf8f8d040
$ cat /sys/module/snd/sections/.bss
0xf8f8e280
$ cat tools/xsource.d/addmod2gdb
#!/bin/sh
# addmod2gdb($modname)
[ $# != 1 ] && echo "printf \"Usage : addmod2gdb modname\n\"" && exit 1
MODNAME=$1
MODFILE=$KMODSDIR/$MODNAME/${MODNAME}.ko
if [ -f $MODFILE ];then
cat <xsource getmod _addmod2gdb_mod $MODNAME
if \$_addmod2gdb_mod != 0
set \$_addmod2gdb_i = 0
set \$_addmod2gdb_c = 0
while \$_addmod2gdb_i < \$_addmod2gdb_mod->sect_attrs->nsections
if \$_addmod2gdb_c == 3
loop_break
end
xsource strcmp_vs _addmod2gdb_r \$_addmod2gdb_mod->sect_attrs->attrs[\$_addmod2gdb_i].name .text
if \$_addmod2gdb_r == 0
set \$_addmod2gdb_text = \$_addmod2gdb_mod->sect_attrs->attrs[\$_addmod2gdb_i].address
set \$_addmod2gdb_c = \$_addmod2gdb_c + 1
set \$_addmod2gdb_i = \$_addmod2gdb_i + 1
loop_continue
end
xsource strcmp_vs _addmod2gdb_r \$_addmod2gdb_mod->sect_attrs->attrs[\$_addmod2gdb_i].name .data
if \$_addmod2gdb_r == 0
set \$_addmod2gdb_data = \$_addmod2gdb_mod->sect_attrs->attrs[\$_addmod2gdb_i].address
set \$_addmod2gdb_c = \$_addmod2gdb_c + 1
set \$_addmod2gdb_i = \$_addmod2gdb_i + 1
loop_continue
end
xsource strcmp_vs _addmod2gdb_r \$_addmod2gdb_mod->sect_attrs->attrs[\$_addmod2gdb_i].name .bss
if \$_addmod2gdb_r == 0
set \$_addmod2gdb_bss = \$_addmod2gdb_mod->sect_attrs->attrs[\$_addmod2gdb_i].address
set \$_addmod2gdb_c = \$_addmod2gdb_c + 1
set \$_addmod2gdb_i = \$_addmod2gdb_i + 1
loop_continue
end
set \$_addmod2gdb_i = \$_addmod2gdb_i + 1
end
add-symbol-file $MODFILE \\
\$_addmod2gdb_text \\
-s .data \$_addmod2gdb_data \\
-s .bss \$_addmod2gdb_bss
end
EOF
else
echo "printf \"No such module file : $MODFILE\n\""
fi