PDBFileBuilder.h 3.6 KB

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