kvm tools: Beautify debug output
PATCH 1/1 kvm tools: Beautify debug output
1. print mem debug info into debugfd instead guest console
2. always print page table info
Signed-off-by Asias He <[email protected]>
--- tools/kvm/include/kvm/kvm.h | 2 +- tools/kvm/kvm.c | 11 ++++++----- tools/kvm/x86/kvm-cpu.c | 12 +++++++++--- 3 files changed, 16 insertions(+), 9 deletions(-)
tools/kvm/include/kvm/kvm.h +1 -1
@@ -114,7 +114,7 @@ bool load_bzimage(struct kvm *kvm, int fd_kernel, int fd_initrd, const char *ker/* * Debugging */ -void kvm__dump_mem (struct kvm *kvm,unsigned long addr,unsigned long size); +void kvm__dump_mem (struct kvm *kvm,unsigned long addr,unsigned long size,int debug_fd);extern const char *kvm_exit_reasons[];
tools/kvm/kvm.c +6 -5
@@ -444,7 +444,7 @@ int kvm_timer__exit(struct kvm *kvm) }firmware_exit (kvm_timer__exit); -void kvm__dump_mem (struct kvm *kvm,unsigned long addr,unsigned long size) +void kvm__dump_mem (struct kvm *kvm,unsigned long addr,unsigned long size,int debug_fd) {unsigned char *p;unsigned long n;
@@ -456,10 +456,11 @@ void kvm__dump_mem(struct kvm *kvm, unsigned long addr, unsigned long size) p =guest_flat_to_host (kvm, addr);for (n =0 ; n < size; n +=8 ) { -if (!host_ptr_in_ram (kvm, p + n)) -break ; - -printf (" 0x%08lx: %02x %02x %02x %02x %02x %02x %02x %02x\n" , +if (!host_ptr_in_ram (kvm, p + n)) { +dprintf (debug_fd," 0x%08lx: <unknown>\n" , addr + n); +continue ; + } +dprintf (debug_fd," 0x%08lx: %02x %02x %02x %02x %02x %02x %02x %02x\n" , addr + n, p[n +0 ], p[n +1 ], p[n +2 ], p[n +3 ], p[n +4 ], p[n +5 ], p[n +6 ], p[n +7 ]); }
tools/kvm/x86/kvm-cpu.c +9 -3
@@ -364,7 +364,8 @@ void kvm_cpu__show_code(struct kvm_cpu *vcpu)dprintf (debug_fd,"\n Stack:\n" );dprintf (debug_fd," ------\n" ); -kvm__dump_mem (vcpu->kvm, vcpu->regs.rsp,32 ); +dprintf (debug_fd," rsp: [<%016lx>] \n" , (unsigned long ) vcpu->regs.rsp); +kvm__dump_mem (vcpu->kvm, vcpu->regs.rsp,32 , debug_fd); }void kvm_cpu__show_page_tables (struct kvm_cpu *vcpu)
@@ -374,8 +375,12 @@ void kvm_cpu__show_page_tables(struct kvm_cpu *vcpu)u64 *pte3;u64 *pte4; -if (!is_in_protected_mode (vcpu)) +if (!is_in_protected_mode (vcpu)) { +dprintf (debug_fd,"\n Page Tables:\n" ); +dprintf (debug_fd," ------\n" ); +dprintf (debug_fd," Not in protected mode\n" );return ; + }if (ioctl (vcpu->vcpu_fd,KVM_GET_SREGS , &vcpu->sregs) <0 )die ("KVM_GET_SREGS failed" );
@@ -396,7 +401,8 @@ void kvm_cpu__show_page_tables(struct kvm_cpu *vcpu)if (!host_ptr_in_ram (vcpu->kvm, pte1))return ; -dprintf (debug_fd,"Page Tables:\n" ); +dprintf (debug_fd,"\n Page Tables:\n" ); +dprintf (debug_fd," ------\n" );if (*pte2 & (1 <<7 )) dprintf(debug_fd, " pte4: %016llx pte3: %016llx" " pte2: %016llx\n",
Signature · 1 line
1.8.1