From 0e2b34c4b60df753a700bcdf2cd6c10901f0dcc8 Mon Sep 17 00:00:00 2001 From: Zhou Wenjian Date: Wed, 10 Dec 2014 09:38:39 +0800 Subject: [PATCH 4/5] Make qemu64 note human readable --- netdump.c | 75 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 files changed, 75 insertions(+), 0 deletions(-) diff --git a/netdump.c b/netdump.c index 51403b7..4bb847f 100644 --- a/netdump.c +++ b/netdump.c @@ -2701,12 +2701,87 @@ display_prstatus_elf32(void *note_ptr, char *buf) } static void +display_qemu_elf(QEMUCPUState *ptr, char *buf, int flags) +{ + int i, size, t=0; + QEMUCPUSegment *seg; + char *seg_names[] = {"CS", "DS", "ES", "FS", "GS", "SS", "LDT", "TR", + "GDT", "IDT"}; + + ptr = (QEMUCPUState *)roundup((ulong)ptr, 4); + seg = &(ptr->cs); + + size = sprintf(buf, + "\t\tversion: 0x%08x\tsize: 0x%08x\n" + "\t\tRAX : 0x%016llx\tRBX : 0x%016llx\n" + "\t\tRCX : 0x%016llx\tRDX : 0x%016llx\n" + "\t\tRSI : 0x%016llx\tRDI : 0x%016llx\n" + "\t\tRSP : 0x%016llx\tRBP : 0x%016llx\n" + "\t\tRIP : 0x%016llx\tRFLAGS: 0x%016llx\n", + ptr->version, ptr->size, + (ulonglong)ptr->rax, (ulonglong)ptr->rbx, (ulonglong)ptr->rcx, + (ulonglong)ptr->rdx, (ulonglong)ptr->rsi, (ulonglong)ptr->rdi, + (ulonglong)ptr->rsp, (ulonglong)ptr->rbp, + (ulonglong)ptr->rip, (ulonglong)ptr->rflags + ); + buf += size; + t+=size; + if (flags == KDUMP_ELF64) { + size = sprintf(buf, + "\t\tR8 : 0x%016llx\tR9 : 0x%016llx\n" + "\t\tR10 : 0x%016llx\tR11 : 0x%016llx\n" + "\t\tR12 : 0x%016llx\tR13 : 0x%016llx\n" + "\t\tR14 : 0x%016llx\tR15 : 0x%016llx\n", + (ulonglong)ptr->r8, (ulonglong)ptr->r9, (ulonglong)ptr->r10, + (ulonglong)ptr->r11, (ulonglong)ptr->r12, (ulonglong)ptr->r13, + (ulonglong)ptr->r14, (ulonglong)ptr->r15 + ); + buf += size; + } + + for(i = 0; i < sizeof(seg_names)/sizeof(seg_names[0]); i++) { + size = sprintf(buf, + "\t\t%s:\n" + "\t\tselector: 0x%08x\tlimit: 0x%08x\tflags: 0x%08x\n" + "\t\tpad : 0x%08x\tbase : 0x%016llx\n", + seg_names[i], + seg->selector, seg->limit, seg->flags, + seg->pad, (ulonglong)seg->base + ); + buf += size; + seg++; + } + + sprintf(buf, + "\t\tcr[0]: %016llx\tcr[1]: %016llx\tcr[2]: %016llx\n" + "\t\tcr[3]: %016llx\tcr[4]: %016llx\n", + (ulonglong)ptr->cr[0], (ulonglong)ptr->cr[1], (ulonglong)ptr->cr[2], + (ulonglong)ptr->cr[3], (ulonglong)ptr->cr[4] + ); +} + +static void +display_qemu_elf64(void *note_ptr, char *buf) +{ + Elf64_Nhdr *note; + QEMUCPUState *ptr; + + note = (Elf64_Nhdr *)note_ptr; + ptr = (QEMUCPUState *)( + (char *)note + sizeof(Elf64_Nhdr) + note->n_namesz); + + display_qemu_elf(ptr, buf, KDUMP_ELF64); +} + +static void display_note(void *note_ptr, char *buf, int descsz) { if (descsz == (2 * sizeof(struct x86_64_prstatus))) display_prstatus_elf64(note_ptr, buf); else if (descsz == sizeof(struct x86_prstatus)) display_prstatus_elf32(note_ptr, buf); + else if (descsz == (2 * sizeof(QEMUCPUState))) + display_qemu_elf64(note_ptr, buf); } void -- 1.7.1