Qemu调试Windows

来源:互联网 发布:ni软件卸载工具 编辑:程序博客网 时间:2024/05/17 01:09

原文地址:http://blog.csdn.net/ariesjzj/article/details/8698439

Kernel级的Windows调试,Windbg+Virtualbox(Vmware )这套方案很好用,但Windbg依赖于guest(也就是Windows)。如果guest中的Windows小crash,可以抓到,但如果crash得比较严重,把和Windbg通信的那部分也破坏了,那Windbg就没法work了。而用qemu则没有这个问题,因为qemu中的gdbserver是在虚拟机里的,guest无论怎么crash都没有影响。


1. 准备Windows的image文件,可以用qemu的虚拟cdrom进行安装。也可以用Virtualbox选择qcow格式并安装(最新的Virtualbox才有这功能)。注意qcow不支持snapshot,而qcow2支持,两者可以通过qemu-img转。


2. 运行qemu,如:

$ qemu-sytem-x86_64 -hda /home/zjin/win7.qcow -m 2048 -net nic.vlan=0 -net user,vlan=0,hostname=emu -boot c

最好不要加kvm: -machine accel=kvm 或 -enable-kvm,否则系统能跑起来,但软件中断停不下来。


3. 起gdbserver

在qemu里Ctrl+Alt+2进入monitor,然后

(qemu) gdbserver

也可以在qemu命令行加-s -S随系统启动。


4. 在host上起gdb,执行

(gdb)target remote localhost:1234

如果guest是64位的话还要执行

(gdb)set architecture i386:x86-64

然后就可以用gdb调了,要看一些模拟硬件的信息(tlb, crx, msr, gdt等)可以Ctrl+Alt+2到monitor里看。



一些问题:

* No available block device supports snapshots

可能是image文件格式不支持,将image文件转成qcow2

* Remote 'g' packet reply is too long:

Mode的变化gdb并不知道,所以要手动改:

gdb set architecture i386:x86-64

gdb set archtecture i386


Reference:

Running Virtual Machines with qemu-kvm http://doc.opensuse.org/products/draft/SLES/SLES-kvm_sd_draft/cha.qemu.running.html

Debugging Tips(Qemu+windbg) http://www.h7.dion.ne.jp/~qemu-win/DebuggingTips-en.html#windbg

Developing Linux inside QEMU/KVM Virtual Machines http://chemnitzer.linux-tage.de/2012/vortraege/folien/1061-VirtualDebugging.pdf

qemu+gdb http://www.ece.cmu.edu/~ee349/f-2012/lab2/qemu.pdf

Using IDA's GDB debugger with QEMU emulator https://www.hex-rays.com/products/ida/support/tutorials/debugging_gdb_qemu.pdf