If qemu crashes or fails when run under libguestfs, it can be a bit hard to debug things. However a small qemu wrapper and gdbserver can help.
Create a file called qemu-wrapper
chmod +x and containing:
#!/bin/bash - if ! echo "$@" | grep -sqE -- '-help|-version|-device \?' ; then gdbserver="gdbserver :1234" fi exec $gdbserver /usr/bin/qemu-system-x86_64 "$@"
Set your environment variables so libguestfs will use the qemu wrapper instead of running qemu directly:
$ export LIBGUESTFS_BACKEND=direct $ export LIBGUESTFS_HV=/path/to/qemu-wrapper
Now we run guestfish or another virt tool as normal:
$ guestfish -a /dev/null -v -x run
When qemu starts up, gdbserver will run and halt the process, printing:
Listening on port 1234
At this point you can connect gdb:
$ gdb (gdb) file /usr/bin/qemu-system-x86_64 (gdb) target remote tcp::1234 set breakpoints etc here (gdb) cont