From 23919372d1db1dba80e8c4697e0a0922e830fc3a Mon Sep 17 00:00:00 2001 From: David Blaikie Date: Sat, 6 Feb 2016 01:15:26 +0000 Subject: [PATCH] [llvm-dwp] Merge cu_index from DWPs This is almost feature complete - just missing tu_index merging now. llvm-svn: 259971 --- .../llvm/DebugInfo/DWARF/DWARFUnitIndex.h | 11 ++++ .../llvm-dwp/Inputs/merge/notypes/ab.dwp | Bin 0 -> 1384 bytes .../tools/llvm-dwp/Inputs/merge/notypes/c.dwo | Bin 0 -> 1257 bytes llvm/test/tools/llvm-dwp/X86/merge.test | 48 ++++++++++++++++++ llvm/tools/llvm-dwp/llvm-dwp.cpp | 43 +++++++++++++--- 5 files changed, 96 insertions(+), 6 deletions(-) create mode 100644 llvm/test/tools/llvm-dwp/Inputs/merge/notypes/ab.dwp create mode 100644 llvm/test/tools/llvm-dwp/Inputs/merge/notypes/c.dwo create mode 100644 llvm/test/tools/llvm-dwp/X86/merge.test diff --git a/llvm/include/llvm/DebugInfo/DWARF/DWARFUnitIndex.h b/llvm/include/llvm/DebugInfo/DWARF/DWARFUnitIndex.h index a85c2f9f0a23..9f051cd7081c 100644 --- a/llvm/include/llvm/DebugInfo/DWARF/DWARFUnitIndex.h +++ b/llvm/include/llvm/DebugInfo/DWARF/DWARFUnitIndex.h @@ -10,6 +10,7 @@ #ifndef LLVM_LIB_DEBUGINFO_DWARFUNITINDEX_H #define LLVM_LIB_DEBUGINFO_DWARFUNITINDEX_H +#include "llvm/ADT/ArrayRef.h" #include "llvm/Support/DataExtractor.h" #include "llvm/Support/Format.h" #include "llvm/Support/raw_ostream.h" @@ -56,6 +57,10 @@ public: public: const SectionContribution *getOffset(DWARFSectionKind Sec) const; const SectionContribution *getOffset() const; + const SectionContribution *getOffsets() const { + return Contributions.get(); + } + uint64_t getSignature() const { return Signature; } }; private: @@ -75,6 +80,12 @@ public: : InfoColumnKind(InfoColumnKind) {} void dump(raw_ostream &OS) const; const Entry *getFromOffset(uint32_t Offset) const; + ArrayRef getColumnKinds() const { + return makeArrayRef(ColumnKinds.get(), Header.NumColumns); + } + ArrayRef getRows() const { + return makeArrayRef(Rows.get(), Header.NumBuckets); + } }; } diff --git a/llvm/test/tools/llvm-dwp/Inputs/merge/notypes/ab.dwp b/llvm/test/tools/llvm-dwp/Inputs/merge/notypes/ab.dwp new file mode 100644 index 0000000000000000000000000000000000000000..a3274f1e23e79537a6467800ad0ea74db5ab1823 GIT binary patch literal 1384 zcmbtU&2G~`5T0G9KOzDV%ptv5K&9qll7Q&~;z%1%O%KtK=@ z7o_wB;2HV^9J%)idgRWr7iR3;rWuepFw*SI_suu6%50K%_a5GtLVz{_4$P2d0e;F^ z?q;bAXHdC{c_G8g0u%B0@a^|cN5&f|FC#0YJO;xMctMQ`pM3l=o&MVYCh>M*z#^%) zjDnB_xjz=NoXr#^u{v?g1!LkI++G5Z*8tO&*<9Hy-Yk;HFo`J^3DXGPFjqEgQTpIq zSai$L#KAUdYOdf1SO8fj&@yqxS#$|_8whcH4wvx<(dm29wlxZpG>jvwZr`x0*4iK$ zMmyGeqrOqys90*%-8n*`AA zptsN;p>LtnJJ7;)#B|Q|1L*zgB0VbgP&CkK1}&Xi1qphq68d>`jvL6`RrQM)|7CVJ z@Q2&&&afRu-Czs~d%m9pBfI-5)=WA`+HtR!27{E*r(qcN;?uYvM!_78J2}L01J4IL zeZ5QZe{GBdXl>kH(oWGn=i%h!zo8H-oFlPI$6t(V=_|lFYIEs8dy$8elWXZYIY;8J zs$;044qW>T3!EdZsmM#ZQAMuZM4q@R(>0XvDdTm&j@iEn(-8ck1Xoy1_i36i=csm| e$f*{p$hGg0S5G~se4xnu|0=(OdY6?-^S=Qgg@NP% literal 0 HcmV?d00001 diff --git a/llvm/test/tools/llvm-dwp/Inputs/merge/notypes/c.dwo b/llvm/test/tools/llvm-dwp/Inputs/merge/notypes/c.dwo new file mode 100644 index 0000000000000000000000000000000000000000..e02969d365b2ac57e88d606e5b4fa55491d8f0be GIT binary patch literal 1257 zcmbu8%}VP~5P;_-ZT$&es0FdO$wHyJ$n^)6D#oBF6z&ywf}7gJREsguH1={uD0c5- zT(}z-zJbr+(w!@P2RF_%C-Ha;xNugIezCf+v^1?(Jg;;5Q(()};26%?8PxaZoDMk9 z@*}Vtm;Gax(XOFxqHdwqQ0Gu{r~rcu19tUrK3TZBol-zW#`YAIDHV*=Su}aZa=AQq z71>nJEalan`P41nZ43Y?1{AN&(ZX}LY>oRp6H6=Fs#Ytlm$3!s$Dmf?5I0T&#-^re zc^V$%4`t=U-Jb72*S^Ho3eAYgG#FtLZd>Pu8bz|aLHzCe1 QBW+Y6FOfJ^q41f%0dDGMQ2+n{ literal 0 HcmV?d00001 diff --git a/llvm/test/tools/llvm-dwp/X86/merge.test b/llvm/test/tools/llvm-dwp/X86/merge.test new file mode 100644 index 000000000000..8feb5a0237e6 --- /dev/null +++ b/llvm/test/tools/llvm-dwp/X86/merge.test @@ -0,0 +1,48 @@ +RUN: llvm-dwp %p/../Inputs/merge/notypes/c.dwo %p/../Inputs/merge/notypes/ab.dwp -o %t +RUN: llvm-dwarfdump %t | FileCheck --check-prefix=CHECK --check-prefix=NOTYP %s + +FIXME: For some reason, piping straight from llvm-dwp to llvm-dwarfdump doesn't behave well - looks like dwarfdump is reading/closes before dwp has finished. + +DWP from a DWO (c.dwo) and a DWP (ab.dwp, created from a.dwo and b.dwo) +Make sure the entries for A and B are updated correctly when read/processed from ab.dwp +a.cpp: + struct foo { }; + foo a; + +b.cpp: + struct bar { }; + void b(bar) { + } + +c.cpp: + typedef int baz; + baz c() { + } + +CHECK-LABEL: .debug_abbrev.dwo contents: +CHECK-LABEL: Abbrev table for offset: +CHECK: 0x0000[[CAOFF:.*]] +CHECK-LABEL: Abbrev table for offset: +CHECK: 0x0000[[AAOFF:.*]] +CHECK-LABEL: Abbrev table for offset: +CHECK: 0x0000[[BAOFF:.*]] + +CHECK: .debug_info.dwo contents: +CHECK: [[COFF:0x[0-9a-f]*]]: +CHECK-LABEL: Compile Unit: length = {{.*}} version = 0x0004 abbr_offset = +CHECK: 0x[[CAOFF]] addr_size = 0x08 (next unit at [[AOFF:.*]]) +CHECK: DW_AT_GNU_dwo_id {{.*}} ([[DWOC:.*]]) +CHECK: [[AOFF]]: +CHECK-LABEL: Compile Unit: length = {{.*}} version = 0x0004 abbr_offset = +CHECK: 0x[[AAOFF]] addr_size = 0x08 (next unit at [[BOFF:.*]]) +CHECK: DW_AT_GNU_dwo_id {{.*}} ([[DWOA:.*]]) +CHECK: [[BOFF]]: +CHECK-LABEL: Compile Unit: length = {{.*}} version = 0x0004 abbr_offset = +CHECK: 0x[[BAOFF]] addr_size = 0x08 (next unit at [[XOFF:.*]]) +CHECK: DW_AT_GNU_dwo_id {{.*}} ([[DWOB:.*]]) + +CHECK-LABEL: .debug_cu_index +CHECK: Index Signature INFO ABBREV LINE STR_OFFSETS +CHECK-DAG: [[DWOC]] {{\[}}[[COFF]], [[AOFF]]) [0x0000[[CAOFF]], 0x0000[[AAOFF]]) [0x00000000, 0x00000011) [0x00000000, 0x00000018) +CHECK-DAG: [[DWOA]] {{\[}}[[AOFF]], [[BOFF]]) [0x0000[[AAOFF]], 0x0000[[BAOFF]]) [0x00000011, 0x00000022) [0x00000018, 0x00000028) +CHECK-DAG: [[DWOB]] {{\[}}[[BOFF]], [[XOFF]]) [0x0000[[BAOFF]], 0x000000c3) [0x00000022, 0x00000033) [0x00000028, 0x0000003c) diff --git a/llvm/tools/llvm-dwp/llvm-dwp.cpp b/llvm/tools/llvm-dwp/llvm-dwp.cpp index 570854b849c1..bf0d29f4c2d0 100644 --- a/llvm/tools/llvm-dwp/llvm-dwp.cpp +++ b/llvm/tools/llvm-dwp/llvm-dwp.cpp @@ -24,6 +24,7 @@ #include #include #include +#include using namespace llvm; using namespace llvm::object; @@ -239,6 +240,7 @@ static std::error_code write(MCStreamer &Out, ArrayRef Inputs) { MCSection *const StrSection = MCOFI.getDwarfStrDWOSection(); MCSection *const StrOffsetSection = MCOFI.getDwarfStrOffDWOSection(); MCSection *const TypesSection = MCOFI.getDwarfTypesDWOSection(); + MCSection *const CUIndexSection = MCOFI.getDwarfCUIndexSection(); const StringMap> KnownSections = { {"debug_info.dwo", {MCOFI.getDwarfInfoDWOSection(), DW_SECT_INFO}}, {"debug_types.dwo", {MCOFI.getDwarfTypesDWOSection(), DW_SECT_TYPES}}, @@ -246,7 +248,9 @@ static std::error_code write(MCStreamer &Out, ArrayRef Inputs) { {"debug_str.dwo", {StrSection, static_cast(0)}}, {"debug_loc.dwo", {MCOFI.getDwarfLocDWOSection(), DW_SECT_LOC}}, {"debug_line.dwo", {MCOFI.getDwarfLineDWOSection(), DW_SECT_LINE}}, - {"debug_abbrev.dwo", {MCOFI.getDwarfAbbrevDWOSection(), DW_SECT_ABBREV}}}; + {"debug_abbrev.dwo", {MCOFI.getDwarfAbbrevDWOSection(), DW_SECT_ABBREV}}, + {"debug_cu_index", + {MCOFI.getDwarfCUIndexSection(), static_cast(0)}}}; std::vector IndexEntries; std::vector TypeIndexEntries; @@ -261,14 +265,14 @@ static std::error_code write(MCStreamer &Out, ArrayRef Inputs) { if (!ErrOrObj) return ErrOrObj.getError(); - IndexEntries.emplace_back(); - UnitIndexEntry &CurEntry = IndexEntries.back(); + UnitIndexEntry CurEntry = {}; StringRef CurStrSection; StringRef CurStrOffsetSection; StringRef CurTypesSection; StringRef InfoSection; StringRef AbbrevSection; + StringRef CurCUIndexSection; for (const auto &Section : ErrOrObj->getBinary()->sections()) { StringRef Name; @@ -311,6 +315,8 @@ static std::error_code write(MCStreamer &Out, ArrayRef Inputs) { CurStrSection = Contents; else if (OutSection == TypesSection) CurTypesSection = Contents; + else if (OutSection == CUIndexSection) + CurCUIndexSection = Contents; else { Out.SwitchSection(OutSection); Out.EmitBytes(Contents); @@ -319,9 +325,34 @@ static std::error_code write(MCStreamer &Out, ArrayRef Inputs) { assert(!AbbrevSection.empty()); assert(!InfoSection.empty()); - CurEntry.Signature = getCUSignature(AbbrevSection, InfoSection); - addAllTypes(Out, TypeIndexEntries, TypesSection, CurTypesSection, CurEntry, - ContributionOffsets[DW_SECT_TYPES - DW_SECT_INFO]); + if (!CurCUIndexSection.empty()) { + DWARFUnitIndex CUIndex(DW_SECT_INFO); + DataExtractor CUIndexData(CurCUIndexSection, + ErrOrObj->getBinary()->isLittleEndian(), 0); + if (!CUIndex.parse(CUIndexData)) + return make_error_code(std::errc::invalid_argument); + + for (const DWARFUnitIndex::Entry &E : CUIndex.getRows()) { + auto NewEntry = CurEntry; + auto *I = E.getOffsets(); + if (!I) + continue; + NewEntry.Signature = E.getSignature(); + for (auto Kind : CUIndex.getColumnKinds()) { + auto &C = NewEntry.Contributions[Kind - DW_SECT_INFO]; + C.Offset += I->Offset; + C.Length = I->Length; + ++I; + } + IndexEntries.push_back(NewEntry); + } + } else { + CurEntry.Signature = getCUSignature(AbbrevSection, InfoSection); + addAllTypes(Out, TypeIndexEntries, TypesSection, CurTypesSection, + CurEntry, ContributionOffsets[DW_SECT_TYPES - DW_SECT_INFO]); + + IndexEntries.push_back(CurEntry); + } if (auto Err = writeStringsAndOffsets(Out, Strings, StringOffset, StrSection, StrOffsetSection,