comparison lib/DebugInfo/DWARFDebugLine.h @ 77:54457678186b LLVM3.6

LLVM 3.6
author Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
date Mon, 08 Sep 2014 22:06:00 +0900
parents 95c75e76d11b
children
comparison
equal deleted inserted replaced
34:e874dbf0ad9d 77:54457678186b
5 // This file is distributed under the University of Illinois Open Source 5 // This file is distributed under the University of Illinois Open Source
6 // License. See LICENSE.TXT for details. 6 // License. See LICENSE.TXT for details.
7 // 7 //
8 //===----------------------------------------------------------------------===// 8 //===----------------------------------------------------------------------===//
9 9
10 #ifndef LLVM_DEBUGINFO_DWARFDEBUGLINE_H 10 #ifndef LLVM_LIB_DEBUGINFO_DWARFDEBUGLINE_H
11 #define LLVM_DEBUGINFO_DWARFDEBUGLINE_H 11 #define LLVM_LIB_DEBUGINFO_DWARFDEBUGLINE_H
12 12
13 #include "DWARFRelocMap.h" 13 #include "DWARFRelocMap.h"
14 #include "llvm/DebugInfo/DIContext.h"
14 #include "llvm/Support/DataExtractor.h" 15 #include "llvm/Support/DataExtractor.h"
15 #include <map> 16 #include <map>
16 #include <string> 17 #include <string>
17 #include <vector> 18 #include <vector>
18 19
22 23
23 class DWARFDebugLine { 24 class DWARFDebugLine {
24 public: 25 public:
25 DWARFDebugLine(const RelocAddrMap* LineInfoRelocMap) : RelocMap(LineInfoRelocMap) {} 26 DWARFDebugLine(const RelocAddrMap* LineInfoRelocMap) : RelocMap(LineInfoRelocMap) {}
26 struct FileNameEntry { 27 struct FileNameEntry {
27 FileNameEntry() : Name(0), DirIdx(0), ModTime(0), Length(0) {} 28 FileNameEntry() : Name(nullptr), DirIdx(0), ModTime(0), Length(0) {}
28 29
29 const char *Name; 30 const char *Name;
30 uint64_t DirIdx; 31 uint64_t DirIdx;
31 uint64_t ModTime; 32 uint64_t ModTime;
32 uint64_t Length; 33 uint64_t Length;
33 }; 34 };
34 35
35 struct Prologue { 36 struct Prologue {
36 Prologue() 37 Prologue();
37 : TotalLength(0), Version(0), PrologueLength(0), MinInstLength(0),
38 DefaultIsStmt(0), LineBase(0), LineRange(0), OpcodeBase(0) {}
39 38
40 // The size in bytes of the statement information for this compilation unit 39 // The size in bytes of the statement information for this compilation unit
41 // (not including the total_length field itself). 40 // (not including the total_length field itself).
42 uint32_t TotalLength; 41 uint32_t TotalLength;
43 // Version identifier for the statement information format. 42 // Version identifier for the statement information format.
47 uint32_t PrologueLength; 46 uint32_t PrologueLength;
48 // The size in bytes of the smallest target machine instruction. Statement 47 // The size in bytes of the smallest target machine instruction. Statement
49 // program opcodes that alter the address register first multiply their 48 // program opcodes that alter the address register first multiply their
50 // operands by this value. 49 // operands by this value.
51 uint8_t MinInstLength; 50 uint8_t MinInstLength;
51 // The maximum number of individual operations that may be encoded in an
52 // instruction.
53 uint8_t MaxOpsPerInst;
52 // The initial value of theis_stmtregister. 54 // The initial value of theis_stmtregister.
53 uint8_t DefaultIsStmt; 55 uint8_t DefaultIsStmt;
54 // This parameter affects the meaning of the special opcodes. See below. 56 // This parameter affects the meaning of the special opcodes. See below.
55 int8_t LineBase; 57 int8_t LineBase;
56 // This parameter affects the meaning of the special opcodes. See below. 58 // This parameter affects the meaning of the special opcodes. See below.
71 return TotalLength + sizeof(TotalLength) - getLength(); 73 return TotalLength + sizeof(TotalLength) - getLength();
72 } 74 }
73 int32_t getMaxLineIncrementForSpecialOpcode() const { 75 int32_t getMaxLineIncrementForSpecialOpcode() const {
74 return LineBase + (int8_t)LineRange - 1; 76 return LineBase + (int8_t)LineRange - 1;
75 } 77 }
78
79 void clear();
76 void dump(raw_ostream &OS) const; 80 void dump(raw_ostream &OS) const;
77 void clear() { 81 bool parse(DataExtractor debug_line_data, uint32_t *offset_ptr);
78 TotalLength = Version = PrologueLength = 0;
79 MinInstLength = LineBase = LineRange = OpcodeBase = 0;
80 StandardOpcodeLengths.clear();
81 IncludeDirectories.clear();
82 FileNames.clear();
83 }
84 }; 82 };
85 83
86 // Standard .debug_line state machine structure. 84 // Standard .debug_line state machine structure.
87 struct Row { 85 struct Row {
88 Row(bool default_is_stmt = false) { reset(default_is_stmt); } 86 explicit Row(bool default_is_stmt = false);
87
89 /// Called after a row is appended to the matrix. 88 /// Called after a row is appended to the matrix.
90 void postAppend(); 89 void postAppend();
91 void reset(bool default_is_stmt); 90 void reset(bool default_is_stmt);
92 void dump(raw_ostream &OS) const; 91 void dump(raw_ostream &OS) const;
93 92
110 // corresponding to a machine instruction. 109 // corresponding to a machine instruction.
111 uint16_t File; 110 uint16_t File;
112 // An unsigned integer whose value encodes the applicable instruction set 111 // An unsigned integer whose value encodes the applicable instruction set
113 // architecture for the current instruction. 112 // architecture for the current instruction.
114 uint8_t Isa; 113 uint8_t Isa;
114 // An unsigned integer representing the DWARF path discriminator value
115 // for this location.
116 uint32_t Discriminator;
115 // A boolean indicating that the current instruction is the beginning of a 117 // A boolean indicating that the current instruction is the beginning of a
116 // statement. 118 // statement.
117 uint8_t IsStmt:1, 119 uint8_t IsStmt:1,
118 // A boolean indicating that the current instruction is the 120 // A boolean indicating that the current instruction is the
119 // beginning of a basic block. 121 // beginning of a basic block.
142 uint64_t HighPC; 144 uint64_t HighPC;
143 unsigned FirstRowIndex; 145 unsigned FirstRowIndex;
144 unsigned LastRowIndex; 146 unsigned LastRowIndex;
145 bool Empty; 147 bool Empty;
146 148
147 Sequence() { reset(); } 149 Sequence();
148 void reset() { 150 void reset();
149 LowPC = 0; 151
150 HighPC = 0;
151 FirstRowIndex = 0;
152 LastRowIndex = 0;
153 Empty = true;
154 }
155 static bool orderByLowPC(const Sequence& LHS, const Sequence& RHS) { 152 static bool orderByLowPC(const Sequence& LHS, const Sequence& RHS) {
156 return LHS.LowPC < RHS.LowPC; 153 return LHS.LowPC < RHS.LowPC;
157 } 154 }
158 bool isValid() const { 155 bool isValid() const {
159 return !Empty && (LowPC < HighPC) && (FirstRowIndex < LastRowIndex); 156 return !Empty && (LowPC < HighPC) && (FirstRowIndex < LastRowIndex);
162 return (LowPC <= pc && pc < HighPC); 159 return (LowPC <= pc && pc < HighPC);
163 } 160 }
164 }; 161 };
165 162
166 struct LineTable { 163 struct LineTable {
167 void appendRow(const DWARFDebugLine::Row &state) { Rows.push_back(state); } 164 LineTable();
168 void appendSequence(const DWARFDebugLine::Sequence &sequence) { 165
169 Sequences.push_back(sequence); 166 void appendRow(const DWARFDebugLine::Row &R) {
170 } 167 Rows.push_back(R);
171 void clear() { 168 }
172 Prologue.clear(); 169 void appendSequence(const DWARFDebugLine::Sequence &S) {
173 Rows.clear(); 170 Sequences.push_back(S);
174 Sequences.clear();
175 } 171 }
176 172
177 // Returns the index of the row with file/line info for a given address, 173 // Returns the index of the row with file/line info for a given address,
178 // or -1 if there is no such row. 174 // or -1 if there is no such row.
179 uint32_t lookupAddress(uint64_t address) const; 175 uint32_t lookupAddress(uint64_t address) const;
180 176
181 bool lookupAddressRange(uint64_t address, 177 bool lookupAddressRange(uint64_t address, uint64_t size,
182 uint64_t size, 178 std::vector<uint32_t> &result) const;
183 std::vector<uint32_t>& result) const;
184 179
185 // Extracts filename by its index in filename table in prologue. 180 // Extracts filename by its index in filename table in prologue.
186 // Returns true on success. 181 // Returns true on success.
187 bool getFileNameByIndex(uint64_t FileIndex, 182 bool getFileNameByIndex(uint64_t FileIndex,
188 bool NeedsAbsoluteFilePath, 183 DILineInfoSpecifier::FileLineInfoKind Kind,
189 std::string &Result) const; 184 std::string &Result) const;
190 185
191 void dump(raw_ostream &OS) const; 186 void dump(raw_ostream &OS) const;
187 void clear();
188
189 /// Parse prologue and all rows.
190 bool parse(DataExtractor debug_line_data, const RelocAddrMap *RMap,
191 uint32_t *offset_ptr);
192 192
193 struct Prologue Prologue; 193 struct Prologue Prologue;
194 typedef std::vector<Row> RowVector; 194 typedef std::vector<Row> RowVector;
195 typedef RowVector::const_iterator RowIter; 195 typedef RowVector::const_iterator RowIter;
196 typedef std::vector<Sequence> SequenceVector; 196 typedef std::vector<Sequence> SequenceVector;
197 typedef SequenceVector::const_iterator SequenceIter; 197 typedef SequenceVector::const_iterator SequenceIter;
198 RowVector Rows; 198 RowVector Rows;
199 SequenceVector Sequences; 199 SequenceVector Sequences;
200 }; 200 };
201 201
202 struct State : public Row, public Sequence, public LineTable {
203 // Special row codes.
204 enum {
205 StartParsingLineTable = 0,
206 DoneParsingLineTable = -1
207 };
208
209 State() : row(StartParsingLineTable) {}
210 virtual ~State();
211
212 virtual void appendRowToMatrix(uint32_t offset);
213 virtual void finalize();
214 virtual void reset() {
215 Row::reset(Prologue.DefaultIsStmt);
216 Sequence::reset();
217 }
218
219 // The row number that starts at zero for the prologue, and increases for
220 // each row added to the matrix.
221 unsigned row;
222 };
223
224 struct DumpingState : public State {
225 DumpingState(raw_ostream &OS) : OS(OS) {}
226 virtual ~DumpingState();
227 virtual void finalize();
228 private:
229 raw_ostream &OS;
230 };
231
232 static bool parsePrologue(DataExtractor debug_line_data, uint32_t *offset_ptr,
233 Prologue *prologue);
234 /// Parse a single line table (prologue and all rows).
235 static bool parseStatementTable(DataExtractor debug_line_data,
236 const RelocAddrMap *RMap,
237 uint32_t *offset_ptr, State &state);
238
239 const LineTable *getLineTable(uint32_t offset) const; 202 const LineTable *getLineTable(uint32_t offset) const;
240 const LineTable *getOrParseLineTable(DataExtractor debug_line_data, 203 const LineTable *getOrParseLineTable(DataExtractor debug_line_data,
241 uint32_t offset); 204 uint32_t offset);
242 205
243 private: 206 private:
207 struct ParsingState {
208 ParsingState(struct LineTable *LT);
209
210 void resetRowAndSequence();
211 void appendRowToMatrix(uint32_t offset);
212
213 // Line table we're currently parsing.
214 struct LineTable *LineTable;
215 // The row number that starts at zero for the prologue, and increases for
216 // each row added to the matrix.
217 unsigned RowNumber;
218 struct Row Row;
219 struct Sequence Sequence;
220 };
221
244 typedef std::map<uint32_t, LineTable> LineTableMapTy; 222 typedef std::map<uint32_t, LineTable> LineTableMapTy;
245 typedef LineTableMapTy::iterator LineTableIter; 223 typedef LineTableMapTy::iterator LineTableIter;
246 typedef LineTableMapTy::const_iterator LineTableConstIter; 224 typedef LineTableMapTy::const_iterator LineTableConstIter;
247 225
248 const RelocAddrMap *RelocMap; 226 const RelocAddrMap *RelocMap;