<div dir="ltr"><br><div class="gmail_extra"><br><div class="gmail_quote">On Wed, Nov 11, 2015 at 1:23 PM, Alexey Samsonov <span dir="ltr"><<a href="mailto:vonosmas@gmail.com" target="_blank">vonosmas@gmail.com</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left-width:1px;border-left-color:rgb(204,204,204);border-left-style:solid;padding-left:1ex"><div dir="ltr"><br><div class="gmail_extra"><br><div class="gmail_quote"><div><div class="h5">On Wed, Nov 11, 2015 at 11:28 AM, David Blaikie via llvm-commits <span dir="ltr"><<a href="mailto:llvm-commits@lists.llvm.org" target="_blank">llvm-commits@lists.llvm.org</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left-width:1px;border-left-color:rgb(204,204,204);border-left-style:solid;padding-left:1ex">Author: dblaikie<br>
Date: Wed Nov 11 13:28:21 2015<br>
New Revision: 252781<br>
<br>
URL: <a href="http://llvm.org/viewvc/llvm-project?rev=252781&view=rev" rel="noreferrer" target="_blank">http://llvm.org/viewvc/llvm-project?rev=252781&view=rev</a><br>
Log:<br>
dwarfdump: First piece of support for DWP dumping<br>
<br>
Just a tiny piece of index dumping - the header in this instance.<br>
<br>
Added:<br>
    llvm/trunk/include/llvm/DebugInfo/DWARF/DWARFUnitIndex.h<br>
    llvm/trunk/lib/DebugInfo/DWARF/DWARFUnitIndex.cpp<br>
    llvm/trunk/test/DebugInfo/Inputs/dwarfdump-dwp.x86_64.o<br>
    llvm/trunk/test/DebugInfo/dwarfdump-dwp.test<br>
Modified:<br>
    llvm/trunk/include/llvm/DebugInfo/DIContext.h<br>
    llvm/trunk/include/llvm/DebugInfo/DWARF/DWARFContext.h<br>
    llvm/trunk/lib/DebugInfo/DWARF/CMakeLists.txt<br>
    llvm/trunk/lib/DebugInfo/DWARF/DWARFContext.cpp<br>
    llvm/trunk/tools/llvm-dwarfdump/llvm-dwarfdump.cpp<br>
<br>
Modified: llvm/trunk/include/llvm/DebugInfo/DIContext.h<br>
URL: <a href="http://llvm.org/viewvc/llvm-project/llvm/trunk/include/llvm/DebugInfo/DIContext.h?rev=252781&r1=252780&r2=252781&view=diff" rel="noreferrer" target="_blank">http://llvm.org/viewvc/llvm-project/llvm/trunk/include/llvm/DebugInfo/DIContext.h?rev=252781&r1=252780&r2=252781&view=diff</a><br>
==============================================================================<br>
--- llvm/trunk/include/llvm/DebugInfo/DIContext.h (original)<br>
+++ llvm/trunk/include/llvm/DebugInfo/DIContext.h Wed Nov 11 13:28:21 2015<br>
@@ -123,7 +123,8 @@ enum DIDumpType {<br>
   DIDT_AppleNames,<br>
   DIDT_AppleTypes,<br>
   DIDT_AppleNamespaces,<br>
-  DIDT_AppleObjC<br>
+  DIDT_AppleObjC,<br>
+  DIDT_CUIndex,<br>
 };<br>
