1317017Sdim//===- DbiStream.h - PDB Dbi Stream (Stream 3) Access -----------*- C++ -*-===//
2317017Sdim//
3353358Sdim// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4353358Sdim// See https://llvm.org/LICENSE.txt for license information.
5353358Sdim// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6317017Sdim//
7317017Sdim//===----------------------------------------------------------------------===//
8317017Sdim
9317017Sdim#ifndef LLVM_DEBUGINFO_PDB_RAW_PDBDBISTREAM_H
10317017Sdim#define LLVM_DEBUGINFO_PDB_RAW_PDBDBISTREAM_H
11317017Sdim
12319250Sdim#include "llvm/DebugInfo/CodeView/DebugSubsection.h"
13353358Sdim#include "llvm/DebugInfo/CodeView/DebugFrameDataSubsection.h"
14317017Sdim#include "llvm/DebugInfo/MSF/MappedBlockStream.h"
15317778Sdim#include "llvm/DebugInfo/PDB/Native/DbiModuleDescriptor.h"
16317969Sdim#include "llvm/DebugInfo/PDB/Native/DbiModuleList.h"
17317778Sdim#include "llvm/DebugInfo/PDB/Native/PDBStringTable.h"
18317017Sdim#include "llvm/DebugInfo/PDB/Native/RawConstants.h"
19317017Sdim#include "llvm/DebugInfo/PDB/Native/RawTypes.h"
20317017Sdim#include "llvm/DebugInfo/PDB/PDBTypes.h"
21317017Sdim#include "llvm/Support/BinaryStreamArray.h"
22317017Sdim#include "llvm/Support/BinaryStreamRef.h"
23317017Sdim#include "llvm/Support/Endian.h"
24317017Sdim#include "llvm/Support/Error.h"
25317017Sdim
26317017Sdimnamespace llvm {
27317017Sdimnamespace object {
28317017Sdimstruct FpoData;
29317017Sdimstruct coff_section;
30317017Sdim}
31317017Sdim
32317017Sdimnamespace pdb {
33317017Sdimclass DbiStreamBuilder;
34317017Sdimclass PDBFile;
35317017Sdimclass ISectionContribVisitor;
36317017Sdim
37317017Sdimclass DbiStream {
38317017Sdim  friend class DbiStreamBuilder;
39317017Sdim
40317017Sdimpublic:
41341825Sdim  explicit DbiStream(std::unique_ptr<BinaryStream> Stream);
42317017Sdim  ~DbiStream();
43341825Sdim  Error reload(PDBFile *Pdb);
44317017Sdim
45317017Sdim  PdbRaw_DbiVer getDbiVersion() const;
46317017Sdim  uint32_t getAge() const;
47317017Sdim  uint16_t getPublicSymbolStreamIndex() const;
48317017Sdim  uint16_t getGlobalSymbolStreamIndex() const;
49317017Sdim
50317017Sdim  uint16_t getFlags() const;
51317017Sdim  bool isIncrementallyLinked() const;
52317017Sdim  bool hasCTypes() const;
53317017Sdim  bool isStripped() const;
54317017Sdim
55317017Sdim  uint16_t getBuildNumber() const;
56317017Sdim  uint16_t getBuildMajorVersion() const;
57317017Sdim  uint16_t getBuildMinorVersion() const;
58317017Sdim
59317017Sdim  uint16_t getPdbDllRbld() const;
60317017Sdim  uint32_t getPdbDllVersion() const;
61317017Sdim
62317017Sdim  uint32_t getSymRecordStreamIndex() const;
63317017Sdim
64317017Sdim  PDB_Machine getMachineType() const;
65317017Sdim
66341825Sdim  const DbiStreamHeader *getHeader() const { return Header; }
67341825Sdim
68320397Sdim  BinarySubstreamRef getSectionContributionData() const;
69320397Sdim  BinarySubstreamRef getSecMapSubstreamData() const;
70320397Sdim  BinarySubstreamRef getModiSubstreamData() const;
71320397Sdim  BinarySubstreamRef getFileInfoSubstreamData() const;
72320397Sdim  BinarySubstreamRef getTypeServerMapSubstreamData() const;
73320397Sdim  BinarySubstreamRef getECSubstreamData() const;
74320397Sdim
75317017Sdim  /// If the given stream type is present, returns its stream index. If it is
76317017Sdim  /// not present, returns InvalidStreamIndex.
77317017Sdim  uint32_t getDebugStreamIndex(DbgHeaderType Type) const;
78317017Sdim
79317969Sdim  const DbiModuleList &modules() const;
80317017Sdim
81344779Sdim  FixedStreamArray<object::coff_section> getSectionHeaders() const;
82317017Sdim
83353358Sdim  bool hasOldFpoRecords() const;
84353358Sdim  FixedStreamArray<object::FpoData> getOldFpoRecords() const;
85353358Sdim  bool hasNewFpoRecords() const;
86353358Sdim  const codeview::DebugFrameDataSubsectionRef &getNewFpoRecords() const;
87317017Sdim
88317017Sdim  FixedStreamArray<SecMapEntry> getSectionMap() const;
89317017Sdim  void visitSectionContributions(ISectionContribVisitor &Visitor) const;
90317017Sdim
91320970Sdim  Expected<StringRef> getECName(uint32_t NI) const;
92320970Sdim
93317017Sdimprivate:
94317017Sdim  Error initializeSectionContributionData();
95341825Sdim  Error initializeSectionHeadersData(PDBFile *Pdb);
96317017Sdim  Error initializeSectionMapData();
97353358Sdim  Error initializeOldFpoRecords(PDBFile *Pdb);
98353358Sdim  Error initializeNewFpoRecords(PDBFile *Pdb);
99317017Sdim
100353358Sdim  Expected<std::unique_ptr<msf::MappedBlockStream>>
101353358Sdim  createIndexedStreamForHeaderType(PDBFile *Pdb, DbgHeaderType Type) const;
102353358Sdim
103341825Sdim  std::unique_ptr<BinaryStream> Stream;
104317017Sdim
105317778Sdim  PDBStringTable ECNames;
106317017Sdim
107320397Sdim  BinarySubstreamRef SecContrSubstream;
108320397Sdim  BinarySubstreamRef SecMapSubstream;
109320397Sdim  BinarySubstreamRef ModiSubstream;
110320397Sdim  BinarySubstreamRef FileInfoSubstream;
111320397Sdim  BinarySubstreamRef TypeServerMapSubstream;
112320397Sdim  BinarySubstreamRef ECSubstream;
113317017Sdim
114317969Sdim  DbiModuleList Modules;
115317017Sdim
116317017Sdim  FixedStreamArray<support::ulittle16_t> DbgStreams;
117317017Sdim
118319799Sdim  PdbRaw_DbiSecContribVer SectionContribVersion =
119319799Sdim      PdbRaw_DbiSecContribVer::DbiSecContribVer60;
120317017Sdim  FixedStreamArray<SectionContrib> SectionContribs;
121317017Sdim  FixedStreamArray<SectionContrib2> SectionContribs2;
122317017Sdim  FixedStreamArray<SecMapEntry> SectionMap;
123317017Sdim
124317017Sdim  std::unique_ptr<msf::MappedBlockStream> SectionHeaderStream;
125317017Sdim  FixedStreamArray<object::coff_section> SectionHeaders;
126317017Sdim
127353358Sdim  std::unique_ptr<msf::MappedBlockStream> OldFpoStream;
128353358Sdim  FixedStreamArray<object::FpoData> OldFpoRecords;
129353358Sdim
130353358Sdim  std::unique_ptr<msf::MappedBlockStream> NewFpoStream;
131353358Sdim  codeview::DebugFrameDataSubsectionRef NewFpoRecords;
132317017Sdim
133317017Sdim  const DbiStreamHeader *Header;
134317017Sdim};
135317017Sdim}
136317017Sdim}
137317017Sdim
138317017Sdim#endif
139