LLDB  mainline
DWARFDebugLine.h
Go to the documentation of this file.
1 //===-- DWARFDebugLine.h ----------------------------------------*- C++ -*-===//
2 //
3 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4 // See https://llvm.org/LICENSE.txt for license information.
5 // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6 //
7 //===----------------------------------------------------------------------===//
8 
9 #ifndef SymbolFileDWARF_DWARFDebugLine_h_
10 #define SymbolFileDWARF_DWARFDebugLine_h_
11 
12 #include <map>
13 #include <string>
14 #include <vector>
15 
16 #include "lldb/Utility/FileSpec.h"
17 #include "lldb/lldb-private.h"
18 
19 #include "DWARFDataExtractor.h"
20 #include "DWARFDefines.h"
21 
22 #include "llvm/Support/MD5.h"
23 
24 class DWARFUnit;
25 class SymbolFileDWARF;
26 
27 // DWARFDebugLine
29 public:
30  // FileNameEntry
31  struct FileNameEntry {
32  FileNameEntry() : name(nullptr), dir_idx(0), mod_time(0), length(0) {}
33 
34  const char *name;
38  llvm::MD5::MD5Result checksum;
39  };
40 
41  // Prologue
42  struct Prologue {
43 
45  : total_length(0), version(0), prologue_length(0), min_inst_length(0),
46  default_is_stmt(0), line_base(0), line_range(0), opcode_base(0),
47  standard_opcode_lengths(), include_directories(), file_names() {}
48 
49  typedef std::shared_ptr<Prologue> shared_ptr;
50 
51  uint32_t total_length; // The size in bytes of the statement information for
52  // this compilation unit (not including the
53  // total_length field itself).
54  uint16_t
55  version; // Version identifier for the statement information format.
56 
57  uint8_t address_size;
59 
60  uint32_t prologue_length; // The number of bytes following the
61  // prologue_length field to the beginning of the
62  // first byte of the statement program itself.
63  uint8_t min_inst_length; // The size in bytes of the smallest target machine
64  // instruction. Statement program opcodes that
65  // alter the address register first multiply their
66  // operands by this value.
67  uint8_t maximum_operations_per_instruction; // New in DWARF4. The maximum
68  // number of individual
69  // operations that may be
70  // encoded in an instruction.
71  uint8_t default_is_stmt; // The initial value of theis_stmtregister.
72  int8_t line_base; // This parameter affects the meaning of the special
73  // opcodes. See below.
74  uint8_t line_range; // This parameter affects the meaning of the special
75  // opcodes. See below.
76  uint8_t opcode_base; // The number assigned to the first special opcode.
77  std::vector<uint8_t> standard_opcode_lengths;
78  std::vector<const char *> include_directories;
79  std::vector<FileNameEntry> file_names;
80 
82  return line_base + (int8_t)line_range - 1;
83  }
84  bool IsValid() const;
85  // void Append(BinaryStreamBuf& buff) const;
86  void Dump(lldb_private::Log *log);
87  void Clear() {
88  total_length = version = prologue_length = min_inst_length = line_base =
89  line_range = opcode_base = 0;
90  line_base = 0;
91  standard_opcode_lengths.clear();
92  include_directories.clear();
93  file_names.clear();
94  }
95  bool GetFile(uint32_t file_idx, const lldb_private::FileSpec &cu_comp_dir,
97  lldb_private::FileSpec &file) const;
98  };
99 
100  // Standard .debug_line state machine structure
101  struct Row {
102  typedef std::vector<Row> collection;
103  typedef collection::iterator iterator;
104  typedef collection::const_iterator const_iterator;
105 
106  Row(bool default_is_stmt = false);
107  virtual ~Row() {}
108  void PostAppend();
109  void Reset(bool default_is_stmt);
110  void Dump(lldb_private::Log *log) const;
111  static void Insert(Row::collection &state_coll, const Row &state);
112 
113  dw_addr_t address; // The program-counter value corresponding to a machine
114  // instruction generated by the compiler.
115  uint32_t line; // An unsigned integer indicating a source line number. Lines
116  // are numbered beginning at 1. The compiler may emit the
117  // value 0 in cases where an instruction cannot be attributed
118  // to any source line.
119  uint16_t column; // An unsigned integer indicating a column number within a
120  // source line. Columns are numbered beginning at 1. The
121  // value 0 is reserved to indicate that a statement begins
122  // at the 'left edge' of the line.
123  uint16_t file; // An unsigned integer indicating the identity of the source
124  // file corresponding to a machine instruction.
125  uint8_t is_stmt : 1, // A boolean indicating that the current instruction is
126  // the beginning of a statement.
127  basic_block : 1, // A boolean indicating that the current instruction is
128  // the beginning of a basic block.
129  end_sequence : 1, // A boolean indicating that the current address is
130  // that of the first byte after the end of a sequence
131  // of target machine instructions.
132  prologue_end : 1, // A boolean indicating that the current address is
133  // one (of possibly many) where execution should be
134  // suspended for an entry breakpoint of a function.
135  epilogue_begin : 1; // A boolean indicating that the current address is
136  // one (of possibly many) where execution should be
137  // suspended for an exit breakpoint of a function.
138  uint32_t isa; // An unsigned integer whose value encodes the applicable
139  // instruction set architecture for the current instruction.
140  };
141 
142  // LineTable
143  struct LineTable {
144  typedef std::shared_ptr<LineTable> shared_ptr;
145 
146  LineTable() : prologue(), rows() {}
147 
148  void AppendRow(const DWARFDebugLine::Row &state);
149  void Clear() {
150  prologue.reset();
151  rows.clear();
152  }
153 
154  uint32_t LookupAddress(dw_addr_t address, dw_addr_t cu_high_pc) const;
155 
158  };
159 
160  // State
161  struct State : public Row {
162  typedef void (*Callback)(dw_offset_t offset, const State &state,
163  void *userData);
164 
165  // Special row codes used when calling the callback
166  enum { StartParsingLineTable = 0, DoneParsingLineTable = -1 };
167 
168  State(Prologue::shared_ptr &prologue_sp, lldb_private::Log *log,
169  Callback callback, void *userData);
170 
171  void AppendRowToMatrix(dw_offset_t offset);
172 
173  void Finalize(dw_offset_t offset);
174 
175  void Reset();
176 
179  Callback callback; // Callback function that gets called each time an entry
180  // is to be added to the matrix
182  int row; // The row number that starts at zero for the prologue, and
183  // increases for each row added to the matrix
184  private:
185  DISALLOW_COPY_AND_ASSIGN(State);
186  };
187 
188  static bool
189  ParseSupportFiles(const lldb::ModuleSP &module_sp,
190  const lldb_private::DWARFDataExtractor &debug_line_data,
191  dw_offset_t stmt_list,
192  lldb_private::FileSpecList &support_files,
193  DWARFUnit *dwarf_cu);
194  static bool
195  ParsePrologue(const lldb_private::DWARFDataExtractor &debug_line_data,
196  lldb::offset_t *offset_ptr, Prologue *prologue,
197  DWARFUnit *dwarf_cu = nullptr);
198  static bool
200  lldb::offset_t *offset_ptr, State::Callback callback,
201  void *userData, DWARFUnit *dwarf_cu);
202  static bool
204  lldb::offset_t *offset_ptr, LineTable *line_table,
205  DWARFUnit *dwarf_cu);
206  static void Parse(const lldb_private::DWARFDataExtractor &debug_line_data,
207  DWARFDebugLine::State::Callback callback, void *userData);
208  // static void AppendLineTableData(const DWARFDebugLine::Prologue* prologue,
209  // const DWARFDebugLine::Row::collection& state_coll, const uint32_t
210  // addr_size, BinaryStreamBuf &debug_line_data);
211 
213 
214  void Parse(const lldb_private::DWARFDataExtractor &debug_line_data);
215  void ParseIfNeeded(const lldb_private::DWARFDataExtractor &debug_line_data);
216  LineTable::shared_ptr GetLineTable(const dw_offset_t offset) const;
217 
218 protected:
219  typedef std::map<dw_offset_t, LineTable::shared_ptr> LineTableMap;
220  typedef LineTableMap::iterator LineTableIter;
221  typedef LineTableMap::const_iterator LineTableConstIter;
222 
223  LineTableMap m_lineTableMap;
224 };
225 
226 #endif // SymbolFileDWARF_DWARFDebugLine_h_
static bool ParseStatementTable(const lldb_private::DWARFDataExtractor &debug_line_data, lldb::offset_t *offset_ptr, State::Callback callback, void *userData, DWARFUnit *dwarf_cu)
std::vector< const char * > include_directories
collection::const_iterator const_iterator
A file utility class.
Definition: FileSpec.h:55
void ParseIfNeeded(const lldb_private::DWARFDataExtractor &debug_line_data)
std::vector< uint8_t > standard_opcode_lengths
uint64_t dw_addr_t
Definition: dwarf.h:26
collection::iterator iterator
void(* Callback)(dw_offset_t offset, const State &state, void *userData)
std::vector< Row > collection
uint64_t offset_t
Definition: lldb-types.h:87
LineTableMap::const_iterator LineTableConstIter
uint8_t maximum_operations_per_instruction
static bool ParsePrologue(const lldb_private::DWARFDataExtractor &debug_line_data, lldb::offset_t *offset_ptr, Prologue *prologue, DWARFUnit *dwarf_cu=nullptr)
lldb_private::Log * log
std::shared_ptr< Prologue > shared_ptr
Prologue::shared_ptr prologue
std::shared_ptr< LineTable > shared_ptr
llvm::sys::path::Style Style
Definition: FileSpec.h:57
LineTable::shared_ptr GetLineTable(const dw_offset_t offset) const
LineTableMap::iterator LineTableIter
llvm::MD5::MD5Result checksum
int32_t MaxLineIncrementForSpecialOpcode() const
Prologue::shared_ptr prologue
int32_t dw_sleb128_t
Definition: dwarf.h:22
LineTableMap m_lineTableMap
static void Parse(const lldb_private::DWARFDataExtractor &debug_line_data, DWARFDebugLine::State::Callback callback, void *userData)
static bool ParseSupportFiles(const lldb::ModuleSP &module_sp, const lldb_private::DWARFDataExtractor &debug_line_data, dw_offset_t stmt_list, lldb_private::FileSpecList &support_files, DWARFUnit *dwarf_cu)
std::map< dw_offset_t, LineTable::shared_ptr > LineTableMap
std::vector< FileNameEntry > file_names