1 //===-- SymbolFileBreakpad.cpp ----------------------------------*- 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 #include "Plugins/SymbolFile/Breakpad/SymbolFileBreakpad.h" 10 #include "Plugins/ObjectFile/Breakpad/BreakpadRecords.h" 11 #include "Plugins/ObjectFile/Breakpad/ObjectFileBreakpad.h" 12 #include "lldb/Core/Module.h" 13 #include "lldb/Core/PluginManager.h" 14 #include "lldb/Core/Section.h" 15 #include "lldb/Host/FileSystem.h" 16 #include "lldb/Symbol/CompileUnit.h" 17 #include "lldb/Symbol/ObjectFile.h" 18 #include "lldb/Symbol/PostfixExpression.h" 19 #include "lldb/Symbol/SymbolVendor.h" 20 #include "lldb/Symbol/TypeMap.h" 21 #include "lldb/Utility/Log.h" 22 #include "lldb/Utility/StreamString.h" 23 #include "llvm/ADT/StringExtras.h" 24 25 using namespace lldb; 26 using namespace lldb_private; 27 using namespace lldb_private::breakpad; 28 29 class SymbolFileBreakpad::LineIterator { 30 public: 31 // begin iterator for sections of given type 32 LineIterator(ObjectFile &obj, Record::Kind section_type) 33 : m_obj(&obj), m_section_type(toString(section_type)), 34 m_next_section_idx(0), m_next_line(llvm::StringRef::npos) { 35 ++*this; 36 } 37 38 // An iterator starting at the position given by the bookmark. 39 LineIterator(ObjectFile &obj, Record::Kind section_type, Bookmark bookmark); 40 41 // end iterator 42 explicit LineIterator(ObjectFile &obj) 43 : m_obj(&obj), 44 m_next_section_idx(m_obj->GetSectionList()->GetNumSections(0)), 45 m_current_line(llvm::StringRef::npos), 46 m_next_line(llvm::StringRef::npos) {} 47 48 friend bool operator!=(const LineIterator &lhs, const LineIterator &rhs) { 49 assert(lhs.m_obj == rhs.m_obj); 50 if (lhs.m_next_section_idx != rhs.m_next_section_idx) 51 return true; 52 if (lhs.m_current_line != rhs.m_current_line) 53 return true; 54 assert(lhs.m_next_line == rhs.m_next_line); 55 return false; 56 } 57 58 const LineIterator &operator++(); 59 llvm::StringRef operator*() const { 60 return m_section_text.slice(m_current_line, m_next_line); 61 } 62 63 Bookmark GetBookmark() const { 64 return Bookmark{m_next_section_idx, m_current_line}; 65 } 66 67 private: 68 ObjectFile *m_obj; 69 ConstString m_section_type; 70 uint32_t m_next_section_idx; 71 llvm::StringRef m_section_text; 72 size_t m_current_line; 73 size_t m_next_line; 74 75 void FindNextLine() { 76 m_next_line = m_section_text.find('\n', m_current_line); 77 if (m_next_line != llvm::StringRef::npos) { 78 ++m_next_line; 79 if (m_next_line >= m_section_text.size()) 80 m_next_line = llvm::StringRef::npos; 81 } 82 } 83 }; 84 85 SymbolFileBreakpad::LineIterator::LineIterator(ObjectFile &obj, 86 Record::Kind section_type, 87 Bookmark bookmark) 88 : m_obj(&obj), m_section_type(toString(section_type)), 89 m_next_section_idx(bookmark.section), m_current_line(bookmark.offset) { 90 Section § = 91 *obj.GetSectionList()->GetSectionAtIndex(m_next_section_idx - 1); 92 assert(sect.GetName() == m_section_type); 93 94 DataExtractor data; 95 obj.ReadSectionData(§, data); 96 m_section_text = toStringRef(data.GetData()); 97 98 assert(m_current_line < m_section_text.size()); 99 FindNextLine(); 100 } 101 102 const SymbolFileBreakpad::LineIterator & 103 SymbolFileBreakpad::LineIterator::operator++() { 104 const SectionList &list = *m_obj->GetSectionList(); 105 size_t num_sections = list.GetNumSections(0); 106 while (m_next_line != llvm::StringRef::npos || 107 m_next_section_idx < num_sections) { 108 if (m_next_line != llvm::StringRef::npos) { 109 m_current_line = m_next_line; 110 FindNextLine(); 111 return *this; 112 } 113 114 Section § = *list.GetSectionAtIndex(m_next_section_idx++); 115 if (sect.GetName() != m_section_type) 116 continue; 117 DataExtractor data; 118 m_obj->ReadSectionData(§, data); 119 m_section_text = toStringRef(data.GetData()); 120 m_next_line = 0; 121 } 122 // We've reached the end. 123 m_current_line = m_next_line; 124 return *this; 125 } 126 127 llvm::iterator_range<SymbolFileBreakpad::LineIterator> 128 SymbolFileBreakpad::lines(Record::Kind section_type) { 129 return llvm::make_range(LineIterator(*m_obj_file, section_type), 130 LineIterator(*m_obj_file)); 131 } 132 133 namespace { 134 // A helper class for constructing the list of support files for a given compile 135 // unit. 136 class SupportFileMap { 137 public: 138 // Given a breakpad file ID, return a file ID to be used in the support files 139 // for this compile unit. 140 size_t operator[](size_t file) { 141 return m_map.try_emplace(file, m_map.size() + 1).first->second; 142 } 143 144 // Construct a FileSpecList containing only the support files relevant for 145 // this compile unit (in the correct order). 146 FileSpecList translate(const FileSpec &cu_spec, 147 llvm::ArrayRef<FileSpec> all_files); 148 149 private: 150 llvm::DenseMap<size_t, size_t> m_map; 151 }; 152 } // namespace 153 154 FileSpecList SupportFileMap::translate(const FileSpec &cu_spec, 155 llvm::ArrayRef<FileSpec> all_files) { 156 std::vector<FileSpec> result; 157 result.resize(m_map.size() + 1); 158 result[0] = cu_spec; 159 for (const auto &KV : m_map) { 160 if (KV.first < all_files.size()) 161 result[KV.second] = all_files[KV.first]; 162 } 163 return FileSpecList(std::move(result)); 164 } 165 166 void SymbolFileBreakpad::Initialize() { 167 PluginManager::RegisterPlugin(GetPluginNameStatic(), 168 GetPluginDescriptionStatic(), CreateInstance, 169 DebuggerInitialize); 170 } 171 172 void SymbolFileBreakpad::Terminate() { 173 PluginManager::UnregisterPlugin(CreateInstance); 174 } 175 176 ConstString SymbolFileBreakpad::GetPluginNameStatic() { 177 static ConstString g_name("breakpad"); 178 return g_name; 179 } 180 181 uint32_t SymbolFileBreakpad::CalculateAbilities() { 182 if (!m_obj_file) 183 return 0; 184 if (m_obj_file->GetPluginName() != ObjectFileBreakpad::GetPluginNameStatic()) 185 return 0; 186 187 return CompileUnits | Functions | LineTables; 188 } 189 190 uint32_t SymbolFileBreakpad::GetNumCompileUnits() { 191 ParseCUData(); 192 return m_cu_data->GetSize(); 193 } 194 195 CompUnitSP SymbolFileBreakpad::ParseCompileUnitAtIndex(uint32_t index) { 196 if (index >= m_cu_data->GetSize()) 197 return nullptr; 198 199 CompUnitData &data = m_cu_data->GetEntryRef(index).data; 200 201 ParseFileRecords(); 202 203 FileSpec spec; 204 205 // The FileSpec of the compile unit will be the file corresponding to the 206 // first LINE record. 207 LineIterator It(*m_obj_file, Record::Func, data.bookmark), End(*m_obj_file); 208 assert(Record::classify(*It) == Record::Func); 209 ++It; // Skip FUNC record. 210 if (It != End) { 211 auto record = LineRecord::parse(*It); 212 if (record && record->FileNum < m_files->size()) 213 spec = (*m_files)[record->FileNum]; 214 } 215 216 auto cu_sp = std::make_shared<CompileUnit>(m_obj_file->GetModule(), 217 /*user_data*/ nullptr, spec, index, 218 eLanguageTypeUnknown, 219 /*is_optimized*/ eLazyBoolNo); 220 221 GetSymbolVendor().SetCompileUnitAtIndex(index, cu_sp); 222 return cu_sp; 223 } 224 225 size_t SymbolFileBreakpad::ParseFunctions(CompileUnit &comp_unit) { 226 // TODO 227 return 0; 228 } 229 230 bool SymbolFileBreakpad::ParseLineTable(CompileUnit &comp_unit) { 231 CompUnitData &data = m_cu_data->GetEntryRef(comp_unit.GetID()).data; 232 233 if (!data.line_table_up) 234 ParseLineTableAndSupportFiles(comp_unit, data); 235 236 comp_unit.SetLineTable(data.line_table_up.release()); 237 return true; 238 } 239 240 bool SymbolFileBreakpad::ParseSupportFiles(CompileUnit &comp_unit, 241 FileSpecList &support_files) { 242 CompUnitData &data = m_cu_data->GetEntryRef(comp_unit.GetID()).data; 243 if (!data.support_files) 244 ParseLineTableAndSupportFiles(comp_unit, data); 245 246 support_files = std::move(*data.support_files); 247 return true; 248 } 249 250 uint32_t 251 SymbolFileBreakpad::ResolveSymbolContext(const Address &so_addr, 252 SymbolContextItem resolve_scope, 253 SymbolContext &sc) { 254 if (!(resolve_scope & (eSymbolContextCompUnit | eSymbolContextLineEntry))) 255 return 0; 256 257 ParseCUData(); 258 uint32_t idx = 259 m_cu_data->FindEntryIndexThatContains(so_addr.GetFileAddress()); 260 if (idx == UINT32_MAX) 261 return 0; 262 263 sc.comp_unit = GetSymbolVendor().GetCompileUnitAtIndex(idx).get(); 264 SymbolContextItem result = eSymbolContextCompUnit; 265 if (resolve_scope & eSymbolContextLineEntry) { 266 if (sc.comp_unit->GetLineTable()->FindLineEntryByAddress(so_addr, 267 sc.line_entry)) { 268 result |= eSymbolContextLineEntry; 269 } 270 } 271 272 return result; 273 } 274 275 uint32_t SymbolFileBreakpad::ResolveSymbolContext( 276 const FileSpec &file_spec, uint32_t line, bool check_inlines, 277 lldb::SymbolContextItem resolve_scope, SymbolContextList &sc_list) { 278 if (!(resolve_scope & eSymbolContextCompUnit)) 279 return 0; 280 281 uint32_t old_size = sc_list.GetSize(); 282 for (size_t i = 0, size = GetNumCompileUnits(); i < size; ++i) { 283 CompileUnit &cu = *GetSymbolVendor().GetCompileUnitAtIndex(i); 284 cu.ResolveSymbolContext(file_spec, line, check_inlines, 285 /*exact*/ false, resolve_scope, sc_list); 286 } 287 return sc_list.GetSize() - old_size; 288 } 289 290 uint32_t SymbolFileBreakpad::FindFunctions( 291 ConstString name, const CompilerDeclContext *parent_decl_ctx, 292 FunctionNameType name_type_mask, bool include_inlines, bool append, 293 SymbolContextList &sc_list) { 294 // TODO 295 if (!append) 296 sc_list.Clear(); 297 return sc_list.GetSize(); 298 } 299 300 uint32_t SymbolFileBreakpad::FindFunctions(const RegularExpression ®ex, 301 bool include_inlines, bool append, 302 SymbolContextList &sc_list) { 303 // TODO 304 if (!append) 305 sc_list.Clear(); 306 return sc_list.GetSize(); 307 } 308 309 uint32_t SymbolFileBreakpad::FindTypes( 310 ConstString name, const CompilerDeclContext *parent_decl_ctx, 311 bool append, uint32_t max_matches, 312 llvm::DenseSet<SymbolFile *> &searched_symbol_files, TypeMap &types) { 313 if (!append) 314 types.Clear(); 315 return types.GetSize(); 316 } 317 318 size_t 319 SymbolFileBreakpad::FindTypes(const std::vector<CompilerContext> &context, 320 bool append, TypeMap &types) { 321 if (!append) 322 types.Clear(); 323 return types.GetSize(); 324 } 325 326 void SymbolFileBreakpad::AddSymbols(Symtab &symtab) { 327 Log *log = GetLogIfAllCategoriesSet(LIBLLDB_LOG_SYMBOLS); 328 Module &module = *m_obj_file->GetModule(); 329 addr_t base = GetBaseFileAddress(); 330 if (base == LLDB_INVALID_ADDRESS) { 331 LLDB_LOG(log, "Unable to fetch the base address of object file. Skipping " 332 "symtab population."); 333 return; 334 } 335 336 const SectionList &list = *module.GetSectionList(); 337 llvm::DenseMap<addr_t, Symbol> symbols; 338 auto add_symbol = [&](addr_t address, llvm::Optional<addr_t> size, 339 llvm::StringRef name) { 340 address += base; 341 SectionSP section_sp = list.FindSectionContainingFileAddress(address); 342 if (!section_sp) { 343 LLDB_LOG(log, 344 "Ignoring symbol {0}, whose address ({1}) is outside of the " 345 "object file. Mismatched symbol file?", 346 name, address); 347 return; 348 } 349 symbols.try_emplace( 350 address, /*symID*/ 0, Mangled(name, /*is_mangled*/ false), 351 eSymbolTypeCode, /*is_global*/ true, /*is_debug*/ false, 352 /*is_trampoline*/ false, /*is_artificial*/ false, 353 AddressRange(section_sp, address - section_sp->GetFileAddress(), 354 size.getValueOr(0)), 355 size.hasValue(), /*contains_linker_annotations*/ false, /*flags*/ 0); 356 }; 357 358 for (llvm::StringRef line : lines(Record::Func)) { 359 if (auto record = FuncRecord::parse(line)) 360 add_symbol(record->Address, record->Size, record->Name); 361 } 362 363 for (llvm::StringRef line : lines(Record::Public)) { 364 if (auto record = PublicRecord::parse(line)) 365 add_symbol(record->Address, llvm::None, record->Name); 366 else 367 LLDB_LOG(log, "Failed to parse: {0}. Skipping record.", line); 368 } 369 370 for (auto &KV : symbols) 371 symtab.AddSymbol(std::move(KV.second)); 372 symtab.CalculateSymbolSizes(); 373 } 374 375 static llvm::Optional<std::pair<llvm::StringRef, llvm::StringRef>> 376 GetRule(llvm::StringRef &unwind_rules) { 377 // Unwind rules are of the form 378 // register1: expression1 register2: expression2 ... 379 // We assume none of the tokens in expression<n> end with a colon. 380 381 llvm::StringRef lhs, rest; 382 std::tie(lhs, rest) = getToken(unwind_rules); 383 if (!lhs.consume_back(":")) 384 return llvm::None; 385 386 // Seek forward to the next register: expression pair 387 llvm::StringRef::size_type pos = rest.find(": "); 388 if (pos == llvm::StringRef::npos) { 389 // No pair found, this means the rest of the string is a single expression. 390 unwind_rules = llvm::StringRef(); 391 return std::make_pair(lhs, rest); 392 } 393 394 // Go back one token to find the end of the current rule. 395 pos = rest.rfind(' ', pos); 396 if (pos == llvm::StringRef::npos) 397 return llvm::None; 398 399 llvm::StringRef rhs = rest.take_front(pos); 400 unwind_rules = rest.drop_front(pos); 401 return std::make_pair(lhs, rhs); 402 } 403 404 static const RegisterInfo * 405 ResolveRegister(const SymbolFile::RegisterInfoResolver &resolver, 406 llvm::StringRef name) { 407 if (name.consume_front("$")) 408 return resolver.ResolveName(name); 409 410 return nullptr; 411 } 412 413 static const RegisterInfo * 414 ResolveRegisterOrRA(const SymbolFile::RegisterInfoResolver &resolver, 415 llvm::StringRef name) { 416 if (name == ".ra") 417 return resolver.ResolveNumber(eRegisterKindGeneric, LLDB_REGNUM_GENERIC_PC); 418 return ResolveRegister(resolver, name); 419 } 420 421 bool SymbolFileBreakpad::ParseUnwindRow(llvm::StringRef unwind_rules, 422 const RegisterInfoResolver &resolver, 423 UnwindPlan::Row &row) { 424 Log *log = GetLogIfAllCategoriesSet(LIBLLDB_LOG_SYMBOLS); 425 426 llvm::BumpPtrAllocator node_alloc; 427 while (auto rule = GetRule(unwind_rules)) { 428 node_alloc.Reset(); 429 llvm::StringRef lhs = rule->first; 430 postfix::Node *rhs = postfix::Parse(rule->second, node_alloc); 431 if (!rhs) { 432 LLDB_LOG(log, "Could not parse `{0}` as unwind rhs.", rule->second); 433 return false; 434 } 435 436 bool success = postfix::ResolveSymbols( 437 rhs, [&](postfix::SymbolNode &symbol) -> postfix::Node * { 438 llvm::StringRef name = symbol.GetName(); 439 if (name == ".cfa" && lhs != ".cfa") 440 return postfix::MakeNode<postfix::InitialValueNode>(node_alloc); 441 442 if (const RegisterInfo *info = ResolveRegister(resolver, name)) { 443 return postfix::MakeNode<postfix::RegisterNode>( 444 node_alloc, info->kinds[eRegisterKindLLDB]); 445 } 446 return nullptr; 447 }); 448 449 if (!success) { 450 LLDB_LOG(log, "Resolving symbols in `{0}` failed.", rule->second); 451 return false; 452 } 453 454 ArchSpec arch = m_obj_file->GetArchitecture(); 455 StreamString dwarf(Stream::eBinary, arch.GetAddressByteSize(), 456 arch.GetByteOrder()); 457 ToDWARF(*rhs, dwarf); 458 uint8_t *saved = m_allocator.Allocate<uint8_t>(dwarf.GetSize()); 459 std::memcpy(saved, dwarf.GetData(), dwarf.GetSize()); 460 461 if (lhs == ".cfa") { 462 row.GetCFAValue().SetIsDWARFExpression(saved, dwarf.GetSize()); 463 } else if (const RegisterInfo *info = ResolveRegisterOrRA(resolver, lhs)) { 464 UnwindPlan::Row::RegisterLocation loc; 465 loc.SetIsDWARFExpression(saved, dwarf.GetSize()); 466 row.SetRegisterInfo(info->kinds[eRegisterKindLLDB], loc); 467 } else 468 LLDB_LOG(log, "Invalid register `{0}` in unwind rule.", lhs); 469 } 470 if (unwind_rules.empty()) 471 return true; 472 473 LLDB_LOG(log, "Could not parse `{0}` as an unwind rule.", unwind_rules); 474 return false; 475 } 476 477 UnwindPlanSP 478 SymbolFileBreakpad::GetUnwindPlan(const Address &address, 479 const RegisterInfoResolver &resolver) { 480 ParseUnwindData(); 481 const UnwindMap::Entry *entry = 482 m_unwind_data->FindEntryThatContains(address.GetFileAddress()); 483 if (!entry) 484 return nullptr; 485 486 addr_t base = GetBaseFileAddress(); 487 if (base == LLDB_INVALID_ADDRESS) 488 return nullptr; 489 490 LineIterator It(*m_obj_file, Record::StackCFI, entry->data), End(*m_obj_file); 491 llvm::Optional<StackCFIRecord> init_record = StackCFIRecord::parse(*It); 492 assert(init_record.hasValue()); 493 assert(init_record->Size.hasValue()); 494 495 auto plan_sp = std::make_shared<UnwindPlan>(lldb::eRegisterKindLLDB); 496 plan_sp->SetSourceName("breakpad STACK CFI"); 497 plan_sp->SetUnwindPlanValidAtAllInstructions(eLazyBoolNo); 498 plan_sp->SetSourcedFromCompiler(eLazyBoolYes); 499 plan_sp->SetPlanValidAddressRange( 500 AddressRange(base + init_record->Address, *init_record->Size, 501 m_obj_file->GetModule()->GetSectionList())); 502 503 auto row_sp = std::make_shared<UnwindPlan::Row>(); 504 row_sp->SetOffset(0); 505 if (!ParseUnwindRow(init_record->UnwindRules, resolver, *row_sp)) 506 return nullptr; 507 plan_sp->AppendRow(row_sp); 508 for (++It; It != End; ++It) { 509 llvm::Optional<StackCFIRecord> record = StackCFIRecord::parse(*It); 510 if (!record.hasValue()) 511 return nullptr; 512 if (record->Size.hasValue()) 513 break; 514 515 row_sp = std::make_shared<UnwindPlan::Row>(*row_sp); 516 row_sp->SetOffset(record->Address - init_record->Address); 517 if (!ParseUnwindRow(record->UnwindRules, resolver, *row_sp)) 518 return nullptr; 519 plan_sp->AppendRow(row_sp); 520 } 521 return plan_sp; 522 } 523 524 SymbolVendor &SymbolFileBreakpad::GetSymbolVendor() { 525 return *m_obj_file->GetModule()->GetSymbolVendor(); 526 } 527 528 addr_t SymbolFileBreakpad::GetBaseFileAddress() { 529 return m_obj_file->GetModule() 530 ->GetObjectFile() 531 ->GetBaseAddress() 532 .GetFileAddress(); 533 } 534 535 // Parse out all the FILE records from the breakpad file. These will be needed 536 // when constructing the support file lists for individual compile units. 537 void SymbolFileBreakpad::ParseFileRecords() { 538 if (m_files) 539 return; 540 m_files.emplace(); 541 542 Log *log = GetLogIfAllCategoriesSet(LIBLLDB_LOG_SYMBOLS); 543 for (llvm::StringRef line : lines(Record::File)) { 544 auto record = FileRecord::parse(line); 545 if (!record) { 546 LLDB_LOG(log, "Failed to parse: {0}. Skipping record.", line); 547 continue; 548 } 549 550 if (record->Number >= m_files->size()) 551 m_files->resize(record->Number + 1); 552 FileSpec::Style style = FileSpec::GuessPathStyle(record->Name) 553 .getValueOr(FileSpec::Style::native); 554 (*m_files)[record->Number] = FileSpec(record->Name, style); 555 } 556 } 557 558 void SymbolFileBreakpad::ParseCUData() { 559 if (m_cu_data) 560 return; 561 562 m_cu_data.emplace(); 563 Log *log = GetLogIfAllCategoriesSet(LIBLLDB_LOG_SYMBOLS); 564 addr_t base = GetBaseFileAddress(); 565 if (base == LLDB_INVALID_ADDRESS) { 566 LLDB_LOG(log, "SymbolFile parsing failed: Unable to fetch the base address " 567 "of object file."); 568 } 569 570 // We shall create one compile unit for each FUNC record. So, count the number 571 // of FUNC records, and store them in m_cu_data, together with their ranges. 572 for (LineIterator It(*m_obj_file, Record::Func), End(*m_obj_file); It != End; 573 ++It) { 574 if (auto record = FuncRecord::parse(*It)) { 575 m_cu_data->Append(CompUnitMap::Entry(base + record->Address, record->Size, 576 CompUnitData(It.GetBookmark()))); 577 } else 578 LLDB_LOG(log, "Failed to parse: {0}. Skipping record.", *It); 579 } 580 m_cu_data->Sort(); 581 } 582 583 // Construct the list of support files and line table entries for the given 584 // compile unit. 585 void SymbolFileBreakpad::ParseLineTableAndSupportFiles(CompileUnit &cu, 586 CompUnitData &data) { 587 addr_t base = GetBaseFileAddress(); 588 assert(base != LLDB_INVALID_ADDRESS && 589 "How did we create compile units without a base address?"); 590 591 SupportFileMap map; 592 data.line_table_up = llvm::make_unique<LineTable>(&cu); 593 std::unique_ptr<LineSequence> line_seq_up( 594 data.line_table_up->CreateLineSequenceContainer()); 595 llvm::Optional<addr_t> next_addr; 596 auto finish_sequence = [&]() { 597 data.line_table_up->AppendLineEntryToSequence( 598 line_seq_up.get(), *next_addr, /*line*/ 0, /*column*/ 0, 599 /*file_idx*/ 0, /*is_start_of_statement*/ false, 600 /*is_start_of_basic_block*/ false, /*is_prologue_end*/ false, 601 /*is_epilogue_begin*/ false, /*is_terminal_entry*/ true); 602 data.line_table_up->InsertSequence(line_seq_up.get()); 603 line_seq_up->Clear(); 604 }; 605 606 LineIterator It(*m_obj_file, Record::Func, data.bookmark), End(*m_obj_file); 607 assert(Record::classify(*It) == Record::Func); 608 for (++It; It != End; ++It) { 609 auto record = LineRecord::parse(*It); 610 if (!record) 611 break; 612 613 record->Address += base; 614 615 if (next_addr && *next_addr != record->Address) { 616 // Discontiguous entries. Finish off the previous sequence and reset. 617 finish_sequence(); 618 } 619 data.line_table_up->AppendLineEntryToSequence( 620 line_seq_up.get(), record->Address, record->LineNum, /*column*/ 0, 621 map[record->FileNum], /*is_start_of_statement*/ true, 622 /*is_start_of_basic_block*/ false, /*is_prologue_end*/ false, 623 /*is_epilogue_begin*/ false, /*is_terminal_entry*/ false); 624 next_addr = record->Address + record->Size; 625 } 626 if (next_addr) 627 finish_sequence(); 628 data.support_files = map.translate(cu, *m_files); 629 } 630 631 void SymbolFileBreakpad::ParseUnwindData() { 632 if (m_unwind_data) 633 return; 634 635 m_unwind_data.emplace(); 636 Log *log = GetLogIfAllCategoriesSet(LIBLLDB_LOG_SYMBOLS); 637 addr_t base = GetBaseFileAddress(); 638 if (base == LLDB_INVALID_ADDRESS) { 639 LLDB_LOG(log, "SymbolFile parsing failed: Unable to fetch the base address " 640 "of object file."); 641 } 642 643 for (LineIterator It(*m_obj_file, Record::StackCFI), End(*m_obj_file); 644 It != End; ++It) { 645 if (auto record = StackCFIRecord::parse(*It)) { 646 if (record->Size) 647 m_unwind_data->Append(UnwindMap::Entry( 648 base + record->Address, *record->Size, It.GetBookmark())); 649 } else 650 LLDB_LOG(log, "Failed to parse: {0}. Skipping record.", *It); 651 } 652 m_unwind_data->Sort(); 653 } 654