diff options
| author | Ralf Luther <luther.ralf@gmail.com> | 2019-03-27 20:23:17 +0000 |
|---|---|---|
| committer | Gerrit Code Review <gerrit2@aicp-server-3> | 2019-03-27 20:23:17 +0000 |
| commit | 1ce3a9d272e564b22a1333a1e36a3d3ab7cfab01 (patch) | |
| tree | 391382eadd4fec5bb480f2e8934fa352770221d1 /clang-r353983/include/llvm/DebugInfo/PDB/Native | |
| parent | d1d48b140bafaa8a50107292f5fce95562575765 (diff) | |
| parent | 4f56932d3416ac03f646bc1a611b3135fec2fe08 (diff) | |
Merge "Update prebuilt Clang to r353983." into p9.0HEADp9.0-backupp9.0
Diffstat (limited to 'clang-r353983/include/llvm/DebugInfo/PDB/Native')
45 files changed, 4004 insertions, 0 deletions
diff --git a/clang-r353983/include/llvm/DebugInfo/PDB/Native/DbiModuleDescriptor.h b/clang-r353983/include/llvm/DebugInfo/PDB/Native/DbiModuleDescriptor.h new file mode 100644 index 00000000..568f0c98 --- /dev/null +++ b/clang-r353983/include/llvm/DebugInfo/PDB/Native/DbiModuleDescriptor.h @@ -0,0 +1,71 @@ +//===- DbiModuleDescriptor.h - PDB module information -----------*- C++ -*-===// +// +// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. +// See https://llvm.org/LICENSE.txt for license information. +// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception +// +//===----------------------------------------------------------------------===// + +#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 <cstdint> +#include <vector> + +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 getC11LineInfoByteSize() 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; + + const SectionContrib &getSectionContrib() const; + +private: + StringRef ModuleName; + StringRef ObjFileName; + const ModuleInfoHeader *Layout = nullptr; +}; + +} // end namespace pdb + +template <> struct VarStreamArrayExtractor<pdb::DbiModuleDescriptor> { + Error operator()(BinaryStreamRef Stream, uint32_t &Length, + pdb::DbiModuleDescriptor &Info) { + 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 diff --git a/clang-r353983/include/llvm/DebugInfo/PDB/Native/DbiModuleDescriptorBuilder.h b/clang-r353983/include/llvm/DebugInfo/PDB/Native/DbiModuleDescriptorBuilder.h new file mode 100644 index 00000000..4f5d28bb --- /dev/null +++ b/clang-r353983/include/llvm/DebugInfo/PDB/Native/DbiModuleDescriptorBuilder.h @@ -0,0 +1,106 @@ +//===- DbiModuleDescriptorBuilder.h - PDB module information ----*- C++ -*-===// +// +// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. +// See https://llvm.org/LICENSE.txt for license information. +// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception +// +//===----------------------------------------------------------------------===// + +#ifndef LLVM_DEBUGINFO_PDB_RAW_DBIMODULEDESCRIPTORBUILDER_H +#define LLVM_DEBUGINFO_PDB_RAW_DBIMODULEDESCRIPTORBUILDER_H + +#include "llvm/ADT/StringRef.h" +#include "llvm/DebugInfo/CodeView/DebugChecksumsSubsection.h" +#include "llvm/DebugInfo/CodeView/DebugInlineeLinesSubsection.h" +#include "llvm/DebugInfo/CodeView/DebugLinesSubsection.h" +#include "llvm/DebugInfo/CodeView/DebugSubsectionRecord.h" +#include "llvm/DebugInfo/CodeView/SymbolRecord.h" +#include "llvm/DebugInfo/PDB/Native/RawTypes.h" +#include "llvm/Support/Error.h" +#include <cstdint> +#include <string> +#include <vector> + +namespace llvm { +class BinaryStreamWriter; + +namespace codeview { +class DebugSubsectionRecordBuilder; +} + +namespace msf { +class MSFBuilder; +struct MSFLayout; +} +namespace pdb { + +class DbiModuleDescriptorBuilder { + friend class DbiStreamBuilder; + +public: + DbiModuleDescriptorBuilder(StringRef ModuleName, uint32_t ModIndex, + msf::MSFBuilder &Msf); + ~DbiModuleDescriptorBuilder(); + + DbiModuleDescriptorBuilder(const DbiModuleDescriptorBuilder &) = delete; + DbiModuleDescriptorBuilder & + operator=(const DbiModuleDescriptorBuilder &) = delete; + + void setPdbFilePathNI(uint32_t NI); + void setObjFileName(StringRef Name); + void setFirstSectionContrib(const SectionContrib &SC); + void addSymbol(codeview::CVSymbol Symbol); + void addSymbolsInBulk(ArrayRef<uint8_t> BulkSymbols); + + void + addDebugSubsection(std::shared_ptr<codeview::DebugSubsection> Subsection); + + void + addDebugSubsection(const codeview::DebugSubsectionRecord &SubsectionContents); + + uint16_t getStreamIndex() const; + StringRef getModuleName() const { return ModuleName; } + StringRef getObjFileName() const { return ObjFileName; } + + unsigned getModuleIndex() const { return Layout.Mod; } + + ArrayRef<std::string> source_files() const { + return makeArrayRef(SourceFiles); + } + + uint32_t calculateSerializedLength() const; + + /// Return the offset within the module symbol stream of the next symbol + /// record passed to addSymbol. Add four to account for the signature. + uint32_t getNextSymbolOffset() const { return SymbolByteSize + 4; } + + void finalize(); + Error finalizeMsfLayout(); + + Error commit(BinaryStreamWriter &ModiWriter, const msf::MSFLayout &MsfLayout, + WritableBinaryStreamRef MsfBuffer); + +private: + uint32_t calculateC13DebugInfoSize() const; + + void addSourceFile(StringRef Path); + msf::MSFBuilder &MSF; + + uint32_t SymbolByteSize = 0; + uint32_t PdbFilePathNI = 0; + std::string ModuleName; + std::string ObjFileName; + std::vector<std::string> SourceFiles; + std::vector<ArrayRef<uint8_t>> Symbols; + + std::vector<std::unique_ptr<codeview::DebugSubsectionRecordBuilder>> + C13Builders; + + ModuleInfoHeader Layout; +}; + +} // end namespace pdb + +} // end namespace llvm + +#endif // LLVM_DEBUGINFO_PDB_RAW_DBIMODULEDESCRIPTORBUILDER_H diff --git a/clang-r353983/include/llvm/DebugInfo/PDB/Native/DbiModuleList.h b/clang-r353983/include/llvm/DebugInfo/PDB/Native/DbiModuleList.h new file mode 100644 index 00000000..14223273 --- /dev/null +++ b/clang-r353983/include/llvm/DebugInfo/PDB/Native/DbiModuleList.h @@ -0,0 +1,117 @@ +//===- DbiModuleList.h - PDB module information list ------------*- C++ -*-===// +// +// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. +// See https://llvm.org/LICENSE.txt for license information. +// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception +// +//===----------------------------------------------------------------------===// + +#ifndef LLVM_DEBUGINFO_PDB_NATIVE_DBIMODULELIST_H +#define LLVM_DEBUGINFO_PDB_NATIVE_DBIMODULELIST_H + +#include "llvm/ADT/StringRef.h" +#include "llvm/ADT/iterator.h" +#include "llvm/ADT/iterator_range.h" +#include "llvm/DebugInfo/PDB/Native/DbiModuleDescriptor.h" +#include "llvm/Support/BinaryStreamArray.h" +#include "llvm/Support/BinaryStreamRef.h" +#include "llvm/Support/Endian.h" +#include "llvm/Support/Error.h" +#include <cstddef> +#include <cstdint> +#include <iterator> +#include <vector> + +namespace llvm { +namespace pdb { + +class DbiModuleList; +struct FileInfoSubstreamHeader; + +class DbiModuleSourceFilesIterator + : public iterator_facade_base<DbiModuleSourceFilesIterator, + std::random_access_iterator_tag, StringRef> { + using BaseType = + iterator_facade_base<DbiModuleSourceFilesIterator, + std::random_access_iterator_tag, StringRef>; + +public: + DbiModuleSourceFilesIterator(const DbiModuleList &Modules, uint32_t Modi, + uint16_t Filei); + DbiModuleSourceFilesIterator() = default; + DbiModuleSourceFilesIterator & + operator=(const DbiModuleSourceFilesIterator &R) = default; + + bool operator==(const DbiModuleSourceFilesIterator &R) const; + + const StringRef &operator*() const { return ThisValue; } + StringRef &operator*() { return ThisValue; } + + bool operator<(const DbiModuleSourceFilesIterator &RHS) const; + std::ptrdiff_t operator-(const DbiModuleSourceFilesIterator &R) const; + DbiModuleSourceFilesIterator &operator+=(std::ptrdiff_t N); + DbiModuleSourceFilesIterator &operator-=(std::ptrdiff_t N); + +private: + void setValue(); + + bool isEnd() const; + bool isCompatible(const DbiModuleSourceFilesIterator &R) const; + bool isUniversalEnd() const; + + StringRef ThisValue; + const DbiModuleList *Modules{nullptr}; + uint32_t Modi{0}; + uint16_t Filei{0}; +}; + +class DbiModuleList { + friend DbiModuleSourceFilesIterator; + +public: + Error initialize(BinaryStreamRef ModInfo, BinaryStreamRef FileInfo); + + Expected<StringRef> getFileName(uint32_t Index) const; + uint32_t getModuleCount() const; + uint32_t getSourceFileCount() const; + uint16_t getSourceFileCount(uint32_t Modi) const; + + iterator_range<DbiModuleSourceFilesIterator> + source_files(uint32_t Modi) const; + + DbiModuleDescriptor getModuleDescriptor(uint32_t Modi) const; + +private: + Error initializeModInfo(BinaryStreamRef ModInfo); + Error initializeFileInfo(BinaryStreamRef FileInfo); + + VarStreamArray<DbiModuleDescriptor> Descriptors; + + FixedStreamArray<support::little32_t> FileNameOffsets; + FixedStreamArray<support::ulittle16_t> ModFileCountArray; + + // For each module, there are multiple filenames, which can be obtained by + // knowing the index of the file. Given the index of the file, one can use + // that as an offset into the FileNameOffsets array, which contains the + // absolute offset of the file name in NamesBuffer. Thus, for each module + // we store the first index in the FileNameOffsets array for this module. + // The number of files for the corresponding module is stored in + // ModFileCountArray. + std::vector<uint32_t> ModuleInitialFileIndex; + + // In order to provide random access into the Descriptors array, we iterate it + // once up front to find the offsets of the individual items and store them in + // this array. + std::vector<uint32_t> ModuleDescriptorOffsets; + + const FileInfoSubstreamHeader *FileInfoHeader = nullptr; + + BinaryStreamRef ModInfoSubstream; + BinaryStreamRef FileInfoSubstream; + BinaryStreamRef NamesBuffer; +}; + +} // end namespace pdb +} // end namespace llvm + +#endif // LLVM_DEBUGINFO_PDB_NATIVE_DBIMODULELIST_H diff --git a/clang-r353983/include/llvm/DebugInfo/PDB/Native/DbiStream.h b/clang-r353983/include/llvm/DebugInfo/PDB/Native/DbiStream.h new file mode 100644 index 00000000..7d75c159 --- /dev/null +++ b/clang-r353983/include/llvm/DebugInfo/PDB/Native/DbiStream.h @@ -0,0 +1,138 @@ +//===- DbiStream.h - PDB Dbi Stream (Stream 3) Access -----------*- C++ -*-===// +// +// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. +// See https://llvm.org/LICENSE.txt for license information. +// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception +// +//===----------------------------------------------------------------------===// + +#ifndef LLVM_DEBUGINFO_PDB_RAW_PDBDBISTREAM_H +#define LLVM_DEBUGINFO_PDB_RAW_PDBDBISTREAM_H + +#include "llvm/DebugInfo/CodeView/DebugSubsection.h" +#include "llvm/DebugInfo/CodeView/DebugFrameDataSubsection.h" +#include "llvm/DebugInfo/MSF/MappedBlockStream.h" +#include "llvm/DebugInfo/PDB/Native/DbiModuleDescriptor.h" +#include "llvm/DebugInfo/PDB/Native/DbiModuleList.h" +#include "llvm/DebugInfo/PDB/Native/PDBStringTable.h" +#include "llvm/DebugInfo/PDB/Native/RawConstants.h" +#include "llvm/DebugInfo/PDB/Native/RawTypes.h" +#include "llvm/DebugInfo/PDB/PDBTypes.h" +#include "llvm/Support/BinaryStreamArray.h" +#include "llvm/Support/BinaryStreamRef.h" +#include "llvm/Support/Endian.h" +#include "llvm/Support/Error.h" + +namespace llvm { +namespace object { +struct FpoData; +struct coff_section; +} + +namespace pdb { +class DbiStreamBuilder; +class PDBFile; +class ISectionContribVisitor; + +class DbiStream { + friend class DbiStreamBuilder; + +public: + explicit DbiStream(std::unique_ptr<BinaryStream> Stream); + ~DbiStream(); + Error reload(PDBFile *Pdb); + + PdbRaw_DbiVer getDbiVersion() const; + uint32_t getAge() const; + uint16_t getPublicSymbolStreamIndex() const; + uint16_t getGlobalSymbolStreamIndex() const; + + uint16_t getFlags() const; + bool isIncrementallyLinked() const; + bool hasCTypes() const; + bool isStripped() const; + + uint16_t getBuildNumber() const; + uint16_t getBuildMajorVersion() const; + uint16_t getBuildMinorVersion() const; + + uint16_t getPdbDllRbld() const; + uint32_t getPdbDllVersion() const; + + uint32_t getSymRecordStreamIndex() const; + + PDB_Machine getMachineType() const; + + const DbiStreamHeader *getHeader() const { return Header; } + + BinarySubstreamRef getSectionContributionData() const; + BinarySubstreamRef getSecMapSubstreamData() const; + BinarySubstreamRef getModiSubstreamData() const; + BinarySubstreamRef getFileInfoSubstreamData() const; + BinarySubstreamRef getTypeServerMapSubstreamData() const; + BinarySubstreamRef getECSubstreamData() const; + + /// If the given stream type is present, returns its stream index. If it is + /// not present, returns InvalidStreamIndex. + uint32_t getDebugStreamIndex(DbgHeaderType Type) const; + + const DbiModuleList &modules() const; + + FixedStreamArray<object::coff_section> getSectionHeaders() const; + + bool hasOldFpoRecords() const; + FixedStreamArray<object::FpoData> getOldFpoRecords() const; + bool hasNewFpoRecords() const; + const codeview::DebugFrameDataSubsectionRef &getNewFpoRecords() const; + + FixedStreamArray<SecMapEntry> getSectionMap() const; + void visitSectionContributions(ISectionContribVisitor &Visitor) const; + + Expected<StringRef> getECName(uint32_t NI) const; + +private: + Error initializeSectionContributionData(); + Error initializeSectionHeadersData(PDBFile *Pdb); + Error initializeSectionMapData(); + Error initializeOldFpoRecords(PDBFile *Pdb); + Error initializeNewFpoRecords(PDBFile *Pdb); + + Expected<std::unique_ptr<msf::MappedBlockStream>> + createIndexedStreamForHeaderType(PDBFile *Pdb, DbgHeaderType Type) const; + + std::unique_ptr<BinaryStream> Stream; + + PDBStringTable ECNames; + + BinarySubstreamRef SecContrSubstream; + BinarySubstreamRef SecMapSubstream; + BinarySubstreamRef ModiSubstream; + BinarySubstreamRef FileInfoSubstream; + BinarySubstreamRef TypeServerMapSubstream; + BinarySubstreamRef ECSubstream; + + DbiModuleList Modules; + + FixedStreamArray<support::ulittle16_t> DbgStreams; + + PdbRaw_DbiSecContribVer SectionContribVersion = + PdbRaw_DbiSecContribVer::DbiSecContribVer60; + FixedStreamArray<SectionContrib> SectionContribs; + FixedStreamArray<SectionContrib2> SectionContribs2; + FixedStreamArray<SecMapEntry> SectionMap; + + std::unique_ptr<msf::MappedBlockStream> SectionHeaderStream; + FixedStreamArray<object::coff_section> SectionHeaders; + + std::unique_ptr<msf::MappedBlockStream> OldFpoStream; + FixedStreamArray<object::FpoData> OldFpoRecords; + + std::unique_ptr<msf::MappedBlockStream> NewFpoStream; + codeview::DebugFrameDataSubsectionRef NewFpoRecords; + + const DbiStreamHeader *Header; +}; +} +} + +#endif diff --git a/clang-r353983/include/llvm/DebugInfo/PDB/Native/DbiStreamBuilder.h b/clang-r353983/include/llvm/DebugInfo/PDB/Native/DbiStreamBuilder.h new file mode 100644 index 00000000..d9be238a --- /dev/null +++ b/clang-r353983/include/llvm/DebugInfo/PDB/Native/DbiStreamBuilder.h @@ -0,0 +1,142 @@ +//===- DbiStreamBuilder.h - PDB Dbi Stream Creation -------------*- C++ -*-===// +// +// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. +// See https://llvm.org/LICENSE.txt for license information. +// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception +// +//===----------------------------------------------------------------------===// + +#ifndef LLVM_DEBUGINFO_PDB_RAW_PDBDBISTREAMBUILDER_H +#define LLVM_DEBUGINFO_PDB_RAW_PDBDBISTREAMBUILDER_H + +#include "llvm/ADT/Optional.h" +#include "llvm/ADT/StringSet.h" +#include "llvm/BinaryFormat/COFF.h" +#include "llvm/Support/Error.h" + +#include "llvm/DebugInfo/CodeView/DebugFrameDataSubsection.h" +#include "llvm/DebugInfo/PDB/Native/PDBFile.h" +#include "llvm/DebugInfo/PDB/Native/PDBStringTableBuilder.h" +#include "llvm/DebugInfo/PDB/Native/RawConstants.h" +#include "llvm/DebugInfo/PDB/PDBTypes.h" +#include "llvm/Support/BinaryByteStream.h" +#include "llvm/Support/BinaryStreamReader.h" +#include "llvm/Support/Endian.h" + +namespace llvm { +namespace codeview { +struct FrameData; +} +namespace msf { +class MSFBuilder; +} +namespace object { +struct coff_section; +struct FpoData; +} +namespace pdb { +class DbiStream; +struct DbiStreamHeader; +class DbiModuleDescriptorBuilder; +class PDBFile; + +class DbiStreamBuilder { +public: + DbiStreamBuilder(msf::MSFBuilder &Msf); + ~DbiStreamBuilder(); + + DbiStreamBuilder(const DbiStreamBuilder &) = delete; + DbiStreamBuilder &operator=(const DbiStreamBuilder &) = delete; + + void setVersionHeader(PdbRaw_DbiVer V); + void setAge(uint32_t A); + void setBuildNumber(uint16_t B); + void setBuildNumber(uint8_t Major, uint8_t Minor); + void setPdbDllVersion(uint16_t V); + void setPdbDllRbld(uint16_t R); + void setFlags(uint16_t F); + void setMachineType(PDB_Machine M); + void setMachineType(COFF::MachineTypes M); + void setSectionMap(ArrayRef<SecMapEntry> SecMap); + + // Add given bytes as a new stream. + Error addDbgStream(pdb::DbgHeaderType Type, ArrayRef<uint8_t> Data); + + uint32_t addECName(StringRef Name); + + uint32_t calculateSerializedLength() const; + + void setGlobalsStreamIndex(uint32_t Index); + void setPublicsStreamIndex(uint32_t Index); + void setSymbolRecordStreamIndex(uint32_t Index); + void addNewFpoData(const codeview::FrameData &FD); + void addOldFpoData(const object::FpoData &Fpo); + + Expected<DbiModuleDescriptorBuilder &> addModuleInfo(StringRef ModuleName); + Error addModuleSourceFile(DbiModuleDescriptorBuilder &Module, StringRef File); + Expected<uint32_t> getSourceFileNameIndex(StringRef FileName); + + Error finalizeMsfLayout(); + + Error commit(const msf::MSFLayout &Layout, WritableBinaryStreamRef MsfBuffer); + + void addSectionContrib(const SectionContrib &SC) { + SectionContribs.emplace_back(SC); + } + + // A helper function to create a Section Map from a COFF section header. + static std::vector<SecMapEntry> + createSectionMap(ArrayRef<llvm::object::coff_section> SecHdrs); + +private: + struct DebugStream { + std::function<Error(BinaryStreamWriter &)> WriteFn; + uint32_t Size = 0; + uint16_t StreamNumber = kInvalidStreamIndex; + }; + + Error finalize(); + uint32_t calculateModiSubstreamSize() const; + uint32_t calculateNamesOffset() const; + uint32_t calculateSectionContribsStreamSize() const; + uint32_t calculateSectionMapStreamSize() const; + uint32_t calculateFileInfoSubstreamSize() const; + uint32_t calculateNamesBufferSize() const; + uint32_t calculateDbgStreamsSize() const; + + Error generateFileInfoSubstream(); + + msf::MSFBuilder &Msf; + BumpPtrAllocator &Allocator; + + Optional<PdbRaw_DbiVer> VerHeader; + uint32_t Age; + uint16_t BuildNumber; + uint16_t PdbDllVersion; + uint16_t PdbDllRbld; + uint16_t Flags; + PDB_Machine MachineType; + uint32_t GlobalsStreamIndex = kInvalidStreamIndex; + uint32_t PublicsStreamIndex = kInvalidStreamIndex; + uint32_t SymRecordStreamIndex = kInvalidStreamIndex; + + const DbiStreamHeader *Header; + + std::vector<std::unique_ptr<DbiModuleDescriptorBuilder>> ModiList; + + Optional<codeview::DebugFrameDataSubsection> NewFpoData; + std::vector<object::FpoData> OldFpoData; + + StringMap<uint32_t> SourceFileNames; + + PDBStringTableBuilder ECNamesBuilder; + WritableBinaryStreamRef NamesBuffer; + MutableBinaryByteStream FileInfoBuffer; + std::vector<SectionContrib> SectionContribs; + ArrayRef<SecMapEntry> SectionMap; + std::array<Optional<DebugStream>, (int)DbgHeaderType::Max> DbgStreams; +}; +} +} + +#endif diff --git a/clang-r353983/include/llvm/DebugInfo/PDB/Native/EnumTables.h b/clang-r353983/include/llvm/DebugInfo/PDB/Native/EnumTables.h new file mode 100644 index 00000000..70161fad --- /dev/null +++ b/clang-r353983/include/llvm/DebugInfo/PDB/Native/EnumTables.h @@ -0,0 +1,21 @@ +//===- EnumTables.h - Enum to string conversion tables ----------*- C++ -*-===// +// +// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. +// See https://llvm.org/LICENSE.txt for license information. +// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception +// +//===----------------------------------------------------------------------===// + +#ifndef LLVM_DEBUGINFO_PDB_RAW_ENUMTABLES_H +#define LLVM_DEBUGINFO_PDB_RAW_ENUMTABLES_H + +#include "llvm/ADT/ArrayRef.h" +#include "llvm/Support/ScopedPrinter.h" + +namespace llvm { +namespace pdb { +ArrayRef<EnumEntry<uint16_t>> getOMFSegMapDescFlagNames(); +} +} + +#endif // LLVM_DEBUGINFO_PDB_RAW_ENUMTABLES_H diff --git a/clang-r353983/include/llvm/DebugInfo/PDB/Native/Formatters.h b/clang-r353983/include/llvm/DebugInfo/PDB/Native/Formatters.h new file mode 100644 index 00000000..29c957ee --- /dev/null +++ b/clang-r353983/include/llvm/DebugInfo/PDB/Native/Formatters.h @@ -0,0 +1,44 @@ +//===- Formatters.h ---------------------------------------------*- C++ -*-===// +// +// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. +// See https://llvm.org/LICENSE.txt for license information. +// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception +// +//===----------------------------------------------------------------------===// + +#ifndef LLVM_DEBUGINFO_PDB_NATIVE_FORMATTERS_H +#define LLVM_DEBUGINFO_PDB_NATIVE_FORMATTERS_H + +#include "llvm/ADT/ArrayRef.h" +#include "llvm/ADT/StringRef.h" +#include "llvm/DebugInfo/CodeView/Formatters.h" +#include "llvm/DebugInfo/PDB/Native/RawConstants.h" +#include "llvm/DebugInfo/PDB/Native/RawTypes.h" +#include "llvm/Support/FormatProviders.h" + +#define FORMAT_CASE(Value, Name) \ + case Value: \ + Stream << Name; \ + break; + +namespace llvm { +template <> struct format_provider<pdb::PdbRaw_ImplVer> { + static void format(const pdb::PdbRaw_ImplVer &V, llvm::raw_ostream &Stream, + StringRef Style) { + switch (V) { + FORMAT_CASE(pdb::PdbRaw_ImplVer::PdbImplVC110, "VC110") + FORMAT_CASE(pdb::PdbRaw_ImplVer::PdbImplVC140, "VC140") + FORMAT_CASE(pdb::PdbRaw_ImplVer::PdbImplVC2, "VC2") + FORMAT_CASE(pdb::PdbRaw_ImplVer::PdbImplVC4, "VC4") + FORMAT_CASE(pdb::PdbRaw_ImplVer::PdbImplVC41, "VC41") + FORMAT_CASE(pdb::PdbRaw_ImplVer::PdbImplVC50, "VC50") + FORMAT_CASE(pdb::PdbRaw_ImplVer::PdbImplVC70, "VC70") + FORMAT_CASE(pdb::PdbRaw_ImplVer::PdbImplVC70Dep, "VC70Dep") + FORMAT_CASE(pdb::PdbRaw_ImplVer::PdbImplVC80, "VC80") + FORMAT_CASE(pdb::PdbRaw_ImplVer::PdbImplVC98, "VC98") + } + } +}; +} + +#endif diff --git a/clang-r353983/include/llvm/DebugInfo/PDB/Native/GSIStreamBuilder.h b/clang-r353983/include/llvm/DebugInfo/PDB/Native/GSIStreamBuilder.h new file mode 100644 index 00000000..a4979560 --- /dev/null +++ b/clang-r353983/include/llvm/DebugInfo/PDB/Native/GSIStreamBuilder.h @@ -0,0 +1,80 @@ +//===- GSIStreamBuilder.h - PDB Publics/Globals Stream Creation -*- C++ -*-===// +// +// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. +// See https://llvm.org/LICENSE.txt for license information. +// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception +// +//===----------------------------------------------------------------------===// + +#ifndef LLVM_DEBUGINFO_PDB_RAW_GSISTREAMBUILDER_H +#define LLVM_DEBUGINFO_PDB_RAW_GSISTREAMBUILDER_H + +#include "llvm/DebugInfo/CodeView/SymbolRecord.h" +#include "llvm/DebugInfo/PDB/Native/GlobalsStream.h" +#include "llvm/DebugInfo/PDB/Native/RawConstants.h" +#include "llvm/DebugInfo/PDB/Native/RawTypes.h" +#include "llvm/Support/BinaryByteStream.h" +#include "llvm/Support/BinaryItemStream.h" +#include "llvm/Support/BinaryStreamRef.h" +#include "llvm/Support/BinaryStreamWriter.h" +#include "llvm/Support/Endian.h" +#include "llvm/Support/Error.h" + +namespace llvm { + +template <> struct BinaryItemTraits<codeview::CVSymbol> { + static size_t length(const codeview::CVSymbol &Item) { + return Item.RecordData.size(); + } + static ArrayRef<uint8_t> bytes(const codeview::CVSymbol &Item) { + return Item.RecordData; + } +}; + +namespace msf { +class MSFBuilder; +struct MSFLayout; +} // namespace msf +namespace pdb { +struct GSIHashStreamBuilder; + +class GSIStreamBuilder { + +public: + explicit GSIStreamBuilder(msf::MSFBuilder &Msf); + ~GSIStreamBuilder(); + + GSIStreamBuilder(const GSIStreamBuilder &) = delete; + GSIStreamBuilder &operator=(const GSIStreamBuilder &) = delete; + + Error finalizeMsfLayout(); + + Error commit(const msf::MSFLayout &Layout, WritableBinaryStreamRef Buffer); + + uint32_t getPublicsStreamIndex() const; + uint32_t getGlobalsStreamIndex() const; + uint32_t getRecordStreamIdx() const { return RecordStreamIdx; } + + void addPublicSymbol(const codeview::PublicSym32 &Pub); + + void addGlobalSymbol(const codeview::ProcRefSym &Sym); + void addGlobalSymbol(const codeview::DataSym &Sym); + void addGlobalSymbol(const codeview::ConstantSym &Sym); + void addGlobalSymbol(const codeview::CVSymbol &Sym); + +private: + uint32_t calculatePublicsHashStreamSize() const; + uint32_t calculateGlobalsHashStreamSize() const; + Error commitSymbolRecordStream(WritableBinaryStreamRef Stream); + Error commitPublicsHashStream(WritableBinaryStreamRef Stream); + Error commitGlobalsHashStream(WritableBinaryStreamRef Stream); + + uint32_t RecordStreamIdx = kInvalidStreamIndex; + msf::MSFBuilder &Msf; + std::unique_ptr<GSIHashStreamBuilder> PSH; + std::unique_ptr<GSIHashStreamBuilder> GSH; +}; +} // namespace pdb +} // namespace llvm + +#endif diff --git a/clang-r353983/include/llvm/DebugInfo/PDB/Native/GlobalsStream.h b/clang-r353983/include/llvm/DebugInfo/PDB/Native/GlobalsStream.h new file mode 100644 index 00000000..404baaa2 --- /dev/null +++ b/clang-r353983/include/llvm/DebugInfo/PDB/Native/GlobalsStream.h @@ -0,0 +1,87 @@ +//===- GlobalsStream.h - PDB Index of Symbols by Name -----------*- C++ -*-===// +// +// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. +// See https://llvm.org/LICENSE.txt for license information. +// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception +// +//===----------------------------------------------------------------------===// + +#ifndef LLVM_DEBUGINFO_PDB_RAW_GLOBALS_STREAM_H +#define LLVM_DEBUGINFO_PDB_RAW_GLOBALS_STREAM_H + +#include "llvm/ADT/iterator.h" +#include "llvm/DebugInfo/CodeView/SymbolRecord.h" +#include "llvm/DebugInfo/MSF/MappedBlockStream.h" +#include "llvm/DebugInfo/PDB/Native/RawConstants.h" +#include "llvm/DebugInfo/PDB/Native/RawTypes.h" +#include "llvm/DebugInfo/PDB/PDBTypes.h" +#include "llvm/Support/BinaryStreamArray.h" +#include "llvm/Support/Error.h" + +namespace llvm { +namespace pdb { +class DbiStream; +class PDBFile; +class SymbolStream; + +/// Iterator over hash records producing symbol record offsets. Abstracts away +/// the fact that symbol record offsets on disk are off-by-one. +class GSIHashIterator + : public iterator_adaptor_base< + GSIHashIterator, FixedStreamArrayIterator<PSHashRecord>, + std::random_access_iterator_tag, const uint32_t> { +public: + template <typename T> + GSIHashIterator(T &&v) + : GSIHashIterator::iterator_adaptor_base(std::forward<T &&>(v)) {} + + uint32_t operator*() const { + uint32_t Off = this->I->Off; + return --Off; + } +}; + +/// From https://github.com/Microsoft/microsoft-pdb/blob/master/PDB/dbi/gsi.cpp +enum : unsigned { IPHR_HASH = 4096 }; + +/// A readonly view of a hash table used in the globals and publics streams. +/// Most clients will only want to iterate this to get symbol record offsets +/// into the PDB symbol stream. +class GSIHashTable { +public: + const GSIHashHeader *HashHdr; + FixedStreamArray<PSHashRecord> HashRecords; + FixedStreamArray<support::ulittle32_t> HashBitmap; + FixedStreamArray<support::ulittle32_t> HashBuckets; + std::array<int32_t, IPHR_HASH + 1> BucketMap; + + Error read(BinaryStreamReader &Reader); + + uint32_t getVerSignature() const { return HashHdr->VerSignature; } + uint32_t getVerHeader() const { return HashHdr->VerHdr; } + uint32_t getHashRecordSize() const { return HashHdr->HrSize; } + uint32_t getNumBuckets() const { return HashHdr->NumBuckets; } + + typedef GSIHashHeader iterator; + GSIHashIterator begin() const { return GSIHashIterator(HashRecords.begin()); } + GSIHashIterator end() const { return GSIHashIterator(HashRecords.end()); } +}; + +class GlobalsStream { +public: + explicit GlobalsStream(std::unique_ptr<msf::MappedBlockStream> Stream); + ~GlobalsStream(); + const GSIHashTable &getGlobalsTable() const { return GlobalsTable; } + Error reload(); + + std::vector<std::pair<uint32_t, codeview::CVSymbol>> + findRecordsByName(StringRef Name, const SymbolStream &Symbols) const; + +private: + GSIHashTable GlobalsTable; + std::unique_ptr<msf::MappedBlockStream> Stream; +}; +} +} + +#endif diff --git a/clang-r353983/include/llvm/DebugInfo/PDB/Native/Hash.h b/clang-r353983/include/llvm/DebugInfo/PDB/Native/Hash.h new file mode 100644 index 00000000..b048d878 --- /dev/null +++ b/clang-r353983/include/llvm/DebugInfo/PDB/Native/Hash.h @@ -0,0 +1,26 @@ +//===- Hash.h - PDB hash functions ------------------------------*- C++ -*-===// +// +// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. +// See https://llvm.org/LICENSE.txt for license information. +// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception +// +//===----------------------------------------------------------------------===// + +#ifndef LLVM_DEBUGINFO_PDB_NATIVE_HASH_H +#define LLVM_DEBUGINFO_PDB_NATIVE_HASH_H + +#include "llvm/ADT/ArrayRef.h" +#include "llvm/ADT/StringRef.h" +#include <cstdint> + +namespace llvm { +namespace pdb { + +uint32_t hashStringV1(StringRef Str); +uint32_t hashStringV2(StringRef Str); +uint32_t hashBufferV8(ArrayRef<uint8_t> Data); + +} // end namespace pdb +} // end namespace llvm + +#endif // LLVM_DEBUGINFO_PDB_NATIVE_HASH_H diff --git a/clang-r353983/include/llvm/DebugInfo/PDB/Native/HashTable.h b/clang-r353983/include/llvm/DebugInfo/PDB/Native/HashTable.h new file mode 100644 index 00000000..e8f08c68 --- /dev/null +++ b/clang-r353983/include/llvm/DebugInfo/PDB/Native/HashTable.h @@ -0,0 +1,334 @@ +//===- HashTable.h - PDB Hash Table -----------------------------*- C++ -*-===// +// +// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. +// See https://llvm.org/LICENSE.txt for license information. +// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception +// +//===----------------------------------------------------------------------===// + +#ifndef LLVM_DEBUGINFO_PDB_NATIVE_HASHTABLE_H +#define LLVM_DEBUGINFO_PDB_NATIVE_HASHTABLE_H + +#include "llvm/ADT/SparseBitVector.h" +#include "llvm/ADT/iterator.h" +#include "llvm/DebugInfo/PDB/Native/RawError.h" +#include "llvm/Support/BinaryStreamReader.h" +#include "llvm/Support/BinaryStreamWriter.h" +#include "llvm/Support/Endian.h" +#include "llvm/Support/Error.h" +#include <cstdint> +#include <iterator> +#include <utility> +#include <vector> + +namespace llvm { + +class BinaryStreamReader; +class BinaryStreamWriter; + +namespace pdb { + +Error readSparseBitVector(BinaryStreamReader &Stream, SparseBitVector<> &V); +Error writeSparseBitVector(BinaryStreamWriter &Writer, SparseBitVector<> &Vec); + +template <typename ValueT, typename TraitsT> class HashTable; + +template <typename ValueT, typename TraitsT> +class HashTableIterator + : public iterator_facade_base<HashTableIterator<ValueT, TraitsT>, + std::forward_iterator_tag, + std::pair<uint32_t, ValueT>> { + friend HashTable<ValueT, TraitsT>; + + HashTableIterator(const HashTable<ValueT, TraitsT> &Map, uint32_t Index, + bool IsEnd) + : Map(&Map), Index(Index), IsEnd(IsEnd) {} + +public: + HashTableIterator(const HashTable<ValueT, TraitsT> &Map) : Map(&Map) { + int I = Map.Present.find_first(); + if (I == -1) { + Index = 0; + IsEnd = true; + } else { + Index = static_cast<uint32_t>(I); + IsEnd = false; + } + } + + HashTableIterator &operator=(const HashTableIterator &R) { + Map = R.Map; + return *this; + } + bool operator==(const HashTableIterator &R) const { + if (IsEnd && R.IsEnd) + return true; + if (IsEnd != R.IsEnd) + return false; + + return (Map == R.Map) && (Index == R.Index); + } + const std::pair<uint32_t, ValueT> &operator*() const { + assert(Map->Present.test(Index)); + return Map->Buckets[Index]; + } + HashTableIterator &operator++() { + while (Index < Map->Buckets.size()) { + ++Index; + if (Map->Present.test(Index)) + return *this; + } + + IsEnd = true; + return *this; + } + +private: + bool isEnd() const { return IsEnd; } + uint32_t index() const { return Index; } + + const HashTable<ValueT, TraitsT> *Map; + uint32_t Index; + bool IsEnd; +}; + +template <typename T> struct PdbHashTraits {}; + +template <> struct PdbHashTraits<uint32_t> { + uint32_t hashLookupKey(uint32_t N) const { return N; } + uint32_t storageKeyToLookupKey(uint32_t N) const { return N; } + uint32_t lookupKeyToStorageKey(uint32_t N) { return N; } +}; + +template <typename ValueT, typename TraitsT = PdbHashTraits<ValueT>> +class HashTable { + using iterator = HashTableIterator<ValueT, TraitsT>; + friend iterator; + + struct Header { + support::ulittle32_t Size; + support::ulittle32_t Capacity; + }; + + using BucketList = std::vector<std::pair<uint32_t, ValueT>>; + +public: + HashTable() { Buckets.resize(8); } + + explicit HashTable(TraitsT Traits) : HashTable(8, std::move(Traits)) {} + HashTable(uint32_t Capacity, TraitsT Traits) : Traits(Traits) { + Buckets.resize(Capacity); + } + + Error load(BinaryStreamReader &Stream) { + const Header *H; + if (auto EC = Stream.readObject(H)) + return EC; + if (H->Capacity == 0) + return make_error<RawError>(raw_error_code::corrupt_file, + "Invalid Hash Table Capacity"); + if (H->Size > maxLoad(H->Capacity)) + return make_error<RawError>(raw_error_code::corrupt_file, + "Invalid Hash Table Size"); + + Buckets.resize(H->Capacity); + + if (auto EC = readSparseBitVector(Stream, Present)) + return EC; + if (Present.count() != H->Size) + return make_error<RawError>(raw_error_code::corrupt_file, + "Present bit vector does not match size!"); + + if (auto EC = readSparseBitVector(Stream, Deleted)) + return EC; + if (Present.intersects(Deleted)) + return make_error<RawError>(raw_error_code::corrupt_file, + "Present bit vector interesects deleted!"); + + for (uint32_t P : Present) { + if (auto EC = Stream.readInteger(Buckets[P].first)) + return EC; + const ValueT *Value; + if (auto EC = Stream.readObject(Value)) + return EC; + Buckets[P].second = *Value; + } + + return Error::success(); + } + + uint32_t calculateSerializedLength() const { + uint32_t Size = sizeof(Header); + + constexpr int BitsPerWord = 8 * sizeof(uint32_t); + + int NumBitsP = Present.find_last() + 1; + int NumBitsD = Deleted.find_last() + 1; + + uint32_t NumWordsP = alignTo(NumBitsP, BitsPerWord) / BitsPerWord; + uint32_t NumWordsD = alignTo(NumBitsD, BitsPerWord) / BitsPerWord; + + // Present bit set number of words (4 bytes), followed by that many actual + // words (4 bytes each). + Size += sizeof(uint32_t); + Size += NumWordsP * sizeof(uint32_t); + + // Deleted bit set number of words (4 bytes), followed by that many actual + // words (4 bytes each). + Size += sizeof(uint32_t); + Size += NumWordsD * sizeof(uint32_t); + + // One (Key, ValueT) pair for each entry Present. + Size += (sizeof(uint32_t) + sizeof(ValueT)) * size(); + + return Size; + } + + Error commit(BinaryStreamWriter &Writer) const { + Header H; + H.Size = size(); + H.Capacity = capacity(); + if (auto EC = Writer.writeObject(H)) + return EC; + + if (auto EC = writeSparseBitVector(Writer, Present)) + return EC; + + if (auto EC = writeSparseBitVector(Writer, Deleted)) + return EC; + + for (const auto &Entry : *this) { + if (auto EC = Writer.writeInteger(Entry.first)) + return EC; + if (auto EC = Writer.writeObject(Entry.second)) + return EC; + } + return Error::success(); + } + + void clear() { + Buckets.resize(8); + Present.clear(); + Deleted.clear(); + } + + bool empty() const { return size() == 0; } + uint32_t capacity() const { return Buckets.size(); } + uint32_t size() const { return Present.count(); } + + iterator begin() const { return iterator(*this); } + iterator end() const { return iterator(*this, 0, true); } + + /// Find the entry whose key has the specified hash value, using the specified + /// traits defining hash function and equality. + template <typename Key> iterator find_as(const Key &K) const { + uint32_t H = Traits.hashLookupKey(K) % capacity(); + uint32_t I = H; + Optional<uint32_t> FirstUnused; + do { + if (isPresent(I)) { + if (Traits.storageKeyToLookupKey(Buckets[I].first) == K) + return iterator(*this, I, false); + } else { + if (!FirstUnused) + FirstUnused = I; + // Insertion occurs via linear probing from the slot hint, and will be + // inserted at the first empty / deleted location. Therefore, if we are + // probing and find a location that is neither present nor deleted, then + // nothing must have EVER been inserted at this location, and thus it is + // not possible for a matching value to occur later. + if (!isDeleted(I)) + break; + } + I = (I + 1) % capacity(); + } while (I != H); + + // The only way FirstUnused would not be set is if every single entry in the + // table were Present. But this would violate the load factor constraints + // that we impose, so it should never happen. + assert(FirstUnused); + return iterator(*this, *FirstUnused, true); + } + + /// Set the entry using a key type that the specified Traits can convert + /// from a real key to an internal key. + template <typename Key> bool set_as(const Key &K, ValueT V) { + return set_as_internal(K, std::move(V), None); + } + + template <typename Key> ValueT get(const Key &K) const { + auto Iter = find_as(K); + assert(Iter != end()); + return (*Iter).second; + } + +protected: + bool isPresent(uint32_t K) const { return Present.test(K); } + bool isDeleted(uint32_t K) const { return Deleted.test(K); } + + TraitsT Traits; + BucketList Buckets; + mutable SparseBitVector<> Present; + mutable SparseBitVector<> Deleted; + +private: + /// Set the entry using a key type that the specified Traits can convert + /// from a real key to an internal key. + template <typename Key> + bool set_as_internal(const Key &K, ValueT V, Optional<uint32_t> InternalKey) { + auto Entry = find_as(K); + if (Entry != end()) { + assert(isPresent(Entry.index())); + assert(Traits.storageKeyToLookupKey(Buckets[Entry.index()].first) == K); + // We're updating, no need to do anything special. + Buckets[Entry.index()].second = V; + return false; + } + + auto &B = Buckets[Entry.index()]; + assert(!isPresent(Entry.index())); + assert(Entry.isEnd()); + B.first = InternalKey ? *InternalKey : Traits.lookupKeyToStorageKey(K); + B.second = V; + Present.set(Entry.index()); + Deleted.reset(Entry.index()); + + grow(); + + assert((find_as(K)) != end()); + return true; + } + + static uint32_t maxLoad(uint32_t capacity) { return capacity * 2 / 3 + 1; } + + void grow() { + uint32_t S = size(); + uint32_t MaxLoad = maxLoad(capacity()); + if (S < maxLoad(capacity())) + return; + assert(capacity() != UINT32_MAX && "Can't grow Hash table!"); + + uint32_t NewCapacity = (capacity() <= INT32_MAX) ? MaxLoad * 2 : UINT32_MAX; + + // Growing requires rebuilding the table and re-hashing every item. Make a + // copy with a larger capacity, insert everything into the copy, then swap + // it in. + HashTable NewMap(NewCapacity, Traits); + for (auto I : Present) { + auto LookupKey = Traits.storageKeyToLookupKey(Buckets[I].first); + NewMap.set_as_internal(LookupKey, Buckets[I].second, Buckets[I].first); + } + + Buckets.swap(NewMap.Buckets); + std::swap(Present, NewMap.Present); + std::swap(Deleted, NewMap.Deleted); + assert(capacity() == NewCapacity); + assert(size() == S); + } +}; + +} // end namespace pdb + +} // end namespace llvm + +#endif // LLVM_DEBUGINFO_PDB_NATIVE_HASHTABLE_H diff --git a/clang-r353983/include/llvm/DebugInfo/PDB/Native/ISectionContribVisitor.h b/clang-r353983/include/llvm/DebugInfo/PDB/Native/ISectionContribVisitor.h new file mode 100644 index 00000000..717dce2f --- /dev/null +++ b/clang-r353983/include/llvm/DebugInfo/PDB/Native/ISectionContribVisitor.h @@ -0,0 +1,29 @@ +//===- ISectionContribVisitor.h ---------------------------------*- C++ -*-===// +// +// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. +// See https://llvm.org/LICENSE.txt for license information. +// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception +// +//===----------------------------------------------------------------------===// + +#ifndef LLVM_DEBUGINFO_PDB_RAW_ISECTIONCONTRIBVISITOR_H +#define LLVM_DEBUGINFO_PDB_RAW_ISECTIONCONTRIBVISITOR_H + +namespace llvm { +namespace pdb { + +struct SectionContrib; +struct SectionContrib2; + +class ISectionContribVisitor { +public: + virtual ~ISectionContribVisitor() = default; + + virtual void visit(const SectionContrib &C) = 0; + virtual void visit(const SectionContrib2 &C) = 0; +}; + +} // end namespace pdb +} // end namespace llvm + +#endif // LLVM_DEBUGINFO_PDB_RAW_ISECTIONCONTRIBVISITOR_H diff --git a/clang-r353983/include/llvm/DebugInfo/PDB/Native/InfoStream.h b/clang-r353983/include/llvm/DebugInfo/PDB/Native/InfoStream.h new file mode 100644 index 00000000..315b0935 --- /dev/null +++ b/clang-r353983/include/llvm/DebugInfo/PDB/Native/InfoStream.h @@ -0,0 +1,74 @@ +//===- InfoStream.h - PDB Info Stream (Stream 1) Access ---------*- C++ -*-===// +// +// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. +// See https://llvm.org/LICENSE.txt for license information. +// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception +// +//===----------------------------------------------------------------------===// + +#ifndef LLVM_DEBUGINFO_PDB_RAW_PDBINFOSTREAM_H +#define LLVM_DEBUGINFO_PDB_RAW_PDBINFOSTREAM_H + +#include "llvm/ADT/BitmaskEnum.h" +#include "llvm/ADT/StringMap.h" +#include "llvm/DebugInfo/CodeView/GUID.h" +#include "llvm/DebugInfo/MSF/MappedBlockStream.h" +#include "llvm/DebugInfo/PDB/Native/NamedStreamMap.h" +#include "llvm/DebugInfo/PDB/Native/RawConstants.h" +#include "llvm/DebugInfo/PDB/PDBTypes.h" + +#include "llvm/Support/Endian.h" +#include "llvm/Support/Error.h" + +namespace llvm { +namespace pdb { +class InfoStreamBuilder; +class PDBFile; + +class InfoStream { + friend class InfoStreamBuilder; + +public: + InfoStream(std::unique_ptr<BinaryStream> Stream); + + Error reload(); + + uint32_t getStreamSize() const; + + const InfoStreamHeader *getHeader() const { return Header; } + + bool containsIdStream() const; + PdbRaw_ImplVer getVersion() const; + uint32_t getSignature() const; + uint32_t getAge() const; + codeview::GUID getGuid() const; + uint32_t getNamedStreamMapByteSize() const; + + PdbRaw_Features getFeatures() const; + ArrayRef<PdbRaw_FeatureSig> getFeatureSignatures() const; + + const NamedStreamMap &getNamedStreams() const; + + BinarySubstreamRef getNamedStreamsBuffer() const; + + Expected<uint32_t> getNamedStreamIndex(llvm::StringRef Name) const; + StringMap<uint32_t> named_streams() const; + +private: + std::unique_ptr<BinaryStream> Stream; + + const InfoStreamHeader *Header; + + BinarySubstreamRef SubNamedStreams; + + std::vector<PdbRaw_FeatureSig> FeatureSignatures; + PdbRaw_Features Features = PdbFeatureNone; + + uint32_t NamedStreamMapByteSize = 0; + + NamedStreamMap NamedStreams; +}; +} +} + +#endif diff --git a/clang-r353983/include/llvm/DebugInfo/PDB/Native/InfoStreamBuilder.h b/clang-r353983/include/llvm/DebugInfo/PDB/Native/InfoStreamBuilder.h new file mode 100644 index 00000000..208a37c4 --- /dev/null +++ b/clang-r353983/include/llvm/DebugInfo/PDB/Native/InfoStreamBuilder.h @@ -0,0 +1,76 @@ +//===- InfoStreamBuilder.h - PDB Info Stream Creation -----------*- C++ -*-===// +// +// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. +// See https://llvm.org/LICENSE.txt for license information. +// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception +// +//===----------------------------------------------------------------------===// + +#ifndef LLVM_DEBUGINFO_PDB_RAW_PDBINFOSTREAMBUILDER_H +#define LLVM_DEBUGINFO_PDB_RAW_PDBINFOSTREAMBUILDER_H + +#include "llvm/ADT/Optional.h" +#include "llvm/Support/Error.h" + +#include "llvm/DebugInfo/PDB/Native/NamedStreamMap.h" +#include "llvm/DebugInfo/PDB/Native/PDBFile.h" +#include "llvm/DebugInfo/PDB/Native/RawConstants.h" +#include "llvm/DebugInfo/PDB/PDBTypes.h" + +namespace llvm { +class WritableBinaryStreamRef; + +namespace msf { +class MSFBuilder; +} +namespace pdb { +class PDBFile; +class NamedStreamMap; + +class InfoStreamBuilder { +public: + InfoStreamBuilder(msf::MSFBuilder &Msf, NamedStreamMap &NamedStreams); + InfoStreamBuilder(const InfoStreamBuilder &) = delete; + InfoStreamBuilder &operator=(const InfoStreamBuilder &) = delete; + + void setVersion(PdbRaw_ImplVer V); + void addFeature(PdbRaw_FeatureSig Sig); + + // If this is true, the PDB contents are hashed and this hash is used as + // PDB GUID and as Signature. The age is always 1. + void setHashPDBContentsToGUID(bool B); + + // These only have an effect if hashPDBContentsToGUID() is false. + void setSignature(uint32_t S); + void setAge(uint32_t A); + void setGuid(codeview::GUID G); + + bool hashPDBContentsToGUID() const { return HashPDBContentsToGUID; } + uint32_t getAge() const { return Age; } + codeview::GUID getGuid() const { return Guid; } + Optional<uint32_t> getSignature() const { return Signature; } + + uint32_t finalize(); + + Error finalizeMsfLayout(); + + Error commit(const msf::MSFLayout &Layout, + WritableBinaryStreamRef Buffer) const; + +private: + msf::MSFBuilder &Msf; + + std::vector<PdbRaw_FeatureSig> Features; + PdbRaw_ImplVer Ver; + uint32_t Age; + Optional<uint32_t> Signature; + codeview::GUID Guid; + + bool HashPDBContentsToGUID = false; + + NamedStreamMap &NamedStreams; +}; +} +} + +#endif diff --git a/clang-r353983/include/llvm/DebugInfo/PDB/Native/ModuleDebugStream.h b/clang-r353983/include/llvm/DebugInfo/PDB/Native/ModuleDebugStream.h new file mode 100644 index 00000000..161aa32f --- /dev/null +++ b/clang-r353983/include/llvm/DebugInfo/PDB/Native/ModuleDebugStream.h @@ -0,0 +1,90 @@ +//===- ModuleDebugStream.h - PDB Module Info Stream Access ------*- C++ -*-===// +// +// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. +// See https://llvm.org/LICENSE.txt for license information. +// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception +// +//===----------------------------------------------------------------------===// + +#ifndef LLVM_DEBUGINFO_PDB_NATIVE_MODULEDEBUGSTREAM_H +#define LLVM_DEBUGINFO_PDB_NATIVE_MODULEDEBUGSTREAM_H + +#include "llvm/ADT/iterator_range.h" +#include "llvm/DebugInfo/CodeView/DebugChecksumsSubsection.h" +#include "llvm/DebugInfo/CodeView/DebugSubsectionRecord.h" +#include "llvm/DebugInfo/CodeView/SymbolRecord.h" +#include "llvm/DebugInfo/MSF/MappedBlockStream.h" +#include "llvm/DebugInfo/PDB/Native/DbiModuleDescriptor.h" +#include "llvm/Support/BinaryStreamRef.h" +#include "llvm/Support/Error.h" +#include <cstdint> +#include <memory> + +namespace llvm { +namespace pdb { + +class DbiModuleDescriptor; + +class ModuleDebugStreamRef { + using DebugSubsectionIterator = codeview::DebugSubsectionArray::Iterator; + +public: + ModuleDebugStreamRef(const DbiModuleDescriptor &Module, + std::unique_ptr<msf::MappedBlockStream> Stream); + ModuleDebugStreamRef(ModuleDebugStreamRef &&Other) = default; + ModuleDebugStreamRef(const ModuleDebugStreamRef &Other) = default; + ~ModuleDebugStreamRef(); + + Error reload(); + + uint32_t signature() const { return Signature; } + + iterator_range<codeview::CVSymbolArray::Iterator> + symbols(bool *HadError) const; + + const codeview::CVSymbolArray &getSymbolArray() const { return SymbolArray; } + const codeview::CVSymbolArray + getSymbolArrayForScope(uint32_t ScopeBegin) const; + + BinarySubstreamRef getSymbolsSubstream() const; + BinarySubstreamRef getC11LinesSubstream() const; + BinarySubstreamRef getC13LinesSubstream() const; + BinarySubstreamRef getGlobalRefsSubstream() const; + + ModuleDebugStreamRef &operator=(ModuleDebugStreamRef &&Other) = delete; + + codeview::CVSymbol readSymbolAtOffset(uint32_t Offset) const; + + iterator_range<DebugSubsectionIterator> subsections() const; + codeview::DebugSubsectionArray getSubsectionsArray() const { + return Subsections; + } + + bool hasDebugSubsections() const; + + Error commit(); + + Expected<codeview::DebugChecksumsSubsectionRef> + findChecksumsSubsection() const; + +private: + DbiModuleDescriptor Mod; + + uint32_t Signature; + + std::shared_ptr<msf::MappedBlockStream> Stream; + + codeview::CVSymbolArray SymbolArray; + + BinarySubstreamRef SymbolsSubstream; + BinarySubstreamRef C11LinesSubstream; + BinarySubstreamRef C13LinesSubstream; + BinarySubstreamRef GlobalRefsSubstream; + + codeview::DebugSubsectionArray Subsections; +}; + +} // end namespace pdb +} // end namespace llvm + +#endif // LLVM_DEBUGINFO_PDB_NATIVE_MODULEDEBUGSTREAM_H diff --git a/clang-r353983/include/llvm/DebugInfo/PDB/Native/NamedStreamMap.h b/clang-r353983/include/llvm/DebugInfo/PDB/Native/NamedStreamMap.h new file mode 100644 index 00000000..c49d7963 --- /dev/null +++ b/clang-r353983/include/llvm/DebugInfo/PDB/Native/NamedStreamMap.h @@ -0,0 +1,72 @@ +//===- NamedStreamMap.h - PDB Named Stream Map ------------------*- C++ -*-===// +// +// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. +// See https://llvm.org/LICENSE.txt for license information. +// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception +// +//===----------------------------------------------------------------------===// + +#ifndef LLVM_DEBUGINFO_PDB_NATIVE_NAMEDSTREAMMAP_H +#define LLVM_DEBUGINFO_PDB_NATIVE_NAMEDSTREAMMAP_H + +#include "llvm/ADT/Optional.h" +#include "llvm/ADT/StringMap.h" +#include "llvm/ADT/StringRef.h" +#include "llvm/ADT/iterator_range.h" +#include "llvm/DebugInfo/PDB/Native/HashTable.h" +#include "llvm/Support/Error.h" +#include <cstdint> + +namespace llvm { + +class BinaryStreamReader; +class BinaryStreamWriter; + +namespace pdb { + +class NamedStreamMap; + +struct NamedStreamMapTraits { + NamedStreamMap *NS; + + explicit NamedStreamMapTraits(NamedStreamMap &NS); + uint16_t hashLookupKey(StringRef S) const; + StringRef storageKeyToLookupKey(uint32_t Offset) const; + uint32_t lookupKeyToStorageKey(StringRef S); +}; + +class NamedStreamMap { + friend class NamedStreamMapBuilder; + +public: + NamedStreamMap(); + + Error load(BinaryStreamReader &Stream); + Error commit(BinaryStreamWriter &Writer) const; + uint32_t calculateSerializedLength() const; + + uint32_t size() const; + bool get(StringRef Stream, uint32_t &StreamNo) const; + void set(StringRef Stream, uint32_t StreamNo); + + uint32_t appendStringData(StringRef S); + StringRef getString(uint32_t Offset) const; + uint32_t hashString(uint32_t Offset) const; + + StringMap<uint32_t> entries() const; + +private: + NamedStreamMapTraits HashTraits; + /// Closed hash table from Offset -> StreamNumber, where Offset is the offset + /// of the stream name in NamesBuffer. + HashTable<support::ulittle32_t, NamedStreamMapTraits> OffsetIndexMap; + + /// Buffer of string data. + std::vector<char> NamesBuffer; +}; + +} // end namespace pdb + +} // end namespace llvm + +#endif // LLVM_DEBUGINFO_PDB_NATIVE_NAMEDSTREAMMAP_H diff --git a/clang-r353983/include/llvm/DebugInfo/PDB/Native/NativeCompilandSymbol.h b/clang-r353983/include/llvm/DebugInfo/PDB/Native/NativeCompilandSymbol.h new file mode 100644 index 00000000..50d43764 --- /dev/null +++ b/clang-r353983/include/llvm/DebugInfo/PDB/Native/NativeCompilandSymbol.h @@ -0,0 +1,39 @@ +//===- NativeCompilandSymbol.h - native impl for compiland syms -*- C++ -*-===// +// +// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. +// See https://llvm.org/LICENSE.txt for license information. +// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception +// +//===----------------------------------------------------------------------===// + +#ifndef LLVM_DEBUGINFO_PDB_NATIVE_NATIVECOMPILANDSYMBOL_H +#define LLVM_DEBUGINFO_PDB_NATIVE_NATIVECOMPILANDSYMBOL_H + +#include "llvm/DebugInfo/PDB/Native/DbiModuleDescriptor.h" +#include "llvm/DebugInfo/PDB/Native/NativeRawSymbol.h" + +namespace llvm { +namespace pdb { + +class NativeCompilandSymbol : public NativeRawSymbol { +public: + NativeCompilandSymbol(NativeSession &Session, SymIndexId SymbolId, + DbiModuleDescriptor MI); + + void dump(raw_ostream &OS, int Indent, PdbSymbolIdField ShowIdFields, + PdbSymbolIdField RecurseIdFields) const override; + + PDB_SymType getSymTag() const override; + bool isEditAndContinueEnabled() const override; + SymIndexId getLexicalParentId() const override; + std::string getLibraryName() const override; + std::string getName() const override; + +private: + DbiModuleDescriptor Module; +}; + +} // namespace pdb +} // namespace llvm + +#endif diff --git a/clang-r353983/include/llvm/DebugInfo/PDB/Native/NativeEnumGlobals.h b/clang-r353983/include/llvm/DebugInfo/PDB/Native/NativeEnumGlobals.h new file mode 100644 index 00000000..073878af --- /dev/null +++ b/clang-r353983/include/llvm/DebugInfo/PDB/Native/NativeEnumGlobals.h @@ -0,0 +1,42 @@ +//==- NativeEnumGlobals.h - Native Global Enumerator impl --------*- C++ -*-==// +// +// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. +// See https://llvm.org/LICENSE.txt for license information. +// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception +// +//===----------------------------------------------------------------------===// + +#ifndef LLVM_DEBUGINFO_PDB_NATIVE_NATIVEENUMGLOBALS_H +#define LLVM_DEBUGINFO_PDB_NATIVE_NATIVEENUMGLOBALS_H + +#include "llvm/DebugInfo/CodeView/SymbolRecord.h" +#include "llvm/DebugInfo/PDB/IPDBEnumChildren.h" +#include "llvm/DebugInfo/PDB/PDBSymbol.h" + +#include <vector> + +namespace llvm { +namespace pdb { + +class NativeSession; + +class NativeEnumGlobals : public IPDBEnumChildren<PDBSymbol> { +public: + NativeEnumGlobals(NativeSession &Session, + std::vector<codeview::SymbolKind> Kinds); + + uint32_t getChildCount() const override; + std::unique_ptr<PDBSymbol> getChildAtIndex(uint32_t Index) const override; + std::unique_ptr<PDBSymbol> getNext() override; + void reset() override; + +private: + std::vector<uint32_t> MatchOffsets; + uint32_t Index; + NativeSession &Session; +}; + +} // namespace pdb +} // namespace llvm + +#endif diff --git a/clang-r353983/include/llvm/DebugInfo/PDB/Native/NativeEnumModules.h b/clang-r353983/include/llvm/DebugInfo/PDB/Native/NativeEnumModules.h new file mode 100644 index 00000000..94f1ee18 --- /dev/null +++ b/clang-r353983/include/llvm/DebugInfo/PDB/Native/NativeEnumModules.h @@ -0,0 +1,35 @@ +//==- NativeEnumModules.h - Native Module Enumerator impl --------*- C++ -*-==// +// +// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. +// See https://llvm.org/LICENSE.txt for license information. +// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception +// +//===----------------------------------------------------------------------===// + +#ifndef LLVM_DEBUGINFO_PDB_NATIVE_NATIVEENUMMODULES_H +#define LLVM_DEBUGINFO_PDB_NATIVE_NATIVEENUMMODULES_H + +#include "llvm/DebugInfo/PDB/IPDBEnumChildren.h" +#include "llvm/DebugInfo/PDB/PDBSymbol.h" +namespace llvm { +namespace pdb { + +class NativeSession; + +class NativeEnumModules : public IPDBEnumChildren<PDBSymbol> { +public: + NativeEnumModules(NativeSession &Session, uint32_t Index = 0); + + uint32_t getChildCount() const override; + std::unique_ptr<PDBSymbol> getChildAtIndex(uint32_t Index) const override; + std::unique_ptr<PDBSymbol> getNext() override; + void reset() override; + +private: + NativeSession &Session; + uint32_t Index; +}; +} +} + +#endif diff --git a/clang-r353983/include/llvm/DebugInfo/PDB/Native/NativeEnumTypes.h b/clang-r353983/include/llvm/DebugInfo/PDB/Native/NativeEnumTypes.h new file mode 100644 index 00000000..25c56567 --- /dev/null +++ b/clang-r353983/include/llvm/DebugInfo/PDB/Native/NativeEnumTypes.h @@ -0,0 +1,47 @@ +//==- NativeEnumTypes.h - Native Type Enumerator impl ------------*- C++ -*-==// +// +// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. +// See https://llvm.org/LICENSE.txt for license information. +// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception +// +//===----------------------------------------------------------------------===// + +#ifndef LLVM_DEBUGINFO_PDB_NATIVE_NATIVEENUMTYPES_H +#define LLVM_DEBUGINFO_PDB_NATIVE_NATIVEENUMTYPES_H + +#include "llvm/DebugInfo/CodeView/LazyRandomTypeCollection.h" +#include "llvm/DebugInfo/CodeView/TypeRecord.h" +#include "llvm/DebugInfo/PDB/IPDBEnumChildren.h" +#include "llvm/DebugInfo/PDB/PDBSymbol.h" + +#include <vector> + +namespace llvm { +namespace pdb { + +class NativeSession; + +class NativeEnumTypes : public IPDBEnumChildren<PDBSymbol> { +public: + NativeEnumTypes(NativeSession &Session, + codeview::LazyRandomTypeCollection &TypeCollection, + std::vector<codeview::TypeLeafKind> Kinds); + + NativeEnumTypes(NativeSession &Session, + std::vector<codeview::TypeIndex> Indices); + + uint32_t getChildCount() const override; + std::unique_ptr<PDBSymbol> getChildAtIndex(uint32_t Index) const override; + std::unique_ptr<PDBSymbol> getNext() override; + void reset() override; + +private: + std::vector<codeview::TypeIndex> Matches; + uint32_t Index; + NativeSession &Session; +}; + +} // namespace pdb +} // namespace llvm + +#endif diff --git a/clang-r353983/include/llvm/DebugInfo/PDB/Native/NativeExeSymbol.h b/clang-r353983/include/llvm/DebugInfo/PDB/Native/NativeExeSymbol.h new file mode 100644 index 00000000..280358d0 --- /dev/null +++ b/clang-r353983/include/llvm/DebugInfo/PDB/Native/NativeExeSymbol.h @@ -0,0 +1,40 @@ +//===- NativeExeSymbol.h - native impl for PDBSymbolExe ---------*- C++ -*-===// +// +// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. +// See https://llvm.org/LICENSE.txt for license information. +// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception +// +//===----------------------------------------------------------------------===// + +#ifndef LLVM_DEBUGINFO_PDB_NATIVE_NATIVEEXESYMBOL_H +#define LLVM_DEBUGINFO_PDB_NATIVE_NATIVEEXESYMBOL_H + +#include "llvm/DebugInfo/PDB/Native/NativeRawSymbol.h" +#include "llvm/DebugInfo/PDB/Native/NativeSession.h" + +namespace llvm { +namespace pdb { + +class DbiStream; + +class NativeExeSymbol : public NativeRawSymbol { + // EXE symbol is the authority on the various symbol types. + DbiStream *Dbi = nullptr; + +public: + NativeExeSymbol(NativeSession &Session, SymIndexId Id); + + std::unique_ptr<IPDBEnumSymbols> + findChildren(PDB_SymType Type) const override; + + uint32_t getAge() const override; + std::string getSymbolsFileName() const override; + codeview::GUID getGuid() const override; + bool hasCTypes() const override; + bool hasPrivateSymbols() const override; +}; + +} // namespace pdb +} // namespace llvm + +#endif diff --git a/clang-r353983/include/llvm/DebugInfo/PDB/Native/NativeRawSymbol.h b/clang-r353983/include/llvm/DebugInfo/PDB/Native/NativeRawSymbol.h new file mode 100644 index 00000000..4133be22 --- /dev/null +++ b/clang-r353983/include/llvm/DebugInfo/PDB/Native/NativeRawSymbol.h @@ -0,0 +1,240 @@ +//==- NativeRawSymbol.h - Native implementation of IPDBRawSymbol -*- C++ -*-==// +// +// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. +// See https://llvm.org/LICENSE.txt for license information. +// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception +// +//===----------------------------------------------------------------------===// + +#ifndef LLVM_DEBUGINFO_PDB_NATIVE_NATIVERAWSYMBOL_H +#define LLVM_DEBUGINFO_PDB_NATIVE_NATIVERAWSYMBOL_H + +#include "llvm/DebugInfo/PDB/IPDBRawSymbol.h" +#include <cstdint> +#include <memory> + +namespace llvm { +namespace pdb { + +class NativeSession; + +class NativeRawSymbol : public IPDBRawSymbol { + friend class SymbolCache; + virtual void initialize() {} + +public: + NativeRawSymbol(NativeSession &PDBSession, PDB_SymType Tag, + SymIndexId SymbolId); + + void dump(raw_ostream &OS, int Indent, PdbSymbolIdField ShowIdFields, + PdbSymbolIdField RecurseIdFields) const override; + + std::unique_ptr<IPDBEnumSymbols> + findChildren(PDB_SymType Type) const override; + std::unique_ptr<IPDBEnumSymbols> + findChildren(PDB_SymType Type, StringRef Name, + PDB_NameSearchFlags Flags) const override; + std::unique_ptr<IPDBEnumSymbols> + findChildrenByAddr(PDB_SymType Type, StringRef Name, + PDB_NameSearchFlags Flags, + uint32_t Section, uint32_t Offset) const override; + std::unique_ptr<IPDBEnumSymbols> + findChildrenByVA(PDB_SymType Type, StringRef Name, PDB_NameSearchFlags Flags, + uint64_t VA) const override; + std::unique_ptr<IPDBEnumSymbols> + findChildrenByRVA(PDB_SymType Type, StringRef Name, PDB_NameSearchFlags Flags, + uint32_t RVA) const override; + + std::unique_ptr<IPDBEnumSymbols> + findInlineFramesByAddr(uint32_t Section, uint32_t Offset) const override; + std::unique_ptr<IPDBEnumSymbols> + findInlineFramesByRVA(uint32_t RVA) const override; + std::unique_ptr<IPDBEnumSymbols> + findInlineFramesByVA(uint64_t VA) const override; + + std::unique_ptr<IPDBEnumLineNumbers> findInlineeLines() const override; + std::unique_ptr<IPDBEnumLineNumbers> + findInlineeLinesByAddr(uint32_t Section, uint32_t Offset, + uint32_t Length) const override; + std::unique_ptr<IPDBEnumLineNumbers> + findInlineeLinesByRVA(uint32_t RVA, uint32_t Length) const override; + std::unique_ptr<IPDBEnumLineNumbers> + findInlineeLinesByVA(uint64_t VA, uint32_t Length) const override; + + void getDataBytes(SmallVector<uint8_t, 32> &Bytes) const override; + void getFrontEndVersion(VersionInfo &Version) const override; + void getBackEndVersion(VersionInfo &Version) const override; + PDB_MemberAccess getAccess() const override; + uint32_t getAddressOffset() const override; + uint32_t getAddressSection() const override; + uint32_t getAge() const override; + SymIndexId getArrayIndexTypeId() const override; + uint32_t getBaseDataOffset() const override; + uint32_t getBaseDataSlot() const override; + SymIndexId getBaseSymbolId() const override; + PDB_BuiltinType getBuiltinType() const override; + uint32_t getBitPosition() const override; + PDB_CallingConv getCallingConvention() const override; + SymIndexId getClassParentId() const override; + std::string getCompilerName() const override; + uint32_t getCount() const override; + uint32_t getCountLiveRanges() const override; + PDB_Lang getLanguage() const override; + SymIndexId getLexicalParentId() const override; + std::string getLibraryName() const override; + uint32_t getLiveRangeStartAddressOffset() const override; + uint32_t getLiveRangeStartAddressSection() const override; + uint32_t getLiveRangeStartRelativeVirtualAddress() const override; + codeview::RegisterId getLocalBasePointerRegisterId() const override; + SymIndexId getLowerBoundId() const override; + uint32_t getMemorySpaceKind() const override; + std::string getName() const override; + uint32_t getNumberOfAcceleratorPointerTags() const override; + uint32_t getNumberOfColumns() const override; + uint32_t getNumberOfModifiers() const override; + uint32_t getNumberOfRegisterIndices() const override; + uint32_t getNumberOfRows() const override; + std::string getObjectFileName() const override; + uint32_t getOemId() const override; + SymIndexId getOemSymbolId() const override; + uint32_t getOffsetInUdt() const override; + PDB_Cpu getPlatform() const override; + uint32_t getRank() const override; + codeview::RegisterId getRegisterId() const override; + uint32_t getRegisterType() const override; + uint32_t getRelativeVirtualAddress() const override; + uint32_t getSamplerSlot() const override; + uint32_t getSignature() const override; + uint32_t getSizeInUdt() const override; + uint32_t getSlot() const override; + std::string getSourceFileName() const override; + std::unique_ptr<IPDBLineNumber> getSrcLineOnTypeDefn() const override; + uint32_t getStride() const override; + SymIndexId getSubTypeId() const override; + std::string getSymbolsFileName() const override; + SymIndexId getSymIndexId() const override; + uint32_t getTargetOffset() const override; + uint32_t getTargetRelativeVirtualAddress() const override; + uint64_t getTargetVirtualAddress() const override; + uint32_t getTargetSection() const override; + uint32_t getTextureSlot() const override; + uint32_t getTimeStamp() const override; + uint32_t getToken() const override; + SymIndexId getTypeId() const override; + uint32_t getUavSlot() const override; + std::string getUndecoratedName() const override; + std::string getUndecoratedNameEx(PDB_UndnameFlags Flags) const override; + SymIndexId getUnmodifiedTypeId() const override; + SymIndexId getUpperBoundId() const override; + Variant getValue() const override; + uint32_t getVirtualBaseDispIndex() const override; + uint32_t getVirtualBaseOffset() const override; + SymIndexId getVirtualTableShapeId() const override; + std::unique_ptr<PDBSymbolTypeBuiltin> + getVirtualBaseTableType() const override; + PDB_DataKind getDataKind() const override; + PDB_SymType getSymTag() const override; + codeview::GUID getGuid() const override; + int32_t getOffset() const override; + int32_t getThisAdjust() const override; + int32_t getVirtualBasePointerOffset() const override; + PDB_LocType getLocationType() const override; + PDB_Machine getMachineType() const override; + codeview::ThunkOrdinal getThunkOrdinal() const override; + uint64_t getLength() const override; + uint64_t getLiveRangeLength() const override; + uint64_t getVirtualAddress() const override; + PDB_UdtType getUdtKind() const override; + bool hasConstructor() const override; + bool hasCustomCallingConvention() const override; + bool hasFarReturn() const override; + bool isCode() const override; + bool isCompilerGenerated() const override; + bool isConstType() const override; + bool isEditAndContinueEnabled() const override; + bool isFunction() const override; + bool getAddressTaken() const override; + bool getNoStackOrdering() const override; + bool hasAlloca() const override; + bool hasAssignmentOperator() const override; + bool hasCTypes() const override; + bool hasCastOperator() const override; + bool hasDebugInfo() const override; + bool hasEH() const override; + bool hasEHa() const override; + bool hasInlAsm() const override; + bool hasInlineAttribute() const override; + bool hasInterruptReturn() const override; + bool hasFramePointer() const override; + bool hasLongJump() const override; + bool hasManagedCode() const override; + bool hasNestedTypes() const override; + bool hasNoInlineAttribute() const override; + bool hasNoReturnAttribute() const override; + bool hasOptimizedCodeDebugInfo() const override; + bool hasOverloadedOperator() const override; + bool hasSEH() const override; + bool hasSecurityChecks() const override; + bool hasSetJump() const override; + bool hasStrictGSCheck() const override; + bool isAcceleratorGroupSharedLocal() const override; + bool isAcceleratorPointerTagLiveRange() const override; + bool isAcceleratorStubFunction() const override; + bool isAggregated() const override; + bool isIntroVirtualFunction() const override; + bool isCVTCIL() const override; + bool isConstructorVirtualBase() const override; + bool isCxxReturnUdt() const override; + bool isDataAligned() const override; + bool isHLSLData() const override; + bool isHotpatchable() const override; + bool isIndirectVirtualBaseClass() const override; + bool isInterfaceUdt() const override; + bool isIntrinsic() const override; + bool isLTCG() const override; + bool isLocationControlFlowDependent() const override; + bool isMSILNetmodule() const override; + bool isMatrixRowMajor() const override; + bool isManagedCode() const override; + bool isMSILCode() const override; + bool isMultipleInheritance() const override; + bool isNaked() const override; + bool isNested() const override; + bool isOptimizedAway() const override; + bool isPacked() const override; + bool isPointerBasedOnSymbolValue() const override; + bool isPointerToDataMember() const override; + bool isPointerToMemberFunction() const override; + bool isPureVirtual() const override; + bool isRValueReference() const override; + bool isRefUdt() const override; + bool isReference() const override; + bool isRestrictedType() const override; + bool isReturnValue() const override; + bool isSafeBuffers() const override; + bool isScoped() const override; + bool isSdl() const override; + bool isSingleInheritance() const override; + bool isSplitted() const override; + bool isStatic() const override; + bool hasPrivateSymbols() const override; + bool isUnalignedType() const override; + bool isUnreached() const override; + bool isValueUdt() const override; + bool isVirtual() const override; + bool isVirtualBaseClass() const override; + bool isVirtualInheritance() const override; + bool isVolatileType() const override; + bool wasInlined() const override; + std::string getUnused() const override; + +protected: + NativeSession &Session; + PDB_SymType Tag; + SymIndexId SymbolId; +}; + +} // end namespace pdb +} // end namespace llvm + +#endif // LLVM_DEBUGINFO_PDB_NATIVE_NATIVERAWSYMBOL_H diff --git a/clang-r353983/include/llvm/DebugInfo/PDB/Native/NativeSession.h b/clang-r353983/include/llvm/DebugInfo/PDB/Native/NativeSession.h new file mode 100644 index 00000000..ee7d8cde --- /dev/null +++ b/clang-r353983/include/llvm/DebugInfo/PDB/Native/NativeSession.h @@ -0,0 +1,116 @@ +//===- NativeSession.h - Native implementation of IPDBSession ---*- C++ -*-===// +// +// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. +// See https://llvm.org/LICENSE.txt for license information. +// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception +// +//===----------------------------------------------------------------------===// + +#ifndef LLVM_DEBUGINFO_PDB_NATIVE_NATIVESESSION_H +#define LLVM_DEBUGINFO_PDB_NATIVE_NATIVESESSION_H + +#include "llvm/ADT/DenseMap.h" +#include "llvm/ADT/StringRef.h" +#include "llvm/DebugInfo/CodeView/TypeIndex.h" +#include "llvm/DebugInfo/PDB/IPDBRawSymbol.h" +#include "llvm/DebugInfo/PDB/IPDBSession.h" +#include "llvm/DebugInfo/PDB/Native/NativeRawSymbol.h" +#include "llvm/DebugInfo/PDB/Native/SymbolCache.h" +#include "llvm/Support/Allocator.h" +#include "llvm/Support/Error.h" + +namespace llvm { +class MemoryBuffer; +namespace pdb { +class PDBFile; +class NativeExeSymbol; + +class NativeSession : public IPDBSession { +public: + NativeSession(std::unique_ptr<PDBFile> PdbFile, + std::unique_ptr<BumpPtrAllocator> Allocator); + ~NativeSession() override; + + static Error createFromPdb(std::unique_ptr<MemoryBuffer> MB, + std::unique_ptr<IPDBSession> &Session); + static Error createFromExe(StringRef Path, + std::unique_ptr<IPDBSession> &Session); + + uint64_t getLoadAddress() const override; + bool setLoadAddress(uint64_t Address) override; + std::unique_ptr<PDBSymbolExe> getGlobalScope() override; + std::unique_ptr<PDBSymbol> getSymbolById(SymIndexId SymbolId) const override; + + bool addressForVA(uint64_t VA, uint32_t &Section, + uint32_t &Offset) const override; + bool addressForRVA(uint32_t RVA, uint32_t &Section, + uint32_t &Offset) const override; + + std::unique_ptr<PDBSymbol> + findSymbolByAddress(uint64_t Address, PDB_SymType Type) const override; + std::unique_ptr<PDBSymbol> findSymbolByRVA(uint32_t RVA, + PDB_SymType Type) const override; + std::unique_ptr<PDBSymbol> + findSymbolBySectOffset(uint32_t Sect, uint32_t Offset, + PDB_SymType Type) const override; + + std::unique_ptr<IPDBEnumLineNumbers> + findLineNumbers(const PDBSymbolCompiland &Compiland, + const IPDBSourceFile &File) const override; + std::unique_ptr<IPDBEnumLineNumbers> + findLineNumbersByAddress(uint64_t Address, uint32_t Length) const override; + std::unique_ptr<IPDBEnumLineNumbers> + findLineNumbersByRVA(uint32_t RVA, uint32_t Length) const override; + std::unique_ptr<IPDBEnumLineNumbers> + findLineNumbersBySectOffset(uint32_t Section, uint32_t Offset, + uint32_t Length) const override; + + std::unique_ptr<IPDBEnumSourceFiles> + findSourceFiles(const PDBSymbolCompiland *Compiland, llvm::StringRef Pattern, + PDB_NameSearchFlags Flags) const override; + std::unique_ptr<IPDBSourceFile> + findOneSourceFile(const PDBSymbolCompiland *Compiland, + llvm::StringRef Pattern, + PDB_NameSearchFlags Flags) const override; + std::unique_ptr<IPDBEnumChildren<PDBSymbolCompiland>> + findCompilandsForSourceFile(llvm::StringRef Pattern, + PDB_NameSearchFlags Flags) const override; + std::unique_ptr<PDBSymbolCompiland> + findOneCompilandForSourceFile(llvm::StringRef Pattern, + PDB_NameSearchFlags Flags) const override; + std::unique_ptr<IPDBEnumSourceFiles> getAllSourceFiles() const override; + std::unique_ptr<IPDBEnumSourceFiles> getSourceFilesForCompiland( + const PDBSymbolCompiland &Compiland) const override; + std::unique_ptr<IPDBSourceFile> + getSourceFileById(uint32_t FileId) const override; + + std::unique_ptr<IPDBEnumDataStreams> getDebugStreams() const override; + + std::unique_ptr<IPDBEnumTables> getEnumTables() const override; + + std::unique_ptr<IPDBEnumInjectedSources> getInjectedSources() const override; + + std::unique_ptr<IPDBEnumSectionContribs> getSectionContribs() const override; + + std::unique_ptr<IPDBEnumFrameData> getFrameData() const override; + + PDBFile &getPDBFile() { return *Pdb; } + const PDBFile &getPDBFile() const { return *Pdb; } + + NativeExeSymbol &getNativeGlobalScope() const; + SymbolCache &getSymbolCache() { return Cache; } + const SymbolCache &getSymbolCache() const { return Cache; } + +private: + void initializeExeSymbol(); + + std::unique_ptr<PDBFile> Pdb; + std::unique_ptr<BumpPtrAllocator> Allocator; + + SymbolCache Cache; + SymIndexId ExeSymbol = 0; +}; +} // namespace pdb +} // namespace llvm + +#endif diff --git a/clang-r353983/include/llvm/DebugInfo/PDB/Native/NativeSymbolEnumerator.h b/clang-r353983/include/llvm/DebugInfo/PDB/Native/NativeSymbolEnumerator.h new file mode 100644 index 00000000..06358509 --- /dev/null +++ b/clang-r353983/include/llvm/DebugInfo/PDB/Native/NativeSymbolEnumerator.h @@ -0,0 +1,50 @@ +//===- NativeSymbolEnumerator.h - info about enumerator values --*- C++ -*-===// +// +// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. +// See https://llvm.org/LICENSE.txt for license information. +// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception +// +//===----------------------------------------------------------------------===// + +#ifndef LLVM_DEBUGINFO_PDB_NATIVE_NATIVESYMBOLENUMERATOR_H +#define LLVM_DEBUGINFO_PDB_NATIVE_NATIVESYMBOLENUMERATOR_H + +#include "llvm/DebugInfo/CodeView/CodeView.h" +#include "llvm/DebugInfo/PDB/Native/NativeRawSymbol.h" +#include "llvm/DebugInfo/PDB/Native/NativeSession.h" + +namespace llvm { +namespace pdb { +class NativeTypeEnum; + +class NativeSymbolEnumerator : public NativeRawSymbol { +public: + NativeSymbolEnumerator(NativeSession &Session, SymIndexId Id, + const NativeTypeEnum &Parent, + codeview::EnumeratorRecord Record); + + ~NativeSymbolEnumerator() override; + + void dump(raw_ostream &OS, int Indent, PdbSymbolIdField ShowIdFields, + PdbSymbolIdField RecurseIdFields) const override; + + SymIndexId getClassParentId() const override; + SymIndexId getLexicalParentId() const override; + std::string getName() const override; + SymIndexId getTypeId() const override; + PDB_DataKind getDataKind() const override; + PDB_LocType getLocationType() const override; + bool isConstType() const override; + bool isVolatileType() const override; + bool isUnalignedType() const override; + Variant getValue() const override; + +protected: + const NativeTypeEnum &Parent; + codeview::EnumeratorRecord Record; +}; + +} // namespace pdb +} // namespace llvm + +#endif // LLVM_DEBUGINFO_PDB_NATIVE_NATIVETYPEENUM_H diff --git a/clang-r353983/include/llvm/DebugInfo/PDB/Native/NativeTypeArray.h b/clang-r353983/include/llvm/DebugInfo/PDB/Native/NativeTypeArray.h new file mode 100644 index 00000000..262864fd --- /dev/null +++ b/clang-r353983/include/llvm/DebugInfo/PDB/Native/NativeTypeArray.h @@ -0,0 +1,49 @@ +//===- NativeTypeArray.h ------------------------------------------ C++ -*-===// +// +// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. +// See https://llvm.org/LICENSE.txt for license information. +// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception +// +//===----------------------------------------------------------------------===// + +#ifndef LLVM_DEBUGINFO_PDB_NATIVE_NATIVETYPEARRAY_H +#define LLVM_DEBUGINFO_PDB_NATIVE_NATIVETYPEARRAY_H + +#include "llvm/DebugInfo/PDB/Native/NativeRawSymbol.h" + +#include "llvm/DebugInfo/CodeView/TypeRecord.h" +#include "llvm/DebugInfo/PDB/PDBTypes.h" + +namespace llvm { +namespace pdb { + +class NativeSession; + +class NativeTypeArray : public NativeRawSymbol { +public: + NativeTypeArray(NativeSession &Session, SymIndexId Id, codeview::TypeIndex TI, + codeview::ArrayRecord Record); + ~NativeTypeArray() override; + + void dump(raw_ostream &OS, int Indent, PdbSymbolIdField ShowIdFields, + PdbSymbolIdField RecurseIdFields) const override; + + SymIndexId getArrayIndexTypeId() const override; + + bool isConstType() const override; + bool isUnalignedType() const override; + bool isVolatileType() const override; + + uint32_t getCount() const override; + SymIndexId getTypeId() const override; + uint64_t getLength() const override; + +protected: + codeview::ArrayRecord Record; + codeview::TypeIndex Index; +}; + +} // namespace pdb +} // namespace llvm + +#endif diff --git a/clang-r353983/include/llvm/DebugInfo/PDB/Native/NativeTypeBuiltin.h b/clang-r353983/include/llvm/DebugInfo/PDB/Native/NativeTypeBuiltin.h new file mode 100644 index 00000000..8bb09f05 --- /dev/null +++ b/clang-r353983/include/llvm/DebugInfo/PDB/Native/NativeTypeBuiltin.h @@ -0,0 +1,49 @@ +//===- NativeTypeBuiltin.h ---------------------------------------- C++ -*-===// +// +// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. +// See https://llvm.org/LICENSE.txt for license information. +// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception +// +//===----------------------------------------------------------------------===// + +#ifndef LLVM_DEBUGINFO_PDB_NATIVE_NATIVETYPEBUILTIN_H +#define LLVM_DEBUGINFO_PDB_NATIVE_NATIVETYPEBUILTIN_H + +#include "llvm/DebugInfo/PDB/Native/NativeRawSymbol.h" + +#include "llvm/DebugInfo/PDB/PDBTypes.h" + +namespace llvm { +namespace pdb { + +class NativeSession; + +class NativeTypeBuiltin : public NativeRawSymbol { +public: + NativeTypeBuiltin(NativeSession &PDBSession, SymIndexId Id, + codeview::ModifierOptions Mods, PDB_BuiltinType T, + uint64_t L); + ~NativeTypeBuiltin() override; + + void dump(raw_ostream &OS, int Indent, PdbSymbolIdField ShowIdFields, + PdbSymbolIdField RecurseIdFields) const override; + + PDB_SymType getSymTag() const override; + + PDB_BuiltinType getBuiltinType() const override; + bool isConstType() const override; + uint64_t getLength() const override; + bool isUnalignedType() const override; + bool isVolatileType() const override; + +protected: + NativeSession &Session; + codeview::ModifierOptions Mods; + PDB_BuiltinType Type; + uint64_t Length; +}; + +} // namespace pdb +} // namespace llvm + +#endif diff --git a/clang-r353983/include/llvm/DebugInfo/PDB/Native/NativeTypeEnum.h b/clang-r353983/include/llvm/DebugInfo/PDB/Native/NativeTypeEnum.h new file mode 100644 index 00000000..2068c88f --- /dev/null +++ b/clang-r353983/include/llvm/DebugInfo/PDB/Native/NativeTypeEnum.h @@ -0,0 +1,74 @@ +//===- NativeTypeEnum.h - info about enum type ------------------*- C++ -*-===// +// +// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. +// See https://llvm.org/LICENSE.txt for license information. +// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception +// +//===----------------------------------------------------------------------===// + +#ifndef LLVM_DEBUGINFO_PDB_NATIVE_NATIVETYPEENUM_H +#define LLVM_DEBUGINFO_PDB_NATIVE_NATIVETYPEENUM_H + +#include "llvm/ADT/Optional.h" +#include "llvm/DebugInfo/CodeView/CodeView.h" +#include "llvm/DebugInfo/CodeView/TypeVisitorCallbacks.h" +#include "llvm/DebugInfo/PDB/Native/NativeRawSymbol.h" +#include "llvm/DebugInfo/PDB/Native/NativeSession.h" + +namespace llvm { +namespace pdb { + +class NativeTypeBuiltin; + +class NativeTypeEnum : public NativeRawSymbol { +public: + NativeTypeEnum(NativeSession &Session, SymIndexId Id, codeview::TypeIndex TI, + codeview::EnumRecord Record); + + NativeTypeEnum(NativeSession &Session, SymIndexId Id, + NativeTypeEnum &UnmodifiedType, + codeview::ModifierRecord Modifier); + ~NativeTypeEnum() override; + + void dump(raw_ostream &OS, int Indent, PdbSymbolIdField ShowIdFields, + PdbSymbolIdField RecurseIdFields) const override; + + std::unique_ptr<IPDBEnumSymbols> + findChildren(PDB_SymType Type) const override; + + PDB_BuiltinType getBuiltinType() const override; + PDB_SymType getSymTag() const override; + SymIndexId getUnmodifiedTypeId() const override; + bool hasConstructor() const override; + bool hasAssignmentOperator() const override; + bool hasCastOperator() const override; + uint64_t getLength() const override; + std::string getName() const override; + bool isConstType() const override; + bool isVolatileType() const override; + bool isUnalignedType() const override; + bool isNested() const override; + bool hasOverloadedOperator() const override; + bool hasNestedTypes() const override; + bool isIntrinsic() const override; + bool isPacked() const override; + bool isScoped() const override; + SymIndexId getTypeId() const override; + bool isRefUdt() const override; + bool isValueUdt() const override; + bool isInterfaceUdt() const override; + + const NativeTypeBuiltin &getUnderlyingBuiltinType() const; + const codeview::EnumRecord &getEnumRecord() const { return *Record; } + +protected: + codeview::TypeIndex Index; + Optional<codeview::EnumRecord> Record; + NativeTypeEnum *UnmodifiedType = nullptr; + Optional<codeview::ModifierRecord> Modifiers; +}; + +} // namespace pdb +} // namespace llvm + +#endif // LLVM_DEBUGINFO_PDB_NATIVE_NATIVETYPEENUM_H diff --git a/clang-r353983/include/llvm/DebugInfo/PDB/Native/NativeTypeFunctionSig.h b/clang-r353983/include/llvm/DebugInfo/PDB/Native/NativeTypeFunctionSig.h new file mode 100644 index 00000000..a7ea287d --- /dev/null +++ b/clang-r353983/include/llvm/DebugInfo/PDB/Native/NativeTypeFunctionSig.h @@ -0,0 +1,73 @@ +//===- NativeTypeFunctionSig.h - info about function signature ---*- C++-*-===// +// +// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. +// See https://llvm.org/LICENSE.txt for license information. +// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception +// +//===----------------------------------------------------------------------===// + +#ifndef LLVM_DEBUGINFO_PDB_NATIVE_NATIVETYPEFUNCTIONSIG_H +#define LLVM_DEBUGINFO_PDB_NATIVE_NATIVETYPEFUNCTIONSIG_H + +#include "llvm/ADT/Optional.h" +#include "llvm/ADT/SmallVector.h" +#include "llvm/DebugInfo/CodeView/CodeView.h" +#include "llvm/DebugInfo/CodeView/TypeRecord.h" +#include "llvm/DebugInfo/PDB/Native/NativeRawSymbol.h" +#include "llvm/DebugInfo/PDB/Native/NativeSession.h" + +namespace llvm { +namespace pdb { + +class NativeTypeUDT; + +class NativeTypeFunctionSig : public NativeRawSymbol { +protected: + void initialize() override; + +public: + NativeTypeFunctionSig(NativeSession &Session, SymIndexId Id, + codeview::TypeIndex TI, codeview::ProcedureRecord Proc); + + NativeTypeFunctionSig(NativeSession &Session, SymIndexId Id, + codeview::TypeIndex TI, + codeview::MemberFunctionRecord MemberFunc); + + ~NativeTypeFunctionSig() override; + + void dump(raw_ostream &OS, int Indent, PdbSymbolIdField ShowIdFields, + PdbSymbolIdField RecurseIdFields) const override; + + std::unique_ptr<IPDBEnumSymbols> + findChildren(PDB_SymType Type) const override; + + SymIndexId getClassParentId() const override; + PDB_CallingConv getCallingConvention() const override; + uint32_t getCount() const override; + SymIndexId getTypeId() const override; + int32_t getThisAdjust() const override; + bool hasConstructor() const override; + bool isConstType() const override; + bool isConstructorVirtualBase() const override; + bool isCxxReturnUdt() const override; + bool isUnalignedType() const override; + bool isVolatileType() const override; + +private: + void initializeArgList(codeview::TypeIndex ArgListTI); + + union { + codeview::MemberFunctionRecord MemberFunc; + codeview::ProcedureRecord Proc; + }; + + SymIndexId ClassParentId = 0; + codeview::TypeIndex Index; + codeview::ArgListRecord ArgList; + bool IsMemberFunction = false; +}; + +} // namespace pdb +} // namespace llvm + +#endif // LLVM_DEBUGINFO_PDB_NATIVE_NATIVETYPEPOINTER_H
\ No newline at end of file diff --git a/clang-r353983/include/llvm/DebugInfo/PDB/Native/NativeTypePointer.h b/clang-r353983/include/llvm/DebugInfo/PDB/Native/NativeTypePointer.h new file mode 100644 index 00000000..446f77db --- /dev/null +++ b/clang-r353983/include/llvm/DebugInfo/PDB/Native/NativeTypePointer.h @@ -0,0 +1,60 @@ +//===- NativeTypePointer.h - info about pointer type -------------*- C++-*-===// +// +// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. +// See https://llvm.org/LICENSE.txt for license information. +// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception +// +//===----------------------------------------------------------------------===// + +#ifndef LLVM_DEBUGINFO_PDB_NATIVE_NATIVETYPEPOINTER_H +#define LLVM_DEBUGINFO_PDB_NATIVE_NATIVETYPEPOINTER_H + +#include "llvm/ADT/Optional.h" +#include "llvm/DebugInfo/CodeView/CodeView.h" +#include "llvm/DebugInfo/CodeView/TypeRecord.h" +#include "llvm/DebugInfo/PDB/Native/NativeRawSymbol.h" +#include "llvm/DebugInfo/PDB/Native/NativeSession.h" + +namespace llvm { +namespace pdb { + +class NativeTypePointer : public NativeRawSymbol { +public: + // Create a pointer record for a simple type. + NativeTypePointer(NativeSession &Session, SymIndexId Id, + codeview::TypeIndex TI); + + // Create a pointer record for a non-simple type. + NativeTypePointer(NativeSession &Session, SymIndexId Id, + codeview::TypeIndex TI, codeview::PointerRecord PR); + ~NativeTypePointer() override; + + void dump(raw_ostream &OS, int Indent, PdbSymbolIdField ShowIdFields, + PdbSymbolIdField RecurseIdFields) const override; + + SymIndexId getClassParentId() const override; + bool isConstType() const override; + uint64_t getLength() const override; + bool isReference() const override; + bool isRValueReference() const override; + bool isPointerToDataMember() const override; + bool isPointerToMemberFunction() const override; + SymIndexId getTypeId() const override; + bool isRestrictedType() const override; + bool isVolatileType() const override; + bool isUnalignedType() const override; + + bool isSingleInheritance() const override; + bool isMultipleInheritance() const override; + bool isVirtualInheritance() const override; + +protected: + bool isMemberPointer() const; + codeview::TypeIndex TI; + Optional<codeview::PointerRecord> Record; +}; + +} // namespace pdb +} // namespace llvm + +#endif // LLVM_DEBUGINFO_PDB_NATIVE_NATIVETYPEPOINTER_H
\ No newline at end of file diff --git a/clang-r353983/include/llvm/DebugInfo/PDB/Native/NativeTypeTypedef.h b/clang-r353983/include/llvm/DebugInfo/PDB/Native/NativeTypeTypedef.h new file mode 100644 index 00000000..fe8a6f7f --- /dev/null +++ b/clang-r353983/include/llvm/DebugInfo/PDB/Native/NativeTypeTypedef.h @@ -0,0 +1,41 @@ +//===- NativeTypeTypedef.h - info about typedef ------------------*- C++-*-===// +// +// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. +// See https://llvm.org/LICENSE.txt for license information. +// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception +// +//===----------------------------------------------------------------------===// + +#ifndef LLVM_DEBUGINFO_PDB_NATIVE_NATIVETYPETYPEDEF_H +#define LLVM_DEBUGINFO_PDB_NATIVE_NATIVETYPETYPEDEF_H + +#include "llvm/DebugInfo/CodeView/CodeView.h" +#include "llvm/DebugInfo/CodeView/SymbolRecord.h" +#include "llvm/DebugInfo/PDB/Native/NativeRawSymbol.h" +#include "llvm/DebugInfo/PDB/Native/NativeSession.h" + +namespace llvm { +namespace pdb { + +class NativeTypeTypedef : public NativeRawSymbol { +public: + // Create a pointer record for a non-simple type. + NativeTypeTypedef(NativeSession &Session, SymIndexId Id, + codeview::UDTSym Typedef); + + ~NativeTypeTypedef() override; + + void dump(raw_ostream &OS, int Indent, PdbSymbolIdField ShowIdFields, + PdbSymbolIdField RecurseIdFields) const override; + + std::string getName() const override; + SymIndexId getTypeId() const override; + +protected: + codeview::UDTSym Record; +}; + +} // namespace pdb +} // namespace llvm + +#endif // LLVM_DEBUGINFO_PDB_NATIVE_NATIVETYPEPOINTER_H
\ No newline at end of file diff --git a/clang-r353983/include/llvm/DebugInfo/PDB/Native/NativeTypeUDT.h b/clang-r353983/include/llvm/DebugInfo/PDB/Native/NativeTypeUDT.h new file mode 100644 index 00000000..8f4dee3e --- /dev/null +++ b/clang-r353983/include/llvm/DebugInfo/PDB/Native/NativeTypeUDT.h @@ -0,0 +1,73 @@ +//===- NativeTypeUDT.h - info about class/struct type ------------*- C++-*-===// +// +// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. +// See https://llvm.org/LICENSE.txt for license information. +// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception +// +//===----------------------------------------------------------------------===// + +#ifndef LLVM_DEBUGINFO_PDB_NATIVE_NATIVETYPEUDT_H +#define LLVM_DEBUGINFO_PDB_NATIVE_NATIVETYPEUDT_H + +#include "llvm/ADT/Optional.h" +#include "llvm/DebugInfo/CodeView/CodeView.h" +#include "llvm/DebugInfo/CodeView/TypeRecord.h" +#include "llvm/DebugInfo/PDB/Native/NativeRawSymbol.h" +#include "llvm/DebugInfo/PDB/Native/NativeSession.h" + +namespace llvm { +namespace pdb { + +class NativeTypeUDT : public NativeRawSymbol { +public: + NativeTypeUDT(NativeSession &Session, SymIndexId Id, codeview::TypeIndex TI, + codeview::ClassRecord Class); + + NativeTypeUDT(NativeSession &Session, SymIndexId Id, codeview::TypeIndex TI, + codeview::UnionRecord Union); + + NativeTypeUDT(NativeSession &Session, SymIndexId Id, + NativeTypeUDT &UnmodifiedType, + codeview::ModifierRecord Modifier); + + ~NativeTypeUDT() override; + + void dump(raw_ostream &OS, int Indent, PdbSymbolIdField ShowIdFields, + PdbSymbolIdField RecurseIdFields) const override; + + std::string getName() const override; + SymIndexId getLexicalParentId() const override; + SymIndexId getUnmodifiedTypeId() const override; + SymIndexId getVirtualTableShapeId() const override; + uint64_t getLength() const override; + PDB_UdtType getUdtKind() const override; + bool hasConstructor() const override; + bool isConstType() const override; + bool hasAssignmentOperator() const override; + bool hasCastOperator() const override; + bool hasNestedTypes() const override; + bool hasOverloadedOperator() const override; + bool isInterfaceUdt() const override; + bool isIntrinsic() const override; + bool isNested() const override; + bool isPacked() const override; + bool isRefUdt() const override; + bool isScoped() const override; + bool isValueUdt() const override; + bool isUnalignedType() const override; + bool isVolatileType() const override; + +protected: + codeview::TypeIndex Index; + + Optional<codeview::ClassRecord> Class; + Optional<codeview::UnionRecord> Union; + NativeTypeUDT *UnmodifiedType = nullptr; + codeview::TagRecord *Tag = nullptr; + Optional<codeview::ModifierRecord> Modifiers; +}; + +} // namespace pdb +} // namespace llvm + +#endif // LLVM_DEBUGINFO_PDB_NATIVE_NATIVETYPEUDT_H
\ No newline at end of file diff --git a/clang-r353983/include/llvm/DebugInfo/PDB/Native/NativeTypeVTShape.h b/clang-r353983/include/llvm/DebugInfo/PDB/Native/NativeTypeVTShape.h new file mode 100644 index 00000000..4ec0f9bf --- /dev/null +++ b/clang-r353983/include/llvm/DebugInfo/PDB/Native/NativeTypeVTShape.h @@ -0,0 +1,45 @@ +//===- NativeTypeVTShape.h - info about virtual table shape ------*- C++-*-===// +// +// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. +// See https://llvm.org/LICENSE.txt for license information. +// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception +// +//===----------------------------------------------------------------------===// + +#ifndef LLVM_DEBUGINFO_PDB_NATIVE_NATIVETYPEVTSHAPE_H +#define LLVM_DEBUGINFO_PDB_NATIVE_NATIVETYPEVTSHAPE_H + +#include "llvm/ADT/Optional.h" +#include "llvm/DebugInfo/CodeView/CodeView.h" +#include "llvm/DebugInfo/CodeView/TypeRecord.h" +#include "llvm/DebugInfo/PDB/Native/NativeRawSymbol.h" +#include "llvm/DebugInfo/PDB/Native/NativeSession.h" + +namespace llvm { +namespace pdb { + +class NativeTypeVTShape : public NativeRawSymbol { +public: + // Create a pointer record for a non-simple type. + NativeTypeVTShape(NativeSession &Session, SymIndexId Id, + codeview::TypeIndex TI, codeview::VFTableShapeRecord SR); + + ~NativeTypeVTShape() override; + + void dump(raw_ostream &OS, int Indent, PdbSymbolIdField ShowIdFields, + PdbSymbolIdField RecurseIdFields) const override; + + bool isConstType() const override; + bool isVolatileType() const override; + bool isUnalignedType() const override; + uint32_t getCount() const override; + +protected: + codeview::TypeIndex TI; + codeview::VFTableShapeRecord Record; +}; + +} // namespace pdb +} // namespace llvm + +#endif // LLVM_DEBUGINFO_PDB_NATIVE_NATIVETYPEVTSHAPE_H
\ No newline at end of file diff --git a/clang-r353983/include/llvm/DebugInfo/PDB/Native/PDBFile.h b/clang-r353983/include/llvm/DebugInfo/PDB/Native/PDBFile.h new file mode 100644 index 00000000..cb9bd071 --- /dev/null +++ b/clang-r353983/include/llvm/DebugInfo/PDB/Native/PDBFile.h @@ -0,0 +1,143 @@ +//===- PDBFile.h - Low level interface to a PDB file ------------*- C++ -*-===// +// +// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. +// See https://llvm.org/LICENSE.txt for license information. +// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception +// +//===----------------------------------------------------------------------===// + +#ifndef LLVM_DEBUGINFO_PDB_RAW_PDBFILE_H +#define LLVM_DEBUGINFO_PDB_RAW_PDBFILE_H + +#include "llvm/ADT/DenseMap.h" +#include "llvm/DebugInfo/MSF/IMSFFile.h" +#include "llvm/DebugInfo/MSF/MSFCommon.h" +#include "llvm/Support/Allocator.h" +#include "llvm/Support/BinaryStreamRef.h" +#include "llvm/Support/Endian.h" +#include "llvm/Support/Error.h" +#include "llvm/Support/MathExtras.h" + +#include <memory> + +namespace llvm { + +class BinaryStream; + +namespace msf { +class MappedBlockStream; +} + +namespace pdb { +class DbiStream; +class GlobalsStream; +class InfoStream; +class PDBStringTable; +class PDBFileBuilder; +class PublicsStream; +class SymbolStream; +class TpiStream; + +class PDBFile : public msf::IMSFFile { + friend PDBFileBuilder; + +public: + PDBFile(StringRef Path, std::unique_ptr<BinaryStream> PdbFileBuffer, + BumpPtrAllocator &Allocator); + ~PDBFile() override; + + StringRef getFileDirectory() const; + StringRef getFilePath() const; + + uint32_t getFreeBlockMapBlock() const; + uint32_t getUnknown1() const; + + uint32_t getBlockSize() const override; + uint32_t getBlockCount() const override; + uint32_t getNumDirectoryBytes() const; + uint32_t getBlockMapIndex() const; + uint32_t getNumDirectoryBlocks() const; + uint64_t getBlockMapOffset() const; + + uint32_t getNumStreams() const override; + uint32_t getMaxStreamSize() const; + uint32_t getStreamByteSize(uint32_t StreamIndex) const override; + ArrayRef<support::ulittle32_t> + getStreamBlockList(uint32_t StreamIndex) const override; + uint32_t getFileSize() const; + + Expected<ArrayRef<uint8_t>> getBlockData(uint32_t BlockIndex, + uint32_t NumBytes) const override; + Error setBlockData(uint32_t BlockIndex, uint32_t Offset, + ArrayRef<uint8_t> Data) const override; + + ArrayRef<support::ulittle32_t> getStreamSizes() const { + return ContainerLayout.StreamSizes; + } + ArrayRef<ArrayRef<support::ulittle32_t>> getStreamMap() const { + return ContainerLayout.StreamMap; + } + + const msf::MSFLayout &getMsfLayout() const { return ContainerLayout; } + BinaryStreamRef getMsfBuffer() const { return *Buffer; } + + ArrayRef<support::ulittle32_t> getDirectoryBlockArray() const; + + std::unique_ptr<msf::MappedBlockStream> createIndexedStream(uint16_t SN); + + msf::MSFStreamLayout getStreamLayout(uint32_t StreamIdx) const; + msf::MSFStreamLayout getFpmStreamLayout() const; + + Error parseFileHeaders(); + Error parseStreamData(); + + Expected<InfoStream &> getPDBInfoStream(); + Expected<DbiStream &> getPDBDbiStream(); + Expected<GlobalsStream &> getPDBGlobalsStream(); + Expected<TpiStream &> getPDBTpiStream(); + Expected<TpiStream &> getPDBIpiStream(); + Expected<PublicsStream &> getPDBPublicsStream(); + Expected<SymbolStream &> getPDBSymbolStream(); + Expected<PDBStringTable &> getStringTable(); + + BumpPtrAllocator &getAllocator() { return Allocator; } + + bool hasPDBDbiStream() const; + bool hasPDBGlobalsStream(); + bool hasPDBInfoStream() const; + bool hasPDBIpiStream() const; + bool hasPDBPublicsStream(); + bool hasPDBSymbolStream(); + bool hasPDBTpiStream() const; + bool hasPDBStringTable(); + + uint32_t getPointerSize(); + +private: + Expected<std::unique_ptr<msf::MappedBlockStream>> + safelyCreateIndexedStream(const msf::MSFLayout &Layout, + BinaryStreamRef MsfData, + uint32_t StreamIndex) const; + + std::string FilePath; + BumpPtrAllocator &Allocator; + + std::unique_ptr<BinaryStream> Buffer; + + msf::MSFLayout ContainerLayout; + + std::unique_ptr<GlobalsStream> Globals; + std::unique_ptr<InfoStream> Info; + std::unique_ptr<DbiStream> Dbi; + std::unique_ptr<TpiStream> Tpi; + std::unique_ptr<TpiStream> Ipi; + std::unique_ptr<PublicsStream> Publics; + std::unique_ptr<SymbolStream> Symbols; + std::unique_ptr<msf::MappedBlockStream> DirectoryStream; + std::unique_ptr<msf::MappedBlockStream> StringTableStream; + std::unique_ptr<PDBStringTable> Strings; +}; +} +} + +#endif diff --git a/clang-r353983/include/llvm/DebugInfo/PDB/Native/PDBFileBuilder.h b/clang-r353983/include/llvm/DebugInfo/PDB/Native/PDBFileBuilder.h new file mode 100644 index 00000000..72000bdc --- /dev/null +++ b/clang-r353983/include/llvm/DebugInfo/PDB/Native/PDBFileBuilder.h @@ -0,0 +1,110 @@ +//===- PDBFileBuilder.h - PDB File Creation ---------------------*- C++ -*-===// +// +// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. +// See https://llvm.org/LICENSE.txt for license information. +// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception +// +//===----------------------------------------------------------------------===// + +#ifndef LLVM_DEBUGINFO_PDB_RAW_PDBFILEBUILDER_H +#define LLVM_DEBUGINFO_PDB_RAW_PDBFILEBUILDER_H + +#include "llvm/ADT/ArrayRef.h" +#include "llvm/ADT/BitVector.h" +#include "llvm/ADT/Optional.h" +#include "llvm/DebugInfo/PDB/Native/NamedStreamMap.h" +#include "llvm/DebugInfo/PDB/Native/PDBFile.h" +#include "llvm/DebugInfo/PDB/Native/PDBStringTableBuilder.h" +#include "llvm/DebugInfo/PDB/Native/RawConstants.h" +#include "llvm/DebugInfo/PDB/Native/RawTypes.h" +#include "llvm/Support/Allocator.h" +#include "llvm/Support/Endian.h" +#include "llvm/Support/Error.h" +#include "llvm/Support/MemoryBuffer.h" + +#include <memory> +#include <vector> + +namespace llvm { +namespace msf { +class MSFBuilder; +} +namespace pdb { +class DbiStreamBuilder; +class InfoStreamBuilder; +class GSIStreamBuilder; +class TpiStreamBuilder; + +class PDBFileBuilder { +public: + explicit PDBFileBuilder(BumpPtrAllocator &Allocator); + ~PDBFileBuilder(); + PDBFileBuilder(const PDBFileBuilder &) = delete; + PDBFileBuilder &operator=(const PDBFileBuilder &) = delete; + + Error initialize(uint32_t BlockSize); + + msf::MSFBuilder &getMsfBuilder(); + InfoStreamBuilder &getInfoBuilder(); + DbiStreamBuilder &getDbiBuilder(); + TpiStreamBuilder &getTpiBuilder(); + TpiStreamBuilder &getIpiBuilder(); + PDBStringTableBuilder &getStringTableBuilder(); + GSIStreamBuilder &getGsiBuilder(); + + // If HashPDBContentsToGUID is true on the InfoStreamBuilder, Guid is filled + // with the computed PDB GUID on return. + Error commit(StringRef Filename, codeview::GUID *Guid); + + Expected<uint32_t> getNamedStreamIndex(StringRef Name) const; + Error addNamedStream(StringRef Name, StringRef Data); + void addInjectedSource(StringRef Name, std::unique_ptr<MemoryBuffer> Buffer); + +private: + struct InjectedSourceDescriptor { + // The full name of the stream that contains the contents of this injected + // source. This is built as a concatenation of the literal "/src/files" + // plus the "vname". + std::string StreamName; + + // The exact name of the file name as specified by the user. + uint32_t NameIndex; + + // The string table index of the "vname" of the file. As far as we + // understand, this is the same as the name, except it is lowercased and + // forward slashes are converted to backslashes. + uint32_t VNameIndex; + std::unique_ptr<MemoryBuffer> Content; + }; + + Error finalizeMsfLayout(); + Expected<uint32_t> allocateNamedStream(StringRef Name, uint32_t Size); + + void commitFpm(WritableBinaryStream &MsfBuffer, const msf::MSFLayout &Layout); + void commitInjectedSources(WritableBinaryStream &MsfBuffer, + const msf::MSFLayout &Layout); + void commitSrcHeaderBlock(WritableBinaryStream &MsfBuffer, + const msf::MSFLayout &Layout); + + BumpPtrAllocator &Allocator; + + std::unique_ptr<msf::MSFBuilder> Msf; + std::unique_ptr<InfoStreamBuilder> Info; + std::unique_ptr<DbiStreamBuilder> Dbi; + std::unique_ptr<GSIStreamBuilder> Gsi; + std::unique_ptr<TpiStreamBuilder> Tpi; + std::unique_ptr<TpiStreamBuilder> Ipi; + + PDBStringTableBuilder Strings; + StringTableHashTraits InjectedSourceHashTraits; + HashTable<SrcHeaderBlockEntry, StringTableHashTraits> InjectedSourceTable; + + SmallVector<InjectedSourceDescriptor, 2> InjectedSources; + + NamedStreamMap NamedStreams; + DenseMap<uint32_t, std::string> NamedStreamData; +}; +} +} + +#endif diff --git a/clang-r353983/include/llvm/DebugInfo/PDB/Native/PDBStringTable.h b/clang-r353983/include/llvm/DebugInfo/PDB/Native/PDBStringTable.h new file mode 100644 index 00000000..57f0b64a --- /dev/null +++ b/clang-r353983/include/llvm/DebugInfo/PDB/Native/PDBStringTable.h @@ -0,0 +1,64 @@ +//===- PDBStringTable.h - PDB String Table -----------------------*- C++-*-===// +// +// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. +// See https://llvm.org/LICENSE.txt for license information. +// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception +// +//===----------------------------------------------------------------------===// + +#ifndef LLVM_DEBUGINFO_PDB_RAW_PDBSTRINGTABLE_H +#define LLVM_DEBUGINFO_PDB_RAW_PDBSTRINGTABLE_H + +#include "llvm/ADT/ArrayRef.h" +#include "llvm/ADT/StringRef.h" +#include "llvm/DebugInfo/CodeView/DebugStringTableSubsection.h" +#include "llvm/Support/BinaryStreamArray.h" +#include "llvm/Support/BinaryStreamRef.h" +#include "llvm/Support/Endian.h" +#include "llvm/Support/Error.h" +#include <cstdint> +#include <vector> + +namespace llvm { +class BinaryStreamReader; + +namespace msf { +class MappedBlockStream; +} + +namespace pdb { + +struct PDBStringTableHeader; + +class PDBStringTable { +public: + Error reload(BinaryStreamReader &Reader); + + uint32_t getByteSize() const; + uint32_t getNameCount() const; + uint32_t getHashVersion() const; + uint32_t getSignature() const; + + Expected<StringRef> getStringForID(uint32_t ID) const; + Expected<uint32_t> getIDForString(StringRef Str) const; + + FixedStreamArray<support::ulittle32_t> name_ids() const; + + const codeview::DebugStringTableSubsectionRef &getStringTable() const; + +private: + Error readHeader(BinaryStreamReader &Reader); + Error readStrings(BinaryStreamReader &Reader); + Error readHashTable(BinaryStreamReader &Reader); + Error readEpilogue(BinaryStreamReader &Reader); + + const PDBStringTableHeader *Header = nullptr; + codeview::DebugStringTableSubsectionRef Strings; + FixedStreamArray<support::ulittle32_t> IDs; + uint32_t NameCount = 0; +}; + +} // end namespace pdb +} // end namespace llvm + +#endif // LLVM_DEBUGINFO_PDB_RAW_STRINGTABLE_H diff --git a/clang-r353983/include/llvm/DebugInfo/PDB/Native/PDBStringTableBuilder.h b/clang-r353983/include/llvm/DebugInfo/PDB/Native/PDBStringTableBuilder.h new file mode 100644 index 00000000..57267ef5 --- /dev/null +++ b/clang-r353983/include/llvm/DebugInfo/PDB/Native/PDBStringTableBuilder.h @@ -0,0 +1,71 @@ +//===- PDBStringTableBuilder.h - PDB String Table Builder -------*- C++ -*-===// +// +// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. +// See https://llvm.org/LICENSE.txt for license information. +// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception +// +//===----------------------------------------------------------------------===// +// +// This file creates the "/names" stream. +// +//===----------------------------------------------------------------------===// + +#ifndef LLVM_DEBUGINFO_PDB_RAW_PDBSTRINGTABLEBUILDER_H +#define LLVM_DEBUGINFO_PDB_RAW_PDBSTRINGTABLEBUILDER_H + +#include "llvm/ADT/DenseMap.h" +#include "llvm/ADT/StringRef.h" +#include "llvm/DebugInfo/CodeView/DebugStringTableSubsection.h" +#include "llvm/Support/Error.h" +#include <vector> + +namespace llvm { +class BinaryStreamWriter; +class WritableBinaryStreamRef; + +namespace msf { +struct MSFLayout; +} + +namespace pdb { + +class PDBFileBuilder; +class PDBStringTableBuilder; + +struct StringTableHashTraits { + PDBStringTableBuilder *Table; + + explicit StringTableHashTraits(PDBStringTableBuilder &Table); + uint32_t hashLookupKey(StringRef S) const; + StringRef storageKeyToLookupKey(uint32_t Offset) const; + uint32_t lookupKeyToStorageKey(StringRef S); +}; + +class PDBStringTableBuilder { +public: + // If string S does not exist in the string table, insert it. + // Returns the ID for S. + uint32_t insert(StringRef S); + + uint32_t getIdForString(StringRef S) const; + StringRef getStringForId(uint32_t Id) const; + + uint32_t calculateSerializedSize() const; + Error commit(BinaryStreamWriter &Writer) const; + + void setStrings(const codeview::DebugStringTableSubsection &Strings); + +private: + uint32_t calculateHashTableSize() const; + Error writeHeader(BinaryStreamWriter &Writer) const; + Error writeStrings(BinaryStreamWriter &Writer) const; + Error writeHashTable(BinaryStreamWriter &Writer) const; + Error writeEpilogue(BinaryStreamWriter &Writer) const; + + codeview::DebugStringTableSubsection Strings; +}; + +} // end namespace pdb +} // end namespace llvm + +#endif // LLVM_DEBUGINFO_PDB_RAW_PDBSTRINGTABLEBUILDER_H diff --git a/clang-r353983/include/llvm/DebugInfo/PDB/Native/PublicsStream.h b/clang-r353983/include/llvm/DebugInfo/PDB/Native/PublicsStream.h new file mode 100644 index 00000000..ee28d108 --- /dev/null +++ b/clang-r353983/include/llvm/DebugInfo/PDB/Native/PublicsStream.h @@ -0,0 +1,59 @@ +//===- PublicsStream.h - PDB Public Symbol Stream -------- ------*- C++ -*-===// +// +// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. +// See https://llvm.org/LICENSE.txt for license information. +// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception +// +//===----------------------------------------------------------------------===// + +#ifndef LLVM_DEBUGINFO_PDB_RAW_PUBLICSSTREAM_H +#define LLVM_DEBUGINFO_PDB_RAW_PUBLICSSTREAM_H + +#include "llvm/DebugInfo/CodeView/SymbolRecord.h" +#include "llvm/DebugInfo/MSF/MappedBlockStream.h" +#include "llvm/DebugInfo/PDB/Native/GlobalsStream.h" +#include "llvm/DebugInfo/PDB/Native/RawConstants.h" +#include "llvm/DebugInfo/PDB/Native/RawTypes.h" +#include "llvm/DebugInfo/PDB/PDBTypes.h" +#include "llvm/Support/BinaryStreamArray.h" +#include "llvm/Support/Error.h" + +namespace llvm { +namespace pdb { +class DbiStream; +struct GSIHashHeader; +class PDBFile; + +class PublicsStream { +public: + PublicsStream(std::unique_ptr<msf::MappedBlockStream> Stream); + ~PublicsStream(); + Error reload(); + + uint32_t getSymHash() const; + uint16_t getThunkTableSection() const; + uint32_t getThunkTableOffset() const; + const GSIHashTable &getPublicsTable() const { return PublicsTable; } + FixedStreamArray<support::ulittle32_t> getAddressMap() const { + return AddressMap; + } + FixedStreamArray<support::ulittle32_t> getThunkMap() const { + return ThunkMap; + } + FixedStreamArray<SectionOffset> getSectionOffsets() const { + return SectionOffsets; + } + +private: + std::unique_ptr<msf::MappedBlockStream> Stream; + GSIHashTable PublicsTable; + FixedStreamArray<support::ulittle32_t> AddressMap; + FixedStreamArray<support::ulittle32_t> ThunkMap; + FixedStreamArray<SectionOffset> SectionOffsets; + + const PublicsStreamHeader *Header; +}; +} +} + +#endif diff --git a/clang-r353983/include/llvm/DebugInfo/PDB/Native/RawConstants.h b/clang-r353983/include/llvm/DebugInfo/PDB/Native/RawConstants.h new file mode 100644 index 00000000..0dde5ef6 --- /dev/null +++ b/clang-r353983/include/llvm/DebugInfo/PDB/Native/RawConstants.h @@ -0,0 +1,118 @@ +//===- RawConstants.h -------------------------------------------*- C++ -*-===// +// +// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. +// See https://llvm.org/LICENSE.txt for license information. +// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception +// +//===----------------------------------------------------------------------===// + +#ifndef LLVM_DEBUGINFO_PDB_RAW_PDBRAWCONSTANTS_H +#define LLVM_DEBUGINFO_PDB_RAW_PDBRAWCONSTANTS_H + +#include "llvm/ADT/BitmaskEnum.h" +#include "llvm/DebugInfo/CodeView/CodeView.h" +#include <cstdint> + +namespace llvm { +namespace pdb { + +const uint16_t kInvalidStreamIndex = 0xFFFF; + +enum PdbRaw_ImplVer : uint32_t { + PdbImplVC2 = 19941610, + PdbImplVC4 = 19950623, + PdbImplVC41 = 19950814, + PdbImplVC50 = 19960307, + PdbImplVC98 = 19970604, + PdbImplVC70Dep = 19990604, // deprecated + PdbImplVC70 = 20000404, + PdbImplVC80 = 20030901, + PdbImplVC110 = 20091201, + PdbImplVC140 = 20140508, +}; + +enum class PdbRaw_SrcHeaderBlockVer : uint32_t { SrcVerOne = 19980827 }; + +enum class PdbRaw_FeatureSig : uint32_t { + VC110 = PdbImplVC110, + VC140 = PdbImplVC140, + NoTypeMerge = 0x4D544F4E, + MinimalDebugInfo = 0x494E494D, +}; + +enum PdbRaw_Features : uint32_t { + PdbFeatureNone = 0x0, + PdbFeatureContainsIdStream = 0x1, + PdbFeatureMinimalDebugInfo = 0x2, + PdbFeatureNoTypeMerging = 0x4, + LLVM_MARK_AS_BITMASK_ENUM(/* LargestValue = */ PdbFeatureNoTypeMerging) +}; + +enum PdbRaw_DbiVer : uint32_t { + PdbDbiVC41 = 930803, + PdbDbiV50 = 19960307, + PdbDbiV60 = 19970606, + PdbDbiV70 = 19990903, + PdbDbiV110 = 20091201 +}; + +enum PdbRaw_TpiVer : uint32_t { + PdbTpiV40 = 19950410, + PdbTpiV41 = 19951122, + PdbTpiV50 = 19961031, + PdbTpiV70 = 19990903, + PdbTpiV80 = 20040203, +}; + +enum PdbRaw_DbiSecContribVer : uint32_t { + DbiSecContribVer60 = 0xeffe0000 + 19970605, + DbiSecContribV2 = 0xeffe0000 + 20140516 +}; + +enum SpecialStream : uint32_t { + // Stream 0 contains the copy of previous version of the MSF directory. + // We are not currently using it, but technically if we find the main + // MSF is corrupted, we could fallback to it. + OldMSFDirectory = 0, + + StreamPDB = 1, + StreamTPI = 2, + StreamDBI = 3, + StreamIPI = 4, + + kSpecialStreamCount +}; + +enum class DbgHeaderType : uint16_t { + FPO, + Exception, + Fixup, + OmapToSrc, + OmapFromSrc, + SectionHdr, + TokenRidMap, + Xdata, + Pdata, + NewFPO, + SectionHdrOrig, + Max +}; + +enum class OMFSegDescFlags : uint16_t { + None = 0, + Read = 1 << 0, // Segment is readable. + Write = 1 << 1, // Segment is writable. + Execute = 1 << 2, // Segment is executable. + AddressIs32Bit = 1 << 3, // Descriptor describes a 32-bit linear address. + IsSelector = 1 << 8, // Frame represents a selector. + IsAbsoluteAddress = 1 << 9, // Frame represents an absolute address. + IsGroup = 1 << 10, // If set, descriptor represents a group. + LLVM_MARK_AS_BITMASK_ENUM(/* LargestValue = */ IsGroup) +}; + +LLVM_ENABLE_BITMASK_ENUMS_IN_NAMESPACE(); + +} // end namespace pdb +} // end namespace llvm + +#endif // LLVM_DEBUGINFO_PDB_RAW_PDBRAWCONSTANTS_H diff --git a/clang-r353983/include/llvm/DebugInfo/PDB/Native/RawError.h b/clang-r353983/include/llvm/DebugInfo/PDB/Native/RawError.h new file mode 100644 index 00000000..aadb64c2 --- /dev/null +++ b/clang-r353983/include/llvm/DebugInfo/PDB/Native/RawError.h @@ -0,0 +1,58 @@ +//===- RawError.h - Error extensions for raw PDB implementation -*- C++ -*-===// +// +// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. +// See https://llvm.org/LICENSE.txt for license information. +// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception +// +//===----------------------------------------------------------------------===// + +#ifndef LLVM_DEBUGINFO_PDB_RAW_RAWERROR_H +#define LLVM_DEBUGINFO_PDB_RAW_RAWERROR_H + +#include "llvm/Support/Error.h" + +#include <string> + +namespace llvm { +namespace pdb { +enum class raw_error_code { + unspecified = 1, + feature_unsupported, + invalid_format, + corrupt_file, + insufficient_buffer, + no_stream, + index_out_of_bounds, + invalid_block_address, + duplicate_entry, + no_entry, + not_writable, + stream_too_long, + invalid_tpi_hash, +}; +} // namespace pdb +} // namespace llvm + +namespace std { +template <> +struct is_error_code_enum<llvm::pdb::raw_error_code> : std::true_type {}; +} // namespace std + +namespace llvm { +namespace pdb { +const std::error_category &RawErrCategory(); + +inline std::error_code make_error_code(raw_error_code E) { + return std::error_code(static_cast<int>(E), RawErrCategory()); +} + +/// Base class for errors originating when parsing raw PDB files +class RawError : public ErrorInfo<RawError, StringError> { +public: + using ErrorInfo<RawError, StringError>::ErrorInfo; // inherit constructors + RawError(const Twine &S) : ErrorInfo(S, raw_error_code::unspecified) {} + static char ID; +}; +} // namespace pdb +} // namespace llvm +#endif diff --git a/clang-r353983/include/llvm/DebugInfo/PDB/Native/RawTypes.h b/clang-r353983/include/llvm/DebugInfo/PDB/Native/RawTypes.h new file mode 100644 index 00000000..84b0cb39 --- /dev/null +++ b/clang-r353983/include/llvm/DebugInfo/PDB/Native/RawTypes.h @@ -0,0 +1,350 @@ +//===- RawTypes.h -----------------------------------------------*- C++ -*-===// +// +// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. +// See https://llvm.org/LICENSE.txt for license information. +// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception +// +//===----------------------------------------------------------------------===// + +#ifndef LLVM_DEBUGINFO_PDB_RAW_RAWTYPES_H +#define LLVM_DEBUGINFO_PDB_RAW_RAWTYPES_H + +#include "llvm/DebugInfo/CodeView/GUID.h" +#include "llvm/DebugInfo/CodeView/TypeRecord.h" +#include "llvm/Support/Endian.h" + +namespace llvm { +namespace pdb { +// This struct is defined as "SO" in langapi/include/pdb.h. +struct SectionOffset { + support::ulittle32_t Off; + support::ulittle16_t Isect; + char Padding[2]; +}; + +/// Header of the hash tables found in the globals and publics sections. +/// Based on GSIHashHdr in +/// https://github.com/Microsoft/microsoft-pdb/blob/master/PDB/dbi/gsi.h +struct GSIHashHeader { + enum : unsigned { + HdrSignature = ~0U, + HdrVersion = 0xeffe0000 + 19990810, + }; + support::ulittle32_t VerSignature; + support::ulittle32_t VerHdr; + support::ulittle32_t HrSize; + support::ulittle32_t NumBuckets; +}; + +// This is HRFile. +struct PSHashRecord { + support::ulittle32_t Off; // Offset in the symbol record stream + support::ulittle32_t CRef; +}; + +// This struct is defined as `SC` in include/dbicommon.h +struct SectionContrib { + support::ulittle16_t ISect; + char Padding[2]; + support::little32_t Off; + support::little32_t Size; + support::ulittle32_t Characteristics; + support::ulittle16_t Imod; + char Padding2[2]; + support::ulittle32_t DataCrc; + support::ulittle32_t RelocCrc; +}; + +// This struct is defined as `SC2` in include/dbicommon.h +struct SectionContrib2 { + // To guarantee SectionContrib2 is standard layout, we cannot use inheritance. + SectionContrib Base; + support::ulittle32_t ISectCoff; +}; + +// This corresponds to the `OMFSegMap` structure. +struct SecMapHeader { + support::ulittle16_t SecCount; // Number of segment descriptors in table + support::ulittle16_t SecCountLog; // Number of logical segment descriptors +}; + +// This corresponds to the `OMFSegMapDesc` structure. The definition is not +// present in the reference implementation, but the layout is derived from +// code that accesses the fields. +struct SecMapEntry { + support::ulittle16_t Flags; // Descriptor flags. See OMFSegDescFlags + support::ulittle16_t Ovl; // Logical overlay number. + support::ulittle16_t Group; // Group index into descriptor array. + support::ulittle16_t Frame; + support::ulittle16_t SecName; // Byte index of the segment or group name + // in the sstSegName table, or 0xFFFF. + support::ulittle16_t ClassName; // Byte index of the class name in the + // sstSegName table, or 0xFFFF. + support::ulittle32_t Offset; // Byte offset of the logical segment + // within the specified physical segment. + // If group is set in flags, offset is the + // offset of the group. + support::ulittle32_t SecByteLength; // Byte count of the segment or group. +}; + +/// Some of the values are stored in bitfields. Since this needs to be portable +/// across compilers and architectures (big / little endian in particular) we +/// can't use the actual structures below, but must instead do the shifting +/// and masking ourselves. The struct definitions are provided for reference. +struct DbiFlags { + /// uint16_t IncrementalLinking : 1; // True if linked incrementally + /// uint16_t IsStripped : 1; // True if private symbols were + /// stripped. + /// uint16_t HasCTypes : 1; // True if linked with /debug:ctypes. + /// uint16_t Reserved : 13; + static const uint16_t FlagIncrementalMask = 0x0001; + static const uint16_t FlagStrippedMask = 0x0002; + static const uint16_t FlagHasCTypesMask = 0x0004; +}; + +struct DbiBuildNo { + /// uint16_t MinorVersion : 8; + /// uint16_t MajorVersion : 7; + /// uint16_t NewVersionFormat : 1; + static const uint16_t BuildMinorMask = 0x00FF; + static const uint16_t BuildMinorShift = 0; + + static const uint16_t BuildMajorMask = 0x7F00; + static const uint16_t BuildMajorShift = 8; + + static const uint16_t NewVersionFormatMask = 0x8000; +}; + +/// The fixed size header that appears at the beginning of the DBI Stream. +struct DbiStreamHeader { + support::little32_t VersionSignature; + support::ulittle32_t VersionHeader; + + /// How "old" is this DBI Stream. Should match the age of the PDB InfoStream. + support::ulittle32_t Age; + + /// Global symbol stream # + support::ulittle16_t GlobalSymbolStreamIndex; + + /// See DbiBuildNo structure. + support::ulittle16_t BuildNumber; + + /// Public symbols stream # + support::ulittle16_t PublicSymbolStreamIndex; + + /// version of mspdbNNN.dll + support::ulittle16_t PdbDllVersion; + + /// Symbol records stream # + support::ulittle16_t SymRecordStreamIndex; + + /// rbld number of mspdbNNN.dll + support::ulittle16_t PdbDllRbld; + + /// Size of module info stream + support::little32_t ModiSubstreamSize; + + /// Size of sec. contrib stream + support::little32_t SecContrSubstreamSize; + + /// Size of sec. map substream + support::little32_t SectionMapSize; + + /// Size of file info substream + support::little32_t FileInfoSize; + + /// Size of type server map + support::little32_t TypeServerSize; + + /// Index of MFC Type Server + support::ulittle32_t MFCTypeServerIndex; + + /// Size of DbgHeader info + support::little32_t OptionalDbgHdrSize; + + /// Size of EC stream (what is EC?) + support::little32_t ECSubstreamSize; + + /// See DbiFlags enum. + support::ulittle16_t Flags; + + /// See PDB_MachineType enum. + support::ulittle16_t MachineType; + + /// Pad to 64 bytes + support::ulittle32_t Reserved; +}; +static_assert(sizeof(DbiStreamHeader) == 64, "Invalid DbiStreamHeader size!"); + +/// The header preceeding the File Info Substream of the DBI stream. +struct FileInfoSubstreamHeader { + /// Total # of modules, should match number of records in the ModuleInfo + /// substream. + support::ulittle16_t NumModules; + + /// Total # of source files. This value is not accurate because PDB actually + /// supports more than 64k source files, so we ignore it and compute the value + /// from other stream fields. + support::ulittle16_t NumSourceFiles; + + /// Following this header the File Info Substream is laid out as follows: + /// ulittle16_t ModIndices[NumModules]; + /// ulittle16_t ModFileCounts[NumModules]; + /// ulittle32_t FileNameOffsets[NumSourceFiles]; + /// char Names[][NumSourceFiles]; + /// with the caveat that `NumSourceFiles` cannot be trusted, so + /// it is computed by summing the `ModFileCounts` array. +}; + +struct ModInfoFlags { + /// 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 + static const uint16_t HasECFlagMask = 0x2; + + static const uint16_t TypeServerIndexMask = 0xFF00; + static const uint16_t TypeServerIndexShift = 8; +}; + +/// The header preceeding each entry in the Module Info substream of the DBI +/// stream. Corresponds to the type MODI in the reference implementation. +struct ModuleInfoHeader { + /// Currently opened module. This field is a pointer in the reference + /// implementation, but that won't work on 64-bit systems, and anyway it + /// doesn't make sense to read a pointer from a file. For now it is unused, + /// so just ignore it. + support::ulittle32_t Mod; + + /// First section contribution of this module. + SectionContrib SC; + + /// See ModInfoFlags definition. + support::ulittle16_t Flags; + + /// Stream Number of module debug info + support::ulittle16_t ModDiStream; + + /// Size of local symbol debug info in above stream + support::ulittle32_t SymBytes; + + /// Size of C11 line number info in above stream + support::ulittle32_t C11Bytes; + + /// Size of C13 line number info in above stream + support::ulittle32_t C13Bytes; + + /// Number of files contributing to this module + support::ulittle16_t NumFiles; + + /// Padding so the next field is 4-byte aligned. + char Padding1[2]; + + /// Array of [0..NumFiles) DBI name buffer offsets. In the reference + /// implementation this field is a pointer. But since you can't portably + /// serialize a pointer, on 64-bit platforms they copy all the values except + /// this one into the 32-bit version of the struct and use that for + /// serialization. Regardless, this field is unused, it is only there to + /// store a pointer that can be accessed at runtime. + support::ulittle32_t FileNameOffs; + + /// Name Index for src file name + support::ulittle32_t SrcFileNameNI; + + /// Name Index for path to compiler PDB + support::ulittle32_t PdbFilePathNI; + + /// Following this header are two zero terminated strings. + /// char ModuleName[]; + /// char ObjFileName[]; +}; + +// This is PSGSIHDR struct defined in +// https://github.com/Microsoft/microsoft-pdb/blob/master/PDB/dbi/gsi.h +struct PublicsStreamHeader { + support::ulittle32_t SymHash; + support::ulittle32_t AddrMap; + support::ulittle32_t NumThunks; + support::ulittle32_t SizeOfThunk; + support::ulittle16_t ISectThunkTable; + char Padding[2]; + support::ulittle32_t OffThunkTable; + support::ulittle32_t NumSections; +}; + +// The header preceeding the global TPI stream. +// This corresponds to `HDR` in PDB/dbi/tpi.h. +struct TpiStreamHeader { + struct EmbeddedBuf { + support::little32_t Off; + support::ulittle32_t Length; + }; + + support::ulittle32_t Version; + support::ulittle32_t HeaderSize; + support::ulittle32_t TypeIndexBegin; + support::ulittle32_t TypeIndexEnd; + support::ulittle32_t TypeRecordBytes; + + // The following members correspond to `TpiHash` in PDB/dbi/tpi.h. + support::ulittle16_t HashStreamIndex; + support::ulittle16_t HashAuxStreamIndex; + support::ulittle32_t HashKeySize; + support::ulittle32_t NumHashBuckets; + + EmbeddedBuf HashValueBuffer; + EmbeddedBuf IndexOffsetBuffer; + EmbeddedBuf HashAdjBuffer; +}; + +const uint32_t MinTpiHashBuckets = 0x1000; +const uint32_t MaxTpiHashBuckets = 0x40000; + +/// The header preceeding the global PDB Stream (Stream 1) +struct InfoStreamHeader { + support::ulittle32_t Version; + support::ulittle32_t Signature; + support::ulittle32_t Age; + codeview::GUID Guid; +}; + +/// The header preceeding the /names stream. +struct PDBStringTableHeader { + support::ulittle32_t Signature; // PDBStringTableSignature + support::ulittle32_t HashVersion; // 1 or 2 + support::ulittle32_t ByteSize; // Number of bytes of names buffer. +}; + +const uint32_t PDBStringTableSignature = 0xEFFEEFFE; + +/// The header preceding the /src/headerblock stream. +struct SrcHeaderBlockHeader { + support::ulittle32_t Version; // PdbRaw_SrcHeaderBlockVer enumeration. + support::ulittle32_t Size; // Size of entire stream. + uint64_t FileTime; // Time stamp (Windows FILETIME format). + support::ulittle32_t Age; // Age + uint8_t Padding[44]; // Pad to 64 bytes. +}; +static_assert(sizeof(SrcHeaderBlockHeader) == 64, "Incorrect struct size!"); + +/// A single file record entry within the /src/headerblock stream. +struct SrcHeaderBlockEntry { + support::ulittle32_t Size; // Record Length. + support::ulittle32_t Version; // PdbRaw_SrcHeaderBlockVer enumeration. + support::ulittle32_t CRC; // CRC of the original file contents. + support::ulittle32_t FileSize; // Size of original source file. + support::ulittle32_t FileNI; // String table index of file name. + support::ulittle32_t ObjNI; // String table index of object name. + support::ulittle32_t VFileNI; // String table index of virtual file name. + uint8_t Compression; // PDB_SourceCompression enumeration. + uint8_t IsVirtual; // Is this a virtual file (injected)? + short Padding; // Pad to 4 bytes. + char Reserved[8]; +}; + +static_assert(sizeof(SrcHeaderBlockEntry) == 40, "Incorrect struct size!"); + +} // namespace pdb +} // namespace llvm + +#endif diff --git a/clang-r353983/include/llvm/DebugInfo/PDB/Native/SymbolCache.h b/clang-r353983/include/llvm/DebugInfo/PDB/Native/SymbolCache.h new file mode 100644 index 00000000..0b15ab47 --- /dev/null +++ b/clang-r353983/include/llvm/DebugInfo/PDB/Native/SymbolCache.h @@ -0,0 +1,147 @@ +//==- SymbolCache.h - Cache of native symbols and ids ------------*- C++ -*-==// +// +// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. +// See https://llvm.org/LICENSE.txt for license information. +// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception +// +//===----------------------------------------------------------------------===// + +#ifndef LLVM_DEBUGINFO_PDB_NATIVE_SYMBOLCACHE_H +#define LLVM_DEBUGINFO_PDB_NATIVE_SYMBOLCACHE_H + +#include "llvm/ADT/DenseMap.h" +#include "llvm/DebugInfo/CodeView/TypeDeserializer.h" +#include "llvm/DebugInfo/CodeView/TypeIndex.h" +#include "llvm/DebugInfo/CodeView/TypeRecord.h" +#include "llvm/DebugInfo/PDB/Native/NativeRawSymbol.h" +#include "llvm/Support/Allocator.h" + +#include <memory> +#include <vector> + +namespace llvm { +namespace pdb { +class DbiStream; +class PDBFile; + +class SymbolCache { + NativeSession &Session; + DbiStream *Dbi = nullptr; + + /// Cache of all stable symbols, indexed by SymIndexId. Just because a + /// symbol has been parsed does not imply that it will be stable and have + /// an Id. Id allocation is an implementation, with the only guarantee + /// being that once an Id is allocated, the symbol can be assumed to be + /// cached. + std::vector<std::unique_ptr<NativeRawSymbol>> Cache; + + /// For type records from the TPI stream which have been paresd and cached, + /// stores a mapping to SymIndexId of the cached symbol. + DenseMap<codeview::TypeIndex, SymIndexId> TypeIndexToSymbolId; + + /// For field list members which have been parsed and cached, stores a mapping + /// from (IndexOfClass, MemberIndex) to the corresponding SymIndexId of the + /// cached symbol. + DenseMap<std::pair<codeview::TypeIndex, uint32_t>, SymIndexId> + FieldListMembersToSymbolId; + + /// List of SymIndexIds for each compiland, indexed by compiland index as they + /// appear in the PDB file. + std::vector<SymIndexId> Compilands; + + /// Map from global symbol offset to SymIndexId. + DenseMap<uint32_t, SymIndexId> GlobalOffsetToSymbolId; + + SymIndexId createSymbolPlaceholder() { + SymIndexId Id = Cache.size(); + Cache.push_back(nullptr); + return Id; + } + + template <typename ConcreteSymbolT, typename CVRecordT, typename... Args> + SymIndexId createSymbolForType(codeview::TypeIndex TI, codeview::CVType CVT, + Args &&... ConstructorArgs) { + CVRecordT Record; + if (auto EC = + codeview::TypeDeserializer::deserializeAs<CVRecordT>(CVT, Record)) { + consumeError(std::move(EC)); + return 0; + } + + return createSymbol<ConcreteSymbolT>( + TI, std::move(Record), std::forward<Args>(ConstructorArgs)...); + } + + SymIndexId createSymbolForModifiedType(codeview::TypeIndex ModifierTI, + codeview::CVType CVT); + + SymIndexId createSimpleType(codeview::TypeIndex TI, + codeview::ModifierOptions Mods); + +public: + SymbolCache(NativeSession &Session, DbiStream *Dbi); + + template <typename ConcreteSymbolT, typename... Args> + SymIndexId createSymbol(Args &&... ConstructorArgs) { + SymIndexId Id = Cache.size(); + + // Initial construction must not access the cache, since it must be done + // atomically. + auto Result = llvm::make_unique<ConcreteSymbolT>( + Session, Id, std::forward<Args>(ConstructorArgs)...); + Result->SymbolId = Id; + + NativeRawSymbol *NRS = static_cast<NativeRawSymbol *>(Result.get()); + Cache.push_back(std::move(Result)); + + // After the item is in the cache, we can do further initialization which + // is then allowed to access the cache. + NRS->initialize(); + return Id; + } + + std::unique_ptr<IPDBEnumSymbols> + createTypeEnumerator(codeview::TypeLeafKind Kind); + + std::unique_ptr<IPDBEnumSymbols> + createTypeEnumerator(std::vector<codeview::TypeLeafKind> Kinds); + + std::unique_ptr<IPDBEnumSymbols> + createGlobalsEnumerator(codeview::SymbolKind Kind); + + SymIndexId findSymbolByTypeIndex(codeview::TypeIndex TI); + + template <typename ConcreteSymbolT, typename... Args> + SymIndexId getOrCreateFieldListMember(codeview::TypeIndex FieldListTI, + uint32_t Index, + Args &&... ConstructorArgs) { + SymIndexId SymId = Cache.size(); + std::pair<codeview::TypeIndex, uint32_t> Key{FieldListTI, Index}; + auto Result = FieldListMembersToSymbolId.try_emplace(Key, SymId); + if (Result.second) + SymId = + createSymbol<ConcreteSymbolT>(std::forward<Args>(ConstructorArgs)...); + else + SymId = Result.first->second; + return SymId; + } + + SymIndexId getOrCreateGlobalSymbolByOffset(uint32_t Offset); + + std::unique_ptr<PDBSymbolCompiland> getOrCreateCompiland(uint32_t Index); + uint32_t getNumCompilands() const; + + std::unique_ptr<PDBSymbol> getSymbolById(SymIndexId SymbolId) const; + + NativeRawSymbol &getNativeSymbolById(SymIndexId SymbolId) const; + + template <typename ConcreteT> + ConcreteT &getNativeSymbolById(SymIndexId SymbolId) const { + return static_cast<ConcreteT &>(getNativeSymbolById(SymbolId)); + } +}; + +} // namespace pdb +} // namespace llvm + +#endif diff --git a/clang-r353983/include/llvm/DebugInfo/PDB/Native/SymbolStream.h b/clang-r353983/include/llvm/DebugInfo/PDB/Native/SymbolStream.h new file mode 100644 index 00000000..4fe1bd97 --- /dev/null +++ b/clang-r353983/include/llvm/DebugInfo/PDB/Native/SymbolStream.h @@ -0,0 +1,47 @@ +//===- SymbolStream.cpp - PDB Symbol Stream Access --------------*- C++ -*-===// +// +// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. +// See https://llvm.org/LICENSE.txt for license information. +// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception +// +//===----------------------------------------------------------------------===// + +#ifndef LLVM_DEBUGINFO_PDB_RAW_PDBSYMBOLSTREAM_H +#define LLVM_DEBUGINFO_PDB_RAW_PDBSYMBOLSTREAM_H + +#include "llvm/DebugInfo/CodeView/SymbolRecord.h" + +#include "llvm/Support/Error.h" + +namespace llvm { +namespace msf { +class MappedBlockStream; +} +namespace pdb { +class PDBFile; + +class SymbolStream { +public: + SymbolStream(std::unique_ptr<msf::MappedBlockStream> Stream); + ~SymbolStream(); + Error reload(); + + const codeview::CVSymbolArray &getSymbolArray() const { + return SymbolRecords; + } + + codeview::CVSymbol readRecord(uint32_t Offset) const; + + iterator_range<codeview::CVSymbolArray::Iterator> + getSymbols(bool *HadError) const; + + Error commit(); + +private: + codeview::CVSymbolArray SymbolRecords; + std::unique_ptr<msf::MappedBlockStream> Stream; +}; +} +} + +#endif diff --git a/clang-r353983/include/llvm/DebugInfo/PDB/Native/TpiHashing.h b/clang-r353983/include/llvm/DebugInfo/PDB/Native/TpiHashing.h new file mode 100644 index 00000000..4ac60a80 --- /dev/null +++ b/clang-r353983/include/llvm/DebugInfo/PDB/Native/TpiHashing.h @@ -0,0 +1,71 @@ +//===- TpiHashing.h ---------------------------------------------*- C++ -*-===// +// +// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. +// See https://llvm.org/LICENSE.txt for license information. +// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception +// +//===----------------------------------------------------------------------===// + +#ifndef LLVM_DEBUGINFO_PDB_TPIHASHING_H +#define LLVM_DEBUGINFO_PDB_TPIHASHING_H + +#include "llvm/DebugInfo/CodeView/TypeRecord.h" +#include "llvm/Support/Error.h" + +namespace llvm { +namespace pdb { + +Expected<uint32_t> hashTypeRecord(const llvm::codeview::CVType &Type); + +struct TagRecordHash { + explicit TagRecordHash(codeview::ClassRecord CR, uint32_t Full, + uint32_t Forward) + : FullRecordHash(Full), ForwardDeclHash(Forward), Class(std::move(CR)) { + State = 0; + } + + explicit TagRecordHash(codeview::EnumRecord ER, uint32_t Full, + uint32_t Forward) + : FullRecordHash(Full), ForwardDeclHash(Forward), Enum(std::move(ER)) { + State = 1; + } + + explicit TagRecordHash(codeview::UnionRecord UR, uint32_t Full, + uint32_t Forward) + : FullRecordHash(Full), ForwardDeclHash(Forward), Union(std::move(UR)) { + State = 2; + } + + uint32_t FullRecordHash; + uint32_t ForwardDeclHash; + + codeview::TagRecord &getRecord() { + switch (State) { + case 0: + return Class; + case 1: + return Enum; + case 2: + return Union; + } + llvm_unreachable("unreachable!"); + } + +private: + union { + codeview::ClassRecord Class; + codeview::EnumRecord Enum; + codeview::UnionRecord Union; + }; + + uint8_t State = 0; +}; + +/// Given a CVType referring to a class, structure, union, or enum, compute +/// the hash of its forward decl and full decl. +Expected<TagRecordHash> hashTagRecord(const codeview::CVType &Type); + +} // end namespace pdb +} // end namespace llvm + +#endif // LLVM_DEBUGINFO_PDB_TPIHASHING_H diff --git a/clang-r353983/include/llvm/DebugInfo/PDB/Native/TpiStream.h b/clang-r353983/include/llvm/DebugInfo/PDB/Native/TpiStream.h new file mode 100644 index 00000000..1b7fd2d5 --- /dev/null +++ b/clang-r353983/include/llvm/DebugInfo/PDB/Native/TpiStream.h @@ -0,0 +1,97 @@ +//===- TpiStream.cpp - PDB Type Info (TPI) Stream 2 Access ------*- C++ -*-===// +// +// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. +// See https://llvm.org/LICENSE.txt for license information. +// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception +// +//===----------------------------------------------------------------------===// + +#ifndef LLVM_DEBUGINFO_PDB_RAW_PDBTPISTREAM_H +#define LLVM_DEBUGINFO_PDB_RAW_PDBTPISTREAM_H + +#include "llvm/DebugInfo/CodeView/TypeRecord.h" +#include "llvm/DebugInfo/PDB/Native/HashTable.h" +#include "llvm/DebugInfo/PDB/Native/RawConstants.h" +#include "llvm/DebugInfo/PDB/Native/RawTypes.h" +#include "llvm/DebugInfo/PDB/PDBTypes.h" +#include "llvm/Support/BinaryStreamArray.h" +#include "llvm/Support/BinaryStreamRef.h" +#include "llvm/Support/raw_ostream.h" + +#include "llvm/Support/Error.h" + +namespace llvm { +namespace codeview { +class LazyRandomTypeCollection; +} +namespace msf { +class MappedBlockStream; +} +namespace pdb { +class PDBFile; + +class TpiStream { + friend class TpiStreamBuilder; + +public: + TpiStream(PDBFile &File, std::unique_ptr<msf::MappedBlockStream> Stream); + ~TpiStream(); + Error reload(); + + PdbRaw_TpiVer getTpiVersion() const; + + uint32_t TypeIndexBegin() const; + uint32_t TypeIndexEnd() const; + uint32_t getNumTypeRecords() const; + uint16_t getTypeHashStreamIndex() const; + uint16_t getTypeHashStreamAuxIndex() const; + + uint32_t getHashKeySize() const; + uint32_t getNumHashBuckets() const; + FixedStreamArray<support::ulittle32_t> getHashValues() const; + FixedStreamArray<codeview::TypeIndexOffset> getTypeIndexOffsets() const; + HashTable<support::ulittle32_t> &getHashAdjusters(); + + codeview::CVTypeRange types(bool *HadError) const; + const codeview::CVTypeArray &typeArray() const { return TypeRecords; } + + codeview::LazyRandomTypeCollection &typeCollection() { return *Types; } + + Expected<codeview::TypeIndex> + findFullDeclForForwardRef(codeview::TypeIndex ForwardRefTI) const; + + std::vector<codeview::TypeIndex> findRecordsByName(StringRef Name) const; + + codeview::CVType getType(codeview::TypeIndex Index); + + BinarySubstreamRef getTypeRecordsSubstream() const; + + Error commit(); + + void buildHashMap(); + + bool supportsTypeLookup() const; + +private: + PDBFile &Pdb; + std::unique_ptr<msf::MappedBlockStream> Stream; + + std::unique_ptr<codeview::LazyRandomTypeCollection> Types; + + BinarySubstreamRef TypeRecordsSubstream; + + codeview::CVTypeArray TypeRecords; + + std::unique_ptr<BinaryStream> HashStream; + FixedStreamArray<support::ulittle32_t> HashValues; + FixedStreamArray<codeview::TypeIndexOffset> TypeIndexOffsets; + HashTable<support::ulittle32_t> HashAdjusters; + + std::vector<std::vector<codeview::TypeIndex>> HashMap; + + const TpiStreamHeader *Header; +}; +} +} + +#endif diff --git a/clang-r353983/include/llvm/DebugInfo/PDB/Native/TpiStreamBuilder.h b/clang-r353983/include/llvm/DebugInfo/PDB/Native/TpiStreamBuilder.h new file mode 100644 index 00000000..72d98e9c --- /dev/null +++ b/clang-r353983/include/llvm/DebugInfo/PDB/Native/TpiStreamBuilder.h @@ -0,0 +1,89 @@ +//===- TpiStreamBuilder.h - PDB Tpi Stream Creation -------------*- C++ -*-===// +// +// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. +// See https://llvm.org/LICENSE.txt for license information. +// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception +// +//===----------------------------------------------------------------------===// + +#ifndef LLVM_DEBUGINFO_PDB_RAW_PDBTPISTREAMBUILDER_H +#define LLVM_DEBUGINFO_PDB_RAW_PDBTPISTREAMBUILDER_H + +#include "llvm/ADT/Optional.h" +#include "llvm/DebugInfo/CodeView/TypeRecord.h" +#include "llvm/DebugInfo/PDB/Native/RawConstants.h" +#include "llvm/DebugInfo/PDB/Native/RawTypes.h" +#include "llvm/Support/Allocator.h" +#include "llvm/Support/BinaryByteStream.h" +#include "llvm/Support/BinaryItemStream.h" +#include "llvm/Support/BinaryStreamRef.h" +#include "llvm/Support/Error.h" + +#include <vector> + +namespace llvm { +class BinaryByteStream; +class WritableBinaryStreamRef; + +template <> struct BinaryItemTraits<llvm::codeview::CVType> { + static size_t length(const codeview::CVType &Item) { return Item.length(); } + static ArrayRef<uint8_t> bytes(const codeview::CVType &Item) { + return Item.data(); + } +}; + +namespace codeview { +class TypeRecord; +} +namespace msf { +class MSFBuilder; +struct MSFLayout; +} +namespace pdb { +class PDBFile; +class TpiStream; +struct TpiStreamHeader; + +class TpiStreamBuilder { +public: + explicit TpiStreamBuilder(msf::MSFBuilder &Msf, uint32_t StreamIdx); + ~TpiStreamBuilder(); + + TpiStreamBuilder(const TpiStreamBuilder &) = delete; + TpiStreamBuilder &operator=(const TpiStreamBuilder &) = delete; + + void setVersionHeader(PdbRaw_TpiVer Version); + void addTypeRecord(ArrayRef<uint8_t> Type, Optional<uint32_t> Hash); + + Error finalizeMsfLayout(); + + uint32_t getRecordCount() const { return TypeRecords.size(); } + + Error commit(const msf::MSFLayout &Layout, WritableBinaryStreamRef Buffer); + + uint32_t calculateSerializedLength(); + +private: + uint32_t calculateHashBufferSize() const; + uint32_t calculateIndexOffsetSize() const; + Error finalize(); + + msf::MSFBuilder &Msf; + BumpPtrAllocator &Allocator; + + size_t TypeRecordBytes = 0; + + PdbRaw_TpiVer VerHeader = PdbRaw_TpiVer::PdbTpiV80; + std::vector<ArrayRef<uint8_t>> TypeRecords; + std::vector<uint32_t> TypeHashes; + std::vector<codeview::TypeIndexOffset> TypeIndexOffsets; + uint32_t HashStreamIndex = kInvalidStreamIndex; + std::unique_ptr<BinaryByteStream> HashValueStream; + + const TpiStreamHeader *Header; + uint32_t Idx; +}; +} +} + +#endif |
