1 //===- InfoStream.cpp - PDB Info Stream (Stream 1) Access -------*- 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/InfoStream.h" 11 #include "llvm/ADT/BitVector.h" 12 #include "llvm/ADT/SmallVector.h" 13 #include "llvm/DebugInfo/CodeView/StreamReader.h" 14 #include "llvm/DebugInfo/CodeView/StreamWriter.h" 15 #include "llvm/DebugInfo/PDB/Raw/IndexedStreamData.h" 16 #include "llvm/DebugInfo/PDB/Raw/PDBFile.h" 17 #include "llvm/DebugInfo/PDB/Raw/RawConstants.h" 18 #include "llvm/DebugInfo/PDB/Raw/RawError.h" 19 20 using namespace llvm; 21 using namespace llvm::codeview; 22 using namespace llvm::pdb; 23 InfoStream(std::unique_ptr<MappedBlockStream> Stream)24InfoStream::InfoStream(std::unique_ptr<MappedBlockStream> Stream) 25 : Stream(std::move(Stream)) {} 26 reload()27Error InfoStream::reload() { 28 codeview::StreamReader Reader(*Stream); 29 30 const Header *H; 31 if (auto EC = Reader.readObject(H)) 32 return joinErrors( 33 std::move(EC), 34 make_error<RawError>(raw_error_code::corrupt_file, 35 "PDB Stream does not contain a header.")); 36 37 switch (H->Version) { 38 case PdbImplVC70: 39 case PdbImplVC80: 40 case PdbImplVC110: 41 case PdbImplVC140: 42 break; 43 default: 44 return make_error<RawError>(raw_error_code::corrupt_file, 45 "Unsupported PDB stream version."); 46 } 47 48 Version = H->Version; 49 Signature = H->Signature; 50 Age = H->Age; 51 Guid = H->Guid; 52 53 return NamedStreams.load(Reader); 54 } 55 getNamedStreamIndex(llvm::StringRef Name) const56uint32_t InfoStream::getNamedStreamIndex(llvm::StringRef Name) const { 57 uint32_t Result; 58 if (!NamedStreams.tryGetValue(Name, Result)) 59 return 0; 60 return Result; 61 } 62 63 iterator_range<StringMapConstIterator<uint32_t>> named_streams() const64InfoStream::named_streams() const { 65 return NamedStreams.entries(); 66 } 67 getVersion() const68PdbRaw_ImplVer InfoStream::getVersion() const { 69 return static_cast<PdbRaw_ImplVer>(Version); 70 } 71 getSignature() const72uint32_t InfoStream::getSignature() const { return Signature; } 73 getAge() const74uint32_t InfoStream::getAge() const { return Age; } 75 getGuid() const76PDB_UniqueId InfoStream::getGuid() const { return Guid; } 77 commit()78Error InfoStream::commit() { 79 StreamWriter Writer(*Stream); 80 81 Header H; 82 H.Age = Age; 83 H.Signature = Signature; 84 H.Version = Version; 85 H.Guid = Guid; 86 if (auto EC = Writer.writeObject(H)) 87 return EC; 88 89 return NamedStreams.commit(Writer); 90 }