Line data Source code
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/MSF/StreamReader.h"
14 : #include "llvm/DebugInfo/MSF/StreamWriter.h"
15 : #include "llvm/DebugInfo/PDB/Raw/PDBFile.h"
16 : #include "llvm/DebugInfo/PDB/Raw/RawConstants.h"
17 : #include "llvm/DebugInfo/PDB/Raw/RawError.h"
18 : #include "llvm/DebugInfo/PDB/Raw/RawTypes.h"
19 :
20 : using namespace llvm;
21 : using namespace llvm::codeview;
22 : using namespace llvm::msf;
23 : using namespace llvm::pdb;
24 :
25 15 : InfoStream::InfoStream(std::unique_ptr<MappedBlockStream> Stream)
26 30 : : Stream(std::move(Stream)) {}
27 :
28 15 : Error InfoStream::reload() {
29 45 : StreamReader Reader(*Stream);
30 :
31 : const InfoStreamHeader *H;
32 45 : if (auto EC = Reader.readObject(H))
33 : return joinErrors(
34 0 : std::move(EC),
35 0 : make_error<RawError>(raw_error_code::corrupt_file,
36 0 : "PDB Stream does not contain a header."));
37 :
38 30 : switch (H->Version) {
39 : case PdbImplVC70:
40 : case PdbImplVC80:
41 : case PdbImplVC110:
42 : case PdbImplVC140:
43 : break;
44 : default:
45 : return make_error<RawError>(raw_error_code::corrupt_file,
46 0 : "Unsupported PDB stream version.");
47 : }
48 :
49 30 : Version = H->Version;
50 30 : Signature = H->Signature;
51 30 : Age = H->Age;
52 15 : Guid = H->Guid;
53 :
54 15 : return NamedStreams.load(Reader);
55 : }
56 :
57 6 : uint32_t InfoStream::getNamedStreamIndex(llvm::StringRef Name) const {
58 : uint32_t Result;
59 6 : if (!NamedStreams.get(Name, Result))
60 : return 0;
61 6 : return Result;
62 : }
63 :
64 : iterator_range<StringMapConstIterator<uint32_t>>
65 4 : InfoStream::named_streams() const {
66 4 : return NamedStreams.entries();
67 : }
68 :
69 12 : PdbRaw_ImplVer InfoStream::getVersion() const {
70 12 : return static_cast<PdbRaw_ImplVer>(Version);
71 : }
72 :
73 12 : uint32_t InfoStream::getSignature() const { return Signature; }
74 :
75 22 : uint32_t InfoStream::getAge() const { return Age; }
76 :
77 12 : PDB_UniqueId InfoStream::getGuid() const { return Guid; }
78 :
79 5 : const NamedStreamMap &InfoStream::getNamedStreams() const {
80 5 : return NamedStreams;
81 : }
|