From 119b9304a9b02ae8740c11742055517373e8c186 Mon Sep 17 00:00:00 2001 From: David Blaikie Date: Mon, 16 May 2016 20:42:27 +0000 Subject: [PATCH] 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. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@269692 91177308-0d34-0410-b5e6-96231b3b80d8 --- test/tools/llvm-dwp/X86/duplicate.test | 12 ++++---- tools/llvm-dwp/llvm-dwp.cpp | 51 ++++++++++++++++++---------------- 2 files changed, 33 insertions(+), 30 deletions(-) diff --git a/test/tools/llvm-dwp/X86/duplicate.test b/test/tools/llvm-dwp/X86/duplicate.test index 67b68294789..43266a24b60 100644 --- a/test/tools/llvm-dwp/X86/duplicate.test +++ b/test/tools/llvm-dwp/X86/duplicate.test @@ -18,10 +18,10 @@ 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. -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'){{$}} diff --git a/tools/llvm-dwp/llvm-dwp.cpp b/tools/llvm-dwp/llvm-dwp.cpp index f25c87c241a..5e83d7c9cac 100644 --- a/tools/llvm-dwp/llvm-dwp.cpp +++ b/tools/llvm-dwp/llvm-dwp.cpp @@ -346,24 +346,31 @@ static bool consumeCompressedDebugSectionHeader(StringRef &data, return true; } -void printDuplicateError(const std::pair &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 &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 Inputs) { const auto &MCOFI = *Out.getContext().getObjectFileInfo(); @@ -504,10 +511,8 @@ static Error write(MCStreamer &Out, ArrayRef Inputs) { 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("Duplicate DWO ID"); - } + if (!P.second) + return make_error(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, ArrayRef Inputs) { 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("Duplicate DWO ID"); - } + if (!P.second) + return make_error(buildDuplicateError(*P.first, ID, "")); P.first->second.Name = ID.Name; P.first->second.DWOName = ID.DWOName; addAllTypes(Out, TypeIndexEntries, TypesSection, CurTypesSection, -- 2.11.0