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 SymbolFileDWARF_DWARFDebugLine_h_
11 #define SymbolFileDWARF_DWARFDebugLine_h_
17 #include "lldb/lldb-private.h"
19 #include "DWARFDataExtractor.h"
20 #include "DWARFDefines.h"
22 #include "llvm/Support/MD5.h"
25 class SymbolFileDWARF;
27 //----------------------------------------------------------------------
29 //----------------------------------------------------------------------
30 class DWARFDebugLine {
32 //------------------------------------------------------------------
34 //------------------------------------------------------------------
35 struct FileNameEntry {
36 FileNameEntry() : name(nullptr), dir_idx(0), mod_time(0), length(0) {}
40 dw_sleb128_t mod_time;
42 llvm::MD5::MD5Result checksum;
45 //------------------------------------------------------------------
47 //------------------------------------------------------------------
51 : total_length(0), version(0), prologue_length(0), min_inst_length(0),
52 default_is_stmt(0), line_base(0), line_range(0), opcode_base(0),
53 standard_opcode_lengths(), include_directories(), file_names() {}
55 typedef std::shared_ptr<Prologue> shared_ptr;
57 uint32_t total_length; // The size in bytes of the statement information for
58 // this compilation unit (not including the
59 // total_length field itself).
61 version; // Version identifier for the statement information format.
64 uint8_t segment_selector_size;
66 uint32_t prologue_length; // The number of bytes following the
67 // prologue_length field to the beginning of the
68 // first byte of the statement program itself.
69 uint8_t min_inst_length; // The size in bytes of the smallest target machine
70 // instruction. Statement program opcodes that
71 // alter the address register first multiply their
72 // operands by this value.
73 uint8_t maximum_operations_per_instruction; // New in DWARF4. The maximum
74 // number of individual
75 // operations that may be
76 // encoded in an instruction.
77 uint8_t default_is_stmt; // The initial value of theis_stmtregister.
78 int8_t line_base; // This parameter affects the meaning of the special
79 // opcodes. See below.
80 uint8_t line_range; // This parameter affects the meaning of the special
81 // opcodes. See below.
82 uint8_t opcode_base; // The number assigned to the first special opcode.
83 std::vector<uint8_t> standard_opcode_lengths;
84 std::vector<const char *> include_directories;
85 std::vector<FileNameEntry> file_names;
87 int32_t MaxLineIncrementForSpecialOpcode() const {
88 return line_base + (int8_t)line_range - 1;
91 // void Append(BinaryStreamBuf& buff) const;
92 void Dump(lldb_private::Log *log);
94 total_length = version = prologue_length = min_inst_length = line_base =
95 line_range = opcode_base = 0;
97 standard_opcode_lengths.clear();
98 include_directories.clear();
101 bool GetFile(uint32_t file_idx, const lldb_private::FileSpec &cu_comp_dir,
102 lldb_private::FileSpec &file) const;
105 // Standard .debug_line state machine structure
107 typedef std::vector<Row> collection;
108 typedef collection::iterator iterator;
109 typedef collection::const_iterator const_iterator;
111 Row(bool default_is_stmt = false);
114 void Reset(bool default_is_stmt);
115 void Dump(lldb_private::Log *log) const;
116 static void Insert(Row::collection &state_coll, const Row &state);
117 static void Dump(lldb_private::Log *log, const Row::collection &state_coll);
119 dw_addr_t address; // The program-counter value corresponding to a machine
120 // instruction generated by the compiler.
121 uint32_t line; // An unsigned integer indicating a source line number. Lines
122 // are numbered beginning at 1. The compiler may emit the
123 // value 0 in cases where an instruction cannot be attributed
124 // to any source line.
125 uint16_t column; // An unsigned integer indicating a column number within a
126 // source line. Columns are numbered beginning at 1. The
127 // value 0 is reserved to indicate that a statement begins
128 // at the 'left edge' of the line.
129 uint16_t file; // An unsigned integer indicating the identity of the source
130 // file corresponding to a machine instruction.
131 uint8_t is_stmt : 1, // A boolean indicating that the current instruction is
132 // the beginning of a statement.
133 basic_block : 1, // A boolean indicating that the current instruction is
134 // the beginning of a basic block.
135 end_sequence : 1, // A boolean indicating that the current address is
136 // that of the first byte after the end of a sequence
137 // of target machine instructions.
138 prologue_end : 1, // A boolean indicating that the current address is
139 // one (of possibly many) where execution should be
140 // suspended for an entry breakpoint of a function.
141 epilogue_begin : 1; // A boolean indicating that the current address is
142 // one (of possibly many) where execution should be
143 // suspended for an exit breakpoint of a function.
144 uint32_t isa; // An unsigned integer whose value encodes the applicable
145 // instruction set architecture for the current instruction.
148 //------------------------------------------------------------------
150 //------------------------------------------------------------------
152 typedef std::shared_ptr<LineTable> shared_ptr;
154 LineTable() : prologue(), rows() {}
156 void AppendRow(const DWARFDebugLine::Row &state);
162 uint32_t LookupAddress(dw_addr_t address, dw_addr_t cu_high_pc) const;
163 void Dump(lldb_private::Log *log) const;
165 Prologue::shared_ptr prologue;
166 Row::collection rows;
169 //------------------------------------------------------------------
171 //------------------------------------------------------------------
172 struct State : public Row {
173 typedef void (*Callback)(dw_offset_t offset, const State &state,
176 // Special row codes used when calling the callback
177 enum { StartParsingLineTable = 0, DoneParsingLineTable = -1 };
179 State(Prologue::shared_ptr &prologue_sp, lldb_private::Log *log,
180 Callback callback, void *userData);
182 void AppendRowToMatrix(dw_offset_t offset);
184 void Finalize(dw_offset_t offset);
188 Prologue::shared_ptr prologue;
189 lldb_private::Log *log;
190 Callback callback; // Callback function that gets called each time an entry
191 // is to be added to the matrix
192 void *callbackUserData;
193 int row; // The row number that starts at zero for the prologue, and
194 // increases for each row added to the matrix
196 DISALLOW_COPY_AND_ASSIGN(State);
199 static bool DumpOpcodes(
200 lldb_private::Log *log, SymbolFileDWARF *dwarf2Data,
201 dw_offset_t line_offset = DW_INVALID_OFFSET,
202 uint32_t dump_flags = 0); // If line_offset is invalid, dump everything
203 static bool DumpLineTableRows(
204 lldb_private::Log *log, SymbolFileDWARF *dwarf2Data,
205 dw_offset_t line_offset =
206 DW_INVALID_OFFSET); // If line_offset is invalid, dump everything
208 ParseSupportFiles(const lldb::ModuleSP &module_sp,
209 const lldb_private::DWARFDataExtractor &debug_line_data,
210 const lldb_private::FileSpec &cu_comp_dir,
211 dw_offset_t stmt_list,
212 lldb_private::FileSpecList &support_files, DWARFUnit *dwarf_cu);
214 ParsePrologue(const lldb_private::DWARFDataExtractor &debug_line_data,
215 lldb::offset_t *offset_ptr, Prologue *prologue,
216 DWARFUnit *dwarf_cu = nullptr);
218 ParseStatementTable(const lldb_private::DWARFDataExtractor &debug_line_data,
219 lldb::offset_t *offset_ptr, State::Callback callback,
220 void *userData, DWARFUnit *dwarf_cu);
222 DumpStatementTable(lldb_private::Log *log,
223 const lldb_private::DWARFDataExtractor &debug_line_data,
224 const dw_offset_t line_offset);
226 DumpStatementOpcodes(lldb_private::Log *log,
227 const lldb_private::DWARFDataExtractor &debug_line_data,
228 const dw_offset_t line_offset, uint32_t flags);
230 ParseStatementTable(const lldb_private::DWARFDataExtractor &debug_line_data,
231 lldb::offset_t *offset_ptr, LineTable *line_table,
232 DWARFUnit *dwarf_cu);
233 static void Parse(const lldb_private::DWARFDataExtractor &debug_line_data,
234 DWARFDebugLine::State::Callback callback, void *userData);
235 // static void AppendLineTableData(const DWARFDebugLine::Prologue* prologue,
236 // const DWARFDebugLine::Row::collection& state_coll, const uint32_t
237 // addr_size, BinaryStreamBuf &debug_line_data);
239 DWARFDebugLine() : m_lineTableMap() {}
241 void Parse(const lldb_private::DWARFDataExtractor &debug_line_data);
242 void ParseIfNeeded(const lldb_private::DWARFDataExtractor &debug_line_data);
243 LineTable::shared_ptr GetLineTable(const dw_offset_t offset) const;
246 typedef std::map<dw_offset_t, LineTable::shared_ptr> LineTableMap;
247 typedef LineTableMap::iterator LineTableIter;
248 typedef LineTableMap::const_iterator LineTableConstIter;
250 LineTableMap m_lineTableMap;
253 #endif // SymbolFileDWARF_DWARFDebugLine_h_