From 803e9997e302a0923920c8da0fb126c48cebb3db Mon Sep 17 00:00:00 2001
From: Mitchel Humpherys <mitchelh@codeaurora.org>
Date: Fri, 27 Feb 2015 16:44:04 -0800
Subject: [PATCH] lrdpv2: roareadiff: don't print non-printable characters

The format of the roareadiff output was recently changed, in
[99a8ae9d0515: "linux-ramdump-parser-v2: Update roareadiff for arm64"].
That change introduced the possibility of printing non-printable
characters in string representations of the memory dumps.  Fix this by
outputting a `.' for non-printable characters.

Change-Id: I1efd0775fac89618f43986523c6a9207afed7e5e
---
 linux-ramdump-parser-v2/parsers/roareadiff.py | 9 ++++++---
 1 file changed, 6 insertions(+), 3 deletions(-)

diff --git a/linux-ramdump-parser-v2/parsers/roareadiff.py b/linux-ramdump-parser-v2/parsers/roareadiff.py
index 77634ef..49df71e 100644
--- a/linux-ramdump-parser-v2/parsers/roareadiff.py
+++ b/linux-ramdump-parser-v2/parsers/roareadiff.py
@@ -1,4 +1,4 @@
-# Copyright (c) 2013-2014, The Linux Foundation. All rights reserved.
+# Copyright (c) 2013-2015, The Linux Foundation. All rights reserved.
 #
 # This program is free software; you can redistribute it and/or modify
 # it under the terms of the GNU General Public License version 2 and
@@ -10,6 +10,7 @@
 # GNU General Public License for more details.
 
 import struct
+import string
 
 from print_out import print_out_str
 from collections import namedtuple
@@ -126,8 +127,10 @@ class ROData(RamParser):
                                     ddr_str += '{0:0>8x}'.format(ram_value)
                                     vmlinux_str += '{0:0>8x}'.format(vm_value)
                                     for j in range(4):
-                                        ddr_ascii += '{0:c}'.format(struct.unpack('B', ram_values[i + j])[0]).rstrip()
-                                        vm_ascii += '{0:c}'.format(struct.unpack('B', vm_values[i + j])[0]).rstrip()
+                                        c = '{0:c}'.format(struct.unpack('B', ram_values[i + j])[0]).rstrip()
+                                        ddr_ascii += c if c in string.printable else '.'
+                                        c = '{0:c}'.format(struct.unpack('B', vm_values[i + j])[0]).rstrip()
+                                        vm_ascii += c if c in string.printable else '.'
                                     detect += 1
                                 i = i + 4
                             if detect != 0xFFFFFFFF:
-- 
GitLab