[Lldb-commits] [lldb] 8c5f334 - Add a unit test for llvm-gcc producer strings and cleanup code. (NFC)

Adrian Prantl via lldb-commits lldb-commits at lists.llvm.org
Wed Oct 6 14:56:32 PDT 2021


Author: Adrian Prantl
Date: 2021-10-06T14:56:17-07:00
New Revision: 8c5f3348af38843b5f0ca13e82cc285af4e3582d

URL: https://github.com/llvm/llvm-project/commit/8c5f3348af38843b5f0ca13e82cc285af4e3582d
DIFF: https://github.com/llvm/llvm-project/commit/8c5f3348af38843b5f0ca13e82cc285af4e3582d.diff

LOG: Add a unit test for llvm-gcc producer strings and cleanup code. (NFC)

Added: 
    

Modified: 
    lldb/source/Plugins/SymbolFile/DWARF/DWARFUnit.cpp
    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 17417f7a5326..39411b54e036 100644
--- a/lldb/source/Plugins/SymbolFile/DWARF/DWARFUnit.cpp
+++ b/lldb/source/Plugins/SymbolFile/DWARF/DWARFUnit.cpp
@@ -671,16 +671,17 @@ void DWARFUnit::ParseProducerInfo() {
   if (producer.empty())
     return;
 
-  static RegularExpression llvm_gcc_regex(
-      llvm::StringRef("^4\\.[012]\\.[01] \\(Based on Apple "
-                      "Inc\\. build [0-9]+\\) \\(LLVM build "
-                      "[\\.0-9]+\\)$"));
-  if (llvm_gcc_regex.Execute(producer)) {
+  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;
   } else if (producer.contains("clang")) {
-    static RegularExpression g_clang_version_regex(
-        llvm::StringRef(R"(clang-([0-9]+\.[0-9]+\.[0-9]+(\.[0-9]+)?))"));
-    llvm::SmallVector<llvm::StringRef, 4> matches;
+    llvm::SmallVector<llvm::StringRef, 3> matches;
     if (g_clang_version_regex.Execute(producer, &matches))
       m_producer_version.tryParse(matches[1]);
     m_producer = eProducerClang;

diff  --git a/lldb/unittests/SymbolFile/DWARF/DWARFUnitTest.cpp b/lldb/unittests/SymbolFile/DWARF/DWARFUnitTest.cpp
index 5b36f22aea1b..85e3ae3cd8a5 100644
--- a/lldb/unittests/SymbolFile/DWARF/DWARFUnitTest.cpp
+++ b/lldb/unittests/SymbolFile/DWARF/DWARFUnitTest.cpp
@@ -85,7 +85,7 @@ TEST(DWARFUnitTest, MissingSentinel) {
   EXPECT_EQ(die_first->GetSibling(), nullptr);
 }
 
-TEST(DWARFUnitTest, Producer) {
+TEST(DWARFUnitTest, ClangProducer) {
   const char *yamldata = R"(
 --- !ELF
 FileHeader:
@@ -104,8 +104,6 @@ TEST(DWARFUnitTest, Producer) {
           Attributes:
             - Attribute:       DW_AT_producer
               Form:            DW_FORM_strp
-            - Attribute:       DW_AT_language
-              Form:            DW_FORM_data2
   debug_info:
     - Version:         4
       AddrSize:        8
@@ -113,7 +111,6 @@ TEST(DWARFUnitTest, Producer) {
         - AbbrCode:        0x1
           Values:
             - Value:           0x0
-            - Value:           0xC
         - AbbrCode:        0x0
 )";
 
@@ -123,3 +120,38 @@ TEST(DWARFUnitTest, Producer) {
   EXPECT_EQ(unit->GetProducer(), eProducerClang);
   EXPECT_EQ(unit->GetProducerVersion(), llvm::VersionTuple(1300, 0, 29, 3));
 }
+
+TEST(DWARFUnitTest, LLVMGCCProducer) {
+  const char *yamldata = R"(
+--- !ELF
+FileHeader:
+  Class:   ELFCLASS64
+  Data:    ELFDATA2LSB
+  Type:    ET_EXEC
+  Machine: EM_386
+DWARF:
+  debug_str:
+    - 'i686-apple-darwin11-llvm-gcc-4.2 (GCC) 4.2.1 (Based on Apple Inc. build 5658) (LLVM build 2336.11.00)'
+  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(), eProducerLLVMGCC);
+}


        


More information about the lldb-commits mailing list