1*9880d681SAndroid Build Coastguard Worker //===- InfoStream.cpp - PDB Info Stream (Stream 1) Access -------*- C++ -*-===// 2*9880d681SAndroid Build Coastguard Worker // 3*9880d681SAndroid Build Coastguard Worker // The LLVM Compiler Infrastructure 4*9880d681SAndroid Build Coastguard Worker // 5*9880d681SAndroid Build Coastguard Worker // This file is distributed under the University of Illinois Open Source 6*9880d681SAndroid Build Coastguard Worker // License. See LICENSE.TXT for details. 7*9880d681SAndroid Build Coastguard Worker // 8*9880d681SAndroid Build Coastguard Worker //===----------------------------------------------------------------------===// 9*9880d681SAndroid Build Coastguard Worker 10*9880d681SAndroid Build Coastguard Worker #include "llvm/DebugInfo/PDB/Raw/InfoStream.h" 11*9880d681SAndroid Build Coastguard Worker #include "llvm/ADT/BitVector.h" 12*9880d681SAndroid Build Coastguard Worker #include "llvm/ADT/SmallVector.h" 13*9880d681SAndroid Build Coastguard Worker #include "llvm/DebugInfo/CodeView/StreamReader.h" 14*9880d681SAndroid Build Coastguard Worker #include "llvm/DebugInfo/CodeView/StreamWriter.h" 15*9880d681SAndroid Build Coastguard Worker #include "llvm/DebugInfo/PDB/Raw/IndexedStreamData.h" 16*9880d681SAndroid Build Coastguard Worker #include "llvm/DebugInfo/PDB/Raw/PDBFile.h" 17*9880d681SAndroid Build Coastguard Worker #include "llvm/DebugInfo/PDB/Raw/RawConstants.h" 18*9880d681SAndroid Build Coastguard Worker #include "llvm/DebugInfo/PDB/Raw/RawError.h" 19*9880d681SAndroid Build Coastguard Worker 20*9880d681SAndroid Build Coastguard Worker using namespace llvm; 21*9880d681SAndroid Build Coastguard Worker using namespace llvm::codeview; 22*9880d681SAndroid Build Coastguard Worker using namespace llvm::pdb; 23*9880d681SAndroid Build Coastguard Worker InfoStream(std::unique_ptr<MappedBlockStream> Stream)24*9880d681SAndroid Build Coastguard WorkerInfoStream::InfoStream(std::unique_ptr<MappedBlockStream> Stream) 25*9880d681SAndroid Build Coastguard Worker : Stream(std::move(Stream)) {} 26*9880d681SAndroid Build Coastguard Worker reload()27*9880d681SAndroid Build Coastguard WorkerError InfoStream::reload() { 28*9880d681SAndroid Build Coastguard Worker codeview::StreamReader Reader(*Stream); 29*9880d681SAndroid Build Coastguard Worker 30*9880d681SAndroid Build Coastguard Worker const Header *H; 31*9880d681SAndroid Build Coastguard Worker if (auto EC = Reader.readObject(H)) 32*9880d681SAndroid Build Coastguard Worker return joinErrors( 33*9880d681SAndroid Build Coastguard Worker std::move(EC), 34*9880d681SAndroid Build Coastguard Worker make_error<RawError>(raw_error_code::corrupt_file, 35*9880d681SAndroid Build Coastguard Worker "PDB Stream does not contain a header.")); 36*9880d681SAndroid Build Coastguard Worker 37*9880d681SAndroid Build Coastguard Worker switch (H->Version) { 38*9880d681SAndroid Build Coastguard Worker case PdbImplVC70: 39*9880d681SAndroid Build Coastguard Worker case PdbImplVC80: 40*9880d681SAndroid Build Coastguard Worker case PdbImplVC110: 41*9880d681SAndroid Build Coastguard Worker case PdbImplVC140: 42*9880d681SAndroid Build Coastguard Worker break; 43*9880d681SAndroid Build Coastguard Worker default: 44*9880d681SAndroid Build Coastguard Worker return make_error<RawError>(raw_error_code::corrupt_file, 45*9880d681SAndroid Build Coastguard Worker "Unsupported PDB stream version."); 46*9880d681SAndroid Build Coastguard Worker } 47*9880d681SAndroid Build Coastguard Worker 48*9880d681SAndroid Build Coastguard Worker Version = H->Version; 49*9880d681SAndroid Build Coastguard Worker Signature = H->Signature; 50*9880d681SAndroid Build Coastguard Worker Age = H->Age; 51*9880d681SAndroid Build Coastguard Worker Guid = H->Guid; 52*9880d681SAndroid Build Coastguard Worker 53*9880d681SAndroid Build Coastguard Worker return NamedStreams.load(Reader); 54*9880d681SAndroid Build Coastguard Worker } 55*9880d681SAndroid Build Coastguard Worker getNamedStreamIndex(llvm::StringRef Name) const56*9880d681SAndroid Build Coastguard Workeruint32_t InfoStream::getNamedStreamIndex(llvm::StringRef Name) const { 57*9880d681SAndroid Build Coastguard Worker uint32_t Result; 58*9880d681SAndroid Build Coastguard Worker if (!NamedStreams.tryGetValue(Name, Result)) 59*9880d681SAndroid Build Coastguard Worker return 0; 60*9880d681SAndroid Build Coastguard Worker return Result; 61*9880d681SAndroid Build Coastguard Worker } 62*9880d681SAndroid Build Coastguard Worker 63*9880d681SAndroid Build Coastguard Worker iterator_range<StringMapConstIterator<uint32_t>> named_streams() const64*9880d681SAndroid Build Coastguard WorkerInfoStream::named_streams() const { 65*9880d681SAndroid Build Coastguard Worker return NamedStreams.entries(); 66*9880d681SAndroid Build Coastguard Worker } 67*9880d681SAndroid Build Coastguard Worker getVersion() const68*9880d681SAndroid Build Coastguard WorkerPdbRaw_ImplVer InfoStream::getVersion() const { 69*9880d681SAndroid Build Coastguard Worker return static_cast<PdbRaw_ImplVer>(Version); 70*9880d681SAndroid Build Coastguard Worker } 71*9880d681SAndroid Build Coastguard Worker getSignature() const72*9880d681SAndroid Build Coastguard Workeruint32_t InfoStream::getSignature() const { return Signature; } 73*9880d681SAndroid Build Coastguard Worker getAge() const74*9880d681SAndroid Build Coastguard Workeruint32_t InfoStream::getAge() const { return Age; } 75*9880d681SAndroid Build Coastguard Worker getGuid() const76*9880d681SAndroid Build Coastguard WorkerPDB_UniqueId InfoStream::getGuid() const { return Guid; } 77*9880d681SAndroid Build Coastguard Worker commit()78*9880d681SAndroid Build Coastguard WorkerError InfoStream::commit() { 79*9880d681SAndroid Build Coastguard Worker StreamWriter Writer(*Stream); 80*9880d681SAndroid Build Coastguard Worker 81*9880d681SAndroid Build Coastguard Worker Header H; 82*9880d681SAndroid Build Coastguard Worker H.Age = Age; 83*9880d681SAndroid Build Coastguard Worker H.Signature = Signature; 84*9880d681SAndroid Build Coastguard Worker H.Version = Version; 85*9880d681SAndroid Build Coastguard Worker H.Guid = Guid; 86*9880d681SAndroid Build Coastguard Worker if (auto EC = Writer.writeObject(H)) 87*9880d681SAndroid Build Coastguard Worker return EC; 88*9880d681SAndroid Build Coastguard Worker 89*9880d681SAndroid Build Coastguard Worker return NamedStreams.commit(Writer); 90*9880d681SAndroid Build Coastguard Worker }