dwarfdump: First piece of support for DWP dumping
authorDavid Blaikie <dblaikie@gmail.com>
Wed, 11 Nov 2015 19:28:21 +0000 (19:28 +0000)
committerDavid Blaikie <dblaikie@gmail.com>
Wed, 11 Nov 2015 19:28:21 +0000 (19:28 +0000)
Just a tiny piece of index dumping - the header in this instance.

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@252781 91177308-0d34-0410-b5e6-96231b3b80d8

include/llvm/DebugInfo/DIContext.h
include/llvm/DebugInfo/DWARF/DWARFContext.h
include/llvm/DebugInfo/DWARF/DWARFUnitIndex.h [new file with mode: 0644]
lib/DebugInfo/DWARF/CMakeLists.txt
lib/DebugInfo/DWARF/DWARFContext.cpp
lib/DebugInfo/DWARF/DWARFUnitIndex.cpp [new file with mode: 0644]
test/DebugInfo/Inputs/dwarfdump-dwp.x86_64.o [new file with mode: 0644]
test/DebugInfo/dwarfdump-dwp.test [new file with mode: 0644]
tools/llvm-dwarfdump/llvm-dwarfdump.cpp

index 1ca7b044df1bd8ce2368858a511e57f8b64be151..873084705079be856599df7b15f06dc6103bd482 100644 (file)
@@ -123,7 +123,8 @@ enum DIDumpType {
   DIDT_AppleNames,
   DIDT_AppleTypes,
   DIDT_AppleNamespaces,
   DIDT_AppleNames,
   DIDT_AppleTypes,
   DIDT_AppleNamespaces,
-  DIDT_AppleObjC
+  DIDT_AppleObjC,
+  DIDT_CUIndex,
 };
 
 class DIContext {
 };
 
 class DIContext {
index 423c0d32f1b5e4ec7499390bbb1611552451aba4..01d25f7aa8a0445656dfe7acbf8de66bfc77c296 100644 (file)
@@ -203,6 +203,7 @@ public:
   virtual const DWARFSection& getAppleTypesSection() = 0;
   virtual const DWARFSection& getAppleNamespacesSection() = 0;
   virtual const DWARFSection& getAppleObjCSection() = 0;
   virtual const DWARFSection& getAppleTypesSection() = 0;
   virtual const DWARFSection& getAppleNamespacesSection() = 0;
   virtual const DWARFSection& getAppleObjCSection() = 0;
+  virtual StringRef getCUIndexSection() = 0;
 
   static bool isSupportedVersion(unsigned version) {
     return version == 2 || version == 3 || version == 4;
 
   static bool isSupportedVersion(unsigned version) {
     return version == 2 || version == 3 || version == 4;
@@ -251,6 +252,7 @@ class DWARFContextInMemory : public DWARFContext {
   DWARFSection AppleTypesSection;
   DWARFSection AppleNamespacesSection;
   DWARFSection AppleObjCSection;
   DWARFSection AppleTypesSection;
   DWARFSection AppleNamespacesSection;
   DWARFSection AppleObjCSection;
+  StringRef CUIndexSection;
 
   SmallVector<SmallString<32>, 4> UncompressedSections;
 
 
   SmallVector<SmallString<32>, 4> UncompressedSections;
 
@@ -293,6 +295,7 @@ public:
   StringRef getAddrSection() override {
     return AddrSection;
   }
   StringRef getAddrSection() override {
     return AddrSection;
   }
+  StringRef getCUIndexSection() override { return CUIndexSection; }
 };
 
 }
 };
 
 }
