PDBFileBuilder.h 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117
  1. #pragma once
  2. #ifdef __GNUC__
  3. #pragma GCC diagnostic push
  4. #pragma GCC diagnostic ignored "-Wunused-parameter"
  5. #endif
  6. //===- PDBFileBuilder.h - PDB File Creation ---------------------*- C++ -*-===//
  7. //
  8. // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
  9. // See https://llvm.org/LICENSE.txt for license information.
  10. // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
  11. //
  12. //===----------------------------------------------------------------------===//
  13. #ifndef LLVM_DEBUGINFO_PDB_NATIVE_PDBFILEBUILDER_H
  14. #define LLVM_DEBUGINFO_PDB_NATIVE_PDBFILEBUILDER_H
  15. #include "llvm/ADT/ArrayRef.h"
  16. #include "llvm/ADT/SmallVector.h"
  17. #include "llvm/DebugInfo/PDB/Native/NamedStreamMap.h"
  18. #include "llvm/DebugInfo/PDB/Native/PDBFile.h"
  19. #include "llvm/DebugInfo/PDB/Native/PDBStringTableBuilder.h"
  20. #include "llvm/DebugInfo/PDB/Native/RawConstants.h"
  21. #include "llvm/DebugInfo/PDB/Native/RawTypes.h"
  22. #include "llvm/Support/Allocator.h"
  23. #include "llvm/Support/Endian.h"
  24. #include "llvm/Support/Error.h"
  25. #include "llvm/Support/MemoryBuffer.h"
  26. #include <memory>
  27. namespace llvm {
  28. namespace msf {
  29. class MSFBuilder;
  30. }
  31. namespace pdb {
  32. class DbiStreamBuilder;
  33. class InfoStreamBuilder;
  34. class GSIStreamBuilder;
  35. class TpiStreamBuilder;
  36. class PDBFileBuilder {
  37. public:
  38. explicit PDBFileBuilder(BumpPtrAllocator &Allocator);
  39. ~PDBFileBuilder();
  40. PDBFileBuilder(const PDBFileBuilder &) = delete;
  41. PDBFileBuilder &operator=(const PDBFileBuilder &) = delete;
  42. Error initialize(uint32_t BlockSize);
  43. msf::MSFBuilder &getMsfBuilder();
  44. InfoStreamBuilder &getInfoBuilder();
  45. DbiStreamBuilder &getDbiBuilder();
  46. TpiStreamBuilder &getTpiBuilder();
  47. TpiStreamBuilder &getIpiBuilder();
  48. PDBStringTableBuilder &getStringTableBuilder();
  49. GSIStreamBuilder &getGsiBuilder();
  50. // If HashPDBContentsToGUID is true on the InfoStreamBuilder, Guid is filled
  51. // with the computed PDB GUID on return.
  52. Error commit(StringRef Filename, codeview::GUID *Guid);
  53. Expected<uint32_t> getNamedStreamIndex(StringRef Name) const;
  54. Error addNamedStream(StringRef Name, StringRef Data);
  55. void addInjectedSource(StringRef Name, std::unique_ptr<MemoryBuffer> Buffer);
  56. private:
  57. struct InjectedSourceDescriptor {
  58. // The full name of the stream that contains the contents of this injected
  59. // source. This is built as a concatenation of the literal "/src/files"
  60. // plus the "vname".
  61. std::string StreamName;
  62. // The exact name of the file name as specified by the user.
  63. uint32_t NameIndex;
  64. // The string table index of the "vname" of the file. As far as we
  65. // understand, this is the same as the name, except it is lowercased and
  66. // forward slashes are converted to backslashes.
  67. uint32_t VNameIndex;
  68. std::unique_ptr<MemoryBuffer> Content;
  69. };
  70. Error finalizeMsfLayout();
  71. Expected<uint32_t> allocateNamedStream(StringRef Name, uint32_t Size);
  72. void commitInjectedSources(WritableBinaryStream &MsfBuffer,
  73. const msf::MSFLayout &Layout);
  74. void commitSrcHeaderBlock(WritableBinaryStream &MsfBuffer,
  75. const msf::MSFLayout &Layout);
  76. BumpPtrAllocator &Allocator;
  77. std::unique_ptr<msf::MSFBuilder> Msf;
  78. std::unique_ptr<InfoStreamBuilder> Info;
  79. std::unique_ptr<DbiStreamBuilder> Dbi;
  80. std::unique_ptr<GSIStreamBuilder> Gsi;
  81. std::unique_ptr<TpiStreamBuilder> Tpi;
  82. std::unique_ptr<TpiStreamBuilder> Ipi;
  83. PDBStringTableBuilder Strings;
  84. StringTableHashTraits InjectedSourceHashTraits;
  85. HashTable<SrcHeaderBlockEntry> InjectedSourceTable;
  86. SmallVector<InjectedSourceDescriptor, 2> InjectedSources;
  87. NamedStreamMap NamedStreams;
  88. DenseMap<uint32_t, std::string> NamedStreamData;
  89. };
  90. }
  91. }
  92. #endif
  93. #ifdef __GNUC__
  94. #pragma GCC diagnostic pop
  95. #endif