LLVM  15.0.0git
DebugLinesSubsection.h
Go to the documentation of this file.
1 //===- DebugLinesSubsection.h -----------------------------------*- 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_CODEVIEW_DEBUGLINESSUBSECTION_H
10 #define LLVM_DEBUGINFO_CODEVIEW_DEBUGLINESSUBSECTION_H
11 
12 #include "llvm/ADT/StringRef.h"
18 #include "llvm/Support/Endian.h"
19 #include "llvm/Support/Error.h"
20 #include <cstdint>
21 #include <vector>
22 
23 namespace llvm {
24 class BinaryStreamReader;
25 class BinaryStreamWriter;
26 namespace codeview {
27 
28 class DebugChecksumsSubsection;
29 class DebugStringTableSubsection;
30 
31 // Corresponds to the `CV_DebugSLinesHeader_t` structure.
33  support::ulittle32_t RelocOffset; // Code offset of line contribution.
34  support::ulittle16_t RelocSegment; // Code segment of line contribution.
35  support::ulittle16_t Flags; // See LineFlags enumeration.
36  support::ulittle32_t CodeSize; // Code size of this line contribution.
37 };
38 
39 // Corresponds to the `CV_DebugSLinesFileBlockHeader_t` structure.
41  support::ulittle32_t NameIndex; // Offset of FileChecksum entry in File
42  // checksums buffer. The checksum entry then
43  // contains another offset into the string
44  // table of the actual name.
45  support::ulittle32_t NumLines; // Number of lines
46  support::ulittle32_t BlockSize; // Code size of block, in bytes.
47  // The following two variable length arrays appear immediately after the
48  // header. The structure definitions follow.
49  // LineNumberEntry Lines[NumLines];
50  // ColumnNumberEntry Columns[NumLines];
51 };
52 
53 // Corresponds to `CV_Line_t` structure
55  support::ulittle32_t Offset; // Offset to start of code bytes for line number
56  support::ulittle32_t Flags; // Start:24, End:7, IsStatement:1
57 };
58 
59 // Corresponds to `CV_Column_t` structure
63 };
64 
69 };
70 
72 public:
74  LineColumnEntry &Item);
75 
76  const LineFragmentHeader *Header = nullptr;
77 };
78 
80  friend class LineColumnExtractor;
81 
84 
85 public:
87 
88  static bool classof(const DebugSubsectionRef *S) {
89  return S->kind() == DebugSubsectionKind::Lines;
90  }
91 
93 
94  Iterator begin() const { return LinesAndColumns.begin(); }
95  Iterator end() const { return LinesAndColumns.end(); }
96 
97  const LineFragmentHeader *header() const { return Header; }
98 
99  bool hasColumnInfo() const;
100 
101 private:
102  const LineFragmentHeader *Header = nullptr;
103  LineInfoArray LinesAndColumns;
104 };
105 
106 class DebugLinesSubsection final : public DebugSubsection {
107  struct Block {
108  Block(uint32_t ChecksumBufferOffset)
109  : ChecksumBufferOffset(ChecksumBufferOffset) {}
110 
111  uint32_t ChecksumBufferOffset;
112  std::vector<LineNumberEntry> Lines;
113  std::vector<ColumnNumberEntry> Columns;
114  };
115 
116 public:
118  DebugStringTableSubsection &Strings);
119 
120  static bool classof(const DebugSubsection *S) {
121  return S->kind() == DebugSubsectionKind::Lines;
122  }
123 
124  void createBlock(StringRef FileName);
125  void addLineInfo(uint32_t Offset, const LineInfo &Line);
126  void addLineAndColumnInfo(uint32_t Offset, const LineInfo &Line,
127  uint32_t ColStart, uint32_t ColEnd);
128 
129  uint32_t calculateSerializedSize() const override;
130  Error commit(BinaryStreamWriter &Writer) const override;
131 
132  void setRelocationAddress(uint16_t Segment, uint32_t Offset);
133  void setCodeSize(uint32_t Size);
134  void setFlags(LineFlags Flags);
135 
136  bool hasColumnInfo() const;
137 
138 private:
139  DebugChecksumsSubsection &Checksums;
140  uint32_t RelocOffset = 0;
141  uint16_t RelocSegment = 0;
142  uint32_t CodeSize = 0;
143  LineFlags Flags = LF_None;
144  std::vector<Block> Blocks;
145 };
146 
147 } // end namespace codeview
148 } // end namespace llvm
149 
150 #endif // LLVM_DEBUGINFO_CODEVIEW_DEBUGLINESSUBSECTION_H
llvm::codeview::DebugLinesSubsection::createBlock
void createBlock(StringRef FileName)
Definition: DebugLinesSubsection.cpp:75
llvm::codeview::DebugLinesSubsection::commit
Error commit(BinaryStreamWriter &Writer) const override
Definition: DebugLinesSubsection.cpp:103
llvm::codeview::LineBlockFragmentHeader::NumLines
support::ulittle32_t NumLines
Definition: DebugLinesSubsection.h:45
llvm
This is an optimization pass for GlobalISel generic memory operations.
Definition: AddressRanges.h:17
llvm::codeview::LineColumnEntry::Columns
FixedStreamArray< ColumnNumberEntry > Columns
Definition: DebugLinesSubsection.h:68
llvm::codeview::LineBlockFragmentHeader
Definition: DebugLinesSubsection.h:40
llvm::codeview::DebugSubsectionKind::Lines
@ Lines
llvm::codeview::DebugChecksumsSubsection
Definition: DebugChecksumsSubsection.h:77
llvm::support::detail::packed_endian_specific_integral
Definition: Endian.h:206
llvm::codeview::LineBlockFragmentHeader::BlockSize
support::ulittle32_t BlockSize
Definition: DebugLinesSubsection.h:46
llvm::codeview::DebugLinesSubsectionRef::initialize
Error initialize(BinaryStreamReader Reader)
Definition: DebugLinesSubsection.cpp:56
StringRef.h
llvm::BinaryStreamWriter
Provides write only access to a subclass of WritableBinaryStream.
Definition: BinaryStreamWriter.h:30
llvm::codeview::Line
Definition: Line.h:90
llvm::codeview::DebugLinesSubsection::classof
static bool classof(const DebugSubsection *S)
Definition: DebugLinesSubsection.h:120
Error.h
llvm::codeview::LineNumberEntry::Flags
support::ulittle32_t Flags
Definition: DebugLinesSubsection.h:56
llvm::codeview::DebugLinesSubsectionRef::DebugLinesSubsectionRef
DebugLinesSubsectionRef()
Definition: DebugLinesSubsection.cpp:53
llvm::codeview::LineFragmentHeader::RelocSegment
support::ulittle16_t RelocSegment
Definition: DebugLinesSubsection.h:34
llvm::codeview::DebugStringTableSubsection
Represents a read-write view of a CodeView string table.
Definition: DebugStringTableSubsection.h:56
llvm::codeview::ColumnNumberEntry
Definition: DebugLinesSubsection.h:60
llvm::VarStreamArray::end
Iterator end() const
Definition: BinaryStreamArray.h:117
llvm::codeview::DebugLinesSubsection::setFlags
void setFlags(LineFlags Flags)
Definition: DebugLinesSubsection.cpp:156
llvm::FixedStreamArray
FixedStreamArray is similar to VarStreamArray, except with each record having a fixed-length.
Definition: BinaryStreamArray.h:259
llvm::codeview::DebugLinesSubsection::hasColumnInfo
bool hasColumnInfo() const
Definition: DebugLinesSubsection.cpp:158
llvm::codeview::ColumnNumberEntry::StartColumn
support::ulittle16_t StartColumn
Definition: DebugLinesSubsection.h:61
llvm::codeview::DebugLinesSubsectionRef::end
Iterator end() const
Definition: DebugLinesSubsection.h:95
llvm::codeview::LineColumnEntry
Definition: DebugLinesSubsection.h:65
llvm::codeview::LineColumnExtractor::operator()
Error operator()(BinaryStreamRef Stream, uint32_t &Len, LineColumnEntry &Item)
Definition: DebugLinesSubsection.cpp:23
llvm::VarStreamArray< LineColumnEntry, LineColumnExtractor >
llvm::codeview::LineBlockFragmentHeader::NameIndex
support::ulittle32_t NameIndex
Definition: DebugLinesSubsection.h:41
llvm::codeview::LineColumnEntry::NameIndex
support::ulittle32_t NameIndex
Definition: DebugLinesSubsection.h:66
llvm::codeview::DebugSubsectionRef
Definition: DebugSubsection.h:21
llvm::VarStreamArray< LineColumnEntry, LineColumnExtractor >::Iterator
VarStreamArrayIterator< LineColumnEntry, LineColumnExtractor > Iterator
Definition: BinaryStreamArray.h:96
llvm::codeview::LineNumberEntry
Definition: DebugLinesSubsection.h:54
CodeView.h
llvm::BinaryStreamReader
Provides read only access to a subclass of BinaryStream.
Definition: BinaryStreamReader.h:29
Line.h
llvm::codeview::LineFragmentHeader
Definition: DebugLinesSubsection.h:32
DebugSubsection.h
llvm::codeview::DebugLinesSubsection::addLineInfo
void addLineInfo(uint32_t Offset, const LineInfo &Line)
Definition: DebugLinesSubsection.cpp:81
llvm::codeview::LineNumberEntry::Offset
support::ulittle32_t Offset
Definition: DebugLinesSubsection.h:55
llvm::codeview::DebugLinesSubsectionRef
Definition: DebugLinesSubsection.h:79
BinaryStreamArray.h
llvm::VarStreamArrayIterator
VarStreamArray represents an array of variable length records backed by a stream.
Definition: BinaryStreamArray.h:88
llvm::codeview::DebugLinesSubsection::addLineAndColumnInfo
void addLineAndColumnInfo(uint32_t Offset, const LineInfo &Line, uint32_t ColStart, uint32_t ColEnd)
Definition: DebugLinesSubsection.cpp:89
llvm::codeview::LineColumnExtractor::Header
const LineFragmentHeader * Header
Definition: DebugLinesSubsection.h:76
llvm::codeview::DebugLinesSubsection::setRelocationAddress
void setRelocationAddress(uint16_t Segment, uint32_t Offset)
Definition: DebugLinesSubsection.cpp:148
llvm::codeview::LineColumnExtractor
Definition: DebugLinesSubsection.h:71
llvm::StringRef
StringRef - Represent a constant reference to a string, i.e.
Definition: StringRef.h:58
BinaryStreamRef.h
llvm::codeview::LineColumnEntry::LineNumbers
FixedStreamArray< LineNumberEntry > LineNumbers
Definition: DebugLinesSubsection.h:67
llvm::codeview::DebugLinesSubsection
Definition: DebugLinesSubsection.h:106
uint32_t
S
add sub stmia L5 ldr r0 bl L_printf $stub Instead of a and a wouldn t it be better to do three moves *Return an aggregate type is even return S
Definition: README.txt:210
llvm::codeview::ColumnNumberEntry::EndColumn
support::ulittle16_t EndColumn
Definition: DebugLinesSubsection.h:62
llvm::VarStreamArray::begin
Iterator begin(bool *HadError=nullptr) const
Definition: BinaryStreamArray.h:108
llvm::codeview::LineInfo
Definition: Line.h:20
llvm::codeview::DebugSubsection
Definition: DebugSubsection.h:34
uint16_t
llvm::codeview::LineFragmentHeader::RelocOffset
support::ulittle32_t RelocOffset
Definition: DebugLinesSubsection.h:33
llvm::codeview::DebugLinesSubsectionRef::classof
static bool classof(const DebugSubsectionRef *S)
Definition: DebugLinesSubsection.h:88
llvm::Error
Lightweight error class with error context and mandatory checking.
Definition: Error.h:155
llvm::codeview::DebugLinesSubsectionRef::hasColumnInfo
bool hasColumnInfo() const
Definition: DebugLinesSubsection.cpp:67
llvm::codeview::DebugLinesSubsectionRef::header
const LineFragmentHeader * header() const
Definition: DebugLinesSubsection.h:97
llvm::codeview::LineFragmentHeader::CodeSize
support::ulittle32_t CodeSize
Definition: DebugLinesSubsection.h:36
llvm::codeview::LineFragmentHeader::Flags
support::ulittle16_t Flags
Definition: DebugLinesSubsection.h:35
llvm::codeview::DebugLinesSubsection::calculateSerializedSize
uint32_t calculateSerializedSize() const override
Definition: DebugLinesSubsection.cpp:137
llvm::codeview::DebugLinesSubsectionRef::begin
Iterator begin() const
Definition: DebugLinesSubsection.h:94
llvm::codeview::DebugLinesSubsection::DebugLinesSubsection
DebugLinesSubsection(DebugChecksumsSubsection &Checksums, DebugStringTableSubsection &Strings)
Definition: DebugLinesSubsection.cpp:71
Endian.h
llvm::codeview::LineFlags
LineFlags
Definition: CodeView.h:568
llvm::codeview::DebugLinesSubsection::setCodeSize
void setCodeSize(uint32_t Size)
Definition: DebugLinesSubsection.cpp:154
llvm::codeview::LF_None
@ LF_None
Definition: CodeView.h:569
llvm::BinaryStreamRef
BinaryStreamRef is to BinaryStream what ArrayRef is to an Array.
Definition: BinaryStreamRef.h:155