Index: llvm/trunk/include/llvm/DebugInfo/CodeView/CodeView.h =================================================================== --- llvm/trunk/include/llvm/DebugInfo/CodeView/CodeView.h +++ llvm/trunk/include/llvm/DebugInfo/CodeView/CodeView.h @@ -291,7 +291,7 @@ }; CV_DEFINE_ENUM_CLASS_FLAGS_OPERATORS(ModifierOptions) -enum class ModuleSubstreamKind : uint32_t { +enum class ModuleDebugFragmentKind : uint32_t { None = 0, Symbols = 0xf1, Lines = 0xf2, Index: llvm/trunk/include/llvm/DebugInfo/CodeView/ModuleDebugFragment.h =================================================================== --- llvm/trunk/include/llvm/DebugInfo/CodeView/ModuleDebugFragment.h +++ llvm/trunk/include/llvm/DebugInfo/CodeView/ModuleDebugFragment.h @@ -0,0 +1,87 @@ +//===- 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/BinaryStreamArray.h" +#include "llvm/Support/BinaryStreamRef.h" +#include "llvm/Support/Endian.h" +#include "llvm/Support/Error.h" + +namespace llvm { +namespace codeview { + +// 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. +}; + +// 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; // Index in DBI name buffer of filename. + 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; +}; + +class ModuleDebugFragment { +public: + ModuleDebugFragment(); + ModuleDebugFragment(ModuleDebugFragmentKind Kind, BinaryStreamRef Data); + static Error initialize(BinaryStreamRef Stream, ModuleDebugFragment &Info); + uint32_t getRecordLength() const; + ModuleDebugFragmentKind kind() const; + BinaryStreamRef getRecordData() const; + +private: + ModuleDebugFragmentKind Kind; + BinaryStreamRef Data; +}; + +typedef VarStreamArray ModuleDebugFragmentArray; +} // namespace codeview + +template <> struct VarStreamArrayExtractor { + Error operator()(BinaryStreamRef Stream, uint32_t &Length, + codeview::ModuleDebugFragment &Info) const { + if (auto EC = codeview::ModuleDebugFragment::initialize(Stream, Info)) + return EC; + Length = Info.getRecordLength(); + return Error::success(); + } +}; +} // namespace llvm + +#endif // LLVM_DEBUGINFO_CODEVIEW_MODULEDEBUGFRAGMENT_H Index: llvm/trunk/include/llvm/DebugInfo/CodeView/ModuleDebugFragmentVisitor.h =================================================================== --- llvm/trunk/include/llvm/DebugInfo/CodeView/ModuleDebugFragmentVisitor.h +++ llvm/trunk/include/llvm/DebugInfo/CodeView/ModuleDebugFragmentVisitor.h @@ -0,0 +1,132 @@ +//===- 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/ADT/ArrayRef.h" +#include "llvm/DebugInfo/CodeView/CodeView.h" +#include "llvm/DebugInfo/CodeView/CodeViewError.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/BinaryStreamRef.h" +#include "llvm/Support/Endian.h" +#include "llvm/Support/Error.h" +#include + +namespace llvm { + +namespace codeview { + +struct LineColumnEntry { + support::ulittle32_t NameIndex; + FixedStreamArray LineNumbers; + FixedStreamArray Columns; +}; + +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. +}; + +typedef VarStreamArray LineInfoArray; +typedef VarStreamArray FileChecksumArray; + +class ModuleDebugFragmentVisitor { +public: + virtual ~ModuleDebugFragmentVisitor() = default; + + virtual Error visitUnknown(ModuleDebugFragmentKind Kind, + BinaryStreamRef Data) = 0; + virtual Error visitSymbols(BinaryStreamRef Data); + virtual Error visitLines(BinaryStreamRef Data, + const LineFragmentHeader *Header, + const LineInfoArray &Lines); + virtual Error visitStringTable(BinaryStreamRef Data); + virtual Error visitFileChecksums(BinaryStreamRef Data, + const FileChecksumArray &Checksums); + virtual Error visitFrameData(BinaryStreamRef Data); + virtual Error visitInlineeLines(BinaryStreamRef Data); + virtual Error visitCrossScopeImports(BinaryStreamRef Data); + virtual Error visitCrossScopeExports(BinaryStreamRef Data); + virtual Error visitILLines(BinaryStreamRef Data); + virtual Error visitFuncMDTokenMap(BinaryStreamRef Data); + virtual Error visitTypeMDTokenMap(BinaryStreamRef Data); + virtual Error visitMergedAssemblyInput(BinaryStreamRef Data); + virtual Error visitCoffSymbolRVA(BinaryStreamRef Data); +}; + +Error visitModuleDebugFragment(const ModuleDebugFragment &R, + ModuleDebugFragmentVisitor &V); +} // end namespace codeview + +template <> class VarStreamArrayExtractor { +public: + VarStreamArrayExtractor(const codeview::LineFragmentHeader *Header) + : Header(Header) {} + + Error operator()(BinaryStreamRef Stream, uint32_t &Len, + codeview::LineColumnEntry &Item) const { + using namespace codeview; + const LineBlockFragmentHeader *BlockHeader; + BinaryStreamReader Reader(Stream); + if (auto EC = Reader.readObject(BlockHeader)) + return EC; + bool HasColumn = Header->Flags & uint32_t(LineFlags::HaveColumns); + uint32_t LineInfoSize = + BlockHeader->NumLines * + (sizeof(LineNumberEntry) + (HasColumn ? sizeof(ColumnNumberEntry) : 0)); + if (BlockHeader->BlockSize < sizeof(LineBlockFragmentHeader)) + return make_error(cv_error_code::corrupt_record, + "Invalid line block record size"); + uint32_t Size = BlockHeader->BlockSize - sizeof(LineBlockFragmentHeader); + if (LineInfoSize > Size) + return make_error(cv_error_code::corrupt_record, + "Invalid line block record size"); + // The value recorded in BlockHeader->BlockSize includes the size of + // LineBlockFragmentHeader. + Len = BlockHeader->BlockSize; + Item.NameIndex = BlockHeader->NameIndex; + if (auto EC = Reader.readArray(Item.LineNumbers, BlockHeader->NumLines)) + return EC; + if (HasColumn) { + if (auto EC = Reader.readArray(Item.Columns, BlockHeader->NumLines)) + return EC; + } + return Error::success(); + } + +private: + const codeview::LineFragmentHeader *Header; +}; + +template <> class VarStreamArrayExtractor { +public: + Error operator()(BinaryStreamRef Stream, uint32_t &Len, + codeview::FileChecksumEntry &Item) const { + using namespace codeview; + const FileChecksum *Header; + BinaryStreamReader Reader(Stream); + if (auto EC = Reader.readObject(Header)) + return EC; + Item.FileNameOffset = Header->FileNameOffset; + Item.Kind = static_cast(Header->ChecksumKind); + if (auto EC = Reader.readBytes(Item.Checksum, Header->ChecksumSize)) + return EC; + Len = sizeof(FileChecksum) + Header->ChecksumSize; + return Error::success(); + } +}; + +} // end namespace llvm + +#endif // LLVM_DEBUGINFO_CODEVIEW_MODULEDEBUGFRAGMENTVISITOR_H Index: llvm/trunk/include/llvm/DebugInfo/CodeView/ModuleSubstream.h =================================================================== --- llvm/trunk/include/llvm/DebugInfo/CodeView/ModuleSubstream.h +++ llvm/trunk/include/llvm/DebugInfo/CodeView/ModuleSubstream.h @@ -1,87 +0,0 @@ -//===- ModuleSubstream.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_MODULESUBSTREAM_H -#define LLVM_DEBUGINFO_CODEVIEW_MODULESUBSTREAM_H - -#include "llvm/DebugInfo/CodeView/CodeView.h" -#include "llvm/Support/BinaryStreamArray.h" -#include "llvm/Support/BinaryStreamRef.h" -#include "llvm/Support/Endian.h" -#include "llvm/Support/Error.h" - -namespace llvm { -namespace codeview { - -// Corresponds to the `CV_DebugSSubsectionHeader_t` structure. -struct ModuleSubsectionHeader { - support::ulittle32_t Kind; // codeview::ModuleSubstreamKind enum - support::ulittle32_t Length; // number of bytes occupied by this record. -}; - -// Corresponds to the `CV_DebugSLinesHeader_t` structure. -struct LineSubstreamHeader { - 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 LineFileBlockHeader { - support::ulittle32_t NameIndex; // Index in DBI name buffer of filename. - 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; -}; - -class ModuleSubstream { -public: - ModuleSubstream(); - ModuleSubstream(ModuleSubstreamKind Kind, BinaryStreamRef Data); - static Error initialize(BinaryStreamRef Stream, ModuleSubstream &Info); - uint32_t getRecordLength() const; - ModuleSubstreamKind getSubstreamKind() const; - BinaryStreamRef getRecordData() const; - -private: - ModuleSubstreamKind Kind; - BinaryStreamRef Data; -}; - -typedef VarStreamArray ModuleSubstreamArray; -} // namespace codeview - -template <> struct VarStreamArrayExtractor { - Error operator()(BinaryStreamRef Stream, uint32_t &Length, - codeview::ModuleSubstream &Info) const { - if (auto EC = codeview::ModuleSubstream::initialize(Stream, Info)) - return EC; - Length = Info.getRecordLength(); - return Error::success(); - } -}; -} // namespace llvm - -#endif // LLVM_DEBUGINFO_CODEVIEW_MODULESUBSTREAM_H Index: llvm/trunk/include/llvm/DebugInfo/CodeView/ModuleSubstreamVisitor.h =================================================================== --- llvm/trunk/include/llvm/DebugInfo/CodeView/ModuleSubstreamVisitor.h +++ llvm/trunk/include/llvm/DebugInfo/CodeView/ModuleSubstreamVisitor.h @@ -1,132 +0,0 @@ -//===- ModuleSubstreamVisitor.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_MODULESUBSTREAMVISITOR_H -#define LLVM_DEBUGINFO_CODEVIEW_MODULESUBSTREAMVISITOR_H - -#include "llvm/ADT/ArrayRef.h" -#include "llvm/DebugInfo/CodeView/CodeView.h" -#include "llvm/DebugInfo/CodeView/CodeViewError.h" -#include "llvm/DebugInfo/CodeView/Line.h" -#include "llvm/DebugInfo/CodeView/ModuleSubstream.h" -#include "llvm/Support/BinaryStreamArray.h" -#include "llvm/Support/BinaryStreamReader.h" -#include "llvm/Support/BinaryStreamRef.h" -#include "llvm/Support/Endian.h" -#include "llvm/Support/Error.h" -#include - -namespace llvm { - -namespace codeview { - -struct LineColumnEntry { - support::ulittle32_t NameIndex; - FixedStreamArray LineNumbers; - FixedStreamArray Columns; -}; - -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. -}; - -typedef VarStreamArray LineInfoArray; -typedef VarStreamArray FileChecksumArray; - -class IModuleSubstreamVisitor { -public: - virtual ~IModuleSubstreamVisitor() = default; - - virtual Error visitUnknown(ModuleSubstreamKind Kind, - BinaryStreamRef Data) = 0; - virtual Error visitSymbols(BinaryStreamRef Data); - virtual Error visitLines(BinaryStreamRef Data, - const LineSubstreamHeader *Header, - const LineInfoArray &Lines); - virtual Error visitStringTable(BinaryStreamRef Data); - virtual Error visitFileChecksums(BinaryStreamRef Data, - const FileChecksumArray &Checksums); - virtual Error visitFrameData(BinaryStreamRef Data); - virtual Error visitInlineeLines(BinaryStreamRef Data); - virtual Error visitCrossScopeImports(BinaryStreamRef Data); - virtual Error visitCrossScopeExports(BinaryStreamRef Data); - virtual Error visitILLines(BinaryStreamRef Data); - virtual Error visitFuncMDTokenMap(BinaryStreamRef Data); - virtual Error visitTypeMDTokenMap(BinaryStreamRef Data); - virtual Error visitMergedAssemblyInput(BinaryStreamRef Data); - virtual Error visitCoffSymbolRVA(BinaryStreamRef Data); -}; - -Error visitModuleSubstream(const ModuleSubstream &R, - IModuleSubstreamVisitor &V); -} // end namespace codeview - -template <> class VarStreamArrayExtractor { -public: - VarStreamArrayExtractor(const codeview::LineSubstreamHeader *Header) - : Header(Header) {} - - Error operator()(BinaryStreamRef Stream, uint32_t &Len, - codeview::LineColumnEntry &Item) const { - using namespace codeview; - const LineFileBlockHeader *BlockHeader; - BinaryStreamReader Reader(Stream); - if (auto EC = Reader.readObject(BlockHeader)) - return EC; - bool HasColumn = Header->Flags & uint32_t(LineFlags::HaveColumns); - uint32_t LineInfoSize = - BlockHeader->NumLines * - (sizeof(LineNumberEntry) + (HasColumn ? sizeof(ColumnNumberEntry) : 0)); - if (BlockHeader->BlockSize < sizeof(LineFileBlockHeader)) - return make_error(cv_error_code::corrupt_record, - "Invalid line block record size"); - uint32_t Size = BlockHeader->BlockSize - sizeof(LineFileBlockHeader); - if (LineInfoSize > Size) - return make_error(cv_error_code::corrupt_record, - "Invalid line block record size"); - // The value recorded in BlockHeader->BlockSize includes the size of - // LineFileBlockHeader. - Len = BlockHeader->BlockSize; - Item.NameIndex = BlockHeader->NameIndex; - if (auto EC = Reader.readArray(Item.LineNumbers, BlockHeader->NumLines)) - return EC; - if (HasColumn) { - if (auto EC = Reader.readArray(Item.Columns, BlockHeader->NumLines)) - return EC; - } - return Error::success(); - } - -private: - const codeview::LineSubstreamHeader *Header; -}; - -template <> class VarStreamArrayExtractor { -public: - Error operator()(BinaryStreamRef Stream, uint32_t &Len, - codeview::FileChecksumEntry &Item) const { - using namespace codeview; - const FileChecksum *Header; - BinaryStreamReader Reader(Stream); - if (auto EC = Reader.readObject(Header)) - return EC; - Item.FileNameOffset = Header->FileNameOffset; - Item.Kind = static_cast(Header->ChecksumKind); - if (auto EC = Reader.readBytes(Item.Checksum, Header->ChecksumSize)) - return EC; - Len = sizeof(FileChecksum) + Header->ChecksumSize; - return Error::success(); - } -}; - -} // end namespace llvm - -#endif // LLVM_DEBUGINFO_CODEVIEW_MODULESUBSTREAMVISITOR_H Index: llvm/trunk/include/llvm/DebugInfo/PDB/Native/DbiModuleDescriptor.h =================================================================== --- llvm/trunk/include/llvm/DebugInfo/PDB/Native/DbiModuleDescriptor.h +++ llvm/trunk/include/llvm/DebugInfo/PDB/Native/DbiModuleDescriptor.h @@ -0,0 +1,78 @@ +//===- DbiModuleDescriptor.h - PDB module information -----------*- 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_PDB_RAW_DBIMODULEDESCRIPTOR_H +#define LLVM_DEBUGINFO_PDB_RAW_DBIMODULEDESCRIPTOR_H + +#include "llvm/ADT/StringRef.h" +#include "llvm/DebugInfo/PDB/Native/RawTypes.h" +#include "llvm/Support/BinaryStreamArray.h" +#include "llvm/Support/BinaryStreamRef.h" +#include "llvm/Support/Error.h" +#include +#include + +namespace llvm { + +namespace pdb { + +class DbiModuleDescriptor { + friend class DbiStreamBuilder; + +public: + DbiModuleDescriptor(); + DbiModuleDescriptor(const DbiModuleDescriptor &Info); + ~DbiModuleDescriptor(); + + static Error initialize(BinaryStreamRef Stream, DbiModuleDescriptor &Info); + + bool hasECInfo() const; + uint16_t getTypeServerIndex() const; + uint16_t getModuleStreamIndex() const; + uint32_t getSymbolDebugInfoByteSize() const; + uint32_t getLineInfoByteSize() const; + uint32_t getC13LineInfoByteSize() const; + uint32_t getNumberOfFiles() const; + uint32_t getSourceFileNameIndex() const; + uint32_t getPdbFilePathNameIndex() const; + + StringRef getModuleName() const; + StringRef getObjFileName() const; + + uint32_t getRecordLength() const; + +private: + StringRef ModuleName; + StringRef ObjFileName; + const ModuleInfoHeader *Layout = nullptr; +}; + +struct ModuleInfoEx { + ModuleInfoEx(const DbiModuleDescriptor &Info) : Info(Info) {} + ModuleInfoEx(const ModuleInfoEx &Ex) = default; + + DbiModuleDescriptor Info; + std::vector SourceFiles; +}; + +} // end namespace pdb + +template <> struct VarStreamArrayExtractor { + Error operator()(BinaryStreamRef Stream, uint32_t &Length, + pdb::DbiModuleDescriptor &Info) const { + if (auto EC = pdb::DbiModuleDescriptor::initialize(Stream, Info)) + return EC; + Length = Info.getRecordLength(); + return Error::success(); + } +}; + +} // end namespace llvm + +#endif // LLVM_DEBUGINFO_PDB_RAW_DBIMODULEDESCRIPTOR_H Index: llvm/trunk/include/llvm/DebugInfo/PDB/Native/DbiModuleDescriptorBuilder.h =================================================================== --- llvm/trunk/include/llvm/DebugInfo/PDB/Native/DbiModuleDescriptorBuilder.h +++ llvm/trunk/include/llvm/DebugInfo/PDB/Native/DbiModuleDescriptorBuilder.h @@ -0,0 +1,76 @@ +//===- DbiModuleDescriptorBuilder.h - PDB module information ----*- 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_PDB_RAW_DBIMODULEDESCRIPTORBUILDER_H +#define LLVM_DEBUGINFO_PDB_RAW_DBIMODULEDESCRIPTORBUILDER_H + +#include "llvm/ADT/StringRef.h" +#include "llvm/DebugInfo/CodeView/SymbolRecord.h" +#include "llvm/DebugInfo/PDB/Native/RawTypes.h" +#include "llvm/Support/Error.h" +#include +#include +#include + +namespace llvm { +class BinaryStreamWriter; + +namespace msf { +class MSFBuilder; +struct MSFLayout; +} +namespace pdb { + +class DbiModuleDescriptorBuilder { + friend class DbiStreamBuilder; + +public: + DbiModuleDescriptorBuilder(StringRef ModuleName, uint32_t ModIndex, + msf::MSFBuilder &Msf); + + DbiModuleDescriptorBuilder(const DbiModuleDescriptorBuilder &) = delete; + DbiModuleDescriptorBuilder & + operator=(const DbiModuleDescriptorBuilder &) = delete; + + void setObjFileName(StringRef Name); + void addSymbol(codeview::CVSymbol Symbol); + + uint16_t getStreamIndex() const; + StringRef getModuleName() const { return ModuleName; } + StringRef getObjFileName() const { return ObjFileName; } + + ArrayRef source_files() const { + return makeArrayRef(SourceFiles); + } + + uint32_t calculateSerializedLength() const; + + void finalize(); + Error finalizeMsfLayout(); + + Error commit(BinaryStreamWriter &ModiWriter, const msf::MSFLayout &MsfLayout, + WritableBinaryStreamRef MsfBuffer); + +private: + void addSourceFile(StringRef Path); + msf::MSFBuilder &MSF; + + uint32_t SymbolByteSize = 0; + std::string ModuleName; + std::string ObjFileName; + std::vector SourceFiles; + std::vector Symbols; + ModuleInfoHeader Layout; +}; + +} // end namespace pdb + +} // end namespace llvm + +#endif // LLVM_DEBUGINFO_PDB_RAW_DBIMODULEDESCRIPTORBUILDER_H Index: llvm/trunk/include/llvm/DebugInfo/PDB/Native/DbiStream.h =================================================================== --- llvm/trunk/include/llvm/DebugInfo/PDB/Native/DbiStream.h +++ llvm/trunk/include/llvm/DebugInfo/PDB/Native/DbiStream.h @@ -10,9 +10,9 @@ #ifndef LLVM_DEBUGINFO_PDB_RAW_PDBDBISTREAM_H #define LLVM_DEBUGINFO_PDB_RAW_PDBDBISTREAM_H -#include "llvm/DebugInfo/CodeView/ModuleSubstream.h" +#include "llvm/DebugInfo/CodeView/ModuleDebugFragment.h" #include "llvm/DebugInfo/MSF/MappedBlockStream.h" -#include "llvm/DebugInfo/PDB/Native/ModInfo.h" +#include "llvm/DebugInfo/PDB/Native/DbiModuleDescriptor.h" #include "llvm/DebugInfo/PDB/Native/RawConstants.h" #include "llvm/DebugInfo/PDB/Native/RawTypes.h" #include "llvm/DebugInfo/PDB/Native/StringTable.h" Index: llvm/trunk/include/llvm/DebugInfo/PDB/Native/DbiStreamBuilder.h =================================================================== --- llvm/trunk/include/llvm/DebugInfo/PDB/Native/DbiStreamBuilder.h +++ llvm/trunk/include/llvm/DebugInfo/PDB/Native/DbiStreamBuilder.h @@ -31,7 +31,7 @@ namespace pdb { class DbiStream; struct DbiStreamHeader; -class ModInfoBuilder; +class DbiModuleDescriptorBuilder; class PDBFile; class DbiStreamBuilder { @@ -57,7 +57,7 @@ uint32_t calculateSerializedLength() const; - Expected addModuleInfo(StringRef ModuleName); + Expected addModuleInfo(StringRef ModuleName); Error addModuleSourceFile(StringRef Module, StringRef File); Error finalizeMsfLayout(); @@ -103,8 +103,8 @@ const DbiStreamHeader *Header; - StringMap> ModiMap; - std::vector ModiList; + StringMap> ModiMap; + std::vector ModiList; StringMap SourceFileNames; Index: llvm/trunk/include/llvm/DebugInfo/PDB/Native/ModInfo.h =================================================================== --- llvm/trunk/include/llvm/DebugInfo/PDB/Native/ModInfo.h +++ llvm/trunk/include/llvm/DebugInfo/PDB/Native/ModInfo.h @@ -1,78 +0,0 @@ -//===- ModInfo.h - PDB module information -----------------------*- 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_PDB_RAW_MODINFO_H -#define LLVM_DEBUGINFO_PDB_RAW_MODINFO_H - -#include "llvm/ADT/StringRef.h" -#include "llvm/DebugInfo/PDB/Native/RawTypes.h" -#include "llvm/Support/BinaryStreamArray.h" -#include "llvm/Support/BinaryStreamRef.h" -#include "llvm/Support/Error.h" -#include -#include - -namespace llvm { - -namespace pdb { - -class ModInfo { - friend class DbiStreamBuilder; - -public: - ModInfo(); - ModInfo(const ModInfo &Info); - ~ModInfo(); - - static Error initialize(BinaryStreamRef Stream, ModInfo &Info); - - bool hasECInfo() const; - uint16_t getTypeServerIndex() const; - uint16_t getModuleStreamIndex() const; - uint32_t getSymbolDebugInfoByteSize() const; - uint32_t getLineInfoByteSize() const; - uint32_t getC13LineInfoByteSize() const; - uint32_t getNumberOfFiles() const; - uint32_t getSourceFileNameIndex() const; - uint32_t getPdbFilePathNameIndex() const; - - StringRef getModuleName() const; - StringRef getObjFileName() const; - - uint32_t getRecordLength() const; - -private: - StringRef ModuleName; - StringRef ObjFileName; - const ModuleInfoHeader *Layout = nullptr; -}; - -struct ModuleInfoEx { - ModuleInfoEx(const ModInfo &Info) : Info(Info) {} - ModuleInfoEx(const ModuleInfoEx &Ex) = default; - - ModInfo Info; - std::vector SourceFiles; -}; - -} // end namespace pdb - -template <> struct VarStreamArrayExtractor { - Error operator()(BinaryStreamRef Stream, uint32_t &Length, - pdb::ModInfo &Info) const { - if (auto EC = pdb::ModInfo::initialize(Stream, Info)) - return EC; - Length = Info.getRecordLength(); - return Error::success(); - } -}; - -} // end namespace llvm - -#endif // LLVM_DEBUGINFO_PDB_RAW_MODINFO_H Index: llvm/trunk/include/llvm/DebugInfo/PDB/Native/ModInfoBuilder.h =================================================================== --- llvm/trunk/include/llvm/DebugInfo/PDB/Native/ModInfoBuilder.h +++ llvm/trunk/include/llvm/DebugInfo/PDB/Native/ModInfoBuilder.h @@ -1,74 +0,0 @@ -//===- ModInfoBuilder.h - PDB module information ----------------*- 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_PDB_RAW_MODINFOBUILDER_H -#define LLVM_DEBUGINFO_PDB_RAW_MODINFOBUILDER_H - -#include "llvm/ADT/StringRef.h" -#include "llvm/DebugInfo/CodeView/SymbolRecord.h" -#include "llvm/DebugInfo/PDB/Native/RawTypes.h" -#include "llvm/Support/Error.h" -#include -#include -#include - -namespace llvm { -class BinaryStreamWriter; - -namespace msf { -class MSFBuilder; -struct MSFLayout; -} -namespace pdb { - -class ModInfoBuilder { - friend class DbiStreamBuilder; - -public: - ModInfoBuilder(StringRef ModuleName, uint32_t ModIndex, msf::MSFBuilder &Msf); - - ModInfoBuilder(const ModInfoBuilder &) = delete; - ModInfoBuilder &operator=(const ModInfoBuilder &) = delete; - - void setObjFileName(StringRef Name); - void addSymbol(codeview::CVSymbol Symbol); - - uint16_t getStreamIndex() const; - StringRef getModuleName() const { return ModuleName; } - StringRef getObjFileName() const { return ObjFileName; } - - ArrayRef source_files() const { - return makeArrayRef(SourceFiles); - } - - uint32_t calculateSerializedLength() const; - - void finalize(); - Error finalizeMsfLayout(); - - Error commit(BinaryStreamWriter &ModiWriter, const msf::MSFLayout &MsfLayout, - WritableBinaryStreamRef MsfBuffer); - -private: - void addSourceFile(StringRef Path); - msf::MSFBuilder &MSF; - - uint32_t SymbolByteSize = 0; - std::string ModuleName; - std::string ObjFileName; - std::vector SourceFiles; - std::vector Symbols; - ModuleInfoHeader Layout; -}; - -} // end namespace pdb - -} // end namespace llvm - -#endif // LLVM_DEBUGINFO_PDB_RAW_MODINFOBUILDER_H Index: llvm/trunk/include/llvm/DebugInfo/PDB/Native/ModStream.h =================================================================== --- llvm/trunk/include/llvm/DebugInfo/PDB/Native/ModStream.h +++ llvm/trunk/include/llvm/DebugInfo/PDB/Native/ModStream.h @@ -1,64 +0,0 @@ -//===- ModStream.h - PDB Module Info Stream Access ------------------------===// -// -// The LLVM Compiler Infrastructure -// -// This file is distributed under the University of Illinois Open Source -// License. See LICENSE.TXT for details. -// -//===----------------------------------------------------------------------===// - -#ifndef LLVM_DEBUGINFO_PDB_RAW_MODSTREAM_H -#define LLVM_DEBUGINFO_PDB_RAW_MODSTREAM_H - -#include "llvm/ADT/iterator_range.h" -#include "llvm/DebugInfo/CodeView/CVRecord.h" -#include "llvm/DebugInfo/CodeView/ModuleSubstream.h" -#include "llvm/DebugInfo/CodeView/SymbolRecord.h" -#include "llvm/DebugInfo/MSF/MappedBlockStream.h" -#include "llvm/Support/BinaryStreamArray.h" -#include "llvm/Support/BinaryStreamRef.h" -#include "llvm/Support/Error.h" - -namespace llvm { -namespace pdb { -class PDBFile; -class ModInfo; - -class ModStream { -public: - ModStream(const ModInfo &Module, - std::unique_ptr Stream); - ~ModStream(); - - Error reload(); - - uint32_t signature() const { return Signature; } - - iterator_range - symbols(bool *HadError) const; - - iterator_range - lines(bool *HadError) const; - - bool hasLineInfo() const; - - Error commit(); - -private: - const ModInfo &Mod; - - uint32_t Signature; - - std::unique_ptr Stream; - - codeview::CVSymbolArray SymbolsSubstream; - BinaryStreamRef LinesSubstream; - BinaryStreamRef C13LinesSubstream; - BinaryStreamRef GlobalRefsSubstream; - - codeview::ModuleSubstreamArray LineInfo; -}; -} -} - -#endif Index: llvm/trunk/include/llvm/DebugInfo/PDB/Native/ModuleDebugStream.h =================================================================== --- llvm/trunk/include/llvm/DebugInfo/PDB/Native/ModuleDebugStream.h +++ llvm/trunk/include/llvm/DebugInfo/PDB/Native/ModuleDebugStream.h @@ -0,0 +1,64 @@ +//===- ModuleDebugStream.h - PDB Module Info Stream Access ----------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is distributed under the University of Illinois Open Source +// License. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +#ifndef LLVM_DEBUGINFO_PDB_RAW_MODULEDEBUGSTREAM_H +#define LLVM_DEBUGINFO_PDB_RAW_MODULEDEBUGSTREAM_H + +#include "llvm/ADT/iterator_range.h" +#include "llvm/DebugInfo/CodeView/CVRecord.h" +#include "llvm/DebugInfo/CodeView/ModuleDebugFragment.h" +#include "llvm/DebugInfo/CodeView/SymbolRecord.h" +#include "llvm/DebugInfo/MSF/MappedBlockStream.h" +#include "llvm/Support/BinaryStreamArray.h" +#include "llvm/Support/BinaryStreamRef.h" +#include "llvm/Support/Error.h" + +namespace llvm { +namespace pdb { +class PDBFile; +class DbiModuleDescriptor; + +class ModuleDebugStream { +public: + ModuleDebugStream(const DbiModuleDescriptor &Module, + std::unique_ptr Stream); + ~ModuleDebugStream(); + + Error reload(); + + uint32_t signature() const { return Signature; } + + iterator_range + symbols(bool *HadError) const; + + iterator_range + lines(bool *HadError) const; + + bool hasLineInfo() const; + + Error commit(); + +private: + const DbiModuleDescriptor &Mod; + + uint32_t Signature; + + std::unique_ptr Stream; + + codeview::CVSymbolArray SymbolsSubstream; + BinaryStreamRef LinesSubstream; + BinaryStreamRef C13LinesSubstream; + BinaryStreamRef GlobalRefsSubstream; + + codeview::ModuleDebugFragmentArray LineInfo; +}; +} +} + +#endif Index: llvm/trunk/include/llvm/DebugInfo/PDB/Native/NativeCompilandSymbol.h =================================================================== --- llvm/trunk/include/llvm/DebugInfo/PDB/Native/NativeCompilandSymbol.h +++ llvm/trunk/include/llvm/DebugInfo/PDB/Native/NativeCompilandSymbol.h @@ -10,7 +10,7 @@ #ifndef LLVM_DEBUGINFO_PDB_NATIVE_NATIVECOMPILANDSYMBOL_H #define LLVM_DEBUGINFO_PDB_NATIVE_NATIVECOMPILANDSYMBOL_H -#include "llvm/DebugInfo/PDB/Native/ModInfo.h" +#include "llvm/DebugInfo/PDB/Native/DbiModuleDescriptor.h" #include "llvm/DebugInfo/PDB/Native/NativeRawSymbol.h" namespace llvm { Index: llvm/trunk/include/llvm/DebugInfo/PDB/Native/NativeEnumModules.h =================================================================== --- llvm/trunk/include/llvm/DebugInfo/PDB/Native/NativeEnumModules.h +++ llvm/trunk/include/llvm/DebugInfo/PDB/Native/NativeEnumModules.h @@ -11,7 +11,7 @@ #define LLVM_DEBUGINFO_PDB_NATIVE_NATIVEENUMMODULES_H #include "llvm/DebugInfo/PDB/IPDBEnumChildren.h" -#include "llvm/DebugInfo/PDB/Native/ModInfo.h" +#include "llvm/DebugInfo/PDB/Native/DbiModuleDescriptor.h" #include "llvm/DebugInfo/PDB/PDBSymbol.h" namespace llvm { namespace pdb { Index: llvm/trunk/include/llvm/DebugInfo/PDB/Native/RawTypes.h =================================================================== --- llvm/trunk/include/llvm/DebugInfo/PDB/Native/RawTypes.h +++ llvm/trunk/include/llvm/DebugInfo/PDB/Native/RawTypes.h @@ -200,7 +200,7 @@ }; struct ModInfoFlags { - /// uint16_t fWritten : 1; // True if ModInfo is dirty + /// uint16_t fWritten : 1; // True if DbiModuleDescriptor is dirty /// uint16_t fECEnabled : 1; // Is EC symbolic info present? (What is EC?) /// uint16_t unused : 6; // Reserved /// uint16_t iTSM : 8; // Type Server Index for this module Index: llvm/trunk/include/llvm/DebugInfo/Symbolize/Symbolize.h =================================================================== --- llvm/trunk/include/llvm/DebugInfo/Symbolize/Symbolize.h +++ llvm/trunk/include/llvm/DebugInfo/Symbolize/Symbolize.h @@ -56,8 +56,9 @@ Expected symbolizeData(const std::string &ModuleName, uint64_t ModuleOffset); void flush(); - static std::string DemangleName(const std::string &Name, - const SymbolizableModule *ModInfo); + static std::string + DemangleName(const std::string &Name, + const SymbolizableModule *DbiModuleDescriptor); private: // Bundles together object file with code/data and object file with Index: llvm/trunk/lib/CodeGen/AsmPrinter/CodeViewDebug.h =================================================================== --- llvm/trunk/lib/CodeGen/AsmPrinter/CodeViewDebug.h +++ llvm/trunk/lib/CodeGen/AsmPrinter/CodeViewDebug.h @@ -216,7 +216,7 @@ /// Opens a subsection of the given kind in a .debug$S codeview section. /// Returns an end label for use with endCVSubsection when the subsection is /// finished. - MCSymbol *beginCVSubsection(codeview::ModuleSubstreamKind Kind); + MCSymbol *beginCVSubsection(codeview::ModuleDebugFragmentKind Kind); void endCVSubsection(MCSymbol *EndLabel); Index: llvm/trunk/lib/CodeGen/AsmPrinter/CodeViewDebug.cpp =================================================================== --- llvm/trunk/lib/CodeGen/AsmPrinter/CodeViewDebug.cpp +++ llvm/trunk/lib/CodeGen/AsmPrinter/CodeViewDebug.cpp @@ -392,7 +392,7 @@ // subprograms. switchToDebugSectionForSymbol(nullptr); - MCSymbol *CompilerInfo = beginCVSubsection(ModuleSubstreamKind::Symbols); + MCSymbol *CompilerInfo = beginCVSubsection(ModuleDebugFragmentKind::Symbols); emitCompilerInformation(); endCVSubsection(CompilerInfo); @@ -416,7 +416,7 @@ // Emit UDT records for any types used by global variables. if (!GlobalUDTs.empty()) { - MCSymbol *SymbolsEnd = beginCVSubsection(ModuleSubstreamKind::Symbols); + MCSymbol *SymbolsEnd = beginCVSubsection(ModuleDebugFragmentKind::Symbols); emitDebugInfoForUDTs(GlobalUDTs); endCVSubsection(SymbolsEnd); } @@ -644,7 +644,8 @@ return; OS.AddComment("Inlinee lines subsection"); - MCSymbol *InlineEnd = beginCVSubsection(ModuleSubstreamKind::InlineeLines); + MCSymbol *InlineEnd = + beginCVSubsection(ModuleDebugFragmentKind::InlineeLines); // We don't provide any extra file info. // FIXME: Find out if debuggers use this info. @@ -769,7 +770,7 @@ // Emit a symbol subsection, required by VS2012+ to find function boundaries. OS.AddComment("Symbol subsection for " + Twine(FuncName)); - MCSymbol *SymbolsEnd = beginCVSubsection(ModuleSubstreamKind::Symbols); + MCSymbol *SymbolsEnd = beginCVSubsection(ModuleDebugFragmentKind::Symbols); { MCSymbol *ProcRecordBegin = MMI->getContext().createTempSymbol(), *ProcRecordEnd = MMI->getContext().createTempSymbol(); @@ -2114,7 +2115,7 @@ maybeRecordLocation(DL, Asm->MF); } -MCSymbol *CodeViewDebug::beginCVSubsection(ModuleSubstreamKind Kind) { +MCSymbol *CodeViewDebug::beginCVSubsection(ModuleDebugFragmentKind Kind) { MCSymbol *BeginLabel = MMI->getContext().createTempSymbol(), *EndLabel = MMI->getContext().createTempSymbol(); OS.EmitIntValue(unsigned(Kind), 4); @@ -2174,7 +2175,7 @@ if (!GV->hasComdat() && !GV->isDeclarationForLinker()) { if (!EndLabel) { OS.AddComment("Symbol subsection for globals"); - EndLabel = beginCVSubsection(ModuleSubstreamKind::Symbols); + EndLabel = beginCVSubsection(ModuleDebugFragmentKind::Symbols); } // FIXME: emitDebugInfoForGlobal() doesn't handle DIExpressions. emitDebugInfoForGlobal(GVE->getVariable(), GV, Asm->getSymbol(GV)); @@ -2192,7 +2193,7 @@ OS.AddComment("Symbol subsection for " + Twine(GlobalValue::getRealLinkageName(GV->getName()))); switchToDebugSectionForSymbol(GVSym); - EndLabel = beginCVSubsection(ModuleSubstreamKind::Symbols); + EndLabel = beginCVSubsection(ModuleDebugFragmentKind::Symbols); // FIXME: emitDebugInfoForGlobal() doesn't handle DIExpressions. emitDebugInfoForGlobal(GVE->getVariable(), GV, GVSym); endCVSubsection(EndLabel); Index: llvm/trunk/lib/DebugInfo/CodeView/CMakeLists.txt =================================================================== --- llvm/trunk/lib/DebugInfo/CodeView/CMakeLists.txt +++ llvm/trunk/lib/DebugInfo/CodeView/CMakeLists.txt @@ -7,8 +7,8 @@ EnumTables.cpp Formatters.cpp Line.cpp - ModuleSubstream.cpp - ModuleSubstreamVisitor.cpp + ModuleDebugFragment.cpp + ModuleDebugFragmentVisitor.cpp RecordSerialization.cpp SymbolRecordMapping.cpp SymbolDumper.cpp Index: llvm/trunk/lib/DebugInfo/CodeView/EnumTables.cpp =================================================================== --- llvm/trunk/lib/DebugInfo/CodeView/EnumTables.cpp +++ llvm/trunk/lib/DebugInfo/CodeView/EnumTables.cpp @@ -245,20 +245,20 @@ }; static const EnumEntry ModuleSubstreamKindNames[] = { - CV_ENUM_CLASS_ENT(ModuleSubstreamKind, None), - CV_ENUM_CLASS_ENT(ModuleSubstreamKind, Symbols), - CV_ENUM_CLASS_ENT(ModuleSubstreamKind, Lines), - CV_ENUM_CLASS_ENT(ModuleSubstreamKind, StringTable), - CV_ENUM_CLASS_ENT(ModuleSubstreamKind, FileChecksums), - CV_ENUM_CLASS_ENT(ModuleSubstreamKind, FrameData), - CV_ENUM_CLASS_ENT(ModuleSubstreamKind, InlineeLines), - CV_ENUM_CLASS_ENT(ModuleSubstreamKind, CrossScopeImports), - CV_ENUM_CLASS_ENT(ModuleSubstreamKind, CrossScopeExports), - CV_ENUM_CLASS_ENT(ModuleSubstreamKind, ILLines), - CV_ENUM_CLASS_ENT(ModuleSubstreamKind, FuncMDTokenMap), - CV_ENUM_CLASS_ENT(ModuleSubstreamKind, TypeMDTokenMap), - CV_ENUM_CLASS_ENT(ModuleSubstreamKind, MergedAssemblyInput), - CV_ENUM_CLASS_ENT(ModuleSubstreamKind, CoffSymbolRVA), + CV_ENUM_CLASS_ENT(ModuleDebugFragmentKind, None), + CV_ENUM_CLASS_ENT(ModuleDebugFragmentKind, Symbols), + CV_ENUM_CLASS_ENT(ModuleDebugFragmentKind, Lines), + CV_ENUM_CLASS_ENT(ModuleDebugFragmentKind, StringTable), + CV_ENUM_CLASS_ENT(ModuleDebugFragmentKind, FileChecksums), + CV_ENUM_CLASS_ENT(ModuleDebugFragmentKind, FrameData), + CV_ENUM_CLASS_ENT(ModuleDebugFragmentKind, InlineeLines), + CV_ENUM_CLASS_ENT(ModuleDebugFragmentKind, CrossScopeImports), + CV_ENUM_CLASS_ENT(ModuleDebugFragmentKind, CrossScopeExports), + CV_ENUM_CLASS_ENT(ModuleDebugFragmentKind, ILLines), + CV_ENUM_CLASS_ENT(ModuleDebugFragmentKind, FuncMDTokenMap), + CV_ENUM_CLASS_ENT(ModuleDebugFragmentKind, TypeMDTokenMap), + CV_ENUM_CLASS_ENT(ModuleDebugFragmentKind, MergedAssemblyInput), + CV_ENUM_CLASS_ENT(ModuleDebugFragmentKind, CoffSymbolRVA), }; static const EnumEntry ExportSymFlagNames[] = { Index: llvm/trunk/lib/DebugInfo/CodeView/ModuleDebugFragment.cpp =================================================================== --- llvm/trunk/lib/DebugInfo/CodeView/ModuleDebugFragment.cpp +++ llvm/trunk/lib/DebugInfo/CodeView/ModuleDebugFragment.cpp @@ -0,0 +1,46 @@ +//===- ModuleDebugFragment.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/CodeView/ModuleDebugFragment.h" + +#include "llvm/Support/BinaryStreamReader.h" + +using namespace llvm; +using namespace llvm::codeview; + +ModuleDebugFragment::ModuleDebugFragment() + : Kind(ModuleDebugFragmentKind::None) {} + +ModuleDebugFragment::ModuleDebugFragment(ModuleDebugFragmentKind Kind, + BinaryStreamRef Data) + : Kind(Kind), Data(Data) {} + +Error ModuleDebugFragment::initialize(BinaryStreamRef Stream, + ModuleDebugFragment &Info) { + const ModuleDebugFragmentHeader *Header; + BinaryStreamReader Reader(Stream); + if (auto EC = Reader.readObject(Header)) + return EC; + + ModuleDebugFragmentKind Kind = + static_cast(uint32_t(Header->Kind)); + if (auto EC = Reader.readStreamRef(Info.Data, Header->Length)) + return EC; + Info.Kind = Kind; + return Error::success(); +} + +uint32_t ModuleDebugFragment::getRecordLength() const { + return sizeof(ModuleDebugFragmentHeader) + Data.getLength(); +} + +ModuleDebugFragmentKind ModuleDebugFragment::kind() const { return Kind; } + +BinaryStreamRef ModuleDebugFragment::getRecordData() const { return Data; } Index: llvm/trunk/lib/DebugInfo/CodeView/ModuleDebugFragmentVisitor.cpp =================================================================== --- llvm/trunk/lib/DebugInfo/CodeView/ModuleDebugFragmentVisitor.cpp +++ llvm/trunk/lib/DebugInfo/CodeView/ModuleDebugFragmentVisitor.cpp @@ -0,0 +1,107 @@ +//===- ModuleDebugFragmentVisitor.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/CodeView/ModuleDebugFragmentVisitor.h" +#include "llvm/Support/BinaryStreamReader.h" +#include "llvm/Support/BinaryStreamRef.h" + +using namespace llvm; +using namespace llvm::codeview; + +Error ModuleDebugFragmentVisitor::visitSymbols(BinaryStreamRef Data) { + return visitUnknown(ModuleDebugFragmentKind::Symbols, Data); +} +Error ModuleDebugFragmentVisitor::visitLines(BinaryStreamRef Data, + const LineFragmentHeader *Header, + const LineInfoArray &Lines) { + return visitUnknown(ModuleDebugFragmentKind::Lines, Data); +} +Error ModuleDebugFragmentVisitor::visitStringTable(BinaryStreamRef Data) { + return visitUnknown(ModuleDebugFragmentKind::StringTable, Data); +} +Error ModuleDebugFragmentVisitor::visitFileChecksums( + BinaryStreamRef Data, const FileChecksumArray &Checksums) { + return visitUnknown(ModuleDebugFragmentKind::FileChecksums, Data); +} +Error ModuleDebugFragmentVisitor::visitFrameData(BinaryStreamRef Data) { + return visitUnknown(ModuleDebugFragmentKind::FrameData, Data); +} +Error ModuleDebugFragmentVisitor::visitInlineeLines(BinaryStreamRef Data) { + return visitUnknown(ModuleDebugFragmentKind::InlineeLines, Data); +} +Error ModuleDebugFragmentVisitor::visitCrossScopeImports(BinaryStreamRef Data) { + return visitUnknown(ModuleDebugFragmentKind::CrossScopeExports, Data); +} +Error ModuleDebugFragmentVisitor::visitCrossScopeExports(BinaryStreamRef Data) { + return visitUnknown(ModuleDebugFragmentKind::CrossScopeImports, Data); +} +Error ModuleDebugFragmentVisitor::visitILLines(BinaryStreamRef Data) { + return visitUnknown(ModuleDebugFragmentKind::ILLines, Data); +} +Error ModuleDebugFragmentVisitor::visitFuncMDTokenMap(BinaryStreamRef Data) { + return visitUnknown(ModuleDebugFragmentKind::FuncMDTokenMap, Data); +} +Error ModuleDebugFragmentVisitor::visitTypeMDTokenMap(BinaryStreamRef Data) { + return visitUnknown(ModuleDebugFragmentKind::TypeMDTokenMap, Data); +} +Error ModuleDebugFragmentVisitor::visitMergedAssemblyInput( + BinaryStreamRef Data) { + return visitUnknown(ModuleDebugFragmentKind::MergedAssemblyInput, Data); +} +Error ModuleDebugFragmentVisitor::visitCoffSymbolRVA(BinaryStreamRef Data) { + return visitUnknown(ModuleDebugFragmentKind::CoffSymbolRVA, Data); +} + +Error llvm::codeview::visitModuleDebugFragment(const ModuleDebugFragment &R, + ModuleDebugFragmentVisitor &V) { + switch (R.kind()) { + case ModuleDebugFragmentKind::Symbols: + return V.visitSymbols(R.getRecordData()); + case ModuleDebugFragmentKind::Lines: { + BinaryStreamReader Reader(R.getRecordData()); + const LineFragmentHeader *Header; + if (auto EC = Reader.readObject(Header)) + return EC; + VarStreamArrayExtractor E(Header); + LineInfoArray LineInfos(E); + if (auto EC = Reader.readArray(LineInfos, Reader.bytesRemaining())) + return EC; + return V.visitLines(R.getRecordData(), Header, LineInfos); + } + case ModuleDebugFragmentKind::StringTable: + return V.visitStringTable(R.getRecordData()); + case ModuleDebugFragmentKind::FileChecksums: { + BinaryStreamReader Reader(R.getRecordData()); + FileChecksumArray Checksums; + if (auto EC = Reader.readArray(Checksums, Reader.bytesRemaining())) + return EC; + return V.visitFileChecksums(R.getRecordData(), Checksums); + } + case ModuleDebugFragmentKind::FrameData: + return V.visitFrameData(R.getRecordData()); + case ModuleDebugFragmentKind::InlineeLines: + return V.visitInlineeLines(R.getRecordData()); + case ModuleDebugFragmentKind::CrossScopeImports: + return V.visitCrossScopeImports(R.getRecordData()); + case ModuleDebugFragmentKind::CrossScopeExports: + return V.visitCrossScopeExports(R.getRecordData()); + case ModuleDebugFragmentKind::ILLines: + return V.visitILLines(R.getRecordData()); + case ModuleDebugFragmentKind::FuncMDTokenMap: + return V.visitFuncMDTokenMap(R.getRecordData()); + case ModuleDebugFragmentKind::TypeMDTokenMap: + return V.visitTypeMDTokenMap(R.getRecordData()); + case ModuleDebugFragmentKind::MergedAssemblyInput: + return V.visitMergedAssemblyInput(R.getRecordData()); + case ModuleDebugFragmentKind::CoffSymbolRVA: + return V.visitCoffSymbolRVA(R.getRecordData()); + default: + return V.visitUnknown(R.kind(), R.getRecordData()); + } +} Index: llvm/trunk/lib/DebugInfo/CodeView/ModuleSubstream.cpp =================================================================== --- llvm/trunk/lib/DebugInfo/CodeView/ModuleSubstream.cpp +++ llvm/trunk/lib/DebugInfo/CodeView/ModuleSubstream.cpp @@ -1,43 +0,0 @@ -//===- ModuleSubstream.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/CodeView/ModuleSubstream.h" - -#include "llvm/Support/BinaryStreamReader.h" - -using namespace llvm; -using namespace llvm::codeview; - -ModuleSubstream::ModuleSubstream() : Kind(ModuleSubstreamKind::None) {} - -ModuleSubstream::ModuleSubstream(ModuleSubstreamKind Kind, BinaryStreamRef Data) - : Kind(Kind), Data(Data) {} - -Error ModuleSubstream::initialize(BinaryStreamRef Stream, - ModuleSubstream &Info) { - const ModuleSubsectionHeader *Header; - BinaryStreamReader Reader(Stream); - if (auto EC = Reader.readObject(Header)) - return EC; - - ModuleSubstreamKind Kind = - static_cast(uint32_t(Header->Kind)); - if (auto EC = Reader.readStreamRef(Info.Data, Header->Length)) - return EC; - Info.Kind = Kind; - return Error::success(); -} - -uint32_t ModuleSubstream::getRecordLength() const { - return sizeof(ModuleSubsectionHeader) + Data.getLength(); -} - -ModuleSubstreamKind ModuleSubstream::getSubstreamKind() const { return Kind; } - -BinaryStreamRef ModuleSubstream::getRecordData() const { return Data; } Index: llvm/trunk/lib/DebugInfo/CodeView/ModuleSubstreamVisitor.cpp =================================================================== --- llvm/trunk/lib/DebugInfo/CodeView/ModuleSubstreamVisitor.cpp +++ llvm/trunk/lib/DebugInfo/CodeView/ModuleSubstreamVisitor.cpp @@ -1,106 +0,0 @@ -//===- ModuleSubstreamVisitor.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/CodeView/ModuleSubstreamVisitor.h" -#include "llvm/Support/BinaryStreamReader.h" -#include "llvm/Support/BinaryStreamRef.h" - -using namespace llvm; -using namespace llvm::codeview; - -Error IModuleSubstreamVisitor::visitSymbols(BinaryStreamRef Data) { - return visitUnknown(ModuleSubstreamKind::Symbols, Data); -} -Error IModuleSubstreamVisitor::visitLines(BinaryStreamRef Data, - const LineSubstreamHeader *Header, - const LineInfoArray &Lines) { - return visitUnknown(ModuleSubstreamKind::Lines, Data); -} -Error IModuleSubstreamVisitor::visitStringTable(BinaryStreamRef Data) { - return visitUnknown(ModuleSubstreamKind::StringTable, Data); -} -Error IModuleSubstreamVisitor::visitFileChecksums( - BinaryStreamRef Data, const FileChecksumArray &Checksums) { - return visitUnknown(ModuleSubstreamKind::FileChecksums, Data); -} -Error IModuleSubstreamVisitor::visitFrameData(BinaryStreamRef Data) { - return visitUnknown(ModuleSubstreamKind::FrameData, Data); -} -Error IModuleSubstreamVisitor::visitInlineeLines(BinaryStreamRef Data) { - return visitUnknown(ModuleSubstreamKind::InlineeLines, Data); -} -Error IModuleSubstreamVisitor::visitCrossScopeImports(BinaryStreamRef Data) { - return visitUnknown(ModuleSubstreamKind::CrossScopeExports, Data); -} -Error IModuleSubstreamVisitor::visitCrossScopeExports(BinaryStreamRef Data) { - return visitUnknown(ModuleSubstreamKind::CrossScopeImports, Data); -} -Error IModuleSubstreamVisitor::visitILLines(BinaryStreamRef Data) { - return visitUnknown(ModuleSubstreamKind::ILLines, Data); -} -Error IModuleSubstreamVisitor::visitFuncMDTokenMap(BinaryStreamRef Data) { - return visitUnknown(ModuleSubstreamKind::FuncMDTokenMap, Data); -} -Error IModuleSubstreamVisitor::visitTypeMDTokenMap(BinaryStreamRef Data) { - return visitUnknown(ModuleSubstreamKind::TypeMDTokenMap, Data); -} -Error IModuleSubstreamVisitor::visitMergedAssemblyInput(BinaryStreamRef Data) { - return visitUnknown(ModuleSubstreamKind::MergedAssemblyInput, Data); -} -Error IModuleSubstreamVisitor::visitCoffSymbolRVA(BinaryStreamRef Data) { - return visitUnknown(ModuleSubstreamKind::CoffSymbolRVA, Data); -} - -Error llvm::codeview::visitModuleSubstream(const ModuleSubstream &R, - IModuleSubstreamVisitor &V) { - switch (R.getSubstreamKind()) { - case ModuleSubstreamKind::Symbols: - return V.visitSymbols(R.getRecordData()); - case ModuleSubstreamKind::Lines: { - BinaryStreamReader Reader(R.getRecordData()); - const LineSubstreamHeader *Header; - if (auto EC = Reader.readObject(Header)) - return EC; - VarStreamArrayExtractor E(Header); - LineInfoArray LineInfos(E); - if (auto EC = Reader.readArray(LineInfos, Reader.bytesRemaining())) - return EC; - return V.visitLines(R.getRecordData(), Header, LineInfos); - } - case ModuleSubstreamKind::StringTable: - return V.visitStringTable(R.getRecordData()); - case ModuleSubstreamKind::FileChecksums: { - BinaryStreamReader Reader(R.getRecordData()); - FileChecksumArray Checksums; - if (auto EC = Reader.readArray(Checksums, Reader.bytesRemaining())) - return EC; - return V.visitFileChecksums(R.getRecordData(), Checksums); - } - case ModuleSubstreamKind::FrameData: - return V.visitFrameData(R.getRecordData()); - case ModuleSubstreamKind::InlineeLines: - return V.visitInlineeLines(R.getRecordData()); - case ModuleSubstreamKind::CrossScopeImports: - return V.visitCrossScopeImports(R.getRecordData()); - case ModuleSubstreamKind::CrossScopeExports: - return V.visitCrossScopeExports(R.getRecordData()); - case ModuleSubstreamKind::ILLines: - return V.visitILLines(R.getRecordData()); - case ModuleSubstreamKind::FuncMDTokenMap: - return V.visitFuncMDTokenMap(R.getRecordData()); - case ModuleSubstreamKind::TypeMDTokenMap: - return V.visitTypeMDTokenMap(R.getRecordData()); - case ModuleSubstreamKind::MergedAssemblyInput: - return V.visitMergedAssemblyInput(R.getRecordData()); - case ModuleSubstreamKind::CoffSymbolRVA: - return V.visitCoffSymbolRVA(R.getRecordData()); - default: - return V.visitUnknown(R.getSubstreamKind(), R.getRecordData()); - } -} Index: llvm/trunk/lib/DebugInfo/PDB/CMakeLists.txt =================================================================== --- llvm/trunk/lib/DebugInfo/PDB/CMakeLists.txt +++ llvm/trunk/lib/DebugInfo/PDB/CMakeLists.txt @@ -28,6 +28,8 @@ endif() add_pdb_impl_folder(Native + Native/DbiModuleDescriptor.cpp + Native/DbiModuleDescriptorBuilder.cpp Native/DbiStream.cpp Native/DbiStreamBuilder.cpp Native/EnumTables.cpp @@ -37,9 +39,7 @@ Native/HashTable.cpp Native/InfoStream.cpp Native/InfoStreamBuilder.cpp - Native/ModInfo.cpp - Native/ModInfoBuilder.cpp - Native/ModStream.cpp + Native/ModuleDebugStream.cpp Native/NativeCompilandSymbol.cpp Native/NativeEnumModules.cpp Native/NativeExeSymbol.cpp Index: llvm/trunk/lib/DebugInfo/PDB/Native/DbiModuleDescriptor.cpp =================================================================== --- llvm/trunk/lib/DebugInfo/PDB/Native/DbiModuleDescriptor.cpp +++ llvm/trunk/lib/DebugInfo/PDB/Native/DbiModuleDescriptor.cpp @@ -0,0 +1,90 @@ +//===- DbiModuleDescriptor.cpp - PDB module information -------------------===// +// +// 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/Native/DbiModuleDescriptor.h" +#include "llvm/DebugInfo/PDB/Native/RawTypes.h" +#include "llvm/Support/BinaryStreamReader.h" +#include "llvm/Support/Endian.h" +#include "llvm/Support/Error.h" +#include "llvm/Support/MathExtras.h" +#include + +using namespace llvm; +using namespace llvm::pdb; +using namespace llvm::support; + +DbiModuleDescriptor::DbiModuleDescriptor() = default; + +DbiModuleDescriptor::DbiModuleDescriptor(const DbiModuleDescriptor &Info) = + default; + +DbiModuleDescriptor::~DbiModuleDescriptor() = default; + +Error DbiModuleDescriptor::initialize(BinaryStreamRef Stream, + DbiModuleDescriptor &Info) { + BinaryStreamReader Reader(Stream); + if (auto EC = Reader.readObject(Info.Layout)) + return EC; + + if (auto EC = Reader.readCString(Info.ModuleName)) + return EC; + + if (auto EC = Reader.readCString(Info.ObjFileName)) + return EC; + return Error::success(); +} + +bool DbiModuleDescriptor::hasECInfo() const { + return (Layout->Flags & ModInfoFlags::HasECFlagMask) != 0; +} + +uint16_t DbiModuleDescriptor::getTypeServerIndex() const { + return (Layout->Flags & ModInfoFlags::TypeServerIndexMask) >> + ModInfoFlags::TypeServerIndexShift; +} + +uint16_t DbiModuleDescriptor::getModuleStreamIndex() const { + return Layout->ModDiStream; +} + +uint32_t DbiModuleDescriptor::getSymbolDebugInfoByteSize() const { + return Layout->SymBytes; +} + +uint32_t DbiModuleDescriptor::getLineInfoByteSize() const { + return Layout->LineBytes; +} + +uint32_t DbiModuleDescriptor::getC13LineInfoByteSize() const { + return Layout->C13Bytes; +} + +uint32_t DbiModuleDescriptor::getNumberOfFiles() const { + return Layout->NumFiles; +} + +uint32_t DbiModuleDescriptor::getSourceFileNameIndex() const { + return Layout->SrcFileNameNI; +} + +uint32_t DbiModuleDescriptor::getPdbFilePathNameIndex() const { + return Layout->PdbFilePathNI; +} + +StringRef DbiModuleDescriptor::getModuleName() const { return ModuleName; } + +StringRef DbiModuleDescriptor::getObjFileName() const { return ObjFileName; } + +uint32_t DbiModuleDescriptor::getRecordLength() const { + uint32_t M = ModuleName.str().size() + 1; + uint32_t O = ObjFileName.str().size() + 1; + uint32_t Size = sizeof(ModuleInfoHeader) + M + O; + Size = alignTo(Size, 4); + return Size; +} Index: llvm/trunk/lib/DebugInfo/PDB/Native/DbiModuleDescriptorBuilder.cpp =================================================================== --- llvm/trunk/lib/DebugInfo/PDB/Native/DbiModuleDescriptorBuilder.cpp +++ llvm/trunk/lib/DebugInfo/PDB/Native/DbiModuleDescriptorBuilder.cpp @@ -0,0 +1,141 @@ +//===- DbiModuleDescriptorBuilder.cpp - PDB Mod Info Creation ---*- 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/Native/DbiModuleDescriptorBuilder.h" + +#include "llvm/ADT/ArrayRef.h" +#include "llvm/DebugInfo/MSF/MSFBuilder.h" +#include "llvm/DebugInfo/MSF/MSFCommon.h" +#include "llvm/DebugInfo/MSF/MappedBlockStream.h" +#include "llvm/DebugInfo/PDB/Native/DbiModuleDescriptor.h" +#include "llvm/DebugInfo/PDB/Native/RawConstants.h" +#include "llvm/DebugInfo/PDB/Native/RawError.h" +#include "llvm/Support/BinaryItemStream.h" +#include "llvm/Support/BinaryStreamWriter.h" +#include "llvm/Support/COFF.h" + +using namespace llvm; +using namespace llvm::codeview; +using namespace llvm::msf; +using namespace llvm::pdb; + +namespace llvm { +template <> struct BinaryItemTraits { + static size_t length(const CVSymbol &Item) { return Item.RecordData.size(); } + + static ArrayRef bytes(const CVSymbol &Item) { + return Item.RecordData; + } +}; +} + +static uint32_t calculateDiSymbolStreamSize(uint32_t SymbolByteSize) { + uint32_t Size = sizeof(uint32_t); // Signature + Size += SymbolByteSize; // Symbol Data + Size += 0; // TODO: Layout.LineBytes + Size += 0; // TODO: Layout.C13Bytes + Size += sizeof(uint32_t); // GlobalRefs substream size (always 0) + Size += 0; // GlobalRefs substream bytes + return Size; +} + +DbiModuleDescriptorBuilder::DbiModuleDescriptorBuilder(StringRef ModuleName, + uint32_t ModIndex, + msf::MSFBuilder &Msf) + : MSF(Msf), ModuleName(ModuleName) { + Layout.Mod = ModIndex; +} + +uint16_t DbiModuleDescriptorBuilder::getStreamIndex() const { + return Layout.ModDiStream; +} + +void DbiModuleDescriptorBuilder::setObjFileName(StringRef Name) { + ObjFileName = Name; +} + +void DbiModuleDescriptorBuilder::addSymbol(CVSymbol Symbol) { + Symbols.push_back(Symbol); + SymbolByteSize += Symbol.data().size(); +} + +void DbiModuleDescriptorBuilder::addSourceFile(StringRef Path) { + SourceFiles.push_back(Path); +} + +uint32_t DbiModuleDescriptorBuilder::calculateSerializedLength() const { + uint32_t L = sizeof(Layout); + uint32_t M = ModuleName.size() + 1; + uint32_t O = ObjFileName.size() + 1; + return alignTo(L + M + O, sizeof(uint32_t)); +} + +void DbiModuleDescriptorBuilder::finalize() { + Layout.C13Bytes = 0; + Layout.FileNameOffs = 0; // TODO: Fix this + Layout.Flags = 0; // TODO: Fix this + Layout.LineBytes = 0; + (void)Layout.Mod; // Set in constructor + (void)Layout.ModDiStream; // Set in finalizeMsfLayout + Layout.NumFiles = SourceFiles.size(); + Layout.PdbFilePathNI = 0; + Layout.SrcFileNameNI = 0; + + // This value includes both the signature field as well as the record bytes + // from the symbol stream. + Layout.SymBytes = SymbolByteSize + sizeof(uint32_t); +} + +Error DbiModuleDescriptorBuilder::finalizeMsfLayout() { + this->Layout.ModDiStream = kInvalidStreamIndex; + auto ExpectedSN = MSF.addStream(calculateDiSymbolStreamSize(SymbolByteSize)); + if (!ExpectedSN) + return ExpectedSN.takeError(); + Layout.ModDiStream = *ExpectedSN; + return Error::success(); +} + +Error DbiModuleDescriptorBuilder::commit(BinaryStreamWriter &ModiWriter, + const msf::MSFLayout &MsfLayout, + WritableBinaryStreamRef MsfBuffer) { + // We write the Modi record to the `ModiWriter`, but we additionally write its + // symbol stream to a brand new stream. + if (auto EC = ModiWriter.writeObject(Layout)) + return EC; + if (auto EC = ModiWriter.writeCString(ModuleName)) + return EC; + if (auto EC = ModiWriter.writeCString(ObjFileName)) + return EC; + if (auto EC = ModiWriter.padToAlignment(sizeof(uint32_t))) + return EC; + + if (Layout.ModDiStream != kInvalidStreamIndex) { + auto NS = WritableMappedBlockStream::createIndexedStream( + MsfLayout, MsfBuffer, Layout.ModDiStream); + WritableBinaryStreamRef Ref(*NS); + BinaryStreamWriter SymbolWriter(Ref); + // Write the symbols. + if (auto EC = + SymbolWriter.writeInteger(COFF::DEBUG_SECTION_MAGIC)) + return EC; + BinaryItemStream Records(llvm::support::endianness::little); + Records.setItems(Symbols); + BinaryStreamRef RecordsRef(Records); + if (auto EC = SymbolWriter.writeStreamRef(RecordsRef)) + return EC; + // TODO: Write C11 Line data + // TODO: Write C13 Line data + // TODO: Figure out what GlobalRefs substream actually is and populate it. + if (auto EC = SymbolWriter.writeInteger(0)) + return EC; + if (SymbolWriter.bytesRemaining() > 0) + return make_error(raw_error_code::stream_too_long); + } + return Error::success(); +} Index: llvm/trunk/lib/DebugInfo/PDB/Native/DbiStream.cpp =================================================================== --- llvm/trunk/lib/DebugInfo/PDB/Native/DbiStream.cpp +++ llvm/trunk/lib/DebugInfo/PDB/Native/DbiStream.cpp @@ -10,9 +10,9 @@ #include "llvm/DebugInfo/PDB/Native/DbiStream.h" #include "llvm/ADT/StringRef.h" #include "llvm/DebugInfo/MSF/MappedBlockStream.h" +#include "llvm/DebugInfo/PDB/Native/DbiModuleDescriptor.h" #include "llvm/DebugInfo/PDB/Native/ISectionContribVisitor.h" #include "llvm/DebugInfo/PDB/Native/InfoStream.h" -#include "llvm/DebugInfo/PDB/Native/ModInfo.h" #include "llvm/DebugInfo/PDB/Native/PDBFile.h" #include "llvm/DebugInfo/PDB/Native/RawConstants.h" #include "llvm/DebugInfo/PDB/Native/RawError.h" @@ -252,11 +252,12 @@ if (ModInfoSubstream.getLength() == 0) return Error::success(); - // Since each ModInfo in the stream is a variable length, we have to iterate + // Since each DbiModuleDescriptor in the stream is a variable length, we have + // to iterate // them to know how many there actually are. BinaryStreamReader Reader(ModInfoSubstream); - VarStreamArray ModInfoArray; + VarStreamArray ModInfoArray; if (auto EC = Reader.readArray(ModInfoArray, ModInfoSubstream.getLength())) return EC; for (auto &Info : ModInfoArray) { @@ -371,10 +372,12 @@ NumSourceFiles += Count; // This is the array that in the reference implementation corresponds to - // `ModInfo::FileLayout::FileNameOffs`, which is commented there as being a + // `DbiModuleDescriptor::FileLayout::FileNameOffs`, which is commented there + // as being a // pointer. Due to the mentioned problems of pointers causing difficulty // when reading from the file on 64-bit systems, we continue to ignore that - // field in `ModInfo`, and instead build a vector of StringRefs and stores + // field in `DbiModuleDescriptor`, and instead build a vector of StringRefs + // and stores // them in `ModuleInfoEx`. The value written to and read from the file is // not used anyway, it is only there as a way to store the offsets for the // purposes of later accessing the names at runtime. Index: llvm/trunk/lib/DebugInfo/PDB/Native/DbiStreamBuilder.cpp =================================================================== --- llvm/trunk/lib/DebugInfo/PDB/Native/DbiStreamBuilder.cpp +++ llvm/trunk/lib/DebugInfo/PDB/Native/DbiStreamBuilder.cpp @@ -12,8 +12,8 @@ #include "llvm/ADT/ArrayRef.h" #include "llvm/DebugInfo/MSF/MSFBuilder.h" #include "llvm/DebugInfo/MSF/MappedBlockStream.h" +#include "llvm/DebugInfo/PDB/Native/DbiModuleDescriptorBuilder.h" #include "llvm/DebugInfo/PDB/Native/DbiStream.h" -#include "llvm/DebugInfo/PDB/Native/ModInfoBuilder.h" #include "llvm/DebugInfo/PDB/Native/RawError.h" #include "llvm/Object/COFF.h" #include "llvm/Support/BinaryStreamWriter.h" @@ -74,10 +74,11 @@ calculateSectionMapStreamSize() + calculateDbgStreamsSize(); } -Expected +Expected DbiStreamBuilder::addModuleInfo(StringRef ModuleName) { uint32_t Index = ModiList.size(); - auto MIB = llvm::make_unique(ModuleName, Index, Msf); + auto MIB = + llvm::make_unique(ModuleName, Index, Msf); auto M = MIB.get(); auto Result = ModiMap.insert(std::make_pair(ModuleName, std::move(MIB))); Index: llvm/trunk/lib/DebugInfo/PDB/Native/ModInfo.cpp =================================================================== --- llvm/trunk/lib/DebugInfo/PDB/Native/ModInfo.cpp +++ llvm/trunk/lib/DebugInfo/PDB/Native/ModInfo.cpp @@ -1,80 +0,0 @@ -//===- ModInfo.cpp - PDB module information -------------------------------===// -// -// 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/Native/ModInfo.h" -#include "llvm/DebugInfo/PDB/Native/RawTypes.h" -#include "llvm/Support/BinaryStreamReader.h" -#include "llvm/Support/Endian.h" -#include "llvm/Support/Error.h" -#include "llvm/Support/MathExtras.h" -#include - -using namespace llvm; -using namespace llvm::pdb; -using namespace llvm::support; - -ModInfo::ModInfo() = default; - -ModInfo::ModInfo(const ModInfo &Info) = default; - -ModInfo::~ModInfo() = default; - -Error ModInfo::initialize(BinaryStreamRef Stream, ModInfo &Info) { - BinaryStreamReader Reader(Stream); - if (auto EC = Reader.readObject(Info.Layout)) - return EC; - - if (auto EC = Reader.readCString(Info.ModuleName)) - return EC; - - if (auto EC = Reader.readCString(Info.ObjFileName)) - return EC; - return Error::success(); -} - -bool ModInfo::hasECInfo() const { - return (Layout->Flags & ModInfoFlags::HasECFlagMask) != 0; -} - -uint16_t ModInfo::getTypeServerIndex() const { - return (Layout->Flags & ModInfoFlags::TypeServerIndexMask) >> - ModInfoFlags::TypeServerIndexShift; -} - -uint16_t ModInfo::getModuleStreamIndex() const { return Layout->ModDiStream; } - -uint32_t ModInfo::getSymbolDebugInfoByteSize() const { - return Layout->SymBytes; -} - -uint32_t ModInfo::getLineInfoByteSize() const { return Layout->LineBytes; } - -uint32_t ModInfo::getC13LineInfoByteSize() const { return Layout->C13Bytes; } - -uint32_t ModInfo::getNumberOfFiles() const { return Layout->NumFiles; } - -uint32_t ModInfo::getSourceFileNameIndex() const { - return Layout->SrcFileNameNI; -} - -uint32_t ModInfo::getPdbFilePathNameIndex() const { - return Layout->PdbFilePathNI; -} - -StringRef ModInfo::getModuleName() const { return ModuleName; } - -StringRef ModInfo::getObjFileName() const { return ObjFileName; } - -uint32_t ModInfo::getRecordLength() const { - uint32_t M = ModuleName.str().size() + 1; - uint32_t O = ObjFileName.str().size() + 1; - uint32_t Size = sizeof(ModuleInfoHeader) + M + O; - Size = alignTo(Size, 4); - return Size; -} Index: llvm/trunk/lib/DebugInfo/PDB/Native/ModInfoBuilder.cpp =================================================================== --- llvm/trunk/lib/DebugInfo/PDB/Native/ModInfoBuilder.cpp +++ llvm/trunk/lib/DebugInfo/PDB/Native/ModInfoBuilder.cpp @@ -1,136 +0,0 @@ -//===- ModInfoBuilder.cpp - PDB Module Info Stream Creation -----*- 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/Native/ModInfoBuilder.h" - -#include "llvm/ADT/ArrayRef.h" -#include "llvm/DebugInfo/MSF/MSFBuilder.h" -#include "llvm/DebugInfo/MSF/MSFCommon.h" -#include "llvm/DebugInfo/MSF/MappedBlockStream.h" -#include "llvm/DebugInfo/PDB/Native/ModInfo.h" -#include "llvm/DebugInfo/PDB/Native/RawConstants.h" -#include "llvm/DebugInfo/PDB/Native/RawError.h" -#include "llvm/Support/BinaryItemStream.h" -#include "llvm/Support/BinaryStreamWriter.h" -#include "llvm/Support/COFF.h" - -using namespace llvm; -using namespace llvm::codeview; -using namespace llvm::msf; -using namespace llvm::pdb; - -namespace llvm { -template <> struct BinaryItemTraits { - static size_t length(const CVSymbol &Item) { return Item.RecordData.size(); } - - static ArrayRef bytes(const CVSymbol &Item) { - return Item.RecordData; - } -}; -} - -static uint32_t calculateDiSymbolStreamSize(uint32_t SymbolByteSize) { - uint32_t Size = sizeof(uint32_t); // Signature - Size += SymbolByteSize; // Symbol Data - Size += 0; // TODO: Layout.LineBytes - Size += 0; // TODO: Layout.C13Bytes - Size += sizeof(uint32_t); // GlobalRefs substream size (always 0) - Size += 0; // GlobalRefs substream bytes - return Size; -} - -ModInfoBuilder::ModInfoBuilder(StringRef ModuleName, uint32_t ModIndex, - msf::MSFBuilder &Msf) - : MSF(Msf), ModuleName(ModuleName) { - Layout.Mod = ModIndex; -} - -uint16_t ModInfoBuilder::getStreamIndex() const { return Layout.ModDiStream; } - -void ModInfoBuilder::setObjFileName(StringRef Name) { ObjFileName = Name; } - -void ModInfoBuilder::addSymbol(CVSymbol Symbol) { - Symbols.push_back(Symbol); - SymbolByteSize += Symbol.data().size(); -} - -void ModInfoBuilder::addSourceFile(StringRef Path) { - SourceFiles.push_back(Path); -} - -uint32_t ModInfoBuilder::calculateSerializedLength() const { - uint32_t L = sizeof(Layout); - uint32_t M = ModuleName.size() + 1; - uint32_t O = ObjFileName.size() + 1; - return alignTo(L + M + O, sizeof(uint32_t)); -} - -void ModInfoBuilder::finalize() { - Layout.C13Bytes = 0; - Layout.FileNameOffs = 0; // TODO: Fix this - Layout.Flags = 0; // TODO: Fix this - Layout.LineBytes = 0; - (void)Layout.Mod; // Set in constructor - (void)Layout.ModDiStream; // Set in finalizeMsfLayout - Layout.NumFiles = SourceFiles.size(); - Layout.PdbFilePathNI = 0; - Layout.SrcFileNameNI = 0; - - // This value includes both the signature field as well as the record bytes - // from the symbol stream. - Layout.SymBytes = SymbolByteSize + sizeof(uint32_t); -} - -Error ModInfoBuilder::finalizeMsfLayout() { - this->Layout.ModDiStream = kInvalidStreamIndex; - auto ExpectedSN = MSF.addStream(calculateDiSymbolStreamSize(SymbolByteSize)); - if (!ExpectedSN) - return ExpectedSN.takeError(); - Layout.ModDiStream = *ExpectedSN; - return Error::success(); -} - -Error ModInfoBuilder::commit(BinaryStreamWriter &ModiWriter, - const msf::MSFLayout &MsfLayout, - WritableBinaryStreamRef MsfBuffer) { - // We write the Modi record to the `ModiWriter`, but we additionally write its - // symbol stream to a brand new stream. - if (auto EC = ModiWriter.writeObject(Layout)) - return EC; - if (auto EC = ModiWriter.writeCString(ModuleName)) - return EC; - if (auto EC = ModiWriter.writeCString(ObjFileName)) - return EC; - if (auto EC = ModiWriter.padToAlignment(sizeof(uint32_t))) - return EC; - - if (Layout.ModDiStream != kInvalidStreamIndex) { - auto NS = WritableMappedBlockStream::createIndexedStream( - MsfLayout, MsfBuffer, Layout.ModDiStream); - WritableBinaryStreamRef Ref(*NS); - BinaryStreamWriter SymbolWriter(Ref); - // Write the symbols. - if (auto EC = - SymbolWriter.writeInteger(COFF::DEBUG_SECTION_MAGIC)) - return EC; - BinaryItemStream Records(llvm::support::endianness::little); - Records.setItems(Symbols); - BinaryStreamRef RecordsRef(Records); - if (auto EC = SymbolWriter.writeStreamRef(RecordsRef)) - return EC; - // TODO: Write C11 Line data - // TODO: Write C13 Line data - // TODO: Figure out what GlobalRefs substream actually is and populate it. - if (auto EC = SymbolWriter.writeInteger(0)) - return EC; - if (SymbolWriter.bytesRemaining() > 0) - return make_error(raw_error_code::stream_too_long); - } - return Error::success(); -} Index: llvm/trunk/lib/DebugInfo/PDB/Native/ModStream.cpp =================================================================== --- llvm/trunk/lib/DebugInfo/PDB/Native/ModStream.cpp +++ llvm/trunk/lib/DebugInfo/PDB/Native/ModStream.cpp @@ -1,89 +0,0 @@ -//===- ModStream.cpp - PDB Module Info Stream Access ----------------------===// -// -// 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/Native/ModStream.h" -#include "llvm/ADT/iterator_range.h" -#include "llvm/DebugInfo/CodeView/SymbolRecord.h" -#include "llvm/DebugInfo/PDB/Native/ModInfo.h" -#include "llvm/DebugInfo/PDB/Native/PDBFile.h" -#include "llvm/DebugInfo/PDB/Native/RawError.h" -#include "llvm/DebugInfo/PDB/Native/RawTypes.h" -#include "llvm/Support/BinaryStreamReader.h" -#include "llvm/Support/BinaryStreamRef.h" -#include "llvm/Support/Error.h" -#include -#include - -using namespace llvm; -using namespace llvm::msf; -using namespace llvm::pdb; - -ModStream::ModStream(const ModInfo &Module, - std::unique_ptr Stream) - : Mod(Module), Stream(std::move(Stream)) {} - -ModStream::~ModStream() = default; - -Error ModStream::reload() { - BinaryStreamReader Reader(*Stream); - - uint32_t SymbolSize = Mod.getSymbolDebugInfoByteSize(); - uint32_t C11Size = Mod.getLineInfoByteSize(); - uint32_t C13Size = Mod.getC13LineInfoByteSize(); - - if (C11Size > 0 && C13Size > 0) - return make_error(raw_error_code::corrupt_file, - "Module has both C11 and C13 line info"); - - BinaryStreamRef S; - - if (auto EC = Reader.readInteger(Signature)) - return EC; - if (auto EC = Reader.readArray(SymbolsSubstream, SymbolSize - 4)) - return EC; - - if (auto EC = Reader.readStreamRef(LinesSubstream, C11Size)) - return EC; - if (auto EC = Reader.readStreamRef(C13LinesSubstream, C13Size)) - return EC; - - BinaryStreamReader LineReader(C13LinesSubstream); - if (auto EC = LineReader.readArray(LineInfo, LineReader.bytesRemaining())) - return EC; - - uint32_t GlobalRefsSize; - if (auto EC = Reader.readInteger(GlobalRefsSize)) - return EC; - if (auto EC = Reader.readStreamRef(GlobalRefsSubstream, GlobalRefsSize)) - return EC; - if (Reader.bytesRemaining() > 0) - return make_error(raw_error_code::corrupt_file, - "Unexpected bytes in module stream."); - - return Error::success(); -} - -iterator_range -ModStream::symbols(bool *HadError) const { - // It's OK if the stream is empty. - if (SymbolsSubstream.getUnderlyingStream().getLength() == 0) - return make_range(SymbolsSubstream.end(), SymbolsSubstream.end()); - return make_range(SymbolsSubstream.begin(HadError), SymbolsSubstream.end()); -} - -iterator_range -ModStream::lines(bool *HadError) const { - return make_range(LineInfo.begin(HadError), LineInfo.end()); -} - -bool ModStream::hasLineInfo() const { - return C13LinesSubstream.getLength() > 0 || LinesSubstream.getLength() > 0; -} - -Error ModStream::commit() { return Error::success(); } Index: llvm/trunk/lib/DebugInfo/PDB/Native/ModuleDebugStream.cpp =================================================================== --- llvm/trunk/lib/DebugInfo/PDB/Native/ModuleDebugStream.cpp +++ llvm/trunk/lib/DebugInfo/PDB/Native/ModuleDebugStream.cpp @@ -0,0 +1,89 @@ +//===- ModuleDebugStream.cpp - PDB Module Info Stream Access --------------===// +// +// 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/Native/ModuleDebugStream.h" +#include "llvm/ADT/iterator_range.h" +#include "llvm/DebugInfo/CodeView/SymbolRecord.h" +#include "llvm/DebugInfo/PDB/Native/DbiModuleDescriptor.h" +#include "llvm/DebugInfo/PDB/Native/PDBFile.h" +#include "llvm/DebugInfo/PDB/Native/RawError.h" +#include "llvm/DebugInfo/PDB/Native/RawTypes.h" +#include "llvm/Support/BinaryStreamReader.h" +#include "llvm/Support/BinaryStreamRef.h" +#include "llvm/Support/Error.h" +#include +#include + +using namespace llvm; +using namespace llvm::msf; +using namespace llvm::pdb; + +ModuleDebugStream::ModuleDebugStream(const DbiModuleDescriptor &Module, + std::unique_ptr Stream) + : Mod(Module), Stream(std::move(Stream)) {} + +ModuleDebugStream::~ModuleDebugStream() = default; + +Error ModuleDebugStream::reload() { + BinaryStreamReader Reader(*Stream); + + uint32_t SymbolSize = Mod.getSymbolDebugInfoByteSize(); + uint32_t C11Size = Mod.getLineInfoByteSize(); + uint32_t C13Size = Mod.getC13LineInfoByteSize(); + + if (C11Size > 0 && C13Size > 0) + return make_error(raw_error_code::corrupt_file, + "Module has both C11 and C13 line info"); + + BinaryStreamRef S; + + if (auto EC = Reader.readInteger(Signature)) + return EC; + if (auto EC = Reader.readArray(SymbolsSubstream, SymbolSize - 4)) + return EC; + + if (auto EC = Reader.readStreamRef(LinesSubstream, C11Size)) + return EC; + if (auto EC = Reader.readStreamRef(C13LinesSubstream, C13Size)) + return EC; + + BinaryStreamReader LineReader(C13LinesSubstream); + if (auto EC = LineReader.readArray(LineInfo, LineReader.bytesRemaining())) + return EC; + + uint32_t GlobalRefsSize; + if (auto EC = Reader.readInteger(GlobalRefsSize)) + return EC; + if (auto EC = Reader.readStreamRef(GlobalRefsSubstream, GlobalRefsSize)) + return EC; + if (Reader.bytesRemaining() > 0) + return make_error(raw_error_code::corrupt_file, + "Unexpected bytes in module stream."); + + return Error::success(); +} + +iterator_range +ModuleDebugStream::symbols(bool *HadError) const { + // It's OK if the stream is empty. + if (SymbolsSubstream.getUnderlyingStream().getLength() == 0) + return make_range(SymbolsSubstream.end(), SymbolsSubstream.end()); + return make_range(SymbolsSubstream.begin(HadError), SymbolsSubstream.end()); +} + +iterator_range +ModuleDebugStream::lines(bool *HadError) const { + return make_range(LineInfo.begin(HadError), LineInfo.end()); +} + +bool ModuleDebugStream::hasLineInfo() const { + return C13LinesSubstream.getLength() > 0 || LinesSubstream.getLength() > 0; +} + +Error ModuleDebugStream::commit() { return Error::success(); } Index: llvm/trunk/lib/DebugInfo/Symbolize/Symbolize.cpp =================================================================== --- llvm/trunk/lib/DebugInfo/Symbolize/Symbolize.cpp +++ llvm/trunk/lib/DebugInfo/Symbolize/Symbolize.cpp @@ -461,8 +461,9 @@ size_t *length, int *status); #endif -std::string LLVMSymbolizer::DemangleName(const std::string &Name, - const SymbolizableModule *ModInfo) { +std::string +LLVMSymbolizer::DemangleName(const std::string &Name, + const SymbolizableModule *DbiModuleDescriptor) { #if !defined(_MSC_VER) // We can spoil names of symbols with C linkage, so use an heuristic // approach to check if the name should be demangled. @@ -490,7 +491,7 @@ return (result == 0) ? Name : std::string(DemangledName); } #endif - if (ModInfo && ModInfo->isWin32Module()) + if (DbiModuleDescriptor && DbiModuleDescriptor->isWin32Module()) return std::string(demanglePE32ExternCFunc(Name)); return Name; } Index: llvm/trunk/lib/MC/MCCodeView.cpp =================================================================== --- llvm/trunk/lib/MC/MCCodeView.cpp +++ llvm/trunk/lib/MC/MCCodeView.cpp @@ -145,7 +145,7 @@ MCSymbol *StringBegin = Ctx.createTempSymbol("strtab_begin", false), *StringEnd = Ctx.createTempSymbol("strtab_end", false); - OS.EmitIntValue(unsigned(ModuleSubstreamKind::StringTable), 4); + OS.EmitIntValue(unsigned(ModuleDebugFragmentKind::StringTable), 4); OS.emitAbsoluteSymbolDiff(StringEnd, StringBegin, 4); OS.EmitLabel(StringBegin); @@ -172,7 +172,7 @@ MCSymbol *FileBegin = Ctx.createTempSymbol("filechecksums_begin", false), *FileEnd = Ctx.createTempSymbol("filechecksums_end", false); - OS.EmitIntValue(unsigned(ModuleSubstreamKind::FileChecksums), 4); + OS.EmitIntValue(unsigned(ModuleDebugFragmentKind::FileChecksums), 4); OS.emitAbsoluteSymbolDiff(FileEnd, FileBegin, 4); OS.EmitLabel(FileBegin); @@ -197,7 +197,7 @@ MCSymbol *LineBegin = Ctx.createTempSymbol("linetable_begin", false), *LineEnd = Ctx.createTempSymbol("linetable_end", false); - OS.EmitIntValue(unsigned(ModuleSubstreamKind::Lines), 4); + OS.EmitIntValue(unsigned(ModuleDebugFragmentKind::Lines), 4); OS.emitAbsoluteSymbolDiff(LineEnd, LineBegin, 4); OS.EmitLabel(LineBegin); OS.EmitCOFFSecRel32(FuncBegin, /*Offset=*/0); Index: llvm/trunk/tools/llvm-pdbdump/LLVMOutputStyle.cpp =================================================================== --- llvm/trunk/tools/llvm-pdbdump/LLVMOutputStyle.cpp +++ llvm/trunk/tools/llvm-pdbdump/LLVMOutputStyle.cpp @@ -16,20 +16,20 @@ #include "llvm/DebugInfo/CodeView/CVTypeDumper.h" #include "llvm/DebugInfo/CodeView/CVTypeVisitor.h" #include "llvm/DebugInfo/CodeView/EnumTables.h" -#include "llvm/DebugInfo/CodeView/ModuleSubstreamVisitor.h" +#include "llvm/DebugInfo/CodeView/ModuleDebugFragmentVisitor.h" #include "llvm/DebugInfo/CodeView/SymbolDumper.h" #include "llvm/DebugInfo/CodeView/TypeDatabaseVisitor.h" #include "llvm/DebugInfo/CodeView/TypeDeserializer.h" #include "llvm/DebugInfo/CodeView/TypeDumpVisitor.h" #include "llvm/DebugInfo/CodeView/TypeVisitorCallbackPipeline.h" #include "llvm/DebugInfo/MSF/MappedBlockStream.h" +#include "llvm/DebugInfo/PDB/Native/DbiModuleDescriptor.h" #include "llvm/DebugInfo/PDB/Native/DbiStream.h" #include "llvm/DebugInfo/PDB/Native/EnumTables.h" #include "llvm/DebugInfo/PDB/Native/GlobalsStream.h" #include "llvm/DebugInfo/PDB/Native/ISectionContribVisitor.h" #include "llvm/DebugInfo/PDB/Native/InfoStream.h" -#include "llvm/DebugInfo/PDB/Native/ModInfo.h" -#include "llvm/DebugInfo/PDB/Native/ModStream.h" +#include "llvm/DebugInfo/PDB/Native/ModuleDebugStream.h" #include "llvm/DebugInfo/PDB/Native/PDBFile.h" #include "llvm/DebugInfo/PDB/Native/PublicsStream.h" #include "llvm/DebugInfo/PDB/Native/RawError.h" @@ -606,7 +606,7 @@ File.getMsfLayout(), File.getMsfBuffer(), Modi.Info.getModuleStreamIndex()); - ModStream ModS(Modi.Info, std::move(ModStreamData)); + ModuleDebugStream ModS(Modi.Info, std::move(ModStreamData)); if (auto EC = ModS.reload()) return EC; @@ -636,10 +636,10 @@ bool HadError = false; // Define a locally scoped visitor to print the different // substream types types. - class RecordVisitor : public codeview::IModuleSubstreamVisitor { + class RecordVisitor : public codeview::ModuleDebugFragmentVisitor { public: RecordVisitor(ScopedPrinter &P, PDBFile &F) : P(P), F(F) {} - Error visitUnknown(ModuleSubstreamKind Kind, + Error visitUnknown(ModuleDebugFragmentKind Kind, BinaryStreamRef Stream) override { DictScope DD(P, "Unknown"); ArrayRef Data; @@ -670,7 +670,7 @@ } Error visitLines(BinaryStreamRef Data, - const LineSubstreamHeader *Header, + const LineFragmentHeader *Header, const LineInfoArray &Lines) override { DictScope DD(P, "Lines"); for (const auto &L : Lines) { @@ -721,7 +721,7 @@ RecordVisitor V(P, File); for (const auto &L : ModS.lines(&HadError)) { - if (auto EC = codeview::visitModuleSubstream(L, V)) + if (auto EC = codeview::visitModuleDebugFragment(L, V)) return EC; } } Index: llvm/trunk/tools/llvm-pdbdump/StreamUtil.cpp =================================================================== --- llvm/trunk/tools/llvm-pdbdump/StreamUtil.cpp +++ llvm/trunk/tools/llvm-pdbdump/StreamUtil.cpp @@ -11,9 +11,9 @@ #include "llvm/ADT/DenseMap.h" #include "llvm/ADT/DenseMapInfo.h" +#include "llvm/DebugInfo/PDB/Native/DbiModuleDescriptor.h" #include "llvm/DebugInfo/PDB/Native/DbiStream.h" #include "llvm/DebugInfo/PDB/Native/InfoStream.h" -#include "llvm/DebugInfo/PDB/Native/ModInfo.h" #include "llvm/DebugInfo/PDB/Native/PDBFile.h" #include "llvm/DebugInfo/PDB/Native/TpiStream.h" Index: llvm/trunk/tools/llvm-pdbdump/YAMLOutputStyle.h =================================================================== --- llvm/trunk/tools/llvm-pdbdump/YAMLOutputStyle.h +++ llvm/trunk/tools/llvm-pdbdump/YAMLOutputStyle.h @@ -19,7 +19,7 @@ namespace llvm { namespace pdb { -class ModStream; +class ModuleDebugStream; class YAMLOutputStyle : public OutputStyle { public: @@ -29,7 +29,7 @@ private: Expected> - getFileLineInfo(const pdb::ModStream &ModS); + getFileLineInfo(const pdb::ModuleDebugStream &ModS); Error dumpStringTable(); Error dumpFileHeaders(); Index: llvm/trunk/tools/llvm-pdbdump/YAMLOutputStyle.cpp =================================================================== --- llvm/trunk/tools/llvm-pdbdump/YAMLOutputStyle.cpp +++ llvm/trunk/tools/llvm-pdbdump/YAMLOutputStyle.cpp @@ -13,12 +13,12 @@ #include "llvm-pdbdump.h" #include "llvm/DebugInfo/CodeView/Line.h" -#include "llvm/DebugInfo/CodeView/ModuleSubstream.h" -#include "llvm/DebugInfo/CodeView/ModuleSubstreamVisitor.h" +#include "llvm/DebugInfo/CodeView/ModuleDebugFragment.h" +#include "llvm/DebugInfo/CodeView/ModuleDebugFragmentVisitor.h" #include "llvm/DebugInfo/MSF/MappedBlockStream.h" #include "llvm/DebugInfo/PDB/Native/DbiStream.h" #include "llvm/DebugInfo/PDB/Native/InfoStream.h" -#include "llvm/DebugInfo/PDB/Native/ModStream.h" +#include "llvm/DebugInfo/PDB/Native/ModuleDebugStream.h" #include "llvm/DebugInfo/PDB/Native/PDBFile.h" #include "llvm/DebugInfo/PDB/Native/RawConstants.h" #include "llvm/DebugInfo/PDB/Native/TpiStream.h" @@ -75,12 +75,12 @@ } namespace { -class C13SubstreamVisitor : public codeview::IModuleSubstreamVisitor { +class C13SubstreamVisitor : public codeview::ModuleDebugFragmentVisitor { public: C13SubstreamVisitor(llvm::pdb::yaml::PdbSourceFileInfo &Info, PDBFile &F) : Info(Info), F(F) {} - Error visitUnknown(codeview::ModuleSubstreamKind Kind, + Error visitUnknown(codeview::ModuleDebugFragmentKind Kind, BinaryStreamRef Stream) override { return Error::success(); } @@ -103,7 +103,7 @@ } Error visitLines(BinaryStreamRef Data, - const codeview::LineSubstreamHeader *Header, + const codeview::LineFragmentHeader *Header, const codeview::LineInfoArray &Lines) override { Info.Lines.CodeSize = Header->CodeSize; @@ -165,15 +165,15 @@ } Expected> -YAMLOutputStyle::getFileLineInfo(const pdb::ModStream &ModS) { +YAMLOutputStyle::getFileLineInfo(const pdb::ModuleDebugStream &ModS) { if (!ModS.hasLineInfo()) return None; yaml::PdbSourceFileInfo Info; bool Error = false; C13SubstreamVisitor Visitor(Info, File); - for (auto &Substream : ModS.lines(&Error)) { - if (auto E = codeview::visitModuleSubstream(Substream, Visitor)) + for (auto &Frag : ModS.lines(&Error)) { + if (auto E = codeview::visitModuleDebugFragment(Frag, Visitor)) return std::move(E); } @@ -293,7 +293,7 @@ File.getMsfLayout(), File.getMsfBuffer(), MI.Info.getModuleStreamIndex()); - pdb::ModStream ModS(MI.Info, std::move(ModStreamData)); + pdb::ModuleDebugStream ModS(MI.Info, std::move(ModStreamData)); if (auto EC = ModS.reload()) return EC; Index: llvm/trunk/tools/llvm-pdbdump/fuzzer/llvm-pdbdump-fuzzer.cpp =================================================================== --- llvm/trunk/tools/llvm-pdbdump/fuzzer/llvm-pdbdump-fuzzer.cpp +++ llvm/trunk/tools/llvm-pdbdump/fuzzer/llvm-pdbdump-fuzzer.cpp @@ -19,7 +19,7 @@ #include "llvm/DebugInfo/PDB/Raw/DbiStream.h" #include "llvm/DebugInfo/PDB/Raw/IPDBStreamData.h" #include "llvm/DebugInfo/PDB/Raw/MappedBlockStream.h" -#include "llvm/DebugInfo/PDB/Raw/ModStream.h" +#include "llvm/DebugInfo/PDB/Raw/ModuleDebugStream.h" #include "llvm/DebugInfo/PDB/Raw/PDBFile.h" #include "llvm/DebugInfo/PDB/Raw/RawSession.h" #include "llvm/Support/MemoryBuffer.h" @@ -90,7 +90,7 @@ consumeError(ModStreamData.takeError()); return 0; } - pdb::ModStream ModS(Modi.Info, std::move(*ModStreamData)); + pdb::ModuleDebugStream ModS(Modi.Info, std::move(*ModStreamData)); if (auto E = ModS.reload()) { consumeError(std::move(E)); return 0; Index: llvm/trunk/tools/llvm-pdbdump/llvm-pdbdump.cpp =================================================================== --- llvm/trunk/tools/llvm-pdbdump/llvm-pdbdump.cpp +++ llvm/trunk/tools/llvm-pdbdump/llvm-pdbdump.cpp @@ -35,11 +35,11 @@ #include "llvm/DebugInfo/PDB/IPDBEnumChildren.h" #include "llvm/DebugInfo/PDB/IPDBRawSymbol.h" #include "llvm/DebugInfo/PDB/IPDBSession.h" +#include "llvm/DebugInfo/PDB/Native/DbiModuleDescriptorBuilder.h" #include "llvm/DebugInfo/PDB/Native/DbiStream.h" #include "llvm/DebugInfo/PDB/Native/DbiStreamBuilder.h" #include "llvm/DebugInfo/PDB/Native/InfoStream.h" #include "llvm/DebugInfo/PDB/Native/InfoStreamBuilder.h" -#include "llvm/DebugInfo/PDB/Native/ModInfoBuilder.h" #include "llvm/DebugInfo/PDB/Native/NativeSession.h" #include "llvm/DebugInfo/PDB/Native/PDBFile.h" #include "llvm/DebugInfo/PDB/Native/PDBFileBuilder.h" Index: llvm/trunk/tools/llvm-readobj/COFFDumper.cpp =================================================================== --- llvm/trunk/tools/llvm-readobj/COFFDumper.cpp +++ llvm/trunk/tools/llvm-readobj/COFFDumper.cpp @@ -496,19 +496,19 @@ }; static const EnumEntry SubSectionTypes[] = { - LLVM_READOBJ_ENUM_CLASS_ENT(ModuleSubstreamKind, Symbols), - LLVM_READOBJ_ENUM_CLASS_ENT(ModuleSubstreamKind, Lines), - LLVM_READOBJ_ENUM_CLASS_ENT(ModuleSubstreamKind, StringTable), - LLVM_READOBJ_ENUM_CLASS_ENT(ModuleSubstreamKind, FileChecksums), - LLVM_READOBJ_ENUM_CLASS_ENT(ModuleSubstreamKind, FrameData), - LLVM_READOBJ_ENUM_CLASS_ENT(ModuleSubstreamKind, InlineeLines), - LLVM_READOBJ_ENUM_CLASS_ENT(ModuleSubstreamKind, CrossScopeImports), - LLVM_READOBJ_ENUM_CLASS_ENT(ModuleSubstreamKind, CrossScopeExports), - LLVM_READOBJ_ENUM_CLASS_ENT(ModuleSubstreamKind, ILLines), - LLVM_READOBJ_ENUM_CLASS_ENT(ModuleSubstreamKind, FuncMDTokenMap), - LLVM_READOBJ_ENUM_CLASS_ENT(ModuleSubstreamKind, TypeMDTokenMap), - LLVM_READOBJ_ENUM_CLASS_ENT(ModuleSubstreamKind, MergedAssemblyInput), - LLVM_READOBJ_ENUM_CLASS_ENT(ModuleSubstreamKind, CoffSymbolRVA), + LLVM_READOBJ_ENUM_CLASS_ENT(ModuleDebugFragmentKind, Symbols), + LLVM_READOBJ_ENUM_CLASS_ENT(ModuleDebugFragmentKind, Lines), + LLVM_READOBJ_ENUM_CLASS_ENT(ModuleDebugFragmentKind, StringTable), + LLVM_READOBJ_ENUM_CLASS_ENT(ModuleDebugFragmentKind, FileChecksums), + LLVM_READOBJ_ENUM_CLASS_ENT(ModuleDebugFragmentKind, FrameData), + LLVM_READOBJ_ENUM_CLASS_ENT(ModuleDebugFragmentKind, InlineeLines), + LLVM_READOBJ_ENUM_CLASS_ENT(ModuleDebugFragmentKind, CrossScopeImports), + LLVM_READOBJ_ENUM_CLASS_ENT(ModuleDebugFragmentKind, CrossScopeExports), + LLVM_READOBJ_ENUM_CLASS_ENT(ModuleDebugFragmentKind, ILLines), + LLVM_READOBJ_ENUM_CLASS_ENT(ModuleDebugFragmentKind, FuncMDTokenMap), + LLVM_READOBJ_ENUM_CLASS_ENT(ModuleDebugFragmentKind, TypeMDTokenMap), + LLVM_READOBJ_ENUM_CLASS_ENT(ModuleDebugFragmentKind, MergedAssemblyInput), + LLVM_READOBJ_ENUM_CLASS_ENT(ModuleDebugFragmentKind, CoffSymbolRVA), }; static const EnumEntry FrameDataFlags[] = { @@ -730,11 +730,11 @@ error(consume(Data, SubSectionSize)); if (SubSectionSize > Data.size()) return error(object_error::parse_failed); - switch (ModuleSubstreamKind(SubType)) { - case ModuleSubstreamKind::FileChecksums: + switch (ModuleDebugFragmentKind(SubType)) { + case ModuleDebugFragmentKind::FileChecksums: CVFileChecksumTable = Data.substr(0, SubSectionSize); break; - case ModuleSubstreamKind::StringTable: + case ModuleDebugFragmentKind::StringTable: CVStringTable = Data.substr(0, SubSectionSize); break; default: @@ -800,20 +800,20 @@ printBinaryBlockWithRelocs("SubSectionContents", Section, SectionContents, Contents); - switch (ModuleSubstreamKind(SubType)) { - case ModuleSubstreamKind::Symbols: + switch (ModuleDebugFragmentKind(SubType)) { + case ModuleDebugFragmentKind::Symbols: printCodeViewSymbolsSubsection(Contents, Section, SectionContents); break; - case ModuleSubstreamKind::InlineeLines: + case ModuleDebugFragmentKind::InlineeLines: printCodeViewInlineeLines(Contents); break; - case ModuleSubstreamKind::FileChecksums: + case ModuleDebugFragmentKind::FileChecksums: printCodeViewFileChecksums(Contents); break; - case ModuleSubstreamKind::Lines: { + case ModuleDebugFragmentKind::Lines: { // Holds a PC to file:line table. Some data to parse this subsection is // stored in the other subsections, so just check sanity and store the // pointers for deferred processing. @@ -839,7 +839,7 @@ FunctionNames.push_back(LinkageName); break; } - case ModuleSubstreamKind::FrameData: { + case ModuleDebugFragmentKind::FrameData: { // First four bytes is a relocation against the function. BinaryByteStream S(Contents, llvm::support::little); BinaryStreamReader SR(S);