免费注册 查看新帖 |

Chinaunix

  平台 论坛 博客 文库
最近访问板块 发新帖
楼主: ktrudger
打印 上一主题 下一主题

[FreeBSD] 如何调试FreeBSD内核和内核模块? [复制链接]

论坛徽章:
0
11 [报告]
发表于 2006-06-19 17:42 |只看该作者
还是不行,晕
[root@shyfzx ~/soft/qemu-0.8.1]# make
"Makefile", line 4: Need an operator
"Makefile", line 6: Need an operator
"Makefile", line 11: Need an operator
"Makefile", line 13: Need an operator
"Makefile", line 14: Need an operator
"Makefile", line 16: Need an operator
"Makefile", line 18: Need an operator
"Makefile", line 53: Need an operator
"Makefile", line 56: Need an operator
Error expanding embedded variable

论坛徽章:
0
12 [报告]
发表于 2006-06-19 17:47 |只看该作者
原帖由 ktrudger 于 2006-6-19 17:25 发表
最后一句就是这个:
[root@shyfzx ~/hook]# make COPTS=-g
Warning: Object directory not changed from original /root/hook
@ -> /usr/src/sys
machine -> /usr/src/sys/i386/include
cc -O2 -fno-s ...


调试符号都给strip掉了,哪儿还有啊?

在你的Makefile里面加上这样一句:
DEBUG_FLAGS = -g

原来的编译信息为:
  1. ld -Bshareable  -d -warn-common -o xxxx.ko xxxx.kld
  2. objcopy --strip-debug xxxx.ko
复制代码


现在的编译信息为:
  1. ld -Bshareable  -d -warn-common -o xxxx.ko.debug xxxx.kld
  2. objcopy --strip-debug xxxx.ko.debug xxxx.ko
复制代码


说明xxxx.ko是去掉调试符号之后的版本,但它在之前会生成一个名叫xxxx.ko.debug的带有调试符号的版本。

论坛徽章:
0
13 [报告]
发表于 2006-06-19 17:52 |只看该作者
原帖由 ktrudger 于 2006-6-19 17:35 发表
我下载了一个0.81的qemu源码,configure的时候会错。报告少SDL。我已经对这些复杂的依赖关系深恶痛绝,所以也就懒得理它了。
ports目录下好像没有qemu的,呵呵。
ERROR: QEMU requires SDL or Cocoa ...

ports下面有,emulator目录下.
自己编译的话,你的系统中可能有SDL了,你需要自己改configure,把sdl_config改为你的系统中用的SDL config.

论坛徽章:
0
14 [报告]
发表于 2006-06-19 18:04 |只看该作者
哦 这个搞定了。接下来怎么调试呢?
我b func再func处设断点。
但是运行run,似乎是不行啊。

我再运行kgdb前已经将hook.ko装入系统了。
现在怎么再kgdb中调试该模块呢?让该模块运行到断点停止下来?

或者说我再kgdb中如何运行这个模块呢?

我自己摸索看看。

[ 本帖最后由 ktrudger 于 2006-6-19 18:21 编辑 ]

论坛徽章:
0
15 [报告]
发表于 2006-08-23 11:40 |只看该作者
-bash-2.05b# kldload /root/kernel/main.ko
-bash-2.05b# kldstat
Id Refs Address    Size     Name
1    5 0xc0100000 3dfd8c   kernel
2    1 0xc1fd4000 7000     ipfw.ko
4    1 0xc7f43000 7000     bridge.ko
7    1 0xc2075000 15000    linux.ko
8    1 0xc2091000 7000     main.ko
-bash-2.05b# objdump --section-headers /root/kernel/main.ko | grep text
  3 .rel.text     00001058  00001568  00001568  00001568  2**2
  8 .text         00002780  000027b0  000027b0  000027b0  2**2
