From: Jan Kiszka <jan.kiszka@xxxxxxxxxxx> The latter provides even more information. Signed-off-by: Jan Kiszka <jan.kiszka@xxxxxxxxxxx> --- qemu-kvm-x86.c | 95 -------------------------------------------------------- qemu-kvm.c | 7 ++-- qemu-kvm.h | 17 ---------- 3 files changed, 3 insertions(+), 116 deletions(-) diff --git a/qemu-kvm-x86.c b/qemu-kvm-x86.c index c0061a1..df4f0b4 100644 --- a/qemu-kvm-x86.c +++ b/qemu-kvm-x86.c @@ -319,101 +319,6 @@ int kvm_has_pit_state2(kvm_context_t kvm) return r; } -void kvm_show_code(CPUState *env) -{ -#define SHOW_CODE_LEN 50 - struct kvm_regs regs; - struct kvm_sregs sregs; - int r, n; - int back_offset; - unsigned char code; - char code_str[SHOW_CODE_LEN * 3 + 1]; - unsigned long rip; - - r = kvm_vcpu_ioctl(env, KVM_GET_SREGS, &sregs); - if (r < 0 ) { - perror("KVM_GET_SREGS"); - return; - } - r = kvm_vcpu_ioctl(env, KVM_GET_REGS, ®s); - if (r < 0) { - perror("KVM_GET_REGS"); - return; - } - rip = sregs.cs.base + regs.rip; - back_offset = regs.rip; - if (back_offset > 20) { - back_offset = 20; - } - *code_str = 0; - for (n = -back_offset; n < SHOW_CODE_LEN-back_offset; ++n) { - if (n == 0) { - strcat(code_str, " -->"); - } - cpu_physical_memory_rw(rip + n, &code, 1, 1); - sprintf(code_str + strlen(code_str), " %02x", code); - } - fprintf(stderr, "code:%s\n", code_str); -} - -static void print_seg(FILE *file, const char *name, struct kvm_segment *seg) -{ - fprintf(stderr, - "%s %04x (%08llx/%08x p %d dpl %d db %d s %d type %x l %d" - " g %d avl %d)\n", - name, seg->selector, seg->base, seg->limit, seg->present, - seg->dpl, seg->db, seg->s, seg->type, seg->l, seg->g, - seg->avl); -} - -static void print_dt(FILE *file, const char *name, struct kvm_dtable *dt) -{ - fprintf(stderr, "%s %llx/%x\n", name, dt->base, dt->limit); -} - -void kvm_show_regs(CPUState *env) -{ - struct kvm_regs regs; - struct kvm_sregs sregs; - int r; - - r = kvm_vcpu_ioctl(env, KVM_GET_REGS, ®s); - if (r < 0) { - perror("KVM_GET_REGS"); - return; - } - fprintf(stderr, - "rax %016llx rbx %016llx rcx %016llx rdx %016llx\n" - "rsi %016llx rdi %016llx rsp %016llx rbp %016llx\n" - "r8 %016llx r9 %016llx r10 %016llx r11 %016llx\n" - "r12 %016llx r13 %016llx r14 %016llx r15 %016llx\n" - "rip %016llx rflags %08llx\n", - regs.rax, regs.rbx, regs.rcx, regs.rdx, - regs.rsi, regs.rdi, regs.rsp, regs.rbp, - regs.r8, regs.r9, regs.r10, regs.r11, - regs.r12, regs.r13, regs.r14, regs.r15, - regs.rip, regs.rflags); - r = kvm_vcpu_ioctl(env, KVM_GET_SREGS, &sregs); - if (r < 0) { - perror("KVM_GET_SREGS"); - return; - } - print_seg(stderr, "cs", &sregs.cs); - print_seg(stderr, "ds", &sregs.ds); - print_seg(stderr, "es", &sregs.es); - print_seg(stderr, "ss", &sregs.ss); - print_seg(stderr, "fs", &sregs.fs); - print_seg(stderr, "gs", &sregs.gs); - print_seg(stderr, "tr", &sregs.tr); - print_seg(stderr, "ldt", &sregs.ldt); - print_dt(stderr, "gdt", &sregs.gdt); - print_dt(stderr, "idt", &sregs.idt); - fprintf(stderr, "cr0 %llx cr2 %llx cr3 %llx cr4 %llx cr8 %llx" - " efer %llx\n", - sregs.cr0, sregs.cr2, sregs.cr3, sregs.cr4, sregs.cr8, - sregs.efer); -} - static void kvm_set_cr8(CPUState *env, uint64_t cr8) { env->kvm_run->cr8 = cr8; diff --git a/qemu-kvm.c b/qemu-kvm.c index bd595b1..55de971 100644 --- a/qemu-kvm.c +++ b/qemu-kvm.c @@ -425,8 +425,7 @@ int kvm_run(CPUState *env) case KVM_EXIT_EXCEPTION: fprintf(stderr, "exception %d (%x)\n", run->ex.exception, run->ex.error_code); - kvm_show_regs(env); - kvm_show_code(env); + cpu_dump_state(env, stderr, fprintf, CPU_DUMP_CODE); abort(); break; case KVM_EXIT_IO: @@ -463,7 +462,7 @@ int kvm_run(CPUState *env) r = kvm_arch_run(env); if (r < 0) { fprintf(stderr, "unhandled vm exit: 0x%x\n", run->exit_reason); - kvm_show_regs(env); + cpu_dump_state(env, stderr, fprintf, CPU_DUMP_CODE); abort(); } if (r > 0) { @@ -988,7 +987,7 @@ int kvm_cpu_exec(CPUState *env) r = kvm_run(env); if (r < 0) { printf("kvm_run returned %d\n", r); - kvm_show_regs(env); + cpu_dump_state(env, stderr, fprintf, CPU_DUMP_CODE); vm_stop(VMSTOP_PANIC); } diff --git a/qemu-kvm.h b/qemu-kvm.h index 0814883..752aebd 100644 --- a/qemu-kvm.h +++ b/qemu-kvm.h @@ -68,9 +68,6 @@ int kvm_arch_create(kvm_context_t kvm); int kvm_arch_run(CPUState *env); - -void kvm_show_code(CPUState *env); - int handle_halt(CPUState *env); int handle_shutdown(kvm_context_t kvm, CPUState *env); @@ -139,20 +136,6 @@ int kvm_set_shadow_pages(kvm_context_t kvm, unsigned int nrshadow_pages); #endif -/*! - * \brief Dump VCPU registers - * - * This dumps some of the information that KVM has about a virtual CPU, namely: - * - GP Registers - * - * A much more verbose version of this is available as kvm_dump_vcpu() - * - * \param kvm Pointer to the current kvm_context - * \param vcpu Which virtual CPU should get dumped - * \return 0 on success - */ -void kvm_show_regs(CPUState *env); - int kvm_set_irq_level(kvm_context_t kvm, int irq, int level, int *status); #ifdef KVM_CAP_IRQCHIP -- 1.7.1 -- To unsubscribe from this list: send the line "unsubscribe kvm" in the body of a message to majordomo@xxxxxxxxxxxxxxx More majordomo info at http://vger.kernel.org/majordomo-info.html