rainconut 发表于 2009-08-05 22:44

求助,用kgdb调试模块问题

用kgdb调试内核没有问题,但调试模块始终不能成功,找不到源文件,也不能设断点,google了一段时间问题还不清楚

程序用简单的hello world

void myfunc(void)
{
      printk("<1>in myfunc\n");
}

static int __init hello_init(void)
{

      printk("<1>Hello, mod\n");
      myfunc();
      return 0;
}

static void __exit hello_exit(void)
{
      printk("<1>Hello, exit\n");
}

module_init(hello_init);
module_exit(hello_exit);

放在开发机的/home/work/hellomod目录下,然后整个目录copy到测试机下, 开发机上的内核2.6.23
测试机2.6.28, 所以copy后重新编译了hellomod.c
过程大致为:
1.测试机重启,加启动参数kgdbwait kgdboc=ttyS0, 9600
2.开发机设置stty ispeed 9600 ospeed 9600
   gdbmod vmlinux      
   target remote /dev/ttyS0
   continue 后又切换到开发机上来
   set solib-search-path /home/work/hellomod
   br myfunc    提示Make breakpoint pending on future shared library load? (y or ) y
3.测试机上
   insmodhellomod.ko
切不到开发机上来,设的断点没用

值得注意的2个地方:
target remote /dev/ttyS0后提示:
Remote debugging using /dev/ttyS0
0xc04686bc in kgdb_register_io_module ()
warning: shared library handler failed to enable breakpoint

另外是编译时的-g选项,不用我编译使用
obj-m := hellomod.o
default:
      $(MAKE) -C /lib/modules/$(shell uname -r)/build M=$(shell pwd)
应该包含了-g吧

求高人指点!

dreamice 发表于 2009-08-06 10:49

没怎么调试过,呵呵,哪位朋友调试过得,来指点一下。

rainconut 发表于 2009-08-06 14:28

自己顶一下

rainconut 发表于 2009-08-06 20:49

用add-symbol-file倒是可以设断点了,但设后在断点处停不下来

superfight 发表于 2009-08-06 21:10

= = 我是静态编辑进内核DEBUG

或者printk的~

rainconut 发表于 2009-08-06 21:22

回复 #5 superfight 的帖子

静态有个不好的地方是每次要make, make install 这2项在我机器上要花5min左右

emmoblin 发表于 2009-08-08 01:32

调试模块需要加载模块的符号表,并且还要做偏移计算。

rainconut 发表于 2009-08-09 09:46

回复 #7 emmoblin 的帖子

我用add-symbol-file .../hellomod.ko 添加符号,后面加的.text, .bss, .data地址是从
/sys/modules/下面看的,添加后可以设置断点,但运行时不能停在断点处。

至于地址计算,在其它帖看到说module_list + sizeof(module_list), 但是发现没有 module_list
这个符号,可能我用的版本较新,2.6.28

rainconut 发表于 2009-08-09 16:08

奇怪,很少人用kgdb调试?
页: [1]
查看完整版本: 求助,用kgdb调试模块问题