diff --git a/include/llvm/DebugInfo/DWARF/DWARFUnitIndex.h b/include/llvm/DebugInfo/DWARF/DWARFUnitIndex.h
new file mode 100644 (file)
index 0000000..d50b6b1
--- /dev/null
@@ -0,0 +1,41 @@
+//===-- DWARFUnitIndex.h --------------------------------------------------===//
+//
+//                     The LLVM Compiler Infrastructure
+//
+// This file is distributed under the University of Illinois Open Source
+// License. See LICENSE.TXT for details.
+//
+//===----------------------------------------------------------------------===//
+
+#ifndef LLVM_LIB_DEBUGINFO_DWARFUNITINDEX_H
+#define LLVM_LIB_DEBUGINFO_DWARFUNITINDEX_H
+
+#include "llvm/Support/DataExtractor.h"
+#include "llvm/Support/Format.h"
+#include "llvm/Support/raw_ostream.h"
+#include <cstdint>
+
+namespace llvm {
+
+class DWARFUnitIndex {
+  class Header {
+    uint32_t Version;
+    uint32_t NumColumns;
+    uint32_t NumUnits;
+    uint32_t NumBuckets;
+
+  public:
+    bool parse(DataExtractor IndexData, uint32_t *OffsetPtr);
+    void dump(raw_ostream &OS) const;
+  };
+
+  class Header Header;
+
+public:
+  bool parse(DataExtractor IndexData);
+  void dump(raw_ostream &OS) const;
+};
+
+}
+
+#endif
index d5f8a6f24eec7d51084ea0da4a2f6d3e577e6c07..b3df0422acf5d3cddd8e0253942103b778124b5e 100644 (file)
@@ -13,6 +13,7 @@ add_llvm_library(LLVMDebugInfoDWARF
   DWARFDebugRangeList.cpp
   DWARFFormValue.cpp
   DWARFTypeUnit.cpp
   DWARFDebugRangeList.cpp
   DWARFFormValue.cpp
   DWARFTypeUnit.cpp
+  DWARFUnitIndex.cpp
   DWARFUnit.cpp
   SyntaxHighlighting.cpp
 
   DWARFUnit.cpp
   SyntaxHighlighting.cpp
 
index aecd991ff0db2c32c60b3e4e435054eab4ab4215..7ece6787d076b2be6e5e84683e04eb57bd1a575b 100644 (file)
@@ -12,6 +12,7 @@
 #include "llvm/ADT/StringSwitch.h"
 #include "llvm/DebugInfo/DWARF/DWARFAcceleratorTable.h"
 #include "llvm/DebugInfo/DWARF/DWARFDebugArangeSet.h"
 #include "llvm/ADT/StringSwitch.h"
 #include "llvm/DebugInfo/DWARF/DWARFAcceleratorTable.h"
 #include "llvm/DebugInfo/DWARF/DWARFDebugArangeSet.h"
+#include "llvm/DebugInfo/DWARF/DWARFUnitIndex.h"
 #include "llvm/Support/Compression.h"
 #include "llvm/Support/Dwarf.h"
 #include "llvm/Support/Format.h"
 #include "llvm/Support/Compression.h"
 #include "llvm/Support/Dwarf.h"
 #include "llvm/Support/Format.h"
@@ -155,6 +156,14 @@ void DWARFContext::dump(raw_ostream &OS, DIDumpType DumpType) {
     }
   }
 
     }
   }
 
