Line data Source code
1 : //===- ModuleSubstream.h ----------------------------------------*- C++ -*-===//
2 : //
3 : // The LLVM Compiler Infrastructure
4 : //
5 : // This file is distributed under the University of Illinois Open Source
6 : // License. See LICENSE.TXT for details.
7 : //
8 : //===----------------------------------------------------------------------===//
9 :
10 : #ifndef LLVM_DEBUGINFO_CODEVIEW_MODULESUBSTREAM_H
11 : #define LLVM_DEBUGINFO_CODEVIEW_MODULESUBSTREAM_H
12 :
13 : #include "llvm/DebugInfo/CodeView/CodeView.h"
14 : #include "llvm/Support/BinaryStreamArray.h"
15 : #include "llvm/Support/BinaryStreamRef.h"
16 : #include "llvm/Support/Endian.h"
17 : #include "llvm/Support/Error.h"
18 :
19 : namespace llvm {
20 : namespace codeview {
21 :
22 : // Corresponds to the `CV_DebugSSubsectionHeader_t` structure.
23 : struct ModuleSubsectionHeader {
24 : support::ulittle32_t Kind; // codeview::ModuleSubstreamKind enum
25 : support::ulittle32_t Length; // number of bytes occupied by this record.
26 : };
27 :
28 : // Corresponds to the `CV_DebugSLinesHeader_t` structure.
29 : struct LineSubstreamHeader {
30 : support::ulittle32_t RelocOffset; // Code offset of line contribution.
31 : support::ulittle16_t RelocSegment; // Code segment of line contribution.
32 : support::ulittle16_t Flags; // See LineFlags enumeration.
33 : support::ulittle32_t CodeSize; // Code size of this line contribution.
34 : };
35 :
36 : // Corresponds to the `CV_DebugSLinesFileBlockHeader_t` structure.
37 : struct LineFileBlockHeader {
38 : support::ulittle32_t NameIndex; // Index in DBI name buffer of filename.
39 : support::ulittle32_t NumLines; // Number of lines
40 : support::ulittle32_t BlockSize; // Code size of block, in bytes.
41 : // The following two variable length arrays appear immediately after the
42 : // header. The structure definitions follow.
43 : // LineNumberEntry Lines[NumLines];
44 : // ColumnNumberEntry Columns[NumLines];
45 : };
46 :
47 : // Corresponds to `CV_Line_t` structure
48 : struct LineNumberEntry {
49 : support::ulittle32_t Offset; // Offset to start of code bytes for line number
50 : support::ulittle32_t Flags; // Start:24, End:7, IsStatement:1
51 : };
52 :
53 : // Corresponds to `CV_Column_t` structure
54 : struct ColumnNumberEntry {
55 : support::ulittle16_t StartColumn;
56 : support::ulittle16_t EndColumn;
57 : };
58 :
59 : class ModuleSubstream {
60 : public:
61 : ModuleSubstream();
62 : ModuleSubstream(ModuleSubstreamKind Kind, BinaryStreamRef Data);
63 : static Error initialize(BinaryStreamRef Stream, ModuleSubstream &Info);
64 : uint32_t getRecordLength() const;
65 : ModuleSubstreamKind getSubstreamKind() const;
66 : BinaryStreamRef getRecordData() const;
67 :
68 : private:
69 : ModuleSubstreamKind Kind;
70 : BinaryStreamRef Data;
71 : };
72 :
73 : typedef VarStreamArray<ModuleSubstream> ModuleSubstreamArray;
74 : } // namespace codeview
75 :
76 : template <> struct VarStreamArrayExtractor<codeview::ModuleSubstream> {
77 6 : Error operator()(BinaryStreamRef Stream, uint32_t &Length,
78 : codeview::ModuleSubstream &Info) const {
79 18 : if (auto EC = codeview::ModuleSubstream::initialize(Stream, Info))
80 0 : return EC;
81 6 : Length = Info.getRecordLength();
82 18 : return Error::success();
83 : }
84 : };
85 : } // namespace llvm
86 :
87 : #endif // LLVM_DEBUGINFO_CODEVIEW_MODULESUBSTREAM_H
|