InjectedSourceStream.cpp 2.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465
  1. //===- InjectedSourceStream.cpp - PDB Headerblock Stream Access -----------===//
  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/InjectedSourceStream.h"
  9. #include "llvm/DebugInfo/MSF/MappedBlockStream.h"
  10. #include "llvm/DebugInfo/PDB/Native/HashTable.h"
  11. #include "llvm/DebugInfo/PDB/Native/PDBStringTable.h"
  12. #include "llvm/DebugInfo/PDB/Native/RawConstants.h"
  13. #include "llvm/DebugInfo/PDB/Native/RawTypes.h"
  14. #include "llvm/Support/BinaryStreamReader.h"
  15. #include "llvm/Support/Endian.h"
  16. using namespace llvm;
  17. using namespace llvm::msf;
  18. using namespace llvm::support;
  19. using namespace llvm::pdb;
  20. InjectedSourceStream::InjectedSourceStream(
  21. std::unique_ptr<MappedBlockStream> Stream)
  22. : Stream(std::move(Stream)) {}
  23. Error InjectedSourceStream::reload(const PDBStringTable &Strings) {
  24. BinaryStreamReader Reader(*Stream);
  25. if (auto EC = Reader.readObject(Header))
  26. return EC;
  27. if (Header->Version !=
  28. static_cast<uint32_t>(PdbRaw_SrcHeaderBlockVer::SrcVerOne))
  29. return make_error<RawError>(raw_error_code::corrupt_file,
  30. "Invalid headerblock header version");
  31. if (auto EC = InjectedSourceTable.load(Reader))
  32. return EC;
  33. for (const auto& Entry : *this) {
  34. if (Entry.second.Size != sizeof(SrcHeaderBlockEntry))
  35. return make_error<RawError>(raw_error_code::corrupt_file,
  36. "Invalid headerbock entry size");
  37. if (Entry.second.Version !=
  38. static_cast<uint32_t>(PdbRaw_SrcHeaderBlockVer::SrcVerOne))
  39. return make_error<RawError>(raw_error_code::corrupt_file,
  40. "Invalid headerbock entry version");
  41. // Check that all name references are valid.
  42. auto Name = Strings.getStringForID(Entry.second.FileNI);
  43. if (!Name)
  44. return Name.takeError();
  45. auto ObjName = Strings.getStringForID(Entry.second.ObjNI);
  46. if (!ObjName)
  47. return ObjName.takeError();
  48. auto VName = Strings.getStringForID(Entry.second.VFileNI);
  49. if (!VName)
  50. return VName.takeError();
  51. }
  52. assert(Reader.bytesRemaining() == 0);
  53. return Error::success();
  54. }