llvmorg-github-actions[bot] wrote:
<!--LLVM PR SUMMARY COMMENT--> @llvm/pr-subscribers-lldb Author: Pavel Labath (labath) <details> <summary>Changes</summary> Right now, there isn't a way to access the dynamic type of the value. This fixes that. This is the lazy version of the patch, and I'm not convinced it's the right approach. It seems to me that it may be better/more consistent to make SBType behave similar to SBValue, in that it stores a flag that tells you whether you're looking at the static or dynamic version of the type. But before I set out on that path, I wanted to hear what you think first. --- Full diff: https://github.com/llvm/llvm-project/pull/204811.diff 6 Files Affected: - (modified) lldb/include/lldb/API/SBType.h (+1) - (modified) lldb/include/lldb/Symbol/Type.h (+1-1) - (modified) lldb/source/API/SBType.cpp (+7-1) - (modified) lldb/source/Symbol/Type.cpp (+2-3) - (modified) lldb/test/API/python_api/type/TestTypeList.py (+11) - (modified) lldb/test/API/python_api/type/main.cpp (+11) ``````````diff 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..ff027ed74b095 100644 --- a/lldb/test/API/python_api/type/TestTypeList.py +++ b/lldb/test/API/python_api/type/TestTypeList.py @@ -232,6 +232,17 @@ 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 } `````````` </details> https://github.com/llvm/llvm-project/pull/204811 _______________________________________________ lldb-commits mailing list [email protected] https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits
