diff options
5 files changed, 99 insertions, 3 deletions
diff --git a/lldb/include/lldb/DataFormatters/CXXFormatterFunctions.h b/lldb/include/lldb/DataFormatters/CXXFormatterFunctions.h index 9b1a02ca0a5..a175e1a4d16 100644 --- a/lldb/include/lldb/DataFormatters/CXXFormatterFunctions.h +++ b/lldb/include/lldb/DataFormatters/CXXFormatterFunctions.h @@ -18,6 +18,7 @@ #include "lldb/Core/ConstString.h" #include "lldb/DataFormatters/FormatClasses.h" #include "lldb/DataFormatters/TypeSynthetic.h" +#include "lldb/DataFormatters/VectorType.h" #include "lldb/Target/ExecutionContext.h" #include "lldb/Target/ObjCLanguageRuntime.h" #include "lldb/Target/Target.h" diff --git a/lldb/include/lldb/DataFormatters/VectorType.h b/lldb/include/lldb/DataFormatters/VectorType.h index e69de29bb2d..56d0c6d90ec 100644 --- a/lldb/include/lldb/DataFormatters/VectorType.h +++ b/lldb/include/lldb/DataFormatters/VectorType.h @@ -0,0 +1,28 @@ +//===-- VectorType.h ------------------------------------*- C++ -*-===// +// +// The LLVM Compiler Infrastructure +// +// This file is distributed under the University of Illinois Open Source +// License. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +#ifndef liblldb_VectorType_h_ +#define liblldb_VectorType_h_ + +#include "lldb/lldb-forward.h" + +namespace lldb_private { + namespace formatters + { + bool + VectorTypeSummaryProvider (ValueObject&, + Stream&, + const TypeSummaryOptions&); + + SyntheticChildrenFrontEnd* + VectorTypeSyntheticFrontEndCreator (CXXSyntheticChildren*, lldb::ValueObjectSP); + } // namespace formatters +} // namespace lldb_private + +#endif // liblldb_VectorType_h_ diff --git a/lldb/source/DataFormatters/FormatManager.cpp b/lldb/source/DataFormatters/FormatManager.cpp index 47456ba5c45..4e0fffbe6a1 100644 --- a/lldb/source/DataFormatters/FormatManager.cpp +++ b/lldb/source/DataFormatters/FormatManager.cpp @@ -1608,6 +1608,26 @@ FormatManager::LoadHardcodedFormatters() } return nullptr; }); + m_hardcoded_summaries.push_back( + [](lldb_private::ValueObject& valobj, + lldb::DynamicValueType, + FormatManager& fmt_mgr) -> TypeSummaryImpl::SharedPointer { + static CXXFunctionSummaryFormat::SharedPointer formatter_sp(new CXXFunctionSummaryFormat(TypeSummaryImpl::Flags() + .SetCascades(true) + .SetDontShowChildren(true) + .SetHideItemNames(true) + .SetShowMembersOneLiner(true) + .SetSkipPointers(true) + .SetSkipReferences(false), + lldb_private::formatters::VectorTypeSummaryProvider, + "vector_type pointer summary provider")); + if (valobj.GetClangType().IsVectorType(nullptr, nullptr)) + { + if (fmt_mgr.GetCategory(fmt_mgr.m_vectortypes_category_name)->IsEnabled()) + return formatter_sp; + } + return nullptr; + }); } { // insert code to load synthetics here diff --git a/lldb/source/DataFormatters/VectorType.cpp b/lldb/source/DataFormatters/VectorType.cpp index 57bf696ba4f..316d7b540bc 100644 --- a/lldb/source/DataFormatters/VectorType.cpp +++ b/lldb/source/DataFormatters/VectorType.cpp @@ -7,9 +7,10 @@ // //===----------------------------------------------------------------------===// -#include "lldb/DataFormatters/CXXFormatterFunctions.h" +#include "lldb/DataFormatters/VectorType.h" #include "lldb/Core/ValueObject.h" +#include "lldb/DataFormatters/CXXFormatterFunctions.h" #include "lldb/Symbol/ClangASTContext.h" #include "lldb/Symbol/ClangASTType.h" @@ -267,6 +268,51 @@ namespace lldb_private { } } +bool +lldb_private::formatters::VectorTypeSummaryProvider (ValueObject& valobj, + Stream& s, + const TypeSummaryOptions&) +{ + auto synthetic_children = VectorTypeSyntheticFrontEndCreator(nullptr, valobj.GetSP()); + if (!synthetic_children) + return false; + + synthetic_children->Update(); + + s.PutChar('('); + bool first = true; + + size_t idx = 0, len = synthetic_children->CalculateNumChildren(); + + for (; + idx < len; + idx++) + { + auto child_sp = synthetic_children->GetChildAtIndex(idx); + if (!child_sp) + continue; + child_sp = child_sp->GetQualifiedRepresentationIfAvailable(lldb::eDynamicDontRunTarget, true); + + const char* child_value = child_sp->GetValueAsCString(); + if (child_value && *child_value) + { + if (first) + { + s.Printf("%s", child_value); + first = false; + } + else + { + s.Printf(", %s", child_value); + } + } + } + + s.PutChar(')'); + + return true; +} + lldb_private::SyntheticChildrenFrontEnd* lldb_private::formatters::VectorTypeSyntheticFrontEndCreator (CXXSyntheticChildren*, lldb::ValueObjectSP valobj_sp) { diff --git a/lldb/test/functionalities/data-formatter/vector-types/TestVectorTypesFormatting.py b/lldb/test/functionalities/data-formatter/vector-types/TestVectorTypesFormatting.py index 3bd2262f601..61f96312cd6 100644 --- a/lldb/test/functionalities/data-formatter/vector-types/TestVectorTypesFormatting.py +++ b/lldb/test/functionalities/data-formatter/vector-types/TestVectorTypesFormatting.py @@ -69,8 +69,9 @@ class VectorTypesFormattingTestCase(TestBase): self.assertTrue(v.GetChildAtIndex(2).GetData().float[0] == 2.50, "child 2 == 2.50") self.assertTrue(v.GetChildAtIndex(3).GetData().float[0] == 2.50, "child 3 == 2.50") - self.expect("expr -f int16_t[] -- v", substrs=['[0] = 0', '[1] = 16288', '[2] = 0', '[3] = 16288', '[4] = 0', '[5] = 16416', '[6] = 0', '[7] = 16416']) - self.expect("expr -f uint128_t[] -- v", substrs=['[0] = 85236745249553456609335044694184296448']) + self.expect("expr -f int16_t[] -- v", substrs=['(0, 16288, 0, 16288, 0, 16416, 0, 16416)']) + self.expect("expr -f uint128_t[] -- v", substrs=['(85236745249553456609335044694184296448)']) + self.expect("expr -f float32[] -- v", substrs=['(1.25, 1.25, 2.5, 2.5)']) oldValue = v.GetChildAtIndex(0).GetValue() v.SetFormat(lldb.eFormatHex) |