1//===- ModuleDebugStream.h - PDB Module Info Stream 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
9#ifndef LLVM_DEBUGINFO_PDB_NATIVE_MODULEDEBUGSTREAM_H
10#define LLVM_DEBUGINFO_PDB_NATIVE_MODULEDEBUGSTREAM_H
11
12#include "llvm/ADT/iterator_range.h"
13#include "llvm/DebugInfo/CodeView/CVRecord.h"
14#include "llvm/DebugInfo/CodeView/DebugSubsectionRecord.h"
15#include "llvm/DebugInfo/PDB/Native/DbiModuleDescriptor.h"
16#include "llvm/Support/BinaryStreamRef.h"
17#include "llvm/Support/Error.h"
18#include <cstdint>
19#include <memory>
20
21namespace llvm {
22class BinaryStreamReader;
23namespace codeview {
24class DebugChecksumsSubsectionRef;
25}
26namespace msf {
27class MappedBlockStream;
28}
29namespace pdb {
30
31class ModuleDebugStreamRef {
32  using DebugSubsectionIterator = codeview::DebugSubsectionArray::Iterator;
33
34public:
35  ModuleDebugStreamRef(const DbiModuleDescriptor &Module,
36                       std::unique_ptr<msf::MappedBlockStream> Stream);
37  ModuleDebugStreamRef(ModuleDebugStreamRef &&Other) = default;
38  ModuleDebugStreamRef(const ModuleDebugStreamRef &Other) = default;
39  ~ModuleDebugStreamRef();
40
41  Error reload();
42
43  uint32_t signature() const { return Signature; }
44
45  iterator_range<codeview::CVSymbolArray::Iterator>
46  symbols(bool *HadError) const;
47
48  const codeview::CVSymbolArray &getSymbolArray() const { return SymbolArray; }
49  const codeview::CVSymbolArray
50  getSymbolArrayForScope(uint32_t ScopeBegin) const;
51
52  BinarySubstreamRef getSymbolsSubstream() const;
53  BinarySubstreamRef getC11LinesSubstream() const;
54  BinarySubstreamRef getC13LinesSubstream() const;
55  BinarySubstreamRef getGlobalRefsSubstream() const;
56
57  ModuleDebugStreamRef &operator=(ModuleDebugStreamRef &&Other) = delete;
58
59  codeview::CVSymbol readSymbolAtOffset(uint32_t Offset) const;
60
61  iterator_range<DebugSubsectionIterator> subsections() const;
62  codeview::DebugSubsectionArray getSubsectionsArray() const {
63    return Subsections;
64  }
65
66  bool hasDebugSubsections() const;
67
68  Error commit();
69
70  Expected<codeview::DebugChecksumsSubsectionRef>
71  findChecksumsSubsection() const;
72
73private:
74  Error reloadSerialize(BinaryStreamReader &Reader);
75
76  DbiModuleDescriptor Mod;
77
78  uint32_t Signature;
79
80  std::shared_ptr<msf::MappedBlockStream> Stream;
81
82  codeview::CVSymbolArray SymbolArray;
83
84  BinarySubstreamRef SymbolsSubstream;
85  BinarySubstreamRef C11LinesSubstream;
86  BinarySubstreamRef C13LinesSubstream;
87  BinarySubstreamRef GlobalRefsSubstream;
88
89  codeview::DebugSubsectionArray Subsections;
90};
91
92} // end namespace pdb
93} // end namespace llvm
94
95#endif // LLVM_DEBUGINFO_PDB_NATIVE_MODULEDEBUGSTREAM_H
96