<br>
 class DIContext {<br>
<br>
Modified: llvm/trunk/include/llvm/DebugInfo/DWARF/DWARFContext.h<br>
URL: <a href="http://llvm.org/viewvc/llvm-project/llvm/trunk/include/llvm/DebugInfo/DWARF/DWARFContext.h?rev=252781&r1=252780&r2=252781&view=diff" rel="noreferrer" target="_blank">http://llvm.org/viewvc/llvm-project/llvm/trunk/include/llvm/DebugInfo/DWARF/DWARFContext.h?rev=252781&r1=252780&r2=252781&view=diff</a><br>
==============================================================================<br>
--- llvm/trunk/include/llvm/DebugInfo/DWARF/DWARFContext.h (original)<br>
+++ llvm/trunk/include/llvm/DebugInfo/DWARF/DWARFContext.h Wed Nov 11 13:28:21 2015<br>
@@ -203,6 +203,7 @@ public:<br>
   virtual const DWARFSection& getAppleTypesSection() = 0;<br>
   virtual const DWARFSection& getAppleNamespacesSection() = 0;<br>
   virtual const DWARFSection& getAppleObjCSection() = 0;<br>
+  virtual StringRef getCUIndexSection() = 0;<br>
<br>
   static bool isSupportedVersion(unsigned version) {<br>
     return version == 2 || version == 3 || version == 4;<br>
@@ -251,6 +252,7 @@ class DWARFContextInMemory : public DWAR<br>
   DWARFSection AppleTypesSection;<br>
   DWARFSection AppleNamespacesSection;<br>
   DWARFSection AppleObjCSection;<br>
+  StringRef CUIndexSection;<br>
<br>
   SmallVector<SmallString<32>, 4> UncompressedSections;<br>
<br>
@@ -293,6 +295,7 @@ public:<br>
   StringRef getAddrSection() override {<br>
     return AddrSection;<br>
   }<br>
+  StringRef getCUIndexSection() override { return CUIndexSection; }<br>
 };<br>
<br>
 }<br>
<br>
Added: llvm/trunk/include/llvm/DebugInfo/DWARF/DWARFUnitIndex.h<br>
URL: <a href="http://llvm.org/viewvc/llvm-project/llvm/trunk/include/llvm/DebugInfo/DWARF/DWARFUnitIndex.h?rev=252781&view=auto" rel="noreferrer" target="_blank">http://llvm.org/viewvc/llvm-project/llvm/trunk/include/llvm/DebugInfo/DWARF/DWARFUnitIndex.h?rev=252781&view=auto</a><br>
==============================================================================<br>
--- llvm/trunk/include/llvm/DebugInfo/DWARF/DWARFUnitIndex.h (added)<br>
+++ llvm/trunk/include/llvm/DebugInfo/DWARF/DWARFUnitIndex.h Wed Nov 11 13:28:21 2015<br>
@@ -0,0 +1,41 @@<br>
+//===-- DWARFUnitIndex.h --------------------------------------------------===//<br>
+//<br>
+//                     The LLVM Compiler Infrastructure<br>
+//<br>
+// This file is distributed under the University of Illinois Open Source<br>
+// License. See LICENSE.TXT for details.<br>
+//<br>
+//===----------------------------------------------------------------------===//<br>
+<br>
+#ifndef LLVM_LIB_DEBUGINFO_DWARFUNITINDEX_H<br>
+#define LLVM_LIB_DEBUGINFO_DWARFUNITINDEX_H<br>
+<br>
+#include "llvm/Support/DataExtractor.h"<br>
+#include "llvm/Support/Format.h"<br>
+#include "llvm/Support/raw_ostream.h"<br>
+#include <cstdint><br>
+<br>
+namespace llvm {<br>
+<br>
+class DWARFUnitIndex {<br>
+  class Header {<br>
+    uint32_t Version;<br>
+    uint32_t NumColumns;<br>
+    uint32_t NumUnits;<br>
+    uint32_t NumBuckets;<br>
+<br>
+  public:<br>
+    bool parse(DataExtractor IndexData, uint32_t *OffsetPtr);<br>
+    void dump(raw_ostream &OS) const;<br>
+  };<br>
+<br>
+  class Header Header;<br>
+<br>
+public:<br>
+  bool parse(DataExtractor IndexData);<br>
+  void dump(raw_ostream &OS) const;<br>
+};<br>
+<br>
+}<br>
+<br>
+#endif<br>
<br>
Modified: llvm/trunk/lib/DebugInfo/DWARF/CMakeLists.txt<br>
URL: <a href="http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/DebugInfo/DWARF/CMakeLists.txt?rev=252781&r1=252780&r2=252781&view=diff" rel="noreferrer" target="_blank">http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/DebugInfo/DWARF/CMakeLists.txt?rev=252781&r1=252780&r2=252781&view=diff</a><br>
==============================================================================<br>
--- llvm/trunk/lib/DebugInfo/DWARF/CMakeLists.txt (original)<br>
+++ llvm/trunk/lib/DebugInfo/DWARF/CMakeLists.txt Wed Nov 11 13:28:21 2015<br>
@@ -13,6 +13,7 @@ add_llvm_library(LLVMDebugInfoDWARF<br>
   DWARFDebugRangeList.cpp<br>
   DWARFFormValue.cpp<br>
   DWARFTypeUnit.cpp<br>
+  DWARFUnitIndex.cpp<br>
   DWARFUnit.cpp<br>
   SyntaxHighlighting.cpp<br>
<br>
<br>
Modified: llvm/trunk/lib/DebugInfo/DWARF/DWARFContext.cpp<br>
URL: <a href="http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/DebugInfo/DWARF/DWARFContext.cpp?rev=252781&r1=252780&r2=252781&view=diff" rel="noreferrer" target="_blank">http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/DebugInfo/DWARF/DWARFContext.cpp?rev=252781&r1=252780&r2=252781&view=diff</a><br>
==============================================================================<br>
--- llvm/trunk/lib/DebugInfo/DWARF/DWARFContext.cpp (original)<br>
+++ llvm/trunk/lib/DebugInfo/DWARF/DWARFContext.cpp Wed Nov 11 13:28:21 2015<br>
@@ -12,6 +12,7 @@<br>
 #include "llvm/ADT/StringSwitch.h"<br>
 #include "llvm/DebugInfo/DWARF/DWARFAcceleratorTable.h"<br>
 #include "llvm/DebugInfo/DWARF/DWARFDebugArangeSet.h"<br>
+#include "llvm/DebugInfo/DWARF/DWARFUnitIndex.h"<br>
 #include "llvm/Support/Compression.h"<br>
 #include "llvm/Support/Dwarf.h"<br>
 #include "llvm/Support/Format.h"<br>
@@ -155,6 +156,14 @@ void DWARFContext::dump(raw_ostream &OS,<br>
     }<br>
   }<br>
