Skip to content

Commit

Permalink
llvm-dwarfdump: Replace -debug-dump=sect option with individual options.
Browse files Browse the repository at this point in the history
As discussed on llvm-dev in
http://lists.llvm.org/pipermail/llvm-dev/2017-September/117301.html
this changes the command line interface of llvm-dwarfdump to match the
one used by the dwarfdump utility shipping on macOS. In addition to
being shorter to type this format also has the advantage of allowing
more than one section to be specified at the same time.

In a nutshell, with this change

  $ llvm-dwarfdump --debug-dump=info
  $ llvm-dwarfdump --debug-dump=apple-objc

becomes

  $ dwarfdump --debug-info --apple-objc

Differential Revision: https://reviews.llvm.org/D37714

llvm-svn: 312970
  • Loading branch information
adrian-prantl committed Sep 11, 2017
1 parent 50479f6 commit 7bc1b28
Show file tree
Hide file tree
Showing 229 changed files with 383 additions and 367 deletions.
43 changes: 42 additions & 1 deletion llvm/include/llvm/BinaryFormat/Dwarf.def
Expand Up @@ -20,7 +20,7 @@
defined HANDLE_DW_LNE || defined HANDLE_DW_LNCT || \
defined HANDLE_DW_MACRO || defined HANDLE_DW_RLE || \
defined HANDLE_DW_CFA || defined HANDLE_DW_APPLE_PROPERTY || \
defined HANDLE_DW_UT)
defined HANDLE_DW_UT || defined HANDLE_DWARF_SECTION)
#error "Missing macro definition of HANDLE_DW*"
#endif

Expand Down Expand Up @@ -92,6 +92,10 @@
#define HANDLE_DW_UT(ID, NAME)
#endif

#ifndef HANDLE_DWARF_SECTION
#define HANDLE_DWARF_SECTION(ENUM_NAME, ELF_NAME, CMDLINE_NAME)
#endif

HANDLE_DW_TAG(0x0000, null, 2, DWARF)
HANDLE_DW_TAG(0x0001, array_type, 2, DWARF)
HANDLE_DW_TAG(0x0002, class_type, 2, DWARF)
Expand Down Expand Up @@ -819,6 +823,42 @@ HANDLE_DW_UT(0x04, skeleton)
HANDLE_DW_UT(0x05, split_compile)
HANDLE_DW_UT(0x06, split_type)

// DWARF section types. (enum name, ELF name, cmdline name)
// Note that these IDs don't mean anything.
// TODO: Add Mach-O and COFF names.
// Official DWARF sections.
HANDLE_DWARF_SECTION(DebugAbbrev, ".debug_abbrev", "debug-abbrev")
HANDLE_DWARF_SECTION(DebugAbbrevDwo, ".debug_abbrev.dwo", "debug-abbrev-dwo")
HANDLE_DWARF_SECTION(DebugAranges, ".debug_aranges", "debug-aranges")
HANDLE_DWARF_SECTION(DebugInfo, ".debug_info", "debug-info")
HANDLE_DWARF_SECTION(DebugInfoDwo, ".debug_info.dwo", "debug-info-dwo")
HANDLE_DWARF_SECTION(DebugTypes, ".debug_types", "debug-types")
HANDLE_DWARF_SECTION(DebugTypesDwo, ".debug_types.dwo", "debug-types-dwo")
HANDLE_DWARF_SECTION(DebugLine, ".debug_line", "debug-line")
HANDLE_DWARF_SECTION(DebugLineDwo, ".debug_line.dwo", "debug-line-dwo")
HANDLE_DWARF_SECTION(DebugLoc, ".debug_loc", "debug-loc")
HANDLE_DWARF_SECTION(DebugLocDwo, ".debug_loc.dwo", "debug-loc-dwo")
HANDLE_DWARF_SECTION(DebugFrames, ".debug_frames", "debug-frames")
HANDLE_DWARF_SECTION(DebugMacro, ".debug_macro", "debug-macro")
HANDLE_DWARF_SECTION(DebugRanges, ".debug_ranges", "debug-ranges")
HANDLE_DWARF_SECTION(DebugPubnames, ".debug_pubnames", "debug-pubnames")
HANDLE_DWARF_SECTION(DebugPubtypes, ".debug_pubtypes", "debug-pubtypes")
HANDLE_DWARF_SECTION(DebugGnuPubnames, ".debug_gnu_pubnames", "debug-gnu-pubnames")
HANDLE_DWARF_SECTION(DebugGnuPubtypes, ".debug_gnu_pubtypes", "debug-gnu-pubtypes")
HANDLE_DWARF_SECTION(DebugStr, ".debug_str", "debug-str")
HANDLE_DWARF_SECTION(DebugStrOffsets, ".debug_str_offsets", "debug-str-offsets")
HANDLE_DWARF_SECTION(DebugStrDwo, ".debug_str.dwo", "debug-str-dwo")
HANDLE_DWARF_SECTION(DebugStrOffsetsDwo, ".debug_str_offsets.dwo", "debug-str-offsets-dwo")
HANDLE_DWARF_SECTION(DebugCUIndex, ".debug_cu_index", "debug-cu-index")
HANDLE_DWARF_SECTION(DebugTUIndex, ".debug_tu_index", "debug-tu-index")
// Vendor extensions.
HANDLE_DWARF_SECTION(AppleNames, ".apple_names", "apple-names")
HANDLE_DWARF_SECTION(AppleTypes, ".apple_types", "apple-types")
HANDLE_DWARF_SECTION(AppleNamespaces, ".apple_namespaces", "apple-namespaces")
HANDLE_DWARF_SECTION(AppleObjC, ".apple_objc", "apple-objc")
HANDLE_DWARF_SECTION(GdbIndex, ".gdb_index", "gdb-index")


