From 06d3d01295cfa1e22bf46caf35e6fd4e4d286607 Mon Sep 17 00:00:00 2001 From: Sean Callanan Date: Wed, 4 Jan 2012 17:36:30 +0000 Subject: Instead of blindly printing a string when eFormatCString is specified, I have made DataExtractor::Dump properly escape the string. This prevents LLDB from printing characters that confuse terminals. llvm-svn: 147536 --- lldb/source/Core/DataExtractor.cpp | 36 +++++++++++++++++++++++++++++++++--- 1 file changed, 33 insertions(+), 3 deletions(-) (limited to 'lldb/source/Core') diff --git a/lldb/source/Core/DataExtractor.cpp b/lldb/source/Core/DataExtractor.cpp index 72e2dc249c5..55e5ed22e7e 100644 --- a/lldb/source/Core/DataExtractor.cpp +++ b/lldb/source/Core/DataExtractor.cpp @@ -1577,13 +1577,43 @@ DataExtractor::Dump (Stream *s, case eFormatCString: { const char *cstr = GetCStr(&offset); - if (cstr) - s->Printf("\"%s\"", cstr); - else + + if (!cstr) { s->Printf("NULL"); offset = UINT32_MAX; } + else + { + s->PutChar('\"'); + + while (const char c = *cstr) + { + if (isprint(c)) + { + s->PutChar(c); + } + else + { + switch (c) + { + case '\033': s->Printf ("\\e"); break; + case '\a': s->Printf ("\\a"); break; + case '\b': s->Printf ("\\b"); break; + case '\f': s->Printf ("\\f"); break; + case '\n': s->Printf ("\\n"); break; + case '\r': s->Printf ("\\r"); break; + case '\t': s->Printf ("\\t"); break; + case '\v': s->Printf ("\\v"); break; + default: s->Printf ("\\x%2.2x", c); break; + } + } + + ++cstr; + } + + s->PutChar('\"'); + } } break; -- cgit v1.2.3