[llvm] r264520 - llvm-dwp: Include the dwo name (if available) when diagnosing duplicate CU IDs from dwp input files

David Blaikie via llvm-commits llvm-commits at lists.llvm.org
Sat Mar 26 13:32:15 PDT 2016


Author: dblaikie
Date: Sat Mar 26 15:32:14 2016
New Revision: 264520

URL: http://llvm.org/viewvc/llvm-project?rev=264520&view=rev
Log:
llvm-dwp: Include the dwo name (if available) when diagnosing duplicate CU IDs from dwp input files

If you're building dwps from other dwps, it can be hard to track down a
duplicate CU ID if it comes from two compilations of the same file in
different modes, etc. By including the .dwo path (which is hopefully
more unique than the file path) it can help track down where the
duplicates came from.

Added:
    llvm/trunk/test/tools/llvm-dwp/Inputs/duplicate_dwo_name/
    llvm/trunk/test/tools/llvm-dwp/Inputs/duplicate_dwo_name/ac.dwp
    llvm/trunk/test/tools/llvm-dwp/Inputs/duplicate_dwo_name/bc.dwp
    llvm/trunk/test/tools/llvm-dwp/Inputs/duplicate_dwo_name/c.dwo
Modified:
    llvm/trunk/test/tools/llvm-dwp/X86/duplicate.test
    llvm/trunk/tools/llvm-dwp/llvm-dwp.cpp

Added: llvm/trunk/test/tools/llvm-dwp/Inputs/duplicate_dwo_name/ac.dwp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/test/tools/llvm-dwp/Inputs/duplicate_dwo_name/ac.dwp?rev=264520&view=auto
==============================================================================
Binary files llvm/trunk/test/tools/llvm-dwp/Inputs/duplicate_dwo_name/ac.dwp (added) and llvm/trunk/test/tools/llvm-dwp/Inputs/duplicate_dwo_name/ac.dwp Sat Mar 26 15:32:14 2016 differ

Added: llvm/trunk/test/tools/llvm-dwp/Inputs/duplicate_dwo_name/bc.dwp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/test/tools/llvm-dwp/Inputs/duplicate_dwo_name/bc.dwp?rev=264520&view=auto
==============================================================================
Binary files llvm/trunk/test/tools/llvm-dwp/Inputs/duplicate_dwo_name/bc.dwp (added) and llvm/trunk/test/tools/llvm-dwp/Inputs/duplicate_dwo_name/bc.dwp Sat Mar 26 15:32:14 2016 differ

Added: llvm/trunk/test/tools/llvm-dwp/Inputs/duplicate_dwo_name/c.dwo
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/test/tools/llvm-dwp/Inputs/duplicate_dwo_name/c.dwo?rev=264520&view=auto
==============================================================================
Binary files llvm/trunk/test/tools/llvm-dwp/Inputs/duplicate_dwo_name/c.dwo (added) and llvm/trunk/test/tools/llvm-dwp/Inputs/duplicate_dwo_name/c.dwo Sat Mar 26 15:32:14 2016 differ

Modified: llvm/trunk/test/tools/llvm-dwp/X86/duplicate.test
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/test/tools/llvm-dwp/X86/duplicate.test?rev=264520&r1=264519&r2=264520&view=diff
==============================================================================
--- llvm/trunk/test/tools/llvm-dwp/X86/duplicate.test (original)
+++ llvm/trunk/test/tools/llvm-dwp/X86/duplicate.test Sat Mar 26 15:32:14 2016
@@ -1,18 +1,27 @@
 RUN: not llvm-dwp %p/../Inputs/duplicate/c.dwo %p/../Inputs/duplicate/c.dwo -o %t 2>&1 \
-RUN:   | FileCheck --check-prefix=CHECK %s
+RUN:   | FileCheck --check-prefix=DWOS %s
 
 RUN: not llvm-dwp %p/../Inputs/duplicate/c.dwo %p/../Inputs/duplicate/bc.dwp -o %t 2>&1 \
-RUN:   | FileCheck --check-prefix=CHECK --check-prefix=DWP2 %s
+RUN:   | FileCheck --check-prefix=2DWP %s
 
 RUN: not llvm-dwp %p/../Inputs/duplicate/ac.dwp %p/../Inputs/duplicate/c.dwo -o %t 2>&1 \
