https://github.com/labath updated 
https://github.com/llvm/llvm-project/pull/207743

>From df80d3e2dd9aaa38f175030bb30b5387e01271ae Mon Sep 17 00:00:00 2001
From: Pavel Labath <[email protected]>
Date: Wed, 8 Jul 2026 10:12:52 +0200
Subject: [PATCH] [lldb] Return static SBType for static SBValues

The type should reflect our view of the value. To enable looking at the
nested types of dynamic types, I change TypeImpl::FindDirectNestedType
to prefer dynamic types (if it exists). To get the previous behavior,
explicitly ask for a static type from the value.
---
 lldb/source/API/SBValue.cpp                   |  2 ++
 lldb/source/Symbol/Type.cpp                   |  2 +-
 lldb/test/API/python_api/type/TestTypeList.py | 23 +++++++++++++++++++
 lldb/test/API/python_api/type/main.cpp        | 11 +++++++++
 4 files changed, 37 insertions(+), 1 deletion(-)

diff --git a/lldb/source/API/SBValue.cpp b/lldb/source/API/SBValue.cpp
index 9b84fb975c302..a4d8a790071de 100644
--- a/lldb/source/API/SBValue.cpp
+++ b/lldb/source/API/SBValue.cpp
@@ -229,6 +229,8 @@ SBType SBValue::GetType() {
   ValueLocker locker;
   lldb::ValueObjectSP value_sp(GetSP(locker));
   TypeImplSP type_sp;
+  if (value_sp && GetPreferDynamicValue() == eNoDynamicValues)
+    value_sp = value_sp->GetStaticValue();
   if (value_sp) {
     type_sp = std::make_shared<TypeImpl>(value_sp->GetTypeImpl());
     sb_type.SetSP(type_sp);
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..1097f75e4e49a 100644
--- a/lldb/test/API/python_api/type/TestTypeList.py
+++ b/lldb/test/API/python_api/type/TestTypeList.py
@@ -300,6 +300,29 @@ 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")
+
+        static = polymorphic.GetStaticValue()
+        self.DebugSBValue(static)
+        static_type = static.GetType().GetPointeeType()
+        self.assertFalse(static_type.FindDirectNestedType("Nested"))
+
     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..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
 }

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

Reply via email to