#undef HANDLE_DW_TAG
#undef HANDLE_DW_AT
#undef HANDLE_DW_FORM
Expand All @@ -836,3 +876,4 @@ HANDLE_DW_UT(0x06, split_type)
#undef HANDLE_DW_CFA
#undef HANDLE_DW_APPLE_PROPERTY
#undef HANDLE_DW_UT
#undef HANDLE_DWARF_SECTION
52 changes: 19 additions & 33 deletions llvm/include/llvm/DebugInfo/DIContext.h
Expand Up @@ -112,45 +112,31 @@ struct DILineInfoSpecifier {
: FLIKind(FLIKind), FNKind(FNKind) {}
};

namespace {
/// This is just a helper to programmatically construct DIDumpType.
enum DIDumpTypeCounter {
DIDT_ID_Null = 0,
#define HANDLE_DWARF_SECTION(ENUM_NAME, ELF_NAME, CMDLINE_NAME) \
DIDT_ID##ENUM_NAME,
#include "llvm/BinaryFormat/Dwarf.def"
#undef HANDLE_DWARF_SECTION
};
}

/// Selects which debug sections get dumped.
enum DIDumpType {
enum DIDumpType : uint64_t {
DIDT_Null,
DIDT_All,
DIDT_Abbrev,
DIDT_AbbrevDwo,
DIDT_Aranges,
DIDT_Frames,
DIDT_Info,
DIDT_InfoDwo,
DIDT_Types,
DIDT_TypesDwo,
DIDT_Line,
DIDT_LineDwo,
DIDT_Loc,
DIDT_LocDwo,
DIDT_Macro,
DIDT_Ranges,
DIDT_Pubnames,
DIDT_Pubtypes,
DIDT_GnuPubnames,
DIDT_GnuPubtypes,
DIDT_Str,
DIDT_StrOffsets,
DIDT_StrDwo,
DIDT_StrOffsetsDwo,
DIDT_AppleNames,
DIDT_AppleTypes,
DIDT_AppleNamespaces,
DIDT_AppleObjC,
DIDT_CUIndex,
DIDT_GdbIndex,
DIDT_TUIndex,
DIDT_All = ~0ULL,
#define HANDLE_DWARF_SECTION(ENUM_NAME, ELF_NAME, CMDLINE_NAME) \
DIDT_##ENUM_NAME = 1 << DIDT_ID##ENUM_NAME,
#include "llvm/BinaryFormat/Dwarf.def"
#undef HANDLE_DWARF_SECTION
};

/// Container for dump options that control which debug information will be
/// dumped.
struct DIDumpOptions {
DIDumpType DumpType = DIDT_All;
uint64_t DumpType = DIDT_All;
bool DumpEH = false;
bool SummarizeTypes = false;
bool Brief = false;
Expand All @@ -170,7 +156,7 @@ class DIContext {

virtual void dump(raw_ostream &OS, DIDumpOptions DumpOpts) = 0;

virtual bool verify(raw_ostream &OS, DIDumpType DumpType = DIDT_All) {
virtual bool verify(raw_ostream &OS, uint64_t DumpType = DIDT_All) {
// No verifier? Just say things went well.
return true;
}
Expand Down
2 changes: 1 addition & 1 deletion llvm/include/llvm/DebugInfo/DWARF/DWARFContext.h
Expand Up @@ -123,7 +123,7 @@ class DWARFContext : public DIContext {

void dump(raw_ostream &OS, DIDumpOptions DumpOpts) override;

bool verify(raw_ostream &OS, DIDumpType DumpType = DIDT_All) override;
bool verify(raw_ostream &OS, uint64_t DumpType = DIDT_All) override;

using cu_iterator_range = DWARFUnitSection<DWARFCompileUnit>::iterator_range;
using tu_iterator_range = DWARFUnitSection<DWARFTypeUnit>::iterator_range;
Expand Down
66 changes: 33 additions & 33 deletions llvm/lib/DebugInfo/DWARF/DWARFContext.cpp
Expand Up @@ -200,60 +200,60 @@ static void dumpStringOffsetsSection(raw_ostream &OS, StringRef SectionName,
}

void DWARFContext::dump(raw_ostream &OS, DIDumpOptions DumpOpts) {
DIDumpType DumpType = DumpOpts.DumpType;
uint64_t DumpType = DumpOpts.DumpType;
bool DumpEH = DumpOpts.DumpEH;
bool SummarizeTypes = DumpOpts.SummarizeTypes;

if (DumpType == DIDT_All || DumpType == DIDT_Abbrev) {
if (DumpType & DIDT_DebugAbbrev) {
OS << ".debug_abbrev contents:\n";
getDebugAbbrev()->dump(OS);
}

if (DumpType == DIDT_All || DumpType == DIDT_AbbrevDwo)
if (DumpType & DIDT_DebugAbbrevDwo)
if (const DWARFDebugAbbrev *D = getDebugAbbrevDWO()) {
OS << "\n.debug_abbrev.dwo contents:\n";
D->dump(OS);
}

if (DumpType == DIDT_All || DumpType == DIDT_Info) {
if (DumpType & DIDT_DebugInfo) {
OS << "\n.debug_info contents:\n";
for (const auto &CU : compile_units())
CU->dump(OS, DumpOpts);
}

if ((DumpType == DIDT_All || DumpType == DIDT_InfoDwo) &&
if ((DumpType & DIDT_DebugInfoDwo) &&
getNumDWOCompileUnits()) {
OS << "\n.debug_info.dwo contents:\n";
for (const auto &DWOCU : dwo_compile_units())
DWOCU->dump(OS, DumpOpts);
}

if ((DumpType == DIDT_All || DumpType == DIDT_Types) && getNumTypeUnits()) {
if ((DumpType & DIDT_DebugTypes) && getNumTypeUnits()) {
OS << "\n.debug_types contents:\n";
for (const auto &TUS : type_unit_sections())
for (const auto &TU : TUS)
TU->dump(OS, SummarizeTypes);
}

if ((DumpType == DIDT_All || DumpType == DIDT_TypesDwo) &&
if ((DumpType & DIDT_DebugTypesDwo) &&
getNumDWOTypeUnits()) {
OS << "\n.debug_types.dwo contents:\n";
for (const auto &DWOTUS : dwo_type_unit_sections())
for (const auto &DWOTU : DWOTUS)
DWOTU->dump(OS, SummarizeTypes);
}

if (DumpType == DIDT_All || DumpType == DIDT_Loc) {
if (DumpType & DIDT_DebugLoc) {
OS << "\n.debug_loc contents:\n";
getDebugLoc()->dump(OS, getRegisterInfo());
}

if (DumpType == DIDT_All || DumpType == DIDT_LocDwo) {
if (DumpType & DIDT_DebugLocDwo) {
OS << "\n.debug_loc.dwo contents:\n";
getDebugLocDWO()->dump(OS, getRegisterInfo());
}

if (DumpType == DIDT_All || DumpType == DIDT_Frames) {
if (DumpType & DIDT_DebugFrames) {
OS << "\n.debug_frame contents:\n";
getDebugFrame()->dump(OS);
if (DumpEH) {
Expand All @@ -262,13 +262,13 @@ void DWARFContext::dump(raw_ostream &OS, DIDumpOptions DumpOpts) {
}
}

if (DumpType == DIDT_All || DumpType == DIDT_Macro) {
if (DumpType & DIDT_DebugMacro) {
OS << "\n.debug_macinfo contents:\n";
getDebugMacro()->dump(OS);
}

uint32_t offset = 0;
if (DumpType == DIDT_All || DumpType == DIDT_Aranges) {
if (DumpType & DIDT_DebugAranges) {
OS << "\n.debug_aranges contents:\n";
DataExtractor arangesData(DObj->getARangeSection(), isLittleEndian(), 0);
DWARFDebugArangeSet set;
Expand All @@ -277,7 +277,7 @@ void DWARFContext::dump(raw_ostream &OS, DIDumpOptions DumpOpts) {
}

uint8_t savedAddressByteSize = 0;
if (DumpType == DIDT_All || DumpType == DIDT_Line) {
if (DumpType & DIDT_DebugLine) {
OS << "\n.debug_line contents:\n";
for (const auto &CU : compile_units()) {
savedAddressByteSize = CU->getAddressByteSize();
Expand All @@ -295,17 +295,17 @@ void DWARFContext::dump(raw_ostream &OS, DIDumpOptions DumpOpts) {
}
}

if (DumpType == DIDT_All || DumpType == DIDT_CUIndex) {
if (DumpType & DIDT_DebugCUIndex) {
OS << "\n.debug_cu_index contents:\n";
getCUIndex().dump(OS);
}

if (DumpType == DIDT_All || DumpType == DIDT_TUIndex) {
if (DumpType & DIDT_DebugTUIndex) {
OS << "\n.debug_tu_index contents:\n";
getTUIndex().dump(OS);
}

if (DumpType == DIDT_All || DumpType == DIDT_LineDwo) {
if (DumpType & DIDT_DebugLineDwo) {
OS << "\n.debug_line.dwo contents:\n";
unsigned stmtOffset = 0;
DWARFDataExtractor lineData(*DObj, DObj->getLineDWOSection(),
Expand All @@ -317,7 +317,7 @@ void DWARFContext::dump(raw_ostream &OS, DIDumpOptions DumpOpts) {
}
}

if (DumpType == DIDT_All || DumpType == DIDT_Str) {
if (DumpType & DIDT_DebugStr) {
OS << "\n.debug_str contents:\n";
DataExtractor strData(DObj->getStringSection(), isLittleEndian(), 0);
offset = 0;
Expand All @@ -328,7 +328,7 @@ void DWARFContext::dump(raw_ostream &OS, DIDumpOptions DumpOpts) {
}
}

if ((DumpType == DIDT_All || DumpType == DIDT_StrDwo) &&
if ((DumpType & DIDT_DebugStrDwo) &&
!DObj->getStringDWOSection().empty()) {
OS << "\n.debug_str.dwo contents:\n";
DataExtractor strDWOData(DObj->getStringDWOSection(), isLittleEndian(), 0);
Expand All @@ -340,7 +340,7 @@ void DWARFContext::dump(raw_ostream &OS, DIDumpOptions DumpOpts) {
}
}

if (DumpType == DIDT_All || DumpType == DIDT_Ranges) {
if (DumpType & DIDT_DebugRanges) {
OS << "\n.debug_ranges contents:\n";
// In fact, different compile units may have different address byte
// sizes, but for simplicity we just use the address byte size of the last
Expand All @@ -354,55 +354,55 @@ void DWARFContext::dump(raw_ostream &OS, DIDumpOptions DumpOpts) {
rangeList.dump(OS);
}

if (DumpType == DIDT_All || DumpType == DIDT_Pubnames)
if (DumpType & DIDT_DebugPubnames)
DWARFDebugPubTable(DObj->getPubNamesSection(), isLittleEndian(), false)
.dump("debug_pubnames", OS);

if (DumpType == DIDT_All || DumpType == DIDT_Pubtypes)
if (DumpType & DIDT_DebugPubtypes)
DWARFDebugPubTable(DObj->getPubTypesSection(), isLittleEndian(), false)
.dump("debug_pubtypes", OS);

if (DumpType == DIDT_All || DumpType == DIDT_GnuPubnames)
if (DumpType & DIDT_DebugGnuPubnames)
DWARFDebugPubTable(DObj->getGnuPubNamesSection(), isLittleEndian(),
true /* GnuStyle */)
.dump("debug_gnu_pubnames", OS);

if (DumpType == DIDT_All || DumpType == DIDT_GnuPubtypes)
if (DumpType & DIDT_DebugGnuPubtypes)
DWARFDebugPubTable(DObj->getGnuPubTypesSection(), isLittleEndian(),
true /* GnuStyle */)
.dump("debug_gnu_pubtypes", OS);

if (DumpType == DIDT_All || DumpType == DIDT_StrOffsets)
if (DumpType & DIDT_DebugStrOffsets)
dumpStringOffsetsSection(
OS, "debug_str_offsets", *DObj, DObj->getStringOffsetSection(),
DObj->getStringSection(), isLittleEndian(), getMaxVersion());

if (DumpType == DIDT_All || DumpType == DIDT_StrOffsetsDwo) {
if (DumpType & DIDT_DebugStrOffsetsDwo) {
dumpStringOffsetsSection(
OS, "debug_str_offsets.dwo", *DObj, DObj->getStringOffsetDWOSection(),
DObj->getStringDWOSection(), isLittleEndian(), getMaxVersion());
}

if ((DumpType == DIDT_All || DumpType == DIDT_GdbIndex) &&
if ((DumpType & DIDT_GdbIndex) &&
!DObj->getGdbIndexSection().empty()) {
OS << "\n.gnu_index contents:\n";
getGdbIndex().dump(OS);
}

if (DumpType == DIDT_All || DumpType == DIDT_AppleNames)
if (DumpType & DIDT_AppleNames)
dumpAccelSection(OS, "apple_names", *DObj, DObj->getAppleNamesSection(),
DObj->getStringSection(), isLittleEndian());

if (DumpType == DIDT_All || DumpType == DIDT_AppleTypes)
if (DumpType & DIDT_AppleTypes)
dumpAccelSection(OS, "apple_types", *DObj, DObj->getAppleTypesSection(),
DObj->getStringSection(), isLittleEndian());

if (DumpType == DIDT_All || DumpType == DIDT_AppleNamespaces)
if (DumpType & DIDT_AppleNamespaces)
dumpAccelSection(OS, "apple_namespaces", *DObj,
DObj->getAppleNamespacesSection(),
DObj->getStringSection(), isLittleEndian());

if (DumpType == DIDT_All || DumpType == DIDT_AppleObjC)
if (DumpType & DIDT_AppleObjC)
dumpAccelSection(OS, "apple_objc", *DObj, DObj->getAppleObjCSection(),
DObj->getStringSection(), isLittleEndian());
}
Expand Down Expand Up @@ -434,14 +434,14 @@ DWARFDie DWARFContext::getDIEForOffset(uint32_t Offset) {
return DWARFDie();
}

bool DWARFContext::verify(raw_ostream &OS, DIDumpType DumpType) {
bool DWARFContext::verify(raw_ostream &OS, uint64_t DumpType) {
bool Success = true;
DWARFVerifier verifier(OS, *this);

Success &= verifier.handleDebugAbbrev();
if (DumpType == DIDT_All || DumpType == DIDT_Info)
if (DumpType & DIDT_DebugInfo)
Success &= verifier.handleDebugInfo();
if (DumpType == DIDT_All || DumpType == DIDT_Line)
if (DumpType & DIDT_DebugLine)
Success &= verifier.handleDebugLine();
Success &= verifier.handleAccelTables();
return Success;
Expand Down
2 changes: 1 addition & 1 deletion llvm/test/CodeGen/ARM/2011-01-19-MergedGlobalDbg.ll
@@ -1,4 +1,4 @@
; RUN: llc -arm-global-merge -global-merge-group-by-use=false -filetype=obj < %s | llvm-dwarfdump -debug-dump=info - | FileCheck %s
; RUN: llc -arm-global-merge -global-merge-group-by-use=false -filetype=obj < %s | llvm-dwarfdump -debug-info - | FileCheck %s

source_filename = "test/CodeGen/ARM/2011-01-19-MergedGlobalDbg.ll"
target datalayout = "e-p:32:32:32-i1:8:32-i8:8:32-i16:16:32-i32:32:32-i64:32:64-f32:32:32-f64:32:64-v64:32:64-v128:32:128-a0:0:32-n32"
Expand Down
2 changes: 1 addition & 1 deletion llvm/test/CodeGen/ARM/2011-08-02-MergedGlobalDbg.ll
@@ -1,4 +1,4 @@
; RUN: llc -arm-global-merge -global-merge-group-by-use=false -filetype=obj < %s | llvm-dwarfdump -debug-dump=info - | FileCheck %s
; RUN: llc -arm-global-merge -global-merge-group-by-use=false -filetype=obj < %s | llvm-dwarfdump -debug-info - | FileCheck %s

; CHECK: DW_TAG_variable
; CHECK-NOT: DW_TAG
Expand Down
2 changes: 1 addition & 1 deletion llvm/test/CodeGen/ARM/debug-info-sreg2.ll
@@ -1,4 +1,4 @@
; RUN: llc < %s - -filetype=obj | llvm-dwarfdump -debug-dump=loc - | FileCheck %s
; RUN: llc < %s - -filetype=obj | llvm-dwarfdump -debug-loc - | FileCheck %s
; Radar 9376013
target datalayout = "e-p:32:32:32-i1:8:32-i8:8:32-i16:16:32-i32:32:32-i64:32:32-f32:32:32-f64:32:32-v64:32:64-v128:32:128-a0:0:32-n32"
target triple = "thumbv7-apple-macosx10.6.7"
Expand Down

0 comments on commit 7bc1b28

Please sign in to comment.