[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Qemu-devel] [PATCH 4/5] contrib/elf2dmp: add DMP file name as 2nd argum
From: |
Viktor Prutyanov |
Subject: |
[Qemu-devel] [PATCH 4/5] contrib/elf2dmp: add DMP file name as 2nd argument |
Date: |
Wed, 29 Aug 2018 15:41:27 +0300 |
Before this patch output DMP file name was strictly 'memory.dmp'.
Signed-off-by: Viktor Prutyanov <address@hidden>
---
contrib/elf2dmp/main.c | 34 +++++++++++++++++++++++-----------
1 file changed, 23 insertions(+), 11 deletions(-)
diff --git a/contrib/elf2dmp/main.c b/contrib/elf2dmp/main.c
index 62f08e0..64782fc 100644
--- a/contrib/elf2dmp/main.c
+++ b/contrib/elf2dmp/main.c
@@ -334,24 +334,36 @@ static int fill_context(KDDEBUGGER_DATA64 *kdbg,
return 0;
}
-static int write_dump(struct pa_space *ps, WinDumpHeader64 *hdr)
+static int write_dump(struct pa_space *ps,
+ WinDumpHeader64 *hdr, const char *name)
{
- FILE *dmp_file = fopen("memory.dmp", "wb");
+ FILE *dmp_file = fopen(name, "wb");
if (!dmp_file) {
+ eprintf("Failed to open output file \'%s\'\n", name);
return 1;
}
- printf("Writing down to file...\n");
- fwrite(hdr, sizeof(*hdr), 1, dmp_file);
+ printf("Writing header to file...\n");
- for (size_t i = 0; i < ps->block_nr; i++) {
- fwrite(ps->block[i].addr, ps->block[i].size, 1, dmp_file);
+ if (fwrite(hdr, sizeof(*hdr), 1, dmp_file) != 1) {
+ eprintf("Failed to write dump header\n");
+ fclose(dmp_file);
+ return 1;
}
- fclose(dmp_file);
+ for (size_t i = 0; i < ps->block_nr; i++) {
+ struct pa_block *b = &ps->block[i];
- return 0;
+ printf("Writing block #%zu/%zu to file...\n", i, ps->block_nr);
+ if (fwrite(b->addr, b->size, 1, dmp_file) != 1) {
+ eprintf("Failed to write dump header\n");
+ fclose(dmp_file);
+ return 1;
+ }
+ }
+
+ return fclose(dmp_file);
}
static int pe_get_pdb_symstore_hash(uint64_t base, void *start_addr,
@@ -464,8 +476,8 @@ int main(int argc, char *argv[])
KDDEBUGGER_DATA64 *kdbg;
uint64_t KdVersionBlock;
- if (argc != 2) {
- eprintf("usage:\n\t%s elf_dump\n", argv[0]);
+ if (argc != 3) {
+ eprintf("usage:\n\t%s elf_file dmp_file\n", argv[0]);
return 1;
}
@@ -561,7 +573,7 @@ int main(int argc, char *argv[])
goto out_pdb;
}
- if (write_dump(&ps, &header)) {
+ if (write_dump(&ps, &header, argv[2])) {
eprintf("Failed to save dump\n");
err = 1;
goto out_kdbg;
--
2.7.4