diff options
author | Stephen Hines <srhines@google.com> | 2015-03-23 12:10:34 -0700 |
---|---|---|
committer | Stephen Hines <srhines@google.com> | 2015-03-23 12:10:34 -0700 |
commit | ebe69fe11e48d322045d5949c83283927a0d790b (patch) | |
tree | c92f1907a6b8006628a4b01615f38264d29834ea /lib/DebugInfo | |
parent | b7d2e72b02a4cb8034f32f8247a2558d2434e121 (diff) | |
download | external_llvm-ebe69fe11e48d322045d5949c83283927a0d790b.zip external_llvm-ebe69fe11e48d322045d5949c83283927a0d790b.tar.gz external_llvm-ebe69fe11e48d322045d5949c83283927a0d790b.tar.bz2 |
Update aosp/master LLVM for rebase to r230699.
Change-Id: I2b5be30509658cb8266be782de0ab24f9099f9b9
Diffstat (limited to 'lib/DebugInfo')
93 files changed, 3929 insertions, 1690 deletions
diff --git a/lib/DebugInfo/CMakeLists.txt b/lib/DebugInfo/CMakeLists.txt index 81fc84d..645d92f 100644 --- a/lib/DebugInfo/CMakeLists.txt +++ b/lib/DebugInfo/CMakeLists.txt @@ -1,18 +1,4 @@ -add_llvm_library(LLVMDebugInfo - DIContext.cpp - DWARFAbbreviationDeclaration.cpp - DWARFAcceleratorTable.cpp - DWARFCompileUnit.cpp - DWARFContext.cpp - DWARFDebugAbbrev.cpp - DWARFDebugArangeSet.cpp - DWARFDebugAranges.cpp - DWARFDebugFrame.cpp - DWARFDebugInfoEntry.cpp - DWARFDebugLine.cpp - DWARFDebugLoc.cpp - DWARFDebugRangeList.cpp - DWARFFormValue.cpp - DWARFTypeUnit.cpp - DWARFUnit.cpp - ) + +add_subdirectory(DWARF) +add_subdirectory(PDB) + diff --git a/lib/DebugInfo/Android.mk b/lib/DebugInfo/DWARF/Android.mk index e777e9c..3c8222f 100644 --- a/lib/DebugInfo/Android.mk +++ b/lib/DebugInfo/DWARF/Android.mk @@ -1,6 +1,6 @@ LOCAL_PATH:= $(call my-dir) -debuginfo_SRC_FILES := \ +debuginfo_dwarf_SRC_FILES := \ DIContext.cpp \ DWARFAbbreviationDeclaration.cpp \ DWARFAcceleratorTable.cpp \ @@ -17,6 +17,7 @@ debuginfo_SRC_FILES := \ DWARFFormValue.cpp \ DWARFTypeUnit.cpp \ DWARFUnit.cpp \ + SyntaxHighlighting.cpp # For the host # ===================================================== @@ -24,9 +25,9 @@ include $(CLEAR_VARS) REQUIRES_RTTI := 1 -LOCAL_SRC_FILES := $(debuginfo_SRC_FILES) +LOCAL_SRC_FILES := $(debuginfo_dwarf_SRC_FILES) -LOCAL_MODULE:= libLLVMDebugInfo +LOCAL_MODULE:= libLLVMDebugInfoDWARF LOCAL_MODULE_TAGS := optional @@ -41,9 +42,9 @@ include $(CLEAR_VARS) REQUIRES_RTTI := 1 -LOCAL_SRC_FILES := $(debuginfo_SRC_FILES) +LOCAL_SRC_FILES := $(debuginfo_dwarf_SRC_FILES) -LOCAL_MODULE:= libLLVMDebugInfo +LOCAL_MODULE:= libLLVMDebugInfoDWARF LOCAL_MODULE_TAGS := optional diff --git a/lib/DebugInfo/DWARF/CMakeLists.txt b/lib/DebugInfo/DWARF/CMakeLists.txt new file mode 100644 index 0000000..8c6d495 --- /dev/null +++ b/lib/DebugInfo/DWARF/CMakeLists.txt @@ -0,0 +1,22 @@ +add_llvm_library(LLVMDebugInfoDWARF + DIContext.cpp + DWARFAbbreviationDeclaration.cpp + DWARFAcceleratorTable.cpp + DWARFCompileUnit.cpp + DWARFContext.cpp + DWARFDebugAbbrev.cpp + DWARFDebugArangeSet.cpp + DWARFDebugAranges.cpp + DWARFDebugFrame.cpp + DWARFDebugInfoEntry.cpp + DWARFDebugLine.cpp + DWARFDebugLoc.cpp + DWARFDebugRangeList.cpp + DWARFFormValue.cpp + DWARFTypeUnit.cpp + DWARFUnit.cpp + SyntaxHighlighting.cpp + + ADDITIONAL_HEADER_DIRS + ${LLVM_MAIN_INCLUDE_DIR}/llvm/DebugInfo/DWARF + ) diff --git a/lib/DebugInfo/DIContext.cpp b/lib/DebugInfo/DWARF/DIContext.cpp index 01aecf8..a1c6ca4 100644 --- a/lib/DebugInfo/DIContext.cpp +++ b/lib/DebugInfo/DWARF/DIContext.cpp @@ -7,8 +7,8 @@ // //===----------------------------------------------------------------------===// -#include "llvm/DebugInfo/DIContext.h" -#include "DWARFContext.h" +#include "llvm/DebugInfo/DWARF/DIContext.h" +#include "llvm/DebugInfo/DWARF/DWARFContext.h" using namespace llvm; DIContext::~DIContext() {} diff --git a/lib/DebugInfo/DWARFAbbreviationDeclaration.cpp b/lib/DebugInfo/DWARF/DWARFAbbreviationDeclaration.cpp index c3e570e..9314c9e 100644 --- a/lib/DebugInfo/DWARFAbbreviationDeclaration.cpp +++ b/lib/DebugInfo/DWARF/DWARFAbbreviationDeclaration.cpp @@ -7,7 +7,7 @@ // //===----------------------------------------------------------------------===// -#include "DWARFAbbreviationDeclaration.h" +#include "llvm/DebugInfo/DWARF/DWARFAbbreviationDeclaration.h" #include "llvm/Support/Dwarf.h" #include "llvm/Support/Format.h" #include "llvm/Support/raw_ostream.h" diff --git a/lib/DebugInfo/DWARFAcceleratorTable.cpp b/lib/DebugInfo/DWARF/DWARFAcceleratorTable.cpp index 703274d..8ae0543 100644 --- a/lib/DebugInfo/DWARFAcceleratorTable.cpp +++ b/lib/DebugInfo/DWARF/DWARFAcceleratorTable.cpp @@ -7,8 +7,7 @@ // //===----------------------------------------------------------------------===// -#include "DWARFAcceleratorTable.h" - +#include "llvm/DebugInfo/DWARF/DWARFAcceleratorTable.h" #include "llvm/Support/Dwarf.h" #include "llvm/Support/Format.h" #include "llvm/Support/raw_ostream.h" diff --git a/lib/DebugInfo/DWARFCompileUnit.cpp b/lib/DebugInfo/DWARF/DWARFCompileUnit.cpp index 33869d8..01e7247 100644 --- a/lib/DebugInfo/DWARFCompileUnit.cpp +++ b/lib/DebugInfo/DWARF/DWARFCompileUnit.cpp @@ -7,7 +7,7 @@ // //===----------------------------------------------------------------------===// -#include "DWARFCompileUnit.h" +#include "llvm/DebugInfo/DWARF/DWARFCompileUnit.h" #include "llvm/Support/Format.h" #include "llvm/Support/raw_ostream.h" diff --git a/lib/DebugInfo/DWARFContext.cpp b/lib/DebugInfo/DWARF/DWARFContext.cpp index 9a2c7cc..3b42700 100644 --- a/lib/DebugInfo/DWARFContext.cpp +++ b/lib/DebugInfo/DWARF/DWARFContext.cpp @@ -7,12 +7,11 @@ // //===----------------------------------------------------------------------===// -#include "DWARFContext.h" -#include "DWARFDebugArangeSet.h" -#include "DWARFAcceleratorTable.h" - +#include "llvm/DebugInfo/DWARF/DWARFContext.h" #include "llvm/ADT/SmallString.h" #include "llvm/ADT/StringSwitch.h" +#include "llvm/DebugInfo/DWARF/DWARFAcceleratorTable.h" +#include "llvm/DebugInfo/DWARF/DWARFDebugArangeSet.h" #include "llvm/Support/Compression.h" #include "llvm/Support/Dwarf.h" #include "llvm/Support/Format.h" diff --git a/lib/DebugInfo/DWARFDebugAbbrev.cpp b/lib/DebugInfo/DWARF/DWARFDebugAbbrev.cpp index c1a088e..e63e289 100644 --- a/lib/DebugInfo/DWARFDebugAbbrev.cpp +++ b/lib/DebugInfo/DWARF/DWARFDebugAbbrev.cpp @@ -7,7 +7,7 @@ // //===----------------------------------------------------------------------===// -#include "DWARFDebugAbbrev.h" +#include "llvm/DebugInfo/DWARF/DWARFDebugAbbrev.h" #include "llvm/Support/Format.h" #include "llvm/Support/raw_ostream.h" using namespace llvm; diff --git a/lib/DebugInfo/DWARFDebugArangeSet.cpp b/lib/DebugInfo/DWARF/DWARFDebugArangeSet.cpp index c0a33ce..67589cd 100644 --- a/lib/DebugInfo/DWARFDebugArangeSet.cpp +++ b/lib/DebugInfo/DWARF/DWARFDebugArangeSet.cpp @@ -7,7 +7,7 @@ // //===----------------------------------------------------------------------===// -#include "DWARFDebugArangeSet.h" +#include "llvm/DebugInfo/DWARF/DWARFDebugArangeSet.h" #include "llvm/Support/Format.h" #include "llvm/Support/raw_ostream.h" #include <algorithm> diff --git a/lib/DebugInfo/DWARFDebugAranges.cpp b/lib/DebugInfo/DWARF/DWARFDebugAranges.cpp index fe7e46d..27a02c4 100644 --- a/lib/DebugInfo/DWARFDebugAranges.cpp +++ b/lib/DebugInfo/DWARF/DWARFDebugAranges.cpp @@ -7,10 +7,10 @@ // //===----------------------------------------------------------------------===// -#include "DWARFDebugAranges.h" -#include "DWARFCompileUnit.h" -#include "DWARFContext.h" -#include "DWARFDebugArangeSet.h" +#include "llvm/DebugInfo/DWARF/DWARFDebugAranges.h" +#include "llvm/DebugInfo/DWARF/DWARFCompileUnit.h" +#include "llvm/DebugInfo/DWARF/DWARFContext.h" +#include "llvm/DebugInfo/DWARF/DWARFDebugArangeSet.h" #include "llvm/Support/Format.h" #include "llvm/Support/raw_ostream.h" #include <algorithm> diff --git a/lib/DebugInfo/DWARFDebugFrame.cpp b/lib/DebugInfo/DWARF/DWARFDebugFrame.cpp index dfa7e82..7d77290 100644 --- a/lib/DebugInfo/DWARFDebugFrame.cpp +++ b/lib/DebugInfo/DWARF/DWARFDebugFrame.cpp @@ -7,8 +7,10 @@ // //===----------------------------------------------------------------------===// -#include "DWARFDebugFrame.h" +#include "llvm/DebugInfo/DWARF/DWARFDebugFrame.h" +#include "llvm/ADT/ArrayRef.h" #include "llvm/ADT/SmallString.h" +#include "llvm/Support/Casting.h" #include "llvm/Support/DataTypes.h" #include "llvm/Support/Dwarf.h" #include "llvm/Support/ErrorHandling.h" @@ -179,19 +181,6 @@ void FrameEntry::parseInstructions(DataExtractor Data, uint32_t *Offset, } } - -void FrameEntry::dumpInstructions(raw_ostream &OS) const { - // TODO: at the moment only instruction names are dumped. Expand this to - // dump operands as well. - for (const auto &Instr : Instructions) { - uint8_t Opcode = Instr.Opcode; - if (Opcode & DWARF_CFI_PRIMARY_OPCODE_MASK) - Opcode &= DWARF_CFI_PRIMARY_OPCODE_MASK; - OS << " " << CallFrameString(Opcode) << ":\n"; - } -} - - namespace { /// \brief DWARF Common Information Entry (CIE) class CIE : public FrameEntry { @@ -210,6 +199,9 @@ public: ~CIE() { } + uint64_t getCodeAlignmentFactor() const { return CodeAlignmentFactor; } + int64_t getDataAlignmentFactor() const { return DataAlignmentFactor; } + void dumpHeader(raw_ostream &OS) const override { OS << format("%08x %08x %08x CIE", (uint32_t)Offset, (uint32_t)Length, DW_CIE_ID) @@ -246,14 +238,17 @@ public: // an offset to the CIE (provided by parsing the FDE header). The CIE itself // is obtained lazily once it's actually required. FDE(uint64_t Offset, uint64_t Length, int64_t LinkedCIEOffset, - uint64_t InitialLocation, uint64_t AddressRange) + uint64_t InitialLocation, uint64_t AddressRange, + CIE *Cie) : FrameEntry(FK_FDE, Offset, Length), LinkedCIEOffset(LinkedCIEOffset), InitialLocation(InitialLocation), AddressRange(AddressRange), - LinkedCIE(nullptr) {} + LinkedCIE(Cie) {} ~FDE() { } + CIE *getLinkedCIE() const { return LinkedCIE; } + void dumpHeader(raw_ostream &OS) const override { OS << format("%08x %08x %08x FDE ", (uint32_t)Offset, (uint32_t)Length, (int32_t)LinkedCIEOffset); @@ -261,9 +256,6 @@ public: (int32_t)LinkedCIEOffset, (uint32_t)InitialLocation, (uint32_t)InitialLocation + (uint32_t)AddressRange); - if (LinkedCIE) { - OS << format("%p\n", LinkedCIE); - } } static bool classof(const FrameEntry *FE) { @@ -277,8 +269,149 @@ private: uint64_t AddressRange; CIE *LinkedCIE; }; + +/// \brief Types of operands to CF instructions. +enum OperandType { + OT_Unset, + OT_None, + OT_Address, + OT_Offset, + OT_FactoredCodeOffset, + OT_SignedFactDataOffset, + OT_UnsignedFactDataOffset, + OT_Register, + OT_Expression +}; + } // end anonymous namespace +/// \brief Initialize the array describing the types of operands. +static ArrayRef<OperandType[2]> getOperandTypes() { + static OperandType OpTypes[DW_CFA_restore+1][2]; + +#define DECLARE_OP2(OP, OPTYPE0, OPTYPE1) \ + do { \ + OpTypes[OP][0] = OPTYPE0; \ + OpTypes[OP][1] = OPTYPE1; \ + } while (0) +#define DECLARE_OP1(OP, OPTYPE0) DECLARE_OP2(OP, OPTYPE0, OT_None) +#define DECLARE_OP0(OP) DECLARE_OP1(OP, OT_None) + + DECLARE_OP1(DW_CFA_set_loc, OT_Address); + DECLARE_OP1(DW_CFA_advance_loc, OT_FactoredCodeOffset); + DECLARE_OP1(DW_CFA_advance_loc1, OT_FactoredCodeOffset); + DECLARE_OP1(DW_CFA_advance_loc2, OT_FactoredCodeOffset); + DECLARE_OP1(DW_CFA_advance_loc4, OT_FactoredCodeOffset); + DECLARE_OP1(DW_CFA_MIPS_advance_loc8, OT_FactoredCodeOffset); + DECLARE_OP2(DW_CFA_def_cfa, OT_Register, OT_Offset); + DECLARE_OP2(DW_CFA_def_cfa_sf, OT_Register, OT_SignedFactDataOffset); + DECLARE_OP1(DW_CFA_def_cfa_register, OT_Register); + DECLARE_OP1(DW_CFA_def_cfa_offset, OT_Offset); + DECLARE_OP1(DW_CFA_def_cfa_offset_sf, OT_SignedFactDataOffset); + DECLARE_OP1(DW_CFA_def_cfa_expression, OT_Expression); + DECLARE_OP1(DW_CFA_undefined, OT_Register); + DECLARE_OP1(DW_CFA_same_value, OT_Register); + DECLARE_OP2(DW_CFA_offset, OT_Register, OT_UnsignedFactDataOffset); + DECLARE_OP2(DW_CFA_offset_extended, OT_Register, OT_UnsignedFactDataOffset); + DECLARE_OP2(DW_CFA_offset_extended_sf, OT_Register, OT_SignedFactDataOffset); + DECLARE_OP2(DW_CFA_val_offset, OT_Register, OT_UnsignedFactDataOffset); + DECLARE_OP2(DW_CFA_val_offset_sf, OT_Register, OT_SignedFactDataOffset); + DECLARE_OP2(DW_CFA_register, OT_Register, OT_Register); + DECLARE_OP2(DW_CFA_expression, OT_Register, OT_Expression); + DECLARE_OP2(DW_CFA_val_expression, OT_Register, OT_Expression); + DECLARE_OP1(DW_CFA_restore, OT_Register); + DECLARE_OP1(DW_CFA_restore_extended, OT_Register); + DECLARE_OP0(DW_CFA_remember_state); + DECLARE_OP0(DW_CFA_restore_state); + DECLARE_OP0(DW_CFA_GNU_window_save); + DECLARE_OP1(DW_CFA_GNU_args_size, OT_Offset); + DECLARE_OP0(DW_CFA_nop); + +#undef DECLARE_OP0 +#undef DECLARE_OP1 +#undef DECLARE_OP2 + return ArrayRef<OperandType[2]>(&OpTypes[0], DW_CFA_restore+1); +} + +static ArrayRef<OperandType[2]> OpTypes = getOperandTypes(); + +/// \brief Print \p Opcode's operand number \p OperandIdx which has +/// value \p Operand. +static void printOperand(raw_ostream &OS, uint8_t Opcode, unsigned OperandIdx, + uint64_t Operand, uint64_t CodeAlignmentFactor, + int64_t DataAlignmentFactor) { + assert(OperandIdx < 2); + OperandType Type = OpTypes[Opcode][OperandIdx]; + + switch (Type) { + case OT_Unset: + OS << " Unsupported " << (OperandIdx ? "second" : "first") << " operand to"; + if (const char *OpcodeName = CallFrameString(Opcode)) + OS << " " << OpcodeName; + else + OS << format(" Opcode %x", Opcode); + break; + case OT_None: + break; + case OT_Address: + OS << format(" %" PRIx64, Operand); + break; + case OT_Offset: + // The offsets are all encoded in a unsigned form, but in practice + // consumers use them signed. It's most certainly legacy due to + // the lack of signed variants in the first Dwarf standards. + OS << format(" %+" PRId64, int64_t(Operand)); + break; + case OT_FactoredCodeOffset: // Always Unsigned + if (CodeAlignmentFactor) + OS << format(" %" PRId64, Operand * CodeAlignmentFactor); + else + OS << format(" %" PRId64 "*code_alignment_factor" , Operand); + break; + case OT_SignedFactDataOffset: + if (DataAlignmentFactor) + OS << format(" %" PRId64, int64_t(Operand) * DataAlignmentFactor); + else + OS << format(" %" PRId64 "*data_alignment_factor" , int64_t(Operand)); + break; + case OT_UnsignedFactDataOffset: + if (DataAlignmentFactor) + OS << format(" %" PRId64, Operand * DataAlignmentFactor); + else + OS << format(" %" PRId64 "*data_alignment_factor" , Operand); + break; + case OT_Register: + OS << format(" reg%" PRId64, Operand); + break; + case OT_Expression: + OS << " expression"; + break; + } +} + +void FrameEntry::dumpInstructions(raw_ostream &OS) const { + uint64_t CodeAlignmentFactor = 0; + int64_t DataAlignmentFactor = 0; + const CIE *Cie = dyn_cast<CIE>(this); + + if (!Cie) + Cie = cast<FDE>(this)->getLinkedCIE(); + if (Cie) { + CodeAlignmentFactor = Cie->getCodeAlignmentFactor(); + DataAlignmentFactor = Cie->getDataAlignmentFactor(); + } + + for (const auto &Instr : Instructions) { + uint8_t Opcode = Instr.Opcode; + if (Opcode & DWARF_CFI_PRIMARY_OPCODE_MASK) + Opcode &= DWARF_CFI_PRIMARY_OPCODE_MASK; + OS << " " << CallFrameString(Opcode) << ":"; + for (unsigned i = 0; i < Instr.Ops.size(); ++i) + printOperand(OS, Opcode, i, Instr.Ops[i], CodeAlignmentFactor, + DataAlignmentFactor); + OS << '\n'; + } +} DWARFDebugFrame::DWARFDebugFrame() { } @@ -299,6 +432,7 @@ static void LLVM_ATTRIBUTE_UNUSED dumpDataAux(DataExtractor Data, void DWARFDebugFrame::parse(DataExtractor Data) { uint32_t Offset = 0; + DenseMap<uint32_t, CIE *> CIEs; while (Data.isValidOffset(Offset)) { uint32_t StartOffset = Offset; @@ -338,9 +472,11 @@ void DWARFDebugFrame::parse(DataExtractor Data) { int64_t DataAlignmentFactor = Data.getSLEB128(&Offset); uint64_t ReturnAddressRegister = Data.getULEB128(&Offset); - Entries.emplace_back(new CIE(StartOffset, Length, Version, - StringRef(Augmentation), CodeAlignmentFactor, - DataAlignmentFactor, ReturnAddressRegister)); + auto Cie = make_unique<CIE>(StartOffset, Length, Version, + StringRef(Augmentation), CodeAlignmentFactor, + DataAlignmentFactor, ReturnAddressRegister); + CIEs[StartOffset] = Cie.get(); + Entries.emplace_back(std::move(Cie)); } else { // FDE uint64_t CIEPointer = Id; @@ -348,7 +484,8 @@ void DWARFDebugFrame::parse(DataExtractor Data) { uint64_t AddressRange = Data.getAddress(&Offset); Entries.emplace_back(new FDE(StartOffset, Length, CIEPointer, - InitialLocation, AddressRange)); + InitialLocation, AddressRange, + CIEs[CIEPointer])); } Entries.back()->parseInstructions(Data, &Offset, EndStructureOffset); diff --git a/lib/DebugInfo/DWARFDebugInfoEntry.cpp b/lib/DebugInfo/DWARF/DWARFDebugInfoEntry.cpp index 583e700..e963b7c 100644 --- a/lib/DebugInfo/DWARFDebugInfoEntry.cpp +++ b/lib/DebugInfo/DWARF/DWARFDebugInfoEntry.cpp @@ -7,11 +7,12 @@ // //===----------------------------------------------------------------------===// -#include "DWARFDebugInfoEntry.h" -#include "DWARFCompileUnit.h" -#include "DWARFContext.h" -#include "DWARFDebugAbbrev.h" -#include "llvm/DebugInfo/DWARFFormValue.h" +#include "SyntaxHighlighting.h" +#include "llvm/DebugInfo/DWARF/DWARFCompileUnit.h" +#include "llvm/DebugInfo/DWARF/DWARFContext.h" +#include "llvm/DebugInfo/DWARF/DWARFDebugAbbrev.h" +#include "llvm/DebugInfo/DWARF/DWARFDebugInfoEntry.h" +#include "llvm/DebugInfo/DWARF/DWARFFormValue.h" #include "llvm/Support/DataTypes.h" #include "llvm/Support/Debug.h" #include "llvm/Support/Dwarf.h" @@ -19,6 +20,7 @@ #include "llvm/Support/raw_ostream.h" using namespace llvm; using namespace dwarf; +using namespace syntax; // Small helper to extract a DIE pointed by a reference // attribute. It looks up the Unit containing the DIE and calls @@ -39,15 +41,17 @@ void DWARFDebugInfoEntryMinimal::dump(raw_ostream &OS, DWARFUnit *u, if (debug_info_data.isValidOffset(offset)) { uint32_t abbrCode = debug_info_data.getULEB128(&offset); + WithColor(OS, syntax::Address).get() << format("\n0x%8.8x: ", Offset); - OS << format("\n0x%8.8x: ", Offset); if (abbrCode) { if (AbbrevDecl) { - const char *tagString = TagString(getTag()); - if (tagString) - OS.indent(indent) << tagString; - else - OS.indent(indent) << format("DW_TAG_Unknown_%x", getTag()); + const char *tagString = TagString(getTag()); + if (tagString) + WithColor(OS, syntax::Tag).get().indent(indent) << tagString; + else + WithColor(OS, syntax::Tag).get().indent(indent) << + format("DW_TAG_Unknown_%x", getTag()); + OS << format(" [%u] %c\n", abbrCode, AbbrevDecl->hasChildren() ? '*' : ' '); @@ -76,7 +80,9 @@ void DWARFDebugInfoEntryMinimal::dump(raw_ostream &OS, DWARFUnit *u, static void dumpApplePropertyAttribute(raw_ostream &OS, uint64_t Val) { OS << " ("; do { - uint64_t Bit = 1ULL << countTrailingZeros(Val); + uint64_t Shift = countTrailingZeros(Val); + assert(Shift < 64 && "undefined behavior"); + uint64_t Bit = 1ULL << Shift; if (const char *PropName = ApplePropertyString(Bit)) OS << PropName; else @@ -112,9 +118,10 @@ void DWARFDebugInfoEntryMinimal::dumpAttribute(raw_ostream &OS, OS.indent(indent+2); const char *attrString = AttributeString(attr); if (attrString) - OS << attrString; + WithColor(OS, syntax::Attribute) << attrString; else - OS << format("DW_AT_Unknown_%x", attr); + WithColor(OS, syntax::Attribute).get() << format("DW_AT_Unknown_%x", attr); + const char *formString = FormEncodingString(form); if (formString) OS << " [" << formString << ']'; @@ -130,7 +137,9 @@ void DWARFDebugInfoEntryMinimal::dumpAttribute(raw_ostream &OS, const char *Name = nullptr; std::string File; + auto Color = syntax::Enumerator; if (attr == DW_AT_decl_file || attr == DW_AT_call_file) { + Color = syntax::String; if (const auto *LT = u->getContext().getLineTableForUnit(u)) if (LT->getFileNameByIndex( formValue.getAsUnsignedConstant().getValue(), @@ -142,13 +151,12 @@ void DWARFDebugInfoEntryMinimal::dumpAttribute(raw_ostream &OS, } else if (Optional<uint64_t> Val = formValue.getAsUnsignedConstant()) Name = AttributeValueString(attr, *Val); - if (Name) { - OS << Name; - } else if (attr == DW_AT_decl_line || attr == DW_AT_call_line) { + if (Name) + WithColor(OS, Color) << Name; + else if (attr == DW_AT_decl_line || attr == DW_AT_call_line) OS << *formValue.getAsUnsignedConstant(); - } else { + else formValue.dump(OS, u); - } // We have dumped the attribute raw value. For some attributes // having both the raw value and the pretty-printed value is diff --git a/lib/DebugInfo/DWARFDebugLine.cpp b/lib/DebugInfo/DWARF/DWARFDebugLine.cpp index a6ee461..b63af6a 100644 --- a/lib/DebugInfo/DWARFDebugLine.cpp +++ b/lib/DebugInfo/DWARF/DWARFDebugLine.cpp @@ -7,7 +7,7 @@ // //===----------------------------------------------------------------------===// -#include "DWARFDebugLine.h" +#include "llvm/DebugInfo/DWARF/DWARFDebugLine.h" #include "llvm/Support/Dwarf.h" #include "llvm/Support/Format.h" #include "llvm/Support/Path.h" diff --git a/lib/DebugInfo/DWARFDebugLoc.cpp b/lib/DebugInfo/DWARF/DWARFDebugLoc.cpp index e4aa5dc..fdb6dd2 100644 --- a/lib/DebugInfo/DWARFDebugLoc.cpp +++ b/lib/DebugInfo/DWARF/DWARFDebugLoc.cpp @@ -7,11 +7,11 @@ // //===----------------------------------------------------------------------===// -#include "DWARFDebugLoc.h" +#include "llvm/DebugInfo/DWARF/DWARFDebugLoc.h" #include "llvm/Support/Compiler.h" +#include "llvm/Support/Dwarf.h" #include "llvm/Support/Format.h" #include "llvm/Support/raw_ostream.h" -#include "llvm/Support/Dwarf.h" using namespace llvm; diff --git a/lib/DebugInfo/DWARFDebugRangeList.cpp b/lib/DebugInfo/DWARF/DWARFDebugRangeList.cpp index 07b23b3..d5df688 100644 --- a/lib/DebugInfo/DWARFDebugRangeList.cpp +++ b/lib/DebugInfo/DWARF/DWARFDebugRangeList.cpp @@ -7,7 +7,7 @@ // //===----------------------------------------------------------------------===// -#include "DWARFDebugRangeList.h" +#include "llvm/DebugInfo/DWARF/DWARFDebugRangeList.h" #include "llvm/Support/Format.h" #include "llvm/Support/raw_ostream.h" diff --git a/lib/DebugInfo/DWARFFormValue.cpp b/lib/DebugInfo/DWARF/DWARFFormValue.cpp index 69b9771..45bd197 100644 --- a/lib/DebugInfo/DWARFFormValue.cpp +++ b/lib/DebugInfo/DWARF/DWARFFormValue.cpp @@ -7,11 +7,12 @@ // //===----------------------------------------------------------------------===// -#include "llvm/DebugInfo/DWARFFormValue.h" -#include "DWARFCompileUnit.h" -#include "DWARFContext.h" +#include "SyntaxHighlighting.h" #include "llvm/ADT/ArrayRef.h" #include "llvm/ADT/StringRef.h" +#include "llvm/DebugInfo/DWARF/DWARFCompileUnit.h" +#include "llvm/DebugInfo/DWARF/DWARFContext.h" +#include "llvm/DebugInfo/DWARF/DWARFFormValue.h" #include "llvm/Support/Debug.h" #include "llvm/Support/Dwarf.h" #include "llvm/Support/Format.h" @@ -19,6 +20,7 @@ #include <cassert> using namespace llvm; using namespace dwarf; +using namespace syntax; namespace { uint8_t getRefAddrSize(uint8_t AddrSize, uint16_t Version) { @@ -423,9 +425,10 @@ DWARFFormValue::dump(raw_ostream &OS, const DWARFUnit *cu) const { OS << format(" .debug_str[0x%8.8x] = ", (uint32_t)uvalue); Optional<const char *> DbgStr = getAsCString(cu); if (DbgStr.hasValue()) { - OS << '"'; - OS.write_escaped(DbgStr.getValue()); - OS << '"'; + raw_ostream &COS = WithColor(OS, syntax::String); + COS << '"'; + COS.write_escaped(DbgStr.getValue()); + COS << '"'; } break; } @@ -433,9 +436,10 @@ DWARFFormValue::dump(raw_ostream &OS, const DWARFUnit *cu) const { OS << format(" indexed (%8.8x) string = ", (uint32_t)uvalue); Optional<const char *> DbgStr = getAsCString(cu); if (DbgStr.hasValue()) { - OS << '"'; - OS.write_escaped(DbgStr.getValue()); - OS << '"'; + raw_ostream &COS = WithColor(OS, syntax::String); + COS << '"'; + COS.write_escaped(DbgStr.getValue()); + COS << '"'; } break; } @@ -479,8 +483,12 @@ DWARFFormValue::dump(raw_ostream &OS, const DWARFUnit *cu) const { break; } - if (cu_relative_offset) - OS << format(" => {0x%8.8" PRIx64 "}", uvalue + (cu ? cu->getOffset() : 0)); + if (cu_relative_offset) { + OS << " => {"; + WithColor(OS, syntax::Address).get() + << format("0x%8.8" PRIx64, uvalue + (cu ? cu->getOffset() : 0)); + OS << "}"; + } } Optional<const char *> DWARFFormValue::getAsCString(const DWARFUnit *U) const { diff --git a/lib/DebugInfo/DWARFTypeUnit.cpp b/lib/DebugInfo/DWARF/DWARFTypeUnit.cpp index 303bf70..65c7bff 100644 --- a/lib/DebugInfo/DWARFTypeUnit.cpp +++ b/lib/DebugInfo/DWARF/DWARFTypeUnit.cpp @@ -7,7 +7,7 @@ // //===----------------------------------------------------------------------===// -#include "DWARFTypeUnit.h" +#include "llvm/DebugInfo/DWARF/DWARFTypeUnit.h" #include "llvm/Support/Format.h" #include "llvm/Support/raw_ostream.h" diff --git a/lib/DebugInfo/DWARFUnit.cpp b/lib/DebugInfo/DWARF/DWARFUnit.cpp index 82c4529..d4ecd69 100644 --- a/lib/DebugInfo/DWARFUnit.cpp +++ b/lib/DebugInfo/DWARF/DWARFUnit.cpp @@ -7,9 +7,9 @@ // //===----------------------------------------------------------------------===// -#include "DWARFUnit.h" -#include "DWARFContext.h" -#include "llvm/DebugInfo/DWARFFormValue.h" +#include "llvm/DebugInfo/DWARF/DWARFUnit.h" +#include "llvm/DebugInfo/DWARF/DWARFContext.h" +#include "llvm/DebugInfo/DWARF/DWARFFormValue.h" #include "llvm/Support/Dwarf.h" #include "llvm/Support/Path.h" #include <cstdio> diff --git a/lib/DebugInfo/DWARF/LLVMBuild.txt b/lib/DebugInfo/DWARF/LLVMBuild.txt new file mode 100644 index 0000000..9f8b104 --- /dev/null +++ b/lib/DebugInfo/DWARF/LLVMBuild.txt @@ -0,0 +1,22 @@ +;===- ./lib/DebugInfo/DWARF/LLVMBuild.txt ----------------------*- Conf -*--===; +; +; The LLVM Compiler Infrastructure +; +; This file is distributed under the University of Illinois Open Source +; License. See LICENSE.TXT for details. +; +;===------------------------------------------------------------------------===; +; +; This is an LLVMBuild description file for the components in this subdirectory. +; +; For more information on the LLVMBuild system, please see: +; +; http://llvm.org/docs/LLVMBuild.html +; +;===------------------------------------------------------------------------===; + +[component_0] +type = Library +name = DebugInfoDWARF +parent = DebugInfo +required_libraries = Object Support diff --git a/lib/DebugInfo/DWARF/Makefile b/lib/DebugInfo/DWARF/Makefile new file mode 100644 index 0000000..8633373 --- /dev/null +++ b/lib/DebugInfo/DWARF/Makefile @@ -0,0 +1,14 @@ +##===- lib/DebugInfo/DWARF/Makefile ------------------------*- Makefile -*-===## +# +# The LLVM Compiler Infrastructure +# +# This file is distributed under the University of Illinois Open Source +# License. See LICENSE.TXT for details. +# +##===----------------------------------------------------------------------===## + +LEVEL = ../../.. +LIBRARYNAME = LLVMDebugInfoDWARF +BUILD_ARCHIVE := 1 + +include $(LEVEL)/Makefile.common diff --git a/lib/DebugInfo/DWARF/SyntaxHighlighting.cpp b/lib/DebugInfo/DWARF/SyntaxHighlighting.cpp new file mode 100644 index 0000000..a6b4c65 --- /dev/null +++ b/lib/DebugInfo/DWARF/SyntaxHighlighting.cpp @@ -0,0 +1,37 @@ +//===-- SyntaxHighlighting.cpp ----------------------------------*- C++ -*-===// +// +// The LLVM Compiler Infrastructure +// +// This file is distributed under the University of Illinois Open Source +// License. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +#include "SyntaxHighlighting.h" +#include "llvm/Support/CommandLine.h" +using namespace llvm; +using namespace dwarf; +using namespace syntax; + +static cl::opt<cl::boolOrDefault> + UseColor("color", + cl::desc("use colored syntax highlighting (default=autodetect)"), + cl::init(cl::BOU_UNSET)); + +WithColor::WithColor(llvm::raw_ostream &OS, enum HighlightColor Type) : OS(OS) { + // Detect color from terminal type unless the user passed the --color option. + if (UseColor == cl::BOU_UNSET ? OS.has_colors() : UseColor == cl::BOU_TRUE) { + switch (Type) { + case Address: OS.changeColor(llvm::raw_ostream::YELLOW); break; + case String: OS.changeColor(llvm::raw_ostream::GREEN); break; + case Tag: OS.changeColor(llvm::raw_ostream::BLUE); break; + case Attribute: OS.changeColor(llvm::raw_ostream::CYAN); break; + case Enumerator: OS.changeColor(llvm::raw_ostream::MAGENTA); break; + } + } +} + +WithColor::~WithColor() { + if (UseColor == cl::BOU_UNSET ? OS.has_colors() : UseColor == cl::BOU_TRUE) + OS.resetColor(); +} diff --git a/lib/DebugInfo/DWARF/SyntaxHighlighting.h b/lib/DebugInfo/DWARF/SyntaxHighlighting.h new file mode 100644 index 0000000..946a313 --- /dev/null +++ b/lib/DebugInfo/DWARF/SyntaxHighlighting.h @@ -0,0 +1,39 @@ +//===-- SyntaxHighlighting.h ------------------------------------*- C++ -*-===// +// +// 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_SYNTAXHIGHLIGHTING_H +#define LLVM_LIB_DEBUGINFO_SYNTAXHIGHLIGHTING_H + +#include "llvm/Support/raw_ostream.h" + +namespace llvm { +namespace dwarf { +namespace syntax { + +// Symbolic names for various syntax elements. +enum HighlightColor { Address, String, Tag, Attribute, Enumerator }; + +/// An RAII object that temporarily switches an output stream to a +/// specific color. +class WithColor { + llvm::raw_ostream &OS; + +public: + /// To be used like this: WithColor(OS, syntax::String) << "text"; + WithColor(llvm::raw_ostream &OS, enum HighlightColor Type); + ~WithColor(); + + llvm::raw_ostream& get() { return OS; } + operator llvm::raw_ostream& () { return OS; } +}; +} +} +} + +#endif diff --git a/lib/DebugInfo/DWARF/module.modulemap b/lib/DebugInfo/DWARF/module.modulemap new file mode 100644 index 0000000..c2f624f --- /dev/null +++ b/lib/DebugInfo/DWARF/module.modulemap @@ -0,0 +1 @@ +module DebugInfoDWARF { requires cplusplus umbrella "." module * { export * } } diff --git a/lib/DebugInfo/DWARFAbbreviationDeclaration.h b/lib/DebugInfo/DWARFAbbreviationDeclaration.h deleted file mode 100644 index bb05c30..0000000 --- a/lib/DebugInfo/DWARFAbbreviationDeclaration.h +++ /dev/null @@ -1,60 +0,0 @@ -//===-- DWARFAbbreviationDeclaration.h --------------------------*- C++ -*-===// -// -// 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_DWARFABBREVIATIONDECLARATION_H -#define LLVM_LIB_DEBUGINFO_DWARFABBREVIATIONDECLARATION_H - -#include "llvm/ADT/SmallVector.h" -#include "llvm/Support/DataExtractor.h" - -namespace llvm { - -class raw_ostream; - -class DWARFAbbreviationDeclaration { - uint32_t Code; - uint32_t Tag; - bool HasChildren; - - struct AttributeSpec { - AttributeSpec(uint16_t Attr, uint16_t Form) : Attr(Attr), Form(Form) {} - uint16_t Attr; - uint16_t Form; - }; - typedef SmallVector<AttributeSpec, 8> AttributeSpecVector; - AttributeSpecVector AttributeSpecs; -public: - DWARFAbbreviationDeclaration(); - - uint32_t getCode() const { return Code; } - uint32_t getTag() const { return Tag; } - bool hasChildren() const { return HasChildren; } - - typedef iterator_range<AttributeSpecVector::const_iterator> - attr_iterator_range; - - attr_iterator_range attributes() const { - return attr_iterator_range(AttributeSpecs.begin(), AttributeSpecs.end()); - } - - uint16_t getFormByIndex(uint32_t idx) const { - return idx < AttributeSpecs.size() ? AttributeSpecs[idx].Form : 0; - } - - uint32_t findAttributeIndex(uint16_t attr) const; - bool extract(DataExtractor Data, uint32_t* OffsetPtr); - void dump(raw_ostream &OS) const; - -private: - void clear(); -}; - -} - -#endif diff --git a/lib/DebugInfo/DWARFAcceleratorTable.h b/lib/DebugInfo/DWARFAcceleratorTable.h deleted file mode 100644 index 7dc9591..0000000 --- a/lib/DebugInfo/DWARFAcceleratorTable.h +++ /dev/null @@ -1,51 +0,0 @@ -//===--- DWARFAcceleratorTable.h --------------------------------*- C++ -*-===// -// -// The LLVM Compiler Infrastructure -// -// This file is distributed under the University of Illinois Open Source -// License. See LICENSE.TXT for details. -// -//===----------------------------------------------------------------------===// - -#include "DWARFRelocMap.h" - -#include "llvm/ADT/SmallVector.h" -#include "llvm/DebugInfo/DWARFFormValue.h" - -#include <cstdint> - -namespace llvm { - -class DWARFAcceleratorTable { - - struct Header { - uint32_t Magic; - uint16_t Version; - uint16_t HashFunction; - uint32_t NumBuckets; - uint32_t NumHashes; - uint32_t HeaderDataLength; - }; - - struct HeaderData { - typedef uint16_t AtomType; - typedef uint16_t Form; - uint32_t DIEOffsetBase; - SmallVector<std::pair<AtomType, Form>, 3> Atoms; - }; - - struct Header Hdr; - struct HeaderData HdrData; - DataExtractor AccelSection; - DataExtractor StringSection; - const RelocAddrMap& Relocs; -public: - DWARFAcceleratorTable(DataExtractor AccelSection, DataExtractor StringSection, - const RelocAddrMap &Relocs) - : AccelSection(AccelSection), StringSection(StringSection), Relocs(Relocs) {} - - bool extract(); - void dump(raw_ostream &OS) const; -}; - -} diff --git a/lib/DebugInfo/DWARFCompileUnit.h b/lib/DebugInfo/DWARFCompileUnit.h deleted file mode 100644 index b3190b18..0000000 --- a/lib/DebugInfo/DWARFCompileUnit.h +++ /dev/null @@ -1,31 +0,0 @@ -//===-- DWARFCompileUnit.h --------------------------------------*- C++ -*-===// -// -// 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_DWARFCOMPILEUNIT_H -#define LLVM_LIB_DEBUGINFO_DWARFCOMPILEUNIT_H - -#include "DWARFUnit.h" - -namespace llvm { - -class DWARFCompileUnit : public DWARFUnit { -public: - DWARFCompileUnit(DWARFContext &Context, const DWARFSection &Section, - const DWARFDebugAbbrev *DA, StringRef RS, StringRef SS, - StringRef SOS, StringRef AOS, bool LE, - const DWARFUnitSectionBase &UnitSection) - : DWARFUnit(Context, Section, DA, RS, SS, SOS, AOS, LE, UnitSection) {} - void dump(raw_ostream &OS); - // VTable anchor. - ~DWARFCompileUnit() override; -}; - -} - -#endif diff --git a/lib/DebugInfo/DWARFContext.h b/lib/DebugInfo/DWARFContext.h deleted file mode 100644 index dd3fcc7..0000000 --- a/lib/DebugInfo/DWARFContext.h +++ /dev/null @@ -1,292 +0,0 @@ -//===-- DWARFContext.h ------------------------------------------*- C++ -*-===// -// -// 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_DWARFCONTEXT_H -#define LLVM_LIB_DEBUGINFO_DWARFCONTEXT_H - -#include "DWARFCompileUnit.h" -#include "DWARFDebugAranges.h" -#include "DWARFDebugFrame.h" -#include "DWARFDebugLine.h" -#include "DWARFDebugLoc.h" -#include "DWARFDebugRangeList.h" -#include "DWARFSection.h" -#include "DWARFTypeUnit.h" -#include "llvm/ADT/MapVector.h" -#include "llvm/ADT/SmallVector.h" -#include "llvm/DebugInfo/DIContext.h" -#include <vector> - -namespace llvm { - -/// DWARFContext -/// This data structure is the top level entity that deals with dwarf debug -/// information parsing. The actual data is supplied through pure virtual -/// methods that a concrete implementation provides. -class DWARFContext : public DIContext { - - DWARFUnitSection<DWARFCompileUnit> CUs; - std::vector<DWARFUnitSection<DWARFTypeUnit>> TUs; - std::unique_ptr<DWARFDebugAbbrev> Abbrev; - std::unique_ptr<DWARFDebugLoc> Loc; - std::unique_ptr<DWARFDebugAranges> Aranges; - std::unique_ptr<DWARFDebugLine> Line; - std::unique_ptr<DWARFDebugFrame> DebugFrame; - - DWARFUnitSection<DWARFCompileUnit> DWOCUs; - std::vector<DWARFUnitSection<DWARFTypeUnit>> DWOTUs; - std::unique_ptr<DWARFDebugAbbrev> AbbrevDWO; - std::unique_ptr<DWARFDebugLocDWO> LocDWO; - - DWARFContext(DWARFContext &) LLVM_DELETED_FUNCTION; - DWARFContext &operator=(DWARFContext &) LLVM_DELETED_FUNCTION; - - /// Read compile units from the debug_info section (if necessary) - /// and store them in CUs. - void parseCompileUnits(); - - /// Read type units from the debug_types sections (if necessary) - /// and store them in TUs. - void parseTypeUnits(); - - /// Read compile units from the debug_info.dwo section (if necessary) - /// and store them in DWOCUs. - void parseDWOCompileUnits(); - - /// Read type units from the debug_types.dwo section (if necessary) - /// and store them in DWOTUs. - void parseDWOTypeUnits(); - -public: - DWARFContext() : DIContext(CK_DWARF) {} - - static bool classof(const DIContext *DICtx) { - return DICtx->getKind() == CK_DWARF; - } - - void dump(raw_ostream &OS, DIDumpType DumpType = DIDT_All) override; - - typedef DWARFUnitSection<DWARFCompileUnit>::iterator_range cu_iterator_range; - typedef DWARFUnitSection<DWARFTypeUnit>::iterator_range tu_iterator_range; - typedef iterator_range<std::vector<DWARFUnitSection<DWARFTypeUnit>>::iterator> tu_section_iterator_range; - - /// Get compile units in this context. - cu_iterator_range compile_units() { - parseCompileUnits(); - return cu_iterator_range(CUs.begin(), CUs.end()); - } - - /// Get type units in this context. - tu_section_iterator_range type_unit_sections() { - parseTypeUnits(); - return tu_section_iterator_range(TUs.begin(), TUs.end()); - } - - /// Get compile units in the DWO context. - cu_iterator_range dwo_compile_units() { - parseDWOCompileUnits(); - return cu_iterator_range(DWOCUs.begin(), DWOCUs.end()); - } - - /// Get type units in the DWO context. - tu_section_iterator_range dwo_type_unit_sections() { - parseDWOTypeUnits(); - return tu_section_iterator_range(DWOTUs.begin(), DWOTUs.end()); - } - - /// Get the number of compile units in this context. - unsigned getNumCompileUnits() { - parseCompileUnits(); - return CUs.size(); - } - - /// Get the number of compile units in this context. - unsigned getNumTypeUnits() { - parseTypeUnits(); - return TUs.size(); - } - - /// Get the number of compile units in the DWO context. - unsigned getNumDWOCompileUnits() { - parseDWOCompileUnits(); - return DWOCUs.size(); - } - - /// Get the number of compile units in the DWO context. - unsigned getNumDWOTypeUnits() { - parseDWOTypeUnits(); - return DWOTUs.size(); - } - - /// Get the compile unit at the specified index for this compile unit. - DWARFCompileUnit *getCompileUnitAtIndex(unsigned index) { - parseCompileUnits(); - return CUs[index].get(); - } - - /// Get the compile unit at the specified index for the DWO compile units. - DWARFCompileUnit *getDWOCompileUnitAtIndex(unsigned index) { - parseDWOCompileUnits(); - return DWOCUs[index].get(); - } - - /// Get a pointer to the parsed DebugAbbrev object. - const DWARFDebugAbbrev *getDebugAbbrev(); - - /// Get a pointer to the parsed DebugLoc object. - const DWARFDebugLoc *getDebugLoc(); - - /// Get a pointer to the parsed dwo abbreviations object. - const DWARFDebugAbbrev *getDebugAbbrevDWO(); - - /// Get a pointer to the parsed DebugLoc object. - const DWARFDebugLocDWO *getDebugLocDWO(); - - /// Get a pointer to the parsed DebugAranges object. - const DWARFDebugAranges *getDebugAranges(); - - /// Get a pointer to the parsed frame information object. - const DWARFDebugFrame *getDebugFrame(); - - /// Get a pointer to a parsed line table corresponding to a compile unit. - const DWARFDebugLine::LineTable *getLineTableForUnit(DWARFUnit *cu); - - DILineInfo getLineInfoForAddress(uint64_t Address, - DILineInfoSpecifier Specifier = DILineInfoSpecifier()) override; - DILineInfoTable getLineInfoForAddressRange(uint64_t Address, uint64_t Size, - DILineInfoSpecifier Specifier = DILineInfoSpecifier()) override; - DIInliningInfo getInliningInfoForAddress(uint64_t Address, - DILineInfoSpecifier Specifier = DILineInfoSpecifier()) override; - - virtual bool isLittleEndian() const = 0; - virtual uint8_t getAddressSize() const = 0; - virtual const DWARFSection &getInfoSection() = 0; - typedef MapVector<object::SectionRef, DWARFSection, - std::map<object::SectionRef, unsigned>> TypeSectionMap; - virtual const TypeSectionMap &getTypesSections() = 0; - virtual StringRef getAbbrevSection() = 0; - virtual const DWARFSection &getLocSection() = 0; - virtual StringRef getARangeSection() = 0; - virtual StringRef getDebugFrameSection() = 0; - virtual const DWARFSection &getLineSection() = 0; - virtual StringRef getStringSection() = 0; - virtual StringRef getRangeSection() = 0; - virtual StringRef getPubNamesSection() = 0; - virtual StringRef getPubTypesSection() = 0; - virtual StringRef getGnuPubNamesSection() = 0; - virtual StringRef getGnuPubTypesSection() = 0; - - // Sections for DWARF5 split dwarf proposal. - virtual const DWARFSection &getInfoDWOSection() = 0; - virtual const TypeSectionMap &getTypesDWOSections() = 0; - virtual StringRef getAbbrevDWOSection() = 0; - virtual const DWARFSection &getLineDWOSection() = 0; - virtual const DWARFSection &getLocDWOSection() = 0; - virtual StringRef getStringDWOSection() = 0; - virtual StringRef getStringOffsetDWOSection() = 0; - virtual StringRef getRangeDWOSection() = 0; - virtual StringRef getAddrSection() = 0; - virtual const DWARFSection& getAppleNamesSection() = 0; - virtual const DWARFSection& getAppleTypesSection() = 0; - virtual const DWARFSection& getAppleNamespacesSection() = 0; - virtual const DWARFSection& getAppleObjCSection() = 0; - - static bool isSupportedVersion(unsigned version) { - return version == 2 || version == 3 || version == 4; - } -private: - /// Return the compile unit that includes an offset (relative to .debug_info). - DWARFCompileUnit *getCompileUnitForOffset(uint32_t Offset); - - /// Return the compile unit which contains instruction with provided - /// address. - DWARFCompileUnit *getCompileUnitForAddress(uint64_t Address); -}; - -/// DWARFContextInMemory is the simplest possible implementation of a -/// DWARFContext. It assumes all content is available in memory and stores -/// pointers to it. -class DWARFContextInMemory : public DWARFContext { - virtual void anchor(); - bool IsLittleEndian; - uint8_t AddressSize; - DWARFSection InfoSection; - TypeSectionMap TypesSections; - StringRef AbbrevSection; - DWARFSection LocSection; - StringRef ARangeSection; - StringRef DebugFrameSection; - DWARFSection LineSection; - StringRef StringSection; - StringRef RangeSection; - StringRef PubNamesSection; - StringRef PubTypesSection; - StringRef GnuPubNamesSection; - StringRef GnuPubTypesSection; - - // Sections for DWARF5 split dwarf proposal. - DWARFSection InfoDWOSection; - TypeSectionMap TypesDWOSections; - StringRef AbbrevDWOSection; - DWARFSection LineDWOSection; - DWARFSection LocDWOSection; - StringRef StringDWOSection; - StringRef StringOffsetDWOSection; - StringRef RangeDWOSection; - StringRef AddrSection; - DWARFSection AppleNamesSection; - DWARFSection AppleTypesSection; - DWARFSection AppleNamespacesSection; - DWARFSection AppleObjCSection; - - SmallVector<SmallString<32>, 4> UncompressedSections; - -public: - DWARFContextInMemory(const object::ObjectFile &Obj); - bool isLittleEndian() const override { return IsLittleEndian; } - uint8_t getAddressSize() const override { return AddressSize; } - const DWARFSection &getInfoSection() override { return InfoSection; } - const TypeSectionMap &getTypesSections() override { return TypesSections; } - StringRef getAbbrevSection() override { return AbbrevSection; } - const DWARFSection &getLocSection() override { return LocSection; } - StringRef getARangeSection() override { return ARangeSection; } - StringRef getDebugFrameSection() override { return DebugFrameSection; } - const DWARFSection &getLineSection() override { return LineSection; } - StringRef getStringSection() override { return StringSection; } - StringRef getRangeSection() override { return RangeSection; } - StringRef getPubNamesSection() override { return PubNamesSection; } - StringRef getPubTypesSection() override { return PubTypesSection; } - StringRef getGnuPubNamesSection() override { return GnuPubNamesSection; } - StringRef getGnuPubTypesSection() override { return GnuPubTypesSection; } - const DWARFSection& getAppleNamesSection() override { return AppleNamesSection; } - const DWARFSection& getAppleTypesSection() override { return AppleTypesSection; } - const DWARFSection& getAppleNamespacesSection() override { return AppleNamespacesSection; } - const DWARFSection& getAppleObjCSection() override { return AppleObjCSection; } - - // Sections for DWARF5 split dwarf proposal. - const DWARFSection &getInfoDWOSection() override { return InfoDWOSection; } - const TypeSectionMap &getTypesDWOSections() override { - return TypesDWOSections; - } - StringRef getAbbrevDWOSection() override { return AbbrevDWOSection; } - const DWARFSection &getLineDWOSection() override { return LineDWOSection; } - const DWARFSection &getLocDWOSection() override { return LocDWOSection; } - StringRef getStringDWOSection() override { return StringDWOSection; } - StringRef getStringOffsetDWOSection() override { - return StringOffsetDWOSection; - } - StringRef getRangeDWOSection() override { return RangeDWOSection; } - StringRef getAddrSection() override { - return AddrSection; - } -}; - -} - -#endif diff --git a/lib/DebugInfo/DWARFDebugAbbrev.h b/lib/DebugInfo/DWARFDebugAbbrev.h deleted file mode 100644 index 4b3b814..0000000 --- a/lib/DebugInfo/DWARFDebugAbbrev.h +++ /dev/null @@ -1,63 +0,0 @@ -//===-- DWARFDebugAbbrev.h --------------------------------------*- C++ -*-===// -// -// 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_DWARFDEBUGABBREV_H -#define LLVM_LIB_DEBUGINFO_DWARFDEBUGABBREV_H - -#include "DWARFAbbreviationDeclaration.h" -#include <list> -#include <map> -#include <vector> - -namespace llvm { - -class DWARFAbbreviationDeclarationSet { - uint32_t Offset; - /// Code of the first abbreviation, if all abbreviations in the set have - /// consecutive codes. UINT32_MAX otherwise. - uint32_t FirstAbbrCode; - std::vector<DWARFAbbreviationDeclaration> Decls; - -public: - DWARFAbbreviationDeclarationSet(); - - uint32_t getOffset() const { return Offset; } - void dump(raw_ostream &OS) const; - bool extract(DataExtractor Data, uint32_t *OffsetPtr); - - const DWARFAbbreviationDeclaration * - getAbbreviationDeclaration(uint32_t AbbrCode) const; - -private: - void clear(); -}; - -class DWARFDebugAbbrev { - typedef std::map<uint64_t, DWARFAbbreviationDeclarationSet> - DWARFAbbreviationDeclarationSetMap; - - DWARFAbbreviationDeclarationSetMap AbbrDeclSets; - mutable DWARFAbbreviationDeclarationSetMap::const_iterator PrevAbbrOffsetPos; - -public: - DWARFDebugAbbrev(); - - const DWARFAbbreviationDeclarationSet * - getAbbreviationDeclarationSet(uint64_t CUAbbrOffset) const; - - void dump(raw_ostream &OS) const; - void extract(DataExtractor Data); - -private: - void clear(); -}; - -} - -#endif diff --git a/lib/DebugInfo/DWARFDebugArangeSet.h b/lib/DebugInfo/DWARFDebugArangeSet.h deleted file mode 100644 index 837a8e6..0000000 --- a/lib/DebugInfo/DWARFDebugArangeSet.h +++ /dev/null @@ -1,70 +0,0 @@ -//===-- DWARFDebugArangeSet.h -----------------------------------*- C++ -*-===// -// -// 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_DWARFDEBUGARANGESET_H -#define LLVM_LIB_DEBUGINFO_DWARFDEBUGARANGESET_H - -#include "llvm/ADT/iterator_range.h" -#include "llvm/Support/DataExtractor.h" -#include <vector> - -namespace llvm { - -class raw_ostream; - -class DWARFDebugArangeSet { -public: - struct Header { - // The total length of the entries for that set, not including the length - // field itself. - uint32_t Length; - // The offset from the beginning of the .debug_info section of the - // compilation unit entry referenced by the table. - uint32_t CuOffset; - // The DWARF version number. - uint16_t Version; - // The size in bytes of an address on the target architecture. For segmented - // addressing, this is the size of the offset portion of the address. - uint8_t AddrSize; - // The size in bytes of a segment descriptor on the target architecture. - // If the target system uses a flat address space, this value is 0. - uint8_t SegSize; - }; - - struct Descriptor { - uint64_t Address; - uint64_t Length; - uint64_t getEndAddress() const { return Address + Length; } - }; - -private: - typedef std::vector<Descriptor> DescriptorColl; - typedef iterator_range<DescriptorColl::const_iterator> desc_iterator_range; - - uint32_t Offset; - Header HeaderData; - DescriptorColl ArangeDescriptors; - -public: - DWARFDebugArangeSet() { clear(); } - void clear(); - bool extract(DataExtractor data, uint32_t *offset_ptr); - void dump(raw_ostream &OS) const; - - uint32_t getCompileUnitDIEOffset() const { return HeaderData.CuOffset; } - - desc_iterator_range descriptors() const { - return desc_iterator_range(ArangeDescriptors.begin(), - ArangeDescriptors.end()); - } -}; - -} - -#endif diff --git a/lib/DebugInfo/DWARFDebugAranges.h b/lib/DebugInfo/DWARFDebugAranges.h deleted file mode 100644 index 791f010..0000000 --- a/lib/DebugInfo/DWARFDebugAranges.h +++ /dev/null @@ -1,87 +0,0 @@ -//===-- DWARFDebugAranges.h -------------------------------------*- C++ -*-===// -// -// 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_DWARFDEBUGARANGES_H -#define LLVM_LIB_DEBUGINFO_DWARFDEBUGARANGES_H - -#include "llvm/ADT/DenseSet.h" -#include "llvm/Support/DataExtractor.h" -#include <vector> - -namespace llvm { - -class DWARFContext; - -class DWARFDebugAranges { -public: - void generate(DWARFContext *CTX); - uint32_t findAddress(uint64_t Address) const; - -private: - void clear(); - void extract(DataExtractor DebugArangesData); - - // Call appendRange multiple times and then call construct. - void appendRange(uint32_t CUOffset, uint64_t LowPC, uint64_t HighPC); - void construct(); - - struct Range { - explicit Range(uint64_t LowPC = -1ULL, uint64_t HighPC = -1ULL, - uint32_t CUOffset = -1U) - : LowPC(LowPC), Length(HighPC - LowPC), CUOffset(CUOffset) {} - - void setHighPC(uint64_t HighPC) { - if (HighPC == -1ULL || HighPC <= LowPC) - Length = 0; - else - Length = HighPC - LowPC; - } - uint64_t HighPC() const { - if (Length) - return LowPC + Length; - return -1ULL; - } - - bool containsAddress(uint64_t Address) const { - return LowPC <= Address && Address < HighPC(); - } - bool operator<(const Range &other) const { - return LowPC < other.LowPC; - } - - uint64_t LowPC; // Start of address range. - uint32_t Length; // End of address range (not including this address). - uint32_t CUOffset; // Offset of the compile unit or die. - }; - - struct RangeEndpoint { - uint64_t Address; - uint32_t CUOffset; - bool IsRangeStart; - - RangeEndpoint(uint64_t Address, uint32_t CUOffset, bool IsRangeStart) - : Address(Address), CUOffset(CUOffset), IsRangeStart(IsRangeStart) {} - - bool operator<(const RangeEndpoint &Other) const { - return Address < Other.Address; - } - }; - - - typedef std::vector<Range> RangeColl; - typedef RangeColl::const_iterator RangeCollIterator; - - std::vector<RangeEndpoint> Endpoints; - RangeColl Aranges; - DenseSet<uint32_t> ParsedCUOffsets; -}; - -} - -#endif diff --git a/lib/DebugInfo/DWARFDebugFrame.h b/lib/DebugInfo/DWARFDebugFrame.h deleted file mode 100644 index be925cb..0000000 --- a/lib/DebugInfo/DWARFDebugFrame.h +++ /dev/null @@ -1,43 +0,0 @@ -//===-- DWARFDebugFrame.h - Parsing of .debug_frame -------------*- C++ -*-===// -// -// 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_DWARFDEBUGFRAME_H -#define LLVM_LIB_DEBUGINFO_DWARFDEBUGFRAME_H - -#include "llvm/Support/DataExtractor.h" -#include "llvm/Support/raw_ostream.h" -#include <memory> -#include <vector> - -namespace llvm { - -class FrameEntry; - -/// \brief A parsed .debug_frame section -/// -class DWARFDebugFrame { -public: - DWARFDebugFrame(); - ~DWARFDebugFrame(); - - /// \brief Dump the section data into the given stream. - void dump(raw_ostream &OS) const; - - /// \brief Parse the section from raw data. - /// data is assumed to be pointing to the beginning of the section. - void parse(DataExtractor Data); - -private: - std::vector<std::unique_ptr<FrameEntry>> Entries; -}; - - -} // namespace llvm - -#endif diff --git a/lib/DebugInfo/DWARFDebugInfoEntry.h b/lib/DebugInfo/DWARFDebugInfoEntry.h deleted file mode 100644 index 7e7efb9..0000000 --- a/lib/DebugInfo/DWARFDebugInfoEntry.h +++ /dev/null @@ -1,160 +0,0 @@ -//===-- DWARFDebugInfoEntry.h -----------------------------------*- C++ -*-===// -// -// 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_DWARFDEBUGINFOENTRY_H -#define LLVM_LIB_DEBUGINFO_DWARFDEBUGINFOENTRY_H - -#include "DWARFAbbreviationDeclaration.h" -#include "DWARFDebugRangeList.h" -#include "llvm/ADT/SmallVector.h" -#include "llvm/DebugInfo/DIContext.h" -#include "llvm/Support/DataTypes.h" - -namespace llvm { - -class DWARFDebugAranges; -class DWARFCompileUnit; -class DWARFUnit; -class DWARFContext; -class DWARFFormValue; -struct DWARFDebugInfoEntryInlinedChain; - -/// DWARFDebugInfoEntryMinimal - A DIE with only the minimum required data. -class DWARFDebugInfoEntryMinimal { - /// Offset within the .debug_info of the start of this entry. - uint32_t Offset; - - /// How many to add to "this" to get the sibling. - uint32_t SiblingIdx; - - const DWARFAbbreviationDeclaration *AbbrevDecl; -public: - DWARFDebugInfoEntryMinimal() - : Offset(0), SiblingIdx(0), AbbrevDecl(nullptr) {} - - void dump(raw_ostream &OS, DWARFUnit *u, unsigned recurseDepth, - unsigned indent = 0) const; - void dumpAttribute(raw_ostream &OS, DWARFUnit *u, uint32_t *offset_ptr, - uint16_t attr, uint16_t form, unsigned indent = 0) const; - - /// Extracts a debug info entry, which is a child of a given unit, - /// starting at a given offset. If DIE can't be extracted, returns false and - /// doesn't change OffsetPtr. - bool extractFast(const DWARFUnit *U, uint32_t *OffsetPtr); - - uint32_t getTag() const { return AbbrevDecl ? AbbrevDecl->getTag() : 0; } - bool isNULL() const { return AbbrevDecl == nullptr; } - - /// Returns true if DIE represents a subprogram (not inlined). - bool isSubprogramDIE() const; - /// Returns true if DIE represents a subprogram or an inlined - /// subroutine. - bool isSubroutineDIE() const; - - uint32_t getOffset() const { return Offset; } - bool hasChildren() const { return !isNULL() && AbbrevDecl->hasChildren(); } - - // We know we are kept in a vector of contiguous entries, so we know - // our sibling will be some index after "this". - const DWARFDebugInfoEntryMinimal *getSibling() const { - return SiblingIdx > 0 ? this + SiblingIdx : nullptr; - } - - // We know we are kept in a vector of contiguous entries, so we know - // we don't need to store our child pointer, if we have a child it will - // be the next entry in the list... - const DWARFDebugInfoEntryMinimal *getFirstChild() const { - return hasChildren() ? this + 1 : nullptr; - } - - void setSibling(const DWARFDebugInfoEntryMinimal *Sibling) { - if (Sibling) { - // We know we are kept in a vector of contiguous entries, so we know - // our sibling will be some index after "this". - SiblingIdx = Sibling - this; - } else - SiblingIdx = 0; - } - - const DWARFAbbreviationDeclaration *getAbbreviationDeclarationPtr() const { - return AbbrevDecl; - } - - bool getAttributeValue(const DWARFUnit *U, const uint16_t Attr, - DWARFFormValue &FormValue) const; - - const char *getAttributeValueAsString(const DWARFUnit *U, const uint16_t Attr, - const char *FailValue) const; - - uint64_t getAttributeValueAsAddress(const DWARFUnit *U, const uint16_t Attr, - uint64_t FailValue) const; - - uint64_t getAttributeValueAsUnsignedConstant(const DWARFUnit *U, - const uint16_t Attr, - uint64_t FailValue) const; - - uint64_t getAttributeValueAsReference(const DWARFUnit *U, const uint16_t Attr, - uint64_t FailValue) const; - - uint64_t getAttributeValueAsSectionOffset(const DWARFUnit *U, - const uint16_t Attr, - uint64_t FailValue) const; - - uint64_t getRangesBaseAttribute(const DWARFUnit *U, uint64_t FailValue) const; - - /// Retrieves DW_AT_low_pc and DW_AT_high_pc from CU. - /// Returns true if both attributes are present. - bool getLowAndHighPC(const DWARFUnit *U, uint64_t &LowPC, - uint64_t &HighPC) const; - - DWARFAddressRangesVector getAddressRanges(const DWARFUnit *U) const; - - void collectChildrenAddressRanges(const DWARFUnit *U, - DWARFAddressRangesVector &Ranges) const; - - bool addressRangeContainsAddress(const DWARFUnit *U, - const uint64_t Address) const; - - /// If a DIE represents a subprogram (or inlined subroutine), - /// returns its mangled name (or short name, if mangled is missing). - /// This name may be fetched from specification or abstract origin - /// for this subprogram. Returns null if no name is found. - const char *getSubroutineName(const DWARFUnit *U, DINameKind Kind) const; - - /// Return the DIE name resolving DW_AT_sepcification or - /// DW_AT_abstract_origin references if necessary. - /// Returns null if no name is found. - const char *getName(const DWARFUnit *U, DINameKind Kind) const; - - /// Retrieves values of DW_AT_call_file, DW_AT_call_line and - /// DW_AT_call_column from DIE (or zeroes if they are missing). - void getCallerFrame(const DWARFUnit *U, uint32_t &CallFile, - uint32_t &CallLine, uint32_t &CallColumn) const; - - /// Get inlined chain for a given address, rooted at the current DIE. - /// Returns empty chain if address is not contained in address range - /// of current DIE. - DWARFDebugInfoEntryInlinedChain - getInlinedChainForAddress(const DWARFUnit *U, const uint64_t Address) const; -}; - -/// DWARFDebugInfoEntryInlinedChain - represents a chain of inlined_subroutine -/// DIEs, (possibly ending with subprogram DIE), all of which are contained -/// in some concrete inlined instance tree. Address range for each DIE -/// (except the last DIE) in this chain is contained in address -/// range for next DIE in the chain. -struct DWARFDebugInfoEntryInlinedChain { - DWARFDebugInfoEntryInlinedChain() : U(nullptr) {} - SmallVector<DWARFDebugInfoEntryMinimal, 4> DIEs; - const DWARFUnit *U; -}; - -} - -#endif diff --git a/lib/DebugInfo/DWARFDebugLine.h b/lib/DebugInfo/DWARFDebugLine.h deleted file mode 100644 index 7a6f1bd..0000000 --- a/lib/DebugInfo/DWARFDebugLine.h +++ /dev/null @@ -1,238 +0,0 @@ -//===-- DWARFDebugLine.h ----------------------------------------*- C++ -*-===// -// -// 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_DWARFDEBUGLINE_H -#define LLVM_LIB_DEBUGINFO_DWARFDEBUGLINE_H - -#include "DWARFRelocMap.h" -#include "llvm/DebugInfo/DIContext.h" -#include "llvm/Support/DataExtractor.h" -#include <map> -#include <string> -#include <vector> - -namespace llvm { - -class raw_ostream; - -class DWARFDebugLine { -public: - DWARFDebugLine(const RelocAddrMap* LineInfoRelocMap) : RelocMap(LineInfoRelocMap) {} - struct FileNameEntry { - FileNameEntry() : Name(nullptr), DirIdx(0), ModTime(0), Length(0) {} - - const char *Name; - uint64_t DirIdx; - uint64_t ModTime; - uint64_t Length; - }; - - struct Prologue { - Prologue(); - - // The size in bytes of the statement information for this compilation unit - // (not including the total_length field itself). - uint32_t TotalLength; - // Version identifier for the statement information format. - uint16_t Version; - // The number of bytes following the prologue_length field to the beginning - // of the first byte of the statement program itself. - uint32_t PrologueLength; - // The size in bytes of the smallest target machine instruction. Statement - // program opcodes that alter the address register first multiply their - // operands by this value. - uint8_t MinInstLength; - // The maximum number of individual operations that may be encoded in an - // instruction. - uint8_t MaxOpsPerInst; - // The initial value of theis_stmtregister. - uint8_t DefaultIsStmt; - // This parameter affects the meaning of the special opcodes. See below. - int8_t LineBase; - // This parameter affects the meaning of the special opcodes. See below. - uint8_t LineRange; - // The number assigned to the first special opcode. - uint8_t OpcodeBase; - std::vector<uint8_t> StandardOpcodeLengths; - std::vector<const char*> IncludeDirectories; - std::vector<FileNameEntry> FileNames; - - // Length of the prologue in bytes. - uint32_t getLength() const { - return PrologueLength + sizeof(TotalLength) + sizeof(Version) + - sizeof(PrologueLength); - } - // Length of the line table data in bytes (not including the prologue). - uint32_t getStatementTableLength() const { - return TotalLength + sizeof(TotalLength) - getLength(); - } - int32_t getMaxLineIncrementForSpecialOpcode() const { - return LineBase + (int8_t)LineRange - 1; - } - - void clear(); - void dump(raw_ostream &OS) const; - bool parse(DataExtractor debug_line_data, uint32_t *offset_ptr); - }; - - // Standard .debug_line state machine structure. - struct Row { - explicit Row(bool default_is_stmt = false); - - /// Called after a row is appended to the matrix. - void postAppend(); - void reset(bool default_is_stmt); - void dump(raw_ostream &OS) const; - - static bool orderByAddress(const Row& LHS, const Row& RHS) { - return LHS.Address < RHS.Address; - } - - // The program-counter value corresponding to a machine instruction - // generated by the compiler. - uint64_t Address; - // An unsigned integer indicating a source line number. Lines are numbered - // beginning at 1. The compiler may emit the value 0 in cases where an - // instruction cannot be attributed to any source line. - uint32_t Line; - // An unsigned integer indicating a column number within a source line. - // Columns are numbered beginning at 1. The value 0 is reserved to indicate - // that a statement begins at the 'left edge' of the line. - uint16_t Column; - // An unsigned integer indicating the identity of the source file - // corresponding to a machine instruction. - uint16_t File; - // An unsigned integer whose value encodes the applicable instruction set - // architecture for the current instruction. - uint8_t Isa; - // An unsigned integer representing the DWARF path discriminator value - // for this location. - uint32_t Discriminator; - // A boolean indicating that the current instruction is the beginning of a - // statement. - uint8_t IsStmt:1, - // A boolean indicating that the current instruction is the - // beginning of a basic block. - BasicBlock:1, - // A boolean indicating that the current address is that of the - // first byte after the end of a sequence of target machine - // instructions. - EndSequence:1, - // A boolean indicating that the current address is one (of possibly - // many) where execution should be suspended for an entry breakpoint - // of a function. - PrologueEnd:1, - // A boolean indicating that the current address is one (of possibly - // many) where execution should be suspended for an exit breakpoint - // of a function. - EpilogueBegin:1; - }; - - // Represents a series of contiguous machine instructions. Line table for each - // compilation unit may consist of multiple sequences, which are not - // guaranteed to be in the order of ascending instruction address. - struct Sequence { - // Sequence describes instructions at address range [LowPC, HighPC) - // and is described by line table rows [FirstRowIndex, LastRowIndex). - uint64_t LowPC; - uint64_t HighPC; - unsigned FirstRowIndex; - unsigned LastRowIndex; - bool Empty; - - Sequence(); - void reset(); - - static bool orderByLowPC(const Sequence& LHS, const Sequence& RHS) { - return LHS.LowPC < RHS.LowPC; - } - bool isValid() const { - return !Empty && (LowPC < HighPC) && (FirstRowIndex < LastRowIndex); - } - bool containsPC(uint64_t pc) const { - return (LowPC <= pc && pc < HighPC); - } - }; - - struct LineTable { - LineTable(); - - void appendRow(const DWARFDebugLine::Row &R) { - Rows.push_back(R); - } - void appendSequence(const DWARFDebugLine::Sequence &S) { - Sequences.push_back(S); - } - - // Returns the index of the row with file/line info for a given address, - // or -1 if there is no such row. - uint32_t lookupAddress(uint64_t address) const; - - bool lookupAddressRange(uint64_t address, uint64_t size, - std::vector<uint32_t> &result) const; - - // Extracts filename by its index in filename table in prologue. - // Returns true on success. - bool getFileNameByIndex(uint64_t FileIndex, const char *CompDir, - DILineInfoSpecifier::FileLineInfoKind Kind, - std::string &Result) const; - - // Fills the Result argument with the file and line information - // corresponding to Address. Returns true on success. - bool getFileLineInfoForAddress(uint64_t Address, const char *CompDir, - DILineInfoSpecifier::FileLineInfoKind Kind, - DILineInfo &Result) const; - - void dump(raw_ostream &OS) const; - void clear(); - - /// Parse prologue and all rows. - bool parse(DataExtractor debug_line_data, const RelocAddrMap *RMap, - uint32_t *offset_ptr); - - struct Prologue Prologue; - typedef std::vector<Row> RowVector; - typedef RowVector::const_iterator RowIter; - typedef std::vector<Sequence> SequenceVector; - typedef SequenceVector::const_iterator SequenceIter; - RowVector Rows; - SequenceVector Sequences; - }; - - const LineTable *getLineTable(uint32_t offset) const; - const LineTable *getOrParseLineTable(DataExtractor debug_line_data, - uint32_t offset); - -private: - struct ParsingState { - ParsingState(struct LineTable *LT); - - void resetRowAndSequence(); - void appendRowToMatrix(uint32_t offset); - - // Line table we're currently parsing. - struct LineTable *LineTable; - // The row number that starts at zero for the prologue, and increases for - // each row added to the matrix. - unsigned RowNumber; - struct Row Row; - struct Sequence Sequence; - }; - - typedef std::map<uint32_t, LineTable> LineTableMapTy; - typedef LineTableMapTy::iterator LineTableIter; - typedef LineTableMapTy::const_iterator LineTableConstIter; - - const RelocAddrMap *RelocMap; - LineTableMapTy LineTableMap; -}; - -} - -#endif diff --git a/lib/DebugInfo/DWARFDebugLoc.h b/lib/DebugInfo/DWARFDebugLoc.h deleted file mode 100644 index 50110b3..0000000 --- a/lib/DebugInfo/DWARFDebugLoc.h +++ /dev/null @@ -1,81 +0,0 @@ -//===-- DWARFDebugLoc.h -----------------------------------------*- C++ -*-===// -// -// 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_DWARFDEBUGLOC_H -#define LLVM_LIB_DEBUGINFO_DWARFDEBUGLOC_H - -#include "DWARFRelocMap.h" -#include "llvm/ADT/SmallVector.h" -#include "llvm/Support/DataExtractor.h" - -namespace llvm { - -class raw_ostream; - -class DWARFDebugLoc { - /// A single location within a location list. - struct Entry { - /// The beginning address of the instruction range. - uint64_t Begin; - /// The ending address of the instruction range. - uint64_t End; - /// The location of the variable within the specified range. - SmallVector<unsigned char, 4> Loc; - }; - - /// A list of locations that contain one variable. - struct LocationList { - /// The beginning offset where this location list is stored in the debug_loc - /// section. - unsigned Offset; - /// All the locations in which the variable is stored. - SmallVector<Entry, 2> Entries; - }; - - typedef SmallVector<LocationList, 4> LocationLists; - - /// A list of all the variables in the debug_loc section, each one describing - /// the locations in which the variable is stored. - LocationLists Locations; - - /// A map used to resolve binary relocations. - const RelocAddrMap &RelocMap; - -public: - DWARFDebugLoc(const RelocAddrMap &LocRelocMap) : RelocMap(LocRelocMap) {} - /// Print the location lists found within the debug_loc section. - void dump(raw_ostream &OS) const; - /// Parse the debug_loc section accessible via the 'data' parameter using the - /// specified address size to interpret the address ranges. - void parse(DataExtractor data, unsigned AddressSize); -}; - -class DWARFDebugLocDWO { - struct Entry { - uint64_t Start; - uint32_t Length; - SmallVector<unsigned char, 4> Loc; - }; - - struct LocationList { - unsigned Offset; - SmallVector<Entry, 2> Entries; - }; - - typedef SmallVector<LocationList, 4> LocationLists; - - LocationLists Locations; - -public: - void parse(DataExtractor data); - void dump(raw_ostream &OS) const; -}; -} - -#endif diff --git a/lib/DebugInfo/DWARFDebugRangeList.h b/lib/DebugInfo/DWARFDebugRangeList.h deleted file mode 100644 index 4ee3bda..0000000 --- a/lib/DebugInfo/DWARFDebugRangeList.h +++ /dev/null @@ -1,77 +0,0 @@ -//===-- DWARFDebugRangeList.h -----------------------------------*- C++ -*-===// -// -// 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_DWARFDEBUGRANGELIST_H -#define LLVM_LIB_DEBUGINFO_DWARFDEBUGRANGELIST_H - -#include "llvm/Support/DataExtractor.h" -#include <vector> - -namespace llvm { - -class raw_ostream; - -/// DWARFAddressRangesVector - represents a set of absolute address ranges. -typedef std::vector<std::pair<uint64_t, uint64_t>> DWARFAddressRangesVector; - -class DWARFDebugRangeList { -public: - struct RangeListEntry { - // A beginning address offset. This address offset has the size of an - // address and is relative to the applicable base address of the - // compilation unit referencing this range list. It marks the beginning - // of an address range. - uint64_t StartAddress; - // An ending address offset. This address offset again has the size of - // an address and is relative to the applicable base address of the - // compilation unit referencing this range list. It marks the first - // address past the end of the address range. The ending address must - // be greater than or equal to the beginning address. - uint64_t EndAddress; - // The end of any given range list is marked by an end of list entry, - // which consists of a 0 for the beginning address offset - // and a 0 for the ending address offset. - bool isEndOfListEntry() const { - return (StartAddress == 0) && (EndAddress == 0); - } - // A base address selection entry consists of: - // 1. The value of the largest representable address offset - // (for example, 0xffffffff when the size of an address is 32 bits). - // 2. An address, which defines the appropriate base address for - // use in interpreting the beginning and ending address offsets of - // subsequent entries of the location list. - bool isBaseAddressSelectionEntry(uint8_t AddressSize) const { - assert(AddressSize == 4 || AddressSize == 8); - if (AddressSize == 4) - return StartAddress == -1U; - else - return StartAddress == -1ULL; - } - }; - -private: - // Offset in .debug_ranges section. - uint32_t Offset; - uint8_t AddressSize; - std::vector<RangeListEntry> Entries; - -public: - DWARFDebugRangeList() { clear(); } - void clear(); - void dump(raw_ostream &OS) const; - bool extract(DataExtractor data, uint32_t *offset_ptr); - /// 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; -}; - -} // namespace llvm - -#endif // LLVM_DEBUGINFO_DWARFDEBUGRANGELIST_H diff --git a/lib/DebugInfo/DWARFRelocMap.h b/lib/DebugInfo/DWARFRelocMap.h deleted file mode 100644 index d7fe303..0000000 --- a/lib/DebugInfo/DWARFRelocMap.h +++ /dev/null @@ -1,22 +0,0 @@ -//===-- DWARFRelocMap.h -----------------------------------------*- C++ -*-===// -// -// 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_DWARFRELOCMAP_H -#define LLVM_LIB_DEBUGINFO_DWARFRELOCMAP_H - -#include "llvm/ADT/DenseMap.h" - -namespace llvm { - -typedef DenseMap<uint64_t, std::pair<uint8_t, int64_t> > RelocAddrMap; - -} // namespace llvm - -#endif - diff --git a/lib/DebugInfo/DWARFSection.h b/lib/DebugInfo/DWARFSection.h deleted file mode 100644 index 3aaf0ff..0000000 --- a/lib/DebugInfo/DWARFSection.h +++ /dev/null @@ -1,24 +0,0 @@ -//===-- DWARFSection.h ------------------------------------------*- C++ -*-===// -// -// 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_DWARFSECTION_H -#define LLVM_LIB_DEBUGINFO_DWARFSECTION_H - -#include "DWARFRelocMap.h" - -namespace llvm { - -struct DWARFSection { - StringRef Data; - RelocAddrMap Relocs; -}; - -} - -#endif diff --git a/lib/DebugInfo/DWARFTypeUnit.h b/lib/DebugInfo/DWARFTypeUnit.h deleted file mode 100644 index 7471b5a..0000000 --- a/lib/DebugInfo/DWARFTypeUnit.h +++ /dev/null @@ -1,38 +0,0 @@ -//===-- DWARFTypeUnit.h -----------------------------------------*- C++ -*-===// -// -// 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_DWARFTYPEUNIT_H -#define LLVM_LIB_DEBUGINFO_DWARFTYPEUNIT_H - -#include "DWARFUnit.h" - -namespace llvm { - -class DWARFTypeUnit : public DWARFUnit { -private: - uint64_t TypeHash; - uint32_t TypeOffset; -public: - DWARFTypeUnit(DWARFContext &Context, const DWARFSection &Section, - const DWARFDebugAbbrev *DA, StringRef RS, StringRef SS, - StringRef SOS, StringRef AOS, bool LE, - const DWARFUnitSectionBase &UnitSection) - : DWARFUnit(Context, Section, DA, RS, SS, SOS, AOS, LE, UnitSection) {} - uint32_t getHeaderSize() const override { - return DWARFUnit::getHeaderSize() + 12; - } - void dump(raw_ostream &OS); -protected: - bool extractImpl(DataExtractor debug_info, uint32_t *offset_ptr) override; -}; - -} - -#endif - diff --git a/lib/DebugInfo/DWARFUnit.h b/lib/DebugInfo/DWARFUnit.h deleted file mode 100644 index 786f00f..0000000 --- a/lib/DebugInfo/DWARFUnit.h +++ /dev/null @@ -1,245 +0,0 @@ -//===-- DWARFUnit.h ---------------------------------------------*- C++ -*-===// -// -// 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_DWARFUNIT_H -#define LLVM_LIB_DEBUGINFO_DWARFUNIT_H - -#include "DWARFDebugAbbrev.h" -#include "DWARFDebugInfoEntry.h" -#include "DWARFDebugRangeList.h" -#include "DWARFRelocMap.h" -#include "DWARFSection.h" -#include <vector> - -namespace llvm { - -namespace object { -class ObjectFile; -} - -class DWARFContext; -class DWARFDebugAbbrev; -class DWARFUnit; -class StringRef; -class raw_ostream; - -/// Base class for all DWARFUnitSection classes. This provides the -/// functionality common to all unit types. -class DWARFUnitSectionBase { -public: - /// Returns the Unit that contains the given section offset in the - /// same section this Unit originated from. - virtual DWARFUnit *getUnitForOffset(uint32_t Offset) const = 0; - - void parse(DWARFContext &C, const DWARFSection &Section); - void parseDWO(DWARFContext &C, const DWARFSection &DWOSection); - -protected: - virtual void parseImpl(DWARFContext &Context, const DWARFSection &Section, - const DWARFDebugAbbrev *DA, StringRef RS, StringRef SS, - StringRef SOS, StringRef AOS, bool isLittleEndian) = 0; - - ~DWARFUnitSectionBase() {} -}; - -/// Concrete instance of DWARFUnitSection, specialized for one Unit type. -template<typename UnitType> -class DWARFUnitSection final : public SmallVector<std::unique_ptr<UnitType>, 1>, - public DWARFUnitSectionBase { - - struct UnitOffsetComparator { - bool operator()(uint32_t LHS, - const std::unique_ptr<UnitType> &RHS) const { - return LHS < RHS->getNextUnitOffset(); - } - }; - - bool Parsed; - -public: - DWARFUnitSection() : Parsed(false) {} - DWARFUnitSection(DWARFUnitSection &&DUS) : - SmallVector<std::unique_ptr<UnitType>, 1>(std::move(DUS)), Parsed(DUS.Parsed) {} - - typedef llvm::SmallVectorImpl<std::unique_ptr<UnitType>> UnitVector; - typedef typename UnitVector::iterator iterator; - typedef llvm::iterator_range<typename UnitVector::iterator> iterator_range; - - UnitType *getUnitForOffset(uint32_t Offset) const override { - auto *CU = std::upper_bound(this->begin(), this->end(), Offset, - UnitOffsetComparator()); - if (CU != this->end()) - return CU->get(); - return nullptr; - } - -private: - void parseImpl(DWARFContext &Context, const DWARFSection &Section, - const DWARFDebugAbbrev *DA, StringRef RS, StringRef SS, - StringRef SOS, StringRef AOS, bool LE) override { - if (Parsed) - return; - DataExtractor Data(Section.Data, LE, 0); - uint32_t Offset = 0; - while (Data.isValidOffset(Offset)) { - auto U = llvm::make_unique<UnitType>(Context, Section, DA, RS, SS, SOS, - AOS, LE, *this); - if (!U->extract(Data, &Offset)) - break; - this->push_back(std::move(U)); - Offset = this->back()->getNextUnitOffset(); - } - Parsed = true; - } -}; - -class DWARFUnit { - DWARFContext &Context; - // Section containing this DWARFUnit. - const DWARFSection &InfoSection; - - const DWARFDebugAbbrev *Abbrev; - StringRef RangeSection; - uint32_t RangeSectionBase; - StringRef StringSection; - StringRef StringOffsetSection; - StringRef AddrOffsetSection; - uint32_t AddrOffsetSectionBase; - bool isLittleEndian; - const DWARFUnitSectionBase &UnitSection; - - uint32_t Offset; - uint32_t Length; - uint16_t Version; - const DWARFAbbreviationDeclarationSet *Abbrevs; - uint8_t AddrSize; - uint64_t BaseAddr; - // The compile unit debug information entry items. - std::vector<DWARFDebugInfoEntryMinimal> DieArray; - - class DWOHolder { - object::OwningBinary<object::ObjectFile> DWOFile; - std::unique_ptr<DWARFContext> DWOContext; - DWARFUnit *DWOU; - public: - DWOHolder(StringRef DWOPath); - DWARFUnit *getUnit() const { return DWOU; } - }; - std::unique_ptr<DWOHolder> DWO; - -protected: - virtual bool extractImpl(DataExtractor debug_info, uint32_t *offset_ptr); - /// Size in bytes of the unit header. - virtual uint32_t getHeaderSize() const { return 11; } - -public: - DWARFUnit(DWARFContext &Context, const DWARFSection &Section, - const DWARFDebugAbbrev *DA, StringRef RS, StringRef SS, - StringRef SOS, StringRef AOS, bool LE, - const DWARFUnitSectionBase &UnitSection); - - virtual ~DWARFUnit(); - - DWARFContext& getContext() const { return Context; } - - StringRef getStringSection() const { return StringSection; } - StringRef getStringOffsetSection() const { return StringOffsetSection; } - void setAddrOffsetSection(StringRef AOS, uint32_t Base) { - AddrOffsetSection = AOS; - AddrOffsetSectionBase = Base; - } - void setRangesSection(StringRef RS, uint32_t Base) { - RangeSection = RS; - RangeSectionBase = Base; - } - - bool getAddrOffsetSectionItem(uint32_t Index, uint64_t &Result) const; - // FIXME: Result should be uint64_t in DWARF64. - bool getStringOffsetSectionItem(uint32_t Index, uint32_t &Result) const; - - DataExtractor getDebugInfoExtractor() const { - return DataExtractor(InfoSection.Data, isLittleEndian, AddrSize); - } - DataExtractor getStringExtractor() const { - return DataExtractor(StringSection, false, 0); - } - - const RelocAddrMap *getRelocMap() const { return &InfoSection.Relocs; } - - bool extract(DataExtractor debug_info, uint32_t* offset_ptr); - - /// extractRangeList - extracts the range list referenced by this compile - /// unit from .debug_ranges section. Returns true on success. - /// Requires that compile unit is already extracted. - bool extractRangeList(uint32_t RangeListOffset, - DWARFDebugRangeList &RangeList) const; - void clear(); - uint32_t getOffset() const { return Offset; } - uint32_t getNextUnitOffset() const { return Offset + Length + 4; } - uint32_t getLength() const { return Length; } - uint16_t getVersion() const { return Version; } - const DWARFAbbreviationDeclarationSet *getAbbreviations() const { - return Abbrevs; - } - uint8_t getAddressByteSize() const { return AddrSize; } - uint64_t getBaseAddress() const { return BaseAddr; } - - void setBaseAddress(uint64_t base_addr) { - BaseAddr = base_addr; - } - - const DWARFDebugInfoEntryMinimal * - getCompileUnitDIE(bool extract_cu_die_only = true) { - extractDIEsIfNeeded(extract_cu_die_only); - return DieArray.empty() ? nullptr : &DieArray[0]; - } - - const char *getCompilationDir(); - uint64_t getDWOId(); - - void collectAddressRanges(DWARFAddressRangesVector &CURanges); - - /// getInlinedChainForAddress - fetches inlined chain for a given address. - /// Returns empty chain if there is no subprogram containing address. The - /// chain is valid as long as parsed compile unit DIEs are not cleared. - DWARFDebugInfoEntryInlinedChain getInlinedChainForAddress(uint64_t Address); - - /// getUnitSection - Return the DWARFUnitSection containing this unit. - const DWARFUnitSectionBase &getUnitSection() const { return UnitSection; } - -private: - /// Size in bytes of the .debug_info data associated with this compile unit. - size_t getDebugInfoSize() const { return Length + 4 - getHeaderSize(); } - - /// extractDIEsIfNeeded - Parses a compile unit and indexes its DIEs if it - /// hasn't already been done. Returns the number of DIEs parsed at this call. - size_t extractDIEsIfNeeded(bool CUDieOnly); - /// extractDIEsToVector - Appends all parsed DIEs to a vector. - void extractDIEsToVector(bool AppendCUDie, bool AppendNonCUDIEs, - std::vector<DWARFDebugInfoEntryMinimal> &DIEs) const; - /// setDIERelations - We read in all of the DIE entries into our flat list - /// of DIE entries and now we need to go back through all of them and set the - /// parent, sibling and child pointers for quick DIE navigation. - void setDIERelations(); - /// clearDIEs - Clear parsed DIEs to keep memory usage low. - void clearDIEs(bool KeepCUDie); - - /// parseDWO - Parses .dwo file for current compile unit. Returns true if - /// it was actually constructed. - bool parseDWO(); - - /// getSubprogramForAddress - Returns subprogram DIE with address range - /// encompassing the provided address. The pointer is alive as long as parsed - /// compile unit DIEs are not cleared. - const DWARFDebugInfoEntryMinimal *getSubprogramForAddress(uint64_t Address); -}; - -} - -#endif diff --git a/lib/DebugInfo/LLVMBuild.txt b/lib/DebugInfo/LLVMBuild.txt index f347d5e..7a8e8ba 100644 --- a/lib/DebugInfo/LLVMBuild.txt +++ b/lib/DebugInfo/LLVMBuild.txt @@ -15,8 +15,10 @@ ; ;===------------------------------------------------------------------------===; +[common] +subdirectories = DWARF PDB + [component_0] -type = Library +type = Group name = DebugInfo -parent = Libraries -required_libraries = Object Support +parent = $ROOT diff --git a/lib/DebugInfo/Makefile b/lib/DebugInfo/Makefile index 1292b57..27a5e1f 100644 --- a/lib/DebugInfo/Makefile +++ b/lib/DebugInfo/Makefile @@ -6,9 +6,10 @@ # License. See LICENSE.TXT for details. # ##===----------------------------------------------------------------------===## - LEVEL = ../.. -LIBRARYNAME = LLVMDebugInfo -BUILD_ARCHIVE := 1 -include $(LEVEL)/Makefile.common +include $(LEVEL)/Makefile.config + +PARALLEL_DIRS := DWARF PDB + +include $(LEVEL)/Makefile.common
\ No newline at end of file diff --git a/lib/DebugInfo/PDB/Android.mk b/lib/DebugInfo/PDB/Android.mk new file mode 100644 index 0000000..c8d4fd1 --- /dev/null +++ b/lib/DebugInfo/PDB/Android.mk @@ -0,0 +1,75 @@ +LOCAL_PATH:= $(call my-dir) + +# No dia support +debuginfo_pdb_SRC_FILES := \ + IPDBSourceFile.cpp \ + PDB.cpp \ + PDBExtras.cpp \ + PDBInterfaceAnchors.cpp \ + PDBSymbolAnnotation.cpp \ + PDBSymbolBlock.cpp \ + PDBSymbolCompiland.cpp \ + PDBSymbolCompilandDetails.cpp \ + PDBSymbolCompilandEnv.cpp \ + PDBSymbol.cpp \ + PDBSymbolCustom.cpp \ + PDBSymbolData.cpp \ + PDBSymbolExe.cpp \ + PDBSymbolFunc.cpp \ + PDBSymbolFuncDebugEnd.cpp \ + PDBSymbolFuncDebugStart.cpp \ + PDBSymbolLabel.cpp \ + PDBSymbolPublicSymbol.cpp \ + PDBSymbolThunk.cpp \ + PDBSymbolTypeArray.cpp \ + PDBSymbolTypeBaseClass.cpp \ + PDBSymbolTypeBuiltin.cpp \ + PDBSymbolTypeCustom.cpp \ + PDBSymbolTypeDimension.cpp \ + PDBSymbolTypeEnum.cpp \ + PDBSymbolTypeFriend.cpp \ + PDBSymbolTypeFunctionArg.cpp \ + PDBSymbolTypeFunctionSig.cpp \ + PDBSymbolTypeManaged.cpp \ + PDBSymbolTypePointer.cpp \ + PDBSymbolTypeTypedef.cpp \ + PDBSymbolTypeUDT.cpp \ + PDBSymbolTypeVTable.cpp \ + PDBSymbolTypeVTableShape.cpp \ + PDBSymbolUnknown.cpp \ + PDBSymbolUsingNamespace.cpp \ + PDBSymDumper.cpp + +# For the host +# ===================================================== +include $(CLEAR_VARS) + +REQUIRES_RTTI := 1 + +LOCAL_SRC_FILES := $(debuginfo_pdb_SRC_FILES) + +LOCAL_MODULE:= libLLVMDebugInfoPDB + +LOCAL_MODULE_TAGS := optional + +include $(LLVM_HOST_BUILD_MK) +include $(LLVM_GEN_INTRINSICS_MK) +include $(BUILD_HOST_STATIC_LIBRARY) + +# For the device +# ===================================================== +ifneq (true,$(DISABLE_LLVM_DEVICE_BUILDS)) +include $(CLEAR_VARS) + +REQUIRES_RTTI := 1 + +LOCAL_SRC_FILES := $(debuginfo_pdb_SRC_FILES) + +LOCAL_MODULE:= libLLVMDebugInfoPDB + +LOCAL_MODULE_TAGS := optional + +include $(LLVM_DEVICE_BUILD_MK) +include $(LLVM_GEN_INTRINSICS_MK) +include $(BUILD_STATIC_LIBRARY) +endif diff --git a/lib/DebugInfo/PDB/CMakeLists.txt b/lib/DebugInfo/PDB/CMakeLists.txt new file mode 100644 index 0000000..87e357e --- /dev/null +++ b/lib/DebugInfo/PDB/CMakeLists.txt @@ -0,0 +1,76 @@ +macro(add_pdb_impl_folder group) + list(APPEND PDB_IMPL_SOURCES ${ARGN}) + source_group(${group} FILES ${ARGN}) +endmacro() + +if(HAVE_DIA_SDK) + include_directories(${MSVC_DIA_SDK_DIR}/include) + set(LIBPDB_LINK_FOLDERS "${MSVC_DIA_SDK_DIR}\\lib") + if (CMAKE_SIZEOF_VOID_P EQUAL 8) + set(LIBPDB_LINK_FOLDERS "${LIBPDB_LINK_FOLDERS}\\amd64") + endif() + set(LIBPDB_ADDITIONAL_LIBRARIES "${LIBPDB_LINK_FOLDERS}\\diaguids.lib") + + add_pdb_impl_folder(DIA + DIA/DIADataStream.cpp + DIA/DIAEnumDebugStreams.cpp + DIA/DIAEnumLineNumbers.cpp + DIA/DIAEnumSourceFiles.cpp + DIA/DIAEnumSymbols.cpp + DIA/DIALineNumber.cpp + DIA/DIARawSymbol.cpp + DIA/DIASession.cpp + DIA/DIASourceFile.cpp + ) + + set(LIBPDB_ADDITIONAL_HEADER_DIRS "${LLVM_MAIN_INCLUDE_DIR}/llvm/DebugInfo/PDB/DIA") + +endif() + +list(APPEND LIBPDB_ADDITIONAL_HEADER_DIRS "${LLVM_MAIN_INCLUDE_DIR}/llvm/DebugInfo/PDB") + +add_llvm_library(LLVMDebugInfoPDB + IPDBSourceFile.cpp + PDB.cpp + PDBExtras.cpp + PDBInterfaceAnchors.cpp + PDBSymbol.cpp + PDBSymbolAnnotation.cpp + PDBSymbolBlock.cpp + PDBSymbolCompiland.cpp + PDBSymbolCompilandDetails.cpp + PDBSymbolCompilandEnv.cpp + PDBSymbolCustom.cpp + PDBSymbolData.cpp + PDBSymbolExe.cpp + PDBSymbolFunc.cpp + PDBSymbolFuncDebugEnd.cpp + PDBSymbolFuncDebugStart.cpp + PDBSymbolLabel.cpp + PDBSymbolPublicSymbol.cpp + PDBSymbolThunk.cpp + PDBSymbolTypeArray.cpp + PDBSymbolTypeBaseClass.cpp + PDBSymbolTypeBuiltin.cpp + PDBSymbolTypeCustom.cpp + PDBSymbolTypeDimension.cpp + PDBSymbolTypeEnum.cpp + PDBSymbolTypeFriend.cpp + PDBSymbolTypeFunctionArg.cpp + PDBSymbolTypeFunctionSig.cpp + PDBSymbolTypeManaged.cpp + PDBSymbolTypePointer.cpp + PDBSymbolTypeTypedef.cpp + PDBSymbolTypeUDT.cpp + PDBSymbolTypeVTable.cpp + PDBSymbolTypeVTableShape.cpp + PDBSymbolUnknown.cpp + PDBSymbolUsingNamespace.cpp + PDBSymDumper.cpp + ${PDB_IMPL_SOURCES} + + ADDITIONAL_HEADER_DIRS + ${LIBPDB_ADDITIONAL_HEADER_DIRS} + ) + +target_link_libraries(LLVMDebugInfoPDB ${cmake_2_8_12_INTERFACE} "${LIBPDB_ADDITIONAL_LIBRARIES}") diff --git a/lib/DebugInfo/PDB/DIA/DIADataStream.cpp b/lib/DebugInfo/PDB/DIA/DIADataStream.cpp new file mode 100644 index 0000000..e0e1b27 --- /dev/null +++ b/lib/DebugInfo/PDB/DIA/DIADataStream.cpp @@ -0,0 +1,73 @@ +//===- DIADataStream.cpp - DIA implementation of IPDBDataStream -*- C++ -*-===// +// +// The LLVM Compiler Infrastructure +// +// This file is distributed under the University of Illinois Open Source +// License. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +#include "llvm/DebugInfo/PDB/DIA/DIADataStream.h" +#include "llvm/Support/ConvertUTF.h" + +using namespace llvm; + +DIADataStream::DIADataStream(CComPtr<IDiaEnumDebugStreamData> DiaStreamData) + : StreamData(DiaStreamData) {} + +uint32_t DIADataStream::getRecordCount() const { + LONG Count = 0; + return (S_OK == StreamData->get_Count(&Count)) ? Count : 0; +} + +std::string DIADataStream::getName() const { + CComBSTR Name16; + if (S_OK != StreamData->get_name(&Name16)) + return std::string(); + + std::string Name8; + llvm::ArrayRef<char> Name16Bytes(reinterpret_cast<char *>(Name16.m_str), + Name16.ByteLength()); + if (!llvm::convertUTF16ToUTF8String(Name16Bytes, Name8)) + return std::string(); + return Name8; +} + +llvm::Optional<DIADataStream::RecordType> +DIADataStream::getItemAtIndex(uint32_t Index) const { + RecordType Record; + DWORD RecordSize = 0; + StreamData->Item(Index, 0, &RecordSize, nullptr); + if (RecordSize == 0) + return llvm::Optional<RecordType>(); + + Record.resize(RecordSize); + if (S_OK != StreamData->Item(Index, RecordSize, &RecordSize, &Record[0])) + return llvm::Optional<RecordType>(); + return Record; +} + +bool DIADataStream::getNext(RecordType &Record) { + Record.clear(); + DWORD RecordSize = 0; + ULONG CountFetched = 0; + StreamData->Next(1, 0, &RecordSize, nullptr, &CountFetched); + if (RecordSize == 0) + return false; + + Record.resize(RecordSize); + if (S_OK == + StreamData->Next(1, RecordSize, &RecordSize, &Record[0], &CountFetched)) + return false; + return true; +} + +void DIADataStream::reset() { StreamData->Reset(); } + +DIADataStream *DIADataStream::clone() const { + CComPtr<IDiaEnumDebugStreamData> EnumeratorClone; + if (S_OK != StreamData->Clone(&EnumeratorClone)) + return nullptr; + + return new DIADataStream(EnumeratorClone); +} diff --git a/lib/DebugInfo/PDB/DIA/DIAEnumDebugStreams.cpp b/lib/DebugInfo/PDB/DIA/DIAEnumDebugStreams.cpp new file mode 100644 index 0000000..23c6489 --- /dev/null +++ b/lib/DebugInfo/PDB/DIA/DIAEnumDebugStreams.cpp @@ -0,0 +1,53 @@ +//==- DIAEnumDebugStreams.cpp - DIA Debug Stream Enumerator impl -*- C++ -*-==// +// +// The LLVM Compiler Infrastructure +// +// This file is distributed under the University of Illinois Open Source +// License. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +#include "llvm/DebugInfo/PDB/PDBSymbol.h" +#include "llvm/DebugInfo/PDB/DIA/DIADataStream.h" +#include "llvm/DebugInfo/PDB/DIA/DIAEnumDebugStreams.h" + +using namespace llvm; + +DIAEnumDebugStreams::DIAEnumDebugStreams( + CComPtr<IDiaEnumDebugStreams> DiaEnumerator) + : Enumerator(DiaEnumerator) {} + +uint32_t DIAEnumDebugStreams::getChildCount() const { + LONG Count = 0; + return (S_OK == Enumerator->get_Count(&Count)) ? Count : 0; +} + +std::unique_ptr<IPDBDataStream> +DIAEnumDebugStreams::getChildAtIndex(uint32_t Index) const { + CComPtr<IDiaEnumDebugStreamData> Item; + VARIANT VarIndex; + VarIndex.vt = VT_I4; + VarIndex.lVal = Index; + if (S_OK != Enumerator->Item(VarIndex, &Item)) + return nullptr; + + return std::unique_ptr<IPDBDataStream>(new DIADataStream(Item)); +} + +std::unique_ptr<IPDBDataStream> DIAEnumDebugStreams::getNext() { + CComPtr<IDiaEnumDebugStreamData> Item; + ULONG NumFetched = 0; + if (S_OK != Enumerator->Next(1, &Item, &NumFetched)) + return nullptr; + + return std::unique_ptr<IPDBDataStream>(new DIADataStream(Item)); +} + +void DIAEnumDebugStreams::reset() { Enumerator->Reset(); } + +DIAEnumDebugStreams *DIAEnumDebugStreams::clone() const { + CComPtr<IDiaEnumDebugStreams> EnumeratorClone; + if (S_OK != Enumerator->Clone(&EnumeratorClone)) + return nullptr; + return new DIAEnumDebugStreams(EnumeratorClone); +} diff --git a/lib/DebugInfo/PDB/DIA/DIAEnumLineNumbers.cpp b/lib/DebugInfo/PDB/DIA/DIAEnumLineNumbers.cpp new file mode 100644 index 0000000..32a9af2 --- /dev/null +++ b/lib/DebugInfo/PDB/DIA/DIAEnumLineNumbers.cpp @@ -0,0 +1,50 @@ +//==- DIAEnumLineNumbers.cpp - DIA Line Number Enumerator impl ---*- C++ -*-==// +// +// The LLVM Compiler Infrastructure +// +// This file is distributed under the University of Illinois Open Source +// License. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +#include "llvm/DebugInfo/PDB/PDBSymbol.h" +#include "llvm/DebugInfo/PDB/DIA/DIAEnumLineNumbers.h" +#include "llvm/DebugInfo/PDB/DIA/DIALineNumber.h" + +using namespace llvm; + +DIAEnumLineNumbers::DIAEnumLineNumbers( + CComPtr<IDiaEnumLineNumbers> DiaEnumerator) + : Enumerator(DiaEnumerator) {} + +uint32_t DIAEnumLineNumbers::getChildCount() const { + LONG Count = 0; + return (S_OK == Enumerator->get_Count(&Count)) ? Count : 0; +} + +std::unique_ptr<IPDBLineNumber> +DIAEnumLineNumbers::getChildAtIndex(uint32_t Index) const { + CComPtr<IDiaLineNumber> Item; + if (S_OK != Enumerator->Item(Index, &Item)) + return nullptr; + + return std::unique_ptr<IPDBLineNumber>(new DIALineNumber(Item)); +} + +std::unique_ptr<IPDBLineNumber> DIAEnumLineNumbers::getNext() { + CComPtr<IDiaLineNumber> Item; + ULONG NumFetched = 0; + if (S_OK != Enumerator->Next(1, &Item, &NumFetched)) + return nullptr; + + return std::unique_ptr<IPDBLineNumber>(new DIALineNumber(Item)); +} + +void DIAEnumLineNumbers::reset() { Enumerator->Reset(); } + +DIAEnumLineNumbers *DIAEnumLineNumbers::clone() const { + CComPtr<IDiaEnumLineNumbers> EnumeratorClone; + if (S_OK != Enumerator->Clone(&EnumeratorClone)) + return nullptr; + return new DIAEnumLineNumbers(EnumeratorClone); +} diff --git a/lib/DebugInfo/PDB/DIA/DIAEnumSourceFiles.cpp b/lib/DebugInfo/PDB/DIA/DIAEnumSourceFiles.cpp new file mode 100644 index 0000000..1a94610 --- /dev/null +++ b/lib/DebugInfo/PDB/DIA/DIAEnumSourceFiles.cpp @@ -0,0 +1,50 @@ +//==- DIAEnumSourceFiles.cpp - DIA Source File Enumerator impl ---*- C++ -*-==// +// +// The LLVM Compiler Infrastructure +// +// This file is distributed under the University of Illinois Open Source +// License. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +#include "llvm/DebugInfo/PDB/PDBSymbol.h" +#include "llvm/DebugInfo/PDB/DIA/DIAEnumSourceFiles.h" +#include "llvm/DebugInfo/PDB/DIA/DIASourceFile.h" + +using namespace llvm; + +DIAEnumSourceFiles::DIAEnumSourceFiles( + const DIASession &PDBSession, CComPtr<IDiaEnumSourceFiles> DiaEnumerator) + : Session(PDBSession), Enumerator(DiaEnumerator) {} + +uint32_t DIAEnumSourceFiles::getChildCount() const { + LONG Count = 0; + return (S_OK == Enumerator->get_Count(&Count)) ? Count : 0; +} + +std::unique_ptr<IPDBSourceFile> +DIAEnumSourceFiles::getChildAtIndex(uint32_t Index) const { + CComPtr<IDiaSourceFile> Item; + if (S_OK != Enumerator->Item(Index, &Item)) + return nullptr; + + return std::unique_ptr<IPDBSourceFile>(new DIASourceFile(Session, Item)); +} + +std::unique_ptr<IPDBSourceFile> DIAEnumSourceFiles::getNext() { + CComPtr<IDiaSourceFile> Item; + ULONG NumFetched = 0; + if (S_OK != Enumerator->Next(1, &Item, &NumFetched)) + return nullptr; + + return std::unique_ptr<IPDBSourceFile>(new DIASourceFile(Session, Item)); +} + +void DIAEnumSourceFiles::reset() { Enumerator->Reset(); } + +DIAEnumSourceFiles *DIAEnumSourceFiles::clone() const { + CComPtr<IDiaEnumSourceFiles> EnumeratorClone; + if (S_OK != Enumerator->Clone(&EnumeratorClone)) + return nullptr; + return new DIAEnumSourceFiles(Session, EnumeratorClone); +} diff --git a/lib/DebugInfo/PDB/DIA/DIAEnumSymbols.cpp b/lib/DebugInfo/PDB/DIA/DIAEnumSymbols.cpp new file mode 100644 index 0000000..6754d9a --- /dev/null +++ b/lib/DebugInfo/PDB/DIA/DIAEnumSymbols.cpp @@ -0,0 +1,54 @@ +//==- DIAEnumSymbols.cpp - DIA Symbol Enumerator impl ------------*- C++ -*-==// +// +// The LLVM Compiler Infrastructure +// +// This file is distributed under the University of Illinois Open Source +// License. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +#include "llvm/DebugInfo/PDB/PDBSymbol.h" +#include "llvm/DebugInfo/PDB/DIA/DIAEnumSymbols.h" +#include "llvm/DebugInfo/PDB/DIA/DIARawSymbol.h" +#include "llvm/DebugInfo/PDB/DIA/DIASession.h" + +using namespace llvm; + +DIAEnumSymbols::DIAEnumSymbols(const DIASession &PDBSession, + CComPtr<IDiaEnumSymbols> DiaEnumerator) + : Session(PDBSession), Enumerator(DiaEnumerator) {} + +uint32_t DIAEnumSymbols::getChildCount() const { + LONG Count = 0; + return (S_OK == Enumerator->get_Count(&Count)) ? Count : 0; +} + +std::unique_ptr<PDBSymbol> +DIAEnumSymbols::getChildAtIndex(uint32_t Index) const { + CComPtr<IDiaSymbol> Item; + if (S_OK != Enumerator->Item(Index, &Item)) + return nullptr; + + std::unique_ptr<DIARawSymbol> RawSymbol(new DIARawSymbol(Session, Item)); + return std::unique_ptr<PDBSymbol>(PDBSymbol::create(Session, std::move(RawSymbol))); +} + +std::unique_ptr<PDBSymbol> DIAEnumSymbols::getNext() { + CComPtr<IDiaSymbol> Item; + ULONG NumFetched = 0; + if (S_OK != Enumerator->Next(1, &Item, &NumFetched)) + return nullptr; + + std::unique_ptr<DIARawSymbol> RawSymbol(new DIARawSymbol(Session, Item)); + return std::unique_ptr<PDBSymbol>( + PDBSymbol::create(Session, std::move(RawSymbol))); +} + +void DIAEnumSymbols::reset() { Enumerator->Reset(); } + +DIAEnumSymbols *DIAEnumSymbols::clone() const { + CComPtr<IDiaEnumSymbols> EnumeratorClone; + if (S_OK != Enumerator->Clone(&EnumeratorClone)) + return nullptr; + return new DIAEnumSymbols(Session, EnumeratorClone); +} diff --git a/lib/DebugInfo/PDB/DIA/DIALineNumber.cpp b/lib/DebugInfo/PDB/DIA/DIALineNumber.cpp new file mode 100644 index 0000000..c5577f1 --- /dev/null +++ b/lib/DebugInfo/PDB/DIA/DIALineNumber.cpp @@ -0,0 +1,75 @@ +//===- DIALineNumber.cpp - DIA implementation of IPDBLineNumber -*- C++ -*-===// +// +// The LLVM Compiler Infrastructure +// +// This file is distributed under the University of Illinois Open Source +// License. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +#include "llvm/DebugInfo/PDB/DIA/DIALineNumber.h" + +using namespace llvm; + +DIALineNumber::DIALineNumber(CComPtr<IDiaLineNumber> DiaLineNumber) + : LineNumber(DiaLineNumber) {} + +uint32_t DIALineNumber::getLineNumber() const { + DWORD Line = 0; + return (S_OK == LineNumber->get_lineNumber(&Line)) ? Line : 0; +} + +uint32_t DIALineNumber::getLineNumberEnd() const { + DWORD LineEnd = 0; + return (S_OK == LineNumber->get_lineNumberEnd(&LineEnd)) ? LineEnd : 0; +} + +uint32_t DIALineNumber::getColumnNumber() const { + DWORD Column = 0; + return (S_OK == LineNumber->get_columnNumber(&Column)) ? Column : 0; +} + +uint32_t DIALineNumber::getColumnNumberEnd() const { + DWORD ColumnEnd = 0; + return (S_OK == LineNumber->get_columnNumberEnd(&ColumnEnd)) ? ColumnEnd : 0; +} + +uint32_t DIALineNumber::getAddressSection() const { + DWORD Section = 0; + return (S_OK == LineNumber->get_addressSection(&Section)) ? Section : 0; +} + +uint32_t DIALineNumber::getAddressOffset() const { + DWORD Offset = 0; + return (S_OK == LineNumber->get_addressOffset(&Offset)) ? Offset : 0; +} + +uint32_t DIALineNumber::getRelativeVirtualAddress() const { + DWORD RVA = 0; + return (S_OK == LineNumber->get_relativeVirtualAddress(&RVA)) ? RVA : 0; +} + +uint64_t DIALineNumber::getVirtualAddress() const { + ULONGLONG Addr = 0; + return (S_OK == LineNumber->get_virtualAddress(&Addr)) ? Addr : 0; +} + +uint32_t DIALineNumber::getLength() const { + DWORD Length = 0; + return (S_OK == LineNumber->get_length(&Length)) ? Length : 0; +} + +uint32_t DIALineNumber::getSourceFileId() const { + DWORD Id = 0; + return (S_OK == LineNumber->get_sourceFileId(&Id)) ? Id : 0; +} + +uint32_t DIALineNumber::getCompilandId() const { + DWORD Id = 0; + return (S_OK == LineNumber->get_compilandId(&Id)) ? Id : 0; +} + +bool DIALineNumber::isStatement() const { + BOOL Statement = 0; + return (S_OK == LineNumber->get_statement(&Statement)) ? Statement : false; +} diff --git a/lib/DebugInfo/PDB/DIA/DIARawSymbol.cpp b/lib/DebugInfo/PDB/DIA/DIARawSymbol.cpp new file mode 100644 index 0000000..abe0ab5 --- /dev/null +++ b/lib/DebugInfo/PDB/DIA/DIARawSymbol.cpp @@ -0,0 +1,1095 @@ +//===- DIARawSymbol.cpp - DIA implementation of IPDBRawSymbol ---*- C++ -*-===// +// +// The LLVM Compiler Infrastructure +// +// This file is distributed under the University of Illinois Open Source +// License. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +#include "llvm/ADT/STLExtras.h" +#include "llvm/DebugInfo/PDB/DIA/DIAEnumSymbols.h" +#include "llvm/DebugInfo/PDB/DIA/DIARawSymbol.h" +#include "llvm/DebugInfo/PDB/DIA/DIASession.h" +#include "llvm/DebugInfo/PDB/PDBExtras.h" +#include "llvm/Support/ConvertUTF.h" +#include "llvm/Support/raw_ostream.h" + +using namespace llvm; + +namespace { +Variant VariantFromVARIANT(const VARIANT &V) { + Variant Result; + switch (V.vt) { + case VT_I1: + Result.Int8 = V.cVal; + Result.Type = PDB_VariantType::Int8; + break; + case VT_I2: + Result.Int16 = V.iVal; + Result.Type = PDB_VariantType::Int16; + break; + case VT_I4: + Result.Int32 = V.intVal; + Result.Type = PDB_VariantType::Int32; + break; + case VT_I8: + Result.Int64 = V.llVal; + Result.Type = PDB_VariantType::Int64; + break; + case VT_UI1: + Result.UInt8 = V.bVal; + Result.Type = PDB_VariantType::UInt8; + break; + case VT_UI2: + Result.UInt16 = V.uiVal; + Result.Type = PDB_VariantType::UInt16; + break; + case VT_UI4: + Result.UInt32 = V.uintVal; + Result.Type = PDB_VariantType::UInt32; + break; + case VT_UI8: + Result.UInt64 = V.ullVal; + Result.Type = PDB_VariantType::UInt64; + break; + case VT_BOOL: + Result.Bool = (V.boolVal == VARIANT_TRUE) ? true : false; + Result.Type = PDB_VariantType::Bool; + break; + case VT_R4: + Result.Single = V.fltVal; + Result.Type = PDB_VariantType::Single; + break; + case VT_R8: + Result.Double = V.dblVal; + Result.Type = PDB_VariantType::Double; + break; + default: + Result.Type = PDB_VariantType::Unknown; + break; + } + return Result; +} + +template <typename ArgType> +ArgType PrivateGetDIAValue(IDiaSymbol *Symbol, + HRESULT (__stdcall IDiaSymbol::*Method)(ArgType *)) { + ArgType Value; + if (S_OK == (Symbol->*Method)(&Value)) + return static_cast<ArgType>(Value); + + return ArgType(); +} + +template <typename ArgType, typename RetType> +RetType PrivateGetDIAValue(IDiaSymbol *Symbol, + HRESULT (__stdcall IDiaSymbol::*Method)(ArgType *)) { + ArgType Value; + if (S_OK == (Symbol->*Method)(&Value)) + return static_cast<RetType>(Value); + + return RetType(); +} + +std::string +PrivateGetDIAValue(IDiaSymbol *Symbol, + HRESULT (__stdcall IDiaSymbol::*Method)(BSTR *)) { + CComBSTR Result16; + if (S_OK != (Symbol->*Method)(&Result16)) + return std::string(); + + const char *SrcBytes = reinterpret_cast<const char *>(Result16.m_str); + llvm::ArrayRef<char> SrcByteArray(SrcBytes, Result16.ByteLength()); + std::string Result8; + if (!llvm::convertUTF16ToUTF8String(SrcByteArray, Result8)) + return std::string(); + return Result8; +} + +PDB_UniqueId +PrivateGetDIAValue(IDiaSymbol *Symbol, + HRESULT (__stdcall IDiaSymbol::*Method)(GUID *)) { + GUID Result; + if (S_OK != (Symbol->*Method)(&Result)) + return PDB_UniqueId(); + + static_assert(sizeof(PDB_UniqueId) == sizeof(GUID), + "PDB_UniqueId is the wrong size!"); + PDB_UniqueId IdResult; + ::memcpy(&IdResult, &Result, sizeof(GUID)); + return IdResult; +} + +template <typename ArgType> +void DumpDIAValue(llvm::raw_ostream &OS, int Indent, StringRef Name, + IDiaSymbol *Symbol, + HRESULT (__stdcall IDiaSymbol::*Method)(ArgType *)) { + ArgType Value; + if (S_OK == (Symbol->*Method)(&Value)) { + OS << "\n"; + OS.indent(Indent); + OS << Name << ": " << Value; + } +} + +void DumpDIAValue(llvm::raw_ostream &OS, int Indent, StringRef Name, + IDiaSymbol *Symbol, + HRESULT (__stdcall IDiaSymbol::*Method)(BSTR *)) { + BSTR Value = nullptr; + if (S_OK != (Symbol->*Method)(&Value)) + return; + const char *Bytes = reinterpret_cast<const char *>(Value); + ArrayRef<char> ByteArray(Bytes, ::SysStringByteLen(Value)); + std::string Result; + if (llvm::convertUTF16ToUTF8String(ByteArray, Result)) { + OS << "\n"; + OS.indent(Indent); + OS << Name << ": " << Result; + } + ::SysFreeString(Value); +} + +void DumpDIAValue(llvm::raw_ostream &OS, int Indent, StringRef Name, + IDiaSymbol *Symbol, + HRESULT (__stdcall IDiaSymbol::*Method)(VARIANT *)) { + VARIANT Value; + Value.vt = VT_EMPTY; + if (S_OK != (Symbol->*Method)(&Value)) + return; + OS << "\n"; + OS.indent(Indent); + Variant V = VariantFromVARIANT(Value); + OS << V; +} +} + +namespace llvm { +raw_ostream &operator<<(raw_ostream &OS, const GUID &Guid) { + const PDB_UniqueId *Id = reinterpret_cast<const PDB_UniqueId *>(&Guid); + OS << *Id; + return OS; +} +} + +DIARawSymbol::DIARawSymbol(const DIASession &PDBSession, + CComPtr<IDiaSymbol> DiaSymbol) + : Session(PDBSession), Symbol(DiaSymbol) {} + +#define RAW_METHOD_DUMP(Stream, Method) \ + DumpDIAValue(Stream, Indent, StringRef(#Method), Symbol, &IDiaSymbol::Method); + +void DIARawSymbol::dump(raw_ostream &OS, int Indent) const { + RAW_METHOD_DUMP(OS, get_access) + RAW_METHOD_DUMP(OS, get_addressOffset) + RAW_METHOD_DUMP(OS, get_addressSection) + RAW_METHOD_DUMP(OS, get_age) + RAW_METHOD_DUMP(OS, get_arrayIndexTypeId) + RAW_METHOD_DUMP(OS, get_backEndMajor) + RAW_METHOD_DUMP(OS, get_backEndMinor) + RAW_METHOD_DUMP(OS, get_backEndBuild) + RAW_METHOD_DUMP(OS, get_backEndQFE) + RAW_METHOD_DUMP(OS, get_baseDataOffset) + RAW_METHOD_DUMP(OS, get_baseDataSlot) + RAW_METHOD_DUMP(OS, get_baseSymbolId) + RAW_METHOD_DUMP(OS, get_baseType) + RAW_METHOD_DUMP(OS, get_bitPosition) + RAW_METHOD_DUMP(OS, get_callingConvention) + RAW_METHOD_DUMP(OS, get_classParentId) + RAW_METHOD_DUMP(OS, get_compilerName) + RAW_METHOD_DUMP(OS, get_count) + RAW_METHOD_DUMP(OS, get_countLiveRanges) + RAW_METHOD_DUMP(OS, get_frontEndMajor) + RAW_METHOD_DUMP(OS, get_frontEndMinor) + RAW_METHOD_DUMP(OS, get_frontEndBuild) + RAW_METHOD_DUMP(OS, get_frontEndQFE) + RAW_METHOD_DUMP(OS, get_lexicalParentId) + RAW_METHOD_DUMP(OS, get_libraryName) + RAW_METHOD_DUMP(OS, get_liveRangeStartAddressOffset) + RAW_METHOD_DUMP(OS, get_liveRangeStartAddressSection) + RAW_METHOD_DUMP(OS, get_liveRangeStartRelativeVirtualAddress) + RAW_METHOD_DUMP(OS, get_localBasePointerRegisterId) + RAW_METHOD_DUMP(OS, get_lowerBoundId) + RAW_METHOD_DUMP(OS, get_memorySpaceKind) + RAW_METHOD_DUMP(OS, get_name) + RAW_METHOD_DUMP(OS, get_numberOfAcceleratorPointerTags) + RAW_METHOD_DUMP(OS, get_numberOfColumns) + RAW_METHOD_DUMP(OS, get_numberOfModifiers) + RAW_METHOD_DUMP(OS, get_numberOfRegisterIndices) + RAW_METHOD_DUMP(OS, get_numberOfRows) + RAW_METHOD_DUMP(OS, get_objectFileName) + RAW_METHOD_DUMP(OS, get_oemId) + RAW_METHOD_DUMP(OS, get_oemSymbolId) + RAW_METHOD_DUMP(OS, get_offsetInUdt) + RAW_METHOD_DUMP(OS, get_platform) + RAW_METHOD_DUMP(OS, get_rank) + RAW_METHOD_DUMP(OS, get_registerId) + RAW_METHOD_DUMP(OS, get_registerType) + RAW_METHOD_DUMP(OS, get_relativeVirtualAddress) + RAW_METHOD_DUMP(OS, get_samplerSlot) + RAW_METHOD_DUMP(OS, get_signature) + RAW_METHOD_DUMP(OS, get_sizeInUdt) + RAW_METHOD_DUMP(OS, get_slot) + RAW_METHOD_DUMP(OS, get_sourceFileName) + RAW_METHOD_DUMP(OS, get_stride) + RAW_METHOD_DUMP(OS, get_subTypeId) + RAW_METHOD_DUMP(OS, get_symbolsFileName) + RAW_METHOD_DUMP(OS, get_symIndexId) + RAW_METHOD_DUMP(OS, get_targetOffset) + RAW_METHOD_DUMP(OS, get_targetRelativeVirtualAddress) + RAW_METHOD_DUMP(OS, get_targetVirtualAddress) + RAW_METHOD_DUMP(OS, get_targetSection) + RAW_METHOD_DUMP(OS, get_textureSlot) + RAW_METHOD_DUMP(OS, get_timeStamp) + RAW_METHOD_DUMP(OS, get_token) + RAW_METHOD_DUMP(OS, get_typeId) + RAW_METHOD_DUMP(OS, get_uavSlot) + RAW_METHOD_DUMP(OS, get_undecoratedName) + RAW_METHOD_DUMP(OS, get_unmodifiedTypeId) + RAW_METHOD_DUMP(OS, get_upperBoundId) + RAW_METHOD_DUMP(OS, get_virtualBaseDispIndex) + RAW_METHOD_DUMP(OS, get_virtualBaseOffset) + RAW_METHOD_DUMP(OS, get_virtualTableShapeId) + RAW_METHOD_DUMP(OS, get_dataKind) + RAW_METHOD_DUMP(OS, get_symTag) + RAW_METHOD_DUMP(OS, get_guid) + RAW_METHOD_DUMP(OS, get_offset) + RAW_METHOD_DUMP(OS, get_thisAdjust) + RAW_METHOD_DUMP(OS, get_virtualBasePointerOffset) + RAW_METHOD_DUMP(OS, get_locationType) + RAW_METHOD_DUMP(OS, get_machineType) + RAW_METHOD_DUMP(OS, get_thunkOrdinal) + RAW_METHOD_DUMP(OS, get_length) + RAW_METHOD_DUMP(OS, get_liveRangeLength) + RAW_METHOD_DUMP(OS, get_virtualAddress) + RAW_METHOD_DUMP(OS, get_udtKind) + RAW_METHOD_DUMP(OS, get_constructor) + RAW_METHOD_DUMP(OS, get_customCallingConvention) + RAW_METHOD_DUMP(OS, get_farReturn) + RAW_METHOD_DUMP(OS, get_code) + RAW_METHOD_DUMP(OS, get_compilerGenerated) + RAW_METHOD_DUMP(OS, get_constType) + RAW_METHOD_DUMP(OS, get_editAndContinueEnabled) + RAW_METHOD_DUMP(OS, get_function) + RAW_METHOD_DUMP(OS, get_stride) + RAW_METHOD_DUMP(OS, get_noStackOrdering) + RAW_METHOD_DUMP(OS, get_hasAlloca) + RAW_METHOD_DUMP(OS, get_hasAssignmentOperator) + RAW_METHOD_DUMP(OS, get_isCTypes) + RAW_METHOD_DUMP(OS, get_hasCastOperator) + RAW_METHOD_DUMP(OS, get_hasDebugInfo) + RAW_METHOD_DUMP(OS, get_hasEH) + RAW_METHOD_DUMP(OS, get_hasEHa) + RAW_METHOD_DUMP(OS, get_hasInlAsm) + RAW_METHOD_DUMP(OS, get_framePointerPresent) + RAW_METHOD_DUMP(OS, get_inlSpec) + RAW_METHOD_DUMP(OS, get_interruptReturn) + RAW_METHOD_DUMP(OS, get_hasLongJump) + RAW_METHOD_DUMP(OS, get_hasManagedCode) + RAW_METHOD_DUMP(OS, get_hasNestedTypes) + RAW_METHOD_DUMP(OS, get_noInline) + RAW_METHOD_DUMP(OS, get_noReturn) + RAW_METHOD_DUMP(OS, get_optimizedCodeDebugInfo) + RAW_METHOD_DUMP(OS, get_overloadedOperator) + RAW_METHOD_DUMP(OS, get_hasSEH) + RAW_METHOD_DUMP(OS, get_hasSecurityChecks) + RAW_METHOD_DUMP(OS, get_hasSetJump) + RAW_METHOD_DUMP(OS, get_strictGSCheck) + RAW_METHOD_DUMP(OS, get_isAcceleratorGroupSharedLocal) + RAW_METHOD_DUMP(OS, get_isAcceleratorPointerTagLiveRange) + RAW_METHOD_DUMP(OS, get_isAcceleratorStubFunction) + RAW_METHOD_DUMP(OS, get_isAggregated) + RAW_METHOD_DUMP(OS, get_intro) + RAW_METHOD_DUMP(OS, get_isCVTCIL) + RAW_METHOD_DUMP(OS, get_isConstructorVirtualBase) + RAW_METHOD_DUMP(OS, get_isCxxReturnUdt) + RAW_METHOD_DUMP(OS, get_isDataAligned) + RAW_METHOD_DUMP(OS, get_isHLSLData) + RAW_METHOD_DUMP(OS, get_isHotpatchable) + RAW_METHOD_DUMP(OS, get_indirectVirtualBaseClass) + RAW_METHOD_DUMP(OS, get_isInterfaceUdt) + RAW_METHOD_DUMP(OS, get_intrinsic) + RAW_METHOD_DUMP(OS, get_isLTCG) + RAW_METHOD_DUMP(OS, get_isLocationControlFlowDependent) + RAW_METHOD_DUMP(OS, get_isMSILNetmodule) + RAW_METHOD_DUMP(OS, get_isMatrixRowMajor) + RAW_METHOD_DUMP(OS, get_managed) + RAW_METHOD_DUMP(OS, get_msil) + RAW_METHOD_DUMP(OS, get_isMultipleInheritance) + RAW_METHOD_DUMP(OS, get_isNaked) + RAW_METHOD_DUMP(OS, get_nested) + RAW_METHOD_DUMP(OS, get_isOptimizedAway) + RAW_METHOD_DUMP(OS, get_packed) + RAW_METHOD_DUMP(OS, get_isPointerBasedOnSymbolValue) + RAW_METHOD_DUMP(OS, get_isPointerToDataMember) + RAW_METHOD_DUMP(OS, get_isPointerToMemberFunction) + RAW_METHOD_DUMP(OS, get_pure) + RAW_METHOD_DUMP(OS, get_RValueReference) + RAW_METHOD_DUMP(OS, get_isRefUdt) + RAW_METHOD_DUMP(OS, get_reference) + RAW_METHOD_DUMP(OS, get_restrictedType) + RAW_METHOD_DUMP(OS, get_isReturnValue) + RAW_METHOD_DUMP(OS, get_isSafeBuffers) + RAW_METHOD_DUMP(OS, get_scoped) + RAW_METHOD_DUMP(OS, get_isSdl) + RAW_METHOD_DUMP(OS, get_isSingleInheritance) + RAW_METHOD_DUMP(OS, get_isSplitted) + RAW_METHOD_DUMP(OS, get_isStatic) + RAW_METHOD_DUMP(OS, get_isStripped) + RAW_METHOD_DUMP(OS, get_unalignedType) + RAW_METHOD_DUMP(OS, get_notReached) + RAW_METHOD_DUMP(OS, get_isValueUdt) + RAW_METHOD_DUMP(OS, get_virtual) + RAW_METHOD_DUMP(OS, get_virtualBaseClass) + RAW_METHOD_DUMP(OS, get_isVirtualInheritance) + RAW_METHOD_DUMP(OS, get_volatileType) + RAW_METHOD_DUMP(OS, get_wasInlined) + RAW_METHOD_DUMP(OS, get_unused) + RAW_METHOD_DUMP(OS, get_value) +} + +std::unique_ptr<IPDBEnumSymbols> +DIARawSymbol::findChildren(PDB_SymType Type) const { + enum SymTagEnum EnumVal = static_cast<enum SymTagEnum>(Type); + + CComPtr<IDiaEnumSymbols> DiaEnumerator; + if (S_OK != Symbol->findChildrenEx(EnumVal, nullptr, nsNone, &DiaEnumerator)) + return nullptr; + + return llvm::make_unique<DIAEnumSymbols>(Session, DiaEnumerator); +} + +std::unique_ptr<IPDBEnumSymbols> +DIARawSymbol::findChildren(PDB_SymType Type, StringRef Name, + PDB_NameSearchFlags Flags) const { + llvm::SmallVector<UTF16, 32> Name16; + llvm::convertUTF8ToUTF16String(Name, Name16); + + enum SymTagEnum EnumVal = static_cast<enum SymTagEnum>(Type); + DWORD CompareFlags = static_cast<DWORD>(Flags); + wchar_t *Name16Str = reinterpret_cast<wchar_t *>(Name16.data()); + + CComPtr<IDiaEnumSymbols> DiaEnumerator; + if (S_OK != + Symbol->findChildrenEx(EnumVal, Name16Str, CompareFlags, &DiaEnumerator)) + return nullptr; + + return llvm::make_unique<DIAEnumSymbols>(Session, DiaEnumerator); +} + +std::unique_ptr<IPDBEnumSymbols> +DIARawSymbol::findChildrenByRVA(PDB_SymType Type, StringRef Name, + PDB_NameSearchFlags Flags, uint32_t RVA) const { + llvm::SmallVector<UTF16, 32> Name16; + llvm::convertUTF8ToUTF16String(Name, Name16); + + enum SymTagEnum EnumVal = static_cast<enum SymTagEnum>(Type); + DWORD CompareFlags = static_cast<DWORD>(Flags); + wchar_t *Name16Str = reinterpret_cast<wchar_t *>(Name16.data()); + + CComPtr<IDiaEnumSymbols> DiaEnumerator; + if (S_OK != + Symbol->findChildrenExByRVA(EnumVal, Name16Str, CompareFlags, RVA, + &DiaEnumerator)) + return nullptr; + + return llvm::make_unique<DIAEnumSymbols>(Session, DiaEnumerator); +} + +std::unique_ptr<IPDBEnumSymbols> +DIARawSymbol::findInlineFramesByRVA(uint32_t RVA) const { + CComPtr<IDiaEnumSymbols> DiaEnumerator; + if (S_OK != Symbol->findInlineFramesByRVA(RVA, &DiaEnumerator)) + return nullptr; + + return llvm::make_unique<DIAEnumSymbols>(Session, DiaEnumerator); +} + +void DIARawSymbol::getDataBytes(llvm::SmallVector<uint8_t, 32> &bytes) const { + bytes.clear(); + + DWORD DataSize = 0; + Symbol->get_dataBytes(0, &DataSize, nullptr); + if (DataSize == 0) + return; + + bytes.resize(DataSize); + Symbol->get_dataBytes(DataSize, &DataSize, bytes.data()); +} + +PDB_MemberAccess DIARawSymbol::getAccess() const { + return PrivateGetDIAValue<DWORD, PDB_MemberAccess>(Symbol, + &IDiaSymbol::get_access); +} + +uint32_t DIARawSymbol::getAddressOffset() const { + return PrivateGetDIAValue(Symbol, &IDiaSymbol::get_addressOffset); +} + +uint32_t DIARawSymbol::getAddressSection() const { + return PrivateGetDIAValue(Symbol, &IDiaSymbol::get_addressSection); +} + +uint32_t DIARawSymbol::getAge() const { + return PrivateGetDIAValue(Symbol, &IDiaSymbol::get_age); +} + +uint32_t DIARawSymbol::getArrayIndexTypeId() const { + return PrivateGetDIAValue(Symbol, &IDiaSymbol::get_arrayIndexTypeId); +} + +void DIARawSymbol::getBackEndVersion(VersionInfo &Version) const { + Version.Major = PrivateGetDIAValue(Symbol, &IDiaSymbol::get_backEndMajor); + Version.Minor = PrivateGetDIAValue(Symbol, &IDiaSymbol::get_backEndMinor); + Version.Build = PrivateGetDIAValue(Symbol, &IDiaSymbol::get_backEndBuild); + Version.QFE = PrivateGetDIAValue(Symbol, &IDiaSymbol::get_backEndQFE); +} + +uint32_t DIARawSymbol::getBaseDataOffset() const { + return PrivateGetDIAValue(Symbol, &IDiaSymbol::get_baseDataOffset); +} + +uint32_t DIARawSymbol::getBaseDataSlot() const { + return PrivateGetDIAValue(Symbol, &IDiaSymbol::get_baseDataSlot); +} + +uint32_t DIARawSymbol::getBaseSymbolId() const { + return PrivateGetDIAValue(Symbol, &IDiaSymbol::get_baseSymbolId); +} + +PDB_BuiltinType DIARawSymbol::getBuiltinType() const { + return PrivateGetDIAValue<DWORD, PDB_BuiltinType>(Symbol, + &IDiaSymbol::get_baseType); +} + +uint32_t DIARawSymbol::getBitPosition() const { + return PrivateGetDIAValue(Symbol, &IDiaSymbol::get_bitPosition); +} + +PDB_CallingConv DIARawSymbol::getCallingConvention() const { + return PrivateGetDIAValue<DWORD, PDB_CallingConv>( + Symbol, &IDiaSymbol::get_callingConvention); +} + +uint32_t DIARawSymbol::getClassParentId() const { + return PrivateGetDIAValue(Symbol, &IDiaSymbol::get_classParentId); +} + +std::string DIARawSymbol::getCompilerName() const { + return PrivateGetDIAValue(Symbol, &IDiaSymbol::get_compilerName); +} + +uint32_t DIARawSymbol::getCount() const { + return PrivateGetDIAValue(Symbol, &IDiaSymbol::get_count); +} + +uint32_t DIARawSymbol::getCountLiveRanges() const { + return PrivateGetDIAValue(Symbol, &IDiaSymbol::get_countLiveRanges); +} + +void DIARawSymbol::getFrontEndVersion(VersionInfo &Version) const { + Version.Major = PrivateGetDIAValue(Symbol, &IDiaSymbol::get_frontEndMajor); + Version.Minor = PrivateGetDIAValue(Symbol, &IDiaSymbol::get_frontEndMinor); + Version.Build = PrivateGetDIAValue(Symbol, &IDiaSymbol::get_frontEndBuild); + Version.QFE = PrivateGetDIAValue(Symbol, &IDiaSymbol::get_frontEndQFE); +} + +PDB_Lang DIARawSymbol::getLanguage() const { + return PrivateGetDIAValue<DWORD, PDB_Lang>(Symbol, &IDiaSymbol::get_language); +} + +uint32_t DIARawSymbol::getLexicalParentId() const { + return PrivateGetDIAValue(Symbol, &IDiaSymbol::get_lexicalParentId); +} + +std::string DIARawSymbol::getLibraryName() const { + return PrivateGetDIAValue(Symbol, &IDiaSymbol::get_libraryName); +} + +uint32_t DIARawSymbol::getLiveRangeStartAddressOffset() const { + return PrivateGetDIAValue(Symbol, + &IDiaSymbol::get_liveRangeStartAddressOffset); +} + +uint32_t DIARawSymbol::getLiveRangeStartAddressSection() const { + return PrivateGetDIAValue(Symbol, + &IDiaSymbol::get_liveRangeStartAddressSection); +} + +uint32_t DIARawSymbol::getLiveRangeStartRelativeVirtualAddress() const { + return PrivateGetDIAValue( + Symbol, &IDiaSymbol::get_liveRangeStartRelativeVirtualAddress); +} + +PDB_RegisterId DIARawSymbol::getLocalBasePointerRegisterId() const { + return PrivateGetDIAValue<DWORD, PDB_RegisterId>( + Symbol, &IDiaSymbol::get_localBasePointerRegisterId); +} + +uint32_t DIARawSymbol::getLowerBoundId() const { + return PrivateGetDIAValue(Symbol, &IDiaSymbol::get_lowerBoundId); +} + +uint32_t DIARawSymbol::getMemorySpaceKind() const { + return PrivateGetDIAValue(Symbol, &IDiaSymbol::get_memorySpaceKind); +} + +std::string DIARawSymbol::getName() const { + return PrivateGetDIAValue(Symbol, &IDiaSymbol::get_name); +} + +uint32_t DIARawSymbol::getNumberOfAcceleratorPointerTags() const { + return PrivateGetDIAValue(Symbol, + &IDiaSymbol::get_numberOfAcceleratorPointerTags); +} + +uint32_t DIARawSymbol::getNumberOfColumns() const { + return PrivateGetDIAValue(Symbol, &IDiaSymbol::get_numberOfColumns); +} + +uint32_t DIARawSymbol::getNumberOfModifiers() const { + return PrivateGetDIAValue(Symbol, &IDiaSymbol::get_numberOfModifiers); +} + +uint32_t DIARawSymbol::getNumberOfRegisterIndices() const { + return PrivateGetDIAValue(Symbol, &IDiaSymbol::get_numberOfRegisterIndices); +} + +uint32_t DIARawSymbol::getNumberOfRows() const { + return PrivateGetDIAValue(Symbol, &IDiaSymbol::get_numberOfRows); +} + +std::string DIARawSymbol::getObjectFileName() const { + return PrivateGetDIAValue(Symbol, &IDiaSymbol::get_objectFileName); +} + +uint32_t DIARawSymbol::getOemId() const { + return PrivateGetDIAValue(Symbol, &IDiaSymbol::get_oemId); +} + +uint32_t DIARawSymbol::getOemSymbolId() const { + return PrivateGetDIAValue(Symbol, &IDiaSymbol::get_oemSymbolId); +} + +uint32_t DIARawSymbol::getOffsetInUdt() const { + return PrivateGetDIAValue(Symbol, &IDiaSymbol::get_offsetInUdt); +} + +PDB_Cpu DIARawSymbol::getPlatform() const { + return PrivateGetDIAValue<DWORD, PDB_Cpu>(Symbol, &IDiaSymbol::get_platform); +} + +uint32_t DIARawSymbol::getRank() const { + return PrivateGetDIAValue(Symbol, &IDiaSymbol::get_rank); +} + +PDB_RegisterId DIARawSymbol::getRegisterId() const { + return PrivateGetDIAValue<DWORD, PDB_RegisterId>(Symbol, + &IDiaSymbol::get_registerId); +} + +uint32_t DIARawSymbol::getRegisterType() const { + return PrivateGetDIAValue(Symbol, &IDiaSymbol::get_registerType); +} + +uint32_t DIARawSymbol::getRelativeVirtualAddress() const { + return PrivateGetDIAValue(Symbol, &IDiaSymbol::get_relativeVirtualAddress); +} + +uint32_t DIARawSymbol::getSamplerSlot() const { + return PrivateGetDIAValue(Symbol, &IDiaSymbol::get_samplerSlot); +} + +uint32_t DIARawSymbol::getSignature() const { + return PrivateGetDIAValue(Symbol, &IDiaSymbol::get_signature); +} + +uint32_t DIARawSymbol::getSizeInUdt() const { + return PrivateGetDIAValue(Symbol, &IDiaSymbol::get_sizeInUdt); +} + +uint32_t DIARawSymbol::getSlot() const { + return PrivateGetDIAValue(Symbol, &IDiaSymbol::get_slot); +} + +std::string DIARawSymbol::getSourceFileName() const { + return PrivateGetDIAValue(Symbol, &IDiaSymbol::get_sourceFileName); +} + +uint32_t DIARawSymbol::getStride() const { + return PrivateGetDIAValue(Symbol, &IDiaSymbol::get_stride); +} + +uint32_t DIARawSymbol::getSubTypeId() const { + return PrivateGetDIAValue(Symbol, &IDiaSymbol::get_subTypeId); +} + +std::string DIARawSymbol::getSymbolsFileName() const { + return PrivateGetDIAValue(Symbol, &IDiaSymbol::get_symbolsFileName); +} + +uint32_t DIARawSymbol::getSymIndexId() const { + return PrivateGetDIAValue(Symbol, &IDiaSymbol::get_symIndexId); +} + +uint32_t DIARawSymbol::getTargetOffset() const { + return PrivateGetDIAValue(Symbol, &IDiaSymbol::get_targetOffset); +} + +uint32_t DIARawSymbol::getTargetRelativeVirtualAddress() const { + return PrivateGetDIAValue(Symbol, + &IDiaSymbol::get_targetRelativeVirtualAddress); +} + +uint64_t DIARawSymbol::getTargetVirtualAddress() const { + return PrivateGetDIAValue(Symbol, &IDiaSymbol::get_targetVirtualAddress); +} + +uint32_t DIARawSymbol::getTargetSection() const { + return PrivateGetDIAValue(Symbol, &IDiaSymbol::get_targetSection); +} + +uint32_t DIARawSymbol::getTextureSlot() const { + return PrivateGetDIAValue(Symbol, &IDiaSymbol::get_textureSlot); +} + +uint32_t DIARawSymbol::getTimeStamp() const { + return PrivateGetDIAValue(Symbol, &IDiaSymbol::get_timeStamp); +} + +uint32_t DIARawSymbol::getToken() const { + return PrivateGetDIAValue(Symbol, &IDiaSymbol::get_token); +} + +uint32_t DIARawSymbol::getTypeId() const { + return PrivateGetDIAValue(Symbol, &IDiaSymbol::get_typeId); +} + +uint32_t DIARawSymbol::getUavSlot() const { + return PrivateGetDIAValue(Symbol, &IDiaSymbol::get_uavSlot); +} + +std::string DIARawSymbol::getUndecoratedName() const { + return PrivateGetDIAValue(Symbol, &IDiaSymbol::get_undecoratedName); +} + +uint32_t DIARawSymbol::getUnmodifiedTypeId() const { + return PrivateGetDIAValue(Symbol, &IDiaSymbol::get_unmodifiedTypeId); +} + +uint32_t DIARawSymbol::getUpperBoundId() const { + return PrivateGetDIAValue(Symbol, &IDiaSymbol::get_upperBoundId); +} + +Variant DIARawSymbol::getValue() const { + VARIANT Value; + Value.vt = VT_EMPTY; + if (S_OK != Symbol->get_value(&Value)) + return Variant(); + + return VariantFromVARIANT(Value); +} + +uint32_t DIARawSymbol::getVirtualBaseDispIndex() const { + return PrivateGetDIAValue(Symbol, &IDiaSymbol::get_virtualBaseDispIndex); +} + +uint32_t DIARawSymbol::getVirtualBaseOffset() const { + return PrivateGetDIAValue(Symbol, &IDiaSymbol::get_virtualBaseOffset); +} + +uint32_t DIARawSymbol::getVirtualTableShapeId() const { + return PrivateGetDIAValue(Symbol, &IDiaSymbol::get_virtualTableShapeId); +} + +PDB_DataKind DIARawSymbol::getDataKind() const { + return PrivateGetDIAValue<DWORD, PDB_DataKind>(Symbol, + &IDiaSymbol::get_dataKind); +} + +PDB_SymType DIARawSymbol::getSymTag() const { + return PrivateGetDIAValue<DWORD, PDB_SymType>(Symbol, + &IDiaSymbol::get_symTag); +} + +PDB_UniqueId DIARawSymbol::getGuid() const { + return PrivateGetDIAValue(Symbol, &IDiaSymbol::get_guid); +} + +int32_t DIARawSymbol::getOffset() const { + return PrivateGetDIAValue(Symbol, &IDiaSymbol::get_offset); +} + +int32_t DIARawSymbol::getThisAdjust() const { + return PrivateGetDIAValue(Symbol, &IDiaSymbol::get_thisAdjust); +} + +int32_t DIARawSymbol::getVirtualBasePointerOffset() const { + return PrivateGetDIAValue(Symbol, &IDiaSymbol::get_virtualBasePointerOffset); +} + +PDB_LocType DIARawSymbol::getLocationType() const { + return PrivateGetDIAValue<DWORD, PDB_LocType>(Symbol, + &IDiaSymbol::get_locationType); +} + +PDB_Machine DIARawSymbol::getMachineType() const { + return PrivateGetDIAValue<DWORD, PDB_Machine>(Symbol, + &IDiaSymbol::get_machineType); +} + +PDB_ThunkOrdinal DIARawSymbol::getThunkOrdinal() const { + return PrivateGetDIAValue<DWORD, PDB_ThunkOrdinal>( + Symbol, &IDiaSymbol::get_thunkOrdinal); +} + +uint64_t DIARawSymbol::getLength() const { + return PrivateGetDIAValue(Symbol, &IDiaSymbol::get_length); +} + +uint64_t DIARawSymbol::getLiveRangeLength() const { + return PrivateGetDIAValue(Symbol, &IDiaSymbol::get_liveRangeLength); +} + +uint64_t DIARawSymbol::getVirtualAddress() const { + return PrivateGetDIAValue(Symbol, &IDiaSymbol::get_virtualAddress); +} + +PDB_UdtType DIARawSymbol::getUdtKind() const { + return PrivateGetDIAValue<DWORD, PDB_UdtType>(Symbol, + &IDiaSymbol::get_udtKind); +} + +bool DIARawSymbol::hasConstructor() const { + return PrivateGetDIAValue(Symbol, &IDiaSymbol::get_constructor); +} + +bool DIARawSymbol::hasCustomCallingConvention() const { + return PrivateGetDIAValue(Symbol, &IDiaSymbol::get_customCallingConvention); +} + +bool DIARawSymbol::hasFarReturn() const { + return PrivateGetDIAValue(Symbol, &IDiaSymbol::get_farReturn); +} + +bool DIARawSymbol::isCode() const { + return PrivateGetDIAValue(Symbol, &IDiaSymbol::get_code); +} + +bool DIARawSymbol::isCompilerGenerated() const { + return PrivateGetDIAValue(Symbol, &IDiaSymbol::get_compilerGenerated); +} + +bool DIARawSymbol::isConstType() const { + return PrivateGetDIAValue(Symbol, &IDiaSymbol::get_constType); +} + +bool DIARawSymbol::isEditAndContinueEnabled() const { + return PrivateGetDIAValue(Symbol, &IDiaSymbol::get_editAndContinueEnabled); +} + +bool DIARawSymbol::isFunction() const { + return PrivateGetDIAValue(Symbol, &IDiaSymbol::get_function); +} + +bool DIARawSymbol::getAddressTaken() const { + return PrivateGetDIAValue(Symbol, &IDiaSymbol::get_addressTaken); +} + +bool DIARawSymbol::getNoStackOrdering() const { + return PrivateGetDIAValue(Symbol, &IDiaSymbol::get_noStackOrdering); +} + +bool DIARawSymbol::hasAlloca() const { + return PrivateGetDIAValue(Symbol, &IDiaSymbol::get_hasAlloca); +} + +bool DIARawSymbol::hasAssignmentOperator() const { + return PrivateGetDIAValue(Symbol, &IDiaSymbol::get_hasAssignmentOperator); +} + +bool DIARawSymbol::hasCTypes() const { + return PrivateGetDIAValue(Symbol, &IDiaSymbol::get_isCTypes); +} + +bool DIARawSymbol::hasCastOperator() const { + return PrivateGetDIAValue(Symbol, &IDiaSymbol::get_hasCastOperator); +} + +bool DIARawSymbol::hasDebugInfo() const { + return PrivateGetDIAValue(Symbol, &IDiaSymbol::get_hasDebugInfo); +} + +bool DIARawSymbol::hasEH() const { + return PrivateGetDIAValue(Symbol, &IDiaSymbol::get_hasEH); +} + +bool DIARawSymbol::hasEHa() const { + return PrivateGetDIAValue(Symbol, &IDiaSymbol::get_hasEHa); +} + +bool DIARawSymbol::hasInlAsm() const { + return PrivateGetDIAValue(Symbol, &IDiaSymbol::get_hasInlAsm); +} + +bool DIARawSymbol::hasInlineAttribute() const { + return PrivateGetDIAValue(Symbol, &IDiaSymbol::get_inlSpec); +} + +bool DIARawSymbol::hasInterruptReturn() const { + return PrivateGetDIAValue(Symbol, &IDiaSymbol::get_interruptReturn); +} + +bool DIARawSymbol::hasFramePointer() const { + return PrivateGetDIAValue(Symbol, &IDiaSymbol::get_framePointerPresent); +} + +bool DIARawSymbol::hasLongJump() const { + return PrivateGetDIAValue(Symbol, &IDiaSymbol::get_hasLongJump); +} + +bool DIARawSymbol::hasManagedCode() const { + return PrivateGetDIAValue(Symbol, &IDiaSymbol::get_hasManagedCode); +} + +bool DIARawSymbol::hasNestedTypes() const { + return PrivateGetDIAValue(Symbol, &IDiaSymbol::get_hasNestedTypes); +} + +bool DIARawSymbol::hasNoInlineAttribute() const { + return PrivateGetDIAValue(Symbol, &IDiaSymbol::get_noInline); +} + +bool DIARawSymbol::hasNoReturnAttribute() const { + return PrivateGetDIAValue(Symbol, &IDiaSymbol::get_noReturn); +} + +bool DIARawSymbol::hasOptimizedCodeDebugInfo() const { + return PrivateGetDIAValue(Symbol, &IDiaSymbol::get_optimizedCodeDebugInfo); +} + +bool DIARawSymbol::hasOverloadedOperator() const { + return PrivateGetDIAValue(Symbol, &IDiaSymbol::get_overloadedOperator); +} + +bool DIARawSymbol::hasSEH() const { + return PrivateGetDIAValue(Symbol, &IDiaSymbol::get_hasSEH); +} + +bool DIARawSymbol::hasSecurityChecks() const { + return PrivateGetDIAValue(Symbol, &IDiaSymbol::get_hasSecurityChecks); +} + +bool DIARawSymbol::hasSetJump() const { + return PrivateGetDIAValue(Symbol, &IDiaSymbol::get_hasSetJump); +} + +bool DIARawSymbol::hasStrictGSCheck() const { + return PrivateGetDIAValue(Symbol, &IDiaSymbol::get_strictGSCheck); +} + +bool DIARawSymbol::isAcceleratorGroupSharedLocal() const { + return PrivateGetDIAValue(Symbol, + &IDiaSymbol::get_isAcceleratorGroupSharedLocal); +} + +bool DIARawSymbol::isAcceleratorPointerTagLiveRange() const { + return PrivateGetDIAValue(Symbol, + &IDiaSymbol::get_isAcceleratorPointerTagLiveRange); +} + +bool DIARawSymbol::isAcceleratorStubFunction() const { + return PrivateGetDIAValue(Symbol, &IDiaSymbol::get_isAcceleratorStubFunction); +} + +bool DIARawSymbol::isAggregated() const { + return PrivateGetDIAValue(Symbol, &IDiaSymbol::get_isAggregated); +} + +bool DIARawSymbol::isIntroVirtualFunction() const { + return PrivateGetDIAValue(Symbol, &IDiaSymbol::get_intro); +} + +bool DIARawSymbol::isCVTCIL() const { + return PrivateGetDIAValue(Symbol, &IDiaSymbol::get_isCVTCIL); +} + +bool DIARawSymbol::isConstructorVirtualBase() const { + return PrivateGetDIAValue(Symbol, &IDiaSymbol::get_isConstructorVirtualBase); +} + +bool DIARawSymbol::isCxxReturnUdt() const { + return PrivateGetDIAValue(Symbol, &IDiaSymbol::get_isCxxReturnUdt); +} + +bool DIARawSymbol::isDataAligned() const { + return PrivateGetDIAValue(Symbol, &IDiaSymbol::get_isDataAligned); +} + +bool DIARawSymbol::isHLSLData() const { + return PrivateGetDIAValue(Symbol, &IDiaSymbol::get_isHLSLData); +} + +bool DIARawSymbol::isHotpatchable() const { + return PrivateGetDIAValue(Symbol, &IDiaSymbol::get_isHotpatchable); +} + +bool DIARawSymbol::isIndirectVirtualBaseClass() const { + return PrivateGetDIAValue(Symbol, &IDiaSymbol::get_indirectVirtualBaseClass); +} + +bool DIARawSymbol::isInterfaceUdt() const { + return PrivateGetDIAValue(Symbol, &IDiaSymbol::get_isInterfaceUdt); +} + +bool DIARawSymbol::isIntrinsic() const { + return PrivateGetDIAValue(Symbol, &IDiaSymbol::get_intrinsic); +} + +bool DIARawSymbol::isLTCG() const { + return PrivateGetDIAValue(Symbol, &IDiaSymbol::get_isLTCG); +} + +bool DIARawSymbol::isLocationControlFlowDependent() const { + return PrivateGetDIAValue(Symbol, + &IDiaSymbol::get_isLocationControlFlowDependent); +} + +bool DIARawSymbol::isMSILNetmodule() const { + return PrivateGetDIAValue(Symbol, &IDiaSymbol::get_isMSILNetmodule); +} + +bool DIARawSymbol::isMatrixRowMajor() const { + return PrivateGetDIAValue(Symbol, &IDiaSymbol::get_isMatrixRowMajor); +} + +bool DIARawSymbol::isManagedCode() const { + return PrivateGetDIAValue(Symbol, &IDiaSymbol::get_managed); +} + +bool DIARawSymbol::isMSILCode() const { + return PrivateGetDIAValue(Symbol, &IDiaSymbol::get_msil); +} + +bool DIARawSymbol::isMultipleInheritance() const { + return PrivateGetDIAValue(Symbol, &IDiaSymbol::get_isMultipleInheritance); +} + +bool DIARawSymbol::isNaked() const { + return PrivateGetDIAValue(Symbol, &IDiaSymbol::get_isNaked); +} + +bool DIARawSymbol::isNested() const { + return PrivateGetDIAValue(Symbol, &IDiaSymbol::get_nested); +} + +bool DIARawSymbol::isOptimizedAway() const { + return PrivateGetDIAValue(Symbol, &IDiaSymbol::get_isOptimizedAway); +} + +bool DIARawSymbol::isPacked() const { + return PrivateGetDIAValue(Symbol, &IDiaSymbol::get_packed); +} + +bool DIARawSymbol::isPointerBasedOnSymbolValue() const { + return PrivateGetDIAValue(Symbol, + &IDiaSymbol::get_isPointerBasedOnSymbolValue); +} + +bool DIARawSymbol::isPointerToDataMember() const { + return PrivateGetDIAValue(Symbol, &IDiaSymbol::get_isPointerToDataMember); +} + +bool DIARawSymbol::isPointerToMemberFunction() const { + return PrivateGetDIAValue(Symbol, &IDiaSymbol::get_isPointerToMemberFunction); +} + +bool DIARawSymbol::isPureVirtual() const { + return PrivateGetDIAValue(Symbol, &IDiaSymbol::get_pure); +} + +bool DIARawSymbol::isRValueReference() const { + return PrivateGetDIAValue(Symbol, &IDiaSymbol::get_RValueReference); +} + +bool DIARawSymbol::isRefUdt() const { + return PrivateGetDIAValue(Symbol, &IDiaSymbol::get_isRefUdt); +} + +bool DIARawSymbol::isReference() const { + return PrivateGetDIAValue(Symbol, &IDiaSymbol::get_reference); +} + +bool DIARawSymbol::isRestrictedType() const { + return PrivateGetDIAValue(Symbol, &IDiaSymbol::get_restrictedType); +} + +bool DIARawSymbol::isReturnValue() const { + return PrivateGetDIAValue(Symbol, &IDiaSymbol::get_isReturnValue); +} + +bool DIARawSymbol::isSafeBuffers() const { + return PrivateGetDIAValue(Symbol, &IDiaSymbol::get_isSafeBuffers); +} + +bool DIARawSymbol::isScoped() const { + return PrivateGetDIAValue(Symbol, &IDiaSymbol::get_scoped); +} + +bool DIARawSymbol::isSdl() const { + return PrivateGetDIAValue(Symbol, &IDiaSymbol::get_isSdl); +} + +bool DIARawSymbol::isSingleInheritance() const { + return PrivateGetDIAValue(Symbol, &IDiaSymbol::get_isSingleInheritance); +} + +bool DIARawSymbol::isSplitted() const { + return PrivateGetDIAValue(Symbol, &IDiaSymbol::get_isSplitted); +} + +bool DIARawSymbol::isStatic() const { + return PrivateGetDIAValue(Symbol, &IDiaSymbol::get_isStatic); +} + +bool DIARawSymbol::hasPrivateSymbols() const { + // hasPrivateSymbols is the opposite of isStripped, but we expose + // hasPrivateSymbols as a more intuitive interface. + return !PrivateGetDIAValue(Symbol, &IDiaSymbol::get_isStripped); +} + +bool DIARawSymbol::isUnalignedType() const { + return PrivateGetDIAValue(Symbol, &IDiaSymbol::get_unalignedType); +} + +bool DIARawSymbol::isUnreached() const { + return PrivateGetDIAValue(Symbol, &IDiaSymbol::get_notReached); +} + +bool DIARawSymbol::isValueUdt() const { + return PrivateGetDIAValue(Symbol, &IDiaSymbol::get_isValueUdt); +} + +bool DIARawSymbol::isVirtual() const { + return PrivateGetDIAValue(Symbol, &IDiaSymbol::get_virtual); +} + +bool DIARawSymbol::isVirtualBaseClass() const { + return PrivateGetDIAValue(Symbol, &IDiaSymbol::get_virtualBaseClass); +} + +bool DIARawSymbol::isVirtualInheritance() const { + return PrivateGetDIAValue(Symbol, &IDiaSymbol::get_isVirtualInheritance); +} + +bool DIARawSymbol::isVolatileType() const { + return PrivateGetDIAValue(Symbol, &IDiaSymbol::get_volatileType); +} + +bool DIARawSymbol::wasInlined() const { + return PrivateGetDIAValue(Symbol, &IDiaSymbol::get_wasInlined); +} + +std::string DIARawSymbol::getUnused() const { + return PrivateGetDIAValue(Symbol, &IDiaSymbol::get_unused); +} diff --git a/lib/DebugInfo/PDB/DIA/DIASession.cpp b/lib/DebugInfo/PDB/DIA/DIASession.cpp new file mode 100644 index 0000000..24791f2 --- /dev/null +++ b/lib/DebugInfo/PDB/DIA/DIASession.cpp @@ -0,0 +1,117 @@ +//===- DIASession.cpp - DIA implementation of IPDBSession -------*- C++ -*-===// +// +// The LLVM Compiler Infrastructure +// +// This file is distributed under the University of Illinois Open Source +// License. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +#include "llvm/ADT/STLExtras.h" +#include "llvm/DebugInfo/PDB/DIA/DIAEnumDebugStreams.h" +#include "llvm/DebugInfo/PDB/DIA/DIAEnumSourceFiles.h" +#include "llvm/DebugInfo/PDB/DIA/DIARawSymbol.h" +#include "llvm/DebugInfo/PDB/DIA/DIASession.h" +#include "llvm/DebugInfo/PDB/DIA/DIASourceFile.h" +#include "llvm/DebugInfo/PDB/PDBSymbolCompiland.h" +#include "llvm/DebugInfo/PDB/PDBSymbolExe.h" +#include "llvm/Support/ConvertUTF.h" + +using namespace llvm; + +namespace {} + +DIASession::DIASession(CComPtr<IDiaSession> DiaSession) : Session(DiaSession) {} + +DIASession *DIASession::createFromPdb(StringRef Path) { + CComPtr<IDiaDataSource> DataSource; + CComPtr<IDiaSession> Session; + + // We assume that CoInitializeEx has already been called by the executable. + HRESULT Result = ::CoCreateInstance(CLSID_DiaSource, nullptr, + CLSCTX_INPROC_SERVER, IID_IDiaDataSource, + reinterpret_cast<LPVOID *>(&DataSource)); + if (FAILED(Result)) + return nullptr; + + llvm::SmallVector<UTF16, 128> Path16; + if (!llvm::convertUTF8ToUTF16String(Path, Path16)) + return nullptr; + + const wchar_t *Path16Str = reinterpret_cast<const wchar_t*>(Path16.data()); + if (FAILED(DataSource->loadDataFromPdb(Path16Str))) + return nullptr; + + if (FAILED(DataSource->openSession(&Session))) + return nullptr; + return new DIASession(Session); +} + +uint64_t DIASession::getLoadAddress() const { + uint64_t LoadAddress; + bool success = (S_OK == Session->get_loadAddress(&LoadAddress)); + return (success) ? LoadAddress : 0; +} + +void DIASession::setLoadAddress(uint64_t Address) { + Session->put_loadAddress(Address); +} + +std::unique_ptr<PDBSymbolExe> DIASession::getGlobalScope() const { + CComPtr<IDiaSymbol> GlobalScope; + if (S_OK != Session->get_globalScope(&GlobalScope)) + return nullptr; + + auto RawSymbol = llvm::make_unique<DIARawSymbol>(*this, GlobalScope); + auto PdbSymbol(PDBSymbol::create(*this, std::move(RawSymbol))); + std::unique_ptr<PDBSymbolExe> ExeSymbol( + static_cast<PDBSymbolExe *>(PdbSymbol.release())); + return ExeSymbol; +} + +std::unique_ptr<PDBSymbol> DIASession::getSymbolById(uint32_t SymbolId) const { + CComPtr<IDiaSymbol> LocatedSymbol; + if (S_OK != Session->symbolById(SymbolId, &LocatedSymbol)) + return nullptr; + + auto RawSymbol = llvm::make_unique<DIARawSymbol>(*this, LocatedSymbol); + return PDBSymbol::create(*this, std::move(RawSymbol)); +} + +std::unique_ptr<IPDBEnumSourceFiles> DIASession::getAllSourceFiles() const { + CComPtr<IDiaEnumSourceFiles> Files; + if (S_OK != Session->findFile(nullptr, nullptr, nsNone, &Files)) + return nullptr; + + return llvm::make_unique<DIAEnumSourceFiles>(*this, Files); +} + +std::unique_ptr<IPDBEnumSourceFiles> DIASession::getSourceFilesForCompiland( + const PDBSymbolCompiland &Compiland) const { + CComPtr<IDiaEnumSourceFiles> Files; + + const DIARawSymbol &RawSymbol = + static_cast<const DIARawSymbol &>(Compiland.getRawSymbol()); + if (S_OK != + Session->findFile(RawSymbol.getDiaSymbol(), nullptr, nsNone, &Files)) + return nullptr; + + return llvm::make_unique<DIAEnumSourceFiles>(*this, Files); +} + +std::unique_ptr<IPDBSourceFile> +DIASession::getSourceFileById(uint32_t FileId) const { + CComPtr<IDiaSourceFile> LocatedFile; + if (S_OK != Session->findFileById(FileId, &LocatedFile)) + return nullptr; + + return llvm::make_unique<DIASourceFile>(*this, LocatedFile); +} + +std::unique_ptr<IPDBEnumDataStreams> DIASession::getDebugStreams() const { + CComPtr<IDiaEnumDebugStreams> DiaEnumerator; + if (S_OK != Session->getEnumDebugStreams(&DiaEnumerator)) + return nullptr; + + return llvm::make_unique<DIAEnumDebugStreams>(DiaEnumerator); +} diff --git a/lib/DebugInfo/PDB/DIA/DIASourceFile.cpp b/lib/DebugInfo/PDB/DIA/DIASourceFile.cpp new file mode 100644 index 0000000..0a9c444 --- /dev/null +++ b/lib/DebugInfo/PDB/DIA/DIASourceFile.cpp @@ -0,0 +1,67 @@ +//===- DIASourceFile.cpp - DIA implementation of IPDBSourceFile -*- C++ -*-===// +// +// The LLVM Compiler Infrastructure +// +// This file is distributed under the University of Illinois Open Source +// License. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +#include "llvm/DebugInfo/PDB/DIA/DIAEnumSymbols.h" +#include "llvm/DebugInfo/PDB/DIA/DIASession.h" +#include "llvm/DebugInfo/PDB/DIA/DIASourceFile.h" +#include "llvm/Support/ConvertUTF.h" + +using namespace llvm; + +DIASourceFile::DIASourceFile(const DIASession &PDBSession, + CComPtr<IDiaSourceFile> DiaSourceFile) + : Session(PDBSession), SourceFile(DiaSourceFile) {} + +std::string DIASourceFile::getFileName() const { + CComBSTR FileName16; + HRESULT Result = SourceFile->get_fileName(&FileName16); + if (S_OK != Result) + return std::string(); + + std::string FileName8; + llvm::ArrayRef<char> FileNameBytes(reinterpret_cast<char *>(FileName16.m_str), + FileName16.ByteLength()); + llvm::convertUTF16ToUTF8String(FileNameBytes, FileName8); + return FileName8; +} + +uint32_t DIASourceFile::getUniqueId() const { + DWORD Id; + return (S_OK == SourceFile->get_uniqueId(&Id)) ? Id : 0; +} + +std::string DIASourceFile::getChecksum() const { + DWORD ByteSize = 0; + HRESULT Result = SourceFile->get_checksum(0, &ByteSize, nullptr); + if (ByteSize == 0) + return std::string(); + std::vector<BYTE> ChecksumBytes(ByteSize); + Result = SourceFile->get_checksum(ByteSize, &ByteSize, &ChecksumBytes[0]); + if (S_OK != Result) + return std::string(); + return std::string(ChecksumBytes.begin(), ChecksumBytes.end()); +} + +PDB_Checksum DIASourceFile::getChecksumType() const { + DWORD Type; + HRESULT Result = SourceFile->get_checksumType(&Type); + if (S_OK != Result) + return PDB_Checksum::None; + return static_cast<PDB_Checksum>(Type); +} + +std::unique_ptr<IPDBEnumSymbols> DIASourceFile::getCompilands() const { + CComPtr<IDiaEnumSymbols> DiaEnumerator; + HRESULT Result = SourceFile->get_compilands(&DiaEnumerator); + if (S_OK != Result) + return nullptr; + + return std::unique_ptr<IPDBEnumSymbols>( + new DIAEnumSymbols(Session, DiaEnumerator)); +} diff --git a/lib/DebugInfo/PDB/IPDBSourceFile.cpp b/lib/DebugInfo/PDB/IPDBSourceFile.cpp new file mode 100644 index 0000000..3abe59d --- /dev/null +++ b/lib/DebugInfo/PDB/IPDBSourceFile.cpp @@ -0,0 +1,32 @@ +//===- IPDBSourceFile.cpp - base interface for a PDB source file *- C++ -*-===// +// +// The LLVM Compiler Infrastructure +// +// This file is distributed under the University of Illinois Open Source +// License. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +#include "llvm/DebugInfo/PDB/IPDBSourceFile.h" + +#include "llvm/DebugInfo/PDB/PDBExtras.h" +#include "llvm/Support/Format.h" +#include "llvm/Support/raw_ostream.h" + +using namespace llvm; + +IPDBSourceFile::~IPDBSourceFile() {} + +void IPDBSourceFile::dump(raw_ostream &OS, int Indent) const { + OS.indent(Indent); + PDB_Checksum ChecksumType = getChecksumType(); + OS << "["; + if (ChecksumType != PDB_Checksum::None) { + OS << ChecksumType << ": "; + std::string Checksum = getChecksum(); + for (uint8_t c : Checksum) + OS << format_hex_no_prefix(c, 2, true); + } else + OS << "No checksum"; + OS << "] " << getFileName() << "\n"; +} diff --git a/lib/DebugInfo/PDB/LLVMBuild.txt b/lib/DebugInfo/PDB/LLVMBuild.txt new file mode 100644 index 0000000..690598a --- /dev/null +++ b/lib/DebugInfo/PDB/LLVMBuild.txt @@ -0,0 +1,23 @@ +;===- ./lib/DebugInfo/PDB/LLVMBuild.txt ------------------------*- Conf -*--===; +; +; The LLVM Compiler Infrastructure +; +; This file is distributed under the University of Illinois Open Source +; License. See LICENSE.TXT for details. +; +;===------------------------------------------------------------------------===; +; +; This is an LLVMBuild description file for the components in this subdirectory. +; +; For more information on the LLVMBuild system, please see: +; +; http://llvm.org/docs/LLVMBuild.html +; +;===------------------------------------------------------------------------===; + +[component_0] +type = Library +name = DebugInfoPDB +parent = DebugInfo +required_libraries = Support + diff --git a/lib/DebugInfo/PDB/Makefile b/lib/DebugInfo/PDB/Makefile new file mode 100644 index 0000000..444019e --- /dev/null +++ b/lib/DebugInfo/PDB/Makefile @@ -0,0 +1,14 @@ +##===- lib/DebugInfo/PDB/Makefile --------------------------*- Makefile -*-===## +# +# The LLVM Compiler Infrastructure +# +# This file is distributed under the University of Illinois Open Source +# License. See LICENSE.TXT for details. +# +##===----------------------------------------------------------------------===## + +LEVEL = ../../.. +LIBRARYNAME = LLVMDebugInfoPDB +BUILD_ARCHIVE := 1 + +include $(LEVEL)/Makefile.common diff --git a/lib/DebugInfo/PDB/PDB.cpp b/lib/DebugInfo/PDB/PDB.cpp new file mode 100644 index 0000000..aa84c28 --- /dev/null +++ b/lib/DebugInfo/PDB/PDB.cpp @@ -0,0 +1,30 @@ +//===- PDB.cpp - base header file for creating a PDB reader -----*- C++ -*-===// +// +// The LLVM Compiler Infrastructure +// +// This file is distributed under the University of Illinois Open Source +// License. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +#include "llvm/DebugInfo/PDB/PDB.h" + +#include "llvm/ADT/StringRef.h" +#include "llvm/Config/config.h" +#include "llvm/DebugInfo/PDB/IPDBSession.h" +#include "llvm/DebugInfo/PDB/PDB.h" + +#if HAVE_DIA_SDK +#include "llvm/DebugInfo/PDB/DIA/DIASession.h" +#endif + +using namespace llvm; + +std::unique_ptr<IPDBSession> llvm::createPDBReader(PDB_ReaderType Type, + StringRef Path) { + // Create the correct concrete instance type based on the value of Type. +#if HAVE_DIA_SDK + return std::unique_ptr<DIASession>(DIASession::createFromPdb(Path)); +#endif + return nullptr; +} diff --git a/lib/DebugInfo/PDB/PDBExtras.cpp b/lib/DebugInfo/PDB/PDBExtras.cpp new file mode 100644 index 0000000..1002b2e --- /dev/null +++ b/lib/DebugInfo/PDB/PDBExtras.cpp @@ -0,0 +1,346 @@ +//===- PDBExtras.cpp - helper functions and classes for PDBs -----*- C++-*-===// +// +// The LLVM Compiler Infrastructure +// +// This file is distributed under the University of Illinois Open Source +// License. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +#include "llvm/DebugInfo/PDB/PDBExtras.h" + +#include "llvm/ADT/ArrayRef.h" + +using namespace llvm; + +#define CASE_OUTPUT_ENUM_CLASS_STR(Class, Value, Str, Stream) \ + case Class::Value: \ + Stream << Str; \ + break; + +#define CASE_OUTPUT_ENUM_CLASS_NAME(Class, Value, Stream) \ + CASE_OUTPUT_ENUM_CLASS_STR(Class, Value, #Value, Stream) + +raw_ostream &llvm::operator<<(raw_ostream &OS, const PDB_VariantType &Type) { + switch (Type) { + CASE_OUTPUT_ENUM_CLASS_NAME(PDB_VariantType, Bool, OS) + CASE_OUTPUT_ENUM_CLASS_NAME(PDB_VariantType, Single, OS) + CASE_OUTPUT_ENUM_CLASS_NAME(PDB_VariantType, Double, OS) + CASE_OUTPUT_ENUM_CLASS_NAME(PDB_VariantType, Int8, OS) + CASE_OUTPUT_ENUM_CLASS_NAME(PDB_VariantType, Int16, OS) + CASE_OUTPUT_ENUM_CLASS_NAME(PDB_VariantType, Int32, OS) + CASE_OUTPUT_ENUM_CLASS_NAME(PDB_VariantType, Int64, OS) + CASE_OUTPUT_ENUM_CLASS_NAME(PDB_VariantType, UInt8, OS) + CASE_OUTPUT_ENUM_CLASS_NAME(PDB_VariantType, UInt16, OS) + CASE_OUTPUT_ENUM_CLASS_NAME(PDB_VariantType, UInt32, OS) + CASE_OUTPUT_ENUM_CLASS_NAME(PDB_VariantType, UInt64, OS) + default: + OS << "Unknown"; + } + return OS; +} + +raw_ostream &llvm::operator<<(raw_ostream &OS, const PDB_CallingConv &Conv) { + OS << "__"; + switch (Conv) { + CASE_OUTPUT_ENUM_CLASS_STR(PDB_CallingConv, NearCdecl, "cdecl", OS) + CASE_OUTPUT_ENUM_CLASS_STR(PDB_CallingConv, FarCdecl, "cdecl", OS) + CASE_OUTPUT_ENUM_CLASS_STR(PDB_CallingConv, NearPascal, "pascal", OS) + CASE_OUTPUT_ENUM_CLASS_STR(PDB_CallingConv, FarPascal, "pascal", OS) + CASE_OUTPUT_ENUM_CLASS_STR(PDB_CallingConv, NearFastcall, "fastcall", OS) + CASE_OUTPUT_ENUM_CLASS_STR(PDB_CallingConv, FarFastcall, "fastcall", OS) + CASE_OUTPUT_ENUM_CLASS_STR(PDB_CallingConv, Skipped, "skippedcall", OS) + CASE_OUTPUT_ENUM_CLASS_STR(PDB_CallingConv, NearStdcall, "stdcall", OS) + CASE_OUTPUT_ENUM_CLASS_STR(PDB_CallingConv, FarStdcall, "stdcall", OS) + CASE_OUTPUT_ENUM_CLASS_STR(PDB_CallingConv, NearSyscall, "syscall", OS) + CASE_OUTPUT_ENUM_CLASS_STR(PDB_CallingConv, FarSyscall, "syscall", OS) + CASE_OUTPUT_ENUM_CLASS_STR(PDB_CallingConv, Thiscall, "thiscall", OS) + CASE_OUTPUT_ENUM_CLASS_STR(PDB_CallingConv, MipsCall, "mipscall", OS) + CASE_OUTPUT_ENUM_CLASS_STR(PDB_CallingConv, Generic, "genericcall", OS) + CASE_OUTPUT_ENUM_CLASS_STR(PDB_CallingConv, Alphacall, "alphacall", OS) + CASE_OUTPUT_ENUM_CLASS_STR(PDB_CallingConv, Ppccall, "ppccall", OS) + CASE_OUTPUT_ENUM_CLASS_STR(PDB_CallingConv, SuperHCall, "superhcall", OS) + CASE_OUTPUT_ENUM_CLASS_STR(PDB_CallingConv, Armcall, "armcall", OS) + CASE_OUTPUT_ENUM_CLASS_STR(PDB_CallingConv, AM33call, "am33call", OS) + CASE_OUTPUT_ENUM_CLASS_STR(PDB_CallingConv, Tricall, "tricall", OS) + CASE_OUTPUT_ENUM_CLASS_STR(PDB_CallingConv, Sh5call, "sh5call", OS) + CASE_OUTPUT_ENUM_CLASS_STR(PDB_CallingConv, M32R, "m32rcall", OS) + CASE_OUTPUT_ENUM_CLASS_STR(PDB_CallingConv, Clrcall, "clrcall", OS) + CASE_OUTPUT_ENUM_CLASS_STR(PDB_CallingConv, Inline, "inlinecall", OS) + CASE_OUTPUT_ENUM_CLASS_STR(PDB_CallingConv, NearVectorcall, "vectorcall", + OS) + default: + OS << "unknowncall"; + } + return OS; +} + +raw_ostream &llvm::operator<<(raw_ostream &OS, const PDB_DataKind &Data) { + switch (Data) { + CASE_OUTPUT_ENUM_CLASS_STR(PDB_DataKind, Unknown, "unknown", OS) + CASE_OUTPUT_ENUM_CLASS_STR(PDB_DataKind, Local, "local", OS) + CASE_OUTPUT_ENUM_CLASS_STR(PDB_DataKind, StaticLocal, "static local", OS) + CASE_OUTPUT_ENUM_CLASS_STR(PDB_DataKind, Param, "param", OS) + CASE_OUTPUT_ENUM_CLASS_STR(PDB_DataKind, ObjectPtr, "this ptr", OS) + CASE_OUTPUT_ENUM_CLASS_STR(PDB_DataKind, FileStatic, "static global", OS) + CASE_OUTPUT_ENUM_CLASS_STR(PDB_DataKind, Global, "global", OS) + CASE_OUTPUT_ENUM_CLASS_STR(PDB_DataKind, Member, "member", OS) + CASE_OUTPUT_ENUM_CLASS_STR(PDB_DataKind, StaticMember, "static member", OS) + CASE_OUTPUT_ENUM_CLASS_STR(PDB_DataKind, Constant, "const", OS) + } + return OS; +} + +raw_ostream &llvm::operator<<(raw_ostream &OS, const PDB_RegisterId &Reg) { + switch (Reg) { + CASE_OUTPUT_ENUM_CLASS_NAME(PDB_RegisterId, AL, OS) + CASE_OUTPUT_ENUM_CLASS_NAME(PDB_RegisterId, CL, OS) + CASE_OUTPUT_ENUM_CLASS_NAME(PDB_RegisterId, DL, OS) + CASE_OUTPUT_ENUM_CLASS_NAME(PDB_RegisterId, BL, OS) + CASE_OUTPUT_ENUM_CLASS_NAME(PDB_RegisterId, AH, OS) + CASE_OUTPUT_ENUM_CLASS_NAME(PDB_RegisterId, CH, OS) + CASE_OUTPUT_ENUM_CLASS_NAME(PDB_RegisterId, DH, OS) + CASE_OUTPUT_ENUM_CLASS_NAME(PDB_RegisterId, BH, OS) + CASE_OUTPUT_ENUM_CLASS_NAME(PDB_RegisterId, AX, OS) + CASE_OUTPUT_ENUM_CLASS_NAME(PDB_RegisterId, CX, OS) + CASE_OUTPUT_ENUM_CLASS_NAME(PDB_RegisterId, DX, OS) + CASE_OUTPUT_ENUM_CLASS_NAME(PDB_RegisterId, BX, OS) + CASE_OUTPUT_ENUM_CLASS_NAME(PDB_RegisterId, SP, OS) + CASE_OUTPUT_ENUM_CLASS_NAME(PDB_RegisterId, BP, OS) + CASE_OUTPUT_ENUM_CLASS_NAME(PDB_RegisterId, SI, OS) + CASE_OUTPUT_ENUM_CLASS_NAME(PDB_RegisterId, DI, OS) + CASE_OUTPUT_ENUM_CLASS_NAME(PDB_RegisterId, EAX, OS) + CASE_OUTPUT_ENUM_CLASS_NAME(PDB_RegisterId, ECX, OS) + CASE_OUTPUT_ENUM_CLASS_NAME(PDB_RegisterId, EDX, OS) + CASE_OUTPUT_ENUM_CLASS_NAME(PDB_RegisterId, EBX, OS) + CASE_OUTPUT_ENUM_CLASS_NAME(PDB_RegisterId, ESP, OS) + CASE_OUTPUT_ENUM_CLASS_NAME(PDB_RegisterId, EBP, OS) + CASE_OUTPUT_ENUM_CLASS_NAME(PDB_RegisterId, ESI, OS) + CASE_OUTPUT_ENUM_CLASS_NAME(PDB_RegisterId, EDI, OS) + CASE_OUTPUT_ENUM_CLASS_NAME(PDB_RegisterId, ES, OS) + CASE_OUTPUT_ENUM_CLASS_NAME(PDB_RegisterId, CS, OS) + CASE_OUTPUT_ENUM_CLASS_NAME(PDB_RegisterId, SS, OS) + CASE_OUTPUT_ENUM_CLASS_NAME(PDB_RegisterId, DS, OS) + CASE_OUTPUT_ENUM_CLASS_NAME(PDB_RegisterId, FS, OS) + CASE_OUTPUT_ENUM_CLASS_NAME(PDB_RegisterId, GS, OS) + CASE_OUTPUT_ENUM_CLASS_NAME(PDB_RegisterId, IP, OS) + CASE_OUTPUT_ENUM_CLASS_NAME(PDB_RegisterId, RAX, OS) + CASE_OUTPUT_ENUM_CLASS_NAME(PDB_RegisterId, RBX, OS) + CASE_OUTPUT_ENUM_CLASS_NAME(PDB_RegisterId, RCX, OS) + CASE_OUTPUT_ENUM_CLASS_NAME(PDB_RegisterId, RDX, OS) + CASE_OUTPUT_ENUM_CLASS_NAME(PDB_RegisterId, RSI, OS) + CASE_OUTPUT_ENUM_CLASS_NAME(PDB_RegisterId, RDI, OS) + CASE_OUTPUT_ENUM_CLASS_NAME(PDB_RegisterId, RBP, OS) + CASE_OUTPUT_ENUM_CLASS_NAME(PDB_RegisterId, RSP, OS) + CASE_OUTPUT_ENUM_CLASS_NAME(PDB_RegisterId, R8, OS) + CASE_OUTPUT_ENUM_CLASS_NAME(PDB_RegisterId, R9, OS) + CASE_OUTPUT_ENUM_CLASS_NAME(PDB_RegisterId, R10, OS) + CASE_OUTPUT_ENUM_CLASS_NAME(PDB_RegisterId, R11, OS) + CASE_OUTPUT_ENUM_CLASS_NAME(PDB_RegisterId, R12, OS) + CASE_OUTPUT_ENUM_CLASS_NAME(PDB_RegisterId, R13, OS) + CASE_OUTPUT_ENUM_CLASS_NAME(PDB_RegisterId, R14, OS) + CASE_OUTPUT_ENUM_CLASS_NAME(PDB_RegisterId, R15, OS) + default: + OS << static_cast<int>(Reg); + } + return OS; +} + +raw_ostream &llvm::operator<<(raw_ostream &OS, const PDB_LocType &Loc) { + switch (Loc) { + CASE_OUTPUT_ENUM_CLASS_STR(PDB_LocType, Static, "static", OS) + CASE_OUTPUT_ENUM_CLASS_STR(PDB_LocType, TLS, "tls", OS) + CASE_OUTPUT_ENUM_CLASS_STR(PDB_LocType, RegRel, "regrel", OS) + CASE_OUTPUT_ENUM_CLASS_STR(PDB_LocType, ThisRel, "thisrel", OS) + CASE_OUTPUT_ENUM_CLASS_STR(PDB_LocType, Enregistered, "register", OS) + CASE_OUTPUT_ENUM_CLASS_STR(PDB_LocType, BitField, "bitfield", OS) + CASE_OUTPUT_ENUM_CLASS_STR(PDB_LocType, Slot, "slot", OS) + CASE_OUTPUT_ENUM_CLASS_STR(PDB_LocType, IlRel, "IL rel", OS) + CASE_OUTPUT_ENUM_CLASS_STR(PDB_LocType, MetaData, "metadata", OS) + CASE_OUTPUT_ENUM_CLASS_STR(PDB_LocType, Constant, "constant", OS) + default: + OS << "Unknown"; + } + return OS; +} + +raw_ostream &llvm::operator<<(raw_ostream &OS, const PDB_ThunkOrdinal &Thunk) { + switch (Thunk) { + CASE_OUTPUT_ENUM_CLASS_NAME(PDB_ThunkOrdinal, BranchIsland, OS) + CASE_OUTPUT_ENUM_CLASS_NAME(PDB_ThunkOrdinal, Pcode, OS) + CASE_OUTPUT_ENUM_CLASS_NAME(PDB_ThunkOrdinal, Standard, OS) + CASE_OUTPUT_ENUM_CLASS_NAME(PDB_ThunkOrdinal, ThisAdjustor, OS) + CASE_OUTPUT_ENUM_CLASS_NAME(PDB_ThunkOrdinal, TrampIncremental, OS) + CASE_OUTPUT_ENUM_CLASS_NAME(PDB_ThunkOrdinal, UnknownLoad, OS) + CASE_OUTPUT_ENUM_CLASS_NAME(PDB_ThunkOrdinal, Vcall, OS) + } + return OS; +} + +raw_ostream &llvm::operator<<(raw_ostream &OS, const PDB_Checksum &Checksum) { + switch (Checksum) { + CASE_OUTPUT_ENUM_CLASS_NAME(PDB_Checksum, None, OS) + CASE_OUTPUT_ENUM_CLASS_NAME(PDB_Checksum, MD5, OS) + CASE_OUTPUT_ENUM_CLASS_NAME(PDB_Checksum, SHA1, OS) + } + return OS; +} + +raw_ostream &llvm::operator<<(raw_ostream &OS, const PDB_Lang &Lang) { + switch (Lang) { + CASE_OUTPUT_ENUM_CLASS_NAME(PDB_Lang, C, OS) + CASE_OUTPUT_ENUM_CLASS_STR(PDB_Lang, Cpp, "C++", OS) + CASE_OUTPUT_ENUM_CLASS_NAME(PDB_Lang, Fortran, OS) + CASE_OUTPUT_ENUM_CLASS_NAME(PDB_Lang, Masm, OS) + CASE_OUTPUT_ENUM_CLASS_NAME(PDB_Lang, Pascal, OS) + CASE_OUTPUT_ENUM_CLASS_NAME(PDB_Lang, Basic, OS) + CASE_OUTPUT_ENUM_CLASS_NAME(PDB_Lang, Cobol, OS) + CASE_OUTPUT_ENUM_CLASS_NAME(PDB_Lang, Link, OS) + CASE_OUTPUT_ENUM_CLASS_NAME(PDB_Lang, Cvtres, OS) + CASE_OUTPUT_ENUM_CLASS_NAME(PDB_Lang, Cvtpgd, OS) + CASE_OUTPUT_ENUM_CLASS_NAME(PDB_Lang, CSharp, OS) + CASE_OUTPUT_ENUM_CLASS_NAME(PDB_Lang, VB, OS) + CASE_OUTPUT_ENUM_CLASS_NAME(PDB_Lang, ILAsm, OS) + CASE_OUTPUT_ENUM_CLASS_NAME(PDB_Lang, Java, OS) + CASE_OUTPUT_ENUM_CLASS_NAME(PDB_Lang, JScript, OS) + CASE_OUTPUT_ENUM_CLASS_NAME(PDB_Lang, MSIL, OS) + CASE_OUTPUT_ENUM_CLASS_NAME(PDB_Lang, HLSL, OS) + } + return OS; +} + +raw_ostream &llvm::operator<<(raw_ostream &OS, const PDB_SymType &Tag) { + switch (Tag) { + CASE_OUTPUT_ENUM_CLASS_NAME(PDB_SymType, Exe, OS) + CASE_OUTPUT_ENUM_CLASS_NAME(PDB_SymType, Compiland, OS) + CASE_OUTPUT_ENUM_CLASS_NAME(PDB_SymType, CompilandDetails, OS) + CASE_OUTPUT_ENUM_CLASS_NAME(PDB_SymType, CompilandEnv, OS) + CASE_OUTPUT_ENUM_CLASS_NAME(PDB_SymType, Function, OS) + CASE_OUTPUT_ENUM_CLASS_NAME(PDB_SymType, Block, OS) + CASE_OUTPUT_ENUM_CLASS_NAME(PDB_SymType, Data, OS) + CASE_OUTPUT_ENUM_CLASS_NAME(PDB_SymType, Annotation, OS) + CASE_OUTPUT_ENUM_CLASS_NAME(PDB_SymType, Label, OS) + CASE_OUTPUT_ENUM_CLASS_NAME(PDB_SymType, PublicSymbol, OS) + CASE_OUTPUT_ENUM_CLASS_NAME(PDB_SymType, UDT, OS) + CASE_OUTPUT_ENUM_CLASS_NAME(PDB_SymType, Enum, OS) + CASE_OUTPUT_ENUM_CLASS_NAME(PDB_SymType, FunctionSig, OS) + CASE_OUTPUT_ENUM_CLASS_NAME(PDB_SymType, PointerType, OS) + CASE_OUTPUT_ENUM_CLASS_NAME(PDB_SymType, ArrayType, OS) + CASE_OUTPUT_ENUM_CLASS_NAME(PDB_SymType, BuiltinType, OS) + CASE_OUTPUT_ENUM_CLASS_NAME(PDB_SymType, Typedef, OS) + CASE_OUTPUT_ENUM_CLASS_NAME(PDB_SymType, BaseClass, OS) + CASE_OUTPUT_ENUM_CLASS_NAME(PDB_SymType, Friend, OS) + CASE_OUTPUT_ENUM_CLASS_NAME(PDB_SymType, FunctionArg, OS) + CASE_OUTPUT_ENUM_CLASS_NAME(PDB_SymType, FuncDebugStart, OS) + CASE_OUTPUT_ENUM_CLASS_NAME(PDB_SymType, FuncDebugEnd, OS) + CASE_OUTPUT_ENUM_CLASS_NAME(PDB_SymType, UsingNamespace, OS) + CASE_OUTPUT_ENUM_CLASS_NAME(PDB_SymType, VTableShape, OS) + CASE_OUTPUT_ENUM_CLASS_NAME(PDB_SymType, VTable, OS) + CASE_OUTPUT_ENUM_CLASS_NAME(PDB_SymType, Custom, OS) + CASE_OUTPUT_ENUM_CLASS_NAME(PDB_SymType, Thunk, OS) + CASE_OUTPUT_ENUM_CLASS_NAME(PDB_SymType, CustomType, OS) + CASE_OUTPUT_ENUM_CLASS_NAME(PDB_SymType, ManagedType, OS) + CASE_OUTPUT_ENUM_CLASS_NAME(PDB_SymType, Dimension, OS) + default: + OS << "Unknown"; + } + return OS; +} + +raw_ostream &llvm::operator<<(raw_ostream &OS, const PDB_BuiltinType &Type) { + switch (Type) { + CASE_OUTPUT_ENUM_CLASS_STR(PDB_BuiltinType, Void, "void", OS) + CASE_OUTPUT_ENUM_CLASS_STR(PDB_BuiltinType, Char, "char", OS) + CASE_OUTPUT_ENUM_CLASS_STR(PDB_BuiltinType, WCharT, "wchar_t", OS) + CASE_OUTPUT_ENUM_CLASS_STR(PDB_BuiltinType, Int, "int", OS) + CASE_OUTPUT_ENUM_CLASS_STR(PDB_BuiltinType, UInt, "uint", OS) + CASE_OUTPUT_ENUM_CLASS_STR(PDB_BuiltinType, Float, "float", OS) + CASE_OUTPUT_ENUM_CLASS_STR(PDB_BuiltinType, BCD, "BCD", OS) + CASE_OUTPUT_ENUM_CLASS_STR(PDB_BuiltinType, Bool, "bool", OS) + CASE_OUTPUT_ENUM_CLASS_STR(PDB_BuiltinType, Long, "long", OS) + CASE_OUTPUT_ENUM_CLASS_STR(PDB_BuiltinType, ULong, "ulong", OS) + CASE_OUTPUT_ENUM_CLASS_STR(PDB_BuiltinType, Currency, "CURRENCY", OS) + CASE_OUTPUT_ENUM_CLASS_STR(PDB_BuiltinType, Date, "DATE", OS) + CASE_OUTPUT_ENUM_CLASS_STR(PDB_BuiltinType, Variant, "VARIANT", OS) + CASE_OUTPUT_ENUM_CLASS_STR(PDB_BuiltinType, Complex, "complex", OS) + CASE_OUTPUT_ENUM_CLASS_STR(PDB_BuiltinType, Bitfield, "bitfield", OS) + CASE_OUTPUT_ENUM_CLASS_STR(PDB_BuiltinType, BSTR, "BSTR", OS) + CASE_OUTPUT_ENUM_CLASS_STR(PDB_BuiltinType, HResult, "HRESULT", OS) + default: + break; + } + return OS; +} + +raw_ostream &llvm::operator<<(raw_ostream &OS, const PDB_UniqueId &Id) { + static const char *Lookup = "0123456789ABCDEF"; + + static_assert(sizeof(PDB_UniqueId) == 16, "Expected 16-byte GUID"); + ArrayRef<uint8_t> GuidBytes(reinterpret_cast<const uint8_t*>(&Id), 16); + OS << "{"; + for (int i=0; i < 16;) { + uint8_t Byte = GuidBytes[i]; + uint8_t HighNibble = (Byte >> 4) & 0xF; + uint8_t LowNibble = Byte & 0xF; + OS << Lookup[HighNibble] << Lookup[LowNibble]; + ++i; + if (i>=4 && i<=10 && i%2==0) + OS << "-"; + } + OS << "}"; + return OS; +} + +raw_ostream &llvm::operator<<(raw_ostream &OS, const Variant &Value) { + switch (Value.Type) { + case PDB_VariantType::Bool: + OS << (Value.Bool ? "true" : "false"); + break; + case PDB_VariantType::Double: + OS << Value.Double; + break; + case PDB_VariantType::Int16: + OS << Value.Int16; + break; + case PDB_VariantType::Int32: + OS << Value.Int32; + break; + case PDB_VariantType::Int64: + OS << Value.Int64; + break; + case PDB_VariantType::Int8: + OS << Value.Int8; + break; + case PDB_VariantType::Single: + OS << Value.Single; + break; + case PDB_VariantType::UInt16: + OS << Value.Double; + break; + case PDB_VariantType::UInt32: + OS << Value.UInt32; + break; + case PDB_VariantType::UInt64: + OS << Value.UInt64; + break; + case PDB_VariantType::UInt8: + OS << Value.UInt8; + break; + default: + OS << Value.Type; + } + OS << " {" << Value.Type << "}"; + return OS; +} + +raw_ostream &llvm::operator<<(raw_ostream &OS, const VersionInfo &Version) { + OS << Version.Major << "." << Version.Minor << "." << Version.Build; + return OS; +} + +raw_ostream &llvm::operator<<(raw_ostream &OS, const TagStats &Stats) { + for (auto Tag : Stats) { + OS << Tag.first << ":" << Tag.second << " "; + } + return OS; +} diff --git a/lib/DebugInfo/PDB/PDBInterfaceAnchors.cpp b/lib/DebugInfo/PDB/PDBInterfaceAnchors.cpp new file mode 100644 index 0000000..7b6268d --- /dev/null +++ b/lib/DebugInfo/PDB/PDBInterfaceAnchors.cpp @@ -0,0 +1,28 @@ +//===- PDBInterfaceAnchors.h - defines class anchor funcions ----*- C++ -*-===// +// +// The LLVM Compiler Infrastructure +// +// This file is distributed under the University of Illinois Open Source +// License. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// +// Class anchors are necessary per the LLVM Coding style guide, to ensure that +// the vtable is only generated in this object file, and not in every object +// file that incldues the corresponding header. +//===----------------------------------------------------------------------===// + +#include "llvm/DebugInfo/PDB/IPDBDataStream.h" +#include "llvm/DebugInfo/PDB/IPDBLineNumber.h" +#include "llvm/DebugInfo/PDB/IPDBRawSymbol.h" +#include "llvm/DebugInfo/PDB/IPDBSession.h" +#include "llvm/DebugInfo/PDB/IPDBRawSymbol.h" + +using namespace llvm; + +IPDBSession::~IPDBSession() {} + +IPDBDataStream::~IPDBDataStream() {} + +IPDBRawSymbol::~IPDBRawSymbol() {} + +IPDBLineNumber::~IPDBLineNumber() {} diff --git a/lib/DebugInfo/PDB/PDBSymDumper.cpp b/lib/DebugInfo/PDB/PDBSymDumper.cpp new file mode 100644 index 0000000..0f29c74 --- /dev/null +++ b/lib/DebugInfo/PDB/PDBSymDumper.cpp @@ -0,0 +1,177 @@ +//===- PDBSymDumper.cpp - ---------------------------------------*- C++ -*-===// +// +// The LLVM Compiler Infrastructure +// +// This file is distributed under the University of Illinois Open Source +// License. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +#include "llvm/DebugInfo/PDB/PDBSymDumper.h" +#include "llvm/Support/ErrorHandling.h" + +using namespace llvm; + +#define PDB_SYMDUMP_UNREACHABLE(Type) \ + if (RequireImpl) \ + llvm_unreachable("Attempt to dump " #Type " with no dump implementation"); + +PDBSymDumper::PDBSymDumper(bool ShouldRequireImpl) + : RequireImpl(ShouldRequireImpl) {} + +PDBSymDumper::~PDBSymDumper() {} + +void PDBSymDumper::dump(const PDBSymbolAnnotation &Symbol, raw_ostream &OS, + int Indent) { + PDB_SYMDUMP_UNREACHABLE(PDBSymbolAnnotation) +} + +void PDBSymDumper::dump(const PDBSymbolBlock &Symbol, raw_ostream &OS, + int Indent) { + PDB_SYMDUMP_UNREACHABLE(PDBSymbolBlock) +} + +void PDBSymDumper::dump(const PDBSymbolCompiland &Symbol, raw_ostream &OS, + int Indent) { + PDB_SYMDUMP_UNREACHABLE(PDBSymbolCompiland) +} + +void PDBSymDumper::dump(const PDBSymbolCompilandDetails &Symbol, + raw_ostream &OS, int Indent) { + PDB_SYMDUMP_UNREACHABLE(PDBSymbolCompilandDetails) +} + +void PDBSymDumper::dump(const PDBSymbolCompilandEnv &Symbol, raw_ostream &OS, + int Indent) { + PDB_SYMDUMP_UNREACHABLE(PDBSymbolCompilandEnv) +} + +void PDBSymDumper::dump(const PDBSymbolCustom &Symbol, raw_ostream &OS, + int Indent) { + PDB_SYMDUMP_UNREACHABLE(PDBSymbolCustom) +} + +void PDBSymDumper::dump(const PDBSymbolData &Symbol, raw_ostream &OS, + int Indent) { + PDB_SYMDUMP_UNREACHABLE(PDBSymbolData) +} + +void PDBSymDumper::dump(const PDBSymbolExe &Symbol, raw_ostream &OS, + int Indent) { + PDB_SYMDUMP_UNREACHABLE(PDBSymbolExe) +} + +void PDBSymDumper::dump(const PDBSymbolFunc &Symbol, raw_ostream &OS, + int Indent) { + PDB_SYMDUMP_UNREACHABLE(PDBSymbolFunc) +} + +void PDBSymDumper::dump(const PDBSymbolFuncDebugEnd &Symbol, raw_ostream &OS, + int Indent) { + PDB_SYMDUMP_UNREACHABLE(PDBSymbolFuncDebugEnd) +} + +void PDBSymDumper::dump(const PDBSymbolFuncDebugStart &Symbol, raw_ostream &OS, + int Indent) { + PDB_SYMDUMP_UNREACHABLE(PDBSymbolFuncDebugStart) +} + +void PDBSymDumper::dump(const PDBSymbolLabel &Symbol, raw_ostream &OS, + int Indent) { + PDB_SYMDUMP_UNREACHABLE(PDBSymbolLabel) +} + +void PDBSymDumper::dump(const PDBSymbolPublicSymbol &Symbol, raw_ostream &OS, + int Indent) { + PDB_SYMDUMP_UNREACHABLE(PDBSymbolPublicSymbol) +} + +void PDBSymDumper::dump(const PDBSymbolThunk &Symbol, raw_ostream &OS, + int Indent) { + PDB_SYMDUMP_UNREACHABLE(PDBSymbolThunk) +} + +void PDBSymDumper::dump(const PDBSymbolTypeArray &Symbol, raw_ostream &OS, + int Indent) { + PDB_SYMDUMP_UNREACHABLE(PDBSymbolTypeArray) +} + +void PDBSymDumper::dump(const PDBSymbolTypeBaseClass &Symbol, raw_ostream &OS, + int Indent) { + PDB_SYMDUMP_UNREACHABLE(PDBSymbolTypeBaseClass) +} + +void PDBSymDumper::dump(const PDBSymbolTypeBuiltin &Symbol, raw_ostream &OS, + int Indent) { + PDB_SYMDUMP_UNREACHABLE(PDBSymbolTypeBuiltin) +} + +void PDBSymDumper::dump(const PDBSymbolTypeCustom &Symbol, raw_ostream &OS, + int Indent) { + PDB_SYMDUMP_UNREACHABLE(PDBSymbolTypeCustom) +} + +void PDBSymDumper::dump(const PDBSymbolTypeDimension &Symbol, raw_ostream &OS, + int Indent) { + PDB_SYMDUMP_UNREACHABLE(PDBSymbolTypeDimension) +} + +void PDBSymDumper::dump(const PDBSymbolTypeEnum &Symbol, raw_ostream &OS, + int Indent) { + PDB_SYMDUMP_UNREACHABLE(PDBSymbolTypeEnum) +} + +void PDBSymDumper::dump(const PDBSymbolTypeFriend &Symbol, raw_ostream &OS, + int Indent) { + PDB_SYMDUMP_UNREACHABLE(PDBSymbolTypeFriend) +} + +void PDBSymDumper::dump(const PDBSymbolTypeFunctionArg &Symbol, raw_ostream &OS, + int Indent) { + PDB_SYMDUMP_UNREACHABLE(PDBSymbolTypeFunctionArg) +} + +void PDBSymDumper::dump(const PDBSymbolTypeFunctionSig &Symbol, raw_ostream &OS, + int Indent) { + PDB_SYMDUMP_UNREACHABLE(PDBSymbolTypeFunctionSig) +} + +void PDBSymDumper::dump(const PDBSymbolTypeManaged &Symbol, raw_ostream &OS, + int Indent) { + PDB_SYMDUMP_UNREACHABLE(PDBSymbolTypeManaged) +} + +void PDBSymDumper::dump(const PDBSymbolTypePointer &Symbol, raw_ostream &OS, + int Indent) { + PDB_SYMDUMP_UNREACHABLE(PDBSymbolTypePointer) +} + +void PDBSymDumper::dump(const PDBSymbolTypeTypedef &Symbol, raw_ostream &OS, + int Indent) { + PDB_SYMDUMP_UNREACHABLE(PDBSymbolTypeTypedef) +} + +void PDBSymDumper::dump(const PDBSymbolTypeUDT &Symbol, raw_ostream &OS, + int Indent) { + PDB_SYMDUMP_UNREACHABLE(PDBSymbolTypeUDT) +} + +void PDBSymDumper::dump(const PDBSymbolTypeVTable &Symbol, raw_ostream &OS, + int Indent) { + PDB_SYMDUMP_UNREACHABLE(PDBSymbolTypeVTable) +} + +void PDBSymDumper::dump(const PDBSymbolTypeVTableShape &Symbol, raw_ostream &OS, + int Indent) { + PDB_SYMDUMP_UNREACHABLE(PDBSymbolTypeVTableShape) +} + +void PDBSymDumper::dump(const PDBSymbolUnknown &Symbol, raw_ostream &OS, + int Indent) { + PDB_SYMDUMP_UNREACHABLE(PDBSymbolUnknown) +} + +void PDBSymDumper::dump(const PDBSymbolUsingNamespace &Symbol, raw_ostream &OS, + int Indent) { + PDB_SYMDUMP_UNREACHABLE(PDBSymbolUsingNamespace) +} diff --git a/lib/DebugInfo/PDB/PDBSymbol.cpp b/lib/DebugInfo/PDB/PDBSymbol.cpp new file mode 100644 index 0000000..f9aaf3a --- /dev/null +++ b/lib/DebugInfo/PDB/PDBSymbol.cpp @@ -0,0 +1,151 @@ +//===- PDBSymbol.cpp - base class for user-facing symbol types --*- C++ -*-===// +// +// The LLVM Compiler Infrastructure +// +// This file is distributed under the University of Illinois Open Source +// License. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +#include "llvm/DebugInfo/PDB/PDBSymbol.h" + +#include "llvm/DebugInfo/PDB/IPDBEnumChildren.h" +#include "llvm/DebugInfo/PDB/IPDBRawSymbol.h" +#include "llvm/DebugInfo/PDB/PDBSymbolAnnotation.h" +#include "llvm/DebugInfo/PDB/PDBSymbolBlock.h" +#include "llvm/DebugInfo/PDB/PDBSymbolCompiland.h" +#include "llvm/DebugInfo/PDB/PDBSymbolCompilandDetails.h" +#include "llvm/DebugInfo/PDB/PDBSymbolCompilandEnv.h" +#include "llvm/DebugInfo/PDB/PDBSymbolCustom.h" +#include "llvm/DebugInfo/PDB/PDBSymbolData.h" +#include "llvm/DebugInfo/PDB/PDBSymbolExe.h" +#include "llvm/DebugInfo/PDB/PDBSymbolFunc.h" +#include "llvm/DebugInfo/PDB/PDBSymbolFuncDebugEnd.h" +#include "llvm/DebugInfo/PDB/PDBSymbolFuncDebugStart.h" +#include "llvm/DebugInfo/PDB/PDBSymbolLabel.h" +#include "llvm/DebugInfo/PDB/PDBSymbolPublicSymbol.h" +#include "llvm/DebugInfo/PDB/PDBSymbolThunk.h" +#include "llvm/DebugInfo/PDB/PDBSymbolTypeArray.h" +#include "llvm/DebugInfo/PDB/PDBSymbolTypeBaseClass.h" +#include "llvm/DebugInfo/PDB/PDBSymbolTypeBuiltin.h" +#include "llvm/DebugInfo/PDB/PDBSymbolTypeCustom.h" +#include "llvm/DebugInfo/PDB/PDBSymbolTypeDimension.h" +#include "llvm/DebugInfo/PDB/PDBSymbolTypeEnum.h" +#include "llvm/DebugInfo/PDB/PDBSymbolTypeFriend.h" +#include "llvm/DebugInfo/PDB/PDBSymbolTypeFunctionArg.h" +#include "llvm/DebugInfo/PDB/PDBSymbolTypeFunctionSig.h" +#include "llvm/DebugInfo/PDB/PDBSymbolTypeManaged.h" +#include "llvm/DebugInfo/PDB/PDBSymbolTypePointer.h" +#include "llvm/DebugInfo/PDB/PDBSymbolTypeTypedef.h" +#include "llvm/DebugInfo/PDB/PDBSymbolTypeUDT.h" +#include "llvm/DebugInfo/PDB/PDBSymbolTypeVTable.h" +#include "llvm/DebugInfo/PDB/PDBSymbolTypeVTableShape.h" +#include "llvm/DebugInfo/PDB/PDBSymbolUnknown.h" +#include "llvm/DebugInfo/PDB/PDBSymbolUsingNamespace.h" +#include "llvm/DebugInfo/PDB/PDBSymDumper.h" +#include <memory> +#include <utility> + +#include <memory> +#include <utility> + +using namespace llvm; + +PDBSymbol::PDBSymbol(const IPDBSession &PDBSession, + std::unique_ptr<IPDBRawSymbol> Symbol) + : Session(PDBSession), RawSymbol(std::move(Symbol)) {} + +PDBSymbol::~PDBSymbol() {} + +#define FACTORY_SYMTAG_CASE(Tag, Type) \ + case PDB_SymType::Tag: \ + return std::unique_ptr<PDBSymbol>(new Type(PDBSession, std::move(Symbol))); + +std::unique_ptr<PDBSymbol> +PDBSymbol::create(const IPDBSession &PDBSession, + std::unique_ptr<IPDBRawSymbol> Symbol) { + switch (Symbol->getSymTag()) { + FACTORY_SYMTAG_CASE(Exe, PDBSymbolExe) + FACTORY_SYMTAG_CASE(Compiland, PDBSymbolCompiland) + FACTORY_SYMTAG_CASE(CompilandDetails, PDBSymbolCompilandDetails) + FACTORY_SYMTAG_CASE(CompilandEnv, PDBSymbolCompilandEnv) + FACTORY_SYMTAG_CASE(Function, PDBSymbolFunc) + FACTORY_SYMTAG_CASE(Block, PDBSymbolBlock) + FACTORY_SYMTAG_CASE(Data, PDBSymbolData) + FACTORY_SYMTAG_CASE(Annotation, PDBSymbolAnnotation) + FACTORY_SYMTAG_CASE(Label, PDBSymbolLabel) + FACTORY_SYMTAG_CASE(PublicSymbol, PDBSymbolPublicSymbol) + FACTORY_SYMTAG_CASE(UDT, PDBSymbolTypeUDT) + FACTORY_SYMTAG_CASE(Enum, PDBSymbolTypeEnum) + FACTORY_SYMTAG_CASE(FunctionSig, PDBSymbolTypeFunctionSig) + FACTORY_SYMTAG_CASE(PointerType, PDBSymbolTypePointer) + FACTORY_SYMTAG_CASE(ArrayType, PDBSymbolTypeArray) + FACTORY_SYMTAG_CASE(BuiltinType, PDBSymbolTypeBuiltin) + FACTORY_SYMTAG_CASE(Typedef, PDBSymbolTypeTypedef) + FACTORY_SYMTAG_CASE(BaseClass, PDBSymbolTypeBaseClass) + FACTORY_SYMTAG_CASE(Friend, PDBSymbolTypeFriend) + FACTORY_SYMTAG_CASE(FunctionArg, PDBSymbolTypeFunctionArg) + FACTORY_SYMTAG_CASE(FuncDebugStart, PDBSymbolFuncDebugStart) + FACTORY_SYMTAG_CASE(FuncDebugEnd, PDBSymbolFuncDebugEnd) + FACTORY_SYMTAG_CASE(UsingNamespace, PDBSymbolUsingNamespace) + FACTORY_SYMTAG_CASE(VTableShape, PDBSymbolTypeVTableShape) + FACTORY_SYMTAG_CASE(VTable, PDBSymbolTypeVTable) + FACTORY_SYMTAG_CASE(Custom, PDBSymbolCustom) + FACTORY_SYMTAG_CASE(Thunk, PDBSymbolThunk) + FACTORY_SYMTAG_CASE(CustomType, PDBSymbolTypeCustom) + FACTORY_SYMTAG_CASE(ManagedType, PDBSymbolTypeManaged) + FACTORY_SYMTAG_CASE(Dimension, PDBSymbolTypeDimension) + default: + return std::unique_ptr<PDBSymbol>( + new PDBSymbolUnknown(PDBSession, std::move(Symbol))); + } +} + +#define TRY_DUMP_TYPE(Type) \ + if (const Type *DerivedThis = dyn_cast<Type>(this)) \ + Dumper.dump(OS, Indent, *DerivedThis); + +#define ELSE_TRY_DUMP_TYPE(Type, Dumper) else TRY_DUMP_TYPE(Type, Dumper) + +void PDBSymbol::defaultDump(raw_ostream &OS, int Indent) const { + RawSymbol->dump(OS, Indent); +} + +PDB_SymType PDBSymbol::getSymTag() const { return RawSymbol->getSymTag(); } + +std::unique_ptr<IPDBEnumSymbols> PDBSymbol::findAllChildren() const { + return findAllChildren(PDB_SymType::None); +} + +std::unique_ptr<IPDBEnumSymbols> +PDBSymbol::findAllChildren(PDB_SymType Type) const { + return RawSymbol->findChildren(Type); +} + +std::unique_ptr<IPDBEnumSymbols> +PDBSymbol::findChildren(PDB_SymType Type, StringRef Name, + PDB_NameSearchFlags Flags) const { + return RawSymbol->findChildren(Type, Name, Flags); +} + +std::unique_ptr<IPDBEnumSymbols> +PDBSymbol::findChildrenByRVA(PDB_SymType Type, StringRef Name, + PDB_NameSearchFlags Flags, uint32_t RVA) const { + return RawSymbol->findChildrenByRVA(Type, Name, Flags, RVA); +} + +std::unique_ptr<IPDBEnumSymbols> +PDBSymbol::findInlineFramesByRVA(uint32_t RVA) const { + return RawSymbol->findInlineFramesByRVA(RVA); +} + +std::unique_ptr<IPDBEnumSymbols> +PDBSymbol::getChildStats(TagStats &Stats) const { + std::unique_ptr<IPDBEnumSymbols> Result(findAllChildren()); + Stats.clear(); + while (auto Child = Result->getNext()) { + ++Stats[Child->getSymTag()]; + } + Result->reset(); + return Result; +} diff --git a/lib/DebugInfo/PDB/PDBSymbolAnnotation.cpp b/lib/DebugInfo/PDB/PDBSymbolAnnotation.cpp new file mode 100644 index 0000000..4c76e3b --- /dev/null +++ b/lib/DebugInfo/PDB/PDBSymbolAnnotation.cpp @@ -0,0 +1,25 @@ +//===- PDBSymbolAnnotation.cpp - --------------------------------*- C++ -*-===// +// +// The LLVM Compiler Infrastructure +// +// This file is distributed under the University of Illinois Open Source +// License. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +#include "llvm/DebugInfo/PDB/PDBSymbolAnnotation.h" + +#include "llvm/DebugInfo/PDB/PDBSymDumper.h" + +#include <utility> + +using namespace llvm; + +PDBSymbolAnnotation::PDBSymbolAnnotation(const IPDBSession &PDBSession, + std::unique_ptr<IPDBRawSymbol> Symbol) + : PDBSymbol(PDBSession, std::move(Symbol)) {} + +void PDBSymbolAnnotation::dump(raw_ostream &OS, int Indent, + PDBSymDumper &Dumper) const { + Dumper.dump(*this, OS, Indent); +} diff --git a/lib/DebugInfo/PDB/PDBSymbolBlock.cpp b/lib/DebugInfo/PDB/PDBSymbolBlock.cpp new file mode 100644 index 0000000..bb159d5 --- /dev/null +++ b/lib/DebugInfo/PDB/PDBSymbolBlock.cpp @@ -0,0 +1,26 @@ +//===- PDBSymbolBlock.cpp - -------------------------------------*- C++ -*-===// +// +// The LLVM Compiler Infrastructure +// +// This file is distributed under the University of Illinois Open Source +// License. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +#include "llvm/DebugInfo/PDB/PDBSymbolBlock.h" + +#include "llvm/DebugInfo/PDB/PDBSymbol.h" +#include "llvm/DebugInfo/PDB/PDBSymDumper.h" + +#include <utility> + +using namespace llvm; + +PDBSymbolBlock::PDBSymbolBlock(const IPDBSession &PDBSession, + std::unique_ptr<IPDBRawSymbol> Symbol) + : PDBSymbol(PDBSession, std::move(Symbol)) {} + +void PDBSymbolBlock::dump(raw_ostream &OS, int Indent, + PDBSymDumper &Dumper) const { + Dumper.dump(*this, OS, Indent); +} diff --git a/lib/DebugInfo/PDB/PDBSymbolCompiland.cpp b/lib/DebugInfo/PDB/PDBSymbolCompiland.cpp new file mode 100644 index 0000000..0c9b190 --- /dev/null +++ b/lib/DebugInfo/PDB/PDBSymbolCompiland.cpp @@ -0,0 +1,25 @@ +//===- PDBSymbolCompiland.cpp - compiland details --------*- C++ -*-===// +// +// The LLVM Compiler Infrastructure +// +// This file is distributed under the University of Illinois Open Source +// License. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +#include "llvm/DebugInfo/PDB/PDBSymbolCompiland.h" + +#include "llvm/DebugInfo/PDB/PDBSymDumper.h" + +#include <utility> + +using namespace llvm; + +PDBSymbolCompiland::PDBSymbolCompiland(const IPDBSession &PDBSession, + std::unique_ptr<IPDBRawSymbol> Symbol) + : PDBSymbol(PDBSession, std::move(Symbol)) {} + +void PDBSymbolCompiland::dump(raw_ostream &OS, int Indent, + PDBSymDumper &Dumper) const { + Dumper.dump(*this, OS, Indent); +} diff --git a/lib/DebugInfo/PDB/PDBSymbolCompilandDetails.cpp b/lib/DebugInfo/PDB/PDBSymbolCompilandDetails.cpp new file mode 100644 index 0000000..208d68f --- /dev/null +++ b/lib/DebugInfo/PDB/PDBSymbolCompilandDetails.cpp @@ -0,0 +1,26 @@ +//===- PDBSymbolCompilandDetails.cpp - compiland details --------*- C++ -*-===// +// +// The LLVM Compiler Infrastructure +// +// This file is distributed under the University of Illinois Open Source +// License. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +#include "llvm/DebugInfo/PDB/PDBSymbolCompilandDetails.h" + +#include "llvm/DebugInfo/PDB/PDBSymbol.h" +#include "llvm/DebugInfo/PDB/PDBSymDumper.h" + +#include <utility> + +using namespace llvm; + +PDBSymbolCompilandDetails::PDBSymbolCompilandDetails( + const IPDBSession &PDBSession, std::unique_ptr<IPDBRawSymbol> Symbol) + : PDBSymbol(PDBSession, std::move(Symbol)) {} + +void PDBSymbolCompilandDetails::dump(raw_ostream &OS, int Indent, + PDBSymDumper &Dumper) const { + Dumper.dump(*this, OS, Indent); +} diff --git a/lib/DebugInfo/PDB/PDBSymbolCompilandEnv.cpp b/lib/DebugInfo/PDB/PDBSymbolCompilandEnv.cpp new file mode 100644 index 0000000..c54b8fb --- /dev/null +++ b/lib/DebugInfo/PDB/PDBSymbolCompilandEnv.cpp @@ -0,0 +1,32 @@ +//===- PDBSymbolCompilandEnv.cpp - compiland env variables ------*- C++ -*-===// +// +// The LLVM Compiler Infrastructure +// +// This file is distributed under the University of Illinois Open Source +// License. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +#include "llvm/DebugInfo/PDB/PDBSymbolCompilandEnv.h" + +#include "llvm/DebugInfo/PDB/IPDBRawSymbol.h" +#include "llvm/DebugInfo/PDB/PDBSymbol.h" +#include "llvm/DebugInfo/PDB/PDBSymDumper.h" + +#include <utility> + +using namespace llvm; + +PDBSymbolCompilandEnv::PDBSymbolCompilandEnv( + const IPDBSession &PDBSession, std::unique_ptr<IPDBRawSymbol> Symbol) + : PDBSymbol(PDBSession, std::move(Symbol)) {} + +std::string PDBSymbolCompilandEnv::getValue() const { + // call RawSymbol->getValue() and convert the result to an std::string. + return std::string(); +} + +void PDBSymbolCompilandEnv::dump(raw_ostream &OS, int Indent, + PDBSymDumper &Dumper) const { + Dumper.dump(*this, OS, Indent); +} diff --git a/lib/DebugInfo/PDB/PDBSymbolCustom.cpp b/lib/DebugInfo/PDB/PDBSymbolCustom.cpp new file mode 100644 index 0000000..1b6b50b --- /dev/null +++ b/lib/DebugInfo/PDB/PDBSymbolCustom.cpp @@ -0,0 +1,31 @@ +//===- PDBSymbolCustom.cpp - compiler-specific types ------------*- C++ -*-===// +// +// The LLVM Compiler Infrastructure +// +// This file is distributed under the University of Illinois Open Source +// License. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +#include "llvm/DebugInfo/PDB/PDBSymbolCustom.h" + +#include "llvm/DebugInfo/PDB/IPDBRawSymbol.h" +#include "llvm/DebugInfo/PDB/PDBSymbol.h" +#include "llvm/DebugInfo/PDB/PDBSymDumper.h" + +#include <utility> + +using namespace llvm; + +PDBSymbolCustom::PDBSymbolCustom(const IPDBSession &PDBSession, + std::unique_ptr<IPDBRawSymbol> CustomSymbol) + : PDBSymbol(PDBSession, std::move(CustomSymbol)) {} + +void PDBSymbolCustom::getDataBytes(llvm::SmallVector<uint8_t, 32> &bytes) { + RawSymbol->getDataBytes(bytes); +} + +void PDBSymbolCustom::dump(raw_ostream &OS, int Indent, + PDBSymDumper &Dumper) const { + Dumper.dump(*this, OS, Indent); +}
\ No newline at end of file diff --git a/lib/DebugInfo/PDB/PDBSymbolData.cpp b/lib/DebugInfo/PDB/PDBSymbolData.cpp new file mode 100644 index 0000000..6bf7e0f --- /dev/null +++ b/lib/DebugInfo/PDB/PDBSymbolData.cpp @@ -0,0 +1,30 @@ +//===- PDBSymbolData.cpp - PDB data (e.g. variable) accessors ---*- C++ -*-===// +// +// The LLVM Compiler Infrastructure +// +// This file is distributed under the University of Illinois Open Source +// License. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +#include "llvm/DebugInfo/PDB/PDBSymbolData.h" + +#include "llvm/DebugInfo/PDB/IPDBSession.h" +#include "llvm/DebugInfo/PDB/PDBSymDumper.h" + +#include <utility> + +using namespace llvm; + +PDBSymbolData::PDBSymbolData(const IPDBSession &PDBSession, + std::unique_ptr<IPDBRawSymbol> DataSymbol) + : PDBSymbol(PDBSession, std::move(DataSymbol)) {} + +std::unique_ptr<PDBSymbol> PDBSymbolData::getType() const { + return Session.getSymbolById(getTypeId()); +} + +void PDBSymbolData::dump(raw_ostream &OS, int Indent, + PDBSymDumper &Dumper) const { + Dumper.dump(*this, OS, Indent); +}
\ No newline at end of file diff --git a/lib/DebugInfo/PDB/PDBSymbolExe.cpp b/lib/DebugInfo/PDB/PDBSymbolExe.cpp new file mode 100644 index 0000000..ef09193 --- /dev/null +++ b/lib/DebugInfo/PDB/PDBSymbolExe.cpp @@ -0,0 +1,25 @@ +//===- PDBSymbolExe.cpp - ---------------------------------------*- C++ -*-===// +// +// The LLVM Compiler Infrastructure +// +// This file is distributed under the University of Illinois Open Source +// License. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +#include "llvm/DebugInfo/PDB/PDBSymbolExe.h" + +#include "llvm/DebugInfo/PDB/PDBSymDumper.h" + +#include <utility> + +using namespace llvm; + +PDBSymbolExe::PDBSymbolExe(const IPDBSession &PDBSession, + std::unique_ptr<IPDBRawSymbol> Symbol) + : PDBSymbol(PDBSession, std::move(Symbol)) {} + +void PDBSymbolExe::dump(raw_ostream &OS, int Indent, + PDBSymDumper &Dumper) const { + Dumper.dump(*this, OS, Indent); +} diff --git a/lib/DebugInfo/PDB/PDBSymbolFunc.cpp b/lib/DebugInfo/PDB/PDBSymbolFunc.cpp new file mode 100644 index 0000000..e2d859f --- /dev/null +++ b/lib/DebugInfo/PDB/PDBSymbolFunc.cpp @@ -0,0 +1,104 @@ +//===- PDBSymbolFunc.cpp - --------------------------------------*- C++ -*-===// +// +// The LLVM Compiler Infrastructure +// +// This file is distributed under the University of Illinois Open Source +// License. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +#include "llvm/DebugInfo/PDB/PDBSymbolFunc.h" + +#include "llvm/DebugInfo/PDB/ConcreteSymbolEnumerator.h" +#include "llvm/DebugInfo/PDB/IPDBEnumChildren.h" +#include "llvm/DebugInfo/PDB/IPDBSession.h" +#include "llvm/DebugInfo/PDB/PDBSymbolData.h" +#include "llvm/DebugInfo/PDB/PDBSymbolTypeFunctionSig.h" +#include "llvm/DebugInfo/PDB/PDBSymbolTypeUDT.h" +#include "llvm/DebugInfo/PDB/PDBSymDumper.h" +#include "llvm/DebugInfo/PDB/PDBTypes.h" + +#include <unordered_set> +#include <utility> +#include <vector> + +using namespace llvm; + +namespace { +class FunctionArgEnumerator : public IPDBEnumChildren<PDBSymbolData> { +public: + typedef ConcreteSymbolEnumerator<PDBSymbolData> ArgEnumeratorType; + + FunctionArgEnumerator(const IPDBSession &PDBSession, + const PDBSymbolFunc &PDBFunc) + : Session(PDBSession), Func(PDBFunc) { + // Arguments can appear multiple times if they have live range + // information, so we only take the first occurrence. + std::unordered_set<std::string> SeenNames; + auto DataChildren = Func.findAllChildren<PDBSymbolData>(); + while (auto Child = DataChildren->getNext()) { + if (Child->getDataKind() == PDB_DataKind::Param) { + std::string Name = Child->getName(); + if (SeenNames.find(Name) != SeenNames.end()) + continue; + Args.push_back(std::move(Child)); + SeenNames.insert(Name); + } + } + reset(); + } + + uint32_t getChildCount() const { return Args.size(); } + + std::unique_ptr<PDBSymbolData> getChildAtIndex(uint32_t Index) const { + if (Index >= Args.size()) + return nullptr; + + return Session.getConcreteSymbolById<PDBSymbolData>( + Args[Index]->getSymIndexId()); + } + + std::unique_ptr<PDBSymbolData> getNext() { + if (CurIter == Args.end()) + return nullptr; + const auto &Result = **CurIter; + ++CurIter; + return Session.getConcreteSymbolById<PDBSymbolData>(Result.getSymIndexId()); + } + + void reset() { CurIter = Args.empty() ? Args.end() : Args.begin(); } + + FunctionArgEnumerator *clone() const { + return new FunctionArgEnumerator(Session, Func); + } + +private: + typedef std::vector<std::unique_ptr<PDBSymbolData>> ArgListType; + const IPDBSession &Session; + const PDBSymbolFunc &Func; + ArgListType Args; + ArgListType::const_iterator CurIter; +}; +} + +PDBSymbolFunc::PDBSymbolFunc(const IPDBSession &PDBSession, + std::unique_ptr<IPDBRawSymbol> Symbol) + : PDBSymbol(PDBSession, std::move(Symbol)) {} + +std::unique_ptr<PDBSymbolTypeFunctionSig> PDBSymbolFunc::getSignature() const { + return Session.getConcreteSymbolById<PDBSymbolTypeFunctionSig>(getTypeId()); +} + +std::unique_ptr<IPDBEnumChildren<PDBSymbolData>> +PDBSymbolFunc::getArguments() const { + return llvm::make_unique<FunctionArgEnumerator>(Session, *this); +} + +std::unique_ptr<PDBSymbolTypeUDT> PDBSymbolFunc::getClassParent() const { + return Session.getConcreteSymbolById<PDBSymbolTypeUDT>(getClassParentId()); +} + +void PDBSymbolFunc::dump(raw_ostream &OS, int Indent, + PDBSymDumper &Dumper) const { + Dumper.dump(*this, OS, Indent); +} diff --git a/lib/DebugInfo/PDB/PDBSymbolFuncDebugEnd.cpp b/lib/DebugInfo/PDB/PDBSymbolFuncDebugEnd.cpp new file mode 100644 index 0000000..c207488 --- /dev/null +++ b/lib/DebugInfo/PDB/PDBSymbolFuncDebugEnd.cpp @@ -0,0 +1,26 @@ +//===- PDBSymbolFuncDebugEnd.cpp - ------------------------------*- C++ -*-===// +// +// The LLVM Compiler Infrastructure +// +// This file is distributed under the University of Illinois Open Source +// License. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +#include "llvm/DebugInfo/PDB/PDBSymbolFuncDebugEnd.h" + +#include "llvm/DebugInfo/PDB/PDBSymbol.h" +#include "llvm/DebugInfo/PDB/PDBSymDumper.h" + +#include <utility> + +using namespace llvm; + +PDBSymbolFuncDebugEnd::PDBSymbolFuncDebugEnd( + const IPDBSession &PDBSession, std::unique_ptr<IPDBRawSymbol> Symbol) + : PDBSymbol(PDBSession, std::move(Symbol)) {} + +void PDBSymbolFuncDebugEnd::dump(raw_ostream &OS, int Indent, + PDBSymDumper &Dumper) const { + Dumper.dump(*this, OS, Indent); +} diff --git a/lib/DebugInfo/PDB/PDBSymbolFuncDebugStart.cpp b/lib/DebugInfo/PDB/PDBSymbolFuncDebugStart.cpp new file mode 100644 index 0000000..83df22e --- /dev/null +++ b/lib/DebugInfo/PDB/PDBSymbolFuncDebugStart.cpp @@ -0,0 +1,26 @@ +//===- PDBSymbolFuncDebugStart.cpp - ----------------------------*- C++ -*-===// +// +// The LLVM Compiler Infrastructure +// +// This file is distributed under the University of Illinois Open Source +// License. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +#include "llvm/DebugInfo/PDB/PDBSymbolFuncDebugStart.h" + +#include "llvm/DebugInfo/PDB/PDBSymbol.h" +#include "llvm/DebugInfo/PDB/PDBSymDumper.h" + +#include <utility> + +using namespace llvm; + +PDBSymbolFuncDebugStart::PDBSymbolFuncDebugStart( + const IPDBSession &PDBSession, std::unique_ptr<IPDBRawSymbol> Symbol) + : PDBSymbol(PDBSession, std::move(Symbol)) {} + +void PDBSymbolFuncDebugStart::dump(raw_ostream &OS, int Indent, + PDBSymDumper &Dumper) const { + Dumper.dump(*this, OS, Indent); +} diff --git a/lib/DebugInfo/PDB/PDBSymbolLabel.cpp b/lib/DebugInfo/PDB/PDBSymbolLabel.cpp new file mode 100644 index 0000000..ce569e2 --- /dev/null +++ b/lib/DebugInfo/PDB/PDBSymbolLabel.cpp @@ -0,0 +1,25 @@ +//===- PDBSymbolLabel.cpp - -------------------------------------*- C++ -*-===// +// +// The LLVM Compiler Infrastructure +// +// This file is distributed under the University of Illinois Open Source +// License. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +#include "llvm/DebugInfo/PDB/PDBSymbolLabel.h" + +#include "llvm/DebugInfo/PDB/PDBSymDumper.h" + +#include <utility> + +using namespace llvm; + +PDBSymbolLabel::PDBSymbolLabel(const IPDBSession &PDBSession, + std::unique_ptr<IPDBRawSymbol> Symbol) + : PDBSymbol(PDBSession, std::move(Symbol)) {} + +void PDBSymbolLabel::dump(raw_ostream &OS, int Indent, + PDBSymDumper &Dumper) const { + Dumper.dump(*this, OS, Indent); +} diff --git a/lib/DebugInfo/PDB/PDBSymbolPublicSymbol.cpp b/lib/DebugInfo/PDB/PDBSymbolPublicSymbol.cpp new file mode 100644 index 0000000..a7f156c --- /dev/null +++ b/lib/DebugInfo/PDB/PDBSymbolPublicSymbol.cpp @@ -0,0 +1,26 @@ +//===- PDBSymbolPublicSymbol.cpp - ------------------------------*- C++ -*-===// +// +// The LLVM Compiler Infrastructure +// +// This file is distributed under the University of Illinois Open Source +// License. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +#include "llvm/DebugInfo/PDB/PDBSymbolPublicSymbol.h" + +#include "llvm/DebugInfo/PDB/PDBSymbol.h" +#include "llvm/DebugInfo/PDB/PDBSymDumper.h" + +#include <utility> + +using namespace llvm; + +PDBSymbolPublicSymbol::PDBSymbolPublicSymbol( + const IPDBSession &PDBSession, std::unique_ptr<IPDBRawSymbol> Symbol) + : PDBSymbol(PDBSession, std::move(Symbol)) {} + +void PDBSymbolPublicSymbol::dump(raw_ostream &OS, int Indent, + PDBSymDumper &Dumper) const { + Dumper.dump(*this, OS, Indent); +} diff --git a/lib/DebugInfo/PDB/PDBSymbolThunk.cpp b/lib/DebugInfo/PDB/PDBSymbolThunk.cpp new file mode 100644 index 0000000..edade83 --- /dev/null +++ b/lib/DebugInfo/PDB/PDBSymbolThunk.cpp @@ -0,0 +1,25 @@ +//===- PDBSymbolThunk.cpp - -------------------------------------*- C++ -*-===// +// +// The LLVM Compiler Infrastructure +// +// This file is distributed under the University of Illinois Open Source +// License. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +#include "llvm/DebugInfo/PDB/PDBSymbolThunk.h" + +#include "llvm/DebugInfo/PDB/PDBSymDumper.h" + +#include <utility> + +using namespace llvm; + +PDBSymbolThunk::PDBSymbolThunk(const IPDBSession &PDBSession, + std::unique_ptr<IPDBRawSymbol> Symbol) + : PDBSymbol(PDBSession, std::move(Symbol)) {} + +void PDBSymbolThunk::dump(raw_ostream &OS, int Indent, + PDBSymDumper &Dumper) const { + Dumper.dump(*this, OS, Indent); +} diff --git a/lib/DebugInfo/PDB/PDBSymbolTypeArray.cpp b/lib/DebugInfo/PDB/PDBSymbolTypeArray.cpp new file mode 100644 index 0000000..ffe6c80 --- /dev/null +++ b/lib/DebugInfo/PDB/PDBSymbolTypeArray.cpp @@ -0,0 +1,30 @@ +//===- PDBSymbolTypeArray.cpp - ---------------------------------*- C++ -*-===// +// +// The LLVM Compiler Infrastructure +// +// This file is distributed under the University of Illinois Open Source +// License. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +#include "llvm/DebugInfo/PDB/PDBSymbolTypeArray.h" + +#include "llvm/DebugInfo/PDB/IPDBSession.h" +#include "llvm/DebugInfo/PDB/PDBSymDumper.h" + +#include <utility> + +using namespace llvm; + +PDBSymbolTypeArray::PDBSymbolTypeArray(const IPDBSession &PDBSession, + std::unique_ptr<IPDBRawSymbol> Symbol) + : PDBSymbol(PDBSession, std::move(Symbol)) {} + +std::unique_ptr<PDBSymbol> PDBSymbolTypeArray::getElementType() const { + return Session.getSymbolById(getTypeId()); +} + +void PDBSymbolTypeArray::dump(raw_ostream &OS, int Indent, + PDBSymDumper &Dumper) const { + Dumper.dump(*this, OS, Indent); +} diff --git a/lib/DebugInfo/PDB/PDBSymbolTypeBaseClass.cpp b/lib/DebugInfo/PDB/PDBSymbolTypeBaseClass.cpp new file mode 100644 index 0000000..c44cc52 --- /dev/null +++ b/lib/DebugInfo/PDB/PDBSymbolTypeBaseClass.cpp @@ -0,0 +1,26 @@ +//===- PDBSymbolTypeBaseClass.cpp - -----------------------------*- C++ -*-===// +// +// The LLVM Compiler Infrastructure +// +// This file is distributed under the University of Illinois Open Source +// License. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +#include "llvm/DebugInfo/PDB/PDBSymbolTypeBaseClass.h" + +#include "llvm/DebugInfo/PDB/PDBSymbol.h" +#include "llvm/DebugInfo/PDB/PDBSymDumper.h" + +#include <utility> + +using namespace llvm; + +PDBSymbolTypeBaseClass::PDBSymbolTypeBaseClass( + const IPDBSession &PDBSession, std::unique_ptr<IPDBRawSymbol> Symbol) + : PDBSymbol(PDBSession, std::move(Symbol)) {} + +void PDBSymbolTypeBaseClass::dump(raw_ostream &OS, int Indent, + PDBSymDumper &Dumper) const { + Dumper.dump(*this, OS, Indent); +} diff --git a/lib/DebugInfo/PDB/PDBSymbolTypeBuiltin.cpp b/lib/DebugInfo/PDB/PDBSymbolTypeBuiltin.cpp new file mode 100644 index 0000000..f0c94c7 --- /dev/null +++ b/lib/DebugInfo/PDB/PDBSymbolTypeBuiltin.cpp @@ -0,0 +1,25 @@ +//===- PDBSymbolTypeBuiltin.cpp - ------------------------------*- C++ -*-===// +// +// The LLVM Compiler Infrastructure +// +// This file is distributed under the University of Illinois Open Source +// License. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +#include "llvm/DebugInfo/PDB/PDBSymbolTypeBuiltin.h" + +#include "llvm/DebugInfo/PDB/PDBSymDumper.h" + +#include <utility> + +using namespace llvm; + +PDBSymbolTypeBuiltin::PDBSymbolTypeBuiltin( + const IPDBSession &PDBSession, std::unique_ptr<IPDBRawSymbol> Symbol) + : PDBSymbol(PDBSession, std::move(Symbol)) {} + +void PDBSymbolTypeBuiltin::dump(raw_ostream &OS, int Indent, + PDBSymDumper &Dumper) const { + Dumper.dump(*this, OS, Indent); +} diff --git a/lib/DebugInfo/PDB/PDBSymbolTypeCustom.cpp b/lib/DebugInfo/PDB/PDBSymbolTypeCustom.cpp new file mode 100644 index 0000000..0fa8f45 --- /dev/null +++ b/lib/DebugInfo/PDB/PDBSymbolTypeCustom.cpp @@ -0,0 +1,26 @@ +//===- PDBSymbolTypeCustom.cpp - --------------------------------*- C++ -*-===// +// +// The LLVM Compiler Infrastructure +// +// This file is distributed under the University of Illinois Open Source +// License. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +#include "llvm/DebugInfo/PDB/PDBSymbolTypeCustom.h" + +#include "llvm/DebugInfo/PDB/PDBSymbol.h" +#include "llvm/DebugInfo/PDB/PDBSymDumper.h" + +#include <utility> + +using namespace llvm; + +PDBSymbolTypeCustom::PDBSymbolTypeCustom(const IPDBSession &PDBSession, + std::unique_ptr<IPDBRawSymbol> Symbol) + : PDBSymbol(PDBSession, std::move(Symbol)) {} + +void PDBSymbolTypeCustom::dump(raw_ostream &OS, int Indent, + PDBSymDumper &Dumper) const { + Dumper.dump(*this, OS, Indent); +} diff --git a/lib/DebugInfo/PDB/PDBSymbolTypeDimension.cpp b/lib/DebugInfo/PDB/PDBSymbolTypeDimension.cpp new file mode 100644 index 0000000..47fb08d --- /dev/null +++ b/lib/DebugInfo/PDB/PDBSymbolTypeDimension.cpp @@ -0,0 +1,27 @@ +//===- PDBSymbolTypeDimension.cpp - --------------------------------*- C++ +//-*-===// +// +// The LLVM Compiler Infrastructure +// +// This file is distributed under the University of Illinois Open Source +// License. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +#include "llvm/DebugInfo/PDB/PDBSymbolTypeDimension.h" + +#include "llvm/DebugInfo/PDB/PDBSymbol.h" +#include "llvm/DebugInfo/PDB/PDBSymDumper.h" + +#include <utility> + +using namespace llvm; + +PDBSymbolTypeDimension::PDBSymbolTypeDimension( + const IPDBSession &PDBSession, std::unique_ptr<IPDBRawSymbol> Symbol) + : PDBSymbol(PDBSession, std::move(Symbol)) {} + +void PDBSymbolTypeDimension::dump(raw_ostream &OS, int Indent, + PDBSymDumper &Dumper) const { + Dumper.dump(*this, OS, Indent); +} diff --git a/lib/DebugInfo/PDB/PDBSymbolTypeEnum.cpp b/lib/DebugInfo/PDB/PDBSymbolTypeEnum.cpp new file mode 100644 index 0000000..121d41e --- /dev/null +++ b/lib/DebugInfo/PDB/PDBSymbolTypeEnum.cpp @@ -0,0 +1,25 @@ +//===- PDBSymbolTypeEnum.cpp - --------------------------------*- C++ -*-===// +// +// The LLVM Compiler Infrastructure +// +// This file is distributed under the University of Illinois Open Source +// License. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +#include "llvm/DebugInfo/PDB/PDBSymbolTypeEnum.h" + +#include "llvm/DebugInfo/PDB/PDBSymDumper.h" + +#include <utility> + +using namespace llvm; + +PDBSymbolTypeEnum::PDBSymbolTypeEnum(const IPDBSession &PDBSession, + std::unique_ptr<IPDBRawSymbol> Symbol) + : PDBSymbol(PDBSession, std::move(Symbol)) {} + +void PDBSymbolTypeEnum::dump(raw_ostream &OS, int Indent, + PDBSymDumper &Dumper) const { + Dumper.dump(*this, OS, Indent); +} diff --git a/lib/DebugInfo/PDB/PDBSymbolTypeFriend.cpp b/lib/DebugInfo/PDB/PDBSymbolTypeFriend.cpp new file mode 100644 index 0000000..b2bf72e --- /dev/null +++ b/lib/DebugInfo/PDB/PDBSymbolTypeFriend.cpp @@ -0,0 +1,26 @@ +//===- PDBSymbolTypeFriend.cpp - --------------------------------*- C++ -*-===// +// +// The LLVM Compiler Infrastructure +// +// This file is distributed under the University of Illinois Open Source +// License. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +#include "llvm/DebugInfo/PDB/PDBSymbolTypeFriend.h" + +#include "llvm/DebugInfo/PDB/PDBSymbol.h" +#include "llvm/DebugInfo/PDB/PDBSymDumper.h" + +#include <utility> + +using namespace llvm; + +PDBSymbolTypeFriend::PDBSymbolTypeFriend(const IPDBSession &PDBSession, + std::unique_ptr<IPDBRawSymbol> Symbol) + : PDBSymbol(PDBSession, std::move(Symbol)) {} + +void PDBSymbolTypeFriend::dump(raw_ostream &OS, int Indent, + PDBSymDumper &Dumper) const { + Dumper.dump(*this, OS, Indent); +} diff --git a/lib/DebugInfo/PDB/PDBSymbolTypeFunctionArg.cpp b/lib/DebugInfo/PDB/PDBSymbolTypeFunctionArg.cpp new file mode 100644 index 0000000..f394c04 --- /dev/null +++ b/lib/DebugInfo/PDB/PDBSymbolTypeFunctionArg.cpp @@ -0,0 +1,25 @@ +//===- PDBSymbolTypeFunctionArg.cpp - --------------------------*- C++ -*-===// +// +// The LLVM Compiler Infrastructure +// +// This file is distributed under the University of Illinois Open Source +// License. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +#include "llvm/DebugInfo/PDB/PDBSymbolTypeFunctionArg.h" + +#include "llvm/DebugInfo/PDB/PDBSymDumper.h" + +#include <utility> + +using namespace llvm; + +PDBSymbolTypeFunctionArg::PDBSymbolTypeFunctionArg( + const IPDBSession &PDBSession, std::unique_ptr<IPDBRawSymbol> Symbol) + : PDBSymbol(PDBSession, std::move(Symbol)) {} + +void PDBSymbolTypeFunctionArg::dump(raw_ostream &OS, int Indent, + PDBSymDumper &Dumper) const { + Dumper.dump(*this, OS, Indent); +} diff --git a/lib/DebugInfo/PDB/PDBSymbolTypeFunctionSig.cpp b/lib/DebugInfo/PDB/PDBSymbolTypeFunctionSig.cpp new file mode 100644 index 0000000..1ba397b --- /dev/null +++ b/lib/DebugInfo/PDB/PDBSymbolTypeFunctionSig.cpp @@ -0,0 +1,89 @@ +//===- PDBSymbolTypeFunctionSig.cpp - --------------------------*- C++ -*-===// +// +// The LLVM Compiler Infrastructure +// +// This file is distributed under the University of Illinois Open Source +// License. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +#include "llvm/DebugInfo/PDB/PDBSymbolTypeFunctionSig.h" + +#include "llvm/DebugInfo/PDB/ConcreteSymbolEnumerator.h" +#include "llvm/DebugInfo/PDB/IPDBEnumChildren.h" +#include "llvm/DebugInfo/PDB/IPDBSession.h" +#include "llvm/DebugInfo/PDB/PDBSymbol.h" +#include "llvm/DebugInfo/PDB/PDBSymbolTypeFunctionArg.h" +#include "llvm/DebugInfo/PDB/PDBSymDumper.h" + +#include <utility> + +using namespace llvm; + +namespace { +class FunctionArgEnumerator : public IPDBEnumSymbols { +public: + typedef ConcreteSymbolEnumerator<PDBSymbolTypeFunctionArg> ArgEnumeratorType; + + FunctionArgEnumerator(const IPDBSession &PDBSession, + const PDBSymbolTypeFunctionSig &Sig) + : Session(PDBSession), + Enumerator(Sig.findAllChildren<PDBSymbolTypeFunctionArg>()) {} + + FunctionArgEnumerator(const IPDBSession &PDBSession, + std::unique_ptr<ArgEnumeratorType> ArgEnumerator) + : Session(PDBSession), Enumerator(std::move(ArgEnumerator)) {} + + uint32_t getChildCount() const { return Enumerator->getChildCount(); } + + std::unique_ptr<PDBSymbol> getChildAtIndex(uint32_t Index) const { + auto FunctionArgSymbol = Enumerator->getChildAtIndex(Index); + if (!FunctionArgSymbol) + return nullptr; + return Session.getSymbolById(FunctionArgSymbol->getTypeId()); + } + + std::unique_ptr<PDBSymbol> getNext() { + auto FunctionArgSymbol = Enumerator->getNext(); + if (!FunctionArgSymbol) + return nullptr; + return Session.getSymbolById(FunctionArgSymbol->getTypeId()); + } + + void reset() { Enumerator->reset(); } + + MyType *clone() const { + std::unique_ptr<ArgEnumeratorType> Clone(Enumerator->clone()); + return new FunctionArgEnumerator(Session, std::move(Clone)); + } + +private: + const IPDBSession &Session; + std::unique_ptr<ArgEnumeratorType> Enumerator; +}; +} + +PDBSymbolTypeFunctionSig::PDBSymbolTypeFunctionSig( + const IPDBSession &PDBSession, std::unique_ptr<IPDBRawSymbol> Symbol) + : PDBSymbol(PDBSession, std::move(Symbol)) {} + +std::unique_ptr<PDBSymbol> PDBSymbolTypeFunctionSig::getReturnType() const { + return Session.getSymbolById(getTypeId()); +} + +std::unique_ptr<IPDBEnumSymbols> +PDBSymbolTypeFunctionSig::getArguments() const { + return llvm::make_unique<FunctionArgEnumerator>(Session, *this); +} + +std::unique_ptr<PDBSymbol> PDBSymbolTypeFunctionSig::getClassParent() const { + uint32_t ClassId = getClassParentId(); + if (ClassId == 0) + return nullptr; + return Session.getSymbolById(ClassId); +} + +void PDBSymbolTypeFunctionSig::dump(raw_ostream &OS, int Indent, + PDBSymDumper &Dumper) const { + Dumper.dump(*this, OS, Indent); +} diff --git a/lib/DebugInfo/PDB/PDBSymbolTypeManaged.cpp b/lib/DebugInfo/PDB/PDBSymbolTypeManaged.cpp new file mode 100644 index 0000000..e04fb66 --- /dev/null +++ b/lib/DebugInfo/PDB/PDBSymbolTypeManaged.cpp @@ -0,0 +1,26 @@ +//===- PDBSymboTypelManaged.cpp - ------------------------------*- C++ -*-===// +// +// The LLVM Compiler Infrastructure +// +// This file is distributed under the University of Illinois Open Source +// License. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +#include "llvm/DebugInfo/PDB/PDBSymbolTypeManaged.h" + +#include "llvm/DebugInfo/PDB/PDBSymbol.h" +#include "llvm/DebugInfo/PDB/PDBSymDumper.h" + +#include <utility> + +using namespace llvm; + +PDBSymbolTypeManaged::PDBSymbolTypeManaged( + const IPDBSession &PDBSession, std::unique_ptr<IPDBRawSymbol> Symbol) + : PDBSymbol(PDBSession, std::move(Symbol)) {} + +void PDBSymbolTypeManaged::dump(raw_ostream &OS, int Indent, + PDBSymDumper &Dumper) const { + Dumper.dump(*this, OS, Indent); +} diff --git a/lib/DebugInfo/PDB/PDBSymbolTypePointer.cpp b/lib/DebugInfo/PDB/PDBSymbolTypePointer.cpp new file mode 100644 index 0000000..d274bf5 --- /dev/null +++ b/lib/DebugInfo/PDB/PDBSymbolTypePointer.cpp @@ -0,0 +1,30 @@ +//===- PDBSymbolTypePointer.cpp -----------------------------------*- C++ -===// +// +// The LLVM Compiler Infrastructure +// +// This file is distributed under the University of Illinois Open Source +// License. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +#include "llvm/DebugInfo/PDB/PDBSymbolTypePointer.h" + +#include "llvm/DebugInfo/PDB/IPDBSession.h" +#include "llvm/DebugInfo/PDB/PDBSymDumper.h" + +#include <utility> + +using namespace llvm; + +PDBSymbolTypePointer::PDBSymbolTypePointer( + const IPDBSession &PDBSession, std::unique_ptr<IPDBRawSymbol> Symbol) + : PDBSymbol(PDBSession, std::move(Symbol)) {} + +std::unique_ptr<PDBSymbol> PDBSymbolTypePointer::getPointeeType() const { + return Session.getSymbolById(getTypeId()); +} + +void PDBSymbolTypePointer::dump(raw_ostream &OS, int Indent, + PDBSymDumper &Dumper) const { + Dumper.dump(*this, OS, Indent); +} diff --git a/lib/DebugInfo/PDB/PDBSymbolTypeTypedef.cpp b/lib/DebugInfo/PDB/PDBSymbolTypeTypedef.cpp new file mode 100644 index 0000000..12e3ead --- /dev/null +++ b/lib/DebugInfo/PDB/PDBSymbolTypeTypedef.cpp @@ -0,0 +1,25 @@ +//===- PDBSymbolTypeTypedef.cpp ---------------------------------*- C++ -*-===// +// +// The LLVM Compiler Infrastructure +// +// This file is distributed under the University of Illinois Open Source +// License. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +#include "llvm/DebugInfo/PDB/PDBSymbolTypeTypedef.h" + +#include "llvm/DebugInfo/PDB/PDBSymDumper.h" + +#include <utility> + +using namespace llvm; + +PDBSymbolTypeTypedef::PDBSymbolTypeTypedef( + const IPDBSession &PDBSession, std::unique_ptr<IPDBRawSymbol> Symbol) + : PDBSymbol(PDBSession, std::move(Symbol)) {} + +void PDBSymbolTypeTypedef::dump(raw_ostream &OS, int Indent, + PDBSymDumper &Dumper) const { + Dumper.dump(*this, OS, Indent); +} diff --git a/lib/DebugInfo/PDB/PDBSymbolTypeUDT.cpp b/lib/DebugInfo/PDB/PDBSymbolTypeUDT.cpp new file mode 100644 index 0000000..8a72368 --- /dev/null +++ b/lib/DebugInfo/PDB/PDBSymbolTypeUDT.cpp @@ -0,0 +1,25 @@ +//===- PDBSymbolTypeUDT.cpp - --------------------------------*- C++ -*-===// +// +// The LLVM Compiler Infrastructure +// +// This file is distributed under the University of Illinois Open Source +// License. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +#include "llvm/DebugInfo/PDB/PDBSymbolTypeUDT.h" + +#include "llvm/DebugInfo/PDB/PDBSymDumper.h" + +#include <utility> + +using namespace llvm; + +PDBSymbolTypeUDT::PDBSymbolTypeUDT(const IPDBSession &PDBSession, + std::unique_ptr<IPDBRawSymbol> Symbol) + : PDBSymbol(PDBSession, std::move(Symbol)) {} + +void PDBSymbolTypeUDT::dump(raw_ostream &OS, int Indent, + PDBSymDumper &Dumper) const { + Dumper.dump(*this, OS, Indent); +} diff --git a/lib/DebugInfo/PDB/PDBSymbolTypeVTable.cpp b/lib/DebugInfo/PDB/PDBSymbolTypeVTable.cpp new file mode 100644 index 0000000..a100526 --- /dev/null +++ b/lib/DebugInfo/PDB/PDBSymbolTypeVTable.cpp @@ -0,0 +1,25 @@ +//===- PDBSymbolTypeVTable.cpp - --------------------------------*- C++ -*-===// +// +// The LLVM Compiler Infrastructure +// +// This file is distributed under the University of Illinois Open Source +// License. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +#include "llvm/DebugInfo/PDB/PDBSymbolTypeVTable.h" + +#include "llvm/DebugInfo/PDB/PDBSymDumper.h" + +#include <utility> + +using namespace llvm; + +PDBSymbolTypeVTable::PDBSymbolTypeVTable(const IPDBSession &PDBSession, + std::unique_ptr<IPDBRawSymbol> Symbol) + : PDBSymbol(PDBSession, std::move(Symbol)) {} + +void PDBSymbolTypeVTable::dump(raw_ostream &OS, int Indent, + PDBSymDumper &Dumper) const { + Dumper.dump(*this, OS, Indent); +} diff --git a/lib/DebugInfo/PDB/PDBSymbolTypeVTableShape.cpp b/lib/DebugInfo/PDB/PDBSymbolTypeVTableShape.cpp new file mode 100644 index 0000000..6aaa668 --- /dev/null +++ b/lib/DebugInfo/PDB/PDBSymbolTypeVTableShape.cpp @@ -0,0 +1,26 @@ +//===- PDBSymbolTypeVTableShape.cpp - ---------------------------*- C++ -*-===// +// +// The LLVM Compiler Infrastructure +// +// This file is distributed under the University of Illinois Open Source +// License. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +#include "llvm/DebugInfo/PDB/PDBSymbolTypeVTableShape.h" + +#include "llvm/DebugInfo/PDB/PDBSymbol.h" +#include "llvm/DebugInfo/PDB/PDBSymDumper.h" + +#include <utility> + +using namespace llvm; + +PDBSymbolTypeVTableShape::PDBSymbolTypeVTableShape( + const IPDBSession &PDBSession, std::unique_ptr<IPDBRawSymbol> Symbol) + : PDBSymbol(PDBSession, std::move(Symbol)) {} + +void PDBSymbolTypeVTableShape::dump(raw_ostream &OS, int Indent, + PDBSymDumper &Dumper) const { + Dumper.dump(*this, OS, Indent); +} diff --git a/lib/DebugInfo/PDB/PDBSymbolUnknown.cpp b/lib/DebugInfo/PDB/PDBSymbolUnknown.cpp new file mode 100644 index 0000000..9cfb88a --- /dev/null +++ b/lib/DebugInfo/PDB/PDBSymbolUnknown.cpp @@ -0,0 +1,26 @@ +//===- PDBSymbolUnknown.cpp - -----------------------------------*- C++ -*-===// +// +// The LLVM Compiler Infrastructure +// +// This file is distributed under the University of Illinois Open Source +// License. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +#include "llvm/DebugInfo/PDB/PDBSymbolUnknown.h" + +#include "llvm/DebugInfo/PDB/PDBSymbol.h" +#include "llvm/DebugInfo/PDB/PDBSymDumper.h" + +#include <utility> + +using namespace llvm; + +PDBSymbolUnknown::PDBSymbolUnknown(const IPDBSession &PDBSession, + std::unique_ptr<IPDBRawSymbol> Symbol) + : PDBSymbol(PDBSession, std::move(Symbol)) {} + +void PDBSymbolUnknown::dump(raw_ostream &OS, int Indent, + PDBSymDumper &Dumper) const { + Dumper.dump(*this, OS, Indent); +} diff --git a/lib/DebugInfo/PDB/PDBSymbolUsingNamespace.cpp b/lib/DebugInfo/PDB/PDBSymbolUsingNamespace.cpp new file mode 100644 index 0000000..9176dfb --- /dev/null +++ b/lib/DebugInfo/PDB/PDBSymbolUsingNamespace.cpp @@ -0,0 +1,26 @@ +//===- PDBSymbolUsingNamespace.cpp - ------------------- --------*- C++ -*-===// +// +// The LLVM Compiler Infrastructure +// +// This file is distributed under the University of Illinois Open Source +// License. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +#include "llvm/DebugInfo/PDB/PDBSymbolUsingNamespace.h" + +#include "llvm/DebugInfo/PDB/PDBSymbol.h" +#include "llvm/DebugInfo/PDB/PDBSymDumper.h" + +#include <utility> + +using namespace llvm; + +PDBSymbolUsingNamespace::PDBSymbolUsingNamespace( + const IPDBSession &PDBSession, std::unique_ptr<IPDBRawSymbol> Symbol) + : PDBSymbol(PDBSession, std::move(Symbol)) {} + +void PDBSymbolUsingNamespace::dump(raw_ostream &OS, int Indent, + PDBSymDumper &Dumper) const { + Dumper.dump(*this, OS, Indent); +} diff --git a/lib/DebugInfo/module.modulemap b/lib/DebugInfo/module.modulemap deleted file mode 100644 index 1fe5ab1..0000000 --- a/lib/DebugInfo/module.modulemap +++ /dev/null @@ -1 +0,0 @@ -module DebugInfo { requires cplusplus umbrella "." module * { export * } } |