如何调试QEMU
2015-10-16 10:08
393 查看
我总结了一个非常简单的办法,希望对大家有帮助。由于是给老外回的,所以写成了英文
STEP 1: add a gloab control variable before main in vl.c. we will stop on main() if the control variable is zero
int g_stop_here = 1;
int main(int argc, char **argv, char **envp){
......
while(g_stop_here){
;//loop, wait debug;
}
......
}
STEP 2: compile and run qemu
qemu-system-x86_64 -machine accel=kvm -smp 8 -drive file=./test.raw,format=raw -drive file=./disk.qcow2 -cdrom ./RHEL6.3-20120613.2-Server-x86_64-DVD1.iso -m 2048 -serial stdio -vnc 10.238.153.111:0 -monitor telnet:10.238.153.111:6666,server,nowait
STEP 3: gdb attach the qemu process
[root@localhost host]# ps -ef | grep qemu
root 18816 17406 99 22:06 pts/1 00:00:05 qemu-system-x86_64
roooot@localhost host]# gdb -p 18816
STEP 4: set the breakpoint
(gdb) bt
#0 0x000055580c4d3fbd in main (argc=19, argv=0x7ffcae0149a8, envp=0x7ffcae014a48) at vl.c:2944
(gdb) b kvm_put_msr_feature_control
Breakpoint 1 at 0x55580c4b1a89: file /home/mce/workspace/git/qemu/qemu/target-i386/kvm.c, line 1311.
(gdb) b x86_cpu_reset
Breakpoint 2 at 0x55580c47f49f: file /home/mce/workspace/git/qemu/qemu/target-i386/cpu.c, line 2608.
STEP 5: set the gloab control variable to zero and contiue run qemu process
(gdb) set var g_stop_here=0
(gdb) c
STEP 6: QEMU will stop at the breakpoint, and we can debug the process. Also we need see the logic of qemu, some printf could be very helpful.
Breakpoint 2, x86_cpu_reset (s=0x55580e906f30) at /home/mce/workspace/git/qemu/qemu/target-i386/cpu.c:2608
2608 X86CPU *cpu = X86_CPU(s);
(gdb) bt
#0 x86_cpu_reset (s=0x55580e906f30) at /home/mce/workspace/git/qemu/qemu/target-i386/cpu.c:2608
#1 0x000055580c68a571 in cpu_reset (cpu=0x55580e906f30) at qom/cpu.c:231
#2 0x000055580c4800c7 in x86_cpu_realizefn (dev=0x55580e906f30, errp=0x7ffcae014210) at /home/mce/workspace/git/qemu/qemu/target-i386/cpu.c:2914
#3 0x000055580c55c9bd in device_set_realized (obj=0x55580e906f30, value=true, errp=0x7ffcae0143c8) at hw/core/qdev.c:1055
#4 0x000055580c6cd84d in property_set_bool (obj=0x55580e906f30, v=0x55580e921bf0, opaque=0x55580e8f7720, name=0x55580c7ba530 "realized", errp=0x7ffcae0143c8) at qom/object.c:1708
#5 0x000055580c6cbe84 in object_property_set (obj=0x55580e906f30, v=0x55580e921bf0, name=0x55580c7ba530 "realized", errp=0x7ffcae0143c8) at qom/object.c:965
#6 0x000055580c6ce71b in object_property_set_qobject (obj=0x55580e906f30, value=0x55580e8f6bc0, name=0x55580c7ba530 "realized", errp=0x7ffcae0143c8) at qom/qom-qobject.c:24
#7 0x000055580c6cc11a in object_property_set_bool (obj=0x55580e906f30, value=true, name=0x55580c7ba530 "realized", errp=0x7ffcae0143c8) at qom/object.c:1034
#8 0x000055580c431fff in pc_new_cpu (cpu_model=0x55580c7ba5e5 "qemu64", apic_id=0, errp=0x7ffcae014420) at /home/mce/workspace/git/qemu/qemu/hw/i386/pc.c:1069
#9 0x000055580c4322bc in pc_cpus_init (cpu_model=0x55580c7ba5e5 "qemu64") at /home/mce/workspace/git/qemu/qemu/hw/i386/pc.c:1145
#10 0x000055580c434d2d in pc_init1 (machine=0x55580e8a5bc0, host_type=0x55580c7bb237 "i440FX-pcihost", pci_type=0x55580c7bb230 "i440FX")
at /home/mce/workspace/git/qemu/qemu/hw/i386/pc_piix.c:142
#11 0x000055580c43597b in pc_init_v2_5 (machine=0x55580e8a5bc0) at /home/mce/workspace/git/qemu/qemu/hw/i386/pc_piix.c:474
#12 0x000055580c4d7cbb in main (argc=19, argv=0x7ffcae0149a8, envp=0x7ffcae014a48) at vl.c:4474
STEP 1: add a gloab control variable before main in vl.c. we will stop on main() if the control variable is zero
int g_stop_here = 1;
int main(int argc, char **argv, char **envp){
......
while(g_stop_here){
;//loop, wait debug;
}
......
}
STEP 2: compile and run qemu
qemu-system-x86_64 -machine accel=kvm -smp 8 -drive file=./test.raw,format=raw -drive file=./disk.qcow2 -cdrom ./RHEL6.3-20120613.2-Server-x86_64-DVD1.iso -m 2048 -serial stdio -vnc 10.238.153.111:0 -monitor telnet:10.238.153.111:6666,server,nowait
STEP 3: gdb attach the qemu process
[root@localhost host]# ps -ef | grep qemu
root 18816 17406 99 22:06 pts/1 00:00:05 qemu-system-x86_64
roooot@localhost host]# gdb -p 18816
STEP 4: set the breakpoint
(gdb) bt
#0 0x000055580c4d3fbd in main (argc=19, argv=0x7ffcae0149a8, envp=0x7ffcae014a48) at vl.c:2944
(gdb) b kvm_put_msr_feature_control
Breakpoint 1 at 0x55580c4b1a89: file /home/mce/workspace/git/qemu/qemu/target-i386/kvm.c, line 1311.
(gdb) b x86_cpu_reset
Breakpoint 2 at 0x55580c47f49f: file /home/mce/workspace/git/qemu/qemu/target-i386/cpu.c, line 2608.
STEP 5: set the gloab control variable to zero and contiue run qemu process
(gdb) set var g_stop_here=0
(gdb) c
STEP 6: QEMU will stop at the breakpoint, and we can debug the process. Also we need see the logic of qemu, some printf could be very helpful.
Breakpoint 2, x86_cpu_reset (s=0x55580e906f30) at /home/mce/workspace/git/qemu/qemu/target-i386/cpu.c:2608
2608 X86CPU *cpu = X86_CPU(s);
(gdb) bt
#0 x86_cpu_reset (s=0x55580e906f30) at /home/mce/workspace/git/qemu/qemu/target-i386/cpu.c:2608
#1 0x000055580c68a571 in cpu_reset (cpu=0x55580e906f30) at qom/cpu.c:231
#2 0x000055580c4800c7 in x86_cpu_realizefn (dev=0x55580e906f30, errp=0x7ffcae014210) at /home/mce/workspace/git/qemu/qemu/target-i386/cpu.c:2914
#3 0x000055580c55c9bd in device_set_realized (obj=0x55580e906f30, value=true, errp=0x7ffcae0143c8) at hw/core/qdev.c:1055
#4 0x000055580c6cd84d in property_set_bool (obj=0x55580e906f30, v=0x55580e921bf0, opaque=0x55580e8f7720, name=0x55580c7ba530 "realized", errp=0x7ffcae0143c8) at qom/object.c:1708
#5 0x000055580c6cbe84 in object_property_set (obj=0x55580e906f30, v=0x55580e921bf0, name=0x55580c7ba530 "realized", errp=0x7ffcae0143c8) at qom/object.c:965
#6 0x000055580c6ce71b in object_property_set_qobject (obj=0x55580e906f30, value=0x55580e8f6bc0, name=0x55580c7ba530 "realized", errp=0x7ffcae0143c8) at qom/qom-qobject.c:24
#7 0x000055580c6cc11a in object_property_set_bool (obj=0x55580e906f30, value=true, name=0x55580c7ba530 "realized", errp=0x7ffcae0143c8) at qom/object.c:1034
#8 0x000055580c431fff in pc_new_cpu (cpu_model=0x55580c7ba5e5 "qemu64", apic_id=0, errp=0x7ffcae014420) at /home/mce/workspace/git/qemu/qemu/hw/i386/pc.c:1069
#9 0x000055580c4322bc in pc_cpus_init (cpu_model=0x55580c7ba5e5 "qemu64") at /home/mce/workspace/git/qemu/qemu/hw/i386/pc.c:1145
#10 0x000055580c434d2d in pc_init1 (machine=0x55580e8a5bc0, host_type=0x55580c7bb237 "i440FX-pcihost", pci_type=0x55580c7bb230 "i440FX")
at /home/mce/workspace/git/qemu/qemu/hw/i386/pc_piix.c:142
#11 0x000055580c43597b in pc_init_v2_5 (machine=0x55580e8a5bc0) at /home/mce/workspace/git/qemu/qemu/hw/i386/pc_piix.c:474
#12 0x000055580c4d7cbb in main (argc=19, argv=0x7ffcae0149a8, envp=0x7ffcae014a48) at vl.c:4474
相关文章推荐
- Linux 自检和 SystemTap
- Python 七步捉虫法
- 路由器的配置与调试
- 对于技术人员的出现了运行时间错误,是否要进行调试的解决方法
- 我的服务器SQL2000的sqlserver占用了90%的cpu,怎么查是那个库?
- MySQL服务器进程CPU占用100%的解决方法
- C#获取CPU编号的方法
- 使用MySQL Slow Log来解决MySQL CPU占用高的问题
- 笔记本下什么是迅驰处理器(cpu)相关资料第1/2页
- doscan.exe进程占用了大量的CPU和内存的解决方法
- 可以用来调试JavaScript错误的解决方案
- 如何调试异步加载页面里包含的js文件
- jQuery下的Ajax调试步骤
- CPU也有远程攻击漏洞 英特尔匆匆修补
- w3wp.exe占用cpu过高的解决方法第1/2页
- 调试一段PHP程序时遇到的三个问题
- JavaScript高级程序设计 错误处理与调试学习笔记
- Javascript调试脚本的经验之谈第1/2页
- 在IE,Firefox,Safari,Chrome,Opera浏览器上调试javascript