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