From 1040f990fc26f08f59b3a2156b17814e72903e69 Mon Sep 17 00:00:00 2001 From: David Blaikie Date: Wed, 11 Nov 2015 19:28:21 +0000 Subject: [PATCH] dwarfdump: First piece of support for DWP dumping 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 | 3 +- include/llvm/DebugInfo/DWARF/DWARFContext.h | 3 ++ include/llvm/DebugInfo/DWARF/DWARFUnitIndex.h | 41 ++++++++++++++++++ lib/DebugInfo/DWARF/CMakeLists.txt | 1 + lib/DebugInfo/DWARF/DWARFContext.cpp | 10 +++++ lib/DebugInfo/DWARF/DWARFUnitIndex.cpp | 41 ++++++++++++++++++ test/DebugInfo/Inputs/dwarfdump-dwp.x86_64.o | Bin 0 -> 1904 bytes test/DebugInfo/dwarfdump-dwp.test | 19 ++++++++ tools/llvm-dwarfdump/llvm-dwarfdump.cpp | 1 + 9 files changed, 118 insertions(+), 1 deletion(-) create mode 100644 include/llvm/DebugInfo/DWARF/DWARFUnitIndex.h create mode 100644 lib/DebugInfo/DWARF/DWARFUnitIndex.cpp create mode 100644 test/DebugInfo/Inputs/dwarfdump-dwp.x86_64.o create mode 100644 test/DebugInfo/dwarfdump-dwp.test diff --git a/include/llvm/DebugInfo/DIContext.h b/include/llvm/DebugInfo/DIContext.h index 1ca7b044df1..87308470507 100644 --- a/include/llvm/DebugInfo/DIContext.h +++ b/include/llvm/DebugInfo/DIContext.h @@ -123,7 +123,8 @@ enum DIDumpType { DIDT_AppleNames, DIDT_AppleTypes, DIDT_AppleNamespaces, - DIDT_AppleObjC + DIDT_AppleObjC, + DIDT_CUIndex, }; class DIContext { diff --git a/include/llvm/DebugInfo/DWARF/DWARFContext.h b/include/llvm/DebugInfo/DWARF/DWARFContext.h index 423c0d32f1b..01d25f7aa8a 100644 --- a/include/llvm/DebugInfo/DWARF/DWARFContext.h +++ b/include/llvm/DebugInfo/DWARF/DWARFContext.h @@ -203,6 +203,7 @@ public: 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; @@ -251,6 +252,7 @@ class DWARFContextInMemory : public DWARFContext { DWARFSection AppleTypesSection; DWARFSection AppleNamespacesSection; DWARFSection AppleObjCSection; + StringRef CUIndexSection; SmallVector, 4> UncompressedSections; @@ -293,6 +295,7 @@ public: 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 index 00000000000..d50b6b1eea1 --- /dev/null +++ b/include/llvm/DebugInfo/DWARF/DWARFUnitIndex.h @@ -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 + +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 diff --git a/lib/DebugInfo/DWARF/CMakeLists.txt b/lib/DebugInfo/DWARF/CMakeLists.txt index d5f8a6f24ee..b3df0422acf 100644 --- a/lib/DebugInfo/DWARF/CMakeLists.txt +++ b/lib/DebugInfo/DWARF/CMakeLists.txt @@ -13,6 +13,7 @@ add_llvm_library(LLVMDebugInfoDWARF DWARFDebugRangeList.cpp DWARFFormValue.cpp DWARFTypeUnit.cpp + DWARFUnitIndex.cpp DWARFUnit.cpp SyntaxHighlighting.cpp diff --git a/lib/DebugInfo/DWARF/DWARFContext.cpp b/lib/DebugInfo/DWARF/DWARFContext.cpp index aecd991ff0d..7ece6787d07 100644 --- a/lib/DebugInfo/DWARF/DWARFContext.cpp +++ b/lib/DebugInfo/DWARF/DWARFContext.cpp @@ -12,6 +12,7 @@ #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" @@ -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; @@ -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("debug_cu_index", &CUIndexSection) // 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 index 00000000000..5970fe03360 --- /dev/null +++ b/lib/DebugInfo/DWARF/DWARFUnitIndex.cpp @@ -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 index 0000000000000000000000000000000000000000..3588369af4785a6d244f5e20ca6328be2a548432 GIT binary patch literal 1904 zcmb_cL2DC16n?YY*u{uc7SxK!Koy#UtHf$U)if%KMGp!h=q2oKHgz@bhU_NVlhA|U zKhR$N1NsjH|AHrvJqhA3s0ZImX41)Pl2Yn}H#6`1zV~MK&F;Rt`|zG61ZWdbh22P_ z0AFTy*R}q#21PguC0q|EN8my@kA7@Fo&9cG)&erZvUb4!8~!}I{jFQsBR=-{{vUtk z_tsdkI3X@FremH*z>D;CfZ==&Q9We>DzKApR{0urh?|!lF57qr2{lPL* zO<(*}(E-SD{hHRF^H|&L4|t6z=&slOAm~Irukj|;NGndFkvI*_Fv~mjwAsv}JTu`q zX{KhJZ?vNk0p^)}*saG&BYLZM&4+RJ0;Rbh9H1Ffq|_(gE0S-iocC(h6W6*(aE!E4 zflE43&0M>HILBDZNXWJ23HeWyP>y8p-HZM~ye6g8Xh3^Dn1& z`w~fxk^Z9sADGEwv>RhEO8KSoB`fX_Y1ju`GfAIy=wl&cB+vhZ5-siP)!@*N2<`J= J8jh?S`~w@%nxp^# literal 0 HcmV?d00001 diff --git a/test/DebugInfo/dwarfdump-dwp.test b/test/DebugInfo/dwarfdump-dwp.test new file mode 100644 index 00000000000..38630f6bb78 --- /dev/null +++ b/test/DebugInfo/dwarfdump-dwp.test @@ -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 diff --git a/tools/llvm-dwarfdump/llvm-dwarfdump.cpp b/tools/llvm-dwarfdump/llvm-dwarfdump.cpp index f641c6be536..9ab2047c352 100644 --- a/tools/llvm-dwarfdump/llvm-dwarfdump.cpp +++ b/tools/llvm-dwarfdump/llvm-dwarfdump.cpp @@ -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_CUIndex, "cu_index", ".debug_cu_index"), clEnumValEnd)); static void error(StringRef Filename, std::error_code EC) { -- 2.34.1