Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2026-05-10 08:43:45

0001 //===- PDBFileBuilder.h - PDB File Creation ---------------------*- C++ -*-===//
0002 //
0003 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
0004 // See https://llvm.org/LICENSE.txt for license information.
0005 // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
0006 //
0007 //===----------------------------------------------------------------------===//
0008 
0009 #ifndef LLVM_DEBUGINFO_PDB_NATIVE_PDBFILEBUILDER_H
0010 #define LLVM_DEBUGINFO_PDB_NATIVE_PDBFILEBUILDER_H
0011 
0012 #include "llvm/ADT/DenseMap.h"
0013 #include "llvm/ADT/SmallVector.h"
0014 #include "llvm/DebugInfo/PDB/Native/HashTable.h"
0015 #include "llvm/DebugInfo/PDB/Native/NamedStreamMap.h"
0016 #include "llvm/DebugInfo/PDB/Native/PDBStringTableBuilder.h"
0017 #include "llvm/Support/Allocator.h"
0018 #include "llvm/Support/Error.h"
0019 #include "llvm/Support/MemoryBuffer.h"
0020 #include <memory>
0021 
0022 namespace llvm {
0023 class WritableBinaryStream;
0024 namespace codeview {
0025 struct GUID;
0026 }
0027 
0028 namespace msf {
0029 class MSFBuilder;
0030 struct MSFLayout;
0031 }
0032 namespace pdb {
0033 struct SrcHeaderBlockEntry;
0034 class DbiStreamBuilder;
0035 class InfoStreamBuilder;
0036 class GSIStreamBuilder;
0037 class TpiStreamBuilder;
0038 
0039 class PDBFileBuilder {
0040 public:
0041   explicit PDBFileBuilder(BumpPtrAllocator &Allocator);
0042   ~PDBFileBuilder();
0043   PDBFileBuilder(const PDBFileBuilder &) = delete;
0044   PDBFileBuilder &operator=(const PDBFileBuilder &) = delete;
0045 
0046   Error initialize(uint32_t BlockSize);
0047 
0048   msf::MSFBuilder &getMsfBuilder();
0049   InfoStreamBuilder &getInfoBuilder();
0050   DbiStreamBuilder &getDbiBuilder();
0051   TpiStreamBuilder &getTpiBuilder();
0052   TpiStreamBuilder &getIpiBuilder();
0053   PDBStringTableBuilder &getStringTableBuilder();
0054   GSIStreamBuilder &getGsiBuilder();
0055 
0056   // If HashPDBContentsToGUID is true on the InfoStreamBuilder, Guid is filled
0057   // with the computed PDB GUID on return.
0058   Error commit(StringRef Filename, codeview::GUID *Guid);
0059 
0060   Expected<uint32_t> getNamedStreamIndex(StringRef Name) const;
0061   Error addNamedStream(StringRef Name, StringRef Data);
0062   void addInjectedSource(StringRef Name, std::unique_ptr<MemoryBuffer> Buffer);
0063 
0064 private:
0065   struct InjectedSourceDescriptor {
0066     // The full name of the stream that contains the contents of this injected
0067     // source.  This is built as a concatenation of the literal "/src/files"
0068     // plus the "vname".
0069     std::string StreamName;
0070 
0071     // The exact name of the file name as specified by the user.
0072     uint32_t NameIndex;
0073 
0074     // The string table index of the "vname" of the file.  As far as we
0075     // understand, this is the same as the name, except it is lowercased and
0076     // forward slashes are converted to backslashes.
0077     uint32_t VNameIndex;
0078     std::unique_ptr<MemoryBuffer> Content;
0079   };
0080 
0081   Error finalizeMsfLayout();
0082   Expected<uint32_t> allocateNamedStream(StringRef Name, uint32_t Size);
0083 
0084   void commitInjectedSources(WritableBinaryStream &MsfBuffer,
0085                              const msf::MSFLayout &Layout);
0086   void commitSrcHeaderBlock(WritableBinaryStream &MsfBuffer,
0087                             const msf::MSFLayout &Layout);
0088 
0089   BumpPtrAllocator &Allocator;
0090 
0091   std::unique_ptr<msf::MSFBuilder> Msf;
0092   std::unique_ptr<InfoStreamBuilder> Info;
0093   std::unique_ptr<DbiStreamBuilder> Dbi;
0094   std::unique_ptr<GSIStreamBuilder> Gsi;
0095   std::unique_ptr<TpiStreamBuilder> Tpi;
0096   std::unique_ptr<TpiStreamBuilder> Ipi;
0097 
0098   PDBStringTableBuilder Strings;
0099   StringTableHashTraits InjectedSourceHashTraits;
0100   HashTable<SrcHeaderBlockEntry> InjectedSourceTable;
0101 
0102   SmallVector<InjectedSourceDescriptor, 2> InjectedSources;
0103 
0104   NamedStreamMap NamedStreams;
0105   DenseMap<uint32_t, std::string> NamedStreamData;
0106 };
0107 }
0108 }
0109 
0110 #endif