gdb + kvm调试内核

1.编译内核
修改Makefile,修改为-O1 或者-O0
ifdef CONFIG_PROFILE_ALL_BRANCHES
KBUILD_CFLAGS += -O1 $(call cc-disable-warning,maybe-uninitialized,)
else
KBUILD_CFLAGS += -O1
endif

  1. 修改虚拟机xml文件
    <domain type='kvm' xmlns:qemu='http://libvirt.org/schemas/domain/qemu/1.0'>;
    ......
    </devices>
    <qemu:commandline>
    <qemu:arg value='-S'/>
    <qemu:arg value='-gdb'/>
    <qemu:arg value='tcp::1234'/>
    </qemu:commandline>
    </domain>

启动虚拟机
id=balloon0,bus=pci.0,addr=0x9 -S -gdb tcp::1234 -msg timestamp=on

  1. 在宿主机上创建目录,拷贝需要调试的内核文件到该目录下,如:
    vmlinuz-4.14.0-generic
    vmlinuz-4.14.0-generic: x86 boot sector

4.启动gdb
gdb vmlinuz-4.14.0-generic
(gdb) target remote 127.0.0.1:1234
Remote debugging using 127.0.0.1:1234

编译kvm
1.进入kvm所在的目录
linux-4.14/arch/x86/kvm
2.执行编译命令
make CONFIG_KVM=m CONFIG_INTEL_KVM=m -C /vms/kernel4.14/linux-4.14 M=$PWD modules
/vms/kernel4.14/linux-4.14 内核所在的路径
M=$PWD kvm所在的路径

进入内核代码目路
make CONFIG_KVM=m CONFIG_INTEL_KVM=m -C /vms/kernel4.14/linux-4.14 M=/vms/kernel4.14/linux-4.14/arch/x86/kvm modules

猜你喜欢

转载自blog.51cto.com/zybcloud/2407547
0条评论
添加一条新回复