Zachary Turner | dbeaea7 | 2016-07-11 21:45:26 +0000 | [diff] [blame] | 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 | |
Zachary Turner | faa554b | 2016-07-15 22:16:56 +0000 | [diff] [blame^] | 21 | DbiStreamBuilder::DbiStreamBuilder() |
| 22 | : Age(1), BuildNumber(0), PdbDllVersion(0), PdbDllRbld(0), Flags(0), |
| 23 | MachineType(PDB_Machine::x86) {} |
Zachary Turner | dbeaea7 | 2016-07-11 21:45:26 +0000 | [diff] [blame] | 24 | |
| 25 | void DbiStreamBuilder::setVersionHeader(PdbRaw_DbiVer V) { VerHeader = V; } |
| 26 | |
| 27 | void DbiStreamBuilder::setAge(uint32_t A) { Age = A; } |
| 28 | |
| 29 | void DbiStreamBuilder::setBuildNumber(uint16_t B) { BuildNumber = B; } |
| 30 | |
| 31 | void DbiStreamBuilder::setPdbDllVersion(uint16_t V) { PdbDllVersion = V; } |
| 32 | |
| 33 | void DbiStreamBuilder::setPdbDllRbld(uint16_t R) { PdbDllRbld = R; } |
| 34 | |
| 35 | void DbiStreamBuilder::setFlags(uint16_t F) { Flags = F; } |
| 36 | |
| 37 | void DbiStreamBuilder::setMachineType(PDB_Machine M) { MachineType = M; } |
| 38 | |
Zachary Turner | faa554b | 2016-07-15 22:16:56 +0000 | [diff] [blame^] | 39 | uint32_t DbiStreamBuilder::calculateSerializedLength() const { |
| 40 | // For now we only support serializing the header. |
| 41 | return sizeof(DbiStream::HeaderInfo); |
| 42 | } |
| 43 | |
| 44 | Expected<std::unique_ptr<DbiStream>> DbiStreamBuilder::build(PDBFile &File) { |
Zachary Turner | dbeaea7 | 2016-07-11 21:45:26 +0000 | [diff] [blame] | 45 | if (!VerHeader.hasValue()) |
| 46 | return make_error<RawError>(raw_error_code::unspecified, |
| 47 | "Missing DBI Stream Version"); |
| 48 | |
| 49 | auto DbiS = MappedBlockStream::createIndexedStream(StreamDBI, File); |
| 50 | if (!DbiS) |
| 51 | return DbiS.takeError(); |
| 52 | auto DS = std::move(*DbiS); |
| 53 | DbiStream::HeaderInfo *H = |
| 54 | static_cast<DbiStream::HeaderInfo *>(DS->getAllocator().Allocate( |
| 55 | sizeof(DbiStream::HeaderInfo), |
| 56 | llvm::AlignOf<DbiStream::HeaderInfo>::Alignment)); |
| 57 | H->VersionHeader = *VerHeader; |
| 58 | H->VersionSignature = -1; |
| 59 | H->Age = Age; |
| 60 | H->BuildNumber = BuildNumber; |
| 61 | H->Flags = Flags; |
| 62 | H->PdbDllRbld = PdbDllRbld; |
| 63 | H->PdbDllVersion = PdbDllVersion; |
| 64 | H->MachineType = static_cast<uint16_t>(MachineType); |
| 65 | |
| 66 | H->ECSubstreamSize = 0; |
| 67 | H->FileInfoSize = 0; |
| 68 | H->ModiSubstreamSize = 0; |
| 69 | H->OptionalDbgHdrSize = 0; |
| 70 | H->SecContrSubstreamSize = 0; |
| 71 | H->SectionMapSize = 0; |
| 72 | H->TypeServerSize = 0; |
| 73 | H->SymRecordStreamIndex = DbiStream::InvalidStreamIndex; |
| 74 | H->PublicSymbolStreamIndex = DbiStream::InvalidStreamIndex; |
| 75 | H->MFCTypeServerIndex = DbiStream::InvalidStreamIndex; |
| 76 | H->GlobalSymbolStreamIndex = DbiStream::InvalidStreamIndex; |
| 77 | |
| 78 | auto Dbi = llvm::make_unique<DbiStream>(File, std::move(DS)); |
| 79 | Dbi->Header = H; |
| 80 | return std::move(Dbi); |
| 81 | } |