diff options
| author | Dimitry Andric <dim@FreeBSD.org> | 2023-12-09 13:28:42 +0000 |
|---|---|---|
| committer | Dimitry Andric <dim@FreeBSD.org> | 2023-12-09 13:28:42 +0000 |
| commit | b1c73532ee8997fe5dfbeb7d223027bdf99758a0 (patch) | |
| tree | 7d6e51c294ab6719475d660217aa0c0ad0526292 /lldb/source/DataFormatters | |
| parent | 7fa27ce4a07f19b07799a767fc29416f3b625afb (diff) | |
Diffstat (limited to 'lldb/source/DataFormatters')
| -rw-r--r-- | lldb/source/DataFormatters/CXXFunctionPointer.cpp | 6 | ||||
| -rw-r--r-- | lldb/source/DataFormatters/StringPrinter.cpp | 2 | ||||
| -rw-r--r-- | lldb/source/DataFormatters/TypeCategoryMap.cpp | 30 | ||||
| -rw-r--r-- | lldb/source/DataFormatters/TypeFormat.cpp | 6 | ||||
| -rw-r--r-- | lldb/source/DataFormatters/TypeSynthetic.cpp | 21 | ||||
| -rw-r--r-- | lldb/source/DataFormatters/VectorType.cpp | 63 |
6 files changed, 85 insertions, 43 deletions
diff --git a/lldb/source/DataFormatters/CXXFunctionPointer.cpp b/lldb/source/DataFormatters/CXXFunctionPointer.cpp index d7df280e56ef..6543433d17ff 100644 --- a/lldb/source/DataFormatters/CXXFunctionPointer.cpp +++ b/lldb/source/DataFormatters/CXXFunctionPointer.cpp @@ -13,6 +13,7 @@ #include "lldb/Target/SectionLoadList.h" #include "lldb/Target/Target.h" #include "lldb/Utility/Stream.h" +#include "lldb/lldb-enumerations.h" #include <string> @@ -76,7 +77,10 @@ bool lldb_private::formatters::CXXFunctionPointerSummaryProvider( } } if (sstr.GetSize() > 0) { - stream.Printf("(%s)", sstr.GetData()); + if (valobj.GetValueType() == lldb::eValueTypeVTableEntry) + stream.PutCString(sstr.GetData()); + else + stream.Printf("(%s)", sstr.GetData()); return true; } else return false; diff --git a/lldb/source/DataFormatters/StringPrinter.cpp b/lldb/source/DataFormatters/StringPrinter.cpp index 4b57e87b4ccd..ab07c74fd185 100644 --- a/lldb/source/DataFormatters/StringPrinter.cpp +++ b/lldb/source/DataFormatters/StringPrinter.cpp @@ -183,7 +183,7 @@ DecodedCharBuffer GetPrintableImpl<StringElementType::UTF8>( &buffer_for_conversion, buffer_end, &codepoint, llvm::strictConversion); assert(result == llvm::conversionOK && "Failed to convert legal utf8 sequence"); - (void)result; + UNUSED_IF_ASSERT_DISABLED(result); // The UTF8 helper always advances by the utf8 encoded length. const unsigned utf8_encoded_len = buffer_for_conversion - buffer; diff --git a/lldb/source/DataFormatters/TypeCategoryMap.cpp b/lldb/source/DataFormatters/TypeCategoryMap.cpp index 55635173cc8c..fd76bab95826 100644 --- a/lldb/source/DataFormatters/TypeCategoryMap.cpp +++ b/lldb/source/DataFormatters/TypeCategoryMap.cpp @@ -24,7 +24,7 @@ TypeCategoryMap::TypeCategoryMap(IFormatChangeListener *lst) Enable(default_cs, First); } -void TypeCategoryMap::Add(KeyType name, const ValueSP &entry) { +void TypeCategoryMap::Add(KeyType name, const TypeCategoryImplSP &entry) { std::lock_guard<std::recursive_mutex> guard(m_map_mutex); m_map[name] = entry; if (listener) @@ -45,7 +45,7 @@ bool TypeCategoryMap::Delete(KeyType name) { bool TypeCategoryMap::Enable(KeyType category_name, Position pos) { std::lock_guard<std::recursive_mutex> guard(m_map_mutex); - ValueSP category; + TypeCategoryImplSP category; if (!Get(category_name, category)) return false; return Enable(category, pos); @@ -53,13 +53,13 @@ bool TypeCategoryMap::Enable(KeyType category_name, Position pos) { bool TypeCategoryMap::Disable(KeyType category_name) { std::lock_guard<std::recursive_mutex> guard(m_map_mutex); - ValueSP category; + TypeCategoryImplSP category; if (!Get(category_name, category)) return false; return Disable(category); } -bool TypeCategoryMap::Enable(ValueSP category, Position pos) { +bool TypeCategoryMap::Enable(TypeCategoryImplSP category, Position pos) { std::lock_guard<std::recursive_mutex> guard(m_map_mutex); if (category.get()) { Position pos_w = pos; @@ -81,7 +81,7 @@ bool TypeCategoryMap::Enable(ValueSP category, Position pos) { return false; } -bool TypeCategoryMap::Disable(ValueSP category) { +bool TypeCategoryMap::Disable(TypeCategoryImplSP category) { std::lock_guard<std::recursive_mutex> guard(m_map_mutex); if (category.get()) { m_active_categories.remove_if(delete_matching_categories(category)); @@ -93,7 +93,7 @@ bool TypeCategoryMap::Disable(ValueSP category) { void TypeCategoryMap::EnableAllCategories() { std::lock_guard<std::recursive_mutex> guard(m_map_mutex); - std::vector<ValueSP> sorted_categories(m_map.size(), ValueSP()); + std::vector<TypeCategoryImplSP> sorted_categories(m_map.size(), TypeCategoryImplSP()); MapType::iterator iter = m_map.begin(), end = m_map.end(); for (; iter != end; ++iter) { if (iter->second->IsEnabled()) @@ -102,7 +102,7 @@ void TypeCategoryMap::EnableAllCategories() { if (pos >= sorted_categories.size()) { auto iter = std::find_if( sorted_categories.begin(), sorted_categories.end(), - [](const ValueSP &sp) -> bool { return sp.get() == nullptr; }); + [](const TypeCategoryImplSP &sp) -> bool { return sp.get() == nullptr; }); pos = std::distance(sorted_categories.begin(), iter); } sorted_categories.at(pos) = iter->second; @@ -130,7 +130,7 @@ void TypeCategoryMap::Clear() { listener->Changed(); } -bool TypeCategoryMap::Get(KeyType name, ValueSP &entry) { +bool TypeCategoryMap::Get(KeyType name, TypeCategoryImplSP &entry) { std::lock_guard<std::recursive_mutex> guard(m_map_mutex); MapIterator iter = m_map.find(name); if (iter == m_map.end()) @@ -139,20 +139,6 @@ bool TypeCategoryMap::Get(KeyType name, ValueSP &entry) { return true; } -bool TypeCategoryMap::Get(uint32_t pos, ValueSP &entry) { - std::lock_guard<std::recursive_mutex> guard(m_map_mutex); - MapIterator iter = m_map.begin(); - MapIterator end = m_map.end(); - while (pos > 0) { - iter++; - pos--; - if (iter == end) - return false; - } - entry = iter->second; - return false; -} - bool TypeCategoryMap::AnyMatches( const FormattersMatchCandidate &candidate_type, TypeCategoryImpl::FormatCategoryItems items, bool only_enabled, diff --git a/lldb/source/DataFormatters/TypeFormat.cpp b/lldb/source/DataFormatters/TypeFormat.cpp index 5ee89fc0d5eb..126240aeca65 100644 --- a/lldb/source/DataFormatters/TypeFormat.cpp +++ b/lldb/source/DataFormatters/TypeFormat.cpp @@ -81,9 +81,9 @@ bool TypeFormatImpl_Format::FormatObject(ValueObject *valobj, WritableDataBufferSP buffer_sp( new DataBufferHeap(max_len + 1, 0)); Address address(valobj->GetPointerValue()); - if (target_sp->ReadCStringFromMemory( - address, (char *)buffer_sp->GetBytes(), max_len, error) && - error.Success()) + target_sp->ReadCStringFromMemory( + address, (char *)buffer_sp->GetBytes(), max_len, error); + if (error.Success()) data.SetData(buffer_sp); } } diff --git a/lldb/source/DataFormatters/TypeSynthetic.cpp b/lldb/source/DataFormatters/TypeSynthetic.cpp index 2cca5d65f470..de042e474903 100644 --- a/lldb/source/DataFormatters/TypeSynthetic.cpp +++ b/lldb/source/DataFormatters/TypeSynthetic.cpp @@ -84,6 +84,27 @@ std::string TypeFilterImpl::GetDescription() { return std::string(sstr.GetString()); } +SyntheticChildren::SyntheticChildren(const Flags &flags) : m_flags(flags) {} + +SyntheticChildren::~SyntheticChildren() = default; + +CXXSyntheticChildren::CXXSyntheticChildren( + const SyntheticChildren::Flags &flags, const char *description, + CreateFrontEndCallback callback) + : SyntheticChildren(flags), m_create_callback(std::move(callback)), + m_description(description ? description : "") {} + +CXXSyntheticChildren::~CXXSyntheticChildren() = default; + +bool SyntheticChildren::IsScripted() { return false; } + +std::string SyntheticChildren::GetDescription() { return ""; } + +SyntheticChildrenFrontEnd::AutoPointer +SyntheticChildren::GetFrontEnd(ValueObject &backend) { + return nullptr; +} + std::string CXXSyntheticChildren::GetDescription() { StreamString sstr; sstr.Printf("%s%s%s %s", Cascades() ? "" : " (not cascading)", diff --git a/lldb/source/DataFormatters/VectorType.cpp b/lldb/source/DataFormatters/VectorType.cpp index 4afcfa2e8e49..57dae0b2c71f 100644 --- a/lldb/source/DataFormatters/VectorType.cpp +++ b/lldb/source/DataFormatters/VectorType.cpp @@ -169,21 +169,49 @@ static lldb::Format GetItemFormatForFormat(lldb::Format format, } } -static size_t CalculateNumChildren( - CompilerType container_type, CompilerType element_type, - lldb_private::ExecutionContextScope *exe_scope = - nullptr // does not matter here because all we trade in are basic types - ) { - std::optional<uint64_t> container_size = - container_type.GetByteSize(exe_scope); - std::optional<uint64_t> element_size = element_type.GetByteSize(exe_scope); +/// Calculates the number of elements stored in a container (with +/// element type 'container_elem_type') as if it had elements of type +/// 'element_type'. +/// +/// For example, a container of type +/// `uint8_t __attribute__((vector_size(16)))` has 16 elements. +/// But calling `CalculateNumChildren` with an 'element_type' +/// of `float` (4-bytes) will return `4` because we are interpreting +/// the byte-array as a `float32[]`. +/// +/// \param[in] container_elem_type The type of the elements stored +/// in the container we are calculating the children of. +/// +/// \param[in] num_elements Number of 'container_elem_type's our +/// container stores. +/// +/// \param[in] element_type The type of elements we interpret +/// container_type to contain for the purposes of calculating +/// the number of children. +/// +/// \returns The number of elements stored in a container of +/// type 'element_type'. Returns a std::nullopt if the +/// size of the container is not a multiple of 'element_type' +/// or if an error occurs. +static std::optional<size_t> +CalculateNumChildren(CompilerType container_elem_type, uint64_t num_elements, + CompilerType element_type) { + std::optional<uint64_t> container_elem_size = + container_elem_type.GetByteSize(/* exe_scope */ nullptr); + if (!container_elem_size) + return {}; - if (container_size && element_size && *element_size) { - if (*container_size % *element_size) - return 0; - return *container_size / *element_size; - } - return 0; + auto container_size = *container_elem_size * num_elements; + + std::optional<uint64_t> element_size = + element_type.GetByteSize(/* exe_scope */ nullptr); + if (!element_size || !*element_size) + return {}; + + if (container_size % *element_size) + return {}; + + return container_size / *element_size; } namespace lldb_private { @@ -221,11 +249,14 @@ public: m_parent_format = m_backend.GetFormat(); CompilerType parent_type(m_backend.GetCompilerType()); CompilerType element_type; - parent_type.IsVectorType(&element_type); + uint64_t num_elements; + parent_type.IsVectorType(&element_type, &num_elements); m_child_type = ::GetCompilerTypeForFormat( m_parent_format, element_type, parent_type.GetTypeSystem().GetSharedPointer()); - m_num_children = ::CalculateNumChildren(parent_type, m_child_type); + m_num_children = + ::CalculateNumChildren(element_type, num_elements, m_child_type) + .value_or(0); m_item_format = GetItemFormatForFormat(m_parent_format, m_child_type); return false; } |
