symbolize.py: disable terminal local echo

When scripts/symbolize.py is used interactively and the input data is
copied and pasted into the terminal, both the input and output text are
displayed on the same screen. There is nothing preventing both text
streams from mixing up because it depends on buffering and how Python
reads and flushes its buffers.

Things usually go well with Python 2, but I have observed that Python 3
is more problematic. So the issue needs to be properly addressed. This
patch temporarily disables local echo so that only the processed text is
shown.

Signed-off-by: Jerome Forissier <jerome@forissier.org>
Reviewed-by: Rouven Czerwinski <r.czerwinski@pengutronix.de>
Acked-by: Jens Wiklander <jens.wiklander@linaro.org>
diff --git a/scripts/symbolize.py b/scripts/symbolize.py
index 48ba1c0..b61202d 100755
--- a/scripts/symbolize.py
+++ b/scripts/symbolize.py
@@ -12,6 +12,7 @@
 import re
 import subprocess
 import sys
+import termios
 
 CALL_STACK_RE = re.compile('Call stack:')
 # This gets the address from lines looking like this:
@@ -479,9 +480,17 @@
         args.dirs = []
     symbolizer = Symbolizer(sys.stdout, args.dirs, args.strip_path)
 
-    for line in sys.stdin:
-        symbolizer.write(line)
-    symbolizer.flush()
+    fd = sys.stdin.fileno()
+    old = termios.tcgetattr(fd)
+    new = termios.tcgetattr(fd)
+    new[3] = new[3] & ~termios.ECHO  # lflags
+    try:
+        termios.tcsetattr(fd, termios.TCSADRAIN, new)
+        for line in sys.stdin:
+            symbolizer.write(line)
+    finally:
+        symbolizer.flush()
+        termios.tcsetattr(fd, termios.TCSADRAIN, old)
 
 
 if __name__ == "__main__":