aboutsummaryrefslogtreecommitdiff
path: root/include/llvm/DebugInfo/PDB/Native
diff options
context:
space:
mode:
Diffstat (limited to 'include/llvm/DebugInfo/PDB/Native')
-rw-r--r--include/llvm/DebugInfo/PDB/Native/DbiStream.h124
-rw-r--r--include/llvm/DebugInfo/PDB/Native/DbiStreamBuilder.h120
-rw-r--r--include/llvm/DebugInfo/PDB/Native/EnumTables.h22
-rw-r--r--include/llvm/DebugInfo/PDB/Native/Formatters.h52
-rw-r--r--include/llvm/DebugInfo/PDB/Native/GlobalsStream.h45
-rw-r--r--include/llvm/DebugInfo/PDB/Native/Hash.h25
-rw-r--r--include/llvm/DebugInfo/PDB/Native/HashTable.h106
-rw-r--r--include/llvm/DebugInfo/PDB/Native/ISectionContribVisitor.h30
-rw-r--r--include/llvm/DebugInfo/PDB/Native/InfoStream.h83
-rw-r--r--include/llvm/DebugInfo/PDB/Native/InfoStreamBuilder.h64
-rw-r--r--include/llvm/DebugInfo/PDB/Native/ModInfo.h78
-rw-r--r--include/llvm/DebugInfo/PDB/Native/ModInfoBuilder.h74
-rw-r--r--include/llvm/DebugInfo/PDB/Native/ModStream.h62
-rw-r--r--include/llvm/DebugInfo/PDB/Native/NamedStreamMap.h55
-rw-r--r--include/llvm/DebugInfo/PDB/Native/NativeCompilandSymbol.h35
-rw-r--r--include/llvm/DebugInfo/PDB/Native/NativeEnumModules.h41
-rw-r--r--include/llvm/DebugInfo/PDB/Native/NativeExeSymbol.h39
-rw-r--r--include/llvm/DebugInfo/PDB/Native/NativeRawSymbol.h208
-rw-r--r--include/llvm/DebugInfo/PDB/Native/NativeSession.h78
-rw-r--r--include/llvm/DebugInfo/PDB/Native/PDBFile.h139
-rw-r--r--include/llvm/DebugInfo/PDB/Native/PDBFileBuilder.h71
-rw-r--r--include/llvm/DebugInfo/PDB/Native/PDBTypeServerHandler.h48
-rw-r--r--include/llvm/DebugInfo/PDB/Native/PublicsStream.h73
-rw-r--r--include/llvm/DebugInfo/PDB/Native/RawConstants.h114
-rw-r--r--include/llvm/DebugInfo/PDB/Native/RawError.h53
-rw-r--r--include/llvm/DebugInfo/PDB/Native/RawTypes.h321
-rw-r--r--include/llvm/DebugInfo/PDB/Native/StringTable.h56
-rw-r--r--include/llvm/DebugInfo/PDB/Native/StringTableBuilder.h44
-rw-r--r--include/llvm/DebugInfo/PDB/Native/SymbolStream.h42
-rw-r--r--include/llvm/DebugInfo/PDB/Native/TpiHashing.h95
-rw-r--r--include/llvm/DebugInfo/PDB/Native/TpiStream.h75
-rw-r--r--include/llvm/DebugInfo/PDB/Native/TpiStreamBuilder.h88
32 files changed, 2560 insertions, 0 deletions
diff --git a/include/llvm/DebugInfo/PDB/Native/DbiStream.h b/include/llvm/DebugInfo/PDB/Native/DbiStream.h
new file mode 100644
index 000000000000..f49f5aaefaca
--- /dev/null
+++ b/include/llvm/DebugInfo/PDB/Native/DbiStream.h
@@ -0,0 +1,124 @@
+//===- DbiStream.h - PDB Dbi Stream (Stream 3) Access -----------*- C++ -*-===//
+//
+// The LLVM Compiler Infrastructure
+//
+// This file is distributed under the University of Illinois Open Source
+// License. See LICENSE.TXT for details.
+//
+//===----------------------------------------------------------------------===//
+
+#ifndef LLVM_DEBUGINFO_PDB_RAW_PDBDBISTREAM_H
+#define LLVM_DEBUGINFO_PDB_RAW_PDBDBISTREAM_H
+
+#include "llvm/DebugInfo/CodeView/ModuleSubstream.h"
+#include "llvm/DebugInfo/MSF/MappedBlockStream.h"
+#include "llvm/DebugInfo/PDB/Native/ModInfo.h"
+#include "llvm/DebugInfo/PDB/Native/RawConstants.h"
+#include "llvm/DebugInfo/PDB/Native/RawTypes.h"
+#include "llvm/DebugInfo/PDB/Native/StringTable.h"
+#include "llvm/DebugInfo/PDB/PDBTypes.h"
+#include "llvm/Support/BinaryStreamArray.h"
+#include "llvm/Support/BinaryStreamArray.h"
+#include "llvm/Support/BinaryStreamRef.h"
+#include "llvm/Support/BinaryStreamRef.h"
+#include "llvm/Support/Endian.h"
+#include "llvm/Support/Error.h"
+
+namespace llvm {
+namespace object {
+struct FpoData;
+struct coff_section;
+}
+
+namespace pdb {
+class DbiStreamBuilder;
+class PDBFile;
+class ISectionContribVisitor;
+
+class DbiStream {
+ friend class DbiStreamBuilder;
+
+public:
+ DbiStream(PDBFile &File, std::unique_ptr<msf::MappedBlockStream> Stream);
+ ~DbiStream();
+ Error reload();
+
+ 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;
+
+ /// If the given stream type is present, returns its stream index. If it is
+ /// not present, returns InvalidStreamIndex.
+ uint32_t getDebugStreamIndex(DbgHeaderType Type) const;
+
+ ArrayRef<ModuleInfoEx> modules() const;
+
+ Expected<StringRef> getFileNameForIndex(uint32_t Index) const;
+
+ FixedStreamArray<object::coff_section> getSectionHeaders();
+
+ FixedStreamArray<object::FpoData> getFpoRecords();
+
+ FixedStreamArray<SecMapEntry> getSectionMap() const;
+ void visitSectionContributions(ISectionContribVisitor &Visitor) const;
+
+private:
+ Error initializeModInfoArray();
+ Error initializeSectionContributionData();
+ Error initializeSectionHeadersData();
+ Error initializeSectionMapData();
+ Error initializeFileInfo();
+ Error initializeFpoRecords();
+
+ PDBFile &Pdb;
+ std::unique_ptr<msf::MappedBlockStream> Stream;
+
+ std::vector<ModuleInfoEx> ModuleInfos;
+ StringTable ECNames;
+
+ BinaryStreamRef ModInfoSubstream;
+ BinaryStreamRef SecContrSubstream;
+ BinaryStreamRef SecMapSubstream;
+ BinaryStreamRef FileInfoSubstream;
+ BinaryStreamRef TypeServerMapSubstream;
+ BinaryStreamRef ECSubstream;
+
+ BinaryStreamRef NamesBuffer;
+
+ FixedStreamArray<support::ulittle16_t> DbgStreams;
+
+ PdbRaw_DbiSecContribVer SectionContribVersion;
+ FixedStreamArray<SectionContrib> SectionContribs;
+ FixedStreamArray<SectionContrib2> SectionContribs2;
+ FixedStreamArray<SecMapEntry> SectionMap;
+ FixedStreamArray<support::little32_t> FileNameOffsets;
+
+ std::unique_ptr<msf::MappedBlockStream> SectionHeaderStream;
+ FixedStreamArray<object::coff_section> SectionHeaders;
+
+ std::unique_ptr<msf::MappedBlockStream> FpoStream;
+ FixedStreamArray<object::FpoData> FpoRecords;
+
+ const DbiStreamHeader *Header;
+};
+}
+}
+
+#endif
diff --git a/include/llvm/DebugInfo/PDB/Native/DbiStreamBuilder.h b/include/llvm/DebugInfo/PDB/Native/DbiStreamBuilder.h
new file mode 100644
index 000000000000..16426bd93847
--- /dev/null
+++ b/include/llvm/DebugInfo/PDB/Native/DbiStreamBuilder.h
@@ -0,0 +1,120 @@
+//===- DbiStreamBuilder.h - PDB Dbi Stream Creation -------------*- C++ -*-===//
+//
+// The LLVM Compiler Infrastructure
+//
+// This file is distributed under the University of Illinois Open Source
+// License. See LICENSE.TXT for details.
+//
+//===----------------------------------------------------------------------===//
+
+#ifndef LLVM_DEBUGINFO_PDB_RAW_PDBDBISTREAMBUILDER_H
+#define LLVM_DEBUGINFO_PDB_RAW_PDBDBISTREAMBUILDER_H
+
+#include "llvm/ADT/Optional.h"
+#include "llvm/ADT/StringSet.h"
+#include "llvm/Support/Error.h"
+
+#include "llvm/DebugInfo/PDB/Native/PDBFile.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 msf {
+class MSFBuilder;
+}
+namespace object {
+struct coff_section;
+}
+namespace pdb {
+class DbiStream;
+struct DbiStreamHeader;
+class ModInfoBuilder;
+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 setPdbDllVersion(uint16_t V);
+ void setPdbDllRbld(uint16_t R);
+ void setFlags(uint16_t F);
+ void setMachineType(PDB_Machine M);
+ void setSectionContribs(ArrayRef<SectionContrib> SecMap);
+ void setSectionMap(ArrayRef<SecMapEntry> SecMap);
+
+ // Add given bytes as a new stream.
+ Error addDbgStream(pdb::DbgHeaderType Type, ArrayRef<uint8_t> Data);
+
+ uint32_t calculateSerializedLength() const;
+
+ Expected<ModInfoBuilder &> addModuleInfo(StringRef ModuleName);
+ Error addModuleSourceFile(StringRef Module, StringRef File);
+
+ Error finalizeMsfLayout();
+
+ Error commit(const msf::MSFLayout &Layout, WritableBinaryStreamRef MsfBuffer);
+
+ // A helper function to create Section Contributions from COFF input
+ // section headers.
+ static std::vector<SectionContrib>
+ createSectionContribs(ArrayRef<llvm::object::coff_section> SecHdrs);
+
+ // 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 {
+ ArrayRef<uint8_t> Data;
+ uint16_t StreamNumber = 0;
+ };
+
+ Error finalize();
+ uint32_t calculateModiSubstreamSize() const;
+ uint32_t calculateSectionContribsStreamSize() const;
+ uint32_t calculateSectionMapStreamSize() const;
+ uint32_t calculateFileInfoSubstreamSize() const;
+ uint32_t calculateNamesBufferSize() const;
+ uint32_t calculateDbgStreamsSize() const;
+
+ Error generateModiSubstream();
+ 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;
+
+ const DbiStreamHeader *Header;
+
+ StringMap<std::unique_ptr<ModInfoBuilder>> ModiMap;
+ std::vector<ModInfoBuilder *> ModiList;
+
+ StringMap<uint32_t> SourceFileNames;
+
+ WritableBinaryStreamRef NamesBuffer;
+ MutableBinaryByteStream FileInfoBuffer;
+ ArrayRef<SectionContrib> SectionContribs;
+ ArrayRef<SecMapEntry> SectionMap;
+ llvm::SmallVector<DebugStream, (int)DbgHeaderType::Max> DbgStreams;
+};
+}
+}
+
+#endif
diff --git a/include/llvm/DebugInfo/PDB/Native/EnumTables.h b/include/llvm/DebugInfo/PDB/Native/EnumTables.h
new file mode 100644
index 000000000000..c018445630fe
--- /dev/null
+++ b/include/llvm/DebugInfo/PDB/Native/EnumTables.h
@@ -0,0 +1,22 @@
+//===- EnumTables.h - Enum to string conversion tables ----------*- C++ -*-===//
+//
+// The LLVM Compiler Infrastructure
+//
+// This file is distributed under the University of Illinois Open Source
+// License. See LICENSE.TXT for details.
+//
+//===----------------------------------------------------------------------===//
+
+#ifndef LLVM_DEBUGINFO_PDB_RAW_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/include/llvm/DebugInfo/PDB/Native/Formatters.h b/include/llvm/DebugInfo/PDB/Native/Formatters.h
new file mode 100644
index 000000000000..183f0ad8307e
--- /dev/null
+++ b/include/llvm/DebugInfo/PDB/Native/Formatters.h
@@ -0,0 +1,52 @@
+//===- Formatters.h ---------------------------------------------*- C++ -*-===//
+//
+// The LLVM Compiler Infrastructure
+//
+// This file is distributed under the University of Illinois Open Source
+// License. See LICENSE.TXT for details.
+//
+//===----------------------------------------------------------------------===//
+
+#ifndef LLVM_DEBUGINFO_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::PDB_UniqueId> {
+ static void format(const pdb::PDB_UniqueId &V, llvm::raw_ostream &Stream,
+ StringRef Style) {
+ codeview::fmt_guid(V.Guid).format(Stream, Style);
+ }
+};
+
+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/include/llvm/DebugInfo/PDB/Native/GlobalsStream.h b/include/llvm/DebugInfo/PDB/Native/GlobalsStream.h
new file mode 100644
index 000000000000..dcea3d3be0ab
--- /dev/null
+++ b/include/llvm/DebugInfo/PDB/Native/GlobalsStream.h
@@ -0,0 +1,45 @@
+//===- GlobalsStream.h - PDB Index of Symbols by Name ------ ----*- C++ -*-===//
+//
+// The LLVM Compiler Infrastructure
+//
+// This file is distributed under the University of Illinois Open Source
+// License. See LICENSE.TXT for details.
+//
+//===----------------------------------------------------------------------===//
+
+#ifndef LLVM_DEBUGINFO_PDB_RAW_GLOBALS_STREAM_H
+#define LLVM_DEBUGINFO_PDB_RAW_GLOBALS_STREAM_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 GlobalsStream {
+public:
+ explicit GlobalsStream(std::unique_ptr<msf::MappedBlockStream> Stream);
+ ~GlobalsStream();
+ Error commit();
+ FixedStreamArray<support::ulittle32_t> getHashBuckets() const {
+ return HashBuckets;
+ }
+ uint32_t getNumBuckets() const { return NumBuckets; }
+ Error reload();
+
+private:
+ FixedStreamArray<support::ulittle32_t> HashBuckets;
+ FixedStreamArray<PSHashRecord> HashRecords;
+ uint32_t NumBuckets;
+ std::unique_ptr<msf::MappedBlockStream> Stream;
+};
+}
+}
+
+#endif
diff --git a/include/llvm/DebugInfo/PDB/Native/Hash.h b/include/llvm/DebugInfo/PDB/Native/Hash.h
new file mode 100644
index 000000000000..0340554d7b0b
--- /dev/null
+++ b/include/llvm/DebugInfo/PDB/Native/Hash.h
@@ -0,0 +1,25 @@
+//===- Hash.h - PDB hash functions ------------------------------*- C++ -*-===//
+//
+// The LLVM Compiler Infrastructure
+//
+// This file is distributed under the University of Illinois Open Source
+// License. See LICENSE.TXT for details.
+//
+//===----------------------------------------------------------------------===//
+
+#ifndef LLVM_DEBUGINFO_PDB_RAW_HASH_H
+#define LLVM_DEBUGINFO_PDB_RAW_HASH_H
+
+#include "llvm/ADT/ArrayRef.h"
+#include "llvm/ADT/StringRef.h"
+#include <stdint.h>
+
+namespace llvm {
+namespace pdb {
+uint32_t hashStringV1(StringRef Str);
+uint32_t hashStringV2(StringRef Str);
+uint32_t hashBufferV8(ArrayRef<uint8_t> Data);
+}
+}
+
+#endif
diff --git a/include/llvm/DebugInfo/PDB/Native/HashTable.h b/include/llvm/DebugInfo/PDB/Native/HashTable.h
new file mode 100644
index 000000000000..46eefa968e52
--- /dev/null
+++ b/include/llvm/DebugInfo/PDB/Native/HashTable.h
@@ -0,0 +1,106 @@
+//===- HashTable.h - PDB Hash Table -----------------------------*- C++ -*-===//
+//
+// The LLVM Compiler Infrastructure
+//
+// This file is distributed under the University of Illinois Open Source
+// License. See LICENSE.TXT for details.
+//
+//===----------------------------------------------------------------------===//
+
+#ifndef LLVM_DEBUGINFO_PDB_RAW_HASHTABLE_H
+#define LLVM_DEBUGINFO_PDB_RAW_HASHTABLE_H
+
+#include "llvm/ADT/ArrayRef.h"
+#include "llvm/ADT/SparseBitVector.h"
+#include "llvm/ADT/StringRef.h"
+#include "llvm/ADT/iterator.h"
+#include "llvm/Support/BinaryStreamArray.h"
+#include "llvm/Support/BinaryStreamReader.h"
+#include "llvm/Support/BinaryStreamWriter.h"
+#include "llvm/Support/Endian.h"
+#include "llvm/Support/Error.h"
+#include "llvm/Support/MathExtras.h"
+
+#include <cstdint>
+#include <utility>
+
+namespace llvm {
+namespace pdb {
+
+class HashTableIterator;
+
+class HashTable {
+ friend class HashTableIterator;
+ struct Header {
+ support::ulittle32_t Size;
+ support::ulittle32_t Capacity;
+ };
+
+ typedef std::vector<std::pair<uint32_t, uint32_t>> BucketList;
+
+public:
+ HashTable();
+ explicit HashTable(uint32_t Capacity);
+
+ Error load(BinaryStreamReader &Stream);
+
+ uint32_t calculateSerializedLength() const;
+ Error commit(BinaryStreamWriter &Writer) const;
+
+ void clear();
+
+ uint32_t capacity() const;
+ uint32_t size() const;
+
+ HashTableIterator begin() const;
+ HashTableIterator end() const;
+ HashTableIterator find(uint32_t K);
+
+ void set(uint32_t K, uint32_t V);
+ void remove(uint32_t K);
+ uint32_t get(uint32_t K);
+
+protected:
+ bool isPresent(uint32_t K) const { return Present.test(K); }
+ bool isDeleted(uint32_t K) const { return Deleted.test(K); }
+ BucketList Buckets;
+ mutable SparseBitVector<> Present;
+ mutable SparseBitVector<> Deleted;
+
+private:
+ static uint32_t maxLoad(uint32_t capacity);
+ void grow();
+
+ static Error readSparseBitVector(BinaryStreamReader &Stream,
+ SparseBitVector<> &V);
+ static Error writeSparseBitVector(BinaryStreamWriter &Writer,
+ SparseBitVector<> &Vec);
+};
+
+class HashTableIterator
+ : public iterator_facade_base<HashTableIterator, std::forward_iterator_tag,
+ std::pair<uint32_t, uint32_t>> {
+ friend class HashTable;
+ HashTableIterator(const HashTable &Map, uint32_t Index, bool IsEnd);
+
+public:
+ HashTableIterator(const HashTable &Map);
+
+ HashTableIterator &operator=(const HashTableIterator &R);
+ bool operator==(const HashTableIterator &R) const;
+ const std::pair<uint32_t, uint32_t> &operator*() const;
+ HashTableIterator &operator++();
+
+private:
+ bool isEnd() const { return IsEnd; }
+ uint32_t index() const { return Index; }
+
+ const HashTable *Map;
+ uint32_t Index;
+ bool IsEnd;
+};
+
+} // end namespace pdb
+} // end namespace llvm
+
+#endif // LLVM_DEBUGINFO_PDB_RAW_HASHTABLE_H
diff --git a/include/llvm/DebugInfo/PDB/Native/ISectionContribVisitor.h b/include/llvm/DebugInfo/PDB/Native/ISectionContribVisitor.h
new file mode 100644
index 000000000000..fb00d6ad4bc7
--- /dev/null
+++ b/include/llvm/DebugInfo/PDB/Native/ISectionContribVisitor.h
@@ -0,0 +1,30 @@
+//===- ISectionContribVisitor.h ---------------------------------*- C++ -*-===//
+//
+// The LLVM Compiler Infrastructure
+//
+// This file is distributed under the University of Illinois Open Source
+// License. See LICENSE.TXT for details.
+//
+//===----------------------------------------------------------------------===//
+
+#ifndef LLVM_DEBUGINFO_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/include/llvm/DebugInfo/PDB/Native/InfoStream.h b/include/llvm/DebugInfo/PDB/Native/InfoStream.h
new file mode 100644
index 000000000000..1c38c2b6194f
--- /dev/null
+++ b/include/llvm/DebugInfo/PDB/Native/InfoStream.h
@@ -0,0 +1,83 @@
+//===- InfoStream.h - PDB Info Stream (Stream 1) Access ---------*- C++ -*-===//
+//
+// The LLVM Compiler Infrastructure
+//
+// This file is distributed under the University of Illinois Open Source
+// License. See LICENSE.TXT for details.
+//
+//===----------------------------------------------------------------------===//
+
+#ifndef LLVM_DEBUGINFO_PDB_RAW_PDBINFOSTREAM_H
+#define LLVM_DEBUGINFO_PDB_RAW_PDBINFOSTREAM_H
+
+#include "llvm/ADT/BitmaskEnum.h"
+#include "llvm/ADT/StringMap.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<msf::MappedBlockStream> Stream);
+
+ Error reload();
+
+ uint32_t getStreamSize() const;
+
+ PdbRaw_ImplVer getVersion() const;
+ uint32_t getSignature() const;
+ uint32_t getAge() const;
+ PDB_UniqueId getGuid() const;
+ uint32_t getNamedStreamMapByteSize() const;
+
+ PdbRaw_Features getFeatures() const;
+ ArrayRef<PdbRaw_FeatureSig> getFeatureSignatures() const;
+
+ const NamedStreamMap &getNamedStreams() const;
+
+ uint32_t getNamedStreamIndex(llvm::StringRef Name) const;
+ iterator_range<StringMapConstIterator<uint32_t>> named_streams() const;
+
+private:
+ std::unique_ptr<msf::MappedBlockStream> Stream;
+
+ // PDB file format version. We only support VC70. See the enumeration
+ // `PdbRaw_ImplVer` for the other possible values.
+ uint32_t Version;
+
+ // A 32-bit signature unique across all PDBs. This is generated with
+ // a call to time() when the PDB is written, but obviously this is not
+ // universally unique.
+ uint32_t Signature;
+
+ // The number of times the PDB has been written. Might also be used to
+ // ensure that the PDB matches the executable.
+ uint32_t Age;
+
+ // Due to the aforementioned limitations with `Signature`, this is a new
+ // signature present on VC70 and higher PDBs which is guaranteed to be
+ // universally unique.
+ PDB_UniqueId Guid;
+
+ std::vector<PdbRaw_FeatureSig> FeatureSignatures;
+ PdbRaw_Features Features = PdbFeatureNone;
+
+ uint32_t NamedStreamMapByteSize = 0;
+
+ NamedStreamMap NamedStreams;
+};
+}
+}
+
+#endif
diff --git a/include/llvm/DebugInfo/PDB/Native/InfoStreamBuilder.h b/include/llvm/DebugInfo/PDB/Native/InfoStreamBuilder.h
new file mode 100644
index 000000000000..90c28a90d252
--- /dev/null
+++ b/include/llvm/DebugInfo/PDB/Native/InfoStreamBuilder.h
@@ -0,0 +1,64 @@
+//===- InfoStreamBuilder.h - PDB Info Stream Creation -----------*- C++ -*-===//
+//
+// The LLVM Compiler Infrastructure
+//
+// This file is distributed under the University of Illinois Open Source
+// License. See LICENSE.TXT for details.
+//
+//===----------------------------------------------------------------------===//
+
+#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 setSignature(uint32_t S);
+ void setAge(uint32_t A);
+ void setGuid(PDB_UniqueId G);
+ void addFeature(PdbRaw_FeatureSig Sig);
+
+ 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 Sig;
+ uint32_t Age;
+ PDB_UniqueId Guid;
+
+ NamedStreamMap &NamedStreams;
+};
+}
+}
+
+#endif
diff --git a/include/llvm/DebugInfo/PDB/Native/ModInfo.h b/include/llvm/DebugInfo/PDB/Native/ModInfo.h
new file mode 100644
index 000000000000..d26d0d618449
--- /dev/null
+++ b/include/llvm/DebugInfo/PDB/Native/ModInfo.h
@@ -0,0 +1,78 @@
+//===- ModInfo.h - PDB module information -----------------------*- C++ -*-===//
+//
+// The LLVM Compiler Infrastructure
+//
+// This file is distributed under the University of Illinois Open Source
+// License. See LICENSE.TXT for details.
+//
+//===----------------------------------------------------------------------===//
+
+#ifndef LLVM_DEBUGINFO_PDB_RAW_MODINFO_H
+#define LLVM_DEBUGINFO_PDB_RAW_MODINFO_H
+
+#include "llvm/ADT/StringRef.h"
+#include "llvm/DebugInfo/PDB/Native/RawTypes.h"
+#include "llvm/Support/BinaryStreamArray.h"
+#include "llvm/Support/BinaryStreamRef.h"
+#include "llvm/Support/Error.h"
+#include <cstdint>
+#include <vector>
+
+namespace llvm {
+
+namespace pdb {
+
+class ModInfo {
+ friend class DbiStreamBuilder;
+
+public:
+ ModInfo();
+ ModInfo(const ModInfo &Info);
+ ~ModInfo();
+
+ static Error initialize(BinaryStreamRef Stream, ModInfo &Info);
+
+ bool hasECInfo() const;
+ uint16_t getTypeServerIndex() const;
+ uint16_t getModuleStreamIndex() const;
+ uint32_t getSymbolDebugInfoByteSize() const;
+ uint32_t getLineInfoByteSize() const;
+ uint32_t getC13LineInfoByteSize() const;
+ uint32_t getNumberOfFiles() const;
+ uint32_t getSourceFileNameIndex() const;
+ uint32_t getPdbFilePathNameIndex() const;
+
+ StringRef getModuleName() const;
+ StringRef getObjFileName() const;
+
+ uint32_t getRecordLength() const;
+
+private:
+ StringRef ModuleName;
+ StringRef ObjFileName;
+ const ModuleInfoHeader *Layout = nullptr;
+};
+
+struct ModuleInfoEx {
+ ModuleInfoEx(const ModInfo &Info) : Info(Info) {}
+ ModuleInfoEx(const ModuleInfoEx &Ex) = default;
+
+ ModInfo Info;
+ std::vector<StringRef> SourceFiles;
+};
+
+} // end namespace pdb
+
+template <> struct VarStreamArrayExtractor<pdb::ModInfo> {
+ Error operator()(BinaryStreamRef Stream, uint32_t &Length,
+ pdb::ModInfo &Info) const {
+ if (auto EC = pdb::ModInfo::initialize(Stream, Info))
+ return EC;
+ Length = Info.getRecordLength();
+ return Error::success();
+ }
+};
+
+} // end namespace llvm
+
+#endif // LLVM_DEBUGINFO_PDB_RAW_MODINFO_H
diff --git a/include/llvm/DebugInfo/PDB/Native/ModInfoBuilder.h b/include/llvm/DebugInfo/PDB/Native/ModInfoBuilder.h
new file mode 100644
index 000000000000..605fd2483c3b
--- /dev/null
+++ b/include/llvm/DebugInfo/PDB/Native/ModInfoBuilder.h
@@ -0,0 +1,74 @@
+//===- ModInfoBuilder.h - PDB module information ----------------*- C++ -*-===//
+//
+// The LLVM Compiler Infrastructure
+//
+// This file is distributed under the University of Illinois Open Source
+// License. See LICENSE.TXT for details.
+//
+//===----------------------------------------------------------------------===//
+
+#ifndef LLVM_DEBUGINFO_PDB_RAW_MODINFOBUILDER_H
+#define LLVM_DEBUGINFO_PDB_RAW_MODINFOBUILDER_H
+
+#include "llvm/ADT/StringRef.h"
+#include "llvm/DebugInfo/CodeView/SymbolRecord.h"
+#include "llvm/DebugInfo/PDB/Native/RawTypes.h"
+#include "llvm/Support/Error.h"
+#include <cstdint>
+#include <string>
+#include <vector>
+
+namespace llvm {
+class BinaryStreamWriter;
+
+namespace msf {
+class MSFBuilder;
+struct MSFLayout;
+}
+namespace pdb {
+
+class ModInfoBuilder {
+ friend class DbiStreamBuilder;
+
+public:
+ ModInfoBuilder(StringRef ModuleName, uint32_t ModIndex, msf::MSFBuilder &Msf);
+
+ ModInfoBuilder(const ModInfoBuilder &) = delete;
+ ModInfoBuilder &operator=(const ModInfoBuilder &) = delete;
+
+ void setObjFileName(StringRef Name);
+ void addSymbol(codeview::CVSymbol Symbol);
+
+ uint16_t getStreamIndex() const;
+ StringRef getModuleName() const { return ModuleName; }
+ StringRef getObjFileName() const { return ObjFileName; }
+
+ ArrayRef<std::string> source_files() const {
+ return makeArrayRef(SourceFiles);
+ }
+
+ uint32_t calculateSerializedLength() const;
+
+ void finalize();
+ Error finalizeMsfLayout();
+
+ Error commit(BinaryStreamWriter &ModiWriter, const msf::MSFLayout &MsfLayout,
+ WritableBinaryStreamRef MsfBuffer);
+
+private:
+ void addSourceFile(StringRef Path);
+ msf::MSFBuilder &MSF;
+
+ uint32_t SymbolByteSize = 0;
+ std::string ModuleName;
+ std::string ObjFileName;
+ std::vector<std::string> SourceFiles;
+ std::vector<codeview::CVSymbol> Symbols;
+ ModuleInfoHeader Layout;
+};
+
+} // end namespace pdb
+
+} // end namespace llvm
+
+#endif // LLVM_DEBUGINFO_PDB_RAW_MODINFOBUILDER_H
diff --git a/include/llvm/DebugInfo/PDB/Native/ModStream.h b/include/llvm/DebugInfo/PDB/Native/ModStream.h
new file mode 100644
index 000000000000..d65e195dbb95
--- /dev/null
+++ b/include/llvm/DebugInfo/PDB/Native/ModStream.h
@@ -0,0 +1,62 @@
+//===- ModStream.h - PDB Module Info Stream Access ------------------------===//
+//
+// The LLVM Compiler Infrastructure
+//
+// This file is distributed under the University of Illinois Open Source
+// License. See LICENSE.TXT for details.
+//
+//===----------------------------------------------------------------------===//
+
+#ifndef LLVM_DEBUGINFO_PDB_RAW_MODSTREAM_H
+#define LLVM_DEBUGINFO_PDB_RAW_MODSTREAM_H
+
+#include "llvm/ADT/iterator_range.h"
+#include "llvm/DebugInfo/CodeView/CVRecord.h"
+#include "llvm/DebugInfo/CodeView/ModuleSubstream.h"
+#include "llvm/DebugInfo/CodeView/SymbolRecord.h"
+#include "llvm/DebugInfo/MSF/MappedBlockStream.h"
+#include "llvm/Support/BinaryStreamArray.h"
+#include "llvm/Support/BinaryStreamRef.h"
+#include "llvm/Support/Error.h"
+
+namespace llvm {
+namespace pdb {
+class PDBFile;
+class ModInfo;
+
+class ModStream {
+public:
+ ModStream(const ModInfo &Module,
+ std::unique_ptr<msf::MappedBlockStream> Stream);
+ ~ModStream();
+
+ Error reload();
+
+ uint32_t signature() const { return Signature; }
+
+ iterator_range<codeview::CVSymbolArray::Iterator>
+ symbols(bool *HadError) const;
+
+ iterator_range<codeview::ModuleSubstreamArray::Iterator>
+ lines(bool *HadError) const;
+
+ Error commit();
+
+private:
+ const ModInfo &Mod;
+
+ uint32_t Signature;
+
+ std::unique_ptr<msf::MappedBlockStream> Stream;
+
+ codeview::CVSymbolArray SymbolsSubstream;
+ BinaryStreamRef LinesSubstream;
+ BinaryStreamRef C13LinesSubstream;
+ BinaryStreamRef GlobalRefsSubstream;
+
+ codeview::ModuleSubstreamArray LineInfo;
+};
+}
+}
+
+#endif
diff --git a/include/llvm/DebugInfo/PDB/Native/NamedStreamMap.h b/include/llvm/DebugInfo/PDB/Native/NamedStreamMap.h
new file mode 100644
index 000000000000..d4206503e7dc
--- /dev/null
+++ b/include/llvm/DebugInfo/PDB/Native/NamedStreamMap.h
@@ -0,0 +1,55 @@
+//===- NamedStreamMap.h - PDB Named Stream Map ------------------*- C++ -*-===//
+//
+// The LLVM Compiler Infrastructure
+//
+// This file is distributed under the University of Illinois Open Source
+// License. See LICENSE.TXT for details.
+//
+//===----------------------------------------------------------------------===//
+
+#ifndef LLVM_DEBUGINFO_PDB_RAW_PDBNAMEDSTREAMMAP_H
+#define LLVM_DEBUGINFO_PDB_RAW_PDBNAMEDSTREAMMAP_H
+
+#include "llvm/ADT/StringMap.h"
+#include "llvm/ADT/StringRef.h"
+#include "llvm/DebugInfo/PDB/Native/HashTable.h"
+#include "llvm/Support/Error.h"
+#include <cstdint>
+
+namespace llvm {
+class BinaryStreamReader;
+class BinaryStreamWriter;
+
+namespace pdb {
+class NamedStreamMapBuilder;
+class NamedStreamMap {
+ struct FinalizationInfo {
+ uint32_t StringDataBytes = 0;
+ uint32_t SerializedLength = 0;
+ };
+ friend NamedStreamMapBuilder;
+
+public:
+ NamedStreamMap();
+
+ Error load(BinaryStreamReader &Stream);
+ Error commit(BinaryStreamWriter &Writer) const;
+ uint32_t finalize();
+
+ uint32_t size() const;
+ bool get(StringRef Stream, uint32_t &StreamNo) const;
+ void set(StringRef Stream, uint32_t StreamNo);
+ void remove(StringRef Stream);
+
+ iterator_range<StringMapConstIterator<uint32_t>> entries() const;
+
+private:
+ Optional<FinalizationInfo> FinalizedInfo;
+ HashTable FinalizedHashTable;
+ StringMap<uint32_t> Mapping;
+};
+
+} // end namespace pdb
+} // end namespace llvm
+
+#endif // LLVM_DEBUGINFO_PDB_RAW_PDBNAMEDSTREAMMAP_H
diff --git a/include/llvm/DebugInfo/PDB/Native/NativeCompilandSymbol.h b/include/llvm/DebugInfo/PDB/Native/NativeCompilandSymbol.h
new file mode 100644
index 000000000000..8eeaf3e0ea49
--- /dev/null
+++ b/include/llvm/DebugInfo/PDB/Native/NativeCompilandSymbol.h
@@ -0,0 +1,35 @@
+//===- NativeCompilandSymbol.h - native impl for compiland syms -*- C++ -*-===//
+//
+// The LLVM Compiler Infrastructure
+//
+// This file is distributed under the University of Illinois Open Source
+// License. See LICENSE.TXT for details.
+//
+//===----------------------------------------------------------------------===//
+
+#ifndef LLVM_DEBUGINFO_PDB_NATIVE_NATIVECOMPILANDSYMBOL_H
+#define LLVM_DEBUGINFO_PDB_NATIVE_NATIVECOMPILANDSYMBOL_H
+
+#include "llvm/DebugInfo/PDB/Native/ModInfo.h"
+#include "llvm/DebugInfo/PDB/Native/NativeRawSymbol.h"
+
+namespace llvm {
+namespace pdb {
+
+class NativeCompilandSymbol : public NativeRawSymbol {
+public:
+ NativeCompilandSymbol(NativeSession &Session, const ModuleInfoEx &MI);
+ PDB_SymType getSymTag() const override;
+ bool isEditAndContinueEnabled() const override;
+ uint32_t getLexicalParentId() const override;
+ std::string getLibraryName() const override;
+ std::string getName() const override;
+
+private:
+ ModuleInfoEx Module;
+};
+
+} // namespace pdb
+} // namespace llvm
+
+#endif
diff --git a/include/llvm/DebugInfo/PDB/Native/NativeEnumModules.h b/include/llvm/DebugInfo/PDB/Native/NativeEnumModules.h
new file mode 100644
index 000000000000..60a55ee50cc4
--- /dev/null
+++ b/include/llvm/DebugInfo/PDB/Native/NativeEnumModules.h
@@ -0,0 +1,41 @@
+//==- NativeEnumModules.h - Native Module Enumerator impl --------*- C++ -*-==//
+//
+// The LLVM Compiler Infrastructure
+//
+// This file is distributed under the University of Illinois Open Source
+// License. See LICENSE.TXT for details.
+//
+//===----------------------------------------------------------------------===//
+
+#ifndef LLVM_DEBUGINFO_PDB_NATIVE_NATIVEENUMMODULES_H
+#define LLVM_DEBUGINFO_PDB_NATIVE_NATIVEENUMMODULES_H
+
+#include "llvm/DebugInfo/PDB/IPDBEnumChildren.h"
+#include "llvm/DebugInfo/PDB/Native/ModInfo.h"
+#include "llvm/DebugInfo/PDB/PDBSymbol.h"
+namespace llvm {
+namespace pdb {
+
+class NativeSession;
+
+class NativeEnumModules : public IPDBEnumChildren<PDBSymbol> {
+public:
+ explicit NativeEnumModules(NativeSession &Session,
+ ArrayRef<ModuleInfoEx> Modules,
+ 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;
+ NativeEnumModules *clone() const override;
+
+private:
+ NativeSession &Session;
+ ArrayRef<ModuleInfoEx> Modules;
+ uint32_t Index;
+};
+}
+}
+
+#endif
diff --git a/include/llvm/DebugInfo/PDB/Native/NativeExeSymbol.h b/include/llvm/DebugInfo/PDB/Native/NativeExeSymbol.h
new file mode 100644
index 000000000000..9516810539b6
--- /dev/null
+++ b/include/llvm/DebugInfo/PDB/Native/NativeExeSymbol.h
@@ -0,0 +1,39 @@
+//===- NativeExeSymbol.h - native impl for PDBSymbolExe ---------*- C++ -*-===//
+//
+// The LLVM Compiler Infrastructure
+//
+// This file is distributed under the University of Illinois Open Source
+// License. See LICENSE.TXT for details.
+//
+//===----------------------------------------------------------------------===//
+
+#ifndef LLVM_DEBUGINFO_PDB_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 NativeExeSymbol : public NativeRawSymbol {
+public:
+ NativeExeSymbol(NativeSession &Session);
+
+ std::unique_ptr<IPDBEnumSymbols>
+ findChildren(PDB_SymType Type) const override;
+
+ uint32_t getAge() const override;
+ std::string getSymbolsFileName() const override;
+ PDB_UniqueId getGuid() const override;
+ bool hasCTypes() const override;
+ bool hasPrivateSymbols() const override;
+
+private:
+ PDBFile &File;
+};
+
+} // namespace pdb
+} // namespace llvm
+
+#endif
diff --git a/include/llvm/DebugInfo/PDB/Native/NativeRawSymbol.h b/include/llvm/DebugInfo/PDB/Native/NativeRawSymbol.h
new file mode 100644
index 000000000000..cffb5d09d225
--- /dev/null
+++ b/include/llvm/DebugInfo/PDB/Native/NativeRawSymbol.h
@@ -0,0 +1,208 @@
+//===- NativeRawSymbol.h - Native implementation of IPDBRawSymbol - C++ -*-===//
+//
+// The LLVM Compiler Infrastructure
+//
+// This file is distributed under the University of Illinois Open Source
+// License. See LICENSE.TXT for details.
+//
+//===----------------------------------------------------------------------===//
+
+#ifndef LLVM_DEBUGINFO_PDB_NATIVE_NATIVERAWSYMBOL_H
+#define LLVM_DEBUGINFO_PDB_NATIVE_NATIVERAWSYMBOL_H
+
+#include "llvm/DebugInfo/PDB/IPDBRawSymbol.h"
+
+namespace llvm {
+namespace pdb {
+
+class NativeSession;
+
+class NativeRawSymbol : public IPDBRawSymbol {
+public:
+ explicit NativeRawSymbol(NativeSession &PDBSession);
+
+ void dump(raw_ostream &OS, int Indent) 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>
+ findChildrenByRVA(PDB_SymType Type, StringRef Name, PDB_NameSearchFlags Flags,
+ uint32_t RVA) const override;
+ std::unique_ptr<IPDBEnumSymbols>
+ findInlineFramesByRVA(uint32_t RVA) const override;
+
+ void getDataBytes(llvm::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;
+ uint32_t getArrayIndexTypeId() const override;
+ uint32_t getBaseDataOffset() const override;
+ uint32_t getBaseDataSlot() const override;
+ uint32_t getBaseSymbolId() const override;
+ PDB_BuiltinType getBuiltinType() const override;
+ uint32_t getBitPosition() const override;
+ PDB_CallingConv getCallingConvention() const override;
+ uint32_t getClassParentId() const override;
+ std::string getCompilerName() const override;
+ uint32_t getCount() const override;
+ uint32_t getCountLiveRanges() const override;
+ PDB_Lang getLanguage() const override;
+ uint32_t 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;
+ uint32_t 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;
+ uint32_t 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;
+ uint32_t getStride() const override;
+ uint32_t getSubTypeId() const override;
+ std::string getSymbolsFileName() const override;
+ uint32_t 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;
+ uint32_t getTypeId() const override;
+ uint32_t getUavSlot() const override;
+ std::string getUndecoratedName() const override;
+ uint32_t getUnmodifiedTypeId() const override;
+ uint32_t getUpperBoundId() const override;
+ Variant getValue() const override;
+ uint32_t getVirtualBaseDispIndex() const override;
+ uint32_t getVirtualBaseOffset() const override;
+ uint32_t getVirtualTableShapeId() const override;
+ std::unique_ptr<PDBSymbolTypeVTable> getVirtualBaseTableType() const override;
+ PDB_DataKind getDataKind() const override;
+ PDB_SymType getSymTag() const override;
+ PDB_UniqueId 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;
+};
+
+}
+}
+
+#endif
diff --git a/include/llvm/DebugInfo/PDB/Native/NativeSession.h b/include/llvm/DebugInfo/PDB/Native/NativeSession.h
new file mode 100644
index 000000000000..e6da266f796d
--- /dev/null
+++ b/include/llvm/DebugInfo/PDB/Native/NativeSession.h
@@ -0,0 +1,78 @@
+//===- NativeSession.h - Native implementation of IPDBSession ---*- C++ -*-===//
+//
+// The LLVM Compiler Infrastructure
+//
+// This file is distributed under the University of Illinois Open Source
+// License. See LICENSE.TXT for details.
+//
+//===----------------------------------------------------------------------===//
+
+#ifndef LLVM_DEBUGINFO_PDB_RAW_RAWSESSION_H
+#define LLVM_DEBUGINFO_PDB_RAW_RAWSESSION_H
+
+#include "llvm/ADT/StringRef.h"
+#include "llvm/DebugInfo/PDB/IPDBSession.h"
+#include "llvm/Support/Allocator.h"
+#include "llvm/Support/Error.h"
+
+namespace llvm {
+namespace pdb {
+class PDBFile;
+
+class NativeSession : public IPDBSession {
+public:
+ NativeSession(std::unique_ptr<PDBFile> PdbFile,
+ std::unique_ptr<BumpPtrAllocator> Allocator);
+ ~NativeSession() override;
+
+ static Error createFromPdb(StringRef Path,
+ std::unique_ptr<IPDBSession> &Session);
+ static Error createFromExe(StringRef Path,
+ std::unique_ptr<IPDBSession> &Session);
+
+ uint64_t getLoadAddress() const override;
+ void setLoadAddress(uint64_t Address) override;
+ std::unique_ptr<PDBSymbolExe> getGlobalScope() const override;
+ std::unique_ptr<PDBSymbol> getSymbolById(uint32_t SymbolId) const override;
+
+ std::unique_ptr<PDBSymbol>
+ findSymbolByAddress(uint64_t Address, 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<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;
+
+ PDBFile &getPDBFile() { return *Pdb; }
+ const PDBFile &getPDBFile() const { return *Pdb; }
+
+private:
+ std::unique_ptr<PDBFile> Pdb;
+ std::unique_ptr<BumpPtrAllocator> Allocator;
+};
+}
+}
+
+#endif
diff --git a/include/llvm/DebugInfo/PDB/Native/PDBFile.h b/include/llvm/DebugInfo/PDB/Native/PDBFile.h
new file mode 100644
index 000000000000..fbca62d6e9d9
--- /dev/null
+++ b/include/llvm/DebugInfo/PDB/Native/PDBFile.h
@@ -0,0 +1,139 @@
+//===- PDBFile.h - Low level interface to a PDB file ------------*- C++ -*-===//
+//
+// The LLVM Compiler Infrastructure
+//
+// This file is distributed under the University of Illinois Open Source
+// License. See LICENSE.TXT for details.
+//
+//===----------------------------------------------------------------------===//
+
+#ifndef LLVM_DEBUGINFO_PDB_RAW_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 StringTable;
+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 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<uint32_t> getFpmPages() const { return FpmPages; }
+
+ 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;
+
+ 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<StringTable &> getStringTable();
+
+ BumpPtrAllocator &getAllocator() { return Allocator; }
+
+ bool hasPDBDbiStream() const;
+ bool hasPDBGlobalsStream();
+ bool hasPDBInfoStream();
+ bool hasPDBIpiStream() const;
+ bool hasPDBPublicsStream();
+ bool hasPDBSymbolStream();
+ bool hasPDBTpiStream() const;
+ bool hasStringTable();
+
+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;
+
+ std::vector<uint32_t> FpmPages;
+ 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<StringTable> Strings;
+};
+}
+}
+
+#endif
diff --git a/include/llvm/DebugInfo/PDB/Native/PDBFileBuilder.h b/include/llvm/DebugInfo/PDB/Native/PDBFileBuilder.h
new file mode 100644
index 000000000000..3898af5afc9e
--- /dev/null
+++ b/include/llvm/DebugInfo/PDB/Native/PDBFileBuilder.h
@@ -0,0 +1,71 @@
+//===- PDBFileBuilder.h - PDB File Creation ---------------------*- C++ -*-===//
+//
+// The LLVM Compiler Infrastructure
+//
+// This file is distributed under the University of Illinois Open Source
+// License. See LICENSE.TXT for details.
+//
+//===----------------------------------------------------------------------===//
+
+#ifndef LLVM_DEBUGINFO_PDB_RAW_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/RawConstants.h"
+#include "llvm/DebugInfo/PDB/Native/StringTableBuilder.h"
+#include "llvm/Support/Allocator.h"
+#include "llvm/Support/Endian.h"
+#include "llvm/Support/Error.h"
+
+#include <memory>
+#include <vector>
+
+namespace llvm {
+namespace msf {
+class MSFBuilder;
+}
+namespace pdb {
+class DbiStreamBuilder;
+class InfoStreamBuilder;
+class TpiStreamBuilder;
+
+class PDBFileBuilder {
+public:
+ explicit PDBFileBuilder(BumpPtrAllocator &Allocator);
+ 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();
+ StringTableBuilder &getStringTableBuilder();
+
+ Error commit(StringRef Filename);
+
+private:
+ Error addNamedStream(StringRef Name, uint32_t Size);
+ Expected<msf::MSFLayout> finalizeMsfLayout();
+
+ BumpPtrAllocator &Allocator;
+
+ std::unique_ptr<msf::MSFBuilder> Msf;
+ std::unique_ptr<InfoStreamBuilder> Info;
+ std::unique_ptr<DbiStreamBuilder> Dbi;
+ std::unique_ptr<TpiStreamBuilder> Tpi;
+ std::unique_ptr<TpiStreamBuilder> Ipi;
+
+ StringTableBuilder Strings;
+ NamedStreamMap NamedStreams;
+};
+}
+}
+
+#endif
diff --git a/include/llvm/DebugInfo/PDB/Native/PDBTypeServerHandler.h b/include/llvm/DebugInfo/PDB/Native/PDBTypeServerHandler.h
new file mode 100644
index 000000000000..d965e1008e95
--- /dev/null
+++ b/include/llvm/DebugInfo/PDB/Native/PDBTypeServerHandler.h
@@ -0,0 +1,48 @@
+//===- PDBTypeServerHandler.h -----------------------------------*- C++ -*-===//
+//
+// The LLVM Compiler Infrastructure
+//
+// This file is distributed under the University of Illinois Open Source
+// License. See LICENSE.TXT for details.
+//
+//===----------------------------------------------------------------------===//
+
+#ifndef LLVM_DEBUGINFO_PDB_PDBTYPESERVERHANDLER_H
+#define LLVM_DEBUGINFO_PDB_PDBTYPESERVERHANDLER_H
+
+#include "llvm/ADT/SmallString.h"
+#include "llvm/ADT/SmallVector.h"
+#include "llvm/ADT/StringMap.h"
+#include "llvm/DebugInfo/CodeView/CVTypeVisitor.h"
+#include "llvm/DebugInfo/CodeView/TypeRecord.h"
+#include "llvm/DebugInfo/CodeView/TypeServerHandler.h"
+#include "llvm/DebugInfo/PDB/Native/NativeSession.h"
+#include "llvm/DebugInfo/PDB/PDBTypes.h"
+
+#include <memory>
+#include <string>
+
+namespace llvm {
+namespace pdb {
+class NativeSession;
+
+class PDBTypeServerHandler : public codeview::TypeServerHandler {
+public:
+ PDBTypeServerHandler(bool RevisitAlways = false);
+
+ void addSearchPath(StringRef Path);
+ Expected<bool> handle(codeview::TypeServer2Record &TS,
+ codeview::TypeVisitorCallbacks &Callbacks) override;
+
+private:
+ Expected<bool> handleInternal(PDBFile &File,
+ codeview::TypeVisitorCallbacks &Callbacks);
+
+ bool RevisitAlways;
+ std::unique_ptr<NativeSession> Session;
+ SmallVector<SmallString<64>, 4> SearchPaths;
+};
+}
+}
+
+#endif
diff --git a/include/llvm/DebugInfo/PDB/Native/PublicsStream.h b/include/llvm/DebugInfo/PDB/Native/PublicsStream.h
new file mode 100644
index 000000000000..4a541edd6a7b
--- /dev/null
+++ b/include/llvm/DebugInfo/PDB/Native/PublicsStream.h
@@ -0,0 +1,73 @@
+//===- PublicsStream.h - PDB Public Symbol Stream -------- ------*- C++ -*-===//
+//
+// The LLVM Compiler Infrastructure
+//
+// This file is distributed under the University of Illinois Open Source
+// License. See LICENSE.TXT for details.
+//
+//===----------------------------------------------------------------------===//
+
+#ifndef LLVM_DEBUGINFO_PDB_RAW_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/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 {
+ struct HeaderInfo;
+
+public:
+ PublicsStream(PDBFile &File, std::unique_ptr<msf::MappedBlockStream> Stream);
+ ~PublicsStream();
+ Error reload();
+
+ uint32_t getSymHash() const;
+ uint32_t getAddrMap() const;
+ uint32_t getNumBuckets() const { return NumBuckets; }
+ iterator_range<codeview::CVSymbolArray::Iterator>
+ getSymbols(bool *HadError) const;
+ FixedStreamArray<support::ulittle32_t> getHashBuckets() const {
+ return HashBuckets;
+ }
+ FixedStreamArray<support::ulittle32_t> getAddressMap() const {
+ return AddressMap;
+ }
+ FixedStreamArray<support::ulittle32_t> getThunkMap() const {
+ return ThunkMap;
+ }
+ FixedStreamArray<SectionOffset> getSectionOffsets() const {
+ return SectionOffsets;
+ }
+
+ Error commit();
+
+private:
+ PDBFile &Pdb;
+
+ std::unique_ptr<msf::MappedBlockStream> Stream;
+ uint32_t NumBuckets = 0;
+ ArrayRef<uint8_t> Bitmap;
+ FixedStreamArray<PSHashRecord> HashRecords;
+ FixedStreamArray<support::ulittle32_t> HashBuckets;
+ FixedStreamArray<support::ulittle32_t> AddressMap;
+ FixedStreamArray<support::ulittle32_t> ThunkMap;
+ FixedStreamArray<SectionOffset> SectionOffsets;
+
+ const HeaderInfo *Header;
+ const GSIHashHeader *HashHdr;
+};
+}
+}
+
+#endif
diff --git a/include/llvm/DebugInfo/PDB/Native/RawConstants.h b/include/llvm/DebugInfo/PDB/Native/RawConstants.h
new file mode 100644
index 000000000000..f5d4df8feb2e
--- /dev/null
+++ b/include/llvm/DebugInfo/PDB/Native/RawConstants.h
@@ -0,0 +1,114 @@
+//===- RawConstants.h -------------------------------------------*- C++ -*-===//
+//
+// The LLVM Compiler Infrastructure
+//
+// This file is distributed under the University of Illinois Open Source
+// License. See LICENSE.TXT for details.
+//
+//===----------------------------------------------------------------------===//
+
+#ifndef LLVM_DEBUGINFO_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_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 {
+ 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.
+};
+
+} // end namespace pdb
+} // end namespace llvm
+
+#endif // LLVM_DEBUGINFO_PDB_RAW_PDBRAWCONSTANTS_H
diff --git a/include/llvm/DebugInfo/PDB/Native/RawError.h b/include/llvm/DebugInfo/PDB/Native/RawError.h
new file mode 100644
index 000000000000..3624a7682e38
--- /dev/null
+++ b/include/llvm/DebugInfo/PDB/Native/RawError.h
@@ -0,0 +1,53 @@
+//===- RawError.h - Error extensions for raw PDB implementation -*- C++ -*-===//
+//
+// The LLVM Compiler Infrastructure
+//
+// This file is distributed under the University of Illinois Open Source
+// License. See LICENSE.TXT for details.
+//
+//===----------------------------------------------------------------------===//
+
+#ifndef LLVM_DEBUGINFO_PDB_RAW_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,
+};
+
+/// Base class for errors originating when parsing raw PDB files
+class RawError : public ErrorInfo<RawError> {
+public:
+ static char ID;
+ RawError(raw_error_code C);
+ RawError(const std::string &Context);
+ RawError(raw_error_code C, const std::string &Context);
+
+ void log(raw_ostream &OS) const override;
+ const std::string &getErrorMessage() const;
+ std::error_code convertToErrorCode() const override;
+
+private:
+ std::string ErrMsg;
+ raw_error_code Code;
+};
+}
+}
+#endif
diff --git a/include/llvm/DebugInfo/PDB/Native/RawTypes.h b/include/llvm/DebugInfo/PDB/Native/RawTypes.h
new file mode 100644
index 000000000000..1b2631efce70
--- /dev/null
+++ b/include/llvm/DebugInfo/PDB/Native/RawTypes.h
@@ -0,0 +1,321 @@
+//===- RawTypes.h -----------------------------------------------*- C++ -*-===//
+//
+// The LLVM Compiler Infrastructure
+//
+// This file is distributed under the University of Illinois Open Source
+// License. See LICENSE.TXT for details.
+//
+//===----------------------------------------------------------------------===//
+
+#ifndef LLVM_DEBUGINFO_PDB_RAW_RAWTYPES_H
+#define LLVM_DEBUGINFO_PDB_RAW_RAWTYPES_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];
+};
+
+// 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.
+};
+
+// Used for serialized hash table in TPI stream.
+// In the reference, it is an array of TI and cbOff pair.
+struct TypeIndexOffset {
+ codeview::TypeIndex Type;
+ support::ulittle32_t Offset;
+};
+
+/// 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;
+};
+
+/// 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!");
+
+struct SectionContribEntry {
+ support::ulittle16_t Section;
+ char Padding1[2];
+ support::little32_t Offset;
+ support::little32_t Size;
+ support::ulittle32_t Characteristics;
+ support::ulittle16_t ModuleIndex;
+ char Padding2[2];
+ support::ulittle32_t DataCrc;
+ support::ulittle32_t RelocCrc;
+};
+
+/// 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 ModInfo 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.
+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.
+ SectionContribEntry 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 line number debug info in above stream
+ support::ulittle32_t LineBytes;
+
+ /// 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. This field is a pointer
+ /// in the reference implementation, but as with `Mod`, we ignore it for now
+ /// since it is unused.
+ 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[];
+};
+
+/// Defines a 128-bit unique identifier. This maps to a GUID on Windows, but
+/// is abstracted here for the purposes of non-Windows platforms that don't have
+/// the GUID structure defined.
+struct PDB_UniqueId {
+ uint8_t Guid[16];
+};
+
+inline bool operator==(const PDB_UniqueId &LHS, const PDB_UniqueId &RHS) {
+ return 0 == ::memcmp(LHS.Guid, RHS.Guid, sizeof(LHS.Guid));
+}
+
+// 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;
+ PDB_UniqueId Guid;
+};
+
+/// The header preceeding the /names stream.
+struct StringTableHeader {
+ support::ulittle32_t Signature;
+ support::ulittle32_t HashVersion;
+ support::ulittle32_t ByteSize;
+};
+
+const uint32_t StringTableSignature = 0xEFFEEFFE;
+
+} // namespace pdb
+} // namespace llvm
+
+#endif
diff --git a/include/llvm/DebugInfo/PDB/Native/StringTable.h b/include/llvm/DebugInfo/PDB/Native/StringTable.h
new file mode 100644
index 000000000000..dd5e30e61827
--- /dev/null
+++ b/include/llvm/DebugInfo/PDB/Native/StringTable.h
@@ -0,0 +1,56 @@
+//===- StringTable.h - PDB String Table -------------------------*- C++ -*-===//
+//
+// The LLVM Compiler Infrastructure
+//
+// This file is distributed under the University of Illinois Open Source
+// License. See LICENSE.TXT for details.
+//
+//===----------------------------------------------------------------------===//
+
+#ifndef LLVM_DEBUGINFO_PDB_RAW_STRINGTABLE_H
+#define LLVM_DEBUGINFO_PDB_RAW_STRINGTABLE_H
+
+#include "llvm/ADT/ArrayRef.h"
+#include "llvm/ADT/StringRef.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 pdb {
+
+class StringTable {
+public:
+ StringTable();
+
+ Error load(BinaryStreamReader &Stream);
+
+ uint32_t getByteSize() const;
+
+ uint32_t getNameCount() const { return NameCount; }
+ uint32_t getHashVersion() const { return HashVersion; }
+ uint32_t getSignature() const { return Signature; }
+
+ StringRef getStringForID(uint32_t ID) const;
+ uint32_t getIDForString(StringRef Str) const;
+
+ FixedStreamArray<support::ulittle32_t> name_ids() const;
+
+private:
+ BinaryStreamRef NamesBuffer;
+ FixedStreamArray<support::ulittle32_t> IDs;
+ uint32_t ByteSize = 0;
+ uint32_t Signature = 0;
+ uint32_t HashVersion = 0;
+ uint32_t NameCount = 0;
+};
+
+} // end namespace pdb
+} // end namespace llvm
+
+#endif // LLVM_DEBUGINFO_PDB_RAW_STRINGTABLE_H
diff --git a/include/llvm/DebugInfo/PDB/Native/StringTableBuilder.h b/include/llvm/DebugInfo/PDB/Native/StringTableBuilder.h
new file mode 100644
index 000000000000..dd0f40b1978d
--- /dev/null
+++ b/include/llvm/DebugInfo/PDB/Native/StringTableBuilder.h
@@ -0,0 +1,44 @@
+//===- StringTableBuilder.h - PDB String Table Builder ----------*- C++ -*-===//
+//
+// The LLVM Compiler Infrastructure
+//
+// This file is distributed under the University of Illinois Open Source
+// License. See LICENSE.TXT for details.
+//
+//===----------------------------------------------------------------------===//
+//
+// This file creates the "/names" stream.
+//
+//===----------------------------------------------------------------------===//
+
+#ifndef LLVM_DEBUGINFO_PDB_RAW_STRINGTABLEBUILDER_H
+#define LLVM_DEBUGINFO_PDB_RAW_STRINGTABLEBUILDER_H
+
+#include "llvm/ADT/DenseMap.h"
+#include "llvm/ADT/StringRef.h"
+#include "llvm/Support/Error.h"
+#include <vector>
+
+namespace llvm {
+class BinaryStreamWriter;
+
+namespace pdb {
+
+class StringTableBuilder {
+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 finalize();
+ Error commit(BinaryStreamWriter &Writer) const;
+
+private:
+ DenseMap<StringRef, uint32_t> Strings;
+ uint32_t StringSize = 1;
+};
+
+} // end namespace pdb
+} // end namespace llvm
+
+#endif // LLVM_DEBUGINFO_PDB_RAW_STRINGTABLEBUILDER_H
diff --git a/include/llvm/DebugInfo/PDB/Native/SymbolStream.h b/include/llvm/DebugInfo/PDB/Native/SymbolStream.h
new file mode 100644
index 000000000000..41d5e6ad64a0
--- /dev/null
+++ b/include/llvm/DebugInfo/PDB/Native/SymbolStream.h
@@ -0,0 +1,42 @@
+//===- SymbolStream.cpp - PDB Symbol Stream Access --------------*- C++ -*-===//
+//
+// The LLVM Compiler Infrastructure
+//
+// This file is distributed under the University of Illinois Open Source
+// License. See LICENSE.TXT for details.
+//
+//===----------------------------------------------------------------------===//
+
+#ifndef LLVM_DEBUGINFO_PDB_RAW_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();
+
+ 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/include/llvm/DebugInfo/PDB/Native/TpiHashing.h b/include/llvm/DebugInfo/PDB/Native/TpiHashing.h
new file mode 100644
index 000000000000..dd2698c354a2
--- /dev/null
+++ b/include/llvm/DebugInfo/PDB/Native/TpiHashing.h
@@ -0,0 +1,95 @@
+//===- TpiHashing.h ---------------------------------------------*- C++ -*-===//
+//
+// The LLVM Compiler Infrastructure
+//
+// This file is distributed under the University of Illinois Open Source
+// License. See LICENSE.TXT for details.
+//
+//===----------------------------------------------------------------------===//
+
+#ifndef LLVM_DEBUGINFO_PDB_TPIHASHING_H
+#define LLVM_DEBUGINFO_PDB_TPIHASHING_H
+
+#include "llvm/ADT/Optional.h"
+#include "llvm/ADT/StringExtras.h"
+#include "llvm/DebugInfo/CodeView/TypeIndex.h"
+#include "llvm/DebugInfo/CodeView/TypeRecord.h"
+#include "llvm/DebugInfo/CodeView/TypeVisitorCallbacks.h"
+#include "llvm/DebugInfo/PDB/Native/RawError.h"
+#include "llvm/Support/BinaryStreamArray.h"
+#include "llvm/Support/Endian.h"
+#include "llvm/Support/Error.h"
+#include <cstdint>
+#include <string>
+
+namespace llvm {
+namespace pdb {
+
+class TpiHashUpdater : public codeview::TypeVisitorCallbacks {
+public:
+ TpiHashUpdater() = default;
+
+#define TYPE_RECORD(EnumName, EnumVal, Name) \
+ virtual Error visitKnownRecord(codeview::CVType &CVR, \
+ codeview::Name##Record &Record) override { \
+ visitKnownRecordImpl(CVR, Record); \
+ return Error::success(); \
+ }
+#define TYPE_RECORD_ALIAS(EnumName, EnumVal, Name, AliasName)
+#define MEMBER_RECORD(EnumName, EnumVal, Name)
+#define MEMBER_RECORD_ALIAS(EnumName, EnumVal, Name, AliasName)
+#include "llvm/DebugInfo/CodeView/TypeRecords.def"
+
+private:
+ template <typename RecordKind>
+ void visitKnownRecordImpl(codeview::CVType &CVR, RecordKind &Record) {
+ CVR.Hash = 0;
+ }
+
+ void visitKnownRecordImpl(codeview::CVType &CVR,
+ codeview::UdtSourceLineRecord &Rec);
+ void visitKnownRecordImpl(codeview::CVType &CVR,
+ codeview::UdtModSourceLineRecord &Rec);
+ void visitKnownRecordImpl(codeview::CVType &CVR, codeview::ClassRecord &Rec);
+ void visitKnownRecordImpl(codeview::CVType &CVR, codeview::EnumRecord &Rec);
+ void visitKnownRecordImpl(codeview::CVType &CVR, codeview::UnionRecord &Rec);
+};
+
+class TpiHashVerifier : public codeview::TypeVisitorCallbacks {
+public:
+ TpiHashVerifier(FixedStreamArray<support::ulittle32_t> &HashValues,
+ uint32_t NumHashBuckets)
+ : HashValues(HashValues), NumHashBuckets(NumHashBuckets) {}
+
+ Error visitKnownRecord(codeview::CVType &CVR,
+ codeview::UdtSourceLineRecord &Rec) override;
+ Error visitKnownRecord(codeview::CVType &CVR,
+ codeview::UdtModSourceLineRecord &Rec) override;
+ Error visitKnownRecord(codeview::CVType &CVR,
+ codeview::ClassRecord &Rec) override;
+ Error visitKnownRecord(codeview::CVType &CVR,
+ codeview::EnumRecord &Rec) override;
+ Error visitKnownRecord(codeview::CVType &CVR,
+ codeview::UnionRecord &Rec) override;
+ Error visitTypeBegin(codeview::CVType &CVR) override;
+
+private:
+ Error verifySourceLine(codeview::TypeIndex TI);
+
+ Error errorInvalidHash() {
+ return make_error<RawError>(
+ raw_error_code::invalid_tpi_hash,
+ "Type index is 0x" +
+ utohexstr(codeview::TypeIndex::FirstNonSimpleIndex + Index));
+ }
+
+ FixedStreamArray<support::ulittle32_t> HashValues;
+ codeview::CVType RawRecord;
+ uint32_t NumHashBuckets;
+ uint32_t Index = -1;
+};
+
+} // end namespace pdb
+} // end namespace llvm
+
+#endif // LLVM_DEBUGINFO_PDB_TPIHASHING_H
diff --git a/include/llvm/DebugInfo/PDB/Native/TpiStream.h b/include/llvm/DebugInfo/PDB/Native/TpiStream.h
new file mode 100644
index 000000000000..62dde0ef08b7
--- /dev/null
+++ b/include/llvm/DebugInfo/PDB/Native/TpiStream.h
@@ -0,0 +1,75 @@
+//===- TpiStream.cpp - PDB Type Info (TPI) Stream 2 Access ------*- C++ -*-===//
+//
+// The LLVM Compiler Infrastructure
+//
+// This file is distributed under the University of Illinois Open Source
+// License. See LICENSE.TXT for details.
+//
+//===----------------------------------------------------------------------===//
+
+#ifndef LLVM_DEBUGINFO_PDB_RAW_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/raw_ostream.h"
+
+#include "llvm/Support/Error.h"
+
+namespace llvm {
+namespace msf {
+class MappedBlockStream;
+}
+namespace pdb {
+class PDBFile;
+
+class TpiStream {
+ friend class TpiStreamBuilder;
+
+public:
+ TpiStream(const 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 NumTypeRecords() const;
+ uint16_t getTypeHashStreamIndex() const;
+ uint16_t getTypeHashStreamAuxIndex() const;
+
+ uint32_t getHashKeySize() const;
+ uint32_t NumHashBuckets() const;
+ FixedStreamArray<support::ulittle32_t> getHashValues() const;
+ FixedStreamArray<TypeIndexOffset> getTypeIndexOffsets() const;
+ HashTable &getHashAdjusters();
+
+ codeview::CVTypeRange types(bool *HadError) const;
+
+ Error commit();
+
+private:
+ Error verifyHashValues();
+
+ const PDBFile &Pdb;
+ std::unique_ptr<msf::MappedBlockStream> Stream;
+
+ codeview::CVTypeArray TypeRecords;
+
+ std::unique_ptr<BinaryStream> HashStream;
+ FixedStreamArray<support::ulittle32_t> HashValues;
+ FixedStreamArray<TypeIndexOffset> TypeIndexOffsets;
+ HashTable HashAdjusters;
+
+ const TpiStreamHeader *Header;
+};
+}
+}
+
+#endif
diff --git a/include/llvm/DebugInfo/PDB/Native/TpiStreamBuilder.h b/include/llvm/DebugInfo/PDB/Native/TpiStreamBuilder.h
new file mode 100644
index 000000000000..a29ed0b610d3
--- /dev/null
+++ b/include/llvm/DebugInfo/PDB/Native/TpiStreamBuilder.h
@@ -0,0 +1,88 @@
+//===- TpiStreamBuilder.h - PDB Tpi Stream Creation -------------*- C++ -*-===//
+//
+// The LLVM Compiler Infrastructure
+//
+// This file is distributed under the University of Illinois Open Source
+// License. See LICENSE.TXT for details.
+//
+//===----------------------------------------------------------------------===//
+
+#ifndef LLVM_DEBUGINFO_PDB_RAW_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();
+
+ 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;
+
+ Optional<PdbRaw_TpiVer> VerHeader;
+ std::vector<ArrayRef<uint8_t>> TypeRecords;
+ std::vector<uint32_t> TypeHashes;
+ std::vector<TypeIndexOffset> TypeIndexOffsets;
+ uint32_t HashStreamIndex = kInvalidStreamIndex;
+ std::unique_ptr<BinaryByteStream> HashValueStream;
+
+ const TpiStreamHeader *Header;
+ uint32_t Idx;
+};
+}
+}
+
+#endif