https://github.com/labath updated https://github.com/llvm/llvm-project/pull/207743
>From ce18af4f2bfc92aff6de0b7f925bcaae8bc80d91 Mon Sep 17 00:00:00 2001 From: Pavel Labath <[email protected]> Date: Mon, 6 Jul 2026 16:18:04 +0200 Subject: [PATCH 1/3] [lldb] Make SBType know its dynamic-ness SBType (via lldb_private::TypeImpl) stores both static and dynamic types, but there's no way (at the SB level) to choose which view to access. At the lldb_private level, one could pass arguments to the GetCompilerType function, but there one often did not know which value to pass, which resulted in a mostly random distribution of constants. This patch makes TypeImpl store the dynamic property, similar to ValueImpl does for SBValue. It also adds the Get{Static,Dynamic}Type accessors to toggle it. For testing, I add a test case which accesses the nested type of a dynamic type -- something that was not possible before this patch, and my motivation for implementing this. --- lldb/include/lldb/API/SBType.h | 4 + lldb/include/lldb/Symbol/Type.h | 13 ++- lldb/source/API/SBTarget.cpp | 4 +- lldb/source/API/SBType.cpp | 98 +++++++++++-------- lldb/source/API/SBTypeNameSpecifier.cpp | 2 +- lldb/source/API/SBValue.cpp | 8 +- .../DataFormatters/FormatterBytecode.cpp | 2 +- lldb/source/Symbol/Type.cpp | 14 +-- lldb/test/API/python_api/type/TestTypeList.py | 13 +++ lldb/test/API/python_api/type/main.cpp | 11 +++ 10 files changed, 111 insertions(+), 58 deletions(-) diff --git a/lldb/include/lldb/API/SBType.h b/lldb/include/lldb/API/SBType.h index 9ad3244686328..6b65a4ed490bb 100644 --- a/lldb/include/lldb/API/SBType.h +++ b/lldb/include/lldb/API/SBType.h @@ -148,6 +148,10 @@ class SBType { bool IsValid() const; + SBType GetStaticType(); + + SBType GetDynamicType(lldb::DynamicValueType use_dynamic); + uint64_t GetByteSize(); uint64_t GetByteAlign(); diff --git a/lldb/include/lldb/Symbol/Type.h b/lldb/include/lldb/Symbol/Type.h index 84666a04818a5..b76c9936f2255 100644 --- a/lldb/include/lldb/Symbol/Type.h +++ b/lldb/include/lldb/Symbol/Type.h @@ -17,6 +17,7 @@ #include "lldb/Symbol/TypeSystem.h" #include "lldb/Utility/ConstString.h" #include "lldb/Utility/UserID.h" +#include "lldb/lldb-enumerations.h" #include "lldb/lldb-private.h" #include "llvm/ADT/APSInt.h" @@ -644,6 +645,12 @@ class TypeImpl { void SetType(const CompilerType &compiler_type, const CompilerType &dynamic); + lldb::DynamicValueType GetUseDynamic() { return m_use_dynamic; } + + void SetUseDynamic(lldb::DynamicValueType use_dynamic) { + m_use_dynamic = use_dynamic; + } + bool operator==(const TypeImpl &rhs) const; bool operator!=(const TypeImpl &rhs) const; @@ -674,9 +681,9 @@ class TypeImpl { TypeImpl GetCanonicalType() const; - CompilerType GetCompilerType(bool prefer_dynamic); + CompilerType GetCompilerType() const; - CompilerType::TypeSystemSPWrapper GetTypeSystem(bool prefer_dynamic); + CompilerType::TypeSystemSPWrapper GetTypeSystem(); bool GetDescription(lldb_private::Stream &strm, lldb::DescriptionLevel description_level); @@ -693,6 +700,8 @@ class TypeImpl { lldb::ModuleWP m_exe_module_wp; CompilerType m_static_type; CompilerType m_dynamic_type; + + lldb::DynamicValueType m_use_dynamic = lldb::eDynamicDontRunTarget; }; class TypeListImpl { diff --git a/lldb/source/API/SBTarget.cpp b/lldb/source/API/SBTarget.cpp index 669c05c42fd1a..e5f34d1069e4d 100644 --- a/lldb/source/API/SBTarget.cpp +++ b/lldb/source/API/SBTarget.cpp @@ -1454,7 +1454,7 @@ SBValue SBTarget::CreateValueFromAddress(const char *name, SBAddress addr, lldb::addr_t load_addr(addr.GetLoadAddress(*this)); ExecutionContext exe_ctx( ExecutionContextRef(ExecutionContext(m_opaque_sp.get(), false))); - CompilerType ast_type(type.GetSP()->GetCompilerType(true)); + CompilerType ast_type(type.GetSP()->GetCompilerType()); new_value_sp = ValueObject::CreateValueObjectFromAddress(name, load_addr, exe_ctx, ast_type); } @@ -1472,7 +1472,7 @@ lldb::SBValue SBTarget::CreateValueFromData(const char *name, lldb::SBData data, DataExtractorSP extractor(*data); ExecutionContext exe_ctx( ExecutionContextRef(ExecutionContext(m_opaque_sp.get(), false))); - CompilerType ast_type(type.GetSP()->GetCompilerType(true)); + CompilerType ast_type(type.GetSP()->GetCompilerType()); new_value_sp = ValueObject::CreateValueObjectFromData(name, *extractor, exe_ctx, ast_type); } diff --git a/lldb/source/API/SBType.cpp b/lldb/source/API/SBType.cpp index f58902dcf44d8..87621e8eb537b 100644 --- a/lldb/source/API/SBType.cpp +++ b/lldb/source/API/SBType.cpp @@ -123,12 +123,30 @@ SBType::operator bool() const { return m_opaque_sp->IsValid(); } +SBType SBType::GetStaticType() { + LLDB_INSTRUMENT_VA(this); + + return GetDynamicType(eNoDynamicValues); +} + +SBType SBType::GetDynamicType(DynamicValueType use_dynamic) { + LLDB_INSTRUMENT_VA(this); + + SBType result; + if (IsValid()) { + TypeImplSP type_impl_sp(new TypeImpl(*m_opaque_sp)); + type_impl_sp->SetUseDynamic(use_dynamic); + result.SetSP(type_impl_sp); + } + return result; +} + uint64_t SBType::GetByteSize() { LLDB_INSTRUMENT_VA(this); if (IsValid()) if (std::optional<uint64_t> size = llvm::expectedToOptional( - m_opaque_sp->GetCompilerType(false).GetByteSize(nullptr))) + m_opaque_sp->GetCompilerType().GetByteSize(nullptr))) return *size; return 0; } @@ -140,8 +158,7 @@ uint64_t SBType::GetByteAlign() { return 0; std::optional<uint64_t> bit_align = - m_opaque_sp->GetCompilerType(/*prefer_dynamic=*/false) - .GetTypeBitAlign(nullptr); + m_opaque_sp->GetCompilerType().GetTypeBitAlign(nullptr); return llvm::divideCeil(bit_align.value_or(0), 8); } @@ -150,7 +167,7 @@ bool SBType::IsPointerType() { if (!IsValid()) return false; - return m_opaque_sp->GetCompilerType(true).IsPointerType(); + return m_opaque_sp->GetCompilerType().IsPointerType(); } bool SBType::IsArrayType() { @@ -158,8 +175,7 @@ bool SBType::IsArrayType() { if (!IsValid()) return false; - return m_opaque_sp->GetCompilerType(true).IsArrayType(nullptr, nullptr, - nullptr); + return m_opaque_sp->GetCompilerType().IsArrayType(nullptr, nullptr, nullptr); } bool SBType::IsVectorType() { @@ -167,7 +183,7 @@ bool SBType::IsVectorType() { if (!IsValid()) return false; - return m_opaque_sp->GetCompilerType(true).IsVectorType(nullptr, nullptr); + return m_opaque_sp->GetCompilerType().IsVectorType(nullptr, nullptr); } bool SBType::IsReferenceType() { @@ -175,7 +191,7 @@ bool SBType::IsReferenceType() { if (!IsValid()) return false; - return m_opaque_sp->GetCompilerType(true).IsReferenceType(); + return m_opaque_sp->GetCompilerType().IsReferenceType(); } SBType SBType::GetPointerType() { @@ -225,7 +241,7 @@ SBType SBType::GetArrayElementType() { if (!IsValid()) return SBType(); return SBType(std::make_shared<TypeImpl>( - m_opaque_sp->GetCompilerType(true).GetArrayElementType(nullptr))); + m_opaque_sp->GetCompilerType().GetArrayElementType(nullptr))); } SBType SBType::GetArrayType(uint64_t size) { @@ -234,7 +250,7 @@ SBType SBType::GetArrayType(uint64_t size) { if (!IsValid()) return SBType(); return SBType(std::make_shared<TypeImpl>( - m_opaque_sp->GetCompilerType(true).GetArrayType(size))); + m_opaque_sp->GetCompilerType().GetArrayType(size))); } SBType SBType::GetVectorElementType() { @@ -243,7 +259,7 @@ SBType SBType::GetVectorElementType() { SBType type_sb; if (IsValid()) { CompilerType vector_element_type; - if (m_opaque_sp->GetCompilerType(true).IsVectorType(&vector_element_type, + if (m_opaque_sp->GetCompilerType().IsVectorType(&vector_element_type, nullptr)) type_sb.SetSP(std::make_shared<TypeImpl>(vector_element_type)); } @@ -255,7 +271,7 @@ bool SBType::IsFunctionType() { if (!IsValid()) return false; - return m_opaque_sp->GetCompilerType(true).IsFunctionType(); + return m_opaque_sp->GetCompilerType().IsFunctionType(); } bool SBType::IsPolymorphicClass() { @@ -263,7 +279,7 @@ bool SBType::IsPolymorphicClass() { if (!IsValid()) return false; - return m_opaque_sp->GetCompilerType(true).IsPolymorphicClass(); + return m_opaque_sp->GetCompilerType().IsPolymorphicClass(); } bool SBType::IsTypedefType() { @@ -271,7 +287,7 @@ bool SBType::IsTypedefType() { if (!IsValid()) return false; - return m_opaque_sp->GetCompilerType(true).IsTypedefType(); + return m_opaque_sp->GetCompilerType().IsTypedefType(); } bool SBType::IsAnonymousType() { @@ -279,7 +295,7 @@ bool SBType::IsAnonymousType() { if (!IsValid()) return false; - return m_opaque_sp->GetCompilerType(true).IsAnonymousType(); + return m_opaque_sp->GetCompilerType().IsAnonymousType(); } bool SBType::IsScopedEnumerationType() { @@ -287,7 +303,7 @@ bool SBType::IsScopedEnumerationType() { if (!IsValid()) return false; - return m_opaque_sp->GetCompilerType(true).IsScopedEnumerationType(); + return m_opaque_sp->GetCompilerType().IsScopedEnumerationType(); } bool SBType::IsAggregateType() { @@ -295,7 +311,7 @@ bool SBType::IsAggregateType() { if (!IsValid()) return false; - return m_opaque_sp->GetCompilerType(true).IsAggregateType(); + return m_opaque_sp->GetCompilerType().IsAggregateType(); } lldb::SBType SBType::GetFunctionReturnType() { @@ -303,7 +319,7 @@ lldb::SBType SBType::GetFunctionReturnType() { if (IsValid()) { CompilerType return_type( - m_opaque_sp->GetCompilerType(true).GetFunctionReturnType()); + m_opaque_sp->GetCompilerType().GetFunctionReturnType()); if (return_type.IsValid()) return SBType(return_type); } @@ -315,7 +331,7 @@ lldb::SBTypeList SBType::GetFunctionArgumentTypes() { SBTypeList sb_type_list; if (IsValid()) { - CompilerType func_type(m_opaque_sp->GetCompilerType(true)); + CompilerType func_type(m_opaque_sp->GetCompilerType()); size_t count = func_type.GetNumberOfFunctionArguments(); for (size_t i = 0; i < count; i++) { sb_type_list.Append(SBType(func_type.GetFunctionArgumentAtIndex(i))); @@ -328,7 +344,7 @@ uint32_t SBType::GetNumberOfMemberFunctions() { LLDB_INSTRUMENT_VA(this); if (IsValid()) { - return m_opaque_sp->GetCompilerType(true).GetNumMemberFunctions(); + return m_opaque_sp->GetCompilerType().GetNumMemberFunctions(); } return 0; } @@ -339,7 +355,7 @@ lldb::SBTypeMemberFunction SBType::GetMemberFunctionAtIndex(uint32_t idx) { SBTypeMemberFunction sb_func_type; if (IsValid()) sb_func_type.reset(new TypeMemberFunctionImpl( - m_opaque_sp->GetCompilerType(true).GetMemberFunctionAtIndex(idx))); + m_opaque_sp->GetCompilerType().GetMemberFunctionAtIndex(idx))); return sb_func_type; } @@ -437,7 +453,7 @@ SBType SBType::GetEnumerationIntegerType() { if (IsValid()) { return SBType( - m_opaque_sp->GetCompilerType(true).GetEnumerationIntegerType()); + m_opaque_sp->GetCompilerType().GetEnumerationIntegerType()); } return SBType(); } @@ -446,7 +462,7 @@ lldb::BasicType SBType::GetBasicType() { LLDB_INSTRUMENT_VA(this); if (IsValid()) - return m_opaque_sp->GetCompilerType(false).GetBasicTypeEnumeration(); + return m_opaque_sp->GetCompilerType().GetBasicTypeEnumeration(); return eBasicTypeInvalid; } @@ -454,7 +470,7 @@ SBType SBType::GetBasicType(lldb::BasicType basic_type) { LLDB_INSTRUMENT_VA(this, basic_type); if (IsValid() && m_opaque_sp->IsValid()) - if (auto ts = m_opaque_sp->GetTypeSystem(false)) + if (auto ts = m_opaque_sp->GetTypeSystem()) return SBType(ts->GetBasicTypeFromAST(basic_type)); return SBType(); } @@ -463,7 +479,7 @@ uint32_t SBType::GetNumberOfDirectBaseClasses() { LLDB_INSTRUMENT_VA(this); if (IsValid()) - return m_opaque_sp->GetCompilerType(true).GetNumDirectBaseClasses(); + return m_opaque_sp->GetCompilerType().GetNumDirectBaseClasses(); return 0; } @@ -471,7 +487,7 @@ uint32_t SBType::GetNumberOfVirtualBaseClasses() { LLDB_INSTRUMENT_VA(this); if (IsValid()) - return m_opaque_sp->GetCompilerType(true).GetNumVirtualBaseClasses(); + return m_opaque_sp->GetCompilerType().GetNumVirtualBaseClasses(); return 0; } @@ -479,7 +495,7 @@ uint32_t SBType::GetNumberOfFields() { LLDB_INSTRUMENT_VA(this); if (IsValid()) - return m_opaque_sp->GetCompilerType(true).GetNumFields(); + return m_opaque_sp->GetCompilerType().GetNumFields(); return 0; } @@ -504,7 +520,7 @@ SBTypeMember SBType::GetDirectBaseClassAtIndex(uint32_t idx) { if (IsValid()) { uint32_t bit_offset = 0; CompilerType base_class_type = - m_opaque_sp->GetCompilerType(true).GetDirectBaseClassAtIndex( + m_opaque_sp->GetCompilerType().GetDirectBaseClassAtIndex( idx, &bit_offset); if (base_class_type.IsValid()) sb_type_member.reset(new TypeMemberImpl( @@ -520,7 +536,7 @@ SBTypeMember SBType::GetVirtualBaseClassAtIndex(uint32_t idx) { if (IsValid()) { uint32_t bit_offset = 0; CompilerType base_class_type = - m_opaque_sp->GetCompilerType(true).GetVirtualBaseClassAtIndex( + m_opaque_sp->GetCompilerType().GetVirtualBaseClassAtIndex( idx, &bit_offset); if (base_class_type.IsValid()) sb_type_member.reset(new TypeMemberImpl( @@ -535,8 +551,8 @@ SBTypeStaticField SBType::GetStaticFieldWithName(const char *name) { if (!IsValid() || !name) return SBTypeStaticField(); - return SBTypeStaticField(m_opaque_sp->GetCompilerType(/*prefer_dynamic=*/true) - .GetStaticFieldWithName(name)); + return SBTypeStaticField( + m_opaque_sp->GetCompilerType().GetStaticFieldWithName(name)); } SBTypeEnumMemberList SBType::GetEnumMembers() { @@ -544,7 +560,7 @@ SBTypeEnumMemberList SBType::GetEnumMembers() { SBTypeEnumMemberList sb_enum_member_list; if (IsValid()) { - CompilerType this_type(m_opaque_sp->GetCompilerType(true)); + CompilerType this_type(m_opaque_sp->GetCompilerType()); if (this_type.IsValid()) { this_type.ForEachEnumerator( [&sb_enum_member_list](const CompilerType &integer_type, @@ -565,7 +581,7 @@ SBTypeMember SBType::GetFieldAtIndex(uint32_t idx) { SBTypeMember sb_type_member; if (IsValid()) { - CompilerType this_type(m_opaque_sp->GetCompilerType(false)); + CompilerType this_type(m_opaque_sp->GetCompilerType()); if (this_type.IsValid()) { uint64_t bit_offset = 0; uint32_t bitfield_bit_size = 0; @@ -591,7 +607,7 @@ bool SBType::IsTypeComplete() { if (!IsValid()) return false; - CompilerType compiler_type = m_opaque_sp->GetCompilerType(false); + CompilerType compiler_type = m_opaque_sp->GetCompilerType(); // Only return true if we have a complete type and it wasn't forcefully // completed. if (compiler_type.IsCompleteType()) @@ -604,7 +620,7 @@ uint32_t SBType::GetTypeFlags() { if (!IsValid()) return 0; - return m_opaque_sp->GetCompilerType(true).GetTypeInfo(); + return m_opaque_sp->GetCompilerType().GetTypeInfo(); } lldb::SBModule SBType::GetModule() { @@ -638,7 +654,7 @@ lldb::TypeClass SBType::GetTypeClass() { LLDB_INSTRUMENT_VA(this); if (IsValid()) - return m_opaque_sp->GetCompilerType(true).GetTypeClass(); + return m_opaque_sp->GetCompilerType().GetTypeClass(); return lldb::eTypeClassInvalid; } @@ -646,7 +662,7 @@ uint32_t SBType::GetNumberOfTemplateArguments() { LLDB_INSTRUMENT_VA(this); if (IsValid()) - return m_opaque_sp->GetCompilerType(false).GetNumTemplateArguments( + return m_opaque_sp->GetCompilerType().GetNumTemplateArguments( /*expand_pack=*/true); return 0; } @@ -661,11 +677,11 @@ lldb::SBType SBType::GetTemplateArgumentType(uint32_t idx) { const bool expand_pack = true; switch(GetTemplateArgumentKind(idx)) { case eTemplateArgumentKindType: - type = m_opaque_sp->GetCompilerType(false).GetTypeTemplateArgument( + type = m_opaque_sp->GetCompilerType().GetTypeTemplateArgument( idx, expand_pack); break; case eTemplateArgumentKindIntegral: - type = m_opaque_sp->GetCompilerType(false) + type = m_opaque_sp->GetCompilerType() .GetIntegralTemplateArgument(idx, expand_pack) ->type; break; @@ -681,7 +697,7 @@ lldb::TemplateArgumentKind SBType::GetTemplateArgumentKind(uint32_t idx) { LLDB_INSTRUMENT_VA(this, idx); if (IsValid()) - return m_opaque_sp->GetCompilerType(false).GetTemplateArgumentKind( + return m_opaque_sp->GetCompilerType().GetTemplateArgumentKind( idx, /*expand_pack=*/true); return eTemplateArgumentKindNull; } @@ -698,7 +714,7 @@ lldb::SBValue SBType::GetTemplateArgumentValue(lldb::SBTarget target, switch (GetTemplateArgumentKind(idx)) { case eTemplateArgumentKindStructuralValue: case eTemplateArgumentKindIntegral: - arg = m_opaque_sp->GetCompilerType(false).GetIntegralTemplateArgument( + arg = m_opaque_sp->GetCompilerType().GetIntegralTemplateArgument( idx, expand_pack); break; default: diff --git a/lldb/source/API/SBTypeNameSpecifier.cpp b/lldb/source/API/SBTypeNameSpecifier.cpp index dd817202a9d71..7e43921cbeed7 100644 --- a/lldb/source/API/SBTypeNameSpecifier.cpp +++ b/lldb/source/API/SBTypeNameSpecifier.cpp @@ -39,7 +39,7 @@ SBTypeNameSpecifier::SBTypeNameSpecifier(SBType type) { if (type.IsValid()) m_opaque_sp = std::make_shared<TypeNameSpecifierImpl>( - type.m_opaque_sp->GetCompilerType(true)); + type.m_opaque_sp->GetCompilerType()); } SBTypeNameSpecifier::SBTypeNameSpecifier(const lldb::SBTypeNameSpecifier &rhs) diff --git a/lldb/source/API/SBValue.cpp b/lldb/source/API/SBValue.cpp index 9b84fb975c302..9c574f251bb67 100644 --- a/lldb/source/API/SBValue.cpp +++ b/lldb/source/API/SBValue.cpp @@ -394,7 +394,7 @@ lldb::SBValue SBValue::CreateChildAtOffset(const char *name, uint32_t offset, TypeImplSP type_sp(type.GetSP()); if (type.IsValid()) { sb_value.SetSP(value_sp->GetSyntheticChildAtOffset( - offset, type_sp->GetCompilerType(false), true), + offset, type_sp->GetCompilerType(), true), GetPreferDynamicValue(), GetPreferSyntheticValue(), name); } } @@ -409,7 +409,7 @@ lldb::SBValue SBValue::Cast(SBType type) { lldb::ValueObjectSP value_sp(GetSP(locker)); TypeImplSP type_sp(type.GetSP()); if (value_sp && type_sp) - sb_value.SetSP(value_sp->Cast(type_sp->GetCompilerType(false)), + sb_value.SetSP(value_sp->Cast(type_sp->GetCompilerType()), GetPreferDynamicValue(), GetPreferSyntheticValue()); return sb_value; } @@ -454,7 +454,7 @@ lldb::SBValue SBValue::CreateValueFromAddress(const char *name, lldb::ValueObjectSP new_value_sp; lldb::TypeImplSP type_impl_sp(sb_type.GetSP()); if (value_sp && type_impl_sp) { - CompilerType ast_type(type_impl_sp->GetCompilerType(true)); + CompilerType ast_type(type_impl_sp->GetCompilerType()); ExecutionContext exe_ctx(value_sp->GetExecutionContextRef()); new_value_sp = value_sp->CreateChildValueObjectFromAddress( name, address, exe_ctx, ast_type); @@ -475,7 +475,7 @@ lldb::SBValue SBValue::CreateValueFromData(const char *name, SBData data, if (value_sp && type_impl_sp) { ExecutionContext exe_ctx(value_sp->GetExecutionContextRef()); new_value_sp = value_sp->CreateChildValueObjectFromData( - name, **data, exe_ctx, type_impl_sp->GetCompilerType(true)); + name, **data, exe_ctx, type_impl_sp->GetCompilerType()); new_value_sp->SetAddressTypeOfChildren(eAddressTypeLoad); } sb_value.SetSP(new_value_sp); diff --git a/lldb/source/DataFormatters/FormatterBytecode.cpp b/lldb/source/DataFormatters/FormatterBytecode.cpp index 2d79641f516f1..49f08bfe51383 100644 --- a/lldb/source/DataFormatters/FormatterBytecode.cpp +++ b/lldb/source/DataFormatters/FormatterBytecode.cpp @@ -509,7 +509,7 @@ llvm::Error Interpret(ControlStack &control, DataStack &data, Signatures sig) { TYPE_CHECK(Object); POP_VALOBJ(valobj); // FIXME: do we need to control dynamic type resolution? - data.Push(valobj->GetTypeImpl().GetCompilerType(false)); + data.Push(valobj->GetTypeImpl().GetCompilerType()); break; } case sel_get_template_argument_type: { diff --git a/lldb/source/Symbol/Type.cpp b/lldb/source/Symbol/Type.cpp index 7681d7065a522..b5afcc7029399 100644 --- a/lldb/source/Symbol/Type.cpp +++ b/lldb/source/Symbol/Type.cpp @@ -1038,7 +1038,8 @@ bool TypeImpl::CheckModuleCommon(const lldb::ModuleWP &input_module_wp, bool TypeImpl::operator==(const TypeImpl &rhs) const { return m_static_type == rhs.m_static_type && - m_dynamic_type == rhs.m_dynamic_type; + m_dynamic_type == rhs.m_dynamic_type && + m_use_dynamic == rhs.m_use_dynamic; } bool TypeImpl::operator!=(const TypeImpl &rhs) const { @@ -1172,10 +1173,10 @@ TypeImpl TypeImpl::GetCanonicalType() const { return TypeImpl(); } -CompilerType TypeImpl::GetCompilerType(bool prefer_dynamic) { +CompilerType TypeImpl::GetCompilerType() const { ModuleSP module_sp; if (CheckModule(module_sp)) { - if (prefer_dynamic) { + if (m_use_dynamic != eNoDynamicValues) { if (m_dynamic_type.IsValid()) return m_dynamic_type; } @@ -1184,10 +1185,10 @@ CompilerType TypeImpl::GetCompilerType(bool prefer_dynamic) { return CompilerType(); } -CompilerType::TypeSystemSPWrapper TypeImpl::GetTypeSystem(bool prefer_dynamic) { +CompilerType::TypeSystemSPWrapper TypeImpl::GetTypeSystem() { ModuleSP module_sp; if (CheckModule(module_sp)) { - if (prefer_dynamic) { + if (m_use_dynamic != eNoDynamicValues) { if (m_dynamic_type.IsValid()) return m_dynamic_type.GetTypeSystem(); } @@ -1215,8 +1216,7 @@ bool TypeImpl::GetDescription(lldb_private::Stream &strm, CompilerType TypeImpl::FindDirectNestedType(llvm::StringRef name) { if (name.empty()) return CompilerType(); - return GetCompilerType(/*prefer_dynamic=*/false) - .GetDirectNestedTypeWithName(name); + return GetCompilerType().GetDirectNestedTypeWithName(name); } bool TypeMemberFunctionImpl::IsValid() { diff --git a/lldb/test/API/python_api/type/TestTypeList.py b/lldb/test/API/python_api/type/TestTypeList.py index e4dc810169089..5072e87a41781 100644 --- a/lldb/test/API/python_api/type/TestTypeList.py +++ b/lldb/test/API/python_api/type/TestTypeList.py @@ -232,6 +232,19 @@ def test(self): frame0.EvaluateExpression("task_head").GetType() ) + # Check FindDirectNestedType on dynamic values + polymorphic = frame0.FindVariable("polymorphic").GetDynamicValue( + lldb.eDynamicDontRunTarget + ) + self.DebugSBValue(polymorphic) + polymorphic_type = polymorphic.GetType().GetPointeeType() + self.DebugSBType(polymorphic_type) + static_type = polymorphic_type.GetStaticType() + self.assertFalse(static_type.FindDirectNestedType("Nested")) + nested = polymorphic_type.FindDirectNestedType("Nested") + self.DebugSBType(nested) + self.assertEqual(nested.GetName(), "PolymorphicDerived::Nested") + # We'll now get the child member 'id' from 'task_head'. id = task_head.GetChildMemberWithName("id") self.DebugSBValue(id) diff --git a/lldb/test/API/python_api/type/main.cpp b/lldb/test/API/python_api/type/main.cpp index 449f77db0d75e..3d31790be05ee 100644 --- a/lldb/test/API/python_api/type/main.cpp +++ b/lldb/test/API/python_api/type/main.cpp @@ -63,6 +63,15 @@ struct WithNestedTypedef { }; WithNestedTypedef::TheTypedef typedefed_value; +struct PolymorphicBase { + virtual void foo() {} +}; + +struct PolymorphicDerived : PolymorphicBase { + struct Nested {}; + Nested get() { return {}; } +}; + int main (int argc, char const *argv[]) { Task *task_head = new Task(-1, NULL); @@ -100,5 +109,7 @@ int main (int argc, char const *argv[]) PointerInfo<3>::Masks1 mask1 = PointerInfo<3>::Masks1::pointer_mask; PointerInfo<3>::Masks2 mask2 = PointerInfo<3>::Masks2::pointer_mask; + PolymorphicBase *polymorphic = new PolymorphicDerived(); + return 0; // Break at this line } >From 0eeb6c7564f8abb4b54f4126957cff3151f22821 Mon Sep 17 00:00:00 2001 From: Pavel Labath <[email protected]> Date: Mon, 6 Jul 2026 18:06:45 +0200 Subject: [PATCH 2/3] format --- lldb/source/API/SBType.cpp | 13 ++++++------- 1 file changed, 6 insertions(+), 7 deletions(-) diff --git a/lldb/source/API/SBType.cpp b/lldb/source/API/SBType.cpp index 87621e8eb537b..1ad578288430d 100644 --- a/lldb/source/API/SBType.cpp +++ b/lldb/source/API/SBType.cpp @@ -260,7 +260,7 @@ SBType SBType::GetVectorElementType() { if (IsValid()) { CompilerType vector_element_type; if (m_opaque_sp->GetCompilerType().IsVectorType(&vector_element_type, - nullptr)) + nullptr)) type_sb.SetSP(std::make_shared<TypeImpl>(vector_element_type)); } return type_sb; @@ -452,8 +452,7 @@ SBType SBType::GetEnumerationIntegerType() { LLDB_INSTRUMENT_VA(this); if (IsValid()) { - return SBType( - m_opaque_sp->GetCompilerType().GetEnumerationIntegerType()); + return SBType(m_opaque_sp->GetCompilerType().GetEnumerationIntegerType()); } return SBType(); } @@ -520,8 +519,8 @@ SBTypeMember SBType::GetDirectBaseClassAtIndex(uint32_t idx) { if (IsValid()) { uint32_t bit_offset = 0; CompilerType base_class_type = - m_opaque_sp->GetCompilerType().GetDirectBaseClassAtIndex( - idx, &bit_offset); + m_opaque_sp->GetCompilerType().GetDirectBaseClassAtIndex(idx, + &bit_offset); if (base_class_type.IsValid()) sb_type_member.reset(new TypeMemberImpl( std::make_shared<TypeImpl>(base_class_type), bit_offset)); @@ -536,8 +535,8 @@ SBTypeMember SBType::GetVirtualBaseClassAtIndex(uint32_t idx) { if (IsValid()) { uint32_t bit_offset = 0; CompilerType base_class_type = - m_opaque_sp->GetCompilerType().GetVirtualBaseClassAtIndex( - idx, &bit_offset); + m_opaque_sp->GetCompilerType().GetVirtualBaseClassAtIndex(idx, + &bit_offset); if (base_class_type.IsValid()) sb_type_member.reset(new TypeMemberImpl( std::make_shared<TypeImpl>(base_class_type), bit_offset)); >From 9f9867fd9bd2fe39d01e0da9e38635d160d38514 Mon Sep 17 00:00:00 2001 From: Pavel Labath <[email protected]> Date: Tue, 7 Jul 2026 14:19:11 +0200 Subject: [PATCH 3/3] Separate out the test + expectedFailureWindows --- lldb/test/API/python_api/type/TestTypeList.py | 33 +++++++++++-------- 1 file changed, 20 insertions(+), 13 deletions(-) diff --git a/lldb/test/API/python_api/type/TestTypeList.py b/lldb/test/API/python_api/type/TestTypeList.py index 5072e87a41781..8dc46c79b6589 100644 --- a/lldb/test/API/python_api/type/TestTypeList.py +++ b/lldb/test/API/python_api/type/TestTypeList.py @@ -232,19 +232,6 @@ def test(self): frame0.EvaluateExpression("task_head").GetType() ) - # Check FindDirectNestedType on dynamic values - polymorphic = frame0.FindVariable("polymorphic").GetDynamicValue( - lldb.eDynamicDontRunTarget - ) - self.DebugSBValue(polymorphic) - polymorphic_type = polymorphic.GetType().GetPointeeType() - self.DebugSBType(polymorphic_type) - static_type = polymorphic_type.GetStaticType() - self.assertFalse(static_type.FindDirectNestedType("Nested")) - nested = polymorphic_type.FindDirectNestedType("Nested") - self.DebugSBType(nested) - self.assertEqual(nested.GetName(), "PolymorphicDerived::Nested") - # We'll now get the child member 'id' from 'task_head'. id = task_head.GetChildMemberWithName("id") self.DebugSBValue(id) @@ -313,6 +300,26 @@ def test_nested_typedef(self): self.assertTrue(the_typedef) self.assertEqual(the_typedef.GetTypedefedType().GetName(), "int") + @expectedFailureWindows # Dynamic type resolution not implemented + def test_dynamic_values(self): + """Test FindDirectNestedType on dynamic values""" + + self.build() + lldbutil.run_to_line_breakpoint(self, lldb.SBFileSpec(self.source), self.line) + polymorphic = ( + self.frame() + .FindVariable("polymorphic") + .GetDynamicValue(lldb.eDynamicDontRunTarget) + ) + self.DebugSBValue(polymorphic) + polymorphic_type = polymorphic.GetType().GetPointeeType() + self.DebugSBType(polymorphic_type) + static_type = polymorphic_type.GetStaticType() + self.assertFalse(static_type.FindDirectNestedType("Nested")) + nested = polymorphic_type.FindDirectNestedType("Nested") + self.DebugSBType(nested) + self.assertEqual(nested.GetName(), "PolymorphicDerived::Nested") + def test_GetByteAlign(self): """Exercise SBType::GetByteAlign""" self.build() _______________________________________________ lldb-commits mailing list [email protected] https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits
