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