[minicoredumper] [PATCH 13/14] minicoredumper: Add an option to dump memory pages pointed by registers

Mateusz Moscicki m.moscicki2 at partner.samsung.com
Tue May 21 14:52:49 CEST 2019


If recept option "dump_pointed_by_regs" is set to true then if a
register value looks like a pointer to a memory then store previous,
current and next page to the minicoredump.

Change-Id: I6f58b7c3549b7ac38e233637be3d6008f281c6f2
---
 etc/minicoredumper/generic.recept.json          |  3 +-
 src/minicoredumper/corestripper.c               | 39 +++++++++++++++++++++++++
 src/minicoredumper/minicoredumper.recept.json.5 |  3 ++
 src/minicoredumper/prog_config.c                |  3 ++
 src/minicoredumper/prog_config.h                |  1 +
 5 files changed, 48 insertions(+), 1 deletion(-)

diff --git a/etc/minicoredumper/generic.recept.json b/etc/minicoredumper/generic.recept.json
index 15406fb..fe24195 100644
--- a/etc/minicoredumper/generic.recept.json
+++ b/etc/minicoredumper/generic.recept.json
@@ -22,5 +22,6 @@
     "live_dumper": true,
     "write_proc_info": false,
     "write_debug_log": false,
-    "dump_fat_core": false
+    "dump_fat_core": false,
+    "dump_pointed_by_regs": true
 }
diff --git a/src/minicoredumper/corestripper.c b/src/minicoredumper/corestripper.c
index 12f8de9..c0d6514 100644
--- a/src/minicoredumper/corestripper.c
+++ b/src/minicoredumper/corestripper.c
@@ -31,6 +31,7 @@
 #include <sys/user.h>
 #include <linux/futex.h>
 #include <elfutils/version.h>
+#include <elf.h>
 
 #include "prog_config.h"
 #include "dump_data_private.h"
@@ -3542,6 +3543,41 @@ static int add_dumplist_section(struct dump_info *di)
 }
 #endif
 
+void dump_pointed_by_registers_for_tasknr(struct dump_info *di, int tsk_nr)
+{
+	char *msg;
+	struct elf_greg_t *regs = (struct elf_greg_t *)&di->tsks[tsk_nr].pr_reg;
+	elf_greg_t region, registers[ELF_NGREG];
+
+	memcpy(registers, regs, sizeof(registers));
+
+	for (int i = 0; i < ELF_NGREG; i++) {
+		if (get_vma_pos(di, registers[i]) != NULL) {
+			region = (registers[i] & (~(PAGESZ-1))) - PAGESZ;
+			int ret;
+#if defined(__x86_64__)
+			ret = asprintf(&msg, "pointed by register 0x%llx (0x%llx - 0x%llx)", registers[i], region, region + 3*PAGESZ);
+#else
+			ret = asprintf(&msg, "pointed by register 0x%lx (0x%lx - 0x%lx)", registers[i], region, region + 3*PAGESZ);
+#endif
+			if (ret == -1) {
+				info("unable to allocate memory: %m");
+				continue;
+			}
+			dump_vma(di, region, PAGESZ, 0, msg);
+			dump_vma(di, region + PAGESZ, PAGESZ, 0, msg);
+			dump_vma(di, region + 2*PAGESZ, PAGESZ, 0, msg);
+			free(msg);
+		}
+	}
+}
+
+void dump_pointed_by_registers(struct dump_info *di)
+{
+	for (int i = 0; i < di->ntsks; i++)
+		dump_pointed_by_registers_for_tasknr(di, i);
+}
+
 static void do_dump(struct dump_info *di)
 {
 	int ret;
@@ -3600,6 +3636,9 @@ static void do_dump(struct dump_info *di)
 		get_interesting_buffers(di);
 	}
 
+	if (di->cfg->prog_config.dump_pointed_by_regs)
+		dump_pointed_by_registers(di);	
+
 	/* dump registered application data */
 	dyn_dump(di);
 
diff --git a/src/minicoredumper/minicoredumper.recept.json.5 b/src/minicoredumper/minicoredumper.recept.json.5
index 4bac92b..0d66b20 100644
--- a/src/minicoredumper/minicoredumper.recept.json.5
+++ b/src/minicoredumper/minicoredumper.recept.json.5
@@ -88,6 +88,9 @@ particularly useful if
 .BR syslog (3)
 is not available on the system.
 .TP
+.B dump_pointed_by_regs
+(boolean) Dump pages that are pointed by register values. Minicoredumper will also save one page before and one after.
+.TP
 .B dump_fat_core
 (boolean) Whether all virtual memory areas should be dumped.
 This will generate a separate "fatcore" file that is typically larger
diff --git a/src/minicoredumper/prog_config.c b/src/minicoredumper/prog_config.c
index a9b8b09..a58da3e 100644
--- a/src/minicoredumper/prog_config.c
+++ b/src/minicoredumper/prog_config.c
@@ -408,6 +408,9 @@ static int read_prog_config(struct json_object *root, struct prog_config *cfg)
 			if (get_json_boolean(v, &cfg->live_dumper) != 0)
 				return -1;
 
+		} else if (strcmp(n, "dump_pointed_by_regs") == 0) {
+			if (get_json_boolean(v, &cfg->dump_pointed_by_regs) != 0)
+				return -1;
 		} else {
 			info("WARNING: ignoring unknown config item: %s", n);
 		}
diff --git a/src/minicoredumper/prog_config.h b/src/minicoredumper/prog_config.h
index 5d77f2d..9d69153 100644
--- a/src/minicoredumper/prog_config.h
+++ b/src/minicoredumper/prog_config.h
@@ -54,6 +54,7 @@ struct prog_config {
 	bool write_debug_log;
 	bool live_dumper;
 	unsigned int dump_scope;
+	bool dump_pointed_by_regs;
 };
 
 struct config {
-- 
2.7.4




More information about the minicoredumper mailing list