diff options
Diffstat (limited to 'lldb/source/DataFormatters')
-rw-r--r-- | lldb/source/DataFormatters/CXXFunctionPointer.cpp | 2 | ||||
-rw-r--r-- | lldb/source/DataFormatters/DataVisualization.cpp | 3 | ||||
-rw-r--r-- | lldb/source/DataFormatters/DumpValueObjectOptions.cpp | 3 | ||||
-rw-r--r-- | lldb/source/DataFormatters/FormatCache.cpp | 20 | ||||
-rw-r--r-- | lldb/source/DataFormatters/FormatClasses.cpp | 3 | ||||
-rw-r--r-- | lldb/source/DataFormatters/FormatManager.cpp | 27 | ||||
-rw-r--r-- | lldb/source/DataFormatters/FormattersHelpers.cpp | 14 | ||||
-rw-r--r-- | lldb/source/DataFormatters/LanguageCategory.cpp | 7 | ||||
-rw-r--r-- | lldb/source/DataFormatters/StringPrinter.cpp | 585 | ||||
-rw-r--r-- | lldb/source/DataFormatters/TypeCategory.cpp | 40 | ||||
-rw-r--r-- | lldb/source/DataFormatters/TypeCategoryMap.cpp | 11 | ||||
-rw-r--r-- | lldb/source/DataFormatters/TypeFormat.cpp | 12 | ||||
-rw-r--r-- | lldb/source/DataFormatters/TypeSummary.cpp | 14 | ||||
-rw-r--r-- | lldb/source/DataFormatters/TypeSynthetic.cpp | 9 | ||||
-rw-r--r-- | lldb/source/DataFormatters/ValueObjectPrinter.cpp | 35 | ||||
-rw-r--r-- | lldb/source/DataFormatters/VectorType.cpp | 2 |
16 files changed, 331 insertions, 456 deletions
diff --git a/lldb/source/DataFormatters/CXXFunctionPointer.cpp b/lldb/source/DataFormatters/CXXFunctionPointer.cpp index 0ca000eb0529d..3b7b0bc27cf81 100644 --- a/lldb/source/DataFormatters/CXXFunctionPointer.cpp +++ b/lldb/source/DataFormatters/CXXFunctionPointer.cpp @@ -1,4 +1,4 @@ -//===-- CXXFunctionPointer.cpp-----------------------------------*- C++ -*-===// +//===-- CXXFunctionPointer.cpp---------------------------------------------===// // // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. // See https://llvm.org/LICENSE.txt for license information. diff --git a/lldb/source/DataFormatters/DataVisualization.cpp b/lldb/source/DataFormatters/DataVisualization.cpp index 99c303c9f0b1c..450a5cbc3ef36 100644 --- a/lldb/source/DataFormatters/DataVisualization.cpp +++ b/lldb/source/DataFormatters/DataVisualization.cpp @@ -1,5 +1,4 @@ -//===-- DataVisualization.cpp ---------------------------------------*- C++ -//-*-===// +//===-- DataVisualization.cpp ---------------------------------------------===// // // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. // See https://llvm.org/LICENSE.txt for license information. diff --git a/lldb/source/DataFormatters/DumpValueObjectOptions.cpp b/lldb/source/DataFormatters/DumpValueObjectOptions.cpp index 84f21696e0548..46a2a489586b8 100644 --- a/lldb/source/DataFormatters/DumpValueObjectOptions.cpp +++ b/lldb/source/DataFormatters/DumpValueObjectOptions.cpp @@ -1,5 +1,4 @@ -//===-- DumpValueObjectOptions.cpp -----------------------------------*- C++ -//-*-===// +//===-- DumpValueObjectOptions.cpp ----------------------------------------===// // // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. // See https://llvm.org/LICENSE.txt for license information. diff --git a/lldb/source/DataFormatters/FormatCache.cpp b/lldb/source/DataFormatters/FormatCache.cpp index 231e7ed0c0a07..5e0965fcdae40 100644 --- a/lldb/source/DataFormatters/FormatCache.cpp +++ b/lldb/source/DataFormatters/FormatCache.cpp @@ -1,5 +1,4 @@ -//===-- FormatCache.cpp ------------------------------------------*- C++ -//-*-===// +//===-- FormatCache.cpp ---------------------------------------------------===// // // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. // See https://llvm.org/LICENSE.txt for license information. @@ -52,15 +51,6 @@ void FormatCache::Entry::Set(lldb::SyntheticChildrenSP synthetic_sp) { m_synthetic_sp = synthetic_sp; } -FormatCache::FormatCache() - : m_map(), m_mutex() -#ifdef LLDB_CONFIGURATION_DEBUG - , - m_cache_hits(0), m_cache_misses(0) -#endif -{ -} - FormatCache::Entry &FormatCache::GetEntry(ConstString type) { auto i = m_map.find(type), e = m_map.end(); if (i != e) @@ -69,6 +59,8 @@ FormatCache::Entry &FormatCache::GetEntry(ConstString type) { return m_map[type]; } +namespace lldb_private { + template<> bool FormatCache::Entry::IsCached<lldb::TypeFormatImplSP>() { return IsFormatCached(); } @@ -79,20 +71,18 @@ template<> bool FormatCache::Entry::IsCached<lldb::SyntheticChildrenSP>() { return IsSyntheticCached(); } +} // namespace lldb_private + template <typename ImplSP> bool FormatCache::Get(ConstString type, ImplSP &format_impl_sp) { std::lock_guard<std::recursive_mutex> guard(m_mutex); auto entry = GetEntry(type); if (entry.IsCached<ImplSP>()) { -#ifdef LLDB_CONFIGURATION_DEBUG m_cache_hits++; -#endif entry.Get(format_impl_sp); return true; } -#ifdef LLDB_CONFIGURATION_DEBUG m_cache_misses++; -#endif format_impl_sp.reset(); return false; } diff --git a/lldb/source/DataFormatters/FormatClasses.cpp b/lldb/source/DataFormatters/FormatClasses.cpp index 6a9279f54d64c..44fa96033bc1e 100644 --- a/lldb/source/DataFormatters/FormatClasses.cpp +++ b/lldb/source/DataFormatters/FormatClasses.cpp @@ -1,5 +1,4 @@ -//===-- FormatClasses.cpp ----------------------------------------*- C++ -//-*-===// +//===-- FormatClasses.cpp -------------------------------------------------===// // // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. // See https://llvm.org/LICENSE.txt for license information. diff --git a/lldb/source/DataFormatters/FormatManager.cpp b/lldb/source/DataFormatters/FormatManager.cpp index d5db3ee75bf34..ad02d37360b84 100644 --- a/lldb/source/DataFormatters/FormatManager.cpp +++ b/lldb/source/DataFormatters/FormatManager.cpp @@ -1,4 +1,4 @@ -//===-- FormatManager.cpp ----------------------------------------*- C++-*-===// +//===-- FormatManager.cpp -------------------------------------------------===// // // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. // See https://llvm.org/LICENSE.txt for license information. @@ -174,28 +174,27 @@ void FormatManager::DisableAllCategories() { } void FormatManager::GetPossibleMatches( - ValueObject &valobj, CompilerType compiler_type, uint32_t reason, + ValueObject &valobj, CompilerType compiler_type, lldb::DynamicValueType use_dynamic, FormattersMatchVector &entries, bool did_strip_ptr, bool did_strip_ref, bool did_strip_typedef, bool root_level) { compiler_type = compiler_type.GetTypeForFormatters(); - ConstString type_name(compiler_type.GetConstTypeName()); + ConstString type_name(compiler_type.GetTypeName()); if (valobj.GetBitfieldBitSize() > 0) { StreamString sstring; sstring.Printf("%s:%d", type_name.AsCString(), valobj.GetBitfieldBitSize()); ConstString bitfieldname(sstring.GetString()); entries.push_back( - {bitfieldname, 0, did_strip_ptr, did_strip_ref, did_strip_typedef}); - reason |= lldb_private::eFormatterChoiceCriterionStrippedBitField; + {bitfieldname, did_strip_ptr, did_strip_ref, did_strip_typedef}); } if (!compiler_type.IsMeaninglessWithoutDynamicResolution()) { entries.push_back( - {type_name, reason, did_strip_ptr, did_strip_ref, did_strip_typedef}); + {type_name, did_strip_ptr, did_strip_ref, did_strip_typedef}); - ConstString display_type_name(compiler_type.GetDisplayTypeName()); + ConstString display_type_name(compiler_type.GetTypeName()); if (display_type_name != type_name) - entries.push_back({display_type_name, reason, did_strip_ptr, + entries.push_back({display_type_name, did_strip_ptr, did_strip_ref, did_strip_typedef}); } @@ -204,8 +203,6 @@ void FormatManager::GetPossibleMatches( CompilerType non_ref_type = compiler_type.GetNonReferenceType(); GetPossibleMatches( valobj, non_ref_type, - reason | - lldb_private::eFormatterChoiceCriterionStrippedPointerReference, use_dynamic, entries, did_strip_ptr, true, did_strip_typedef); if (non_ref_type.IsTypedefType()) { CompilerType deffed_referenced_type = non_ref_type.GetTypedefedType(); @@ -214,7 +211,6 @@ void FormatManager::GetPossibleMatches( : deffed_referenced_type.GetLValueReferenceType(); GetPossibleMatches( valobj, deffed_referenced_type, - reason | lldb_private::eFormatterChoiceCriterionNavigatedTypedefs, use_dynamic, entries, did_strip_ptr, did_strip_ref, true); // this is not exactly the usual meaning of stripping typedefs } @@ -224,8 +220,6 @@ void FormatManager::GetPossibleMatches( CompilerType non_ptr_type = compiler_type.GetPointeeType(); GetPossibleMatches( valobj, non_ptr_type, - reason | - lldb_private::eFormatterChoiceCriterionStrippedPointerReference, use_dynamic, entries, true, did_strip_ref, did_strip_typedef); if (non_ptr_type.IsTypedefType()) { CompilerType deffed_pointed_type = @@ -233,7 +227,6 @@ void FormatManager::GetPossibleMatches( const bool stripped_typedef = true; GetPossibleMatches( valobj, deffed_pointed_type, - reason | lldb_private::eFormatterChoiceCriterionNavigatedTypedefs, use_dynamic, entries, did_strip_ptr, did_strip_ref, stripped_typedef); // this is not exactly the usual meaning of // stripping typedefs @@ -253,7 +246,6 @@ void FormatManager::GetPossibleMatches( const bool stripped_typedef = true; GetPossibleMatches( valobj, deffed_array_type, - reason | lldb_private::eFormatterChoiceCriterionNavigatedTypedefs, use_dynamic, entries, did_strip_ptr, did_strip_ref, stripped_typedef); // this is not exactly the usual meaning of // stripping typedefs @@ -267,7 +259,6 @@ void FormatManager::GetPossibleMatches( language->GetPossibleFormattersMatches(valobj, use_dynamic)) { entries.push_back( {candidate, - reason | lldb_private::eFormatterChoiceCriterionLanguagePlugin, did_strip_ptr, did_strip_ref, did_strip_typedef}); } } @@ -278,7 +269,6 @@ void FormatManager::GetPossibleMatches( CompilerType deffed_type = compiler_type.GetTypedefedType(); GetPossibleMatches( valobj, deffed_type, - reason | lldb_private::eFormatterChoiceCriterionNavigatedTypedefs, use_dynamic, entries, did_strip_ptr, did_strip_ref, true); } @@ -293,7 +283,7 @@ void FormatManager::GetPossibleMatches( break; if (unqual_compiler_ast_type.GetOpaqueQualType() != compiler_type.GetOpaqueQualType()) - GetPossibleMatches(valobj, unqual_compiler_ast_type, reason, + GetPossibleMatches(valobj, unqual_compiler_ast_type, use_dynamic, entries, did_strip_ptr, did_strip_ref, did_strip_typedef); } while (false); @@ -304,7 +294,6 @@ void FormatManager::GetPossibleMatches( if (static_value_sp) GetPossibleMatches( *static_value_sp.get(), static_value_sp->GetCompilerType(), - reason | lldb_private::eFormatterChoiceCriterionWentToStaticValue, use_dynamic, entries, did_strip_ptr, did_strip_ref, did_strip_typedef, true); } diff --git a/lldb/source/DataFormatters/FormattersHelpers.cpp b/lldb/source/DataFormatters/FormattersHelpers.cpp index b2a5a17595c8f..7944ff06eee53 100644 --- a/lldb/source/DataFormatters/FormattersHelpers.cpp +++ b/lldb/source/DataFormatters/FormattersHelpers.cpp @@ -1,5 +1,4 @@ -//===-- FormattersHelpers.cpp -------------------------------------*- C++ -//-*-===// +//===-- FormattersHelpers.cpp ---------------------------------------------===// // // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. // See https://llvm.org/LICENSE.txt for license information. @@ -143,3 +142,14 @@ lldb_private::formatters::GetArrayAddressOrPointerValue(ValueObject &valobj) { return data_addr; } + +lldb::ValueObjectSP +lldb_private::formatters::GetValueOfLibCXXCompressedPair(ValueObject &pair) { + ValueObjectSP value = + pair.GetChildMemberWithName(ConstString("__value_"), true); + if (!value) { + // pre-r300140 member name + value = pair.GetChildMemberWithName(ConstString("__first_"), true); + } + return value; +} diff --git a/lldb/source/DataFormatters/LanguageCategory.cpp b/lldb/source/DataFormatters/LanguageCategory.cpp index e18ec0feaa8b2..4794186ce9aec 100644 --- a/lldb/source/DataFormatters/LanguageCategory.cpp +++ b/lldb/source/DataFormatters/LanguageCategory.cpp @@ -1,5 +1,4 @@ -//===-- LanguageCategory.cpp ---------------------------------------*- C++ -//-*-===// +//===-- LanguageCategory.cpp ----------------------------------------------===// // // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. // See https://llvm.org/LICENSE.txt for license information. @@ -55,6 +54,8 @@ bool LanguageCategory::Get(FormattersMatchData &match_data, return result; } +namespace lldb_private { + /// Explicit instantiations for the three types. /// \{ template bool @@ -83,6 +84,8 @@ auto &LanguageCategory::GetHardcodedFinder<lldb::SyntheticChildrenSP>() { return m_hardcoded_synthetics; } +} // namespace lldb_private + template <typename ImplSP> bool LanguageCategory::GetHardcoded(FormatManager &fmt_mgr, FormattersMatchData &match_data, diff --git a/lldb/source/DataFormatters/StringPrinter.cpp b/lldb/source/DataFormatters/StringPrinter.cpp index 27d649bfc370e..139f1ec0554f9 100644 --- a/lldb/source/DataFormatters/StringPrinter.cpp +++ b/lldb/source/DataFormatters/StringPrinter.cpp @@ -1,5 +1,4 @@ -//===-- StringPrinter.cpp ----------------------------------------*- C++ -//-*-===// +//===-- StringPrinter.cpp -------------------------------------------------===// // // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. // See https://llvm.org/LICENSE.txt for license information. @@ -16,6 +15,7 @@ #include "lldb/Target/Target.h" #include "lldb/Utility/Status.h" +#include "llvm/ADT/StringExtras.h" #include "llvm/Support/ConvertUTF.h" #include <ctype.h> @@ -25,15 +25,48 @@ using namespace lldb; using namespace lldb_private; using namespace lldb_private::formatters; +using GetPrintableElementType = StringPrinter::GetPrintableElementType; +using StringElementType = StringPrinter::StringElementType; + +/// DecodedCharBuffer stores the decoded contents of a single character. It +/// avoids managing memory on the heap by copying decoded bytes into an in-line +/// buffer. +class DecodedCharBuffer { +public: + DecodedCharBuffer(std::nullptr_t) {} + + DecodedCharBuffer(const uint8_t *bytes, size_t size) : m_size(size) { + if (size > MaxLength) + llvm_unreachable("unsupported length"); + memcpy(m_data, bytes, size); + } + + DecodedCharBuffer(const char *bytes, size_t size) + : DecodedCharBuffer(reinterpret_cast<const uint8_t *>(bytes), size) {} + + const uint8_t *GetBytes() const { return m_data; } + + size_t GetSize() const { return m_size; } + +private: + static constexpr unsigned MaxLength = 16; + + size_t m_size = 0; + uint8_t m_data[MaxLength] = {0}; +}; + +using EscapingHelper = + std::function<DecodedCharBuffer(uint8_t *, uint8_t *, uint8_t *&)>; // we define this for all values of type but only implement it for those we // care about that's good because we get linker errors for any unsupported type -template <lldb_private::formatters::StringPrinter::StringElementType type> -static StringPrinter::StringPrinterBufferPointer<> -GetPrintableImpl(uint8_t *buffer, uint8_t *buffer_end, uint8_t *&next); +template <StringElementType type> +static DecodedCharBuffer +GetPrintableImpl(uint8_t *buffer, uint8_t *buffer_end, uint8_t *&next, + StringPrinter::EscapeStyle escape_style); -// mimic isprint() for Unicode codepoints -static bool isprint(char32_t codepoint) { +// Mimic isprint() for Unicode codepoints. +static bool isprint32(char32_t codepoint) { if (codepoint <= 0x1F || codepoint == 0x7F) // C0 { return false; @@ -60,216 +93,174 @@ static bool isprint(char32_t codepoint) { return true; } -template <> -StringPrinter::StringPrinterBufferPointer<> -GetPrintableImpl<StringPrinter::StringElementType::ASCII>(uint8_t *buffer, - uint8_t *buffer_end, - uint8_t *&next) { - StringPrinter::StringPrinterBufferPointer<> retval = {nullptr}; - - switch (*buffer) { +DecodedCharBuffer attemptASCIIEscape(llvm::UTF32 c, + StringPrinter::EscapeStyle escape_style) { + const bool is_swift_escape_style = + escape_style == StringPrinter::EscapeStyle::Swift; + switch (c) { case 0: - retval = {"\\0", 2}; - break; + return {"\\0", 2}; case '\a': - retval = {"\\a", 2}; - break; + return {"\\a", 2}; case '\b': - retval = {"\\b", 2}; - break; + if (is_swift_escape_style) + return nullptr; + return {"\\b", 2}; case '\f': - retval = {"\\f", 2}; - break; + if (is_swift_escape_style) + return nullptr; + return {"\\f", 2}; case '\n': - retval = {"\\n", 2}; - break; + return {"\\n", 2}; case '\r': - retval = {"\\r", 2}; - break; + return {"\\r", 2}; case '\t': - retval = {"\\t", 2}; - break; + return {"\\t", 2}; case '\v': - retval = {"\\v", 2}; - break; + if (is_swift_escape_style) + return nullptr; + return {"\\v", 2}; case '\"': - retval = {"\\\"", 2}; - break; + return {"\\\"", 2}; + case '\'': + if (is_swift_escape_style) + return {"\\'", 2}; + return nullptr; case '\\': - retval = {"\\\\", 2}; - break; - default: - if (isprint(*buffer)) - retval = {buffer, 1}; - else { - uint8_t *data = new uint8_t[5]; - sprintf((char *)data, "\\x%02x", *buffer); - retval = {data, 4, [](const uint8_t *c) { delete[] c; }}; - break; - } + return {"\\\\", 2}; } - - next = buffer + 1; - return retval; -} - -static char32_t ConvertUTF8ToCodePoint(unsigned char c0, unsigned char c1) { - return (c0 - 192) * 64 + (c1 - 128); -} -static char32_t ConvertUTF8ToCodePoint(unsigned char c0, unsigned char c1, - unsigned char c2) { - return (c0 - 224) * 4096 + (c1 - 128) * 64 + (c2 - 128); -} -static char32_t ConvertUTF8ToCodePoint(unsigned char c0, unsigned char c1, - unsigned char c2, unsigned char c3) { - return (c0 - 240) * 262144 + (c2 - 128) * 4096 + (c2 - 128) * 64 + (c3 - 128); + return nullptr; } template <> -StringPrinter::StringPrinterBufferPointer<> -GetPrintableImpl<StringPrinter::StringElementType::UTF8>(uint8_t *buffer, - uint8_t *buffer_end, - uint8_t *&next) { - StringPrinter::StringPrinterBufferPointer<> retval{nullptr}; - - unsigned utf8_encoded_len = llvm::getNumBytesForUTF8(*buffer); - - if (1u + std::distance(buffer, buffer_end) < utf8_encoded_len) { - // I don't have enough bytes - print whatever I have left - retval = {buffer, static_cast<size_t>(1 + buffer_end - buffer)}; - next = buffer_end + 1; +DecodedCharBuffer GetPrintableImpl<StringElementType::ASCII>( + uint8_t *buffer, uint8_t *buffer_end, uint8_t *&next, + StringPrinter::EscapeStyle escape_style) { + // The ASCII helper always advances 1 byte at a time. + next = buffer + 1; + + DecodedCharBuffer retval = attemptASCIIEscape(*buffer, escape_style); + if (retval.GetSize()) return retval; - } - char32_t codepoint = 0; - switch (utf8_encoded_len) { - case 1: - // this is just an ASCII byte - ask ASCII - return GetPrintableImpl<StringPrinter::StringElementType::ASCII>( - buffer, buffer_end, next); - case 2: - codepoint = ConvertUTF8ToCodePoint((unsigned char)*buffer, - (unsigned char)*(buffer + 1)); - break; - case 3: - codepoint = ConvertUTF8ToCodePoint((unsigned char)*buffer, - (unsigned char)*(buffer + 1), - (unsigned char)*(buffer + 2)); + // Use llvm's locale-independent isPrint(char), instead of the libc + // implementation which may give different results on different platforms. + if (llvm::isPrint(*buffer)) + return {buffer, 1}; + + unsigned escaped_len; + constexpr unsigned max_buffer_size = 7; + uint8_t data[max_buffer_size]; + switch (escape_style) { + case StringPrinter::EscapeStyle::CXX: + // Prints 4 characters, then a \0 terminator. + escaped_len = sprintf((char *)data, "\\x%02x", *buffer); break; - case 4: - codepoint = ConvertUTF8ToCodePoint( - (unsigned char)*buffer, (unsigned char)*(buffer + 1), - (unsigned char)*(buffer + 2), (unsigned char)*(buffer + 3)); + case StringPrinter::EscapeStyle::Swift: + // Prints up to 6 characters, then a \0 terminator. + escaped_len = sprintf((char *)data, "\\u{%x}", *buffer); break; - default: - // this is probably some bogus non-character thing just print it as-is and - // hope to sync up again soon - retval = {buffer, 1}; - next = buffer + 1; - return retval; } + lldbassert(escaped_len > 0 && "unknown string escape style"); + return {data, escaped_len}; +} - if (codepoint) { - switch (codepoint) { - case 0: - retval = {"\\0", 2}; - break; - case '\a': - retval = {"\\a", 2}; - break; - case '\b': - retval = {"\\b", 2}; - break; - case '\f': - retval = {"\\f", 2}; - break; - case '\n': - retval = {"\\n", 2}; - break; - case '\r': - retval = {"\\r", 2}; - break; - case '\t': - retval = {"\\t", 2}; - break; - case '\v': - retval = {"\\v", 2}; - break; - case '\"': - retval = {"\\\"", 2}; - break; - case '\\': - retval = {"\\\\", 2}; - break; - default: - if (isprint(codepoint)) - retval = {buffer, utf8_encoded_len}; - else { - uint8_t *data = new uint8_t[11]; - sprintf((char *)data, "\\U%08x", (unsigned)codepoint); - retval = {data, 10, [](const uint8_t *c) { delete[] c; }}; - break; - } - } - - next = buffer + utf8_encoded_len; +template <> +DecodedCharBuffer GetPrintableImpl<StringElementType::UTF8>( + uint8_t *buffer, uint8_t *buffer_end, uint8_t *&next, + StringPrinter::EscapeStyle escape_style) { + // If the utf8 encoded length is invalid (i.e., not in the closed interval + // [1;4]), or if there aren't enough bytes to print, or if the subsequence + // isn't valid utf8, fall back to printing an ASCII-escaped subsequence. + if (!llvm::isLegalUTF8Sequence(buffer, buffer_end)) + return GetPrintableImpl<StringElementType::ASCII>(buffer, buffer_end, next, + escape_style); + + // Convert the valid utf8 sequence to a utf32 codepoint. This cannot fail. + llvm::UTF32 codepoint = 0; + const llvm::UTF8 *buffer_for_conversion = buffer; + llvm::ConversionResult result = llvm::convertUTF8Sequence( + &buffer_for_conversion, buffer_end, &codepoint, llvm::strictConversion); + assert(result == llvm::conversionOK && + "Failed to convert legal utf8 sequence"); + (void)result; + + // The UTF8 helper always advances by the utf8 encoded length. + const unsigned utf8_encoded_len = buffer_for_conversion - buffer; + next = buffer + utf8_encoded_len; + + DecodedCharBuffer retval = attemptASCIIEscape(codepoint, escape_style); + if (retval.GetSize()) return retval; + if (isprint32(codepoint)) + return {buffer, utf8_encoded_len}; + + unsigned escaped_len; + constexpr unsigned max_buffer_size = 13; + uint8_t data[max_buffer_size]; + switch (escape_style) { + case StringPrinter::EscapeStyle::CXX: + // Prints 10 characters, then a \0 terminator. + escaped_len = sprintf((char *)data, "\\U%08x", codepoint); + break; + case StringPrinter::EscapeStyle::Swift: + // Prints up to 12 characters, then a \0 terminator. + escaped_len = sprintf((char *)data, "\\u{%x}", codepoint); + break; } - - // this should not happen - but just in case.. try to resync at some point - retval = {buffer, 1}; - next = buffer + 1; - return retval; + lldbassert(escaped_len > 0 && "unknown string escape style"); + return {data, escaped_len}; } // Given a sequence of bytes, this function returns: a sequence of bytes to // actually print out + a length the following unscanned position of the buffer // is in next -static StringPrinter::StringPrinterBufferPointer<> -GetPrintable(StringPrinter::StringElementType type, uint8_t *buffer, - uint8_t *buffer_end, uint8_t *&next) { - if (!buffer) +static DecodedCharBuffer GetPrintable(StringElementType type, uint8_t *buffer, + uint8_t *buffer_end, uint8_t *&next, + StringPrinter::EscapeStyle escape_style) { + if (!buffer || buffer >= buffer_end) return {nullptr}; switch (type) { - case StringPrinter::StringElementType::ASCII: - return GetPrintableImpl<StringPrinter::StringElementType::ASCII>( - buffer, buffer_end, next); - case StringPrinter::StringElementType::UTF8: - return GetPrintableImpl<StringPrinter::StringElementType::UTF8>( - buffer, buffer_end, next); + case StringElementType::ASCII: + return GetPrintableImpl<StringElementType::ASCII>(buffer, buffer_end, next, + escape_style); + case StringElementType::UTF8: + return GetPrintableImpl<StringElementType::UTF8>(buffer, buffer_end, next, + escape_style); default: return {nullptr}; } } -StringPrinter::EscapingHelper -StringPrinter::GetDefaultEscapingHelper(GetPrintableElementType elem_type) { +static EscapingHelper +GetDefaultEscapingHelper(GetPrintableElementType elem_type, + StringPrinter::EscapeStyle escape_style) { switch (elem_type) { case GetPrintableElementType::UTF8: - return [](uint8_t *buffer, uint8_t *buffer_end, - uint8_t *&next) -> StringPrinter::StringPrinterBufferPointer<> { - return GetPrintable(StringPrinter::StringElementType::UTF8, buffer, - buffer_end, next); - }; case GetPrintableElementType::ASCII: - return [](uint8_t *buffer, uint8_t *buffer_end, - uint8_t *&next) -> StringPrinter::StringPrinterBufferPointer<> { - return GetPrintable(StringPrinter::StringElementType::ASCII, buffer, - buffer_end, next); + return [escape_style, elem_type](uint8_t *buffer, uint8_t *buffer_end, + uint8_t *&next) -> DecodedCharBuffer { + return GetPrintable(elem_type == GetPrintableElementType::UTF8 + ? StringElementType::UTF8 + : StringElementType::ASCII, + buffer, buffer_end, next, escape_style); }; } llvm_unreachable("bad element type"); } -// use this call if you already have an LLDB-side buffer for the data +/// Read a string encoded in accordance with \tparam SourceDataType from a +/// host-side LLDB buffer, then pretty-print it to a stream using \p style. template <typename SourceDataType> -static bool DumpUTFBufferToStream( +static bool DumpEncodedBufferToStream( + GetPrintableElementType style, llvm::ConversionResult (*ConvertFunction)(const SourceDataType **, const SourceDataType *, llvm::UTF8 **, llvm::UTF8 *, llvm::ConversionFlags), const StringPrinter::ReadBufferAndDumpToStreamOptions &dump_options) { + assert(dump_options.GetStream() && "need a Stream to print the string to"); Stream &stream(*dump_options.GetStream()); if (dump_options.GetPrefixToken() != nullptr) stream.Printf("%s", dump_options.GetPrefixToken()); @@ -329,18 +320,10 @@ static bool DumpUTFBufferToStream( } const bool escape_non_printables = dump_options.GetEscapeNonPrintables(); - lldb_private::formatters::StringPrinter::EscapingHelper escaping_callback; - if (escape_non_printables) { - if (Language *language = Language::FindPlugin(dump_options.GetLanguage())) - escaping_callback = language->GetStringPrinterEscapingHelper( - lldb_private::formatters::StringPrinter::GetPrintableElementType:: - UTF8); - else - escaping_callback = - lldb_private::formatters::StringPrinter::GetDefaultEscapingHelper( - lldb_private::formatters::StringPrinter:: - GetPrintableElementType::UTF8); - } + EscapingHelper escaping_callback; + if (escape_non_printables) + escaping_callback = + GetDefaultEscapingHelper(style, dump_options.GetEscapeStyle()); // since we tend to accept partial data (and even partially malformed data) // we might end up with no NULL terminator before the end_ptr hence we need @@ -355,13 +338,11 @@ static bool DumpUTFBufferToStream( escaping_callback(utf8_data_ptr, utf8_data_end_ptr, next_data); auto printable_bytes = printable.GetBytes(); auto printable_size = printable.GetSize(); - if (!printable_bytes || !next_data) { - // GetPrintable() failed on us - print one byte in a desperate resync - // attempt - printable_bytes = utf8_data_ptr; - printable_size = 1; - next_data = utf8_data_ptr + 1; - } + + // We failed to figure out how to print this string. + if (!printable_bytes || !next_data) + return false; + for (unsigned c = 0; c < printable_size; c++) stream.Printf("%c", *(printable_bytes + c)); utf8_data_ptr = (uint8_t *)next_data; @@ -404,173 +385,91 @@ lldb_private::formatters::StringPrinter::ReadBufferAndDumpToStreamOptions:: SetQuote(options.GetQuote()); SetEscapeNonPrintables(options.GetEscapeNonPrintables()); SetBinaryZeroIsTerminator(options.GetBinaryZeroIsTerminator()); - SetLanguage(options.GetLanguage()); + SetEscapeStyle(options.GetEscapeStyle()); } namespace lldb_private { namespace formatters { -template <> -bool StringPrinter::ReadStringAndDumpToStream< - StringPrinter::StringElementType::ASCII>( - const ReadStringAndDumpToStreamOptions &options) { - assert(options.GetStream() && "need a Stream to print the string to"); - Status my_error; - - ProcessSP process_sp(options.GetProcessSP()); - - if (process_sp.get() == nullptr || options.GetLocation() == 0) - return false; - - size_t size; - const auto max_size = process_sp->GetTarget().GetMaximumSizeOfStringSummary(); - bool is_truncated = false; - - if (options.GetSourceSize() == 0) - size = max_size; - else if (!options.GetIgnoreMaxLength()) { - size = options.GetSourceSize(); - if (size > max_size) { - size = max_size; - is_truncated = true; - } - } else - size = options.GetSourceSize(); - - lldb::DataBufferSP buffer_sp(new DataBufferHeap(size, 0)); - - process_sp->ReadCStringFromMemory( - options.GetLocation(), (char *)buffer_sp->GetBytes(), size, my_error); - - if (my_error.Fail()) - return false; - - const char *prefix_token = options.GetPrefixToken(); - char quote = options.GetQuote(); - - if (prefix_token != nullptr) - options.GetStream()->Printf("%s%c", prefix_token, quote); - else if (quote != 0) - options.GetStream()->Printf("%c", quote); - - uint8_t *data_end = buffer_sp->GetBytes() + buffer_sp->GetByteSize(); - - const bool escape_non_printables = options.GetEscapeNonPrintables(); - lldb_private::formatters::StringPrinter::EscapingHelper escaping_callback; - if (escape_non_printables) { - if (Language *language = Language::FindPlugin(options.GetLanguage())) - escaping_callback = language->GetStringPrinterEscapingHelper( - lldb_private::formatters::StringPrinter::GetPrintableElementType:: - ASCII); - else - escaping_callback = - lldb_private::formatters::StringPrinter::GetDefaultEscapingHelper( - lldb_private::formatters::StringPrinter::GetPrintableElementType:: - ASCII); - } - - // since we tend to accept partial data (and even partially malformed data) - // we might end up with no NULL terminator before the end_ptr hence we need - // to take a slower route and ensure we stay within boundaries - for (uint8_t *data = buffer_sp->GetBytes(); *data && (data < data_end);) { - if (escape_non_printables) { - uint8_t *next_data = nullptr; - auto printable = escaping_callback(data, data_end, next_data); - auto printable_bytes = printable.GetBytes(); - auto printable_size = printable.GetSize(); - if (!printable_bytes || !next_data) { - // GetPrintable() failed on us - print one byte in a desperate resync - // attempt - printable_bytes = data; - printable_size = 1; - next_data = data + 1; - } - for (unsigned c = 0; c < printable_size; c++) - options.GetStream()->Printf("%c", *(printable_bytes + c)); - data = (uint8_t *)next_data; - } else { - options.GetStream()->Printf("%c", *data); - data++; - } - } - - const char *suffix_token = options.GetSuffixToken(); - - if (suffix_token != nullptr) - options.GetStream()->Printf("%c%s", quote, suffix_token); - else if (quote != 0) - options.GetStream()->Printf("%c", quote); - - if (is_truncated) - options.GetStream()->Printf("..."); - - return true; -} - template <typename SourceDataType> -static bool ReadUTFBufferAndDumpToStream( +static bool ReadEncodedBufferAndDumpToStream( + StringElementType elem_type, const StringPrinter::ReadStringAndDumpToStreamOptions &options, llvm::ConversionResult (*ConvertFunction)(const SourceDataType **, const SourceDataType *, llvm::UTF8 **, llvm::UTF8 *, llvm::ConversionFlags)) { assert(options.GetStream() && "need a Stream to print the string to"); + if (!options.GetStream()) + return false; if (options.GetLocation() == 0 || options.GetLocation() == LLDB_INVALID_ADDRESS) return false; lldb::ProcessSP process_sp(options.GetProcessSP()); - if (!process_sp) return false; - const int type_width = sizeof(SourceDataType); - const int origin_encoding = 8 * type_width; + constexpr int type_width = sizeof(SourceDataType); + constexpr int origin_encoding = 8 * type_width; if (origin_encoding != 8 && origin_encoding != 16 && origin_encoding != 32) return false; - // if not UTF8, I need a conversion function to return proper UTF8 + // If not UTF8 or ASCII, conversion to UTF8 is necessary. if (origin_encoding != 8 && !ConvertFunction) return false; - if (!options.GetStream()) - return false; - - 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) { + uint32_t sourceSize; + if (elem_type == StringElementType::ASCII && !options.GetSourceSize()) { + // FIXME: The NSString formatter sets HasSourceSize(true) when the size is + // actually unknown, as well as SetBinaryZeroIsTerminator(false). IIUC the + // C++ formatter also sets SetBinaryZeroIsTerminator(false) when it doesn't + // mean to. I don't see how this makes sense: we should fix the formatters. + // + // Until then, the behavior that's expected for ASCII strings with unknown + // lengths is to read up to the max size and then null-terminate. Do that. sourceSize = max_size; needs_zero_terminator = true; - } else if (!options.GetIgnoreMaxLength()) { - if (sourceSize > max_size) { - sourceSize = max_size; - is_truncated = true; + } else if (options.HasSourceSize()) { + sourceSize = options.GetSourceSize(); + if (!options.GetIgnoreMaxLength()) { + if (sourceSize > max_size) { + sourceSize = max_size; + is_truncated = true; + } } + } else { + sourceSize = max_size; + needs_zero_terminator = true; } const int bufferSPSize = sourceSize * type_width; - lldb::DataBufferSP buffer_sp(new DataBufferHeap(bufferSPSize, 0)); - if (!buffer_sp->GetBytes()) + // Check if we got bytes. We never get any bytes if we have an empty + // string, but we still continue so that we end up actually printing + // an empty string (""). + if (sourceSize != 0 && !buffer_sp->GetBytes()) return false; Status error; char *buffer = reinterpret_cast<char *>(buffer_sp->GetBytes()); - if (needs_zero_terminator) + if (elem_type == StringElementType::ASCII) + process_sp->ReadCStringFromMemory(options.GetLocation(), buffer, + bufferSPSize, error); + else if (needs_zero_terminator) process_sp->ReadStringFromMemory(options.GetLocation(), buffer, bufferSPSize, error, type_width); else - process_sp->ReadMemoryFromInferior(options.GetLocation(), - (char *)buffer_sp->GetBytes(), + process_sp->ReadMemoryFromInferior(options.GetLocation(), buffer, bufferSPSize, error); - if (error.Fail()) { options.GetStream()->Printf("unable to read data"); return true; @@ -583,67 +482,79 @@ static bool ReadUTFBufferAndDumpToStream( dump_options.SetData(data); dump_options.SetSourceSize(sourceSize); dump_options.SetIsTruncated(is_truncated); + dump_options.SetNeedsZeroTermination(needs_zero_terminator); + if (needs_zero_terminator) + dump_options.SetBinaryZeroIsTerminator(true); - return DumpUTFBufferToStream(ConvertFunction, dump_options); + GetPrintableElementType print_style = (elem_type == StringElementType::ASCII) + ? GetPrintableElementType::ASCII + : GetPrintableElementType::UTF8; + return DumpEncodedBufferToStream(print_style, ConvertFunction, dump_options); } template <> -bool StringPrinter::ReadStringAndDumpToStream< - StringPrinter::StringElementType::UTF8>( +bool StringPrinter::ReadStringAndDumpToStream<StringElementType::UTF8>( const ReadStringAndDumpToStreamOptions &options) { - return ReadUTFBufferAndDumpToStream<llvm::UTF8>(options, nullptr); + return ReadEncodedBufferAndDumpToStream<llvm::UTF8>(StringElementType::UTF8, + options, nullptr); } template <> -bool StringPrinter::ReadStringAndDumpToStream< - StringPrinter::StringElementType::UTF16>( +bool StringPrinter::ReadStringAndDumpToStream<StringElementType::UTF16>( const ReadStringAndDumpToStreamOptions &options) { - return ReadUTFBufferAndDumpToStream<llvm::UTF16>(options, - llvm::ConvertUTF16toUTF8); + return ReadEncodedBufferAndDumpToStream<llvm::UTF16>( + StringElementType::UTF16, options, llvm::ConvertUTF16toUTF8); } template <> -bool StringPrinter::ReadStringAndDumpToStream< - StringPrinter::StringElementType::UTF32>( +bool StringPrinter::ReadStringAndDumpToStream<StringElementType::UTF32>( const ReadStringAndDumpToStreamOptions &options) { - return ReadUTFBufferAndDumpToStream<llvm::UTF32>(options, - llvm::ConvertUTF32toUTF8); + return ReadEncodedBufferAndDumpToStream<llvm::UTF32>( + StringElementType::UTF32, options, llvm::ConvertUTF32toUTF8); } template <> -bool StringPrinter::ReadBufferAndDumpToStream< - StringPrinter::StringElementType::UTF8>( - const ReadBufferAndDumpToStreamOptions &options) { - assert(options.GetStream() && "need a Stream to print the string to"); - - return DumpUTFBufferToStream<llvm::UTF8>(nullptr, options); +bool StringPrinter::ReadStringAndDumpToStream<StringElementType::ASCII>( + const ReadStringAndDumpToStreamOptions &options) { + return ReadEncodedBufferAndDumpToStream<char>(StringElementType::ASCII, + options, nullptr); } template <> -bool StringPrinter::ReadBufferAndDumpToStream< - StringPrinter::StringElementType::ASCII>( +bool StringPrinter::ReadBufferAndDumpToStream<StringElementType::UTF8>( const ReadBufferAndDumpToStreamOptions &options) { - // treat ASCII the same as UTF8 - // FIXME: can we optimize ASCII some more? - return ReadBufferAndDumpToStream<StringElementType::UTF8>(options); + return DumpEncodedBufferToStream<llvm::UTF8>(GetPrintableElementType::UTF8, + nullptr, options); } template <> -bool StringPrinter::ReadBufferAndDumpToStream< - StringPrinter::StringElementType::UTF16>( +bool StringPrinter::ReadBufferAndDumpToStream<StringElementType::UTF16>( const ReadBufferAndDumpToStreamOptions &options) { - assert(options.GetStream() && "need a Stream to print the string to"); - - return DumpUTFBufferToStream(llvm::ConvertUTF16toUTF8, options); + return DumpEncodedBufferToStream(GetPrintableElementType::UTF8, + llvm::ConvertUTF16toUTF8, options); } template <> -bool StringPrinter::ReadBufferAndDumpToStream< - StringPrinter::StringElementType::UTF32>( +bool StringPrinter::ReadBufferAndDumpToStream<StringElementType::UTF32>( const ReadBufferAndDumpToStreamOptions &options) { - assert(options.GetStream() && "need a Stream to print the string to"); + return DumpEncodedBufferToStream(GetPrintableElementType::UTF8, + llvm::ConvertUTF32toUTF8, options); +} - return DumpUTFBufferToStream(llvm::ConvertUTF32toUTF8, options); +template <> +bool StringPrinter::ReadBufferAndDumpToStream<StringElementType::ASCII>( + const ReadBufferAndDumpToStreamOptions &options) { + // Treat ASCII the same as UTF8. + // + // FIXME: This is probably not the right thing to do (well, it's debatable). + // If an ASCII-encoded string happens to contain a sequence of invalid bytes + // that forms a valid UTF8 character, we'll print out that character. This is + // good if you're playing fast and loose with encodings (probably good for + // std::string users), but maybe not so good if you care about your string + // formatter respecting the semantics of your selected string encoding. In + // the latter case you'd want to see the character byte sequence ('\x..'), not + // the UTF8 character itself. + return ReadBufferAndDumpToStream<StringElementType::UTF8>(options); } } // namespace formatters diff --git a/lldb/source/DataFormatters/TypeCategory.cpp b/lldb/source/DataFormatters/TypeCategory.cpp index 85699691f52ba..8368c91a57f12 100644 --- a/lldb/source/DataFormatters/TypeCategory.cpp +++ b/lldb/source/DataFormatters/TypeCategory.cpp @@ -1,4 +1,4 @@ -//===-- TypeCategory.cpp -----------------------------------------*- C++-*-===// +//===-- TypeCategory.cpp --------------------------------------------------===// // // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. // See https://llvm.org/LICENSE.txt for license information. @@ -86,51 +86,41 @@ void TypeCategoryImpl::AddLanguage(lldb::LanguageType lang) { bool TypeCategoryImpl::Get(lldb::LanguageType lang, const FormattersMatchVector &candidates, - lldb::TypeFormatImplSP &entry, uint32_t *reason) { + lldb::TypeFormatImplSP &entry) { if (!IsEnabled() || !IsApplicable(lang)) return false; - if (GetTypeFormatsContainer()->Get(candidates, entry, reason)) + if (GetTypeFormatsContainer()->Get(candidates, entry)) return true; - bool regex = GetRegexTypeFormatsContainer()->Get(candidates, entry, reason); - if (regex && reason) - *reason |= lldb_private::eFormatterChoiceCriterionRegularExpressionSummary; + bool regex = GetRegexTypeFormatsContainer()->Get(candidates, entry); return regex; } bool TypeCategoryImpl::Get(lldb::LanguageType lang, const FormattersMatchVector &candidates, - lldb::TypeSummaryImplSP &entry, uint32_t *reason) { + lldb::TypeSummaryImplSP &entry) { if (!IsEnabled() || !IsApplicable(lang)) return false; - if (GetTypeSummariesContainer()->Get(candidates, entry, reason)) + if (GetTypeSummariesContainer()->Get(candidates, entry)) return true; - bool regex = GetRegexTypeSummariesContainer()->Get(candidates, entry, reason); - if (regex && reason) - *reason |= lldb_private::eFormatterChoiceCriterionRegularExpressionSummary; + bool regex = GetRegexTypeSummariesContainer()->Get(candidates, entry); return regex; } bool TypeCategoryImpl::Get(lldb::LanguageType lang, const FormattersMatchVector &candidates, - lldb::SyntheticChildrenSP &entry, uint32_t *reason) { + lldb::SyntheticChildrenSP &entry) { if (!IsEnabled() || !IsApplicable(lang)) return false; TypeFilterImpl::SharedPointer filter_sp; - uint32_t reason_filter = 0; - bool regex_filter = false; // first find both Filter and Synth, and then check which is most recent - if (!GetTypeFiltersContainer()->Get(candidates, filter_sp, &reason_filter)) - regex_filter = GetRegexTypeFiltersContainer()->Get(candidates, filter_sp, - &reason_filter); + if (!GetTypeFiltersContainer()->Get(candidates, filter_sp)) + GetRegexTypeFiltersContainer()->Get(candidates, filter_sp); - bool regex_synth = false; - uint32_t reason_synth = 0; bool pick_synth = false; ScriptedSyntheticChildren::SharedPointer synth; - if (!GetTypeSyntheticsContainer()->Get(candidates, synth, &reason_synth)) - regex_synth = GetRegexTypeSyntheticsContainer()->Get(candidates, synth, - &reason_synth); + if (!GetTypeSyntheticsContainer()->Get(candidates, synth)) + GetRegexTypeSyntheticsContainer()->Get(candidates, synth); if (!filter_sp.get() && !synth.get()) return false; else if (!filter_sp.get() && synth.get()) @@ -144,13 +134,9 @@ bool TypeCategoryImpl::Get(lldb::LanguageType lang, pick_synth = filter_sp->GetRevision() <= synth->GetRevision(); } if (pick_synth) { - if (regex_synth && reason) - *reason |= lldb_private::eFormatterChoiceCriterionRegularExpressionFilter; entry = synth; return true; } else { - if (regex_filter && reason) - *reason |= lldb_private::eFormatterChoiceCriterionRegularExpressionFilter; entry = filter_sp; return true; } @@ -492,5 +478,5 @@ std::string TypeCategoryImpl::GetDescription() { if (print_lang) stream.PutCString(lang_stream.GetString()); stream.PutChar(')'); - return stream.GetString(); + return std::string(stream.GetString()); } diff --git a/lldb/source/DataFormatters/TypeCategoryMap.cpp b/lldb/source/DataFormatters/TypeCategoryMap.cpp index ac515154299a2..a011c5414ee90 100644 --- a/lldb/source/DataFormatters/TypeCategoryMap.cpp +++ b/lldb/source/DataFormatters/TypeCategoryMap.cpp @@ -1,5 +1,4 @@ -//===-- TypeCategoryMap.cpp ----------------------------------------*- C++ -//-*-===// +//===-- TypeCategoryMap.cpp -----------------------------------------------===// // // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. // See https://llvm.org/LICENSE.txt for license information. @@ -173,7 +172,6 @@ template <typename ImplSP> void TypeCategoryMap::Get(FormattersMatchData &match_data, ImplSP &retval) { std::lock_guard<std::recursive_mutex> guard(m_map_mutex); - uint32_t reason_why; ActiveCategoriesIterator begin, end = m_active_categories.end(); Log *log(lldb_private::GetLogIfAllCategoriesSet(LIBLLDB_LOG_DATAFORMATTERS)); @@ -182,13 +180,12 @@ void TypeCategoryMap::Get(FormattersMatchData &match_data, ImplSP &retval) { for (auto match : match_data.GetMatchesVector()) { LLDB_LOGF( log, - "[%s] candidate match = %s %s %s %s reason = %" PRIu32, + "[%s] candidate match = %s %s %s %s", __FUNCTION__, match.GetTypeName().GetCString(), match.DidStripPointer() ? "strip-pointers" : "no-strip-pointers", match.DidStripReference() ? "strip-reference" : "no-strip-reference", - match.DidStripTypedef() ? "strip-typedef" : "no-strip-typedef", - match.GetReason()); + match.DidStripTypedef() ? "strip-typedef" : "no-strip-typedef"); } } @@ -199,7 +196,7 @@ void TypeCategoryMap::Get(FormattersMatchData &match_data, ImplSP &retval) { category_sp->GetName()); if (!category_sp->Get( match_data.GetValueObject().GetObjectRuntimeLanguage(), - match_data.GetMatchesVector(), current_format, &reason_why)) + match_data.GetMatchesVector(), current_format)) continue; retval = std::move(current_format); diff --git a/lldb/source/DataFormatters/TypeFormat.cpp b/lldb/source/DataFormatters/TypeFormat.cpp index b272c2e8dc3b3..b9a9447c5f3e8 100644 --- a/lldb/source/DataFormatters/TypeFormat.cpp +++ b/lldb/source/DataFormatters/TypeFormat.cpp @@ -1,4 +1,4 @@ -//===-- TypeFormat.cpp ----------------------------------------*- C++ -*-===// +//===-- TypeFormat.cpp ----------------------------------------------------===// // // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. // See https://llvm.org/LICENSE.txt for license information. @@ -60,7 +60,7 @@ bool TypeFormatImpl_Format::FormatObject(ValueObject *valobj, DumpDataExtractor(data, ®_sstr, 0, GetFormat(), reg_info->byte_size, 1, UINT32_MAX, LLDB_INVALID_ADDRESS, 0, 0, exe_ctx.GetBestExecutionContextScope()); - dest = reg_sstr.GetString(); + dest = std::string(reg_sstr.GetString()); } } else { CompilerType compiler_type = value.GetCompilerType(); @@ -114,7 +114,7 @@ bool TypeFormatImpl_Format::FormatObject(ValueObject *valobj, // here, but that's about as severe as we get // CompilerType::DumpTypeValue() should always return something, even // if that something is an error message - dest = sstr.GetString(); + dest = std::string(sstr.GetString()); } } return !dest.empty(); @@ -128,7 +128,7 @@ std::string TypeFormatImpl_Format::GetDescription() { Cascades() ? "" : " (not cascading)", SkipsPointers() ? " (skip pointers)" : "", SkipsReferences() ? " (skip references)" : ""); - return sstr.GetString(); + return std::string(sstr.GetString()); } TypeFormatImpl_EnumType::TypeFormatImpl_EnumType( @@ -191,7 +191,7 @@ bool TypeFormatImpl_EnumType::FormatObject(ValueObject *valobj, data.GetByteSize(), 0, 0, exe_ctx.GetBestExecutionContextScope()); if (!sstr.GetString().empty()) - dest = sstr.GetString(); + dest = std::string(sstr.GetString()); return !dest.empty(); } @@ -201,5 +201,5 @@ std::string TypeFormatImpl_EnumType::GetDescription() { Cascades() ? "" : " (not cascading)", SkipsPointers() ? " (skip pointers)" : "", SkipsReferences() ? " (skip references)" : ""); - return sstr.GetString(); + return std::string(sstr.GetString()); } diff --git a/lldb/source/DataFormatters/TypeSummary.cpp b/lldb/source/DataFormatters/TypeSummary.cpp index 7f6930fdf41f9..5d4fe2e467f85 100644 --- a/lldb/source/DataFormatters/TypeSummary.cpp +++ b/lldb/source/DataFormatters/TypeSummary.cpp @@ -1,4 +1,4 @@ -//===-- TypeSummary.cpp ----------------------------------------*- C++ -*-===// +//===-- TypeSummary.cpp ---------------------------------------------------===// // // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. // See https://llvm.org/LICENSE.txt for license information. @@ -83,13 +83,13 @@ bool StringSummaryFormat::FormatObject(ValueObject *valobj, std::string &retval, if (IsOneLiner()) { ValueObjectPrinter printer(valobj, &s, DumpValueObjectOptions()); printer.PrintChildrenOneLiner(HideNames(valobj)); - retval = s.GetString(); + retval = std::string(s.GetString()); return true; } else { if (FormatEntity::Format(m_format, s, &sc, &exe_ctx, &sc.line_entry.range.GetBaseAddress(), valobj, false, false)) { - retval.assign(s.GetString()); + retval.assign(std::string(s.GetString())); return true; } else { retval.assign("error: summary string parsing error"); @@ -111,7 +111,7 @@ std::string StringSummaryFormat::GetDescription() { SkipsPointers() ? " (skip pointers)" : "", SkipsReferences() ? " (skip references)" : "", HideNames(nullptr) ? " (hide member names)" : ""); - return sstr.GetString(); + return std::string(sstr.GetString()); } CXXFunctionSummaryFormat::CXXFunctionSummaryFormat( @@ -126,7 +126,7 @@ bool CXXFunctionSummaryFormat::FormatObject(ValueObject *valobj, StreamString stream; if (!m_impl || !m_impl(*valobj, stream, options)) return false; - dest = stream.GetString(); + dest = std::string(stream.GetString()); return true; } @@ -140,7 +140,7 @@ std::string CXXFunctionSummaryFormat::GetDescription() { SkipsReferences() ? " (skip references)" : "", HideNames(nullptr) ? " (hide member names)" : "", m_description.c_str()); - return sstr.GetString(); + return std::string(sstr.GetString()); } ScriptSummaryFormat::ScriptSummaryFormat(const TypeSummaryImpl::Flags &flags, @@ -197,5 +197,5 @@ std::string ScriptSummaryFormat::GetDescription() { } else { sstr.PutCString(m_python_script); } - return sstr.GetString(); + return std::string(sstr.GetString()); } diff --git a/lldb/source/DataFormatters/TypeSynthetic.cpp b/lldb/source/DataFormatters/TypeSynthetic.cpp index 23c80fc58d021..75388a93cc640 100644 --- a/lldb/source/DataFormatters/TypeSynthetic.cpp +++ b/lldb/source/DataFormatters/TypeSynthetic.cpp @@ -1,5 +1,4 @@ -//===-- TypeSynthetic.cpp ----------------------------------------*- C++ -//-*-===// +//===-- TypeSynthetic.cpp -------------------------------------------------===// // // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. // See https://llvm.org/LICENSE.txt for license information. @@ -82,7 +81,7 @@ std::string TypeFilterImpl::GetDescription() { } sstr.Printf("}"); - return sstr.GetString(); + return std::string(sstr.GetString()); } std::string CXXSyntheticChildren::GetDescription() { @@ -92,7 +91,7 @@ std::string CXXSyntheticChildren::GetDescription() { SkipsReferences() ? " (skip references)" : "", m_description.c_str()); - return sstr.GetString(); + return std::string(sstr.GetString()); } lldb::ValueObjectSP SyntheticChildrenFrontEnd::CreateValueObjectFromExpression( @@ -213,5 +212,5 @@ std::string ScriptedSyntheticChildren::GetDescription() { SkipsReferences() ? " (skip references)" : "", m_python_class.c_str()); - return sstr.GetString(); + return std::string(sstr.GetString()); } diff --git a/lldb/source/DataFormatters/ValueObjectPrinter.cpp b/lldb/source/DataFormatters/ValueObjectPrinter.cpp index 466cf398ec24c..c8a306334cf56 100644 --- a/lldb/source/DataFormatters/ValueObjectPrinter.cpp +++ b/lldb/source/DataFormatters/ValueObjectPrinter.cpp @@ -1,4 +1,4 @@ -//===-- ValueObjectPrinter.cpp -----------------------------------*- C++-*-===// +//===-- ValueObjectPrinter.cpp --------------------------------------------===// // // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. // See https://llvm.org/LICENSE.txt for license information. @@ -151,11 +151,11 @@ const char *ValueObjectPrinter::GetDescriptionForDisplay() { return str; } -const char *ValueObjectPrinter::GetRootNameForDisplay(const char *if_fail) { +const char *ValueObjectPrinter::GetRootNameForDisplay() { const char *root_valobj_name = m_options.m_root_valobj_name.empty() ? m_valobj->GetName().AsCString() : m_options.m_root_valobj_name.c_str(); - return root_valobj_name ? root_valobj_name : if_fail; + return root_valobj_name ? root_valobj_name : ""; } bool ValueObjectPrinter::ShouldPrintValueObject() { @@ -239,17 +239,14 @@ void ValueObjectPrinter::PrintDecl() { // type if there is one to print ConstString type_name; if (m_compiler_type.IsValid()) { - if (m_options.m_use_type_display_name) - type_name = m_valobj->GetDisplayTypeName(); - else - type_name = m_valobj->GetQualifiedTypeName(); + type_name = m_options.m_use_type_display_name + ? m_valobj->GetDisplayTypeName() + : m_valobj->GetQualifiedTypeName(); } else { // only show an invalid type name if the user explicitly triggered // show_type if (m_options.m_show_types) type_name = ConstString("<invalid type>"); - else - type_name.Clear(); } if (type_name) { @@ -260,21 +257,17 @@ void ValueObjectPrinter::PrintDecl() { type_name_str.erase(iter, 2); } } - typeName.Printf("%s", type_name_str.c_str()); + typeName << type_name_str.c_str(); } } StreamString varName; - if (m_options.m_flat_output) { - // If we are showing types, also qualify the C++ base classes - const bool qualify_cxx_base_classes = show_type; - if (!m_options.m_hide_name) { - m_valobj->GetExpressionPath(varName, qualify_cxx_base_classes); - } - } else if (!m_options.m_hide_name) { - const char *name_cstr = GetRootNameForDisplay(""); - varName.Printf("%s", name_cstr); + if (!m_options.m_hide_name) { + if (m_options.m_flat_output) + m_valobj->GetExpressionPath(varName); + else + varName << GetRootNameForDisplay(); } bool decl_printed = false; @@ -450,9 +443,9 @@ bool ValueObjectPrinter::PrintObjectDescriptionIfNeeded(bool value_printed, // If the description already ends with a \n don't add another one. size_t object_end = strlen(object_desc) - 1; if (object_desc[object_end] == '\n') - m_stream->Printf("%s", object_desc); + m_stream->Printf("%s", object_desc); else - m_stream->Printf("%s\n", object_desc); + m_stream->Printf("%s\n", object_desc); return true; } else if (!value_printed && !summary_printed) return true; diff --git a/lldb/source/DataFormatters/VectorType.cpp b/lldb/source/DataFormatters/VectorType.cpp index 26fc03a4cdc29..fd1c0bc96cd47 100644 --- a/lldb/source/DataFormatters/VectorType.cpp +++ b/lldb/source/DataFormatters/VectorType.cpp @@ -1,4 +1,4 @@ -//===-- VectorType.cpp ------------------------------------------*- C++ -*-===// +//===-- VectorType.cpp ----------------------------------------------------===// // // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. // See https://llvm.org/LICENSE.txt for license information. |