-bash-2.05b# gdb -k /root/kernel/main.ko
GNU gdb 4.18 (FreeBSD)
Copyright 1998 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-unknown-freebsd"...Deprecated bfd_read called at /usr/src/gnu/usr.bin/binutils/gdb/../../../../contrib/gdb/gdb/dbxread.c line 2627 in elfstab_build_psymtabs
Deprecated bfd_read called at /usr/src/gnu/usr.bin/binutils/gdb/../../../../contrib/gdb/gdb/dbxread.c line 933 in fill_symbuf

(kgdb) add-symbol-file /root/kernel/main.ko 0xc20937b0
add symbol table from file "/root/kernel/main.ko" at text_addr = 0xc20937b0?
(y or n) y
Reading symbols from /root/kernel/main.ko...done.
(kgdb) l sys_exit
157
158
159     /* exit sytem */
160     static void sys_exit(void)
161     {
163        destroy_dev(ntd_dev);
165        unregister_hook();
(kgdb) b sys_exit
Cannot access memory at address 0xc20938b0.
(kgdb)

论坛徽章:
0
16 [报告]
发表于 2006-08-23 11:41 |只看该作者
怎么回事?

论坛徽章:
0
17 [报告]
发表于 2006-08-23 11:47 |只看该作者
把你的kernel放到qemu中跑,在启动qemu的时候加上-s选项,启用远程调试。
然后,gdb kernel
在gdb中target remote localhost:1234
就连接到qemu了

论坛徽章:
0
18 [报告]
发表于 2006-08-23 13:20 |只看该作者
qemu支持FreeBSD 4.11吗?
另外kgdb不支持FreeBSD4.11?

论坛徽章:
0
19 [报告]
发表于 2006-08-23 14:28 |只看该作者
超级郁闷啊,FreeBSD 4.11的/usr/ports/emulators下面没有qemu!
FreeBSD也不支持kgdb,那内核怎个调法?

论坛徽章:
0
20 [报告]
发表于 2006-08-23 15:17 |只看该作者
-bash-2.05b# ./configure  --disable-gfx-check
sdl-config: not found
sdl-config: not found
Install prefix    /usr/local
BIOS directory    /usr/local/share/qemu
binary directory  /usr/local/bin
Manual directory  /usr/local/share/man
ELF interp prefix /usr/gnemul/qemu-%M
Source path       /root/qemu-0.8.2
C compiler        gcc
Host C compiler   gcc
make              gmake
install           install
host CPU          i386
host big endian   no
target list       i386-softmmu ppc-softmmu sparc-softmmu x86_64-softmmu mips-softmmu mipsel-softmmu arm-softmmu
gprof enabled     no
profiler          no
static build      no
SDL support       no
mingw32 support   no
Adlib support     no
CoreAudio support no
ALSA support      no
DSound support    no
FMOD support      no
kqemu support     yes
Documentation     no
-bash-2.05b# make
"Makefile", line 9: Need an operator
"Makefile", line 11: Need an operator
"Makefile", line 12: Missing dependency operator
"Makefile", line 14: Need an operator
"Makefile", line 19: Need an operator
"Makefile", line 21: Need an operator
"Makefile", line 22: Need an operator
"Makefile", line 24: Need an operator
"Makefile", line 26: Need an operator
"Makefile", line 64: Need an operator
"Makefile", line 67: Need an operator
Error expanding embedded variable.
-bash-2.05b# pwd
/root/qemu-0.8.2
-bash-2.05b#
改用gmake来编译,则会出很多编译错误!

[ 本帖最后由 ktrudger 于 2006-8-23 15:30 编辑 ]
您需要登录后才可以回帖 登录 | 注册

本版积分规则 发表回复

  

北京盛拓优讯信息技术有限公司. 版权所有 京ICP备16024965号-6 北京市公安局海淀分局网监中心备案编号:11010802020122 niuxiaotong@pcpop.com 17352615567
未成年举报专区
中国互联网协会会员  联系我们:huangweiwei@itpub.net
感谢所有关心和支持过ChinaUnix的朋友们 转载本站内容请注明原作者名及出处

清除 Cookies - ChinaUnix - Archiver - WAP - TOP