1 //===- ModuleDebugStream.cpp - PDB Module Info Stream Access --------------===//
3 // The LLVM Compiler Infrastructure
5 // This file is distributed under the University of Illinois Open Source
6 // License. See LICENSE.TXT for details.
8 //===----------------------------------------------------------------------===//
10 #include "llvm/DebugInfo/PDB/Native/ModuleDebugStream.h"
11 #include "llvm/ADT/iterator_range.h"
12 #include "llvm/DebugInfo/CodeView/SymbolRecord.h"
13 #include "llvm/DebugInfo/PDB/Native/DbiModuleDescriptor.h"
14 #include "llvm/DebugInfo/PDB/Native/PDBFile.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/BinaryStreamRef.h"
19 #include "llvm/Support/Error.h"
24 using namespace llvm::codeview;
25 using namespace llvm::msf;
26 using namespace llvm::pdb;
28 ModuleDebugStreamRef::ModuleDebugStreamRef(
29 const DbiModuleDescriptor &Module,
30 std::unique_ptr<MappedBlockStream> Stream)
31 : Mod(Module), Stream(std::move(Stream)) {}
33 ModuleDebugStreamRef::~ModuleDebugStreamRef() = default;
35 Error ModuleDebugStreamRef::reload() {
36 BinaryStreamReader Reader(*Stream);
38 uint32_t SymbolSize = Mod.getSymbolDebugInfoByteSize();
39 uint32_t C11Size = Mod.getC11LineInfoByteSize();
40 uint32_t C13Size = Mod.getC13LineInfoByteSize();
42 if (C11Size > 0 && C13Size > 0)
43 return make_error<RawError>(raw_error_code::corrupt_file,
44 "Module has both C11 and C13 line info");
48 if (auto EC = Reader.readInteger(Signature))
50 if (auto EC = Reader.readArray(SymbolsSubstream, SymbolSize - 4))
53 if (auto EC = Reader.readStreamRef(C11LinesSubstream, C11Size))
55 if (auto EC = Reader.readStreamRef(C13LinesSubstream, C13Size))
58 BinaryStreamReader SubsectionsReader(C13LinesSubstream);
59 if (auto EC = SubsectionsReader.readArray(Subsections,
60 SubsectionsReader.bytesRemaining()))
63 uint32_t GlobalRefsSize;
64 if (auto EC = Reader.readInteger(GlobalRefsSize))
66 if (auto EC = Reader.readStreamRef(GlobalRefsSubstream, GlobalRefsSize))
68 if (Reader.bytesRemaining() > 0)
69 return make_error<RawError>(raw_error_code::corrupt_file,
70 "Unexpected bytes in module stream.");
72 return Error::success();
75 iterator_range<codeview::CVSymbolArray::Iterator>
76 ModuleDebugStreamRef::symbols(bool *HadError) const {
77 return make_range(SymbolsSubstream.begin(HadError), SymbolsSubstream.end());
80 llvm::iterator_range<ModuleDebugStreamRef::DebugSubsectionIterator>
81 ModuleDebugStreamRef::subsections() const {
82 return make_range(Subsections.begin(), Subsections.end());
85 bool ModuleDebugStreamRef::hasDebugSubsections() const {
86 return C13LinesSubstream.getLength() > 0;
89 Error ModuleDebugStreamRef::commit() { return Error::success(); }
91 Expected<codeview::DebugChecksumsSubsectionRef>
92 ModuleDebugStreamRef::findChecksumsSubsection() const {
93 for (const auto &SS : subsections()) {
94 if (SS.kind() != DebugSubsectionKind::FileChecksums)
97 codeview::DebugChecksumsSubsectionRef Result;
98 if (auto EC = Result.initialize(SS.getRecordData()))
102 return make_error<RawError>(raw_error_code::no_entry);