LLVM  6.0.0svn
DWARFDebugLine.h
Go to the documentation of this file.
1 //===- DWARFDebugLine.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_DWARFDEBUGLINE_H
11 #define LLVM_DEBUGINFO_DWARFDEBUGLINE_H
12 
13 #include "llvm/ADT/StringRef.h"
18 #include <cstdint>
19 #include <map>
20 #include <string>
21 #include <vector>
22 
23 namespace llvm {
24 
25 class DWARFUnit;
26 class raw_ostream;
27 
29 public:
30  struct FileNameEntry {
31  FileNameEntry() = default;
32 
34  uint64_t DirIdx = 0;
35  uint64_t ModTime = 0;
36  uint64_t Length = 0;
37  };
38 
39  struct Prologue {
40  Prologue();
41 
42  /// The size in bytes of the statement information for this compilation unit
43  /// (not including the total_length field itself).
44  uint64_t TotalLength;
45  /// Version, address size (starting in v5), and DWARF32/64 format; these
46  /// parameters affect interpretation of forms (used in the directory and
47  /// file tables starting with v5).
49  /// In v5, size in bytes of a segment selector.
50  uint8_t SegSelectorSize;
51  /// The number of bytes following the prologue_length field to the beginning
52  /// of the first byte of the statement program itself.
53  uint64_t PrologueLength;
54  /// The size in bytes of the smallest target machine instruction. Statement
55  /// program opcodes that alter the address register first multiply their
56  /// operands by this value.
57  uint8_t MinInstLength;
58  /// The maximum number of individual operations that may be encoded in an
59  /// instruction.
60  uint8_t MaxOpsPerInst;
61  /// The initial value of theis_stmtregister.
62  uint8_t DefaultIsStmt;
63  /// This parameter affects the meaning of the special opcodes. See below.
64  int8_t LineBase;
65  /// This parameter affects the meaning of the special opcodes. See below.
66  uint8_t LineRange;
67  /// The number assigned to the first special opcode.
68  uint8_t OpcodeBase;
69  std::vector<uint8_t> StandardOpcodeLengths;
70  std::vector<StringRef> IncludeDirectories;
71  std::vector<FileNameEntry> FileNames;
72 
73  const DWARFFormParams getFormParams() const { return FormParams; }
74  uint16_t getVersion() const { return FormParams.Version; }
75  uint8_t getAddressSize() const { return FormParams.AddrSize; }
76  bool isDWARF64() const { return FormParams.Format == dwarf::DWARF64; }
77 
78  uint32_t sizeofTotalLength() const { return isDWARF64() ? 12 : 4; }
79 
80  uint32_t sizeofPrologueLength() const { return isDWARF64() ? 8 : 4; }
81 
82  /// Length of the prologue in bytes.
83  uint32_t getLength() const {
84  return PrologueLength + sizeofTotalLength() + sizeof(getVersion()) +
85  sizeofPrologueLength();
86  }
87 
88  /// Length of the line table data in bytes (not including the prologue).
90  return TotalLength + sizeofTotalLength() - getLength();
91  }
92 
94  return LineBase + (int8_t)LineRange - 1;
95  }
96 
97  void clear();
98  void dump(raw_ostream &OS) const;
99  bool parse(const DWARFDataExtractor &DebugLineData, uint32_t *OffsetPtr,
100  const DWARFUnit *U = nullptr);
101  };
102 
103  /// Standard .debug_line state machine structure.
104  struct Row {
105  explicit Row(bool DefaultIsStmt = false);
106 
107  /// Called after a row is appended to the matrix.
108  void postAppend();
109  void reset(bool DefaultIsStmt);
110  void dump(raw_ostream &OS) const;
111 
112  static void dumpTableHeader(raw_ostream &OS);
113 
114  static bool orderByAddress(const Row &LHS, const Row &RHS) {
115  return LHS.Address < RHS.Address;
116  }
117 
118  /// The program-counter value corresponding to a machine instruction
119  /// generated by the compiler.
120  uint64_t Address;
121  /// An unsigned integer indicating a source line number. Lines are numbered
122  /// beginning at 1. The compiler may emit the value 0 in cases where an
123  /// instruction cannot be attributed to any source line.
125  /// An unsigned integer indicating a column number within a source line.
126  /// Columns are numbered beginning at 1. The value 0 is reserved to indicate
127  /// that a statement begins at the 'left edge' of the line.
128  uint16_t Column;
129  /// An unsigned integer indicating the identity of the source file
130  /// corresponding to a machine instruction.
131  uint16_t File;
132  /// An unsigned integer representing the DWARF path discriminator value
133  /// for this location.
135  /// An unsigned integer whose value encodes the applicable instruction set
136  /// architecture for the current instruction.
137  uint8_t Isa;
138  /// A boolean indicating that the current instruction is the beginning of a
139  /// statement.
140  uint8_t IsStmt : 1,
141  /// A boolean indicating that the current instruction is the
142  /// beginning of a basic block.
143  BasicBlock : 1,
144  /// A boolean indicating that the current address is that of the
145  /// first byte after the end of a sequence of target machine
146  /// instructions.
147  EndSequence : 1,
148  /// A boolean indicating that the current address is one (of possibly
149  /// many) where execution should be suspended for an entry breakpoint
150  /// of a function.
151  PrologueEnd : 1,
152  /// A boolean indicating that the current address is one (of possibly
153  /// many) where execution should be suspended for an exit breakpoint
154  /// of a function.
155  EpilogueBegin : 1;
156  };
157 
158  /// Represents a series of contiguous machine instructions. Line table for
159  /// each compilation unit may consist of multiple sequences, which are not
160  /// guaranteed to be in the order of ascending instruction address.
161  struct Sequence {
162  Sequence();
163 
164  /// Sequence describes instructions at address range [LowPC, HighPC)
165  /// and is described by line table rows [FirstRowIndex, LastRowIndex).
166  uint64_t LowPC;
167  uint64_t HighPC;
168  unsigned FirstRowIndex;
169  unsigned LastRowIndex;
170  bool Empty;
171 
172  void reset();
173 
174  static bool orderByLowPC(const Sequence &LHS, const Sequence &RHS) {
175  return LHS.LowPC < RHS.LowPC;
176  }
177 
178  bool isValid() const {
179  return !Empty && (LowPC < HighPC) && (FirstRowIndex < LastRowIndex);
180  }
181 
182  bool containsPC(uint64_t PC) const { return (LowPC <= PC && PC < HighPC); }
183  };
184 
185  struct LineTable {
186  LineTable();
187 
188  /// Represents an invalid row
189  const uint32_t UnknownRowIndex = UINT32_MAX;
190 
191  void appendRow(const DWARFDebugLine::Row &R) { Rows.push_back(R); }
192 
194  Sequences.push_back(S);
195  }
196 
197  /// Returns the index of the row with file/line info for a given address,
198  /// or UnknownRowIndex if there is no such row.
199  uint32_t lookupAddress(uint64_t Address) const;
200 
201  bool lookupAddressRange(uint64_t Address, uint64_t Size,
202  std::vector<uint32_t> &Result) const;
203 
204  bool hasFileAtIndex(uint64_t FileIndex) const;
205 
206  /// Extracts filename by its index in filename table in prologue.
207  /// Returns true on success.
208  bool getFileNameByIndex(uint64_t FileIndex, const char *CompDir,
210  std::string &Result) const;
211 
212  /// Fills the Result argument with the file and line information
213  /// corresponding to Address. Returns true on success.
214  bool getFileLineInfoForAddress(uint64_t Address, const char *CompDir,
216  DILineInfo &Result) const;
217 
218  void dump(raw_ostream &OS) const;
219  void clear();
220 
221  /// Parse prologue and all rows.
222  bool parse(DWARFDataExtractor &DebugLineData, uint32_t *OffsetPtr,
223  const DWARFUnit *U, raw_ostream *OS = nullptr);
224 
225  using RowVector = std::vector<Row>;
226  using RowIter = RowVector::const_iterator;
227  using SequenceVector = std::vector<Sequence>;
228  using SequenceIter = SequenceVector::const_iterator;
229 
233 
234  private:
235  uint32_t findRowInSeq(const DWARFDebugLine::Sequence &Seq,
236  uint64_t Address) const;
237  };
238 
239  const LineTable *getLineTable(uint32_t Offset) const;
240  const LineTable *getOrParseLineTable(DWARFDataExtractor &DebugLineData,
241  uint32_t Offset, const DWARFUnit *U);
242 
243 private:
244  struct ParsingState {
245  ParsingState(struct LineTable *LT);
246 
247  void resetRowAndSequence();
248  void appendRowToMatrix(uint32_t Offset);
249 
250  /// Line table we're currently parsing.
251  struct LineTable *LineTable;
252  /// The row number that starts at zero for the prologue, and increases for
253  /// each row added to the matrix.
254  unsigned RowNumber = 0;
255  struct Row Row;
256  struct Sequence Sequence;
257  };
258 
259  using LineTableMapTy = std::map<uint32_t, LineTable>;
260  using LineTableIter = LineTableMapTy::iterator;
261  using LineTableConstIter = LineTableMapTy::const_iterator;
262 
263  LineTableMapTy LineTableMap;
264 };
265 
266 } // end namespace llvm
267 
268 #endif // LLVM_DEBUGINFO_DWARFDEBUGLINE_H
SequenceVector::const_iterator SequenceIter
uint64_t LowPC
Sequence describes instructions at address range [LowPC, HighPC) and is described by line table rows ...
Compute iterated dominance frontiers using a linear time algorithm.
Definition: AllocatorList.h:24
Various leaf nodes.
Definition: ISDOpcodes.h:60
std::vector< Sequence > SequenceVector
uint32_t sizeofTotalLength() const
static bool orderByAddress(const Row &LHS, const Row &RHS)
uint32_t getLength() const
Length of the prologue in bytes.
uint32_t getStatementTableLength() const
Length of the line table data in bytes (not including the prologue).
uint8_t MinInstLength
The size in bytes of the smallest target machine instruction.
uint32_t Line
An unsigned integer indicating a source line number.
dwarf::DwarfFormat Format
const LineTable * getOrParseLineTable(DWARFDataExtractor &DebugLineData, uint32_t Offset, const DWARFUnit *U)
A format-neutral container for source line information.
Definition: DIContext.h:31
uint8_t Isa
An unsigned integer whose value encodes the applicable instruction set architecture for the current i...
uint8_t MaxOpsPerInst
The maximum number of individual operations that may be encoded in an instruction.
Represents a series of contiguous machine instructions.
uint32_t sizeofPrologueLength() const
uint64_t Address
The program-counter value corresponding to a machine instruction generated by the compiler...
Definition: regcomp.c:196
uint8_t LineRange
This parameter affects the meaning of the special opcodes. See below.
uint8_t OpcodeBase
The number assigned to the first special opcode.
uint64_t TotalLength
The size in bytes of the statement information for this compilation unit (not including the total_len...
void dump(const SparseBitVector< ElementSize > &LHS, raw_ostream &out)
uint8_t SegSelectorSize
In v5, size in bytes of a segment selector.
uint16_t File
An unsigned integer indicating the identity of the source file corresponding to a machine instruction...
uint64_t PrologueLength
The number of bytes following the prologue_length field to the beginning of the first byte of the sta...
DWARFFormParams FormParams
Version, address size (starting in v5), and DWARF32/64 format; these parameters affect interpretation...
int32_t getMaxLineIncrementForSpecialOpcode() const
void appendSequence(const DWARFDebugLine::Sequence &S)
Standard .debug_line state machine structure.
A DataExtractor (typically for an in-memory copy of an object-file section) plus a relocation map for...
bool containsPC(uint64_t PC) const
uint16_t Column
An unsigned integer indicating a column number within a source line.
void appendRow(const DWARFDebugLine::Row &R)
A helper struct for DWARFFormValue methods, providing information that allows it to know the byte siz...
uint8_t PrologueEnd
A boolean indicating that the current address is one (of possibly many) where execution should be sus...
std::vector< uint8_t > StandardOpcodeLengths
static void clear(coro::Shape &Shape)
Definition: Coroutines.cpp:210
std::vector< FileNameEntry > FileNames
uint32_t Discriminator
An unsigned integer representing the DWARF path discriminator value for this location.
RowVector::const_iterator RowIter
static bool orderByLowPC(const Sequence &LHS, const Sequence &RHS)
Sequence
A sequence of states that a pointer may go through in which an objc_retain and objc_release are actua...
Definition: PtrState.h:41
uint8_t DefaultIsStmt
The initial value of theis_stmtregister.
const unsigned Kind
const DWARFFormParams getFormParams() const
int8_t LineBase
This parameter affects the meaning of the special opcodes. See below.
const LineTable * getLineTable(uint32_t Offset) const
constexpr char Size[]
Key for Kernel::Arg::Metadata::mSize.
This class implements an extremely fast bulk output stream that can only output to a stream...
Definition: raw_ostream.h:44
StringRef - Represent a constant reference to a string, i.e.
Definition: StringRef.h:49
std::vector< StringRef > IncludeDirectories