qemu 调试 kernel (二)

来源:互联网 发布:朝鲜 中国 关系 知乎 编辑:程序博客网 时间:2024/06/06 12:48

qemu搭建调试环境见前面,现在已经将裸kernel起来,马上进行debug:

 

1. 在qemu界面,用ctrl+alt+1  或 ctrl+alt+2, 切换到qemu输出与控制页面

2. 在qemu控制页面下,输入: gdbserver 1234;(这里我总是提示 could not open device on device '1234', 输入gdbserver tcp::1234就ok了!)

3. 回到shell,gdb vmlinux

提示:

This GDB was configured as "i686-linux-gnu".
For bug reporting instructions, please see:
<
http://www.gnu.org/software/gdb/bugs/>...
Reading symbols from /root/linux-code/linux-stable-3.8.3/vmlinux...done.
(gdb)

4. target remote 127.0.0.1:1234

显示:

Remote debugging using 127.0.0.1:1234
0x0000fff0 in ?? ()

5. 简单的一个测试:

(gdb) b start_kernel
Breakpoint 1 at 0xc164662b: file init/main.c, line 469.
(gdb) i b
Num     Type           Disp Enb Address    What
1       breakpoint     keep y   0xc164662b in start_kernel at init/main.c:469
(gdb) b idle_init
Breakpoint 2 at 0xc1658f0d: file kernel/smpboot.c, line 50.
(gdb) i b
Num     Type           Disp Enb Address    What
1       breakpoint     keep y   0xc164662b in start_kernel at init/main.c:469
2       breakpoint     keep y   0xc1658f0d in idle_threads_init
                                           at kernel/smpboot.c:50
(gdb) c
Continuing.

Breakpoint 1, start_kernel () at init/main.c:469
469 {
(gdb) c
Continuing.

Breakpoint 2, idle_threads_init () at kernel/smpboot.c:72
72    idle_init(cpu);
(gdb) bt
#0  idle_threads_init () at kernel/smpboot.c:72
#1  0xc1659e95 in smp_init () at kernel/smp.c:665
#2  0xc16469b5 in kernel_init_freeable () at init/main.c:874
#3  0xc1464a0b in kernel_init (unused=<optimized out>) at init/main.c:809
#4  0xc147d7f7 in ret_from_kernel_thread () at arch/x86/kernel/entry_32.S:311
#5  0xc1464a00 in ?? ()
Backtrace stopped: previous frame inner to this frame (corrupt stack?)
(gdb)

 

初始化的过程: start_kernel => 起thread: rest_init                                     

                                                               ---->  kernel_init =>  smp_init => idle_threads_init()为每个cpu创建idle thread; 

原创粉丝点击