+  if (DumpType == DIDT_All || DumpType == DIDT_CUIndex) {
+    OS << "\n.debug_cu_index contents:\n";
+    DataExtractor CUIndexData(getCUIndexSection(), isLittleEndian(), savedAddressByteSize);
+    DWARFUnitIndex CUIndex;
+    CUIndex.parse(CUIndexData);
+    CUIndex.dump(OS);
+  }
+
   if (DumpType == DIDT_All || DumpType == DIDT_LineDwo) {
     OS << "\n.debug_line.dwo contents:\n";
     unsigned stmtOffset = 0;
   if (DumpType == DIDT_All || DumpType == DIDT_LineDwo) {
     OS << "\n.debug_line.dwo contents:\n";
     unsigned stmtOffset = 0;
@@ -608,6 +617,7 @@ DWARFContextInMemory::DWARFContextInMemory(const object::ObjectFile &Obj,
             .Case("apple_namespaces", &AppleNamespacesSection.Data)
             .Case("apple_namespac", &AppleNamespacesSection.Data)
             .Case("apple_objc", &AppleObjCSection.Data)
             .Case("apple_namespaces", &AppleNamespacesSection.Data)
             .Case("apple_namespac", &AppleNamespacesSection.Data)
             .Case("apple_objc", &AppleObjCSection.Data)
+            .Case("debug_cu_index", &CUIndexSection)
             // Any more debug info sections go here.
             .Default(nullptr);
     if (SectionData) {
             // Any more debug info sections go here.
             .Default(nullptr);
     if (SectionData) {
diff --git a/lib/DebugInfo/DWARF/DWARFUnitIndex.cpp b/lib/DebugInfo/DWARF/DWARFUnitIndex.cpp
new file mode 100644 (file)
index 0000000..5970fe0
--- /dev/null
@@ -0,0 +1,41 @@
+//===-- DWARFUnitIndex.cpp ------------------------------------------------===//
+//
+//                     The LLVM Compiler Infrastructure
+//
+// This file is distributed under the University of Illinois Open Source
+// License. See LICENSE.TXT for details.
+//
+//===----------------------------------------------------------------------===//
+
+#include "llvm/DebugInfo/DWARF/DWARFUnitIndex.h"
+
+namespace llvm {
+
+bool DWARFUnitIndex::Header::parse(DataExtractor IndexData, uint32_t *OffsetPtr) {
+  Version = IndexData.getU32(OffsetPtr);
+  NumColumns = IndexData.getU32(OffsetPtr);
+  NumUnits = IndexData.getU32(OffsetPtr);
+  NumBuckets = IndexData.getU32(OffsetPtr);
+  return Version <= 2;
+}
+
+void DWARFUnitIndex::Header::dump(raw_ostream &OS) const {
+  OS << "Index header:\n" << format("   version: %u\n", Version)
+     << format("   columns: %u\n", NumColumns)
+     << format("     units: %u\n", NumUnits)
+     << format("   buckets: %u\n", NumBuckets);
+}
+
+bool DWARFUnitIndex::parse(DataExtractor IndexData) {
+  uint32_t Offset = 0;
+  if (!Header.parse(IndexData, &Offset))
+    return false;
+
+  return true;
+}
+
+void DWARFUnitIndex::dump(raw_ostream &OS) const {
+  Header.dump(OS);
+}
+
+}
diff --git a/test/DebugInfo/Inputs/dwarfdump-dwp.x86_64.o b/test/DebugInfo/Inputs/dwarfdump-dwp.x86_64.o
new file mode 100644 (file)
index 0000000..3588369
Binary files /dev/null and b/test/DebugInfo/Inputs/dwarfdump-dwp.x86_64.o differ
diff --git a/test/DebugInfo/dwarfdump-dwp.test b/test/DebugInfo/dwarfdump-dwp.test
new file mode 100644 (file)
index 0000000..38630f6
--- /dev/null
@@ -0,0 +1,19 @@
+RUN: llvm-dwarfdump %p/Inputs/dwarfdump-dwp.x86_64.o | FileCheck %s
+
+; Testing the following simple dwp file:
+; a.cpp:
+;   struct foo { };
+;   foo a;
+; b.cpp:
+;   struct foo { };
+;   foo b;
+
+; CHECK: .debug_cu_index contents:
+; CHECK: version: 2
+; CHECK: columns: 4
+; CHECK:   units: 2
+; CHECK: buckets: 16
+
+; TODO: debug_tu_index
+; TODO: dump the index contents
+; TODO: use the index section offset info to correctly dump debug_info
index f641c6be536a3b19b7aa3ea3bb55e1796f7a1e43..9ab2047c352206e1d4c8ada68b9249a6f284ff32 100644 (file)
@@ -68,6 +68,7 @@ DumpType("debug-dump", cl::init(DIDT_All),
         clEnumValN(DIDT_Str, "str", ".debug_str"),
         clEnumValN(DIDT_StrDwo, "str.dwo", ".debug_str.dwo"),
         clEnumValN(DIDT_StrOffsetsDwo, "str_offsets.dwo", ".debug_str_offsets.dwo"),
         clEnumValN(DIDT_Str, "str", ".debug_str"),
         clEnumValN(DIDT_StrDwo, "str.dwo", ".debug_str.dwo"),
         clEnumValN(DIDT_StrOffsetsDwo, "str_offsets.dwo", ".debug_str_offsets.dwo"),
+        clEnumValN(DIDT_CUIndex, "cu_index", ".debug_cu_index"),
         clEnumValEnd));
 
 static void error(StringRef Filename, std::error_code EC) {
         clEnumValEnd));
 
 static void error(StringRef Filename, std::error_code EC) {