[Lldb-commits] [PATCH] D111278: Recognize the Swift compiler in DW_AT_producer

Adrian Prantl via Phabricator via lldb-commits lldb-commits at lists.llvm.org
Thu Oct 7 13:54:47 PDT 2021


This revision was automatically updated to reflect the committed changes.
Closed by commit rG4651576edd09: Recognize the Swift compiler in DW_AT_producer (authored by aprantl).
Herald added a project: LLDB.

Changed prior to commit:
  https://reviews.llvm.org/D111278?vs=377977&id=378001#toc

Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D111278/new/

https://reviews.llvm.org/D111278

Files:
  lldb/source/Plugins/SymbolFile/DWARF/DWARFUnit.cpp
  lldb/source/Plugins/SymbolFile/DWARF/DWARFUnit.h
  lldb/unittests/SymbolFile/DWARF/DWARFUnitTest.cpp


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));
+}
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_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() {


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D111278.378001.patch
Type: text/x-patch
Size: 3406 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/lldb-commits/attachments/20211007/368e1a55/attachment.bin>


More information about the lldb-commits mailing list