Add a setting escape-non-printables that drives whether the StringPrinter should or should not escape sequences such as \t, \n, .. and generally any non-printing character

The recent StringPrinter changes made this behavior the default, and the setting defaults to yes
If you want to change this behavior and see non-printables unescaped (e.g. "a\tb" as "a    b"), set it to false

Fixes rdar://12969594

llvm-svn: 221399
This commit is contained in:
Enrico Granata
2014-11-05 21:20:48 +00:00
parent d4bc0bf3a3
commit ebdc1ac014
8 changed files with 77 additions and 18 deletions

View File

@@ -347,6 +347,9 @@ public:
bool
GetAutoOneLineSummaries () const;
bool
GetEscapeNonPrintables () const;
bool
GetNotifyVoid () const;

View File

@@ -41,6 +41,8 @@ namespace lldb_private {
{
}
ReadStringAndDumpToStreamOptions (ValueObject& valobj);
ReadStringAndDumpToStreamOptions&
SetLocation (uint64_t l)
{
@@ -170,6 +172,8 @@ namespace lldb_private {
{
}
ReadBufferAndDumpToStreamOptions (ValueObject& valobj);
ReadBufferAndDumpToStreamOptions&
SetData (DataExtractor d)
{

View File

@@ -144,7 +144,8 @@ g_properties[] =
{ "thread-format", OptionValue::eTypeString , true, 0 , DEFAULT_THREAD_FORMAT, NULL, "The default thread format string to use when displaying thread information." },
{ "use-external-editor", OptionValue::eTypeBoolean, true, false, NULL, NULL, "Whether to use an external editor or not." },
{ "use-color", OptionValue::eTypeBoolean, true, true , NULL, NULL, "Whether to use Ansi color codes or not." },
{ "auto-one-line-summaries", OptionValue::eTypeBoolean, true, true, NULL, NULL, "If true, LLDB will automatically display small structs in one-liner format (default: true)." },
{ "auto-one-line-summaries", OptionValue::eTypeBoolean, true, true, NULL, NULL, "If true, LLDB will automatically display small structs in one-liner format (default: true)." },
{ "escape-non-printables", OptionValue::eTypeBoolean, true, true, NULL, NULL, "If true, LLDB will automatically escape non-printable and escape characters when formatting strings." },
{ NULL, OptionValue::eTypeInvalid, true, 0 , NULL, NULL, NULL }
};
@@ -165,7 +166,8 @@ enum
ePropertyThreadFormat,
ePropertyUseExternalEditor,
ePropertyUseColor,
ePropertyAutoOneLineSummaries
ePropertyAutoOneLineSummaries,
ePropertyEscapeNonPrintables
};
Debugger::LoadPluginCallbackType Debugger::g_load_plugin_callback = NULL;
@@ -177,6 +179,7 @@ Debugger::SetPropertyValue (const ExecutionContext *exe_ctx,
const char *value)
{
bool is_load_script = strcmp(property_path,"target.load-script-from-symbol-file") == 0;
bool is_escape_non_printables = strcmp(property_path, "escape-non-printables") == 0;
TargetSP target_sp;
LoadScriptFromSymFile load_script_old_value;
if (is_load_script && exe_ctx->GetTargetSP())
@@ -224,6 +227,10 @@ Debugger::SetPropertyValue (const ExecutionContext *exe_ctx,
}
}
}
else if (is_escape_non_printables)
{
DataVisualization::ForceUpdate();
}
}
return error;
}
@@ -366,7 +373,13 @@ Debugger::GetAutoOneLineSummaries () const
{
const uint32_t idx = ePropertyAutoOneLineSummaries;
return m_collection_sp->GetPropertyAtIndexAsBoolean (NULL, idx, true);
}
bool
Debugger::GetEscapeNonPrintables () const
{
const uint32_t idx = ePropertyEscapeNonPrintables;
return m_collection_sp->GetPropertyAtIndexAsBoolean (NULL, idx, true);
}
#pragma mark Debugger

View File

@@ -1591,13 +1591,12 @@ ValueObject::DumpPrintableRepresentation(Stream& s,
0,
(custom_format == eFormatVectorOfChar) ||
(custom_format == eFormatCharArray));
lldb_private::formatters::ReadBufferAndDumpToStreamOptions options;
lldb_private::formatters::ReadBufferAndDumpToStreamOptions options(*this);
options.SetData(DataExtractor(buffer_sp, lldb::eByteOrderInvalid, 8)); // none of this matters for a string - pass some defaults
options.SetStream(&s);
options.SetPrefixToken(0);
options.SetQuote('"');
options.SetSourceSize(buffer_sp->GetByteSize());
options.SetEscapeNonPrintables(true);
lldb_private::formatters::ReadBufferAndDumpToStream<lldb_private::formatters::StringElementType::ASCII>(options);
return !error.Fail();
}

