Line data Source code
1 : //===- DbiStreamBuilder.h - PDB Dbi Stream Creation -------------*- C++ -*-===//
2 : //
3 : // The LLVM Compiler Infrastructure
4 : //
5 : // This file is distributed under the University of Illinois Open Source
6 : // License. See LICENSE.TXT for details.
7 : //
8 : //===----------------------------------------------------------------------===//
9 :
10 : #ifndef LLVM_DEBUGINFO_PDB_RAW_PDBDBISTREAMBUILDER_H
11 : #define LLVM_DEBUGINFO_PDB_RAW_PDBDBISTREAMBUILDER_H
12 :
13 : #include "llvm/ADT/Optional.h"
14 : #include "llvm/ADT/StringSet.h"
15 : #include "llvm/Support/Error.h"
16 :
17 : #include "llvm/DebugInfo/MSF/ByteStream.h"
18 : #include "llvm/DebugInfo/MSF/StreamReader.h"
19 : #include "llvm/DebugInfo/PDB/PDBTypes.h"
20 : #include "llvm/DebugInfo/PDB/Raw/PDBFile.h"
21 : #include "llvm/DebugInfo/PDB/Raw/RawConstants.h"
22 : #include "llvm/Support/Endian.h"
23 :
24 : namespace llvm {
25 : namespace msf {
26 : class MSFBuilder;
27 : }
28 : namespace object {
29 : struct coff_section;
30 : }
31 : namespace pdb {
32 : class DbiStream;
33 : struct DbiStreamHeader;
34 : class PDBFile;
35 :
36 18 : class DbiStreamBuilder {
37 : public:
38 : DbiStreamBuilder(msf::MSFBuilder &Msf);
39 :
40 : DbiStreamBuilder(const DbiStreamBuilder &) = delete;
41 : DbiStreamBuilder &operator=(const DbiStreamBuilder &) = delete;
42 :
43 : void setVersionHeader(PdbRaw_DbiVer V);
44 : void setAge(uint32_t A);
45 : void setBuildNumber(uint16_t B);
46 : void setPdbDllVersion(uint16_t V);
47 : void setPdbDllRbld(uint16_t R);
48 : void setFlags(uint16_t F);
49 : void setMachineType(PDB_Machine M);
50 : void setSectionContribs(ArrayRef<SectionContrib> SecMap);
51 : void setSectionMap(ArrayRef<SecMapEntry> SecMap);
52 :
53 : // Add given bytes as a new stream.
54 : Error addDbgStream(pdb::DbgHeaderType Type, ArrayRef<uint8_t> Data);
55 :
56 : uint32_t calculateSerializedLength() const;
57 :
58 : Error addModuleInfo(StringRef ObjFile, StringRef Module);
59 : Error addModuleSourceFile(StringRef Module, StringRef File);
60 :
61 : Error finalizeMsfLayout();
62 :
63 : Error commit(const msf::MSFLayout &Layout,
64 : const msf::WritableStream &Buffer);
65 :
66 : // A helper function to create Section Contributions from COFF input
67 : // section headers.
68 : static std::vector<SectionContrib>
69 : createSectionContribs(ArrayRef<llvm::object::coff_section> SecHdrs);
70 :
71 : // A helper function to create a Section Map from a COFF section header.
72 : static std::vector<SecMapEntry>
73 : createSectionMap(ArrayRef<llvm::object::coff_section> SecHdrs);
74 :
75 : private:
76 6 : struct DebugStream {
77 : ArrayRef<uint8_t> Data;
78 : uint16_t StreamNumber = 0;
79 : };
80 :
81 : Error finalize();
82 : uint32_t calculateModiSubstreamSize() const;
83 : uint32_t calculateSectionContribsStreamSize() const;
84 : uint32_t calculateSectionMapStreamSize() const;
85 : uint32_t calculateFileInfoSubstreamSize() const;
86 : uint32_t calculateNamesBufferSize() const;
87 : uint32_t calculateDbgStreamsSize() const;
88 :
89 : Error generateModiSubstream();
90 : Error generateFileInfoSubstream();
91 :
92 24 : struct ModuleInfo {
93 : std::vector<StringRef> SourceFiles;
94 : StringRef Obj;
95 : StringRef Mod;
96 : };
97 :
98 : msf::MSFBuilder &Msf;
99 : BumpPtrAllocator &Allocator;
100 :
101 : Optional<PdbRaw_DbiVer> VerHeader;
102 : uint32_t Age;
103 : uint16_t BuildNumber;
104 : uint16_t PdbDllVersion;
105 : uint16_t PdbDllRbld;
106 : uint16_t Flags;
107 : PDB_Machine MachineType;
108 :
109 : const DbiStreamHeader *Header;
110 :
111 : StringMap<std::unique_ptr<ModuleInfo>> ModuleInfos;
112 : std::vector<ModuleInfo *> ModuleInfoList;
113 :
114 : StringMap<uint32_t> SourceFileNames;
115 :
116 : msf::WritableStreamRef NamesBuffer;
117 : msf::MutableByteStream ModInfoBuffer;
118 : msf::MutableByteStream FileInfoBuffer;
119 : ArrayRef<SectionContrib> SectionContribs;
120 : ArrayRef<SecMapEntry> SectionMap;
121 : llvm::SmallVector<DebugStream, (int)DbgHeaderType::Max> DbgStreams;
122 : };
123 : }
124 : }
125 :
126 : #endif
|