I'm trying to debug the QEMU source code to track dirty page updates during live migration. My goal is to inspect the behavior inside functions like cpu_physical_memory_set_dirty_lebitmap() on the destination server, which handles syncing of KVM dirty pages.
When I simply use QEMU logs (printf) inside that function, it only prints 0 dirty pages — until I connect to the destination VM using RealVNC, then it starts printing proper dirty page counts. This suggests some laziness or delay in page updates that I want to analyze deeper.
To be clear: I have run a memory-intensive process inside the guest VM to intentionally dirty pages, so dirty pages should be getting tracked.
So I turned to GDB, but I'm running into issues.
Built QEMU from source with debugging enabled using
--enable-debug.Launched the destination VM with:
qemu-system-x86_64 ... -s -S-sopens a GDB server on port 1234.-Stells QEMU to not start the CPU until GDB gives the continue command.
Attached GDB like this:
gdb qemu-system-x86_64 (gdb) target remote localhost:1234 (gdb) break cpu_physical_memory_set_dirty_lebitmap (gdb) continue
But the destination VM (and the source as well, which is normal in post-copy live migration) hangs and displays an unresponsive GUI. Nothing progresses from there.
If I remove
-S, the migration works fine and the destination VM doesn’t hang — but I can’t insert breakpoints early enough, so I lose the ability to properly debug.In the QEMU documentation, it suggests launching GDB like this:
gdb vmlinuxBut from what I understand, that's meant for debugging the Linux kernel, not QEMU itself. Since I'm trying to debug the QEMU source code, I believe the correct approach is:
gdb qemu-system-x86_64
Question
How can I debug QEMU with GDB during live migration, without the destination VM or the migration process hanging when I use -S?
gdb --args qemu-system-x86_64 ...then at the GDB prompt justrun. Or you could start gdb asgdb qemu-system-x86_64then at the GDB promptattach PIDto attach to an already running QEMU process.