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