diff options
-rw-r--r-- | lldb/include/lldb/Core/ValueObject.h | 2 | ||||
-rw-r--r-- | lldb/include/lldb/DataFormatters/StringPrinter.h | 15 | ||||
-rw-r--r-- | lldb/packages/Python/lldbsuite/test/functionalities/data-formatter/stringprinter/main.cpp | 21 | ||||
-rw-r--r-- | lldb/source/Core/ValueObject.cpp | 24 | ||||
-rw-r--r-- | lldb/source/DataFormatters/StringPrinter.cpp | 32 | ||||
-rw-r--r-- | lldb/source/Plugins/Language/CPlusPlus/LibCxx.cpp | 25 | ||||
-rw-r--r-- | lldb/source/Target/Process.cpp | 2 |
7 files changed, 99 insertions, 22 deletions
diff --git a/lldb/include/lldb/Core/ValueObject.h b/lldb/include/lldb/Core/ValueObject.h index 605118814e1..c63947a4927 100644 --- a/lldb/include/lldb/Core/ValueObject.h +++ b/lldb/include/lldb/Core/ValueObject.h @@ -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, diff --git a/lldb/include/lldb/DataFormatters/StringPrinter.h b/lldb/include/lldb/DataFormatters/StringPrinter.h index 1e45a7e83cc..a849c4e0110 100644 --- a/lldb/include/lldb/DataFormatters/StringPrinter.h +++ b/lldb/include/lldb/DataFormatters/StringPrinter.h @@ -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; }; diff --git a/lldb/packages/Python/lldbsuite/test/functionalities/data-formatter/stringprinter/main.cpp b/lldb/packages/Python/lldbsuite/test/functionalities/data-formatter/stringprinter/main.cpp index e30e8fb37f9..4a449e9716c 100644 --- a/lldb/packages/Python/lldbsuite/test/functionalities/data-formatter/stringprinter/main.cpp +++ b/lldb/packages/Python/lldbsuite/test/functionalities/data-formatter/stringprinter/main.cpp @@ -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('"...')) } + diff --git a/lldb/source/Core/ValueObject.cpp b/lldb/source/Core/ValueObject.cpp index cf9dd776c6b..15c34b47b3a 100644 --- a/lldb/source/Core/ValueObject.cpp +++ b/lldb/source/Core/ValueObject.cpp @@ -1255,13 +1255,14 @@ CopyStringDataToBufferSP(const StreamString& source, 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::DataBufferSP& buffer_sp, 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::DataBufferSP& buffer_sp, 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::DataBufferSP& buffer_sp, 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::DataBufferSP& buffer_sp, if (cstr_len_displayed >= 0) { if (capped_cstr) - s << "..."; + was_capped = true; } } } @@ -1396,7 +1397,7 @@ ValueObject::ReadPointedString (lldb::DataBufferSP& buffer_sp, 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(Stream& s, { 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(); } diff --git a/lldb/source/DataFormatters/StringPrinter.cpp b/lldb/source/DataFormatters/StringPrinter.cpp index 041933ae7e9..b114add5064 100644 --- a/lldb/source/DataFormatters/StringPrinter.cpp +++ b/lldb/source/DataFormatters/StringPrinter.cpp @@ -374,6 +374,8 @@ DumpUTFBufferToStream (ConversionResult (*ConvertFunction) (const SourceDataType 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<StringPrinter::StringElementType::ASCII 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<StringPrinter::StringElementType::ASCII else if (quote != 0) options.GetStream()->Printf("%c",quote); + if (is_truncated) + options.GetStream()->Printf("..."); + return true; } @@ -527,14 +541,23 @@ ReadUTFBufferAndDumpToStream (const StringPrinter::ReadStringAndDumpToStreamOpti 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 StringPrinter::ReadStringAndDumpToStreamOpti StringPrinter::ReadBufferAndDumpToStreamOptions dump_options(options); dump_options.SetData(data); dump_options.SetSourceSize(sourceSize); + dump_options.SetIsTruncated(is_truncated); return DumpUTFBufferToStream(ConvertFunction, dump_options); } diff --git a/lldb/source/Plugins/Language/CPlusPlus/LibCxx.cpp b/lldb/source/Plugins/Language/CPlusPlus/LibCxx.cpp index 3eaebef152a..950bd62c5c9 100644 --- a/lldb/source/Plugins/Language/CPlusPlus/LibCxx.cpp +++ b/lldb/source/Plugins/Language/CPlusPlus/LibCxx.cpp @@ -563,14 +563,23 @@ lldb_private::formatters::LibcxxWStringSummaryProvider (ValueObject& valobj, Str 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::LibcxxStringSummaryProvider (ValueObject& valobj, Stre 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); diff --git a/lldb/source/Target/Process.cpp b/lldb/source/Target/Process.cpp index b0e0591d552..6ffc4a96a9b 100644 --- a/lldb/source/Target/Process.cpp +++ b/lldb/source/Target/Process.cpp @@ -1960,7 +1960,7 @@ Process::LoadImage (const FileSpec &image_spec, Error &error) 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(); |