[Lldb-commits] [lldb] r252018 - Fix an issue where LLDB would truncate summaries for string types without producing any evidence thereof
Enrico Granata via lldb-commits
lldb-commits at lists.llvm.org
Tue Nov 3 16:02:09 PST 2015
Author: enrico
Date: Tue Nov 3 18:02:08 2015
New Revision: 252018
URL: http://llvm.org/viewvc/llvm-project?rev=252018&view=rev
Log:
Fix an issue where LLDB would truncate summaries for string types without producing any evidence thereof
Modified:
lldb/trunk/include/lldb/Core/ValueObject.h
lldb/trunk/include/lldb/DataFormatters/StringPrinter.h
lldb/trunk/packages/Python/lldbsuite/test/functionalities/data-formatter/stringprinter/main.cpp
lldb/trunk/source/Core/ValueObject.cpp
lldb/trunk/source/DataFormatters/StringPrinter.cpp
lldb/trunk/source/Plugins/Language/CPlusPlus/LibCxx.cpp
lldb/trunk/source/Target/Process.cpp
Modified: lldb/trunk/include/lldb/Core/ValueObject.h
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/include/lldb/Core/ValueObject.h?rev=252018&r1=252017&r2=252018&view=diff
==============================================================================
--- lldb/trunk/include/lldb/Core/ValueObject.h (original)
+++ lldb/trunk/include/lldb/Core/ValueObject.h Tue Nov 3 18:02:08 2015
@@ -840,7 +840,7 @@ public:
bool
IsCStringContainer (bool check_pointer = false);
- size_t
+ std::pair<size_t,bool>
ReadPointedString (lldb::DataBufferSP& buffer_sp,
Error& error,
uint32_t max_length = 0,
Modified: lldb/trunk/include/lldb/DataFormatters/StringPrinter.h
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/include/lldb/DataFormatters/StringPrinter.h?rev=252018&r1=252017&r2=252018&view=diff
==============================================================================
--- lldb/trunk/include/lldb/DataFormatters/StringPrinter.h (original)
+++ lldb/trunk/include/lldb/DataFormatters/StringPrinter.h Tue Nov 3 18:02:08 2015
@@ -260,6 +260,7 @@ namespace lldb_private {
m_source_size(0),
m_escape_non_printables(true),
m_zero_is_terminator(true),
+ m_is_truncated(false),
m_language_type(lldb::eLanguageTypeUnknown)
{
}
@@ -387,6 +388,19 @@ namespace lldb_private {
}
ReadBufferAndDumpToStreamOptions&
+ SetIsTruncated (bool t)
+ {
+ m_is_truncated = t;
+ return *this;
+ }
+
+ bool
+ GetIsTruncated () const
+ {
+ return m_is_truncated;
+ }
+
+ ReadBufferAndDumpToStreamOptions&
SetLanguage (lldb::LanguageType l)
{
m_language_type = l;
@@ -409,6 +423,7 @@ namespace lldb_private {
uint32_t m_source_size;
bool m_escape_non_printables;
bool m_zero_is_terminator;
+ bool m_is_truncated;
lldb::LanguageType m_language_type;
};
Modified: lldb/trunk/packages/Python/lldbsuite/test/functionalities/data-formatter/stringprinter/main.cpp
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/packages/Python/lldbsuite/test/functionalities/data-formatter/stringprinter/main.cpp?rev=252018&r1=252017&r2=252018&view=diff
==============================================================================
--- lldb/trunk/packages/Python/lldbsuite/test/functionalities/data-formatter/stringprinter/main.cpp (original)
+++ lldb/trunk/packages/Python/lldbsuite/test/functionalities/data-formatter/stringprinter/main.cpp Tue Nov 3 18:02:08 2015
@@ -13,9 +13,28 @@ int main (int argc, char const *argv[])
{
std::string stdstring("Hello\t\tWorld\nI am here\t\tto say hello\n"); //%self.addTearDownHook(lambda x: x.runCmd("setting set escape-non-printables true"))
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"')
+ std::string longstring(
+"I am a very long string; in fact I am longer than any reasonable length that a string should be; quite long indeed; oh my, so many words; so many letters; this is kind of like writing a poem; except in real life all that is happening"
+" is just me producing a very very long set of words; there is text here, text there, text everywhere; it fills me with glee to see so much text; all around me it's just letters, and symbols, and other pleasant drawings that cause me"
+" a large amount of joy upon visually seeing them with my eyes; well, this is now a lot of letters, but it is still not enough for the purpose of the test I want to test, so maybe I should copy and paste this a few times, you know.."
+" for science, or something"
+ "I am a very long string; in fact I am longer than any reasonable length that a string should be; quite long indeed; oh my, so many words; so many letters; this is kind of like writing a poem; except in real life all that is happening"
+ " is just me producing a very very long set of words; there is text here, text there, text everywhere; it fills me with glee to see so much text; all around me it's just letters, and symbols, and other pleasant drawings that cause me"
+ " a large amount of joy upon visually seeing them with my eyes; well, this is now a lot of letters, but it is still not enough for the purpose of the test I want to test, so maybe I should copy and paste this a few times, you know.."
+ " for science, or something"
+ "I am a very long string; in fact I am longer than any reasonable length that a string should be; quite long indeed; oh my, so many words; so many letters; this is kind of like writing a poem; except in real life all that is happening"
+ " is just me producing a very very long set of words; there is text here, text there, text everywhere; it fills me with glee to see so much text; all around me it's just letters, and symbols, and other pleasant drawings that cause me"
+ " a large amount of joy upon visually seeing them with my eyes; well, this is now a lot of letters, but it is still not enough for the purpose of the test I want to test, so maybe I should copy and paste this a few times, you know.."
+ " for science, or something"
+ );
+ const char* longconstcharstar = longstring.c_str();
+ return 0; //% if self.TraceOn(): self.runCmd('frame variable')
+ //% 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")
//% 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.assertTrue(self.frame().FindVariable('longstring').GetSummary().endswith('"...'))
+ //% self.assertTrue(self.frame().FindVariable('longconstcharstar').GetSummary().endswith('"...'))
}
+
Modified: lldb/trunk/source/Core/ValueObject.cpp
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Core/ValueObject.cpp?rev=252018&r1=252017&r2=252018&view=diff
==============================================================================
--- lldb/trunk/source/Core/ValueObject.cpp (original)
+++ lldb/trunk/source/Core/ValueObject.cpp Tue Nov 3 18:02:08 2015
@@ -1255,13 +1255,14 @@ CopyStringDataToBufferSP(const StreamStr
return true;
}
-size_t
+std::pair<size_t,bool>
ValueObject::ReadPointedString (lldb::DataBufferSP& buffer_sp,
Error& error,
uint32_t max_length,
bool honor_array,
Format item_format)
{
+ bool was_capped = false;
StreamString s;
ExecutionContext exe_ctx (GetExecutionContextRef());
Target* target = exe_ctx.GetTargetPtr();
@@ -1271,7 +1272,7 @@ ValueObject::ReadPointedString (lldb::Da
s << "<no target to read from>";
error.SetErrorString("no target to read from");
CopyStringDataToBufferSP(s, buffer_sp);
- return 0;
+ return {0,was_capped};
}
if (max_length == 0)
@@ -1317,7 +1318,7 @@ ValueObject::ReadPointedString (lldb::Da
s << "<invalid address>";
error.SetErrorString("invalid address");
CopyStringDataToBufferSP(s, buffer_sp);
- return 0;
+ return {0,was_capped};
}
Address cstr_so_addr (cstr_address);
@@ -1334,7 +1335,7 @@ ValueObject::ReadPointedString (lldb::Da
for (size_t offset = 0; offset < bytes_read; offset++)
s.Printf("%c", *data.PeekData(offset, 1));
if (capped_data)
- s << "...";
+ was_capped = true;
}
}
else
@@ -1386,7 +1387,7 @@ ValueObject::ReadPointedString (lldb::Da
if (cstr_len_displayed >= 0)
{
if (capped_cstr)
- s << "...";
+ was_capped = true;
}
}
}
@@ -1396,7 +1397,7 @@ ValueObject::ReadPointedString (lldb::Da
s << "<not a string object>";
}
CopyStringDataToBufferSP(s, buffer_sp);
- return total_bytes_read;
+ return {total_bytes_read,was_capped};
}
std::pair<TypeValidatorResult, std::string>
@@ -1644,17 +1645,18 @@ ValueObject::DumpPrintableRepresentation
{
Error error;
lldb::DataBufferSP buffer_sp;
- ReadPointedString(buffer_sp,
- error,
- 0,
- (custom_format == eFormatVectorOfChar) ||
- (custom_format == eFormatCharArray));
+ std::pair<size_t, bool> read_string = ReadPointedString(buffer_sp,
+ error,
+ 0,
+ (custom_format == eFormatVectorOfChar) ||
+ (custom_format == eFormatCharArray));
lldb_private::formatters::StringPrinter::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.SetIsTruncated(read_string.second);
formatters::StringPrinter::ReadBufferAndDumpToStream<lldb_private::formatters::StringPrinter::StringElementType::ASCII>(options);
return !error.Fail();
}
Modified: lldb/trunk/source/DataFormatters/StringPrinter.cpp
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/DataFormatters/StringPrinter.cpp?rev=252018&r1=252017&r2=252018&view=diff
==============================================================================
--- lldb/trunk/source/DataFormatters/StringPrinter.cpp (original)
+++ lldb/trunk/source/DataFormatters/StringPrinter.cpp Tue Nov 3 18:02:08 2015
@@ -374,6 +374,8 @@ DumpUTFBufferToStream (ConversionResult
stream.Printf("%c",dump_options.GetQuote());
if (dump_options.GetSuffixToken() != 0)
stream.Printf("%s",dump_options.GetSuffixToken());
+ if (dump_options.GetIsTruncated())
+ stream.Printf("...");
return true;
}
@@ -421,11 +423,20 @@ StringPrinter::ReadStringAndDumpToStream
return false;
size_t size;
+ const auto max_size = process_sp->GetTarget().GetMaximumSizeOfStringSummary();
+ bool is_truncated = false;
if (options.GetSourceSize() == 0)
- size = process_sp->GetTarget().GetMaximumSizeOfStringSummary();
+ size = max_size;
else if (!options.GetIgnoreMaxLength())
- size = std::min(options.GetSourceSize(),process_sp->GetTarget().GetMaximumSizeOfStringSummary());
+ {
+ size = options.GetSourceSize();
+ if (size > max_size)
+ {
+ size = max_size;
+ is_truncated = true;
+ }
+ }
else
size = options.GetSourceSize();
@@ -492,6 +503,9 @@ StringPrinter::ReadStringAndDumpToStream
else if (quote != 0)
options.GetStream()->Printf("%c",quote);
+ if (is_truncated)
+ options.GetStream()->Printf("...");
+
return true;
}
@@ -527,14 +541,23 @@ ReadUTFBufferAndDumpToStream (const Stri
uint32_t sourceSize = options.GetSourceSize();
bool needs_zero_terminator = options.GetNeedsZeroTermination();
+
+ bool is_truncated = false;
+ const auto max_size = process_sp->GetTarget().GetMaximumSizeOfStringSummary();
if (!sourceSize)
{
- sourceSize = process_sp->GetTarget().GetMaximumSizeOfStringSummary();
+ sourceSize = max_size;
needs_zero_terminator = true;
}
else if (!options.GetIgnoreMaxLength())
- sourceSize = std::min(sourceSize,process_sp->GetTarget().GetMaximumSizeOfStringSummary());
+ {
+ if (sourceSize > max_size)
+ {
+ sourceSize = max_size;
+ is_truncated = true;
+ }
+ }
const int bufferSPSize = sourceSize * type_width;
@@ -562,6 +585,7 @@ ReadUTFBufferAndDumpToStream (const Stri
StringPrinter::ReadBufferAndDumpToStreamOptions dump_options(options);
dump_options.SetData(data);
dump_options.SetSourceSize(sourceSize);
+ dump_options.SetIsTruncated(is_truncated);
return DumpUTFBufferToStream(ConvertFunction, dump_options);
}
Modified: lldb/trunk/source/Plugins/Language/CPlusPlus/LibCxx.cpp
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Plugins/Language/CPlusPlus/LibCxx.cpp?rev=252018&r1=252017&r2=252018&view=diff
==============================================================================
--- lldb/trunk/source/Plugins/Language/CPlusPlus/LibCxx.cpp (original)
+++ lldb/trunk/source/Plugins/Language/CPlusPlus/LibCxx.cpp Tue Nov 3 18:02:08 2015
@@ -563,14 +563,23 @@ lldb_private::formatters::LibcxxWStringS
return false;
DataExtractor extractor;
+
+ StringPrinter::ReadBufferAndDumpToStreamOptions options(valobj);
+
if (summary_options.GetCapping() == TypeSummaryCapping::eTypeSummaryCapped)
- size = std::min<decltype(size)>(size, valobj.GetTargetSP()->GetMaximumSizeOfStringSummary());
+ {
+ const auto max_size = valobj.GetTargetSP()->GetMaximumSizeOfStringSummary();
+ if (size > max_size)
+ {
+ size = max_size;
+ options.SetIsTruncated(true);
+ }
+ }
location_sp->GetPointeeData(extractor, 0, size);
// std::wstring::size() is measured in 'characters', not bytes
auto wchar_t_size = valobj.GetTargetSP()->GetScratchClangASTContext()->GetBasicType(lldb::eBasicTypeWChar).GetByteSize(nullptr);
- StringPrinter::ReadBufferAndDumpToStreamOptions options(valobj);
options.SetData(extractor);
options.SetStream(&stream);
options.SetPrefixToken("L");
@@ -618,12 +627,20 @@ lldb_private::formatters::LibcxxStringSu
if (!location_sp)
return false;
+ StringPrinter::ReadBufferAndDumpToStreamOptions options(valobj);
+
DataExtractor extractor;
if (summary_options.GetCapping() == TypeSummaryCapping::eTypeSummaryCapped)
- size = std::min<decltype(size)>(size, valobj.GetTargetSP()->GetMaximumSizeOfStringSummary());
+ {
+ const auto max_size = valobj.GetTargetSP()->GetMaximumSizeOfStringSummary();
+ if (size > max_size)
+ {
+ size = max_size;
+ options.SetIsTruncated(true);
+ }
+ }
location_sp->GetPointeeData(extractor, 0, size);
- StringPrinter::ReadBufferAndDumpToStreamOptions options(valobj);
options.SetData(extractor);
options.SetStream(&stream);
options.SetPrefixToken(0);
Modified: lldb/trunk/source/Target/Process.cpp
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Target/Process.cpp?rev=252018&r1=252017&r2=252018&view=diff
==============================================================================
--- lldb/trunk/source/Target/Process.cpp (original)
+++ lldb/trunk/source/Target/Process.cpp Tue Nov 3 18:02:08 2015
@@ -1960,7 +1960,7 @@ Process::LoadImage (const FileSpec &imag
if (error_str_sp->IsCStringContainer(true))
{
DataBufferSP buffer_sp(new DataBufferHeap(10240,0));
- size_t num_chars = error_str_sp->ReadPointedString (buffer_sp, error, 10240);
+ size_t num_chars = error_str_sp->ReadPointedString (buffer_sp, error, 10240).first;
if (error.Success() && num_chars > 0)
{
error.Clear();
More information about the lldb-commits
mailing list