[Lldb-commits] [lldb] [lldb] Make FindDirectNestedType be able to access dynamic types (PR #204811)
Pavel Labath via lldb-commits
lldb-commits at lists.llvm.org
Tue Jul 7 05:59:23 PDT 2026
https://github.com/labath updated https://github.com/llvm/llvm-project/pull/204811
>From cbba6a2d8f35da75cb9ceb48c2a9bcff0ade0200 Mon Sep 17 00:00:00 2001
From: Pavel Labath <pavel at labath.sk>
Date: Fri, 19 Jun 2026 14:19:44 +0200
Subject: [PATCH 1/2] [lldb] Make FindDirectNestedType be able to access
dynamic types
Right now, there isn't a way to access the dynamic type of the value.
This fixes that.
---
lldb/include/lldb/API/SBType.h | 1 +
lldb/include/lldb/Symbol/Type.h | 2 +-
lldb/source/API/SBType.cpp | 8 +++++++-
lldb/source/Symbol/Type.cpp | 6 +++---
lldb/test/API/python_api/type/TestTypeList.py | 12 ++++++++++++
lldb/test/API/python_api/type/main.cpp | 11 +++++++++++
6 files changed, 35 insertions(+), 5 deletions(-)
diff --git a/lldb/include/lldb/API/SBType.h b/lldb/include/lldb/API/SBType.h
index 9ad3244686328..282dc72f5675c 100644
--- a/lldb/include/lldb/API/SBType.h
+++ b/lldb/include/lldb/API/SBType.h
@@ -256,6 +256,7 @@ class SBType {
lldb::DescriptionLevel description_level);
lldb::SBType FindDirectNestedType(const char *name);
+ lldb::SBType FindDirectNestedType(const char *name, bool prefer_dynamic);
lldb::SBType &operator=(const lldb::SBType &rhs);
diff --git a/lldb/include/lldb/Symbol/Type.h b/lldb/include/lldb/Symbol/Type.h
index 84666a04818a5..163830d65228a 100644
--- a/lldb/include/lldb/Symbol/Type.h
+++ b/lldb/include/lldb/Symbol/Type.h
@@ -681,7 +681,7 @@ class TypeImpl {
bool GetDescription(lldb_private::Stream &strm,
lldb::DescriptionLevel description_level);
- CompilerType FindDirectNestedType(llvm::StringRef name);
+ CompilerType FindDirectNestedType(llvm::StringRef name, bool prefer_dynamic);
private:
bool CheckModule(lldb::ModuleSP &module_sp) const;
diff --git a/lldb/source/API/SBType.cpp b/lldb/source/API/SBType.cpp
index f58902dcf44d8..108b3752a7f2a 100644
--- a/lldb/source/API/SBType.cpp
+++ b/lldb/source/API/SBType.cpp
@@ -725,9 +725,15 @@ lldb::SBValue SBType::GetTemplateArgumentValue(lldb::SBTarget target,
SBType SBType::FindDirectNestedType(const char *name) {
LLDB_INSTRUMENT_VA(this, name);
+ return FindDirectNestedType(name, /*prefer_dynamic=*/false);
+}
+
+SBType SBType::FindDirectNestedType(const char *name, bool prefer_dynamic) {
+ LLDB_INSTRUMENT_VA(this, name, prefer_dynamic);
+
if (!IsValid())
return SBType();
- return SBType(m_opaque_sp->FindDirectNestedType(name));
+ return SBType(m_opaque_sp->FindDirectNestedType(name, prefer_dynamic));
}
SBTypeList::SBTypeList() : m_opaque_up(new TypeListImpl()) {
diff --git a/lldb/source/Symbol/Type.cpp b/lldb/source/Symbol/Type.cpp
index 7681d7065a522..f9e7df80287c9 100644
--- a/lldb/source/Symbol/Type.cpp
+++ b/lldb/source/Symbol/Type.cpp
@@ -1212,11 +1212,11 @@ bool TypeImpl::GetDescription(lldb_private::Stream &strm,
return true;
}
-CompilerType TypeImpl::FindDirectNestedType(llvm::StringRef name) {
+CompilerType TypeImpl::FindDirectNestedType(llvm::StringRef name,
+ bool prefer_dynamic) {
if (name.empty())
return CompilerType();
- return GetCompilerType(/*prefer_dynamic=*/false)
- .GetDirectNestedTypeWithName(name);
+ return GetCompilerType(prefer_dynamic).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..6f746169b9ac8 100644
--- a/lldb/test/API/python_api/type/TestTypeList.py
+++ b/lldb/test/API/python_api/type/TestTypeList.py
@@ -232,6 +232,18 @@ 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)
+ self.assertFalse(polymorphic_type.FindDirectNestedType("Nested", False))
+ nested = polymorphic_type.FindDirectNestedType("Nested", True)
+ 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 8a6d87338f1f846b39d33d3787d5c9afe308a79f Mon Sep 17 00:00:00 2001
From: Pavel Labath <pavel at labath.sk>
Date: Tue, 7 Jul 2026 14:59:15 +0200
Subject: [PATCH 2/2] separate out test + @expectedFailureWindows
---
lldb/test/API/python_api/type/TestTypeList.py | 31 ++++++++++++-------
1 file changed, 19 insertions(+), 12 deletions(-)
diff --git a/lldb/test/API/python_api/type/TestTypeList.py b/lldb/test/API/python_api/type/TestTypeList.py
index 6f746169b9ac8..7ee6c36ca7d2e 100644
--- a/lldb/test/API/python_api/type/TestTypeList.py
+++ b/lldb/test/API/python_api/type/TestTypeList.py
@@ -232,18 +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)
- self.assertFalse(polymorphic_type.FindDirectNestedType("Nested", False))
- nested = polymorphic_type.FindDirectNestedType("Nested", True)
- 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)
@@ -312,6 +300,25 @@ 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)
+ self.assertFalse(polymorphic_type.FindDirectNestedType("Nested", False))
+ nested = polymorphic_type.FindDirectNestedType("Nested", True)
+ self.DebugSBType(nested)
+ self.assertEqual(nested.GetName(), "PolymorphicDerived::Nested")
+
def test_GetByteAlign(self):
"""Exercise SBType::GetByteAlign"""
self.build()
More information about the lldb-commits
mailing list