FreeBSD 用kgdb調試kernel dump文件

FreeBSD 用kgdb調試kernel dump文件

來自: http://blog.csdn.net/ztz0223/article/details/8600052ui

 

kgdb貌似和ddb同樣屬於FreeBSD專屬的調試器。


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

二、模擬觸發一個內核崩潰,作一個panic便可
root@BTazuo:/root # sysctl debug.kdb.panic=1

三、系統會把這個panic致使的dump文件存儲在 /var/crash/目錄下面,第一個命名爲vmcore.0

四、開始調試,先到 對應的內核版本的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*

五、開始調試
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));

六、查看調用棧:
(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致使的。this

相關文章
相關標籤/搜索