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"
22 class DWARFDebugLine {
24 struct FileNameEntry {
25 FileNameEntry() : DirIdx(0), ModTime(0), Length(0) {}
35 : TotalLength(0), Version(0), PrologueLength(0), MinInstLength(0),
36 DefaultIsStmt(0), LineBase(0), LineRange(0), OpcodeBase(0) {}
38 // The size in bytes of the statement information for this compilation unit
39 // (not including the total_length field itself).
41 // Version identifier for the statement information format.
43 // The number of bytes following the prologue_length field to the beginning
44 // of the first byte of the statement program itself.
45 uint32_t PrologueLength;
46 // The size in bytes of the smallest target machine instruction. Statement
47 // program opcodes that alter the address register first multiply their
48 // operands by this value.
49 uint8_t MinInstLength;
50 // The initial value of theis_stmtregister.
51 uint8_t DefaultIsStmt;
52 // This parameter affects the meaning of the special opcodes. See below.
54 // This parameter affects the meaning of the special opcodes. See below.
56 // The number assigned to the first special opcode.
58 std::vector<uint8_t> StandardOpcodeLengths;
59 std::vector<std::string> IncludeDirectories;
60 std::vector<FileNameEntry> FileNames;
62 // Length of the prologue in bytes.
63 uint32_t getLength() const {
64 return PrologueLength + sizeof(TotalLength) + sizeof(Version) +
65 sizeof(PrologueLength);
67 // Length of the line table data in bytes (not including the prologue).
68 uint32_t getStatementTableLength() const {
69 return TotalLength + sizeof(TotalLength) - getLength();
71 int32_t getMaxLineIncrementForSpecialOpcode() const {
72 return LineBase + (int8_t)LineRange - 1;
74 void dump(raw_ostream &OS) const;
76 TotalLength = Version = PrologueLength = 0;
77 MinInstLength = LineBase = LineRange = OpcodeBase = 0;
78 StandardOpcodeLengths.clear();
79 IncludeDirectories.clear();
82 bool getFile(uint32_t file_idx, std::string& file, std::string& dir) const;
85 // Standard .debug_line state machine structure.
87 Row(bool default_is_stmt = false) { reset(default_is_stmt); }
88 /// Called after a row is appended to the matrix.
90 void reset(bool default_is_stmt);
91 void dump(raw_ostream &OS) const;
93 // The program-counter value corresponding to a machine instruction
94 // generated by the compiler.
96 // An unsigned integer indicating a source line number. Lines are numbered
97 // beginning at 1. The compiler may emit the value 0 in cases where an
98 // instruction cannot be attributed to any source line.
100 // An unsigned integer indicating a column number within a source line.
101 // Columns are numbered beginning at 1. The value 0 is reserved to indicate
102 // that a statement begins at the 'left edge' of the line.
104 // An unsigned integer indicating the identity of the source file
105 // corresponding to a machine instruction.
107 // An unsigned integer whose value encodes the applicable instruction set
108 // architecture for the current instruction.
110 // A boolean indicating that the current instruction is the beginning of a
113 // A boolean indicating that the current instruction is the
114 // beginning of a basic block.
116 // A boolean indicating that the current address is that of the
117 // first byte after the end of a sequence of target machine
120 // A boolean indicating that the current address is one (of possibly
121 // many) where execution should be suspended for an entry breakpoint
124 // A boolean indicating that the current address is one (of possibly
125 // many) where execution should be suspended for an exit breakpoint
131 void appendRow(const DWARFDebugLine::Row &state) { Rows.push_back(state); }
137 uint32_t lookupAddress(uint64_t address, uint64_t cu_high_pc) const;
138 void dump(raw_ostream &OS) const;
140 struct Prologue Prologue;
141 std::vector<Row> Rows;
144 struct State : public Row, public LineTable {
145 // Special row codes.
147 StartParsingLineTable = 0,
148 DoneParsingLineTable = -1
153 virtual void appendRowToMatrix(uint32_t offset);
154 virtual void finalize(uint32_t offset) { row = DoneParsingLineTable; }
155 virtual void reset() { Row::reset(Prologue.DefaultIsStmt); }
157 // The row number that starts at zero for the prologue, and increases for
158 // each row added to the matrix.
162 struct DumpingState : public State {
163 DumpingState(raw_ostream &OS) : OS(OS) {}
164 virtual void finalize(uint32_t offset);
169 static bool parsePrologue(DataExtractor debug_line_data, uint32_t *offset_ptr,
171 /// Parse a single line table (prologue and all rows).
172 static bool parseStatementTable(DataExtractor debug_line_data,
173 uint32_t *offset_ptr, State &state);
175 /// Parse all information in the debug_line_data into an internal
177 void parse(DataExtractor debug_line_data);
178 void parseIfNeeded(DataExtractor debug_line_data) {
179 if (LineTableMap.empty())
180 parse(debug_line_data);
182 static void dump(DataExtractor debug_line_data, raw_ostream &OS);
183 const LineTable *getLineTable(uint32_t offset) const;
186 typedef std::map<uint32_t, LineTable> LineTableMapTy;
187 typedef LineTableMapTy::iterator LineTableIter;
188 typedef LineTableMapTy::const_iterator LineTableConstIter;
190 LineTableMapTy LineTableMap;