[Pdbg] [PATCH 2/2] main: Dump memory on terminal from getmem

Amitay Isaacs amitay at ozlabs.org
Thu Feb 21 11:08:51 AEDT 2019


Signed-off-by: Amitay Isaacs <amitay at ozlabs.org>
---
 src/mem.c | 12 +++++++++---
 1 file changed, 9 insertions(+), 3 deletions(-)

diff --git a/src/mem.c b/src/mem.c
index 6454739..53bf39e 100644
--- a/src/mem.c
+++ b/src/mem.c
@@ -28,6 +28,7 @@
 #include "progress.h"
 #include "optcmd.h"
 #include "parsers.h"
+#include "util.h"
 
 #define PR_ERROR(x, args...) \
 	pdbg_log(PDBG_ERROR, x, ##args)
@@ -68,10 +69,15 @@ static int _getmem(uint64_t addr, uint64_t size, uint8_t block_size)
 		if (rc)
 			PR_ERROR("Unable to read memory.\n");
 
-		if (write(STDOUT_FILENO, buf, size) < 0)
-			PR_ERROR("Unable to write stdout.\n");
-		else
+		if (isatty(STDOUT_FILENO)) {
+			hexdump(addr, buf, size, 1);
+			rc++;
+		} else {
+			if (write(STDOUT_FILENO, buf, size) < 0)
+				PR_ERROR("Unable to write stdout.\n");
+			else
 				rc++;
+		}
 
 		progress_end();
 		break;
-- 
2.20.1



More information about the Pdbg mailing list