Index: lldb/source/Plugins/SymbolFile/DWARF/DWARFUnit.h =================================================================== --- lldb/source/Plugins/SymbolFile/DWARF/DWARFUnit.h +++ lldb/source/Plugins/SymbolFile/DWARF/DWARFUnit.h @@ -29,6 +29,7 @@ eProducerClang, eProducerGCC, eProducerLLVMGCC, + eProducerSwift, eProducerOther }; Index: lldb/source/Plugins/SymbolFile/DWARF/DWARFUnit.cpp =================================================================== --- lldb/source/Plugins/SymbolFile/DWARF/DWARFUnit.cpp +++ lldb/source/Plugins/SymbolFile/DWARF/DWARFUnit.cpp @@ -671,22 +671,28 @@ if (producer.empty()) return; + static RegularExpression g_clang_version_regex( + llvm::StringRef(R"(clang-([0-9]+\.[0-9]+\.[0-9]+(\.[0-9]+)?))")); + static RegularExpression g_swiftlang_version_regex( + llvm::StringRef(R"(swiftlang-([0-9]+\.[0-9]+\.[0-9]+(\.[0-9]+)?))")); + llvm::SmallVector matches; static RegularExpression g_llvm_gcc_regex( llvm::StringRef(R"(4\.[012]\.[01] )" R"(\(Based on Apple Inc\. build [0-9]+\) )" R"(\(LLVM build [\.0-9]+\)$)")); - static RegularExpression g_clang_version_regex( - llvm::StringRef(R"(clang-([0-9]+\.[0-9]+\.[0-9]+(\.[0-9]+)?))")); - if (g_llvm_gcc_regex.Execute(producer)) { - m_producer = eProducerLLVMGCC; + if (g_swiftlang_version_regex.Execute(producer, &matches)) { + m_producer_version.tryParse(matches[1]); + m_producer = eProducerSwift; } else if (producer.contains("clang")) { - llvm::SmallVector matches; if (g_clang_version_regex.Execute(producer, &matches)) m_producer_version.tryParse(matches[1]); m_producer = eProducerClang; - } else if (producer.contains("GNU")) + } else if (producer.contains("GNU")) { m_producer = eProducerGCC; + } else if (g_llvm_gcc_regex.Execute(producer)) { + m_producer = eProducerLLVMGCC; + } } DWARFProducer DWARFUnit::GetProducer() { Index: lldb/unittests/SymbolFile/DWARF/DWARFUnitTest.cpp =================================================================== --- lldb/unittests/SymbolFile/DWARF/DWARFUnitTest.cpp +++ lldb/unittests/SymbolFile/DWARF/DWARFUnitTest.cpp @@ -155,3 +155,39 @@ ASSERT_TRUE((bool)unit); EXPECT_EQ(unit->GetProducer(), eProducerLLVMGCC); } + +TEST(DWARFUnitTest, SwiftProducer) { + const char *yamldata = R"( +--- !ELF +FileHeader: + Class: ELFCLASS64 + Data: ELFDATA2LSB + Type: ET_EXEC + Machine: EM_386 +DWARF: + debug_str: + - 'Apple Swift version 5.5 (swiftlang-1300.0.31.1 clang-1300.0.29.1)' + debug_abbrev: + - Table: + - Code: 0x00000001 + Tag: DW_TAG_compile_unit + Children: DW_CHILDREN_yes + Attributes: + - Attribute: DW_AT_producer + Form: DW_FORM_strp + debug_info: + - Version: 4 + AddrSize: 8 + Entries: + - AbbrCode: 0x1 + Values: + - Value: 0x0 + - AbbrCode: 0x0 +)"; + + YAMLModuleTester t(yamldata); + DWARFUnit *unit = t.GetDwarfUnit(); + ASSERT_TRUE((bool)unit); + EXPECT_EQ(unit->GetProducer(), eProducerSwift); + EXPECT_EQ(unit->GetProducerVersion(), llvm::VersionTuple(1300, 0, 31, 1)); +}