View File

@@ -202,7 +202,7 @@ lldb_private::formatters::Char16StringSummaryProvider (ValueObject& valobj, Stre
if (!valobj_addr)
return false;
ReadStringAndDumpToStreamOptions options;
ReadStringAndDumpToStreamOptions options(valobj);
options.SetLocation(valobj_addr);
options.SetProcessSP(process_sp);
options.SetStream(&stream);
@@ -229,7 +229,7 @@ lldb_private::formatters::Char32StringSummaryProvider (ValueObject& valobj, Stre
if (!valobj_addr)
return false;
ReadStringAndDumpToStreamOptions options;
ReadStringAndDumpToStreamOptions options(valobj);
options.SetLocation(valobj_addr);
options.SetProcessSP(process_sp);
options.SetStream(&stream);
@@ -269,7 +269,7 @@ lldb_private::formatters::WCharStringSummaryProvider (ValueObject& valobj, Strea
ClangASTType wchar_clang_type = ClangASTContext::GetBasicType(ast, lldb::eBasicTypeWChar);
const uint32_t wchar_size = wchar_clang_type.GetBitSize();
ReadStringAndDumpToStreamOptions options;
ReadStringAndDumpToStreamOptions options(valobj);
options.SetLocation(data_addr);
options.SetProcessSP(process_sp);
options.SetStream(&stream);
@@ -305,7 +305,7 @@ lldb_private::formatters::Char16SummaryProvider (ValueObject& valobj, Stream& st
if (!value.empty())
stream.Printf("%s ", value.c_str());
ReadBufferAndDumpToStreamOptions options;
ReadBufferAndDumpToStreamOptions options(valobj);
options.SetData(data);
options.SetStream(&stream);
options.SetPrefixToken('u');
@@ -330,7 +330,7 @@ lldb_private::formatters::Char32SummaryProvider (ValueObject& valobj, Stream& st
if (!value.empty())
stream.Printf("%s ", value.c_str());
ReadBufferAndDumpToStreamOptions options;
ReadBufferAndDumpToStreamOptions options(valobj);
options.SetData(data);
options.SetStream(&stream);
options.SetPrefixToken('U');
@@ -350,7 +350,7 @@ lldb_private::formatters::WCharSummaryProvider (ValueObject& valobj, Stream& str
if (error.Fail())
return false;
ReadBufferAndDumpToStreamOptions options;
ReadBufferAndDumpToStreamOptions options(valobj);
options.SetData(data);
options.SetStream(&stream);
options.SetPrefixToken('L');
@@ -481,13 +481,12 @@ lldb_private::formatters::LibcxxStringSummaryProvider (ValueObject& valobj, Stre
size = std::min<decltype(size)>(size, valobj.GetTargetSP()->GetMaximumSizeOfStringSummary());
location_sp->GetPointeeData(extractor, 0, size);
lldb_private::formatters::ReadBufferAndDumpToStreamOptions options;
ReadBufferAndDumpToStreamOptions options(valobj);
options.SetData(extractor); // none of this matters for a string - pass some defaults
options.SetStream(&stream);
options.SetPrefixToken(0);
options.SetQuote('"');
options.SetSourceSize(size);
options.SetEscapeNonPrintables(true);
lldb_private::formatters::ReadBufferAndDumpToStream<lldb_private::formatters::StringElementType::ASCII>(options);
return true;
@@ -836,7 +835,7 @@ lldb_private::formatters::NSStringSummaryProvider (ValueObject& valobj, Stream&
return false;
if (has_explicit_length && is_unicode)
{
ReadStringAndDumpToStreamOptions options;
ReadStringAndDumpToStreamOptions options(valobj);
options.SetLocation(location);
options.SetProcessSP(process_sp);
options.SetStream(&stream);
@@ -848,7 +847,7 @@ lldb_private::formatters::NSStringSummaryProvider (ValueObject& valobj, Stream&
}
else
{
ReadStringAndDumpToStreamOptions options;
ReadStringAndDumpToStreamOptions options(valobj);
options.SetLocation(location+1);
options.SetProcessSP(process_sp);
options.SetStream(&stream);
@@ -883,7 +882,7 @@ lldb_private::formatters::NSStringSummaryProvider (ValueObject& valobj, Stream&
if (error.Fail())
return false;
}
ReadStringAndDumpToStreamOptions options;
ReadStringAndDumpToStreamOptions options(valobj);
options.SetLocation(location);
options.SetProcessSP(process_sp);
options.SetStream(&stream);
@@ -899,7 +898,7 @@ lldb_private::formatters::NSStringSummaryProvider (ValueObject& valobj, Stream&
explicit_length = reader.GetField<uint32_t>(ConstString("lengthAndRef")) >> 20;
lldb::addr_t location = valobj.GetValueAsUnsigned(0) + ptr_size + 4;
ReadStringAndDumpToStreamOptions options;
ReadStringAndDumpToStreamOptions options(valobj);
options.SetLocation(location);
options.SetProcessSP(process_sp);
options.SetStream(&stream);
@@ -914,7 +913,7 @@ lldb_private::formatters::NSStringSummaryProvider (ValueObject& valobj, Stream&
uint64_t location = valobj_addr + 2*ptr_size;
if (!has_explicit_length)
location++;
ReadStringAndDumpToStreamOptions options;
ReadStringAndDumpToStreamOptions options(valobj);
options.SetLocation(location);
options.SetProcessSP(process_sp);
options.SetStream(&stream);
@@ -930,7 +929,7 @@ lldb_private::formatters::NSStringSummaryProvider (ValueObject& valobj, Stream&
return false;
if (has_explicit_length && !has_null)
explicit_length++; // account for the fact that there is no NULL and we need to have one added
ReadStringAndDumpToStreamOptions options;
ReadStringAndDumpToStreamOptions options(valobj);
options.SetLocation(location);
options.SetProcessSP(process_sp);
options.SetPrefixToken('@');

View File

@@ -10,7 +10,9 @@
#include "lldb/DataFormatters/StringPrinter.h"
#include "lldb/Core/DataExtractor.h"
#include "lldb/Core/Debugger.h"
#include "lldb/Core/Error.h"
#include "lldb/Core/ValueObject.h"
#include "lldb/Target/Process.h"
#include "lldb/Target/Target.h"
@@ -416,6 +418,19 @@ DumpUTFBufferToStream (ConversionResult (*ConvertFunction) (const SourceDataType
return true;
}
lldb_private::formatters::ReadStringAndDumpToStreamOptions::ReadStringAndDumpToStreamOptions (ValueObject& valobj) :
ReadStringAndDumpToStreamOptions()
{
SetEscapeNonPrintables(valobj.GetTargetSP()->GetDebugger().GetEscapeNonPrintables());
}
lldb_private::formatters::ReadBufferAndDumpToStreamOptions::ReadBufferAndDumpToStreamOptions (ValueObject& valobj) :
ReadBufferAndDumpToStreamOptions()
{
SetEscapeNonPrintables(valobj.GetTargetSP()->GetDebugger().GetEscapeNonPrintables());
}
namespace lldb_private
{

View File

@@ -0,0 +1,3 @@
import lldbinline
lldbinline.MakeInlineTest(__file__, globals())

View File

@@ -0,0 +1,23 @@
//===-- main.cpp ------------------------------------------------*- C++ -*-===//
//
// The LLVM Compiler Infrastructure
//
// This file is distributed under the University of Illinois Open Source
// License. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
#include <string>
int main (int argc, char const *argv[])
{
std::string stdstring("Hello\t\tWorld\nI am here\t\tto say hello\n");
const char* constcharstar = stdstring.c_str();
return 0; //% self.assertTrue(self.frame().FindVariable('stdstring').GetSummary() == '"Hello\\t\\tWorld\\nI am here\\t\\tto say hello\\n"')
//% self.assertTrue(self.frame().FindVariable('constcharstar').GetSummary() == '"Hello\\t\\tWorld\\nI am here\\t\\tto say hello\\n"')
//% self.runCmd("setting set escape-non-printables false")
//% print self.frame().FindVariable('stdstring').GetSummary()
//% self.assertTrue(self.frame().FindVariable('stdstring').GetSummary() == '"Hello\t\tWorld\nI am here\t\tto say hello\n"')
//% self.assertTrue(self.frame().FindVariable('constcharstar').GetSummary() == '"Hello\t\tWorld\nI am here\t\tto say hello\n"')
//% self.runCmd("setting set escape-non-printables true")
}