LLVM  15.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/ArrayRef.h"
13 #include "llvm/ADT/StringRef.h"
18 #include "llvm/Support/Error.h"
19 #include <cstdint>
20 #include <string>
21 #include <vector>
22 
23 namespace llvm {
24 class BinaryStreamWriter;
25 namespace codeview {
26 class DebugSubsection;
27 }
28 
29 namespace msf {
30 class MSFBuilder;
31 struct MSFLayout;
32 }
33 namespace pdb {
34 
35 // Represents merged or unmerged symbols. Merged symbols can be written to the
36 // output file as is, but unmerged symbols must be rewritten first. In either
37 // case, the size must be known up front.
40  : SymPtr(const_cast<uint8_t *>(Syms.data())), SymSize(Syms.size()),
42  explicit SymbolListWrapper(void *SymSrc, uint32_t Length)
43  : SymPtr(SymSrc), SymSize(Length), NeedsToBeMerged(true) {}
44 
46  return ArrayRef<uint8_t>(static_cast<const uint8_t *>(SymPtr), SymSize);
47  }
48 
49  uint32_t size() const { return SymSize; }
50 
51  void *SymPtr = nullptr;
53  bool NeedsToBeMerged = false;
54 };
55 
56 /// Represents a string table reference at some offset in the module symbol
57 /// stream.
61 };
62 
64  friend class DbiStreamBuilder;
65 
66 public:
68  msf::MSFBuilder &Msf);
70 
73  operator=(const DbiModuleDescriptorBuilder &) = delete;
74 
75  void setPdbFilePathNI(uint32_t NI);
77 
78  // Callback to merge one source of unmerged symbols.
79  using MergeSymbolsCallback = Error (*)(void *Ctx, void *Symbols,
81 
82  void setMergeSymbolsCallback(void *Ctx, MergeSymbolsCallback Callback) {
83  MergeSymsCtx = Ctx;
84  MergeSymsCallback = Callback;
85  }
86 
87  void setStringTableFixups(std::vector<StringTableFixup> &&Fixups) {
88  StringTableFixups = std::move(Fixups);
89  }
90 
93  void addSymbolsInBulk(ArrayRef<uint8_t> BulkSymbols);
94 
95  // Add symbols of known size which will be merged (rewritten) when committing
96  // the PDB to disk.
97  void addUnmergedSymbols(void *SymSrc, uint32_t SymLength);
98 
99  void
100  addDebugSubsection(std::shared_ptr<codeview::DebugSubsection> Subsection);
101 
102  void
103  addDebugSubsection(const codeview::DebugSubsectionRecord &SubsectionContents);
104 
105  uint16_t getStreamIndex() const;
106  StringRef getModuleName() const { return ModuleName; }
107  StringRef getObjFileName() const { return ObjFileName; }
108 
109  unsigned getModuleIndex() const { return Layout.Mod; }
110 
112  return makeArrayRef(SourceFiles);
113  }
114 
116 
117  /// Return the offset within the module symbol stream of the next symbol
118  /// record passed to addSymbol. Add four to account for the signature.
119  uint32_t getNextSymbolOffset() const { return SymbolByteSize + 4; }
120 
121  void finalize();
123 
124  /// Commit the DBI descriptor to the DBI stream.
125  Error commit(BinaryStreamWriter &ModiWriter);
126 
127  /// Commit the accumulated symbols to the module symbol stream. Safe to call
128  /// in parallel on different DbiModuleDescriptorBuilder objects. Only modifies
129  /// the pre-allocated stream in question.
130  Error commitSymbolStream(const msf::MSFLayout &MsfLayout,
131  WritableBinaryStreamRef MsfBuffer);
132 
133 private:
134  uint32_t calculateC13DebugInfoSize() const;
135 
136  void addSourceFile(StringRef Path);
137  msf::MSFBuilder &MSF;
138 
139  uint32_t SymbolByteSize = 0;
140  uint32_t PdbFilePathNI = 0;
141  std::string ModuleName;
142  std::string ObjFileName;
143  std::vector<std::string> SourceFiles;
144  std::vector<SymbolListWrapper> Symbols;
145 
146  void *MergeSymsCtx = nullptr;
147  MergeSymbolsCallback MergeSymsCallback = nullptr;
148 
149  std::vector<StringTableFixup> StringTableFixups;
150 
151  std::vector<codeview::DebugSubsectionRecordBuilder> C13Builders;
152 
153  ModuleInfoHeader Layout;
154 };
155 
156 } // end namespace pdb
157 
158 } // end namespace llvm
159 
160 #endif // LLVM_DEBUGINFO_PDB_NATIVE_DBIMODULEDESCRIPTORBUILDER_H
llvm
This is an optimization pass for GlobalISel generic memory operations.
Definition: AddressRanges.h:17
llvm::lltok::Error
@ Error
Definition: LLToken.h:21
llvm::pdb::DbiModuleDescriptorBuilder::addSymbolsInBulk
void addSymbolsInBulk(ArrayRef< uint8_t > BulkSymbols)
Definition: DbiModuleDescriptorBuilder.cpp:75
llvm::pdb::SectionContrib
Definition: RawTypes.h:46
RawTypes.h
llvm::pdb::SymbolListWrapper::NeedsToBeMerged
bool NeedsToBeMerged
Definition: DbiModuleDescriptorBuilder.h:53
StringRef.h
llvm::pdb::DbiModuleDescriptorBuilder::addUnmergedSymbols
void addUnmergedSymbols(void *SymSrc, uint32_t SymLength)
Definition: DbiModuleDescriptorBuilder.cpp:89
llvm::BinaryStreamWriter
Provides write only access to a subclass of WritableBinaryStream.
Definition: BinaryStreamWriter.h:30
Error.h
llvm::pdb::DbiModuleDescriptorBuilder::calculateSerializedLength
uint32_t calculateSerializedLength() const
Definition: DbiModuleDescriptorBuilder.cpp:113
true
basic Basic Alias true
Definition: BasicAliasAnalysis.cpp:1909
llvm::pdb::SymbolListWrapper::SymPtr
void * SymPtr
Definition: DbiModuleDescriptorBuilder.h:51
llvm::pdb::SymbolListWrapper::SymSize
uint32_t SymSize
Definition: DbiModuleDescriptorBuilder.h:52
llvm::pdb::SymbolListWrapper
Definition: DbiModuleDescriptorBuilder.h:38
llvm::pdb::DbiModuleDescriptorBuilder::commit
Error commit(BinaryStreamWriter &ModiWriter)
Commit the DBI descriptor to the DBI stream.
Definition: DbiModuleDescriptorBuilder.cpp:150
llvm::msf::MSFBuilder
Definition: MSFBuilder.h:27
llvm::PPCISD::SC
@ SC
CHAIN = SC CHAIN, Imm128 - System call.
Definition: PPCISelLowering.h:418
DebugSubsectionRecord.h
llvm::pdb::DbiStreamBuilder
Definition: DbiStreamBuilder.h:41
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:141
llvm::pdb::DbiModuleDescriptorBuilder::MergeSymbolsCallback
Error(*)(void *Ctx, void *Symbols, BinaryStreamWriter &Writer) MergeSymbolsCallback
Definition: DbiModuleDescriptorBuilder.h:80
llvm::AArch64::Fixups
Fixups
Definition: AArch64FixupKinds.h:17
llvm::pdb::DbiModuleDescriptorBuilder::setFirstSectionContrib
void setFirstSectionContrib(const SectionContrib &SC)
Definition: DbiModuleDescriptorBuilder.cpp:65
llvm::pdb::DbiModuleDescriptorBuilder::setObjFileName
void setObjFileName(StringRef Name)
Definition: DbiModuleDescriptorBuilder.cpp:57
llvm::pdb::DbiModuleDescriptorBuilder::finalize
void finalize()
Definition: DbiModuleDescriptorBuilder.cpp:120
llvm::pdb::DbiModuleDescriptorBuilder::source_files
ArrayRef< std::string > source_files() const
Definition: DbiModuleDescriptorBuilder.h:111
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:164
llvm::pdb::SymbolListWrapper::SymbolListWrapper
SymbolListWrapper(ArrayRef< uint8_t > Syms)
Definition: DbiModuleDescriptorBuilder.h:39
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:119
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
ArrayRef.h
llvm::pdb::DbiModuleDescriptorBuilder::DbiModuleDescriptorBuilder
DbiModuleDescriptorBuilder(StringRef ModuleName, uint32_t ModIndex, msf::MSFBuilder &Msf)
Definition: DbiModuleDescriptorBuilder.cpp:43
llvm::codeview::DebugSubsectionRecord
Definition: DebugSubsectionRecord.h:35
llvm::pdb::DbiModuleDescriptorBuilder::addSymbol
void addSymbol(codeview::CVSymbol Symbol)
Definition: DbiModuleDescriptorBuilder.cpp:70
ModuleName
Definition: ItaniumDemangle.h:989
llvm::pdb::DbiModuleDescriptorBuilder::getObjFileName
StringRef getObjFileName() const
Definition: DbiModuleDescriptorBuilder.h:107
llvm::pdb::SymbolListWrapper::size
uint32_t size() const
Definition: DbiModuleDescriptorBuilder.h:49
llvm::pdb::DbiModuleDescriptorBuilder::setStringTableFixups
void setStringTableFixups(std::vector< StringTableFixup > &&Fixups)
Definition: DbiModuleDescriptorBuilder.h:87
llvm::ArrayRef< uint8_t >
llvm::pdb::StringTableFixup::SymOffsetOfReference
uint32_t SymOffsetOfReference
Definition: DbiModuleDescriptorBuilder.h:60
llvm::StringRef
StringRef - Represent a constant reference to a string, i.e.
Definition: StringRef.h:58
BinaryStreamRef.h
llvm::codeview::CVRecord
CVRecord is a fat pointer (base + size pair) to a symbol or type record.
Definition: CVRecord.h:29
llvm::pdb::DbiModuleDescriptorBuilder::setMergeSymbolsCallback
void setMergeSymbolsCallback(void *Ctx, MergeSymbolsCallback Callback)
Definition: DbiModuleDescriptorBuilder.h:82
uint32_t
llvm::pdb::DbiModuleDescriptorBuilder::getStreamIndex
uint16_t getStreamIndex() const
Definition: DbiModuleDescriptorBuilder.cpp:53
llvm::pdb::StringTableFixup
Represents a string table reference at some offset in the module symbol stream.
Definition: DbiModuleDescriptorBuilder.h:58
llvm::pdb::SymbolListWrapper::SymbolListWrapper
SymbolListWrapper(void *SymSrc, uint32_t Length)
Definition: DbiModuleDescriptorBuilder.h:42
llvm::pdb::DbiModuleDescriptorBuilder::getModuleName
StringRef getModuleName() const
Definition: DbiModuleDescriptorBuilder.h:106
llvm::pdb::SymbolListWrapper::asArray
ArrayRef< uint8_t > asArray() const
Definition: DbiModuleDescriptorBuilder.h:45
llvm::pdb::StringTableFixup::StrTabOffset
uint32_t StrTabOffset
Definition: DbiModuleDescriptorBuilder.h:59
llvm::GraphProgram::Name
Name
Definition: GraphWriter.h:50
uint16_t
llvm::Error
Lightweight error class with error context and mandatory checking.
Definition: Error.h:155
llvm::pdb::DbiModuleDescriptorBuilder
Definition: DbiModuleDescriptorBuilder.h:63
CVRecord.h
llvm::pdb::DbiModuleDescriptorBuilder::getModuleIndex
unsigned getModuleIndex() const
Definition: DbiModuleDescriptorBuilder.h:109
llvm::makeArrayRef
ArrayRef< T > makeArrayRef(const T &OneElt)
Construct an ArrayRef from a single element.
Definition: ArrayRef.h:475
llvm::ARMBuildAttrs::Symbol
@ Symbol
Definition: ARMBuildAttributes.h:83
llvm::pdb::DbiModuleDescriptorBuilder::finalizeMsfLayout
Error finalizeMsfLayout()
Definition: DbiModuleDescriptorBuilder.cpp:137
llvm::pdb::DbiModuleDescriptorBuilder::setPdbFilePathNI
void setPdbFilePathNI(uint32_t NI)
Definition: DbiModuleDescriptorBuilder.cpp:61
llvm::WritableBinaryStreamRef
Definition: BinaryStreamRef.h:220
llvm::pdb::DbiModuleDescriptorBuilder::~DbiModuleDescriptorBuilder
~DbiModuleDescriptorBuilder()
llvm::pdb::ModuleInfoHeader::Mod
support::ulittle32_t Mod
Currently opened module.
Definition: RawTypes.h:217