在VMware环境下,使用KGDB调试内核及内核模块---基于kernel 2.6.26
http://blog.csdn.net/jie12310/archive/2009/09/18/4564853.aspx
 
关于GDB 的一篇文章
http://blog.csdn.net/dadalan/archive/2009/01/12/3758025.aspx
 
Linux 内核调试器内幕
http://www.itchinese.com/plus/view-159902-1.html
http://linux.chinaunix.net/bbs/thread-806375-1-1.html
 
KDB DownLoad
ftp://oss.sgi.com/projects/kdb/download/v4.4/ 

Linux 内核调试器内幕 (KDB)

1 KGDB概述

       KGDBKernel GNU Debugger)是一种源代码级Linux 内核调试器,它以桩函数的方式存在于内核的各个异常处理函数入口,接管内核所有的异常处理。它构建了一种对内核异常的管理机制,例如对断点异常的管理,对单步异常的管理等,通过对这些异常的管理来达到调试内核的目的。KGDB 与运行在主机端的调试器GDBGNU Debugger)配合使用,为调试Linux 内核提供了一种交叉调试机制。GDB KGDB 通过串口或网口进行信息交互,用户可以动态地查看和修改系统的各种变量,或者在内核中进行断点设置、单步执行、查看寄存器和堆栈等操作,与调试普通的应用程序非常相似。
 
 
编译内核开始的小问题Unable to find the Ncurses libraries
2009-09-21 11:10
编译linux的内核,进入该目录,命令make menuconfig
之后,出现下面的错误:
rm -f include/asm-arm/arch include/asm-arm/proc
(cd include/asm-arm; ln -sf arch-mx2ads arch; ln -sf proc-armv proc)
rm -f include/asm
( cd include ; ln -sf asm-arm asm)
make -C scripts/lxdialog all
make[1]: Entering directory `/home/lhs/HHARMMX21/linux-2.4.20/scripts/lxdialog'
/usr/bin/ld: cannot find -lncurses
collect2: ld returned 1 exit status
-e
>> Unable to find the Ncurses libraries.
>>
>> You must have Ncurses installed in order
>> to use 'make menuconfig'

make[1]: *** [ncurses] Error 1
make[1]: Leaving directory `/home/lhs/HHARMMX21/linux-2.4.20/scripts/lxdialog'
make: *** [menuconfig] Error 2

解决方法:

执行命令: sudo apt-get install ncurses-dev 即可!

(ncurses 用于make menuconfig界面显示)
 
原文地址:http://kerneltrap.org/node/112
Thanks the author!

Jeremy Jackson asked "which kernel debugger is 'best'?" on the Linux Kernel Mailing List . The responses from Andrew Morton and Keith Owens offer some interesting insight into the differences between the two main Linux kernel debuggers: kdb and kgdb . Long a sore point by many kernel developers, Linus Torvalds has refused to include a kernel debugger in the main kernel tree.
According to Keith Owens , the kdb maintainer, "kdb and kgdb are aimed at different debugging environments. kgdb requires a second machine containing the kernel compiled with -g, kdb lets you debug directly on the machine that failed, with or without compiling with -g. Almost all the differences flow from that design decision".
From the kdb home page , "This debugger is part of the linux kernel and provides a means of examining kernel memory and data structures while the system is operational. Additional commands may be easily added to format and display essential system data structures given an identifier or address of the data structure. Current command set allows complete control of kernel operations including single-stepping a processor, stopping upon execution of a specific instruction, stopping upon access (or modification) of a specific virtual memory location, stopping upon access to a register in the input-output address space, stack tracebacks for the current active task as well as for all other tasks (by process id), instruction disassembly, et. al."
From the kgdb home page (kgdb is maintained by Amit Kale) introduction , "kgdb is a source level debugger for linux kernel. It is used along with gdb to debug linux kernel. Kernel developers can debug a kernel similar to application programs with use of kgdb. It makes it possible to place breakpoints in kernel code, step through the code and observe variables."
 
KDB完全使用技巧

  1. 简介
    • Built-in Kernel Debugger for Linux
    • http://oss.sgi.com/projects/kdb/
    • Linux内核本身不带debug工具,KDB通过给标准内核打patch来实现调试,patch包括一个通用文件和一个与体系结构相关的文件,目前支持的体系结构是x86(包括i386和x86_64)和ia64
    • KDB的一个特色是更新特别快,比如当前最新的Linux版本是linux-2.6.31-rc2,KDB也立刻对此版本进行了patch更新
  2. 下载及安装
    • ftp://oss.sgi.com/projects/kdb/download/
    • 下载说明
      • kdb-v4.4-2.6.31-rc2-common-2.bz2
      • kdb-v4.4-2.6.31-rc2-ia64-2.bz2
      • kdb-v4.4-2.6.31-rc2-x86-2.bz2
      • KDB提供了以上三种patch文件,含义如下
        • v4.4是KDB的版本号
        • 2.6.31-rc2是Linux内核的版本号
        • common是通用patch,必须下载
        • ia64和x86根据自己的体系结构,选择一种下载
        • 最后的-2表示有多个同样的patch,选择数目最大的下载
    • 安装
      • 实验环境
        • Linux-2.6.25.tar.bz2
        • kdb-v4.4-2.6.25-common-1.bz2
        • kdb-v4.4-2.6.25-x86-2.bz2
      • 安装过程
        • tar -jxf Linux-2.6.25.tar.bz2
        • bunzip2 kdb-v4.4-2.6.25-common-1.bz2
        • bunzip2 kdb-v4.4-2.6.25-x86-2.bz2
        • cd Linux-2.6.25
        • patch -p1 < ../kdb-v4.4-2.6.25-common-1
        • patch -p1 < ../kdb-v4.4-2.6.25-x86-2
        • make menuconfig
          • enable CONFIG_FRAME_POINTER
        • make;make modules;make modules_install;make install
        • reboot
  3. 控制KDB
    • 通过grub
      • kdb=on    开启kdb
      • kdb=off    关闭kdb
      • kdb=early  刚进入系统时就暂停并进入kdb
      • kdb=on-nokey    任何键盘按键都不能触发kdb
    • 通过proc
      • echo '0' > /proc/sys/kernel/kdb            关闭kdb
      • echo '1' > /proc/sys/kernel/kdb            开启kdb
      • echo '2' > /proc/sys/kernel/kdb            任何键盘按键都不能触发kdb
    • 进入kdb环境的方式
      • 在linux运行过程中按下“Pause Break”键
      • 系统panic时自动进入
      • 在内核代码中调用KDB_ENTER()函数
  4. KDB命令解析
另一途径:
先安装Ubuntn 在安装带KDB版本的XEN