InfoStream.cpp 3.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129
  1. //===- InfoStream.cpp - PDB Info Stream (Stream 1) Access -------*- C++ -*-===//
  2. //
  3. // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
  4. // See https://llvm.org/LICENSE.txt for license information.
  5. // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
  6. //
  7. //===----------------------------------------------------------------------===//
  8. #include "llvm/DebugInfo/PDB/Native/InfoStream.h"
  9. #include "llvm/DebugInfo/PDB/Native/RawConstants.h"
  10. #include "llvm/DebugInfo/PDB/Native/RawError.h"
  11. #include "llvm/DebugInfo/PDB/Native/RawTypes.h"
  12. #include "llvm/Support/BinaryStreamReader.h"
  13. using namespace llvm;
  14. using namespace llvm::codeview;
  15. // using namespace llvm::msf;
  16. using namespace llvm::pdb;
  17. InfoStream::InfoStream(std::unique_ptr<BinaryStream> Stream)
  18. : Stream(std::move(Stream)), Header(nullptr) {}
  19. Error InfoStream::reload() {
  20. BinaryStreamReader Reader(*Stream);
  21. if (auto EC = Reader.readObject(Header))
  22. return joinErrors(
  23. std::move(EC),
  24. make_error<RawError>(raw_error_code::corrupt_file,
  25. "PDB Stream does not contain a header."));
  26. switch (Header->Version) {
  27. case PdbImplVC70:
  28. case PdbImplVC80:
  29. case PdbImplVC110:
  30. case PdbImplVC140:
  31. break;
  32. default:
  33. return make_error<RawError>(raw_error_code::corrupt_file,
  34. "Unsupported PDB stream version.");
  35. }
  36. uint32_t Offset = Reader.getOffset();
  37. if (auto EC = NamedStreams.load(Reader))
  38. return EC;
  39. uint32_t NewOffset = Reader.getOffset();
  40. NamedStreamMapByteSize = NewOffset - Offset;
  41. Reader.setOffset(Offset);
  42. if (auto EC = Reader.readSubstream(SubNamedStreams, NamedStreamMapByteSize))
  43. return EC;
  44. bool Stop = false;
  45. while (!Stop && !Reader.empty()) {
  46. PdbRaw_FeatureSig Sig;
  47. if (auto EC = Reader.readEnum(Sig))
  48. return EC;
  49. // Since this value comes from a file, it's possible we have some strange
  50. // value which doesn't correspond to any value. We don't want to warn on
  51. // -Wcovered-switch-default in this case, so switch on the integral value
  52. // instead of the enumeration value.
  53. switch (uint32_t(Sig)) {
  54. case uint32_t(PdbRaw_FeatureSig::VC110):
  55. // No other flags for VC110 PDB.
  56. Stop = true;
  57. [[fallthrough]];
  58. case uint32_t(PdbRaw_FeatureSig::VC140):
  59. Features |= PdbFeatureContainsIdStream;
  60. break;
  61. case uint32_t(PdbRaw_FeatureSig::NoTypeMerge):
  62. Features |= PdbFeatureNoTypeMerging;
  63. break;
  64. case uint32_t(PdbRaw_FeatureSig::MinimalDebugInfo):
  65. Features |= PdbFeatureMinimalDebugInfo;
  66. break;
  67. default:
  68. continue;
  69. }
  70. FeatureSignatures.push_back(Sig);
  71. }
  72. return Error::success();
  73. }
  74. uint32_t InfoStream::getStreamSize() const { return Stream->getLength(); }
  75. Expected<uint32_t> InfoStream::getNamedStreamIndex(llvm::StringRef Name) const {
  76. uint32_t Result;
  77. if (!NamedStreams.get(Name, Result))
  78. return make_error<RawError>(raw_error_code::no_stream);
  79. return Result;
  80. }
  81. StringMap<uint32_t> InfoStream::named_streams() const {
  82. return NamedStreams.entries();
  83. }
  84. bool InfoStream::containsIdStream() const {
  85. return !!(Features & PdbFeatureContainsIdStream);
  86. }
  87. PdbRaw_ImplVer InfoStream::getVersion() const {
  88. return static_cast<PdbRaw_ImplVer>(uint32_t(Header->Version));
  89. }
  90. uint32_t InfoStream::getSignature() const {
  91. return uint32_t(Header->Signature);
  92. }
  93. uint32_t InfoStream::getAge() const { return uint32_t(Header->Age); }
  94. GUID InfoStream::getGuid() const { return Header->Guid; }
  95. uint32_t InfoStream::getNamedStreamMapByteSize() const {
  96. return NamedStreamMapByteSize;
  97. }
  98. PdbRaw_Features InfoStream::getFeatures() const { return Features; }
  99. ArrayRef<PdbRaw_FeatureSig> InfoStream::getFeatureSignatures() const {
  100. return FeatureSignatures;
  101. }
  102. const NamedStreamMap &InfoStream::getNamedStreams() const {
  103. return NamedStreams;
  104. }
  105. BinarySubstreamRef InfoStream::getNamedStreamsBuffer() const {
  106. return SubNamedStreams;
  107. }