momo zone

调核人的blog

搞定KDB

真是辛苦,这次搞定了KDB。 我是读完kernel的change log 后发现KDB 和 KGDB已经作为主线合并进了kernel >=2.6.35 差不多之前的编译配置方法都已经失效了,而且之前折腾的kernel <2.6.35基本都有BUG,不是键盘混乱就是死机。

1.4. KDB kernel debugger frontend

The Linux kernel has had a kernel debugger since 2.6.26, called Kgdb. But Kgdb is not the only linux kernel debugger, there is also KDB, developed years ago by SGI. The key difference between Kgdb and KDB is that using Kgdb requires an additional computer to run a gdb frontend, and you can do source level debugging. KDB, on the other hand, can be run on the local machine and can be used to inspect the system, but it doesn’t do source-level debugging. What is happening in this version is that Jason Wessel, from Windriver, has ported KDB to work on top of the Kgdb core, making possible to use both interfaces.

现在的状况是KDB和KGDB融合了,可以在KDB中进入KGDB(把KDB作为了KGDB的前端),或者在KGDB 中使用KDB的功能,不过总的来看是KDB融合进了KGDB而不是相反。这个进步可以看出内核调试器已经得到了承认。这里说一下KDB的编译条件:

  • CONFIG_DEBUG_RODATA is not set
  • CONFIG_DEBUG_SET_MODULE_RONX is not set
  • CONFIG_FRAME_POINTER=y
  • CONFIG_KGDB=y
  • CONFIG_KGDB_SERIAL_CONSOLE=y
  • CONFIG_KGDB_KDB=y
  • CONFIG_KDB_KEYBOARD=y

这里CONFIG_KGDB_SERIAL_CONSOLE最好编译进内核,原因后面说明。

KDB 的激活方式也完全改变了:

2.6.35以前是 echo 1 > /proc/sys/kernel/kdb 或 内核参数kdb=on

如果要在启动过程中较早进入kdb就需要把kgdboc模块编译进内核,然后加内核启动参数:kgdboc=kbd kgdbwait

2.6.35之后是echo kbd > /sys/module/kgdboc/parameters/kgdboc 没错名字叫kgdboc 就是编译的时候的配置CONFIG_KGDB_SERIAL_CONSOLE的产物,如果编译成了模块是不会自动加载的,需要modprob kgdboc才能看到这个文件。所以还是编译到内核罢了。

另外还可以echo ttyS0 > /sys/module/kgdboc/parameters/kgdboc 启动串口上的调试,这就是kgdb,kdb融合的产物。

然后进入KDB 方式也更改了:

2.6.35 之前是直接按pasue

2.6.35 之后是sysrq + g ,或者echo g > /proc/sysrq-trigger

进入KGDB方式:

gdb vmlinux-kgdb

(gdb) set remotebaud 115200
(gdb) target remote /dev/ttyS0

ok ,这样就可以了,试了半天一切正常,单步执行和继续执行都没有死机,我还开着X ,用着wifi ,比以前稳定得多。

但是KDB好像会使bash进入D进程状态,系统无法响应。继续等官方打补丁。

这里有几个重要的参照:

http://kernelnewbies.org/Linux_2_6_35

https://kgdb.wiki.kernel.org/index.php/Main_Page

https://kgdb.wiki.kernel.org/index.php/KDB_FAQ

http://kernel.org/pub/linux/kernel/people/jwessel/kdb/kgdbKernelArgs.html

Advertisements

发表评论

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / 更改 )

Twitter picture

You are commenting using your Twitter account. Log Out / 更改 )

Facebook photo

You are commenting using your Facebook account. Log Out / 更改 )

Google+ photo

You are commenting using your Google+ account. Log Out / 更改 )

Connecting to %s

%d 博主赞过: