@@ -21,6 +21,7 @@
#include <unistd.h>
#include <assert.h>
#include <stdbool.h>
+#include <ctype.h>
#include <libpdbg.h>
@@ -28,6 +29,7 @@
#include "progress.h"
#include "optcmd.h"
#include "parsers.h"
+#include "util.h"
#define PR_ERROR(x, args...) \
pdbg_log(PDBG_ERROR, x, ##args)
@@ -75,8 +77,22 @@ static int _getmem(uint64_t addr, uint64_t size, uint8_t block_size, bool ci)
}
if (count > 0) {
- if (write(STDOUT_FILENO, buf, size) < 0)
- PR_ERROR("Unable to write stdout.\n");
+ uint64_t i;
+ bool printable = true;
+
+ for (i=0; i<size; i++) {
+ if (!isprint(buf[i])) {
+ printable = false;
+ break;
+ }
+ }
+
+ if (isatty(STDOUT_FILENO) && !printable) {
+ hexdump(addr, buf, size, 1);
+ } else {
+ if (write(STDOUT_FILENO, buf, size) < 0)
+ PR_ERROR("Unable to write stdout.\n");
+ }
}
free(buf);
If getmem is being run on a terminal and if the output contains non-printable characters, then use hexdump() to dump the data. Signed-off-by: Amitay Isaacs <amitay@ozlabs.org> --- src/mem.c | 20 ++++++++++++++++++-- 1 file changed, 18 insertions(+), 2 deletions(-)