| Zachary Turner | 2f09b50 | 2016-04-29 17:28:47 +0000 | [diff] [blame] | 1 | //===- InfoStream.cpp - PDB Info Stream (Stream 1) Access -------*- C++ -*-===// | 
| Zachary Turner | f34e016 | 2016-04-26 16:20:00 +0000 | [diff] [blame] | 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 |  | 
| Adrian McCarthy | 6b6b8c4 | 2017-01-25 22:38:55 +0000 | [diff] [blame] | 10 | #include "llvm/DebugInfo/PDB/Native/InfoStream.h" | 
| Zachary Turner | f34e016 | 2016-04-26 16:20:00 +0000 | [diff] [blame] | 11 | #include "llvm/ADT/BitVector.h" | 
|  | 12 | #include "llvm/ADT/SmallVector.h" | 
| Adrian McCarthy | 6b6b8c4 | 2017-01-25 22:38:55 +0000 | [diff] [blame] | 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" | 
| Zachary Turner | d9dc282 | 2017-03-02 20:52:51 +0000 | [diff] [blame] | 17 | #include "llvm/Support/BinaryStreamReader.h" | 
|  | 18 | #include "llvm/Support/BinaryStreamWriter.h" | 
| Zachary Turner | f34e016 | 2016-04-26 16:20:00 +0000 | [diff] [blame] | 19 |  | 
|  | 20 | using namespace llvm; | 
| Zachary Turner | 8848a7a | 2016-07-06 18:05:57 +0000 | [diff] [blame] | 21 | using namespace llvm::codeview; | 
| Zachary Turner | bac69d3 | 2016-07-22 19:56:05 +0000 | [diff] [blame] | 22 | using namespace llvm::msf; | 
| Zachary Turner | 2f09b50 | 2016-04-29 17:28:47 +0000 | [diff] [blame] | 23 | using namespace llvm::pdb; | 
| Zachary Turner | f34e016 | 2016-04-26 16:20:00 +0000 | [diff] [blame] | 24 |  | 
| Zachary Turner | a1657a9 | 2016-06-08 17:26:39 +0000 | [diff] [blame] | 25 | InfoStream::InfoStream(std::unique_ptr<MappedBlockStream> Stream) | 
|  | 26 | : Stream(std::move(Stream)) {} | 
| Zachary Turner | f34e016 | 2016-04-26 16:20:00 +0000 | [diff] [blame] | 27 |  | 
| Zachary Turner | 819e77d | 2016-05-06 20:51:57 +0000 | [diff] [blame] | 28 | Error InfoStream::reload() { | 
| Zachary Turner | 120faca | 2017-02-27 22:11:43 +0000 | [diff] [blame] | 29 | BinaryStreamReader Reader(*Stream); | 
| Zachary Turner | 6ba65de | 2016-04-29 17:22:58 +0000 | [diff] [blame] | 30 |  | 
| Zachary Turner | d66889c | 2016-07-28 19:12:28 +0000 | [diff] [blame] | 31 | const InfoStreamHeader *H; | 
| Zachary Turner | 8dbe362 | 2016-05-27 01:54:44 +0000 | [diff] [blame] | 32 | if (auto EC = Reader.readObject(H)) | 
| David Majnemer | 74b1fb0 | 2016-05-27 22:07:50 +0000 | [diff] [blame] | 33 | return joinErrors( | 
|  | 34 | std::move(EC), | 
|  | 35 | make_error<RawError>(raw_error_code::corrupt_file, | 
|  | 36 | "PDB Stream does not contain a header.")); | 
| Zachary Turner | b56d904 | 2016-05-02 18:09:21 +0000 | [diff] [blame] | 37 |  | 
| Zachary Turner | 8848a7a | 2016-07-06 18:05:57 +0000 | [diff] [blame] | 38 | switch (H->Version) { | 
|  | 39 | case PdbImplVC70: | 
|  | 40 | case PdbImplVC80: | 
|  | 41 | case PdbImplVC110: | 
|  | 42 | case PdbImplVC140: | 
|  | 43 | break; | 
|  | 44 | default: | 
| Zachary Turner | 819e77d | 2016-05-06 20:51:57 +0000 | [diff] [blame] | 45 | return make_error<RawError>(raw_error_code::corrupt_file, | 
|  | 46 | "Unsupported PDB stream version."); | 
| Zachary Turner | 8848a7a | 2016-07-06 18:05:57 +0000 | [diff] [blame] | 47 | } | 
| Zachary Turner | f34e016 | 2016-04-26 16:20:00 +0000 | [diff] [blame] | 48 |  | 
| Zachary Turner | 8dbe362 | 2016-05-27 01:54:44 +0000 | [diff] [blame] | 49 | Version = H->Version; | 
|  | 50 | Signature = H->Signature; | 
|  | 51 | Age = H->Age; | 
|  | 52 | Guid = H->Guid; | 
| Zachary Turner | f34e016 | 2016-04-26 16:20:00 +0000 | [diff] [blame] | 53 |  | 
| Zachary Turner | 02278ce | 2017-03-16 20:18:41 +0000 | [diff] [blame] | 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; | 
| Zachary Turner | 05d5e61 | 2017-03-16 20:19:11 +0000 | [diff] [blame] | 59 |  | 
|  | 60 | bool Stop = false; | 
|  | 61 | while (!Stop && !Reader.empty()) { | 
|  | 62 | PdbRaw_FeatureSig Sig; | 
|  | 63 | if (auto EC = Reader.readEnum(Sig)) | 
|  | 64 | return EC; | 
| Zachary Turner | c950061 | 2017-03-16 20:45:11 +0000 | [diff] [blame] | 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): | 
| Zachary Turner | 05d5e61 | 2017-03-16 20:19:11 +0000 | [diff] [blame] | 71 | // No other flags for VC110 PDB. | 
|  | 72 | Stop = true; | 
|  | 73 | LLVM_FALLTHROUGH; | 
| Zachary Turner | c950061 | 2017-03-16 20:45:11 +0000 | [diff] [blame] | 74 | case uint32_t(PdbRaw_FeatureSig::VC140): | 
| Zachary Turner | 05d5e61 | 2017-03-16 20:19:11 +0000 | [diff] [blame] | 75 | Features |= PdbFeatureContainsIdStream; | 
|  | 76 | break; | 
| Zachary Turner | c950061 | 2017-03-16 20:45:11 +0000 | [diff] [blame] | 77 | case uint32_t(PdbRaw_FeatureSig::NoTypeMerge): | 
| Zachary Turner | 05d5e61 | 2017-03-16 20:19:11 +0000 | [diff] [blame] | 78 | Features |= PdbFeatureNoTypeMerging; | 
|  | 79 | break; | 
| Zachary Turner | c950061 | 2017-03-16 20:45:11 +0000 | [diff] [blame] | 80 | case uint32_t(PdbRaw_FeatureSig::MinimalDebugInfo): | 
| Zachary Turner | 05d5e61 | 2017-03-16 20:19:11 +0000 | [diff] [blame] | 81 | Features |= PdbFeatureMinimalDebugInfo; | 
| Galina Kistanova | 8c1e2f9 | 2017-05-30 19:02:49 +0000 | [diff] [blame] | 82 | break; | 
| Zachary Turner | 05d5e61 | 2017-03-16 20:19:11 +0000 | [diff] [blame] | 83 | default: | 
|  | 84 | continue; | 
|  | 85 | } | 
|  | 86 | FeatureSignatures.push_back(Sig); | 
|  | 87 | } | 
| Zachary Turner | 02278ce | 2017-03-16 20:18:41 +0000 | [diff] [blame] | 88 | return Error::success(); | 
| Zachary Turner | f34e016 | 2016-04-26 16:20:00 +0000 | [diff] [blame] | 89 | } | 
|  | 90 |  | 
| Zachary Turner | 02278ce | 2017-03-16 20:18:41 +0000 | [diff] [blame] | 91 | uint32_t InfoStream::getStreamSize() const { return Stream->getLength(); } | 
|  | 92 |  | 
| Zachary Turner | 2f09b50 | 2016-04-29 17:28:47 +0000 | [diff] [blame] | 93 | uint32_t InfoStream::getNamedStreamIndex(llvm::StringRef Name) const { | 
| Zachary Turner | f34e016 | 2016-04-26 16:20:00 +0000 | [diff] [blame] | 94 | uint32_t Result; | 
| Zachary Turner | 60667ca | 2017-01-20 22:41:40 +0000 | [diff] [blame] | 95 | if (!NamedStreams.get(Name, Result)) | 
| Zachary Turner | f34e016 | 2016-04-26 16:20:00 +0000 | [diff] [blame] | 96 | return 0; | 
|  | 97 | return Result; | 
|  | 98 | } | 
|  | 99 |  | 
| Zachary Turner | 85ed80b | 2016-05-25 03:43:17 +0000 | [diff] [blame] | 100 | iterator_range<StringMapConstIterator<uint32_t>> | 
|  | 101 | InfoStream::named_streams() const { | 
|  | 102 | return NamedStreams.entries(); | 
|  | 103 | } | 
|  | 104 |  | 
| Zachary Turner | 2f09b50 | 2016-04-29 17:28:47 +0000 | [diff] [blame] | 105 | PdbRaw_ImplVer InfoStream::getVersion() const { | 
| Zachary Turner | f34e016 | 2016-04-26 16:20:00 +0000 | [diff] [blame] | 106 | return static_cast<PdbRaw_ImplVer>(Version); | 
|  | 107 | } | 
|  | 108 |  | 
| Zachary Turner | 2f09b50 | 2016-04-29 17:28:47 +0000 | [diff] [blame] | 109 | uint32_t InfoStream::getSignature() const { return Signature; } | 
| Zachary Turner | f34e016 | 2016-04-26 16:20:00 +0000 | [diff] [blame] | 110 |  | 
| Zachary Turner | 2f09b50 | 2016-04-29 17:28:47 +0000 | [diff] [blame] | 111 | uint32_t InfoStream::getAge() const { return Age; } | 
| Zachary Turner | f34e016 | 2016-04-26 16:20:00 +0000 | [diff] [blame] | 112 |  | 
| Zachary Turner | 2f09b50 | 2016-04-29 17:28:47 +0000 | [diff] [blame] | 113 | PDB_UniqueId InfoStream::getGuid() const { return Guid; } | 
| Zachary Turner | 760ad4d | 2017-01-20 22:42:09 +0000 | [diff] [blame] | 114 |  | 
| Zachary Turner | 02278ce | 2017-03-16 20:18:41 +0000 | [diff] [blame] | 115 | uint32_t InfoStream::getNamedStreamMapByteSize() const { | 
|  | 116 | return NamedStreamMapByteSize; | 
|  | 117 | } | 
|  | 118 |  | 
| Zachary Turner | 05d5e61 | 2017-03-16 20:19:11 +0000 | [diff] [blame] | 119 | PdbRaw_Features InfoStream::getFeatures() const { return Features; } | 
|  | 120 |  | 
|  | 121 | ArrayRef<PdbRaw_FeatureSig> InfoStream::getFeatureSignatures() const { | 
|  | 122 | return FeatureSignatures; | 
|  | 123 | } | 
|  | 124 |  | 
| Zachary Turner | 760ad4d | 2017-01-20 22:42:09 +0000 | [diff] [blame] | 125 | const NamedStreamMap &InfoStream::getNamedStreams() const { | 
|  | 126 | return NamedStreams; | 
|  | 127 | } |