>From 5aef547c1be93f18af5c480da0cae4a7a56a3250 Mon Sep 17 00:00:00 2001
From: qiaonuohan <qiaonuohan@cn.fujitsu.com>
Date: Tue, 21 Aug 2012 10:29:28 +0800
Subject: [PATCH 1/3] add support to qemu memory dump

---
 defs.h    |    1 +
 main.c    |    2 ++
 netdump.c |   16 ++++++++++++----
 3 files changed, 15 insertions(+), 4 deletions(-)

diff --git a/defs.h b/defs.h
index 4a8e2e3..d37e453 100755
--- a/defs.h
+++ b/defs.h
@@ -492,6 +492,7 @@ struct program_context {
 #define FLAT_FORMAT() (pc->flags2 & FLAT)
 #define ELF_NOTES_VALID() (pc->flags2 & ELF_NOTES)
 #define RADIX_OVERRIDE (0x80ULL)
+#define QEMU_MEM_DUMP (0x100ULL)
 	char *cleanup;
 	char *namelist_orig;
 	char *namelist_debug_orig;
diff --git a/main.c b/main.c
index 2dbe902..9dced6e 100755
--- a/main.c
+++ b/main.c
@@ -1330,6 +1330,8 @@ dump_program_context(void)
 		fprintf(fp, "%sLIVE_DUMP", others++ ? "|" : "");
 	if (pc->flags2 & RADIX_OVERRIDE)
 		fprintf(fp, "%sRADIX_OVERRIDE", others++ ? "|" : "");
+	if (pc->flags2 & QEMU_MEM_DUMP)
+		fprintf(fp, "%sQEMU_MEM_DUMP", others++ ? "|" : "");
 	fprintf(fp, ")\n");
 
 	fprintf(fp, "         namelist: %s\n", pc->namelist);
diff --git a/netdump.c b/netdump.c
index 9fecbf3..55073dd 100644
--- a/netdump.c
+++ b/netdump.c
@@ -1670,13 +1670,13 @@ dump_Elf32_Nhdr(Elf32_Off offset, int store)
 	char buf[BUFSIZE];
 	char *ptr;
 	ulong *uptr;
-	int xen_core, vmcoreinfo, eraseinfo;
+	int xen_core, vmcoreinfo, eraseinfo, qemuinfo;
 	uint64_t remaining, notesize;
 
 	note = (Elf32_Nhdr *)((char *)nd->elf32 + offset);
 
         BZERO(buf, BUFSIZE);
-	xen_core = vmcoreinfo = eraseinfo = FALSE;
+	xen_core = vmcoreinfo = eraseinfo = qemuinfo = FALSE;
         ptr = (char *)note + sizeof(Elf32_Nhdr);
 
 	if (ptr > (nd->elf_header + nd->header_size)) {
@@ -1767,6 +1767,7 @@ dump_Elf32_Nhdr(Elf32_Off offset, int store)
 		xen_core = STRNEQ(buf, "XEN CORE") || STRNEQ(buf, "Xen");
 		vmcoreinfo = STRNEQ(buf, "VMCOREINFO");
 		eraseinfo = STRNEQ(buf, "ERASEINFO");
+		qemuinfo = STRNEQ(buf, "QEMU");
 		if (xen_core) {
 			netdump_print("(unknown Xen n_type)\n"); 
 			if (store)
@@ -1785,6 +1786,9 @@ dump_Elf32_Nhdr(Elf32_Off offset, int store)
 				pc->flags2 |= ERASEINFO_DATA;
 		} else
 			netdump_print("(?)\n");
+
+		if (qemuinfo)
+			pc->flags2 |= QEMU_MEM_DUMP;
 		break;
 
 	case NT_XEN_KDUMP_CR3: 
@@ -1900,14 +1904,14 @@ dump_Elf64_Nhdr(Elf64_Off offset, int store)
 	ulonglong *uptr;
 	int *iptr;
 	ulong *up;
-	int xen_core, vmcoreinfo, eraseinfo;
+	int xen_core, vmcoreinfo, eraseinfo, qemuinfo;
 	uint64_t remaining, notesize;
 
 	note = (Elf64_Nhdr *)((char *)nd->elf64 + offset);
 
         BZERO(buf, BUFSIZE);
         ptr = (char *)note + sizeof(Elf64_Nhdr);
-	xen_core = vmcoreinfo = eraseinfo = FALSE;
+	xen_core = vmcoreinfo = eraseinfo = qemuinfo = FALSE;
 
 	if (ptr > (nd->elf_header + nd->header_size)) {
 		error(WARNING, 
@@ -2028,6 +2032,7 @@ dump_Elf64_Nhdr(Elf64_Off offset, int store)
 		xen_core = STRNEQ(buf, "XEN CORE") || STRNEQ(buf, "Xen");
 		vmcoreinfo = STRNEQ(buf, "VMCOREINFO");
 		eraseinfo = STRNEQ(buf, "ERASEINFO");
+		qemuinfo = STRNEQ(buf, "QEMU");
                 if (xen_core) {
                         netdump_print("(unknown Xen n_type)\n");
 			if (store)
@@ -2050,6 +2055,9 @@ dump_Elf64_Nhdr(Elf64_Off offset, int store)
 				pc->flags2 |= ERASEINFO_DATA;
                 } else
                         netdump_print("(?)\n");
+
+		if (qemuinfo)
+			pc->flags2 |= QEMU_MEM_DUMP;
                 break;
 
 	case NT_XEN_KDUMP_CR3: 
-- 
1.7.1

