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

Generated by: LCOV version 1.13