1 //===- DbiStreamBuilder.cpp - 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 #include "llvm/DebugInfo/PDB/Raw/DbiStreamBuilder.h"
11
12 #include "llvm/DebugInfo/CodeView/StreamWriter.h"
13 #include "llvm/DebugInfo/PDB/Raw/DbiStream.h"
14 #include "llvm/DebugInfo/PDB/Raw/MappedBlockStream.h"
15 #include "llvm/DebugInfo/PDB/Raw/RawError.h"
16
17 using namespace llvm;
18 using namespace llvm::codeview;
19 using namespace llvm::pdb;
20
DbiStreamBuilder(PDBFile & File)21 DbiStreamBuilder::DbiStreamBuilder(PDBFile &File)
22 : File(File), Age(1), BuildNumber(0), PdbDllVersion(0), PdbDllRbld(0),
23 Flags(0), MachineType(PDB_Machine::x86) {}
24
setVersionHeader(PdbRaw_DbiVer V)25 void DbiStreamBuilder::setVersionHeader(PdbRaw_DbiVer V) { VerHeader = V; }
26
setAge(uint32_t A)27 void DbiStreamBuilder::setAge(uint32_t A) { Age = A; }
28
setBuildNumber(uint16_t B)29 void DbiStreamBuilder::setBuildNumber(uint16_t B) { BuildNumber = B; }
30
setPdbDllVersion(uint16_t V)31 void DbiStreamBuilder::setPdbDllVersion(uint16_t V) { PdbDllVersion = V; }
32
setPdbDllRbld(uint16_t R)33 void DbiStreamBuilder::setPdbDllRbld(uint16_t R) { PdbDllRbld = R; }
34
setFlags(uint16_t F)35 void DbiStreamBuilder::setFlags(uint16_t F) { Flags = F; }
36
setMachineType(PDB_Machine M)37 void DbiStreamBuilder::setMachineType(PDB_Machine M) { MachineType = M; }
38
build()39 Expected<std::unique_ptr<DbiStream>> DbiStreamBuilder::build() {
40 if (!VerHeader.hasValue())
41 return make_error<RawError>(raw_error_code::unspecified,
42 "Missing DBI Stream Version");
43
44 auto DbiS = MappedBlockStream::createIndexedStream(StreamDBI, File);
45 if (!DbiS)
46 return DbiS.takeError();
47 auto DS = std::move(*DbiS);
48 DbiStream::HeaderInfo *H =
49 static_cast<DbiStream::HeaderInfo *>(DS->getAllocator().Allocate(
50 sizeof(DbiStream::HeaderInfo),
51 llvm::AlignOf<DbiStream::HeaderInfo>::Alignment));
52 H->VersionHeader = *VerHeader;
53 H->VersionSignature = -1;
54 H->Age = Age;
55 H->BuildNumber = BuildNumber;
56 H->Flags = Flags;
57 H->PdbDllRbld = PdbDllRbld;
58 H->PdbDllVersion = PdbDllVersion;
59 H->MachineType = static_cast<uint16_t>(MachineType);
60
61 H->ECSubstreamSize = 0;
62 H->FileInfoSize = 0;
63 H->ModiSubstreamSize = 0;
64 H->OptionalDbgHdrSize = 0;
65 H->SecContrSubstreamSize = 0;
66 H->SectionMapSize = 0;
67 H->TypeServerSize = 0;
68 H->SymRecordStreamIndex = DbiStream::InvalidStreamIndex;
69 H->PublicSymbolStreamIndex = DbiStream::InvalidStreamIndex;
70 H->MFCTypeServerIndex = DbiStream::InvalidStreamIndex;
71 H->GlobalSymbolStreamIndex = DbiStream::InvalidStreamIndex;
72
73 auto Dbi = llvm::make_unique<DbiStream>(File, std::move(DS));
74 Dbi->Header = H;
75 return std::move(Dbi);
76 }
77