[Lldb-commits] [lldb] [lldb] Make SBType::FindDirectNestedType work with dynamic types (PR #207743)

2026-07-09 Thread Pavel Labath via lldb-commits

https://github.com/labath closed 
https://github.com/llvm/llvm-project/pull/207743
___
lldb-commits mailing list
[email protected]
https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits


[Lldb-commits] [lldb] [lldb] Make SBType::FindDirectNestedType work with dynamic types (PR #207743)

2026-07-08 Thread Pavel Labath via lldb-commits

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

>From 9b9d265b055246a6d4d6e6a63786d557f86c674b Mon Sep 17 00:00:00 2001
From: Pavel Labath 
Date: Wed, 8 Jul 2026 10:12:52 +0200
Subject: [PATCH 1/2] [lldb] Make SBType::FindDirectNestedType work with
 dynamic types

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).
---
 lldb/source/Symbol/Type.cpp   |  2 +-
 lldb/test/API/python_api/type/TestTypeList.py | 24 +++
 lldb/test/API/python_api/type/main.cpp| 11 +
 3 files changed, 36 insertions(+), 1 deletion(-)

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..2c7abfe680ad2 100644
--- a/lldb/test/API/python_api/type/TestTypeList.py
+++ b/lldb/test/API/python_api/type/TestTypeList.py
@@ -300,6 +300,30 @@ 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.DebugSBType(static_type)
+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
 }

>From ea6099db5c8bd6de2678e302199c7f23a53c82c9 Mon Sep 17 00:00:00 2001
From: Pavel Labath 
Date: Wed, 8 Jul 2026 12:12:58 +0200
Subject: [PATCH 2/2] beef up the test

---
 lldb/test/API/python_api/type/TestTypeList.py | 6 +-
 lldb/test/API/python_api/type/main.cpp| 4 +++-
 2 files changed, 8 insertions(+), 2 deletions(-)

diff --git a/lldb/test/API/python_api/type/TestTypeList.py 
b/lldb/test/API/python_api/type/TestTypeList.py
index 2c7abfe680ad2..ff9690794d1b3 100644
--- a/lldb/test/API/python_api/type/TestTypeList.py
+++ b/lldb/test/API/python_api/type/TestTypeList.py
@@ -317,12 +317,16 @@ def test_dynamic_values(self):
 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)
-self.assertFalse(static_type.FindDirectNestedType("Nested"))
+nested = static_type.FindDirectNestedType("Nested")
+self.DebugSBType(nested)
+self.assertEqual(nested.GetName(), "PolymorphicBase

[Lldb-commits] [lldb] [lldb] Make SBType::FindDirectNestedType work with dynamic types (PR #207743)

2026-07-08 Thread Pavel Labath via lldb-commits

labath wrote:

You're right, I misdiagnosed the problem. I assumed that TypeImpl works like 
ValueImpl, in that provides access to both view of the value, but of course 
that doesn't make much sense for types. TypeImpl really stores a (static_type, 
dynamic_type) pair, but it only does that for types obtained from dynamic 
values (which is kind of okay). For types obtained from static values, the 
second component with this empty.

In light of this, I think the correct solution to my problem (which is -- being 
able to access nested types of dynamic types) really is just to flip the 
prefer_dynamic flag on the function. For static values/types it will not change 
anything, while for dynamic values it will let us access the properties of the 
nested type. If someone doesn't want that (they really want to access the 
properties of the base type), they can always ask for the type of the static 
value.

Let me know what you think of the new version.

https://github.com/llvm/llvm-project/pull/207743
___
lldb-commits mailing list
[email protected]
https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits


[Lldb-commits] [lldb] [lldb] Make SBType::FindDirectNestedType work with dynamic types (PR #207743)

2026-07-08 Thread Pavel Labath via lldb-commits

https://github.com/labath edited 
https://github.com/llvm/llvm-project/pull/207743
___
lldb-commits mailing list
[email protected]
https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits


[Lldb-commits] [lldb] [lldb] Make SBType::FindDirectNestedType work with dynamic types (PR #207743)

2026-07-08 Thread Pavel Labath via lldb-commits

https://github.com/labath edited 
https://github.com/llvm/llvm-project/pull/207743
___
lldb-commits mailing list
[email protected]
https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits