https://github.com/kuilpd updated https://github.com/llvm/llvm-project/pull/135843
>From 08834d47602b0df46e43678c08b3902d45145871 Mon Sep 17 00:00:00 2001 From: Ilia Kuklin <ikuk...@accesssoftek.com> Date: Wed, 16 Apr 2025 00:30:51 +0500 Subject: [PATCH 1/3] [lldb][TypeSystemClang] Add a function `IsValidDereferenceType` to TypeSystem to allow arrays to be dereferenced in C/C++. --- lldb/include/lldb/Symbol/CompilerType.h | 2 ++ lldb/include/lldb/Symbol/TypeSystem.h | 2 ++ lldb/source/Plugins/TypeSystem/Clang/TypeSystemClang.cpp | 9 +++++++++ lldb/source/Plugins/TypeSystem/Clang/TypeSystemClang.h | 2 ++ lldb/source/Symbol/CompilerType.cpp | 7 +++++++ lldb/source/ValueObject/ValueObject.cpp | 7 ++++--- 6 files changed, 26 insertions(+), 3 deletions(-) diff --git a/lldb/include/lldb/Symbol/CompilerType.h b/lldb/include/lldb/Symbol/CompilerType.h index 671b5314c24a2..6e37f9a64cbf4 100644 --- a/lldb/include/lldb/Symbol/CompilerType.h +++ b/lldb/include/lldb/Symbol/CompilerType.h @@ -186,6 +186,8 @@ class CompilerType { bool IsReferenceType(CompilerType *pointee_type = nullptr, bool *is_rvalue = nullptr) const; + bool IsValidDereferenceType() const; + bool ShouldTreatScalarValueAsAddress() const; bool IsScalarType() const; diff --git a/lldb/include/lldb/Symbol/TypeSystem.h b/lldb/include/lldb/Symbol/TypeSystem.h index 9e9edc09a0846..7a568098ac4a3 100644 --- a/lldb/include/lldb/Symbol/TypeSystem.h +++ b/lldb/include/lldb/Symbol/TypeSystem.h @@ -486,6 +486,8 @@ class TypeSystem : public PluginInterface, virtual bool IsReferenceType(lldb::opaque_compiler_type_t type, CompilerType *pointee_type, bool *is_rvalue) = 0; + virtual bool IsValidDereferenceType(lldb::opaque_compiler_type_t type) = 0; + virtual bool ShouldTreatScalarValueAsAddress(lldb::opaque_compiler_type_t type) { return IsPointerOrReferenceType(type, nullptr); diff --git a/lldb/source/Plugins/TypeSystem/Clang/TypeSystemClang.cpp b/lldb/source/Plugins/TypeSystem/Clang/TypeSystemClang.cpp index 59292f4b24af3..0859614691c69 100644 --- a/lldb/source/Plugins/TypeSystem/Clang/TypeSystemClang.cpp +++ b/lldb/source/Plugins/TypeSystem/Clang/TypeSystemClang.cpp @@ -3443,6 +3443,13 @@ bool TypeSystemClang::IsReferenceType(lldb::opaque_compiler_type_t type, return false; } +bool TypeSystemClang::IsValidDereferenceType( + lldb::opaque_compiler_type_t type) { + CompilerType compiler_type = GetType(clang::QualType::getFromOpaquePtr(type)); + return compiler_type.IsPointerOrReferenceType() || + compiler_type.IsArrayType(); +} + bool TypeSystemClang::IsFloatingPointType(lldb::opaque_compiler_type_t type, uint32_t &count, bool &is_complex) { if (type) { @@ -6565,6 +6572,8 @@ llvm::Expected<CompilerType> TypeSystemClang::GetChildCompilerTypeAtIndex( return size_or_err.takeError(); child_byte_size = *size_or_err; child_byte_offset = (int32_t)idx * (int32_t)child_byte_size; + if (idx == 0) + child_is_deref_of_parent = true; return element_type; } } diff --git a/lldb/source/Plugins/TypeSystem/Clang/TypeSystemClang.h b/lldb/source/Plugins/TypeSystem/Clang/TypeSystemClang.h index 442f88a5b79ae..5026e26041afd 100644 --- a/lldb/source/Plugins/TypeSystem/Clang/TypeSystemClang.h +++ b/lldb/source/Plugins/TypeSystem/Clang/TypeSystemClang.h @@ -716,6 +716,8 @@ class TypeSystemClang : public TypeSystem { bool IsReferenceType(lldb::opaque_compiler_type_t type, CompilerType *pointee_type, bool *is_rvalue) override; + bool IsValidDereferenceType(lldb::opaque_compiler_type_t type) override; + bool IsScalarType(lldb::opaque_compiler_type_t type) override; bool IsTypedefType(lldb::opaque_compiler_type_t type) override; diff --git a/lldb/source/Symbol/CompilerType.cpp b/lldb/source/Symbol/CompilerType.cpp index 8e89d006d08d3..789ff7ae262f0 100644 --- a/lldb/source/Symbol/CompilerType.cpp +++ b/lldb/source/Symbol/CompilerType.cpp @@ -233,6 +233,13 @@ bool CompilerType::IsReferenceType(CompilerType *pointee_type, return false; } +bool CompilerType::IsValidDereferenceType() const { + if (IsValid()) + if (auto type_system_sp = GetTypeSystem()) + return type_system_sp->IsValidDereferenceType(m_type); + return false; +} + bool CompilerType::ShouldTreatScalarValueAsAddress() const { if (IsValid()) if (auto type_system_sp = GetTypeSystem()) diff --git a/lldb/source/ValueObject/ValueObject.cpp b/lldb/source/ValueObject/ValueObject.cpp index 8741cb7343166..f999812f3b7be 100644 --- a/lldb/source/ValueObject/ValueObject.cpp +++ b/lldb/source/ValueObject/ValueObject.cpp @@ -2850,8 +2850,9 @@ ValueObjectSP ValueObject::Dereference(Status &error) { if (m_deref_valobj) return m_deref_valobj->GetSP(); - const bool is_pointer_or_reference_type = IsPointerOrReferenceType(); - if (is_pointer_or_reference_type) { + const bool is_valid_dereference_type = + GetCompilerType().IsValidDereferenceType(); + if (is_valid_dereference_type) { bool omit_empty_base_classes = true; bool ignore_array_bounds = false; @@ -2930,7 +2931,7 @@ ValueObjectSP ValueObject::Dereference(Status &error) { StreamString strm; GetExpressionPath(strm); - if (is_pointer_or_reference_type) + if (is_valid_dereference_type) error = Status::FromErrorStringWithFormat( "dereference failed: (%s) %s", GetTypeName().AsCString("<invalid type>"), strm.GetData()); >From ca4543607707784f1151efe8fdbf4db172be8e05 Mon Sep 17 00:00:00 2001 From: Ilia Kuklin <ikuk...@accesssoftek.com> Date: Thu, 24 Apr 2025 03:34:11 +0500 Subject: [PATCH 2/3] Add a function `GetDereferencedType` instead. --- lldb/include/lldb/Symbol/CompilerType.h | 11 +++- lldb/include/lldb/Symbol/TypeSystem.h | 11 +++- .../TypeSystem/Clang/TypeSystemClang.cpp | 26 +++++--- .../TypeSystem/Clang/TypeSystemClang.h | 11 +++- lldb/source/Symbol/CompilerType.cpp | 26 +++++--- lldb/source/ValueObject/ValueObject.cpp | 59 +++++++++---------- 6 files changed, 94 insertions(+), 50 deletions(-) diff --git a/lldb/include/lldb/Symbol/CompilerType.h b/lldb/include/lldb/Symbol/CompilerType.h index 6e37f9a64cbf4..36c37bdf7fea2 100644 --- a/lldb/include/lldb/Symbol/CompilerType.h +++ b/lldb/include/lldb/Symbol/CompilerType.h @@ -186,8 +186,6 @@ class CompilerType { bool IsReferenceType(CompilerType *pointee_type = nullptr, bool *is_rvalue = nullptr) const; - bool IsValidDereferenceType() const; - bool ShouldTreatScalarValueAsAddress() const; bool IsScalarType() const; @@ -435,6 +433,15 @@ class CompilerType { CompilerDecl GetStaticFieldWithName(llvm::StringRef name) const; + llvm::Expected<CompilerType> GetDereferencedType( + ExecutionContext *exe_ctx, bool transparent_pointers, + bool omit_empty_base_classes, bool ignore_array_bounds, + std::string &child_name, uint32_t &child_byte_size, + int32_t &child_byte_offset, uint32_t &child_bitfield_bit_size, + uint32_t &child_bitfield_bit_offset, bool &child_is_base_class, + bool &child_is_deref_of_parent, ValueObject *valobj, + uint64_t &language_flags, bool &type_valid) const; + llvm::Expected<CompilerType> GetChildCompilerTypeAtIndex( ExecutionContext *exe_ctx, size_t idx, bool transparent_pointers, bool omit_empty_base_classes, bool ignore_array_bounds, diff --git a/lldb/include/lldb/Symbol/TypeSystem.h b/lldb/include/lldb/Symbol/TypeSystem.h index 7a568098ac4a3..2fb831cef4705 100644 --- a/lldb/include/lldb/Symbol/TypeSystem.h +++ b/lldb/include/lldb/Symbol/TypeSystem.h @@ -364,6 +364,15 @@ class TypeSystem : public PluginInterface, return CompilerDecl(); } + virtual llvm::Expected<CompilerType> GetDereferencedType( + lldb::opaque_compiler_type_t type, ExecutionContext *exe_ctx, + bool transparent_pointers, bool omit_empty_base_classes, + bool ignore_array_bounds, std::string &child_name, + uint32_t &child_byte_size, int32_t &child_byte_offset, + uint32_t &child_bitfield_bit_size, uint32_t &child_bitfield_bit_offset, + bool &child_is_base_class, bool &child_is_deref_of_parent, + ValueObject *valobj, uint64_t &language_flags, bool &type_valid) = 0; + virtual llvm::Expected<CompilerType> GetChildCompilerTypeAtIndex( lldb::opaque_compiler_type_t type, ExecutionContext *exe_ctx, size_t idx, bool transparent_pointers, bool omit_empty_base_classes, @@ -486,8 +495,6 @@ class TypeSystem : public PluginInterface, virtual bool IsReferenceType(lldb::opaque_compiler_type_t type, CompilerType *pointee_type, bool *is_rvalue) = 0; - virtual bool IsValidDereferenceType(lldb::opaque_compiler_type_t type) = 0; - virtual bool ShouldTreatScalarValueAsAddress(lldb::opaque_compiler_type_t type) { return IsPointerOrReferenceType(type, nullptr); diff --git a/lldb/source/Plugins/TypeSystem/Clang/TypeSystemClang.cpp b/lldb/source/Plugins/TypeSystem/Clang/TypeSystemClang.cpp index 0859614691c69..af5becd2ef4d2 100644 --- a/lldb/source/Plugins/TypeSystem/Clang/TypeSystemClang.cpp +++ b/lldb/source/Plugins/TypeSystem/Clang/TypeSystemClang.cpp @@ -3443,13 +3443,6 @@ bool TypeSystemClang::IsReferenceType(lldb::opaque_compiler_type_t type, return false; } -bool TypeSystemClang::IsValidDereferenceType( - lldb::opaque_compiler_type_t type) { - CompilerType compiler_type = GetType(clang::QualType::getFromOpaquePtr(type)); - return compiler_type.IsPointerOrReferenceType() || - compiler_type.IsArrayType(); -} - bool TypeSystemClang::IsFloatingPointType(lldb::opaque_compiler_type_t type, uint32_t &count, bool &is_complex) { if (type) { @@ -6208,6 +6201,25 @@ uint32_t TypeSystemClang::GetNumPointeeChildren(clang::QualType type) { return 0; } +llvm::Expected<CompilerType> TypeSystemClang::GetDereferencedType( + lldb::opaque_compiler_type_t type, ExecutionContext *exe_ctx, + bool transparent_pointers, bool omit_empty_base_classes, + bool ignore_array_bounds, std::string &child_name, + uint32_t &child_byte_size, int32_t &child_byte_offset, + uint32_t &child_bitfield_bit_size, uint32_t &child_bitfield_bit_offset, + bool &child_is_base_class, bool &child_is_deref_of_parent, + ValueObject *valobj, uint64_t &language_flags, bool &type_valid) { + type_valid = IsPointerOrReferenceType(type, nullptr) || + IsArrayType(type, nullptr, nullptr, nullptr); + if (!type_valid) + return CompilerType(); + return GetChildCompilerTypeAtIndex( + type, exe_ctx, 0, transparent_pointers, omit_empty_base_classes, + ignore_array_bounds, child_name, child_byte_size, child_byte_offset, + child_bitfield_bit_size, child_bitfield_bit_offset, child_is_base_class, + child_is_deref_of_parent, valobj, language_flags); +} + llvm::Expected<CompilerType> TypeSystemClang::GetChildCompilerTypeAtIndex( lldb::opaque_compiler_type_t type, ExecutionContext *exe_ctx, size_t idx, bool transparent_pointers, bool omit_empty_base_classes, diff --git a/lldb/source/Plugins/TypeSystem/Clang/TypeSystemClang.h b/lldb/source/Plugins/TypeSystem/Clang/TypeSystemClang.h index 5026e26041afd..384129c57e393 100644 --- a/lldb/source/Plugins/TypeSystem/Clang/TypeSystemClang.h +++ b/lldb/source/Plugins/TypeSystem/Clang/TypeSystemClang.h @@ -716,8 +716,6 @@ class TypeSystemClang : public TypeSystem { bool IsReferenceType(lldb::opaque_compiler_type_t type, CompilerType *pointee_type, bool *is_rvalue) override; - bool IsValidDereferenceType(lldb::opaque_compiler_type_t type) override; - bool IsScalarType(lldb::opaque_compiler_type_t type) override; bool IsTypedefType(lldb::opaque_compiler_type_t type) override; @@ -891,6 +889,15 @@ class TypeSystemClang : public TypeSystem { static uint32_t GetNumPointeeChildren(clang::QualType type); + llvm::Expected<CompilerType> GetDereferencedType( + lldb::opaque_compiler_type_t type, ExecutionContext *exe_ctx, + bool transparent_pointers, bool omit_empty_base_classes, + bool ignore_array_bounds, std::string &child_name, + uint32_t &child_byte_size, int32_t &child_byte_offset, + uint32_t &child_bitfield_bit_size, uint32_t &child_bitfield_bit_offset, + bool &child_is_base_class, bool &child_is_deref_of_parent, + ValueObject *valobj, uint64_t &language_flags, bool &type_valid) override; + llvm::Expected<CompilerType> GetChildCompilerTypeAtIndex( lldb::opaque_compiler_type_t type, ExecutionContext *exe_ctx, size_t idx, bool transparent_pointers, bool omit_empty_base_classes, diff --git a/lldb/source/Symbol/CompilerType.cpp b/lldb/source/Symbol/CompilerType.cpp index 789ff7ae262f0..c5bb172013c27 100644 --- a/lldb/source/Symbol/CompilerType.cpp +++ b/lldb/source/Symbol/CompilerType.cpp @@ -233,13 +233,6 @@ bool CompilerType::IsReferenceType(CompilerType *pointee_type, return false; } -bool CompilerType::IsValidDereferenceType() const { - if (IsValid()) - if (auto type_system_sp = GetTypeSystem()) - return type_system_sp->IsValidDereferenceType(m_type); - return false; -} - bool CompilerType::ShouldTreatScalarValueAsAddress() const { if (IsValid()) if (auto type_system_sp = GetTypeSystem()) @@ -900,6 +893,25 @@ CompilerDecl CompilerType::GetStaticFieldWithName(llvm::StringRef name) const { return CompilerDecl(); } +llvm::Expected<CompilerType> CompilerType::GetDereferencedType( + ExecutionContext *exe_ctx, bool transparent_pointers, + bool omit_empty_base_classes, bool ignore_array_bounds, + std::string &child_name, uint32_t &child_byte_size, + int32_t &child_byte_offset, uint32_t &child_bitfield_bit_size, + uint32_t &child_bitfield_bit_offset, bool &child_is_base_class, + bool &child_is_deref_of_parent, ValueObject *valobj, + uint64_t &language_flags, bool &type_valid) const { + if (IsValid()) + if (auto type_system_sp = GetTypeSystem()) + return type_system_sp->GetDereferencedType( + m_type, exe_ctx, transparent_pointers, omit_empty_base_classes, + ignore_array_bounds, child_name, child_byte_size, child_byte_offset, + child_bitfield_bit_size, child_bitfield_bit_offset, + child_is_base_class, child_is_deref_of_parent, valobj, language_flags, + type_valid); + return CompilerType(); +} + llvm::Expected<CompilerType> CompilerType::GetChildCompilerTypeAtIndex( ExecutionContext *exe_ctx, size_t idx, bool transparent_pointers, bool omit_empty_base_classes, bool ignore_array_bounds, diff --git a/lldb/source/ValueObject/ValueObject.cpp b/lldb/source/ValueObject/ValueObject.cpp index f999812f3b7be..c1d2a89076739 100644 --- a/lldb/source/ValueObject/ValueObject.cpp +++ b/lldb/source/ValueObject/ValueObject.cpp @@ -2850,38 +2850,38 @@ ValueObjectSP ValueObject::Dereference(Status &error) { if (m_deref_valobj) return m_deref_valobj->GetSP(); - const bool is_valid_dereference_type = - GetCompilerType().IsValidDereferenceType(); - if (is_valid_dereference_type) { - bool omit_empty_base_classes = true; - bool ignore_array_bounds = false; - - std::string child_name_str; - uint32_t child_byte_size = 0; - int32_t child_byte_offset = 0; - uint32_t child_bitfield_bit_size = 0; - uint32_t child_bitfield_bit_offset = 0; - bool child_is_base_class = false; - bool child_is_deref_of_parent = false; - const bool transparent_pointers = false; - CompilerType compiler_type = GetCompilerType(); - uint64_t language_flags = 0; + bool omit_empty_base_classes = true; + bool ignore_array_bounds = false; + std::string child_name_str; + uint32_t child_byte_size = 0; + int32_t child_byte_offset = 0; + uint32_t child_bitfield_bit_size = 0; + uint32_t child_bitfield_bit_offset = 0; + bool child_is_base_class = false; + bool child_is_deref_of_parent = false; + const bool transparent_pointers = false; + CompilerType compiler_type = GetCompilerType(); + uint64_t language_flags = 0; + bool is_valid_dereference_type = false; - ExecutionContext exe_ctx(GetExecutionContextRef()); + ExecutionContext exe_ctx(GetExecutionContextRef()); - CompilerType child_compiler_type; - auto child_compiler_type_or_err = compiler_type.GetChildCompilerTypeAtIndex( - &exe_ctx, 0, transparent_pointers, omit_empty_base_classes, - ignore_array_bounds, child_name_str, child_byte_size, child_byte_offset, - child_bitfield_bit_size, child_bitfield_bit_offset, child_is_base_class, - child_is_deref_of_parent, this, language_flags); - if (!child_compiler_type_or_err) - LLDB_LOG_ERROR(GetLog(LLDBLog::Types), - child_compiler_type_or_err.takeError(), - "could not find child: {0}"); - else - child_compiler_type = *child_compiler_type_or_err; + CompilerType child_compiler_type; + auto child_compiler_type_or_err = compiler_type.GetDereferencedType( + &exe_ctx, transparent_pointers, omit_empty_base_classes, + ignore_array_bounds, child_name_str, child_byte_size, child_byte_offset, + child_bitfield_bit_size, child_bitfield_bit_offset, child_is_base_class, + child_is_deref_of_parent, this, language_flags, + is_valid_dereference_type); + if (!child_compiler_type_or_err && is_valid_dereference_type) + LLDB_LOG_ERROR(GetLog(LLDBLog::Types), + child_compiler_type_or_err.takeError(), + "could not find child: {0}"); + else + child_compiler_type = *child_compiler_type_or_err; + + if (is_valid_dereference_type) { if (child_compiler_type && child_byte_size) { ConstString child_name; if (!child_name_str.empty()) @@ -2916,7 +2916,6 @@ ValueObjectSP ValueObject::Dereference(Status &error) { } } } - } else if (HasSyntheticValue()) { m_deref_valobj = GetSyntheticValue()->GetChildMemberWithName("$$dereference$$").get(); >From 0d5348a4c2b5e24255a6101d5a0adf43386e0f4b Mon Sep 17 00:00:00 2001 From: Ilia Kuklin <ikuk...@accesssoftek.com> Date: Thu, 24 Apr 2025 21:31:06 +0500 Subject: [PATCH 3/3] Remove unnecessary arguments, add error output from `GetDereferencedType`. --- lldb/include/lldb/Symbol/CompilerType.h | 15 ++++---- lldb/include/lldb/Symbol/TypeSystem.h | 8 ++--- .../TypeSystem/Clang/TypeSystemClang.cpp | 20 +++++------ .../TypeSystem/Clang/TypeSystemClang.h | 8 ++--- lldb/source/Symbol/CompilerType.cpp | 18 ++++------ lldb/source/ValueObject/ValueObject.cpp | 36 +++++++++---------- .../TestDataFormatterGenericOptional.py | 2 +- 7 files changed, 46 insertions(+), 61 deletions(-) diff --git a/lldb/include/lldb/Symbol/CompilerType.h b/lldb/include/lldb/Symbol/CompilerType.h index 36c37bdf7fea2..f02a415afd12c 100644 --- a/lldb/include/lldb/Symbol/CompilerType.h +++ b/lldb/include/lldb/Symbol/CompilerType.h @@ -433,14 +433,13 @@ class CompilerType { CompilerDecl GetStaticFieldWithName(llvm::StringRef name) const; - llvm::Expected<CompilerType> GetDereferencedType( - ExecutionContext *exe_ctx, bool transparent_pointers, - bool omit_empty_base_classes, bool ignore_array_bounds, - std::string &child_name, uint32_t &child_byte_size, - int32_t &child_byte_offset, uint32_t &child_bitfield_bit_size, - uint32_t &child_bitfield_bit_offset, bool &child_is_base_class, - bool &child_is_deref_of_parent, ValueObject *valobj, - uint64_t &language_flags, bool &type_valid) const; + llvm::Expected<CompilerType> + GetDereferencedType(ExecutionContext *exe_ctx, std::string &child_name, + uint32_t &child_byte_size, int32_t &child_byte_offset, + uint32_t &child_bitfield_bit_size, + uint32_t &child_bitfield_bit_offset, + bool &child_is_base_class, ValueObject *valobj, + uint64_t &language_flags, bool &type_valid) const; llvm::Expected<CompilerType> GetChildCompilerTypeAtIndex( ExecutionContext *exe_ctx, size_t idx, bool transparent_pointers, diff --git a/lldb/include/lldb/Symbol/TypeSystem.h b/lldb/include/lldb/Symbol/TypeSystem.h index 2fb831cef4705..7c58805342993 100644 --- a/lldb/include/lldb/Symbol/TypeSystem.h +++ b/lldb/include/lldb/Symbol/TypeSystem.h @@ -366,11 +366,9 @@ class TypeSystem : public PluginInterface, virtual llvm::Expected<CompilerType> GetDereferencedType( lldb::opaque_compiler_type_t type, ExecutionContext *exe_ctx, - bool transparent_pointers, bool omit_empty_base_classes, - bool ignore_array_bounds, std::string &child_name, - uint32_t &child_byte_size, int32_t &child_byte_offset, - uint32_t &child_bitfield_bit_size, uint32_t &child_bitfield_bit_offset, - bool &child_is_base_class, bool &child_is_deref_of_parent, + std::string &child_name, uint32_t &child_byte_size, + int32_t &child_byte_offset, uint32_t &child_bitfield_bit_size, + uint32_t &child_bitfield_bit_offset, bool &child_is_base_class, ValueObject *valobj, uint64_t &language_flags, bool &type_valid) = 0; virtual llvm::Expected<CompilerType> GetChildCompilerTypeAtIndex( diff --git a/lldb/source/Plugins/TypeSystem/Clang/TypeSystemClang.cpp b/lldb/source/Plugins/TypeSystem/Clang/TypeSystemClang.cpp index af5becd2ef4d2..5c1b98509892e 100644 --- a/lldb/source/Plugins/TypeSystem/Clang/TypeSystemClang.cpp +++ b/lldb/source/Plugins/TypeSystem/Clang/TypeSystemClang.cpp @@ -6203,21 +6203,19 @@ uint32_t TypeSystemClang::GetNumPointeeChildren(clang::QualType type) { llvm::Expected<CompilerType> TypeSystemClang::GetDereferencedType( lldb::opaque_compiler_type_t type, ExecutionContext *exe_ctx, - bool transparent_pointers, bool omit_empty_base_classes, - bool ignore_array_bounds, std::string &child_name, - uint32_t &child_byte_size, int32_t &child_byte_offset, - uint32_t &child_bitfield_bit_size, uint32_t &child_bitfield_bit_offset, - bool &child_is_base_class, bool &child_is_deref_of_parent, + std::string &child_name, uint32_t &child_byte_size, + int32_t &child_byte_offset, uint32_t &child_bitfield_bit_size, + uint32_t &child_bitfield_bit_offset, bool &child_is_base_class, ValueObject *valobj, uint64_t &language_flags, bool &type_valid) { type_valid = IsPointerOrReferenceType(type, nullptr) || IsArrayType(type, nullptr, nullptr, nullptr); if (!type_valid) - return CompilerType(); + return llvm::createStringError("not a pointer, reference or array type"); + bool child_is_deref_of_parent; return GetChildCompilerTypeAtIndex( - type, exe_ctx, 0, transparent_pointers, omit_empty_base_classes, - ignore_array_bounds, child_name, child_byte_size, child_byte_offset, - child_bitfield_bit_size, child_bitfield_bit_offset, child_is_base_class, - child_is_deref_of_parent, valobj, language_flags); + type, exe_ctx, 0, false, true, false, child_name, child_byte_size, + child_byte_offset, child_bitfield_bit_size, child_bitfield_bit_offset, + child_is_base_class, child_is_deref_of_parent, valobj, language_flags); } llvm::Expected<CompilerType> TypeSystemClang::GetChildCompilerTypeAtIndex( @@ -6584,8 +6582,6 @@ llvm::Expected<CompilerType> TypeSystemClang::GetChildCompilerTypeAtIndex( return size_or_err.takeError(); child_byte_size = *size_or_err; child_byte_offset = (int32_t)idx * (int32_t)child_byte_size; - if (idx == 0) - child_is_deref_of_parent = true; return element_type; } } diff --git a/lldb/source/Plugins/TypeSystem/Clang/TypeSystemClang.h b/lldb/source/Plugins/TypeSystem/Clang/TypeSystemClang.h index 384129c57e393..ab74027cc75c4 100644 --- a/lldb/source/Plugins/TypeSystem/Clang/TypeSystemClang.h +++ b/lldb/source/Plugins/TypeSystem/Clang/TypeSystemClang.h @@ -891,11 +891,9 @@ class TypeSystemClang : public TypeSystem { llvm::Expected<CompilerType> GetDereferencedType( lldb::opaque_compiler_type_t type, ExecutionContext *exe_ctx, - bool transparent_pointers, bool omit_empty_base_classes, - bool ignore_array_bounds, std::string &child_name, - uint32_t &child_byte_size, int32_t &child_byte_offset, - uint32_t &child_bitfield_bit_size, uint32_t &child_bitfield_bit_offset, - bool &child_is_base_class, bool &child_is_deref_of_parent, + std::string &child_name, uint32_t &child_byte_size, + int32_t &child_byte_offset, uint32_t &child_bitfield_bit_size, + uint32_t &child_bitfield_bit_offset, bool &child_is_base_class, ValueObject *valobj, uint64_t &language_flags, bool &type_valid) override; llvm::Expected<CompilerType> GetChildCompilerTypeAtIndex( diff --git a/lldb/source/Symbol/CompilerType.cpp b/lldb/source/Symbol/CompilerType.cpp index c5bb172013c27..998822708fe21 100644 --- a/lldb/source/Symbol/CompilerType.cpp +++ b/lldb/source/Symbol/CompilerType.cpp @@ -894,21 +894,17 @@ CompilerDecl CompilerType::GetStaticFieldWithName(llvm::StringRef name) const { } llvm::Expected<CompilerType> CompilerType::GetDereferencedType( - ExecutionContext *exe_ctx, bool transparent_pointers, - bool omit_empty_base_classes, bool ignore_array_bounds, - std::string &child_name, uint32_t &child_byte_size, - int32_t &child_byte_offset, uint32_t &child_bitfield_bit_size, - uint32_t &child_bitfield_bit_offset, bool &child_is_base_class, - bool &child_is_deref_of_parent, ValueObject *valobj, - uint64_t &language_flags, bool &type_valid) const { + ExecutionContext *exe_ctx, std::string &child_name, + uint32_t &child_byte_size, int32_t &child_byte_offset, + uint32_t &child_bitfield_bit_size, uint32_t &child_bitfield_bit_offset, + bool &child_is_base_class, ValueObject *valobj, uint64_t &language_flags, + bool &type_valid) const { if (IsValid()) if (auto type_system_sp = GetTypeSystem()) return type_system_sp->GetDereferencedType( - m_type, exe_ctx, transparent_pointers, omit_empty_base_classes, - ignore_array_bounds, child_name, child_byte_size, child_byte_offset, + m_type, exe_ctx, child_name, child_byte_size, child_byte_offset, child_bitfield_bit_size, child_bitfield_bit_offset, - child_is_base_class, child_is_deref_of_parent, valobj, language_flags, - type_valid); + child_is_base_class, valobj, language_flags, type_valid); return CompilerType(); } diff --git a/lldb/source/ValueObject/ValueObject.cpp b/lldb/source/ValueObject/ValueObject.cpp index c1d2a89076739..b023dbf118d78 100644 --- a/lldb/source/ValueObject/ValueObject.cpp +++ b/lldb/source/ValueObject/ValueObject.cpp @@ -2850,16 +2850,12 @@ ValueObjectSP ValueObject::Dereference(Status &error) { if (m_deref_valobj) return m_deref_valobj->GetSP(); - bool omit_empty_base_classes = true; - bool ignore_array_bounds = false; std::string child_name_str; uint32_t child_byte_size = 0; int32_t child_byte_offset = 0; uint32_t child_bitfield_bit_size = 0; uint32_t child_bitfield_bit_offset = 0; bool child_is_base_class = false; - bool child_is_deref_of_parent = false; - const bool transparent_pointers = false; CompilerType compiler_type = GetCompilerType(); uint64_t language_flags = 0; bool is_valid_dereference_type = false; @@ -2868,17 +2864,20 @@ ValueObjectSP ValueObject::Dereference(Status &error) { CompilerType child_compiler_type; auto child_compiler_type_or_err = compiler_type.GetDereferencedType( - &exe_ctx, transparent_pointers, omit_empty_base_classes, - ignore_array_bounds, child_name_str, child_byte_size, child_byte_offset, + &exe_ctx, child_name_str, child_byte_size, child_byte_offset, child_bitfield_bit_size, child_bitfield_bit_offset, child_is_base_class, - child_is_deref_of_parent, this, language_flags, - is_valid_dereference_type); + this, language_flags, is_valid_dereference_type); - if (!child_compiler_type_or_err && is_valid_dereference_type) - LLDB_LOG_ERROR(GetLog(LLDBLog::Types), - child_compiler_type_or_err.takeError(), - "could not find child: {0}"); - else + std::string deref_error; + if (!child_compiler_type_or_err) { + auto err = child_compiler_type_or_err.takeError(); + if (err.isA<llvm::StringError>()) { + deref_error = llvm::toString(std::move(err)); + LLDB_LOG_ERROR(GetLog(LLDBLog::Types), + llvm::createStringError(deref_error), + "could not find child: {0}"); + } + } else child_compiler_type = *child_compiler_type_or_err; if (is_valid_dereference_type) { @@ -2890,8 +2889,7 @@ ValueObjectSP ValueObject::Dereference(Status &error) { m_deref_valobj = new ValueObjectChild( *this, child_compiler_type, child_name, child_byte_size, child_byte_offset, child_bitfield_bit_size, child_bitfield_bit_offset, - child_is_base_class, child_is_deref_of_parent, eAddressTypeInvalid, - language_flags); + child_is_base_class, true, eAddressTypeInvalid, language_flags); } // In case of incomplete child compiler type, use the pointee type and try @@ -2911,8 +2909,8 @@ ValueObjectSP ValueObject::Dereference(Status &error) { m_deref_valobj = new ValueObjectChild( *this, child_compiler_type, child_name, child_byte_size, child_byte_offset, child_bitfield_bit_size, - child_bitfield_bit_offset, child_is_base_class, - child_is_deref_of_parent, eAddressTypeInvalid, language_flags); + child_bitfield_bit_offset, child_is_base_class, true, + eAddressTypeInvalid, language_flags); } } } @@ -2930,13 +2928,13 @@ ValueObjectSP ValueObject::Dereference(Status &error) { StreamString strm; GetExpressionPath(strm); - if (is_valid_dereference_type) + if (deref_error.empty()) error = Status::FromErrorStringWithFormat( "dereference failed: (%s) %s", GetTypeName().AsCString("<invalid type>"), strm.GetData()); else error = Status::FromErrorStringWithFormat( - "not a pointer or reference type: (%s) %s", + "dereference failed: %s: (%s) %s", deref_error.c_str(), GetTypeName().AsCString("<invalid type>"), strm.GetData()); return ValueObjectSP(); } diff --git a/lldb/test/API/functionalities/data-formatter/data-formatter-stl/generic/optional/TestDataFormatterGenericOptional.py b/lldb/test/API/functionalities/data-formatter/data-formatter-stl/generic/optional/TestDataFormatterGenericOptional.py index 7dc656a7ae225..8f36edea7d727 100644 --- a/lldb/test/API/functionalities/data-formatter/data-formatter-stl/generic/optional/TestDataFormatterGenericOptional.py +++ b/lldb/test/API/functionalities/data-formatter/data-formatter-stl/generic/optional/TestDataFormatterGenericOptional.py @@ -88,7 +88,7 @@ def cleanup(): self.expect( "frame variable *number_not_engaged", error=True, - substrs=["not a pointer or reference type"], + substrs=["dereference failed: not a"], ) @add_test_categories(["libc++"]) _______________________________________________ lldb-commits mailing list lldb-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits