1 //===- DbiModuleList.h - PDB module information list ------------*- C++ -*-===//
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
7 //===----------------------------------------------------------------------===//
9 #ifndef LLVM_DEBUGINFO_PDB_NATIVE_DBIMODULELIST_H
10 #define LLVM_DEBUGINFO_PDB_NATIVE_DBIMODULELIST_H
12 #include "llvm/ADT/StringRef.h"
13 #include "llvm/ADT/iterator.h"
14 #include "llvm/ADT/iterator_range.h"
15 #include "llvm/DebugInfo/PDB/Native/DbiModuleDescriptor.h"
16 #include "llvm/Support/BinaryStreamArray.h"
17 #include "llvm/Support/BinaryStreamRef.h"
18 #include "llvm/Support/Endian.h"
19 #include "llvm/Support/Error.h"
29 struct FileInfoSubstreamHeader
;
31 class DbiModuleSourceFilesIterator
32 : public iterator_facade_base
<DbiModuleSourceFilesIterator
,
33 std::random_access_iterator_tag
, StringRef
> {
35 iterator_facade_base
<DbiModuleSourceFilesIterator
,
36 std::random_access_iterator_tag
, StringRef
>;
39 DbiModuleSourceFilesIterator(const DbiModuleList
&Modules
, uint32_t Modi
,
41 DbiModuleSourceFilesIterator() = default;
42 DbiModuleSourceFilesIterator
&
43 operator=(const DbiModuleSourceFilesIterator
&R
) = default;
45 bool operator==(const DbiModuleSourceFilesIterator
&R
) const;
47 const StringRef
&operator*() const { return ThisValue
; }
48 StringRef
&operator*() { return ThisValue
; }
50 bool operator<(const DbiModuleSourceFilesIterator
&RHS
) const;
51 std::ptrdiff_t operator-(const DbiModuleSourceFilesIterator
&R
) const;
52 DbiModuleSourceFilesIterator
&operator+=(std::ptrdiff_t N
);
53 DbiModuleSourceFilesIterator
&operator-=(std::ptrdiff_t N
);
59 bool isCompatible(const DbiModuleSourceFilesIterator
&R
) const;
60 bool isUniversalEnd() const;
63 const DbiModuleList
*Modules
{nullptr};
69 friend DbiModuleSourceFilesIterator
;
72 Error
initialize(BinaryStreamRef ModInfo
, BinaryStreamRef FileInfo
);
74 Expected
<StringRef
> getFileName(uint32_t Index
) const;
75 uint32_t getModuleCount() const;
76 uint32_t getSourceFileCount() const;
77 uint16_t getSourceFileCount(uint32_t Modi
) const;
79 iterator_range
<DbiModuleSourceFilesIterator
>
80 source_files(uint32_t Modi
) const;
82 DbiModuleDescriptor
getModuleDescriptor(uint32_t Modi
) const;
85 Error
initializeModInfo(BinaryStreamRef ModInfo
);
86 Error
initializeFileInfo(BinaryStreamRef FileInfo
);
88 VarStreamArray
<DbiModuleDescriptor
> Descriptors
;
90 FixedStreamArray
<support::little32_t
> FileNameOffsets
;
91 FixedStreamArray
<support::ulittle16_t
> ModFileCountArray
;
93 // For each module, there are multiple filenames, which can be obtained by
94 // knowing the index of the file. Given the index of the file, one can use
95 // that as an offset into the FileNameOffsets array, which contains the
96 // absolute offset of the file name in NamesBuffer. Thus, for each module
97 // we store the first index in the FileNameOffsets array for this module.
98 // The number of files for the corresponding module is stored in
100 std::vector
<uint32_t> ModuleInitialFileIndex
;
102 // In order to provide random access into the Descriptors array, we iterate it
103 // once up front to find the offsets of the individual items and store them in
105 std::vector
<uint32_t> ModuleDescriptorOffsets
;
107 const FileInfoSubstreamHeader
*FileInfoHeader
= nullptr;
109 BinaryStreamRef ModInfoSubstream
;
110 BinaryStreamRef FileInfoSubstream
;
111 BinaryStreamRef NamesBuffer
;
114 } // end namespace pdb
115 } // end namespace llvm
117 #endif // LLVM_DEBUGINFO_PDB_NATIVE_DBIMODULELIST_H