LLVM  14.0.0git
DbiModuleDescriptorBuilder.h
Go to the documentation of this file.
1 //===- DbiModuleDescriptorBuilder.h - PDB module information ----*- C++ -*-===//
2 //
3 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4 // See https://llvm.org/LICENSE.txt for license information.
5 // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6 //
7 //===----------------------------------------------------------------------===//
8 
9 #ifndef LLVM_DEBUGINFO_PDB_NATIVE_DBIMODULEDESCRIPTORBUILDER_H
10 #define LLVM_DEBUGINFO_PDB_NATIVE_DBIMODULEDESCRIPTORBUILDER_H
11 
12 #include "llvm/ADT/StringRef.h"
19 #include "llvm/Support/Error.h"
20 #include <cstdint>
21 #include <string>
22 #include <vector>
23 
24 namespace llvm {
25 class BinaryStreamWriter;
26 
27 namespace codeview {
28 class DebugSubsectionRecordBuilder;
29 }
30 
31 namespace msf {
32 class MSFBuilder;
33 struct MSFLayout;
34 }
35 namespace pdb {
36 
37 // Represents merged or unmerged symbols. Merged symbols can be written to the
38 // output file as is, but unmerged symbols must be rewritten first. In either
39 // case, the size must be known up front.
42  : SymPtr(const_cast<uint8_t *>(Syms.data())), SymSize(Syms.size()),
44  explicit SymbolListWrapper(void *SymSrc, uint32_t Length)
45  : SymPtr(SymSrc), SymSize(Length), NeedsToBeMerged(true) {}
46 
48  return ArrayRef<uint8_t>(static_cast<const uint8_t *>(SymPtr), SymSize);
49  }
50 
51  uint32_t size() const { return SymSize; }
52 
53  void *SymPtr = nullptr;
55  bool NeedsToBeMerged = false;
56 };
57 
58 /// Represents a string table reference at some offset in the module symbol
59 /// stream.
63 };
64 
66  friend class DbiStreamBuilder;
67 
68 public:
69  DbiModuleDescriptorBuilder(StringRef ModuleName, uint32_t ModIndex,
70  msf::MSFBuilder &Msf);
72 
75  operator=(const DbiModuleDescriptorBuilder &) = delete;
76 
77  void setPdbFilePathNI(uint32_t NI);
79 
80  // Callback to merge one source of unmerged symbols.
81  using MergeSymbolsCallback = Error (*)(void *Ctx, void *Symbols,
83 
84  void setMergeSymbolsCallback(void *Ctx, MergeSymbolsCallback Callback) {
85  MergeSymsCtx = Ctx;
86  MergeSymsCallback = Callback;
87  }
88 
89  void setStringTableFixups(std::vector<StringTableFixup> &&Fixups) {
90  StringTableFixups = std::move(Fixups);
91  }
92 
95  void addSymbolsInBulk(ArrayRef<uint8_t> BulkSymbols);
96 
97  // Add symbols of known size which will be merged (rewritten) when committing
98  // the PDB to disk.
99  void addUnmergedSymbols(void *SymSrc, uint32_t SymLength);
100 
101  void
102  addDebugSubsection(std::shared_ptr<codeview::DebugSubsection> Subsection);
103 
104  void
105  addDebugSubsection(const codeview::DebugSubsectionRecord &SubsectionContents);
106 
107  uint16_t getStreamIndex() const;
108  StringRef getModuleName() const { return ModuleName; }
109  StringRef getObjFileName() const { return ObjFileName; }
110 
111  unsigned getModuleIndex() const { return Layout.Mod; }
112 
114  return makeArrayRef(SourceFiles);
115  }
116 
118 
119  /// Return the offset within the module symbol stream of the next symbol
120  /// record passed to addSymbol. Add four to account for the signature.
121  uint32_t getNextSymbolOffset() const { return SymbolByteSize + 4; }
122 
123  void finalize();
125 
126  /// Commit the DBI descriptor to the DBI stream.
127  Error commit(BinaryStreamWriter &ModiWriter);
128 
129  /// Commit the accumulated symbols to the module symbol stream. Safe to call
130  /// in parallel on different DbiModuleDescriptorBuilder objects. Only modifies
131  /// the pre-allocated stream in question.
132  Error commitSymbolStream(const msf::MSFLayout &MsfLayout,
133  WritableBinaryStreamRef MsfBuffer);
134 
135 private:
136  uint32_t calculateC13DebugInfoSize() const;
137 
138  void addSourceFile(StringRef Path);
139  msf::MSFBuilder &MSF;
140 
141  uint32_t SymbolByteSize = 0;
142  uint32_t PdbFilePathNI = 0;
143  std::string ModuleName;
144  std::string ObjFileName;
145  std::vector<std::string> SourceFiles;
146  std::vector<SymbolListWrapper> Symbols;
147 
148  void *MergeSymsCtx = nullptr;
149  MergeSymbolsCallback MergeSymsCallback = nullptr;
150 
151  std::vector<StringTableFixup> StringTableFixups;
152 
153  std::vector<codeview::DebugSubsectionRecordBuilder> C13Builders;
154 
155  ModuleInfoHeader Layout;
156 };
157 
158 } // end namespace pdb
159 
160 } // end namespace llvm
161 
162 #endif // LLVM_DEBUGINFO_PDB_NATIVE_DBIMODULEDESCRIPTORBUILDER_H
llvm
---------------------— PointerInfo ------------------------------------—
Definition: AllocatorList.h:23
llvm::lltok::Error
@ Error
Definition: LLToken.h:21
llvm::pdb::DbiModuleDescriptorBuilder::addSymbolsInBulk
void addSymbolsInBulk(ArrayRef< uint8_t > BulkSymbols)
Definition: DbiModuleDescriptorBuilder.cpp:71
llvm::pdb::SectionContrib
Definition: RawTypes.h:46
RawTypes.h
llvm::pdb::SymbolListWrapper::NeedsToBeMerged
bool NeedsToBeMerged
Definition: DbiModuleDescriptorBuilder.h:55
StringRef.h
llvm::pdb::DbiModuleDescriptorBuilder::addUnmergedSymbols
void addUnmergedSymbols(void *SymSrc, uint32_t SymLength)
Definition: DbiModuleDescriptorBuilder.cpp:85
SymbolRecord.h
llvm::BinaryStreamWriter
Provides write only access to a subclass of WritableBinaryStream.
Definition: BinaryStreamWriter.h:31
Error.h
llvm::pdb::DbiModuleDescriptorBuilder::calculateSerializedLength
uint32_t calculateSerializedLength() const
Definition: DbiModuleDescriptorBuilder.cpp:109
llvm::pdb::SymbolListWrapper::SymPtr
void * SymPtr
Definition: DbiModuleDescriptorBuilder.h:53
llvm::pdb::SymbolListWrapper::SymSize
uint32_t SymSize
Definition: DbiModuleDescriptorBuilder.h:54
llvm::pdb::SymbolListWrapper
Definition: DbiModuleDescriptorBuilder.h:40
llvm::pdb::DbiModuleDescriptorBuilder::commit
Error commit(BinaryStreamWriter &ModiWriter)
Commit the DBI descriptor to the DBI stream.
Definition: DbiModuleDescriptorBuilder.cpp:146
llvm::msf::MSFBuilder
Definition: MSFBuilder.h:26
DebugChecksumsSubsection.h
llvm::PPCISD::SC
@ SC
CHAIN = SC CHAIN, Imm128 - System call.
Definition: PPCISelLowering.h:410
DebugSubsectionRecord.h
llvm::pdb::DbiStreamBuilder
Definition: DbiStreamBuilder.h:43
llvm::msf::MSFLayout
Definition: MSFCommon.h:51
llvm::pdb::ModuleInfoHeader
The header preceding each entry in the Module Info substream of the DBI stream.
Definition: RawTypes.h:212
false
Definition: StackSlotColoring.cpp:142
llvm::pdb::DbiModuleDescriptorBuilder::MergeSymbolsCallback
Error(*)(void *Ctx, void *Symbols, BinaryStreamWriter &Writer) MergeSymbolsCallback
Definition: DbiModuleDescriptorBuilder.h:82
llvm::AArch64::Fixups
Fixups
Definition: AArch64FixupKinds.h:17
llvm::pdb::DbiModuleDescriptorBuilder::setFirstSectionContrib
void setFirstSectionContrib(const SectionContrib &SC)
Definition: DbiModuleDescriptorBuilder.cpp:61
llvm::pdb::DbiModuleDescriptorBuilder::setObjFileName
void setObjFileName(StringRef Name)
Definition: DbiModuleDescriptorBuilder.cpp:53
llvm::pdb::DbiModuleDescriptorBuilder::finalize
void finalize()
Definition: DbiModuleDescriptorBuilder.cpp:116
llvm::pdb::DbiModuleDescriptorBuilder::source_files
ArrayRef< std::string > source_files() const
Definition: DbiModuleDescriptorBuilder.h:113
llvm::pdb::DbiModuleDescriptorBuilder::operator=
DbiModuleDescriptorBuilder & operator=(const DbiModuleDescriptorBuilder &)=delete
llvm::pdb::DbiModuleDescriptorBuilder::addDebugSubsection
void addDebugSubsection(std::shared_ptr< codeview::DebugSubsection > Subsection)
llvm::pdb::DbiModuleDescriptorBuilder::commitSymbolStream
Error commitSymbolStream(const msf::MSFLayout &MsfLayout, WritableBinaryStreamRef MsfBuffer)
Commit the accumulated symbols to the module symbol stream.
Definition: DbiModuleDescriptorBuilder.cpp:160
llvm::pdb::SymbolListWrapper::SymbolListWrapper
SymbolListWrapper(ArrayRef< uint8_t > Syms)
Definition: DbiModuleDescriptorBuilder.h:41
DebugLinesSubsection.h
llvm::pdb::DbiModuleDescriptorBuilder::getNextSymbolOffset
uint32_t getNextSymbolOffset() const
Return the offset within the module symbol stream of the next symbol record passed to addSymbol.
Definition: DbiModuleDescriptorBuilder.h:121
move
compiles ldr LCPI1_0 ldr ldr mov lsr tst moveq r1 ldr LCPI1_1 and r0 bx lr It would be better to do something like to fold the shift into the conditional move
Definition: README.txt:546
llvm::pdb::DbiModuleDescriptorBuilder::DbiModuleDescriptorBuilder
DbiModuleDescriptorBuilder(StringRef ModuleName, uint32_t ModIndex, msf::MSFBuilder &Msf)
Definition: DbiModuleDescriptorBuilder.cpp:39
llvm::codeview::DebugSubsectionRecord
Definition: DebugSubsectionRecord.h:35
llvm::pdb::DbiModuleDescriptorBuilder::addSymbol
void addSymbol(codeview::CVSymbol Symbol)
Definition: DbiModuleDescriptorBuilder.cpp:66
llvm::pdb::DbiModuleDescriptorBuilder::getObjFileName
StringRef getObjFileName() const
Definition: DbiModuleDescriptorBuilder.h:109
llvm::pdb::SymbolListWrapper::size
uint32_t size() const
Definition: DbiModuleDescriptorBuilder.h:51
llvm::pdb::DbiModuleDescriptorBuilder::setStringTableFixups
void setStringTableFixups(std::vector< StringTableFixup > &&Fixups)
Definition: DbiModuleDescriptorBuilder.h:89
llvm::ArrayRef< uint8_t >
llvm::pdb::StringTableFixup::SymOffsetOfReference
uint32_t SymOffsetOfReference
Definition: DbiModuleDescriptorBuilder.h:62
llvm::StringRef
StringRef - Represent a constant reference to a string, i.e.
Definition: StringRef.h:58
llvm::codeview::CVRecord
CVRecord is a fat pointer (base + size pair) to a symbol or type record.
Definition: CVRecord.h:30
llvm::pdb::DbiModuleDescriptorBuilder::setMergeSymbolsCallback
void setMergeSymbolsCallback(void *Ctx, MergeSymbolsCallback Callback)
Definition: DbiModuleDescriptorBuilder.h:84
uint32_t
llvm::pdb::DbiModuleDescriptorBuilder::getStreamIndex
uint16_t getStreamIndex() const
Definition: DbiModuleDescriptorBuilder.cpp:49
llvm::pdb::StringTableFixup
Represents a string table reference at some offset in the module symbol stream.
Definition: DbiModuleDescriptorBuilder.h:60
llvm::pdb::SymbolListWrapper::SymbolListWrapper
SymbolListWrapper(void *SymSrc, uint32_t Length)
Definition: DbiModuleDescriptorBuilder.h:44
llvm::pdb::DbiModuleDescriptorBuilder::getModuleName
StringRef getModuleName() const
Definition: DbiModuleDescriptorBuilder.h:108
llvm::pdb::SymbolListWrapper::asArray
ArrayRef< uint8_t > asArray() const
Definition: DbiModuleDescriptorBuilder.h:47
llvm::pdb::StringTableFixup::StrTabOffset
uint32_t StrTabOffset
Definition: DbiModuleDescriptorBuilder.h:61
DebugInlineeLinesSubsection.h
llvm::GraphProgram::Name
Name
Definition: GraphWriter.h:52
uint16_t
llvm::Error
Lightweight error class with error context and mandatory checking.
Definition: Error.h:157
llvm::pdb::DbiModuleDescriptorBuilder
Definition: DbiModuleDescriptorBuilder.h:65
llvm::pdb::DbiModuleDescriptorBuilder::getModuleIndex
unsigned getModuleIndex() const
Definition: DbiModuleDescriptorBuilder.h:111
llvm::makeArrayRef
ArrayRef< T > makeArrayRef(const T &OneElt)
Construct an ArrayRef from a single element.
Definition: ArrayRef.h:476
llvm::ARMBuildAttrs::Symbol
@ Symbol
Definition: ARMBuildAttributes.h:79
llvm::pdb::DbiModuleDescriptorBuilder::finalizeMsfLayout
Error finalizeMsfLayout()
Definition: DbiModuleDescriptorBuilder.cpp:133
llvm::pdb::DbiModuleDescriptorBuilder::setPdbFilePathNI
void setPdbFilePathNI(uint32_t NI)
Definition: DbiModuleDescriptorBuilder.cpp:57
true
basic Basic Alias true
Definition: BasicAliasAnalysis.cpp:1815
llvm::WritableBinaryStreamRef
Definition: BinaryStreamRef.h:221
llvm::pdb::DbiModuleDescriptorBuilder::~DbiModuleDescriptorBuilder
~DbiModuleDescriptorBuilder()
Definition: DbiModuleDescriptorBuilder.cpp:47
llvm::pdb::ModuleInfoHeader::Mod
support::ulittle32_t Mod
Currently opened module.
Definition: RawTypes.h:217