How to debug qemu and libvirt using gdb

Think about this: you are going to start a virtual machine using qemu command line or libvirt xml or virt-install command line, but fails due to some errors. Now you would like to see what is going on around the values of function parameter and registers during the whole calling procedure. Let's see how to debug qemu and libvirt in this blog.

Precondition:
Install the gdb package.

For QEMU:
- If you use the default qemu package from the distros, like opensuse and redhat, you need to install the debuginfo and debugsource subpackages.
  = Firstly, enable the reporitory includes the debug* subpackages if it is disabled:
    # zypper mr -e openSUSE-Leap-42.3-Debug
  = Secondly, install the debug* subpackages.
    # zypper in qemu-x86-debuginfo qemu-debugsource
  = Now you can use gdb to debug your qemu source code, like
    # gdb --args qemu-system-x86 -m 2048 -enable-kvm -drive file=/opt/opensuse423.qcow2,format=qcow2,if=none,id=drive0 -device virtio-blk-pci,drive=drive0,id=dev0,bootindex=1 -cpu host -name "opensuse423" -boot order=c
- If you have qemu sourcecode by cloning from upstream and plan to build by yourself.
  = Fristly, add the --enable-debug* when you configure:
    # cd qemu
    # ./configure --prefix=/usr --libdir=/usr/lib64/ --target-list=x86_64-softmmu --enable-kvm --enable-debug --enable-sdl //use `./configure --help | less` to see more
    # make && make install
  = Now use gdb to debug qemu
    # gdb --args qemu-system-x86 ...

For Libvirt:
- If you use the dedault libvirt package from distros, install the debug* subpackages.
  = Firstly, enable the reporitory includes the debug* subpackages:
    # zypper mr -e openSUSE-Leap-42.3-Debug
  = Secondly, install the debug* subpackages:
    # zypper in libvirt-debugsource libvirt-daemon-debuginfo
    Install other corresponding subpackages if you need, like libvirt-daemon-driver-network-debuginfo, libvirt-daemon-driver-nodedev-debuginfo and so on.
  = Now use gdb to debug Libvirt
    # gdb --args libvirtd
- If you clone libvirt from upstream, and plan to build my yourself.
  = Firstly, build your own Libvirt:
    # cd libvirt
    # ./autogen.sh --prefix=/usr
    # make && make install
  = Now can use gdb to debug libvirt:
    # gdb --args ./daemon/libvirtd

  • 0
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值