1*0b57cec5SDimitry Andric //===- InjectedSourceStream.cpp - PDB Headerblock Stream Access -----------===// 2*0b57cec5SDimitry Andric // 3*0b57cec5SDimitry Andric // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. 4*0b57cec5SDimitry Andric // See https://llvm.org/LICENSE.txt for license information. 5*0b57cec5SDimitry Andric // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception 6*0b57cec5SDimitry Andric // 7*0b57cec5SDimitry Andric //===----------------------------------------------------------------------===// 8*0b57cec5SDimitry Andric 9*0b57cec5SDimitry Andric #include "llvm/DebugInfo/PDB/Native/InjectedSourceStream.h" 10*0b57cec5SDimitry Andric 11*0b57cec5SDimitry Andric #include "llvm/DebugInfo/MSF/MappedBlockStream.h" 12*0b57cec5SDimitry Andric #include "llvm/DebugInfo/PDB/Native/Hash.h" 13*0b57cec5SDimitry Andric #include "llvm/DebugInfo/PDB/Native/PDBStringTable.h" 14*0b57cec5SDimitry Andric #include "llvm/DebugInfo/PDB/Native/RawConstants.h" 15*0b57cec5SDimitry Andric #include "llvm/DebugInfo/PDB/Native/RawTypes.h" 16*0b57cec5SDimitry Andric #include "llvm/Support/BinaryStreamReader.h" 17*0b57cec5SDimitry Andric #include "llvm/Support/Endian.h" 18*0b57cec5SDimitry Andric 19*0b57cec5SDimitry Andric using namespace llvm; 20*0b57cec5SDimitry Andric using namespace llvm::msf; 21*0b57cec5SDimitry Andric using namespace llvm::support; 22*0b57cec5SDimitry Andric using namespace llvm::pdb; 23*0b57cec5SDimitry Andric InjectedSourceStream(std::unique_ptr<MappedBlockStream> Stream)24*0b57cec5SDimitry AndricInjectedSourceStream::InjectedSourceStream( 25*0b57cec5SDimitry Andric std::unique_ptr<MappedBlockStream> Stream) 26*0b57cec5SDimitry Andric : Stream(std::move(Stream)) {} 27*0b57cec5SDimitry Andric reload(const PDBStringTable & Strings)28*0b57cec5SDimitry AndricError InjectedSourceStream::reload(const PDBStringTable &Strings) { 29*0b57cec5SDimitry Andric BinaryStreamReader Reader(*Stream); 30*0b57cec5SDimitry Andric 31*0b57cec5SDimitry Andric if (auto EC = Reader.readObject(Header)) 32*0b57cec5SDimitry Andric return EC; 33*0b57cec5SDimitry Andric 34*0b57cec5SDimitry Andric if (Header->Version != 35*0b57cec5SDimitry Andric static_cast<uint32_t>(PdbRaw_SrcHeaderBlockVer::SrcVerOne)) 36*0b57cec5SDimitry Andric return make_error<RawError>(raw_error_code::corrupt_file, 37*0b57cec5SDimitry Andric "Invalid headerblock header version"); 38*0b57cec5SDimitry Andric 39*0b57cec5SDimitry Andric if (auto EC = InjectedSourceTable.load(Reader)) 40*0b57cec5SDimitry Andric return EC; 41*0b57cec5SDimitry Andric 42*0b57cec5SDimitry Andric for (const auto& Entry : *this) { 43*0b57cec5SDimitry Andric if (Entry.second.Size != sizeof(SrcHeaderBlockEntry)) 44*0b57cec5SDimitry Andric return make_error<RawError>(raw_error_code::corrupt_file, 45*0b57cec5SDimitry Andric "Invalid headerbock entry size"); 46*0b57cec5SDimitry Andric if (Entry.second.Version != 47*0b57cec5SDimitry Andric static_cast<uint32_t>(PdbRaw_SrcHeaderBlockVer::SrcVerOne)) 48*0b57cec5SDimitry Andric return make_error<RawError>(raw_error_code::corrupt_file, 49*0b57cec5SDimitry Andric "Invalid headerbock entry version"); 50*0b57cec5SDimitry Andric 51*0b57cec5SDimitry Andric // Check that all name references are valid. 52*0b57cec5SDimitry Andric auto Name = Strings.getStringForID(Entry.second.FileNI); 53*0b57cec5SDimitry Andric if (!Name) 54*0b57cec5SDimitry Andric return Name.takeError(); 55*0b57cec5SDimitry Andric auto ObjName = Strings.getStringForID(Entry.second.ObjNI); 56*0b57cec5SDimitry Andric if (!ObjName) 57*0b57cec5SDimitry Andric return ObjName.takeError(); 58*0b57cec5SDimitry Andric auto VName = Strings.getStringForID(Entry.second.VFileNI); 59*0b57cec5SDimitry Andric if (!VName) 60*0b57cec5SDimitry Andric return VName.takeError(); 61*0b57cec5SDimitry Andric } 62*0b57cec5SDimitry Andric 63*0b57cec5SDimitry Andric assert(Reader.bytesRemaining() == 0); 64*0b57cec5SDimitry Andric return Error::success(); 65*0b57cec5SDimitry Andric } 66