LLVM API Documentation
00001 //===-- DWARFDebugLine.cpp ------------------------------------------------===// 00002 // 00003 // The LLVM Compiler Infrastructure 00004 // 00005 // This file is distributed under the University of Illinois Open Source 00006 // License. See LICENSE.TXT for details. 00007 // 00008 //===----------------------------------------------------------------------===// 00009 00010 #include "DWARFDebugLine.h" 00011 #include "llvm/Support/Dwarf.h" 00012 #include "llvm/Support/Format.h" 00013 #include "llvm/Support/Path.h" 00014 #include "llvm/Support/raw_ostream.h" 00015 #include <algorithm> 00016 using namespace llvm; 00017 using namespace dwarf; 00018 00019 void DWARFDebugLine::Prologue::dump(raw_ostream &OS) const { 00020 OS << "Line table prologue:\n" 00021 << format(" total_length: 0x%8.8x\n", TotalLength) 00022 << format(" version: %u\n", Version) 00023 << format("prologue_length: 0x%8.8x\n", PrologueLength) 00024 << format("min_inst_length: %u\n", MinInstLength) 00025 << format("default_is_stmt: %u\n", DefaultIsStmt) 00026 << format(" line_base: %i\n", LineBase) 00027 << format(" line_range: %u\n", LineRange) 00028 << format(" opcode_base: %u\n", OpcodeBase); 00029 00030 for (uint32_t i = 0; i < StandardOpcodeLengths.size(); ++i) 00031 OS << format("standard_opcode_lengths[%s] = %u\n", LNStandardString(i+1), 00032 StandardOpcodeLengths[i]); 00033 00034 if (!IncludeDirectories.empty()) 00035 for (uint32_t i = 0; i < IncludeDirectories.size(); ++i) 00036 OS << format("include_directories[%3u] = '", i+1) 00037 << IncludeDirectories[i] << "'\n"; 00038 00039 if (!FileNames.empty()) { 00040 OS << " Dir Mod Time File Len File Name\n" 00041 << " ---- ---------- ---------- -----------" 00042 "----------------\n"; 00043 for (uint32_t i = 0; i < FileNames.size(); ++i) { 00044 const FileNameEntry& fileEntry = FileNames[i]; 00045 OS << format("file_names[%3u] %4" PRIu64 " ", i+1, fileEntry.DirIdx) 00046 << format("0x%8.8" PRIx64 " 0x%8.8" PRIx64 " ", 00047 fileEntry.ModTime, fileEntry.Length) 00048 << fileEntry.Name << '\n'; 00049 } 00050 } 00051 } 00052 00053 void DWARFDebugLine::Row::postAppend() { 00054 BasicBlock = false; 00055 PrologueEnd = false; 00056 EpilogueBegin = false; 00057 } 00058 00059 void DWARFDebugLine::Row::reset(bool default_is_stmt) { 00060 Address = 0; 00061 Line = 1; 00062 Column = 0; 00063 File = 1; 00064 Isa = 0; 00065 IsStmt = default_is_stmt; 00066 BasicBlock = false; 00067 EndSequence = false; 00068 PrologueEnd = false; 00069 EpilogueBegin = false; 00070 } 00071 00072 void DWARFDebugLine::Row::dump(raw_ostream &OS) const { 00073 OS << format("0x%16.16" PRIx64 " %6u %6u", Address, Line, Column) 00074 << format(" %6u %3u ", File, Isa) 00075 << (IsStmt ? " is_stmt" : "") 00076 << (BasicBlock ? " basic_block" : "") 00077 << (PrologueEnd ? " prologue_end" : "") 00078 << (EpilogueBegin ? " epilogue_begin" : "") 00079 << (EndSequence ? " end_sequence" : "") 00080 << '\n'; 00081 } 00082 00083 void DWARFDebugLine::LineTable::dump(raw_ostream &OS) const { 00084 Prologue.dump(OS); 00085 OS << '\n'; 00086 00087 if (!Rows.empty()) { 00088 OS << "Address Line Column File ISA Flags\n" 00089 << "------------------ ------ ------ ------ --- -------------\n"; 00090 for (std::vector<Row>::const_iterator pos = Rows.begin(), 00091 end = Rows.end(); pos != end; ++pos) 00092 pos->dump(OS); 00093 } 00094 } 00095 00096 DWARFDebugLine::State::~State() {} 00097 00098 void DWARFDebugLine::State::appendRowToMatrix(uint32_t offset) { 00099 if (Sequence::Empty) { 00100 // Record the beginning of instruction sequence. 00101 Sequence::Empty = false; 00102 Sequence::LowPC = Address; 00103 Sequence::FirstRowIndex = row; 00104 } 00105 ++row; // Increase the row number. 00106 LineTable::appendRow(*this); 00107 if (EndSequence) { 00108 // Record the end of instruction sequence. 00109 Sequence::HighPC = Address; 00110 Sequence::LastRowIndex = row; 00111 if (Sequence::isValid()) 00112 LineTable::appendSequence(*this); 00113 Sequence::reset(); 00114 } 00115 Row::postAppend(); 00116 } 00117 00118 void DWARFDebugLine::State::finalize() { 00119 row = DoneParsingLineTable; 00120 if (!Sequence::Empty) { 00121 fprintf(stderr, "warning: last sequence in debug line table is not" 00122 "terminated!\n"); 00123 } 00124 // Sort all sequences so that address lookup will work faster. 00125 if (!Sequences.empty()) { 00126 std::sort(Sequences.begin(), Sequences.end(), Sequence::orderByLowPC); 00127 // Note: actually, instruction address ranges of sequences should not 00128 // overlap (in shared objects and executables). If they do, the address 00129 // lookup would still work, though, but result would be ambiguous. 00130 // We don't report warning in this case. For example, 00131 // sometimes .so compiled from multiple object files contains a few 00132 // rudimentary sequences for address ranges [0x0, 0xsomething). 00133 } 00134 } 00135 00136 DWARFDebugLine::DumpingState::~DumpingState() {} 00137 00138 void DWARFDebugLine::DumpingState::finalize() { 00139 LineTable::dump(OS); 00140 } 00141 00142 const DWARFDebugLine::LineTable * 00143 DWARFDebugLine::getLineTable(uint32_t offset) const { 00144 LineTableConstIter pos = LineTableMap.find(offset); 00145 if (pos != LineTableMap.end()) 00146 return &pos->second; 00147 return 0; 00148 } 00149 00150 const DWARFDebugLine::LineTable * 00151 DWARFDebugLine::getOrParseLineTable(DataExtractor debug_line_data, 00152 uint32_t offset) { 00153 std::pair<LineTableIter, bool> pos = 00154 LineTableMap.insert(LineTableMapTy::value_type(offset, LineTable())); 00155 if (pos.second) { 00156 // Parse and cache the line table for at this offset. 00157 State state; 00158 if (!parseStatementTable(debug_line_data, RelocMap, &offset, state)) 00159 return 0; 00160 pos.first->second = state; 00161 } 00162 return &pos.first->second; 00163 } 00164 00165 bool 00166 DWARFDebugLine::parsePrologue(DataExtractor debug_line_data, 00167 uint32_t *offset_ptr, Prologue *prologue) { 00168 const uint32_t prologue_offset = *offset_ptr; 00169 00170 prologue->clear(); 00171 prologue->TotalLength = debug_line_data.getU32(offset_ptr); 00172 prologue->Version = debug_line_data.getU16(offset_ptr); 00173 if (prologue->Version != 2) 00174 return false; 00175 00176 prologue->PrologueLength = debug_line_data.getU32(offset_ptr); 00177 const uint32_t end_prologue_offset = prologue->PrologueLength + *offset_ptr; 00178 prologue->MinInstLength = debug_line_data.getU8(offset_ptr); 00179 prologue->DefaultIsStmt = debug_line_data.getU8(offset_ptr); 00180 prologue->LineBase = debug_line_data.getU8(offset_ptr); 00181 prologue->LineRange = debug_line_data.getU8(offset_ptr); 00182 prologue->OpcodeBase = debug_line_data.getU8(offset_ptr); 00183 00184 prologue->StandardOpcodeLengths.reserve(prologue->OpcodeBase-1); 00185 for (uint32_t i = 1; i < prologue->OpcodeBase; ++i) { 00186 uint8_t op_len = debug_line_data.getU8(offset_ptr); 00187 prologue->StandardOpcodeLengths.push_back(op_len); 00188 } 00189 00190 while (*offset_ptr < end_prologue_offset) { 00191 const char *s = debug_line_data.getCStr(offset_ptr); 00192 if (s && s[0]) 00193 prologue->IncludeDirectories.push_back(s); 00194 else 00195 break; 00196 } 00197 00198 while (*offset_ptr < end_prologue_offset) { 00199 const char *name = debug_line_data.getCStr(offset_ptr); 00200 if (name && name[0]) { 00201 FileNameEntry fileEntry; 00202 fileEntry.Name = name; 00203 fileEntry.DirIdx = debug_line_data.getULEB128(offset_ptr); 00204 fileEntry.ModTime = debug_line_data.getULEB128(offset_ptr); 00205 fileEntry.Length = debug_line_data.getULEB128(offset_ptr); 00206 prologue->FileNames.push_back(fileEntry); 00207 } else { 00208 break; 00209 } 00210 } 00211 00212 if (*offset_ptr != end_prologue_offset) { 00213 fprintf(stderr, "warning: parsing line table prologue at 0x%8.8x should" 00214 " have ended at 0x%8.8x but it ended ad 0x%8.8x\n", 00215 prologue_offset, end_prologue_offset, *offset_ptr); 00216 return false; 00217 } 00218 return true; 00219 } 00220 00221 bool 00222 DWARFDebugLine::parseStatementTable(DataExtractor debug_line_data, 00223 const RelocAddrMap *RMap, 00224 uint32_t *offset_ptr, State &state) { 00225 const uint32_t debug_line_offset = *offset_ptr; 00226 00227 Prologue *prologue = &state.Prologue; 00228 00229 if (!parsePrologue(debug_line_data, offset_ptr, prologue)) { 00230 // Restore our offset and return false to indicate failure! 00231 *offset_ptr = debug_line_offset; 00232 return false; 00233 } 00234 00235 const uint32_t end_offset = debug_line_offset + prologue->TotalLength + 00236 sizeof(prologue->TotalLength); 00237 00238 state.reset(); 00239 00240 while (*offset_ptr < end_offset) { 00241 uint8_t opcode = debug_line_data.getU8(offset_ptr); 00242 00243 if (opcode == 0) { 00244 // Extended Opcodes always start with a zero opcode followed by 00245 // a uleb128 length so you can skip ones you don't know about 00246 uint32_t ext_offset = *offset_ptr; 00247 uint64_t len = debug_line_data.getULEB128(offset_ptr); 00248 uint32_t arg_size = len - (*offset_ptr - ext_offset); 00249 00250 uint8_t sub_opcode = debug_line_data.getU8(offset_ptr); 00251 switch (sub_opcode) { 00252 case DW_LNE_end_sequence: 00253 // Set the end_sequence register of the state machine to true and 00254 // append a row to the matrix using the current values of the 00255 // state-machine registers. Then reset the registers to the initial 00256 // values specified above. Every statement program sequence must end 00257 // with a DW_LNE_end_sequence instruction which creates a row whose 00258 // address is that of the byte after the last target machine instruction 00259 // of the sequence. 00260 state.EndSequence = true; 00261 state.appendRowToMatrix(*offset_ptr); 00262 state.reset(); 00263 break; 00264 00265 case DW_LNE_set_address: 00266 // Takes a single relocatable address as an operand. The size of the 00267 // operand is the size appropriate to hold an address on the target 00268 // machine. Set the address register to the value given by the 00269 // relocatable address. All of the other statement program opcodes 00270 // that affect the address register add a delta to it. This instruction 00271 // stores a relocatable value into it instead. 00272 { 00273 // If this address is in our relocation map, apply the relocation. 00274 RelocAddrMap::const_iterator AI = RMap->find(*offset_ptr); 00275 if (AI != RMap->end()) { 00276 const std::pair<uint8_t, int64_t> &R = AI->second; 00277 state.Address = debug_line_data.getAddress(offset_ptr) + R.second; 00278 } else 00279 state.Address = debug_line_data.getAddress(offset_ptr); 00280 } 00281 break; 00282 00283 case DW_LNE_define_file: 00284 // Takes 4 arguments. The first is a null terminated string containing 00285 // a source file name. The second is an unsigned LEB128 number 00286 // representing the directory index of the directory in which the file 00287 // was found. The third is an unsigned LEB128 number representing the 00288 // time of last modification of the file. The fourth is an unsigned 00289 // LEB128 number representing the length in bytes of the file. The time 00290 // and length fields may contain LEB128(0) if the information is not 00291 // available. 00292 // 00293 // The directory index represents an entry in the include_directories 00294 // section of the statement program prologue. The index is LEB128(0) 00295 // if the file was found in the current directory of the compilation, 00296 // LEB128(1) if it was found in the first directory in the 00297 // include_directories section, and so on. The directory index is 00298 // ignored for file names that represent full path names. 00299 // 00300 // The files are numbered, starting at 1, in the order in which they 00301 // appear; the names in the prologue come before names defined by 00302 // the DW_LNE_define_file instruction. These numbers are used in the 00303 // the file register of the state machine. 00304 { 00305 FileNameEntry fileEntry; 00306 fileEntry.Name = debug_line_data.getCStr(offset_ptr); 00307 fileEntry.DirIdx = debug_line_data.getULEB128(offset_ptr); 00308 fileEntry.ModTime = debug_line_data.getULEB128(offset_ptr); 00309 fileEntry.Length = debug_line_data.getULEB128(offset_ptr); 00310 prologue->FileNames.push_back(fileEntry); 00311 } 00312 break; 00313 00314 default: 00315 // Length doesn't include the zero opcode byte or the length itself, but 00316 // it does include the sub_opcode, so we have to adjust for that below 00317 (*offset_ptr) += arg_size; 00318 break; 00319 } 00320 } else if (opcode < prologue->OpcodeBase) { 00321 switch (opcode) { 00322 // Standard Opcodes 00323 case DW_LNS_copy: 00324 // Takes no arguments. Append a row to the matrix using the 00325 // current values of the state-machine registers. Then set 00326 // the basic_block register to false. 00327 state.appendRowToMatrix(*offset_ptr); 00328 break; 00329 00330 case DW_LNS_advance_pc: 00331 // Takes a single unsigned LEB128 operand, multiplies it by the 00332 // min_inst_length field of the prologue, and adds the 00333 // result to the address register of the state machine. 00334 state.Address += debug_line_data.getULEB128(offset_ptr) * 00335 prologue->MinInstLength; 00336 break; 00337 00338 case DW_LNS_advance_line: 00339 // Takes a single signed LEB128 operand and adds that value to 00340 // the line register of the state machine. 00341 state.Line += debug_line_data.getSLEB128(offset_ptr); 00342 break; 00343 00344 case DW_LNS_set_file: 00345 // Takes a single unsigned LEB128 operand and stores it in the file 00346 // register of the state machine. 00347 state.File = debug_line_data.getULEB128(offset_ptr); 00348 break; 00349 00350 case DW_LNS_set_column: 00351 // Takes a single unsigned LEB128 operand and stores it in the 00352 // column register of the state machine. 00353 state.Column = debug_line_data.getULEB128(offset_ptr); 00354 break; 00355 00356 case DW_LNS_negate_stmt: 00357 // Takes no arguments. Set the is_stmt register of the state 00358 // machine to the logical negation of its current value. 00359 state.IsStmt = !state.IsStmt; 00360 break; 00361 00362 case DW_LNS_set_basic_block: 00363 // Takes no arguments. Set the basic_block register of the 00364 // state machine to true 00365 state.BasicBlock = true; 00366 break; 00367 00368 case DW_LNS_const_add_pc: 00369 // Takes no arguments. Add to the address register of the state 00370 // machine the address increment value corresponding to special 00371 // opcode 255. The motivation for DW_LNS_const_add_pc is this: 00372 // when the statement program needs to advance the address by a 00373 // small amount, it can use a single special opcode, which occupies 00374 // a single byte. When it needs to advance the address by up to 00375 // twice the range of the last special opcode, it can use 00376 // DW_LNS_const_add_pc followed by a special opcode, for a total 00377 // of two bytes. Only if it needs to advance the address by more 00378 // than twice that range will it need to use both DW_LNS_advance_pc 00379 // and a special opcode, requiring three or more bytes. 00380 { 00381 uint8_t adjust_opcode = 255 - prologue->OpcodeBase; 00382 uint64_t addr_offset = (adjust_opcode / prologue->LineRange) * 00383 prologue->MinInstLength; 00384 state.Address += addr_offset; 00385 } 00386 break; 00387 00388 case DW_LNS_fixed_advance_pc: 00389 // Takes a single uhalf operand. Add to the address register of 00390 // the state machine the value of the (unencoded) operand. This 00391 // is the only extended opcode that takes an argument that is not 00392 // a variable length number. The motivation for DW_LNS_fixed_advance_pc 00393 // is this: existing assemblers cannot emit DW_LNS_advance_pc or 00394 // special opcodes because they cannot encode LEB128 numbers or 00395 // judge when the computation of a special opcode overflows and 00396 // requires the use of DW_LNS_advance_pc. Such assemblers, however, 00397 // can use DW_LNS_fixed_advance_pc instead, sacrificing compression. 00398 state.Address += debug_line_data.getU16(offset_ptr); 00399 break; 00400 00401 case DW_LNS_set_prologue_end: 00402 // Takes no arguments. Set the prologue_end register of the 00403 // state machine to true 00404 state.PrologueEnd = true; 00405 break; 00406 00407 case DW_LNS_set_epilogue_begin: 00408 // Takes no arguments. Set the basic_block register of the 00409 // state machine to true 00410 state.EpilogueBegin = true; 00411 break; 00412 00413 case DW_LNS_set_isa: 00414 // Takes a single unsigned LEB128 operand and stores it in the 00415 // column register of the state machine. 00416 state.Isa = debug_line_data.getULEB128(offset_ptr); 00417 break; 00418 00419 default: 00420 // Handle any unknown standard opcodes here. We know the lengths 00421 // of such opcodes because they are specified in the prologue 00422 // as a multiple of LEB128 operands for each opcode. 00423 { 00424 assert(opcode - 1U < prologue->StandardOpcodeLengths.size()); 00425 uint8_t opcode_length = prologue->StandardOpcodeLengths[opcode - 1]; 00426 for (uint8_t i=0; i<opcode_length; ++i) 00427 debug_line_data.getULEB128(offset_ptr); 00428 } 00429 break; 00430 } 00431 } else { 00432 // Special Opcodes 00433 00434 // A special opcode value is chosen based on the amount that needs 00435 // to be added to the line and address registers. The maximum line 00436 // increment for a special opcode is the value of the line_base 00437 // field in the header, plus the value of the line_range field, 00438 // minus 1 (line base + line range - 1). If the desired line 00439 // increment is greater than the maximum line increment, a standard 00440 // opcode must be used instead of a special opcode. The "address 00441 // advance" is calculated by dividing the desired address increment 00442 // by the minimum_instruction_length field from the header. The 00443 // special opcode is then calculated using the following formula: 00444 // 00445 // opcode = (desired line increment - line_base) + 00446 // (line_range * address advance) + opcode_base 00447 // 00448 // If the resulting opcode is greater than 255, a standard opcode 00449 // must be used instead. 00450 // 00451 // To decode a special opcode, subtract the opcode_base from the 00452 // opcode itself to give the adjusted opcode. The amount to 00453 // increment the address register is the result of the adjusted 00454 // opcode divided by the line_range multiplied by the 00455 // minimum_instruction_length field from the header. That is: 00456 // 00457 // address increment = (adjusted opcode / line_range) * 00458 // minimum_instruction_length 00459 // 00460 // The amount to increment the line register is the line_base plus 00461 // the result of the adjusted opcode modulo the line_range. That is: 00462 // 00463 // line increment = line_base + (adjusted opcode % line_range) 00464 00465 uint8_t adjust_opcode = opcode - prologue->OpcodeBase; 00466 uint64_t addr_offset = (adjust_opcode / prologue->LineRange) * 00467 prologue->MinInstLength; 00468 int32_t line_offset = prologue->LineBase + 00469 (adjust_opcode % prologue->LineRange); 00470 state.Line += line_offset; 00471 state.Address += addr_offset; 00472 state.appendRowToMatrix(*offset_ptr); 00473 } 00474 } 00475 00476 state.finalize(); 00477 00478 return end_offset; 00479 } 00480 00481 uint32_t 00482 DWARFDebugLine::LineTable::lookupAddress(uint64_t address) const { 00483 uint32_t unknown_index = UINT32_MAX; 00484 if (Sequences.empty()) 00485 return unknown_index; 00486 // First, find an instruction sequence containing the given address. 00487 DWARFDebugLine::Sequence sequence; 00488 sequence.LowPC = address; 00489 SequenceIter first_seq = Sequences.begin(); 00490 SequenceIter last_seq = Sequences.end(); 00491 SequenceIter seq_pos = std::lower_bound(first_seq, last_seq, sequence, 00492 DWARFDebugLine::Sequence::orderByLowPC); 00493 DWARFDebugLine::Sequence found_seq; 00494 if (seq_pos == last_seq) { 00495 found_seq = Sequences.back(); 00496 } else if (seq_pos->LowPC == address) { 00497 found_seq = *seq_pos; 00498 } else { 00499 if (seq_pos == first_seq) 00500 return unknown_index; 00501 found_seq = *(seq_pos - 1); 00502 } 00503 if (!found_seq.containsPC(address)) 00504 return unknown_index; 00505 // Search for instruction address in the rows describing the sequence. 00506 // Rows are stored in a vector, so we may use arithmetical operations with 00507 // iterators. 00508 DWARFDebugLine::Row row; 00509 row.Address = address; 00510 RowIter first_row = Rows.begin() + found_seq.FirstRowIndex; 00511 RowIter last_row = Rows.begin() + found_seq.LastRowIndex; 00512 RowIter row_pos = std::lower_bound(first_row, last_row, row, 00513 DWARFDebugLine::Row::orderByAddress); 00514 if (row_pos == last_row) { 00515 return found_seq.LastRowIndex - 1; 00516 } 00517 uint32_t index = found_seq.FirstRowIndex + (row_pos - first_row); 00518 if (row_pos->Address > address) { 00519 if (row_pos == first_row) 00520 return unknown_index; 00521 else 00522 index--; 00523 } 00524 return index; 00525 } 00526 00527 bool 00528 DWARFDebugLine::LineTable::lookupAddressRange(uint64_t address, 00529 uint64_t size, 00530 std::vector<uint32_t>& result) const { 00531 if (Sequences.empty()) 00532 return false; 00533 uint64_t end_addr = address + size; 00534 // First, find an instruction sequence containing the given address. 00535 DWARFDebugLine::Sequence sequence; 00536 sequence.LowPC = address; 00537 SequenceIter first_seq = Sequences.begin(); 00538 SequenceIter last_seq = Sequences.end(); 00539 SequenceIter seq_pos = std::lower_bound(first_seq, last_seq, sequence, 00540 DWARFDebugLine::Sequence::orderByLowPC); 00541 if (seq_pos == last_seq || seq_pos->LowPC != address) { 00542 if (seq_pos == first_seq) 00543 return false; 00544 seq_pos--; 00545 } 00546 if (!seq_pos->containsPC(address)) 00547 return false; 00548 00549 SequenceIter start_pos = seq_pos; 00550 00551 // Add the rows from the first sequence to the vector, starting with the 00552 // index we just calculated 00553 00554 while (seq_pos != last_seq && seq_pos->LowPC < end_addr) { 00555 DWARFDebugLine::Sequence cur_seq = *seq_pos; 00556 uint32_t first_row_index; 00557 uint32_t last_row_index; 00558 if (seq_pos == start_pos) { 00559 // For the first sequence, we need to find which row in the sequence is the 00560 // first in our range. Rows are stored in a vector, so we may use 00561 // arithmetical operations with iterators. 00562 DWARFDebugLine::Row row; 00563 row.Address = address; 00564 RowIter first_row = Rows.begin() + cur_seq.FirstRowIndex; 00565 RowIter last_row = Rows.begin() + cur_seq.LastRowIndex; 00566 RowIter row_pos = std::upper_bound(first_row, last_row, row, 00567 DWARFDebugLine::Row::orderByAddress); 00568 // The 'row_pos' iterator references the first row that is greater than 00569 // our start address. Unless that's the first row, we want to start at 00570 // the row before that. 00571 first_row_index = cur_seq.FirstRowIndex + (row_pos - first_row); 00572 if (row_pos != first_row) 00573 --first_row_index; 00574 } else 00575 first_row_index = cur_seq.FirstRowIndex; 00576 00577 // For the last sequence in our range, we need to figure out the last row in 00578 // range. For all other sequences we can go to the end of the sequence. 00579 if (cur_seq.HighPC > end_addr) { 00580 DWARFDebugLine::Row row; 00581 row.Address = end_addr; 00582 RowIter first_row = Rows.begin() + cur_seq.FirstRowIndex; 00583 RowIter last_row = Rows.begin() + cur_seq.LastRowIndex; 00584 RowIter row_pos = std::upper_bound(first_row, last_row, row, 00585 DWARFDebugLine::Row::orderByAddress); 00586 // The 'row_pos' iterator references the first row that is greater than 00587 // our end address. The row before that is the last row we want. 00588 last_row_index = cur_seq.FirstRowIndex + (row_pos - first_row) - 1; 00589 } else 00590 // Contrary to what you might expect, DWARFDebugLine::SequenceLastRowIndex 00591 // isn't a valid index within the current sequence. It's that plus one. 00592 last_row_index = cur_seq.LastRowIndex - 1; 00593 00594 for (uint32_t i = first_row_index; i <= last_row_index; ++i) { 00595 result.push_back(i); 00596 } 00597 00598 ++seq_pos; 00599 } 00600 00601 return true; 00602 } 00603 00604 bool 00605 DWARFDebugLine::LineTable::getFileNameByIndex(uint64_t FileIndex, 00606 bool NeedsAbsoluteFilePath, 00607 std::string &Result) const { 00608 if (FileIndex == 0 || FileIndex > Prologue.FileNames.size()) 00609 return false; 00610 const FileNameEntry &Entry = Prologue.FileNames[FileIndex - 1]; 00611 const char *FileName = Entry.Name; 00612 if (!NeedsAbsoluteFilePath || 00613 sys::path::is_absolute(FileName)) { 00614 Result = FileName; 00615 return true; 00616 } 00617 SmallString<16> FilePath; 00618 uint64_t IncludeDirIndex = Entry.DirIdx; 00619 // Be defensive about the contents of Entry. 00620 if (IncludeDirIndex > 0 && 00621 IncludeDirIndex <= Prologue.IncludeDirectories.size()) { 00622 const char *IncludeDir = Prologue.IncludeDirectories[IncludeDirIndex - 1]; 00623 sys::path::append(FilePath, IncludeDir); 00624 } 00625 sys::path::append(FilePath, FileName); 00626 Result = FilePath.str(); 00627 return true; 00628 }