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