qemu 源码调试

原文:https://www.cnblogs.com/fangying7/p/5679033.html

1:下载最新的QEMU源码

  git clone https://github.com/qemu/qemu.git

2:对qemu进行编译

 ./configure --prefix=/usr --libdir=/usr/lib64 --sysconfdir=/etc --interp-prefix=/usr/qemu-%M --libexecdir=/usr/libexec --with-confsuffix=/qemu-kvm --localstatedir=/var --target-list=x86_64-softmmu --enable-rdma --enable-kvm --enable-numa --disable-sdl --disable-spice --disable-smartcard --enable-linux-aio --enable-debug --enable-debug-info

     make install 

3: 下载一个精简的image镜像

  wget http://wiki.qemu.org/download/linux-0.2.img.bz2

4:写一个脚本开始调试qemu (写一个脚本:方便调试,将脚本放到qemu源码目录)

  gdb -tui --args /opt/qemu/bin/qemu-system-x86_64 --enable-kvm -m 256 -L /usr/share/qemu-kvm/ -hda linux-0.2.img  -chardev pty,id=charserial0 -device isa-serial,chardev=charserial0,id=serial0 -vnc 0.0.0.0:0 -device piix3-usb-uhci,id=usb,bus=pci.0,addr=0x1.0x2 -device usb-ehci,id=usb1,bus=pci.0,addr=0x7 -device nec-usb-xhci,id=usb2,bus=pci.0,addr=0x8

5:处理信号异常

  handle SIGUSR1 SIGUSR2 noprint nostop

6:邦定和解绑定vfio

bind:

  echo "vfio-pci"  >> "/sys/bus/pci/devices/0000:82:1f.0/driver_override"

  echo 0000:82:1f.0 > /sys/bus/pci/drivers_probe

unbind:

  echo "0000:82:1f.0" >  "/sys/bus/pci/devices/0000:82:1f.0/driver/unbind"

  echo 0000:82:1f.0 > /sys/bus/pci/drivers_probe

run-virt.sh

/root/nemu/build-x86_64_virt/x86_64_virt-softmmu/qemu-system-x86_64_virt \
-bios ./OVMF.fd \
-machine virt,accel=kvm,kernel_irqchip \
-cpu host \
-m 4096,slots=4,maxmem=16950M \
-smp 4 \
-device virtio-serial-pci,id=virtio-serial0 \
-device virtconsole,chardev=charconsole0,id=console0 \
-chardev stdio,id=charconsole0 \
-device sysbus-debugcon,iobase=0x402,chardev=debugcon \
-chardev file,path=/tmp/debug-log,id=debugcon \
-device sysbus-debugcon,iobase=0x3f8,chardev=serialcon \
-chardev file,path=/tmp/serial-log,id=serialcon \
-device virtio-blk-pci,drive=disk -drive if=none,id=disk,file=diskvm.img \
-netdev user,id=mynet0,hostfwd=tcp::2222-:22,hostname=nemuvm \
-device virtio-net-pci,netdev=mynet0

/mnt/sdb/fangying/qemu/x86_64-softmmu/qemu-system-x86_64 \
-machine pc-i440fx-2.8,accel=kvm,kernel_irqchip \
-cpu host -m 4096,slots=4,maxmem=16950M \
-smp 4 \
-chardev pty,id=charserial0 \
-device isa-serial,chardev=charserial0,id=serial0 \
-netdev tap,id=tap0,ifname=virbr0-nic,vhost=on,script=no \
-device virtio-net-pci,netdev=tap0 \
-kernel /mnt/sdb/fangying/code/linux-stable/arch/x86/boot/bzImage \
-initrd /boot/initramfs-4.18.0+.img \
-append 'console=ttyS0 nokaslr' \
-vnc :9 \
-S \
-gdb tcp::1234

开始调试内核

gdb vmlinx

target remote :1234

set architecture i8086

i r 

## KVM Mail List

https://patchwork.kernel.org/project/kvm/list/

  handle SIGUSR1 SIGUSR2 noprint nostop

6:邦定和解绑定vfio

bind:

  echo "vfio-pci"  >> "/sys/bus/pci/devices/0000:82:1f.0/driver_override"

  echo 0000:82:1f.0 > /sys/bus/pci/drivers_probe

unbind:

  echo "0000:82:1f.0" >  "/sys/bus/pci/devices/0000:82:1f.0/driver/unbind"

  echo 0000:82:1f.0 > /sys/bus/pci/drivers_probe

run-virt.sh

/root/nemu/build-x86_64_virt/x86_64_virt-softmmu/qemu-system-x86_64_virt \
-bios ./OVMF.fd \
-machine virt,accel=kvm,kernel_irqchip \
-cpu host \
-m 4096,slots=4,maxmem=16950M \
-smp 4 \
-device virtio-serial-pci,id=virtio-serial0 \
-device virtconsole,chardev=charconsole0,id=console0 \
-chardev stdio,id=charconsole0 \
-device sysbus-debugcon,iobase=0x402,chardev=debugcon \
-chardev file,path=/tmp/debug-log,id=debugcon \
-device sysbus-debugcon,iobase=0x3f8,chardev=serialcon \
-chardev file,path=/tmp/serial-log,id=serialcon \
-device virtio-blk-pci,drive=disk -drive if=none,id=disk,file=diskvm.img \
-netdev user,id=mynet0,hostfwd=tcp::2222-:22,hostname=nemuvm \
-device virtio-net-pci,netdev=mynet0

/mnt/sdb/fangying/qemu/x86_64-softmmu/qemu-system-x86_64 \
-machine pc-i440fx-2.8,accel=kvm,kernel_irqchip \
-cpu host -m 4096,slots=4,maxmem=16950M \
-smp 4 \
-chardev pty,id=charserial0 \
-device isa-serial,chardev=charserial0,id=serial0 \
-netdev tap,id=tap0,ifname=virbr0-nic,vhost=on,script=no \
-device virtio-net-pci,netdev=tap0 \
-kernel /mnt/sdb/fangying/code/linux-stable/arch/x86/boot/bzImage \
-initrd /boot/initramfs-4.18.0+.img \
-append 'console=ttyS0 nokaslr' \
-vnc :9 \
-S \
-gdb tcp::1234

开始调试内核

gdb vmlinx

target remote :1234

set architecture i8086

i r 

## KVM Mail List

https://patchwork.kernel.org/project/kvm/list/

猜你喜欢

转载自www.cnblogs.com/wangjq19920210/p/10611628.html
今日推荐