[Pdbg] [PATCH 11/11] htm: Fix dump filename

Michael Neuling mikey at neuling.org
Thu Jun 7 16:54:38 AEST 2018


Currently we always generate 0.0-htm.dump irrespective of the chip,
core and thread it's generated from.

This changes it to htm-p??-c??-t??.dump using the correct CPU being
run on.

Signed-off-by: Michael Neuling <mikey at neuling.org>
---
 libpdbg/htm.c     | 23 +++++++++--------------
 libpdbg/libpdbg.h |  2 +-
 libpdbg/target.h  |  2 +-
 src/htm.c         | 35 ++++++++++++++---------------------
 4 files changed, 25 insertions(+), 37 deletions(-)

diff --git a/libpdbg/htm.c b/libpdbg/htm.c
index da381f5811..a1975448c2 100644
--- a/libpdbg/htm.c
+++ b/libpdbg/htm.c
@@ -221,7 +221,7 @@ int htm_status(struct pdbg_target *target)
 	return htm ? htm->status(htm) : -1;
 }
 
-int htm_dump(struct pdbg_target *target, uint64_t size, const char *filename)
+int htm_dump(struct pdbg_target *target, uint64_t size, char *filename)
 {
 	struct htm *htm = check_and_convert(target);
 
@@ -834,16 +834,16 @@ static int do_htm_status(struct htm *htm)
 	return 1;
 }
 
-static int do_htm_dump(struct htm *htm, uint64_t size, const char *basename)
+static int do_htm_dump(struct htm *htm, uint64_t size, char *filename)
 {
-	char *trace_file, *dump_file;
+	char *trace_file;
 	struct htm_status status;
 	uint64_t trace[0x1000];
 	int trace_fd, dump_fd;
 	uint32_t chip_id;
 	size_t r;
 
-	if (!basename)
+	if (!filename)
 		return -1;
 
 	if (HTM_ERR(get_status(htm, &status)))
@@ -880,15 +880,10 @@ static int do_htm_dump(struct htm *htm, uint64_t size, const char *basename)
 		return -1;
 	}
 
-	if (asprintf(&dump_file, "%d.%d-%s", chip_id, htm->target.index, basename) == -1) {
-		free(trace_file);
-		close(trace_fd);
-		return -1;
-	}
-	dump_fd = open(dump_file, O_RDWR | O_CREAT, S_IRUSR | S_IWUSR);
+	dump_fd = open(filename, O_RDWR | O_CREAT, S_IRUSR | S_IWUSR);
 	if (dump_fd == -1) {
-		PR_ERROR("Failed to open %s: %m\n", dump_file);
-		free(dump_file);
+		PR_ERROR("Failed to open %s: %m\n", filename);
+		free(filename);
 		free(trace_file);
 		close(trace_fd);
 		return -1;
@@ -899,7 +894,7 @@ static int do_htm_dump(struct htm *htm, uint64_t size, const char *basename)
 		if (r == -1) {
 			PR_ERROR("Failed to read from %s: %m\n", trace_file);
 			free(trace_file);
-			free(dump_file);
+			free(filename);
 			close(trace_fd);
 			close(dump_fd);
 			return -1;
@@ -912,7 +907,7 @@ static int do_htm_dump(struct htm *htm, uint64_t size, const char *basename)
 	}
 
 	free(trace_file);
-	free(dump_file);
+	free(filename);
 	close(trace_fd);
 	close(dump_fd);
 	return 1;
diff --git a/libpdbg/libpdbg.h b/libpdbg/libpdbg.h
index c73cf21fed..c0990d928c 100644
--- a/libpdbg/libpdbg.h
+++ b/libpdbg/libpdbg.h
@@ -166,7 +166,7 @@ int htm_start(struct pdbg_target *target);
 int htm_stop(struct pdbg_target *target);
 int htm_status(struct pdbg_target *target);
 int htm_reset(struct pdbg_target *target, uint64_t *base, uint64_t *size);
-int htm_dump(struct pdbg_target *target, uint64_t size, const char *filename);
+int htm_dump(struct pdbg_target *target, uint64_t size, char *filename);
 
 int adu_getmem(struct pdbg_target *target, uint64_t addr, uint8_t *ouput, uint64_t size);
 int adu_putmem(struct pdbg_target *target, uint64_t addr, uint8_t *input, uint64_t size);
diff --git a/libpdbg/target.h b/libpdbg/target.h
index 716ba42bef..e4a3ed41f0 100644
--- a/libpdbg/target.h
+++ b/libpdbg/target.h
@@ -95,7 +95,7 @@ struct htm {
 	int (*stop)(struct htm *);
 	int (*reset)(struct htm *, uint64_t *, uint64_t *);
 	int (*status)(struct htm *);
-	int (*dump)(struct htm *, uint64_t, const char *);
+	int (*dump)(struct htm *, uint64_t, char *);
 };
 #define target_to_htm(x) container_of(x, struct htm, target)
 
diff --git a/src/htm.c b/src/htm.c
index f2fc8cfb52..e28c75ece3 100644
--- a/src/htm.c
+++ b/src/htm.c
@@ -39,8 +39,6 @@
 
 #include "main.h"
 
-#define HTM_DUMP_BASENAME "htm.dump"
-
 #define HTM_ENUM_TO_STRING(e) ((e == HTM_NEST) ? "nhtm" : "chtm")
 
 #define PR_ERROR(x, args...) \
@@ -61,23 +59,18 @@ static inline void print_htm_address(enum htm_type type,
 	printf("t%d\n", pdbg_target_index(target));
 }
 
-static char *get_htm_dump_filename(void)
+static char *get_htm_dump_filename(struct pdbg_target *target)
 {
 	char *filename;
-	int i;
+	int rc;
 
-	filename = strdup(HTM_DUMP_BASENAME);
-	if (!filename)
+	rc = asprintf(&filename, "htm-p%d-c%d-t%d.dump",
+		      pdbg_parent_index(target, "pib"),
+		      pdbg_parent_index(target, "core"),
+		      pdbg_target_index(target));
+	if (rc == -1)
 		return NULL;
 
-	i = 0;
-	while (access(filename, F_OK) == 0) {
-		free(filename);
-		if (asprintf(&filename, "%s.%d", HTM_DUMP_BASENAME, i) == -1)
-			return NULL;
-		i++;
-	}
-
 	return filename;
 }
 
@@ -192,12 +185,6 @@ static int run_dump(enum htm_type type)
 	char *filename;
 	int rc = 0;
 
-	filename = get_htm_dump_filename();
-	if (!filename)
-		return 0;
-
-	/* size = 0 will dump everything */
-	printf("Dumping HTM trace to file [chip].[#]%s\n", filename);
 	pdbg_for_each_class_target(HTM_ENUM_TO_STRING(type), target) {
 		if (!target_selected(target))
 			continue;
@@ -205,15 +192,21 @@ static int run_dump(enum htm_type type)
 		if (target_is_disabled(target))
 			continue;
 
+		filename = get_htm_dump_filename(target);
+		if (!filename)
+			return 0;
+
+		/* size = 0 will dump everything */
 		printf("Dumping HTM@");
 		print_htm_address(type, target);
+		printf("File: %s\n", filename);
 		if (htm_dump(target, 0, filename) != 1) {
 			printf("Couldn't dump HTM@");
 			print_htm_address(type, target);
 		}
 		rc++;
+		free(filename);
 	}
-	free(filename);
 
 	return rc;
 }
-- 
2.17.0



More information about the Pdbg mailing list