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