Skip to content

[lldb] Make SBType::GetDirectNestedType (mostly) work with typedefs #91189

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
May 9, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions lldb/source/Plugins/TypeSystem/Clang/TypeSystemClang.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -7106,6 +7106,8 @@ TypeSystemClang::GetDirectNestedTypeWithName(lldb::opaque_compiler_type_t type,
for (NamedDecl *decl : record_decl->lookup(decl_name)) {
if (auto *tag_decl = dyn_cast<clang::TagDecl>(decl))
return GetType(getASTContext().getTagDeclType(tag_decl));
if (auto *typedef_decl = dyn_cast<clang::TypedefNameDecl>(decl))
return GetType(getASTContext().getTypedefType(typedef_decl));
}
break;
}
Expand Down
16 changes: 16 additions & 0 deletions lldb/test/API/python_api/type/TestTypeList.py
Original file line number Diff line number Diff line change
Expand Up @@ -273,6 +273,22 @@ def test(self):
self.DebugSBType(int_enum_uchar)
self.assertEqual(int_enum_uchar.GetName(), "unsigned char")

def test_nested_typedef(self):
"""Exercise FindDirectNestedType for typedefs."""
self.build()
target = self.dbg.CreateTarget(self.getBuildArtifact())
self.assertTrue(target)

with_nested_typedef = target.FindFirstType("WithNestedTypedef")
self.assertTrue(with_nested_typedef)

# This is necessary to work around #91186
self.assertTrue(target.FindFirstGlobalVariable("typedefed_value").GetType())

the_typedef = with_nested_typedef.FindDirectNestedType("TheTypedef")
self.assertTrue(the_typedef)
self.assertEqual(the_typedef.GetTypedefedType().GetName(), "int")

def test_GetByteAlign(self):
"""Exercise SBType::GetByteAlign"""
self.build()
Expand Down
5 changes: 5 additions & 0 deletions lldb/test/API/python_api/type/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,11 @@ enum class EnumUChar : unsigned char {};
struct alignas(128) OverAlignedStruct {};
OverAlignedStruct over_aligned_struct;

struct WithNestedTypedef {
typedef int TheTypedef;
};
WithNestedTypedef::TheTypedef typedefed_value;

int main (int argc, char const *argv[])
{
Task *task_head = new Task(-1, NULL);
Expand Down