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