1 //===-- DWARFDebugLine.h ----------------------------------------*- C++ -*-===//
3 // The LLVM Compiler Infrastructure
5 // This file is distributed under the University of Illinois Open Source
6 // License. See LICENSE.TXT for details.
8 //===----------------------------------------------------------------------===//
10 #ifndef LLVM_DEBUGINFO_DWARFDEBUGLINE_H
11 #define LLVM_DEBUGINFO_DWARFDEBUGLINE_H
13 #include "llvm/Support/DataExtractor.h"
21 class DWARFDebugLine {
23 struct FileNameEntry {
24 FileNameEntry() : Name(0), DirIdx(0), ModTime(0), Length(0) {}
34 : TotalLength(0), Version(0), PrologueLength(0), MinInstLength(0),
35 DefaultIsStmt(0), LineBase(0), LineRange(0), OpcodeBase(0) {}
37 // The size in bytes of the statement information for this compilation unit
38 // (not including the total_length field itself).
40 // Version identifier for the statement information format.
42 // The number of bytes following the prologue_length field to the beginning
43 // of the first byte of the statement program itself.
44 uint32_t PrologueLength;
45 // The size in bytes of the smallest target machine instruction. Statement
46 // program opcodes that alter the address register first multiply their
47 // operands by this value.
48 uint8_t MinInstLength;
49 // The initial value of theis_stmtregister.
50 uint8_t DefaultIsStmt;
51 // This parameter affects the meaning of the special opcodes. See below.
53 // This parameter affects the meaning of the special opcodes. See below.
55 // The number assigned to the first special opcode.
57 std::vector<uint8_t> StandardOpcodeLengths;
58 std::vector<const char*> IncludeDirectories;
59 std::vector<FileNameEntry> FileNames;
61 // Length of the prologue in bytes.
62 uint32_t getLength() const {
63 return PrologueLength + sizeof(TotalLength) + sizeof(Version) +
64 sizeof(PrologueLength);
66 // Length of the line table data in bytes (not including the prologue).
67 uint32_t getStatementTableLength() const {
68 return TotalLength + sizeof(TotalLength) - getLength();
70 int32_t getMaxLineIncrementForSpecialOpcode() const {
71 return LineBase + (int8_t)LineRange - 1;
73 void dump(raw_ostream &OS) const;
75 TotalLength = Version = PrologueLength = 0;
76 MinInstLength = LineBase = LineRange = OpcodeBase = 0;
77 StandardOpcodeLengths.clear();
78 IncludeDirectories.clear();
83 // Standard .debug_line state machine structure.
85 Row(bool default_is_stmt = false) { reset(default_is_stmt); }
86 /// Called after a row is appended to the matrix.
88 void reset(bool default_is_stmt);
89 void dump(raw_ostream &OS) const;
91 static bool orderByAddress(const Row& LHS, const Row& RHS) {
92 return LHS.Address < RHS.Address;
95 // The program-counter value corresponding to a machine instruction
96 // generated by the compiler.
98 // An unsigned integer indicating a source line number. Lines are numbered
99 // beginning at 1. The compiler may emit the value 0 in cases where an
100 // instruction cannot be attributed to any source line.
102 // An unsigned integer indicating a column number within a source line.
103 // Columns are numbered beginning at 1. The value 0 is reserved to indicate
104 // that a statement begins at the 'left edge' of the line.
106 // An unsigned integer indicating the identity of the source file
107 // corresponding to a machine instruction.
109 // An unsigned integer whose value encodes the applicable instruction set
110 // architecture for the current instruction.
112 // A boolean indicating that the current instruction is the beginning of a
115 // A boolean indicating that the current instruction is the
116 // beginning of a basic block.
118 // A boolean indicating that the current address is that of the
119 // first byte after the end of a sequence of target machine
122 // A boolean indicating that the current address is one (of possibly
123 // many) where execution should be suspended for an entry breakpoint
126 // A boolean indicating that the current address is one (of possibly
127 // many) where execution should be suspended for an exit breakpoint
132 // Represents a series of contiguous machine instructions. Line table for each
133 // compilation unit may consist of multiple sequences, which are not
134 // guaranteed to be in the order of ascending instruction address.
136 // Sequence describes instructions at address range [LowPC, HighPC)
137 // and is described by line table rows [FirstRowIndex, LastRowIndex).
140 unsigned FirstRowIndex;
141 unsigned LastRowIndex;
144 Sequence() { reset(); }
152 static bool orderByLowPC(const Sequence& LHS, const Sequence& RHS) {
153 return LHS.LowPC < RHS.LowPC;
155 bool isValid() const {
156 return !Empty && (LowPC < HighPC) && (FirstRowIndex < LastRowIndex);
158 bool containsPC(uint64_t pc) const {
159 return (LowPC <= pc && pc < HighPC);
164 void appendRow(const DWARFDebugLine::Row &state) { Rows.push_back(state); }
165 void appendSequence(const DWARFDebugLine::Sequence &sequence) {
166 Sequences.push_back(sequence);
174 // Returns the index of the row with file/line info for a given address,
175 // or -1 if there is no such row.
176 uint32_t lookupAddress(uint64_t address) const;
177 void dump(raw_ostream &OS) const;
179 struct Prologue Prologue;
180 typedef std::vector<Row> RowVector;
181 typedef RowVector::const_iterator RowIter;
182 typedef std::vector<Sequence> SequenceVector;
183 typedef SequenceVector::const_iterator SequenceIter;
185 SequenceVector Sequences;
188 struct State : public Row, public Sequence, public LineTable {
189 // Special row codes.
191 StartParsingLineTable = 0,
192 DoneParsingLineTable = -1
195 State() : row(StartParsingLineTable) {}
198 virtual void appendRowToMatrix(uint32_t offset);
199 virtual void finalize();
200 virtual void reset() {
201 Row::reset(Prologue.DefaultIsStmt);
205 // The row number that starts at zero for the prologue, and increases for
206 // each row added to the matrix.
210 struct DumpingState : public State {
211 DumpingState(raw_ostream &OS) : OS(OS) {}
212 virtual ~DumpingState();
213 virtual void finalize();
218 static bool parsePrologue(DataExtractor debug_line_data, uint32_t *offset_ptr,
220 /// Parse a single line table (prologue and all rows).
221 static bool parseStatementTable(DataExtractor debug_line_data,
222 uint32_t *offset_ptr, State &state);
224 const LineTable *getLineTable(uint32_t offset) const;
225 const LineTable *getOrParseLineTable(DataExtractor debug_line_data,
229 typedef std::map<uint32_t, LineTable> LineTableMapTy;
230 typedef LineTableMapTy::iterator LineTableIter;
231 typedef LineTableMapTy::const_iterator LineTableConstIter;
233 LineTableMapTy LineTableMap;