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