LCOV - code coverage report
Current view: top level - lib/CodeGen/AsmPrinter - DIE.cpp (source / functions) Hit Total Coverage
Test: llvm-toolchain.info Lines: 250 354 70.6 %
Date: 2017-09-14 15:23:50 Functions: 38 52 73.1 %
Legend: Lines: hit not hit

          Line data    Source code
       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             : #define DEBUG_TYPE "dwarfdebug"
      35             : 
      36             : //===----------------------------------------------------------------------===//
      37             : // DIEAbbrevData Implementation
      38             : //===----------------------------------------------------------------------===//
      39             : 
      40             : /// Profile - Used to gather unique data for the abbreviation folding set.
      41             : ///
      42     1608028 : void DIEAbbrevData::Profile(FoldingSetNodeID &ID) const {
      43             :   // Explicitly cast to an integer type for which FoldingSetNodeID has
      44             :   // overloads.  Otherwise MSVC 2010 thinks this call is ambiguous.
      45     1608028 :   ID.AddInteger(unsigned(Attribute));
      46     1608028 :   ID.AddInteger(unsigned(Form));
      47     1608028 :   if (Form == dwarf::DW_FORM_implicit_const)
      48           6 :     ID.AddInteger(Value);
      49     1608028 : }
      50             : 
      51             : //===----------------------------------------------------------------------===//
      52             : // DIEAbbrev Implementation
      53             : //===----------------------------------------------------------------------===//
      54             : 
      55             : /// Profile - Used to gather unique data for the abbreviation folding set.
      56             : ///
      57      452035 : void DIEAbbrev::Profile(FoldingSetNodeID &ID) const {
      58      452035 :   ID.AddInteger(unsigned(Tag));
      59      452035 :   ID.AddInteger(unsigned(Children));
      60             : 
      61             :   // For each attribute description.
      62     2512098 :   for (unsigned i = 0, N = Data.size(); i < N; ++i)
      63     3216056 :     Data[i].Profile(ID);
      64      452035 : }
      65             : 
      66             : /// Emit - Print the abbreviation using the specified asm printer.
      67             : ///
      68        7878 : void DIEAbbrev::Emit(const AsmPrinter *AP) const {
      69             :   // Emit its Dwarf tag type.
      70       15756 :   AP->EmitULEB128(Tag, dwarf::TagString(Tag).data());
      71             : 
      72             :   // Emit whether it has children DIEs.
      73       15756 :   AP->EmitULEB128((unsigned)Children, dwarf::ChildrenString(Children).data());
      74             : 
      75             :   // For each attribute description.
      76       51102 :   for (unsigned i = 0, N = Data.size(); i < N; ++i) {
      77       70692 :     const DIEAbbrevData &AttrData = Data[i];
      78             : 
      79             :     // Emit attribute type.
      80       35346 :     AP->EmitULEB128(AttrData.getAttribute(),
      81       70692 :                     dwarf::AttributeString(AttrData.getAttribute()).data());
      82             : 
      83             :     // Emit form type.
      84             : #ifndef NDEBUG
      85             :     // Could be an assertion, but this way we can see the failing form code
      86             :     // easily, which helps track down where it came from.
      87             :     if (!dwarf::isValidFormForVersion(AttrData.getForm(),
      88             :                                       AP->getDwarfVersion())) {
      89             :       DEBUG(dbgs() << "Invalid form " << format("0x%x", AttrData.getForm())
      90             :                    << " for DWARF version " << AP->getDwarfVersion() << "\n");
      91             :       llvm_unreachable("Invalid form for specified DWARF version");
      92             :     }
      93             : #endif
      94       35346 :     AP->EmitULEB128(AttrData.getForm(),
      95       70692 :                     dwarf::FormEncodingString(AttrData.getForm()).data());
      96             : 
      97             :     // Emit value for DW_FORM_implicit_const.
      98       35346 :     if (AttrData.getForm() == dwarf::DW_FORM_implicit_const)
      99           4 :       AP->EmitSLEB128(AttrData.getValue());
     100             :   }
     101             : 
     102             :   // Mark end of abbreviation.
     103        7878 :   AP->EmitULEB128(0, "EOM(1)");
     104        7878 :   AP->EmitULEB128(0, "EOM(2)");
     105        7878 : }
     106             : 
     107             : LLVM_DUMP_METHOD
     108           0 : void DIEAbbrev::print(raw_ostream &O) const {
     109           0 :   O << "Abbreviation @"
     110           0 :     << format("0x%lx", (long)(intptr_t)this)
     111           0 :     << "  "
     112           0 :     << dwarf::TagString(Tag)
     113           0 :     << " "
     114           0 :     << dwarf::ChildrenString(Children)
     115           0 :     << '\n';
     116             : 
     117           0 :   for (unsigned i = 0, N = Data.size(); i < N; ++i) {
     118           0 :     O << "  "
     119           0 :       << dwarf::AttributeString(Data[i].getAttribute())
     120           0 :       << "  "
     121           0 :       << dwarf::FormEncodingString(Data[i].getForm());
     122             : 
     123           0 :     if (Data[i].getForm() == dwarf::DW_FORM_implicit_const)
     124           0 :       O << " " << Data[i].getValue();
     125             : 
     126           0 :     O << '\n';
     127             :   }
     128           0 : }
     129             : 
     130             : #if !defined(NDEBUG) || defined(LLVM_ENABLE_DUMP)
     131             : LLVM_DUMP_METHOD void DIEAbbrev::dump() const {
     132             :   print(dbgs());
     133             : }
     134             : #endif
     135             : 
     136             : //===----------------------------------------------------------------------===//
     137             : // DIEAbbrevSet Implementation
     138             : //===----------------------------------------------------------------------===//
     139             : 
     140      131156 : DIEAbbrevSet::~DIEAbbrevSet() {
     141      138543 :   for (DIEAbbrev *Abbrev : Abbreviations)
     142        7387 :     Abbrev->~DIEAbbrev();
     143       32789 : }
     144             : 
     145      201818 : DIEAbbrev &DIEAbbrevSet::uniqueAbbreviation(DIE &Die) {
     146             : 
     147      403636 :   FoldingSetNodeID ID;
     148      403636 :   DIEAbbrev Abbrev = Die.generateAbbrev();
     149      201818 :   Abbrev.Profile(ID);
     150             : 
     151             :   void *InsertPos;
     152      201818 :   if (DIEAbbrev *Existing =
     153      403636 :           AbbreviationsSet.FindNodeOrInsertPos(ID, InsertPos)) {
     154      388862 :     Die.setAbbrevNumber(Existing->getNumber());
     155      194431 :     return *Existing;
     156             :   }
     157             : 
     158             :   // Move the abbreviation to the heap and assign a number.
     159       14774 :   DIEAbbrev *New = new (Alloc) DIEAbbrev(std::move(Abbrev));
     160        7387 :   Abbreviations.push_back(New);
     161       22161 :   New->setNumber(Abbreviations.size());
     162       14774 :   Die.setAbbrevNumber(Abbreviations.size());
     163             : 
     164             :   // Store it for lookup.
     165       14774 :   AbbreviationsSet.InsertNode(New, InsertPos);
     166        7387 :   return *New;
     167             : }
     168             : 
     169         781 : void DIEAbbrevSet::Emit(const AsmPrinter *AP, MCSection *Section) const {
     170        1562 :   if (!Abbreviations.empty()) {
     171             :     // Start the debug abbrev section.
     172        1494 :     AP->OutStreamer->SwitchSection(Section);
     173         747 :     AP->emitDwarfAbbrevs(Abbreviations);
     174             :   }
     175         781 : }
     176             : 
     177             : //===----------------------------------------------------------------------===//
     178             : // DIE Implementation
     179             : //===----------------------------------------------------------------------===//
     180             : 
     181      616056 : DIE *DIE::getParent() const {
     182     1232112 :   return Owner.dyn_cast<DIE*>();
     183             : }
     184             : 
     185      202721 : DIEAbbrev DIE::generateAbbrev() const {
     186      405442 :   DIEAbbrev Abbrev(Tag, hasChildren());
     187     1839794 :   for (const DIEValue &V : values())
     188      717176 :     if (V.getForm() == dwarf::DW_FORM_implicit_const)
     189           5 :       Abbrev.AddImplicitConstAttribute(V.getAttribute(),
     190           5 :                                        V.getDIEInteger().getValue());
     191             :     else
     192      717171 :       Abbrev.AddAttribute(V.getAttribute(), V.getForm());
     193      202721 :   return Abbrev;
     194             : }
     195             : 
     196        1045 : unsigned DIE::getDebugSectionOffset() const {
     197        1045 :   const DIEUnit *Unit = getUnit();
     198             :   assert(Unit && "DIE must be owned by a DIEUnit to get its absolute offset");
     199        2090 :   return Unit->getDebugSectionOffset() + getOffset();
     200             : }
     201             : 
     202      464130 : const DIE *DIE::getUnitDie() const {
     203      464130 :   const DIE *p = this;
     204     1696094 :   while (p) {
     205     1596028 :     if (p->getTag() == dwarf::DW_TAG_compile_unit ||
     206      616076 :         p->getTag() == dwarf::DW_TAG_type_unit)
     207             :       return p;
     208      615982 :     p = p->getParent();
     209             :   }
     210             :   return nullptr;
     211             : }
     212             : 
     213      453511 : const DIEUnit *DIE::getUnit() const {
     214      453511 :   const DIE *UnitDie = getUnitDie();
     215      453511 :   if (UnitDie)
     216      353351 :     return UnitDie->Owner.dyn_cast<DIEUnit*>();
     217             :   return nullptr;
     218             : }
     219             : 
     220         100 : DIEValue DIE::findAttribute(dwarf::Attribute Attribute) const {
     221             :   // Iterate through all the attributes until we find the one we're
     222             :   // looking for, if we can't find it return NULL.
     223        1070 :   for (const auto &V : values())
     224         449 :     if (V.getAttribute() == Attribute)
     225          28 :       return V;
     226          72 :   return DIEValue();
     227             : }
     228             : 
     229             : LLVM_DUMP_METHOD
     230           0 : static void printValues(raw_ostream &O, const DIEValueList &Values,
     231             :                         StringRef Type, unsigned Size, unsigned IndentCount) {
     232           0 :   O << Type << ": Size: " << Size << "\n";
     233             : 
     234           0 :   unsigned I = 0;
     235           0 :   const std::string Indent(IndentCount, ' ');
     236           0 :   for (const auto &V : Values.values()) {
     237           0 :     O << Indent;
     238           0 :     O << "Blk[" << I++ << "]";
     239           0 :     O << "  " << dwarf::FormEncodingString(V.getForm()) << " ";
     240           0 :     V.print(O);
     241           0 :     O << "\n";
     242             :   }
     243           0 : }
     244             : 
     245             : LLVM_DUMP_METHOD
     246           0 : void DIE::print(raw_ostream &O, unsigned IndentCount) const {
     247           0 :   const std::string Indent(IndentCount, ' ');
     248           0 :   O << Indent << "Die: " << format("0x%lx", (long)(intptr_t) this)
     249           0 :     << ", Offset: " << Offset << ", Size: " << Size << "\n";
     250             : 
     251           0 :   O << Indent << dwarf::TagString(getTag()) << " "
     252           0 :     << dwarf::ChildrenString(hasChildren()) << "\n";
     253             : 
     254           0 :   IndentCount += 2;
     255           0 :   for (const auto &V : values()) {
     256           0 :     O << Indent;
     257           0 :     O << dwarf::AttributeString(V.getAttribute());
     258           0 :     O << "  " << dwarf::FormEncodingString(V.getForm()) << " ";
     259           0 :     V.print(O);
     260           0 :     O << "\n";
     261             :   }
     262           0 :   IndentCount -= 2;
     263             : 
     264           0 :   for (const auto &Child : children())
     265           0 :     Child.print(O, IndentCount + 4);
     266             : 
     267           0 :   O << "\n";
     268           0 : }
     269             : 
     270             : #if !defined(NDEBUG) || defined(LLVM_ENABLE_DUMP)
     271             : LLVM_DUMP_METHOD void DIE::dump() const {
     272             :   print(dbgs());
     273             : }
     274             : #endif
     275             : 
     276      201818 : unsigned DIE::computeOffsetsAndAbbrevs(const AsmPrinter *AP,
     277             :                                        DIEAbbrevSet &AbbrevSet,
     278             :                                        unsigned CUOffset) {
     279             :   // Unique the abbreviation and fill in the abbreviation number so this DIE
     280             :   // can be emitted.
     281      201818 :   const DIEAbbrev &Abbrev = AbbrevSet.uniqueAbbreviation(*this);
     282             : 
     283             :   // Set compile/type unit relative offset of this DIE.
     284      403636 :   setOffset(CUOffset);
     285             : 
     286             :   // Add the byte size of the abbreviation code.
     287      201818 :   CUOffset += getULEB128Size(getAbbrevNumber());
     288             : 
     289             :   // Add the byte size of all the DIE attribute values.
     290     1829322 :   for (const auto &V : values())
     291      712843 :     CUOffset += V.SizeOf(AP);
     292             : 
     293             :   // Let the children compute their offsets and abbreviation numbers.
     294             :   if (hasChildren()) {
     295             :     (void)Abbrev;
     296             :     assert(Abbrev.hasChildren() && "Children flag not set");
     297             : 
     298      272229 :     for (auto &Child : children())
     299      200990 :       CUOffset = Child.computeOffsetsAndAbbrevs(AP, AbbrevSet, CUOffset);
     300             : 
     301             :     // Each child chain is terminated with a zero byte, adjust the offset.
     302       71239 :     CUOffset += sizeof(int8_t);
     303             :   }
     304             : 
     305             :   // Compute the byte size of this DIE and all of its children correctly. This
     306             :   // is needed so that top level DIE can help the compile unit set its length
     307             :   // correctly.
     308      403636 :   setSize(CUOffset - getOffset());
     309      201818 :   return CUOffset;
     310             : }
     311             : 
     312             : //===----------------------------------------------------------------------===//
     313             : // DIEUnit Implementation
     314             : //===----------------------------------------------------------------------===//
     315         956 : DIEUnit::DIEUnit(uint16_t V, uint8_t A, dwarf::Tag UnitTag)
     316             :     : Die(UnitTag), Section(nullptr), Offset(0), Length(0), Version(V),
     317        1912 :       AddrSize(A)
     318             : {
     319        1912 :   Die.Owner = this;
     320             :   assert((UnitTag == dwarf::DW_TAG_compile_unit ||
     321             :           UnitTag == dwarf::DW_TAG_type_unit ||
     322             :           UnitTag == dwarf::DW_TAG_partial_unit) && "expected a unit TAG");
     323         956 : }
     324             : 
     325      721823 : void DIEValue::EmitValue(const AsmPrinter *AP) const {
     326      721823 :   switch (Ty) {
     327           0 :   case isNone:
     328           0 :     llvm_unreachable("Expected valid DIEValue");
     329             : #define HANDLE_DIEVALUE(T)                                                     \
     330             :   case is##T:                                                                  \
     331             :     getDIE##T().EmitValue(AP, Form);                                           \
     332             :     break;
     333             : #include "llvm/CodeGen/DIEValue.def"
     334             :   }
     335      721823 : }
     336             : 
     337      717515 : unsigned DIEValue::SizeOf(const AsmPrinter *AP) const {
     338      717515 :   switch (Ty) {
     339           0 :   case isNone:
     340           0 :     llvm_unreachable("Expected valid DIEValue");
     341             : #define HANDLE_DIEVALUE(T)                                                     \
     342             :   case is##T:                                                                  \
     343             :     return getDIE##T().SizeOf(AP, Form);
     344             : #include "llvm/CodeGen/DIEValue.def"
     345             :   }
     346           0 :   llvm_unreachable("Unknown DIE kind");
     347             : }
     348             : 
     349             : LLVM_DUMP_METHOD
     350           0 : void DIEValue::print(raw_ostream &O) const {
     351           0 :   switch (Ty) {
     352           0 :   case isNone:
     353           0 :     llvm_unreachable("Expected valid DIEValue");
     354             : #define HANDLE_DIEVALUE(T)                                                     \
     355             :   case is##T:                                                                  \
     356             :     getDIE##T().print(O);                                                      \
     357             :     break;
     358             : #include "llvm/CodeGen/DIEValue.def"
     359             :   }
     360           0 : }
     361             : 
     362             : #if !defined(NDEBUG) || defined(LLVM_ENABLE_DUMP)
     363             : LLVM_DUMP_METHOD void DIEValue::dump() const {
     364             :   print(dbgs());
     365             : }
     366             : #endif
     367             : 
     368             : //===----------------------------------------------------------------------===//
     369             : // DIEInteger Implementation
     370             : //===----------------------------------------------------------------------===//
     371             : 
     372             : /// EmitValue - Emit integer of appropriate size.
     373             : ///
     374      334191 : void DIEInteger::EmitValue(const AsmPrinter *Asm, dwarf::Form Form) const {
     375      334191 :   switch (Form) {
     376       46940 :   case dwarf::DW_FORM_implicit_const:
     377             :   case dwarf::DW_FORM_flag_present:
     378             :     // Emit something to keep the lines and comments in sync.
     379             :     // FIXME: Is there a better way to do this?
     380       93880 :     Asm->OutStreamer->AddBlankLine();
     381       46940 :     return;
     382      283914 :   case dwarf::DW_FORM_flag:
     383             :   case dwarf::DW_FORM_ref1:
     384             :   case dwarf::DW_FORM_data1:
     385             :   case dwarf::DW_FORM_strx1:
     386             :   case dwarf::DW_FORM_addrx1:
     387             :   case dwarf::DW_FORM_ref2:
     388             :   case dwarf::DW_FORM_data2:
     389             :   case dwarf::DW_FORM_strx2:
     390             :   case dwarf::DW_FORM_addrx2:
     391             :   case dwarf::DW_FORM_strp:
     392             :   case dwarf::DW_FORM_ref4:
     393             :   case dwarf::DW_FORM_data4:
     394             :   case dwarf::DW_FORM_ref_sup4:
     395             :   case dwarf::DW_FORM_strx4:
     396             :   case dwarf::DW_FORM_addrx4:
     397             :   case dwarf::DW_FORM_ref8:
     398             :   case dwarf::DW_FORM_ref_sig8:
     399             :   case dwarf::DW_FORM_data8:
     400             :   case dwarf::DW_FORM_ref_sup8:
     401             :   case dwarf::DW_FORM_GNU_ref_alt:
     402             :   case dwarf::DW_FORM_GNU_strp_alt:
     403             :   case dwarf::DW_FORM_line_strp:
     404             :   case dwarf::DW_FORM_sec_offset:
     405             :   case dwarf::DW_FORM_strp_sup:
     406             :   case dwarf::DW_FORM_addr:
     407             :   case dwarf::DW_FORM_ref_addr:
     408      567828 :     Asm->OutStreamer->EmitIntValue(Integer, SizeOf(Asm, Form));
     409      283914 :     return;
     410        2353 :   case dwarf::DW_FORM_GNU_str_index:
     411             :   case dwarf::DW_FORM_GNU_addr_index:
     412             :   case dwarf::DW_FORM_ref_udata:
     413             :   case dwarf::DW_FORM_udata:
     414        2353 :     Asm->EmitULEB128(Integer);
     415        2353 :     return;
     416         984 :   case dwarf::DW_FORM_sdata:
     417         984 :     Asm->EmitSLEB128(Integer);
     418         984 :     return;
     419           0 :   default: llvm_unreachable("DIE Value form not supported yet");
     420             :   }
     421             : }
     422             : 
     423             : /// SizeOf - Determine size of integer value in bytes.
     424             : ///
     425      614548 : unsigned DIEInteger::SizeOf(const AsmPrinter *AP, dwarf::Form Form) const {
     426      614548 :   switch (Form) {
     427             :   case dwarf::DW_FORM_implicit_const:
     428             :   case dwarf::DW_FORM_flag_present:
     429             :     return 0;
     430      416681 :   case dwarf::DW_FORM_flag:
     431             :   case dwarf::DW_FORM_ref1:
     432             :   case dwarf::DW_FORM_data1:
     433             :   case dwarf::DW_FORM_strx1:
     434             :   case dwarf::DW_FORM_addrx1:
     435      416681 :     return sizeof(int8_t);
     436      140544 :   case dwarf::DW_FORM_ref2:
     437             :   case dwarf::DW_FORM_data2:
     438             :   case dwarf::DW_FORM_strx2:
     439             :   case dwarf::DW_FORM_addrx2:
     440      140544 :     return sizeof(int16_t);
     441         482 :   case dwarf::DW_FORM_ref4:
     442             :   case dwarf::DW_FORM_data4:
     443             :   case dwarf::DW_FORM_ref_sup4:
     444             :   case dwarf::DW_FORM_strx4:
     445             :   case dwarf::DW_FORM_addrx4:
     446         482 :     return sizeof(int32_t);
     447         286 :   case dwarf::DW_FORM_ref8:
     448             :   case dwarf::DW_FORM_ref_sig8:
     449             :   case dwarf::DW_FORM_data8:
     450             :   case dwarf::DW_FORM_ref_sup8:
     451         286 :     return sizeof(int64_t);
     452         178 :   case dwarf::DW_FORM_ref_addr:
     453         178 :     if (AP->getDwarfVersion() == 2)
     454         102 :       return AP->getPointerSize();
     455             :     LLVM_FALLTHROUGH;
     456             :   case dwarf::DW_FORM_strp:
     457             :   case dwarf::DW_FORM_GNU_ref_alt:
     458             :   case dwarf::DW_FORM_GNU_strp_alt:
     459             :   case dwarf::DW_FORM_line_strp:
     460             :   case dwarf::DW_FORM_sec_offset:
     461             :   case dwarf::DW_FORM_strp_sup:
     462       11178 :     switch (AP->OutStreamer->getContext().getDwarfFormat()) {
     463             :     case dwarf::DWARF32:
     464        5589 :       return 4;
     465             :     case dwarf::DWARF64:
     466             :       return 8;
     467             :     }
     468             :     llvm_unreachable("Invalid DWARF format");
     469        2360 :   case dwarf::DW_FORM_GNU_str_index:
     470             :   case dwarf::DW_FORM_GNU_addr_index:
     471             :   case dwarf::DW_FORM_ref_udata:
     472             :   case dwarf::DW_FORM_udata:
     473        2360 :     return getULEB128Size(Integer);
     474         984 :   case dwarf::DW_FORM_sdata:
     475         984 :     return getSLEB128Size(Integer);
     476         639 :   case dwarf::DW_FORM_addr:
     477         639 :     return AP->getPointerSize();
     478           0 :   default: llvm_unreachable("DIE Value form not supported yet");
     479             :   }
     480             : }
     481             : 
     482             : LLVM_DUMP_METHOD
     483           0 : void DIEInteger::print(raw_ostream &O) const {
     484           0 :   O << "Int: " << (int64_t)Integer << "  0x";
     485           0 :   O.write_hex(Integer);
     486           0 : }
     487             : 
     488             : //===----------------------------------------------------------------------===//
     489             : // DIEExpr Implementation
     490             : //===----------------------------------------------------------------------===//
     491             : 
     492             : /// EmitValue - Emit expression value.
     493             : ///
     494          13 : void DIEExpr::EmitValue(const AsmPrinter *AP, dwarf::Form Form) const {
     495          13 :   AP->EmitDebugThreadLocal(Expr, SizeOf(AP, Form));
     496          13 : }
     497             : 
     498             : /// SizeOf - Determine size of expression value in bytes.
     499             : ///
     500          26 : unsigned DIEExpr::SizeOf(const AsmPrinter *AP, dwarf::Form Form) const {
     501          26 :   if (Form == dwarf::DW_FORM_data4) return 4;
     502          26 :   if (Form == dwarf::DW_FORM_sec_offset) return 4;
     503          26 :   if (Form == dwarf::DW_FORM_strp) return 4;
     504          26 :   return AP->getPointerSize();
     505             : }
     506             : 
     507             : LLVM_DUMP_METHOD
     508           0 : void DIEExpr::print(raw_ostream &O) const { O << "Expr: " << *Expr; }
     509             : 
     510             : //===----------------------------------------------------------------------===//
     511             : // DIELabel Implementation
     512             : //===----------------------------------------------------------------------===//
     513             : 
     514             : /// EmitValue - Emit label value.
     515             : ///
     516      160834 : void DIELabel::EmitValue(const AsmPrinter *AP, dwarf::Form Form) const {
     517      321668 :   AP->EmitLabelReference(Label, SizeOf(AP, Form),
     518      321668 :                          Form == dwarf::DW_FORM_strp ||
     519      160834 :                              Form == dwarf::DW_FORM_sec_offset ||
     520      200377 :                              Form == dwarf::DW_FORM_ref_addr ||
     521       39543 :                              Form == dwarf::DW_FORM_data4);
     522      160834 : }
     523             : 
     524             : /// SizeOf - Determine size of label value in bytes.
     525             : ///
     526      321668 : unsigned DIELabel::SizeOf(const AsmPrinter *AP, dwarf::Form Form) const {
     527      321668 :   if (Form == dwarf::DW_FORM_data4) return 4;
     528      321510 :   if (Form == dwarf::DW_FORM_sec_offset) return 4;
     529      211188 :   if (Form == dwarf::DW_FORM_strp) return 4;
     530       78928 :   return AP->MAI->getCodePointerSize();
     531             : }
     532             : 
     533             : LLVM_DUMP_METHOD
     534           0 : void DIELabel::print(raw_ostream &O) const { O << "Lbl: " << Label->getName(); }
     535             : 
     536             : //===----------------------------------------------------------------------===//
     537             : // DIEDelta Implementation
     538             : //===----------------------------------------------------------------------===//
     539             : 
     540             : /// EmitValue - Emit delta value.
     541             : ///
     542       38953 : void DIEDelta::EmitValue(const AsmPrinter *AP, dwarf::Form Form) const {
     543       38953 :   AP->EmitLabelDifference(LabelHi, LabelLo, SizeOf(AP, Form));
     544       38953 : }
     545             : 
     546             : /// SizeOf - Determine size of delta value in bytes.
     547             : ///
     548       77906 : unsigned DIEDelta::SizeOf(const AsmPrinter *AP, dwarf::Form Form) const {
     549       77906 :   if (Form == dwarf::DW_FORM_data4) return 4;
     550         300 :   if (Form == dwarf::DW_FORM_sec_offset) return 4;
     551           0 :   if (Form == dwarf::DW_FORM_strp) return 4;
     552           0 :   return AP->MAI->getCodePointerSize();
     553             : }
     554             : 
     555             : LLVM_DUMP_METHOD
     556           0 : void DIEDelta::print(raw_ostream &O) const {
     557           0 :   O << "Del: " << LabelHi->getName() << "-" << LabelLo->getName();
     558           0 : }
     559             : 
     560             : //===----------------------------------------------------------------------===//
     561             : // DIEString Implementation
     562             : //===----------------------------------------------------------------------===//
     563             : 
     564             : /// EmitValue - Emit string value.
     565             : ///
     566       68614 : void DIEString::EmitValue(const AsmPrinter *AP, dwarf::Form Form) const {
     567             :   assert(
     568             :       (Form == dwarf::DW_FORM_strp || Form == dwarf::DW_FORM_GNU_str_index) &&
     569             :       "Expected valid string form");
     570             : 
     571             :   // Index of string in symbol table.
     572       68614 :   if (Form == dwarf::DW_FORM_GNU_str_index) {
     573         849 :     DIEInteger(S.getIndex()).EmitValue(AP, Form);
     574         283 :     return;
     575             :   }
     576             : 
     577             :   // Relocatable symbol.
     578             :   assert(Form == dwarf::DW_FORM_strp);
     579       68331 :   if (AP->MAI->doesDwarfUseRelocationsAcrossSections()) {
     580      198390 :     DIELabel(S.getSymbol()).EmitValue(AP, Form);
     581       66130 :     return;
     582             :   }
     583             : 
     584             :   // Offset into symbol table.
     585        6603 :   DIEInteger(S.getOffset()).EmitValue(AP, Form);
     586             : }
     587             : 
     588             : /// SizeOf - Determine size of delta value in bytes.
     589             : ///
     590       68614 : unsigned DIEString::SizeOf(const AsmPrinter *AP, dwarf::Form Form) const {
     591             :   assert(
     592             :       (Form == dwarf::DW_FORM_strp || Form == dwarf::DW_FORM_GNU_str_index) &&
     593             :       "Expected valid string form");
     594             : 
     595             :   // Index of string in symbol table.
     596       68614 :   if (Form == dwarf::DW_FORM_GNU_str_index)
     597         849 :     return DIEInteger(S.getIndex()).SizeOf(AP, Form);
     598             : 
     599             :   // Relocatable symbol.
     600       68331 :   if (AP->MAI->doesDwarfUseRelocationsAcrossSections())
     601      198390 :     return DIELabel(S.getSymbol()).SizeOf(AP, Form);
     602             : 
     603             :   // Offset into symbol table.
     604        6603 :   return DIEInteger(S.getOffset()).SizeOf(AP, Form);
     605             : }
     606             : 
     607             : LLVM_DUMP_METHOD
     608           0 : void DIEString::print(raw_ostream &O) const {
     609           0 :   O << "String: " << S.getString();
     610           0 : }
     611             : 
     612             : //===----------------------------------------------------------------------===//
     613             : // DIEInlineString Implementation
     614             : //===----------------------------------------------------------------------===//
     615           8 : void DIEInlineString::EmitValue(const AsmPrinter *AP, dwarf::Form Form) const {
     616           8 :   if (Form == dwarf::DW_FORM_string) {
     617          56 :     for (char ch : S)
     618          40 :       AP->EmitInt8(ch);
     619           8 :     AP->EmitInt8(0);
     620           8 :     return;
     621             :   }
     622           0 :   llvm_unreachable("Expected valid string form");
     623             : }
     624             : 
     625           8 : unsigned DIEInlineString::SizeOf(const AsmPrinter *AP, dwarf::Form Form) const {
     626             :   // Emit string bytes + NULL byte.
     627          16 :   return S.size() + 1;
     628             : }
     629             : 
     630             : LLVM_DUMP_METHOD
     631           0 : void DIEInlineString::print(raw_ostream &O) const {
     632           0 :   O << "InlineString: " << S;
     633           0 : }
     634             : 
     635             : //===----------------------------------------------------------------------===//
     636             : // DIEEntry Implementation
     637             : //===----------------------------------------------------------------------===//
     638             : 
     639             : /// EmitValue - Emit debug information entry offset.
     640             : ///
     641      176576 : void DIEEntry::EmitValue(const AsmPrinter *AP, dwarf::Form Form) const {
     642             : 
     643      176576 :   switch (Form) {
     644      176492 :   case dwarf::DW_FORM_ref1:
     645             :   case dwarf::DW_FORM_ref2:
     646             :   case dwarf::DW_FORM_ref4:
     647             :   case dwarf::DW_FORM_ref8:
     648      352984 :     AP->OutStreamer->EmitIntValue(Entry->getOffset(), SizeOf(AP, Form));
     649      176492 :     return;
     650             : 
     651           0 :   case dwarf::DW_FORM_ref_udata:
     652           0 :     AP->EmitULEB128(Entry->getOffset());
     653           0 :     return;
     654             : 
     655          84 :   case dwarf::DW_FORM_ref_addr: {
     656             :     // Get the absolute offset for this DIE within the debug info/types section.
     657          84 :     unsigned Addr = Entry->getDebugSectionOffset();
     658          84 :     if (const MCSymbol *SectionSym =
     659          84 :             Entry->getUnit()->getCrossSectionRelativeBaseAddress()) {
     660          41 :       AP->EmitLabelPlusOffset(SectionSym, Addr, SizeOf(AP, Form), true);
     661          41 :       return;
     662             :     }
     663             : 
     664          86 :     AP->OutStreamer->EmitIntValue(Addr, SizeOf(AP, Form));
     665          43 :     return;
     666             :   }
     667           0 :   default:
     668           0 :     llvm_unreachable("Improper form for DIE reference");
     669             :   }
     670             : }
     671             : 
     672      352750 : unsigned DIEEntry::SizeOf(const AsmPrinter *AP, dwarf::Form Form) const {
     673      352750 :   switch (Form) {
     674             :   case dwarf::DW_FORM_ref1:
     675             :     return 1;
     676          24 :   case dwarf::DW_FORM_ref2:
     677          24 :     return 2;
     678      352510 :   case dwarf::DW_FORM_ref4:
     679      352510 :     return 4;
     680          24 :   case dwarf::DW_FORM_ref8:
     681          24 :     return 8;
     682           0 :   case dwarf::DW_FORM_ref_udata:
     683           0 :     return getULEB128Size(Entry->getOffset());
     684         168 :   case dwarf::DW_FORM_ref_addr:
     685         168 :     if (AP->getDwarfVersion() == 2)
     686          62 :       return AP->MAI->getCodePointerSize();
     687             :     switch (AP->OutStreamer->getContext().getDwarfFormat()) {
     688             :     case dwarf::DWARF32:
     689             :       return 4;
     690             :     case dwarf::DWARF64:
     691             :       return 8;
     692             :     }
     693             :     llvm_unreachable("Invalid DWARF format");
     694             : 
     695           0 :   default:
     696           0 :     llvm_unreachable("Improper form for DIE reference");
     697             :   }
     698             : }
     699             : 
     700             : LLVM_DUMP_METHOD
     701           0 : void DIEEntry::print(raw_ostream &O) const {
     702           0 :   O << format("Die: 0x%lx", (long)(intptr_t)&Entry);
     703           0 : }
     704             : 
     705             : //===----------------------------------------------------------------------===//
     706             : // DIELoc Implementation
     707             : //===----------------------------------------------------------------------===//
     708             : 
     709             : /// ComputeSize - calculate the size of the location expression.
     710             : ///
     711        2206 : unsigned DIELoc::ComputeSize(const AsmPrinter *AP) const {
     712        2206 :   if (!Size) {
     713       11198 :     for (const auto &V : values())
     714        3427 :       Size += V.SizeOf(AP);
     715             :   }
     716             : 
     717        2206 :   return Size;
     718             : }
     719             : 
     720             : /// EmitValue - Emit location data.
     721             : ///
     722        2165 : void DIELoc::EmitValue(const AsmPrinter *Asm, dwarf::Form Form) const {
     723        2165 :   switch (Form) {
     724           0 :   default: llvm_unreachable("Improper form for block");
     725         350 :   case dwarf::DW_FORM_block1: Asm->EmitInt8(Size);    break;
     726           0 :   case dwarf::DW_FORM_block2: Asm->EmitInt16(Size);   break;
     727           0 :   case dwarf::DW_FORM_block4: Asm->EmitInt32(Size);   break;
     728        1815 :   case dwarf::DW_FORM_block:
     729             :   case dwarf::DW_FORM_exprloc:
     730        1815 :     Asm->EmitULEB128(Size); break;
     731             :   }
     732             : 
     733       11142 :   for (const auto &V : values())
     734        3406 :     V.EmitValue(Asm);
     735        2165 : }
     736             : 
     737             : /// SizeOf - Determine size of location data in bytes.
     738             : ///
     739        2104 : unsigned DIELoc::SizeOf(const AsmPrinter *AP, dwarf::Form Form) const {
     740        2104 :   switch (Form) {
     741         350 :   case dwarf::DW_FORM_block1: return Size + sizeof(int8_t);
     742           0 :   case dwarf::DW_FORM_block2: return Size + sizeof(int16_t);
     743           0 :   case dwarf::DW_FORM_block4: return Size + sizeof(int32_t);
     744        1754 :   case dwarf::DW_FORM_block:
     745             :   case dwarf::DW_FORM_exprloc:
     746        1754 :     return Size + getULEB128Size(Size);
     747           0 :   default: llvm_unreachable("Improper form for block");
     748             :   }
     749             : }
     750             : 
     751             : LLVM_DUMP_METHOD
     752           0 : void DIELoc::print(raw_ostream &O) const {
     753           0 :   printValues(O, *this, "ExprLoc", Size, 5);
     754           0 : }
     755             : 
     756             : //===----------------------------------------------------------------------===//
     757             : // DIEBlock Implementation
     758             : //===----------------------------------------------------------------------===//
     759             : 
     760             : /// ComputeSize - calculate the size of the block.
     761             : ///
     762         324 : unsigned DIEBlock::ComputeSize(const AsmPrinter *AP) const {
     763         324 :   if (!Size) {
     764        3138 :     for (const auto &V : values())
     765        1245 :       Size += V.SizeOf(AP);
     766             :   }
     767             : 
     768         324 :   return Size;
     769             : }
     770             : 
     771             : /// EmitValue - Emit block data.
     772             : ///
     773         323 : void DIEBlock::EmitValue(const AsmPrinter *Asm, dwarf::Form Form) const {
     774         323 :   switch (Form) {
     775           0 :   default: llvm_unreachable("Improper form for block");
     776         299 :   case dwarf::DW_FORM_block1: Asm->EmitInt8(Size);    break;
     777           8 :   case dwarf::DW_FORM_block2: Asm->EmitInt16(Size);   break;
     778           8 :   case dwarf::DW_FORM_block4: Asm->EmitInt32(Size);   break;
     779           8 :   case dwarf::DW_FORM_block:  Asm->EmitULEB128(Size); break;
     780             :   }
     781             : 
     782        3128 :   for (const auto &V : values())
     783        1241 :     V.EmitValue(Asm);
     784         323 : }
     785             : 
     786             : /// SizeOf - Determine size of block data in bytes.
     787             : ///
     788          35 : unsigned DIEBlock::SizeOf(const AsmPrinter *AP, dwarf::Form Form) const {
     789          35 :   switch (Form) {
     790          11 :   case dwarf::DW_FORM_block1: return Size + sizeof(int8_t);
     791           8 :   case dwarf::DW_FORM_block2: return Size + sizeof(int16_t);
     792           8 :   case dwarf::DW_FORM_block4: return Size + sizeof(int32_t);
     793           8 :   case dwarf::DW_FORM_block:  return Size + getULEB128Size(Size);
     794           0 :   default: llvm_unreachable("Improper form for block");
     795             :   }
     796             : }
     797             : 
     798             : LLVM_DUMP_METHOD
     799           0 : void DIEBlock::print(raw_ostream &O) const {
     800           0 :   printValues(O, *this, "Blk", Size, 5);
     801           0 : }
     802             : 
     803             : //===----------------------------------------------------------------------===//
     804             : // DIELocList Implementation
     805             : //===----------------------------------------------------------------------===//
     806             : 
     807        8760 : unsigned DIELocList::SizeOf(const AsmPrinter *AP, dwarf::Form Form) const {
     808        8760 :   if (Form == dwarf::DW_FORM_data4)
     809             :     return 4;
     810        8714 :   if (Form == dwarf::DW_FORM_sec_offset)
     811             :     return 4;
     812           0 :   return AP->MAI->getCodePointerSize();
     813             : }
     814             : 
     815             : /// EmitValue - Emit label value.
     816             : ///
     817        8760 : void DIELocList::EmitValue(const AsmPrinter *AP, dwarf::Form Form) const {
     818        8760 :   DwarfDebug *DD = AP->getDwarfDebug();
     819       17520 :   MCSymbol *Label = DD->getDebugLocs().getList(Index).Label;
     820        8760 :   AP->emitDwarfSymbolReference(Label, /*ForceOffset*/ DD->useSplitDwarf());
     821        8760 : }
     822             : 
     823             : LLVM_DUMP_METHOD
     824           0 : void DIELocList::print(raw_ostream &O) const { O << "LocList: " << Index; }

Generated by: LCOV version 1.13