From 601989c5ffe04630963b98c16ff5ea8c7ff39523 Mon Sep 17 00:00:00 2001 From: Ivan Kravets Date: Thu, 24 Oct 2019 16:56:28 +0300 Subject: [PATCH] Escape "\" char in GDB console output --- platformio/commands/debug/helpers.py | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/platformio/commands/debug/helpers.py b/platformio/commands/debug/helpers.py index 67255c46..9175d070 100644 --- a/platformio/commands/debug/helpers.py +++ b/platformio/commands/debug/helpers.py @@ -12,6 +12,7 @@ # See the License for the specific language governing permissions and # limitations under the License. +import re import sys import time from fnmatch import fnmatch @@ -30,12 +31,16 @@ class GDBBytesIO(BytesIO): # pylint: disable=too-few-public-methods STDOUT = sys.stdout + @staticmethod + def escape(text): + return re.sub(r"\\+", "\\\\", text) + def write(self, text): if "\n" in text: for line in text.strip().split("\n"): - self.STDOUT.write('~"%s\\n"\n' % line) + self.STDOUT.write('~"%s\\n"\n' % self.escape(line)) else: - self.STDOUT.write('~"%s"' % text) + self.STDOUT.write('~"%s"' % self.escape(text)) self.STDOUT.flush()