Escape "\" char in GDB console output

This commit is contained in:
Ivan Kravets
2019-10-24 16:56:28 +03:00
parent 234585dc97
commit 601989c5ff

View File

@ -12,6 +12,7 @@
# See the License for the specific language governing permissions and # See the License for the specific language governing permissions and
# limitations under the License. # limitations under the License.
import re
import sys import sys
import time import time
from fnmatch import fnmatch from fnmatch import fnmatch
@ -30,12 +31,16 @@ class GDBBytesIO(BytesIO): # pylint: disable=too-few-public-methods
STDOUT = sys.stdout STDOUT = sys.stdout
@staticmethod
def escape(text):
return re.sub(r"\\+", "\\\\", text)
def write(self, text): def write(self, text):
if "\n" in text: if "\n" in text:
for line in text.strip().split("\n"): for line in text.strip().split("\n"):
self.STDOUT.write('~"%s\\n"\n' % line) self.STDOUT.write('~"%s\\n"\n' % self.escape(line))
else: else:
self.STDOUT.write('~"%s"' % text) self.STDOUT.write('~"%s"' % self.escape(text))
self.STDOUT.flush() self.STDOUT.flush()