10b57cec5SDimitry Andric //===- ModuleDebugStream.h - PDB Module Info Stream Access ------*- C++ -*-===//
20b57cec5SDimitry Andric //
30b57cec5SDimitry Andric // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
40b57cec5SDimitry Andric // See https://llvm.org/LICENSE.txt for license information.
50b57cec5SDimitry Andric // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
60b57cec5SDimitry Andric //
70b57cec5SDimitry Andric //===----------------------------------------------------------------------===//
80b57cec5SDimitry Andric 
90b57cec5SDimitry Andric #ifndef LLVM_DEBUGINFO_PDB_NATIVE_MODULEDEBUGSTREAM_H
100b57cec5SDimitry Andric #define LLVM_DEBUGINFO_PDB_NATIVE_MODULEDEBUGSTREAM_H
110b57cec5SDimitry Andric 
120b57cec5SDimitry Andric #include "llvm/ADT/iterator_range.h"
1381ad6265SDimitry Andric #include "llvm/DebugInfo/CodeView/CVRecord.h"
140b57cec5SDimitry Andric #include "llvm/DebugInfo/CodeView/DebugSubsectionRecord.h"
150b57cec5SDimitry Andric #include "llvm/DebugInfo/PDB/Native/DbiModuleDescriptor.h"
160b57cec5SDimitry Andric #include "llvm/Support/BinaryStreamRef.h"
170b57cec5SDimitry Andric #include "llvm/Support/Error.h"
180b57cec5SDimitry Andric #include <cstdint>
190b57cec5SDimitry Andric #include <memory>
200b57cec5SDimitry Andric 
210b57cec5SDimitry Andric namespace llvm {
2281ad6265SDimitry Andric class BinaryStreamReader;
2381ad6265SDimitry Andric namespace codeview {
2481ad6265SDimitry Andric class DebugChecksumsSubsectionRef;
2581ad6265SDimitry Andric }
2681ad6265SDimitry Andric namespace msf {
2781ad6265SDimitry Andric class MappedBlockStream;
2881ad6265SDimitry Andric }
290b57cec5SDimitry Andric namespace pdb {
300b57cec5SDimitry Andric 
310b57cec5SDimitry Andric class ModuleDebugStreamRef {
320b57cec5SDimitry Andric   using DebugSubsectionIterator = codeview::DebugSubsectionArray::Iterator;
330b57cec5SDimitry Andric 
340b57cec5SDimitry Andric public:
350b57cec5SDimitry Andric   ModuleDebugStreamRef(const DbiModuleDescriptor &Module,
360b57cec5SDimitry Andric                        std::unique_ptr<msf::MappedBlockStream> Stream);
370b57cec5SDimitry Andric   ModuleDebugStreamRef(ModuleDebugStreamRef &&Other) = default;
380b57cec5SDimitry Andric   ModuleDebugStreamRef(const ModuleDebugStreamRef &Other) = default;
390b57cec5SDimitry Andric   ~ModuleDebugStreamRef();
400b57cec5SDimitry Andric 
410b57cec5SDimitry Andric   Error reload();
420b57cec5SDimitry Andric 
signature()430b57cec5SDimitry Andric   uint32_t signature() const { return Signature; }
440b57cec5SDimitry Andric 
450b57cec5SDimitry Andric   iterator_range<codeview::CVSymbolArray::Iterator>
460b57cec5SDimitry Andric   symbols(bool *HadError) const;
470b57cec5SDimitry Andric 
getSymbolArray()480b57cec5SDimitry Andric   const codeview::CVSymbolArray &getSymbolArray() const { return SymbolArray; }
490b57cec5SDimitry Andric   const codeview::CVSymbolArray
500b57cec5SDimitry Andric   getSymbolArrayForScope(uint32_t ScopeBegin) const;
510b57cec5SDimitry Andric 
520b57cec5SDimitry Andric   BinarySubstreamRef getSymbolsSubstream() const;
530b57cec5SDimitry Andric   BinarySubstreamRef getC11LinesSubstream() const;
540b57cec5SDimitry Andric   BinarySubstreamRef getC13LinesSubstream() const;
550b57cec5SDimitry Andric   BinarySubstreamRef getGlobalRefsSubstream() const;
560b57cec5SDimitry Andric 
570b57cec5SDimitry Andric   ModuleDebugStreamRef &operator=(ModuleDebugStreamRef &&Other) = delete;
580b57cec5SDimitry Andric 
590b57cec5SDimitry Andric   codeview::CVSymbol readSymbolAtOffset(uint32_t Offset) const;
600b57cec5SDimitry Andric 
610b57cec5SDimitry Andric   iterator_range<DebugSubsectionIterator> subsections() const;
getSubsectionsArray()620b57cec5SDimitry Andric   codeview::DebugSubsectionArray getSubsectionsArray() const {
630b57cec5SDimitry Andric     return Subsections;
640b57cec5SDimitry Andric   }
650b57cec5SDimitry Andric 
660b57cec5SDimitry Andric   bool hasDebugSubsections() const;
670b57cec5SDimitry Andric 
680b57cec5SDimitry Andric   Error commit();
690b57cec5SDimitry Andric 
700b57cec5SDimitry Andric   Expected<codeview::DebugChecksumsSubsectionRef>
710b57cec5SDimitry Andric   findChecksumsSubsection() const;
720b57cec5SDimitry Andric 
730b57cec5SDimitry Andric private:
740b57cec5SDimitry Andric   Error reloadSerialize(BinaryStreamReader &Reader);
750b57cec5SDimitry Andric 
760b57cec5SDimitry Andric   DbiModuleDescriptor Mod;
770b57cec5SDimitry Andric 
780b57cec5SDimitry Andric   uint32_t Signature;
790b57cec5SDimitry Andric 
800b57cec5SDimitry Andric   std::shared_ptr<msf::MappedBlockStream> Stream;
810b57cec5SDimitry Andric 
820b57cec5SDimitry Andric   codeview::CVSymbolArray SymbolArray;
830b57cec5SDimitry Andric 
840b57cec5SDimitry Andric   BinarySubstreamRef SymbolsSubstream;
850b57cec5SDimitry Andric   BinarySubstreamRef C11LinesSubstream;
860b57cec5SDimitry Andric   BinarySubstreamRef C13LinesSubstream;
870b57cec5SDimitry Andric   BinarySubstreamRef GlobalRefsSubstream;
880b57cec5SDimitry Andric 
890b57cec5SDimitry Andric   codeview::DebugSubsectionArray Subsections;
900b57cec5SDimitry Andric };
910b57cec5SDimitry Andric 
920b57cec5SDimitry Andric } // end namespace pdb
930b57cec5SDimitry Andric } // end namespace llvm
940b57cec5SDimitry Andric 
950b57cec5SDimitry Andric #endif // LLVM_DEBUGINFO_PDB_NATIVE_MODULEDEBUGSTREAM_H
96