1 //===- DWARFDebugFrame.h - Parsing of .debug_frame ------------------------===// 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 "llvm/DebugInfo/DWARF/DWARFDebugFrame.h" 10 #include "llvm/ADT/DenseMap.h" 11 #include "llvm/ADT/Optional.h" 12 #include "llvm/ADT/StringExtras.h" 13 #include "llvm/ADT/StringRef.h" 14 #include "llvm/BinaryFormat/Dwarf.h" 15 #include "llvm/Support/Casting.h" 16 #include "llvm/Support/Compiler.h" 17 #include "llvm/Support/DataExtractor.h" 18 #include "llvm/Support/Errc.h" 19 #include "llvm/Support/ErrorHandling.h" 20 #include "llvm/Support/Format.h" 21 #include "llvm/Support/raw_ostream.h" 22 #include <algorithm> 23 #include <cassert> 24 #include <cinttypes> 25 #include <cstdint> 26 #include <string> 27 #include <vector> 28 29 using namespace llvm; 30 using namespace dwarf; 31 32 33 // See DWARF standard v3, section 7.23 34 const uint8_t DWARF_CFI_PRIMARY_OPCODE_MASK = 0xc0; 35 const uint8_t DWARF_CFI_PRIMARY_OPERAND_MASK = 0x3f; 36 37 Error CFIProgram::parse(DWARFDataExtractor Data, uint64_t *Offset, 38 uint64_t EndOffset) { 39 while (*Offset < EndOffset) { 40 uint8_t Opcode = Data.getRelocatedValue(1, Offset); 41 // Some instructions have a primary opcode encoded in the top bits. 42 uint8_t Primary = Opcode & DWARF_CFI_PRIMARY_OPCODE_MASK; 43 44 if (Primary) { 45 // If it's a primary opcode, the first operand is encoded in the bottom 46 // bits of the opcode itself. 47 uint64_t Op1 = Opcode & DWARF_CFI_PRIMARY_OPERAND_MASK; 48 switch (Primary) { 49 default: 50 return createStringError(errc::illegal_byte_sequence, 51 "Invalid primary CFI opcode 0x%" PRIx8, 52 Primary); 53 case DW_CFA_advance_loc: 54 case DW_CFA_restore: 55 addInstruction(Primary, Op1); 56 break; 57 case DW_CFA_offset: 58 addInstruction(Primary, Op1, Data.getULEB128(Offset)); 59 break; 60 } 61 } else { 62 // Extended opcode - its value is Opcode itself. 63 switch (Opcode) { 64 default: 65 return createStringError(errc::illegal_byte_sequence, 66 "Invalid extended CFI opcode 0x%" PRIx8, 67 Opcode); 68 case DW_CFA_nop: 69 case DW_CFA_remember_state: 70 case DW_CFA_restore_state: 71 case DW_CFA_GNU_window_save: 72 // No operands 73 addInstruction(Opcode); 74 break; 75 case DW_CFA_set_loc: 76 // Operands: Address 77 addInstruction(Opcode, Data.getRelocatedAddress(Offset)); 78 break; 79 case DW_CFA_advance_loc1: 80 // Operands: 1-byte delta 81 addInstruction(Opcode, Data.getRelocatedValue(1, Offset)); 82 break; 83 case DW_CFA_advance_loc2: 84 // Operands: 2-byte delta 85 addInstruction(Opcode, Data.getRelocatedValue(2, Offset)); 86 break; 87 case DW_CFA_advance_loc4: 88 // Operands: 4-byte delta 89 addInstruction(Opcode, Data.getRelocatedValue(4, Offset)); 90 break; 91 case DW_CFA_restore_extended: 92 case DW_CFA_undefined: 93 case DW_CFA_same_value: 94 case DW_CFA_def_cfa_register: 95 case DW_CFA_def_cfa_offset: 96 case DW_CFA_GNU_args_size: 97 // Operands: ULEB128 98 addInstruction(Opcode, Data.getULEB128(Offset)); 99 break; 100 case DW_CFA_def_cfa_offset_sf: 101 // Operands: SLEB128 102 addInstruction(Opcode, Data.getSLEB128(Offset)); 103 break; 104 case DW_CFA_offset_extended: 105 case DW_CFA_register: 106 case DW_CFA_def_cfa: 107 case DW_CFA_val_offset: { 108 // Operands: ULEB128, ULEB128 109 // Note: We can not embed getULEB128 directly into function 110 // argument list. getULEB128 changes Offset and order of evaluation 111 // for arguments is unspecified. 112 auto op1 = Data.getULEB128(Offset); 113 auto op2 = Data.getULEB128(Offset); 114 addInstruction(Opcode, op1, op2); 115 break; 116 } 117 case DW_CFA_offset_extended_sf: 118 case DW_CFA_def_cfa_sf: 119 case DW_CFA_val_offset_sf: { 120 // Operands: ULEB128, SLEB128 121 // Note: see comment for the previous case 122 auto op1 = Data.getULEB128(Offset); 123 auto op2 = (uint64_t)Data.getSLEB128(Offset); 124 addInstruction(Opcode, op1, op2); 125 break; 126 } 127 case DW_CFA_def_cfa_expression: { 128 uint32_t ExprLength = Data.getULEB128(Offset); 129 addInstruction(Opcode, 0); 130 DataExtractor Extractor( 131 Data.getData().slice(*Offset, *Offset + ExprLength), 132 Data.isLittleEndian(), Data.getAddressSize()); 133 Instructions.back().Expression = 134 DWARFExpression(Extractor, Data.getAddressSize()); 135 *Offset += ExprLength; 136 break; 137 } 138 case DW_CFA_expression: 139 case DW_CFA_val_expression: { 140 auto RegNum = Data.getULEB128(Offset); 141 auto BlockLength = Data.getULEB128(Offset); 142 addInstruction(Opcode, RegNum, 0); 143 DataExtractor Extractor( 144 Data.getData().slice(*Offset, *Offset + BlockLength), 145 Data.isLittleEndian(), Data.getAddressSize()); 146 Instructions.back().Expression = 147 DWARFExpression(Extractor, Data.getAddressSize()); 148 *Offset += BlockLength; 149 break; 150 } 151 } 152 } 153 } 154 155 return Error::success(); 156 } 157 158 namespace { 159 160 161 } // end anonymous namespace 162 163 ArrayRef<CFIProgram::OperandType[2]> CFIProgram::getOperandTypes() { 164 static OperandType OpTypes[DW_CFA_restore+1][2]; 165 static bool Initialized = false; 166 if (Initialized) { 167 return ArrayRef<OperandType[2]>(&OpTypes[0], DW_CFA_restore+1); 168 } 169 Initialized = true; 170 171 #define DECLARE_OP2(OP, OPTYPE0, OPTYPE1) \ 172 do { \ 173 OpTypes[OP][0] = OPTYPE0; \ 174 OpTypes[OP][1] = OPTYPE1; \ 175 } while (false) 176 #define DECLARE_OP1(OP, OPTYPE0) DECLARE_OP2(OP, OPTYPE0, OT_None) 177 #define DECLARE_OP0(OP) DECLARE_OP1(OP, OT_None) 178 179 DECLARE_OP1(DW_CFA_set_loc, OT_Address); 180 DECLARE_OP1(DW_CFA_advance_loc, OT_FactoredCodeOffset); 181 DECLARE_OP1(DW_CFA_advance_loc1, OT_FactoredCodeOffset); 182 DECLARE_OP1(DW_CFA_advance_loc2, OT_FactoredCodeOffset); 183 DECLARE_OP1(DW_CFA_advance_loc4, OT_FactoredCodeOffset); 184 DECLARE_OP1(DW_CFA_MIPS_advance_loc8, OT_FactoredCodeOffset); 185 DECLARE_OP2(DW_CFA_def_cfa, OT_Register, OT_Offset); 186 DECLARE_OP2(DW_CFA_def_cfa_sf, OT_Register, OT_SignedFactDataOffset); 187 DECLARE_OP1(DW_CFA_def_cfa_register, OT_Register); 188 DECLARE_OP1(DW_CFA_def_cfa_offset, OT_Offset); 189 DECLARE_OP1(DW_CFA_def_cfa_offset_sf, OT_SignedFactDataOffset); 190 DECLARE_OP1(DW_CFA_def_cfa_expression, OT_Expression); 191 DECLARE_OP1(DW_CFA_undefined, OT_Register); 192 DECLARE_OP1(DW_CFA_same_value, OT_Register); 193 DECLARE_OP2(DW_CFA_offset, OT_Register, OT_UnsignedFactDataOffset); 194 DECLARE_OP2(DW_CFA_offset_extended, OT_Register, OT_UnsignedFactDataOffset); 195 DECLARE_OP2(DW_CFA_offset_extended_sf, OT_Register, OT_SignedFactDataOffset); 196 DECLARE_OP2(DW_CFA_val_offset, OT_Register, OT_UnsignedFactDataOffset); 197 DECLARE_OP2(DW_CFA_val_offset_sf, OT_Register, OT_SignedFactDataOffset); 198 DECLARE_OP2(DW_CFA_register, OT_Register, OT_Register); 199 DECLARE_OP2(DW_CFA_expression, OT_Register, OT_Expression); 200 DECLARE_OP2(DW_CFA_val_expression, OT_Register, OT_Expression); 201 DECLARE_OP1(DW_CFA_restore, OT_Register); 202 DECLARE_OP1(DW_CFA_restore_extended, OT_Register); 203 DECLARE_OP0(DW_CFA_remember_state); 204 DECLARE_OP0(DW_CFA_restore_state); 205 DECLARE_OP0(DW_CFA_GNU_window_save); 206 DECLARE_OP1(DW_CFA_GNU_args_size, OT_Offset); 207 DECLARE_OP0(DW_CFA_nop); 208 209 #undef DECLARE_OP0 210 #undef DECLARE_OP1 211 #undef DECLARE_OP2 212 213 return ArrayRef<OperandType[2]>(&OpTypes[0], DW_CFA_restore+1); 214 } 215 216 /// Print \p Opcode's operand number \p OperandIdx which has value \p Operand. 217 void CFIProgram::printOperand(raw_ostream &OS, const MCRegisterInfo *MRI, 218 bool IsEH, const Instruction &Instr, 219 unsigned OperandIdx, uint64_t Operand) const { 220 assert(OperandIdx < 2); 221 uint8_t Opcode = Instr.Opcode; 222 OperandType Type = getOperandTypes()[Opcode][OperandIdx]; 223 224 switch (Type) { 225 case OT_Unset: { 226 OS << " Unsupported " << (OperandIdx ? "second" : "first") << " operand to"; 227 auto OpcodeName = CallFrameString(Opcode, Arch); 228 if (!OpcodeName.empty()) 229 OS << " " << OpcodeName; 230 else 231 OS << format(" Opcode %x", Opcode); 232 break; 233 } 234 case OT_None: 235 break; 236 case OT_Address: 237 OS << format(" %" PRIx64, Operand); 238 break; 239 case OT_Offset: 240 // The offsets are all encoded in a unsigned form, but in practice 241 // consumers use them signed. It's most certainly legacy due to 242 // the lack of signed variants in the first Dwarf standards. 243 OS << format(" %+" PRId64, int64_t(Operand)); 244 break; 245 case OT_FactoredCodeOffset: // Always Unsigned 246 if (CodeAlignmentFactor) 247 OS << format(" %" PRId64, Operand * CodeAlignmentFactor); 248 else 249 OS << format(" %" PRId64 "*code_alignment_factor" , Operand); 250 break; 251 case OT_SignedFactDataOffset: 252 if (DataAlignmentFactor) 253 OS << format(" %" PRId64, int64_t(Operand) * DataAlignmentFactor); 254 else 255 OS << format(" %" PRId64 "*data_alignment_factor" , int64_t(Operand)); 256 break; 257 case OT_UnsignedFactDataOffset: 258 if (DataAlignmentFactor) 259 OS << format(" %" PRId64, Operand * DataAlignmentFactor); 260 else 261 OS << format(" %" PRId64 "*data_alignment_factor" , Operand); 262 break; 263 case OT_Register: 264 OS << format(" reg%" PRId64, Operand); 265 break; 266 case OT_Expression: 267 assert(Instr.Expression && "missing DWARFExpression object"); 268 OS << " "; 269 Instr.Expression->print(OS, MRI, nullptr, IsEH); 270 break; 271 } 272 } 273 274 void CFIProgram::dump(raw_ostream &OS, const MCRegisterInfo *MRI, bool IsEH, 275 unsigned IndentLevel) const { 276 for (const auto &Instr : Instructions) { 277 uint8_t Opcode = Instr.Opcode; 278 if (Opcode & DWARF_CFI_PRIMARY_OPCODE_MASK) 279 Opcode &= DWARF_CFI_PRIMARY_OPCODE_MASK; 280 OS.indent(2 * IndentLevel); 281 OS << CallFrameString(Opcode, Arch) << ":"; 282 for (unsigned i = 0; i < Instr.Ops.size(); ++i) 283 printOperand(OS, MRI, IsEH, Instr, i, Instr.Ops[i]); 284 OS << '\n'; 285 } 286 } 287 288 // Returns the CIE identifier to be used by the requested format. 289 // CIE ids for .debug_frame sections are defined in Section 7.24 of DWARFv5. 290 // For CIE ID in .eh_frame sections see 291 // https://refspecs.linuxfoundation.org/LSB_5.0.0/LSB-Core-generic/LSB-Core-generic/ehframechpt.html 292 constexpr uint64_t getCIEId(bool IsDWARF64, bool IsEH) { 293 if (IsEH) 294 return 0; 295 if (IsDWARF64) 296 return DW64_CIE_ID; 297 return DW_CIE_ID; 298 } 299 300 void CIE::dump(raw_ostream &OS, const MCRegisterInfo *MRI, bool IsEH) const { 301 OS << format("%08" PRIx64, Offset) 302 << format(" %0*" PRIx64, IsDWARF64 ? 16 : 8, Length) 303 << format(" %0*" PRIx64, IsDWARF64 && !IsEH ? 16 : 8, 304 getCIEId(IsDWARF64, IsEH)) 305 << " CIE\n"; 306 OS << format(" Version: %d\n", Version); 307 OS << " Augmentation: \"" << Augmentation << "\"\n"; 308 if (Version >= 4) { 309 OS << format(" Address size: %u\n", (uint32_t)AddressSize); 310 OS << format(" Segment desc size: %u\n", 311 (uint32_t)SegmentDescriptorSize); 312 } 313 OS << format(" Code alignment factor: %u\n", (uint32_t)CodeAlignmentFactor); 314 OS << format(" Data alignment factor: %d\n", (int32_t)DataAlignmentFactor); 315 OS << format(" Return address column: %d\n", (int32_t)ReturnAddressRegister); 316 if (Personality) 317 OS << format(" Personality Address: %016" PRIx64 "\n", *Personality); 318 if (!AugmentationData.empty()) { 319 OS << " Augmentation data: "; 320 for (uint8_t Byte : AugmentationData) 321 OS << ' ' << hexdigit(Byte >> 4) << hexdigit(Byte & 0xf); 322 OS << "\n"; 323 } 324 OS << "\n"; 325 CFIs.dump(OS, MRI, IsEH); 326 OS << "\n"; 327 } 328 329 void FDE::dump(raw_ostream &OS, const MCRegisterInfo *MRI, bool IsEH) const { 330 OS << format("%08" PRIx64, Offset) 331 << format(" %0*" PRIx64, IsDWARF64 ? 16 : 8, Length) 332 << format(" %0*" PRIx64, IsDWARF64 && !IsEH ? 16 : 8, CIEPointer) 333 << " FDE cie="; 334 if (LinkedCIE) 335 OS << format("%08" PRIx64, LinkedCIE->getOffset()); 336 else 337 OS << "<invalid offset>"; 338 OS << format(" pc=%08" PRIx64 "...%08" PRIx64 "\n", InitialLocation, 339 InitialLocation + AddressRange); 340 if (LSDAAddress) 341 OS << format(" LSDA Address: %016" PRIx64 "\n", *LSDAAddress); 342 CFIs.dump(OS, MRI, IsEH); 343 OS << "\n"; 344 } 345 346 DWARFDebugFrame::DWARFDebugFrame(Triple::ArchType Arch, 347 bool IsEH, uint64_t EHFrameAddress) 348 : Arch(Arch), IsEH(IsEH), EHFrameAddress(EHFrameAddress) {} 349 350 DWARFDebugFrame::~DWARFDebugFrame() = default; 351 352 static void LLVM_ATTRIBUTE_UNUSED dumpDataAux(DataExtractor Data, 353 uint64_t Offset, int Length) { 354 errs() << "DUMP: "; 355 for (int i = 0; i < Length; ++i) { 356 uint8_t c = Data.getU8(&Offset); 357 errs().write_hex(c); errs() << " "; 358 } 359 errs() << "\n"; 360 } 361 362 // This is a workaround for old compilers which do not allow 363 // noreturn attribute usage in lambdas. Once the support for those 364 // compilers are phased out, we can remove this and return back to 365 // a ReportError lambda: [StartOffset](const char *ErrorMsg). 366 static void LLVM_ATTRIBUTE_NORETURN ReportError(uint64_t StartOffset, 367 const char *ErrorMsg) { 368 std::string Str; 369 raw_string_ostream OS(Str); 370 OS << format(ErrorMsg, StartOffset); 371 OS.flush(); 372 report_fatal_error(Str); 373 } 374 375 void DWARFDebugFrame::parse(DWARFDataExtractor Data) { 376 uint64_t Offset = 0; 377 DenseMap<uint64_t, CIE *> CIEs; 378 379 while (Data.isValidOffset(Offset)) { 380 uint64_t StartOffset = Offset; 381 382 uint64_t Length; 383 DwarfFormat Format; 384 std::tie(Length, Format) = Data.getInitialLength(&Offset); 385 uint64_t Id; 386 387 // At this point, Offset points to the next field after Length. 388 // Length is the structure size excluding itself. Compute an offset one 389 // past the end of the structure (needed to know how many instructions to 390 // read). 391 uint64_t StartStructureOffset = Offset; 392 uint64_t EndStructureOffset = Offset + Length; 393 394 // The Id field's size depends on the DWARF format 395 bool IsDWARF64 = Format == DWARF64; 396 Id = Data.getRelocatedValue((IsDWARF64 && !IsEH) ? 8 : 4, &Offset); 397 if (Id == getCIEId(IsDWARF64, IsEH)) { 398 uint8_t Version = Data.getU8(&Offset); 399 const char *Augmentation = Data.getCStr(&Offset); 400 StringRef AugmentationString(Augmentation ? Augmentation : ""); 401 uint8_t AddressSize = Version < 4 ? Data.getAddressSize() : 402 Data.getU8(&Offset); 403 Data.setAddressSize(AddressSize); 404 uint8_t SegmentDescriptorSize = Version < 4 ? 0 : Data.getU8(&Offset); 405 uint64_t CodeAlignmentFactor = Data.getULEB128(&Offset); 406 int64_t DataAlignmentFactor = Data.getSLEB128(&Offset); 407 uint64_t ReturnAddressRegister = 408 Version == 1 ? Data.getU8(&Offset) : Data.getULEB128(&Offset); 409 410 // Parse the augmentation data for EH CIEs 411 StringRef AugmentationData(""); 412 uint32_t FDEPointerEncoding = DW_EH_PE_absptr; 413 uint32_t LSDAPointerEncoding = DW_EH_PE_omit; 414 Optional<uint64_t> Personality; 415 Optional<uint32_t> PersonalityEncoding; 416 if (IsEH) { 417 Optional<uint64_t> AugmentationLength; 418 uint64_t StartAugmentationOffset; 419 uint64_t EndAugmentationOffset; 420 421 // Walk the augmentation string to get all the augmentation data. 422 for (unsigned i = 0, e = AugmentationString.size(); i != e; ++i) { 423 switch (AugmentationString[i]) { 424 default: 425 ReportError( 426 StartOffset, 427 "Unknown augmentation character in entry at %" PRIx64); 428 case 'L': 429 LSDAPointerEncoding = Data.getU8(&Offset); 430 break; 431 case 'P': { 432 if (Personality) 433 ReportError(StartOffset, 434 "Duplicate personality in entry at %" PRIx64); 435 PersonalityEncoding = Data.getU8(&Offset); 436 Personality = Data.getEncodedPointer( 437 &Offset, *PersonalityEncoding, 438 EHFrameAddress ? EHFrameAddress + Offset : 0); 439 break; 440 } 441 case 'R': 442 FDEPointerEncoding = Data.getU8(&Offset); 443 break; 444 case 'S': 445 // Current frame is a signal trampoline. 446 break; 447 case 'z': 448 if (i) 449 ReportError(StartOffset, 450 "'z' must be the first character at %" PRIx64); 451 // Parse the augmentation length first. We only parse it if 452 // the string contains a 'z'. 453 AugmentationLength = Data.getULEB128(&Offset); 454 StartAugmentationOffset = Offset; 455 EndAugmentationOffset = Offset + *AugmentationLength; 456 break; 457 case 'B': 458 // B-Key is used for signing functions associated with this 459 // augmentation string 460 break; 461 } 462 } 463 464 if (AugmentationLength.hasValue()) { 465 if (Offset != EndAugmentationOffset) 466 ReportError(StartOffset, 467 "Parsing augmentation data at %" PRIx64 " failed"); 468 469 AugmentationData = Data.getData().slice(StartAugmentationOffset, 470 EndAugmentationOffset); 471 } 472 } 473 474 auto Cie = std::make_unique<CIE>( 475 IsDWARF64, StartOffset, Length, Version, AugmentationString, 476 AddressSize, SegmentDescriptorSize, CodeAlignmentFactor, 477 DataAlignmentFactor, ReturnAddressRegister, AugmentationData, 478 FDEPointerEncoding, LSDAPointerEncoding, Personality, 479 PersonalityEncoding, Arch); 480 CIEs[StartOffset] = Cie.get(); 481 Entries.emplace_back(std::move(Cie)); 482 } else { 483 // FDE 484 uint64_t CIEPointer = Id; 485 uint64_t InitialLocation = 0; 486 uint64_t AddressRange = 0; 487 Optional<uint64_t> LSDAAddress; 488 CIE *Cie = CIEs[IsEH ? (StartStructureOffset - CIEPointer) : CIEPointer]; 489 490 if (IsEH) { 491 // The address size is encoded in the CIE we reference. 492 if (!Cie) 493 ReportError(StartOffset, "Parsing FDE data at %" PRIx64 494 " failed due to missing CIE"); 495 496 if (auto Val = Data.getEncodedPointer( 497 &Offset, Cie->getFDEPointerEncoding(), 498 EHFrameAddress ? EHFrameAddress + Offset : 0)) { 499 InitialLocation = *Val; 500 } 501 if (auto Val = Data.getEncodedPointer( 502 &Offset, Cie->getFDEPointerEncoding(), 0)) { 503 AddressRange = *Val; 504 } 505 506 StringRef AugmentationString = Cie->getAugmentationString(); 507 if (!AugmentationString.empty()) { 508 // Parse the augmentation length and data for this FDE. 509 uint64_t AugmentationLength = Data.getULEB128(&Offset); 510 511 uint64_t EndAugmentationOffset = Offset + AugmentationLength; 512 513 // Decode the LSDA if the CIE augmentation string said we should. 514 if (Cie->getLSDAPointerEncoding() != DW_EH_PE_omit) { 515 LSDAAddress = Data.getEncodedPointer( 516 &Offset, Cie->getLSDAPointerEncoding(), 517 EHFrameAddress ? Offset + EHFrameAddress : 0); 518 } 519 520 if (Offset != EndAugmentationOffset) 521 ReportError(StartOffset, 522 "Parsing augmentation data at %" PRIx64 " failed"); 523 } 524 } else { 525 InitialLocation = Data.getRelocatedAddress(&Offset); 526 AddressRange = Data.getRelocatedAddress(&Offset); 527 } 528 529 Entries.emplace_back(new FDE(IsDWARF64, StartOffset, Length, CIEPointer, 530 InitialLocation, AddressRange, Cie, 531 LSDAAddress, Arch)); 532 } 533 534 if (Error E = 535 Entries.back()->cfis().parse(Data, &Offset, EndStructureOffset)) { 536 report_fatal_error(toString(std::move(E))); 537 } 538 539 if (Offset != EndStructureOffset) 540 ReportError(StartOffset, 541 "Parsing entry instructions at %" PRIx64 " failed"); 542 } 543 } 544 545 FrameEntry *DWARFDebugFrame::getEntryAtOffset(uint64_t Offset) const { 546 auto It = partition_point(Entries, [=](const std::unique_ptr<FrameEntry> &E) { 547 return E->getOffset() < Offset; 548 }); 549 if (It != Entries.end() && (*It)->getOffset() == Offset) 550 return It->get(); 551 return nullptr; 552 } 553 554 void DWARFDebugFrame::dump(raw_ostream &OS, const MCRegisterInfo *MRI, 555 Optional<uint64_t> Offset) const { 556 if (Offset) { 557 if (auto *Entry = getEntryAtOffset(*Offset)) 558 Entry->dump(OS, MRI, IsEH); 559 return; 560 } 561 562 OS << "\n"; 563 for (const auto &Entry : Entries) 564 Entry->dump(OS, MRI, IsEH); 565 } 566