[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
Fri Jun 19 05:30:07 PDT 2026
https://github.com/labath updated https://github.com/llvm/llvm-project/pull/204811
>From 16b5fd04a8d59475af7edda6bb4f84189a454ecf 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] [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 | 5 ++---
lldb/test/API/python_api/type/TestTypeList.py | 12 ++++++++++++
lldb/test/API/python_api/type/main.cpp | 11 +++++++++++
6 files changed, 34 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..e3d83982e02ef 100644
--- a/lldb/source/Symbol/Type.cpp
+++ b/lldb/source/Symbol/Type.cpp
@@ -1212,11 +1212,10 @@ 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..ba032a9161650 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
}
More information about the lldb-commits
mailing list