-RUN:   | FileCheck --check-prefix=CHECK --check-prefix=DWP1 %s
+RUN:   | FileCheck --check-prefix=1DWP %s
 
-RUN: not llvm-dwp %p/../Inputs/duplicate/ac.dwp %p/../Inputs/duplicate/bc.dwp -o %t 2>&1 \
-RUN:   | FileCheck --check-prefix=CHECK --check-prefix=DWP1 --check-prefix=DWP2 %s
+RUN: not llvm-dwp %p/../Inputs/duplicate_dwo_name/c.dwo %p/../Inputs/duplicate_dwo_name/c.dwo -o %t 2>&1 \
+RUN:   | FileCheck --check-prefix=DWODWOS %s
+
+RUN: not llvm-dwp %p/../Inputs/duplicate_dwo_name/c.dwo %p/../Inputs/duplicate_dwo_name/bc.dwp -o %t 2>&1 \
+RUN:   | FileCheck --check-prefix=DWO2DWP %s
+
+RUN: not llvm-dwp %p/../Inputs/duplicate_dwo_name/ac.dwp %p/../Inputs/duplicate_dwo_name/c.dwo -o %t 2>&1 \
+RUN:   | FileCheck --check-prefix=DWO1DWP %s
 
 Build from a, b, and c.c all containing a single void() func by the name of the file.
 
-CHECK: Duplicate DWO ID ({{.*}}) in 'c.c'
-DWP1-SAME: (from '{{.*}}ac.dwp')
-CHECK-SAME: and 'c.c'
-DWP2-SAME: (from '{{.*}}bc.dwp')
+DWOS: Duplicate DWO ID ({{.*}}) in 'c.c' and 'c.c'{{$}}
+1DWP: Duplicate DWO ID ({{.*}}) in 'c.c' (from '{{.*}}ac.dwp') and 'c.c'{{$}}
+2DWP: Duplicate DWO ID ({{.*}}) in 'c.c' and 'c.c' (from '{{.*}}bc.dwp'){{$}}
+
+DWODWOS: Duplicate DWO ID ({{.*}}) in 'c.c' and 'c.c'{{$}}
+DWO1DWP: Duplicate DWO ID ({{.*}}) in 'c.c' (from 'c.dwo' in '{{.*}}ac.dwp') and 'c.c'{{$}}
+DWO2DWP: Duplicate DWO ID ({{.*}}) in 'c.c' and 'c.c' (from 'c.dwo' in '{{.*}}bc.dwp'){{$}}

