summaryrefslogtreecommitdiffstats
path: root/lldb/source/Core
diff options
context:
space:
mode:
authorSean Callanan <scallanan@apple.com>2012-01-04 17:36:30 +0000
committerSean Callanan <scallanan@apple.com>2012-01-04 17:36:30 +0000
commit06d3d01295cfa1e22bf46caf35e6fd4e4d286607 (patch)
tree147b30d9cc45e6337b1cefda5058ced29b592728 /lldb/source/Core
parentb8c6f1e950fb06131b89329f28712affb11e78ff (diff)
downloadbcm5719-llvm-06d3d01295cfa1e22bf46caf35e6fd4e4d286607.tar.gz
bcm5719-llvm-06d3d01295cfa1e22bf46caf35e6fd4e4d286607.zip
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
Diffstat (limited to 'lldb/source/Core')
-rw-r--r--lldb/source/Core/DataExtractor.cpp36
1 files changed, 33 insertions, 3 deletions
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;
OpenPOWER on IntegriCloud