1 //===--- lib/CodeGen/DIE.cpp - DWARF Info Entries -------------------------===// 2 // 3 // The LLVM Compiler Infrastructure 4 // 5 // This file is distributed under the University of Illinois Open Source 6 // License. See LICENSE.TXT for details. 7 // 8 //===----------------------------------------------------------------------===// 9 // 10 // Data structures for DWARF info entries. 11 // 12 //===----------------------------------------------------------------------===// 13 14 #include "llvm/CodeGen/DIE.h" 15 #include "DwarfCompileUnit.h" 16 #include "DwarfDebug.h" 17 #include "DwarfUnit.h" 18 #include "llvm/ADT/Twine.h" 19 #include "llvm/CodeGen/AsmPrinter.h" 20 #include "llvm/IR/DataLayout.h" 21 #include "llvm/MC/MCAsmInfo.h" 22 #include "llvm/MC/MCContext.h" 23 #include "llvm/MC/MCStreamer.h" 24 #include "llvm/MC/MCSymbol.h" 25 #include "llvm/Support/Debug.h" 26 #include "llvm/Support/ErrorHandling.h" 27 #include "llvm/Support/Format.h" 28 #include "llvm/Support/FormattedStream.h" 29 #include "llvm/Support/LEB128.h" 30 #include "llvm/Support/MD5.h" 31 #include "llvm/Support/raw_ostream.h" 32 using namespace llvm; 33 34 //===----------------------------------------------------------------------===// 35 // EmittingAsmStreamer Implementation 36 //===----------------------------------------------------------------------===// 37 unsigned EmittingAsmStreamer::emitULEB128(uint64_t Value, const char *Desc, 38 unsigned PadTo) { 39 AP->EmitULEB128(Value, Desc, PadTo); 40 return 0; 41 } 42 43 unsigned EmittingAsmStreamer::emitInt8(unsigned char Value) { 44 AP->EmitInt8(Value); 45 return 0; 46 } 47 48 unsigned EmittingAsmStreamer::emitBytes(StringRef Data) { 49 AP->OutStreamer->EmitBytes(Data); 50 return 0; 51 } 52 53 //===----------------------------------------------------------------------===// 54 // SizeReporterAsmStreamer Implementation 55 //===----------------------------------------------------------------------===// 56 unsigned SizeReporterAsmStreamer::emitULEB128(uint64_t Value, const char *Desc, 57 unsigned PadTo) { 58 return getULEB128Size(Value); 59 } 60 61 unsigned SizeReporterAsmStreamer::emitInt8(unsigned char Value) { return 1; } 62 63 unsigned SizeReporterAsmStreamer::emitBytes(StringRef Data) { 64 return Data.size(); 65 } 66 67 //===----------------------------------------------------------------------===// 68 // DIEAbbrevData Implementation 69 //===----------------------------------------------------------------------===// 70 71 /// Profile - Used to gather unique data for the abbreviation folding set. 72 /// 73 void DIEAbbrevData::Profile(FoldingSetNodeID &ID) const { 74 // Explicitly cast to an integer type for which FoldingSetNodeID has 75 // overloads. Otherwise MSVC 2010 thinks this call is ambiguous. 76 ID.AddInteger(unsigned(Attribute)); 77 ID.AddInteger(unsigned(Form)); 78 } 79 80 //===----------------------------------------------------------------------===// 81 // DIEAbbrev Implementation 82 //===----------------------------------------------------------------------===// 83 84 /// Profile - Used to gather unique data for the abbreviation folding set. 85 /// 86 void DIEAbbrev::Profile(FoldingSetNodeID &ID) const { 87 ID.AddInteger(unsigned(Tag)); 88 ID.AddInteger(unsigned(Children)); 89 90 // For each attribute description. 91 for (unsigned i = 0, N = Data.size(); i < N; ++i) 92 Data[i].Profile(ID); 93 } 94 95 /// Emit - Print the abbreviation using the specified asm printer. 96 /// 97 void DIEAbbrev::Emit(const AsmPrinter *AP) const { 98 // Emit its Dwarf tag type. 99 AP->EmitULEB128(Tag, dwarf::TagString(Tag)); 100 101 // Emit whether it has children DIEs. 102 AP->EmitULEB128((unsigned)Children, dwarf::ChildrenString(Children)); 103 104 // For each attribute description. 105 for (unsigned i = 0, N = Data.size(); i < N; ++i) { 106 const DIEAbbrevData &AttrData = Data[i]; 107 108 // Emit attribute type. 109 AP->EmitULEB128(AttrData.getAttribute(), 110 dwarf::AttributeString(AttrData.getAttribute())); 111 112 // Emit form type. 113 AP->EmitULEB128(AttrData.getForm(), 114 dwarf::FormEncodingString(AttrData.getForm())); 115 } 116 117 // Mark end of abbreviation. 118 AP->EmitULEB128(0, "EOM(1)"); 119 AP->EmitULEB128(0, "EOM(2)"); 120 } 121 122 LLVM_DUMP_METHOD 123 void DIEAbbrev::print(raw_ostream &O) { 124 O << "Abbreviation @" 125 << format("0x%lx", (long)(intptr_t)this) 126 << " " 127 << dwarf::TagString(Tag) 128 << " " 129 << dwarf::ChildrenString(Children) 130 << '\n'; 131 132 for (unsigned i = 0, N = Data.size(); i < N; ++i) { 133 O << " " 134 << dwarf::AttributeString(Data[i].getAttribute()) 135 << " " 136 << dwarf::FormEncodingString(Data[i].getForm()) 137 << '\n'; 138 } 139 } 140 141 LLVM_DUMP_METHOD 142 void DIEAbbrev::dump() { print(dbgs()); } 143 144 DIEAbbrev DIE::generateAbbrev() const { 145 DIEAbbrev Abbrev(Tag, hasChildren()); 146 for (const DIEValue &V : values()) 147 Abbrev.AddAttribute(V.getAttribute(), V.getForm()); 148 return Abbrev; 149 } 150 151 /// Climb up the parent chain to get the unit DIE to which this DIE 152 /// belongs. 153 const DIE *DIE::getUnit() const { 154 const DIE *Cu = getUnitOrNull(); 155 assert(Cu && "We should not have orphaned DIEs."); 156 return Cu; 157 } 158 159 /// Climb up the parent chain to get the unit DIE this DIE belongs 160 /// to. Return NULL if DIE is not added to an owner yet. 161 const DIE *DIE::getUnitOrNull() const { 162 const DIE *p = this; 163 while (p) { 164 if (p->getTag() == dwarf::DW_TAG_compile_unit || 165 p->getTag() == dwarf::DW_TAG_type_unit) 166 return p; 167 p = p->getParent(); 168 } 169 return nullptr; 170 } 171 172 DIEValue DIE::findAttribute(dwarf::Attribute Attribute) const { 173 // Iterate through all the attributes until we find the one we're 174 // looking for, if we can't find it return NULL. 175 for (const auto &V : values()) 176 if (V.getAttribute() == Attribute) 177 return V; 178 return DIEValue(); 179 } 180 181 LLVM_DUMP_METHOD 182 static void printValues(raw_ostream &O, const DIEValueList &Values, 183 StringRef Type, unsigned Size, unsigned IndentCount) { 184 O << Type << ": Size: " << Size << "\n"; 185 186 unsigned I = 0; 187 const std::string Indent(IndentCount, ' '); 188 for (const auto &V : Values.values()) { 189 O << Indent; 190 O << "Blk[" << I++ << "]"; 191 O << " " << dwarf::FormEncodingString(V.getForm()) << " "; 192 V.print(O); 193 O << "\n"; 194 } 195 } 196 197 LLVM_DUMP_METHOD 198 void DIE::print(raw_ostream &O, unsigned IndentCount) const { 199 const std::string Indent(IndentCount, ' '); 200 O << Indent << "Die: " << format("0x%lx", (long)(intptr_t) this) 201 << ", Offset: " << Offset << ", Size: " << Size << "\n"; 202 203 O << Indent << dwarf::TagString(getTag()) << " " 204 << dwarf::ChildrenString(hasChildren()) << "\n"; 205 206 IndentCount += 2; 207 for (const auto &V : values()) { 208 O << Indent; 209 O << dwarf::AttributeString(V.getAttribute()); 210 O << " " << dwarf::FormEncodingString(V.getForm()) << " "; 211 V.print(O); 212 O << "\n"; 213 } 214 IndentCount -= 2; 215 216 for (const auto &Child : children()) 217 Child.print(O, IndentCount + 4); 218 219 O << "\n"; 220 } 221 222 LLVM_DUMP_METHOD 223 void DIE::dump() { 224 print(dbgs()); 225 } 226 227 void DIEValue::EmitValue(const AsmPrinter *AP) const { 228 switch (Ty) { 229 case isNone: 230 llvm_unreachable("Expected valid DIEValue"); 231 #define HANDLE_DIEVALUE(T) \ 232 case is##T: \ 233 getDIE##T().EmitValue(AP, Form); \ 234 break; 235 #include "llvm/CodeGen/DIEValue.def" 236 } 237 } 238 239 unsigned DIEValue::SizeOf(const AsmPrinter *AP) const { 240 switch (Ty) { 241 case isNone: 242 llvm_unreachable("Expected valid DIEValue"); 243 #define HANDLE_DIEVALUE(T) \ 244 case is##T: \ 245 return getDIE##T().SizeOf(AP, Form); 246 #include "llvm/CodeGen/DIEValue.def" 247 } 248 llvm_unreachable("Unknown DIE kind"); 249 } 250 251 LLVM_DUMP_METHOD 252 void DIEValue::print(raw_ostream &O) const { 253 switch (Ty) { 254 case isNone: 255 llvm_unreachable("Expected valid DIEValue"); 256 #define HANDLE_DIEVALUE(T) \ 257 case is##T: \ 258 getDIE##T().print(O); \ 259 break; 260 #include "llvm/CodeGen/DIEValue.def" 261 } 262 } 263 264 LLVM_DUMP_METHOD 265 void DIEValue::dump() const { 266 print(dbgs()); 267 } 268 269 //===----------------------------------------------------------------------===// 270 // DIEInteger Implementation 271 //===----------------------------------------------------------------------===// 272 273 /// EmitValue - Emit integer of appropriate size. 274 /// 275 void DIEInteger::EmitValue(const AsmPrinter *Asm, dwarf::Form Form) const { 276 unsigned Size = ~0U; 277 switch (Form) { 278 case dwarf::DW_FORM_flag_present: 279 // Emit something to keep the lines and comments in sync. 280 // FIXME: Is there a better way to do this? 281 Asm->OutStreamer->AddBlankLine(); 282 return; 283 case dwarf::DW_FORM_flag: // Fall thru 284 case dwarf::DW_FORM_ref1: // Fall thru 285 case dwarf::DW_FORM_data1: Size = 1; break; 286 case dwarf::DW_FORM_ref2: // Fall thru 287 case dwarf::DW_FORM_data2: Size = 2; break; 288 case dwarf::DW_FORM_sec_offset: // Fall thru 289 case dwarf::DW_FORM_strp: // Fall thru 290 case dwarf::DW_FORM_ref4: // Fall thru 291 case dwarf::DW_FORM_data4: Size = 4; break; 292 case dwarf::DW_FORM_ref8: // Fall thru 293 case dwarf::DW_FORM_ref_sig8: // Fall thru 294 case dwarf::DW_FORM_data8: Size = 8; break; 295 case dwarf::DW_FORM_GNU_str_index: Asm->EmitULEB128(Integer); return; 296 case dwarf::DW_FORM_GNU_addr_index: Asm->EmitULEB128(Integer); return; 297 case dwarf::DW_FORM_udata: Asm->EmitULEB128(Integer); return; 298 case dwarf::DW_FORM_sdata: Asm->EmitSLEB128(Integer); return; 299 case dwarf::DW_FORM_addr: 300 Size = Asm->getPointerSize(); 301 break; 302 case dwarf::DW_FORM_ref_addr: 303 Size = SizeOf(Asm, dwarf::DW_FORM_ref_addr); 304 break; 305 default: llvm_unreachable("DIE Value form not supported yet"); 306 } 307 Asm->OutStreamer->EmitIntValue(Integer, Size); 308 } 309 310 /// SizeOf - Determine size of integer value in bytes. 311 /// 312 unsigned DIEInteger::SizeOf(const AsmPrinter *AP, dwarf::Form Form) const { 313 switch (Form) { 314 case dwarf::DW_FORM_flag_present: return 0; 315 case dwarf::DW_FORM_flag: // Fall thru 316 case dwarf::DW_FORM_ref1: // Fall thru 317 case dwarf::DW_FORM_data1: return sizeof(int8_t); 318 case dwarf::DW_FORM_ref2: // Fall thru 319 case dwarf::DW_FORM_data2: return sizeof(int16_t); 320 case dwarf::DW_FORM_sec_offset: // Fall thru 321 case dwarf::DW_FORM_strp: // Fall thru 322 case dwarf::DW_FORM_ref4: // Fall thru 323 case dwarf::DW_FORM_data4: return sizeof(int32_t); 324 case dwarf::DW_FORM_ref8: // Fall thru 325 case dwarf::DW_FORM_ref_sig8: // Fall thru 326 case dwarf::DW_FORM_data8: return sizeof(int64_t); 327 case dwarf::DW_FORM_GNU_str_index: return getULEB128Size(Integer); 328 case dwarf::DW_FORM_GNU_addr_index: return getULEB128Size(Integer); 329 case dwarf::DW_FORM_udata: return getULEB128Size(Integer); 330 case dwarf::DW_FORM_sdata: return getSLEB128Size(Integer); 331 case dwarf::DW_FORM_addr: 332 return AP->getPointerSize(); 333 case dwarf::DW_FORM_ref_addr: 334 if (AP->OutStreamer->getContext().getDwarfVersion() == 2) 335 return AP->getPointerSize(); 336 return sizeof(int32_t); 337 default: llvm_unreachable("DIE Value form not supported yet"); 338 } 339 } 340 341 LLVM_DUMP_METHOD 342 void DIEInteger::print(raw_ostream &O) const { 343 O << "Int: " << (int64_t)Integer << " 0x"; 344 O.write_hex(Integer); 345 } 346 347 //===----------------------------------------------------------------------===// 348 // DIEExpr Implementation 349 //===----------------------------------------------------------------------===// 350 351 /// EmitValue - Emit expression value. 352 /// 353 void DIEExpr::EmitValue(const AsmPrinter *AP, dwarf::Form Form) const { 354 AP->OutStreamer->EmitValue(Expr, SizeOf(AP, Form)); 355 } 356 357 /// SizeOf - Determine size of expression value in bytes. 358 /// 359 unsigned DIEExpr::SizeOf(const AsmPrinter *AP, dwarf::Form Form) const { 360 if (Form == dwarf::DW_FORM_data4) return 4; 361 if (Form == dwarf::DW_FORM_sec_offset) return 4; 362 if (Form == dwarf::DW_FORM_strp) return 4; 363 return AP->getPointerSize(); 364 } 365 366 LLVM_DUMP_METHOD 367 void DIEExpr::print(raw_ostream &O) const { O << "Expr: " << *Expr; } 368 369 //===----------------------------------------------------------------------===// 370 // DIELabel Implementation 371 //===----------------------------------------------------------------------===// 372 373 /// EmitValue - Emit label value. 374 /// 375 void DIELabel::EmitValue(const AsmPrinter *AP, dwarf::Form Form) const { 376 AP->EmitLabelReference(Label, SizeOf(AP, Form), 377 Form == dwarf::DW_FORM_strp || 378 Form == dwarf::DW_FORM_sec_offset || 379 Form == dwarf::DW_FORM_ref_addr); 380 } 381 382 /// SizeOf - Determine size of label value in bytes. 383 /// 384 unsigned DIELabel::SizeOf(const AsmPrinter *AP, dwarf::Form Form) const { 385 if (Form == dwarf::DW_FORM_data4) return 4; 386 if (Form == dwarf::DW_FORM_sec_offset) return 4; 387 if (Form == dwarf::DW_FORM_strp) return 4; 388 return AP->getPointerSize(); 389 } 390 391 LLVM_DUMP_METHOD 392 void DIELabel::print(raw_ostream &O) const { O << "Lbl: " << Label->getName(); } 393 394 //===----------------------------------------------------------------------===// 395 // DIEDelta Implementation 396 //===----------------------------------------------------------------------===// 397 398 /// EmitValue - Emit delta value. 399 /// 400 void DIEDelta::EmitValue(const AsmPrinter *AP, dwarf::Form Form) const { 401 AP->EmitLabelDifference(LabelHi, LabelLo, SizeOf(AP, Form)); 402 } 403 404 /// SizeOf - Determine size of delta value in bytes. 405 /// 406 unsigned DIEDelta::SizeOf(const AsmPrinter *AP, dwarf::Form Form) const { 407 if (Form == dwarf::DW_FORM_data4) return 4; 408 if (Form == dwarf::DW_FORM_sec_offset) return 4; 409 if (Form == dwarf::DW_FORM_strp) return 4; 410 return AP->getPointerSize(); 411 } 412 413 LLVM_DUMP_METHOD 414 void DIEDelta::print(raw_ostream &O) const { 415 O << "Del: " << LabelHi->getName() << "-" << LabelLo->getName(); 416 } 417 418 //===----------------------------------------------------------------------===// 419 // DIEString Implementation 420 //===----------------------------------------------------------------------===// 421 422 /// EmitValue - Emit string value. 423 /// 424 void DIEString::EmitValue(const AsmPrinter *AP, dwarf::Form Form) const { 425 assert( 426 (Form == dwarf::DW_FORM_strp || Form == dwarf::DW_FORM_GNU_str_index) && 427 "Expected valid string form"); 428 429 // Index of string in symbol table. 430 if (Form == dwarf::DW_FORM_GNU_str_index) { 431 DIEInteger(S.getIndex()).EmitValue(AP, Form); 432 return; 433 } 434 435 // Relocatable symbol. 436 assert(Form == dwarf::DW_FORM_strp); 437 if (AP->MAI->doesDwarfUseRelocationsAcrossSections()) { 438 DIELabel(S.getSymbol()).EmitValue(AP, Form); 439 return; 440 } 441 442 // Offset into symbol table. 443 DIEInteger(S.getOffset()).EmitValue(AP, Form); 444 } 445 446 /// SizeOf - Determine size of delta value in bytes. 447 /// 448 unsigned DIEString::SizeOf(const AsmPrinter *AP, dwarf::Form Form) const { 449 assert( 450 (Form == dwarf::DW_FORM_strp || Form == dwarf::DW_FORM_GNU_str_index) && 451 "Expected valid string form"); 452 453 // Index of string in symbol table. 454 if (Form == dwarf::DW_FORM_GNU_str_index) 455 return DIEInteger(S.getIndex()).SizeOf(AP, Form); 456 457 // Relocatable symbol. 458 if (AP->MAI->doesDwarfUseRelocationsAcrossSections()) 459 return DIELabel(S.getSymbol()).SizeOf(AP, Form); 460 461 // Offset into symbol table. 462 return DIEInteger(S.getOffset()).SizeOf(AP, Form); 463 } 464 465 LLVM_DUMP_METHOD 466 void DIEString::print(raw_ostream &O) const { 467 O << "String: " << S.getString(); 468 } 469 470 //===----------------------------------------------------------------------===// 471 // DIEEntry Implementation 472 //===----------------------------------------------------------------------===// 473 474 /// EmitValue - Emit debug information entry offset. 475 /// 476 void DIEEntry::EmitValue(const AsmPrinter *AP, dwarf::Form Form) const { 477 478 if (Form == dwarf::DW_FORM_ref_addr) { 479 const DwarfDebug *DD = AP->getDwarfDebug(); 480 unsigned Addr = Entry->getOffset(); 481 assert(!DD->useSplitDwarf() && "TODO: dwo files can't have relocations."); 482 // For DW_FORM_ref_addr, output the offset from beginning of debug info 483 // section. Entry->getOffset() returns the offset from start of the 484 // compile unit. 485 DwarfCompileUnit *CU = DD->lookupUnit(Entry->getUnit()); 486 assert(CU && "CUDie should belong to a CU."); 487 Addr += CU->getDebugInfoOffset(); 488 if (AP->MAI->doesDwarfUseRelocationsAcrossSections()) 489 AP->EmitLabelPlusOffset(CU->getSectionSym(), Addr, 490 DIEEntry::getRefAddrSize(AP)); 491 else 492 AP->OutStreamer->EmitIntValue(Addr, DIEEntry::getRefAddrSize(AP)); 493 } else 494 AP->EmitInt32(Entry->getOffset()); 495 } 496 497 unsigned DIEEntry::getRefAddrSize(const AsmPrinter *AP) { 498 // DWARF4: References that use the attribute form DW_FORM_ref_addr are 499 // specified to be four bytes in the DWARF 32-bit format and eight bytes 500 // in the DWARF 64-bit format, while DWARF Version 2 specifies that such 501 // references have the same size as an address on the target system. 502 const DwarfDebug *DD = AP->getDwarfDebug(); 503 assert(DD && "Expected Dwarf Debug info to be available"); 504 if (DD->getDwarfVersion() == 2) 505 return AP->getPointerSize(); 506 return sizeof(int32_t); 507 } 508 509 LLVM_DUMP_METHOD 510 void DIEEntry::print(raw_ostream &O) const { 511 O << format("Die: 0x%lx", (long)(intptr_t)&Entry); 512 } 513 514 //===----------------------------------------------------------------------===// 515 // DIETypeSignature Implementation 516 //===----------------------------------------------------------------------===// 517 void DIETypeSignature::EmitValue(const AsmPrinter *Asm, 518 dwarf::Form Form) const { 519 assert(Form == dwarf::DW_FORM_ref_sig8); 520 Asm->OutStreamer->EmitIntValue(Unit->getTypeSignature(), 8); 521 } 522 523 LLVM_DUMP_METHOD 524 void DIETypeSignature::print(raw_ostream &O) const { 525 O << format("Type Unit: 0x%lx", Unit->getTypeSignature()); 526 } 527 528 //===----------------------------------------------------------------------===// 529 // DIELoc Implementation 530 //===----------------------------------------------------------------------===// 531 532 /// ComputeSize - calculate the size of the location expression. 533 /// 534 unsigned DIELoc::ComputeSize(const AsmPrinter *AP) const { 535 if (!Size) { 536 for (const auto &V : values()) 537 Size += V.SizeOf(AP); 538 } 539 540 return Size; 541 } 542 543 /// EmitValue - Emit location data. 544 /// 545 void DIELoc::EmitValue(const AsmPrinter *Asm, dwarf::Form Form) const { 546 switch (Form) { 547 default: llvm_unreachable("Improper form for block"); 548 case dwarf::DW_FORM_block1: Asm->EmitInt8(Size); break; 549 case dwarf::DW_FORM_block2: Asm->EmitInt16(Size); break; 550 case dwarf::DW_FORM_block4: Asm->EmitInt32(Size); break; 551 case dwarf::DW_FORM_block: 552 case dwarf::DW_FORM_exprloc: 553 Asm->EmitULEB128(Size); break; 554 } 555 556 for (const auto &V : values()) 557 V.EmitValue(Asm); 558 } 559 560 /// SizeOf - Determine size of location data in bytes. 561 /// 562 unsigned DIELoc::SizeOf(const AsmPrinter *AP, dwarf::Form Form) const { 563 switch (Form) { 564 case dwarf::DW_FORM_block1: return Size + sizeof(int8_t); 565 case dwarf::DW_FORM_block2: return Size + sizeof(int16_t); 566 case dwarf::DW_FORM_block4: return Size + sizeof(int32_t); 567 case dwarf::DW_FORM_block: 568 case dwarf::DW_FORM_exprloc: 569 return Size + getULEB128Size(Size); 570 default: llvm_unreachable("Improper form for block"); 571 } 572 } 573 574 LLVM_DUMP_METHOD 575 void DIELoc::print(raw_ostream &O) const { 576 printValues(O, *this, "ExprLoc", Size, 5); 577 } 578 579 //===----------------------------------------------------------------------===// 580 // DIEBlock Implementation 581 //===----------------------------------------------------------------------===// 582 583 /// ComputeSize - calculate the size of the block. 584 /// 585 unsigned DIEBlock::ComputeSize(const AsmPrinter *AP) const { 586 if (!Size) { 587 for (const auto &V : values()) 588 Size += V.SizeOf(AP); 589 } 590 591 return Size; 592 } 593 594 /// EmitValue - Emit block data. 595 /// 596 void DIEBlock::EmitValue(const AsmPrinter *Asm, dwarf::Form Form) const { 597 switch (Form) { 598 default: llvm_unreachable("Improper form for block"); 599 case dwarf::DW_FORM_block1: Asm->EmitInt8(Size); break; 600 case dwarf::DW_FORM_block2: Asm->EmitInt16(Size); break; 601 case dwarf::DW_FORM_block4: Asm->EmitInt32(Size); break; 602 case dwarf::DW_FORM_block: Asm->EmitULEB128(Size); break; 603 } 604 605 for (const auto &V : values()) 606 V.EmitValue(Asm); 607 } 608 609 /// SizeOf - Determine size of block data in bytes. 610 /// 611 unsigned DIEBlock::SizeOf(const AsmPrinter *AP, dwarf::Form Form) const { 612 switch (Form) { 613 case dwarf::DW_FORM_block1: return Size + sizeof(int8_t); 614 case dwarf::DW_FORM_block2: return Size + sizeof(int16_t); 615 case dwarf::DW_FORM_block4: return Size + sizeof(int32_t); 616 case dwarf::DW_FORM_block: return Size + getULEB128Size(Size); 617 default: llvm_unreachable("Improper form for block"); 618 } 619 } 620 621 LLVM_DUMP_METHOD 622 void DIEBlock::print(raw_ostream &O) const { 623 printValues(O, *this, "Blk", Size, 5); 624 } 625 626 //===----------------------------------------------------------------------===// 627 // DIELocList Implementation 628 //===----------------------------------------------------------------------===// 629 630 unsigned DIELocList::SizeOf(const AsmPrinter *AP, dwarf::Form Form) const { 631 if (Form == dwarf::DW_FORM_data4) 632 return 4; 633 if (Form == dwarf::DW_FORM_sec_offset) 634 return 4; 635 return AP->getPointerSize(); 636 } 637 638 /// EmitValue - Emit label value. 639 /// 640 void DIELocList::EmitValue(const AsmPrinter *AP, dwarf::Form Form) const { 641 DwarfDebug *DD = AP->getDwarfDebug(); 642 MCSymbol *Label = DD->getDebugLocs().getList(Index).Label; 643 AP->emitDwarfSymbolReference(Label, /*ForceOffset*/ DD->useSplitDwarf()); 644 } 645 646 LLVM_DUMP_METHOD 647 void DIELocList::print(raw_ostream &O) const { O << "LocList: " << Index; } 648