[Lldb-commits] [lldb] 4651576 - Recognize the Swift compiler in DW_AT_producer
Adrian Prantl via lldb-commits
lldb-commits at lists.llvm.org
Thu Oct 7 13:54:34 PDT 2021
Author: Adrian Prantl
Date: 2021-10-07T13:54:28-07:00
New Revision: 4651576edd09bb4b0978db8592e938484e7bbd4f
URL: https://github.com/llvm/llvm-project/commit/4651576edd09bb4b0978db8592e938484e7bbd4f
DIFF: https://github.com/llvm/llvm-project/commit/4651576edd09bb4b0978db8592e938484e7bbd4f.diff
LOG: Recognize the Swift compiler in DW_AT_producer
This patch adds support for Swift compiler producer strings to DWARFUnit.
Differential Revision: https://reviews.llvm.org/D111278
Added:
Modified:
lldb/source/Plugins/SymbolFile/DWARF/DWARFUnit.cpp
lldb/source/Plugins/SymbolFile/DWARF/DWARFUnit.h
lldb/unittests/SymbolFile/DWARF/DWARFUnitTest.cpp
Removed:
################################################################################
diff --git a/lldb/source/Plugins/SymbolFile/DWARF/DWARFUnit.cpp b/lldb/source/Plugins/SymbolFile/DWARF/DWARFUnit.cpp
index 39411b54e036e..0eafd62eb9b9e 100644
--- a/lldb/source/Plugins/SymbolFile/DWARF/DWARFUnit.cpp
+++ b/lldb/source/Plugins/SymbolFile/DWARF/DWARFUnit.cpp
@@ -671,22 +671,28 @@ void DWARFUnit::ParseProducerInfo() {
if (producer.empty())
return;
- static RegularExpression g_llvm_gcc_regex(
+ static const RegularExpression g_swiftlang_version_regex(
+ llvm::StringRef(R"(swiftlang-([0-9]+\.[0-9]+\.[0-9]+(\.[0-9]+)?))"));
+ static const RegularExpression g_clang_version_regex(
+ llvm::StringRef(R"(clang-([0-9]+\.[0-9]+\.[0-9]+(\.[0-9]+)?))"));
+ static const 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;
+ llvm::SmallVector<llvm::StringRef, 3> matches;
+ if (g_swiftlang_version_regex.Execute(producer, &matches)) {
+ m_producer_version.tryParse(matches[1]);
+ m_producer = eProducerSwift;
} else if (producer.contains("clang")) {
- llvm::SmallVector<llvm::StringRef, 3> 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() {
diff --git a/lldb/source/Plugins/SymbolFile/DWARF/DWARFUnit.h b/lldb/source/Plugins/SymbolFile/DWARF/DWARFUnit.h
index 0e02da97fdb30..cece29dcf9ac8 100644
--- a/lldb/source/Plugins/SymbolFile/DWARF/DWARFUnit.h
+++ b/lldb/source/Plugins/SymbolFile/DWARF/DWARFUnit.h
@@ -29,6 +29,7 @@ enum DWARFProducer {
eProducerClang,
eProducerGCC,
eProducerLLVMGCC,
+ eProducerSwift,
eProducerOther
};
diff --git a/lldb/unittests/SymbolFile/DWARF/DWARFUnitTest.cpp b/lldb/unittests/SymbolFile/DWARF/DWARFUnitTest.cpp
index 85e3ae3cd8a5f..123acb6ea8e3f 100644
--- a/lldb/unittests/SymbolFile/DWARF/DWARFUnitTest.cpp
+++ b/lldb/unittests/SymbolFile/DWARF/DWARFUnitTest.cpp
@@ -155,3 +155,39 @@ TEST(DWARFUnitTest, LLVMGCCProducer) {
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));
+}
More information about the lldb-commits
mailing list