Skip to content
This repository was archived by the owner on Mar 28, 2020. It is now read-only.

cherry-pick dwarfdump changes #59

Merged
merged 7 commits into from
Sep 13, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
The table of contents is too big for display.
Diff view
Diff view
  •  
  •  
  •  
43 changes: 42 additions & 1 deletion include/llvm/BinaryFormat/Dwarf.def
Original file line number Diff line number Diff line change
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 include/llvm/DebugInfo/DIContext.h
Original file line number Diff line number Diff line change
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 include/llvm/DebugInfo/DWARF/DWARFContext.h
Original file line number Diff line number Diff line change
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
4 changes: 3 additions & 1 deletion include/llvm/DebugInfo/DWARF/DWARFDebugRangeList.h
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@

namespace llvm {

struct BaseAddress;
class raw_ostream;

struct DWARFAddressRange {
Expand Down Expand Up @@ -85,7 +86,8 @@ class DWARFDebugRangeList {
/// getAbsoluteRanges - Returns absolute address ranges defined by this range
/// list. Has to be passed base address of the compile unit referencing this
/// range list.
DWARFAddressRangesVector getAbsoluteRanges(uint64_t BaseAddress) const;
DWARFAddressRangesVector
getAbsoluteRanges(llvm::Optional<BaseAddress> BaseAddr) const;
};

} // end namespace llvm
Expand Down
1 change: 1 addition & 0 deletions include/llvm/DebugInfo/DWARF/DWARFObject.h
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ class DWARFObject {
public:
virtual ~DWARFObject() = default;
virtual StringRef getFileName() const { llvm_unreachable("unimplemented"); }
virtual const object::ObjectFile *getFile() const { return nullptr; }
virtual bool isLittleEndian() const = 0;
virtual uint8_t getAddressSize() const { llvm_unreachable("unimplemented"); }
virtual const DWARFSection &getInfoSection() const { return Dummy; }
Expand Down
14 changes: 9 additions & 5 deletions include/llvm/DebugInfo/DWARF/DWARFUnit.h
Original file line number Diff line number Diff line change
Expand Up @@ -110,6 +110,12 @@ class DWARFUnitSection final : public SmallVector<std::unique_ptr<UnitType>, 1>,
}
};

/// Represents base address of the CU.
struct BaseAddress {
uint64_t Address;
uint64_t SectionIndex;
};

class DWARFUnit {
DWARFContext &Context;
/// Section containing this DWARFUnit.
Expand All @@ -135,7 +141,7 @@ class DWARFUnit {
uint32_t Length;
const DWARFAbbreviationDeclarationSet *Abbrevs;
uint8_t UnitType;
uint64_t BaseAddr;
llvm::Optional<BaseAddress> BaseAddr;
/// The compile unit debug information entry items.
std::vector<DWARFDebugInfoEntry> DieArray;

Expand Down Expand Up @@ -259,11 +265,9 @@ class DWARFUnit {
llvm_unreachable("Invalid UnitType.");
}

uint64_t getBaseAddress() const { return BaseAddr; }
llvm::Optional<BaseAddress> getBaseAddress() const { return BaseAddr; }

void setBaseAddress(uint64_t base_addr) {
BaseAddr = base_addr;
}
void setBaseAddress(BaseAddress BaseAddr) { this->BaseAddr = BaseAddr; }

DWARFDie getUnitDIE(bool ExtractUnitDIEOnly = true) {
extractDIEsIfNeeded(ExtractUnitDIEOnly);
Expand Down
4 changes: 2 additions & 2 deletions lib/CodeGen/AsmPrinter/DwarfDebug.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1336,8 +1336,8 @@ void DwarfDebug::recordSourceLine(unsigned Line, unsigned Col, const MDNode *S,
if (auto *Scope = cast_or_null<DIScope>(S)) {
Fn = Scope->getFilename();
Dir = Scope->getDirectory();
if (auto *LBF = dyn_cast<DILexicalBlockFile>(Scope))
if (getDwarfVersion() >= 4)
if (Line != 0 && getDwarfVersion() >= 4)
if (auto *LBF = dyn_cast<DILexicalBlockFile>(Scope))
Discriminator = LBF->getDiscriminator();

unsigned CUID = Asm->OutStreamer->getContext().getDwarfCompileUnitID();
Expand Down
Loading