Chris Lattner | 9efd118 | 2010-04-04 19:09:29 +0000 | [diff] [blame] | 1 | //===-- AsmPrinterDwarf.cpp - AsmPrinter Dwarf Support --------------------===// |
| 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 | // This file implements the Dwarf emissions parts of AsmPrinter. |
| 11 | // |
| 12 | //===----------------------------------------------------------------------===// |
| 13 | |
Eric Christopher | 29e874d | 2014-03-07 22:40:37 +0000 | [diff] [blame] | 14 | #include "ByteStreamer.h" |
Chandler Carruth | ed0881b | 2012-12-03 16:50:05 +0000 | [diff] [blame] | 15 | #include "llvm/ADT/Twine.h" |
Zachary Turner | 264b5d9 | 2017-06-07 03:48:56 +0000 | [diff] [blame] | 16 | #include "llvm/BinaryFormat/Dwarf.h" |
Chandler Carruth | d990388 | 2015-01-14 11:23:27 +0000 | [diff] [blame] | 17 | #include "llvm/CodeGen/AsmPrinter.h" |
Frederic Riss | 9412d63 | 2015-03-04 02:30:17 +0000 | [diff] [blame] | 18 | #include "llvm/CodeGen/DIE.h" |
Adrian Prantl | b846acc | 2015-03-02 22:02:36 +0000 | [diff] [blame] | 19 | #include "llvm/CodeGen/MachineFunction.h" |
Chandler Carruth | 9fb823b | 2013-01-02 11:36:10 +0000 | [diff] [blame] | 20 | #include "llvm/IR/DataLayout.h" |
Chris Lattner | 9efd118 | 2010-04-04 19:09:29 +0000 | [diff] [blame] | 21 | #include "llvm/MC/MCAsmInfo.h" |
Eric Christopher | 7330264 | 2015-02-19 23:29:42 +0000 | [diff] [blame] | 22 | #include "llvm/MC/MCRegisterInfo.h" |
Chris Lattner | 70a4fce | 2010-04-04 23:25:33 +0000 | [diff] [blame] | 23 | #include "llvm/MC/MCSection.h" |
Chris Lattner | 9efd118 | 2010-04-04 19:09:29 +0000 | [diff] [blame] | 24 | #include "llvm/MC/MCStreamer.h" |
Chris Lattner | 70a4fce | 2010-04-04 23:25:33 +0000 | [diff] [blame] | 25 | #include "llvm/MC/MCSymbol.h" |
Chandler Carruth | ed0881b | 2012-12-03 16:50:05 +0000 | [diff] [blame] | 26 | #include "llvm/MC/MachineLocation.h" |
Chandler Carruth | ed0881b | 2012-12-03 16:50:05 +0000 | [diff] [blame] | 27 | #include "llvm/Support/ErrorHandling.h" |
David Blaikie | 6054e65 | 2018-03-23 23:58:19 +0000 | [diff] [blame] | 28 | #include "llvm/Target/TargetLoweringObjectFile.h" |
Chris Lattner | e619c0d | 2010-04-04 20:20:50 +0000 | [diff] [blame] | 29 | #include "llvm/Target/TargetMachine.h" |
Chris Lattner | 9efd118 | 2010-04-04 19:09:29 +0000 | [diff] [blame] | 30 | using namespace llvm; |
| 31 | |
Chandler Carruth | 1b9dde0 | 2014-04-22 02:02:50 +0000 | [diff] [blame] | 32 | #define DEBUG_TYPE "asm-printer" |
| 33 | |
Chris Lattner | aabc604 | 2010-04-04 23:41:46 +0000 | [diff] [blame] | 34 | //===----------------------------------------------------------------------===// |
| 35 | // Dwarf Emission Helper Routines |
| 36 | //===----------------------------------------------------------------------===// |
| 37 | |
Chris Lattner | 9efd118 | 2010-04-04 19:09:29 +0000 | [diff] [blame] | 38 | /// EmitSLEB128 - emit the specified signed leb128 value. |
David Blaikie | 5acff7e | 2013-06-23 18:31:11 +0000 | [diff] [blame] | 39 | void AsmPrinter::EmitSLEB128(int64_t Value, const char *Desc) const { |
Chris Lattner | 9efd118 | 2010-04-04 19:09:29 +0000 | [diff] [blame] | 40 | if (isVerbose() && Desc) |
Lang Hames | 9ff69c8 | 2015-04-24 19:11:51 +0000 | [diff] [blame] | 41 | OutStreamer->AddComment(Desc); |
Chris Lattner | 9efd118 | 2010-04-04 19:09:29 +0000 | [diff] [blame] | 42 | |
Lang Hames | 9ff69c8 | 2015-04-24 19:11:51 +0000 | [diff] [blame] | 43 | OutStreamer->EmitSLEB128IntValue(Value); |
Chris Lattner | 9efd118 | 2010-04-04 19:09:29 +0000 | [diff] [blame] | 44 | } |
| 45 | |
Sam Clegg | 66a99e4 | 2017-09-15 20:34:47 +0000 | [diff] [blame] | 46 | void AsmPrinter::EmitULEB128(uint64_t Value, const char *Desc) const { |
| 47 | if (isVerbose() && Desc) |
| 48 | OutStreamer->AddComment(Desc); |
| 49 | |
| 50 | OutStreamer->EmitULEB128IntValue(Value); |
Chris Lattner | 9efd118 | 2010-04-04 19:09:29 +0000 | [diff] [blame] | 51 | } |
| 52 | |
Rafael Espindola | d09b416 | 2018-02-09 17:00:25 +0000 | [diff] [blame] | 53 | /// Emit something like ".uleb128 Hi-Lo". |
| 54 | void AsmPrinter::EmitLabelDifferenceAsULEB128(const MCSymbol *Hi, |
| 55 | const MCSymbol *Lo) const { |
| 56 | OutStreamer->emitAbsoluteSymbolDiffAsULEB128(Hi, Lo); |
| 57 | } |
| 58 | |
Chris Lattner | b75af3c | 2010-04-04 20:04:21 +0000 | [diff] [blame] | 59 | static const char *DecodeDWARFEncoding(unsigned Encoding) { |
| 60 | switch (Encoding) { |
Eric Christopher | 596077b | 2013-12-04 22:26:43 +0000 | [diff] [blame] | 61 | case dwarf::DW_EH_PE_absptr: |
| 62 | return "absptr"; |
| 63 | case dwarf::DW_EH_PE_omit: |
| 64 | return "omit"; |
| 65 | case dwarf::DW_EH_PE_pcrel: |
| 66 | return "pcrel"; |
Rafael Espindola | d09b416 | 2018-02-09 17:00:25 +0000 | [diff] [blame] | 67 | case dwarf::DW_EH_PE_uleb128: |
| 68 | return "uleb128"; |
| 69 | case dwarf::DW_EH_PE_sleb128: |
| 70 | return "sleb128"; |
Eric Christopher | 596077b | 2013-12-04 22:26:43 +0000 | [diff] [blame] | 71 | case dwarf::DW_EH_PE_udata4: |
| 72 | return "udata4"; |
| 73 | case dwarf::DW_EH_PE_udata8: |
| 74 | return "udata8"; |
| 75 | case dwarf::DW_EH_PE_sdata4: |
| 76 | return "sdata4"; |
| 77 | case dwarf::DW_EH_PE_sdata8: |
| 78 | return "sdata8"; |
| 79 | case dwarf::DW_EH_PE_pcrel | dwarf::DW_EH_PE_udata4: |
| 80 | return "pcrel udata4"; |
| 81 | case dwarf::DW_EH_PE_pcrel | dwarf::DW_EH_PE_sdata4: |
| 82 | return "pcrel sdata4"; |
| 83 | case dwarf::DW_EH_PE_pcrel | dwarf::DW_EH_PE_udata8: |
| 84 | return "pcrel udata8"; |
| 85 | case dwarf::DW_EH_PE_pcrel | dwarf::DW_EH_PE_sdata8: |
| 86 | return "pcrel sdata8"; |
| 87 | case dwarf::DW_EH_PE_indirect | dwarf::DW_EH_PE_pcrel | dwarf::DW_EH_PE_udata4 |
| 88 | : |
Chris Lattner | b75af3c | 2010-04-04 20:04:21 +0000 | [diff] [blame] | 89 | return "indirect pcrel udata4"; |
Eric Christopher | 596077b | 2013-12-04 22:26:43 +0000 | [diff] [blame] | 90 | case dwarf::DW_EH_PE_indirect | dwarf::DW_EH_PE_pcrel | dwarf::DW_EH_PE_sdata4 |
| 91 | : |
Chris Lattner | b75af3c | 2010-04-04 20:04:21 +0000 | [diff] [blame] | 92 | return "indirect pcrel sdata4"; |
Eric Christopher | 596077b | 2013-12-04 22:26:43 +0000 | [diff] [blame] | 93 | case dwarf::DW_EH_PE_indirect | dwarf::DW_EH_PE_pcrel | dwarf::DW_EH_PE_udata8 |
| 94 | : |
Chris Lattner | b75af3c | 2010-04-04 20:04:21 +0000 | [diff] [blame] | 95 | return "indirect pcrel udata8"; |
Eric Christopher | 596077b | 2013-12-04 22:26:43 +0000 | [diff] [blame] | 96 | case dwarf::DW_EH_PE_indirect | dwarf::DW_EH_PE_pcrel | dwarf::DW_EH_PE_sdata8 |
| 97 | : |
Chris Lattner | b75af3c | 2010-04-04 20:04:21 +0000 | [diff] [blame] | 98 | return "indirect pcrel sdata8"; |
| 99 | } |
Eric Christopher | 1d6bd41 | 2012-11-20 20:34:47 +0000 | [diff] [blame] | 100 | |
Chris Lattner | b75af3c | 2010-04-04 20:04:21 +0000 | [diff] [blame] | 101 | return "<unknown encoding>"; |
| 102 | } |
| 103 | |
Chris Lattner | b75af3c | 2010-04-04 20:04:21 +0000 | [diff] [blame] | 104 | /// EmitEncodingByte - Emit a .byte 42 directive that corresponds to an |
| 105 | /// encoding. If verbose assembly output is enabled, we output comments |
| 106 | /// describing the encoding. Desc is an optional string saying what the |
| 107 | /// encoding is specifying (e.g. "LSDA"). |
Chris Lattner | aabc604 | 2010-04-04 23:41:46 +0000 | [diff] [blame] | 108 | void AsmPrinter::EmitEncodingByte(unsigned Val, const char *Desc) const { |
Chris Lattner | b75af3c | 2010-04-04 20:04:21 +0000 | [diff] [blame] | 109 | if (isVerbose()) { |
Eric Christopher | cb7119e | 2013-12-04 22:29:02 +0000 | [diff] [blame] | 110 | if (Desc) |
Lang Hames | 9ff69c8 | 2015-04-24 19:11:51 +0000 | [diff] [blame] | 111 | OutStreamer->AddComment(Twine(Desc) + " Encoding = " + |
| 112 | Twine(DecodeDWARFEncoding(Val))); |
Chris Lattner | b75af3c | 2010-04-04 20:04:21 +0000 | [diff] [blame] | 113 | else |
Lang Hames | 9ff69c8 | 2015-04-24 19:11:51 +0000 | [diff] [blame] | 114 | OutStreamer->AddComment(Twine("Encoding = ") + DecodeDWARFEncoding(Val)); |
Chris Lattner | b75af3c | 2010-04-04 20:04:21 +0000 | [diff] [blame] | 115 | } |
Eric Christopher | 1d6bd41 | 2012-11-20 20:34:47 +0000 | [diff] [blame] | 116 | |
Lang Hames | 9ff69c8 | 2015-04-24 19:11:51 +0000 | [diff] [blame] | 117 | OutStreamer->EmitIntValue(Val, 1); |
Chris Lattner | b75af3c | 2010-04-04 20:04:21 +0000 | [diff] [blame] | 118 | } |
| 119 | |
Chris Lattner | e619c0d | 2010-04-04 20:20:50 +0000 | [diff] [blame] | 120 | /// GetSizeOfEncodedValue - Return the size of the encoding in bytes. |
| 121 | unsigned AsmPrinter::GetSizeOfEncodedValue(unsigned Encoding) const { |
| 122 | if (Encoding == dwarf::DW_EH_PE_omit) |
| 123 | return 0; |
Eric Christopher | 1d6bd41 | 2012-11-20 20:34:47 +0000 | [diff] [blame] | 124 | |
Chris Lattner | e619c0d | 2010-04-04 20:20:50 +0000 | [diff] [blame] | 125 | switch (Encoding & 0x07) { |
Eric Christopher | 596077b | 2013-12-04 22:26:43 +0000 | [diff] [blame] | 126 | default: |
| 127 | llvm_unreachable("Invalid encoded value."); |
| 128 | case dwarf::DW_EH_PE_absptr: |
Mehdi Amini | bd7287e | 2015-07-16 06:11:10 +0000 | [diff] [blame] | 129 | return MF->getDataLayout().getPointerSize(); |
Eric Christopher | 596077b | 2013-12-04 22:26:43 +0000 | [diff] [blame] | 130 | case dwarf::DW_EH_PE_udata2: |
| 131 | return 2; |
| 132 | case dwarf::DW_EH_PE_udata4: |
| 133 | return 4; |
| 134 | case dwarf::DW_EH_PE_udata8: |
| 135 | return 8; |
Chris Lattner | e619c0d | 2010-04-04 20:20:50 +0000 | [diff] [blame] | 136 | } |
| 137 | } |
| 138 | |
Eric Christopher | 1d6bd41 | 2012-11-20 20:34:47 +0000 | [diff] [blame] | 139 | void AsmPrinter::EmitTTypeReference(const GlobalValue *GV, |
| 140 | unsigned Encoding) const { |
Anton Korobeynikov | 097b0e9 | 2012-11-19 21:17:20 +0000 | [diff] [blame] | 141 | if (GV) { |
| 142 | const TargetLoweringObjectFile &TLOF = getObjFileLowering(); |
Eric Christopher | 1d6bd41 | 2012-11-20 20:34:47 +0000 | [diff] [blame] | 143 | |
Anton Korobeynikov | 097b0e9 | 2012-11-19 21:17:20 +0000 | [diff] [blame] | 144 | const MCExpr *Exp = |
Eric Christopher | 4367c7f | 2016-09-16 07:33:15 +0000 | [diff] [blame] | 145 | TLOF.getTTypeGlobalReference(GV, Encoding, TM, MMI, *OutStreamer); |
Lang Hames | 9ff69c8 | 2015-04-24 19:11:51 +0000 | [diff] [blame] | 146 | OutStreamer->EmitValue(Exp, GetSizeOfEncodedValue(Encoding)); |
Anton Korobeynikov | 097b0e9 | 2012-11-19 21:17:20 +0000 | [diff] [blame] | 147 | } else |
Lang Hames | 9ff69c8 | 2015-04-24 19:11:51 +0000 | [diff] [blame] | 148 | OutStreamer->EmitIntValue(0, GetSizeOfEncodedValue(Encoding)); |
Chris Lattner | e619c0d | 2010-04-04 20:20:50 +0000 | [diff] [blame] | 149 | } |
Chris Lattner | 70a4fce | 2010-04-04 23:25:33 +0000 | [diff] [blame] | 150 | |
Rafael Espindola | 857546e | 2015-06-16 23:22:02 +0000 | [diff] [blame] | 151 | void AsmPrinter::emitDwarfSymbolReference(const MCSymbol *Label, |
| 152 | bool ForceOffset) const { |
| 153 | if (!ForceOffset) { |
| 154 | // On COFF targets, we have to emit the special .secrel32 directive. |
| 155 | if (MAI->needsDwarfSectionOffsetDirective()) { |
Keno Fischer | f7d84ee | 2017-01-02 03:00:19 +0000 | [diff] [blame] | 156 | OutStreamer->EmitCOFFSecRel32(Label, /*Offset=*/0); |
Rafael Espindola | 857546e | 2015-06-16 23:22:02 +0000 | [diff] [blame] | 157 | return; |
| 158 | } |
Eric Christopher | 1d6bd41 | 2012-11-20 20:34:47 +0000 | [diff] [blame] | 159 | |
Rafael Espindola | 857546e | 2015-06-16 23:22:02 +0000 | [diff] [blame] | 160 | // If the format uses relocations with dwarf, refer to the symbol directly. |
| 161 | if (MAI->doesDwarfUseRelocationsAcrossSections()) { |
| 162 | OutStreamer->EmitSymbolValue(Label, 4); |
| 163 | return; |
| 164 | } |
Duncan Sands | b847bf5 | 2011-03-12 13:07:37 +0000 | [diff] [blame] | 165 | } |
Eric Christopher | 1d6bd41 | 2012-11-20 20:34:47 +0000 | [diff] [blame] | 166 | |
Chris Lattner | 70a4fce | 2010-04-04 23:25:33 +0000 | [diff] [blame] | 167 | // Otherwise, emit it as a label difference from the start of the section. |
Rafael Espindola | 063d725 | 2015-03-10 16:58:10 +0000 | [diff] [blame] | 168 | EmitLabelDifference(Label, Label->getSection().getBeginSymbol(), 4); |
Chris Lattner | 70a4fce | 2010-04-04 23:25:33 +0000 | [diff] [blame] | 169 | } |
| 170 | |
Wolfgang Pieb | 20a7453 | 2018-01-11 02:35:00 +0000 | [diff] [blame] | 171 | void AsmPrinter::emitDwarfStringOffset(DwarfStringPoolEntry S) const { |
Duncan P. N. Exon Smith | 1e0d94e | 2015-05-24 16:48:54 +0000 | [diff] [blame] | 172 | if (MAI->doesDwarfUseRelocationsAcrossSections()) { |
Wolfgang Pieb | 20a7453 | 2018-01-11 02:35:00 +0000 | [diff] [blame] | 173 | assert(S.Symbol && "No symbol available"); |
| 174 | emitDwarfSymbolReference(S.Symbol); |
Duncan P. N. Exon Smith | 1e0d94e | 2015-05-24 16:48:54 +0000 | [diff] [blame] | 175 | return; |
| 176 | } |
| 177 | |
| 178 | // Just emit the offset directly; no need for symbol math. |
Rafael Espindola | 4b4d85f | 2018-03-29 23:32:54 +0000 | [diff] [blame] | 179 | emitInt32(S.Offset); |
Duncan P. N. Exon Smith | 1e0d94e | 2015-05-24 16:48:54 +0000 | [diff] [blame] | 180 | } |
| 181 | |
Alexey Bataev | 0725464 | 2018-03-22 16:43:21 +0000 | [diff] [blame] | 182 | void AsmPrinter::EmitDwarfOffset(const MCSymbol *Label, uint64_t Offset) const { |
| 183 | EmitLabelPlusOffset(Label, Offset, MAI->getCodePointerSize()); |
| 184 | } |
| 185 | |
Chris Lattner | aabc604 | 2010-04-04 23:41:46 +0000 | [diff] [blame] | 186 | //===----------------------------------------------------------------------===// |
| 187 | // Dwarf Lowering Routines |
| 188 | //===----------------------------------------------------------------------===// |
Chris Lattner | 70a4fce | 2010-04-04 23:25:33 +0000 | [diff] [blame] | 189 | |
Rafael Espindola | 227144c | 2013-05-13 01:16:13 +0000 | [diff] [blame] | 190 | void AsmPrinter::emitCFIInstruction(const MCCFIInstruction &Inst) const { |
| 191 | switch (Inst.getOperation()) { |
| 192 | default: |
| 193 | llvm_unreachable("Unexpected instruction"); |
| 194 | case MCCFIInstruction::OpDefCfaOffset: |
Lang Hames | 9ff69c8 | 2015-04-24 19:11:51 +0000 | [diff] [blame] | 195 | OutStreamer->EmitCFIDefCfaOffset(Inst.getOffset()); |
Rafael Espindola | 227144c | 2013-05-13 01:16:13 +0000 | [diff] [blame] | 196 | break; |
Michael Kuperstein | 73dc852 | 2015-11-03 08:17:25 +0000 | [diff] [blame] | 197 | case MCCFIInstruction::OpAdjustCfaOffset: |
| 198 | OutStreamer->EmitCFIAdjustCfaOffset(Inst.getOffset()); |
| 199 | break; |
Rafael Espindola | 227144c | 2013-05-13 01:16:13 +0000 | [diff] [blame] | 200 | case MCCFIInstruction::OpDefCfa: |
Lang Hames | 9ff69c8 | 2015-04-24 19:11:51 +0000 | [diff] [blame] | 201 | OutStreamer->EmitCFIDefCfa(Inst.getRegister(), Inst.getOffset()); |
Rafael Espindola | 227144c | 2013-05-13 01:16:13 +0000 | [diff] [blame] | 202 | break; |
| 203 | case MCCFIInstruction::OpDefCfaRegister: |
Lang Hames | 9ff69c8 | 2015-04-24 19:11:51 +0000 | [diff] [blame] | 204 | OutStreamer->EmitCFIDefCfaRegister(Inst.getRegister()); |
Rafael Espindola | 227144c | 2013-05-13 01:16:13 +0000 | [diff] [blame] | 205 | break; |
| 206 | case MCCFIInstruction::OpOffset: |
Lang Hames | 9ff69c8 | 2015-04-24 19:11:51 +0000 | [diff] [blame] | 207 | OutStreamer->EmitCFIOffset(Inst.getRegister(), Inst.getOffset()); |
Rafael Espindola | 227144c | 2013-05-13 01:16:13 +0000 | [diff] [blame] | 208 | break; |
Venkatraman Govindaraju | 4c0cdd7 | 2013-09-26 15:11:00 +0000 | [diff] [blame] | 209 | case MCCFIInstruction::OpRegister: |
Lang Hames | 9ff69c8 | 2015-04-24 19:11:51 +0000 | [diff] [blame] | 210 | OutStreamer->EmitCFIRegister(Inst.getRegister(), Inst.getRegister2()); |
Venkatraman Govindaraju | 4c0cdd7 | 2013-09-26 15:11:00 +0000 | [diff] [blame] | 211 | break; |
Venkatraman Govindaraju | 3816d43 | 2013-09-26 14:49:40 +0000 | [diff] [blame] | 212 | case MCCFIInstruction::OpWindowSave: |
Lang Hames | 9ff69c8 | 2015-04-24 19:11:51 +0000 | [diff] [blame] | 213 | OutStreamer->EmitCFIWindowSave(); |
Venkatraman Govindaraju | 3816d43 | 2013-09-26 14:49:40 +0000 | [diff] [blame] | 214 | break; |
Luke Cheeseman | f57d7d8 | 2018-12-18 10:37:42 +0000 | [diff] [blame] | 215 | case MCCFIInstruction::OpNegateRAState: |
| 216 | OutStreamer->EmitCFINegateRAState(); |
| 217 | break; |
Oliver Stannard | b14c625 | 2014-04-02 16:10:33 +0000 | [diff] [blame] | 218 | case MCCFIInstruction::OpSameValue: |
Lang Hames | 9ff69c8 | 2015-04-24 19:11:51 +0000 | [diff] [blame] | 219 | OutStreamer->EmitCFISameValue(Inst.getRegister()); |
Oliver Stannard | b14c625 | 2014-04-02 16:10:33 +0000 | [diff] [blame] | 220 | break; |
Michael Kuperstein | 259f150 | 2015-10-07 07:01:31 +0000 | [diff] [blame] | 221 | case MCCFIInstruction::OpGnuArgsSize: |
| 222 | OutStreamer->EmitCFIGnuArgsSize(Inst.getOffset()); |
| 223 | break; |
| 224 | case MCCFIInstruction::OpEscape: |
| 225 | OutStreamer->EmitCFIEscape(Inst.getValues()); |
| 226 | break; |
Francis Visoiu Mistrih | 66d2c26 | 2017-11-02 12:00:58 +0000 | [diff] [blame] | 227 | case MCCFIInstruction::OpRestore: |
| 228 | OutStreamer->EmitCFIRestore(Inst.getRegister()); |
| 229 | break; |
Rafael Espindola | beb74c3 | 2011-04-15 20:32:03 +0000 | [diff] [blame] | 230 | } |
| 231 | } |
Frederic Riss | 9412d63 | 2015-03-04 02:30:17 +0000 | [diff] [blame] | 232 | |
| 233 | void AsmPrinter::emitDwarfDIE(const DIE &Die) const { |
Frederic Riss | 9412d63 | 2015-03-04 02:30:17 +0000 | [diff] [blame] | 234 | // Emit the code (index) for the abbreviation. |
| 235 | if (isVerbose()) |
Duncan P. N. Exon Smith | 815a6eb5 | 2015-05-27 22:31:41 +0000 | [diff] [blame] | 236 | OutStreamer->AddComment("Abbrev [" + Twine(Die.getAbbrevNumber()) + "] 0x" + |
| 237 | Twine::utohexstr(Die.getOffset()) + ":0x" + |
| 238 | Twine::utohexstr(Die.getSize()) + " " + |
| 239 | dwarf::TagString(Die.getTag())); |
| 240 | EmitULEB128(Die.getAbbrevNumber()); |
Frederic Riss | 9412d63 | 2015-03-04 02:30:17 +0000 | [diff] [blame] | 241 | |
Frederic Riss | 9412d63 | 2015-03-04 02:30:17 +0000 | [diff] [blame] | 242 | // Emit the DIE attribute values. |
Duncan P. N. Exon Smith | 88a8fc5 | 2015-05-27 22:44:06 +0000 | [diff] [blame] | 243 | for (const auto &V : Die.values()) { |
| 244 | dwarf::Attribute Attr = V.getAttribute(); |
Duncan P. N. Exon Smith | 9dbb501 | 2015-06-24 18:48:11 +0000 | [diff] [blame] | 245 | assert(V.getForm() && "Too many attributes for DIE (check abbreviation)"); |
Frederic Riss | 9412d63 | 2015-03-04 02:30:17 +0000 | [diff] [blame] | 246 | |
| 247 | if (isVerbose()) { |
Lang Hames | 9ff69c8 | 2015-04-24 19:11:51 +0000 | [diff] [blame] | 248 | OutStreamer->AddComment(dwarf::AttributeString(Attr)); |
Frederic Riss | 9412d63 | 2015-03-04 02:30:17 +0000 | [diff] [blame] | 249 | if (Attr == dwarf::DW_AT_accessibility) |
Duncan P. N. Exon Smith | e7e1d0c | 2015-05-27 22:14:58 +0000 | [diff] [blame] | 250 | OutStreamer->AddComment( |
Duncan P. N. Exon Smith | 88a8fc5 | 2015-05-27 22:44:06 +0000 | [diff] [blame] | 251 | dwarf::AccessibilityString(V.getDIEInteger().getValue())); |
Frederic Riss | 9412d63 | 2015-03-04 02:30:17 +0000 | [diff] [blame] | 252 | } |
| 253 | |
| 254 | // Emit an attribute using the defined form. |
Duncan P. N. Exon Smith | 9dbb501 | 2015-06-24 18:48:11 +0000 | [diff] [blame] | 255 | V.EmitValue(this); |
Frederic Riss | 9412d63 | 2015-03-04 02:30:17 +0000 | [diff] [blame] | 256 | } |
| 257 | |
| 258 | // Emit the DIE children if any. |
Duncan P. N. Exon Smith | 815a6eb5 | 2015-05-27 22:31:41 +0000 | [diff] [blame] | 259 | if (Die.hasChildren()) { |
Duncan P. N. Exon Smith | 8d3197f | 2015-05-28 19:56:34 +0000 | [diff] [blame] | 260 | for (auto &Child : Die.children()) |
Duncan P. N. Exon Smith | 827200c | 2015-06-25 23:52:10 +0000 | [diff] [blame] | 261 | emitDwarfDIE(Child); |
Frederic Riss | 9412d63 | 2015-03-04 02:30:17 +0000 | [diff] [blame] | 262 | |
Lang Hames | 9ff69c8 | 2015-04-24 19:11:51 +0000 | [diff] [blame] | 263 | OutStreamer->AddComment("End Of Children Mark"); |
Rafael Espindola | 4b4d85f | 2018-03-29 23:32:54 +0000 | [diff] [blame] | 264 | emitInt8(0); |
Frederic Riss | 9412d63 | 2015-03-04 02:30:17 +0000 | [diff] [blame] | 265 | } |
| 266 | } |
| 267 | |
David Blaikie | 6196aa0 | 2015-11-18 00:34:10 +0000 | [diff] [blame] | 268 | void AsmPrinter::emitDwarfAbbrev(const DIEAbbrev &Abbrev) const { |
| 269 | // Emit the abbreviations code (base 1 index.) |
| 270 | EmitULEB128(Abbrev.getNumber(), "Abbreviation Code"); |
Frederic Riss | 9412d63 | 2015-03-04 02:30:17 +0000 | [diff] [blame] | 271 | |
David Blaikie | 6196aa0 | 2015-11-18 00:34:10 +0000 | [diff] [blame] | 272 | // Emit the abbreviations data. |
| 273 | Abbrev.Emit(this); |
Frederic Riss | 9412d63 | 2015-03-04 02:30:17 +0000 | [diff] [blame] | 274 | } |