Path: blob/main/contrib/llvm-project/llvm/lib/DebugInfo/PDB/Native/InfoStreamBuilder.cpp
35293 views
//===- InfoStreamBuilder.cpp - PDB Info Stream Creation ---------*- C++ -*-===//1//2// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.3// See https://llvm.org/LICENSE.txt for license information.4// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception5//6//===----------------------------------------------------------------------===//78#include "llvm/DebugInfo/PDB/Native/InfoStreamBuilder.h"910#include "llvm/DebugInfo/MSF/MSFBuilder.h"11#include "llvm/DebugInfo/MSF/MappedBlockStream.h"12#include "llvm/DebugInfo/PDB/Native/NamedStreamMap.h"13#include "llvm/DebugInfo/PDB/Native/RawTypes.h"14#include "llvm/Support/BinaryStreamReader.h"15#include "llvm/Support/BinaryStreamWriter.h"16#include "llvm/Support/TimeProfiler.h"1718using namespace llvm;19using namespace llvm::codeview;20using namespace llvm::msf;21using namespace llvm::pdb;2223InfoStreamBuilder::InfoStreamBuilder(msf::MSFBuilder &Msf,24NamedStreamMap &NamedStreams)25: Msf(Msf), Ver(PdbRaw_ImplVer::PdbImplVC70), Age(0),26NamedStreams(NamedStreams) {27::memset(&Guid, 0, sizeof(Guid));28}2930void InfoStreamBuilder::setVersion(PdbRaw_ImplVer V) { Ver = V; }3132void InfoStreamBuilder::addFeature(PdbRaw_FeatureSig Sig) {33Features.push_back(Sig);34}3536void InfoStreamBuilder::setHashPDBContentsToGUID(bool B) {37HashPDBContentsToGUID = B;38}3940void InfoStreamBuilder::setAge(uint32_t A) { Age = A; }4142void InfoStreamBuilder::setSignature(uint32_t S) { Signature = S; }4344void InfoStreamBuilder::setGuid(GUID G) { Guid = G; }454647Error InfoStreamBuilder::finalizeMsfLayout() {48uint32_t Length = sizeof(InfoStreamHeader) +49NamedStreams.calculateSerializedLength() +50(Features.size() + 1) * sizeof(uint32_t);51if (auto EC = Msf.setStreamSize(StreamPDB, Length))52return EC;53return Error::success();54}5556Error InfoStreamBuilder::commit(const msf::MSFLayout &Layout,57WritableBinaryStreamRef Buffer) const {58llvm::TimeTraceScope timeScope("Commit info stream");59auto InfoS = WritableMappedBlockStream::createIndexedStream(60Layout, Buffer, StreamPDB, Msf.getAllocator());61BinaryStreamWriter Writer(*InfoS);6263InfoStreamHeader H;64// Leave the build id fields 0 so they can be set as the last step before65// committing the file to disk.66::memset(&H, 0, sizeof(H));67H.Version = Ver;68if (auto EC = Writer.writeObject(H))69return EC;7071if (auto EC = NamedStreams.commit(Writer))72return EC;73if (auto EC = Writer.writeInteger(0))74return EC;75for (auto E : Features) {76if (auto EC = Writer.writeEnum(E))77return EC;78}79assert(Writer.bytesRemaining() == 0);80return Error::success();81}828384