Modified: llvm/trunk/tools/llvm-dwp/llvm-dwp.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/tools/llvm-dwp/llvm-dwp.cpp?rev=264520&r1=264519&r2=264520&view=diff
==============================================================================
--- llvm/trunk/tools/llvm-dwp/llvm-dwp.cpp (original)
+++ llvm/trunk/tools/llvm-dwp/llvm-dwp.cpp Sat Mar 26 15:32:14 2016
@@ -122,10 +122,19 @@ static uint32_t getCUAbbrev(StringRef Ab
 
 struct CompileUnitIdentifiers {
   uint64_t Signature = 0;
-  const char *Name = nullptr;
-  const char *DWOName = nullptr;
+  const char *Name = "";
+  const char *DWOName = "";
 };
 
+static const char *getIndexedString(uint32_t StrIndex, StringRef StrOffsets,
+                                    StringRef Str) {
+  DataExtractor StrOffsetsData(StrOffsets, true, 0);
+  uint32_t StrOffsetsOffset = 4 * StrIndex;
+  uint32_t StrOffset = StrOffsetsData.getU32(&StrOffsetsOffset);
+  DataExtractor StrData(Str, true, 0);
+  return StrData.getCStr(&StrOffset);
+}
+
 static CompileUnitIdentifiers getCUIdentifiers(StringRef Abbrev, StringRef Info,
                                                StringRef StrOffsets,
                                                StringRef Str) {
@@ -154,13 +163,12 @@ static CompileUnitIdentifiers getCUIdent
          (Name != 0 || Form != 0)) {
     switch (Name) {
     case dwarf::DW_AT_name: {
-      auto StrIndex = InfoData.getULEB128(&Offset);
-
-      DataExtractor StrOffsetsData(StrOffsets, true, 0);
-      uint32_t StrOffsetsOffset = 4 * StrIndex;
-      uint32_t StrOffset = StrOffsetsData.getU32(&StrOffsetsOffset);
-      DataExtractor StrData(Str, true, 0);
-      ID.Name = StrData.getCStr(&StrOffset);
+      ID.Name = getIndexedString(InfoData.getULEB128(&Offset), StrOffsets, Str);
+      break;
+    }
+    case dwarf::DW_AT_GNU_dwo_name: {
+      ID.DWOName =
+          getIndexedString(InfoData.getULEB128(&Offset), StrOffsets, Str);
       break;
     }
     case dwarf::DW_AT_GNU_dwo_id:
@@ -176,6 +184,7 @@ static CompileUnitIdentifiers getCUIdent
 struct UnitIndexEntry {
   DWARFUnitIndex::Entry::SectionContribution Contributions[8];
   std::string Name;
+  std::string DWOName;
   StringRef DWPName;
 };
 
@@ -331,6 +340,25 @@ static bool consumeCompressedDebugSectio
   return true;
 }
 
+void printDuplicateError(const std::pair<uint64_t, UnitIndexEntry> &PrevE,
+                         const CompileUnitIdentifiers &ID, StringRef DWPName) {
+  errs() << "Duplicate DWO ID (" << PrevE.first << ") in '" << PrevE.second.Name
+         << '\'';
+  if (!PrevE.second.DWPName.empty()) {
+    errs() << " (from ";
+    if (!PrevE.second.DWOName.empty())
+      errs() << '\'' << PrevE.second.DWOName << "' in ";
+    errs() << "'" << PrevE.second.DWPName.str() << "')";
+  }
+  errs() << " and '" << ID.Name << '\'';
+  if (!DWPName.empty()) {
+    errs() << " (from ";
+    if (*ID.DWOName)
+      errs() << '\'' << ID.DWOName << "\' in ";
+    errs() << '\'' << DWPName << "')";
+  }
+  errs() << '\n';
+}
 static std::error_code write(MCStreamer &Out, ArrayRef<std::string> Inputs) {
   const auto &MCOFI = *Out.getContext().getObjectFileInfo();
   MCSection *const StrSection = MCOFI.getDwarfStrDWOSection();
@@ -468,15 +496,12 @@ static std::error_code write(MCStreamer
             getSubsection(CurStrOffsetSection, E, DW_SECT_STR_OFFSETS),
             CurStrSection);
         if (!P.second) {
-          auto &PrevE = *P.first;
-          std::cerr << "Duplicate DWO ID (" << PrevE.first << ") in '" << PrevE.second.Name << "' ";
-          if (!PrevE.second.DWPName.empty())
-            std::cerr << "(from '" << PrevE.second.DWPName.str() << "') ";
-          std::cerr << "and '" << ID.Name << "' (from '" << Input << "')\n";
+          printDuplicateError(*P.first, ID, Input);
           return make_error_code(std::errc::invalid_argument);
         }
         auto &NewEntry = P.first->second;
         NewEntry.Name = ID.Name;
+        NewEntry.DWOName = ID.DWOName;
         NewEntry.DWPName = Input;
         for (auto Kind : CUIndex.getColumnKinds()) {
           auto &C = NewEntry.Contributions[Kind - DW_SECT_INFO];
@@ -503,15 +528,11 @@ static std::error_code write(MCStreamer
           AbbrevSection, InfoSection, CurStrOffsetSection, CurStrSection);
       auto P = IndexEntries.insert(std::make_pair(ID.Signature, CurEntry));
       if (!P.second) {
-        auto &E = *P.first;
-        std::cerr << "Duplicate DWO ID (" << E.first << ") in '" << ID.Name
-                  << "' ";
-        if (!E.second.DWPName.empty())
-          std::cerr << "(from '" << E.second.DWPName.str() << "') ";
-        std::cerr << "and '" << E.second.Name << "'\n";
+        printDuplicateError(*P.first, ID, "");
         return make_error_code(std::errc::invalid_argument);
       }
       P.first->second.Name = ID.Name;
+      P.first->second.DWOName = ID.DWOName;
       addAllTypes(Out, TypeIndexEntries, TypesSection, CurTypesSection,
                   CurEntry, ContributionOffsets[DW_SECT_TYPES - DW_SECT_INFO]);
     }




More information about the llvm-commits mailing list