David Blaikie | 319a05f | 2013-12-02 19:33:10 +0000 | [diff] [blame] | 1 | //===-- llvm/CodeGen/DwarfUnit.cpp - Dwarf Type and Compile Units ---------===// |
Devang Patel | 0e821f4 | 2011-04-12 23:21:44 +0000 | [diff] [blame] | 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 | // |
Eric Christopher | 160522c | 2012-08-14 05:13:29 +0000 | [diff] [blame] | 10 | // This file contains support for constructing a dwarf compile unit. |
Devang Patel | 0e821f4 | 2011-04-12 23:21:44 +0000 | [diff] [blame] | 11 | // |
| 12 | //===----------------------------------------------------------------------===// |
| 13 | |
| 14 | #define DEBUG_TYPE "dwarfdebug" |
| 15 | |
David Blaikie | 2c86a72 | 2013-12-02 19:33:15 +0000 | [diff] [blame] | 16 | #include "DwarfUnit.h" |
Chandler Carruth | ed0881b | 2012-12-03 16:50:05 +0000 | [diff] [blame] | 17 | #include "DwarfAccelTable.h" |
Devang Patel | 0e821f4 | 2011-04-12 23:21:44 +0000 | [diff] [blame] | 18 | #include "DwarfDebug.h" |
Chandler Carruth | ed0881b | 2012-12-03 16:50:05 +0000 | [diff] [blame] | 19 | #include "llvm/ADT/APFloat.h" |
Bill Wendling | f799efd | 2012-06-29 08:32:07 +0000 | [diff] [blame] | 20 | #include "llvm/DIBuilder.h" |
Chandler Carruth | 9fb823b | 2013-01-02 11:36:10 +0000 | [diff] [blame] | 21 | #include "llvm/IR/Constants.h" |
| 22 | #include "llvm/IR/DataLayout.h" |
| 23 | #include "llvm/IR/GlobalVariable.h" |
| 24 | #include "llvm/IR/Instructions.h" |
Rafael Espindola | 894843c | 2014-01-07 21:19:40 +0000 | [diff] [blame] | 25 | #include "llvm/IR/Mangler.h" |
Eric Christopher | 8458862 | 2013-12-28 01:39:17 +0000 | [diff] [blame] | 26 | #include "llvm/MC/MCAsmInfo.h" |
Adrian Prantl | cbcd578 | 2014-02-11 22:22:15 +0000 | [diff] [blame] | 27 | #include "llvm/MC/MCContext.h" |
David Blaikie | 6b288cf | 2013-10-30 20:42:41 +0000 | [diff] [blame] | 28 | #include "llvm/MC/MCSection.h" |
| 29 | #include "llvm/MC/MCStreamer.h" |
Chandler Carruth | 8a8cd2b | 2014-01-07 11:48:04 +0000 | [diff] [blame] | 30 | #include "llvm/Support/CommandLine.h" |
Devang Patel | 0e821f4 | 2011-04-12 23:21:44 +0000 | [diff] [blame] | 31 | #include "llvm/Target/TargetFrameLowering.h" |
David Blaikie | f269497 | 2013-06-28 20:05:11 +0000 | [diff] [blame] | 32 | #include "llvm/Target/TargetLoweringObjectFile.h" |
Chandler Carruth | 8a8cd2b | 2014-01-07 11:48:04 +0000 | [diff] [blame] | 33 | #include "llvm/Target/TargetMachine.h" |
Devang Patel | 0e821f4 | 2011-04-12 23:21:44 +0000 | [diff] [blame] | 34 | #include "llvm/Target/TargetRegisterInfo.h" |
Devang Patel | 0e821f4 | 2011-04-12 23:21:44 +0000 | [diff] [blame] | 35 | |
| 36 | using namespace llvm; |
| 37 | |
Eric Christopher | 4287a49 | 2013-12-09 23:57:44 +0000 | [diff] [blame] | 38 | static cl::opt<bool> |
| 39 | GenerateDwarfTypeUnits("generate-type-units", cl::Hidden, |
| 40 | cl::desc("Generate DWARF4 type units."), |
| 41 | cl::init(false)); |
David Blaikie | 409dd9c | 2013-11-19 23:08:21 +0000 | [diff] [blame] | 42 | |
David Blaikie | 2a80e44 | 2013-12-02 22:09:48 +0000 | [diff] [blame] | 43 | /// Unit - Unit constructor. |
David Blaikie | 7480ae6 | 2014-01-09 03:03:27 +0000 | [diff] [blame] | 44 | DwarfUnit::DwarfUnit(unsigned UID, DIE *D, DICompileUnit Node, AsmPrinter *A, |
| 45 | DwarfDebug *DW, DwarfFile *DWU) |
David Blaikie | f645f96 | 2014-01-09 03:23:41 +0000 | [diff] [blame] | 46 | : UniqueID(UID), CUNode(Node), UnitDie(D), DebugInfoOffset(0), Asm(A), |
| 47 | DD(DW), DU(DWU), IndexTyDie(0), Section(0), Skeleton(0) { |
David Blaikie | 319a05f | 2013-12-02 19:33:10 +0000 | [diff] [blame] | 48 | DIEIntegerOne = new (DIEValueAllocator) DIEInteger(1); |
| 49 | } |
| 50 | |
Eric Christopher | 4287a49 | 2013-12-09 23:57:44 +0000 | [diff] [blame] | 51 | DwarfCompileUnit::DwarfCompileUnit(unsigned UID, DIE *D, DICompileUnit Node, |
| 52 | AsmPrinter *A, DwarfDebug *DW, |
| 53 | DwarfFile *DWU) |
David Blaikie | 7480ae6 | 2014-01-09 03:03:27 +0000 | [diff] [blame] | 54 | : DwarfUnit(UID, D, Node, A, DW, DWU) { |
David Blaikie | 5a15240 | 2013-11-15 23:52:02 +0000 | [diff] [blame] | 55 | insertDIE(Node, D); |
Devang Patel | 0e821f4 | 2011-04-12 23:21:44 +0000 | [diff] [blame] | 56 | } |
| 57 | |
David Blaikie | f645f96 | 2014-01-09 03:23:41 +0000 | [diff] [blame] | 58 | DwarfTypeUnit::DwarfTypeUnit(unsigned UID, DIE *D, DICompileUnit CUNode, |
Eric Christopher | 4287a49 | 2013-12-09 23:57:44 +0000 | [diff] [blame] | 59 | AsmPrinter *A, DwarfDebug *DW, DwarfFile *DWU) |
David Blaikie | f645f96 | 2014-01-09 03:23:41 +0000 | [diff] [blame] | 60 | : DwarfUnit(UID, D, CUNode, A, DW, DWU) {} |
David Blaikie | 409dd9c | 2013-11-19 23:08:21 +0000 | [diff] [blame] | 61 | |
David Blaikie | 319a05f | 2013-12-02 19:33:10 +0000 | [diff] [blame] | 62 | /// ~Unit - Destructor for compile unit. |
Eric Christopher | a5a7942 | 2013-12-09 23:32:48 +0000 | [diff] [blame] | 63 | DwarfUnit::~DwarfUnit() { |
Devang Patel | 0e821f4 | 2011-04-12 23:21:44 +0000 | [diff] [blame] | 64 | for (unsigned j = 0, M = DIEBlocks.size(); j < M; ++j) |
| 65 | DIEBlocks[j]->~DIEBlock(); |
| 66 | } |
| 67 | |
| 68 | /// createDIEEntry - Creates a new DIEEntry to be a proxy for a debug |
| 69 | /// information entry. |
Eric Christopher | a5a7942 | 2013-12-09 23:32:48 +0000 | [diff] [blame] | 70 | DIEEntry *DwarfUnit::createDIEEntry(DIE *Entry) { |
Devang Patel | 0e821f4 | 2011-04-12 23:21:44 +0000 | [diff] [blame] | 71 | DIEEntry *Value = new (DIEValueAllocator) DIEEntry(Entry); |
| 72 | return Value; |
| 73 | } |
| 74 | |
Bill Wendling | 3495f9b | 2012-12-06 07:55:19 +0000 | [diff] [blame] | 75 | /// getDefaultLowerBound - Return the default lower bound for an array. If the |
Bill Wendling | 28fe9e7 | 2012-12-06 07:38:10 +0000 | [diff] [blame] | 76 | /// DWARF version doesn't handle the language, return -1. |
Eric Christopher | a5a7942 | 2013-12-09 23:32:48 +0000 | [diff] [blame] | 77 | int64_t DwarfUnit::getDefaultLowerBound() const { |
David Blaikie | cb8e435 | 2013-11-15 23:50:53 +0000 | [diff] [blame] | 78 | switch (getLanguage()) { |
Bill Wendling | 28fe9e7 | 2012-12-06 07:38:10 +0000 | [diff] [blame] | 79 | default: |
| 80 | break; |
| 81 | |
| 82 | case dwarf::DW_LANG_C89: |
| 83 | case dwarf::DW_LANG_C99: |
| 84 | case dwarf::DW_LANG_C: |
| 85 | case dwarf::DW_LANG_C_plus_plus: |
| 86 | case dwarf::DW_LANG_ObjC: |
| 87 | case dwarf::DW_LANG_ObjC_plus_plus: |
| 88 | return 0; |
| 89 | |
| 90 | case dwarf::DW_LANG_Fortran77: |
| 91 | case dwarf::DW_LANG_Fortran90: |
| 92 | case dwarf::DW_LANG_Fortran95: |
| 93 | return 1; |
| 94 | |
| 95 | // The languages below have valid values only if the DWARF version >= 4. |
| 96 | case dwarf::DW_LANG_Java: |
| 97 | case dwarf::DW_LANG_Python: |
| 98 | case dwarf::DW_LANG_UPC: |
| 99 | case dwarf::DW_LANG_D: |
| 100 | if (dwarf::DWARF_VERSION >= 4) |
| 101 | return 0; |
| 102 | break; |
| 103 | |
| 104 | case dwarf::DW_LANG_Ada83: |
| 105 | case dwarf::DW_LANG_Ada95: |
| 106 | case dwarf::DW_LANG_Cobol74: |
| 107 | case dwarf::DW_LANG_Cobol85: |
| 108 | case dwarf::DW_LANG_Modula2: |
| 109 | case dwarf::DW_LANG_Pascal83: |
| 110 | case dwarf::DW_LANG_PLI: |
| 111 | if (dwarf::DWARF_VERSION >= 4) |
| 112 | return 1; |
| 113 | break; |
| 114 | } |
| 115 | |
| 116 | return -1; |
| 117 | } |
| 118 | |
Manman Ren | 4dbdc90 | 2013-10-31 17:54:35 +0000 | [diff] [blame] | 119 | /// Check whether the DIE for this MDNode can be shared across CUs. |
David Blaikie | 4201ddf | 2013-11-15 22:59:36 +0000 | [diff] [blame] | 120 | static bool isShareableAcrossCUs(DIDescriptor D) { |
David Blaikie | bcb418e | 2013-11-20 18:40:16 +0000 | [diff] [blame] | 121 | // When the MDNode can be part of the type system, the DIE can be shared |
| 122 | // across CUs. |
| 123 | // Combining type units and cross-CU DIE sharing is lower value (since |
| 124 | // cross-CU DIE sharing is used in LTO and removes type redundancy at that |
| 125 | // level already) but may be implementable for some value in projects |
| 126 | // building multiple independent libraries with LTO and then linking those |
| 127 | // together. |
David Blaikie | 409dd9c | 2013-11-19 23:08:21 +0000 | [diff] [blame] | 128 | return (D.isType() || |
| 129 | (D.isSubprogram() && !DISubprogram(D).isDefinition())) && |
Eric Christopher | 4287a49 | 2013-12-09 23:57:44 +0000 | [diff] [blame] | 130 | !GenerateDwarfTypeUnits; |
Manman Ren | 4dbdc90 | 2013-10-31 17:54:35 +0000 | [diff] [blame] | 131 | } |
| 132 | |
| 133 | /// getDIE - Returns the debug information entry map slot for the |
| 134 | /// specified debug variable. We delegate the request to DwarfDebug |
| 135 | /// when the DIE for this MDNode can be shared across CUs. The mappings |
| 136 | /// will be kept in DwarfDebug for shareable DIEs. |
Eric Christopher | a5a7942 | 2013-12-09 23:32:48 +0000 | [diff] [blame] | 137 | DIE *DwarfUnit::getDIE(DIDescriptor D) const { |
David Blaikie | 2ad0016 | 2013-11-15 23:09:13 +0000 | [diff] [blame] | 138 | if (isShareableAcrossCUs(D)) |
| 139 | return DD->getDIE(D); |
| 140 | return MDNodeToDieMap.lookup(D); |
Manman Ren | 4dbdc90 | 2013-10-31 17:54:35 +0000 | [diff] [blame] | 141 | } |
| 142 | |
| 143 | /// insertDIE - Insert DIE into the map. We delegate the request to DwarfDebug |
| 144 | /// when the DIE for this MDNode can be shared across CUs. The mappings |
| 145 | /// will be kept in DwarfDebug for shareable DIEs. |
Eric Christopher | a5a7942 | 2013-12-09 23:32:48 +0000 | [diff] [blame] | 146 | void DwarfUnit::insertDIE(DIDescriptor Desc, DIE *D) { |
David Blaikie | 2ad0016 | 2013-11-15 23:09:13 +0000 | [diff] [blame] | 147 | if (isShareableAcrossCUs(Desc)) { |
| 148 | DD->insertDIE(Desc, D); |
Manman Ren | 4dbdc90 | 2013-10-31 17:54:35 +0000 | [diff] [blame] | 149 | return; |
| 150 | } |
David Blaikie | 2ad0016 | 2013-11-15 23:09:13 +0000 | [diff] [blame] | 151 | MDNodeToDieMap.insert(std::make_pair(Desc, D)); |
Manman Ren | 4dbdc90 | 2013-10-31 17:54:35 +0000 | [diff] [blame] | 152 | } |
| 153 | |
Eric Christopher | bb69a27 | 2012-08-24 01:14:27 +0000 | [diff] [blame] | 154 | /// addFlag - Add a flag that is true. |
Eric Christopher | a5a7942 | 2013-12-09 23:32:48 +0000 | [diff] [blame] | 155 | void DwarfUnit::addFlag(DIE *Die, dwarf::Attribute Attribute) { |
Michael Gottesman | c89466f | 2013-09-04 04:39:38 +0000 | [diff] [blame] | 156 | if (DD->getDwarfVersion() >= 4) |
Eric Christopher | dccd328 | 2013-10-04 22:40:05 +0000 | [diff] [blame] | 157 | Die->addValue(Attribute, dwarf::DW_FORM_flag_present, DIEIntegerOne); |
Eric Christopher | bb69a27 | 2012-08-24 01:14:27 +0000 | [diff] [blame] | 158 | else |
Eric Christopher | dccd328 | 2013-10-04 22:40:05 +0000 | [diff] [blame] | 159 | Die->addValue(Attribute, dwarf::DW_FORM_flag, DIEIntegerOne); |
Eric Christopher | bb69a27 | 2012-08-24 01:14:27 +0000 | [diff] [blame] | 160 | } |
| 161 | |
Devang Patel | 0e821f4 | 2011-04-12 23:21:44 +0000 | [diff] [blame] | 162 | /// addUInt - Add an unsigned integer attribute data and value. |
| 163 | /// |
Eric Christopher | a5a7942 | 2013-12-09 23:32:48 +0000 | [diff] [blame] | 164 | void DwarfUnit::addUInt(DIE *Die, dwarf::Attribute Attribute, |
| 165 | Optional<dwarf::Form> Form, uint64_t Integer) { |
Eric Christopher | c2697f8 | 2013-10-19 01:04:47 +0000 | [diff] [blame] | 166 | if (!Form) |
| 167 | Form = DIEInteger::BestForm(false, Integer); |
| 168 | DIEValue *Value = Integer == 1 ? DIEIntegerOne : new (DIEValueAllocator) |
| 169 | DIEInteger(Integer); |
David Blaikie | f244319 | 2013-10-21 17:28:37 +0000 | [diff] [blame] | 170 | Die->addValue(Attribute, *Form, Value); |
| 171 | } |
| 172 | |
Eric Christopher | a5a7942 | 2013-12-09 23:32:48 +0000 | [diff] [blame] | 173 | void DwarfUnit::addUInt(DIEBlock *Block, dwarf::Form Form, uint64_t Integer) { |
David Blaikie | f244319 | 2013-10-21 17:28:37 +0000 | [diff] [blame] | 174 | addUInt(Block, (dwarf::Attribute)0, Form, Integer); |
Devang Patel | 0e821f4 | 2011-04-12 23:21:44 +0000 | [diff] [blame] | 175 | } |
| 176 | |
| 177 | /// addSInt - Add an signed integer attribute data and value. |
| 178 | /// |
Eric Christopher | a5a7942 | 2013-12-09 23:32:48 +0000 | [diff] [blame] | 179 | void DwarfUnit::addSInt(DIE *Die, dwarf::Attribute Attribute, |
| 180 | Optional<dwarf::Form> Form, int64_t Integer) { |
Eric Christopher | c2697f8 | 2013-10-19 01:04:47 +0000 | [diff] [blame] | 181 | if (!Form) |
| 182 | Form = DIEInteger::BestForm(true, Integer); |
Devang Patel | 0e821f4 | 2011-04-12 23:21:44 +0000 | [diff] [blame] | 183 | DIEValue *Value = new (DIEValueAllocator) DIEInteger(Integer); |
David Blaikie | f244319 | 2013-10-21 17:28:37 +0000 | [diff] [blame] | 184 | Die->addValue(Attribute, *Form, Value); |
| 185 | } |
| 186 | |
Eric Christopher | a5a7942 | 2013-12-09 23:32:48 +0000 | [diff] [blame] | 187 | void DwarfUnit::addSInt(DIEBlock *Die, Optional<dwarf::Form> Form, |
| 188 | int64_t Integer) { |
David Blaikie | f244319 | 2013-10-21 17:28:37 +0000 | [diff] [blame] | 189 | addSInt(Die, (dwarf::Attribute)0, Form, Integer); |
Devang Patel | 0e821f4 | 2011-04-12 23:21:44 +0000 | [diff] [blame] | 190 | } |
| 191 | |
Nick Lewycky | cc64ae1 | 2011-10-28 05:29:47 +0000 | [diff] [blame] | 192 | /// addString - Add a string attribute data and value. We always emit a |
| 193 | /// reference to the string pool instead of immediate strings so that DIEs have |
Eric Christopher | fba2260 | 2013-01-07 19:32:45 +0000 | [diff] [blame] | 194 | /// more predictable sizes. In the case of split dwarf we emit an index |
| 195 | /// into another table which gets us the static offset into the string |
| 196 | /// table. |
Eric Christopher | a5a7942 | 2013-12-09 23:32:48 +0000 | [diff] [blame] | 197 | void DwarfUnit::addString(DIE *Die, dwarf::Attribute Attribute, |
| 198 | StringRef String) { |
Eric Christopher | 05893f4 | 2013-12-30 18:32:31 +0000 | [diff] [blame] | 199 | |
| 200 | if (!DD->useSplitDwarf()) |
| 201 | return addLocalString(Die, Attribute, String); |
| 202 | |
| 203 | unsigned idx = DU->getStringPoolIndex(String); |
| 204 | DIEValue *Value = new (DIEValueAllocator) DIEInteger(idx); |
Eric Christopher | 6764643 | 2013-07-26 17:02:41 +0000 | [diff] [blame] | 205 | DIEValue *Str = new (DIEValueAllocator) DIEString(Value, String); |
Eric Christopher | 05893f4 | 2013-12-30 18:32:31 +0000 | [diff] [blame] | 206 | Die->addValue(Attribute, dwarf::DW_FORM_GNU_str_index, Str); |
Eric Christopher | 2cbd576 | 2013-01-07 19:32:41 +0000 | [diff] [blame] | 207 | } |
| 208 | |
| 209 | /// addLocalString - Add a string attribute data and value. This is guaranteed |
| 210 | /// to be in the local string pool instead of indirected. |
Eric Christopher | a5a7942 | 2013-12-09 23:32:48 +0000 | [diff] [blame] | 211 | void DwarfUnit::addLocalString(DIE *Die, dwarf::Attribute Attribute, |
| 212 | StringRef String) { |
Eric Christopher | e698f53 | 2012-12-20 21:58:36 +0000 | [diff] [blame] | 213 | MCSymbol *Symb = DU->getStringPoolEntry(String); |
Nick Lewycky | cc64ae1 | 2011-10-28 05:29:47 +0000 | [diff] [blame] | 214 | DIEValue *Value; |
Eric Christopher | 8458862 | 2013-12-28 01:39:17 +0000 | [diff] [blame] | 215 | if (Asm->MAI->doesDwarfUseRelocationsAcrossSections()) |
Ulrich Weigand | 396ba8b | 2013-07-02 18:46:26 +0000 | [diff] [blame] | 216 | Value = new (DIEValueAllocator) DIELabel(Symb); |
Nick Lewycky | cc64ae1 | 2011-10-28 05:29:47 +0000 | [diff] [blame] | 217 | else { |
Eric Christopher | e698f53 | 2012-12-20 21:58:36 +0000 | [diff] [blame] | 218 | MCSymbol *StringPool = DU->getStringPoolSym(); |
Nick Lewycky | cc64ae1 | 2011-10-28 05:29:47 +0000 | [diff] [blame] | 219 | Value = new (DIEValueAllocator) DIEDelta(Symb, StringPool); |
Nick Lewycky | d59c0ca | 2011-10-27 06:44:11 +0000 | [diff] [blame] | 220 | } |
Eric Christopher | 05893f4 | 2013-12-30 18:32:31 +0000 | [diff] [blame] | 221 | DIEValue *Str = new (DIEValueAllocator) DIEString(Value, String); |
| 222 | Die->addValue(Attribute, dwarf::DW_FORM_strp, Str); |
Devang Patel | 0e821f4 | 2011-04-12 23:21:44 +0000 | [diff] [blame] | 223 | } |
| 224 | |
Ulrich Weigand | 396ba8b | 2013-07-02 18:46:26 +0000 | [diff] [blame] | 225 | /// addExpr - Add a Dwarf expression attribute data and value. |
Devang Patel | 0e821f4 | 2011-04-12 23:21:44 +0000 | [diff] [blame] | 226 | /// |
Eric Christopher | a5a7942 | 2013-12-09 23:32:48 +0000 | [diff] [blame] | 227 | void DwarfUnit::addExpr(DIEBlock *Die, dwarf::Form Form, const MCExpr *Expr) { |
Ulrich Weigand | 396ba8b | 2013-07-02 18:46:26 +0000 | [diff] [blame] | 228 | DIEValue *Value = new (DIEValueAllocator) DIEExpr(Expr); |
David Blaikie | f244319 | 2013-10-21 17:28:37 +0000 | [diff] [blame] | 229 | Die->addValue((dwarf::Attribute)0, Form, Value); |
Devang Patel | 0e821f4 | 2011-04-12 23:21:44 +0000 | [diff] [blame] | 230 | } |
| 231 | |
Ulrich Weigand | 396ba8b | 2013-07-02 18:46:26 +0000 | [diff] [blame] | 232 | /// addLabel - Add a Dwarf label attribute data and value. |
| 233 | /// |
Eric Christopher | a5a7942 | 2013-12-09 23:32:48 +0000 | [diff] [blame] | 234 | void DwarfUnit::addLabel(DIE *Die, dwarf::Attribute Attribute, dwarf::Form Form, |
| 235 | const MCSymbol *Label) { |
Ulrich Weigand | 396ba8b | 2013-07-02 18:46:26 +0000 | [diff] [blame] | 236 | DIEValue *Value = new (DIEValueAllocator) DIELabel(Label); |
| 237 | Die->addValue(Attribute, Form, Value); |
David Blaikie | f3cd7c5 | 2013-06-28 20:05:04 +0000 | [diff] [blame] | 238 | } |
| 239 | |
Eric Christopher | a5a7942 | 2013-12-09 23:32:48 +0000 | [diff] [blame] | 240 | void DwarfUnit::addLabel(DIEBlock *Die, dwarf::Form Form, |
| 241 | const MCSymbol *Label) { |
David Blaikie | f244319 | 2013-10-21 17:28:37 +0000 | [diff] [blame] | 242 | addLabel(Die, (dwarf::Attribute)0, Form, Label); |
| 243 | } |
| 244 | |
Eric Christopher | 33ff697 | 2013-11-21 23:46:41 +0000 | [diff] [blame] | 245 | /// addSectionLabel - Add a Dwarf section label attribute data and value. |
| 246 | /// |
Eric Christopher | a5a7942 | 2013-12-09 23:32:48 +0000 | [diff] [blame] | 247 | void DwarfUnit::addSectionLabel(DIE *Die, dwarf::Attribute Attribute, |
| 248 | const MCSymbol *Label) { |
Eric Christopher | 33ff697 | 2013-11-21 23:46:41 +0000 | [diff] [blame] | 249 | if (DD->getDwarfVersion() >= 4) |
| 250 | addLabel(Die, Attribute, dwarf::DW_FORM_sec_offset, Label); |
| 251 | else |
| 252 | addLabel(Die, Attribute, dwarf::DW_FORM_data4, Label); |
| 253 | } |
| 254 | |
| 255 | /// addSectionOffset - Add an offset into a section attribute data and value. |
| 256 | /// |
Eric Christopher | a5a7942 | 2013-12-09 23:32:48 +0000 | [diff] [blame] | 257 | void DwarfUnit::addSectionOffset(DIE *Die, dwarf::Attribute Attribute, |
| 258 | uint64_t Integer) { |
Eric Christopher | 33ff697 | 2013-11-21 23:46:41 +0000 | [diff] [blame] | 259 | if (DD->getDwarfVersion() >= 4) |
| 260 | addUInt(Die, Attribute, dwarf::DW_FORM_sec_offset, Integer); |
| 261 | else |
| 262 | addUInt(Die, Attribute, dwarf::DW_FORM_data4, Integer); |
| 263 | } |
| 264 | |
Eric Christopher | 962c908 | 2013-01-15 23:56:56 +0000 | [diff] [blame] | 265 | /// addLabelAddress - Add a dwarf label attribute data and value using |
| 266 | /// DW_FORM_addr or DW_FORM_GNU_addr_index. |
| 267 | /// |
Eric Christopher | 4287a49 | 2013-12-09 23:57:44 +0000 | [diff] [blame] | 268 | void DwarfCompileUnit::addLabelAddress(DIE *Die, dwarf::Attribute Attribute, |
| 269 | MCSymbol *Label) { |
Alexey Samsonov | 4436bf0 | 2013-10-03 08:54:43 +0000 | [diff] [blame] | 270 | if (Label) |
| 271 | DD->addArangeLabel(SymbolCU(this, Label)); |
Richard Mitton | 21101b3 | 2013-09-19 23:21:01 +0000 | [diff] [blame] | 272 | |
Eric Christopher | cf48ade | 2014-01-24 11:52:53 +0000 | [diff] [blame] | 273 | if (!DD->useSplitDwarf()) { |
| 274 | if (Label) { |
| 275 | DIEValue *Value = new (DIEValueAllocator) DIELabel(Label); |
| 276 | Die->addValue(Attribute, dwarf::DW_FORM_addr, Value); |
| 277 | } else { |
| 278 | DIEValue *Value = new (DIEValueAllocator) DIEInteger(0); |
| 279 | Die->addValue(Attribute, dwarf::DW_FORM_addr, Value); |
| 280 | } |
Eric Christopher | 962c908 | 2013-01-15 23:56:56 +0000 | [diff] [blame] | 281 | } else { |
Eric Christopher | cf48ade | 2014-01-24 11:52:53 +0000 | [diff] [blame] | 282 | unsigned idx = DU->getAddrPoolIndex(Label); |
| 283 | DIEValue *Value = new (DIEValueAllocator) DIEInteger(idx); |
| 284 | Die->addValue(Attribute, dwarf::DW_FORM_GNU_addr_index, Value); |
Eric Christopher | 962c908 | 2013-01-15 23:56:56 +0000 | [diff] [blame] | 285 | } |
| 286 | } |
| 287 | |
Eric Christopher | e9ec245 | 2013-01-18 22:11:33 +0000 | [diff] [blame] | 288 | /// addOpAddress - Add a dwarf op address data and value using the |
| 289 | /// form given and an op of either DW_FORM_addr or DW_FORM_GNU_addr_index. |
| 290 | /// |
Eric Christopher | a5a7942 | 2013-12-09 23:32:48 +0000 | [diff] [blame] | 291 | void DwarfUnit::addOpAddress(DIEBlock *Die, const MCSymbol *Sym) { |
Eric Christopher | e9ec245 | 2013-01-18 22:11:33 +0000 | [diff] [blame] | 292 | if (!DD->useSplitDwarf()) { |
David Blaikie | f244319 | 2013-10-21 17:28:37 +0000 | [diff] [blame] | 293 | addUInt(Die, dwarf::DW_FORM_data1, dwarf::DW_OP_addr); |
| 294 | addLabel(Die, dwarf::DW_FORM_udata, Sym); |
Eric Christopher | e9ec245 | 2013-01-18 22:11:33 +0000 | [diff] [blame] | 295 | } else { |
David Blaikie | f244319 | 2013-10-21 17:28:37 +0000 | [diff] [blame] | 296 | addUInt(Die, dwarf::DW_FORM_data1, dwarf::DW_OP_GNU_addr_index); |
| 297 | addUInt(Die, dwarf::DW_FORM_GNU_addr_index, DU->getAddrPoolIndex(Sym)); |
Eric Christopher | e9ec245 | 2013-01-18 22:11:33 +0000 | [diff] [blame] | 298 | } |
| 299 | } |
| 300 | |
Eric Christopher | 33ff697 | 2013-11-21 23:46:41 +0000 | [diff] [blame] | 301 | /// addSectionDelta - Add a section label delta attribute data and value. |
Devang Patel | 0e821f4 | 2011-04-12 23:21:44 +0000 | [diff] [blame] | 302 | /// |
Eric Christopher | a5a7942 | 2013-12-09 23:32:48 +0000 | [diff] [blame] | 303 | void DwarfUnit::addSectionDelta(DIE *Die, dwarf::Attribute Attribute, |
| 304 | const MCSymbol *Hi, const MCSymbol *Lo) { |
Devang Patel | 0e821f4 | 2011-04-12 23:21:44 +0000 | [diff] [blame] | 305 | DIEValue *Value = new (DIEValueAllocator) DIEDelta(Hi, Lo); |
Eric Christopher | 33ff697 | 2013-11-21 23:46:41 +0000 | [diff] [blame] | 306 | if (DD->getDwarfVersion() >= 4) |
| 307 | Die->addValue(Attribute, dwarf::DW_FORM_sec_offset, Value); |
| 308 | else |
| 309 | Die->addValue(Attribute, dwarf::DW_FORM_data4, Value); |
Devang Patel | 0e821f4 | 2011-04-12 23:21:44 +0000 | [diff] [blame] | 310 | } |
| 311 | |
| 312 | /// addDIEEntry - Add a DIE attribute data and value. |
| 313 | /// |
Eric Christopher | a5a7942 | 2013-12-09 23:32:48 +0000 | [diff] [blame] | 314 | void DwarfUnit::addDIEEntry(DIE *Die, dwarf::Attribute Attribute, DIE *Entry) { |
Manman Ren | 4dbdc90 | 2013-10-31 17:54:35 +0000 | [diff] [blame] | 315 | addDIEEntry(Die, Attribute, createDIEEntry(Entry)); |
| 316 | } |
| 317 | |
David Blaikie | 47f615e | 2013-12-17 23:32:35 +0000 | [diff] [blame] | 318 | void DwarfUnit::addDIETypeSignature(DIE *Die, const DwarfTypeUnit &Type) { |
| 319 | Die->addValue(dwarf::DW_AT_signature, dwarf::DW_FORM_ref_sig8, |
| 320 | new (DIEValueAllocator) DIETypeSignature(Type)); |
| 321 | } |
| 322 | |
Eric Christopher | a5a7942 | 2013-12-09 23:32:48 +0000 | [diff] [blame] | 323 | void DwarfUnit::addDIEEntry(DIE *Die, dwarf::Attribute Attribute, |
| 324 | DIEEntry *Entry) { |
David Blaikie | 409dd9c | 2013-11-19 23:08:21 +0000 | [diff] [blame] | 325 | const DIE *DieCU = Die->getUnitOrNull(); |
| 326 | const DIE *EntryCU = Entry->getEntry()->getUnitOrNull(); |
Manman Ren | 4dbdc90 | 2013-10-31 17:54:35 +0000 | [diff] [blame] | 327 | if (!DieCU) |
| 328 | // We assume that Die belongs to this CU, if it is not linked to any CU yet. |
David Blaikie | 2a80e44 | 2013-12-02 22:09:48 +0000 | [diff] [blame] | 329 | DieCU = getUnitDie(); |
Manman Ren | 4dbdc90 | 2013-10-31 17:54:35 +0000 | [diff] [blame] | 330 | if (!EntryCU) |
David Blaikie | 2a80e44 | 2013-12-02 22:09:48 +0000 | [diff] [blame] | 331 | EntryCU = getUnitDie(); |
Manman Ren | 4dbdc90 | 2013-10-31 17:54:35 +0000 | [diff] [blame] | 332 | Die->addValue(Attribute, EntryCU == DieCU ? dwarf::DW_FORM_ref4 |
| 333 | : dwarf::DW_FORM_ref_addr, |
| 334 | Entry); |
Devang Patel | 0e821f4 | 2011-04-12 23:21:44 +0000 | [diff] [blame] | 335 | } |
| 336 | |
Manman Ren | b987e51 | 2013-10-29 00:53:03 +0000 | [diff] [blame] | 337 | /// Create a DIE with the given Tag, add the DIE to its parent, and |
| 338 | /// call insertDIE if MD is not null. |
Eric Christopher | a5a7942 | 2013-12-09 23:32:48 +0000 | [diff] [blame] | 339 | DIE *DwarfUnit::createAndAddDIE(unsigned Tag, DIE &Parent, DIDescriptor N) { |
Manman Ren | b987e51 | 2013-10-29 00:53:03 +0000 | [diff] [blame] | 340 | DIE *Die = new DIE(Tag); |
| 341 | Parent.addChild(Die); |
David Blaikie | 52c5020 | 2013-11-16 00:29:01 +0000 | [diff] [blame] | 342 | if (N) |
| 343 | insertDIE(N, Die); |
Manman Ren | b987e51 | 2013-10-29 00:53:03 +0000 | [diff] [blame] | 344 | return Die; |
| 345 | } |
| 346 | |
Devang Patel | 0e821f4 | 2011-04-12 23:21:44 +0000 | [diff] [blame] | 347 | /// addBlock - Add block data. |
| 348 | /// |
Eric Christopher | a5a7942 | 2013-12-09 23:32:48 +0000 | [diff] [blame] | 349 | void DwarfUnit::addBlock(DIE *Die, dwarf::Attribute Attribute, |
| 350 | DIEBlock *Block) { |
Devang Patel | 0e821f4 | 2011-04-12 23:21:44 +0000 | [diff] [blame] | 351 | Block->ComputeSize(Asm); |
| 352 | DIEBlocks.push_back(Block); // Memoize so we can call the destructor later on. |
| 353 | Die->addValue(Attribute, Block->BestForm(), Block); |
| 354 | } |
| 355 | |
| 356 | /// addSourceLine - Add location information to specified debug information |
| 357 | /// entry. |
Eric Christopher | a5a7942 | 2013-12-09 23:32:48 +0000 | [diff] [blame] | 358 | void DwarfUnit::addSourceLine(DIE *Die, DIVariable V) { |
David Blaikie | 5201930 | 2014-02-11 23:57:03 +0000 | [diff] [blame^] | 359 | assert(V.isVariable()); |
Eric Christopher | 92331fd | 2012-11-21 00:34:38 +0000 | [diff] [blame] | 360 | |
Devang Patel | 0e821f4 | 2011-04-12 23:21:44 +0000 | [diff] [blame] | 361 | unsigned Line = V.getLineNumber(); |
| 362 | if (Line == 0) |
| 363 | return; |
Eric Christopher | c2697f8 | 2013-10-19 01:04:47 +0000 | [diff] [blame] | 364 | unsigned FileID = |
| 365 | DD->getOrCreateSourceID(V.getContext().getFilename(), |
| 366 | V.getContext().getDirectory(), getUniqueID()); |
Devang Patel | 0e821f4 | 2011-04-12 23:21:44 +0000 | [diff] [blame] | 367 | assert(FileID && "Invalid file id"); |
David Blaikie | f244319 | 2013-10-21 17:28:37 +0000 | [diff] [blame] | 368 | addUInt(Die, dwarf::DW_AT_decl_file, None, FileID); |
| 369 | addUInt(Die, dwarf::DW_AT_decl_line, None, Line); |
Devang Patel | 0e821f4 | 2011-04-12 23:21:44 +0000 | [diff] [blame] | 370 | } |
| 371 | |
| 372 | /// addSourceLine - Add location information to specified debug information |
| 373 | /// entry. |
Eric Christopher | a5a7942 | 2013-12-09 23:32:48 +0000 | [diff] [blame] | 374 | void DwarfUnit::addSourceLine(DIE *Die, DIGlobalVariable G) { |
David Blaikie | 5201930 | 2014-02-11 23:57:03 +0000 | [diff] [blame^] | 375 | assert(G.isGlobalVariable()); |
Devang Patel | 0e821f4 | 2011-04-12 23:21:44 +0000 | [diff] [blame] | 376 | |
| 377 | unsigned Line = G.getLineNumber(); |
| 378 | if (Line == 0) |
| 379 | return; |
Eric Christopher | c2697f8 | 2013-10-19 01:04:47 +0000 | [diff] [blame] | 380 | unsigned FileID = |
| 381 | DD->getOrCreateSourceID(G.getFilename(), G.getDirectory(), getUniqueID()); |
Devang Patel | 0e821f4 | 2011-04-12 23:21:44 +0000 | [diff] [blame] | 382 | assert(FileID && "Invalid file id"); |
David Blaikie | f244319 | 2013-10-21 17:28:37 +0000 | [diff] [blame] | 383 | addUInt(Die, dwarf::DW_AT_decl_file, None, FileID); |
| 384 | addUInt(Die, dwarf::DW_AT_decl_line, None, Line); |
Devang Patel | 0e821f4 | 2011-04-12 23:21:44 +0000 | [diff] [blame] | 385 | } |
| 386 | |
| 387 | /// addSourceLine - Add location information to specified debug information |
| 388 | /// entry. |
Eric Christopher | a5a7942 | 2013-12-09 23:32:48 +0000 | [diff] [blame] | 389 | void DwarfUnit::addSourceLine(DIE *Die, DISubprogram SP) { |
David Blaikie | 5201930 | 2014-02-11 23:57:03 +0000 | [diff] [blame^] | 390 | assert(SP.isSubprogram()); |
Eric Christopher | 7734ca2 | 2012-03-15 23:55:40 +0000 | [diff] [blame] | 391 | |
Devang Patel | 0e821f4 | 2011-04-12 23:21:44 +0000 | [diff] [blame] | 392 | // If the line number is 0, don't add it. |
Eric Christopher | 7734ca2 | 2012-03-15 23:55:40 +0000 | [diff] [blame] | 393 | unsigned Line = SP.getLineNumber(); |
| 394 | if (Line == 0) |
Devang Patel | 0e821f4 | 2011-04-12 23:21:44 +0000 | [diff] [blame] | 395 | return; |
| 396 | |
Eric Christopher | c2697f8 | 2013-10-19 01:04:47 +0000 | [diff] [blame] | 397 | unsigned FileID = DD->getOrCreateSourceID(SP.getFilename(), SP.getDirectory(), |
| 398 | getUniqueID()); |
Devang Patel | 0e821f4 | 2011-04-12 23:21:44 +0000 | [diff] [blame] | 399 | assert(FileID && "Invalid file id"); |
David Blaikie | f244319 | 2013-10-21 17:28:37 +0000 | [diff] [blame] | 400 | addUInt(Die, dwarf::DW_AT_decl_file, None, FileID); |
| 401 | addUInt(Die, dwarf::DW_AT_decl_line, None, Line); |
Devang Patel | 0e821f4 | 2011-04-12 23:21:44 +0000 | [diff] [blame] | 402 | } |
| 403 | |
| 404 | /// addSourceLine - Add location information to specified debug information |
| 405 | /// entry. |
Eric Christopher | a5a7942 | 2013-12-09 23:32:48 +0000 | [diff] [blame] | 406 | void DwarfUnit::addSourceLine(DIE *Die, DIType Ty) { |
David Blaikie | 5201930 | 2014-02-11 23:57:03 +0000 | [diff] [blame^] | 407 | assert(Ty.isType()); |
Devang Patel | 0e821f4 | 2011-04-12 23:21:44 +0000 | [diff] [blame] | 408 | |
| 409 | unsigned Line = Ty.getLineNumber(); |
Eric Christopher | 7734ca2 | 2012-03-15 23:55:40 +0000 | [diff] [blame] | 410 | if (Line == 0) |
Devang Patel | 0e821f4 | 2011-04-12 23:21:44 +0000 | [diff] [blame] | 411 | return; |
Eric Christopher | c2697f8 | 2013-10-19 01:04:47 +0000 | [diff] [blame] | 412 | unsigned FileID = DD->getOrCreateSourceID(Ty.getFilename(), Ty.getDirectory(), |
| 413 | getUniqueID()); |
Devang Patel | 0e821f4 | 2011-04-12 23:21:44 +0000 | [diff] [blame] | 414 | assert(FileID && "Invalid file id"); |
David Blaikie | f244319 | 2013-10-21 17:28:37 +0000 | [diff] [blame] | 415 | addUInt(Die, dwarf::DW_AT_decl_file, None, FileID); |
| 416 | addUInt(Die, dwarf::DW_AT_decl_line, None, Line); |
Devang Patel | 0e821f4 | 2011-04-12 23:21:44 +0000 | [diff] [blame] | 417 | } |
| 418 | |
| 419 | /// addSourceLine - Add location information to specified debug information |
| 420 | /// entry. |
Eric Christopher | a5a7942 | 2013-12-09 23:32:48 +0000 | [diff] [blame] | 421 | void DwarfUnit::addSourceLine(DIE *Die, DIObjCProperty Ty) { |
David Blaikie | 5201930 | 2014-02-11 23:57:03 +0000 | [diff] [blame^] | 422 | assert(Ty.isObjCProperty()); |
Eric Christopher | 70e1bd8 | 2012-03-29 08:42:56 +0000 | [diff] [blame] | 423 | |
| 424 | unsigned Line = Ty.getLineNumber(); |
| 425 | if (Line == 0) |
| 426 | return; |
| 427 | DIFile File = Ty.getFile(); |
Eric Christopher | 7b30f2e4 | 2012-11-21 00:34:35 +0000 | [diff] [blame] | 428 | unsigned FileID = DD->getOrCreateSourceID(File.getFilename(), |
Manman Ren | 1e42720 | 2013-03-07 01:42:00 +0000 | [diff] [blame] | 429 | File.getDirectory(), getUniqueID()); |
Eric Christopher | 70e1bd8 | 2012-03-29 08:42:56 +0000 | [diff] [blame] | 430 | assert(FileID && "Invalid file id"); |
David Blaikie | f244319 | 2013-10-21 17:28:37 +0000 | [diff] [blame] | 431 | addUInt(Die, dwarf::DW_AT_decl_file, None, FileID); |
| 432 | addUInt(Die, dwarf::DW_AT_decl_line, None, Line); |
Eric Christopher | 70e1bd8 | 2012-03-29 08:42:56 +0000 | [diff] [blame] | 433 | } |
| 434 | |
| 435 | /// addSourceLine - Add location information to specified debug information |
| 436 | /// entry. |
Eric Christopher | a5a7942 | 2013-12-09 23:32:48 +0000 | [diff] [blame] | 437 | void DwarfUnit::addSourceLine(DIE *Die, DINameSpace NS) { |
David Blaikie | 5201930 | 2014-02-11 23:57:03 +0000 | [diff] [blame^] | 438 | assert(NS.Verify()); |
Devang Patel | 0e821f4 | 2011-04-12 23:21:44 +0000 | [diff] [blame] | 439 | |
| 440 | unsigned Line = NS.getLineNumber(); |
| 441 | if (Line == 0) |
| 442 | return; |
| 443 | StringRef FN = NS.getFilename(); |
| 444 | |
Eric Christopher | c2697f8 | 2013-10-19 01:04:47 +0000 | [diff] [blame] | 445 | unsigned FileID = |
| 446 | DD->getOrCreateSourceID(FN, NS.getDirectory(), getUniqueID()); |
Devang Patel | 0e821f4 | 2011-04-12 23:21:44 +0000 | [diff] [blame] | 447 | assert(FileID && "Invalid file id"); |
David Blaikie | f244319 | 2013-10-21 17:28:37 +0000 | [diff] [blame] | 448 | addUInt(Die, dwarf::DW_AT_decl_file, None, FileID); |
| 449 | addUInt(Die, dwarf::DW_AT_decl_line, None, Line); |
Devang Patel | 0e821f4 | 2011-04-12 23:21:44 +0000 | [diff] [blame] | 450 | } |
| 451 | |
Eric Christopher | 92331fd | 2012-11-21 00:34:38 +0000 | [diff] [blame] | 452 | /// addVariableAddress - Add DW_AT_location attribute for a |
Devang Patel | 77dc541 | 2011-04-27 22:45:24 +0000 | [diff] [blame] | 453 | /// DbgVariable based on provided MachineLocation. |
Eric Christopher | a5a7942 | 2013-12-09 23:32:48 +0000 | [diff] [blame] | 454 | void DwarfUnit::addVariableAddress(const DbgVariable &DV, DIE *Die, |
| 455 | MachineLocation Location) { |
Eric Christopher | bf2d23c | 2013-06-24 21:07:27 +0000 | [diff] [blame] | 456 | if (DV.variableHasComplexAddress()) |
Devang Patel | 0e821f4 | 2011-04-12 23:21:44 +0000 | [diff] [blame] | 457 | addComplexAddress(DV, Die, dwarf::DW_AT_location, Location); |
Eric Christopher | bf2d23c | 2013-06-24 21:07:27 +0000 | [diff] [blame] | 458 | else if (DV.isBlockByrefVariable()) |
Devang Patel | 0e821f4 | 2011-04-12 23:21:44 +0000 | [diff] [blame] | 459 | addBlockByrefAddress(DV, Die, dwarf::DW_AT_location, Location); |
| 460 | else |
David Blaikie | ea2605d | 2013-06-20 00:25:24 +0000 | [diff] [blame] | 461 | addAddress(Die, dwarf::DW_AT_location, Location, |
Eric Christopher | bf2d23c | 2013-06-24 21:07:27 +0000 | [diff] [blame] | 462 | DV.getVariable().isIndirect()); |
Devang Patel | 0e821f4 | 2011-04-12 23:21:44 +0000 | [diff] [blame] | 463 | } |
| 464 | |
Devang Patel | ba5fbf1 | 2011-04-26 19:06:18 +0000 | [diff] [blame] | 465 | /// addRegisterOp - Add register operand. |
Eric Christopher | a5a7942 | 2013-12-09 23:32:48 +0000 | [diff] [blame] | 466 | void DwarfUnit::addRegisterOp(DIEBlock *TheDie, unsigned Reg) { |
Devang Patel | ba5fbf1 | 2011-04-26 19:06:18 +0000 | [diff] [blame] | 467 | const TargetRegisterInfo *RI = Asm->TM.getRegisterInfo(); |
Adrian Prantl | cbcd578 | 2014-02-11 22:22:15 +0000 | [diff] [blame] | 468 | int DWReg = RI->getDwarfRegNum(Reg, false); |
| 469 | bool isSubRegister = DWReg < 0; |
| 470 | |
| 471 | unsigned Idx = 0; |
| 472 | |
| 473 | // Go up the super-register chain until we hit a valid dwarf register number. |
| 474 | for (MCSuperRegIterator SR(Reg, RI); SR.isValid() && DWReg < 0; ++SR) { |
| 475 | DWReg = RI->getDwarfRegNum(*SR, false); |
| 476 | if (DWReg >= 0) |
| 477 | Idx = RI->getSubRegIndex(*SR, Reg); |
| 478 | } |
| 479 | |
| 480 | if (DWReg < 0) { |
| 481 | DEBUG(llvm::dbgs() << "Invalid Dwarf register number.\n"); |
| 482 | addUInt(TheDie, dwarf::DW_FORM_data1, dwarf::DW_OP_nop); |
| 483 | return; |
| 484 | } |
| 485 | |
| 486 | // Emit register |
Devang Patel | ba5fbf1 | 2011-04-26 19:06:18 +0000 | [diff] [blame] | 487 | if (DWReg < 32) |
David Blaikie | f244319 | 2013-10-21 17:28:37 +0000 | [diff] [blame] | 488 | addUInt(TheDie, dwarf::DW_FORM_data1, dwarf::DW_OP_reg0 + DWReg); |
Devang Patel | ba5fbf1 | 2011-04-26 19:06:18 +0000 | [diff] [blame] | 489 | else { |
David Blaikie | f244319 | 2013-10-21 17:28:37 +0000 | [diff] [blame] | 490 | addUInt(TheDie, dwarf::DW_FORM_data1, dwarf::DW_OP_regx); |
| 491 | addUInt(TheDie, dwarf::DW_FORM_udata, DWReg); |
Devang Patel | ba5fbf1 | 2011-04-26 19:06:18 +0000 | [diff] [blame] | 492 | } |
Adrian Prantl | cbcd578 | 2014-02-11 22:22:15 +0000 | [diff] [blame] | 493 | |
| 494 | // Emit Mask |
| 495 | if (isSubRegister) { |
| 496 | unsigned Size = RI->getSubRegIdxSize(Idx); |
| 497 | unsigned Offset = RI->getSubRegIdxOffset(Idx); |
| 498 | if (Offset > 0) { |
| 499 | addUInt(TheDie, dwarf::DW_FORM_data1, dwarf::DW_OP_bit_piece); |
| 500 | addUInt(TheDie, dwarf::DW_FORM_data1, Size); |
| 501 | addUInt(TheDie, dwarf::DW_FORM_data1, Offset); |
| 502 | } else { |
| 503 | addUInt(TheDie, dwarf::DW_FORM_data1, dwarf::DW_OP_piece); |
| 504 | addUInt(TheDie, dwarf::DW_FORM_data1, Size); |
| 505 | } |
| 506 | } |
Devang Patel | ba5fbf1 | 2011-04-26 19:06:18 +0000 | [diff] [blame] | 507 | } |
| 508 | |
| 509 | /// addRegisterOffset - Add register offset. |
Eric Christopher | a5a7942 | 2013-12-09 23:32:48 +0000 | [diff] [blame] | 510 | void DwarfUnit::addRegisterOffset(DIEBlock *TheDie, unsigned Reg, |
| 511 | int64_t Offset) { |
Devang Patel | ba5fbf1 | 2011-04-26 19:06:18 +0000 | [diff] [blame] | 512 | const TargetRegisterInfo *RI = Asm->TM.getRegisterInfo(); |
| 513 | unsigned DWReg = RI->getDwarfRegNum(Reg, false); |
| 514 | const TargetRegisterInfo *TRI = Asm->TM.getRegisterInfo(); |
| 515 | if (Reg == TRI->getFrameRegister(*Asm->MF)) |
| 516 | // If variable offset is based in frame register then use fbreg. |
David Blaikie | f244319 | 2013-10-21 17:28:37 +0000 | [diff] [blame] | 517 | addUInt(TheDie, dwarf::DW_FORM_data1, dwarf::DW_OP_fbreg); |
Devang Patel | ba5fbf1 | 2011-04-26 19:06:18 +0000 | [diff] [blame] | 518 | else if (DWReg < 32) |
David Blaikie | f244319 | 2013-10-21 17:28:37 +0000 | [diff] [blame] | 519 | addUInt(TheDie, dwarf::DW_FORM_data1, dwarf::DW_OP_breg0 + DWReg); |
Devang Patel | ba5fbf1 | 2011-04-26 19:06:18 +0000 | [diff] [blame] | 520 | else { |
David Blaikie | f244319 | 2013-10-21 17:28:37 +0000 | [diff] [blame] | 521 | addUInt(TheDie, dwarf::DW_FORM_data1, dwarf::DW_OP_bregx); |
| 522 | addUInt(TheDie, dwarf::DW_FORM_udata, DWReg); |
Devang Patel | ba5fbf1 | 2011-04-26 19:06:18 +0000 | [diff] [blame] | 523 | } |
David Blaikie | f244319 | 2013-10-21 17:28:37 +0000 | [diff] [blame] | 524 | addSInt(TheDie, dwarf::DW_FORM_sdata, Offset); |
Devang Patel | ba5fbf1 | 2011-04-26 19:06:18 +0000 | [diff] [blame] | 525 | } |
| 526 | |
| 527 | /// addAddress - Add an address attribute to a die based on the location |
| 528 | /// provided. |
Eric Christopher | a5a7942 | 2013-12-09 23:32:48 +0000 | [diff] [blame] | 529 | void DwarfUnit::addAddress(DIE *Die, dwarf::Attribute Attribute, |
| 530 | const MachineLocation &Location, bool Indirect) { |
Devang Patel | ba5fbf1 | 2011-04-26 19:06:18 +0000 | [diff] [blame] | 531 | DIEBlock *Block = new (DIEValueAllocator) DIEBlock(); |
| 532 | |
David Blaikie | ea2605d | 2013-06-20 00:25:24 +0000 | [diff] [blame] | 533 | if (Location.isReg() && !Indirect) |
Devang Patel | ba5fbf1 | 2011-04-26 19:06:18 +0000 | [diff] [blame] | 534 | addRegisterOp(Block, Location.getReg()); |
David Blaikie | ea2605d | 2013-06-20 00:25:24 +0000 | [diff] [blame] | 535 | else { |
Devang Patel | ba5fbf1 | 2011-04-26 19:06:18 +0000 | [diff] [blame] | 536 | addRegisterOffset(Block, Location.getReg(), Location.getOffset()); |
David Blaikie | ea2605d | 2013-06-20 00:25:24 +0000 | [diff] [blame] | 537 | if (Indirect && !Location.isReg()) { |
David Blaikie | f244319 | 2013-10-21 17:28:37 +0000 | [diff] [blame] | 538 | addUInt(Block, dwarf::DW_FORM_data1, dwarf::DW_OP_deref); |
David Blaikie | ea2605d | 2013-06-20 00:25:24 +0000 | [diff] [blame] | 539 | } |
| 540 | } |
Devang Patel | ba5fbf1 | 2011-04-26 19:06:18 +0000 | [diff] [blame] | 541 | |
| 542 | // Now attach the location information to the DIE. |
David Blaikie | f244319 | 2013-10-21 17:28:37 +0000 | [diff] [blame] | 543 | addBlock(Die, Attribute, Block); |
Devang Patel | ba5fbf1 | 2011-04-26 19:06:18 +0000 | [diff] [blame] | 544 | } |
| 545 | |
Devang Patel | 0e821f4 | 2011-04-12 23:21:44 +0000 | [diff] [blame] | 546 | /// addComplexAddress - Start with the address based on the location provided, |
| 547 | /// and generate the DWARF information necessary to find the actual variable |
Eric Christopher | 1c70b67 | 2013-12-05 00:13:15 +0000 | [diff] [blame] | 548 | /// given the extra address information encoded in the DbgVariable, starting |
| 549 | /// from the starting location. Add the DWARF information to the die. |
Devang Patel | 0e821f4 | 2011-04-12 23:21:44 +0000 | [diff] [blame] | 550 | /// |
Eric Christopher | a5a7942 | 2013-12-09 23:32:48 +0000 | [diff] [blame] | 551 | void DwarfUnit::addComplexAddress(const DbgVariable &DV, DIE *Die, |
| 552 | dwarf::Attribute Attribute, |
| 553 | const MachineLocation &Location) { |
Devang Patel | 0e821f4 | 2011-04-12 23:21:44 +0000 | [diff] [blame] | 554 | DIEBlock *Block = new (DIEValueAllocator) DIEBlock(); |
Eric Christopher | bf2d23c | 2013-06-24 21:07:27 +0000 | [diff] [blame] | 555 | unsigned N = DV.getNumAddrElements(); |
Devang Patel | 3e02153 | 2011-04-28 02:22:40 +0000 | [diff] [blame] | 556 | unsigned i = 0; |
| 557 | if (Location.isReg()) { |
Eric Christopher | bf2d23c | 2013-06-24 21:07:27 +0000 | [diff] [blame] | 558 | if (N >= 2 && DV.getAddrElement(0) == DIBuilder::OpPlus) { |
Devang Patel | 3e02153 | 2011-04-28 02:22:40 +0000 | [diff] [blame] | 559 | // If first address element is OpPlus then emit |
| 560 | // DW_OP_breg + Offset instead of DW_OP_reg + Offset. |
Eric Christopher | bf2d23c | 2013-06-24 21:07:27 +0000 | [diff] [blame] | 561 | addRegisterOffset(Block, Location.getReg(), DV.getAddrElement(1)); |
Devang Patel | 3e02153 | 2011-04-28 02:22:40 +0000 | [diff] [blame] | 562 | i = 2; |
| 563 | } else |
| 564 | addRegisterOp(Block, Location.getReg()); |
Eric Christopher | c2697f8 | 2013-10-19 01:04:47 +0000 | [diff] [blame] | 565 | } else |
Devang Patel | ba5fbf1 | 2011-04-26 19:06:18 +0000 | [diff] [blame] | 566 | addRegisterOffset(Block, Location.getReg(), Location.getOffset()); |
Devang Patel | 0e821f4 | 2011-04-12 23:21:44 +0000 | [diff] [blame] | 567 | |
Eric Christopher | c2697f8 | 2013-10-19 01:04:47 +0000 | [diff] [blame] | 568 | for (; i < N; ++i) { |
Eric Christopher | bf2d23c | 2013-06-24 21:07:27 +0000 | [diff] [blame] | 569 | uint64_t Element = DV.getAddrElement(i); |
Devang Patel | 0e821f4 | 2011-04-12 23:21:44 +0000 | [diff] [blame] | 570 | if (Element == DIBuilder::OpPlus) { |
David Blaikie | f244319 | 2013-10-21 17:28:37 +0000 | [diff] [blame] | 571 | addUInt(Block, dwarf::DW_FORM_data1, dwarf::DW_OP_plus_uconst); |
| 572 | addUInt(Block, dwarf::DW_FORM_udata, DV.getAddrElement(++i)); |
Devang Patel | 0e821f4 | 2011-04-12 23:21:44 +0000 | [diff] [blame] | 573 | } else if (Element == DIBuilder::OpDeref) { |
Eric Christopher | 4d25052 | 2012-05-08 18:56:00 +0000 | [diff] [blame] | 574 | if (!Location.isReg()) |
David Blaikie | f244319 | 2013-10-21 17:28:37 +0000 | [diff] [blame] | 575 | addUInt(Block, dwarf::DW_FORM_data1, dwarf::DW_OP_deref); |
Eric Christopher | c2697f8 | 2013-10-19 01:04:47 +0000 | [diff] [blame] | 576 | } else |
| 577 | llvm_unreachable("unknown DIBuilder Opcode"); |
Devang Patel | 0e821f4 | 2011-04-12 23:21:44 +0000 | [diff] [blame] | 578 | } |
| 579 | |
| 580 | // Now attach the location information to the DIE. |
David Blaikie | f244319 | 2013-10-21 17:28:37 +0000 | [diff] [blame] | 581 | addBlock(Die, Attribute, Block); |
Devang Patel | 0e821f4 | 2011-04-12 23:21:44 +0000 | [diff] [blame] | 582 | } |
| 583 | |
| 584 | /* Byref variables, in Blocks, are declared by the programmer as "SomeType |
| 585 | VarName;", but the compiler creates a __Block_byref_x_VarName struct, and |
| 586 | gives the variable VarName either the struct, or a pointer to the struct, as |
| 587 | its type. This is necessary for various behind-the-scenes things the |
| 588 | compiler needs to do with by-reference variables in Blocks. |
| 589 | |
| 590 | However, as far as the original *programmer* is concerned, the variable |
| 591 | should still have type 'SomeType', as originally declared. |
| 592 | |
| 593 | The function getBlockByrefType dives into the __Block_byref_x_VarName |
| 594 | struct to find the original type of the variable, which is then assigned to |
| 595 | the variable's Debug Information Entry as its real type. So far, so good. |
| 596 | However now the debugger will expect the variable VarName to have the type |
| 597 | SomeType. So we need the location attribute for the variable to be an |
| 598 | expression that explains to the debugger how to navigate through the |
| 599 | pointers and struct to find the actual variable of type SomeType. |
| 600 | |
| 601 | The following function does just that. We start by getting |
| 602 | the "normal" location for the variable. This will be the location |
| 603 | of either the struct __Block_byref_x_VarName or the pointer to the |
| 604 | struct __Block_byref_x_VarName. |
| 605 | |
| 606 | The struct will look something like: |
| 607 | |
| 608 | struct __Block_byref_x_VarName { |
| 609 | ... <various fields> |
| 610 | struct __Block_byref_x_VarName *forwarding; |
| 611 | ... <various other fields> |
| 612 | SomeType VarName; |
| 613 | ... <maybe more fields> |
| 614 | }; |
| 615 | |
| 616 | If we are given the struct directly (as our starting point) we |
| 617 | need to tell the debugger to: |
| 618 | |
| 619 | 1). Add the offset of the forwarding field. |
| 620 | |
| 621 | 2). Follow that pointer to get the real __Block_byref_x_VarName |
| 622 | struct to use (the real one may have been copied onto the heap). |
| 623 | |
| 624 | 3). Add the offset for the field VarName, to find the actual variable. |
| 625 | |
| 626 | If we started with a pointer to the struct, then we need to |
| 627 | dereference that pointer first, before the other steps. |
| 628 | Translating this into DWARF ops, we will need to append the following |
| 629 | to the current location description for the variable: |
| 630 | |
| 631 | DW_OP_deref -- optional, if we start with a pointer |
| 632 | DW_OP_plus_uconst <forward_fld_offset> |
| 633 | DW_OP_deref |
| 634 | DW_OP_plus_uconst <varName_fld_offset> |
| 635 | |
| 636 | That is what this function does. */ |
| 637 | |
| 638 | /// addBlockByrefAddress - Start with the address based on the location |
| 639 | /// provided, and generate the DWARF information necessary to find the |
| 640 | /// actual Block variable (navigating the Block struct) based on the |
| 641 | /// starting location. Add the DWARF information to the die. For |
| 642 | /// more information, read large comment just above here. |
| 643 | /// |
Eric Christopher | a5a7942 | 2013-12-09 23:32:48 +0000 | [diff] [blame] | 644 | void DwarfUnit::addBlockByrefAddress(const DbgVariable &DV, DIE *Die, |
| 645 | dwarf::Attribute Attribute, |
| 646 | const MachineLocation &Location) { |
Eric Christopher | bf2d23c | 2013-06-24 21:07:27 +0000 | [diff] [blame] | 647 | DIType Ty = DV.getType(); |
Devang Patel | 0e821f4 | 2011-04-12 23:21:44 +0000 | [diff] [blame] | 648 | DIType TmpTy = Ty; |
Eric Christopher | 31b0576 | 2013-08-08 01:41:00 +0000 | [diff] [blame] | 649 | uint16_t Tag = Ty.getTag(); |
Devang Patel | 0e821f4 | 2011-04-12 23:21:44 +0000 | [diff] [blame] | 650 | bool isPointer = false; |
| 651 | |
Eric Christopher | bf2d23c | 2013-06-24 21:07:27 +0000 | [diff] [blame] | 652 | StringRef varName = DV.getName(); |
Devang Patel | 0e821f4 | 2011-04-12 23:21:44 +0000 | [diff] [blame] | 653 | |
| 654 | if (Tag == dwarf::DW_TAG_pointer_type) { |
David Blaikie | 4f6bf27a | 2013-11-18 23:33:32 +0000 | [diff] [blame] | 655 | DIDerivedType DTy(Ty); |
Manman Ren | 93b3090 | 2013-10-08 18:42:58 +0000 | [diff] [blame] | 656 | TmpTy = resolve(DTy.getTypeDerivedFrom()); |
Devang Patel | 0e821f4 | 2011-04-12 23:21:44 +0000 | [diff] [blame] | 657 | isPointer = true; |
| 658 | } |
| 659 | |
David Blaikie | 4f6bf27a | 2013-11-18 23:33:32 +0000 | [diff] [blame] | 660 | DICompositeType blockStruct(TmpTy); |
Devang Patel | 0e821f4 | 2011-04-12 23:21:44 +0000 | [diff] [blame] | 661 | |
| 662 | // Find the __forwarding field and the variable field in the __Block_byref |
| 663 | // struct. |
| 664 | DIArray Fields = blockStruct.getTypeArray(); |
David Blaikie | 4f6bf27a | 2013-11-18 23:33:32 +0000 | [diff] [blame] | 665 | DIDerivedType varField; |
| 666 | DIDerivedType forwardingField; |
Devang Patel | 0e821f4 | 2011-04-12 23:21:44 +0000 | [diff] [blame] | 667 | |
| 668 | for (unsigned i = 0, N = Fields.getNumElements(); i < N; ++i) { |
David Blaikie | 4f6bf27a | 2013-11-18 23:33:32 +0000 | [diff] [blame] | 669 | DIDerivedType DT(Fields.getElement(i)); |
Devang Patel | 0e821f4 | 2011-04-12 23:21:44 +0000 | [diff] [blame] | 670 | StringRef fieldName = DT.getName(); |
| 671 | if (fieldName == "__forwarding") |
David Blaikie | 4f6bf27a | 2013-11-18 23:33:32 +0000 | [diff] [blame] | 672 | forwardingField = DT; |
Devang Patel | 0e821f4 | 2011-04-12 23:21:44 +0000 | [diff] [blame] | 673 | else if (fieldName == varName) |
David Blaikie | 4f6bf27a | 2013-11-18 23:33:32 +0000 | [diff] [blame] | 674 | varField = DT; |
Devang Patel | 0e821f4 | 2011-04-12 23:21:44 +0000 | [diff] [blame] | 675 | } |
| 676 | |
| 677 | // Get the offsets for the forwarding field and the variable field. |
David Blaikie | 4f6bf27a | 2013-11-18 23:33:32 +0000 | [diff] [blame] | 678 | unsigned forwardingFieldOffset = forwardingField.getOffsetInBits() >> 3; |
| 679 | unsigned varFieldOffset = varField.getOffsetInBits() >> 2; |
Devang Patel | 0e821f4 | 2011-04-12 23:21:44 +0000 | [diff] [blame] | 680 | |
| 681 | // Decode the original location, and use that as the start of the byref |
| 682 | // variable's location. |
Devang Patel | 0e821f4 | 2011-04-12 23:21:44 +0000 | [diff] [blame] | 683 | DIEBlock *Block = new (DIEValueAllocator) DIEBlock(); |
| 684 | |
Eric Christopher | ef9d710 | 2012-07-04 02:02:18 +0000 | [diff] [blame] | 685 | if (Location.isReg()) |
| 686 | addRegisterOp(Block, Location.getReg()); |
| 687 | else |
| 688 | addRegisterOffset(Block, Location.getReg(), Location.getOffset()); |
Devang Patel | 0e821f4 | 2011-04-12 23:21:44 +0000 | [diff] [blame] | 689 | |
| 690 | // If we started with a pointer to the __Block_byref... struct, then |
| 691 | // the first thing we need to do is dereference the pointer (DW_OP_deref). |
| 692 | if (isPointer) |
David Blaikie | f244319 | 2013-10-21 17:28:37 +0000 | [diff] [blame] | 693 | addUInt(Block, dwarf::DW_FORM_data1, dwarf::DW_OP_deref); |
Devang Patel | 0e821f4 | 2011-04-12 23:21:44 +0000 | [diff] [blame] | 694 | |
| 695 | // Next add the offset for the '__forwarding' field: |
| 696 | // DW_OP_plus_uconst ForwardingFieldOffset. Note there's no point in |
| 697 | // adding the offset if it's 0. |
| 698 | if (forwardingFieldOffset > 0) { |
David Blaikie | f244319 | 2013-10-21 17:28:37 +0000 | [diff] [blame] | 699 | addUInt(Block, dwarf::DW_FORM_data1, dwarf::DW_OP_plus_uconst); |
| 700 | addUInt(Block, dwarf::DW_FORM_udata, forwardingFieldOffset); |
Devang Patel | 0e821f4 | 2011-04-12 23:21:44 +0000 | [diff] [blame] | 701 | } |
| 702 | |
| 703 | // Now dereference the __forwarding field to get to the real __Block_byref |
| 704 | // struct: DW_OP_deref. |
David Blaikie | f244319 | 2013-10-21 17:28:37 +0000 | [diff] [blame] | 705 | addUInt(Block, dwarf::DW_FORM_data1, dwarf::DW_OP_deref); |
Devang Patel | 0e821f4 | 2011-04-12 23:21:44 +0000 | [diff] [blame] | 706 | |
| 707 | // Now that we've got the real __Block_byref... struct, add the offset |
| 708 | // for the variable's field to get to the location of the actual variable: |
| 709 | // DW_OP_plus_uconst varFieldOffset. Again, don't add if it's 0. |
| 710 | if (varFieldOffset > 0) { |
David Blaikie | f244319 | 2013-10-21 17:28:37 +0000 | [diff] [blame] | 711 | addUInt(Block, dwarf::DW_FORM_data1, dwarf::DW_OP_plus_uconst); |
| 712 | addUInt(Block, dwarf::DW_FORM_udata, varFieldOffset); |
Devang Patel | 0e821f4 | 2011-04-12 23:21:44 +0000 | [diff] [blame] | 713 | } |
| 714 | |
| 715 | // Now attach the location information to the DIE. |
David Blaikie | f244319 | 2013-10-21 17:28:37 +0000 | [diff] [blame] | 716 | addBlock(Die, Attribute, Block); |
Devang Patel | 0e821f4 | 2011-04-12 23:21:44 +0000 | [diff] [blame] | 717 | } |
| 718 | |
Devang Patel | bcd50a1 | 2011-07-20 21:57:04 +0000 | [diff] [blame] | 719 | /// isTypeSigned - Return true if the type is signed. |
Manman Ren | b338860 | 2013-10-05 01:43:03 +0000 | [diff] [blame] | 720 | static bool isTypeSigned(DwarfDebug *DD, DIType Ty, int *SizeInBits) { |
Devang Patel | bcd50a1 | 2011-07-20 21:57:04 +0000 | [diff] [blame] | 721 | if (Ty.isDerivedType()) |
Manman Ren | b338860 | 2013-10-05 01:43:03 +0000 | [diff] [blame] | 722 | return isTypeSigned(DD, DD->resolve(DIDerivedType(Ty).getTypeDerivedFrom()), |
| 723 | SizeInBits); |
Devang Patel | bcd50a1 | 2011-07-20 21:57:04 +0000 | [diff] [blame] | 724 | if (Ty.isBasicType()) |
Eric Christopher | c2697f8 | 2013-10-19 01:04:47 +0000 | [diff] [blame] | 725 | if (DIBasicType(Ty).getEncoding() == dwarf::DW_ATE_signed || |
| 726 | DIBasicType(Ty).getEncoding() == dwarf::DW_ATE_signed_char) { |
Devang Patel | bcd50a1 | 2011-07-20 21:57:04 +0000 | [diff] [blame] | 727 | *SizeInBits = Ty.getSizeInBits(); |
| 728 | return true; |
| 729 | } |
| 730 | return false; |
| 731 | } |
| 732 | |
Manman Ren | b338860 | 2013-10-05 01:43:03 +0000 | [diff] [blame] | 733 | /// Return true if type encoding is unsigned. |
| 734 | static bool isUnsignedDIType(DwarfDebug *DD, DIType Ty) { |
| 735 | DIDerivedType DTy(Ty); |
| 736 | if (DTy.isDerivedType()) |
| 737 | return isUnsignedDIType(DD, DD->resolve(DTy.getTypeDerivedFrom())); |
| 738 | |
| 739 | DIBasicType BTy(Ty); |
| 740 | if (BTy.isBasicType()) { |
| 741 | unsigned Encoding = BTy.getEncoding(); |
| 742 | if (Encoding == dwarf::DW_ATE_unsigned || |
| 743 | Encoding == dwarf::DW_ATE_unsigned_char || |
| 744 | Encoding == dwarf::DW_ATE_boolean) |
| 745 | return true; |
| 746 | } |
| 747 | return false; |
| 748 | } |
| 749 | |
| 750 | /// If this type is derived from a base type then return base type size. |
Manman Ren | bda410f | 2013-10-08 18:46:58 +0000 | [diff] [blame] | 751 | static uint64_t getBaseTypeSize(DwarfDebug *DD, DIDerivedType Ty) { |
Manman Ren | b338860 | 2013-10-05 01:43:03 +0000 | [diff] [blame] | 752 | unsigned Tag = Ty.getTag(); |
| 753 | |
| 754 | if (Tag != dwarf::DW_TAG_member && Tag != dwarf::DW_TAG_typedef && |
| 755 | Tag != dwarf::DW_TAG_const_type && Tag != dwarf::DW_TAG_volatile_type && |
| 756 | Tag != dwarf::DW_TAG_restrict_type) |
| 757 | return Ty.getSizeInBits(); |
| 758 | |
| 759 | DIType BaseType = DD->resolve(Ty.getTypeDerivedFrom()); |
| 760 | |
| 761 | // If this type is not derived from any type then take conservative approach. |
| 762 | if (!BaseType.isValid()) |
| 763 | return Ty.getSizeInBits(); |
| 764 | |
| 765 | // If this is a derived type, go ahead and get the base type, unless it's a |
| 766 | // reference then it's just the size of the field. Pointer types have no need |
| 767 | // of this since they're a different type of qualification on the type. |
| 768 | if (BaseType.getTag() == dwarf::DW_TAG_reference_type || |
| 769 | BaseType.getTag() == dwarf::DW_TAG_rvalue_reference_type) |
| 770 | return Ty.getSizeInBits(); |
| 771 | |
| 772 | if (BaseType.isDerivedType()) |
Manman Ren | bda410f | 2013-10-08 18:46:58 +0000 | [diff] [blame] | 773 | return getBaseTypeSize(DD, DIDerivedType(BaseType)); |
Manman Ren | b338860 | 2013-10-05 01:43:03 +0000 | [diff] [blame] | 774 | |
| 775 | return BaseType.getSizeInBits(); |
| 776 | } |
| 777 | |
Devang Patel | 0e821f4 | 2011-04-12 23:21:44 +0000 | [diff] [blame] | 778 | /// addConstantValue - Add constant value entry in variable DIE. |
Eric Christopher | a5a7942 | 2013-12-09 23:32:48 +0000 | [diff] [blame] | 779 | void DwarfUnit::addConstantValue(DIE *Die, const MachineOperand &MO, |
| 780 | DIType Ty) { |
David Blaikie | a1e813d | 2013-05-10 21:52:07 +0000 | [diff] [blame] | 781 | // FIXME: This is a bit conservative/simple - it emits negative values at |
| 782 | // their maximum bit width which is a bit unfortunate (& doesn't prefer |
| 783 | // udata/sdata over dataN as suggested by the DWARF spec) |
Nick Lewycky | 654f5ce | 2011-10-26 22:55:33 +0000 | [diff] [blame] | 784 | assert(MO.isImm() && "Invalid machine operand!"); |
Devang Patel | bcd50a1 | 2011-07-20 21:57:04 +0000 | [diff] [blame] | 785 | int SizeInBits = -1; |
Manman Ren | b338860 | 2013-10-05 01:43:03 +0000 | [diff] [blame] | 786 | bool SignedConstant = isTypeSigned(DD, Ty, &SizeInBits); |
David Blaikie | f244319 | 2013-10-21 17:28:37 +0000 | [diff] [blame] | 787 | dwarf::Form Form; |
Devang Patel | f1d0470 | 2011-05-27 18:15:52 +0000 | [diff] [blame] | 788 | |
Eric Christopher | 9d1daa8 | 2013-08-27 23:49:04 +0000 | [diff] [blame] | 789 | // If we're a signed constant definitely use sdata. |
| 790 | if (SignedConstant) { |
| 791 | addSInt(Die, dwarf::DW_AT_const_value, dwarf::DW_FORM_sdata, MO.getImm()); |
| 792 | return; |
| 793 | } |
| 794 | |
| 795 | // Else use data for now unless it's larger than we can deal with. |
| 796 | switch (SizeInBits) { |
| 797 | case 8: |
| 798 | Form = dwarf::DW_FORM_data1; |
| 799 | break; |
| 800 | case 16: |
| 801 | Form = dwarf::DW_FORM_data2; |
| 802 | break; |
| 803 | case 32: |
| 804 | Form = dwarf::DW_FORM_data4; |
| 805 | break; |
| 806 | case 64: |
| 807 | Form = dwarf::DW_FORM_data8; |
| 808 | break; |
| 809 | default: |
| 810 | Form = dwarf::DW_FORM_udata; |
| 811 | addUInt(Die, dwarf::DW_AT_const_value, Form, MO.getImm()); |
| 812 | return; |
| 813 | } |
| 814 | addUInt(Die, dwarf::DW_AT_const_value, Form, MO.getImm()); |
Devang Patel | 0e821f4 | 2011-04-12 23:21:44 +0000 | [diff] [blame] | 815 | } |
| 816 | |
| 817 | /// addConstantFPValue - Add constant value entry in variable DIE. |
Eric Christopher | a5a7942 | 2013-12-09 23:32:48 +0000 | [diff] [blame] | 818 | void DwarfUnit::addConstantFPValue(DIE *Die, const MachineOperand &MO) { |
Eric Christopher | c2697f8 | 2013-10-19 01:04:47 +0000 | [diff] [blame] | 819 | assert(MO.isFPImm() && "Invalid machine operand!"); |
Devang Patel | 0e821f4 | 2011-04-12 23:21:44 +0000 | [diff] [blame] | 820 | DIEBlock *Block = new (DIEValueAllocator) DIEBlock(); |
| 821 | APFloat FPImm = MO.getFPImm()->getValueAPF(); |
| 822 | |
| 823 | // Get the raw data form of the floating point. |
| 824 | const APInt FltVal = FPImm.bitcastToAPInt(); |
Eric Christopher | c2697f8 | 2013-10-19 01:04:47 +0000 | [diff] [blame] | 825 | const char *FltPtr = (const char *)FltVal.getRawData(); |
Devang Patel | 0e821f4 | 2011-04-12 23:21:44 +0000 | [diff] [blame] | 826 | |
| 827 | int NumBytes = FltVal.getBitWidth() / 8; // 8 bits per byte. |
Micah Villmow | cdfe20b | 2012-10-08 16:38:25 +0000 | [diff] [blame] | 828 | bool LittleEndian = Asm->getDataLayout().isLittleEndian(); |
Devang Patel | 0e821f4 | 2011-04-12 23:21:44 +0000 | [diff] [blame] | 829 | int Incr = (LittleEndian ? 1 : -1); |
| 830 | int Start = (LittleEndian ? 0 : NumBytes - 1); |
| 831 | int Stop = (LittleEndian ? NumBytes : -1); |
| 832 | |
| 833 | // Output the constant to DWARF one byte at a time. |
| 834 | for (; Start != Stop; Start += Incr) |
Eric Christopher | 98b7f17 | 2013-11-11 18:52:36 +0000 | [diff] [blame] | 835 | addUInt(Block, dwarf::DW_FORM_data1, (unsigned char)0xFF & FltPtr[Start]); |
Devang Patel | 0e821f4 | 2011-04-12 23:21:44 +0000 | [diff] [blame] | 836 | |
David Blaikie | f244319 | 2013-10-21 17:28:37 +0000 | [diff] [blame] | 837 | addBlock(Die, dwarf::DW_AT_const_value, Block); |
Devang Patel | 0e821f4 | 2011-04-12 23:21:44 +0000 | [diff] [blame] | 838 | } |
| 839 | |
David Blaikie | a39a76e | 2013-01-20 01:18:01 +0000 | [diff] [blame] | 840 | /// addConstantFPValue - Add constant value entry in variable DIE. |
Eric Christopher | a5a7942 | 2013-12-09 23:32:48 +0000 | [diff] [blame] | 841 | void DwarfUnit::addConstantFPValue(DIE *Die, const ConstantFP *CFP) { |
Eric Christopher | 9d1daa8 | 2013-08-27 23:49:04 +0000 | [diff] [blame] | 842 | // Pass this down to addConstantValue as an unsigned bag of bits. |
| 843 | addConstantValue(Die, CFP->getValueAPF().bitcastToAPInt(), true); |
David Blaikie | a39a76e | 2013-01-20 01:18:01 +0000 | [diff] [blame] | 844 | } |
| 845 | |
Devang Patel | 0e821f4 | 2011-04-12 23:21:44 +0000 | [diff] [blame] | 846 | /// addConstantValue - Add constant value entry in variable DIE. |
Eric Christopher | a5a7942 | 2013-12-09 23:32:48 +0000 | [diff] [blame] | 847 | void DwarfUnit::addConstantValue(DIE *Die, const ConstantInt *CI, |
| 848 | bool Unsigned) { |
Eric Christopher | 78fcf490 | 2013-07-03 01:08:30 +0000 | [diff] [blame] | 849 | addConstantValue(Die, CI->getValue(), Unsigned); |
David Blaikie | a39a76e | 2013-01-20 01:18:01 +0000 | [diff] [blame] | 850 | } |
| 851 | |
| 852 | // addConstantValue - Add constant value entry in variable DIE. |
Eric Christopher | a5a7942 | 2013-12-09 23:32:48 +0000 | [diff] [blame] | 853 | void DwarfUnit::addConstantValue(DIE *Die, const APInt &Val, bool Unsigned) { |
David Blaikie | a39a76e | 2013-01-20 01:18:01 +0000 | [diff] [blame] | 854 | unsigned CIBitWidth = Val.getBitWidth(); |
Devang Patel | 8816bbc | 2011-05-28 00:39:18 +0000 | [diff] [blame] | 855 | if (CIBitWidth <= 64) { |
Eric Christopher | 9d1daa8 | 2013-08-27 23:49:04 +0000 | [diff] [blame] | 856 | // If we're a signed constant definitely use sdata. |
| 857 | if (!Unsigned) { |
| 858 | addSInt(Die, dwarf::DW_AT_const_value, dwarf::DW_FORM_sdata, |
| 859 | Val.getSExtValue()); |
| 860 | return; |
Devang Patel | 8816bbc | 2011-05-28 00:39:18 +0000 | [diff] [blame] | 861 | } |
Eric Christopher | 9d1daa8 | 2013-08-27 23:49:04 +0000 | [diff] [blame] | 862 | |
| 863 | // Else use data for now unless it's larger than we can deal with. |
David Blaikie | f244319 | 2013-10-21 17:28:37 +0000 | [diff] [blame] | 864 | dwarf::Form Form; |
Eric Christopher | 9d1daa8 | 2013-08-27 23:49:04 +0000 | [diff] [blame] | 865 | switch (CIBitWidth) { |
| 866 | case 8: |
| 867 | Form = dwarf::DW_FORM_data1; |
| 868 | break; |
| 869 | case 16: |
| 870 | Form = dwarf::DW_FORM_data2; |
| 871 | break; |
| 872 | case 32: |
| 873 | Form = dwarf::DW_FORM_data4; |
| 874 | break; |
| 875 | case 64: |
| 876 | Form = dwarf::DW_FORM_data8; |
| 877 | break; |
| 878 | default: |
| 879 | addUInt(Die, dwarf::DW_AT_const_value, dwarf::DW_FORM_udata, |
| 880 | Val.getZExtValue()); |
| 881 | return; |
| 882 | } |
| 883 | addUInt(Die, dwarf::DW_AT_const_value, Form, Val.getZExtValue()); |
Eric Christopher | 78fcf490 | 2013-07-03 01:08:30 +0000 | [diff] [blame] | 884 | return; |
Devang Patel | 0e821f4 | 2011-04-12 23:21:44 +0000 | [diff] [blame] | 885 | } |
| 886 | |
| 887 | DIEBlock *Block = new (DIEValueAllocator) DIEBlock(); |
| 888 | |
| 889 | // Get the raw data form of the large APInt. |
NAKAMURA Takumi | 29ccdd8 | 2011-10-28 14:12:22 +0000 | [diff] [blame] | 890 | const uint64_t *Ptr64 = Val.getRawData(); |
Devang Patel | 0e821f4 | 2011-04-12 23:21:44 +0000 | [diff] [blame] | 891 | |
| 892 | int NumBytes = Val.getBitWidth() / 8; // 8 bits per byte. |
Micah Villmow | cdfe20b | 2012-10-08 16:38:25 +0000 | [diff] [blame] | 893 | bool LittleEndian = Asm->getDataLayout().isLittleEndian(); |
Devang Patel | 0e821f4 | 2011-04-12 23:21:44 +0000 | [diff] [blame] | 894 | |
| 895 | // Output the constant to DWARF one byte at a time. |
NAKAMURA Takumi | 29ccdd8 | 2011-10-28 14:12:22 +0000 | [diff] [blame] | 896 | for (int i = 0; i < NumBytes; i++) { |
| 897 | uint8_t c; |
| 898 | if (LittleEndian) |
| 899 | c = Ptr64[i / 8] >> (8 * (i & 7)); |
| 900 | else |
| 901 | c = Ptr64[(NumBytes - 1 - i) / 8] >> (8 * ((NumBytes - 1 - i) & 7)); |
David Blaikie | f244319 | 2013-10-21 17:28:37 +0000 | [diff] [blame] | 902 | addUInt(Block, dwarf::DW_FORM_data1, c); |
NAKAMURA Takumi | 29ccdd8 | 2011-10-28 14:12:22 +0000 | [diff] [blame] | 903 | } |
Devang Patel | 0e821f4 | 2011-04-12 23:21:44 +0000 | [diff] [blame] | 904 | |
David Blaikie | f244319 | 2013-10-21 17:28:37 +0000 | [diff] [blame] | 905 | addBlock(Die, dwarf::DW_AT_const_value, Block); |
Devang Patel | 0e821f4 | 2011-04-12 23:21:44 +0000 | [diff] [blame] | 906 | } |
| 907 | |
Eric Christopher | 25e3509 | 2013-04-22 07:47:40 +0000 | [diff] [blame] | 908 | /// addTemplateParams - Add template parameters into buffer. |
Eric Christopher | a5a7942 | 2013-12-09 23:32:48 +0000 | [diff] [blame] | 909 | void DwarfUnit::addTemplateParams(DIE &Buffer, DIArray TParams) { |
Devang Patel | 0e821f4 | 2011-04-12 23:21:44 +0000 | [diff] [blame] | 910 | // Add template parameters. |
| 911 | for (unsigned i = 0, e = TParams.getNumElements(); i != e; ++i) { |
| 912 | DIDescriptor Element = TParams.getElement(i); |
| 913 | if (Element.isTemplateTypeParameter()) |
Manman Ren | ffc9a71 | 2013-10-23 23:05:28 +0000 | [diff] [blame] | 914 | constructTemplateTypeParameterDIE(Buffer, |
| 915 | DITemplateTypeParameter(Element)); |
Devang Patel | 0e821f4 | 2011-04-12 23:21:44 +0000 | [diff] [blame] | 916 | else if (Element.isTemplateValueParameter()) |
Manman Ren | ffc9a71 | 2013-10-23 23:05:28 +0000 | [diff] [blame] | 917 | constructTemplateValueParameterDIE(Buffer, |
| 918 | DITemplateValueParameter(Element)); |
Devang Patel | 0e821f4 | 2011-04-12 23:21:44 +0000 | [diff] [blame] | 919 | } |
Devang Patel | 0e821f4 | 2011-04-12 23:21:44 +0000 | [diff] [blame] | 920 | } |
Nick Lewycky | 654f5ce | 2011-10-26 22:55:33 +0000 | [diff] [blame] | 921 | |
Eric Christopher | 4d23a4a | 2013-01-16 01:22:23 +0000 | [diff] [blame] | 922 | /// getOrCreateContextDIE - Get context owner's DIE. |
Eric Christopher | a5a7942 | 2013-12-09 23:32:48 +0000 | [diff] [blame] | 923 | DIE *DwarfUnit::getOrCreateContextDIE(DIScope Context) { |
David Blaikie | bd700e4 | 2013-11-14 21:24:34 +0000 | [diff] [blame] | 924 | if (!Context || Context.isFile()) |
David Blaikie | 2a80e44 | 2013-12-02 22:09:48 +0000 | [diff] [blame] | 925 | return getUnitDie(); |
Eric Christopher | 4d23a4a | 2013-01-16 01:22:23 +0000 | [diff] [blame] | 926 | if (Context.isType()) |
| 927 | return getOrCreateTypeDIE(DIType(Context)); |
David Blaikie | 1dbca70 | 2013-11-14 19:37:56 +0000 | [diff] [blame] | 928 | if (Context.isNameSpace()) |
Eric Christopher | 4d23a4a | 2013-01-16 01:22:23 +0000 | [diff] [blame] | 929 | return getOrCreateNameSpace(DINameSpace(Context)); |
David Blaikie | 1dbca70 | 2013-11-14 19:37:56 +0000 | [diff] [blame] | 930 | if (Context.isSubprogram()) |
Eric Christopher | 4d23a4a | 2013-01-16 01:22:23 +0000 | [diff] [blame] | 931 | return getOrCreateSubprogramDIE(DISubprogram(Context)); |
Adrian Prantl | 7d828bb | 2013-11-15 21:05:09 +0000 | [diff] [blame] | 932 | return getDIE(Context); |
Eric Christopher | 4d23a4a | 2013-01-16 01:22:23 +0000 | [diff] [blame] | 933 | } |
| 934 | |
Eric Christopher | a5a7942 | 2013-12-09 23:32:48 +0000 | [diff] [blame] | 935 | DIE *DwarfUnit::createTypeDIE(DICompositeType Ty) { |
David Blaikie | 9d861be | 2013-11-26 00:15:27 +0000 | [diff] [blame] | 936 | DIScope Context = resolve(Ty.getContext()); |
| 937 | DIE *ContextDIE = getOrCreateContextDIE(Context); |
David Blaikie | 409dd9c | 2013-11-19 23:08:21 +0000 | [diff] [blame] | 938 | |
| 939 | DIE *TyDIE = getDIE(Ty); |
| 940 | if (TyDIE) |
| 941 | return TyDIE; |
| 942 | |
| 943 | // Create new type. |
| 944 | TyDIE = createAndAddDIE(Ty.getTag(), *ContextDIE, Ty); |
| 945 | |
David Blaikie | fbd29eb | 2013-11-26 00:35:04 +0000 | [diff] [blame] | 946 | constructTypeDIE(*TyDIE, Ty); |
David Blaikie | 409dd9c | 2013-11-19 23:08:21 +0000 | [diff] [blame] | 947 | |
David Blaikie | 9d861be | 2013-11-26 00:15:27 +0000 | [diff] [blame] | 948 | updateAcceleratorTables(Context, Ty, TyDIE); |
David Blaikie | 409dd9c | 2013-11-19 23:08:21 +0000 | [diff] [blame] | 949 | return TyDIE; |
| 950 | } |
| 951 | |
Devang Patel | 0e821f4 | 2011-04-12 23:21:44 +0000 | [diff] [blame] | 952 | /// getOrCreateTypeDIE - Find existing DIE or create new DIE for the |
| 953 | /// given DIType. |
Eric Christopher | a5a7942 | 2013-12-09 23:32:48 +0000 | [diff] [blame] | 954 | DIE *DwarfUnit::getOrCreateTypeDIE(const MDNode *TyNode) { |
David Blaikie | 3288755 | 2013-11-14 22:25:02 +0000 | [diff] [blame] | 955 | if (!TyNode) |
Devang Patel | eb1bb4e | 2011-08-16 22:09:43 +0000 | [diff] [blame] | 956 | return NULL; |
Manman Ren | f4c339e | 2013-10-29 22:49:29 +0000 | [diff] [blame] | 957 | |
David Blaikie | 3288755 | 2013-11-14 22:25:02 +0000 | [diff] [blame] | 958 | DIType Ty(TyNode); |
| 959 | assert(Ty.isType()); |
| 960 | |
Manman Ren | f4c339e | 2013-10-29 22:49:29 +0000 | [diff] [blame] | 961 | // Construct the context before querying for the existence of the DIE in case |
| 962 | // such construction creates the DIE. |
David Blaikie | 9d861be | 2013-11-26 00:15:27 +0000 | [diff] [blame] | 963 | DIScope Context = resolve(Ty.getContext()); |
| 964 | DIE *ContextDIE = getOrCreateContextDIE(Context); |
Adrian Prantl | 4583f7d | 2013-11-15 23:21:39 +0000 | [diff] [blame] | 965 | assert(ContextDIE); |
Manman Ren | f4c339e | 2013-10-29 22:49:29 +0000 | [diff] [blame] | 966 | |
Eric Christopher | e595bae | 2013-10-04 17:08:38 +0000 | [diff] [blame] | 967 | DIE *TyDIE = getDIE(Ty); |
Devang Patel | 0e821f4 | 2011-04-12 23:21:44 +0000 | [diff] [blame] | 968 | if (TyDIE) |
| 969 | return TyDIE; |
| 970 | |
| 971 | // Create new type. |
Manman Ren | f4c339e | 2013-10-29 22:49:29 +0000 | [diff] [blame] | 972 | TyDIE = createAndAddDIE(Ty.getTag(), *ContextDIE, Ty); |
| 973 | |
Devang Patel | 0e821f4 | 2011-04-12 23:21:44 +0000 | [diff] [blame] | 974 | if (Ty.isBasicType()) |
| 975 | constructTypeDIE(*TyDIE, DIBasicType(Ty)); |
David Blaikie | 8a263cb | 2013-11-26 00:22:37 +0000 | [diff] [blame] | 976 | else if (Ty.isCompositeType()) { |
| 977 | DICompositeType CTy(Ty); |
David Blaikie | cfb2115 | 2014-01-03 18:59:42 +0000 | [diff] [blame] | 978 | if (GenerateDwarfTypeUnits && !Ty.isForwardDecl()) |
| 979 | if (MDString *TypeId = CTy.getIdentifier()) { |
David Blaikie | f645f96 | 2014-01-09 03:23:41 +0000 | [diff] [blame] | 980 | DD->addDwarfTypeUnitType(getCUNode(), TypeId->getString(), TyDIE, CTy); |
David Blaikie | cfb2115 | 2014-01-03 18:59:42 +0000 | [diff] [blame] | 981 | // Skip updating the accellerator tables since this is not the full type |
| 982 | return TyDIE; |
| 983 | } |
David Blaikie | fbd29eb | 2013-11-26 00:35:04 +0000 | [diff] [blame] | 984 | constructTypeDIE(*TyDIE, CTy); |
David Blaikie | 8a263cb | 2013-11-26 00:22:37 +0000 | [diff] [blame] | 985 | } else { |
Devang Patel | 0e821f4 | 2011-04-12 23:21:44 +0000 | [diff] [blame] | 986 | assert(Ty.isDerivedType() && "Unknown kind of DIType"); |
| 987 | constructTypeDIE(*TyDIE, DIDerivedType(Ty)); |
| 988 | } |
David Blaikie | 2ea848b | 2013-11-19 22:51:04 +0000 | [diff] [blame] | 989 | |
David Blaikie | 9d861be | 2013-11-26 00:15:27 +0000 | [diff] [blame] | 990 | updateAcceleratorTables(Context, Ty, TyDIE); |
David Blaikie | 2ea848b | 2013-11-19 22:51:04 +0000 | [diff] [blame] | 991 | |
| 992 | return TyDIE; |
| 993 | } |
| 994 | |
Eric Christopher | a5a7942 | 2013-12-09 23:32:48 +0000 | [diff] [blame] | 995 | void DwarfUnit::updateAcceleratorTables(DIScope Context, DIType Ty, |
| 996 | const DIE *TyDIE) { |
Eric Christopher | 21bde87 | 2012-01-06 04:35:23 +0000 | [diff] [blame] | 997 | if (!Ty.getName().empty() && !Ty.isForwardDecl()) { |
| 998 | bool IsImplementation = 0; |
| 999 | if (Ty.isCompositeType()) { |
| 1000 | DICompositeType CT(Ty); |
Eric Christopher | 8ea8e4f | 2012-01-06 23:03:37 +0000 | [diff] [blame] | 1001 | // A runtime language of 0 actually means C/C++ and that any |
| 1002 | // non-negative value is some version of Objective-C/C++. |
Eric Christopher | c2697f8 | 2013-10-19 01:04:47 +0000 | [diff] [blame] | 1003 | IsImplementation = (CT.getRunTimeLang() == 0) || CT.isObjcClassComplete(); |
Eric Christopher | 21bde87 | 2012-01-06 04:35:23 +0000 | [diff] [blame] | 1004 | } |
Eric Christopher | cf7289f | 2013-09-05 18:20:16 +0000 | [diff] [blame] | 1005 | unsigned Flags = IsImplementation ? dwarf::DW_FLAG_type_implementation : 0; |
Eric Christopher | 8ea8e4f | 2012-01-06 23:03:37 +0000 | [diff] [blame] | 1006 | addAccelType(Ty.getName(), std::make_pair(TyDIE, Flags)); |
David Blaikie | 9d861be | 2013-11-26 00:15:27 +0000 | [diff] [blame] | 1007 | |
| 1008 | if (!Context || Context.isCompileUnit() || Context.isFile() || |
| 1009 | Context.isNameSpace()) |
| 1010 | GlobalTypes[getParentContextString(Context) + Ty.getName().str()] = TyDIE; |
Eric Christopher | 21bde87 | 2012-01-06 04:35:23 +0000 | [diff] [blame] | 1011 | } |
Devang Patel | 0e821f4 | 2011-04-12 23:21:44 +0000 | [diff] [blame] | 1012 | } |
| 1013 | |
| 1014 | /// addType - Add a new type attribute to the specified entity. |
Eric Christopher | a5a7942 | 2013-12-09 23:32:48 +0000 | [diff] [blame] | 1015 | void DwarfUnit::addType(DIE *Entity, DIType Ty, dwarf::Attribute Attribute) { |
Eric Christopher | 0df08e2 | 2013-08-08 07:40:37 +0000 | [diff] [blame] | 1016 | assert(Ty && "Trying to add a type that doesn't exist?"); |
Devang Patel | 0e821f4 | 2011-04-12 23:21:44 +0000 | [diff] [blame] | 1017 | |
| 1018 | // Check for pre-existence. |
| 1019 | DIEEntry *Entry = getDIEEntry(Ty); |
| 1020 | // If it exists then use the existing value. |
| 1021 | if (Entry) { |
Manman Ren | 4dbdc90 | 2013-10-31 17:54:35 +0000 | [diff] [blame] | 1022 | addDIEEntry(Entity, Attribute, Entry); |
Devang Patel | 0e821f4 | 2011-04-12 23:21:44 +0000 | [diff] [blame] | 1023 | return; |
| 1024 | } |
| 1025 | |
| 1026 | // Construct type. |
| 1027 | DIE *Buffer = getOrCreateTypeDIE(Ty); |
| 1028 | |
| 1029 | // Set up proxy. |
| 1030 | Entry = createDIEEntry(Buffer); |
| 1031 | insertDIEEntry(Ty, Entry); |
Manman Ren | 4dbdc90 | 2013-10-31 17:54:35 +0000 | [diff] [blame] | 1032 | addDIEEntry(Entity, Attribute, Entry); |
Devang Patel | 1cb8ab4 | 2011-05-31 23:30:30 +0000 | [diff] [blame] | 1033 | } |
| 1034 | |
Eric Christopher | 9cd26af | 2013-09-20 23:22:52 +0000 | [diff] [blame] | 1035 | // Accelerator table mutators - add each name along with its companion |
| 1036 | // DIE to the proper table while ensuring that the name that we're going |
| 1037 | // to reference is in the string table. We do this since the names we |
| 1038 | // add may not only be identical to the names in the DIE. |
Eric Christopher | a5a7942 | 2013-12-09 23:32:48 +0000 | [diff] [blame] | 1039 | void DwarfUnit::addAccelName(StringRef Name, const DIE *Die) { |
Paul Robinson | 3878a78 | 2014-01-31 20:39:19 +0000 | [diff] [blame] | 1040 | if (!DD->useDwarfAccelTables()) return; |
Eric Christopher | 9cd26af | 2013-09-20 23:22:52 +0000 | [diff] [blame] | 1041 | DU->getStringPoolEntry(Name); |
David Blaikie | 2ea848b | 2013-11-19 22:51:04 +0000 | [diff] [blame] | 1042 | std::vector<const DIE *> &DIEs = AccelNames[Name]; |
Eric Christopher | 9cd26af | 2013-09-20 23:22:52 +0000 | [diff] [blame] | 1043 | DIEs.push_back(Die); |
| 1044 | } |
| 1045 | |
Eric Christopher | a5a7942 | 2013-12-09 23:32:48 +0000 | [diff] [blame] | 1046 | void DwarfUnit::addAccelObjC(StringRef Name, const DIE *Die) { |
Paul Robinson | 3878a78 | 2014-01-31 20:39:19 +0000 | [diff] [blame] | 1047 | if (!DD->useDwarfAccelTables()) return; |
Eric Christopher | 9cd26af | 2013-09-20 23:22:52 +0000 | [diff] [blame] | 1048 | DU->getStringPoolEntry(Name); |
David Blaikie | 2ea848b | 2013-11-19 22:51:04 +0000 | [diff] [blame] | 1049 | std::vector<const DIE *> &DIEs = AccelObjC[Name]; |
Eric Christopher | 9cd26af | 2013-09-20 23:22:52 +0000 | [diff] [blame] | 1050 | DIEs.push_back(Die); |
| 1051 | } |
| 1052 | |
Eric Christopher | a5a7942 | 2013-12-09 23:32:48 +0000 | [diff] [blame] | 1053 | void DwarfUnit::addAccelNamespace(StringRef Name, const DIE *Die) { |
Paul Robinson | 3878a78 | 2014-01-31 20:39:19 +0000 | [diff] [blame] | 1054 | if (!DD->useDwarfAccelTables()) return; |
Eric Christopher | 9cd26af | 2013-09-20 23:22:52 +0000 | [diff] [blame] | 1055 | DU->getStringPoolEntry(Name); |
David Blaikie | 2ea848b | 2013-11-19 22:51:04 +0000 | [diff] [blame] | 1056 | std::vector<const DIE *> &DIEs = AccelNamespace[Name]; |
Eric Christopher | 9cd26af | 2013-09-20 23:22:52 +0000 | [diff] [blame] | 1057 | DIEs.push_back(Die); |
| 1058 | } |
| 1059 | |
Eric Christopher | a5a7942 | 2013-12-09 23:32:48 +0000 | [diff] [blame] | 1060 | void DwarfUnit::addAccelType(StringRef Name, |
| 1061 | std::pair<const DIE *, unsigned> Die) { |
Paul Robinson | 3878a78 | 2014-01-31 20:39:19 +0000 | [diff] [blame] | 1062 | if (!DD->useDwarfAccelTables()) return; |
Eric Christopher | 9cd26af | 2013-09-20 23:22:52 +0000 | [diff] [blame] | 1063 | DU->getStringPoolEntry(Name); |
David Blaikie | 2ea848b | 2013-11-19 22:51:04 +0000 | [diff] [blame] | 1064 | std::vector<std::pair<const DIE *, unsigned> > &DIEs = AccelTypes[Name]; |
Eric Christopher | 9cd26af | 2013-09-20 23:22:52 +0000 | [diff] [blame] | 1065 | DIEs.push_back(Die); |
| 1066 | } |
| 1067 | |
Eric Christopher | 9c58f31 | 2013-09-20 22:20:55 +0000 | [diff] [blame] | 1068 | /// addGlobalName - Add a new global name to the compile unit. |
Eric Christopher | a5a7942 | 2013-12-09 23:32:48 +0000 | [diff] [blame] | 1069 | void DwarfUnit::addGlobalName(StringRef Name, DIE *Die, DIScope Context) { |
Eric Christopher | 8dba0d5 | 2013-10-19 01:04:42 +0000 | [diff] [blame] | 1070 | std::string FullName = getParentContextString(Context) + Name.str(); |
Eric Christopher | 2c8b790 | 2013-10-17 02:06:06 +0000 | [diff] [blame] | 1071 | GlobalNames[FullName] = Die; |
Eric Christopher | 9c58f31 | 2013-09-20 22:20:55 +0000 | [diff] [blame] | 1072 | } |
| 1073 | |
Eric Christopher | 2c8b790 | 2013-10-17 02:06:06 +0000 | [diff] [blame] | 1074 | /// getParentContextString - Walks the metadata parent chain in a language |
| 1075 | /// specific manner (using the compile unit language) and returns |
| 1076 | /// it as a string. This is done at the metadata level because DIEs may |
| 1077 | /// not currently have been added to the parent context and walking the |
| 1078 | /// DIEs looking for names is more expensive than walking the metadata. |
Eric Christopher | a5a7942 | 2013-12-09 23:32:48 +0000 | [diff] [blame] | 1079 | std::string DwarfUnit::getParentContextString(DIScope Context) const { |
Eric Christopher | 2c8b790 | 2013-10-17 02:06:06 +0000 | [diff] [blame] | 1080 | if (!Context) |
| 1081 | return ""; |
| 1082 | |
| 1083 | // FIXME: Decide whether to implement this for non-C++ languages. |
| 1084 | if (getLanguage() != dwarf::DW_LANG_C_plus_plus) |
| 1085 | return ""; |
| 1086 | |
Eric Christopher | 8dba0d5 | 2013-10-19 01:04:42 +0000 | [diff] [blame] | 1087 | std::string CS; |
Eric Christopher | 2c8b790 | 2013-10-17 02:06:06 +0000 | [diff] [blame] | 1088 | SmallVector<DIScope, 1> Parents; |
| 1089 | while (!Context.isCompileUnit()) { |
| 1090 | Parents.push_back(Context); |
| 1091 | if (Context.getContext()) |
| 1092 | Context = resolve(Context.getContext()); |
| 1093 | else |
| 1094 | // Structure, etc types will have a NULL context if they're at the top |
| 1095 | // level. |
| 1096 | break; |
| 1097 | } |
| 1098 | |
| 1099 | // Reverse iterate over our list to go from the outermost construct to the |
| 1100 | // innermost. |
| 1101 | for (SmallVectorImpl<DIScope>::reverse_iterator I = Parents.rbegin(), |
| 1102 | E = Parents.rend(); |
| 1103 | I != E; ++I) { |
| 1104 | DIScope Ctx = *I; |
| 1105 | StringRef Name = Ctx.getName(); |
Eric Christopher | 8dba0d5 | 2013-10-19 01:04:42 +0000 | [diff] [blame] | 1106 | if (!Name.empty()) { |
Eric Christopher | 2c8b790 | 2013-10-17 02:06:06 +0000 | [diff] [blame] | 1107 | CS += Name; |
| 1108 | CS += "::"; |
| 1109 | } |
| 1110 | } |
| 1111 | return CS; |
Devang Patel | 0e821f4 | 2011-04-12 23:21:44 +0000 | [diff] [blame] | 1112 | } |
| 1113 | |
| 1114 | /// constructTypeDIE - Construct basic type die from DIBasicType. |
Eric Christopher | a5a7942 | 2013-12-09 23:32:48 +0000 | [diff] [blame] | 1115 | void DwarfUnit::constructTypeDIE(DIE &Buffer, DIBasicType BTy) { |
Devang Patel | 0e821f4 | 2011-04-12 23:21:44 +0000 | [diff] [blame] | 1116 | // Get core information. |
| 1117 | StringRef Name = BTy.getName(); |
Devang Patel | 0e821f4 | 2011-04-12 23:21:44 +0000 | [diff] [blame] | 1118 | // Add name if not anonymous or intermediate type. |
| 1119 | if (!Name.empty()) |
Nick Lewycky | d59c0ca | 2011-10-27 06:44:11 +0000 | [diff] [blame] | 1120 | addString(&Buffer, dwarf::DW_AT_name, Name); |
Devang Patel | 04d6d47 | 2011-09-14 23:13:28 +0000 | [diff] [blame] | 1121 | |
David Blaikie | fac5612 | 2013-10-04 23:21:16 +0000 | [diff] [blame] | 1122 | // An unspecified type only has a name attribute. |
| 1123 | if (BTy.getTag() == dwarf::DW_TAG_unspecified_type) |
Devang Patel | 04d6d47 | 2011-09-14 23:13:28 +0000 | [diff] [blame] | 1124 | return; |
Devang Patel | 04d6d47 | 2011-09-14 23:13:28 +0000 | [diff] [blame] | 1125 | |
Nick Lewycky | 654f5ce | 2011-10-26 22:55:33 +0000 | [diff] [blame] | 1126 | addUInt(&Buffer, dwarf::DW_AT_encoding, dwarf::DW_FORM_data1, |
Devang Patel | d925d1a | 2012-02-07 23:33:58 +0000 | [diff] [blame] | 1127 | BTy.getEncoding()); |
Devang Patel | 04d6d47 | 2011-09-14 23:13:28 +0000 | [diff] [blame] | 1128 | |
Devang Patel | 0e821f4 | 2011-04-12 23:21:44 +0000 | [diff] [blame] | 1129 | uint64_t Size = BTy.getSizeInBits() >> 3; |
David Blaikie | f244319 | 2013-10-21 17:28:37 +0000 | [diff] [blame] | 1130 | addUInt(&Buffer, dwarf::DW_AT_byte_size, None, Size); |
Devang Patel | 0e821f4 | 2011-04-12 23:21:44 +0000 | [diff] [blame] | 1131 | } |
| 1132 | |
| 1133 | /// constructTypeDIE - Construct derived type die from DIDerivedType. |
Eric Christopher | a5a7942 | 2013-12-09 23:32:48 +0000 | [diff] [blame] | 1134 | void DwarfUnit::constructTypeDIE(DIE &Buffer, DIDerivedType DTy) { |
Devang Patel | 0e821f4 | 2011-04-12 23:21:44 +0000 | [diff] [blame] | 1135 | // Get core information. |
| 1136 | StringRef Name = DTy.getName(); |
| 1137 | uint64_t Size = DTy.getSizeInBits() >> 3; |
David Blaikie | fac5612 | 2013-10-04 23:21:16 +0000 | [diff] [blame] | 1138 | uint16_t Tag = Buffer.getTag(); |
Devang Patel | 0e821f4 | 2011-04-12 23:21:44 +0000 | [diff] [blame] | 1139 | |
| 1140 | // Map to main type, void will not have a type. |
Manman Ren | 93b3090 | 2013-10-08 18:42:58 +0000 | [diff] [blame] | 1141 | DIType FromTy = resolve(DTy.getTypeDerivedFrom()); |
Eric Christopher | 0df08e2 | 2013-08-08 07:40:37 +0000 | [diff] [blame] | 1142 | if (FromTy) |
| 1143 | addType(&Buffer, FromTy); |
Devang Patel | 0e821f4 | 2011-04-12 23:21:44 +0000 | [diff] [blame] | 1144 | |
| 1145 | // Add name if not anonymous or intermediate type. |
| 1146 | if (!Name.empty()) |
Nick Lewycky | d59c0ca | 2011-10-27 06:44:11 +0000 | [diff] [blame] | 1147 | addString(&Buffer, dwarf::DW_AT_name, Name); |
Devang Patel | 0e821f4 | 2011-04-12 23:21:44 +0000 | [diff] [blame] | 1148 | |
| 1149 | // Add size if non-zero (derived types might be zero-sized.) |
Eric Christopher | 8575790 | 2012-02-21 22:25:53 +0000 | [diff] [blame] | 1150 | if (Size && Tag != dwarf::DW_TAG_pointer_type) |
David Blaikie | f244319 | 2013-10-21 17:28:37 +0000 | [diff] [blame] | 1151 | addUInt(&Buffer, dwarf::DW_AT_byte_size, None, Size); |
Devang Patel | 0e821f4 | 2011-04-12 23:21:44 +0000 | [diff] [blame] | 1152 | |
David Blaikie | 5d3249b | 2013-01-07 05:51:15 +0000 | [diff] [blame] | 1153 | if (Tag == dwarf::DW_TAG_ptr_to_member_type) |
Eric Christopher | c2697f8 | 2013-10-19 01:04:47 +0000 | [diff] [blame] | 1154 | addDIEEntry(&Buffer, dwarf::DW_AT_containing_type, |
| 1155 | getOrCreateTypeDIE(resolve(DTy.getClassType()))); |
Devang Patel | 0e821f4 | 2011-04-12 23:21:44 +0000 | [diff] [blame] | 1156 | // Add source line info if available and TyDesc is not a forward declaration. |
| 1157 | if (!DTy.isForwardDecl()) |
| 1158 | addSourceLine(&Buffer, DTy); |
| 1159 | } |
| 1160 | |
| 1161 | /// constructTypeDIE - Construct type DIE from DICompositeType. |
Eric Christopher | a5a7942 | 2013-12-09 23:32:48 +0000 | [diff] [blame] | 1162 | void DwarfUnit::constructTypeDIE(DIE &Buffer, DICompositeType CTy) { |
David Blaikie | 409dd9c | 2013-11-19 23:08:21 +0000 | [diff] [blame] | 1163 | // Add name if not anonymous or intermediate type. |
Devang Patel | 0e821f4 | 2011-04-12 23:21:44 +0000 | [diff] [blame] | 1164 | StringRef Name = CTy.getName(); |
| 1165 | |
| 1166 | uint64_t Size = CTy.getSizeInBits() >> 3; |
David Blaikie | fac5612 | 2013-10-04 23:21:16 +0000 | [diff] [blame] | 1167 | uint16_t Tag = Buffer.getTag(); |
Devang Patel | 0e821f4 | 2011-04-12 23:21:44 +0000 | [diff] [blame] | 1168 | |
| 1169 | switch (Tag) { |
Devang Patel | 0e821f4 | 2011-04-12 23:21:44 +0000 | [diff] [blame] | 1170 | case dwarf::DW_TAG_array_type: |
Eric Christopher | df9955d | 2013-11-11 18:52:31 +0000 | [diff] [blame] | 1171 | constructArrayTypeDIE(Buffer, CTy); |
Devang Patel | 0e821f4 | 2011-04-12 23:21:44 +0000 | [diff] [blame] | 1172 | break; |
Eric Christopher | aeb105f | 2013-11-11 18:52:39 +0000 | [diff] [blame] | 1173 | case dwarf::DW_TAG_enumeration_type: |
| 1174 | constructEnumTypeDIE(Buffer, CTy); |
| 1175 | break; |
Devang Patel | 0e821f4 | 2011-04-12 23:21:44 +0000 | [diff] [blame] | 1176 | case dwarf::DW_TAG_subroutine_type: { |
Eric Christopher | 0df08e2 | 2013-08-08 07:40:37 +0000 | [diff] [blame] | 1177 | // Add return type. A void return won't have a type. |
Devang Patel | 0e821f4 | 2011-04-12 23:21:44 +0000 | [diff] [blame] | 1178 | DIArray Elements = CTy.getTypeArray(); |
David Blaikie | 4f6bf27a | 2013-11-18 23:33:32 +0000 | [diff] [blame] | 1179 | DIType RTy(Elements.getElement(0)); |
Eric Christopher | 0df08e2 | 2013-08-08 07:40:37 +0000 | [diff] [blame] | 1180 | if (RTy) |
David Blaikie | 4f6bf27a | 2013-11-18 23:33:32 +0000 | [diff] [blame] | 1181 | addType(&Buffer, RTy); |
Devang Patel | 0e821f4 | 2011-04-12 23:21:44 +0000 | [diff] [blame] | 1182 | |
| 1183 | bool isPrototyped = true; |
| 1184 | // Add arguments. |
| 1185 | for (unsigned i = 1, N = Elements.getNumElements(); i < N; ++i) { |
| 1186 | DIDescriptor Ty = Elements.getElement(i); |
| 1187 | if (Ty.isUnspecifiedParameter()) { |
Manman Ren | b987e51 | 2013-10-29 00:53:03 +0000 | [diff] [blame] | 1188 | createAndAddDIE(dwarf::DW_TAG_unspecified_parameters, Buffer); |
Devang Patel | 0e821f4 | 2011-04-12 23:21:44 +0000 | [diff] [blame] | 1189 | isPrototyped = false; |
| 1190 | } else { |
Manman Ren | b987e51 | 2013-10-29 00:53:03 +0000 | [diff] [blame] | 1191 | DIE *Arg = createAndAddDIE(dwarf::DW_TAG_formal_parameter, Buffer); |
Devang Patel | 0e821f4 | 2011-04-12 23:21:44 +0000 | [diff] [blame] | 1192 | addType(Arg, DIType(Ty)); |
David Blaikie | 9a7a7a9 | 2013-01-29 19:35:24 +0000 | [diff] [blame] | 1193 | if (DIType(Ty).isArtificial()) |
| 1194 | addFlag(Arg, dwarf::DW_AT_artificial); |
Devang Patel | 0e821f4 | 2011-04-12 23:21:44 +0000 | [diff] [blame] | 1195 | } |
| 1196 | } |
Eric Christopher | 5cd2a9d | 2012-02-22 08:46:21 +0000 | [diff] [blame] | 1197 | // Add prototype flag if we're dealing with a C language and the |
| 1198 | // function has been prototyped. |
David Blaikie | cb8e435 | 2013-11-15 23:50:53 +0000 | [diff] [blame] | 1199 | uint16_t Language = getLanguage(); |
Eric Christopher | 5cd2a9d | 2012-02-22 08:46:21 +0000 | [diff] [blame] | 1200 | if (isPrototyped && |
Eric Christopher | c2697f8 | 2013-10-19 01:04:47 +0000 | [diff] [blame] | 1201 | (Language == dwarf::DW_LANG_C89 || Language == dwarf::DW_LANG_C99 || |
Eric Christopher | d42b92f | 2012-05-22 18:45:24 +0000 | [diff] [blame] | 1202 | Language == dwarf::DW_LANG_ObjC)) |
Eric Christopher | bb69a27 | 2012-08-24 01:14:27 +0000 | [diff] [blame] | 1203 | addFlag(&Buffer, dwarf::DW_AT_prototyped); |
Adrian Prantl | 99c7af2 | 2013-12-18 21:48:19 +0000 | [diff] [blame] | 1204 | |
| 1205 | if (CTy.isLValueReference()) |
| 1206 | addFlag(&Buffer, dwarf::DW_AT_reference); |
| 1207 | |
| 1208 | if (CTy.isRValueReference()) |
| 1209 | addFlag(&Buffer, dwarf::DW_AT_rvalue_reference); |
Eric Christopher | c2697f8 | 2013-10-19 01:04:47 +0000 | [diff] [blame] | 1210 | } break; |
Devang Patel | 0e821f4 | 2011-04-12 23:21:44 +0000 | [diff] [blame] | 1211 | case dwarf::DW_TAG_structure_type: |
| 1212 | case dwarf::DW_TAG_union_type: |
| 1213 | case dwarf::DW_TAG_class_type: { |
Devang Patel | 0e821f4 | 2011-04-12 23:21:44 +0000 | [diff] [blame] | 1214 | // Add elements to structure type. |
David Blaikie | a1ae0e6 | 2013-08-01 20:30:22 +0000 | [diff] [blame] | 1215 | DIArray Elements = CTy.getTypeArray(); |
| 1216 | for (unsigned i = 0, N = Elements.getNumElements(); i < N; ++i) { |
Devang Patel | 0e821f4 | 2011-04-12 23:21:44 +0000 | [diff] [blame] | 1217 | DIDescriptor Element = Elements.getElement(i); |
| 1218 | DIE *ElemDie = NULL; |
Adrian Prantl | ef129fb | 2014-01-18 02:12:00 +0000 | [diff] [blame] | 1219 | if (Element.isSubprogram()) |
| 1220 | ElemDie = getOrCreateSubprogramDIE(DISubprogram(Element)); |
| 1221 | else if (Element.isDerivedType()) { |
Eric Christopher | d42b92f | 2012-05-22 18:45:24 +0000 | [diff] [blame] | 1222 | DIDerivedType DDTy(Element); |
| 1223 | if (DDTy.getTag() == dwarf::DW_TAG_friend) { |
Manman Ren | b987e51 | 2013-10-29 00:53:03 +0000 | [diff] [blame] | 1224 | ElemDie = createAndAddDIE(dwarf::DW_TAG_friend, Buffer); |
Manman Ren | 93b3090 | 2013-10-08 18:42:58 +0000 | [diff] [blame] | 1225 | addType(ElemDie, resolve(DDTy.getTypeDerivedFrom()), |
Manman Ren | b338860 | 2013-10-05 01:43:03 +0000 | [diff] [blame] | 1226 | dwarf::DW_AT_friend); |
Manman Ren | c6b6392 | 2013-10-14 20:33:57 +0000 | [diff] [blame] | 1227 | } else if (DDTy.isStaticMember()) { |
Manman Ren | 57e6ff7 | 2013-10-23 22:57:12 +0000 | [diff] [blame] | 1228 | getOrCreateStaticMemberDIE(DDTy); |
Manman Ren | c6b6392 | 2013-10-14 20:33:57 +0000 | [diff] [blame] | 1229 | } else { |
Manman Ren | 230ec86 | 2013-10-23 23:00:44 +0000 | [diff] [blame] | 1230 | constructMemberDIE(Buffer, DDTy); |
Manman Ren | c6b6392 | 2013-10-14 20:33:57 +0000 | [diff] [blame] | 1231 | } |
Eric Christopher | 7285c7d | 2012-03-28 07:34:31 +0000 | [diff] [blame] | 1232 | } else if (Element.isObjCProperty()) { |
Devang Patel | d925d1a | 2012-02-07 23:33:58 +0000 | [diff] [blame] | 1233 | DIObjCProperty Property(Element); |
Manman Ren | b987e51 | 2013-10-29 00:53:03 +0000 | [diff] [blame] | 1234 | ElemDie = createAndAddDIE(Property.getTag(), Buffer); |
Devang Patel | d925d1a | 2012-02-07 23:33:58 +0000 | [diff] [blame] | 1235 | StringRef PropertyName = Property.getObjCPropertyName(); |
| 1236 | addString(ElemDie, dwarf::DW_AT_APPLE_property_name, PropertyName); |
Eric Christopher | 4c96056 | 2014-01-23 19:16:28 +0000 | [diff] [blame] | 1237 | if (Property.getType()) |
| 1238 | addType(ElemDie, Property.getType()); |
Eric Christopher | d42b92f | 2012-05-22 18:45:24 +0000 | [diff] [blame] | 1239 | addSourceLine(ElemDie, Property); |
Devang Patel | d925d1a | 2012-02-07 23:33:58 +0000 | [diff] [blame] | 1240 | StringRef GetterName = Property.getObjCPropertyGetterName(); |
| 1241 | if (!GetterName.empty()) |
| 1242 | addString(ElemDie, dwarf::DW_AT_APPLE_property_getter, GetterName); |
| 1243 | StringRef SetterName = Property.getObjCPropertySetterName(); |
| 1244 | if (!SetterName.empty()) |
| 1245 | addString(ElemDie, dwarf::DW_AT_APPLE_property_setter, SetterName); |
| 1246 | unsigned PropertyAttributes = 0; |
Devang Patel | 403e819 | 2012-02-04 01:30:32 +0000 | [diff] [blame] | 1247 | if (Property.isReadOnlyObjCProperty()) |
| 1248 | PropertyAttributes |= dwarf::DW_APPLE_PROPERTY_readonly; |
| 1249 | if (Property.isReadWriteObjCProperty()) |
| 1250 | PropertyAttributes |= dwarf::DW_APPLE_PROPERTY_readwrite; |
| 1251 | if (Property.isAssignObjCProperty()) |
| 1252 | PropertyAttributes |= dwarf::DW_APPLE_PROPERTY_assign; |
| 1253 | if (Property.isRetainObjCProperty()) |
| 1254 | PropertyAttributes |= dwarf::DW_APPLE_PROPERTY_retain; |
| 1255 | if (Property.isCopyObjCProperty()) |
| 1256 | PropertyAttributes |= dwarf::DW_APPLE_PROPERTY_copy; |
| 1257 | if (Property.isNonAtomicObjCProperty()) |
| 1258 | PropertyAttributes |= dwarf::DW_APPLE_PROPERTY_nonatomic; |
| 1259 | if (PropertyAttributes) |
David Blaikie | f244319 | 2013-10-21 17:28:37 +0000 | [diff] [blame] | 1260 | addUInt(ElemDie, dwarf::DW_AT_APPLE_property_attribute, None, |
Eric Christopher | c2697f8 | 2013-10-19 01:04:47 +0000 | [diff] [blame] | 1261 | PropertyAttributes); |
Devang Patel | 4488217 | 2012-02-06 17:49:43 +0000 | [diff] [blame] | 1262 | |
Devang Patel | d925d1a | 2012-02-07 23:33:58 +0000 | [diff] [blame] | 1263 | DIEEntry *Entry = getDIEEntry(Element); |
| 1264 | if (!Entry) { |
| 1265 | Entry = createDIEEntry(ElemDie); |
| 1266 | insertDIEEntry(Element, Entry); |
| 1267 | } |
Devang Patel | 403e819 | 2012-02-04 01:30:32 +0000 | [diff] [blame] | 1268 | } else |
Devang Patel | 0e821f4 | 2011-04-12 23:21:44 +0000 | [diff] [blame] | 1269 | continue; |
Devang Patel | 0e821f4 | 2011-04-12 23:21:44 +0000 | [diff] [blame] | 1270 | } |
| 1271 | |
| 1272 | if (CTy.isAppleBlockExtension()) |
Eric Christopher | bb69a27 | 2012-08-24 01:14:27 +0000 | [diff] [blame] | 1273 | addFlag(&Buffer, dwarf::DW_AT_APPLE_block); |
Devang Patel | 0e821f4 | 2011-04-12 23:21:44 +0000 | [diff] [blame] | 1274 | |
Eric Christopher | 9e429ae | 2013-10-05 00:27:02 +0000 | [diff] [blame] | 1275 | DICompositeType ContainingType(resolve(CTy.getContainingType())); |
David Blaikie | 4f6bf27a | 2013-11-18 23:33:32 +0000 | [diff] [blame] | 1276 | if (ContainingType) |
Manman Ren | 4c4b69c | 2013-10-11 23:58:05 +0000 | [diff] [blame] | 1277 | addDIEEntry(&Buffer, dwarf::DW_AT_containing_type, |
David Blaikie | 4f6bf27a | 2013-11-18 23:33:32 +0000 | [diff] [blame] | 1278 | getOrCreateTypeDIE(ContainingType)); |
Devang Patel | 0e821f4 | 2011-04-12 23:21:44 +0000 | [diff] [blame] | 1279 | |
Devang Patel | 12419ae | 2011-05-12 21:29:42 +0000 | [diff] [blame] | 1280 | if (CTy.isObjcClassComplete()) |
Eric Christopher | bb69a27 | 2012-08-24 01:14:27 +0000 | [diff] [blame] | 1281 | addFlag(&Buffer, dwarf::DW_AT_APPLE_objc_complete_type); |
Devang Patel | 2409e78 | 2011-05-12 19:06:16 +0000 | [diff] [blame] | 1282 | |
Eric Christopher | da011dd | 2011-12-16 23:42:42 +0000 | [diff] [blame] | 1283 | // Add template parameters to a class, structure or union types. |
| 1284 | // FIXME: The support isn't in the metadata for this yet. |
| 1285 | if (Tag == dwarf::DW_TAG_class_type || |
Eric Christopher | c2697f8 | 2013-10-19 01:04:47 +0000 | [diff] [blame] | 1286 | Tag == dwarf::DW_TAG_structure_type || Tag == dwarf::DW_TAG_union_type) |
Devang Patel | 0e821f4 | 2011-04-12 23:21:44 +0000 | [diff] [blame] | 1287 | addTemplateParams(Buffer, CTy.getTemplateParams()); |
| 1288 | |
| 1289 | break; |
| 1290 | } |
| 1291 | default: |
| 1292 | break; |
| 1293 | } |
| 1294 | |
| 1295 | // Add name if not anonymous or intermediate type. |
| 1296 | if (!Name.empty()) |
Nick Lewycky | d59c0ca | 2011-10-27 06:44:11 +0000 | [diff] [blame] | 1297 | addString(&Buffer, dwarf::DW_AT_name, Name); |
Devang Patel | 0e821f4 | 2011-04-12 23:21:44 +0000 | [diff] [blame] | 1298 | |
Eric Christopher | 775cbd2 | 2012-05-22 18:45:18 +0000 | [diff] [blame] | 1299 | if (Tag == dwarf::DW_TAG_enumeration_type || |
Eric Christopher | c2697f8 | 2013-10-19 01:04:47 +0000 | [diff] [blame] | 1300 | Tag == dwarf::DW_TAG_class_type || Tag == dwarf::DW_TAG_structure_type || |
Eric Christopher | 775cbd2 | 2012-05-22 18:45:18 +0000 | [diff] [blame] | 1301 | Tag == dwarf::DW_TAG_union_type) { |
Devang Patel | 0e821f4 | 2011-04-12 23:21:44 +0000 | [diff] [blame] | 1302 | // Add size if non-zero (derived types might be zero-sized.) |
Eric Christopher | 1cf3338 | 2012-06-01 00:22:32 +0000 | [diff] [blame] | 1303 | // TODO: Do we care about size for enum forward declarations? |
Devang Patel | 0e821f4 | 2011-04-12 23:21:44 +0000 | [diff] [blame] | 1304 | if (Size) |
David Blaikie | f244319 | 2013-10-21 17:28:37 +0000 | [diff] [blame] | 1305 | addUInt(&Buffer, dwarf::DW_AT_byte_size, None, Size); |
Eric Christopher | 1cf3338 | 2012-06-01 00:22:32 +0000 | [diff] [blame] | 1306 | else if (!CTy.isForwardDecl()) |
Devang Patel | 0e821f4 | 2011-04-12 23:21:44 +0000 | [diff] [blame] | 1307 | // Add zero size if it is not a forward declaration. |
David Blaikie | f244319 | 2013-10-21 17:28:37 +0000 | [diff] [blame] | 1308 | addUInt(&Buffer, dwarf::DW_AT_byte_size, None, 0); |
Eric Christopher | 1cf3338 | 2012-06-01 00:22:32 +0000 | [diff] [blame] | 1309 | |
| 1310 | // If we're a forward decl, say so. |
| 1311 | if (CTy.isForwardDecl()) |
Eric Christopher | bb69a27 | 2012-08-24 01:14:27 +0000 | [diff] [blame] | 1312 | addFlag(&Buffer, dwarf::DW_AT_declaration); |
Devang Patel | 0e821f4 | 2011-04-12 23:21:44 +0000 | [diff] [blame] | 1313 | |
| 1314 | // Add source line info if available. |
| 1315 | if (!CTy.isForwardDecl()) |
| 1316 | addSourceLine(&Buffer, CTy); |
Eric Christopher | 54cf8ff | 2012-03-07 00:15:19 +0000 | [diff] [blame] | 1317 | |
| 1318 | // No harm in adding the runtime language to the declaration. |
| 1319 | unsigned RLang = CTy.getRunTimeLang(); |
| 1320 | if (RLang) |
Eric Christopher | c2697f8 | 2013-10-19 01:04:47 +0000 | [diff] [blame] | 1321 | addUInt(&Buffer, dwarf::DW_AT_APPLE_runtime_class, dwarf::DW_FORM_data1, |
| 1322 | RLang); |
Devang Patel | 0e821f4 | 2011-04-12 23:21:44 +0000 | [diff] [blame] | 1323 | } |
| 1324 | } |
| 1325 | |
Manman Ren | ffc9a71 | 2013-10-23 23:05:28 +0000 | [diff] [blame] | 1326 | /// constructTemplateTypeParameterDIE - Construct new DIE for the given |
| 1327 | /// DITemplateTypeParameter. |
Eric Christopher | a5a7942 | 2013-12-09 23:32:48 +0000 | [diff] [blame] | 1328 | void DwarfUnit::constructTemplateTypeParameterDIE(DIE &Buffer, |
| 1329 | DITemplateTypeParameter TP) { |
Manman Ren | b987e51 | 2013-10-29 00:53:03 +0000 | [diff] [blame] | 1330 | DIE *ParamDIE = |
| 1331 | createAndAddDIE(dwarf::DW_TAG_template_type_parameter, Buffer); |
Eric Christopher | 056b647 | 2013-08-08 08:09:43 +0000 | [diff] [blame] | 1332 | // Add the type if it exists, it could be void and therefore no type. |
| 1333 | if (TP.getType()) |
Manman Ren | 88b0f94 | 2013-10-09 19:46:28 +0000 | [diff] [blame] | 1334 | addType(ParamDIE, resolve(TP.getType())); |
David Blaikie | 2b38023 | 2013-06-22 18:59:11 +0000 | [diff] [blame] | 1335 | if (!TP.getName().empty()) |
| 1336 | addString(ParamDIE, dwarf::DW_AT_name, TP.getName()); |
Devang Patel | 0e821f4 | 2011-04-12 23:21:44 +0000 | [diff] [blame] | 1337 | } |
| 1338 | |
Manman Ren | ffc9a71 | 2013-10-23 23:05:28 +0000 | [diff] [blame] | 1339 | /// constructTemplateValueParameterDIE - Construct new DIE for the given |
| 1340 | /// DITemplateValueParameter. |
Eric Christopher | a5a7942 | 2013-12-09 23:32:48 +0000 | [diff] [blame] | 1341 | void |
| 1342 | DwarfUnit::constructTemplateValueParameterDIE(DIE &Buffer, |
David Blaikie | 319a05f | 2013-12-02 19:33:10 +0000 | [diff] [blame] | 1343 | DITemplateValueParameter VP) { |
Manman Ren | b987e51 | 2013-10-29 00:53:03 +0000 | [diff] [blame] | 1344 | DIE *ParamDIE = createAndAddDIE(VP.getTag(), Buffer); |
Eric Christopher | 0df08e2 | 2013-08-08 07:40:37 +0000 | [diff] [blame] | 1345 | |
| 1346 | // Add the type if there is one, template template and template parameter |
| 1347 | // packs will not have a type. |
Eric Christopher | 691281b | 2013-10-21 17:48:51 +0000 | [diff] [blame] | 1348 | if (VP.getTag() == dwarf::DW_TAG_template_value_parameter) |
Manman Ren | 88b0f94 | 2013-10-09 19:46:28 +0000 | [diff] [blame] | 1349 | addType(ParamDIE, resolve(VP.getType())); |
Eric Christopher | afb2c41 | 2013-08-08 07:40:31 +0000 | [diff] [blame] | 1350 | if (!VP.getName().empty()) |
| 1351 | addString(ParamDIE, dwarf::DW_AT_name, VP.getName()); |
| 1352 | if (Value *Val = VP.getValue()) { |
David Blaikie | a1e813d | 2013-05-10 21:52:07 +0000 | [diff] [blame] | 1353 | if (ConstantInt *CI = dyn_cast<ConstantInt>(Val)) |
Manman Ren | 88b0f94 | 2013-10-09 19:46:28 +0000 | [diff] [blame] | 1354 | addConstantValue(ParamDIE, CI, |
| 1355 | isUnsignedDIType(DD, resolve(VP.getType()))); |
David Blaikie | a1e813d | 2013-05-10 21:52:07 +0000 | [diff] [blame] | 1356 | else if (GlobalValue *GV = dyn_cast<GlobalValue>(Val)) { |
| 1357 | // For declaration non-type template parameters (such as global values and |
| 1358 | // functions) |
| 1359 | DIEBlock *Block = new (DIEValueAllocator) DIEBlock(); |
Rafael Espindola | 79858aa | 2013-10-29 17:07:16 +0000 | [diff] [blame] | 1360 | addOpAddress(Block, Asm->getSymbol(GV)); |
David Blaikie | a1e813d | 2013-05-10 21:52:07 +0000 | [diff] [blame] | 1361 | // Emit DW_OP_stack_value to use the address as the immediate value of the |
| 1362 | // parameter, rather than a pointer to it. |
David Blaikie | f244319 | 2013-10-21 17:28:37 +0000 | [diff] [blame] | 1363 | addUInt(Block, dwarf::DW_FORM_data1, dwarf::DW_OP_stack_value); |
| 1364 | addBlock(ParamDIE, dwarf::DW_AT_location, Block); |
Eric Christopher | afb2c41 | 2013-08-08 07:40:31 +0000 | [diff] [blame] | 1365 | } else if (VP.getTag() == dwarf::DW_TAG_GNU_template_template_param) { |
David Blaikie | 2b38023 | 2013-06-22 18:59:11 +0000 | [diff] [blame] | 1366 | assert(isa<MDString>(Val)); |
| 1367 | addString(ParamDIE, dwarf::DW_AT_GNU_template_name, |
| 1368 | cast<MDString>(Val)->getString()); |
Eric Christopher | afb2c41 | 2013-08-08 07:40:31 +0000 | [diff] [blame] | 1369 | } else if (VP.getTag() == dwarf::DW_TAG_GNU_template_parameter_pack) { |
David Blaikie | 2b38023 | 2013-06-22 18:59:11 +0000 | [diff] [blame] | 1370 | assert(isa<MDNode>(Val)); |
| 1371 | DIArray A(cast<MDNode>(Val)); |
| 1372 | addTemplateParams(*ParamDIE, A); |
David Blaikie | a1e813d | 2013-05-10 21:52:07 +0000 | [diff] [blame] | 1373 | } |
| 1374 | } |
Devang Patel | 0e821f4 | 2011-04-12 23:21:44 +0000 | [diff] [blame] | 1375 | } |
| 1376 | |
Devang Patel | 17b5327 | 2011-05-06 16:57:54 +0000 | [diff] [blame] | 1377 | /// getOrCreateNameSpace - Create a DIE for DINameSpace. |
Eric Christopher | a5a7942 | 2013-12-09 23:32:48 +0000 | [diff] [blame] | 1378 | DIE *DwarfUnit::getOrCreateNameSpace(DINameSpace NS) { |
Manman Ren | f6b936b | 2013-10-29 05:49:41 +0000 | [diff] [blame] | 1379 | // Construct the context before querying for the existence of the DIE in case |
| 1380 | // such construction creates the DIE. |
| 1381 | DIE *ContextDIE = getOrCreateContextDIE(NS.getContext()); |
Manman Ren | f6b936b | 2013-10-29 05:49:41 +0000 | [diff] [blame] | 1382 | |
Devang Patel | 17b5327 | 2011-05-06 16:57:54 +0000 | [diff] [blame] | 1383 | DIE *NDie = getDIE(NS); |
| 1384 | if (NDie) |
| 1385 | return NDie; |
Manman Ren | f6b936b | 2013-10-29 05:49:41 +0000 | [diff] [blame] | 1386 | NDie = createAndAddDIE(dwarf::DW_TAG_namespace, *ContextDIE, NS); |
| 1387 | |
Eric Christopher | 4996c70 | 2011-11-07 09:24:32 +0000 | [diff] [blame] | 1388 | if (!NS.getName().empty()) { |
Nick Lewycky | d59c0ca | 2011-10-27 06:44:11 +0000 | [diff] [blame] | 1389 | addString(NDie, dwarf::DW_AT_name, NS.getName()); |
Eric Christopher | 4996c70 | 2011-11-07 09:24:32 +0000 | [diff] [blame] | 1390 | addAccelNamespace(NS.getName(), NDie); |
Eric Christopher | 2c8b790 | 2013-10-17 02:06:06 +0000 | [diff] [blame] | 1391 | addGlobalName(NS.getName(), NDie, NS.getContext()); |
Eric Christopher | 4996c70 | 2011-11-07 09:24:32 +0000 | [diff] [blame] | 1392 | } else |
| 1393 | addAccelNamespace("(anonymous namespace)", NDie); |
Devang Patel | 17b5327 | 2011-05-06 16:57:54 +0000 | [diff] [blame] | 1394 | addSourceLine(NDie, NS); |
Devang Patel | 17b5327 | 2011-05-06 16:57:54 +0000 | [diff] [blame] | 1395 | return NDie; |
| 1396 | } |
| 1397 | |
Devang Patel | 8954371 | 2011-08-15 17:24:54 +0000 | [diff] [blame] | 1398 | /// getOrCreateSubprogramDIE - Create new DIE using SP. |
Eric Christopher | a5a7942 | 2013-12-09 23:32:48 +0000 | [diff] [blame] | 1399 | DIE *DwarfUnit::getOrCreateSubprogramDIE(DISubprogram SP) { |
David Blaikie | 309ffe4 | 2013-10-04 01:39:59 +0000 | [diff] [blame] | 1400 | // Construct the context before querying for the existence of the DIE in case |
| 1401 | // such construction creates the DIE (as is the case for member function |
| 1402 | // declarations). |
Manman Ren | c50fa11 | 2013-10-10 18:40:01 +0000 | [diff] [blame] | 1403 | DIE *ContextDIE = getOrCreateContextDIE(resolve(SP.getContext())); |
David Blaikie | 309ffe4 | 2013-10-04 01:39:59 +0000 | [diff] [blame] | 1404 | |
Eric Christopher | e595bae | 2013-10-04 17:08:38 +0000 | [diff] [blame] | 1405 | DIE *SPDie = getDIE(SP); |
Devang Patel | 8954371 | 2011-08-15 17:24:54 +0000 | [diff] [blame] | 1406 | if (SPDie) |
| 1407 | return SPDie; |
| 1408 | |
Manman Ren | 73d697c | 2013-10-29 00:58:04 +0000 | [diff] [blame] | 1409 | DISubprogram SPDecl = SP.getFunctionDeclaration(); |
| 1410 | if (SPDecl.isSubprogram()) |
| 1411 | // Add subprogram definitions to the CU die directly. |
David Blaikie | 2a80e44 | 2013-12-02 22:09:48 +0000 | [diff] [blame] | 1412 | ContextDIE = UnitDie.get(); |
Peter Collingbourne | 4d358b5 | 2012-05-27 18:36:44 +0000 | [diff] [blame] | 1413 | |
| 1414 | // DW_TAG_inlined_subroutine may refer to this DIE. |
Manman Ren | 73d697c | 2013-10-29 00:58:04 +0000 | [diff] [blame] | 1415 | SPDie = createAndAddDIE(dwarf::DW_TAG_subprogram, *ContextDIE, SP); |
Peter Collingbourne | 4d358b5 | 2012-05-27 18:36:44 +0000 | [diff] [blame] | 1416 | |
Rafael Espindola | 7927836 | 2011-11-10 22:34:29 +0000 | [diff] [blame] | 1417 | DIE *DeclDie = NULL; |
Manman Ren | b9512a7 | 2013-10-23 22:12:26 +0000 | [diff] [blame] | 1418 | if (SPDecl.isSubprogram()) |
Rafael Espindola | 7927836 | 2011-11-10 22:34:29 +0000 | [diff] [blame] | 1419 | DeclDie = getOrCreateSubprogramDIE(SPDecl); |
Rafael Espindola | 7927836 | 2011-11-10 22:34:29 +0000 | [diff] [blame] | 1420 | |
Devang Patel | 8954371 | 2011-08-15 17:24:54 +0000 | [diff] [blame] | 1421 | // Add function template parameters. |
| 1422 | addTemplateParams(*SPDie, SP.getTemplateParams()); |
| 1423 | |
Devang Patel | 8954371 | 2011-08-15 17:24:54 +0000 | [diff] [blame] | 1424 | // If this DIE is going to refer declaration info using AT_specification |
Eric Christopher | f20ff97 | 2013-05-09 00:42:33 +0000 | [diff] [blame] | 1425 | // then there is no need to add other attributes. |
Rafael Espindola | 7927836 | 2011-11-10 22:34:29 +0000 | [diff] [blame] | 1426 | if (DeclDie) { |
| 1427 | // Refer function declaration directly. |
Manman Ren | 4c4b69c | 2013-10-11 23:58:05 +0000 | [diff] [blame] | 1428 | addDIEEntry(SPDie, dwarf::DW_AT_specification, DeclDie); |
Rafael Espindola | 7927836 | 2011-11-10 22:34:29 +0000 | [diff] [blame] | 1429 | |
Devang Patel | 8954371 | 2011-08-15 17:24:54 +0000 | [diff] [blame] | 1430 | return SPDie; |
Rafael Espindola | 7927836 | 2011-11-10 22:34:29 +0000 | [diff] [blame] | 1431 | } |
Devang Patel | 8954371 | 2011-08-15 17:24:54 +0000 | [diff] [blame] | 1432 | |
Eric Christopher | acb7115 | 2012-08-23 22:52:55 +0000 | [diff] [blame] | 1433 | // Add the linkage name if we have one. |
Michael Gottesman | c89466f | 2013-09-04 04:39:38 +0000 | [diff] [blame] | 1434 | StringRef LinkageName = SP.getLinkageName(); |
| 1435 | if (!LinkageName.empty()) |
Eric Christopher | acb7115 | 2012-08-23 22:52:55 +0000 | [diff] [blame] | 1436 | addString(SPDie, dwarf::DW_AT_MIPS_linkage_name, |
Benjamin Kramer | 7c27564 | 2013-06-01 17:51:14 +0000 | [diff] [blame] | 1437 | GlobalValue::getRealLinkageName(LinkageName)); |
Eric Christopher | acb7115 | 2012-08-23 22:52:55 +0000 | [diff] [blame] | 1438 | |
Devang Patel | 8954371 | 2011-08-15 17:24:54 +0000 | [diff] [blame] | 1439 | // Constructors and operators for anonymous aggregates do not have names. |
| 1440 | if (!SP.getName().empty()) |
Nick Lewycky | d59c0ca | 2011-10-27 06:44:11 +0000 | [diff] [blame] | 1441 | addString(SPDie, dwarf::DW_AT_name, SP.getName()); |
Devang Patel | 8954371 | 2011-08-15 17:24:54 +0000 | [diff] [blame] | 1442 | |
| 1443 | addSourceLine(SPDie, SP); |
| 1444 | |
Eric Christopher | 5cd2a9d | 2012-02-22 08:46:21 +0000 | [diff] [blame] | 1445 | // Add the prototype if we have a prototype and we have a C like |
| 1446 | // language. |
David Blaikie | cb8e435 | 2013-11-15 23:50:53 +0000 | [diff] [blame] | 1447 | uint16_t Language = getLanguage(); |
Eric Christopher | 5cd2a9d | 2012-02-22 08:46:21 +0000 | [diff] [blame] | 1448 | if (SP.isPrototyped() && |
Eric Christopher | c2697f8 | 2013-10-19 01:04:47 +0000 | [diff] [blame] | 1449 | (Language == dwarf::DW_LANG_C89 || Language == dwarf::DW_LANG_C99 || |
Eric Christopher | 5cd2a9d | 2012-02-22 08:46:21 +0000 | [diff] [blame] | 1450 | Language == dwarf::DW_LANG_ObjC)) |
Eric Christopher | bb69a27 | 2012-08-24 01:14:27 +0000 | [diff] [blame] | 1451 | addFlag(SPDie, dwarf::DW_AT_prototyped); |
Devang Patel | 8954371 | 2011-08-15 17:24:54 +0000 | [diff] [blame] | 1452 | |
Devang Patel | 8954371 | 2011-08-15 17:24:54 +0000 | [diff] [blame] | 1453 | DICompositeType SPTy = SP.getType(); |
David Blaikie | 5174c84 | 2013-05-22 23:22:18 +0000 | [diff] [blame] | 1454 | assert(SPTy.getTag() == dwarf::DW_TAG_subroutine_type && |
| 1455 | "the type of a subprogram should be a subroutine"); |
Devang Patel | 8954371 | 2011-08-15 17:24:54 +0000 | [diff] [blame] | 1456 | |
David Blaikie | 5174c84 | 2013-05-22 23:22:18 +0000 | [diff] [blame] | 1457 | DIArray Args = SPTy.getTypeArray(); |
Eric Christopher | 691281b | 2013-10-21 17:48:51 +0000 | [diff] [blame] | 1458 | // Add a return type. If this is a type like a C/C++ void type we don't add a |
| 1459 | // return type. |
Eric Christopher | 0df08e2 | 2013-08-08 07:40:37 +0000 | [diff] [blame] | 1460 | if (Args.getElement(0)) |
| 1461 | addType(SPDie, DIType(Args.getElement(0))); |
Devang Patel | 8954371 | 2011-08-15 17:24:54 +0000 | [diff] [blame] | 1462 | |
| 1463 | unsigned VK = SP.getVirtuality(); |
| 1464 | if (VK) { |
Nick Lewycky | cfde1a2 | 2011-12-14 00:56:07 +0000 | [diff] [blame] | 1465 | addUInt(SPDie, dwarf::DW_AT_virtuality, dwarf::DW_FORM_data1, VK); |
Devang Patel | 8954371 | 2011-08-15 17:24:54 +0000 | [diff] [blame] | 1466 | DIEBlock *Block = getDIEBlock(); |
David Blaikie | f244319 | 2013-10-21 17:28:37 +0000 | [diff] [blame] | 1467 | addUInt(Block, dwarf::DW_FORM_data1, dwarf::DW_OP_constu); |
| 1468 | addUInt(Block, dwarf::DW_FORM_udata, SP.getVirtualIndex()); |
| 1469 | addBlock(SPDie, dwarf::DW_AT_vtable_elem_location, Block); |
Eric Christopher | 98b7f17 | 2013-11-11 18:52:36 +0000 | [diff] [blame] | 1470 | ContainingTypeMap.insert( |
| 1471 | std::make_pair(SPDie, resolve(SP.getContainingType()))); |
Devang Patel | 8954371 | 2011-08-15 17:24:54 +0000 | [diff] [blame] | 1472 | } |
| 1473 | |
| 1474 | if (!SP.isDefinition()) { |
Eric Christopher | bb69a27 | 2012-08-24 01:14:27 +0000 | [diff] [blame] | 1475 | addFlag(SPDie, dwarf::DW_AT_declaration); |
Eric Christopher | 92331fd | 2012-11-21 00:34:38 +0000 | [diff] [blame] | 1476 | |
Devang Patel | 8954371 | 2011-08-15 17:24:54 +0000 | [diff] [blame] | 1477 | // Add arguments. Do not add arguments for subprogram definition. They will |
| 1478 | // be handled while processing variables. |
Eric Christopher | c2697f8 | 2013-10-19 01:04:47 +0000 | [diff] [blame] | 1479 | for (unsigned i = 1, N = Args.getNumElements(); i < N; ++i) { |
Manman Ren | b987e51 | 2013-10-29 00:53:03 +0000 | [diff] [blame] | 1480 | DIE *Arg = createAndAddDIE(dwarf::DW_TAG_formal_parameter, *SPDie); |
David Blaikie | 4f6bf27a | 2013-11-18 23:33:32 +0000 | [diff] [blame] | 1481 | DIType ATy(Args.getElement(i)); |
David Blaikie | 5174c84 | 2013-05-22 23:22:18 +0000 | [diff] [blame] | 1482 | addType(Arg, ATy); |
| 1483 | if (ATy.isArtificial()) |
| 1484 | addFlag(Arg, dwarf::DW_AT_artificial); |
David Blaikie | 5174c84 | 2013-05-22 23:22:18 +0000 | [diff] [blame] | 1485 | } |
Devang Patel | 8954371 | 2011-08-15 17:24:54 +0000 | [diff] [blame] | 1486 | } |
| 1487 | |
| 1488 | if (SP.isArtificial()) |
Eric Christopher | bb69a27 | 2012-08-24 01:14:27 +0000 | [diff] [blame] | 1489 | addFlag(SPDie, dwarf::DW_AT_artificial); |
Devang Patel | 8954371 | 2011-08-15 17:24:54 +0000 | [diff] [blame] | 1490 | |
| 1491 | if (!SP.isLocalToUnit()) |
Eric Christopher | bb69a27 | 2012-08-24 01:14:27 +0000 | [diff] [blame] | 1492 | addFlag(SPDie, dwarf::DW_AT_external); |
Devang Patel | 8954371 | 2011-08-15 17:24:54 +0000 | [diff] [blame] | 1493 | |
| 1494 | if (SP.isOptimized()) |
Eric Christopher | bb69a27 | 2012-08-24 01:14:27 +0000 | [diff] [blame] | 1495 | addFlag(SPDie, dwarf::DW_AT_APPLE_optimized); |
Devang Patel | 8954371 | 2011-08-15 17:24:54 +0000 | [diff] [blame] | 1496 | |
| 1497 | if (unsigned isa = Asm->getISAEncoding()) { |
| 1498 | addUInt(SPDie, dwarf::DW_AT_APPLE_isa, dwarf::DW_FORM_flag, isa); |
| 1499 | } |
| 1500 | |
Adrian Prantl | 99c7af2 | 2013-12-18 21:48:19 +0000 | [diff] [blame] | 1501 | if (SP.isLValueReference()) |
| 1502 | addFlag(SPDie, dwarf::DW_AT_reference); |
| 1503 | |
| 1504 | if (SP.isRValueReference()) |
| 1505 | addFlag(SPDie, dwarf::DW_AT_rvalue_reference); |
| 1506 | |
Adrian Prantl | ef129fb | 2014-01-18 02:12:00 +0000 | [diff] [blame] | 1507 | if (SP.isProtected()) |
| 1508 | addUInt(SPDie, dwarf::DW_AT_accessibility, dwarf::DW_FORM_data1, |
| 1509 | dwarf::DW_ACCESS_protected); |
| 1510 | else if (SP.isPrivate()) |
| 1511 | addUInt(SPDie, dwarf::DW_AT_accessibility, dwarf::DW_FORM_data1, |
| 1512 | dwarf::DW_ACCESS_private); |
| 1513 | else |
| 1514 | addUInt(SPDie, dwarf::DW_AT_accessibility, dwarf::DW_FORM_data1, |
| 1515 | dwarf::DW_ACCESS_public); |
| 1516 | |
| 1517 | if (SP.isExplicit()) |
| 1518 | addFlag(SPDie, dwarf::DW_AT_explicit); |
| 1519 | |
Devang Patel | 8954371 | 2011-08-15 17:24:54 +0000 | [diff] [blame] | 1520 | return SPDie; |
| 1521 | } |
| 1522 | |
Devang Patel | dfd6ec3 | 2011-08-15 17:57:41 +0000 | [diff] [blame] | 1523 | // Return const expression if value is a GEP to access merged global |
| 1524 | // constant. e.g. |
| 1525 | // i8* getelementptr ({ i8, i8, i8, i8 }* @_MergedGlobals, i32 0, i32 0) |
| 1526 | static const ConstantExpr *getMergedGlobalExpr(const Value *V) { |
| 1527 | const ConstantExpr *CE = dyn_cast_or_null<ConstantExpr>(V); |
| 1528 | if (!CE || CE->getNumOperands() != 3 || |
| 1529 | CE->getOpcode() != Instruction::GetElementPtr) |
| 1530 | return NULL; |
| 1531 | |
| 1532 | // First operand points to a global struct. |
| 1533 | Value *Ptr = CE->getOperand(0); |
| 1534 | if (!isa<GlobalValue>(Ptr) || |
| 1535 | !isa<StructType>(cast<PointerType>(Ptr->getType())->getElementType())) |
| 1536 | return NULL; |
| 1537 | |
| 1538 | // Second operand is zero. |
| 1539 | const ConstantInt *CI = dyn_cast_or_null<ConstantInt>(CE->getOperand(1)); |
| 1540 | if (!CI || !CI->isZero()) |
| 1541 | return NULL; |
| 1542 | |
| 1543 | // Third operand is offset. |
| 1544 | if (!isa<ConstantInt>(CE->getOperand(2))) |
| 1545 | return NULL; |
| 1546 | |
| 1547 | return CE; |
| 1548 | } |
| 1549 | |
| 1550 | /// createGlobalVariableDIE - create global variable DIE. |
Eric Christopher | 4287a49 | 2013-12-09 23:57:44 +0000 | [diff] [blame] | 1551 | void DwarfCompileUnit::createGlobalVariableDIE(DIGlobalVariable GV) { |
Devang Patel | dfd6ec3 | 2011-08-15 17:57:41 +0000 | [diff] [blame] | 1552 | // Check for pre-existence. |
David Blaikie | 2ad0016 | 2013-11-15 23:09:13 +0000 | [diff] [blame] | 1553 | if (getDIE(GV)) |
Devang Patel | dfd6ec3 | 2011-08-15 17:57:41 +0000 | [diff] [blame] | 1554 | return; |
| 1555 | |
David Blaikie | 5e390e4 | 2014-02-04 01:23:52 +0000 | [diff] [blame] | 1556 | assert(GV.isGlobalVariable()); |
Devang Patel | 0ecbcbd | 2011-08-18 23:17:55 +0000 | [diff] [blame] | 1557 | |
Eric Christopher | 08f7c8f | 2013-10-04 23:49:26 +0000 | [diff] [blame] | 1558 | DIScope GVContext = GV.getContext(); |
Eric Christopher | 4d23a4a | 2013-01-16 01:22:23 +0000 | [diff] [blame] | 1559 | DIType GTy = GV.getType(); |
| 1560 | |
| 1561 | // If this is a static data member definition, some attributes belong |
| 1562 | // to the declaration DIE. |
| 1563 | DIE *VariableDIE = NULL; |
Manman Ren | e697d3c | 2013-02-01 23:54:37 +0000 | [diff] [blame] | 1564 | bool IsStaticMember = false; |
Eric Christopher | 4d23a4a | 2013-01-16 01:22:23 +0000 | [diff] [blame] | 1565 | DIDerivedType SDMDecl = GV.getStaticDataMemberDeclaration(); |
| 1566 | if (SDMDecl.Verify()) { |
| 1567 | assert(SDMDecl.isStaticMember() && "Expected static member decl"); |
| 1568 | // We need the declaration DIE that is in the static member's class. |
Manman Ren | c6b6392 | 2013-10-14 20:33:57 +0000 | [diff] [blame] | 1569 | VariableDIE = getOrCreateStaticMemberDIE(SDMDecl); |
Manman Ren | e697d3c | 2013-02-01 23:54:37 +0000 | [diff] [blame] | 1570 | IsStaticMember = true; |
Eric Christopher | 4d23a4a | 2013-01-16 01:22:23 +0000 | [diff] [blame] | 1571 | } |
| 1572 | |
| 1573 | // If this is not a static data member definition, create the variable |
| 1574 | // DIE and add the initial set of attributes to it. |
| 1575 | if (!VariableDIE) { |
Manman Ren | f6b936b | 2013-10-29 05:49:41 +0000 | [diff] [blame] | 1576 | // Construct the context before querying for the existence of the DIE in |
| 1577 | // case such construction creates the DIE. |
| 1578 | DIE *ContextDIE = getOrCreateContextDIE(GVContext); |
Manman Ren | f6b936b | 2013-10-29 05:49:41 +0000 | [diff] [blame] | 1579 | |
Eric Christopher | 4d23a4a | 2013-01-16 01:22:23 +0000 | [diff] [blame] | 1580 | // Add to map. |
David Blaikie | 52c5020 | 2013-11-16 00:29:01 +0000 | [diff] [blame] | 1581 | VariableDIE = createAndAddDIE(GV.getTag(), *ContextDIE, GV); |
Eric Christopher | 4d23a4a | 2013-01-16 01:22:23 +0000 | [diff] [blame] | 1582 | |
| 1583 | // Add name and type. |
| 1584 | addString(VariableDIE, dwarf::DW_AT_name, GV.getDisplayName()); |
| 1585 | addType(VariableDIE, GTy); |
| 1586 | |
| 1587 | // Add scoping info. |
Eric Christopher | d2b497b | 2013-10-16 01:37:49 +0000 | [diff] [blame] | 1588 | if (!GV.isLocalToUnit()) |
Eric Christopher | 4d23a4a | 2013-01-16 01:22:23 +0000 | [diff] [blame] | 1589 | addFlag(VariableDIE, dwarf::DW_AT_external); |
| 1590 | |
| 1591 | // Add line number info. |
| 1592 | addSourceLine(VariableDIE, GV); |
Eric Christopher | 4d23a4a | 2013-01-16 01:22:23 +0000 | [diff] [blame] | 1593 | } |
| 1594 | |
Devang Patel | dfd6ec3 | 2011-08-15 17:57:41 +0000 | [diff] [blame] | 1595 | // Add location. |
Eric Christopher | 4996c70 | 2011-11-07 09:24:32 +0000 | [diff] [blame] | 1596 | bool addToAccelTable = false; |
Eric Christopher | 0a917b7 | 2011-11-11 03:16:32 +0000 | [diff] [blame] | 1597 | DIE *VariableSpecDIE = NULL; |
Eric Christopher | 4d23a4a | 2013-01-16 01:22:23 +0000 | [diff] [blame] | 1598 | bool isGlobalVariable = GV.getGlobal() != NULL; |
Devang Patel | dfd6ec3 | 2011-08-15 17:57:41 +0000 | [diff] [blame] | 1599 | if (isGlobalVariable) { |
Eric Christopher | 4996c70 | 2011-11-07 09:24:32 +0000 | [diff] [blame] | 1600 | addToAccelTable = true; |
Devang Patel | dfd6ec3 | 2011-08-15 17:57:41 +0000 | [diff] [blame] | 1601 | DIEBlock *Block = new (DIEValueAllocator) DIEBlock(); |
Rafael Espindola | 79858aa | 2013-10-29 17:07:16 +0000 | [diff] [blame] | 1602 | const MCSymbol *Sym = Asm->getSymbol(GV.getGlobal()); |
David Blaikie | f269497 | 2013-06-28 20:05:11 +0000 | [diff] [blame] | 1603 | if (GV.getGlobal()->isThreadLocal()) { |
| 1604 | // FIXME: Make this work with -gsplit-dwarf. |
| 1605 | unsigned PointerSize = Asm->getDataLayout().getPointerSize(); |
| 1606 | assert((PointerSize == 4 || PointerSize == 8) && |
| 1607 | "Add support for other sizes if necessary"); |
Ulrich Weigand | 2b6fc8d | 2013-07-02 18:47:09 +0000 | [diff] [blame] | 1608 | const MCExpr *Expr = |
David Blaikie | 8466ca8 | 2013-07-01 23:55:52 +0000 | [diff] [blame] | 1609 | Asm->getObjFileLowering().getDebugThreadLocalSymbol(Sym); |
David Blaikie | f269497 | 2013-06-28 20:05:11 +0000 | [diff] [blame] | 1610 | // Based on GCC's support for TLS: |
David Blaikie | 8466ca8 | 2013-07-01 23:55:52 +0000 | [diff] [blame] | 1611 | if (!DD->useSplitDwarf()) { |
| 1612 | // 1) Start with a constNu of the appropriate pointer size |
David Blaikie | f244319 | 2013-10-21 17:28:37 +0000 | [diff] [blame] | 1613 | addUInt(Block, dwarf::DW_FORM_data1, |
David Blaikie | 8466ca8 | 2013-07-01 23:55:52 +0000 | [diff] [blame] | 1614 | PointerSize == 4 ? dwarf::DW_OP_const4u : dwarf::DW_OP_const8u); |
Richard Mitton | 0aafb58 | 2013-10-07 18:39:18 +0000 | [diff] [blame] | 1615 | // 2) containing the (relocated) offset of the TLS variable |
| 1616 | // within the module's TLS block. |
David Blaikie | f244319 | 2013-10-21 17:28:37 +0000 | [diff] [blame] | 1617 | addExpr(Block, dwarf::DW_FORM_udata, Expr); |
David Blaikie | 8466ca8 | 2013-07-01 23:55:52 +0000 | [diff] [blame] | 1618 | } else { |
David Blaikie | f244319 | 2013-10-21 17:28:37 +0000 | [diff] [blame] | 1619 | addUInt(Block, dwarf::DW_FORM_data1, dwarf::DW_OP_GNU_const_index); |
| 1620 | addUInt(Block, dwarf::DW_FORM_udata, DU->getAddrPoolIndex(Expr)); |
David Blaikie | 8466ca8 | 2013-07-01 23:55:52 +0000 | [diff] [blame] | 1621 | } |
Richard Mitton | 0aafb58 | 2013-10-07 18:39:18 +0000 | [diff] [blame] | 1622 | // 3) followed by a custom OP to make the debugger do a TLS lookup. |
David Blaikie | f244319 | 2013-10-21 17:28:37 +0000 | [diff] [blame] | 1623 | addUInt(Block, dwarf::DW_FORM_data1, dwarf::DW_OP_GNU_push_tls_address); |
David Blaikie | bc7e0d4 | 2013-11-27 23:53:52 +0000 | [diff] [blame] | 1624 | } else { |
| 1625 | DD->addArangeLabel(SymbolCU(this, Sym)); |
David Blaikie | f269497 | 2013-06-28 20:05:11 +0000 | [diff] [blame] | 1626 | addOpAddress(Block, Sym); |
David Blaikie | bc7e0d4 | 2013-11-27 23:53:52 +0000 | [diff] [blame] | 1627 | } |
Devang Patel | dfd6ec3 | 2011-08-15 17:57:41 +0000 | [diff] [blame] | 1628 | // Do not create specification DIE if context is either compile unit |
| 1629 | // or a subprogram. |
Devang Patel | 5e6b65c | 2011-09-21 23:41:11 +0000 | [diff] [blame] | 1630 | if (GVContext && GV.isDefinition() && !GVContext.isCompileUnit() && |
Manman Ren | 3eb9dff | 2013-09-09 19:05:21 +0000 | [diff] [blame] | 1631 | !GVContext.isFile() && !DD->isSubprogramContext(GVContext)) { |
Devang Patel | dfd6ec3 | 2011-08-15 17:57:41 +0000 | [diff] [blame] | 1632 | // Create specification DIE. |
David Blaikie | 2a80e44 | 2013-12-02 22:09:48 +0000 | [diff] [blame] | 1633 | VariableSpecDIE = createAndAddDIE(dwarf::DW_TAG_variable, *UnitDie); |
Manman Ren | 4c4b69c | 2013-10-11 23:58:05 +0000 | [diff] [blame] | 1634 | addDIEEntry(VariableSpecDIE, dwarf::DW_AT_specification, VariableDIE); |
David Blaikie | f244319 | 2013-10-21 17:28:37 +0000 | [diff] [blame] | 1635 | addBlock(VariableSpecDIE, dwarf::DW_AT_location, Block); |
Eric Christopher | 4d23a4a | 2013-01-16 01:22:23 +0000 | [diff] [blame] | 1636 | // A static member's declaration is already flagged as such. |
| 1637 | if (!SDMDecl.Verify()) |
| 1638 | addFlag(VariableDIE, dwarf::DW_AT_declaration); |
Devang Patel | dfd6ec3 | 2011-08-15 17:57:41 +0000 | [diff] [blame] | 1639 | } else { |
David Blaikie | f244319 | 2013-10-21 17:28:37 +0000 | [diff] [blame] | 1640 | addBlock(VariableDIE, dwarf::DW_AT_location, Block); |
Eric Christopher | 4996c70 | 2011-11-07 09:24:32 +0000 | [diff] [blame] | 1641 | } |
Michael Gottesman | c89466f | 2013-09-04 04:39:38 +0000 | [diff] [blame] | 1642 | // Add the linkage name. |
Eric Christopher | 4d23a4a | 2013-01-16 01:22:23 +0000 | [diff] [blame] | 1643 | StringRef LinkageName = GV.getLinkageName(); |
Michael Gottesman | c89466f | 2013-09-04 04:39:38 +0000 | [diff] [blame] | 1644 | if (!LinkageName.empty()) |
Eric Christopher | 3f79b8c | 2013-02-27 23:49:47 +0000 | [diff] [blame] | 1645 | // From DWARF4: DIEs to which DW_AT_linkage_name may apply include: |
| 1646 | // TAG_common_block, TAG_constant, TAG_entry_point, TAG_subprogram and |
| 1647 | // TAG_variable. |
Eric Christopher | c2697f8 | 2013-10-19 01:04:47 +0000 | [diff] [blame] | 1648 | addString(IsStaticMember && VariableSpecDIE ? VariableSpecDIE |
| 1649 | : VariableDIE, |
| 1650 | dwarf::DW_AT_MIPS_linkage_name, |
Benjamin Kramer | 7c27564 | 2013-06-01 17:51:14 +0000 | [diff] [blame] | 1651 | GlobalValue::getRealLinkageName(LinkageName)); |
Eric Christopher | 92331fd | 2012-11-21 00:34:38 +0000 | [diff] [blame] | 1652 | } else if (const ConstantInt *CI = |
Eric Christopher | c2697f8 | 2013-10-19 01:04:47 +0000 | [diff] [blame] | 1653 | dyn_cast_or_null<ConstantInt>(GV.getConstant())) { |
Adrian Prantl | 322f41d | 2013-04-04 22:56:49 +0000 | [diff] [blame] | 1654 | // AT_const_value was added when the static member was created. To avoid |
Manman Ren | e697d3c | 2013-02-01 23:54:37 +0000 | [diff] [blame] | 1655 | // emitting AT_const_value multiple times, we only add AT_const_value when |
| 1656 | // it is not a static member. |
| 1657 | if (!IsStaticMember) |
Manman Ren | b338860 | 2013-10-05 01:43:03 +0000 | [diff] [blame] | 1658 | addConstantValue(VariableDIE, CI, isUnsignedDIType(DD, GTy)); |
David Blaikie | a781b25b | 2013-11-17 21:55:13 +0000 | [diff] [blame] | 1659 | } else if (const ConstantExpr *CE = getMergedGlobalExpr(GV->getOperand(11))) { |
Eric Christopher | 4996c70 | 2011-11-07 09:24:32 +0000 | [diff] [blame] | 1660 | addToAccelTable = true; |
Devang Patel | dfd6ec3 | 2011-08-15 17:57:41 +0000 | [diff] [blame] | 1661 | // GV is a merged global. |
| 1662 | DIEBlock *Block = new (DIEValueAllocator) DIEBlock(); |
| 1663 | Value *Ptr = CE->getOperand(0); |
David Blaikie | bc7e0d4 | 2013-11-27 23:53:52 +0000 | [diff] [blame] | 1664 | MCSymbol *Sym = Asm->getSymbol(cast<GlobalValue>(Ptr)); |
| 1665 | DD->addArangeLabel(SymbolCU(this, Sym)); |
| 1666 | addOpAddress(Block, Sym); |
David Blaikie | f244319 | 2013-10-21 17:28:37 +0000 | [diff] [blame] | 1667 | addUInt(Block, dwarf::DW_FORM_data1, dwarf::DW_OP_constu); |
Eric Christopher | c2697f8 | 2013-10-19 01:04:47 +0000 | [diff] [blame] | 1668 | SmallVector<Value *, 3> Idx(CE->op_begin() + 1, CE->op_end()); |
David Blaikie | f244319 | 2013-10-21 17:28:37 +0000 | [diff] [blame] | 1669 | addUInt(Block, dwarf::DW_FORM_udata, |
Eric Christopher | c2697f8 | 2013-10-19 01:04:47 +0000 | [diff] [blame] | 1670 | Asm->getDataLayout().getIndexedOffset(Ptr->getType(), Idx)); |
David Blaikie | f244319 | 2013-10-21 17:28:37 +0000 | [diff] [blame] | 1671 | addUInt(Block, dwarf::DW_FORM_data1, dwarf::DW_OP_plus); |
| 1672 | addBlock(VariableDIE, dwarf::DW_AT_location, Block); |
Devang Patel | dfd6ec3 | 2011-08-15 17:57:41 +0000 | [diff] [blame] | 1673 | } |
| 1674 | |
Eric Christopher | c12c211 | 2011-11-11 01:55:22 +0000 | [diff] [blame] | 1675 | if (addToAccelTable) { |
| 1676 | DIE *AddrDIE = VariableSpecDIE ? VariableSpecDIE : VariableDIE; |
| 1677 | addAccelName(GV.getName(), AddrDIE); |
Eric Christopher | 4996c70 | 2011-11-07 09:24:32 +0000 | [diff] [blame] | 1678 | |
Eric Christopher | c12c211 | 2011-11-11 01:55:22 +0000 | [diff] [blame] | 1679 | // If the linkage name is different than the name, go ahead and output |
| 1680 | // that as well into the name table. |
| 1681 | if (GV.getLinkageName() != "" && GV.getName() != GV.getLinkageName()) |
| 1682 | addAccelName(GV.getLinkageName(), AddrDIE); |
| 1683 | } |
Eric Christopher | d2b497b | 2013-10-16 01:37:49 +0000 | [diff] [blame] | 1684 | |
| 1685 | if (!GV.isLocalToUnit()) |
Eric Christopher | 2c8b790 | 2013-10-17 02:06:06 +0000 | [diff] [blame] | 1686 | addGlobalName(GV.getName(), VariableSpecDIE ? VariableSpecDIE : VariableDIE, |
| 1687 | GV.getContext()); |
Devang Patel | dfd6ec3 | 2011-08-15 17:57:41 +0000 | [diff] [blame] | 1688 | } |
| 1689 | |
Devang Patel | 0e821f4 | 2011-04-12 23:21:44 +0000 | [diff] [blame] | 1690 | /// constructSubrangeDIE - Construct subrange DIE from DISubrange. |
Eric Christopher | a5a7942 | 2013-12-09 23:32:48 +0000 | [diff] [blame] | 1691 | void DwarfUnit::constructSubrangeDIE(DIE &Buffer, DISubrange SR, DIE *IndexTy) { |
Manman Ren | b987e51 | 2013-10-29 00:53:03 +0000 | [diff] [blame] | 1692 | DIE *DW_Subrange = createAndAddDIE(dwarf::DW_TAG_subrange_type, Buffer); |
Manman Ren | 4c4b69c | 2013-10-11 23:58:05 +0000 | [diff] [blame] | 1693 | addDIEEntry(DW_Subrange, dwarf::DW_AT_type, IndexTy); |
Devang Patel | 0e821f4 | 2011-04-12 23:21:44 +0000 | [diff] [blame] | 1694 | |
Bill Wendling | 28fe9e7 | 2012-12-06 07:38:10 +0000 | [diff] [blame] | 1695 | // The LowerBound value defines the lower bounds which is typically zero for |
| 1696 | // C/C++. The Count value is the number of elements. Values are 64 bit. If |
| 1697 | // Count == -1 then the array is unbounded and we do not emit |
| 1698 | // DW_AT_lower_bound and DW_AT_upper_bound attributes. If LowerBound == 0 and |
| 1699 | // Count == 0, then the array has zero elements in which case we do not emit |
| 1700 | // an upper bound. |
| 1701 | int64_t LowerBound = SR.getLo(); |
Bill Wendling | 3495f9b | 2012-12-06 07:55:19 +0000 | [diff] [blame] | 1702 | int64_t DefaultLowerBound = getDefaultLowerBound(); |
Bill Wendling | d776712 | 2012-12-04 21:34:03 +0000 | [diff] [blame] | 1703 | int64_t Count = SR.getCount(); |
Devang Patel | 0e821f4 | 2011-04-12 23:21:44 +0000 | [diff] [blame] | 1704 | |
Bill Wendling | 3495f9b | 2012-12-06 07:55:19 +0000 | [diff] [blame] | 1705 | if (DefaultLowerBound == -1 || LowerBound != DefaultLowerBound) |
David Blaikie | f244319 | 2013-10-21 17:28:37 +0000 | [diff] [blame] | 1706 | addUInt(DW_Subrange, dwarf::DW_AT_lower_bound, None, LowerBound); |
Bill Wendling | 28fe9e7 | 2012-12-06 07:38:10 +0000 | [diff] [blame] | 1707 | |
| 1708 | if (Count != -1 && Count != 0) |
Bill Wendling | d776712 | 2012-12-04 21:34:03 +0000 | [diff] [blame] | 1709 | // FIXME: An unbounded array should reference the expression that defines |
| 1710 | // the array. |
Eric Christopher | 98b7f17 | 2013-11-11 18:52:36 +0000 | [diff] [blame] | 1711 | addUInt(DW_Subrange, dwarf::DW_AT_upper_bound, None, |
| 1712 | LowerBound + Count - 1); |
Devang Patel | 0e821f4 | 2011-04-12 23:21:44 +0000 | [diff] [blame] | 1713 | } |
| 1714 | |
| 1715 | /// constructArrayTypeDIE - Construct array type DIE from DICompositeType. |
Eric Christopher | a5a7942 | 2013-12-09 23:32:48 +0000 | [diff] [blame] | 1716 | void DwarfUnit::constructArrayTypeDIE(DIE &Buffer, DICompositeType CTy) { |
Eric Christopher | df9955d | 2013-11-11 18:52:31 +0000 | [diff] [blame] | 1717 | if (CTy.isVector()) |
Eric Christopher | bb69a27 | 2012-08-24 01:14:27 +0000 | [diff] [blame] | 1718 | addFlag(&Buffer, dwarf::DW_AT_GNU_vector); |
Devang Patel | 0e821f4 | 2011-04-12 23:21:44 +0000 | [diff] [blame] | 1719 | |
Eric Christopher | 0df08e2 | 2013-08-08 07:40:37 +0000 | [diff] [blame] | 1720 | // Emit the element type. |
Eric Christopher | df9955d | 2013-11-11 18:52:31 +0000 | [diff] [blame] | 1721 | addType(&Buffer, resolve(CTy.getTypeDerivedFrom())); |
Devang Patel | 0e821f4 | 2011-04-12 23:21:44 +0000 | [diff] [blame] | 1722 | |
| 1723 | // Get an anonymous type for index type. |
Eric Christopher | cad9b53 | 2013-01-04 21:51:53 +0000 | [diff] [blame] | 1724 | // FIXME: This type should be passed down from the front end |
| 1725 | // as different languages may have different sizes for indexes. |
Devang Patel | 0e821f4 | 2011-04-12 23:21:44 +0000 | [diff] [blame] | 1726 | DIE *IdxTy = getIndexTyDie(); |
| 1727 | if (!IdxTy) { |
| 1728 | // Construct an anonymous type for index type. |
David Blaikie | 2a80e44 | 2013-12-02 22:09:48 +0000 | [diff] [blame] | 1729 | IdxTy = createAndAddDIE(dwarf::DW_TAG_base_type, *UnitDie); |
Eric Christopher | cad9b53 | 2013-01-04 21:51:53 +0000 | [diff] [blame] | 1730 | addString(IdxTy, dwarf::DW_AT_name, "int"); |
David Blaikie | f244319 | 2013-10-21 17:28:37 +0000 | [diff] [blame] | 1731 | addUInt(IdxTy, dwarf::DW_AT_byte_size, None, sizeof(int32_t)); |
Devang Patel | 0e821f4 | 2011-04-12 23:21:44 +0000 | [diff] [blame] | 1732 | addUInt(IdxTy, dwarf::DW_AT_encoding, dwarf::DW_FORM_data1, |
| 1733 | dwarf::DW_ATE_signed); |
Devang Patel | 0e821f4 | 2011-04-12 23:21:44 +0000 | [diff] [blame] | 1734 | setIndexTyDie(IdxTy); |
| 1735 | } |
| 1736 | |
| 1737 | // Add subranges to array type. |
Eric Christopher | df9955d | 2013-11-11 18:52:31 +0000 | [diff] [blame] | 1738 | DIArray Elements = CTy.getTypeArray(); |
Devang Patel | 0e821f4 | 2011-04-12 23:21:44 +0000 | [diff] [blame] | 1739 | for (unsigned i = 0, N = Elements.getNumElements(); i < N; ++i) { |
| 1740 | DIDescriptor Element = Elements.getElement(i); |
| 1741 | if (Element.getTag() == dwarf::DW_TAG_subrange_type) |
| 1742 | constructSubrangeDIE(Buffer, DISubrange(Element), IdxTy); |
| 1743 | } |
| 1744 | } |
| 1745 | |
Eric Christopher | aeb105f | 2013-11-11 18:52:39 +0000 | [diff] [blame] | 1746 | /// constructEnumTypeDIE - Construct an enum type DIE from DICompositeType. |
Eric Christopher | a5a7942 | 2013-12-09 23:32:48 +0000 | [diff] [blame] | 1747 | void DwarfUnit::constructEnumTypeDIE(DIE &Buffer, DICompositeType CTy) { |
Eric Christopher | aeb105f | 2013-11-11 18:52:39 +0000 | [diff] [blame] | 1748 | DIArray Elements = CTy.getTypeArray(); |
| 1749 | |
| 1750 | // Add enumerators to enumeration type. |
| 1751 | for (unsigned i = 0, N = Elements.getNumElements(); i < N; ++i) { |
David Blaikie | 4f6bf27a | 2013-11-18 23:33:32 +0000 | [diff] [blame] | 1752 | DIEnumerator Enum(Elements.getElement(i)); |
Eric Christopher | aeb105f | 2013-11-11 18:52:39 +0000 | [diff] [blame] | 1753 | if (Enum.isEnumerator()) { |
| 1754 | DIE *Enumerator = createAndAddDIE(dwarf::DW_TAG_enumerator, Buffer); |
David Blaikie | 4f6bf27a | 2013-11-18 23:33:32 +0000 | [diff] [blame] | 1755 | StringRef Name = Enum.getName(); |
Eric Christopher | aeb105f | 2013-11-11 18:52:39 +0000 | [diff] [blame] | 1756 | addString(Enumerator, dwarf::DW_AT_name, Name); |
David Blaikie | 4f6bf27a | 2013-11-18 23:33:32 +0000 | [diff] [blame] | 1757 | int64_t Value = Enum.getEnumValue(); |
Eric Christopher | a07e4f5 | 2013-11-19 09:28:34 +0000 | [diff] [blame] | 1758 | addSInt(Enumerator, dwarf::DW_AT_const_value, dwarf::DW_FORM_sdata, |
| 1759 | Value); |
Eric Christopher | aeb105f | 2013-11-11 18:52:39 +0000 | [diff] [blame] | 1760 | } |
| 1761 | } |
| 1762 | DIType DTy = resolve(CTy.getTypeDerivedFrom()); |
| 1763 | if (DTy) { |
| 1764 | addType(&Buffer, DTy); |
| 1765 | addFlag(&Buffer, dwarf::DW_AT_enum_class); |
| 1766 | } |
Devang Patel | 0e821f4 | 2011-04-12 23:21:44 +0000 | [diff] [blame] | 1767 | } |
| 1768 | |
Devang Patel | 8954371 | 2011-08-15 17:24:54 +0000 | [diff] [blame] | 1769 | /// constructContainingTypeDIEs - Construct DIEs for types that contain |
| 1770 | /// vtables. |
Eric Christopher | a5a7942 | 2013-12-09 23:32:48 +0000 | [diff] [blame] | 1771 | void DwarfUnit::constructContainingTypeDIEs() { |
Devang Patel | 8954371 | 2011-08-15 17:24:54 +0000 | [diff] [blame] | 1772 | for (DenseMap<DIE *, const MDNode *>::iterator CI = ContainingTypeMap.begin(), |
Eric Christopher | c2697f8 | 2013-10-19 01:04:47 +0000 | [diff] [blame] | 1773 | CE = ContainingTypeMap.end(); |
| 1774 | CI != CE; ++CI) { |
Devang Patel | 8954371 | 2011-08-15 17:24:54 +0000 | [diff] [blame] | 1775 | DIE *SPDie = CI->first; |
David Blaikie | 2ad0016 | 2013-11-15 23:09:13 +0000 | [diff] [blame] | 1776 | DIDescriptor D(CI->second); |
| 1777 | if (!D) |
Eric Christopher | c2697f8 | 2013-10-19 01:04:47 +0000 | [diff] [blame] | 1778 | continue; |
David Blaikie | 2ad0016 | 2013-11-15 23:09:13 +0000 | [diff] [blame] | 1779 | DIE *NDie = getDIE(D); |
Eric Christopher | c2697f8 | 2013-10-19 01:04:47 +0000 | [diff] [blame] | 1780 | if (!NDie) |
| 1781 | continue; |
Manman Ren | 4c4b69c | 2013-10-11 23:58:05 +0000 | [diff] [blame] | 1782 | addDIEEntry(SPDie, dwarf::DW_AT_containing_type, NDie); |
Devang Patel | 8954371 | 2011-08-15 17:24:54 +0000 | [diff] [blame] | 1783 | } |
| 1784 | } |
| 1785 | |
Devang Patel | 3acc70e | 2011-08-15 22:04:40 +0000 | [diff] [blame] | 1786 | /// constructVariableDIE - Construct a DIE for the given DbgVariable. |
Eric Christopher | a5a7942 | 2013-12-09 23:32:48 +0000 | [diff] [blame] | 1787 | DIE *DwarfUnit::constructVariableDIE(DbgVariable &DV, bool isScopeAbstract) { |
Eric Christopher | 34a2c87 | 2013-11-15 01:43:19 +0000 | [diff] [blame] | 1788 | StringRef Name = DV.getName(); |
Devang Patel | 3acc70e | 2011-08-15 22:04:40 +0000 | [diff] [blame] | 1789 | |
Devang Patel | 3acc70e | 2011-08-15 22:04:40 +0000 | [diff] [blame] | 1790 | // Define variable debug information entry. |
Eric Christopher | 34a2c87 | 2013-11-15 01:43:19 +0000 | [diff] [blame] | 1791 | DIE *VariableDie = new DIE(DV.getTag()); |
| 1792 | DbgVariable *AbsVar = DV.getAbstractVariable(); |
Devang Patel | 3acc70e | 2011-08-15 22:04:40 +0000 | [diff] [blame] | 1793 | DIE *AbsDIE = AbsVar ? AbsVar->getDIE() : NULL; |
Manman Ren | 4213c39 | 2013-05-29 17:16:59 +0000 | [diff] [blame] | 1794 | if (AbsDIE) |
Manman Ren | 4c4b69c | 2013-10-11 23:58:05 +0000 | [diff] [blame] | 1795 | addDIEEntry(VariableDie, dwarf::DW_AT_abstract_origin, AbsDIE); |
Devang Patel | 3acc70e | 2011-08-15 22:04:40 +0000 | [diff] [blame] | 1796 | else { |
David Blaikie | 715528b | 2013-08-19 03:34:03 +0000 | [diff] [blame] | 1797 | if (!Name.empty()) |
| 1798 | addString(VariableDie, dwarf::DW_AT_name, Name); |
Eric Christopher | 34a2c87 | 2013-11-15 01:43:19 +0000 | [diff] [blame] | 1799 | addSourceLine(VariableDie, DV.getVariable()); |
| 1800 | addType(VariableDie, DV.getType()); |
Devang Patel | 3acc70e | 2011-08-15 22:04:40 +0000 | [diff] [blame] | 1801 | } |
| 1802 | |
Eric Christopher | 34a2c87 | 2013-11-15 01:43:19 +0000 | [diff] [blame] | 1803 | if (DV.isArtificial()) |
Eric Christopher | bb69a27 | 2012-08-24 01:14:27 +0000 | [diff] [blame] | 1804 | addFlag(VariableDie, dwarf::DW_AT_artificial); |
Devang Patel | 3acc70e | 2011-08-15 22:04:40 +0000 | [diff] [blame] | 1805 | |
| 1806 | if (isScopeAbstract) { |
Eric Christopher | 34a2c87 | 2013-11-15 01:43:19 +0000 | [diff] [blame] | 1807 | DV.setDIE(VariableDie); |
Devang Patel | 3acc70e | 2011-08-15 22:04:40 +0000 | [diff] [blame] | 1808 | return VariableDie; |
| 1809 | } |
| 1810 | |
| 1811 | // Add variable address. |
| 1812 | |
Eric Christopher | 34a2c87 | 2013-11-15 01:43:19 +0000 | [diff] [blame] | 1813 | unsigned Offset = DV.getDotDebugLocOffset(); |
Devang Patel | 3acc70e | 2011-08-15 22:04:40 +0000 | [diff] [blame] | 1814 | if (Offset != ~0U) { |
Eric Christopher | 33ff697 | 2013-11-21 23:46:41 +0000 | [diff] [blame] | 1815 | addSectionLabel(VariableDie, dwarf::DW_AT_location, |
| 1816 | Asm->GetTempSymbol("debug_loc", Offset)); |
Eric Christopher | 34a2c87 | 2013-11-15 01:43:19 +0000 | [diff] [blame] | 1817 | DV.setDIE(VariableDie); |
Devang Patel | 3acc70e | 2011-08-15 22:04:40 +0000 | [diff] [blame] | 1818 | return VariableDie; |
| 1819 | } |
| 1820 | |
Eric Christopher | cead033 | 2011-10-03 15:49:20 +0000 | [diff] [blame] | 1821 | // Check if variable is described by a DBG_VALUE instruction. |
Eric Christopher | 34a2c87 | 2013-11-15 01:43:19 +0000 | [diff] [blame] | 1822 | if (const MachineInstr *DVInsn = DV.getMInsn()) { |
David Blaikie | 0252265b | 2013-06-16 20:34:15 +0000 | [diff] [blame] | 1823 | assert(DVInsn->getNumOperands() == 3); |
| 1824 | if (DVInsn->getOperand(0).isReg()) { |
| 1825 | const MachineOperand RegOp = DVInsn->getOperand(0); |
Adrian Prantl | 1994288 | 2013-07-09 21:44:06 +0000 | [diff] [blame] | 1826 | // If the second operand is an immediate, this is an indirect value. |
Adrian Prantl | 418d1d1 | 2013-07-09 20:28:37 +0000 | [diff] [blame] | 1827 | if (DVInsn->getOperand(1).isImm()) { |
Eric Christopher | c2697f8 | 2013-10-19 01:04:47 +0000 | [diff] [blame] | 1828 | MachineLocation Location(RegOp.getReg(), |
| 1829 | DVInsn->getOperand(1).getImm()); |
Eric Christopher | 34a2c87 | 2013-11-15 01:43:19 +0000 | [diff] [blame] | 1830 | addVariableAddress(DV, VariableDie, Location); |
David Blaikie | 0252265b | 2013-06-16 20:34:15 +0000 | [diff] [blame] | 1831 | } else if (RegOp.getReg()) |
Eric Christopher | 34a2c87 | 2013-11-15 01:43:19 +0000 | [diff] [blame] | 1832 | addVariableAddress(DV, VariableDie, MachineLocation(RegOp.getReg())); |
David Blaikie | 0252265b | 2013-06-16 20:34:15 +0000 | [diff] [blame] | 1833 | } else if (DVInsn->getOperand(0).isImm()) |
Eric Christopher | 34a2c87 | 2013-11-15 01:43:19 +0000 | [diff] [blame] | 1834 | addConstantValue(VariableDie, DVInsn->getOperand(0), DV.getType()); |
David Blaikie | 0252265b | 2013-06-16 20:34:15 +0000 | [diff] [blame] | 1835 | else if (DVInsn->getOperand(0).isFPImm()) |
Eric Christopher | 78fcf490 | 2013-07-03 01:08:30 +0000 | [diff] [blame] | 1836 | addConstantFPValue(VariableDie, DVInsn->getOperand(0)); |
David Blaikie | 0252265b | 2013-06-16 20:34:15 +0000 | [diff] [blame] | 1837 | else if (DVInsn->getOperand(0).isCImm()) |
Eric Christopher | 78fcf490 | 2013-07-03 01:08:30 +0000 | [diff] [blame] | 1838 | addConstantValue(VariableDie, DVInsn->getOperand(0).getCImm(), |
Eric Christopher | 34a2c87 | 2013-11-15 01:43:19 +0000 | [diff] [blame] | 1839 | isUnsignedDIType(DD, DV.getType())); |
Eric Christopher | 78fcf490 | 2013-07-03 01:08:30 +0000 | [diff] [blame] | 1840 | |
Eric Christopher | 34a2c87 | 2013-11-15 01:43:19 +0000 | [diff] [blame] | 1841 | DV.setDIE(VariableDie); |
Devang Patel | 3acc70e | 2011-08-15 22:04:40 +0000 | [diff] [blame] | 1842 | return VariableDie; |
| 1843 | } else { |
| 1844 | // .. else use frame index. |
Eric Christopher | 34a2c87 | 2013-11-15 01:43:19 +0000 | [diff] [blame] | 1845 | int FI = DV.getFrameIndex(); |
Devang Patel | 3acc70e | 2011-08-15 22:04:40 +0000 | [diff] [blame] | 1846 | if (FI != ~0) { |
| 1847 | unsigned FrameReg = 0; |
| 1848 | const TargetFrameLowering *TFI = Asm->TM.getFrameLowering(); |
Eric Christopher | c2697f8 | 2013-10-19 01:04:47 +0000 | [diff] [blame] | 1849 | int Offset = TFI->getFrameIndexReference(*Asm->MF, FI, FrameReg); |
Devang Patel | 3acc70e | 2011-08-15 22:04:40 +0000 | [diff] [blame] | 1850 | MachineLocation Location(FrameReg, Offset); |
Eric Christopher | 34a2c87 | 2013-11-15 01:43:19 +0000 | [diff] [blame] | 1851 | addVariableAddress(DV, VariableDie, Location); |
Devang Patel | 3acc70e | 2011-08-15 22:04:40 +0000 | [diff] [blame] | 1852 | } |
| 1853 | } |
| 1854 | |
Eric Christopher | 34a2c87 | 2013-11-15 01:43:19 +0000 | [diff] [blame] | 1855 | DV.setDIE(VariableDie); |
Devang Patel | 3acc70e | 2011-08-15 22:04:40 +0000 | [diff] [blame] | 1856 | return VariableDie; |
| 1857 | } |
| 1858 | |
Manman Ren | 230ec86 | 2013-10-23 23:00:44 +0000 | [diff] [blame] | 1859 | /// constructMemberDIE - Construct member DIE from DIDerivedType. |
Eric Christopher | a5a7942 | 2013-12-09 23:32:48 +0000 | [diff] [blame] | 1860 | void DwarfUnit::constructMemberDIE(DIE &Buffer, DIDerivedType DT) { |
Manman Ren | b987e51 | 2013-10-29 00:53:03 +0000 | [diff] [blame] | 1861 | DIE *MemberDie = createAndAddDIE(DT.getTag(), Buffer); |
Devang Patel | 0e821f4 | 2011-04-12 23:21:44 +0000 | [diff] [blame] | 1862 | StringRef Name = DT.getName(); |
| 1863 | if (!Name.empty()) |
Nick Lewycky | d59c0ca | 2011-10-27 06:44:11 +0000 | [diff] [blame] | 1864 | addString(MemberDie, dwarf::DW_AT_name, Name); |
Devang Patel | 0e821f4 | 2011-04-12 23:21:44 +0000 | [diff] [blame] | 1865 | |
Manman Ren | 93b3090 | 2013-10-08 18:42:58 +0000 | [diff] [blame] | 1866 | addType(MemberDie, resolve(DT.getTypeDerivedFrom())); |
Devang Patel | 0e821f4 | 2011-04-12 23:21:44 +0000 | [diff] [blame] | 1867 | |
| 1868 | addSourceLine(MemberDie, DT); |
| 1869 | |
Eric Christopher | c2697f8 | 2013-10-19 01:04:47 +0000 | [diff] [blame] | 1870 | if (DT.getTag() == dwarf::DW_TAG_inheritance && DT.isVirtual()) { |
Devang Patel | 0e821f4 | 2011-04-12 23:21:44 +0000 | [diff] [blame] | 1871 | |
| 1872 | // For C++, virtual base classes are not at fixed offset. Use following |
| 1873 | // expression to extract appropriate offset from vtable. |
| 1874 | // BaseAddr = ObAddr + *((*ObAddr) - Offset) |
| 1875 | |
| 1876 | DIEBlock *VBaseLocationDie = new (DIEValueAllocator) DIEBlock(); |
David Blaikie | f244319 | 2013-10-21 17:28:37 +0000 | [diff] [blame] | 1877 | addUInt(VBaseLocationDie, dwarf::DW_FORM_data1, dwarf::DW_OP_dup); |
| 1878 | addUInt(VBaseLocationDie, dwarf::DW_FORM_data1, dwarf::DW_OP_deref); |
| 1879 | addUInt(VBaseLocationDie, dwarf::DW_FORM_data1, dwarf::DW_OP_constu); |
| 1880 | addUInt(VBaseLocationDie, dwarf::DW_FORM_udata, DT.getOffsetInBits()); |
| 1881 | addUInt(VBaseLocationDie, dwarf::DW_FORM_data1, dwarf::DW_OP_minus); |
| 1882 | addUInt(VBaseLocationDie, dwarf::DW_FORM_data1, dwarf::DW_OP_deref); |
| 1883 | addUInt(VBaseLocationDie, dwarf::DW_FORM_data1, dwarf::DW_OP_plus); |
Devang Patel | 0e821f4 | 2011-04-12 23:21:44 +0000 | [diff] [blame] | 1884 | |
David Blaikie | f244319 | 2013-10-21 17:28:37 +0000 | [diff] [blame] | 1885 | addBlock(MemberDie, dwarf::DW_AT_data_member_location, VBaseLocationDie); |
David Blaikie | 71d34a2 | 2013-11-01 00:25:45 +0000 | [diff] [blame] | 1886 | } else { |
| 1887 | uint64_t Size = DT.getSizeInBits(); |
| 1888 | uint64_t FieldSize = getBaseTypeSize(DD, DT); |
| 1889 | uint64_t OffsetInBytes; |
| 1890 | |
| 1891 | if (Size != FieldSize) { |
| 1892 | // Handle bitfield. |
| 1893 | addUInt(MemberDie, dwarf::DW_AT_byte_size, None, |
| 1894 | getBaseTypeSize(DD, DT) >> 3); |
| 1895 | addUInt(MemberDie, dwarf::DW_AT_bit_size, None, DT.getSizeInBits()); |
| 1896 | |
| 1897 | uint64_t Offset = DT.getOffsetInBits(); |
| 1898 | uint64_t AlignMask = ~(DT.getAlignInBits() - 1); |
| 1899 | uint64_t HiMark = (Offset + FieldSize) & AlignMask; |
| 1900 | uint64_t FieldOffset = (HiMark - FieldSize); |
| 1901 | Offset -= FieldOffset; |
| 1902 | |
| 1903 | // Maybe we need to work from the other end. |
| 1904 | if (Asm->getDataLayout().isLittleEndian()) |
| 1905 | Offset = FieldSize - (Offset + Size); |
| 1906 | addUInt(MemberDie, dwarf::DW_AT_bit_offset, None, Offset); |
| 1907 | |
Adrian Prantl | c67655a | 2014-01-28 18:13:47 +0000 | [diff] [blame] | 1908 | // Here DW_AT_data_member_location points to the anonymous |
David Blaikie | 71d34a2 | 2013-11-01 00:25:45 +0000 | [diff] [blame] | 1909 | // field that includes this bit field. |
| 1910 | OffsetInBytes = FieldOffset >> 3; |
| 1911 | } else |
| 1912 | // This is not a bitfield. |
| 1913 | OffsetInBytes = DT.getOffsetInBits() >> 3; |
David Blaikie | 2ada116 | 2014-01-03 00:48:38 +0000 | [diff] [blame] | 1914 | |
David Blaikie | 22b29a5 | 2014-01-03 01:30:05 +0000 | [diff] [blame] | 1915 | if (DD->getDwarfVersion() <= 2) { |
| 1916 | DIEBlock *MemLocationDie = new (DIEValueAllocator) DIEBlock(); |
| 1917 | addUInt(MemLocationDie, dwarf::DW_FORM_data1, dwarf::DW_OP_plus_uconst); |
| 1918 | addUInt(MemLocationDie, dwarf::DW_FORM_udata, OffsetInBytes); |
| 1919 | addBlock(MemberDie, dwarf::DW_AT_data_member_location, MemLocationDie); |
| 1920 | } else |
| 1921 | addUInt(MemberDie, dwarf::DW_AT_data_member_location, None, |
| 1922 | OffsetInBytes); |
David Blaikie | 71d34a2 | 2013-11-01 00:25:45 +0000 | [diff] [blame] | 1923 | } |
Devang Patel | 0e821f4 | 2011-04-12 23:21:44 +0000 | [diff] [blame] | 1924 | |
| 1925 | if (DT.isProtected()) |
Nick Lewycky | cb91849 | 2011-12-13 05:09:11 +0000 | [diff] [blame] | 1926 | addUInt(MemberDie, dwarf::DW_AT_accessibility, dwarf::DW_FORM_data1, |
Devang Patel | 0e821f4 | 2011-04-12 23:21:44 +0000 | [diff] [blame] | 1927 | dwarf::DW_ACCESS_protected); |
| 1928 | else if (DT.isPrivate()) |
Nick Lewycky | cb91849 | 2011-12-13 05:09:11 +0000 | [diff] [blame] | 1929 | addUInt(MemberDie, dwarf::DW_AT_accessibility, dwarf::DW_FORM_data1, |
Devang Patel | 0e821f4 | 2011-04-12 23:21:44 +0000 | [diff] [blame] | 1930 | dwarf::DW_ACCESS_private); |
| 1931 | // Otherwise C++ member and base classes are considered public. |
Eric Christopher | 92331fd | 2012-11-21 00:34:38 +0000 | [diff] [blame] | 1932 | else |
Nick Lewycky | cb91849 | 2011-12-13 05:09:11 +0000 | [diff] [blame] | 1933 | addUInt(MemberDie, dwarf::DW_AT_accessibility, dwarf::DW_FORM_data1, |
Devang Patel | 0e821f4 | 2011-04-12 23:21:44 +0000 | [diff] [blame] | 1934 | dwarf::DW_ACCESS_public); |
| 1935 | if (DT.isVirtual()) |
Nick Lewycky | cfde1a2 | 2011-12-14 00:56:07 +0000 | [diff] [blame] | 1936 | addUInt(MemberDie, dwarf::DW_AT_virtuality, dwarf::DW_FORM_data1, |
Devang Patel | 0e821f4 | 2011-04-12 23:21:44 +0000 | [diff] [blame] | 1937 | dwarf::DW_VIRTUALITY_virtual); |
Devang Patel | 514b400 | 2011-04-16 00:11:51 +0000 | [diff] [blame] | 1938 | |
| 1939 | // Objective-C properties. |
Devang Patel | 4488217 | 2012-02-06 17:49:43 +0000 | [diff] [blame] | 1940 | if (MDNode *PNode = DT.getObjCProperty()) |
| 1941 | if (DIEEntry *PropertyDie = getDIEEntry(PNode)) |
Eric Christopher | 92331fd | 2012-11-21 00:34:38 +0000 | [diff] [blame] | 1942 | MemberDie->addValue(dwarf::DW_AT_APPLE_property, dwarf::DW_FORM_ref4, |
Devang Patel | 4488217 | 2012-02-06 17:49:43 +0000 | [diff] [blame] | 1943 | PropertyDie); |
| 1944 | |
David Blaikie | 37fefc3 | 2012-12-13 22:43:07 +0000 | [diff] [blame] | 1945 | if (DT.isArtificial()) |
| 1946 | addFlag(MemberDie, dwarf::DW_AT_artificial); |
Devang Patel | 0e821f4 | 2011-04-12 23:21:44 +0000 | [diff] [blame] | 1947 | } |
Eric Christopher | 4d23a4a | 2013-01-16 01:22:23 +0000 | [diff] [blame] | 1948 | |
Manman Ren | c6b6392 | 2013-10-14 20:33:57 +0000 | [diff] [blame] | 1949 | /// getOrCreateStaticMemberDIE - Create new DIE for C++ static member. |
Eric Christopher | a5a7942 | 2013-12-09 23:32:48 +0000 | [diff] [blame] | 1950 | DIE *DwarfUnit::getOrCreateStaticMemberDIE(DIDerivedType DT) { |
Eric Christopher | 4d23a4a | 2013-01-16 01:22:23 +0000 | [diff] [blame] | 1951 | if (!DT.Verify()) |
| 1952 | return NULL; |
| 1953 | |
Manman Ren | c6b6392 | 2013-10-14 20:33:57 +0000 | [diff] [blame] | 1954 | // Construct the context before querying for the existence of the DIE in case |
| 1955 | // such construction creates the DIE. |
| 1956 | DIE *ContextDIE = getOrCreateContextDIE(resolve(DT.getContext())); |
David Blaikie | bd700e4 | 2013-11-14 21:24:34 +0000 | [diff] [blame] | 1957 | assert(dwarf::isType(ContextDIE->getTag()) && |
| 1958 | "Static member should belong to a type."); |
Manman Ren | c6b6392 | 2013-10-14 20:33:57 +0000 | [diff] [blame] | 1959 | |
| 1960 | DIE *StaticMemberDIE = getDIE(DT); |
| 1961 | if (StaticMemberDIE) |
| 1962 | return StaticMemberDIE; |
| 1963 | |
Manman Ren | b987e51 | 2013-10-29 00:53:03 +0000 | [diff] [blame] | 1964 | StaticMemberDIE = createAndAddDIE(DT.getTag(), *ContextDIE, DT); |
Manman Ren | c6b6392 | 2013-10-14 20:33:57 +0000 | [diff] [blame] | 1965 | |
Manman Ren | 93b3090 | 2013-10-08 18:42:58 +0000 | [diff] [blame] | 1966 | DIType Ty = resolve(DT.getTypeDerivedFrom()); |
Eric Christopher | 4d23a4a | 2013-01-16 01:22:23 +0000 | [diff] [blame] | 1967 | |
| 1968 | addString(StaticMemberDIE, dwarf::DW_AT_name, DT.getName()); |
| 1969 | addType(StaticMemberDIE, Ty); |
| 1970 | addSourceLine(StaticMemberDIE, DT); |
| 1971 | addFlag(StaticMemberDIE, dwarf::DW_AT_external); |
| 1972 | addFlag(StaticMemberDIE, dwarf::DW_AT_declaration); |
| 1973 | |
| 1974 | // FIXME: We could omit private if the parent is a class_type, and |
| 1975 | // public if the parent is something else. |
| 1976 | if (DT.isProtected()) |
| 1977 | addUInt(StaticMemberDIE, dwarf::DW_AT_accessibility, dwarf::DW_FORM_data1, |
| 1978 | dwarf::DW_ACCESS_protected); |
| 1979 | else if (DT.isPrivate()) |
| 1980 | addUInt(StaticMemberDIE, dwarf::DW_AT_accessibility, dwarf::DW_FORM_data1, |
| 1981 | dwarf::DW_ACCESS_private); |
| 1982 | else |
| 1983 | addUInt(StaticMemberDIE, dwarf::DW_AT_accessibility, dwarf::DW_FORM_data1, |
| 1984 | dwarf::DW_ACCESS_public); |
| 1985 | |
| 1986 | if (const ConstantInt *CI = dyn_cast_or_null<ConstantInt>(DT.getConstant())) |
Manman Ren | b338860 | 2013-10-05 01:43:03 +0000 | [diff] [blame] | 1987 | addConstantValue(StaticMemberDIE, CI, isUnsignedDIType(DD, Ty)); |
David Blaikie | a39a76e | 2013-01-20 01:18:01 +0000 | [diff] [blame] | 1988 | if (const ConstantFP *CFP = dyn_cast_or_null<ConstantFP>(DT.getConstant())) |
| 1989 | addConstantFPValue(StaticMemberDIE, CFP); |
Eric Christopher | 4d23a4a | 2013-01-16 01:22:23 +0000 | [diff] [blame] | 1990 | |
Eric Christopher | 4d23a4a | 2013-01-16 01:22:23 +0000 | [diff] [blame] | 1991 | return StaticMemberDIE; |
| 1992 | } |
David Blaikie | 6b288cf | 2013-10-30 20:42:41 +0000 | [diff] [blame] | 1993 | |
Eric Christopher | a5a7942 | 2013-12-09 23:32:48 +0000 | [diff] [blame] | 1994 | void DwarfUnit::emitHeader(const MCSection *ASection, |
David Blaikie | 3332d4c | 2013-12-11 21:14:02 +0000 | [diff] [blame] | 1995 | const MCSymbol *ASectionSym) const { |
David Blaikie | 6b288cf | 2013-10-30 20:42:41 +0000 | [diff] [blame] | 1996 | Asm->OutStreamer.AddComment("DWARF version number"); |
| 1997 | Asm->EmitInt16(DD->getDwarfVersion()); |
| 1998 | Asm->OutStreamer.AddComment("Offset Into Abbrev. Section"); |
David Blaikie | 6896e19 | 2013-12-04 23:39:02 +0000 | [diff] [blame] | 1999 | // We share one abbreviations table across all units so it's always at the |
| 2000 | // start of the section. Use a relocatable offset where needed to ensure |
| 2001 | // linking doesn't invalidate that offset. |
David Blaikie | 91db9ab | 2013-12-04 18:12:28 +0000 | [diff] [blame] | 2002 | Asm->EmitSectionOffset(ASectionSym, ASectionSym); |
David Blaikie | 6b288cf | 2013-10-30 20:42:41 +0000 | [diff] [blame] | 2003 | Asm->OutStreamer.AddComment("Address Size (in bytes)"); |
| 2004 | Asm->EmitInt8(Asm->getDataLayout().getPointerSize()); |
| 2005 | } |
David Blaikie | bc56327 | 2013-12-13 21:33:40 +0000 | [diff] [blame] | 2006 | |
Juergen Ributzka | db9ee00 | 2013-12-14 12:23:14 +0000 | [diff] [blame] | 2007 | DwarfCompileUnit::~DwarfCompileUnit() {} |
| 2008 | DwarfTypeUnit::~DwarfTypeUnit() {} |
| 2009 | |
David Blaikie | bc56327 | 2013-12-13 21:33:40 +0000 | [diff] [blame] | 2010 | void DwarfTypeUnit::emitHeader(const MCSection *ASection, |
| 2011 | const MCSymbol *ASectionSym) const { |
| 2012 | DwarfUnit::emitHeader(ASection, ASectionSym); |
| 2013 | Asm->OutStreamer.AddComment("Type Signature"); |
| 2014 | Asm->OutStreamer.EmitIntValue(TypeSignature, sizeof(TypeSignature)); |
| 2015 | Asm->OutStreamer.AddComment("Type DIE Offset"); |
David Blaikie | 15ed5eb | 2014-01-10 01:38:41 +0000 | [diff] [blame] | 2016 | // In a skeleton type unit there is no type DIE so emit a zero offset. |
| 2017 | Asm->OutStreamer.EmitIntValue(Ty ? Ty->getOffset() : 0, |
| 2018 | sizeof(Ty->getOffset())); |
David Blaikie | bc56327 | 2013-12-13 21:33:40 +0000 | [diff] [blame] | 2019 | } |
| 2020 | |
| 2021 | void DwarfTypeUnit::initSection(const MCSection *Section) { |
| 2022 | assert(!this->Section); |
| 2023 | this->Section = Section; |
| 2024 | // Since each type unit is contained in its own COMDAT section, the begin |
| 2025 | // label and the section label are the same. Using the begin label emission in |
| 2026 | // DwarfDebug to emit the section label as well is slightly subtle/sneaky, but |
| 2027 | // the only other alternative of lazily constructing start-of-section labels |
| 2028 | // and storing a mapping in DwarfDebug (or AsmPrinter). |
| 2029 | this->SectionSym = this->LabelBegin = |
| 2030 | Asm->GetTempSymbol(Section->getLabelBeginName(), getUniqueID()); |
| 2031 | this->LabelEnd = |
| 2032 | Asm->GetTempSymbol(Section->getLabelEndName(), getUniqueID()); |
| 2033 | this->LabelRange = Asm->GetTempSymbol("gnu_ranges", getUniqueID()); |
| 2034 | } |