How to debug kernel with QEMU-KVM
来源:互联网 发布:台湾士林夜市 知乎 编辑:程序博客网 时间:2024/05/16 17:45
Step 1: Configure Guest kernel
Make sure your "CONFIG_DEBUG_INFO" and"CONFIG_FRAME_POINTER" is select as "Y"
Example:
Kernel hacking --->
Compile-time checks and compiler options --->
[*] Compile the kernel with debug info
[*] Compile the kernel with frame pointers
Step 2: Compile andinstall the new kernel on guest
Example:
make -j 143 && make modules && makemodules_install install
Step3: copy guestvmlinx into HOST
The vmlinux should not be compressed.
Example:
scp $(kernel_src)/vmlinux $(user)@$(host_ip)/tmp
Step 4: restart VMguest with "-s" option
Example:
qemu-system-x86_64 -machine accel=kvm -smp 8 -drivefile=./test.raw,format=raw -m 2048 -s
Step 5: use gdb attachto the VM. I assume you use the Intel Chip(the best in the world)
Example
[root@lmcesrv host-mnt]# gdb
(gdb) set architecturei386:x86-64:intel
The target architecture is assumed to bei386:x86-64:intel
(gdb) target remote :1234
(gdb) file /tmp/vmlinux1
A program is being debugged already.
Are you sure you want to change the file? (y or n) y
Reading symbols from /tmp/vmlinux1...done.
(gdb) c
Step 6: Debug thekernel, feel good!
Example:
(gdb) b __schedule
Breakpoint 1 at 0xffffffff815ae7c6: filekernel/sched/core.c, line 3057.
(gdb) c
Continuing.
[New Thread 2]
[Switching to Thread 2]
Breakpoint 1, __schedule () at kernel/sched/core.c:3057
3057 kernel/sched/core.c: No such fileor directory.
(gdb) bt
#0 __schedule () at kernel/sched/core.c:3057
#1 0xffffffff815af0fe in schedule () atkernel/sched/core.c:3144
#2 0xffffffff815af2fe in schedule_preempt_disabled() at kernel/sched/core.c:3177
#3 0xffffffff81095d05 in cpu_idle_loop () atkernel/sched/idle.c:275
#4 0xffffffff81095de3 in cpu_startup_entry(state=<optimized out>) at kernel/sched/idle.c:297
#5 0xffffffff8103a603 in start_secondary(unused=<optimized out>) at arch/x86/kernel/smpboot.c:251
#6 0x0000000000000000 in ?? ()
(gdb) c
Continuing.
Breakpoint 1, __schedule () at kernel/sched/core.c:3057
3057 in kernel/sched/core.c
(gdb) bt
#0 __schedule () at kernel/sched/core.c:3057
#1 0xffffffff815af0fe in schedule () atkernel/sched/core.c:3144
#2 0xffffffff81071ee4 in worker_thread(__worker=<optimized out>) at kernel/workqueue.c:2183
#3 0xffffffff81076bec in kthread(_create=0xffff88007cab4ec0) at kernel/kthread.c:209
#4 0xffffffff815b29ef in ret_from_fork () atarch/x86/entry/entry_64.S:472
#5 0x0000000000000000 in ?? ()\
(gdb) detach
Detaching from program: /tmp/vmlinux1, Remote target
Ending remote debugging.
(gdb)q- How to debug kernel with QEMU-KVM
- debug kernel with qemu
- how to use adb and gdbserver with VirtualBox - KVM (qemu)
- How to debug QEMU
- Debug Linux Kernel with Qemu
- How to debug QEMU (by quqi99)
- from linux kernel to kvm -- debug linux kernel by eclipse
- qemu kernel debug
- How to debug shared librarys with gdb?
- How to debug unusual component with WinDbg
- HOW-TO:Debug Python Scripts with Eclipse
- How To Debug Web Applications With Firefox
- HOW-TO:Debug Python Scripts with Eclipse
- how to configure libvirt to use virtio with KVM guests
- Qemu+Gdb debug linux kernel
- qemu & arm debug uboot kernel
- How to assign devices with VT-d in KVM
- How to assign devices with VT-d in KVM
- IOS 点滴记录
- activiti-explorer部署中文流程报错:Error parsing XML
- 主题模型-LDA小结
- Android开发跟随手指的小球Demo
- maven能帮我们做什么
- How to debug kernel with QEMU-KVM
- zookeeper原理(转)
- poj 3667 Hotel 区间合并
- 直接把View Controller的view addSubview到另一个View,则不会调用viewDidAppear viewWillAppear
- Python:利用turtle库绘制iPhone4草图
- pictureviewer学习记录
- 1061. Dating
- 搭建git服务器之二:gitosis
- 本地通知(设置铃声图标和启动图片)