FreeBSD 9.1用kgdb调试kernel dump文件

本文介绍如何使用kgdb调试FreeBSD 9.1的kerneldump文件。通过配置开启kdump功能,模拟内核崩溃并生成dump文件,最后利用kgdb进行调试分析。文中详细展示了调试步骤及调用栈信息。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

FreeBSD 9.1用kgdb调试kernel dump文件

kgdb貌似和ddb一样属于FreeBSD专属的调试器。


1、开启kdump功能
root@BTazuo:/root # cat /etc/rc.conf
# Set dumpdev to "AUTO" to enable crash dumps, "NO" to disable
dumpdev="AUTO"

2、模拟触发一个内核崩溃,做一个panic即可
root@BTazuo:/root # sysctl debug.kdb.panic=1

3、系统会把这个panic导致的dump文件存储在 /var/crash/目录下面,第一个命名为vmcore.0

4、开始调试,先到 对应的内核版本的kernel.debug文件的路径下去:

root@BTazuo:/usr/obj/usr/src/sys/GENERIC_20130219 # ll | grep kernel
-rwxr-xr-x  1 root  wheel  16031061 Feb 19 14:36 kernel*
-rwxr-xr-x  1 root  wheel  62180463 Feb 19 14:36 kernel.debug*
-rwxr-xr-x  1 root  wheel  48269559 Feb 19 14:36 kernel.symbols*

5、开始调试
root@BTazuo:/usr/obj/usr/src/sys/GENERIC_20130219 # kgdb kernel.debug /var/crash/vmcore.0
GNU gdb 6.1.1 [FreeBSD]
Copyright 2004 Free Software Foundation, Inc.
GDB is free software, covered by the GNU General Public License, and you are
welcome to change it and/or distribute copies of it under certain conditions.
Type "show copying" to see the conditions.
There is absolutely no warranty for GDB.  Type "show warranty" for details.
This GDB was configured as "i386-marcel-freebsd"...

Unread portion of the kernel message buffer:
panic: kdb_sysctl_panic
cpuid = 1
KDB: stack backtrace:
#0 0xc0af3aff at kdb_backtrace+0x4f
#1 0xc0ac052f at panic+0x16f
#2 0xc0af36c9 at kdb_sysctl_panic+0x59
#3 0xc0aca40a at sysctl_root+0x1fa
#4 0xc0aca6c3 at userland_sysctl+0x1d3
#5 0xc0acaa84 at sys___sysctl+0x94
#6 0xc0e2579a at syscall+0x34a
#7 0xc0e0f6d1 at Xint0x80_syscall+0x21
Uptime: 24m35s
Physical memory: 983 MB
Dumping 202 MB: 187 171 155 139 123 107 91 75 59 43 27 11

#0  doadump (textdump=1) at pcpu.h:244
244             __asm("movl %%fs:0,%0" : "=r" (td));

6、查看调用栈:
(kgdb) bt
#0  doadump (textdump=1) at pcpu.h:244
##1  0xc0ac027f in kern_reboot (howto=260) at /usr/src/sys/kern/kern_shutdown.c:448
##2  0xc0ac0572 in panic (fmt=Variable "fmt" is not available.
#) at /usr/src/sys/kern/kern_shutdown.c:636
##3  0xc0af36c9 in kdb_sysctl_panic (oidp=0xc111aa60, arg1=0x0, arg2=0, req=0xd91c9b74) at /usr/src/sys/kern/subr_kdb.c:185
##4  0xc0aca40a in sysctl_root (oidp=Variable "oidp" is not available.
#) at /usr/src/sys/kern/kern_sysctl.c:1513
##5  0xc0aca6c3 in userland_sysctl (td=0xc7d098a0, name=0xd91c9be0, namelen=3, old=0x0, oldlenp=0x0, inkernel=0, new=0xbfbfe4a0, newlen=4, retval=0xd91c9c40, flags=0)
#    at /usr/src/sys/kern/kern_sysctl.c:1623
#    #6  0xc0acaa84 in sys___sysctl (td=0xc7d098a0, uap=0xd91c9ccc) at /usr/src/sys/kern/kern_sysctl.c:1549
#    #7  0xc0e2579a in syscall (frame=0xd91c9d08) at subr_syscall.c:135
#    #8  0xc0e0f6d1 in Xint0x80_syscall () at /usr/src/sys/i386/i386/exception.s:267
#    #9  0x00000033 in ?? ()
#    Previous frame inner to this frame (corrupt stack?)


可见这个panic是因为用户输入了sysctl panic导致的。
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值