https://github.com/Endilll updated https://github.com/llvm/llvm-project/pull/66879
>From 72f83fb2944829c60bd6f12a079bfba95da4f6e7 Mon Sep 17 00:00:00 2001 From: Vlad Serebrennikov <serebrennikov.vladis...@gmail.com> Date: Thu, 14 Sep 2023 09:46:53 +0300 Subject: [PATCH 1/3] Implementation (migrated from Phabricator) --- .../SymbolFile/DWARF/DWARFASTParserClang.cpp | 15 +++++++++------ .../SymbolFile/DWARF/DWARFASTParserClang.h | 2 +- 2 files changed, 10 insertions(+), 7 deletions(-) diff --git a/lldb/source/Plugins/SymbolFile/DWARF/DWARFASTParserClang.cpp b/lldb/source/Plugins/SymbolFile/DWARF/DWARFASTParserClang.cpp index 37fb16d4e0351c9..fc340da8eba0763 100644 --- a/lldb/source/Plugins/SymbolFile/DWARF/DWARFASTParserClang.cpp +++ b/lldb/source/Plugins/SymbolFile/DWARF/DWARFASTParserClang.cpp @@ -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) { @@ -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) { @@ -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: diff --git a/lldb/source/Plugins/SymbolFile/DWARF/DWARFASTParserClang.h b/lldb/source/Plugins/SymbolFile/DWARF/DWARFASTParserClang.h index 88bfc490e890744..d4218959e61a8fa 100644 --- a/lldb/source/Plugins/SymbolFile/DWARF/DWARFASTParserClang.h +++ b/lldb/source/Plugins/SymbolFile/DWARF/DWARFASTParserClang.h @@ -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); >From 4a4aa7ad35124414aafdb7db44c89e51f498aa83 Mon Sep 17 00:00:00 2001 From: Vlad Serebrennikov <serebrennikov.vladis...@gmail.com> Date: Wed, 20 Sep 2023 12:32:44 +0300 Subject: [PATCH 2/3] Add an incomplete unit test --- .../DWARF/DWARFASTParserClangTests.cpp | 93 +++++++++++++++++++ 1 file changed, 93 insertions(+) diff --git a/lldb/unittests/SymbolFile/DWARF/DWARFASTParserClangTests.cpp b/lldb/unittests/SymbolFile/DWARF/DWARFASTParserClangTests.cpp index 20a085741f73d00..d47f9b636ec15eb 100644 --- a/lldb/unittests/SymbolFile/DWARF/DWARFASTParserClangTests.cpp +++ b/lldb/unittests/SymbolFile/DWARF/DWARFASTParserClangTests.cpp @@ -462,3 +462,96 @@ TEST_F(DWARFASTParserClangTests, TestDefaultTemplateParamParsing) { } } } + +TEST_F(DWARFASTParserClangTests, EnsureNestedTypesOfTypeAreParsed) { + const char *yamldata = R"( +--- !ELF +FileHeader: + Class: ELFCLASS64 + Data: ELFDATA2LSB + Type: ET_EXEC + Machine: EM_386 +DWARF: + debug_str: + - Info + - B + - C + - Mask + - Enum + debug_abbrev: + - Table: + - Code: 0x1 + Tag: DW_TAG_compile_unit + Children: DW_CHILDREN_yes + Attributes: + - Attribute: DW_AT_language + Form: DW_FORM_data2 + - Code: 0x2 + Tag: DW_TAG_structure_type + Children: DW_CHILDREN_yes + Attributes: + - Attribute: DW_AT_name + Form: DW_FORM_strp + - Code: 0x3 + Tag: DW_TAG_union_type + Children: DW_CHILDREN_no + Attributes: + - Attribute: DW_AT_name + Form: DW_FORM_strp + - Code: 0x4 + Tag: DW_TAG_structure_type + Children: DW_CHILDREN_no + Attributes: + - Attribute: DW_AT_name + Form: DW_FORM_strp + - Code: 0x5 + Tag: DW_TAG_enumeration_type + Children: DW_CHILDREN_yes + Attributes: + - Attribute: DW_AT_name + Form: DW_FORM_strp + - Code: 0x6 + Tag: DW_TAG_enumerator + Children: DW_CHILDREN_no + Attributes: + - Attribute: DW_AT_name + Form: DW_FORM_strp + debug_info: + - Version: 5 + AddrSize: 8 + UnitType: DW_UT_compile + Entries: + - AbbrCode: 0x1 + Values: + - Value: 0x21 + - AbbrCode: 0x2 + Values: + - Value: 0x0 + - AbbrCode: 0x3 + Values: + - Value: 0x5 + - AbbrCode: 0x4 + Values: + - Value: 0x7 + - AbbrCode: 0x5 + Values: + - Value: 0x9 + - AbbrCode: 0x6 + Values: + - Value: 0xE +)"; + + YAMLModuleTester t(yamldata); + + DWARFUnit *unit = t.GetDwarfUnit(); + ASSERT_NE(unit, nullptr); + const DWARFDebugInfoEntry *cu_entry = unit->DIE().GetDIE(); + ASSERT_EQ(cu_entry->Tag(), DW_TAG_compile_unit); + DWARFDIE cu_die(unit, cu_entry); + + auto holder = std::make_unique<clang_utils::TypeSystemClangHolder>("ast"); + auto &ast_ctx = *holder->GetAST(); + DWARFASTParserClangStub ast_parser(ast_ctx); + + EXPECT_TRUE(false); +} >From fdcf14efd2c5d84252c7b7be9049e68986458270 Mon Sep 17 00:00:00 2001 From: Vlad Serebrennikov <serebrennikov.vladis...@gmail.com> Date: Tue, 26 Sep 2023 20:02:41 +0300 Subject: [PATCH 3/3] Redo incomplete unit test as API test --- lldb/test/API/lang/cpp/nested-type/Makefile | 3 + .../lang/cpp/nested-type/TestNestedType.py | 33 +++++++ lldb/test/API/lang/cpp/nested-type/main.cpp | 23 +++++ .../DWARF/DWARFASTParserClangTests.cpp | 93 ------------------- 4 files changed, 59 insertions(+), 93 deletions(-) create mode 100644 lldb/test/API/lang/cpp/nested-type/Makefile create mode 100644 lldb/test/API/lang/cpp/nested-type/TestNestedType.py create mode 100644 lldb/test/API/lang/cpp/nested-type/main.cpp diff --git a/lldb/test/API/lang/cpp/nested-type/Makefile b/lldb/test/API/lang/cpp/nested-type/Makefile new file mode 100644 index 000000000000000..99998b20bcb0502 --- /dev/null +++ b/lldb/test/API/lang/cpp/nested-type/Makefile @@ -0,0 +1,3 @@ +CXX_SOURCES := main.cpp + +include Makefile.rules diff --git a/lldb/test/API/lang/cpp/nested-type/TestNestedType.py b/lldb/test/API/lang/cpp/nested-type/TestNestedType.py new file mode 100644 index 000000000000000..7aafda001a4eb3a --- /dev/null +++ b/lldb/test/API/lang/cpp/nested-type/TestNestedType.py @@ -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", + ) diff --git a/lldb/test/API/lang/cpp/nested-type/main.cpp b/lldb/test/API/lang/cpp/nested-type/main.cpp new file mode 100644 index 000000000000000..8ee06aac054544c --- /dev/null +++ b/lldb/test/API/lang/cpp/nested-type/main.cpp @@ -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 +} \ No newline at end of file diff --git a/lldb/unittests/SymbolFile/DWARF/DWARFASTParserClangTests.cpp b/lldb/unittests/SymbolFile/DWARF/DWARFASTParserClangTests.cpp index d47f9b636ec15eb..20a085741f73d00 100644 --- a/lldb/unittests/SymbolFile/DWARF/DWARFASTParserClangTests.cpp +++ b/lldb/unittests/SymbolFile/DWARF/DWARFASTParserClangTests.cpp @@ -462,96 +462,3 @@ TEST_F(DWARFASTParserClangTests, TestDefaultTemplateParamParsing) { } } } - -TEST_F(DWARFASTParserClangTests, EnsureNestedTypesOfTypeAreParsed) { - const char *yamldata = R"( ---- !ELF -FileHeader: - Class: ELFCLASS64 - Data: ELFDATA2LSB - Type: ET_EXEC - Machine: EM_386 -DWARF: - debug_str: - - Info - - B - - C - - Mask - - Enum - debug_abbrev: - - Table: - - Code: 0x1 - Tag: DW_TAG_compile_unit - Children: DW_CHILDREN_yes - Attributes: - - Attribute: DW_AT_language - Form: DW_FORM_data2 - - Code: 0x2 - Tag: DW_TAG_structure_type - Children: DW_CHILDREN_yes - Attributes: - - Attribute: DW_AT_name - Form: DW_FORM_strp - - Code: 0x3 - Tag: DW_TAG_union_type - Children: DW_CHILDREN_no - Attributes: - - Attribute: DW_AT_name - Form: DW_FORM_strp - - Code: 0x4 - Tag: DW_TAG_structure_type - Children: DW_CHILDREN_no - Attributes: - - Attribute: DW_AT_name - Form: DW_FORM_strp - - Code: 0x5 - Tag: DW_TAG_enumeration_type - Children: DW_CHILDREN_yes - Attributes: - - Attribute: DW_AT_name - Form: DW_FORM_strp - - Code: 0x6 - Tag: DW_TAG_enumerator - Children: DW_CHILDREN_no - Attributes: - - Attribute: DW_AT_name - Form: DW_FORM_strp - debug_info: - - Version: 5 - AddrSize: 8 - UnitType: DW_UT_compile - Entries: - - AbbrCode: 0x1 - Values: - - Value: 0x21 - - AbbrCode: 0x2 - Values: - - Value: 0x0 - - AbbrCode: 0x3 - Values: - - Value: 0x5 - - AbbrCode: 0x4 - Values: - - Value: 0x7 - - AbbrCode: 0x5 - Values: - - Value: 0x9 - - AbbrCode: 0x6 - Values: - - Value: 0xE -)"; - - YAMLModuleTester t(yamldata); - - DWARFUnit *unit = t.GetDwarfUnit(); - ASSERT_NE(unit, nullptr); - const DWARFDebugInfoEntry *cu_entry = unit->DIE().GetDIE(); - ASSERT_EQ(cu_entry->Tag(), DW_TAG_compile_unit); - DWARFDIE cu_die(unit, cu_entry); - - auto holder = std::make_unique<clang_utils::TypeSystemClangHolder>("ast"); - auto &ast_ctx = *holder->GetAST(); - DWARFASTParserClangStub ast_parser(ast_ctx); - - EXPECT_TRUE(false); -} _______________________________________________ lldb-commits mailing list lldb-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits