Skip to content

[lldb][DWARFASTParserClang] Resolve nested types when parsing structures #66879

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

Closed
wants to merge 3 commits into from
Closed
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
15 changes: 9 additions & 6 deletions lldb/source/Plugins/SymbolFile/DWARF/DWARFASTParserClang.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2150,14 +2150,14 @@ bool DWARFASTParserClang::CompleteRecordType(const DWARFDIE &die,

std::vector<std::unique_ptr<clang::CXXBaseSpecifier>> bases;
// Parse members and base classes first
std::vector<DWARFDIE> member_function_dies;
std::vector<DWARFDIE> member_function_and_type_dies;

DelayedPropertyList delayed_properties;
ParseChildMembers(die, clang_type, bases, member_function_dies,
ParseChildMembers(die, clang_type, bases, member_function_and_type_dies,
delayed_properties, default_accessibility, layout_info);

// Now parse any methods if there were any...
for (const DWARFDIE &die : member_function_dies)
// Now parse any methods or nested types if there were any...
for (const DWARFDIE &die : member_function_and_type_dies)
dwarf->ResolveType(die);

if (type_is_objc_object_or_interface) {
Expand Down Expand Up @@ -3153,7 +3153,7 @@ void DWARFASTParserClang::ParseSingleMember(
bool DWARFASTParserClang::ParseChildMembers(
const DWARFDIE &parent_die, CompilerType &class_clang_type,
std::vector<std::unique_ptr<clang::CXXBaseSpecifier>> &base_classes,
std::vector<DWARFDIE> &member_function_dies,
std::vector<DWARFDIE> &member_function_and_type_dies,
DelayedPropertyList &delayed_properties,
const AccessType default_accessibility,
ClangASTImporter::LayoutInfo &layout_info) {
Expand Down Expand Up @@ -3189,8 +3189,11 @@ bool DWARFASTParserClang::ParseChildMembers(
break;

case DW_TAG_subprogram:
case DW_TAG_enumeration_type:
case DW_TAG_structure_type:
case DW_TAG_union_type:
// Let the type parsing code handle this one for us.
member_function_dies.push_back(die);
member_function_and_type_dies.push_back(die);
break;

case DW_TAG_inheritance:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -157,7 +157,7 @@ class DWARFASTParserClang : public DWARFASTParser {
bool ParseChildMembers(
const DWARFDIE &die, lldb_private::CompilerType &class_compiler_type,
std::vector<std::unique_ptr<clang::CXXBaseSpecifier>> &base_classes,
std::vector<DWARFDIE> &member_function_dies,
std::vector<DWARFDIE> &member_function_and_type_dies,
DelayedPropertyList &delayed_properties,
const lldb::AccessType default_accessibility,
lldb_private::ClangASTImporter::LayoutInfo &layout_info);
Expand Down
3 changes: 3 additions & 0 deletions lldb/test/API/lang/cpp/nested-type/Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
CXX_SOURCES := main.cpp

include Makefile.rules
33 changes: 33 additions & 0 deletions lldb/test/API/lang/cpp/nested-type/TestNestedType.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
"""
Test that nested types are parsed
"""
import lldb
from lldbsuite.test.lldbtest import *
import lldbsuite.test.lldbutil as lldbutil


class CPPNestedTypeTestCase(TestBase):
def test_with_run_command(self):
"""Test that nested types work in the expression evaluator"""
self.build()
lldbutil.run_to_source_breakpoint(
self, "// breakpoint 1", lldb.SBFileSpec("main.cpp")
)

self.expect_expr(
"(int)PointerIntPairInfo::MaskAndShiftConstants::PointerBitMask",
result_type="int",
result_value="42",
)

self.expect_expr(
"sizeof(PointerIntPairInfo::B)",
result_type="unsigned long",
result_value="1",
)

self.expect_expr(
"sizeof(PointerIntPairInfo::C)",
result_type="unsigned long",
result_value="1",
)
23 changes: 23 additions & 0 deletions lldb/test/API/lang/cpp/nested-type/main.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
struct PointerIntPairInfo {
enum MaskAndShiftConstants : unsigned long {
PointerBitMask = 42,
};

union B {};
B b;

struct C {};
C c;

int a{};
};

static unsigned long foo() {
return PointerIntPairInfo::PointerBitMask;
}

int main()
{
PointerIntPairInfo p;
return p.a + foo(); // breakpoint 1
}