17 using namespace dwarf;
25 TotalLength =
Version = PrologueLength = 0;
26 MinInstLength = MaxOpsPerInst = DefaultIsStmt = LineBase = LineRange = 0;
29 StandardOpcodeLengths.clear();
30 IncludeDirectories.clear();
35 OS <<
"Line table prologue:\n"
36 <<
format(
" total_length: 0x%8.8" PRIx64
"\n", TotalLength)
38 <<
format(
" prologue_length: 0x%8.8" PRIx64
"\n", PrologueLength)
39 <<
format(
" min_inst_length: %u\n", MinInstLength)
40 <<
format(
Version >= 4 ?
"max_ops_per_inst: %u\n" :
"", MaxOpsPerInst)
41 <<
format(
" default_is_stmt: %u\n", DefaultIsStmt)
42 <<
format(
" line_base: %i\n", LineBase)
43 <<
format(
" line_range: %u\n", LineRange)
44 <<
format(
" opcode_base: %u\n", OpcodeBase);
46 for (uint32_t i = 0; i < StandardOpcodeLengths.size(); ++i)
48 StandardOpcodeLengths[i]);
50 if (!IncludeDirectories.empty())
51 for (uint32_t i = 0; i < IncludeDirectories.size(); ++i)
52 OS <<
format(
"include_directories[%3u] = '", i+1)
53 << IncludeDirectories[i] <<
"'\n";
55 if (!FileNames.empty()) {
56 OS <<
" Dir Mod Time File Len File Name\n"
57 <<
" ---- ---------- ---------- -----------"
59 for (uint32_t i = 0; i < FileNames.size(); ++i) {
61 OS <<
format(
"file_names[%3u] %4" PRIu64
" ", i+1, fileEntry.
DirIdx)
62 <<
format(
"0x%8.8" PRIx64
" 0x%8.8" PRIx64
" ",
64 << fileEntry.
Name <<
'\n';
70 uint32_t *offset_ptr) {
71 const uint64_t prologue_offset = *offset_ptr;
74 TotalLength = debug_line_data.
getU32(offset_ptr);
75 if (TotalLength == UINT32_MAX) {
77 TotalLength = debug_line_data.
getU64(offset_ptr);
78 }
else if (TotalLength > 0xffffff00) {
85 PrologueLength = debug_line_data.
getUnsigned(offset_ptr,
86 sizeofPrologueLength());
87 const uint64_t end_prologue_offset = PrologueLength + *offset_ptr;
88 MinInstLength = debug_line_data.
getU8(offset_ptr);
90 MaxOpsPerInst = debug_line_data.
getU8(offset_ptr);
91 DefaultIsStmt = debug_line_data.
getU8(offset_ptr);
92 LineBase = debug_line_data.
getU8(offset_ptr);
93 LineRange = debug_line_data.
getU8(offset_ptr);
94 OpcodeBase = debug_line_data.
getU8(offset_ptr);
96 StandardOpcodeLengths.reserve(OpcodeBase - 1);
97 for (uint32_t i = 1; i < OpcodeBase; ++i) {
98 uint8_t op_len = debug_line_data.
getU8(offset_ptr);
99 StandardOpcodeLengths.push_back(op_len);
102 while (*offset_ptr < end_prologue_offset) {
103 const char *s = debug_line_data.
getCStr(offset_ptr);
105 IncludeDirectories.push_back(s);
110 while (*offset_ptr < end_prologue_offset) {
111 const char *
name = debug_line_data.
getCStr(offset_ptr);
112 if (name && name[0]) {
118 FileNames.push_back(fileEntry);
124 if (*offset_ptr != end_prologue_offset) {
125 fprintf(stderr,
"warning: parsing line table prologue at 0x%8.8" PRIx64
126 " should have ended at 0x%8.8" PRIx64
127 " but it ended at 0x%8.8" PRIx64
"\n",
128 prologue_offset, end_prologue_offset, (uint64_t)*offset_ptr);
135 reset(default_is_stmt);
141 EpilogueBegin =
false;
151 IsStmt = default_is_stmt;
155 EpilogueBegin =
false;
159 OS <<
format(
"0x%16.16" PRIx64
" %6u %6u",
Address, Line, Column)
160 <<
format(
" %6u %3u %13u ",
File, Isa, Discriminator)
161 << (IsStmt ?
" is_stmt" :
"")
163 << (PrologueEnd ?
" prologue_end" :
"")
164 << (EpilogueBegin ?
" epilogue_begin" :
"")
165 << (EndSequence ?
" end_sequence" :
"")
190 OS <<
"Address Line Column File ISA Discriminator Flags\n"
191 <<
"------------------ ------ ------ ------ --- ------------- "
193 for (
const Row &R : Rows) {
205 DWARFDebugLine::ParsingState::ParsingState(
struct LineTable *
LT)
207 resetRowAndSequence();
210 void DWARFDebugLine::ParsingState::resetRowAndSequence() {
211 Row.reset(LineTable->Prologue.DefaultIsStmt);
215 void DWARFDebugLine::ParsingState::appendRowToMatrix(uint32_t offset) {
223 LineTable->appendRow(Row);
224 if (Row.EndSequence) {
229 LineTable->appendSequence(
Sequence);
237 LineTableConstIter pos = LineTableMap.find(offset);
238 if (pos != LineTableMap.end())
246 std::pair<LineTableIter, bool> pos =
247 LineTableMap.insert(LineTableMapTy::value_type(offset,
LineTable()));
250 if (!LT->
parse(debug_line_data, RelocMap, &offset))
258 uint32_t *offset_ptr) {
259 const uint32_t debug_line_offset = *offset_ptr;
265 *offset_ptr = debug_line_offset;
272 ParsingState State(
this);
274 while (*offset_ptr < end_offset) {
275 uint8_t opcode = debug_line_data.
getU8(offset_ptr);
280 uint32_t ext_offset = *offset_ptr;
281 uint64_t len = debug_line_data.
getULEB128(offset_ptr);
282 uint32_t arg_size = len - (*offset_ptr - ext_offset);
284 uint8_t sub_opcode = debug_line_data.
getU8(offset_ptr);
285 switch (sub_opcode) {
294 State.Row.EndSequence =
true;
295 State.appendRowToMatrix(*offset_ptr);
296 State.resetRowAndSequence();
309 if (AI != RMap->
end()) {
310 const std::pair<uint8_t, int64_t> &R = AI->second;
312 debug_line_data.
getAddress(offset_ptr) + R.second;
314 State.Row.Address = debug_line_data.
getAddress(offset_ptr);
341 fileEntry.
Name = debug_line_data.
getCStr(offset_ptr);
350 State.Row.Discriminator = debug_line_data.
getULEB128(offset_ptr);
356 (*offset_ptr) += arg_size;
366 State.appendRowToMatrix(*offset_ptr);
380 State.Row.Line += debug_line_data.
getSLEB128(offset_ptr);
386 State.Row.File = debug_line_data.
getULEB128(offset_ptr);
392 State.Row.Column = debug_line_data.
getULEB128(offset_ptr);
398 State.Row.IsStmt = !State.Row.IsStmt;
404 State.Row.BasicBlock =
true;
421 uint64_t addr_offset =
423 State.Row.Address += addr_offset;
437 State.Row.Address += debug_line_data.
getU16(offset_ptr);
443 State.Row.PrologueEnd =
true;
449 State.Row.EpilogueBegin =
true;
455 State.Row.Isa = debug_line_data.
getULEB128(offset_ptr);
465 for (uint8_t i = 0; i < opcode_length; ++i)
505 uint64_t addr_offset =
507 int32_t line_offset =
509 State.Row.Line += line_offset;
510 State.Row.Address += addr_offset;
511 State.appendRowToMatrix(*offset_ptr);
515 if (!State.Sequence.Empty) {
516 fprintf(stderr,
"warning: last sequence in debug line table is not"
521 if (!Sequences.empty()) {
536 uint64_t address)
const {
538 return UnknownRowIndex;
548 if (row_pos == last_row) {
552 if (row_pos->Address > address) {
553 if (row_pos == first_row)
554 return UnknownRowIndex;
562 if (Sequences.empty())
563 return UnknownRowIndex;
566 sequence.
LowPC = address;
569 SequenceIter seq_pos = std::lower_bound(first_seq, last_seq, sequence,
572 if (seq_pos == last_seq) {
573 found_seq = Sequences.back();
574 }
else if (seq_pos->LowPC == address) {
575 found_seq = *seq_pos;
577 if (seq_pos == first_seq)
578 return UnknownRowIndex;
579 found_seq = *(seq_pos - 1);
581 return findRowInSeq(found_seq, address);
585 uint64_t address, uint64_t
size, std::vector<uint32_t> &result)
const {
586 if (Sequences.empty())
588 uint64_t end_addr = address +
size;
591 sequence.
LowPC = address;
594 SequenceIter seq_pos = std::lower_bound(first_seq, last_seq, sequence,
596 if (seq_pos == last_seq || seq_pos->LowPC != address) {
597 if (seq_pos == first_seq)
601 if (!seq_pos->containsPC(address))
609 while (seq_pos != last_seq && seq_pos->LowPC < end_addr) {
614 if (seq_pos == start_pos)
615 first_row_index = findRowInSeq(cur_seq, address);
618 uint32_t last_row_index = findRowInSeq(cur_seq, end_addr - 1);
619 if (last_row_index == UnknownRowIndex)
622 assert(first_row_index != UnknownRowIndex);
623 assert(last_row_index != UnknownRowIndex);
625 for (uint32_t i = first_row_index; i <= last_row_index; ++i) {
639 std::string &Result)
const {
644 const char *FileName = Entry.
Name;
645 if (Kind != FileLineInfoKind::AbsoluteFilePath ||
652 uint64_t IncludeDirIndex = Entry.
DirIdx;
653 const char *IncludeDir =
"";
655 if (IncludeDirIndex > 0 &&
662 if (CompDir && Kind == FileLineInfoKind::AbsoluteFilePath &&
668 Result = FilePath.
str();
678 uint32_t RowIndex = lookupAddress(Address);
682 const auto &
Row = Rows[RowIndex];
RowVector::const_iterator RowIter
bool is_relative(const Twine &path)
Is path relative?
static bool orderByAddress(const Row &LHS, const Row &RHS)
bool getFileNameByIndex(uint64_t FileIndex, const char *CompDir, DILineInfoSpecifier::FileLineInfoKind Kind, std::string &Result) const
SequenceVector::const_iterator SequenceIter
const LineTable * getLineTable(uint32_t offset) const
DILineInfo - a format-neutral container for source line information.
void append(SmallVectorImpl< char > &path, const Twine &a, const Twine &b="", const Twine &c="", const Twine &d="")
Append to path.
void postAppend()
Called after a row is appended to the matrix.
bool is_absolute(const Twine &path)
Is path absolute?
Row(bool default_is_stmt=false)
SmallString - A SmallString is just a SmallVector with methods and accessors that make it work better...
format_object< Ts...> format(const char *Fmt, const Ts &...Vals)
These are helper functions used to produce formatted output.
* if(!EatIfPresent(lltok::kw_thread_local)) return false
ParseOptionalThreadLocal := /*empty.
LLVM Basic Block Representation.
void dump(raw_ostream &OS) const
void dump(raw_ostream &OS) const
bool parse(DataExtractor debug_line_data, uint32_t *offset_ptr)
void dump(raw_ostream &OS) const
bool parse(DataExtractor debug_line_data, const RelocAddrMap *RMap, uint32_t *offset_ptr)
Parse prologue and all rows.
const LineTable * getOrParseLineTable(DataExtractor debug_line_data, uint32_t offset)
bool lookupAddressRange(uint64_t address, uint64_t size, std::vector< uint32_t > &result) const
uint32_t lookupAddress(uint64_t address) const
std::vector< const char * > IncludeDirectories
const char * LNStandardString(unsigned Standard)
uint32_t sizeofTotalLength() const
std::vector< uint8_t > StandardOpcodeLengths
void reset(bool default_is_stmt)
StringRef str() const
Explicit conversion to StringRef.
bool containsPC(uint64_t pc) const
std::vector< FileNameEntry > FileNames
static bool orderByLowPC(const Sequence &LHS, const Sequence &RHS)
Sequence
A sequence of states that a pointer may go through in which an objc_retain and objc_release are actua...
iterator find(const KeyT &Val)
bool getFileLineInfoForAddress(uint64_t Address, const char *CompDir, DILineInfoSpecifier::FileLineInfoKind Kind, DILineInfo &Result) const
const ARM::ArchExtKind Kind
This class implements an extremely fast bulk output stream that can only output to a stream...
DILineInfoSpecifier::FileLineInfoKind FileLineInfoKind