Author: Pavel Labath
Date: 2026-07-09T09:50:18+02:00
New Revision: 832402097e77794095c3b59be9ea60bbaa4ce0f3

URL: 
https://github.com/llvm/llvm-project/commit/832402097e77794095c3b59be9ea60bbaa4ce0f3
DIFF: 
https://github.com/llvm/llvm-project/commit/832402097e77794095c3b59be9ea60bbaa4ce0f3.diff

LOG: [lldb] Make SBType::FindDirectNestedType work with dynamic types (#207743)

This makes it possible to find the nested type just by knowing the
dynamic type of the value. To get the previous behavior, get the type
from a static view of the value (SBValue::GetStaticValue).

Added: 
    

Modified: 
    lldb/source/Symbol/Type.cpp
    lldb/test/API/python_api/type/TestTypeList.py
    lldb/test/API/python_api/type/main.cpp

Removed: 
    


################################################################################
diff  --git a/lldb/source/Symbol/Type.cpp b/lldb/source/Symbol/Type.cpp
index 7681d7065a522..9b62018bbd3d8 100644
--- a/lldb/source/Symbol/Type.cpp
+++ b/lldb/source/Symbol/Type.cpp
@@ -1215,7 +1215,7 @@ bool TypeImpl::GetDescription(lldb_private::Stream &strm,
 CompilerType TypeImpl::FindDirectNestedType(llvm::StringRef name) {
   if (name.empty())
     return CompilerType();
-  return GetCompilerType(/*prefer_dynamic=*/false)
+  return GetCompilerType(/*prefer_dynamic=*/true)
       .GetDirectNestedTypeWithName(name);
 }
 

diff  --git a/lldb/test/API/python_api/type/TestTypeList.py 
b/lldb/test/API/python_api/type/TestTypeList.py
index e4dc810169089..ff9690794d1b3 100644
--- a/lldb/test/API/python_api/type/TestTypeList.py
+++ b/lldb/test/API/python_api/type/TestTypeList.py
@@ -300,6 +300,34 @@ 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)
+        nested = polymorphic_type.FindDirectNestedType("Nested")
+        self.DebugSBType(nested)
+        self.assertEqual(nested.GetName(), "PolymorphicDerived::Nested")
+        self.assertEqual(nested.GetTypedefedType().GetName(), "float")
+
+        static = polymorphic.GetStaticValue()
+        self.DebugSBValue(static)
+        static_type = static.GetType().GetPointeeType()
+        self.DebugSBType(static_type)
+        nested = static_type.FindDirectNestedType("Nested")
+        self.DebugSBType(nested)
+        self.assertEqual(nested.GetName(), "PolymorphicBase::Nested")
+        self.assertEqual(nested.GetTypedefedType().GetName(), "int")
+
     def test_GetByteAlign(self):
         """Exercise SBType::GetByteAlign"""
         self.build()

diff  --git a/lldb/test/API/python_api/type/main.cpp 
b/lldb/test/API/python_api/type/main.cpp
index 449f77db0d75e..9de1988ec7efc 100644
--- a/lldb/test/API/python_api/type/main.cpp
+++ b/lldb/test/API/python_api/type/main.cpp
@@ -63,6 +63,17 @@ struct WithNestedTypedef {
 };
 WithNestedTypedef::TheTypedef typedefed_value;
 
+struct PolymorphicBase {
+  using Nested = int;
+  Nested get() { return {}; }
+  virtual void foo() {}
+};
+
+struct PolymorphicDerived : PolymorphicBase {
+  using Nested = float;
+  Nested get() { return {}; }
+};
+
 int main (int argc, char const *argv[])
 {
     Task *task_head = new Task(-1, NULL);
@@ -100,5 +111,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
 }


        
_______________________________________________
lldb-commits mailing list
[email protected]
https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits

Reply via email to