<br>
+  if (DumpType == DIDT_All || DumpType == DIDT_CUIndex) {<br>
+    OS << "\n.debug_cu_index contents:\n";<br>
+    DataExtractor CUIndexData(getCUIndexSection(), isLittleEndian(), savedAddressByteSize);<br>
+    DWARFUnitIndex CUIndex;<br>
+    CUIndex.parse(CUIndexData);<br>
+    CUIndex.dump(OS);<br>
+  }<br>
+<br>
   if (DumpType == DIDT_All || DumpType == DIDT_LineDwo) {<br>
     OS << "\n.debug_line.dwo contents:\n";<br>
     unsigned stmtOffset = 0;<br>
@@ -608,6 +617,7 @@ DWARFContextInMemory::DWARFContextInMemo<br>
             .Case("apple_namespaces", &AppleNamespacesSection.Data)<br>
             .Case("apple_namespac", &AppleNamespacesSection.Data)<br>
             .Case("apple_objc", &AppleObjCSection.Data)<br>
+            .Case("debug_cu_index", &CUIndexSection)<br>
             // Any more debug info sections go here.<br>
             .Default(nullptr);<br>
     if (SectionData) {<br>
<br>
Added: llvm/trunk/lib/DebugInfo/DWARF/DWARFUnitIndex.cpp<br>
URL: <a href="http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/DebugInfo/DWARF/DWARFUnitIndex.cpp?rev=252781&view=auto" rel="noreferrer" target="_blank">http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/DebugInfo/DWARF/DWARFUnitIndex.cpp?rev=252781&view=auto</a><br>
==============================================================================<br>
--- llvm/trunk/lib/DebugInfo/DWARF/DWARFUnitIndex.cpp (added)<br>
+++ llvm/trunk/lib/DebugInfo/DWARF/DWARFUnitIndex.cpp Wed Nov 11 13:28:21 2015<br>
@@ -0,0 +1,41 @@<br>
+//===-- DWARFUnitIndex.cpp ------------------------------------------------===//<br>
+//<br>
+//                     The LLVM Compiler Infrastructure<br>
+//<br>
+// This file is distributed under the University of Illinois Open Source<br>
+// License. See LICENSE.TXT for details.<br>
+//<br>
+//===----------------------------------------------------------------------===//<br>
+<br>
+#include "llvm/DebugInfo/DWARF/DWARFUnitIndex.h"<br>
+<br>
+namespace llvm {<br>
+<br>
+bool DWARFUnitIndex::Header::parse(DataExtractor IndexData, uint32_t *OffsetPtr) {<br></blockquote><div><br></div></div></div><div>Check IndexData.isValidOffsetForDataOfSize(*OffsetPtr, 16)?</div></div></div></div></blockquote><div><br></div><div>I haven't seen much bounds checking like this, though I can certainly add some to avoid us printing out zeros that aren't actually present in the input. Added some checks like this in r252843</div><div> </div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left-width:1px;border-left-color:rgb(204,204,204);border-left-style:solid;padding-left:1ex"><div dir="ltr"><div class="gmail_extra"><div class="gmail_quote"><span class=""><div> </div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left-width:1px;border-left-color:rgb(204,204,204);border-left-style:solid;padding-left:1ex">
+  Version = IndexData.getU32(OffsetPtr);<br>
+  NumColumns = IndexData.getU32(OffsetPtr);<br>
+  NumUnits = IndexData.getU32(OffsetPtr);<br>
+  NumBuckets = IndexData.getU32(OffsetPtr);<br>
+  return Version <= 2;<br>
+}<br>
+<br>
+void DWARFUnitIndex::Header::dump(raw_ostream &OS) const {<br>
+  OS << "Index header:\n" << format("   version: %u\n", Version)<br>
+     << format("   columns: %u\n", NumColumns)<br>
+     << format("     units: %u\n", NumUnits)<br>
+     << format("   buckets: %u\n", NumBuckets);<br>
+}<br>
+<br>
+bool DWARFUnitIndex::parse(DataExtractor IndexData) {<br>
+  uint32_t Offset = 0;<br>
+  if (!Header.parse(IndexData, &Offset))<br>
+    return false;<br>
+<br>
+  return true;<br></blockquote><div><br></div></span><div>return Header.parse(IndexData, &Offset)?</div><div><br></div><div>(yeah, I understand you probably will add more stuff here).</div></div></div></div></blockquote><div><br></div><div>Yeah, I was tossing up which way to leave that when committed. New stuff is in there in r252842 that justifies the 'if' more. Though I might end up refactoring away the header struct anyway... we'll see.<br><br>Thanks,<br>- Dave</div><div> </div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left-width:1px;border-left-color:rgb(204,204,204);border-left-style:solid;padding-left:1ex"><div dir="ltr"><div class="gmail_extra"><div class="gmail_quote"><div><div class="h5"><div> </div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left-width:1px;border-left-color:rgb(204,204,204);border-left-style:solid;padding-left:1ex">
+}<br>
+<br>
+void DWARFUnitIndex::dump(raw_ostream &OS) const {<br>
+  Header.dump(OS);<br>
+}<br>
+<br>
+}<br>
<br>
Added: llvm/trunk/test/DebugInfo/Inputs/dwarfdump-dwp.x86_64.o<br>
URL: <a href="http://llvm.org/viewvc/llvm-project/llvm/trunk/test/DebugInfo/Inputs/dwarfdump-dwp.x86_64.o?rev=252781&view=auto" rel="noreferrer" target="_blank">http://llvm.org/viewvc/llvm-project/llvm/trunk/test/DebugInfo/Inputs/dwarfdump-dwp.x86_64.o?rev=252781&view=auto</a><br>
==============================================================================<br>
Binary files llvm/trunk/test/DebugInfo/Inputs/dwarfdump-dwp.x86_64.o (added) and llvm/trunk/test/DebugInfo/Inputs/dwarfdump-dwp.x86_64.o Wed Nov 11 13:28:21 2015 differ<br>
<br>
Added: llvm/trunk/test/DebugInfo/dwarfdump-dwp.test<br>
URL: <a href="http://llvm.org/viewvc/llvm-project/llvm/trunk/test/DebugInfo/dwarfdump-dwp.test?rev=252781&view=auto" rel="noreferrer" target="_blank">http://llvm.org/viewvc/llvm-project/llvm/trunk/test/DebugInfo/dwarfdump-dwp.test?rev=252781&view=auto</a><br>
==============================================================================<br>
--- llvm/trunk/test/DebugInfo/dwarfdump-dwp.test (added)<br>
+++ llvm/trunk/test/DebugInfo/dwarfdump-dwp.test Wed Nov 11 13:28:21 2015<br>
@@ -0,0 +1,19 @@<br>
+RUN: llvm-dwarfdump %p/Inputs/dwarfdump-dwp.x86_64.o | FileCheck %s<br>
+<br>
+; Testing the following simple dwp file:<br>
+; a.cpp:<br>
+;   struct foo { };<br>
+;   foo a;<br>
+; b.cpp:<br>
+;   struct foo { };<br>
+;   foo b;<br>
+<br>
+; CHECK: .debug_cu_index contents:<br>
+; CHECK: version: 2<br>
+; CHECK: columns: 4<br>
+; CHECK:   units: 2<br>
+; CHECK: buckets: 16<br>
+<br>
+; TODO: debug_tu_index<br>
+; TODO: dump the index contents<br>
+; TODO: use the index section offset info to correctly dump debug_info<br>
<br>
Modified: llvm/trunk/tools/llvm-dwarfdump/llvm-dwarfdump.cpp<br>
URL: <a href="http://llvm.org/viewvc/llvm-project/llvm/trunk/tools/llvm-dwarfdump/llvm-dwarfdump.cpp?rev=252781&r1=252780&r2=252781&view=diff" rel="noreferrer" target="_blank">http://llvm.org/viewvc/llvm-project/llvm/trunk/tools/llvm-dwarfdump/llvm-dwarfdump.cpp?rev=252781&r1=252780&r2=252781&view=diff</a><br>
==============================================================================<br>
--- llvm/trunk/tools/llvm-dwarfdump/llvm-dwarfdump.cpp (original)<br>
+++ llvm/trunk/tools/llvm-dwarfdump/llvm-dwarfdump.cpp Wed Nov 11 13:28:21 2015<br>
@@ -68,6 +68,7 @@ DumpType("debug-dump", cl::init(DIDT_All<br>
         clEnumValN(DIDT_Str, "str", ".debug_str"),<br>
         clEnumValN(DIDT_StrDwo, "str.dwo", ".debug_str.dwo"),<br>
         clEnumValN(DIDT_StrOffsetsDwo, "str_offsets.dwo", ".debug_str_offsets.dwo"),<br>
+        clEnumValN(DIDT_CUIndex, "cu_index", ".debug_cu_index"),<br>
         clEnumValEnd));<br>
<br>
 static void error(StringRef Filename, std::error_code EC) {<br>
<br>
<br>
_______________________________________________<br>
llvm-commits mailing list<br>
<a href="mailto:llvm-commits@lists.llvm.org" target="_blank">llvm-commits@lists.llvm.org</a><br>
<a href="http://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-commits" rel="noreferrer" target="_blank">http://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-commits</a><br>
</blockquote></div></div></div><span class=""><font color="#888888"><br><br clear="all"><div><br></div>-- <br><div><div dir="ltr">Alexey Samsonov<br><a href="mailto:vonosmas@gmail.com" target="_blank">vonosmas@gmail.com</a></div></div>
</font></span></div></div>
</blockquote></div><br></div></div>