Bill Wendling | 47054f3 | 2009-05-15 00:11:17 +0000 | [diff] [blame] | 1 | //===--- lib/CodeGen/DIE.cpp - DWARF Info Entries -------------------------===// |
| 2 | // |
Chandler Carruth | 2946cd7 | 2019-01-19 08:50:56 +0000 | [diff] [blame] | 3 | // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. |
| 4 | // See https://llvm.org/LICENSE.txt for license information. |
| 5 | // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception |
Bill Wendling | 47054f3 | 2009-05-15 00:11:17 +0000 | [diff] [blame] | 6 | // |
| 7 | //===----------------------------------------------------------------------===// |
| 8 | // |
| 9 | // Data structures for DWARF info entries. |
Eric Christopher | b800ff7 | 2013-01-07 22:40:45 +0000 | [diff] [blame] | 10 | // |
Bill Wendling | 47054f3 | 2009-05-15 00:11:17 +0000 | [diff] [blame] | 11 | //===----------------------------------------------------------------------===// |
| 12 | |
Frederic Riss | e541e0b | 2015-01-05 21:29:41 +0000 | [diff] [blame] | 13 | #include "llvm/CodeGen/DIE.h" |
David Blaikie | 37c5231 | 2014-10-04 15:49:50 +0000 | [diff] [blame] | 14 | #include "DwarfCompileUnit.h" |
Manman Ren | ac8062b | 2013-07-02 23:40:10 +0000 | [diff] [blame] | 15 | #include "DwarfDebug.h" |
David Blaikie | 47f615e | 2013-12-17 23:32:35 +0000 | [diff] [blame] | 16 | #include "DwarfUnit.h" |
Benjamin Kramer | 4d128a2 | 2010-01-17 07:46:39 +0000 | [diff] [blame] | 17 | #include "llvm/ADT/Twine.h" |
Bill Wendling | 47054f3 | 2009-05-15 00:11:17 +0000 | [diff] [blame] | 18 | #include "llvm/CodeGen/AsmPrinter.h" |
Nico Weber | 432a388 | 2018-04-30 14:59:11 +0000 | [diff] [blame] | 19 | #include "llvm/Config/llvm-config.h" |
Chandler Carruth | 9fb823b | 2013-01-02 11:36:10 +0000 | [diff] [blame] | 20 | #include "llvm/IR/DataLayout.h" |
Chris Lattner | 7b26fce | 2009-08-22 20:48:53 +0000 | [diff] [blame] | 21 | #include "llvm/MC/MCAsmInfo.h" |
Rafael Espindola | 74dd854 | 2014-10-21 00:25:49 +0000 | [diff] [blame] | 22 | #include "llvm/MC/MCContext.h" |
Chris Lattner | 71601e8 | 2010-01-20 07:41:15 +0000 | [diff] [blame] | 23 | #include "llvm/MC/MCStreamer.h" |
Chris Lattner | 06d45f6 | 2010-01-16 18:50:28 +0000 | [diff] [blame] | 24 | #include "llvm/MC/MCSymbol.h" |
David Greene | 8bc072c | 2009-12-24 00:27:55 +0000 | [diff] [blame] | 25 | #include "llvm/Support/Debug.h" |
Torok Edwin | 56d0659 | 2009-07-11 20:10:48 +0000 | [diff] [blame] | 26 | #include "llvm/Support/ErrorHandling.h" |
Chris Lattner | 7472571 | 2009-08-23 01:01:17 +0000 | [diff] [blame] | 27 | #include "llvm/Support/Format.h" |
Chris Lattner | f5c834f | 2010-01-22 22:09:00 +0000 | [diff] [blame] | 28 | #include "llvm/Support/FormattedStream.h" |
Logan Chien | 5b776b7 | 2014-02-22 14:00:39 +0000 | [diff] [blame] | 29 | #include "llvm/Support/LEB128.h" |
Eric Christopher | 6764643 | 2013-07-26 17:02:41 +0000 | [diff] [blame] | 30 | #include "llvm/Support/MD5.h" |
Benjamin Kramer | 799003b | 2015-03-23 19:32:43 +0000 | [diff] [blame] | 31 | #include "llvm/Support/raw_ostream.h" |
Bill Wendling | 47054f3 | 2009-05-15 00:11:17 +0000 | [diff] [blame] | 32 | using namespace llvm; |
| 33 | |
Paul Robinson | 70b3453 | 2017-04-20 19:16:51 +0000 | [diff] [blame] | 34 | #define DEBUG_TYPE "dwarfdebug" |
| 35 | |
Bill Wendling | 47054f3 | 2009-05-15 00:11:17 +0000 | [diff] [blame] | 36 | //===----------------------------------------------------------------------===// |
| 37 | // DIEAbbrevData Implementation |
| 38 | //===----------------------------------------------------------------------===// |
| 39 | |
| 40 | /// Profile - Used to gather unique data for the abbreviation folding set. |
| 41 | /// |
| 42 | void DIEAbbrevData::Profile(FoldingSetNodeID &ID) const { |
Reid Kleckner | ad65f10 | 2013-10-21 19:18:31 +0000 | [diff] [blame] | 43 | // Explicitly cast to an integer type for which FoldingSetNodeID has |
| 44 | // overloads. Otherwise MSVC 2010 thinks this call is ambiguous. |
| 45 | ID.AddInteger(unsigned(Attribute)); |
| 46 | ID.AddInteger(unsigned(Form)); |
Victor Leschuk | d7bfa40 | 2017-03-01 22:13:42 +0000 | [diff] [blame] | 47 | if (Form == dwarf::DW_FORM_implicit_const) |
| 48 | ID.AddInteger(Value); |
Bill Wendling | 47054f3 | 2009-05-15 00:11:17 +0000 | [diff] [blame] | 49 | } |
| 50 | |
| 51 | //===----------------------------------------------------------------------===// |
| 52 | // DIEAbbrev Implementation |
| 53 | //===----------------------------------------------------------------------===// |
| 54 | |
| 55 | /// Profile - Used to gather unique data for the abbreviation folding set. |
| 56 | /// |
| 57 | void DIEAbbrev::Profile(FoldingSetNodeID &ID) const { |
Reid Kleckner | ad65f10 | 2013-10-21 19:18:31 +0000 | [diff] [blame] | 58 | ID.AddInteger(unsigned(Tag)); |
Eric Christopher | e8f1072 | 2014-03-05 01:44:58 +0000 | [diff] [blame] | 59 | ID.AddInteger(unsigned(Children)); |
Bill Wendling | 47054f3 | 2009-05-15 00:11:17 +0000 | [diff] [blame] | 60 | |
| 61 | // For each attribute description. |
| 62 | for (unsigned i = 0, N = Data.size(); i < N; ++i) |
| 63 | Data[i].Profile(ID); |
| 64 | } |
| 65 | |
| 66 | /// Emit - Print the abbreviation using the specified asm printer. |
| 67 | /// |
Frederic Riss | cd04434 | 2015-03-04 02:30:08 +0000 | [diff] [blame] | 68 | void DIEAbbrev::Emit(const AsmPrinter *AP) const { |
Bill Wendling | 47054f3 | 2009-05-15 00:11:17 +0000 | [diff] [blame] | 69 | // Emit its Dwarf tag type. |
Mehdi Amini | 149f6ea | 2016-10-05 05:59:29 +0000 | [diff] [blame] | 70 | AP->EmitULEB128(Tag, dwarf::TagString(Tag).data()); |
Bill Wendling | 47054f3 | 2009-05-15 00:11:17 +0000 | [diff] [blame] | 71 | |
| 72 | // Emit whether it has children DIEs. |
Mehdi Amini | 149f6ea | 2016-10-05 05:59:29 +0000 | [diff] [blame] | 73 | AP->EmitULEB128((unsigned)Children, dwarf::ChildrenString(Children).data()); |
Bill Wendling | 47054f3 | 2009-05-15 00:11:17 +0000 | [diff] [blame] | 74 | |
| 75 | // For each attribute description. |
| 76 | for (unsigned i = 0, N = Data.size(); i < N; ++i) { |
| 77 | const DIEAbbrevData &AttrData = Data[i]; |
| 78 | |
| 79 | // Emit attribute type. |
Chris Lattner | 3a383cb | 2010-04-05 00:13:49 +0000 | [diff] [blame] | 80 | AP->EmitULEB128(AttrData.getAttribute(), |
Mehdi Amini | 149f6ea | 2016-10-05 05:59:29 +0000 | [diff] [blame] | 81 | dwarf::AttributeString(AttrData.getAttribute()).data()); |
Bill Wendling | 47054f3 | 2009-05-15 00:11:17 +0000 | [diff] [blame] | 82 | |
| 83 | // Emit form type. |
Paul Robinson | 70b3453 | 2017-04-20 19:16:51 +0000 | [diff] [blame] | 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())) { |
Nicola Zaghen | d34e60c | 2018-05-14 12:53:11 +0000 | [diff] [blame] | 89 | LLVM_DEBUG(dbgs() << "Invalid form " << format("0x%x", AttrData.getForm()) |
| 90 | << " for DWARF version " << AP->getDwarfVersion() |
| 91 | << "\n"); |
Paul Robinson | 70b3453 | 2017-04-20 19:16:51 +0000 | [diff] [blame] | 92 | llvm_unreachable("Invalid form for specified DWARF version"); |
| 93 | } |
| 94 | #endif |
Chris Lattner | 3a383cb | 2010-04-05 00:13:49 +0000 | [diff] [blame] | 95 | AP->EmitULEB128(AttrData.getForm(), |
Mehdi Amini | 149f6ea | 2016-10-05 05:59:29 +0000 | [diff] [blame] | 96 | dwarf::FormEncodingString(AttrData.getForm()).data()); |
Victor Leschuk | cbddae7 | 2017-01-10 21:18:26 +0000 | [diff] [blame] | 97 | |
| 98 | // Emit value for DW_FORM_implicit_const. |
Paul Robinson | 70b3453 | 2017-04-20 19:16:51 +0000 | [diff] [blame] | 99 | if (AttrData.getForm() == dwarf::DW_FORM_implicit_const) |
Victor Leschuk | cbddae7 | 2017-01-10 21:18:26 +0000 | [diff] [blame] | 100 | AP->EmitSLEB128(AttrData.getValue()); |
Bill Wendling | 47054f3 | 2009-05-15 00:11:17 +0000 | [diff] [blame] | 101 | } |
| 102 | |
| 103 | // Mark end of abbreviation. |
Chris Lattner | 3a383cb | 2010-04-05 00:13:49 +0000 | [diff] [blame] | 104 | AP->EmitULEB128(0, "EOM(1)"); |
| 105 | AP->EmitULEB128(0, "EOM(2)"); |
Bill Wendling | 47054f3 | 2009-05-15 00:11:17 +0000 | [diff] [blame] | 106 | } |
| 107 | |
Davide Italiano | c304a0d | 2015-11-24 02:21:43 +0000 | [diff] [blame] | 108 | LLVM_DUMP_METHOD |
Sam Clegg | 705f798 | 2017-06-21 22:19:17 +0000 | [diff] [blame] | 109 | void DIEAbbrev::print(raw_ostream &O) const { |
Bill Wendling | 47054f3 | 2009-05-15 00:11:17 +0000 | [diff] [blame] | 110 | O << "Abbreviation @" |
Chris Lattner | 7472571 | 2009-08-23 01:01:17 +0000 | [diff] [blame] | 111 | << format("0x%lx", (long)(intptr_t)this) |
Bill Wendling | 47054f3 | 2009-05-15 00:11:17 +0000 | [diff] [blame] | 112 | << " " |
| 113 | << dwarf::TagString(Tag) |
| 114 | << " " |
Eric Christopher | e8f1072 | 2014-03-05 01:44:58 +0000 | [diff] [blame] | 115 | << dwarf::ChildrenString(Children) |
Chris Lattner | 7472571 | 2009-08-23 01:01:17 +0000 | [diff] [blame] | 116 | << '\n'; |
Bill Wendling | 47054f3 | 2009-05-15 00:11:17 +0000 | [diff] [blame] | 117 | |
| 118 | for (unsigned i = 0, N = Data.size(); i < N; ++i) { |
| 119 | O << " " |
| 120 | << dwarf::AttributeString(Data[i].getAttribute()) |
| 121 | << " " |
Victor Leschuk | d7bfa40 | 2017-03-01 22:13:42 +0000 | [diff] [blame] | 122 | << dwarf::FormEncodingString(Data[i].getForm()); |
| 123 | |
| 124 | if (Data[i].getForm() == dwarf::DW_FORM_implicit_const) |
| 125 | O << " " << Data[i].getValue(); |
| 126 | |
| 127 | O << '\n'; |
Bill Wendling | 47054f3 | 2009-05-15 00:11:17 +0000 | [diff] [blame] | 128 | } |
| 129 | } |
Davide Italiano | c304a0d | 2015-11-24 02:21:43 +0000 | [diff] [blame] | 130 | |
Aaron Ballman | 615eb47 | 2017-10-15 14:32:27 +0000 | [diff] [blame] | 131 | #if !defined(NDEBUG) || defined(LLVM_ENABLE_DUMP) |
Sam Clegg | 705f798 | 2017-06-21 22:19:17 +0000 | [diff] [blame] | 132 | LLVM_DUMP_METHOD void DIEAbbrev::dump() const { |
Matthias Braun | 8c209aa | 2017-01-28 02:02:38 +0000 | [diff] [blame] | 133 | print(dbgs()); |
| 134 | } |
| 135 | #endif |
Bill Wendling | 47054f3 | 2009-05-15 00:11:17 +0000 | [diff] [blame] | 136 | |
Greg Clayton | 3462a42 | 2016-12-08 01:03:48 +0000 | [diff] [blame] | 137 | //===----------------------------------------------------------------------===// |
| 138 | // DIEAbbrevSet Implementation |
| 139 | //===----------------------------------------------------------------------===// |
| 140 | |
| 141 | DIEAbbrevSet::~DIEAbbrevSet() { |
| 142 | for (DIEAbbrev *Abbrev : Abbreviations) |
| 143 | Abbrev->~DIEAbbrev(); |
| 144 | } |
| 145 | |
| 146 | DIEAbbrev &DIEAbbrevSet::uniqueAbbreviation(DIE &Die) { |
| 147 | |
| 148 | FoldingSetNodeID ID; |
| 149 | DIEAbbrev Abbrev = Die.generateAbbrev(); |
| 150 | Abbrev.Profile(ID); |
| 151 | |
| 152 | void *InsertPos; |
| 153 | if (DIEAbbrev *Existing = |
| 154 | AbbreviationsSet.FindNodeOrInsertPos(ID, InsertPos)) { |
| 155 | Die.setAbbrevNumber(Existing->getNumber()); |
| 156 | return *Existing; |
| 157 | } |
| 158 | |
| 159 | // Move the abbreviation to the heap and assign a number. |
| 160 | DIEAbbrev *New = new (Alloc) DIEAbbrev(std::move(Abbrev)); |
| 161 | Abbreviations.push_back(New); |
| 162 | New->setNumber(Abbreviations.size()); |
| 163 | Die.setAbbrevNumber(Abbreviations.size()); |
| 164 | |
| 165 | // Store it for lookup. |
| 166 | AbbreviationsSet.InsertNode(New, InsertPos); |
| 167 | return *New; |
| 168 | } |
| 169 | |
| 170 | void DIEAbbrevSet::Emit(const AsmPrinter *AP, MCSection *Section) const { |
| 171 | if (!Abbreviations.empty()) { |
| 172 | // Start the debug abbrev section. |
| 173 | AP->OutStreamer->SwitchSection(Section); |
| 174 | AP->emitDwarfAbbrevs(Abbreviations); |
| 175 | } |
| 176 | } |
| 177 | |
| 178 | //===----------------------------------------------------------------------===// |
| 179 | // DIE Implementation |
| 180 | //===----------------------------------------------------------------------===// |
| 181 | |
Greg Clayton | 35630c3 | 2016-12-01 18:56:29 +0000 | [diff] [blame] | 182 | DIE *DIE::getParent() const { |
| 183 | return Owner.dyn_cast<DIE*>(); |
| 184 | } |
| 185 | |
Duncan P. N. Exon Smith | 815a6eb5 | 2015-05-27 22:31:41 +0000 | [diff] [blame] | 186 | DIEAbbrev DIE::generateAbbrev() const { |
| 187 | DIEAbbrev Abbrev(Tag, hasChildren()); |
Duncan P. N. Exon Smith | 1ad5ebc | 2015-08-02 20:42:45 +0000 | [diff] [blame] | 188 | for (const DIEValue &V : values()) |
Victor Leschuk | cbddae7 | 2017-01-10 21:18:26 +0000 | [diff] [blame] | 189 | if (V.getForm() == dwarf::DW_FORM_implicit_const) |
| 190 | Abbrev.AddImplicitConstAttribute(V.getAttribute(), |
| 191 | V.getDIEInteger().getValue()); |
| 192 | else |
| 193 | Abbrev.AddAttribute(V.getAttribute(), V.getForm()); |
Duncan P. N. Exon Smith | 815a6eb5 | 2015-05-27 22:31:41 +0000 | [diff] [blame] | 194 | return Abbrev; |
| 195 | } |
| 196 | |
Greg Clayton | 35630c3 | 2016-12-01 18:56:29 +0000 | [diff] [blame] | 197 | unsigned DIE::getDebugSectionOffset() const { |
| 198 | const DIEUnit *Unit = getUnit(); |
| 199 | assert(Unit && "DIE must be owned by a DIEUnit to get its absolute offset"); |
Benjamin Kramer | 6a8704c | 2016-12-01 19:10:10 +0000 | [diff] [blame] | 200 | return Unit->getDebugSectionOffset() + getOffset(); |
Manman Ren | 4dbdc90 | 2013-10-31 17:54:35 +0000 | [diff] [blame] | 201 | } |
| 202 | |
Greg Clayton | 35630c3 | 2016-12-01 18:56:29 +0000 | [diff] [blame] | 203 | const DIE *DIE::getUnitDie() const { |
Manman Ren | ce20d46 | 2013-10-29 22:57:10 +0000 | [diff] [blame] | 204 | const DIE *p = this; |
| 205 | while (p) { |
David Blaikie | 409dd9c | 2013-11-19 23:08:21 +0000 | [diff] [blame] | 206 | if (p->getTag() == dwarf::DW_TAG_compile_unit || |
| 207 | p->getTag() == dwarf::DW_TAG_type_unit) |
Manman Ren | ce20d46 | 2013-10-29 22:57:10 +0000 | [diff] [blame] | 208 | return p; |
| 209 | p = p->getParent(); |
| 210 | } |
Craig Topper | 353eda4 | 2014-04-24 06:44:33 +0000 | [diff] [blame] | 211 | return nullptr; |
Manman Ren | ce20d46 | 2013-10-29 22:57:10 +0000 | [diff] [blame] | 212 | } |
| 213 | |
Greg Clayton | 35630c3 | 2016-12-01 18:56:29 +0000 | [diff] [blame] | 214 | const DIEUnit *DIE::getUnit() const { |
| 215 | const DIE *UnitDie = getUnitDie(); |
| 216 | if (UnitDie) |
| 217 | return UnitDie->Owner.dyn_cast<DIEUnit*>(); |
| 218 | return nullptr; |
| 219 | } |
| 220 | |
Duncan P. N. Exon Smith | e7e1d0c | 2015-05-27 22:14:58 +0000 | [diff] [blame] | 221 | DIEValue DIE::findAttribute(dwarf::Attribute Attribute) const { |
Eric Christopher | 8552e22 | 2013-08-07 01:18:33 +0000 | [diff] [blame] | 222 | // Iterate through all the attributes until we find the one we're |
| 223 | // looking for, if we can't find it return NULL. |
Duncan P. N. Exon Smith | 88a8fc5 | 2015-05-27 22:44:06 +0000 | [diff] [blame] | 224 | for (const auto &V : values()) |
| 225 | if (V.getAttribute() == Attribute) |
| 226 | return V; |
Duncan P. N. Exon Smith | e7e1d0c | 2015-05-27 22:14:58 +0000 | [diff] [blame] | 227 | return DIEValue(); |
Eric Christopher | 8552e22 | 2013-08-07 01:18:33 +0000 | [diff] [blame] | 228 | } |
| 229 | |
Davide Italiano | c304a0d | 2015-11-24 02:21:43 +0000 | [diff] [blame] | 230 | LLVM_DUMP_METHOD |
Duncan P. N. Exon Smith | c582114 | 2015-08-02 20:46:49 +0000 | [diff] [blame] | 231 | static void printValues(raw_ostream &O, const DIEValueList &Values, |
| 232 | StringRef Type, unsigned Size, unsigned IndentCount) { |
| 233 | O << Type << ": Size: " << Size << "\n"; |
| 234 | |
| 235 | unsigned I = 0; |
| 236 | const std::string Indent(IndentCount, ' '); |
| 237 | for (const auto &V : Values.values()) { |
| 238 | O << Indent; |
| 239 | O << "Blk[" << I++ << "]"; |
| 240 | O << " " << dwarf::FormEncodingString(V.getForm()) << " "; |
| 241 | V.print(O); |
| 242 | O << "\n"; |
| 243 | } |
| 244 | } |
| 245 | |
Davide Italiano | c304a0d | 2015-11-24 02:21:43 +0000 | [diff] [blame] | 246 | LLVM_DUMP_METHOD |
Eric Christopher | 6c6de84 | 2013-05-06 17:50:50 +0000 | [diff] [blame] | 247 | void DIE::print(raw_ostream &O, unsigned IndentCount) const { |
Bill Wendling | 47054f3 | 2009-05-15 00:11:17 +0000 | [diff] [blame] | 248 | const std::string Indent(IndentCount, ' '); |
Duncan P. N. Exon Smith | c582114 | 2015-08-02 20:46:49 +0000 | [diff] [blame] | 249 | O << Indent << "Die: " << format("0x%lx", (long)(intptr_t) this) |
| 250 | << ", Offset: " << Offset << ", Size: " << Size << "\n"; |
Bill Wendling | 47054f3 | 2009-05-15 00:11:17 +0000 | [diff] [blame] | 251 | |
Duncan P. N. Exon Smith | c582114 | 2015-08-02 20:46:49 +0000 | [diff] [blame] | 252 | O << Indent << dwarf::TagString(getTag()) << " " |
| 253 | << dwarf::ChildrenString(hasChildren()) << "\n"; |
Bill Wendling | 47054f3 | 2009-05-15 00:11:17 +0000 | [diff] [blame] | 254 | |
Bill Wendling | 47054f3 | 2009-05-15 00:11:17 +0000 | [diff] [blame] | 255 | IndentCount += 2; |
Duncan P. N. Exon Smith | 1ad5ebc | 2015-08-02 20:42:45 +0000 | [diff] [blame] | 256 | for (const auto &V : values()) { |
Bill Wendling | 47054f3 | 2009-05-15 00:11:17 +0000 | [diff] [blame] | 257 | O << Indent; |
Duncan P. N. Exon Smith | c582114 | 2015-08-02 20:46:49 +0000 | [diff] [blame] | 258 | O << dwarf::AttributeString(V.getAttribute()); |
Duncan P. N. Exon Smith | 4fb1f9c | 2015-06-25 23:46:41 +0000 | [diff] [blame] | 259 | O << " " << dwarf::FormEncodingString(V.getForm()) << " "; |
| 260 | V.print(O); |
Bill Wendling | 47054f3 | 2009-05-15 00:11:17 +0000 | [diff] [blame] | 261 | O << "\n"; |
| 262 | } |
| 263 | IndentCount -= 2; |
| 264 | |
Duncan P. N. Exon Smith | 827200c | 2015-06-25 23:52:10 +0000 | [diff] [blame] | 265 | for (const auto &Child : children()) |
| 266 | Child.print(O, IndentCount + 4); |
Bill Wendling | 47054f3 | 2009-05-15 00:11:17 +0000 | [diff] [blame] | 267 | |
Duncan P. N. Exon Smith | c582114 | 2015-08-02 20:46:49 +0000 | [diff] [blame] | 268 | O << "\n"; |
Bill Wendling | 47054f3 | 2009-05-15 00:11:17 +0000 | [diff] [blame] | 269 | } |
| 270 | |
Aaron Ballman | 615eb47 | 2017-10-15 14:32:27 +0000 | [diff] [blame] | 271 | #if !defined(NDEBUG) || defined(LLVM_ENABLE_DUMP) |
Sam Clegg | 705f798 | 2017-06-21 22:19:17 +0000 | [diff] [blame] | 272 | LLVM_DUMP_METHOD void DIE::dump() const { |
David Greene | 8bc072c | 2009-12-24 00:27:55 +0000 | [diff] [blame] | 273 | print(dbgs()); |
Bill Wendling | 47054f3 | 2009-05-15 00:11:17 +0000 | [diff] [blame] | 274 | } |
Matthias Braun | 8c209aa | 2017-01-28 02:02:38 +0000 | [diff] [blame] | 275 | #endif |
Bill Wendling | 47054f3 | 2009-05-15 00:11:17 +0000 | [diff] [blame] | 276 | |
Greg Clayton | 3462a42 | 2016-12-08 01:03:48 +0000 | [diff] [blame] | 277 | unsigned DIE::computeOffsetsAndAbbrevs(const AsmPrinter *AP, |
| 278 | DIEAbbrevSet &AbbrevSet, |
| 279 | unsigned CUOffset) { |
| 280 | // Unique the abbreviation and fill in the abbreviation number so this DIE |
| 281 | // can be emitted. |
| 282 | const DIEAbbrev &Abbrev = AbbrevSet.uniqueAbbreviation(*this); |
| 283 | |
| 284 | // Set compile/type unit relative offset of this DIE. |
| 285 | setOffset(CUOffset); |
| 286 | |
| 287 | // Add the byte size of the abbreviation code. |
| 288 | CUOffset += getULEB128Size(getAbbrevNumber()); |
| 289 | |
| 290 | // Add the byte size of all the DIE attribute values. |
| 291 | for (const auto &V : values()) |
| 292 | CUOffset += V.SizeOf(AP); |
| 293 | |
| 294 | // Let the children compute their offsets and abbreviation numbers. |
| 295 | if (hasChildren()) { |
| 296 | (void)Abbrev; |
| 297 | assert(Abbrev.hasChildren() && "Children flag not set"); |
| 298 | |
| 299 | for (auto &Child : children()) |
| 300 | CUOffset = Child.computeOffsetsAndAbbrevs(AP, AbbrevSet, CUOffset); |
| 301 | |
| 302 | // Each child chain is terminated with a zero byte, adjust the offset. |
| 303 | CUOffset += sizeof(int8_t); |
| 304 | } |
| 305 | |
| 306 | // Compute the byte size of this DIE and all of its children correctly. This |
| 307 | // is needed so that top level DIE can help the compile unit set its length |
| 308 | // correctly. |
| 309 | setSize(CUOffset - getOffset()); |
| 310 | return CUOffset; |
| 311 | } |
| 312 | |
| 313 | //===----------------------------------------------------------------------===// |
| 314 | // DIEUnit Implementation |
| 315 | //===----------------------------------------------------------------------===// |
Greg Clayton | 35630c3 | 2016-12-01 18:56:29 +0000 | [diff] [blame] | 316 | DIEUnit::DIEUnit(uint16_t V, uint8_t A, dwarf::Tag UnitTag) |
| 317 | : Die(UnitTag), Section(nullptr), Offset(0), Length(0), Version(V), |
| 318 | AddrSize(A) |
| 319 | { |
David Blaikie | e40caae | 2016-12-01 21:59:09 +0000 | [diff] [blame] | 320 | Die.Owner = this; |
Greg Clayton | 35630c3 | 2016-12-01 18:56:29 +0000 | [diff] [blame] | 321 | assert((UnitTag == dwarf::DW_TAG_compile_unit || |
| 322 | UnitTag == dwarf::DW_TAG_type_unit || |
| 323 | UnitTag == dwarf::DW_TAG_partial_unit) && "expected a unit TAG"); |
| 324 | } |
| 325 | |
Duncan P. N. Exon Smith | 9dbb501 | 2015-06-24 18:48:11 +0000 | [diff] [blame] | 326 | void DIEValue::EmitValue(const AsmPrinter *AP) const { |
Duncan P. N. Exon Smith | 68b3f30 | 2015-05-23 01:45:07 +0000 | [diff] [blame] | 327 | switch (Ty) { |
Duncan P. N. Exon Smith | e7e1d0c | 2015-05-27 22:14:58 +0000 | [diff] [blame] | 328 | case isNone: |
| 329 | llvm_unreachable("Expected valid DIEValue"); |
Duncan P. N. Exon Smith | ff18927 | 2015-05-27 21:15:43 +0000 | [diff] [blame] | 330 | #define HANDLE_DIEVALUE(T) \ |
| 331 | case is##T: \ |
Duncan P. N. Exon Smith | e7e1d0c | 2015-05-27 22:14:58 +0000 | [diff] [blame] | 332 | getDIE##T().EmitValue(AP, Form); \ |
Duncan P. N. Exon Smith | 68b3f30 | 2015-05-23 01:45:07 +0000 | [diff] [blame] | 333 | break; |
Duncan P. N. Exon Smith | ff18927 | 2015-05-27 21:15:43 +0000 | [diff] [blame] | 334 | #include "llvm/CodeGen/DIEValue.def" |
Duncan P. N. Exon Smith | 68b3f30 | 2015-05-23 01:45:07 +0000 | [diff] [blame] | 335 | } |
| 336 | } |
| 337 | |
Duncan P. N. Exon Smith | 9dbb501 | 2015-06-24 18:48:11 +0000 | [diff] [blame] | 338 | unsigned DIEValue::SizeOf(const AsmPrinter *AP) const { |
Duncan P. N. Exon Smith | 68b3f30 | 2015-05-23 01:45:07 +0000 | [diff] [blame] | 339 | switch (Ty) { |
Duncan P. N. Exon Smith | e7e1d0c | 2015-05-27 22:14:58 +0000 | [diff] [blame] | 340 | case isNone: |
| 341 | llvm_unreachable("Expected valid DIEValue"); |
Duncan P. N. Exon Smith | ff18927 | 2015-05-27 21:15:43 +0000 | [diff] [blame] | 342 | #define HANDLE_DIEVALUE(T) \ |
| 343 | case is##T: \ |
Duncan P. N. Exon Smith | e7e1d0c | 2015-05-27 22:14:58 +0000 | [diff] [blame] | 344 | return getDIE##T().SizeOf(AP, Form); |
Duncan P. N. Exon Smith | ff18927 | 2015-05-27 21:15:43 +0000 | [diff] [blame] | 345 | #include "llvm/CodeGen/DIEValue.def" |
Duncan P. N. Exon Smith | 68b3f30 | 2015-05-23 01:45:07 +0000 | [diff] [blame] | 346 | } |
Aaron Ballman | c681c3d | 2015-05-23 14:46:49 +0000 | [diff] [blame] | 347 | llvm_unreachable("Unknown DIE kind"); |
Duncan P. N. Exon Smith | 68b3f30 | 2015-05-23 01:45:07 +0000 | [diff] [blame] | 348 | } |
Bill Wendling | 47054f3 | 2009-05-15 00:11:17 +0000 | [diff] [blame] | 349 | |
Davide Italiano | c304a0d | 2015-11-24 02:21:43 +0000 | [diff] [blame] | 350 | LLVM_DUMP_METHOD |
Duncan P. N. Exon Smith | 68b3f30 | 2015-05-23 01:45:07 +0000 | [diff] [blame] | 351 | void DIEValue::print(raw_ostream &O) const { |
| 352 | switch (Ty) { |
Duncan P. N. Exon Smith | e7e1d0c | 2015-05-27 22:14:58 +0000 | [diff] [blame] | 353 | case isNone: |
| 354 | llvm_unreachable("Expected valid DIEValue"); |
Duncan P. N. Exon Smith | ff18927 | 2015-05-27 21:15:43 +0000 | [diff] [blame] | 355 | #define HANDLE_DIEVALUE(T) \ |
| 356 | case is##T: \ |
Duncan P. N. Exon Smith | e7e1d0c | 2015-05-27 22:14:58 +0000 | [diff] [blame] | 357 | getDIE##T().print(O); \ |
Duncan P. N. Exon Smith | 68b3f30 | 2015-05-23 01:45:07 +0000 | [diff] [blame] | 358 | break; |
Duncan P. N. Exon Smith | ff18927 | 2015-05-27 21:15:43 +0000 | [diff] [blame] | 359 | #include "llvm/CodeGen/DIEValue.def" |
Duncan P. N. Exon Smith | 68b3f30 | 2015-05-23 01:45:07 +0000 | [diff] [blame] | 360 | } |
| 361 | } |
| 362 | |
Aaron Ballman | 615eb47 | 2017-10-15 14:32:27 +0000 | [diff] [blame] | 363 | #if !defined(NDEBUG) || defined(LLVM_ENABLE_DUMP) |
Matthias Braun | 8c209aa | 2017-01-28 02:02:38 +0000 | [diff] [blame] | 364 | LLVM_DUMP_METHOD void DIEValue::dump() const { |
David Greene | 8bc072c | 2009-12-24 00:27:55 +0000 | [diff] [blame] | 365 | print(dbgs()); |
Bill Wendling | 47054f3 | 2009-05-15 00:11:17 +0000 | [diff] [blame] | 366 | } |
Matthias Braun | 8c209aa | 2017-01-28 02:02:38 +0000 | [diff] [blame] | 367 | #endif |
Bill Wendling | 47054f3 | 2009-05-15 00:11:17 +0000 | [diff] [blame] | 368 | |
| 369 | //===----------------------------------------------------------------------===// |
| 370 | // DIEInteger Implementation |
| 371 | //===----------------------------------------------------------------------===// |
| 372 | |
| 373 | /// EmitValue - Emit integer of appropriate size. |
| 374 | /// |
Duncan P. N. Exon Smith | e7e1d0c | 2015-05-27 22:14:58 +0000 | [diff] [blame] | 375 | void DIEInteger::EmitValue(const AsmPrinter *Asm, dwarf::Form Form) const { |
Bill Wendling | 47054f3 | 2009-05-15 00:11:17 +0000 | [diff] [blame] | 376 | switch (Form) { |
Victor Leschuk | cbddae7 | 2017-01-10 21:18:26 +0000 | [diff] [blame] | 377 | case dwarf::DW_FORM_implicit_const: |
Eric Christopher | bb69a27 | 2012-08-24 01:14:27 +0000 | [diff] [blame] | 378 | case dwarf::DW_FORM_flag_present: |
| 379 | // Emit something to keep the lines and comments in sync. |
| 380 | // FIXME: Is there a better way to do this? |
Lang Hames | 9ff69c8 | 2015-04-24 19:11:51 +0000 | [diff] [blame] | 381 | Asm->OutStreamer->AddBlankLine(); |
Eric Christopher | bb69a27 | 2012-08-24 01:14:27 +0000 | [diff] [blame] | 382 | return; |
Greg Clayton | 3462a42 | 2016-12-08 01:03:48 +0000 | [diff] [blame] | 383 | case dwarf::DW_FORM_flag: |
Greg Clayton | 3462a42 | 2016-12-08 01:03:48 +0000 | [diff] [blame] | 384 | case dwarf::DW_FORM_ref1: |
Greg Clayton | 3462a42 | 2016-12-08 01:03:48 +0000 | [diff] [blame] | 385 | case dwarf::DW_FORM_data1: |
Paul Robinson | f96e21a | 2017-03-06 22:20:03 +0000 | [diff] [blame] | 386 | case dwarf::DW_FORM_strx1: |
| 387 | case dwarf::DW_FORM_addrx1: |
Greg Clayton | 3462a42 | 2016-12-08 01:03:48 +0000 | [diff] [blame] | 388 | case dwarf::DW_FORM_ref2: |
Greg Clayton | 3462a42 | 2016-12-08 01:03:48 +0000 | [diff] [blame] | 389 | case dwarf::DW_FORM_data2: |
Paul Robinson | f96e21a | 2017-03-06 22:20:03 +0000 | [diff] [blame] | 390 | case dwarf::DW_FORM_strx2: |
| 391 | case dwarf::DW_FORM_addrx2: |
Wolfgang Pieb | 456b555 | 2018-01-26 18:52:58 +0000 | [diff] [blame] | 392 | case dwarf::DW_FORM_strx3: |
Greg Clayton | 3462a42 | 2016-12-08 01:03:48 +0000 | [diff] [blame] | 393 | case dwarf::DW_FORM_strp: |
Greg Clayton | 3462a42 | 2016-12-08 01:03:48 +0000 | [diff] [blame] | 394 | case dwarf::DW_FORM_ref4: |
Greg Clayton | 3462a42 | 2016-12-08 01:03:48 +0000 | [diff] [blame] | 395 | case dwarf::DW_FORM_data4: |
Paul Robinson | f96e21a | 2017-03-06 22:20:03 +0000 | [diff] [blame] | 396 | case dwarf::DW_FORM_ref_sup4: |
| 397 | case dwarf::DW_FORM_strx4: |
| 398 | case dwarf::DW_FORM_addrx4: |
Greg Clayton | 3462a42 | 2016-12-08 01:03:48 +0000 | [diff] [blame] | 399 | case dwarf::DW_FORM_ref8: |
Greg Clayton | 3462a42 | 2016-12-08 01:03:48 +0000 | [diff] [blame] | 400 | case dwarf::DW_FORM_ref_sig8: |
Greg Clayton | 3462a42 | 2016-12-08 01:03:48 +0000 | [diff] [blame] | 401 | case dwarf::DW_FORM_data8: |
Paul Robinson | f96e21a | 2017-03-06 22:20:03 +0000 | [diff] [blame] | 402 | case dwarf::DW_FORM_ref_sup8: |
Greg Clayton | 3462a42 | 2016-12-08 01:03:48 +0000 | [diff] [blame] | 403 | case dwarf::DW_FORM_GNU_ref_alt: |
Greg Clayton | 3462a42 | 2016-12-08 01:03:48 +0000 | [diff] [blame] | 404 | case dwarf::DW_FORM_GNU_strp_alt: |
Greg Clayton | 3462a42 | 2016-12-08 01:03:48 +0000 | [diff] [blame] | 405 | case dwarf::DW_FORM_line_strp: |
Greg Clayton | 3462a42 | 2016-12-08 01:03:48 +0000 | [diff] [blame] | 406 | case dwarf::DW_FORM_sec_offset: |
Greg Clayton | 3462a42 | 2016-12-08 01:03:48 +0000 | [diff] [blame] | 407 | case dwarf::DW_FORM_strp_sup: |
Eric Christopher | e8a7b1b | 2012-09-10 23:34:03 +0000 | [diff] [blame] | 408 | case dwarf::DW_FORM_addr: |
Frederic Riss | ee17fb9b | 2015-03-04 22:07:36 +0000 | [diff] [blame] | 409 | case dwarf::DW_FORM_ref_addr: |
Greg Clayton | 3462a42 | 2016-12-08 01:03:48 +0000 | [diff] [blame] | 410 | Asm->OutStreamer->EmitIntValue(Integer, SizeOf(Asm, Form)); |
| 411 | return; |
| 412 | case dwarf::DW_FORM_GNU_str_index: |
Greg Clayton | 3462a42 | 2016-12-08 01:03:48 +0000 | [diff] [blame] | 413 | case dwarf::DW_FORM_GNU_addr_index: |
Greg Clayton | 3462a42 | 2016-12-08 01:03:48 +0000 | [diff] [blame] | 414 | case dwarf::DW_FORM_ref_udata: |
Wolfgang Pieb | 456b555 | 2018-01-26 18:52:58 +0000 | [diff] [blame] | 415 | case dwarf::DW_FORM_strx: |
David Blaikie | 161dd3c | 2018-10-20 06:02:15 +0000 | [diff] [blame] | 416 | case dwarf::DW_FORM_addrx: |
David Blaikie | c4af8bf | 2018-10-20 07:36:39 +0000 | [diff] [blame] | 417 | case dwarf::DW_FORM_rnglistx: |
Greg Clayton | 3462a42 | 2016-12-08 01:03:48 +0000 | [diff] [blame] | 418 | case dwarf::DW_FORM_udata: |
| 419 | Asm->EmitULEB128(Integer); |
| 420 | return; |
| 421 | case dwarf::DW_FORM_sdata: |
| 422 | Asm->EmitSLEB128(Integer); |
| 423 | return; |
Torok Edwin | fbcc663 | 2009-07-14 16:55:14 +0000 | [diff] [blame] | 424 | default: llvm_unreachable("DIE Value form not supported yet"); |
Bill Wendling | 47054f3 | 2009-05-15 00:11:17 +0000 | [diff] [blame] | 425 | } |
| 426 | } |
| 427 | |
| 428 | /// SizeOf - Determine size of integer value in bytes. |
| 429 | /// |
Duncan P. N. Exon Smith | e7e1d0c | 2015-05-27 22:14:58 +0000 | [diff] [blame] | 430 | unsigned DIEInteger::SizeOf(const AsmPrinter *AP, dwarf::Form Form) const { |
Pavel Labath | 8ed6582b | 2018-03-14 11:31:17 +0000 | [diff] [blame] | 431 | dwarf::FormParams Params = {0, 0, dwarf::DWARF32}; |
Pavel Labath | 322711f | 2018-03-14 09:39:54 +0000 | [diff] [blame] | 432 | if (AP) |
| 433 | Params = {AP->getDwarfVersion(), uint8_t(AP->getPointerSize()), |
| 434 | AP->OutStreamer->getContext().getDwarfFormat()}; |
| 435 | |
| 436 | if (Optional<uint8_t> FixedSize = dwarf::getFixedFormByteSize(Form, Params)) |
| 437 | return *FixedSize; |
| 438 | |
Bill Wendling | 47054f3 | 2009-05-15 00:11:17 +0000 | [diff] [blame] | 439 | switch (Form) { |
Greg Clayton | 3462a42 | 2016-12-08 01:03:48 +0000 | [diff] [blame] | 440 | case dwarf::DW_FORM_GNU_str_index: |
Greg Clayton | 3462a42 | 2016-12-08 01:03:48 +0000 | [diff] [blame] | 441 | case dwarf::DW_FORM_GNU_addr_index: |
Greg Clayton | 3462a42 | 2016-12-08 01:03:48 +0000 | [diff] [blame] | 442 | case dwarf::DW_FORM_ref_udata: |
Wolfgang Pieb | 456b555 | 2018-01-26 18:52:58 +0000 | [diff] [blame] | 443 | case dwarf::DW_FORM_strx: |
David Blaikie | 161dd3c | 2018-10-20 06:02:15 +0000 | [diff] [blame] | 444 | case dwarf::DW_FORM_addrx: |
David Blaikie | c4af8bf | 2018-10-20 07:36:39 +0000 | [diff] [blame] | 445 | case dwarf::DW_FORM_rnglistx: |
Greg Clayton | 3462a42 | 2016-12-08 01:03:48 +0000 | [diff] [blame] | 446 | case dwarf::DW_FORM_udata: |
| 447 | return getULEB128Size(Integer); |
| 448 | case dwarf::DW_FORM_sdata: |
| 449 | return getSLEB128Size(Integer); |
David Blaikie | 46a9f01 | 2012-01-20 21:51:11 +0000 | [diff] [blame] | 450 | default: llvm_unreachable("DIE Value form not supported yet"); |
Bill Wendling | 47054f3 | 2009-05-15 00:11:17 +0000 | [diff] [blame] | 451 | } |
Bill Wendling | 47054f3 | 2009-05-15 00:11:17 +0000 | [diff] [blame] | 452 | } |
| 453 | |
Davide Italiano | c304a0d | 2015-11-24 02:21:43 +0000 | [diff] [blame] | 454 | LLVM_DUMP_METHOD |
Duncan P. N. Exon Smith | e7e1d0c | 2015-05-27 22:14:58 +0000 | [diff] [blame] | 455 | void DIEInteger::print(raw_ostream &O) const { |
Benjamin Kramer | f3da529 | 2011-11-05 08:57:40 +0000 | [diff] [blame] | 456 | O << "Int: " << (int64_t)Integer << " 0x"; |
| 457 | O.write_hex(Integer); |
Bill Wendling | 47054f3 | 2009-05-15 00:11:17 +0000 | [diff] [blame] | 458 | } |
Bill Wendling | 47054f3 | 2009-05-15 00:11:17 +0000 | [diff] [blame] | 459 | |
| 460 | //===----------------------------------------------------------------------===// |
Ulrich Weigand | 396ba8b | 2013-07-02 18:46:26 +0000 | [diff] [blame] | 461 | // DIEExpr Implementation |
| 462 | //===----------------------------------------------------------------------===// |
| 463 | |
| 464 | /// EmitValue - Emit expression value. |
| 465 | /// |
Duncan P. N. Exon Smith | e7e1d0c | 2015-05-27 22:14:58 +0000 | [diff] [blame] | 466 | void DIEExpr::EmitValue(const AsmPrinter *AP, dwarf::Form Form) const { |
Simon Atanasyan | af860d4 | 2018-11-28 11:48:07 +0000 | [diff] [blame] | 467 | AP->EmitDebugValue(Expr, SizeOf(AP, Form)); |
Ulrich Weigand | 396ba8b | 2013-07-02 18:46:26 +0000 | [diff] [blame] | 468 | } |
| 469 | |
| 470 | /// SizeOf - Determine size of expression value in bytes. |
| 471 | /// |
Duncan P. N. Exon Smith | e7e1d0c | 2015-05-27 22:14:58 +0000 | [diff] [blame] | 472 | unsigned DIEExpr::SizeOf(const AsmPrinter *AP, dwarf::Form Form) const { |
Ulrich Weigand | 396ba8b | 2013-07-02 18:46:26 +0000 | [diff] [blame] | 473 | if (Form == dwarf::DW_FORM_data4) return 4; |
| 474 | if (Form == dwarf::DW_FORM_sec_offset) return 4; |
| 475 | if (Form == dwarf::DW_FORM_strp) return 4; |
Mehdi Amini | 1660cab | 2015-07-16 05:59:25 +0000 | [diff] [blame] | 476 | return AP->getPointerSize(); |
Ulrich Weigand | 396ba8b | 2013-07-02 18:46:26 +0000 | [diff] [blame] | 477 | } |
| 478 | |
Davide Italiano | c304a0d | 2015-11-24 02:21:43 +0000 | [diff] [blame] | 479 | LLVM_DUMP_METHOD |
Duncan P. N. Exon Smith | e7e1d0c | 2015-05-27 22:14:58 +0000 | [diff] [blame] | 480 | void DIEExpr::print(raw_ostream &O) const { O << "Expr: " << *Expr; } |
Ulrich Weigand | 396ba8b | 2013-07-02 18:46:26 +0000 | [diff] [blame] | 481 | |
| 482 | //===----------------------------------------------------------------------===// |
Chris Lattner | 8dcf41e | 2010-03-08 22:31:46 +0000 | [diff] [blame] | 483 | // DIELabel Implementation |
Bill Wendling | 47054f3 | 2009-05-15 00:11:17 +0000 | [diff] [blame] | 484 | //===----------------------------------------------------------------------===// |
| 485 | |
| 486 | /// EmitValue - Emit label value. |
| 487 | /// |
Duncan P. N. Exon Smith | e7e1d0c | 2015-05-27 22:14:58 +0000 | [diff] [blame] | 488 | void DIELabel::EmitValue(const AsmPrinter *AP, dwarf::Form Form) const { |
David Blaikie | f244319 | 2013-10-21 17:28:37 +0000 | [diff] [blame] | 489 | AP->EmitLabelReference(Label, SizeOf(AP, Form), |
| 490 | Form == dwarf::DW_FORM_strp || |
| 491 | Form == dwarf::DW_FORM_sec_offset || |
Keno Fischer | f7d84ee | 2017-01-02 03:00:19 +0000 | [diff] [blame] | 492 | Form == dwarf::DW_FORM_ref_addr || |
| 493 | Form == dwarf::DW_FORM_data4); |
Bill Wendling | 47054f3 | 2009-05-15 00:11:17 +0000 | [diff] [blame] | 494 | } |
| 495 | |
| 496 | /// SizeOf - Determine size of label value in bytes. |
| 497 | /// |
Duncan P. N. Exon Smith | e7e1d0c | 2015-05-27 22:14:58 +0000 | [diff] [blame] | 498 | unsigned DIELabel::SizeOf(const AsmPrinter *AP, dwarf::Form Form) const { |
Bill Wendling | 47054f3 | 2009-05-15 00:11:17 +0000 | [diff] [blame] | 499 | if (Form == dwarf::DW_FORM_data4) return 4; |
Eric Christopher | 4c7765f | 2013-01-17 03:00:04 +0000 | [diff] [blame] | 500 | if (Form == dwarf::DW_FORM_sec_offset) return 4; |
Nick Lewycky | d59c0ca | 2011-10-27 06:44:11 +0000 | [diff] [blame] | 501 | if (Form == dwarf::DW_FORM_strp) return 4; |
Konstantin Zhuravlyov | dc77b2e | 2017-04-17 17:41:25 +0000 | [diff] [blame] | 502 | return AP->MAI->getCodePointerSize(); |
Bill Wendling | 47054f3 | 2009-05-15 00:11:17 +0000 | [diff] [blame] | 503 | } |
| 504 | |
Davide Italiano | c304a0d | 2015-11-24 02:21:43 +0000 | [diff] [blame] | 505 | LLVM_DUMP_METHOD |
Duncan P. N. Exon Smith | e7e1d0c | 2015-05-27 22:14:58 +0000 | [diff] [blame] | 506 | void DIELabel::print(raw_ostream &O) const { O << "Lbl: " << Label->getName(); } |
Bill Wendling | 47054f3 | 2009-05-15 00:11:17 +0000 | [diff] [blame] | 507 | |
| 508 | //===----------------------------------------------------------------------===// |
Bill Wendling | 47054f3 | 2009-05-15 00:11:17 +0000 | [diff] [blame] | 509 | // DIEDelta Implementation |
| 510 | //===----------------------------------------------------------------------===// |
| 511 | |
| 512 | /// EmitValue - Emit delta value. |
| 513 | /// |
Duncan P. N. Exon Smith | e7e1d0c | 2015-05-27 22:14:58 +0000 | [diff] [blame] | 514 | void DIEDelta::EmitValue(const AsmPrinter *AP, dwarf::Form Form) const { |
Chris Lattner | 5a00dea | 2010-04-05 00:18:22 +0000 | [diff] [blame] | 515 | AP->EmitLabelDifference(LabelHi, LabelLo, SizeOf(AP, Form)); |
Bill Wendling | 47054f3 | 2009-05-15 00:11:17 +0000 | [diff] [blame] | 516 | } |
| 517 | |
| 518 | /// SizeOf - Determine size of delta value in bytes. |
| 519 | /// |
Duncan P. N. Exon Smith | e7e1d0c | 2015-05-27 22:14:58 +0000 | [diff] [blame] | 520 | unsigned DIEDelta::SizeOf(const AsmPrinter *AP, dwarf::Form Form) const { |
Bill Wendling | 47054f3 | 2009-05-15 00:11:17 +0000 | [diff] [blame] | 521 | if (Form == dwarf::DW_FORM_data4) return 4; |
Eric Christopher | 33ff697 | 2013-11-21 23:46:41 +0000 | [diff] [blame] | 522 | if (Form == dwarf::DW_FORM_sec_offset) return 4; |
Nick Lewycky | d59c0ca | 2011-10-27 06:44:11 +0000 | [diff] [blame] | 523 | if (Form == dwarf::DW_FORM_strp) return 4; |
Konstantin Zhuravlyov | dc77b2e | 2017-04-17 17:41:25 +0000 | [diff] [blame] | 524 | return AP->MAI->getCodePointerSize(); |
Bill Wendling | 47054f3 | 2009-05-15 00:11:17 +0000 | [diff] [blame] | 525 | } |
| 526 | |
Davide Italiano | c304a0d | 2015-11-24 02:21:43 +0000 | [diff] [blame] | 527 | LLVM_DUMP_METHOD |
Duncan P. N. Exon Smith | e7e1d0c | 2015-05-27 22:14:58 +0000 | [diff] [blame] | 528 | void DIEDelta::print(raw_ostream &O) const { |
Chris Lattner | bc9210c | 2010-03-08 22:23:36 +0000 | [diff] [blame] | 529 | O << "Del: " << LabelHi->getName() << "-" << LabelLo->getName(); |
Bill Wendling | 47054f3 | 2009-05-15 00:11:17 +0000 | [diff] [blame] | 530 | } |
Bill Wendling | 47054f3 | 2009-05-15 00:11:17 +0000 | [diff] [blame] | 531 | |
| 532 | //===----------------------------------------------------------------------===// |
Eric Christopher | 6764643 | 2013-07-26 17:02:41 +0000 | [diff] [blame] | 533 | // DIEString Implementation |
| 534 | //===----------------------------------------------------------------------===// |
| 535 | |
| 536 | /// EmitValue - Emit string value. |
| 537 | /// |
Duncan P. N. Exon Smith | e7e1d0c | 2015-05-27 22:14:58 +0000 | [diff] [blame] | 538 | void DIEString::EmitValue(const AsmPrinter *AP, dwarf::Form Form) const { |
Duncan P. N. Exon Smith | f73bcf4 | 2015-05-24 16:40:47 +0000 | [diff] [blame] | 539 | // Index of string in symbol table. |
Wolfgang Pieb | 456b555 | 2018-01-26 18:52:58 +0000 | [diff] [blame] | 540 | switch (Form) { |
| 541 | case dwarf::DW_FORM_GNU_str_index: |
| 542 | case dwarf::DW_FORM_strx: |
| 543 | case dwarf::DW_FORM_strx1: |
| 544 | case dwarf::DW_FORM_strx2: |
| 545 | case dwarf::DW_FORM_strx3: |
| 546 | case dwarf::DW_FORM_strx4: |
Duncan P. N. Exon Smith | f73bcf4 | 2015-05-24 16:40:47 +0000 | [diff] [blame] | 547 | DIEInteger(S.getIndex()).EmitValue(AP, Form); |
| 548 | return; |
Wolfgang Pieb | 456b555 | 2018-01-26 18:52:58 +0000 | [diff] [blame] | 549 | case dwarf::DW_FORM_strp: |
| 550 | if (AP->MAI->doesDwarfUseRelocationsAcrossSections()) |
| 551 | DIELabel(S.getSymbol()).EmitValue(AP, Form); |
| 552 | else |
| 553 | DIEInteger(S.getOffset()).EmitValue(AP, Form); |
Duncan P. N. Exon Smith | f73bcf4 | 2015-05-24 16:40:47 +0000 | [diff] [blame] | 554 | return; |
Wolfgang Pieb | 456b555 | 2018-01-26 18:52:58 +0000 | [diff] [blame] | 555 | default: |
| 556 | llvm_unreachable("Expected valid string form"); |
Duncan P. N. Exon Smith | f73bcf4 | 2015-05-24 16:40:47 +0000 | [diff] [blame] | 557 | } |
Eric Christopher | 6764643 | 2013-07-26 17:02:41 +0000 | [diff] [blame] | 558 | } |
| 559 | |
| 560 | /// SizeOf - Determine size of delta value in bytes. |
| 561 | /// |
Duncan P. N. Exon Smith | e7e1d0c | 2015-05-27 22:14:58 +0000 | [diff] [blame] | 562 | unsigned DIEString::SizeOf(const AsmPrinter *AP, dwarf::Form Form) const { |
Duncan P. N. Exon Smith | f73bcf4 | 2015-05-24 16:40:47 +0000 | [diff] [blame] | 563 | // Index of string in symbol table. |
Wolfgang Pieb | 456b555 | 2018-01-26 18:52:58 +0000 | [diff] [blame] | 564 | switch (Form) { |
| 565 | case dwarf::DW_FORM_GNU_str_index: |
| 566 | case dwarf::DW_FORM_strx: |
| 567 | case dwarf::DW_FORM_strx1: |
| 568 | case dwarf::DW_FORM_strx2: |
| 569 | case dwarf::DW_FORM_strx3: |
| 570 | case dwarf::DW_FORM_strx4: |
Duncan P. N. Exon Smith | f73bcf4 | 2015-05-24 16:40:47 +0000 | [diff] [blame] | 571 | return DIEInteger(S.getIndex()).SizeOf(AP, Form); |
Wolfgang Pieb | 456b555 | 2018-01-26 18:52:58 +0000 | [diff] [blame] | 572 | case dwarf::DW_FORM_strp: |
| 573 | if (AP->MAI->doesDwarfUseRelocationsAcrossSections()) |
| 574 | return DIELabel(S.getSymbol()).SizeOf(AP, Form); |
| 575 | return DIEInteger(S.getOffset()).SizeOf(AP, Form); |
| 576 | default: |
| 577 | llvm_unreachable("Expected valid string form"); |
| 578 | } |
Eric Christopher | 6764643 | 2013-07-26 17:02:41 +0000 | [diff] [blame] | 579 | } |
| 580 | |
Davide Italiano | c304a0d | 2015-11-24 02:21:43 +0000 | [diff] [blame] | 581 | LLVM_DUMP_METHOD |
Duncan P. N. Exon Smith | e7e1d0c | 2015-05-27 22:14:58 +0000 | [diff] [blame] | 582 | void DIEString::print(raw_ostream &O) const { |
Duncan P. N. Exon Smith | f73bcf4 | 2015-05-24 16:40:47 +0000 | [diff] [blame] | 583 | O << "String: " << S.getString(); |
Eric Christopher | 6764643 | 2013-07-26 17:02:41 +0000 | [diff] [blame] | 584 | } |
Eric Christopher | 6764643 | 2013-07-26 17:02:41 +0000 | [diff] [blame] | 585 | |
| 586 | //===----------------------------------------------------------------------===// |
Greg Clayton | 3462a42 | 2016-12-08 01:03:48 +0000 | [diff] [blame] | 587 | // DIEInlineString Implementation |
| 588 | //===----------------------------------------------------------------------===// |
| 589 | void DIEInlineString::EmitValue(const AsmPrinter *AP, dwarf::Form Form) const { |
| 590 | if (Form == dwarf::DW_FORM_string) { |
Alexey Bataev | c15c853 | 2018-10-24 14:04:00 +0000 | [diff] [blame] | 591 | AP->OutStreamer->EmitBytes(S); |
Rafael Espindola | 4b4d85f | 2018-03-29 23:32:54 +0000 | [diff] [blame] | 592 | AP->emitInt8(0); |
Greg Clayton | 3462a42 | 2016-12-08 01:03:48 +0000 | [diff] [blame] | 593 | return; |
| 594 | } |
| 595 | llvm_unreachable("Expected valid string form"); |
| 596 | } |
| 597 | |
| 598 | unsigned DIEInlineString::SizeOf(const AsmPrinter *AP, dwarf::Form Form) const { |
| 599 | // Emit string bytes + NULL byte. |
| 600 | return S.size() + 1; |
| 601 | } |
| 602 | |
| 603 | LLVM_DUMP_METHOD |
| 604 | void DIEInlineString::print(raw_ostream &O) const { |
Benjamin Kramer | eedc405 | 2016-12-09 13:33:41 +0000 | [diff] [blame] | 605 | O << "InlineString: " << S; |
Greg Clayton | 3462a42 | 2016-12-08 01:03:48 +0000 | [diff] [blame] | 606 | } |
| 607 | |
| 608 | //===----------------------------------------------------------------------===// |
Bill Wendling | 47054f3 | 2009-05-15 00:11:17 +0000 | [diff] [blame] | 609 | // DIEEntry Implementation |
| 610 | //===----------------------------------------------------------------------===// |
| 611 | |
| 612 | /// EmitValue - Emit debug information entry offset. |
| 613 | /// |
Duncan P. N. Exon Smith | e7e1d0c | 2015-05-27 22:14:58 +0000 | [diff] [blame] | 614 | void DIEEntry::EmitValue(const AsmPrinter *AP, dwarf::Form Form) const { |
Eric Christopher | dd50838 | 2014-03-06 00:00:56 +0000 | [diff] [blame] | 615 | |
Greg Clayton | 3462a42 | 2016-12-08 01:03:48 +0000 | [diff] [blame] | 616 | switch (Form) { |
| 617 | case dwarf::DW_FORM_ref1: |
| 618 | case dwarf::DW_FORM_ref2: |
| 619 | case dwarf::DW_FORM_ref4: |
| 620 | case dwarf::DW_FORM_ref8: |
| 621 | AP->OutStreamer->EmitIntValue(Entry->getOffset(), SizeOf(AP, Form)); |
| 622 | return; |
| 623 | |
| 624 | case dwarf::DW_FORM_ref_udata: |
| 625 | AP->EmitULEB128(Entry->getOffset()); |
| 626 | return; |
| 627 | |
| 628 | case dwarf::DW_FORM_ref_addr: { |
Greg Clayton | 35630c3 | 2016-12-01 18:56:29 +0000 | [diff] [blame] | 629 | // Get the absolute offset for this DIE within the debug info/types section. |
| 630 | unsigned Addr = Entry->getDebugSectionOffset(); |
David Blaikie | 85366ac | 2017-04-22 07:53:44 +0000 | [diff] [blame] | 631 | if (const MCSymbol *SectionSym = |
| 632 | Entry->getUnit()->getCrossSectionRelativeBaseAddress()) { |
| 633 | AP->EmitLabelPlusOffset(SectionSym, Addr, SizeOf(AP, Form), true); |
| 634 | return; |
Greg Clayton | 3462a42 | 2016-12-08 01:03:48 +0000 | [diff] [blame] | 635 | } |
David Blaikie | 85366ac | 2017-04-22 07:53:44 +0000 | [diff] [blame] | 636 | |
Greg Clayton | 3462a42 | 2016-12-08 01:03:48 +0000 | [diff] [blame] | 637 | AP->OutStreamer->EmitIntValue(Addr, SizeOf(AP, Form)); |
| 638 | return; |
| 639 | } |
| 640 | default: |
| 641 | llvm_unreachable("Improper form for DIE reference"); |
| 642 | } |
Bill Wendling | 47054f3 | 2009-05-15 00:11:17 +0000 | [diff] [blame] | 643 | } |
| 644 | |
Greg Clayton | 3462a42 | 2016-12-08 01:03:48 +0000 | [diff] [blame] | 645 | unsigned DIEEntry::SizeOf(const AsmPrinter *AP, dwarf::Form Form) const { |
| 646 | switch (Form) { |
| 647 | case dwarf::DW_FORM_ref1: |
| 648 | return 1; |
| 649 | case dwarf::DW_FORM_ref2: |
| 650 | return 2; |
| 651 | case dwarf::DW_FORM_ref4: |
| 652 | return 4; |
| 653 | case dwarf::DW_FORM_ref8: |
| 654 | return 8; |
| 655 | case dwarf::DW_FORM_ref_udata: |
| 656 | return getULEB128Size(Entry->getOffset()); |
| 657 | case dwarf::DW_FORM_ref_addr: |
| 658 | if (AP->getDwarfVersion() == 2) |
Konstantin Zhuravlyov | dc77b2e | 2017-04-17 17:41:25 +0000 | [diff] [blame] | 659 | return AP->MAI->getCodePointerSize(); |
Greg Clayton | 3462a42 | 2016-12-08 01:03:48 +0000 | [diff] [blame] | 660 | switch (AP->OutStreamer->getContext().getDwarfFormat()) { |
| 661 | case dwarf::DWARF32: |
| 662 | return 4; |
| 663 | case dwarf::DWARF64: |
| 664 | return 8; |
| 665 | } |
| 666 | llvm_unreachable("Invalid DWARF format"); |
| 667 | |
| 668 | default: |
| 669 | llvm_unreachable("Improper form for DIE reference"); |
| 670 | } |
Manman Ren | ac8062b | 2013-07-02 23:40:10 +0000 | [diff] [blame] | 671 | } |
| 672 | |
Davide Italiano | c304a0d | 2015-11-24 02:21:43 +0000 | [diff] [blame] | 673 | LLVM_DUMP_METHOD |
Duncan P. N. Exon Smith | e7e1d0c | 2015-05-27 22:14:58 +0000 | [diff] [blame] | 674 | void DIEEntry::print(raw_ostream &O) const { |
David Blaikie | 8dbcc3f | 2014-04-25 19:33:43 +0000 | [diff] [blame] | 675 | O << format("Die: 0x%lx", (long)(intptr_t)&Entry); |
Bill Wendling | 47054f3 | 2009-05-15 00:11:17 +0000 | [diff] [blame] | 676 | } |
Bill Wendling | 47054f3 | 2009-05-15 00:11:17 +0000 | [diff] [blame] | 677 | |
| 678 | //===----------------------------------------------------------------------===// |
Eric Christopher | 4a74104 | 2014-02-16 08:46:55 +0000 | [diff] [blame] | 679 | // DIELoc Implementation |
| 680 | //===----------------------------------------------------------------------===// |
| 681 | |
| 682 | /// ComputeSize - calculate the size of the location expression. |
| 683 | /// |
Frederic Riss | cd04434 | 2015-03-04 02:30:08 +0000 | [diff] [blame] | 684 | unsigned DIELoc::ComputeSize(const AsmPrinter *AP) const { |
Eric Christopher | 8bdab43 | 2014-02-27 18:36:10 +0000 | [diff] [blame] | 685 | if (!Size) { |
Duncan P. N. Exon Smith | 1ad5ebc | 2015-08-02 20:42:45 +0000 | [diff] [blame] | 686 | for (const auto &V : values()) |
Duncan P. N. Exon Smith | 9dbb501 | 2015-06-24 18:48:11 +0000 | [diff] [blame] | 687 | Size += V.SizeOf(AP); |
Eric Christopher | 8bdab43 | 2014-02-27 18:36:10 +0000 | [diff] [blame] | 688 | } |
Eric Christopher | 4a74104 | 2014-02-16 08:46:55 +0000 | [diff] [blame] | 689 | |
Eric Christopher | 8bdab43 | 2014-02-27 18:36:10 +0000 | [diff] [blame] | 690 | return Size; |
Eric Christopher | 4a74104 | 2014-02-16 08:46:55 +0000 | [diff] [blame] | 691 | } |
| 692 | |
| 693 | /// EmitValue - Emit location data. |
| 694 | /// |
Duncan P. N. Exon Smith | e7e1d0c | 2015-05-27 22:14:58 +0000 | [diff] [blame] | 695 | void DIELoc::EmitValue(const AsmPrinter *Asm, dwarf::Form Form) const { |
Eric Christopher | 4a74104 | 2014-02-16 08:46:55 +0000 | [diff] [blame] | 696 | switch (Form) { |
| 697 | default: llvm_unreachable("Improper form for block"); |
Rafael Espindola | 4b4d85f | 2018-03-29 23:32:54 +0000 | [diff] [blame] | 698 | case dwarf::DW_FORM_block1: Asm->emitInt8(Size); break; |
| 699 | case dwarf::DW_FORM_block2: Asm->emitInt16(Size); break; |
| 700 | case dwarf::DW_FORM_block4: Asm->emitInt32(Size); break; |
Eric Christopher | 4a74104 | 2014-02-16 08:46:55 +0000 | [diff] [blame] | 701 | case dwarf::DW_FORM_block: |
| 702 | case dwarf::DW_FORM_exprloc: |
| 703 | Asm->EmitULEB128(Size); break; |
| 704 | } |
| 705 | |
Duncan P. N. Exon Smith | 1ad5ebc | 2015-08-02 20:42:45 +0000 | [diff] [blame] | 706 | for (const auto &V : values()) |
Duncan P. N. Exon Smith | 9dbb501 | 2015-06-24 18:48:11 +0000 | [diff] [blame] | 707 | V.EmitValue(Asm); |
Eric Christopher | 4a74104 | 2014-02-16 08:46:55 +0000 | [diff] [blame] | 708 | } |
| 709 | |
| 710 | /// SizeOf - Determine size of location data in bytes. |
| 711 | /// |
Duncan P. N. Exon Smith | e7e1d0c | 2015-05-27 22:14:58 +0000 | [diff] [blame] | 712 | unsigned DIELoc::SizeOf(const AsmPrinter *AP, dwarf::Form Form) const { |
Eric Christopher | 4a74104 | 2014-02-16 08:46:55 +0000 | [diff] [blame] | 713 | switch (Form) { |
| 714 | case dwarf::DW_FORM_block1: return Size + sizeof(int8_t); |
| 715 | case dwarf::DW_FORM_block2: return Size + sizeof(int16_t); |
| 716 | case dwarf::DW_FORM_block4: return Size + sizeof(int32_t); |
| 717 | case dwarf::DW_FORM_block: |
| 718 | case dwarf::DW_FORM_exprloc: |
Logan Chien | 5b776b7 | 2014-02-22 14:00:39 +0000 | [diff] [blame] | 719 | return Size + getULEB128Size(Size); |
Eric Christopher | 4a74104 | 2014-02-16 08:46:55 +0000 | [diff] [blame] | 720 | default: llvm_unreachable("Improper form for block"); |
| 721 | } |
| 722 | } |
| 723 | |
Davide Italiano | c304a0d | 2015-11-24 02:21:43 +0000 | [diff] [blame] | 724 | LLVM_DUMP_METHOD |
Duncan P. N. Exon Smith | e7e1d0c | 2015-05-27 22:14:58 +0000 | [diff] [blame] | 725 | void DIELoc::print(raw_ostream &O) const { |
Duncan P. N. Exon Smith | c582114 | 2015-08-02 20:46:49 +0000 | [diff] [blame] | 726 | printValues(O, *this, "ExprLoc", Size, 5); |
Eric Christopher | 4a74104 | 2014-02-16 08:46:55 +0000 | [diff] [blame] | 727 | } |
Eric Christopher | 4a74104 | 2014-02-16 08:46:55 +0000 | [diff] [blame] | 728 | |
| 729 | //===----------------------------------------------------------------------===// |
Bill Wendling | 47054f3 | 2009-05-15 00:11:17 +0000 | [diff] [blame] | 730 | // DIEBlock Implementation |
| 731 | //===----------------------------------------------------------------------===// |
| 732 | |
| 733 | /// ComputeSize - calculate the size of the block. |
| 734 | /// |
Frederic Riss | cd04434 | 2015-03-04 02:30:08 +0000 | [diff] [blame] | 735 | unsigned DIEBlock::ComputeSize(const AsmPrinter *AP) const { |
Eric Christopher | 8bdab43 | 2014-02-27 18:36:10 +0000 | [diff] [blame] | 736 | if (!Size) { |
Duncan P. N. Exon Smith | 1ad5ebc | 2015-08-02 20:42:45 +0000 | [diff] [blame] | 737 | for (const auto &V : values()) |
Duncan P. N. Exon Smith | 9dbb501 | 2015-06-24 18:48:11 +0000 | [diff] [blame] | 738 | Size += V.SizeOf(AP); |
Eric Christopher | 8bdab43 | 2014-02-27 18:36:10 +0000 | [diff] [blame] | 739 | } |
Bill Wendling | 47054f3 | 2009-05-15 00:11:17 +0000 | [diff] [blame] | 740 | |
Eric Christopher | 8bdab43 | 2014-02-27 18:36:10 +0000 | [diff] [blame] | 741 | return Size; |
Bill Wendling | 47054f3 | 2009-05-15 00:11:17 +0000 | [diff] [blame] | 742 | } |
| 743 | |
| 744 | /// EmitValue - Emit block data. |
| 745 | /// |
Duncan P. N. Exon Smith | e7e1d0c | 2015-05-27 22:14:58 +0000 | [diff] [blame] | 746 | void DIEBlock::EmitValue(const AsmPrinter *Asm, dwarf::Form Form) const { |
Bill Wendling | 47054f3 | 2009-05-15 00:11:17 +0000 | [diff] [blame] | 747 | switch (Form) { |
Craig Topper | ee4dab5 | 2012-02-05 08:31:47 +0000 | [diff] [blame] | 748 | default: llvm_unreachable("Improper form for block"); |
Rafael Espindola | 4b4d85f | 2018-03-29 23:32:54 +0000 | [diff] [blame] | 749 | case dwarf::DW_FORM_block1: Asm->emitInt8(Size); break; |
| 750 | case dwarf::DW_FORM_block2: Asm->emitInt16(Size); break; |
| 751 | case dwarf::DW_FORM_block4: Asm->emitInt32(Size); break; |
Chris Lattner | 9efd118 | 2010-04-04 19:09:29 +0000 | [diff] [blame] | 752 | case dwarf::DW_FORM_block: Asm->EmitULEB128(Size); break; |
Jonas Devlieghere | 9e3e7a9 | 2018-04-02 10:40:43 +0000 | [diff] [blame] | 753 | case dwarf::DW_FORM_string: break; |
Paul Robinson | a06f8dc | 2017-12-18 19:08:35 +0000 | [diff] [blame] | 754 | case dwarf::DW_FORM_data16: break; |
Bill Wendling | 47054f3 | 2009-05-15 00:11:17 +0000 | [diff] [blame] | 755 | } |
| 756 | |
Duncan P. N. Exon Smith | 1ad5ebc | 2015-08-02 20:42:45 +0000 | [diff] [blame] | 757 | for (const auto &V : values()) |
Duncan P. N. Exon Smith | 9dbb501 | 2015-06-24 18:48:11 +0000 | [diff] [blame] | 758 | V.EmitValue(Asm); |
Bill Wendling | 47054f3 | 2009-05-15 00:11:17 +0000 | [diff] [blame] | 759 | } |
| 760 | |
| 761 | /// SizeOf - Determine size of block data in bytes. |
| 762 | /// |
Duncan P. N. Exon Smith | e7e1d0c | 2015-05-27 22:14:58 +0000 | [diff] [blame] | 763 | unsigned DIEBlock::SizeOf(const AsmPrinter *AP, dwarf::Form Form) const { |
Bill Wendling | 47054f3 | 2009-05-15 00:11:17 +0000 | [diff] [blame] | 764 | switch (Form) { |
| 765 | case dwarf::DW_FORM_block1: return Size + sizeof(int8_t); |
| 766 | case dwarf::DW_FORM_block2: return Size + sizeof(int16_t); |
| 767 | case dwarf::DW_FORM_block4: return Size + sizeof(int32_t); |
Logan Chien | 5b776b7 | 2014-02-22 14:00:39 +0000 | [diff] [blame] | 768 | case dwarf::DW_FORM_block: return Size + getULEB128Size(Size); |
Paul Robinson | a06f8dc | 2017-12-18 19:08:35 +0000 | [diff] [blame] | 769 | case dwarf::DW_FORM_data16: return 16; |
David Blaikie | 46a9f01 | 2012-01-20 21:51:11 +0000 | [diff] [blame] | 770 | default: llvm_unreachable("Improper form for block"); |
Bill Wendling | 47054f3 | 2009-05-15 00:11:17 +0000 | [diff] [blame] | 771 | } |
Bill Wendling | 47054f3 | 2009-05-15 00:11:17 +0000 | [diff] [blame] | 772 | } |
| 773 | |
Davide Italiano | c304a0d | 2015-11-24 02:21:43 +0000 | [diff] [blame] | 774 | LLVM_DUMP_METHOD |
Duncan P. N. Exon Smith | e7e1d0c | 2015-05-27 22:14:58 +0000 | [diff] [blame] | 775 | void DIEBlock::print(raw_ostream &O) const { |
Duncan P. N. Exon Smith | c582114 | 2015-08-02 20:46:49 +0000 | [diff] [blame] | 776 | printValues(O, *this, "Blk", Size, 5); |
Bill Wendling | 47054f3 | 2009-05-15 00:11:17 +0000 | [diff] [blame] | 777 | } |
Eric Christopher | a27220f | 2014-03-05 22:41:20 +0000 | [diff] [blame] | 778 | |
| 779 | //===----------------------------------------------------------------------===// |
| 780 | // DIELocList Implementation |
| 781 | //===----------------------------------------------------------------------===// |
| 782 | |
Duncan P. N. Exon Smith | e7e1d0c | 2015-05-27 22:14:58 +0000 | [diff] [blame] | 783 | unsigned DIELocList::SizeOf(const AsmPrinter *AP, dwarf::Form Form) const { |
Eric Christopher | a27220f | 2014-03-05 22:41:20 +0000 | [diff] [blame] | 784 | if (Form == dwarf::DW_FORM_data4) |
| 785 | return 4; |
| 786 | if (Form == dwarf::DW_FORM_sec_offset) |
| 787 | return 4; |
Konstantin Zhuravlyov | dc77b2e | 2017-04-17 17:41:25 +0000 | [diff] [blame] | 788 | return AP->MAI->getCodePointerSize(); |
Eric Christopher | a27220f | 2014-03-05 22:41:20 +0000 | [diff] [blame] | 789 | } |
| 790 | |
| 791 | /// EmitValue - Emit label value. |
| 792 | /// |
Duncan P. N. Exon Smith | e7e1d0c | 2015-05-27 22:14:58 +0000 | [diff] [blame] | 793 | void DIELocList::EmitValue(const AsmPrinter *AP, dwarf::Form Form) const { |
David Blaikie | 9c550ac | 2014-03-25 01:44:02 +0000 | [diff] [blame] | 794 | DwarfDebug *DD = AP->getDwarfDebug(); |
Duncan P. N. Exon Smith | 364a300 | 2015-04-17 21:34:47 +0000 | [diff] [blame] | 795 | MCSymbol *Label = DD->getDebugLocs().getList(Index).Label; |
Rafael Espindola | 857546e | 2015-06-16 23:22:02 +0000 | [diff] [blame] | 796 | AP->emitDwarfSymbolReference(Label, /*ForceOffset*/ DD->useSplitDwarf()); |
Eric Christopher | a27220f | 2014-03-05 22:41:20 +0000 | [diff] [blame] | 797 | } |
| 798 | |
Davide Italiano | c304a0d | 2015-11-24 02:21:43 +0000 | [diff] [blame] | 799 | LLVM_DUMP_METHOD |
Duncan P. N. Exon Smith | e7e1d0c | 2015-05-27 22:14:58 +0000 | [diff] [blame] | 800 | void DIELocList::print(raw_ostream &O) const { O << "LocList: " << Index; } |