[llvm] r259971 - [llvm-dwp] Merge cu_index from DWPs

David Blaikie via llvm-commits llvm-commits at lists.llvm.org
Fri Feb 5 17:15:26 PST 2016


Author: dblaikie
Date: Fri Feb  5 19:15:26 2016
New Revision: 259971

URL: http://llvm.org/viewvc/llvm-project?rev=259971&view=rev
Log:
[llvm-dwp] Merge cu_index from DWPs

This is almost feature complete - just missing tu_index merging now.

Added:
    llvm/trunk/test/tools/llvm-dwp/Inputs/merge/
    llvm/trunk/test/tools/llvm-dwp/Inputs/merge/notypes/
    llvm/trunk/test/tools/llvm-dwp/Inputs/merge/notypes/ab.dwp
    llvm/trunk/test/tools/llvm-dwp/Inputs/merge/notypes/c.dwo
    llvm/trunk/test/tools/llvm-dwp/X86/merge.test
Modified:
    llvm/trunk/include/llvm/DebugInfo/DWARF/DWARFUnitIndex.h
    llvm/trunk/tools/llvm-dwp/llvm-dwp.cpp

Modified: llvm/trunk/include/llvm/DebugInfo/DWARF/DWARFUnitIndex.h
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/include/llvm/DebugInfo/DWARF/DWARFUnitIndex.h?rev=259971&r1=259970&r2=259971&view=diff
==============================================================================
--- llvm/trunk/include/llvm/DebugInfo/DWARF/DWARFUnitIndex.h (original)
+++ llvm/trunk/include/llvm/DebugInfo/DWARF/DWARFUnitIndex.h Fri Feb  5 19:15:26 2016
@@ -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<DWARFSectionKind> getColumnKinds() const {
+    return makeArrayRef(ColumnKinds.get(), Header.NumColumns);
+  }
+  ArrayRef<Entry> getRows() const {
+    return makeArrayRef(Rows.get(), Header.NumBuckets);
+  }
 };
 }
 

Added: llvm/trunk/test/tools/llvm-dwp/Inputs/merge/notypes/ab.dwp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/test/tools/llvm-dwp/Inputs/merge/notypes/ab.dwp?rev=259971&view=auto
==============================================================================
Binary files llvm/trunk/test/tools/llvm-dwp/Inputs/merge/notypes/ab.dwp (added) and llvm/trunk/test/tools/llvm-dwp/Inputs/merge/notypes/ab.dwp Fri Feb  5 19:15:26 2016 differ

Added: llvm/trunk/test/tools/llvm-dwp/Inputs/merge/notypes/c.dwo
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/test/tools/llvm-dwp/Inputs/merge/notypes/c.dwo?rev=259971&view=auto
==============================================================================
Binary files llvm/trunk/test/tools/llvm-dwp/Inputs/merge/notypes/c.dwo (added) and llvm/trunk/test/tools/llvm-dwp/Inputs/merge/notypes/c.dwo Fri Feb  5 19:15:26 2016 differ

Added: llvm/trunk/test/tools/llvm-dwp/X86/merge.test
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/test/tools/llvm-dwp/X86/merge.test?rev=259971&view=auto
==============================================================================
--- llvm/trunk/test/tools/llvm-dwp/X86/merge.test (added)
+++ llvm/trunk/test/tools/llvm-dwp/X86/merge.test Fri Feb  5 19:15:26 2016
@@ -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)

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=259971&r1=259970&r2=259971&view=diff
==============================================================================
--- llvm/trunk/tools/llvm-dwp/llvm-dwp.cpp (original)
+++ llvm/trunk/tools/llvm-dwp/llvm-dwp.cpp Fri Feb  5 19:15:26 2016
@@ -24,6 +24,7 @@
 #include <list>
 #include <memory>
 #include <unordered_set>
+#include <system_error>
 
 using namespace llvm;
 using namespace llvm::object;
@@ -239,6 +240,7 @@ static std::error_code write(MCStreamer
   MCSection *const StrSection = MCOFI.getDwarfStrDWOSection();
   MCSection *const StrOffsetSection = MCOFI.getDwarfStrOffDWOSection();
   MCSection *const TypesSection = MCOFI.getDwarfTypesDWOSection();
+  MCSection *const CUIndexSection = MCOFI.getDwarfCUIndexSection();
   const StringMap<std::pair<MCSection *, DWARFSectionKind>> 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
       {"debug_str.dwo", {StrSection, static_cast<DWARFSectionKind>(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<DWARFSectionKind>(0)}}};
 
   std::vector<UnitIndexEntry> IndexEntries;
   std::vector<UnitIndexEntry> TypeIndexEntries;
@@ -261,14 +265,14 @@ static std::error_code write(MCStreamer
     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
         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
 
     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,




More information about the llvm-commits mailing list