]> CyberLeo.Net >> Repos - FreeBSD/FreeBSD.git/blob - contrib/llvm/lib/DebugInfo/PDB/Native/InfoStream.cpp
Merge ^/head r319251 through r319479.
[FreeBSD/FreeBSD.git] / contrib / llvm / lib / DebugInfo / PDB / Native / InfoStream.cpp
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/Native/InfoStream.h"
11 #include "llvm/ADT/BitVector.h"
12 #include "llvm/ADT/SmallVector.h"
13 #include "llvm/DebugInfo/PDB/Native/PDBFile.h"
14 #include "llvm/DebugInfo/PDB/Native/RawConstants.h"
15 #include "llvm/DebugInfo/PDB/Native/RawError.h"
16 #include "llvm/DebugInfo/PDB/Native/RawTypes.h"
17 #include "llvm/Support/BinaryStreamReader.h"
18 #include "llvm/Support/BinaryStreamWriter.h"
19
20 using namespace llvm;
21 using namespace llvm::codeview;
22 using namespace llvm::msf;
23 using namespace llvm::pdb;
24
25 InfoStream::InfoStream(std::unique_ptr<MappedBlockStream> Stream)
26     : Stream(std::move(Stream)) {}
27
28 Error InfoStream::reload() {
29   BinaryStreamReader Reader(*Stream);
30
31   const InfoStreamHeader *H;
32   if (auto EC = Reader.readObject(H))
33     return joinErrors(
34         std::move(EC),
35         make_error<RawError>(raw_error_code::corrupt_file,
36                              "PDB Stream does not contain a header."));
37
38   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                                 "Unsupported PDB stream version.");
47   }
48
49   Version = H->Version;
50   Signature = H->Signature;
51   Age = H->Age;
52   Guid = H->Guid;
53
54   uint32_t Offset = Reader.getOffset();
55   if (auto EC = NamedStreams.load(Reader))
56     return EC;
57   uint32_t NewOffset = Reader.getOffset();
58   NamedStreamMapByteSize = NewOffset - Offset;
59
60   bool Stop = false;
61   while (!Stop && !Reader.empty()) {
62     PdbRaw_FeatureSig Sig;
63     if (auto EC = Reader.readEnum(Sig))
64       return EC;
65     // Since this value comes from a file, it's possible we have some strange
66     // value which doesn't correspond to any value.  We don't want to warn on
67     // -Wcovered-switch-default in this case, so switch on the integral value
68     // instead of the enumeration value.
69     switch (uint32_t(Sig)) {
70     case uint32_t(PdbRaw_FeatureSig::VC110):
71       // No other flags for VC110 PDB.
72       Stop = true;
73       LLVM_FALLTHROUGH;
74     case uint32_t(PdbRaw_FeatureSig::VC140):
75       Features |= PdbFeatureContainsIdStream;
76       break;
77     case uint32_t(PdbRaw_FeatureSig::NoTypeMerge):
78       Features |= PdbFeatureNoTypeMerging;
79       break;
80     case uint32_t(PdbRaw_FeatureSig::MinimalDebugInfo):
81       Features |= PdbFeatureMinimalDebugInfo;
82       break;
83     default:
84       continue;
85     }
86     FeatureSignatures.push_back(Sig);
87   }
88   return Error::success();
89 }
90
91 uint32_t InfoStream::getStreamSize() const { return Stream->getLength(); }
92
93 uint32_t InfoStream::getNamedStreamIndex(llvm::StringRef Name) const {
94   uint32_t Result;
95   if (!NamedStreams.get(Name, Result))
96     return 0;
97   return Result;
98 }
99
100 iterator_range<StringMapConstIterator<uint32_t>>
101 InfoStream::named_streams() const {
102   return NamedStreams.entries();
103 }
104
105 PdbRaw_ImplVer InfoStream::getVersion() const {
106   return static_cast<PdbRaw_ImplVer>(Version);
107 }
108
109 uint32_t InfoStream::getSignature() const { return Signature; }
110
111 uint32_t InfoStream::getAge() const { return Age; }
112
113 PDB_UniqueId InfoStream::getGuid() const { return Guid; }
114
115 uint32_t InfoStream::getNamedStreamMapByteSize() const {
116   return NamedStreamMapByteSize;
117 }
118
119 PdbRaw_Features InfoStream::getFeatures() const { return Features; }
120
121 ArrayRef<PdbRaw_FeatureSig> InfoStream::getFeatureSignatures() const {
122   return FeatureSignatures;
123 }
124
125 const NamedStreamMap &InfoStream::getNamedStreams() const {
126   return NamedStreams;
127 }