From 62be5ae5779c9e7acd8c8e17a89694d7fadaed2f Mon Sep 17 00:00:00 2001 From: David Blaikie Date: Tue, 5 Apr 2016 20:26:50 +0000 Subject: [PATCH] llvm-dwp: Handle GCC's use of multiple debug_types.dwo sections in a single .dwo file (also includes the .test file missing from my previous commit, r265452) llvm-svn: 265457 --- llvm/test/tools/llvm-dwp/X86/gcc_type.test | 9 +++++ llvm/tools/llvm-dwp/llvm-dwp.cpp | 63 +++++++++++++++--------------- 2 files changed, 41 insertions(+), 31 deletions(-) create mode 100644 llvm/test/tools/llvm-dwp/X86/gcc_type.test diff --git a/llvm/test/tools/llvm-dwp/X86/gcc_type.test b/llvm/test/tools/llvm-dwp/X86/gcc_type.test new file mode 100644 index 0000000..b05fb01 --- /dev/null +++ b/llvm/test/tools/llvm-dwp/X86/gcc_type.test @@ -0,0 +1,9 @@ +RUN: llvm-dwp %p/../Inputs/gcc_type/a.dwo -o %t +RUN: llvm-dwarfdump %t | FileCheck %s +RUN: not llvm-dwp %p/../Inputs/gcc_type/a.dwo %p/../Inputs/gcc_type/a.dwo -o %t 2>&1 | FileCheck --check-prefix=DUP %s + +CHECK: Type Unit +CHECK: Type Unit + +// Check that llvm-dwp can parse DW_FORM_string for CU name +DUP: Duplicate DWO ID ({{.*}}) in 'a.cpp' and 'a.cpp' diff --git a/llvm/tools/llvm-dwp/llvm-dwp.cpp b/llvm/tools/llvm-dwp/llvm-dwp.cpp index f9dada2..bd83610 100644 --- a/llvm/tools/llvm-dwp/llvm-dwp.cpp +++ b/llvm/tools/llvm-dwp/llvm-dwp.cpp @@ -231,36 +231,36 @@ static void addAllTypesFromDWP( static void addAllTypes(MCStreamer &Out, MapVector &TypeIndexEntries, - MCSection *OutputTypes, StringRef Types, + MCSection *OutputTypes, + const std::vector &TypesSections, const UnitIndexEntry &CUEntry, uint32_t &TypesOffset) { - if (Types.empty()) - return; - - Out.SwitchSection(OutputTypes); - uint32_t Offset = 0; - DataExtractor Data(Types, true, 0); - while (Data.isValidOffset(Offset)) { - UnitIndexEntry Entry = CUEntry; - // Zero out the debug_info contribution - Entry.Contributions[0] = {}; - auto &C = Entry.Contributions[DW_SECT_TYPES - DW_SECT_INFO]; - C.Offset = TypesOffset; - auto PrevOffset = Offset; - // Length of the unit, including the 4 byte length field. - C.Length = Data.getU32(&Offset) + 4; - - Data.getU16(&Offset); // Version - Data.getU32(&Offset); // Abbrev offset - Data.getU8(&Offset); // Address size - auto Signature = Data.getU64(&Offset); - Offset = PrevOffset + C.Length; - - auto P = TypeIndexEntries.insert(std::make_pair(Signature, Entry)); - if (!P.second) - continue; + for (StringRef Types : TypesSections) { + Out.SwitchSection(OutputTypes); + uint32_t Offset = 0; + DataExtractor Data(Types, true, 0); + while (Data.isValidOffset(Offset)) { + UnitIndexEntry Entry = CUEntry; + // Zero out the debug_info contribution + Entry.Contributions[0] = {}; + auto &C = Entry.Contributions[DW_SECT_TYPES - DW_SECT_INFO]; + C.Offset = TypesOffset; + auto PrevOffset = Offset; + // Length of the unit, including the 4 byte length field. + C.Length = Data.getU32(&Offset) + 4; + + Data.getU16(&Offset); // Version + Data.getU32(&Offset); // Abbrev offset + Data.getU8(&Offset); // Address size + auto Signature = Data.getU64(&Offset); + Offset = PrevOffset + C.Length; + + auto P = TypeIndexEntries.insert(std::make_pair(Signature, Entry)); + if (!P.second) + continue; - Out.EmitBytes(Types.substr(PrevOffset, C.Length)); - TypesOffset += C.Length; + Out.EmitBytes(Types.substr(PrevOffset, C.Length)); + TypesOffset += C.Length; + } } } @@ -399,7 +399,7 @@ static std::error_code write(MCStreamer &Out, ArrayRef Inputs) { StringRef CurStrSection; StringRef CurStrOffsetSection; - StringRef CurTypesSection; + std::vector CurTypesSection; StringRef InfoSection; StringRef AbbrevSection; StringRef CurCUIndexSection; @@ -468,7 +468,7 @@ static std::error_code write(MCStreamer &Out, ArrayRef Inputs) { else if (OutSection == StrSection) CurStrSection = Contents; else if (OutSection == TypesSection) - CurTypesSection = Contents; + CurTypesSection.push_back(Contents); else if (OutSection == CUIndexSection) CurCUIndexSection = Contents; else if (OutSection == TUIndexSection) @@ -517,6 +517,7 @@ static std::error_code write(MCStreamer &Out, ArrayRef Inputs) { } if (!CurTypesSection.empty()) { + assert(CurTypesSection.size() == 1); if (CurTUIndexSection.empty()) return make_error_code(std::errc::invalid_argument); DWARFUnitIndex TUIndex(DW_SECT_TYPES); @@ -525,7 +526,7 @@ static std::error_code write(MCStreamer &Out, ArrayRef Inputs) { if (!TUIndex.parse(TUIndexData)) return make_error_code(std::errc::invalid_argument); addAllTypesFromDWP(Out, TypeIndexEntries, TUIndex, TypesSection, - CurTypesSection, CurEntry, + CurTypesSection.front(), CurEntry, ContributionOffsets[DW_SECT_TYPES - DW_SECT_INFO]); } } else { -- 2.7.4