[llvm] r269692 - llvm-dwp: Streamline duplicate DWO ID diagnostic handling

David Blaikie via llvm-commits llvm-commits at lists.llvm.org
Mon May 16 13:42:27 PDT 2016


Author: dblaikie
Date: Mon May 16 15:42:27 2016
New Revision: 269692

URL: http://llvm.org/viewvc/llvm-project?rev=269692&view=rev
Log:
llvm-dwp: Streamline duplicate DWO ID diagnostic handling

Actually use the error return path rather than printing the duplicate
information then a separate error. But also just tidy up/deduplicate
some of the code for generating the diagnostic text.

Modified:
    llvm/trunk/test/tools/llvm-dwp/X86/duplicate.test
    llvm/trunk/tools/llvm-dwp/llvm-dwp.cpp

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=269692&r1=269691&r2=269692&view=diff
==============================================================================
--- llvm/trunk/test/tools/llvm-dwp/X86/duplicate.test (original)
+++ llvm/trunk/test/tools/llvm-dwp/X86/duplicate.test Mon May 16 15:42:27 2016
@@ -18,10 +18,10 @@ RUN:   | FileCheck --check-prefix=DWO1DW
 
 Build from a, b, and c.c all containing a single void() func by the name of the file.
 
-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'){{$}}
+DWOS: error: Duplicate DWO ID ({{.*}}) in 'c.c' and 'c.c'{{$}}
+1DWP: error: Duplicate DWO ID ({{.*}}) in 'c.c' (from '{{.*}}ac.dwp') and 'c.c'{{$}}
+2DWP: error: 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'){{$}}
+DWODWOS: error: Duplicate DWO ID ({{.*}}) in 'c.c' and 'c.c'{{$}}
+DWO1DWP: error: Duplicate DWO ID ({{.*}}) in 'c.c' (from 'c.dwo' in '{{.*}}ac.dwp') and 'c.c'{{$}}
+DWO2DWP: error: 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=269692&r1=269691&r2=269692&view=diff
==============================================================================
--- llvm/trunk/tools/llvm-dwp/llvm-dwp.cpp (original)
+++ llvm/trunk/tools/llvm-dwp/llvm-dwp.cpp Mon May 16 15:42:27 2016
@@ -346,24 +346,31 @@ 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 << '\'';
+std::string buildDWODescription(StringRef Name, StringRef DWPName, StringRef DWOName) {
+  std::string Text = "\'";
+  Text += Name;
+  Text += '\'';
   if (!DWPName.empty()) {
-    errs() << " (from ";
-    if (*ID.DWOName)
-      errs() << '\'' << ID.DWOName << "\' in ";
-    errs() << '\'' << DWPName << "')";
+    Text += " (from ";
+    if (!DWOName.empty()) {
+      Text += '\'';
+      Text += DWOName;
+      Text += "' in ";
+    }
+    Text += '\'';
+    Text += DWPName;
+    Text += "')";
   }
-  errs() << '\n';
+  return Text;
+}
+
+std::string
+buildDuplicateError(const std::pair<uint64_t, UnitIndexEntry> &PrevE,
+                    const CompileUnitIdentifiers &ID, StringRef DWPName) {
+  return std::string("Duplicate DWO ID (") + utohexstr(PrevE.first) + ") in " +
+         buildDWODescription(PrevE.second.Name, PrevE.second.DWPName,
+                             PrevE.second.DWOName) +
+         " and " + buildDWODescription(ID.Name, DWPName, ID.DWOName);
 }
 static Error write(MCStreamer &Out, ArrayRef<std::string> Inputs) {
   const auto &MCOFI = *Out.getContext().getObjectFileInfo();
@@ -504,10 +511,8 @@ static Error write(MCStreamer &Out, Arra
             getSubsection(InfoSection, E, DW_SECT_INFO),
             getSubsection(CurStrOffsetSection, E, DW_SECT_STR_OFFSETS),
             CurStrSection);
-        if (!P.second) {
-          printDuplicateError(*P.first, ID, Input);
-          return make_error<DWPError>("Duplicate DWO ID");
-        }
+        if (!P.second)
+          return make_error<DWPError>(buildDuplicateError(*P.first, ID, Input));
         auto &NewEntry = P.first->second;
         NewEntry.Name = ID.Name;
         NewEntry.DWOName = ID.DWOName;
@@ -535,10 +540,8 @@ static Error write(MCStreamer &Out, Arra
       CompileUnitIdentifiers ID = getCUIdentifiers(
           AbbrevSection, InfoSection, CurStrOffsetSection, CurStrSection);
       auto P = IndexEntries.insert(std::make_pair(ID.Signature, CurEntry));
-      if (!P.second) {
-        printDuplicateError(*P.first, ID, "");
-        return make_error<DWPError>("Duplicate DWO ID");
-      }
+      if (!P.second)
+        return make_error<DWPError>(buildDuplicateError(*P.first, ID, ""));
       P.first->second.Name = ID.Name;
       P.first->second.DWOName = ID.DWOName;
       addAllTypes(Out, TypeIndexEntries, TypesSection, CurTypesSection,




More information about the llvm-commits mailing list