1. print mem debug info into debugfd instead guest console
2. always print page table info

Signed-off-by: Asias He <asias.he...@gmail.com>
---
 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(-)

diff --git a/tools/kvm/include/kvm/kvm.h b/tools/kvm/include/kvm/kvm.h
index acb0818..ad53ca7 100644
--- a/tools/kvm/include/kvm/kvm.h
+++ b/tools/kvm/include/kvm/kvm.h
@@ -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[];
 
diff --git a/tools/kvm/kvm.c b/tools/kvm/kvm.c
index a6b3c23..cfd30dd 100644
--- a/tools/kvm/kvm.c
+++ b/tools/kvm/kvm.c
@@ -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]);
        }
diff --git a/tools/kvm/x86/kvm-cpu.c b/tools/kvm/x86/kvm-cpu.c
index b6190ed..5cc4e1e 100644
--- a/tools/kvm/x86/kvm-cpu.c
+++ b/tools/kvm/x86/kvm-cpu.c
@@ -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",
-- 
1.8.1

--
To unsubscribe from this list: send the line "unsubscribe kvm" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html

Reply via email to