LCOV - code coverage report
Current view: top level - lib/CodeGen/AsmPrinter - DIE.cpp (source / functions) Hit Total Coverage
Test: llvm-toolchain.info Lines: 238 341 69.8 %
Date: 2018-02-17 17:14:17 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    13242072 : 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    13242072 :   ID.AddInteger(unsigned(Attribute));
      46    13242072 :   ID.AddInteger(unsigned(Form));
      47    13242072 :   if (Form == dwarf::DW_FORM_implicit_const)
      48           6 :     ID.AddInteger(Value);
      49    13242072 : }
      50             : 
      51             : //===----------------------------------------------------------------------===//
      52             : // DIEAbbrev Implementation
      53             : //===----------------------------------------------------------------------===//
      54             : 
      55             : /// Profile - Used to gather unique data for the abbreviation folding set.
      56             : ///
      57     3886706 : void DIEAbbrev::Profile(FoldingSetNodeID &ID) const {
      58     3886706 :   ID.AddInteger(unsigned(Tag));
      59     3886706 :   ID.AddInteger(unsigned(Children));
      60             : 
      61             :   // For each attribute description.
      62    17128778 :   for (unsigned i = 0, N = Data.size(); i < N; ++i)
      63    26484144 :     Data[i].Profile(ID);
      64     3886706 : }
      65             : 
      66             : /// Emit - Print the abbreviation using the specified asm printer.
      67             : ///
      68       71366 : void DIEAbbrev::Emit(const AsmPrinter *AP) const {
      69             :   // Emit its Dwarf tag type.
      70      142732 :   AP->EmitULEB128(Tag, dwarf::TagString(Tag).data());
      71             : 
      72             :   // Emit whether it has children DIEs.
      73      142732 :   AP->EmitULEB128((unsigned)Children, dwarf::ChildrenString(Children).data());
      74             : 
      75             :   // For each attribute description.
      76      388204 :   for (unsigned i = 0, N = Data.size(); i < N; ++i) {
      77      316838 :     const DIEAbbrevData &AttrData = Data[i];
      78             : 
      79             :     // Emit attribute type.
      80      316838 :     AP->EmitULEB128(AttrData.getAttribute(),
      81      633676 :                     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      316838 :     AP->EmitULEB128(AttrData.getForm(),
      95      633676 :                     dwarf::FormEncodingString(AttrData.getForm()).data());
      96             : 
      97             :     // Emit value for DW_FORM_implicit_const.
      98      316838 :     if (AttrData.getForm() == dwarf::DW_FORM_implicit_const)
      99           4 :       AP->EmitSLEB128(AttrData.getValue());
     100             :   }
     101             : 
     102             :   // Mark end of abbreviation.
     103       71366 :   AP->EmitULEB128(0, "EOM(1)");
     104       71366 :   AP->EmitULEB128(0, "EOM(2)");
     105       71366 : }
     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             :     << '\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             :     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       80862 : DIEAbbrevSet::~DIEAbbrevSet() {
     141      111081 :   for (DIEAbbrev *Abbrev : Abbreviations)
     142             :     Abbrev->~DIEAbbrev();
     143       40431 : }
     144             : 
     145     1590839 : DIEAbbrev &DIEAbbrevSet::uniqueAbbreviation(DIE &Die) {
     146             : 
     147             :   FoldingSetNodeID ID;
     148     1590839 :   DIEAbbrev Abbrev = Die.generateAbbrev();
     149     1590839 :   Abbrev.Profile(ID);
     150             : 
     151             :   void *InsertPos;
     152     1590839 :   if (DIEAbbrev *Existing =
     153             :           AbbreviationsSet.FindNodeOrInsertPos(ID, InsertPos)) {
     154             :     Die.setAbbrevNumber(Existing->getNumber());
     155     1520189 :     return *Existing;
     156             :   }
     157             : 
     158             :   // Move the abbreviation to the heap and assign a number.
     159      141300 :   DIEAbbrev *New = new (Alloc) DIEAbbrev(std::move(Abbrev));
     160       70650 :   Abbreviations.push_back(New);
     161      141300 :   New->setNumber(Abbreviations.size());
     162             :   Die.setAbbrevNumber(Abbreviations.size());
     163             : 
     164             :   // Store it for lookup.
     165       70650 :   AbbreviationsSet.InsertNode(New, InsertPos);
     166       70650 :   return *New;
     167             : }
     168             : 
     169        3389 : void DIEAbbrevSet::Emit(const AsmPrinter *AP, MCSection *Section) const {
     170        3389 :   if (!Abbreviations.empty()) {
     171             :     // Start the debug abbrev section.
     172        3352 :     AP->OutStreamer->SwitchSection(Section);
     173        3352 :     AP->emitDwarfAbbrevs(Abbreviations);
     174             :   }
     175        3389 : }
     176             : 
     177             : //===----------------------------------------------------------------------===//
     178             : // DIE Implementation
     179             : //===----------------------------------------------------------------------===//
     180             : 
     181     5783794 : DIE *DIE::getParent() const {
     182     5783794 :   return Owner.dyn_cast<DIE*>();
     183             : }
     184             : 
     185     1592236 : DIEAbbrev DIE::generateAbbrev() const {
     186     1592236 :   DIEAbbrev Abbrev(Tag, hasChildren());
     187     6776456 :   for (const DIEValue &V : values())
     188     5184220 :     if (V.getForm() == dwarf::DW_FORM_implicit_const)
     189           5 :       Abbrev.AddImplicitConstAttribute(V.getAttribute(),
     190             :                                        V.getDIEInteger().getValue());
     191             :     else
     192             :       Abbrev.AddAttribute(V.getAttribute(), V.getForm());
     193     1592236 :   return Abbrev;
     194             : }
     195             : 
     196        1095 : unsigned DIE::getDebugSectionOffset() const {
     197        1095 :   const DIEUnit *Unit = getUnit();
     198             :   assert(Unit && "DIE must be owned by a DIEUnit to get its absolute offset");
     199        1095 :   return Unit->getDebugSectionOffset() + getOffset();
     200             : }
     201             : 
     202     3108445 : const DIE *DIE::getUnitDie() const {
     203             :   const DIE *p = this;
     204    14575665 :   while (p) {
     205     8634632 :     if (p->getTag() == dwarf::DW_TAG_compile_unit ||
     206             :         p->getTag() == dwarf::DW_TAG_type_unit)
     207             :       return p;
     208     5733610 :     p = p->getParent();
     209             :   }
     210             :   return nullptr;
     211             : }
     212             : 
     213     3031693 : const DIEUnit *DIE::getUnit() const {
     214     3031693 :   const DIE *UnitDie = getUnitDie();
     215     3031693 :   if (UnitDie)
     216             :     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         521 :   for (const auto &V : values())
     224         449 :     if (V.getAttribute() == Attribute)
     225             :       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             :   unsigned I = 0;
     235           0 :   const std::string Indent(IndentCount, ' ');
     236           0 :   for (const auto &V : Values.values()) {
     237             :     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             :   IndentCount += 2;
     255           0 :   for (const auto &V : values()) {
     256             :     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             :   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     1590839 : 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     1590839 :   const DIEAbbrev &Abbrev = AbbrevSet.uniqueAbbreviation(*this);
     282             : 
     283             :   // Set compile/type unit relative offset of this DIE.
     284             :   setOffset(CUOffset);
     285             : 
     286             :   // Add the byte size of the abbreviation code.
     287     1590839 :   CUOffset += getULEB128Size(getAbbrevNumber());
     288             : 
     289             :   // Add the byte size of all the DIE attribute values.
     290     6768370 :   for (const auto &V : values())
     291     5177531 :     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     2006874 :     for (auto &Child : children())
     299     1587391 :       CUOffset = Child.computeOffsetsAndAbbrevs(AP, AbbrevSet, CUOffset);
     300             : 
     301             :     // Each child chain is terminated with a zero byte, adjust the offset.
     302      419483 :     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     1590839 :   setSize(CUOffset - getOffset());
     309     1590839 :   return CUOffset;
     310             : }
     311             : 
     312             : //===----------------------------------------------------------------------===//
     313             : // DIEUnit Implementation
     314             : //===----------------------------------------------------------------------===//
     315        3628 : DIEUnit::DIEUnit(uint16_t V, uint8_t A, dwarf::Tag UnitTag)
     316             :     : Die(UnitTag), Section(nullptr), Offset(0), Length(0), Version(V),
     317        7256 :       AddrSize(A)
     318             : {
     319             :   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        3628 : }
     324             : 
     325     5362818 : void DIEValue::EmitValue(const AsmPrinter *AP) const {
     326     5362818 :   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     5362818 : }
     336             : 
     337     5356154 : unsigned DIEValue::SizeOf(const AsmPrinter *AP) const {
     338     5356154 :   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     2932789 : void DIEInteger::EmitValue(const AsmPrinter *Asm, dwarf::Form Form) const {
     375     2932789 :   switch (Form) {
     376      812926 :   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      812926 :     Asm->OutStreamer->AddBlankLine();
     381      812926 :     return;
     382     1867039 :   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_strx3:
     392             :   case dwarf::DW_FORM_strp:
     393             :   case dwarf::DW_FORM_ref4:
     394             :   case dwarf::DW_FORM_data4:
     395             :   case dwarf::DW_FORM_ref_sup4:
     396             :   case dwarf::DW_FORM_strx4:
     397             :   case dwarf::DW_FORM_addrx4:
     398             :   case dwarf::DW_FORM_ref8:
     399             :   case dwarf::DW_FORM_ref_sig8:
     400             :   case dwarf::DW_FORM_data8:
     401             :   case dwarf::DW_FORM_ref_sup8:
     402             :   case dwarf::DW_FORM_GNU_ref_alt:
     403             :   case dwarf::DW_FORM_GNU_strp_alt:
     404             :   case dwarf::DW_FORM_line_strp:
     405             :   case dwarf::DW_FORM_sec_offset:
     406             :   case dwarf::DW_FORM_strp_sup:
     407             :   case dwarf::DW_FORM_addr:
     408             :   case dwarf::DW_FORM_ref_addr:
     409     1867039 :     Asm->OutStreamer->EmitIntValue(Integer, SizeOf(Asm, Form));
     410     1867039 :     return;
     411      178161 :   case dwarf::DW_FORM_GNU_str_index:
     412             :   case dwarf::DW_FORM_GNU_addr_index:
     413             :   case dwarf::DW_FORM_ref_udata:
     414             :   case dwarf::DW_FORM_strx:
     415             :   case dwarf::DW_FORM_udata:
     416      178161 :     Asm->EmitULEB128(Integer);
     417      178161 :     return;
     418       74663 :   case dwarf::DW_FORM_sdata:
     419       74663 :     Asm->EmitSLEB128(Integer);
     420       74663 :     return;
     421           0 :   default: llvm_unreachable("DIE Value form not supported yet");
     422             :   }
     423             : }
     424             : 
     425             : /// SizeOf - Determine size of integer value in bytes.
     426             : ///
     427     4794495 : unsigned DIEInteger::SizeOf(const AsmPrinter *AP, dwarf::Form Form) const {
     428     4794495 :   switch (Form) {
     429             :   case dwarf::DW_FORM_implicit_const:
     430             :   case dwarf::DW_FORM_flag_present:
     431             :     return 0;
     432     3098007 :   case dwarf::DW_FORM_flag:
     433             :   case dwarf::DW_FORM_ref1:
     434             :   case dwarf::DW_FORM_data1:
     435             :   case dwarf::DW_FORM_strx1:
     436             :   case dwarf::DW_FORM_addrx1:
     437     3098007 :     return sizeof(int8_t);
     438      618700 :   case dwarf::DW_FORM_ref2:
     439             :   case dwarf::DW_FORM_data2:
     440             :   case dwarf::DW_FORM_strx2:
     441             :   case dwarf::DW_FORM_addrx2:
     442      618700 :     return sizeof(int16_t);
     443           0 :   case dwarf::DW_FORM_strx3:
     444           0 :     return 3;
     445         582 :   case dwarf::DW_FORM_ref4:
     446             :   case dwarf::DW_FORM_data4:
     447             :   case dwarf::DW_FORM_ref_sup4:
     448             :   case dwarf::DW_FORM_strx4:
     449             :   case dwarf::DW_FORM_addrx4:
     450         582 :     return sizeof(int32_t);
     451        2684 :   case dwarf::DW_FORM_ref8:
     452             :   case dwarf::DW_FORM_ref_sig8:
     453             :   case dwarf::DW_FORM_data8:
     454             :   case dwarf::DW_FORM_ref_sup8:
     455        2684 :     return sizeof(int64_t);
     456         196 :   case dwarf::DW_FORM_ref_addr:
     457         196 :     if (AP->getDwarfVersion() == 2)
     458         120 :       return AP->getPointerSize();
     459             :     LLVM_FALLTHROUGH;
     460             :   case dwarf::DW_FORM_strp:
     461             :   case dwarf::DW_FORM_GNU_ref_alt:
     462             :   case dwarf::DW_FORM_GNU_strp_alt:
     463             :   case dwarf::DW_FORM_line_strp:
     464             :   case dwarf::DW_FORM_sec_offset:
     465             :   case dwarf::DW_FORM_strp_sup:
     466             :     switch (AP->OutStreamer->getContext().getDwarfFormat()) {
     467             :     case dwarf::DWARF32:
     468        6395 :       return 4;
     469             :     case dwarf::DWARF64:
     470             :       return 8;
     471             :     }
     472             :     llvm_unreachable("Invalid DWARF format");
     473      178168 :   case dwarf::DW_FORM_GNU_str_index:
     474             :   case dwarf::DW_FORM_GNU_addr_index:
     475             :   case dwarf::DW_FORM_ref_udata:
     476             :   case dwarf::DW_FORM_strx:
     477             :   case dwarf::DW_FORM_udata:
     478      178168 :     return getULEB128Size(Integer);
     479       74663 :   case dwarf::DW_FORM_sdata:
     480       74663 :     return getSLEB128Size(Integer);
     481        2313 :   case dwarf::DW_FORM_addr:
     482        2313 :     return AP->getPointerSize();
     483           0 :   default: llvm_unreachable("DIE Value form not supported yet");
     484             :   }
     485             : }
     486             : 
     487             : LLVM_DUMP_METHOD
     488           0 : void DIEInteger::print(raw_ostream &O) const {
     489           0 :   O << "Int: " << (int64_t)Integer << "  0x";
     490           0 :   O.write_hex(Integer);
     491           0 : }
     492             : 
     493             : //===----------------------------------------------------------------------===//
     494             : // DIEExpr Implementation
     495             : //===----------------------------------------------------------------------===//
     496             : 
     497             : /// EmitValue - Emit expression value.
     498             : ///
     499          28 : void DIEExpr::EmitValue(const AsmPrinter *AP, dwarf::Form Form) const {
     500          28 :   AP->EmitDebugThreadLocal(Expr, SizeOf(AP, Form));
     501          28 : }
     502             : 
     503             : /// SizeOf - Determine size of expression value in bytes.
     504             : ///
     505          56 : unsigned DIEExpr::SizeOf(const AsmPrinter *AP, dwarf::Form Form) const {
     506          56 :   if (Form == dwarf::DW_FORM_data4) return 4;
     507          56 :   if (Form == dwarf::DW_FORM_sec_offset) return 4;
     508          56 :   if (Form == dwarf::DW_FORM_strp) return 4;
     509          56 :   return AP->getPointerSize();
     510             : }
     511             : 
     512             : LLVM_DUMP_METHOD
     513           0 : void DIEExpr::print(raw_ostream &O) const { O << "Expr: " << *Expr; }
     514             : 
     515             : //===----------------------------------------------------------------------===//
     516             : // DIELabel Implementation
     517             : //===----------------------------------------------------------------------===//
     518             : 
     519             : /// EmitValue - Emit label value.
     520             : ///
     521      819516 : void DIELabel::EmitValue(const AsmPrinter *AP, dwarf::Form Form) const {
     522      819516 :   AP->EmitLabelReference(Label, SizeOf(AP, Form),
     523     1639032 :                          Form == dwarf::DW_FORM_strp ||
     524      819516 :                              Form == dwarf::DW_FORM_sec_offset ||
     525      894702 :                              Form == dwarf::DW_FORM_ref_addr ||
     526       75186 :                              Form == dwarf::DW_FORM_data4);
     527      819516 : }
     528             : 
     529             : /// SizeOf - Determine size of label value in bytes.
     530             : ///
     531     1639032 : unsigned DIELabel::SizeOf(const AsmPrinter *AP, dwarf::Form Form) const {
     532     1639032 :   if (Form == dwarf::DW_FORM_data4) return 4;
     533     1638870 :   if (Form == dwarf::DW_FORM_sec_offset) return 4;
     534     1515966 :   if (Form == dwarf::DW_FORM_strp) return 4;
     535      150210 :   return AP->MAI->getCodePointerSize();
     536             : }
     537             : 
     538             : LLVM_DUMP_METHOD
     539           0 : void DIELabel::print(raw_ostream &O) const { O << "Lbl: " << Label->getName(); }
     540             : 
     541             : //===----------------------------------------------------------------------===//
     542             : // DIEDelta Implementation
     543             : //===----------------------------------------------------------------------===//
     544             : 
     545             : /// EmitValue - Emit delta value.
     546             : ///
     547       80483 : void DIEDelta::EmitValue(const AsmPrinter *AP, dwarf::Form Form) const {
     548       80483 :   AP->EmitLabelDifference(LabelHi, LabelLo, SizeOf(AP, Form));
     549       80483 : }
     550             : 
     551             : /// SizeOf - Determine size of delta value in bytes.
     552             : ///
     553      160966 : unsigned DIEDelta::SizeOf(const AsmPrinter *AP, dwarf::Form Form) const {
     554      160966 :   if (Form == dwarf::DW_FORM_data4) return 4;
     555         582 :   if (Form == dwarf::DW_FORM_sec_offset) return 4;
     556           0 :   if (Form == dwarf::DW_FORM_strp) return 4;
     557           0 :   return AP->MAI->getCodePointerSize();
     558             : }
     559             : 
     560             : LLVM_DUMP_METHOD
     561           0 : void DIEDelta::print(raw_ostream &O) const {
     562           0 :   O << "Del: " << LabelHi->getName() << "-" << LabelLo->getName();
     563           0 : }
     564             : 
     565             : //===----------------------------------------------------------------------===//
     566             : // DIEString Implementation
     567             : //===----------------------------------------------------------------------===//
     568             : 
     569             : /// EmitValue - Emit string value.
     570             : ///
     571      825746 : void DIEString::EmitValue(const AsmPrinter *AP, dwarf::Form Form) const {
     572             :   // Index of string in symbol table.
     573      825746 :   switch (Form) {
     574      140516 :   case dwarf::DW_FORM_GNU_str_index:
     575             :   case dwarf::DW_FORM_strx:
     576             :   case dwarf::DW_FORM_strx1:
     577             :   case dwarf::DW_FORM_strx2:
     578             :   case dwarf::DW_FORM_strx3:
     579             :   case dwarf::DW_FORM_strx4:
     580      281032 :     DIEInteger(S.getIndex()).EmitValue(AP, Form);
     581      140516 :     return;
     582      685230 :   case dwarf::DW_FORM_strp:
     583      685230 :     if (AP->MAI->doesDwarfUseRelocationsAcrossSections())
     584      682878 :       DIELabel(S.getSymbol()).EmitValue(AP, Form);
     585             :     else
     586        4704 :       DIEInteger(S.getOffset()).EmitValue(AP, Form);
     587             :     return;
     588           0 :   default:
     589           0 :     llvm_unreachable("Expected valid string form");
     590             :   }
     591             : }
     592             : 
     593             : /// SizeOf - Determine size of delta value in bytes.
     594             : ///
     595      825746 : unsigned DIEString::SizeOf(const AsmPrinter *AP, dwarf::Form Form) const {
     596             :   // Index of string in symbol table.
     597      825746 :   switch (Form) {
     598      140516 :   case dwarf::DW_FORM_GNU_str_index:
     599             :   case dwarf::DW_FORM_strx:
     600             :   case dwarf::DW_FORM_strx1:
     601             :   case dwarf::DW_FORM_strx2:
     602             :   case dwarf::DW_FORM_strx3:
     603             :   case dwarf::DW_FORM_strx4:
     604      281032 :     return DIEInteger(S.getIndex()).SizeOf(AP, Form);
     605      685230 :   case dwarf::DW_FORM_strp:
     606      685230 :     if (AP->MAI->doesDwarfUseRelocationsAcrossSections())
     607      682878 :       return DIELabel(S.getSymbol()).SizeOf(AP, Form);
     608        4704 :     return DIEInteger(S.getOffset()).SizeOf(AP, Form);
     609           0 :   default:
     610           0 :     llvm_unreachable("Expected valid string form");
     611             :   }
     612             : }
     613             : 
     614             : LLVM_DUMP_METHOD
     615           0 : void DIEString::print(raw_ostream &O) const {
     616           0 :   O << "String: " << S.getString();
     617           0 : }
     618             : 
     619             : //===----------------------------------------------------------------------===//
     620             : // DIEInlineString Implementation
     621             : //===----------------------------------------------------------------------===//
     622           8 : void DIEInlineString::EmitValue(const AsmPrinter *AP, dwarf::Form Form) const {
     623           8 :   if (Form == dwarf::DW_FORM_string) {
     624          88 :     for (char ch : S)
     625          40 :       AP->EmitInt8(ch);
     626           8 :     AP->EmitInt8(0);
     627           8 :     return;
     628             :   }
     629           0 :   llvm_unreachable("Expected valid string form");
     630             : }
     631             : 
     632           8 : unsigned DIEInlineString::SizeOf(const AsmPrinter *AP, dwarf::Form Form) const {
     633             :   // Emit string bytes + NULL byte.
     634           8 :   return S.size() + 1;
     635             : }
     636             : 
     637             : LLVM_DUMP_METHOD
     638           0 : void DIEInlineString::print(raw_ostream &O) const {
     639           0 :   O << "InlineString: " << S;
     640           0 : }
     641             : 
     642             : //===----------------------------------------------------------------------===//
     643             : // DIEEntry Implementation
     644             : //===----------------------------------------------------------------------===//
     645             : 
     646             : /// EmitValue - Emit debug information entry offset.
     647             : ///
     648     1412348 : void DIEEntry::EmitValue(const AsmPrinter *AP, dwarf::Form Form) const {
     649             : 
     650     1412348 :   switch (Form) {
     651     1412261 :   case dwarf::DW_FORM_ref1:
     652             :   case dwarf::DW_FORM_ref2:
     653             :   case dwarf::DW_FORM_ref4:
     654             :   case dwarf::DW_FORM_ref8:
     655     1412261 :     AP->OutStreamer->EmitIntValue(Entry->getOffset(), SizeOf(AP, Form));
     656     1412261 :     return;
     657             : 
     658           0 :   case dwarf::DW_FORM_ref_udata:
     659           0 :     AP->EmitULEB128(Entry->getOffset());
     660           0 :     return;
     661             : 
     662          87 :   case dwarf::DW_FORM_ref_addr: {
     663             :     // Get the absolute offset for this DIE within the debug info/types section.
     664          87 :     unsigned Addr = Entry->getDebugSectionOffset();
     665          87 :     if (const MCSymbol *SectionSym =
     666          87 :             Entry->getUnit()->getCrossSectionRelativeBaseAddress()) {
     667          44 :       AP->EmitLabelPlusOffset(SectionSym, Addr, SizeOf(AP, Form), true);
     668          44 :       return;
     669             :     }
     670             : 
     671          43 :     AP->OutStreamer->EmitIntValue(Addr, SizeOf(AP, Form));
     672          43 :     return;
     673             :   }
     674           0 :   default:
     675           0 :     llvm_unreachable("Improper form for DIE reference");
     676             :   }
     677             : }
     678             : 
     679     2823956 : unsigned DIEEntry::SizeOf(const AsmPrinter *AP, dwarf::Form Form) const {
     680     2823956 :   switch (Form) {
     681             :   case dwarf::DW_FORM_ref1:
     682             :     return 1;
     683          24 :   case dwarf::DW_FORM_ref2:
     684          24 :     return 2;
     685     2823710 :   case dwarf::DW_FORM_ref4:
     686     2823710 :     return 4;
     687          24 :   case dwarf::DW_FORM_ref8:
     688          24 :     return 8;
     689           0 :   case dwarf::DW_FORM_ref_udata:
     690           0 :     return getULEB128Size(Entry->getOffset());
     691         174 :   case dwarf::DW_FORM_ref_addr:
     692         174 :     if (AP->getDwarfVersion() == 2)
     693          62 :       return AP->MAI->getCodePointerSize();
     694             :     switch (AP->OutStreamer->getContext().getDwarfFormat()) {
     695             :     case dwarf::DWARF32:
     696             :       return 4;
     697             :     case dwarf::DWARF64:
     698             :       return 8;
     699             :     }
     700             :     llvm_unreachable("Invalid DWARF format");
     701             : 
     702           0 :   default:
     703           0 :     llvm_unreachable("Improper form for DIE reference");
     704             :   }
     705             : }
     706             : 
     707             : LLVM_DUMP_METHOD
     708           0 : void DIEEntry::print(raw_ostream &O) const {
     709           0 :   O << format("Die: 0x%lx", (long)(intptr_t)&Entry);
     710           0 : }
     711             : 
     712             : //===----------------------------------------------------------------------===//
     713             : // DIELoc Implementation
     714             : //===----------------------------------------------------------------------===//
     715             : 
     716             : /// ComputeSize - calculate the size of the location expression.
     717             : ///
     718      113495 : unsigned DIELoc::ComputeSize(const AsmPrinter *AP) const {
     719      113495 :   if (!Size) {
     720      282301 :     for (const auto &V : values())
     721      176623 :       Size += V.SizeOf(AP);
     722             :   }
     723             : 
     724      113495 :   return Size;
     725             : }
     726             : 
     727             : /// EmitValue - Emit location data.
     728             : ///
     729      105671 : void DIELoc::EmitValue(const AsmPrinter *Asm, dwarf::Form Form) const {
     730      105671 :   switch (Form) {
     731           0 :   default: llvm_unreachable("Improper form for block");
     732         384 :   case dwarf::DW_FORM_block1: Asm->EmitInt8(Size);    break;
     733           0 :   case dwarf::DW_FORM_block2: Asm->EmitInt16(Size);   break;
     734           0 :   case dwarf::DW_FORM_block4: Asm->EmitInt32(Size);   break;
     735      105287 :   case dwarf::DW_FORM_block:
     736             :   case dwarf::DW_FORM_exprloc:
     737      105287 :     Asm->EmitULEB128(Size); break;
     738             :   }
     739             : 
     740      282273 :   for (const auto &V : values())
     741      176602 :     V.EmitValue(Asm);
     742      105671 : }
     743             : 
     744             : /// SizeOf - Determine size of location data in bytes.
     745             : ///
     746      105606 : unsigned DIELoc::SizeOf(const AsmPrinter *AP, dwarf::Form Form) const {
     747      105606 :   switch (Form) {
     748         384 :   case dwarf::DW_FORM_block1: return Size + sizeof(int8_t);
     749           0 :   case dwarf::DW_FORM_block2: return Size + sizeof(int16_t);
     750           0 :   case dwarf::DW_FORM_block4: return Size + sizeof(int32_t);
     751      105222 :   case dwarf::DW_FORM_block:
     752             :   case dwarf::DW_FORM_exprloc:
     753      105222 :     return Size + getULEB128Size(Size);
     754           0 :   default: llvm_unreachable("Improper form for block");
     755             :   }
     756             : }
     757             : 
     758             : LLVM_DUMP_METHOD
     759           0 : void DIELoc::print(raw_ostream &O) const {
     760           0 :   printValues(O, *this, "ExprLoc", Size, 5);
     761           0 : }
     762             : 
     763             : //===----------------------------------------------------------------------===//
     764             : // DIEBlock Implementation
     765             : //===----------------------------------------------------------------------===//
     766             : 
     767             : /// ComputeSize - calculate the size of the block.
     768             : ///
     769         567 : unsigned DIEBlock::ComputeSize(const AsmPrinter *AP) const {
     770         567 :   if (!Size) {
     771        2567 :     for (const auto &V : values())
     772        2000 :       Size += V.SizeOf(AP);
     773             :   }
     774             : 
     775         567 :   return Size;
     776             : }
     777             : 
     778             : /// EmitValue - Emit block data.
     779             : ///
     780         566 : void DIEBlock::EmitValue(const AsmPrinter *Asm, dwarf::Form Form) const {
     781         566 :   switch (Form) {
     782           0 :   default: llvm_unreachable("Improper form for block");
     783         540 :   case dwarf::DW_FORM_block1: Asm->EmitInt8(Size);    break;
     784           8 :   case dwarf::DW_FORM_block2: Asm->EmitInt16(Size);   break;
     785           8 :   case dwarf::DW_FORM_block4: Asm->EmitInt32(Size);   break;
     786           8 :   case dwarf::DW_FORM_block:  Asm->EmitULEB128(Size); break;
     787             :   case dwarf::DW_FORM_data16: break;
     788             :   }
     789             : 
     790        2562 :   for (const auto &V : values())
     791        1996 :     V.EmitValue(Asm);
     792         566 : }
     793             : 
     794             : /// SizeOf - Determine size of block data in bytes.
     795             : ///
     796          40 : unsigned DIEBlock::SizeOf(const AsmPrinter *AP, dwarf::Form Form) const {
     797          40 :   switch (Form) {
     798          14 :   case dwarf::DW_FORM_block1: return Size + sizeof(int8_t);
     799           8 :   case dwarf::DW_FORM_block2: return Size + sizeof(int16_t);
     800           8 :   case dwarf::DW_FORM_block4: return Size + sizeof(int32_t);
     801           8 :   case dwarf::DW_FORM_block:  return Size + getULEB128Size(Size);
     802             :   case dwarf::DW_FORM_data16: return 16;
     803           0 :   default: llvm_unreachable("Improper form for block");
     804             :   }
     805             : }
     806             : 
     807             : LLVM_DUMP_METHOD
     808           0 : void DIEBlock::print(raw_ostream &O) const {
     809           0 :   printValues(O, *this, "Blk", Size, 5);
     810           0 : }
     811             : 
     812             : //===----------------------------------------------------------------------===//
     813             : // DIELocList Implementation
     814             : //===----------------------------------------------------------------------===//
     815             : 
     816       11409 : unsigned DIELocList::SizeOf(const AsmPrinter *AP, dwarf::Form Form) const {
     817       11409 :   if (Form == dwarf::DW_FORM_data4)
     818             :     return 4;
     819       11356 :   if (Form == dwarf::DW_FORM_sec_offset)
     820             :     return 4;
     821           0 :   return AP->MAI->getCodePointerSize();
     822             : }
     823             : 
     824             : /// EmitValue - Emit label value.
     825             : ///
     826       11409 : void DIELocList::EmitValue(const AsmPrinter *AP, dwarf::Form Form) const {
     827             :   DwarfDebug *DD = AP->getDwarfDebug();
     828       22818 :   MCSymbol *Label = DD->getDebugLocs().getList(Index).Label;
     829       11409 :   AP->emitDwarfSymbolReference(Label, /*ForceOffset*/ DD->useSplitDwarf());
     830       11409 : }
     831             : 
     832             : LLVM_DUMP_METHOD
     833           0 : void DIELocList::print(raw_ostream &O) const { O << "LocList: " << Index; }

Generated by: LCOV version 1.13