From ee2f195dd3e40f49698ca4dc2666ec09c770e80d Mon Sep 17 00:00:00 2001 From: Dimitry Andric Date: Tue, 30 May 2017 17:37:31 +0000 Subject: Vendor import of llvm trunk r304222: https://llvm.org/svn/llvm-project/llvm/trunk@304222 --- include/llvm/DebugInfo/CodeView/CodeView.h | 22 +++- .../DebugInfo/CodeView/DebugChecksumsSubsection.h | 98 ++++++++++++++ .../DebugInfo/CodeView/DebugFrameDataSubsection.h | 59 +++++++++ .../CodeView/DebugInlineeLinesSubsection.h | 105 +++++++++++++++ .../llvm/DebugInfo/CodeView/DebugLinesSubsection.h | 143 +++++++++++++++++++++ .../CodeView/DebugStringTableSubsection.h | 86 +++++++++++++ include/llvm/DebugInfo/CodeView/DebugSubsection.h | 52 ++++++++ .../DebugInfo/CodeView/DebugSubsectionRecord.h | 77 +++++++++++ .../DebugInfo/CodeView/DebugSubsectionVisitor.h | 66 ++++++++++ .../DebugInfo/CodeView/DebugSymbolsSubsection.h | 53 ++++++++ .../DebugInfo/CodeView/DebugUnknownSubsection.h | 32 +++++ .../CodeView/ModuleDebugFileChecksumFragment.h | 95 -------------- .../llvm/DebugInfo/CodeView/ModuleDebugFragment.h | 48 ------- .../DebugInfo/CodeView/ModuleDebugFragmentRecord.h | 80 ------------ .../CodeView/ModuleDebugFragmentVisitor.h | 68 ---------- .../CodeView/ModuleDebugInlineeLinesFragment.h | 106 --------------- .../DebugInfo/CodeView/ModuleDebugLineFragment.h | 143 --------------------- .../CodeView/ModuleDebugUnknownFragment.h | 33 ----- include/llvm/DebugInfo/CodeView/StringTable.h | 75 ----------- .../DebugInfo/CodeView/SymbolVisitorDelegate.h | 4 +- .../PDB/Native/DbiModuleDescriptorBuilder.h | 23 ++-- include/llvm/DebugInfo/PDB/Native/DbiStream.h | 4 +- .../llvm/DebugInfo/PDB/Native/ModuleDebugStream.h | 7 +- include/llvm/DebugInfo/PDB/Native/PDBStringTable.h | 4 +- .../DebugInfo/PDB/Native/PDBStringTableBuilder.h | 10 +- 25 files changed, 817 insertions(+), 676 deletions(-) create mode 100644 include/llvm/DebugInfo/CodeView/DebugChecksumsSubsection.h create mode 100644 include/llvm/DebugInfo/CodeView/DebugFrameDataSubsection.h create mode 100644 include/llvm/DebugInfo/CodeView/DebugInlineeLinesSubsection.h create mode 100644 include/llvm/DebugInfo/CodeView/DebugLinesSubsection.h create mode 100644 include/llvm/DebugInfo/CodeView/DebugStringTableSubsection.h create mode 100644 include/llvm/DebugInfo/CodeView/DebugSubsection.h create mode 100644 include/llvm/DebugInfo/CodeView/DebugSubsectionRecord.h create mode 100644 include/llvm/DebugInfo/CodeView/DebugSubsectionVisitor.h create mode 100644 include/llvm/DebugInfo/CodeView/DebugSymbolsSubsection.h create mode 100644 include/llvm/DebugInfo/CodeView/DebugUnknownSubsection.h delete mode 100644 include/llvm/DebugInfo/CodeView/ModuleDebugFileChecksumFragment.h delete mode 100644 include/llvm/DebugInfo/CodeView/ModuleDebugFragment.h delete mode 100644 include/llvm/DebugInfo/CodeView/ModuleDebugFragmentRecord.h delete mode 100644 include/llvm/DebugInfo/CodeView/ModuleDebugFragmentVisitor.h delete mode 100644 include/llvm/DebugInfo/CodeView/ModuleDebugInlineeLinesFragment.h delete mode 100644 include/llvm/DebugInfo/CodeView/ModuleDebugLineFragment.h delete mode 100644 include/llvm/DebugInfo/CodeView/ModuleDebugUnknownFragment.h delete mode 100644 include/llvm/DebugInfo/CodeView/StringTable.h (limited to 'include/llvm/DebugInfo') diff --git a/include/llvm/DebugInfo/CodeView/CodeView.h b/include/llvm/DebugInfo/CodeView/CodeView.h index f881ad0c9d80..3316e71916ed 100644 --- a/include/llvm/DebugInfo/CodeView/CodeView.h +++ b/include/llvm/DebugInfo/CodeView/CodeView.h @@ -13,6 +13,8 @@ #include #include +#include "llvm/Support/Endian.h" + namespace llvm { namespace codeview { @@ -291,7 +293,7 @@ enum class ModifierOptions : uint16_t { }; CV_DEFINE_ENUM_CLASS_FLAGS_OPERATORS(ModifierOptions) -enum class ModuleDebugFragmentKind : uint32_t { +enum class DebugSubsectionKind : uint32_t { None = 0, Symbols = 0xf1, Lines = 0xf2, @@ -550,6 +552,24 @@ enum LineFlags : uint16_t { LF_None = 0, LF_HaveColumns = 1, // CV_LINES_HAVE_COLUMNS }; + +/// Data in the the SUBSEC_FRAMEDATA subection. +struct FrameData { + support::ulittle32_t RvaStart; + support::ulittle32_t CodeSize; + support::ulittle32_t LocalSize; + support::ulittle32_t ParamsSize; + support::ulittle32_t MaxStackSize; + support::ulittle32_t FrameFunc; + support::ulittle16_t PrologSize; + support::ulittle16_t SavedRegsSize; + support::ulittle32_t Flags; + enum : uint32_t { + HasSEH = 1 << 0, + HasEH = 1 << 1, + IsFunctionStart = 1 << 2, + }; +}; } } diff --git a/include/llvm/DebugInfo/CodeView/DebugChecksumsSubsection.h b/include/llvm/DebugInfo/CodeView/DebugChecksumsSubsection.h new file mode 100644 index 000000000000..e7036033d2d9 --- /dev/null +++ b/include/llvm/DebugInfo/CodeView/DebugChecksumsSubsection.h @@ -0,0 +1,98 @@ +//===- DebugChecksumsSubsection.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_DEBUGINFO_CODEVIEW_DEBUGCHECKSUMSSUBSECTION_H +#define LLVM_DEBUGINFO_CODEVIEW_DEBUGCHECKSUMSSUBSECTION_H + +#include "llvm/ADT/ArrayRef.h" +#include "llvm/ADT/DenseMap.h" +#include "llvm/DebugInfo/CodeView/DebugSubsection.h" +#include "llvm/Support/Allocator.h" +#include "llvm/Support/BinaryStreamArray.h" +#include "llvm/Support/BinaryStreamReader.h" +#include "llvm/Support/Endian.h" + +namespace llvm { +namespace codeview { + +class DebugStringTableSubsection; + +struct FileChecksumEntry { + uint32_t FileNameOffset; // Byte offset of filename in global stringtable. + FileChecksumKind Kind; // The type of checksum. + ArrayRef Checksum; // The bytes of the checksum. +}; +} +} + +namespace llvm { +template <> struct VarStreamArrayExtractor { +public: + typedef void ContextType; + + static Error extract(BinaryStreamRef Stream, uint32_t &Len, + codeview::FileChecksumEntry &Item); +}; +} + +namespace llvm { +namespace codeview { +class DebugChecksumsSubsectionRef final : public DebugSubsectionRef { + typedef VarStreamArray FileChecksumArray; + typedef FileChecksumArray::Iterator Iterator; + +public: + DebugChecksumsSubsectionRef() + : DebugSubsectionRef(DebugSubsectionKind::FileChecksums) {} + + static bool classof(const DebugSubsectionRef *S) { + return S->kind() == DebugSubsectionKind::FileChecksums; + } + + bool valid() const { return Checksums.valid(); } + + Error initialize(BinaryStreamReader Reader); + Error initialize(BinaryStreamRef Stream); + + Iterator begin() { return Checksums.begin(); } + Iterator end() { return Checksums.end(); } + + const FileChecksumArray &getArray() const { return Checksums; } + +private: + FileChecksumArray Checksums; +}; + +class DebugChecksumsSubsection final : public DebugSubsection { +public: + explicit DebugChecksumsSubsection(DebugStringTableSubsection &Strings); + + static bool classof(const DebugSubsection *S) { + return S->kind() == DebugSubsectionKind::FileChecksums; + } + + void addChecksum(StringRef FileName, FileChecksumKind Kind, + ArrayRef Bytes); + + uint32_t calculateSerializedSize() const override; + Error commit(BinaryStreamWriter &Writer) const override; + uint32_t mapChecksumOffset(StringRef FileName) const; + +private: + DebugStringTableSubsection &Strings; + + DenseMap OffsetMap; + uint32_t SerializedSize = 0; + llvm::BumpPtrAllocator Storage; + std::vector Checksums; +}; +} +} + +#endif diff --git a/include/llvm/DebugInfo/CodeView/DebugFrameDataSubsection.h b/include/llvm/DebugInfo/CodeView/DebugFrameDataSubsection.h new file mode 100644 index 000000000000..686b5c4f242e --- /dev/null +++ b/include/llvm/DebugInfo/CodeView/DebugFrameDataSubsection.h @@ -0,0 +1,59 @@ +//===- DebugFrameDataSubsection.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_DEBUGINFO_CODEVIEW_DEBUGFRAMEDATASUBSECTION_H +#define LLVM_DEBUGINFO_CODEVIEW_DEBUGFRAMEDATASUBSECTION_H + +#include "llvm/DebugInfo/CodeView/CodeView.h" +#include "llvm/DebugInfo/CodeView/DebugSubsection.h" +#include "llvm/Support/BinaryStreamReader.h" +#include "llvm/Support/Error.h" + +namespace llvm { +namespace codeview { +class DebugFrameDataSubsectionRef final : public DebugSubsectionRef { +public: + DebugFrameDataSubsectionRef() + : DebugSubsectionRef(DebugSubsectionKind::FrameData) {} + static bool classof(const DebugSubsection *S) { + return S->kind() == DebugSubsectionKind::FrameData; + } + + Error initialize(BinaryStreamReader Reader); + + FixedStreamArray::Iterator begin() const { return Frames.begin(); } + FixedStreamArray::Iterator end() const { return Frames.end(); } + + const void *getRelocPtr() const { return RelocPtr; } + +private: + const uint32_t *RelocPtr = nullptr; + FixedStreamArray Frames; +}; + +class DebugFrameDataSubsection final : public DebugSubsection { +public: + DebugFrameDataSubsection() + : DebugSubsection(DebugSubsectionKind::FrameData) {} + static bool classof(const DebugSubsection *S) { + return S->kind() == DebugSubsectionKind::FrameData; + } + + uint32_t calculateSerializedSize() const override; + Error commit(BinaryStreamWriter &Writer) const override; + + void addFrameData(const FrameData &Frame); + +private: + std::vector Frames; +}; +} +} + +#endif diff --git a/include/llvm/DebugInfo/CodeView/DebugInlineeLinesSubsection.h b/include/llvm/DebugInfo/CodeView/DebugInlineeLinesSubsection.h new file mode 100644 index 000000000000..e2cfc3c99233 --- /dev/null +++ b/include/llvm/DebugInfo/CodeView/DebugInlineeLinesSubsection.h @@ -0,0 +1,105 @@ +//===- DebugInlineeLinesSubsection.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_DEBUGINFO_CODEVIEW_BUGINLINEELINESSUBSECTION_H +#define LLVM_DEBUGINFO_CODEVIEW_BUGINLINEELINESSUBSECTION_H + +#include "llvm/DebugInfo/CodeView/DebugSubsection.h" +#include "llvm/DebugInfo/CodeView/Line.h" +#include "llvm/Support/BinaryStreamArray.h" +#include "llvm/Support/BinaryStreamReader.h" +#include "llvm/Support/Error.h" + +namespace llvm { +namespace codeview { + +class DebugInlineeLinesSubsectionsRef; +class DebugChecksumsSubsection; + +enum class InlineeLinesSignature : uint32_t { + Normal, // CV_INLINEE_SOURCE_LINE_SIGNATURE + ExtraFiles // CV_INLINEE_SOURCE_LINE_SIGNATURE_EX +}; + +struct InlineeSourceLineHeader { + TypeIndex Inlinee; // ID of the function that was inlined. + support::ulittle32_t FileID; // Offset into FileChecksums subsection. + support::ulittle32_t SourceLineNum; // First line of inlined code. + // If extra files present: + // ulittle32_t ExtraFileCount; + // ulittle32_t Files[]; +}; + +struct InlineeSourceLine { + const InlineeSourceLineHeader *Header; + FixedStreamArray ExtraFiles; +}; +} + +template <> struct VarStreamArrayExtractor { + typedef bool ContextType; + + static Error extract(BinaryStreamRef Stream, uint32_t &Len, + codeview::InlineeSourceLine &Item, bool HasExtraFiles); +}; + +namespace codeview { +class DebugInlineeLinesSubsectionRef final : public DebugSubsectionRef { + typedef VarStreamArray LinesArray; + typedef LinesArray::Iterator Iterator; + +public: + DebugInlineeLinesSubsectionRef(); + + static bool classof(const DebugSubsectionRef *S) { + return S->kind() == DebugSubsectionKind::InlineeLines; + } + + Error initialize(BinaryStreamReader Reader); + bool hasExtraFiles() const; + + Iterator begin() const { return Lines.begin(); } + Iterator end() const { return Lines.end(); } + +private: + InlineeLinesSignature Signature; + VarStreamArray Lines; +}; + +class DebugInlineeLinesSubsection final : public DebugSubsection { +public: + DebugInlineeLinesSubsection(DebugChecksumsSubsection &Checksums, + bool HasExtraFiles); + + static bool classof(const DebugSubsection *S) { + return S->kind() == DebugSubsectionKind::InlineeLines; + } + + Error commit(BinaryStreamWriter &Writer) const override; + uint32_t calculateSerializedSize() const override; + + void addInlineSite(TypeIndex FuncId, StringRef FileName, uint32_t SourceLine); + void addExtraFile(StringRef FileName); + +private: + DebugChecksumsSubsection &Checksums; + + bool HasExtraFiles = false; + uint32_t ExtraFileCount = 0; + + struct Entry { + std::vector ExtraFiles; + InlineeSourceLineHeader Header; + }; + std::vector Entries; +}; +} +} + +#endif diff --git a/include/llvm/DebugInfo/CodeView/DebugLinesSubsection.h b/include/llvm/DebugInfo/CodeView/DebugLinesSubsection.h new file mode 100644 index 000000000000..1b63af59c2ed --- /dev/null +++ b/include/llvm/DebugInfo/CodeView/DebugLinesSubsection.h @@ -0,0 +1,143 @@ +//===- DebugLinesSubsection.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_DEBUGINFO_CODEVIEW_MODULEDEBUGLINEFRAGMENT_H +#define LLVM_DEBUGINFO_CODEVIEW_MODULEDEBUGLINEFRAGMENT_H + +#include "llvm/DebugInfo/CodeView/DebugSubsection.h" +#include "llvm/DebugInfo/CodeView/Line.h" +#include "llvm/Support/BinaryStreamArray.h" +#include "llvm/Support/BinaryStreamReader.h" +#include "llvm/Support/Error.h" + +namespace llvm { +namespace codeview { + +class DebugChecksumsSubsection; +class DebugStringTableSubsection; + +// Corresponds to the `CV_DebugSLinesHeader_t` structure. +struct LineFragmentHeader { + support::ulittle32_t RelocOffset; // Code offset of line contribution. + support::ulittle16_t RelocSegment; // Code segment of line contribution. + support::ulittle16_t Flags; // See LineFlags enumeration. + support::ulittle32_t CodeSize; // Code size of this line contribution. +}; + +// Corresponds to the `CV_DebugSLinesFileBlockHeader_t` structure. +struct LineBlockFragmentHeader { + support::ulittle32_t NameIndex; // Offset of FileChecksum entry in File + // checksums buffer. The checksum entry then + // contains another offset into the string + // table of the actual name. + support::ulittle32_t NumLines; // Number of lines + support::ulittle32_t BlockSize; // Code size of block, in bytes. + // The following two variable length arrays appear immediately after the + // header. The structure definitions follow. + // LineNumberEntry Lines[NumLines]; + // ColumnNumberEntry Columns[NumLines]; +}; + +// Corresponds to `CV_Line_t` structure +struct LineNumberEntry { + support::ulittle32_t Offset; // Offset to start of code bytes for line number + support::ulittle32_t Flags; // Start:24, End:7, IsStatement:1 +}; + +// Corresponds to `CV_Column_t` structure +struct ColumnNumberEntry { + support::ulittle16_t StartColumn; + support::ulittle16_t EndColumn; +}; + +struct LineColumnEntry { + support::ulittle32_t NameIndex; + FixedStreamArray LineNumbers; + FixedStreamArray Columns; +}; + +class LineColumnExtractor { +public: + typedef const LineFragmentHeader *ContextType; + + static Error extract(BinaryStreamRef Stream, uint32_t &Len, + LineColumnEntry &Item, const LineFragmentHeader *Ctx); +}; + +class DebugLinesSubsectionRef final : public DebugSubsectionRef { + friend class LineColumnExtractor; + typedef VarStreamArray LineInfoArray; + typedef LineInfoArray::Iterator Iterator; + +public: + DebugLinesSubsectionRef(); + + static bool classof(const DebugSubsectionRef *S) { + return S->kind() == DebugSubsectionKind::Lines; + } + + Error initialize(BinaryStreamReader Reader); + + Iterator begin() const { return LinesAndColumns.begin(); } + Iterator end() const { return LinesAndColumns.end(); } + + const LineFragmentHeader *header() const { return Header; } + + bool hasColumnInfo() const; + +private: + const LineFragmentHeader *Header = nullptr; + LineInfoArray LinesAndColumns; +}; + +class DebugLinesSubsection final : public DebugSubsection { + struct Block { + Block(uint32_t ChecksumBufferOffset) + : ChecksumBufferOffset(ChecksumBufferOffset) {} + + uint32_t ChecksumBufferOffset; + std::vector Lines; + std::vector Columns; + }; + +public: + DebugLinesSubsection(DebugChecksumsSubsection &Checksums, + DebugStringTableSubsection &Strings); + + static bool classof(const DebugSubsection *S) { + return S->kind() == DebugSubsectionKind::Lines; + } + + void createBlock(StringRef FileName); + void addLineInfo(uint32_t Offset, const LineInfo &Line); + void addLineAndColumnInfo(uint32_t Offset, const LineInfo &Line, + uint32_t ColStart, uint32_t ColEnd); + + uint32_t calculateSerializedSize() const override; + Error commit(BinaryStreamWriter &Writer) const override; + + void setRelocationAddress(uint16_t Segment, uint16_t Offset); + void setCodeSize(uint32_t Size); + void setFlags(LineFlags Flags); + + bool hasColumnInfo() const; + +private: + DebugChecksumsSubsection &Checksums; + + uint16_t RelocOffset = 0; + uint16_t RelocSegment = 0; + uint32_t CodeSize = 0; + LineFlags Flags = LF_None; + std::vector Blocks; +}; +} +} + +#endif diff --git a/include/llvm/DebugInfo/CodeView/DebugStringTableSubsection.h b/include/llvm/DebugInfo/CodeView/DebugStringTableSubsection.h new file mode 100644 index 000000000000..fbe39cb16f09 --- /dev/null +++ b/include/llvm/DebugInfo/CodeView/DebugStringTableSubsection.h @@ -0,0 +1,86 @@ +//===- DebugStringTableSubsection.h - CodeView String Table -----*- C++ -*-===// +// +// The LLVM Compiler Infrastructure +// +// This file is distributed under the University of Illinois Open Source +// License. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +#ifndef LLVM_DEBUGINFO_CODEVIEW_DEBUGSTRINGTABLESUBSECTION_H +#define LLVM_DEBUGINFO_CODEVIEW_DEBUGSTRINGTABLESUBSECTION_H + +#include "llvm/ADT/StringMap.h" +#include "llvm/ADT/StringRef.h" +#include "llvm/DebugInfo/CodeView/DebugSubsection.h" +#include "llvm/Support/BinaryStreamRef.h" +#include "llvm/Support/Error.h" + +#include + +namespace llvm { + +class BinaryStreamReader; +class BinaryStreamRef; +class BinaryStreamWriter; + +namespace codeview { + +/// Represents a read-only view of a CodeView string table. This is a very +/// simple flat buffer consisting of null-terminated strings, where strings +/// are retrieved by their offset in the buffer. DebugStringTableSubsectionRef +/// does not own the underlying storage for the buffer. +class DebugStringTableSubsectionRef : public DebugSubsectionRef { +public: + DebugStringTableSubsectionRef(); + + static bool classof(const DebugSubsectionRef *S) { + return S->kind() == DebugSubsectionKind::StringTable; + } + + Error initialize(BinaryStreamRef Contents); + + Expected getString(uint32_t Offset) const; + + bool valid() const { return Stream.valid(); } + +private: + BinaryStreamRef Stream; +}; + +/// Represents a read-write view of a CodeView string table. +/// DebugStringTableSubsection owns the underlying storage for the table, and is +/// capable of serializing the string table into a format understood by +/// DebugStringTableSubsectionRef. +class DebugStringTableSubsection : public DebugSubsection { +public: + DebugStringTableSubsection(); + + static bool classof(const DebugSubsection *S) { + return S->kind() == DebugSubsectionKind::StringTable; + } + + // If string S does not exist in the string table, insert it. + // Returns the ID for S. + uint32_t insert(StringRef S); + + // Return the ID for string S. Assumes S exists in the table. + uint32_t getStringId(StringRef S) const; + + uint32_t calculateSerializedSize() const override; + Error commit(BinaryStreamWriter &Writer) const override; + + uint32_t size() const; + + StringMap::const_iterator begin() const { return Strings.begin(); } + + StringMap::const_iterator end() const { return Strings.end(); } + +private: + StringMap Strings; + uint32_t StringSize = 1; +}; +} +} + +#endif diff --git a/include/llvm/DebugInfo/CodeView/DebugSubsection.h b/include/llvm/DebugInfo/CodeView/DebugSubsection.h new file mode 100644 index 000000000000..e427e0006a55 --- /dev/null +++ b/include/llvm/DebugInfo/CodeView/DebugSubsection.h @@ -0,0 +1,52 @@ +//===- DebugSubsection.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_DEBUGINFO_CODEVIEW_MODULEDEBUGFRAGMENT_H +#define LLVM_DEBUGINFO_CODEVIEW_MODULEDEBUGFRAGMENT_H + +#include "llvm/DebugInfo/CodeView/CodeView.h" +#include "llvm/Support/BinaryStreamWriter.h" +#include "llvm/Support/Casting.h" + +namespace llvm { +namespace codeview { + +class DebugSubsectionRef { +public: + explicit DebugSubsectionRef(DebugSubsectionKind Kind) : Kind(Kind) {} + virtual ~DebugSubsectionRef(); + + static bool classof(const DebugSubsectionRef *S) { return true; } + + DebugSubsectionKind kind() const { return Kind; } + +protected: + DebugSubsectionKind Kind; +}; + +class DebugSubsection { +public: + explicit DebugSubsection(DebugSubsectionKind Kind) : Kind(Kind) {} + virtual ~DebugSubsection(); + + static bool classof(const DebugSubsection *S) { return true; } + + DebugSubsectionKind kind() const { return Kind; } + + virtual Error commit(BinaryStreamWriter &Writer) const = 0; + virtual uint32_t calculateSerializedSize() const = 0; + +protected: + DebugSubsectionKind Kind; +}; + +} // namespace codeview +} // namespace llvm + +#endif // LLVM_DEBUGINFO_CODEVIEW_MODULEDEBUGFRAGMENT_H diff --git a/include/llvm/DebugInfo/CodeView/DebugSubsectionRecord.h b/include/llvm/DebugInfo/CodeView/DebugSubsectionRecord.h new file mode 100644 index 000000000000..b2e1131e5968 --- /dev/null +++ b/include/llvm/DebugInfo/CodeView/DebugSubsectionRecord.h @@ -0,0 +1,77 @@ +//===- DebugSubsection.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_DEBUGINFO_CODEVIEW_MODULEDEBUGFRAGMENTRECORD_H +#define LLVM_DEBUGINFO_CODEVIEW_MODULEDEBUGFRAGMENTRECORD_H + +#include "llvm/DebugInfo/CodeView/CodeView.h" +#include "llvm/Support/BinaryStreamArray.h" +#include "llvm/Support/BinaryStreamRef.h" +#include "llvm/Support/BinaryStreamWriter.h" +#include "llvm/Support/Endian.h" +#include "llvm/Support/Error.h" + +namespace llvm { +namespace codeview { + +class DebugSubsection; + +// Corresponds to the `CV_DebugSSubsectionHeader_t` structure. +struct DebugSubsectionHeader { + support::ulittle32_t Kind; // codeview::DebugSubsectionKind enum + support::ulittle32_t Length; // number of bytes occupied by this record. +}; + +class DebugSubsectionRecord { +public: + DebugSubsectionRecord(); + DebugSubsectionRecord(DebugSubsectionKind Kind, BinaryStreamRef Data); + + static Error initialize(BinaryStreamRef Stream, DebugSubsectionRecord &Info); + + uint32_t getRecordLength() const; + DebugSubsectionKind kind() const; + BinaryStreamRef getRecordData() const; + +private: + DebugSubsectionKind Kind; + BinaryStreamRef Data; +}; + +class DebugSubsectionRecordBuilder { +public: + DebugSubsectionRecordBuilder(DebugSubsectionKind Kind, DebugSubsection &Frag); + uint32_t calculateSerializedLength(); + Error commit(BinaryStreamWriter &Writer); + +private: + DebugSubsectionKind Kind; + DebugSubsection &Frag; +}; + +} // namespace codeview + +template <> struct VarStreamArrayExtractor { + typedef void ContextType; + + static Error extract(BinaryStreamRef Stream, uint32_t &Length, + codeview::DebugSubsectionRecord &Info) { + if (auto EC = codeview::DebugSubsectionRecord::initialize(Stream, Info)) + return EC; + Length = Info.getRecordLength(); + return Error::success(); + } +}; + +namespace codeview { +typedef VarStreamArray DebugSubsectionArray; +} +} // namespace llvm + +#endif // LLVM_DEBUGINFO_CODEVIEW_MODULEDEBUGFRAGMENTRECORD_H diff --git a/include/llvm/DebugInfo/CodeView/DebugSubsectionVisitor.h b/include/llvm/DebugInfo/CodeView/DebugSubsectionVisitor.h new file mode 100644 index 000000000000..55bef491c97e --- /dev/null +++ b/include/llvm/DebugInfo/CodeView/DebugSubsectionVisitor.h @@ -0,0 +1,66 @@ +//===- DebugSubsectionVisitor.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_DEBUGINFO_CODEVIEW_MODULEDEBUGFRAGMENTVISITOR_H +#define LLVM_DEBUGINFO_CODEVIEW_MODULEDEBUGFRAGMENTVISITOR_H + +#include "llvm/Support/Error.h" +#include + +namespace llvm { + +namespace codeview { + +class DebugChecksumsSubsectionRef; +class DebugSubsectionRecord; +class DebugInlineeLinesSubsectionRef; +class DebugLinesSubsectionRef; +class DebugUnknownSubsectionRef; + +class DebugSubsectionVisitor { +public: + virtual ~DebugSubsectionVisitor() = default; + + virtual Error visitUnknown(DebugUnknownSubsectionRef &Unknown) { + return Error::success(); + } + virtual Error visitLines(DebugLinesSubsectionRef &Lines) { + return Error::success(); + } + + virtual Error visitFileChecksums(DebugChecksumsSubsectionRef &Checksums) { + return Error::success(); + } + + virtual Error visitInlineeLines(DebugInlineeLinesSubsectionRef &Inlinees) { + return Error::success(); + } + + virtual Error finished() { return Error::success(); } +}; + +Error visitDebugSubsection(const DebugSubsectionRecord &R, + DebugSubsectionVisitor &V); + +template +Error visitDebugSubsections(T &&FragmentRange, DebugSubsectionVisitor &V) { + for (const auto &L : FragmentRange) { + if (auto EC = visitDebugSubsection(L, V)) + return EC; + } + if (auto EC = V.finished()) + return EC; + return Error::success(); +} + +} // end namespace codeview + +} // end namespace llvm + +#endif // LLVM_DEBUGINFO_CODEVIEW_MODULEDEBUGFRAGMENTVISITOR_H diff --git a/include/llvm/DebugInfo/CodeView/DebugSymbolsSubsection.h b/include/llvm/DebugInfo/CodeView/DebugSymbolsSubsection.h new file mode 100644 index 000000000000..3d1eb27ba270 --- /dev/null +++ b/include/llvm/DebugInfo/CodeView/DebugSymbolsSubsection.h @@ -0,0 +1,53 @@ +//===- DebugSymbolsSubsection.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_DEBUGINFO_CODEVIEW_DEBUGSYMBOLSSUBSECTION_H +#define LLVM_DEBUGINFO_CODEVIEW_DEBUGSYMBOLSSUBSECTION_H + +#include "llvm/DebugInfo/CodeView/DebugSubsection.h" +#include "llvm/DebugInfo/CodeView/SymbolRecord.h" +#include "llvm/Support/Error.h" + +namespace llvm { +namespace codeview { +class DebugSymbolsSubsectionRef final : public DebugSubsectionRef { +public: + DebugSymbolsSubsectionRef() + : DebugSubsectionRef(DebugSubsectionKind::Symbols) {} + + static bool classof(const DebugSubsectionRef *S) { + return S->kind() == DebugSubsectionKind::Symbols; + } + + Error initialize(BinaryStreamReader Reader); + +private: + CVSymbolArray Records; +}; + +class DebugSymbolsSubsection final : public DebugSubsection { +public: + DebugSymbolsSubsection() : DebugSubsection(DebugSubsectionKind::Symbols) {} + static bool classof(const DebugSubsection *S) { + return S->kind() == DebugSubsectionKind::Symbols; + } + + uint32_t calculateSerializedSize() const override; + Error commit(BinaryStreamWriter &Writer) const override; + + void addSymbol(CVSymbol Symbol); + +private: + uint32_t Length = 0; + std::vector Records; +}; +} +} + +#endif diff --git a/include/llvm/DebugInfo/CodeView/DebugUnknownSubsection.h b/include/llvm/DebugInfo/CodeView/DebugUnknownSubsection.h new file mode 100644 index 000000000000..ea9a96ca8d68 --- /dev/null +++ b/include/llvm/DebugInfo/CodeView/DebugUnknownSubsection.h @@ -0,0 +1,32 @@ +//===- DebugUnknownSubsection.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_DEBUGINFO_CODEVIEW_MODULEDEBUGUNKNOWNFRAGMENT_H +#define LLVM_DEBUGINFO_CODEVIEW_MODULEDEBUGUNKNOWNFRAGMENT_H + +#include "llvm/DebugInfo/CodeView/DebugSubsection.h" +#include "llvm/Support/BinaryStreamRef.h" + +namespace llvm { +namespace codeview { + +class DebugUnknownSubsectionRef final : public DebugSubsectionRef { +public: + DebugUnknownSubsectionRef(DebugSubsectionKind Kind, BinaryStreamRef Data) + : DebugSubsectionRef(Kind), Data(Data) {} + + BinaryStreamRef getData() const { return Data; } + +private: + BinaryStreamRef Data; +}; +} +} + +#endif diff --git a/include/llvm/DebugInfo/CodeView/ModuleDebugFileChecksumFragment.h b/include/llvm/DebugInfo/CodeView/ModuleDebugFileChecksumFragment.h deleted file mode 100644 index 6c08c9aa2137..000000000000 --- a/include/llvm/DebugInfo/CodeView/ModuleDebugFileChecksumFragment.h +++ /dev/null @@ -1,95 +0,0 @@ -//===- ModuleDebugFileChecksumFragment.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_DEBUGINFO_CODEVIEW_MODULEDEBUGFILECHECKSUMFRAGMENT_H -#define LLVM_DEBUGINFO_CODEVIEW_MODULEDEBUGFILECHECKSUMFRAGMENT_H - -#include "llvm/ADT/ArrayRef.h" -#include "llvm/ADT/DenseMap.h" -#include "llvm/DebugInfo/CodeView/ModuleDebugFragment.h" -#include "llvm/Support/Allocator.h" -#include "llvm/Support/BinaryStreamArray.h" -#include "llvm/Support/BinaryStreamReader.h" -#include "llvm/Support/Endian.h" - -namespace llvm { -namespace codeview { - -class StringTable; - -struct FileChecksumEntry { - uint32_t FileNameOffset; // Byte offset of filename in global stringtable. - FileChecksumKind Kind; // The type of checksum. - ArrayRef Checksum; // The bytes of the checksum. -}; -} -} - -namespace llvm { -template <> struct VarStreamArrayExtractor { -public: - typedef void ContextType; - - static Error extract(BinaryStreamRef Stream, uint32_t &Len, - codeview::FileChecksumEntry &Item); -}; -} - -namespace llvm { -namespace codeview { -class ModuleDebugFileChecksumFragmentRef final : public ModuleDebugFragmentRef { - typedef VarStreamArray FileChecksumArray; - typedef FileChecksumArray::Iterator Iterator; - -public: - ModuleDebugFileChecksumFragmentRef() - : ModuleDebugFragmentRef(ModuleDebugFragmentKind::FileChecksums) {} - - static bool classof(const ModuleDebugFragmentRef *S) { - return S->kind() == ModuleDebugFragmentKind::FileChecksums; - } - - Error initialize(BinaryStreamReader Reader); - - Iterator begin() { return Checksums.begin(); } - Iterator end() { return Checksums.end(); } - - const FileChecksumArray &getArray() const { return Checksums; } - -private: - FileChecksumArray Checksums; -}; - -class ModuleDebugFileChecksumFragment final : public ModuleDebugFragment { -public: - explicit ModuleDebugFileChecksumFragment(StringTable &Strings); - - static bool classof(const ModuleDebugFragment *S) { - return S->kind() == ModuleDebugFragmentKind::FileChecksums; - } - - void addChecksum(StringRef FileName, FileChecksumKind Kind, - ArrayRef Bytes); - - uint32_t calculateSerializedLength() override; - Error commit(BinaryStreamWriter &Writer) override; - uint32_t mapChecksumOffset(StringRef FileName) const; - -private: - StringTable &Strings; - - DenseMap OffsetMap; - uint32_t SerializedSize = 0; - llvm::BumpPtrAllocator Storage; - std::vector Checksums; -}; -} -} - -#endif diff --git a/include/llvm/DebugInfo/CodeView/ModuleDebugFragment.h b/include/llvm/DebugInfo/CodeView/ModuleDebugFragment.h deleted file mode 100644 index a5311cae9480..000000000000 --- a/include/llvm/DebugInfo/CodeView/ModuleDebugFragment.h +++ /dev/null @@ -1,48 +0,0 @@ -//===- ModuleDebugFragment.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_DEBUGINFO_CODEVIEW_MODULEDEBUGFRAGMENT_H -#define LLVM_DEBUGINFO_CODEVIEW_MODULEDEBUGFRAGMENT_H - -#include "llvm/DebugInfo/CodeView/CodeView.h" -#include "llvm/Support/BinaryStreamWriter.h" -#include "llvm/Support/Casting.h" - -namespace llvm { -namespace codeview { - -class ModuleDebugFragmentRef { -public: - explicit ModuleDebugFragmentRef(ModuleDebugFragmentKind Kind) : Kind(Kind) {} - virtual ~ModuleDebugFragmentRef(); - - ModuleDebugFragmentKind kind() const { return Kind; } - -protected: - ModuleDebugFragmentKind Kind; -}; - -class ModuleDebugFragment { -public: - explicit ModuleDebugFragment(ModuleDebugFragmentKind Kind) : Kind(Kind) {} - virtual ~ModuleDebugFragment(); - - ModuleDebugFragmentKind kind() const { return Kind; } - - virtual Error commit(BinaryStreamWriter &Writer) = 0; - virtual uint32_t calculateSerializedLength() = 0; - -protected: - ModuleDebugFragmentKind Kind; -}; - -} // namespace codeview -} // namespace llvm - -#endif // LLVM_DEBUGINFO_CODEVIEW_MODULEDEBUGFRAGMENT_H diff --git a/include/llvm/DebugInfo/CodeView/ModuleDebugFragmentRecord.h b/include/llvm/DebugInfo/CodeView/ModuleDebugFragmentRecord.h deleted file mode 100644 index f68f21b224f1..000000000000 --- a/include/llvm/DebugInfo/CodeView/ModuleDebugFragmentRecord.h +++ /dev/null @@ -1,80 +0,0 @@ -//===- ModuleDebugFragment.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_DEBUGINFO_CODEVIEW_MODULEDEBUGFRAGMENTRECORD_H -#define LLVM_DEBUGINFO_CODEVIEW_MODULEDEBUGFRAGMENTRECORD_H - -#include "llvm/DebugInfo/CodeView/CodeView.h" -#include "llvm/Support/BinaryStreamArray.h" -#include "llvm/Support/BinaryStreamRef.h" -#include "llvm/Support/BinaryStreamWriter.h" -#include "llvm/Support/Endian.h" -#include "llvm/Support/Error.h" - -namespace llvm { -namespace codeview { - -class ModuleDebugFragment; - -// Corresponds to the `CV_DebugSSubsectionHeader_t` structure. -struct ModuleDebugFragmentHeader { - support::ulittle32_t Kind; // codeview::ModuleDebugFragmentKind enum - support::ulittle32_t Length; // number of bytes occupied by this record. -}; - -class ModuleDebugFragmentRecord { -public: - ModuleDebugFragmentRecord(); - ModuleDebugFragmentRecord(ModuleDebugFragmentKind Kind, BinaryStreamRef Data); - - static Error initialize(BinaryStreamRef Stream, - ModuleDebugFragmentRecord &Info); - - uint32_t getRecordLength() const; - ModuleDebugFragmentKind kind() const; - BinaryStreamRef getRecordData() const; - -private: - ModuleDebugFragmentKind Kind; - BinaryStreamRef Data; -}; - -class ModuleDebugFragmentRecordBuilder { -public: - ModuleDebugFragmentRecordBuilder(ModuleDebugFragmentKind Kind, - ModuleDebugFragment &Frag); - uint32_t calculateSerializedLength(); - Error commit(BinaryStreamWriter &Writer); - -private: - ModuleDebugFragmentKind Kind; - ModuleDebugFragment &Frag; -}; - -} // namespace codeview - -template <> -struct VarStreamArrayExtractor { - typedef void ContextType; - - static Error extract(BinaryStreamRef Stream, uint32_t &Length, - codeview::ModuleDebugFragmentRecord &Info) { - if (auto EC = codeview::ModuleDebugFragmentRecord::initialize(Stream, Info)) - return EC; - Length = Info.getRecordLength(); - return Error::success(); - } -}; - -namespace codeview { -typedef VarStreamArray ModuleDebugFragmentArray; -} -} // namespace llvm - -#endif // LLVM_DEBUGINFO_CODEVIEW_MODULEDEBUGFRAGMENTRECORD_H diff --git a/include/llvm/DebugInfo/CodeView/ModuleDebugFragmentVisitor.h b/include/llvm/DebugInfo/CodeView/ModuleDebugFragmentVisitor.h deleted file mode 100644 index 1f55d2024203..000000000000 --- a/include/llvm/DebugInfo/CodeView/ModuleDebugFragmentVisitor.h +++ /dev/null @@ -1,68 +0,0 @@ -//===- ModuleDebugFragmentVisitor.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_DEBUGINFO_CODEVIEW_MODULEDEBUGFRAGMENTVISITOR_H -#define LLVM_DEBUGINFO_CODEVIEW_MODULEDEBUGFRAGMENTVISITOR_H - -#include "llvm/Support/Error.h" -#include - -namespace llvm { - -namespace codeview { - -class ModuleDebugFileChecksumFragmentRef; -class ModuleDebugFragmentRecord; -class ModuleDebugInlineeLineFragmentRef; -class ModuleDebugLineFragmentRef; -class ModuleDebugUnknownFragmentRef; - -class ModuleDebugFragmentVisitor { -public: - virtual ~ModuleDebugFragmentVisitor() = default; - - virtual Error visitUnknown(ModuleDebugUnknownFragmentRef &Unknown) { - return Error::success(); - } - virtual Error visitLines(ModuleDebugLineFragmentRef &Lines) { - return Error::success(); - } - - virtual Error - visitFileChecksums(ModuleDebugFileChecksumFragmentRef &Checksums) { - return Error::success(); - } - - virtual Error visitInlineeLines(ModuleDebugInlineeLineFragmentRef &Inlinees) { - return Error::success(); - } - - virtual Error finished() { return Error::success(); } -}; - -Error visitModuleDebugFragment(const ModuleDebugFragmentRecord &R, - ModuleDebugFragmentVisitor &V); - -template -Error visitModuleDebugFragments(T &&FragmentRange, - ModuleDebugFragmentVisitor &V) { - for (const auto &L : FragmentRange) { - if (auto EC = visitModuleDebugFragment(L, V)) - return EC; - } - if (auto EC = V.finished()) - return EC; - return Error::success(); -} - -} // end namespace codeview - -} // end namespace llvm - -#endif // LLVM_DEBUGINFO_CODEVIEW_MODULEDEBUGFRAGMENTVISITOR_H diff --git a/include/llvm/DebugInfo/CodeView/ModuleDebugInlineeLinesFragment.h b/include/llvm/DebugInfo/CodeView/ModuleDebugInlineeLinesFragment.h deleted file mode 100644 index 348497cbf7f2..000000000000 --- a/include/llvm/DebugInfo/CodeView/ModuleDebugInlineeLinesFragment.h +++ /dev/null @@ -1,106 +0,0 @@ -//===- ModuleDebugInlineeLinesFragment.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_DEBUGINFO_CODEVIEW_MODULEDEBUGINLINEELINESFRAGMENT_H -#define LLVM_DEBUGINFO_CODEVIEW_MODULEDEBUGINLINEELINESFRAGMENT_H - -#include "llvm/DebugInfo/CodeView/Line.h" -#include "llvm/DebugInfo/CodeView/ModuleDebugFragment.h" -#include "llvm/Support/BinaryStreamArray.h" -#include "llvm/Support/BinaryStreamReader.h" -#include "llvm/Support/Error.h" - -namespace llvm { -namespace codeview { - -class ModuleDebugInlineeLineFragmentRef; -class ModuleDebugFileChecksumFragment; -class StringTable; - -enum class InlineeLinesSignature : uint32_t { - Normal, // CV_INLINEE_SOURCE_LINE_SIGNATURE - ExtraFiles // CV_INLINEE_SOURCE_LINE_SIGNATURE_EX -}; - -struct InlineeSourceLineHeader { - TypeIndex Inlinee; // ID of the function that was inlined. - support::ulittle32_t FileID; // Offset into FileChecksums subsection. - support::ulittle32_t SourceLineNum; // First line of inlined code. - // If extra files present: - // ulittle32_t ExtraFileCount; - // ulittle32_t Files[]; -}; - -struct InlineeSourceLine { - const InlineeSourceLineHeader *Header; - FixedStreamArray ExtraFiles; -}; -} - -template <> struct VarStreamArrayExtractor { - typedef bool ContextType; - - static Error extract(BinaryStreamRef Stream, uint32_t &Len, - codeview::InlineeSourceLine &Item, bool HasExtraFiles); -}; - -namespace codeview { -class ModuleDebugInlineeLineFragmentRef final : public ModuleDebugFragmentRef { - typedef VarStreamArray LinesArray; - typedef LinesArray::Iterator Iterator; - -public: - ModuleDebugInlineeLineFragmentRef(); - - static bool classof(const ModuleDebugFragmentRef *S) { - return S->kind() == ModuleDebugFragmentKind::InlineeLines; - } - - Error initialize(BinaryStreamReader Reader); - bool hasExtraFiles() const; - - Iterator begin() const { return Lines.begin(); } - Iterator end() const { return Lines.end(); } - -private: - InlineeLinesSignature Signature; - VarStreamArray Lines; -}; - -class ModuleDebugInlineeLineFragment final : public ModuleDebugFragment { -public: - ModuleDebugInlineeLineFragment(ModuleDebugFileChecksumFragment &Checksums, - bool HasExtraFiles); - - static bool classof(const ModuleDebugFragment *S) { - return S->kind() == ModuleDebugFragmentKind::InlineeLines; - } - - Error commit(BinaryStreamWriter &Writer) override; - uint32_t calculateSerializedLength() override; - - void addInlineSite(TypeIndex FuncId, StringRef FileName, uint32_t SourceLine); - void addExtraFile(StringRef FileName); - -private: - ModuleDebugFileChecksumFragment &Checksums; - - bool HasExtraFiles = false; - uint32_t ExtraFileCount = 0; - - struct Entry { - std::vector ExtraFiles; - InlineeSourceLineHeader Header; - }; - std::vector Entries; -}; -} -} - -#endif diff --git a/include/llvm/DebugInfo/CodeView/ModuleDebugLineFragment.h b/include/llvm/DebugInfo/CodeView/ModuleDebugLineFragment.h deleted file mode 100644 index 3124236b8fb1..000000000000 --- a/include/llvm/DebugInfo/CodeView/ModuleDebugLineFragment.h +++ /dev/null @@ -1,143 +0,0 @@ -//===- ModuleDebugLineFragment.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_DEBUGINFO_CODEVIEW_MODULEDEBUGLINEFRAGMENT_H -#define LLVM_DEBUGINFO_CODEVIEW_MODULEDEBUGLINEFRAGMENT_H - -#include "llvm/DebugInfo/CodeView/Line.h" -#include "llvm/DebugInfo/CodeView/ModuleDebugFragment.h" -#include "llvm/Support/BinaryStreamArray.h" -#include "llvm/Support/BinaryStreamReader.h" -#include "llvm/Support/Error.h" - -namespace llvm { -namespace codeview { - -class ModuleDebugFileChecksumFragment; -class StringTable; - -// Corresponds to the `CV_DebugSLinesHeader_t` structure. -struct LineFragmentHeader { - support::ulittle32_t RelocOffset; // Code offset of line contribution. - support::ulittle16_t RelocSegment; // Code segment of line contribution. - support::ulittle16_t Flags; // See LineFlags enumeration. - support::ulittle32_t CodeSize; // Code size of this line contribution. -}; - -// Corresponds to the `CV_DebugSLinesFileBlockHeader_t` structure. -struct LineBlockFragmentHeader { - support::ulittle32_t NameIndex; // Offset of FileChecksum entry in File - // checksums buffer. The checksum entry then - // contains another offset into the string - // table of the actual name. - support::ulittle32_t NumLines; // Number of lines - support::ulittle32_t BlockSize; // Code size of block, in bytes. - // The following two variable length arrays appear immediately after the - // header. The structure definitions follow. - // LineNumberEntry Lines[NumLines]; - // ColumnNumberEntry Columns[NumLines]; -}; - -// Corresponds to `CV_Line_t` structure -struct LineNumberEntry { - support::ulittle32_t Offset; // Offset to start of code bytes for line number - support::ulittle32_t Flags; // Start:24, End:7, IsStatement:1 -}; - -// Corresponds to `CV_Column_t` structure -struct ColumnNumberEntry { - support::ulittle16_t StartColumn; - support::ulittle16_t EndColumn; -}; - -struct LineColumnEntry { - support::ulittle32_t NameIndex; - FixedStreamArray LineNumbers; - FixedStreamArray Columns; -}; - -class LineColumnExtractor { -public: - typedef const LineFragmentHeader *ContextType; - - static Error extract(BinaryStreamRef Stream, uint32_t &Len, - LineColumnEntry &Item, const LineFragmentHeader *Ctx); -}; - -class ModuleDebugLineFragmentRef final : public ModuleDebugFragmentRef { - friend class LineColumnExtractor; - typedef VarStreamArray LineInfoArray; - typedef LineInfoArray::Iterator Iterator; - -public: - ModuleDebugLineFragmentRef(); - - static bool classof(const ModuleDebugFragmentRef *S) { - return S->kind() == ModuleDebugFragmentKind::Lines; - } - - Error initialize(BinaryStreamReader Reader); - - Iterator begin() const { return LinesAndColumns.begin(); } - Iterator end() const { return LinesAndColumns.end(); } - - const LineFragmentHeader *header() const { return Header; } - - bool hasColumnInfo() const; - -private: - const LineFragmentHeader *Header = nullptr; - LineInfoArray LinesAndColumns; -}; - -class ModuleDebugLineFragment final : public ModuleDebugFragment { - struct Block { - Block(uint32_t ChecksumBufferOffset) - : ChecksumBufferOffset(ChecksumBufferOffset) {} - - uint32_t ChecksumBufferOffset; - std::vector Lines; - std::vector Columns; - }; - -public: - ModuleDebugLineFragment(ModuleDebugFileChecksumFragment &Checksums, - StringTable &Strings); - - static bool classof(const ModuleDebugFragment *S) { - return S->kind() == ModuleDebugFragmentKind::Lines; - } - - void createBlock(StringRef FileName); - void addLineInfo(uint32_t Offset, const LineInfo &Line); - void addLineAndColumnInfo(uint32_t Offset, const LineInfo &Line, - uint32_t ColStart, uint32_t ColEnd); - - uint32_t calculateSerializedLength() override; - Error commit(BinaryStreamWriter &Writer) override; - - void setRelocationAddress(uint16_t Segment, uint16_t Offset); - void setCodeSize(uint32_t Size); - void setFlags(LineFlags Flags); - - bool hasColumnInfo() const; - -private: - ModuleDebugFileChecksumFragment &Checksums; - - uint16_t RelocOffset = 0; - uint16_t RelocSegment = 0; - uint32_t CodeSize = 0; - LineFlags Flags = LF_None; - std::vector Blocks; -}; -} -} - -#endif diff --git a/include/llvm/DebugInfo/CodeView/ModuleDebugUnknownFragment.h b/include/llvm/DebugInfo/CodeView/ModuleDebugUnknownFragment.h deleted file mode 100644 index b8c1c02e5cf1..000000000000 --- a/include/llvm/DebugInfo/CodeView/ModuleDebugUnknownFragment.h +++ /dev/null @@ -1,33 +0,0 @@ -//===- ModuleDebugUnknownFragment.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_DEBUGINFO_CODEVIEW_MODULEDEBUGUNKNOWNFRAGMENT_H -#define LLVM_DEBUGINFO_CODEVIEW_MODULEDEBUGUNKNOWNFRAGMENT_H - -#include "llvm/DebugInfo/CodeView/ModuleDebugFragment.h" -#include "llvm/Support/BinaryStreamRef.h" - -namespace llvm { -namespace codeview { - -class ModuleDebugUnknownFragmentRef final : public ModuleDebugFragmentRef { -public: - ModuleDebugUnknownFragmentRef(ModuleDebugFragmentKind Kind, - BinaryStreamRef Data) - : ModuleDebugFragmentRef(Kind), Data(Data) {} - - BinaryStreamRef getData() const { return Data; } - -private: - BinaryStreamRef Data; -}; -} -} - -#endif diff --git a/include/llvm/DebugInfo/CodeView/StringTable.h b/include/llvm/DebugInfo/CodeView/StringTable.h deleted file mode 100644 index 05dc02ee849f..000000000000 --- a/include/llvm/DebugInfo/CodeView/StringTable.h +++ /dev/null @@ -1,75 +0,0 @@ -//===- StringTable.h - CodeView String Table Reader/Writer ------*- C++ -*-===// -// -// The LLVM Compiler Infrastructure -// -// This file is distributed under the University of Illinois Open Source -// License. See LICENSE.TXT for details. -// -//===----------------------------------------------------------------------===// - -#ifndef LLVM_DEBUGINFO_CODEVIEW_STRINGTABLE_H -#define LLVM_DEBUGINFO_CODEVIEW_STRINGTABLE_H - -#include "llvm/ADT/StringMap.h" -#include "llvm/ADT/StringRef.h" - -#include "llvm/Support/BinaryStreamRef.h" -#include "llvm/Support/Error.h" - -#include - -namespace llvm { - -class BinaryStreamReader; -class BinaryStreamRef; -class BinaryStreamWriter; - -namespace codeview { - -/// Represents a read-only view of a CodeView string table. This is a very -/// simple flat buffer consisting of null-terminated strings, where strings -/// are retrieved by their offset in the buffer. StringTableRef does not own -/// the underlying storage for the buffer. -class StringTableRef { -public: - StringTableRef(); - - Error initialize(BinaryStreamRef Contents); - - Expected getString(uint32_t Offset) const; - - bool valid() const { return Stream.valid(); } - -private: - BinaryStreamRef Stream; -}; - -/// Represents a read-write view of a CodeView string table. StringTable owns -/// the underlying storage for the table, and is capable of serializing the -/// string table into a format understood by StringTableRef. -class StringTable { -public: - // If string S does not exist in the string table, insert it. - // Returns the ID for S. - uint32_t insert(StringRef S); - - // Return the ID for string S. Assumes S exists in the table. - uint32_t getStringId(StringRef S) const; - - uint32_t calculateSerializedSize() const; - Error commit(BinaryStreamWriter &Writer) const; - - uint32_t size() const; - - StringMap::const_iterator begin() const { return Strings.begin(); } - - StringMap::const_iterator end() const { return Strings.end(); } - -private: - StringMap Strings; - uint32_t StringSize = 1; -}; -} -} - -#endif diff --git a/include/llvm/DebugInfo/CodeView/SymbolVisitorDelegate.h b/include/llvm/DebugInfo/CodeView/SymbolVisitorDelegate.h index 96c8a47a3669..a2a3c6f18fba 100644 --- a/include/llvm/DebugInfo/CodeView/SymbolVisitorDelegate.h +++ b/include/llvm/DebugInfo/CodeView/SymbolVisitorDelegate.h @@ -19,7 +19,7 @@ class BinaryStreamReader; namespace codeview { -class StringTableRef; +class DebugStringTableSubsectionRef; class SymbolVisitorDelegate { public: @@ -27,7 +27,7 @@ public: virtual uint32_t getRecordOffset(BinaryStreamReader Reader) = 0; virtual StringRef getFileNameForFileOffset(uint32_t FileOffset) = 0; - virtual StringTableRef getStringTable() = 0; + virtual DebugStringTableSubsectionRef getStringTable() = 0; }; } // end namespace codeview diff --git a/include/llvm/DebugInfo/PDB/Native/DbiModuleDescriptorBuilder.h b/include/llvm/DebugInfo/PDB/Native/DbiModuleDescriptorBuilder.h index 8cc5db981f56..e5858d0f45e3 100644 --- a/include/llvm/DebugInfo/PDB/Native/DbiModuleDescriptorBuilder.h +++ b/include/llvm/DebugInfo/PDB/Native/DbiModuleDescriptorBuilder.h @@ -11,9 +11,9 @@ #define LLVM_DEBUGINFO_PDB_RAW_DBIMODULEDESCRIPTORBUILDER_H #include "llvm/ADT/StringRef.h" -#include "llvm/DebugInfo/CodeView/ModuleDebugFileChecksumFragment.h" -#include "llvm/DebugInfo/CodeView/ModuleDebugInlineeLinesFragment.h" -#include "llvm/DebugInfo/CodeView/ModuleDebugLineFragment.h" +#include "llvm/DebugInfo/CodeView/DebugChecksumsSubsection.h" +#include "llvm/DebugInfo/CodeView/DebugInlineeLinesSubsection.h" +#include "llvm/DebugInfo/CodeView/DebugLinesSubsection.h" #include "llvm/DebugInfo/CodeView/SymbolRecord.h" #include "llvm/DebugInfo/PDB/Native/RawTypes.h" #include "llvm/Support/Error.h" @@ -25,7 +25,7 @@ namespace llvm { class BinaryStreamWriter; namespace codeview { -class ModuleDebugFragmentRecordBuilder; +class DebugSubsectionRecordBuilder; } namespace msf { @@ -49,11 +49,11 @@ public: void setObjFileName(StringRef Name); void addSymbol(codeview::CVSymbol Symbol); - void addC13Fragment(std::unique_ptr Lines); + void addC13Fragment(std::unique_ptr Lines); void addC13Fragment( - std::unique_ptr Inlinees); + std::unique_ptr Inlinees); void setC13FileChecksums( - std::unique_ptr Checksums); + std::unique_ptr Checksums); uint16_t getStreamIndex() const; StringRef getModuleName() const { return ModuleName; } @@ -83,12 +83,11 @@ private: std::vector SourceFiles; std::vector Symbols; - std::unique_ptr ChecksumInfo; - std::vector> LineInfo; - std::vector> - Inlinees; + std::unique_ptr ChecksumInfo; + std::vector> LineInfo; + std::vector> Inlinees; - std::vector> + std::vector> C13Builders; ModuleInfoHeader Layout; diff --git a/include/llvm/DebugInfo/PDB/Native/DbiStream.h b/include/llvm/DebugInfo/PDB/Native/DbiStream.h index 8f95481f4152..dc35f8c72cd9 100644 --- a/include/llvm/DebugInfo/PDB/Native/DbiStream.h +++ b/include/llvm/DebugInfo/PDB/Native/DbiStream.h @@ -10,7 +10,7 @@ #ifndef LLVM_DEBUGINFO_PDB_RAW_PDBDBISTREAM_H #define LLVM_DEBUGINFO_PDB_RAW_PDBDBISTREAM_H -#include "llvm/DebugInfo/CodeView/ModuleDebugFragment.h" +#include "llvm/DebugInfo/CodeView/DebugSubsection.h" #include "llvm/DebugInfo/MSF/MappedBlockStream.h" #include "llvm/DebugInfo/PDB/Native/DbiModuleDescriptor.h" #include "llvm/DebugInfo/PDB/Native/DbiModuleList.h" @@ -19,8 +19,6 @@ #include "llvm/DebugInfo/PDB/Native/RawTypes.h" #include "llvm/DebugInfo/PDB/PDBTypes.h" #include "llvm/Support/BinaryStreamArray.h" -#include "llvm/Support/BinaryStreamArray.h" -#include "llvm/Support/BinaryStreamRef.h" #include "llvm/Support/BinaryStreamRef.h" #include "llvm/Support/Endian.h" #include "llvm/Support/Error.h" diff --git a/include/llvm/DebugInfo/PDB/Native/ModuleDebugStream.h b/include/llvm/DebugInfo/PDB/Native/ModuleDebugStream.h index 2c95690ed580..822ce3ce13d3 100644 --- a/include/llvm/DebugInfo/PDB/Native/ModuleDebugStream.h +++ b/include/llvm/DebugInfo/PDB/Native/ModuleDebugStream.h @@ -12,7 +12,7 @@ #include "llvm/ADT/iterator_range.h" #include "llvm/DebugInfo/CodeView/CVRecord.h" -#include "llvm/DebugInfo/CodeView/ModuleDebugFragmentRecord.h" +#include "llvm/DebugInfo/CodeView/DebugSubsectionRecord.h" #include "llvm/DebugInfo/CodeView/SymbolRecord.h" #include "llvm/DebugInfo/MSF/MappedBlockStream.h" #include "llvm/Support/BinaryStreamArray.h" @@ -25,8 +25,7 @@ class PDBFile; class DbiModuleDescriptor; class ModuleDebugStreamRef { - typedef codeview::ModuleDebugFragmentArray::Iterator - LinesAndChecksumsIterator; + typedef codeview::DebugSubsectionArray::Iterator LinesAndChecksumsIterator; public: ModuleDebugStreamRef(const DbiModuleDescriptor &Module, @@ -58,7 +57,7 @@ private: BinaryStreamRef C13LinesSubstream; BinaryStreamRef GlobalRefsSubstream; - codeview::ModuleDebugFragmentArray LinesAndChecksums; + codeview::DebugSubsectionArray LinesAndChecksums; }; } } diff --git a/include/llvm/DebugInfo/PDB/Native/PDBStringTable.h b/include/llvm/DebugInfo/PDB/Native/PDBStringTable.h index 7c7f16bd1c73..6aeb0a5479cb 100644 --- a/include/llvm/DebugInfo/PDB/Native/PDBStringTable.h +++ b/include/llvm/DebugInfo/PDB/Native/PDBStringTable.h @@ -12,7 +12,7 @@ #include "llvm/ADT/ArrayRef.h" #include "llvm/ADT/StringRef.h" -#include "llvm/DebugInfo/CodeView/StringTable.h" +#include "llvm/DebugInfo/CodeView/DebugStringTableSubsection.h" #include "llvm/Support/BinaryStreamArray.h" #include "llvm/Support/BinaryStreamRef.h" #include "llvm/Support/Endian.h" @@ -52,7 +52,7 @@ private: Error readEpilogue(BinaryStreamReader &Reader); const PDBStringTableHeader *Header = nullptr; - codeview::StringTableRef Strings; + codeview::DebugStringTableSubsectionRef Strings; FixedStreamArray IDs; uint32_t ByteSize = 0; uint32_t NameCount = 0; diff --git a/include/llvm/DebugInfo/PDB/Native/PDBStringTableBuilder.h b/include/llvm/DebugInfo/PDB/Native/PDBStringTableBuilder.h index 6f85e7a4a074..0faa02dc4525 100644 --- a/include/llvm/DebugInfo/PDB/Native/PDBStringTableBuilder.h +++ b/include/llvm/DebugInfo/PDB/Native/PDBStringTableBuilder.h @@ -16,7 +16,7 @@ #include "llvm/ADT/DenseMap.h" #include "llvm/ADT/StringRef.h" -#include "llvm/DebugInfo/CodeView/StringTable.h" +#include "llvm/DebugInfo/CodeView/DebugStringTableSubsection.h" #include "llvm/Support/Error.h" #include @@ -41,8 +41,10 @@ public: uint32_t calculateSerializedSize() const; Error commit(BinaryStreamWriter &Writer) const; - codeview::StringTable &getStrings() { return Strings; } - const codeview::StringTable &getStrings() const { return Strings; } + codeview::DebugStringTableSubsection &getStrings() { return Strings; } + const codeview::DebugStringTableSubsection &getStrings() const { + return Strings; + } private: uint32_t calculateHashTableSize() const; @@ -51,7 +53,7 @@ private: Error writeHashTable(BinaryStreamWriter &Writer) const; Error writeEpilogue(BinaryStreamWriter &Writer) const; - codeview::StringTable Strings; + codeview::DebugStringTableSubsection Strings; }; } // end namespace pdb -- cgit v1.2.3