Debugging with gdbserver and qemu, how to set watchpoint on a control register, cr3
I'm debugging a kernel and i want to know when the cr3 register is changed. I know how to set a watchpoint on a general purpose register like eax and others.
The problem is, since gdb does not have access to control registers, setting a watchpoint on cr3 does not work.
So, is it possible to set a watchpoint from the qemu monitor? If yes, how?
Sorry, there's no way to do this from the QEMU monitor. (If you look at target-i386/helper.c:cpu_x86_update_cr3() in the QEMU sources you'll see that it doesn't do anything that would notify anybody about CR3 updates, it just puts the new value into the internal CPU state structure.)
The best you can do for this sort of thing is to run with two debuggers (one connected to QEMU's gdbstub to talk to the guest, and one directly debugging QEMU itself). Then you can put a breakpoint on cpu_x86_update_cr3() in QEMU and see what's going on then. You need to know a fair amount about QEMU's internals to be able to do this effectively, though...