Devang Patel | 161b2f4 | 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 | 443c9ed | 2012-08-14 05:13:29 +0000 | [diff] [blame] | 10 | // This file contains support for constructing a dwarf compile unit. |
Devang Patel | 161b2f4 | 2011-04-12 23:21:44 +0000 | [diff] [blame] | 11 | // |
| 12 | //===----------------------------------------------------------------------===// |
| 13 | |
| 14 | #define DEBUG_TYPE "dwarfdebug" |
| 15 | |
| 16 | #include "DwarfCompileUnit.h" |
Chandler Carruth | d04a8d4 | 2012-12-03 16:50:05 +0000 | [diff] [blame] | 17 | #include "DwarfAccelTable.h" |
Devang Patel | 161b2f4 | 2011-04-12 23:21:44 +0000 | [diff] [blame] | 18 | #include "DwarfDebug.h" |
Chandler Carruth | d04a8d4 | 2012-12-03 16:50:05 +0000 | [diff] [blame] | 19 | #include "llvm/ADT/APFloat.h" |
Bill Wendling | 16eeb6f | 2012-06-29 08:32:07 +0000 | [diff] [blame] | 20 | #include "llvm/DIBuilder.h" |
Chandler Carruth | 0b8c9a8 | 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" |
Eric Christopher | d61c34b | 2011-11-11 03:16:32 +0000 | [diff] [blame] | 25 | #include "llvm/Support/Debug.h" |
Chandler Carruth | d04a8d4 | 2012-12-03 16:50:05 +0000 | [diff] [blame] | 26 | #include "llvm/Support/ErrorHandling.h" |
Devang Patel | 6f9d8ff | 2011-08-15 17:57:41 +0000 | [diff] [blame] | 27 | #include "llvm/Target/Mangler.h" |
Devang Patel | 161b2f4 | 2011-04-12 23:21:44 +0000 | [diff] [blame] | 28 | #include "llvm/Target/TargetFrameLowering.h" |
| 29 | #include "llvm/Target/TargetMachine.h" |
| 30 | #include "llvm/Target/TargetRegisterInfo.h" |
Devang Patel | 161b2f4 | 2011-04-12 23:21:44 +0000 | [diff] [blame] | 31 | |
| 32 | using namespace llvm; |
| 33 | |
| 34 | /// CompileUnit - Compile unit constructor. |
Eli Bendersky | d4a05e0 | 2012-12-03 18:45:45 +0000 | [diff] [blame] | 35 | CompileUnit::CompileUnit(unsigned UID, unsigned L, DIE *D, AsmPrinter *A, |
Eric Christopher | 2e5d870 | 2012-12-20 21:58:36 +0000 | [diff] [blame] | 36 | DwarfDebug *DW, DwarfUnits *DWU) |
| 37 | : UniqueID(UID), Language(L), CUDie(D), Asm(A), DD(DW), DU(DWU), |
| 38 | IndexTyDie(0) { |
Devang Patel | 161b2f4 | 2011-04-12 23:21:44 +0000 | [diff] [blame] | 39 | DIEIntegerOne = new (DIEValueAllocator) DIEInteger(1); |
| 40 | } |
| 41 | |
| 42 | /// ~CompileUnit - Destructor for compile unit. |
| 43 | CompileUnit::~CompileUnit() { |
| 44 | for (unsigned j = 0, M = DIEBlocks.size(); j < M; ++j) |
| 45 | DIEBlocks[j]->~DIEBlock(); |
| 46 | } |
| 47 | |
| 48 | /// createDIEEntry - Creates a new DIEEntry to be a proxy for a debug |
| 49 | /// information entry. |
| 50 | DIEEntry *CompileUnit::createDIEEntry(DIE *Entry) { |
| 51 | DIEEntry *Value = new (DIEValueAllocator) DIEEntry(Entry); |
| 52 | return Value; |
| 53 | } |
| 54 | |
Bill Wendling | 6afe478 | 2012-12-06 07:55:19 +0000 | [diff] [blame] | 55 | /// getDefaultLowerBound - Return the default lower bound for an array. If the |
Bill Wendling | 222c2fd | 2012-12-06 07:38:10 +0000 | [diff] [blame] | 56 | /// DWARF version doesn't handle the language, return -1. |
Bill Wendling | 6afe478 | 2012-12-06 07:55:19 +0000 | [diff] [blame] | 57 | int64_t CompileUnit::getDefaultLowerBound() const { |
Bill Wendling | 222c2fd | 2012-12-06 07:38:10 +0000 | [diff] [blame] | 58 | switch (Language) { |
| 59 | default: |
| 60 | break; |
| 61 | |
| 62 | case dwarf::DW_LANG_C89: |
| 63 | case dwarf::DW_LANG_C99: |
| 64 | case dwarf::DW_LANG_C: |
| 65 | case dwarf::DW_LANG_C_plus_plus: |
| 66 | case dwarf::DW_LANG_ObjC: |
| 67 | case dwarf::DW_LANG_ObjC_plus_plus: |
| 68 | return 0; |
| 69 | |
| 70 | case dwarf::DW_LANG_Fortran77: |
| 71 | case dwarf::DW_LANG_Fortran90: |
| 72 | case dwarf::DW_LANG_Fortran95: |
| 73 | return 1; |
| 74 | |
| 75 | // The languages below have valid values only if the DWARF version >= 4. |
| 76 | case dwarf::DW_LANG_Java: |
| 77 | case dwarf::DW_LANG_Python: |
| 78 | case dwarf::DW_LANG_UPC: |
| 79 | case dwarf::DW_LANG_D: |
| 80 | if (dwarf::DWARF_VERSION >= 4) |
| 81 | return 0; |
| 82 | break; |
| 83 | |
| 84 | case dwarf::DW_LANG_Ada83: |
| 85 | case dwarf::DW_LANG_Ada95: |
| 86 | case dwarf::DW_LANG_Cobol74: |
| 87 | case dwarf::DW_LANG_Cobol85: |
| 88 | case dwarf::DW_LANG_Modula2: |
| 89 | case dwarf::DW_LANG_Pascal83: |
| 90 | case dwarf::DW_LANG_PLI: |
| 91 | if (dwarf::DWARF_VERSION >= 4) |
| 92 | return 1; |
| 93 | break; |
| 94 | } |
| 95 | |
| 96 | return -1; |
| 97 | } |
| 98 | |
Eric Christopher | 873cf0a | 2012-08-24 01:14:27 +0000 | [diff] [blame] | 99 | /// addFlag - Add a flag that is true. |
| 100 | void CompileUnit::addFlag(DIE *Die, unsigned Attribute) { |
| 101 | if (!DD->useDarwinGDBCompat()) |
| 102 | Die->addValue(Attribute, dwarf::DW_FORM_flag_present, |
| 103 | DIEIntegerOne); |
| 104 | else |
| 105 | addUInt(Die, Attribute, dwarf::DW_FORM_flag, 1); |
| 106 | } |
| 107 | |
Devang Patel | 161b2f4 | 2011-04-12 23:21:44 +0000 | [diff] [blame] | 108 | /// addUInt - Add an unsigned integer attribute data and value. |
| 109 | /// |
| 110 | void CompileUnit::addUInt(DIE *Die, unsigned Attribute, |
| 111 | unsigned Form, uint64_t Integer) { |
| 112 | if (!Form) Form = DIEInteger::BestForm(false, Integer); |
| 113 | DIEValue *Value = Integer == 1 ? |
| 114 | DIEIntegerOne : new (DIEValueAllocator) DIEInteger(Integer); |
| 115 | Die->addValue(Attribute, Form, Value); |
| 116 | } |
| 117 | |
| 118 | /// addSInt - Add an signed integer attribute data and value. |
| 119 | /// |
| 120 | void CompileUnit::addSInt(DIE *Die, unsigned Attribute, |
| 121 | unsigned Form, int64_t Integer) { |
| 122 | if (!Form) Form = DIEInteger::BestForm(true, Integer); |
| 123 | DIEValue *Value = new (DIEValueAllocator) DIEInteger(Integer); |
| 124 | Die->addValue(Attribute, Form, Value); |
| 125 | } |
| 126 | |
Nick Lewycky | 6a7efcf | 2011-10-28 05:29:47 +0000 | [diff] [blame] | 127 | /// addString - Add a string attribute data and value. We always emit a |
| 128 | /// reference to the string pool instead of immediate strings so that DIEs have |
| 129 | /// more predictable sizes. |
Nick Lewycky | 390c40d | 2011-10-27 06:44:11 +0000 | [diff] [blame] | 130 | void CompileUnit::addString(DIE *Die, unsigned Attribute, StringRef String) { |
Eric Christopher | dd8e9f3 | 2013-01-07 19:32:41 +0000 | [diff] [blame^] | 131 | if (!DD->useSplitDwarf()) { |
| 132 | MCSymbol *Symb = DU->getStringPoolEntry(String); |
| 133 | DIEValue *Value; |
| 134 | if (Asm->needsRelocationsForDwarfStringPool()) |
| 135 | Value = new (DIEValueAllocator) DIELabel(Symb); |
| 136 | else { |
| 137 | MCSymbol *StringPool = DU->getStringPoolSym(); |
| 138 | Value = new (DIEValueAllocator) DIEDelta(Symb, StringPool); |
| 139 | } |
| 140 | Die->addValue(Attribute, dwarf::DW_FORM_strp, Value); |
| 141 | } else { |
| 142 | unsigned idx = DU->getStringPoolIndex(String); |
| 143 | DIEValue *Value = new (DIEValueAllocator) DIEInteger(idx); |
| 144 | Die->addValue(Attribute, dwarf::DW_FORM_GNU_str_index, Value); |
| 145 | } |
| 146 | } |
| 147 | |
| 148 | /// addLocalString - Add a string attribute data and value. This is guaranteed |
| 149 | /// to be in the local string pool instead of indirected. |
| 150 | void CompileUnit::addLocalString(DIE *Die, unsigned Attribute, |
| 151 | StringRef String) { |
Eric Christopher | 2e5d870 | 2012-12-20 21:58:36 +0000 | [diff] [blame] | 152 | MCSymbol *Symb = DU->getStringPoolEntry(String); |
Nick Lewycky | 6a7efcf | 2011-10-28 05:29:47 +0000 | [diff] [blame] | 153 | DIEValue *Value; |
| 154 | if (Asm->needsRelocationsForDwarfStringPool()) |
| 155 | Value = new (DIEValueAllocator) DIELabel(Symb); |
| 156 | else { |
Eric Christopher | 2e5d870 | 2012-12-20 21:58:36 +0000 | [diff] [blame] | 157 | MCSymbol *StringPool = DU->getStringPoolSym(); |
Nick Lewycky | 6a7efcf | 2011-10-28 05:29:47 +0000 | [diff] [blame] | 158 | Value = new (DIEValueAllocator) DIEDelta(Symb, StringPool); |
Nick Lewycky | 390c40d | 2011-10-27 06:44:11 +0000 | [diff] [blame] | 159 | } |
Nick Lewycky | 6a7efcf | 2011-10-28 05:29:47 +0000 | [diff] [blame] | 160 | Die->addValue(Attribute, dwarf::DW_FORM_strp, Value); |
Devang Patel | 161b2f4 | 2011-04-12 23:21:44 +0000 | [diff] [blame] | 161 | } |
| 162 | |
| 163 | /// addLabel - Add a Dwarf label attribute data and value. |
| 164 | /// |
| 165 | void CompileUnit::addLabel(DIE *Die, unsigned Attribute, unsigned Form, |
| 166 | const MCSymbol *Label) { |
| 167 | DIEValue *Value = new (DIEValueAllocator) DIELabel(Label); |
| 168 | Die->addValue(Attribute, Form, Value); |
| 169 | } |
| 170 | |
| 171 | /// addDelta - Add a label delta attribute data and value. |
| 172 | /// |
| 173 | void CompileUnit::addDelta(DIE *Die, unsigned Attribute, unsigned Form, |
| 174 | const MCSymbol *Hi, const MCSymbol *Lo) { |
| 175 | DIEValue *Value = new (DIEValueAllocator) DIEDelta(Hi, Lo); |
| 176 | Die->addValue(Attribute, Form, Value); |
| 177 | } |
| 178 | |
| 179 | /// addDIEEntry - Add a DIE attribute data and value. |
| 180 | /// |
| 181 | void CompileUnit::addDIEEntry(DIE *Die, unsigned Attribute, unsigned Form, |
| 182 | DIE *Entry) { |
| 183 | Die->addValue(Attribute, Form, createDIEEntry(Entry)); |
| 184 | } |
| 185 | |
Devang Patel | 161b2f4 | 2011-04-12 23:21:44 +0000 | [diff] [blame] | 186 | /// addBlock - Add block data. |
| 187 | /// |
| 188 | void CompileUnit::addBlock(DIE *Die, unsigned Attribute, unsigned Form, |
| 189 | DIEBlock *Block) { |
| 190 | Block->ComputeSize(Asm); |
| 191 | DIEBlocks.push_back(Block); // Memoize so we can call the destructor later on. |
| 192 | Die->addValue(Attribute, Block->BestForm(), Block); |
| 193 | } |
| 194 | |
| 195 | /// addSourceLine - Add location information to specified debug information |
| 196 | /// entry. |
| 197 | void CompileUnit::addSourceLine(DIE *Die, DIVariable V) { |
| 198 | // Verify variable. |
| 199 | if (!V.Verify()) |
| 200 | return; |
Eric Christopher | 8b4310b | 2012-11-21 00:34:38 +0000 | [diff] [blame] | 201 | |
Devang Patel | 161b2f4 | 2011-04-12 23:21:44 +0000 | [diff] [blame] | 202 | unsigned Line = V.getLineNumber(); |
| 203 | if (Line == 0) |
| 204 | return; |
Eric Christopher | 7ee5f5d | 2012-11-21 00:34:35 +0000 | [diff] [blame] | 205 | unsigned FileID = DD->getOrCreateSourceID(V.getContext().getFilename(), |
Devang Patel | 161b2f4 | 2011-04-12 23:21:44 +0000 | [diff] [blame] | 206 | V.getContext().getDirectory()); |
| 207 | assert(FileID && "Invalid file id"); |
| 208 | addUInt(Die, dwarf::DW_AT_decl_file, 0, FileID); |
| 209 | addUInt(Die, dwarf::DW_AT_decl_line, 0, Line); |
| 210 | } |
| 211 | |
| 212 | /// addSourceLine - Add location information to specified debug information |
| 213 | /// entry. |
| 214 | void CompileUnit::addSourceLine(DIE *Die, DIGlobalVariable G) { |
| 215 | // Verify global variable. |
| 216 | if (!G.Verify()) |
| 217 | return; |
| 218 | |
| 219 | unsigned Line = G.getLineNumber(); |
| 220 | if (Line == 0) |
| 221 | return; |
Eric Christopher | 7ee5f5d | 2012-11-21 00:34:35 +0000 | [diff] [blame] | 222 | unsigned FileID = DD->getOrCreateSourceID(G.getFilename(), G.getDirectory()); |
Devang Patel | 161b2f4 | 2011-04-12 23:21:44 +0000 | [diff] [blame] | 223 | assert(FileID && "Invalid file id"); |
| 224 | addUInt(Die, dwarf::DW_AT_decl_file, 0, FileID); |
| 225 | addUInt(Die, dwarf::DW_AT_decl_line, 0, Line); |
| 226 | } |
| 227 | |
| 228 | /// addSourceLine - Add location information to specified debug information |
| 229 | /// entry. |
| 230 | void CompileUnit::addSourceLine(DIE *Die, DISubprogram SP) { |
| 231 | // Verify subprogram. |
| 232 | if (!SP.Verify()) |
| 233 | return; |
Eric Christopher | 2125d5a | 2012-03-15 23:55:40 +0000 | [diff] [blame] | 234 | |
Devang Patel | 161b2f4 | 2011-04-12 23:21:44 +0000 | [diff] [blame] | 235 | // If the line number is 0, don't add it. |
Eric Christopher | 2125d5a | 2012-03-15 23:55:40 +0000 | [diff] [blame] | 236 | unsigned Line = SP.getLineNumber(); |
| 237 | if (Line == 0) |
Devang Patel | 161b2f4 | 2011-04-12 23:21:44 +0000 | [diff] [blame] | 238 | return; |
| 239 | |
Eric Christopher | 7ee5f5d | 2012-11-21 00:34:35 +0000 | [diff] [blame] | 240 | unsigned FileID = DD->getOrCreateSourceID(SP.getFilename(), |
Nick Lewycky | 746cb67 | 2011-10-26 22:55:33 +0000 | [diff] [blame] | 241 | SP.getDirectory()); |
Devang Patel | 161b2f4 | 2011-04-12 23:21:44 +0000 | [diff] [blame] | 242 | assert(FileID && "Invalid file id"); |
| 243 | addUInt(Die, dwarf::DW_AT_decl_file, 0, FileID); |
| 244 | addUInt(Die, dwarf::DW_AT_decl_line, 0, Line); |
| 245 | } |
| 246 | |
| 247 | /// addSourceLine - Add location information to specified debug information |
| 248 | /// entry. |
| 249 | void CompileUnit::addSourceLine(DIE *Die, DIType Ty) { |
| 250 | // Verify type. |
| 251 | if (!Ty.Verify()) |
| 252 | return; |
| 253 | |
| 254 | unsigned Line = Ty.getLineNumber(); |
Eric Christopher | 2125d5a | 2012-03-15 23:55:40 +0000 | [diff] [blame] | 255 | if (Line == 0) |
Devang Patel | 161b2f4 | 2011-04-12 23:21:44 +0000 | [diff] [blame] | 256 | return; |
Eric Christopher | 7ee5f5d | 2012-11-21 00:34:35 +0000 | [diff] [blame] | 257 | unsigned FileID = DD->getOrCreateSourceID(Ty.getFilename(), |
Nick Lewycky | 746cb67 | 2011-10-26 22:55:33 +0000 | [diff] [blame] | 258 | Ty.getDirectory()); |
Devang Patel | 161b2f4 | 2011-04-12 23:21:44 +0000 | [diff] [blame] | 259 | assert(FileID && "Invalid file id"); |
| 260 | addUInt(Die, dwarf::DW_AT_decl_file, 0, FileID); |
| 261 | addUInt(Die, dwarf::DW_AT_decl_line, 0, Line); |
| 262 | } |
| 263 | |
| 264 | /// addSourceLine - Add location information to specified debug information |
| 265 | /// entry. |
Eric Christopher | b8ca988 | 2012-03-29 08:42:56 +0000 | [diff] [blame] | 266 | void CompileUnit::addSourceLine(DIE *Die, DIObjCProperty Ty) { |
| 267 | // Verify type. |
| 268 | if (!Ty.Verify()) |
| 269 | return; |
| 270 | |
| 271 | unsigned Line = Ty.getLineNumber(); |
| 272 | if (Line == 0) |
| 273 | return; |
| 274 | DIFile File = Ty.getFile(); |
Eric Christopher | 7ee5f5d | 2012-11-21 00:34:35 +0000 | [diff] [blame] | 275 | unsigned FileID = DD->getOrCreateSourceID(File.getFilename(), |
Eric Christopher | 4d069bf | 2012-05-22 18:45:24 +0000 | [diff] [blame] | 276 | File.getDirectory()); |
Eric Christopher | b8ca988 | 2012-03-29 08:42:56 +0000 | [diff] [blame] | 277 | assert(FileID && "Invalid file id"); |
| 278 | addUInt(Die, dwarf::DW_AT_decl_file, 0, FileID); |
| 279 | addUInt(Die, dwarf::DW_AT_decl_line, 0, Line); |
| 280 | } |
| 281 | |
| 282 | /// addSourceLine - Add location information to specified debug information |
| 283 | /// entry. |
Devang Patel | 161b2f4 | 2011-04-12 23:21:44 +0000 | [diff] [blame] | 284 | void CompileUnit::addSourceLine(DIE *Die, DINameSpace NS) { |
| 285 | // Verify namespace. |
| 286 | if (!NS.Verify()) |
| 287 | return; |
| 288 | |
| 289 | unsigned Line = NS.getLineNumber(); |
| 290 | if (Line == 0) |
| 291 | return; |
| 292 | StringRef FN = NS.getFilename(); |
| 293 | |
Eric Christopher | 7ee5f5d | 2012-11-21 00:34:35 +0000 | [diff] [blame] | 294 | unsigned FileID = DD->getOrCreateSourceID(FN, NS.getDirectory()); |
Devang Patel | 161b2f4 | 2011-04-12 23:21:44 +0000 | [diff] [blame] | 295 | assert(FileID && "Invalid file id"); |
| 296 | addUInt(Die, dwarf::DW_AT_decl_file, 0, FileID); |
| 297 | addUInt(Die, dwarf::DW_AT_decl_line, 0, Line); |
| 298 | } |
| 299 | |
Eric Christopher | 8b4310b | 2012-11-21 00:34:38 +0000 | [diff] [blame] | 300 | /// addVariableAddress - Add DW_AT_location attribute for a |
Devang Patel | e1cdf84 | 2011-04-27 22:45:24 +0000 | [diff] [blame] | 301 | /// DbgVariable based on provided MachineLocation. |
Eric Christopher | 8b4310b | 2012-11-21 00:34:38 +0000 | [diff] [blame] | 302 | void CompileUnit::addVariableAddress(DbgVariable *&DV, DIE *Die, |
Devang Patel | e1cdf84 | 2011-04-27 22:45:24 +0000 | [diff] [blame] | 303 | MachineLocation Location) { |
Devang Patel | 161b2f4 | 2011-04-12 23:21:44 +0000 | [diff] [blame] | 304 | if (DV->variableHasComplexAddress()) |
| 305 | addComplexAddress(DV, Die, dwarf::DW_AT_location, Location); |
| 306 | else if (DV->isBlockByrefVariable()) |
| 307 | addBlockByrefAddress(DV, Die, dwarf::DW_AT_location, Location); |
| 308 | else |
| 309 | addAddress(Die, dwarf::DW_AT_location, Location); |
| 310 | } |
| 311 | |
Devang Patel | 116da2f | 2011-04-26 19:06:18 +0000 | [diff] [blame] | 312 | /// addRegisterOp - Add register operand. |
| 313 | void CompileUnit::addRegisterOp(DIE *TheDie, unsigned Reg) { |
| 314 | const TargetRegisterInfo *RI = Asm->TM.getRegisterInfo(); |
| 315 | unsigned DWReg = RI->getDwarfRegNum(Reg, false); |
| 316 | if (DWReg < 32) |
| 317 | addUInt(TheDie, 0, dwarf::DW_FORM_data1, dwarf::DW_OP_reg0 + DWReg); |
| 318 | else { |
| 319 | addUInt(TheDie, 0, dwarf::DW_FORM_data1, dwarf::DW_OP_regx); |
| 320 | addUInt(TheDie, 0, dwarf::DW_FORM_udata, DWReg); |
| 321 | } |
| 322 | } |
| 323 | |
| 324 | /// addRegisterOffset - Add register offset. |
| 325 | void CompileUnit::addRegisterOffset(DIE *TheDie, unsigned Reg, |
| 326 | int64_t Offset) { |
| 327 | const TargetRegisterInfo *RI = Asm->TM.getRegisterInfo(); |
| 328 | unsigned DWReg = RI->getDwarfRegNum(Reg, false); |
| 329 | const TargetRegisterInfo *TRI = Asm->TM.getRegisterInfo(); |
| 330 | if (Reg == TRI->getFrameRegister(*Asm->MF)) |
| 331 | // If variable offset is based in frame register then use fbreg. |
| 332 | addUInt(TheDie, 0, dwarf::DW_FORM_data1, dwarf::DW_OP_fbreg); |
| 333 | else if (DWReg < 32) |
| 334 | addUInt(TheDie, 0, dwarf::DW_FORM_data1, dwarf::DW_OP_breg0 + DWReg); |
| 335 | else { |
| 336 | addUInt(TheDie, 0, dwarf::DW_FORM_data1, dwarf::DW_OP_bregx); |
| 337 | addUInt(TheDie, 0, dwarf::DW_FORM_udata, DWReg); |
| 338 | } |
| 339 | addSInt(TheDie, 0, dwarf::DW_FORM_sdata, Offset); |
| 340 | } |
| 341 | |
| 342 | /// addAddress - Add an address attribute to a die based on the location |
| 343 | /// provided. |
| 344 | void CompileUnit::addAddress(DIE *Die, unsigned Attribute, |
| 345 | const MachineLocation &Location) { |
| 346 | DIEBlock *Block = new (DIEValueAllocator) DIEBlock(); |
| 347 | |
| 348 | if (Location.isReg()) |
| 349 | addRegisterOp(Block, Location.getReg()); |
| 350 | else |
| 351 | addRegisterOffset(Block, Location.getReg(), Location.getOffset()); |
| 352 | |
| 353 | // Now attach the location information to the DIE. |
| 354 | addBlock(Die, Attribute, 0, Block); |
| 355 | } |
| 356 | |
Devang Patel | 161b2f4 | 2011-04-12 23:21:44 +0000 | [diff] [blame] | 357 | /// addComplexAddress - Start with the address based on the location provided, |
| 358 | /// and generate the DWARF information necessary to find the actual variable |
| 359 | /// given the extra address information encoded in the DIVariable, starting from |
| 360 | /// the starting location. Add the DWARF information to the die. |
| 361 | /// |
| 362 | void CompileUnit::addComplexAddress(DbgVariable *&DV, DIE *Die, |
| 363 | unsigned Attribute, |
| 364 | const MachineLocation &Location) { |
Devang Patel | 161b2f4 | 2011-04-12 23:21:44 +0000 | [diff] [blame] | 365 | DIEBlock *Block = new (DIEValueAllocator) DIEBlock(); |
Devang Patel | c26f544 | 2011-04-28 02:22:40 +0000 | [diff] [blame] | 366 | unsigned N = DV->getNumAddrElements(); |
| 367 | unsigned i = 0; |
| 368 | if (Location.isReg()) { |
| 369 | if (N >= 2 && DV->getAddrElement(0) == DIBuilder::OpPlus) { |
| 370 | // If first address element is OpPlus then emit |
| 371 | // DW_OP_breg + Offset instead of DW_OP_reg + Offset. |
| 372 | addRegisterOffset(Block, Location.getReg(), DV->getAddrElement(1)); |
| 373 | i = 2; |
| 374 | } else |
| 375 | addRegisterOp(Block, Location.getReg()); |
| 376 | } |
Devang Patel | 116da2f | 2011-04-26 19:06:18 +0000 | [diff] [blame] | 377 | else |
| 378 | addRegisterOffset(Block, Location.getReg(), Location.getOffset()); |
Devang Patel | 161b2f4 | 2011-04-12 23:21:44 +0000 | [diff] [blame] | 379 | |
Devang Patel | c26f544 | 2011-04-28 02:22:40 +0000 | [diff] [blame] | 380 | for (;i < N; ++i) { |
Devang Patel | 161b2f4 | 2011-04-12 23:21:44 +0000 | [diff] [blame] | 381 | uint64_t Element = DV->getAddrElement(i); |
Devang Patel | 161b2f4 | 2011-04-12 23:21:44 +0000 | [diff] [blame] | 382 | if (Element == DIBuilder::OpPlus) { |
| 383 | addUInt(Block, 0, dwarf::DW_FORM_data1, dwarf::DW_OP_plus_uconst); |
| 384 | addUInt(Block, 0, dwarf::DW_FORM_udata, DV->getAddrElement(++i)); |
| 385 | } else if (Element == DIBuilder::OpDeref) { |
Eric Christopher | 5012076 | 2012-05-08 18:56:00 +0000 | [diff] [blame] | 386 | if (!Location.isReg()) |
| 387 | addUInt(Block, 0, dwarf::DW_FORM_data1, dwarf::DW_OP_deref); |
Devang Patel | 161b2f4 | 2011-04-12 23:21:44 +0000 | [diff] [blame] | 388 | } else llvm_unreachable("unknown DIBuilder Opcode"); |
| 389 | } |
| 390 | |
| 391 | // Now attach the location information to the DIE. |
| 392 | addBlock(Die, Attribute, 0, Block); |
| 393 | } |
| 394 | |
| 395 | /* Byref variables, in Blocks, are declared by the programmer as "SomeType |
| 396 | VarName;", but the compiler creates a __Block_byref_x_VarName struct, and |
| 397 | gives the variable VarName either the struct, or a pointer to the struct, as |
| 398 | its type. This is necessary for various behind-the-scenes things the |
| 399 | compiler needs to do with by-reference variables in Blocks. |
| 400 | |
| 401 | However, as far as the original *programmer* is concerned, the variable |
| 402 | should still have type 'SomeType', as originally declared. |
| 403 | |
| 404 | The function getBlockByrefType dives into the __Block_byref_x_VarName |
| 405 | struct to find the original type of the variable, which is then assigned to |
| 406 | the variable's Debug Information Entry as its real type. So far, so good. |
| 407 | However now the debugger will expect the variable VarName to have the type |
| 408 | SomeType. So we need the location attribute for the variable to be an |
| 409 | expression that explains to the debugger how to navigate through the |
| 410 | pointers and struct to find the actual variable of type SomeType. |
| 411 | |
| 412 | The following function does just that. We start by getting |
| 413 | the "normal" location for the variable. This will be the location |
| 414 | of either the struct __Block_byref_x_VarName or the pointer to the |
| 415 | struct __Block_byref_x_VarName. |
| 416 | |
| 417 | The struct will look something like: |
| 418 | |
| 419 | struct __Block_byref_x_VarName { |
| 420 | ... <various fields> |
| 421 | struct __Block_byref_x_VarName *forwarding; |
| 422 | ... <various other fields> |
| 423 | SomeType VarName; |
| 424 | ... <maybe more fields> |
| 425 | }; |
| 426 | |
| 427 | If we are given the struct directly (as our starting point) we |
| 428 | need to tell the debugger to: |
| 429 | |
| 430 | 1). Add the offset of the forwarding field. |
| 431 | |
| 432 | 2). Follow that pointer to get the real __Block_byref_x_VarName |
| 433 | struct to use (the real one may have been copied onto the heap). |
| 434 | |
| 435 | 3). Add the offset for the field VarName, to find the actual variable. |
| 436 | |
| 437 | If we started with a pointer to the struct, then we need to |
| 438 | dereference that pointer first, before the other steps. |
| 439 | Translating this into DWARF ops, we will need to append the following |
| 440 | to the current location description for the variable: |
| 441 | |
| 442 | DW_OP_deref -- optional, if we start with a pointer |
| 443 | DW_OP_plus_uconst <forward_fld_offset> |
| 444 | DW_OP_deref |
| 445 | DW_OP_plus_uconst <varName_fld_offset> |
| 446 | |
| 447 | That is what this function does. */ |
| 448 | |
| 449 | /// addBlockByrefAddress - Start with the address based on the location |
| 450 | /// provided, and generate the DWARF information necessary to find the |
| 451 | /// actual Block variable (navigating the Block struct) based on the |
| 452 | /// starting location. Add the DWARF information to the die. For |
| 453 | /// more information, read large comment just above here. |
| 454 | /// |
| 455 | void CompileUnit::addBlockByrefAddress(DbgVariable *&DV, DIE *Die, |
| 456 | unsigned Attribute, |
| 457 | const MachineLocation &Location) { |
| 458 | DIType Ty = DV->getType(); |
| 459 | DIType TmpTy = Ty; |
| 460 | unsigned Tag = Ty.getTag(); |
| 461 | bool isPointer = false; |
| 462 | |
| 463 | StringRef varName = DV->getName(); |
| 464 | |
| 465 | if (Tag == dwarf::DW_TAG_pointer_type) { |
| 466 | DIDerivedType DTy = DIDerivedType(Ty); |
| 467 | TmpTy = DTy.getTypeDerivedFrom(); |
| 468 | isPointer = true; |
| 469 | } |
| 470 | |
| 471 | DICompositeType blockStruct = DICompositeType(TmpTy); |
| 472 | |
| 473 | // Find the __forwarding field and the variable field in the __Block_byref |
| 474 | // struct. |
| 475 | DIArray Fields = blockStruct.getTypeArray(); |
| 476 | DIDescriptor varField = DIDescriptor(); |
| 477 | DIDescriptor forwardingField = DIDescriptor(); |
| 478 | |
| 479 | for (unsigned i = 0, N = Fields.getNumElements(); i < N; ++i) { |
| 480 | DIDescriptor Element = Fields.getElement(i); |
| 481 | DIDerivedType DT = DIDerivedType(Element); |
| 482 | StringRef fieldName = DT.getName(); |
| 483 | if (fieldName == "__forwarding") |
| 484 | forwardingField = Element; |
| 485 | else if (fieldName == varName) |
| 486 | varField = Element; |
| 487 | } |
| 488 | |
| 489 | // Get the offsets for the forwarding field and the variable field. |
| 490 | unsigned forwardingFieldOffset = |
| 491 | DIDerivedType(forwardingField).getOffsetInBits() >> 3; |
| 492 | unsigned varFieldOffset = |
| 493 | DIDerivedType(varField).getOffsetInBits() >> 3; |
| 494 | |
| 495 | // Decode the original location, and use that as the start of the byref |
| 496 | // variable's location. |
Devang Patel | 161b2f4 | 2011-04-12 23:21:44 +0000 | [diff] [blame] | 497 | DIEBlock *Block = new (DIEValueAllocator) DIEBlock(); |
| 498 | |
Eric Christopher | caba263 | 2012-07-04 02:02:18 +0000 | [diff] [blame] | 499 | if (Location.isReg()) |
| 500 | addRegisterOp(Block, Location.getReg()); |
| 501 | else |
| 502 | addRegisterOffset(Block, Location.getReg(), Location.getOffset()); |
Devang Patel | 161b2f4 | 2011-04-12 23:21:44 +0000 | [diff] [blame] | 503 | |
| 504 | // If we started with a pointer to the __Block_byref... struct, then |
| 505 | // the first thing we need to do is dereference the pointer (DW_OP_deref). |
| 506 | if (isPointer) |
| 507 | addUInt(Block, 0, dwarf::DW_FORM_data1, dwarf::DW_OP_deref); |
| 508 | |
| 509 | // Next add the offset for the '__forwarding' field: |
| 510 | // DW_OP_plus_uconst ForwardingFieldOffset. Note there's no point in |
| 511 | // adding the offset if it's 0. |
| 512 | if (forwardingFieldOffset > 0) { |
| 513 | addUInt(Block, 0, dwarf::DW_FORM_data1, dwarf::DW_OP_plus_uconst); |
| 514 | addUInt(Block, 0, dwarf::DW_FORM_udata, forwardingFieldOffset); |
| 515 | } |
| 516 | |
| 517 | // Now dereference the __forwarding field to get to the real __Block_byref |
| 518 | // struct: DW_OP_deref. |
| 519 | addUInt(Block, 0, dwarf::DW_FORM_data1, dwarf::DW_OP_deref); |
| 520 | |
| 521 | // Now that we've got the real __Block_byref... struct, add the offset |
| 522 | // for the variable's field to get to the location of the actual variable: |
| 523 | // DW_OP_plus_uconst varFieldOffset. Again, don't add if it's 0. |
| 524 | if (varFieldOffset > 0) { |
| 525 | addUInt(Block, 0, dwarf::DW_FORM_data1, dwarf::DW_OP_plus_uconst); |
| 526 | addUInt(Block, 0, dwarf::DW_FORM_udata, varFieldOffset); |
| 527 | } |
| 528 | |
| 529 | // Now attach the location information to the DIE. |
| 530 | addBlock(Die, Attribute, 0, Block); |
| 531 | } |
| 532 | |
Devang Patel | 4ec14b0 | 2011-07-20 21:57:04 +0000 | [diff] [blame] | 533 | /// isTypeSigned - Return true if the type is signed. |
| 534 | static bool isTypeSigned(DIType Ty, int *SizeInBits) { |
| 535 | if (Ty.isDerivedType()) |
| 536 | return isTypeSigned(DIDerivedType(Ty).getTypeDerivedFrom(), SizeInBits); |
| 537 | if (Ty.isBasicType()) |
| 538 | if (DIBasicType(Ty).getEncoding() == dwarf::DW_ATE_signed |
| 539 | || DIBasicType(Ty).getEncoding() == dwarf::DW_ATE_signed_char) { |
| 540 | *SizeInBits = Ty.getSizeInBits(); |
| 541 | return true; |
| 542 | } |
| 543 | return false; |
| 544 | } |
| 545 | |
Devang Patel | 161b2f4 | 2011-04-12 23:21:44 +0000 | [diff] [blame] | 546 | /// addConstantValue - Add constant value entry in variable DIE. |
Devang Patel | b58128e | 2011-05-27 16:45:18 +0000 | [diff] [blame] | 547 | bool CompileUnit::addConstantValue(DIE *Die, const MachineOperand &MO, |
| 548 | DIType Ty) { |
Nick Lewycky | 746cb67 | 2011-10-26 22:55:33 +0000 | [diff] [blame] | 549 | assert(MO.isImm() && "Invalid machine operand!"); |
Devang Patel | 161b2f4 | 2011-04-12 23:21:44 +0000 | [diff] [blame] | 550 | DIEBlock *Block = new (DIEValueAllocator) DIEBlock(); |
Devang Patel | 4ec14b0 | 2011-07-20 21:57:04 +0000 | [diff] [blame] | 551 | int SizeInBits = -1; |
| 552 | bool SignedConstant = isTypeSigned(Ty, &SizeInBits); |
| 553 | unsigned Form = SignedConstant ? dwarf::DW_FORM_sdata : dwarf::DW_FORM_udata; |
| 554 | switch (SizeInBits) { |
| 555 | case 8: Form = dwarf::DW_FORM_data1; break; |
| 556 | case 16: Form = dwarf::DW_FORM_data2; break; |
| 557 | case 32: Form = dwarf::DW_FORM_data4; break; |
| 558 | case 64: Form = dwarf::DW_FORM_data8; break; |
Devang Patel | 045c1d4 | 2011-05-27 19:13:26 +0000 | [diff] [blame] | 559 | default: break; |
| 560 | } |
Eric Christopher | 8b4310b | 2012-11-21 00:34:38 +0000 | [diff] [blame] | 561 | SignedConstant ? addSInt(Block, 0, Form, MO.getImm()) |
Devang Patel | 4ec14b0 | 2011-07-20 21:57:04 +0000 | [diff] [blame] | 562 | : addUInt(Block, 0, Form, MO.getImm()); |
Devang Patel | 72f0d9c | 2011-05-27 18:15:52 +0000 | [diff] [blame] | 563 | |
Devang Patel | 161b2f4 | 2011-04-12 23:21:44 +0000 | [diff] [blame] | 564 | addBlock(Die, dwarf::DW_AT_const_value, 0, Block); |
| 565 | return true; |
| 566 | } |
| 567 | |
| 568 | /// addConstantFPValue - Add constant value entry in variable DIE. |
| 569 | bool CompileUnit::addConstantFPValue(DIE *Die, const MachineOperand &MO) { |
Nick Lewycky | 390c40d | 2011-10-27 06:44:11 +0000 | [diff] [blame] | 570 | assert (MO.isFPImm() && "Invalid machine operand!"); |
Devang Patel | 161b2f4 | 2011-04-12 23:21:44 +0000 | [diff] [blame] | 571 | DIEBlock *Block = new (DIEValueAllocator) DIEBlock(); |
| 572 | APFloat FPImm = MO.getFPImm()->getValueAPF(); |
| 573 | |
| 574 | // Get the raw data form of the floating point. |
| 575 | const APInt FltVal = FPImm.bitcastToAPInt(); |
| 576 | const char *FltPtr = (const char*)FltVal.getRawData(); |
| 577 | |
| 578 | int NumBytes = FltVal.getBitWidth() / 8; // 8 bits per byte. |
Micah Villmow | 3574eca | 2012-10-08 16:38:25 +0000 | [diff] [blame] | 579 | bool LittleEndian = Asm->getDataLayout().isLittleEndian(); |
Devang Patel | 161b2f4 | 2011-04-12 23:21:44 +0000 | [diff] [blame] | 580 | int Incr = (LittleEndian ? 1 : -1); |
| 581 | int Start = (LittleEndian ? 0 : NumBytes - 1); |
| 582 | int Stop = (LittleEndian ? NumBytes : -1); |
| 583 | |
| 584 | // Output the constant to DWARF one byte at a time. |
| 585 | for (; Start != Stop; Start += Incr) |
| 586 | addUInt(Block, 0, dwarf::DW_FORM_data1, |
| 587 | (unsigned char)0xFF & FltPtr[Start]); |
| 588 | |
| 589 | addBlock(Die, dwarf::DW_AT_const_value, 0, Block); |
| 590 | return true; |
| 591 | } |
| 592 | |
| 593 | /// addConstantValue - Add constant value entry in variable DIE. |
Devang Patel | 8594d42 | 2011-06-24 20:46:11 +0000 | [diff] [blame] | 594 | bool CompileUnit::addConstantValue(DIE *Die, const ConstantInt *CI, |
Devang Patel | 161b2f4 | 2011-04-12 23:21:44 +0000 | [diff] [blame] | 595 | bool Unsigned) { |
Devang Patel | d6a8136 | 2011-05-28 00:39:18 +0000 | [diff] [blame] | 596 | unsigned CIBitWidth = CI->getBitWidth(); |
| 597 | if (CIBitWidth <= 64) { |
| 598 | unsigned form = 0; |
| 599 | switch (CIBitWidth) { |
| 600 | case 8: form = dwarf::DW_FORM_data1; break; |
| 601 | case 16: form = dwarf::DW_FORM_data2; break; |
| 602 | case 32: form = dwarf::DW_FORM_data4; break; |
| 603 | case 64: form = dwarf::DW_FORM_data8; break; |
Eric Christopher | 8b4310b | 2012-11-21 00:34:38 +0000 | [diff] [blame] | 604 | default: |
Devang Patel | d6a8136 | 2011-05-28 00:39:18 +0000 | [diff] [blame] | 605 | form = Unsigned ? dwarf::DW_FORM_udata : dwarf::DW_FORM_sdata; |
| 606 | } |
Devang Patel | 161b2f4 | 2011-04-12 23:21:44 +0000 | [diff] [blame] | 607 | if (Unsigned) |
Devang Patel | d6a8136 | 2011-05-28 00:39:18 +0000 | [diff] [blame] | 608 | addUInt(Die, dwarf::DW_AT_const_value, form, CI->getZExtValue()); |
Devang Patel | 161b2f4 | 2011-04-12 23:21:44 +0000 | [diff] [blame] | 609 | else |
Devang Patel | d6a8136 | 2011-05-28 00:39:18 +0000 | [diff] [blame] | 610 | addSInt(Die, dwarf::DW_AT_const_value, form, CI->getSExtValue()); |
Devang Patel | 161b2f4 | 2011-04-12 23:21:44 +0000 | [diff] [blame] | 611 | return true; |
| 612 | } |
| 613 | |
| 614 | DIEBlock *Block = new (DIEValueAllocator) DIEBlock(); |
| 615 | |
| 616 | // Get the raw data form of the large APInt. |
| 617 | const APInt Val = CI->getValue(); |
NAKAMURA Takumi | c3e48c3 | 2011-10-28 14:12:22 +0000 | [diff] [blame] | 618 | const uint64_t *Ptr64 = Val.getRawData(); |
Devang Patel | 161b2f4 | 2011-04-12 23:21:44 +0000 | [diff] [blame] | 619 | |
| 620 | int NumBytes = Val.getBitWidth() / 8; // 8 bits per byte. |
Micah Villmow | 3574eca | 2012-10-08 16:38:25 +0000 | [diff] [blame] | 621 | bool LittleEndian = Asm->getDataLayout().isLittleEndian(); |
Devang Patel | 161b2f4 | 2011-04-12 23:21:44 +0000 | [diff] [blame] | 622 | |
| 623 | // Output the constant to DWARF one byte at a time. |
NAKAMURA Takumi | c3e48c3 | 2011-10-28 14:12:22 +0000 | [diff] [blame] | 624 | for (int i = 0; i < NumBytes; i++) { |
| 625 | uint8_t c; |
| 626 | if (LittleEndian) |
| 627 | c = Ptr64[i / 8] >> (8 * (i & 7)); |
| 628 | else |
| 629 | c = Ptr64[(NumBytes - 1 - i) / 8] >> (8 * ((NumBytes - 1 - i) & 7)); |
| 630 | addUInt(Block, 0, dwarf::DW_FORM_data1, c); |
| 631 | } |
Devang Patel | 161b2f4 | 2011-04-12 23:21:44 +0000 | [diff] [blame] | 632 | |
| 633 | addBlock(Die, dwarf::DW_AT_const_value, 0, Block); |
| 634 | return true; |
| 635 | } |
| 636 | |
| 637 | /// addTemplateParams - Add template parameters in buffer. |
| 638 | void CompileUnit::addTemplateParams(DIE &Buffer, DIArray TParams) { |
| 639 | // Add template parameters. |
| 640 | for (unsigned i = 0, e = TParams.getNumElements(); i != e; ++i) { |
| 641 | DIDescriptor Element = TParams.getElement(i); |
| 642 | if (Element.isTemplateTypeParameter()) |
| 643 | Buffer.addChild(getOrCreateTemplateTypeParameterDIE( |
| 644 | DITemplateTypeParameter(Element))); |
| 645 | else if (Element.isTemplateValueParameter()) |
| 646 | Buffer.addChild(getOrCreateTemplateValueParameterDIE( |
| 647 | DITemplateValueParameter(Element))); |
| 648 | } |
Devang Patel | 161b2f4 | 2011-04-12 23:21:44 +0000 | [diff] [blame] | 649 | } |
Nick Lewycky | 746cb67 | 2011-10-26 22:55:33 +0000 | [diff] [blame] | 650 | |
Devang Patel | 161b2f4 | 2011-04-12 23:21:44 +0000 | [diff] [blame] | 651 | /// addToContextOwner - Add Die into the list of its context owner's children. |
| 652 | void CompileUnit::addToContextOwner(DIE *Die, DIDescriptor Context) { |
| 653 | if (Context.isType()) { |
| 654 | DIE *ContextDIE = getOrCreateTypeDIE(DIType(Context)); |
| 655 | ContextDIE->addChild(Die); |
| 656 | } else if (Context.isNameSpace()) { |
| 657 | DIE *ContextDIE = getOrCreateNameSpace(DINameSpace(Context)); |
| 658 | ContextDIE->addChild(Die); |
| 659 | } else if (Context.isSubprogram()) { |
Devang Patel | dbc64af | 2011-08-15 17:24:54 +0000 | [diff] [blame] | 660 | DIE *ContextDIE = getOrCreateSubprogramDIE(DISubprogram(Context)); |
Devang Patel | 161b2f4 | 2011-04-12 23:21:44 +0000 | [diff] [blame] | 661 | ContextDIE->addChild(Die); |
| 662 | } else if (DIE *ContextDIE = getDIE(Context)) |
| 663 | ContextDIE->addChild(Die); |
| 664 | else |
| 665 | addDie(Die); |
| 666 | } |
| 667 | |
| 668 | /// getOrCreateTypeDIE - Find existing DIE or create new DIE for the |
| 669 | /// given DIType. |
Devang Patel | 94c7ddb | 2011-08-16 22:09:43 +0000 | [diff] [blame] | 670 | DIE *CompileUnit::getOrCreateTypeDIE(const MDNode *TyNode) { |
| 671 | DIType Ty(TyNode); |
| 672 | if (!Ty.Verify()) |
| 673 | return NULL; |
Devang Patel | 161b2f4 | 2011-04-12 23:21:44 +0000 | [diff] [blame] | 674 | DIE *TyDIE = getDIE(Ty); |
| 675 | if (TyDIE) |
| 676 | return TyDIE; |
| 677 | |
| 678 | // Create new type. |
| 679 | TyDIE = new DIE(dwarf::DW_TAG_base_type); |
| 680 | insertDIE(Ty, TyDIE); |
| 681 | if (Ty.isBasicType()) |
| 682 | constructTypeDIE(*TyDIE, DIBasicType(Ty)); |
| 683 | else if (Ty.isCompositeType()) |
| 684 | constructTypeDIE(*TyDIE, DICompositeType(Ty)); |
| 685 | else { |
| 686 | assert(Ty.isDerivedType() && "Unknown kind of DIType"); |
| 687 | constructTypeDIE(*TyDIE, DIDerivedType(Ty)); |
| 688 | } |
Eric Christopher | 1b3f919 | 2011-11-10 19:52:58 +0000 | [diff] [blame] | 689 | // If this is a named finished type then include it in the list of types |
| 690 | // for the accelerator tables. |
Eric Christopher | c36145f | 2012-01-06 04:35:23 +0000 | [diff] [blame] | 691 | if (!Ty.getName().empty() && !Ty.isForwardDecl()) { |
| 692 | bool IsImplementation = 0; |
| 693 | if (Ty.isCompositeType()) { |
| 694 | DICompositeType CT(Ty); |
Eric Christopher | e016789 | 2012-01-06 23:03:37 +0000 | [diff] [blame] | 695 | // A runtime language of 0 actually means C/C++ and that any |
| 696 | // non-negative value is some version of Objective-C/C++. |
Eric Christopher | c36145f | 2012-01-06 04:35:23 +0000 | [diff] [blame] | 697 | IsImplementation = (CT.getRunTimeLang() == 0) || |
Eric Christopher | e2dc933 | 2012-02-22 08:46:02 +0000 | [diff] [blame] | 698 | CT.isObjcClassComplete(); |
Eric Christopher | c36145f | 2012-01-06 04:35:23 +0000 | [diff] [blame] | 699 | } |
Eric Christopher | e016789 | 2012-01-06 23:03:37 +0000 | [diff] [blame] | 700 | unsigned Flags = IsImplementation ? |
| 701 | DwarfAccelTable::eTypeFlagClassIsImplementation : 0; |
| 702 | addAccelType(Ty.getName(), std::make_pair(TyDIE, Flags)); |
Eric Christopher | c36145f | 2012-01-06 04:35:23 +0000 | [diff] [blame] | 703 | } |
Eric Christopher | 8b4310b | 2012-11-21 00:34:38 +0000 | [diff] [blame] | 704 | |
Devang Patel | 161b2f4 | 2011-04-12 23:21:44 +0000 | [diff] [blame] | 705 | addToContextOwner(TyDIE, Ty.getContext()); |
| 706 | return TyDIE; |
| 707 | } |
| 708 | |
| 709 | /// addType - Add a new type attribute to the specified entity. |
Eric Christopher | 4d069bf | 2012-05-22 18:45:24 +0000 | [diff] [blame] | 710 | void CompileUnit::addType(DIE *Entity, DIType Ty, unsigned Attribute) { |
Devang Patel | 161b2f4 | 2011-04-12 23:21:44 +0000 | [diff] [blame] | 711 | if (!Ty.Verify()) |
| 712 | return; |
| 713 | |
| 714 | // Check for pre-existence. |
| 715 | DIEEntry *Entry = getDIEEntry(Ty); |
| 716 | // If it exists then use the existing value. |
| 717 | if (Entry) { |
Eric Christopher | 663e0cf | 2012-03-28 07:34:31 +0000 | [diff] [blame] | 718 | Entity->addValue(Attribute, dwarf::DW_FORM_ref4, Entry); |
Devang Patel | 161b2f4 | 2011-04-12 23:21:44 +0000 | [diff] [blame] | 719 | return; |
| 720 | } |
| 721 | |
| 722 | // Construct type. |
| 723 | DIE *Buffer = getOrCreateTypeDIE(Ty); |
| 724 | |
| 725 | // Set up proxy. |
| 726 | Entry = createDIEEntry(Buffer); |
| 727 | insertDIEEntry(Ty, Entry); |
Eric Christopher | 663e0cf | 2012-03-28 07:34:31 +0000 | [diff] [blame] | 728 | Entity->addValue(Attribute, dwarf::DW_FORM_ref4, Entry); |
Devang Patel | e9ae06c | 2011-05-31 22:56:51 +0000 | [diff] [blame] | 729 | |
| 730 | // If this is a complete composite type then include it in the |
| 731 | // list of global types. |
Devang Patel | c20bdf1 | 2011-06-01 00:23:24 +0000 | [diff] [blame] | 732 | addGlobalType(Ty); |
Devang Patel | 66658e4 | 2011-05-31 23:30:30 +0000 | [diff] [blame] | 733 | } |
| 734 | |
| 735 | /// addGlobalType - Add a new global type to the compile unit. |
| 736 | /// |
Devang Patel | c20bdf1 | 2011-06-01 00:23:24 +0000 | [diff] [blame] | 737 | void CompileUnit::addGlobalType(DIType Ty) { |
Devang Patel | e9ae06c | 2011-05-31 22:56:51 +0000 | [diff] [blame] | 738 | DIDescriptor Context = Ty.getContext(); |
Eric Christopher | 8b4310b | 2012-11-21 00:34:38 +0000 | [diff] [blame] | 739 | if (Ty.isCompositeType() && !Ty.getName().empty() && !Ty.isForwardDecl() |
| 740 | && (!Context || Context.isCompileUnit() || Context.isFile() |
Devang Patel | 94c7ddb | 2011-08-16 22:09:43 +0000 | [diff] [blame] | 741 | || Context.isNameSpace())) |
Devang Patel | c20bdf1 | 2011-06-01 00:23:24 +0000 | [diff] [blame] | 742 | if (DIEEntry *Entry = getDIEEntry(Ty)) |
| 743 | GlobalTypes[Ty.getName()] = Entry->getEntry(); |
Devang Patel | 161b2f4 | 2011-04-12 23:21:44 +0000 | [diff] [blame] | 744 | } |
| 745 | |
Devang Patel | 31c5d05 | 2011-05-06 16:57:54 +0000 | [diff] [blame] | 746 | /// addPubTypes - Add type for pubtypes section. |
| 747 | void CompileUnit::addPubTypes(DISubprogram SP) { |
| 748 | DICompositeType SPTy = SP.getType(); |
| 749 | unsigned SPTag = SPTy.getTag(); |
| 750 | if (SPTag != dwarf::DW_TAG_subroutine_type) |
| 751 | return; |
| 752 | |
| 753 | DIArray Args = SPTy.getTypeArray(); |
| 754 | for (unsigned i = 0, e = Args.getNumElements(); i != e; ++i) { |
| 755 | DIType ATy(Args.getElement(i)); |
| 756 | if (!ATy.Verify()) |
| 757 | continue; |
Devang Patel | c20bdf1 | 2011-06-01 00:23:24 +0000 | [diff] [blame] | 758 | addGlobalType(ATy); |
Devang Patel | 31c5d05 | 2011-05-06 16:57:54 +0000 | [diff] [blame] | 759 | } |
| 760 | } |
| 761 | |
Devang Patel | 161b2f4 | 2011-04-12 23:21:44 +0000 | [diff] [blame] | 762 | /// constructTypeDIE - Construct basic type die from DIBasicType. |
| 763 | void CompileUnit::constructTypeDIE(DIE &Buffer, DIBasicType BTy) { |
| 764 | // Get core information. |
| 765 | StringRef Name = BTy.getName(); |
Devang Patel | 161b2f4 | 2011-04-12 23:21:44 +0000 | [diff] [blame] | 766 | // Add name if not anonymous or intermediate type. |
| 767 | if (!Name.empty()) |
Nick Lewycky | 390c40d | 2011-10-27 06:44:11 +0000 | [diff] [blame] | 768 | addString(&Buffer, dwarf::DW_AT_name, Name); |
Devang Patel | 734a67c | 2011-09-14 23:13:28 +0000 | [diff] [blame] | 769 | |
| 770 | if (BTy.getTag() == dwarf::DW_TAG_unspecified_type) { |
| 771 | Buffer.setTag(dwarf::DW_TAG_unspecified_type); |
| 772 | // Unspecified types has only name, nothing else. |
| 773 | return; |
| 774 | } |
| 775 | |
| 776 | Buffer.setTag(dwarf::DW_TAG_base_type); |
Nick Lewycky | 746cb67 | 2011-10-26 22:55:33 +0000 | [diff] [blame] | 777 | addUInt(&Buffer, dwarf::DW_AT_encoding, dwarf::DW_FORM_data1, |
Devang Patel | 30d409c | 2012-02-07 23:33:58 +0000 | [diff] [blame] | 778 | BTy.getEncoding()); |
Devang Patel | 734a67c | 2011-09-14 23:13:28 +0000 | [diff] [blame] | 779 | |
Devang Patel | 161b2f4 | 2011-04-12 23:21:44 +0000 | [diff] [blame] | 780 | uint64_t Size = BTy.getSizeInBits() >> 3; |
| 781 | addUInt(&Buffer, dwarf::DW_AT_byte_size, 0, Size); |
| 782 | } |
| 783 | |
| 784 | /// constructTypeDIE - Construct derived type die from DIDerivedType. |
| 785 | void CompileUnit::constructTypeDIE(DIE &Buffer, DIDerivedType DTy) { |
| 786 | // Get core information. |
| 787 | StringRef Name = DTy.getName(); |
| 788 | uint64_t Size = DTy.getSizeInBits() >> 3; |
| 789 | unsigned Tag = DTy.getTag(); |
| 790 | |
| 791 | // FIXME - Workaround for templates. |
| 792 | if (Tag == dwarf::DW_TAG_inheritance) Tag = dwarf::DW_TAG_reference_type; |
| 793 | |
| 794 | Buffer.setTag(Tag); |
| 795 | |
| 796 | // Map to main type, void will not have a type. |
| 797 | DIType FromTy = DTy.getTypeDerivedFrom(); |
| 798 | addType(&Buffer, FromTy); |
| 799 | |
| 800 | // Add name if not anonymous or intermediate type. |
| 801 | if (!Name.empty()) |
Nick Lewycky | 390c40d | 2011-10-27 06:44:11 +0000 | [diff] [blame] | 802 | addString(&Buffer, dwarf::DW_AT_name, Name); |
Devang Patel | 161b2f4 | 2011-04-12 23:21:44 +0000 | [diff] [blame] | 803 | |
| 804 | // Add size if non-zero (derived types might be zero-sized.) |
Eric Christopher | 35f225a | 2012-02-21 22:25:53 +0000 | [diff] [blame] | 805 | if (Size && Tag != dwarf::DW_TAG_pointer_type) |
Devang Patel | 161b2f4 | 2011-04-12 23:21:44 +0000 | [diff] [blame] | 806 | addUInt(&Buffer, dwarf::DW_AT_byte_size, 0, Size); |
| 807 | |
David Blaikie | 62fdfb5 | 2013-01-07 05:51:15 +0000 | [diff] [blame] | 808 | if (Tag == dwarf::DW_TAG_ptr_to_member_type) |
| 809 | addDIEEntry(&Buffer, dwarf::DW_AT_containing_type, dwarf::DW_FORM_ref4, |
| 810 | getOrCreateTypeDIE(DTy.getClassType())); |
Devang Patel | 161b2f4 | 2011-04-12 23:21:44 +0000 | [diff] [blame] | 811 | // Add source line info if available and TyDesc is not a forward declaration. |
| 812 | if (!DTy.isForwardDecl()) |
| 813 | addSourceLine(&Buffer, DTy); |
| 814 | } |
| 815 | |
| 816 | /// constructTypeDIE - Construct type DIE from DICompositeType. |
| 817 | void CompileUnit::constructTypeDIE(DIE &Buffer, DICompositeType CTy) { |
| 818 | // Get core information. |
| 819 | StringRef Name = CTy.getName(); |
| 820 | |
| 821 | uint64_t Size = CTy.getSizeInBits() >> 3; |
| 822 | unsigned Tag = CTy.getTag(); |
| 823 | Buffer.setTag(Tag); |
| 824 | |
| 825 | switch (Tag) { |
| 826 | case dwarf::DW_TAG_vector_type: |
| 827 | case dwarf::DW_TAG_array_type: |
| 828 | constructArrayTypeDIE(Buffer, &CTy); |
| 829 | break; |
| 830 | case dwarf::DW_TAG_enumeration_type: { |
| 831 | DIArray Elements = CTy.getTypeArray(); |
| 832 | |
| 833 | // Add enumerators to enumeration type. |
| 834 | for (unsigned i = 0, N = Elements.getNumElements(); i < N; ++i) { |
| 835 | DIE *ElemDie = NULL; |
| 836 | DIDescriptor Enum(Elements.getElement(i)); |
| 837 | if (Enum.isEnumerator()) { |
| 838 | ElemDie = constructEnumTypeDIE(DIEnumerator(Enum)); |
| 839 | Buffer.addChild(ElemDie); |
| 840 | } |
| 841 | } |
Eric Christopher | bb0f6ea | 2012-05-23 00:09:20 +0000 | [diff] [blame] | 842 | DIType DTy = CTy.getTypeDerivedFrom(); |
| 843 | if (DTy.Verify()) { |
| 844 | addType(&Buffer, DTy); |
| 845 | addUInt(&Buffer, dwarf::DW_AT_enum_class, dwarf::DW_FORM_flag, 1); |
| 846 | } |
Devang Patel | 161b2f4 | 2011-04-12 23:21:44 +0000 | [diff] [blame] | 847 | } |
| 848 | break; |
| 849 | case dwarf::DW_TAG_subroutine_type: { |
| 850 | // Add return type. |
| 851 | DIArray Elements = CTy.getTypeArray(); |
| 852 | DIDescriptor RTy = Elements.getElement(0); |
| 853 | addType(&Buffer, DIType(RTy)); |
| 854 | |
| 855 | bool isPrototyped = true; |
| 856 | // Add arguments. |
| 857 | for (unsigned i = 1, N = Elements.getNumElements(); i < N; ++i) { |
| 858 | DIDescriptor Ty = Elements.getElement(i); |
| 859 | if (Ty.isUnspecifiedParameter()) { |
| 860 | DIE *Arg = new DIE(dwarf::DW_TAG_unspecified_parameters); |
| 861 | Buffer.addChild(Arg); |
| 862 | isPrototyped = false; |
| 863 | } else { |
| 864 | DIE *Arg = new DIE(dwarf::DW_TAG_formal_parameter); |
| 865 | addType(Arg, DIType(Ty)); |
| 866 | Buffer.addChild(Arg); |
| 867 | } |
| 868 | } |
Eric Christopher | 8b6fe6b | 2012-02-22 08:46:21 +0000 | [diff] [blame] | 869 | // Add prototype flag if we're dealing with a C language and the |
| 870 | // function has been prototyped. |
| 871 | if (isPrototyped && |
Eric Christopher | 4d069bf | 2012-05-22 18:45:24 +0000 | [diff] [blame] | 872 | (Language == dwarf::DW_LANG_C89 || |
| 873 | Language == dwarf::DW_LANG_C99 || |
| 874 | Language == dwarf::DW_LANG_ObjC)) |
Eric Christopher | 873cf0a | 2012-08-24 01:14:27 +0000 | [diff] [blame] | 875 | addFlag(&Buffer, dwarf::DW_AT_prototyped); |
Devang Patel | 161b2f4 | 2011-04-12 23:21:44 +0000 | [diff] [blame] | 876 | } |
| 877 | break; |
| 878 | case dwarf::DW_TAG_structure_type: |
| 879 | case dwarf::DW_TAG_union_type: |
| 880 | case dwarf::DW_TAG_class_type: { |
| 881 | // Add elements to structure type. |
| 882 | DIArray Elements = CTy.getTypeArray(); |
| 883 | |
| 884 | // A forward struct declared type may not have elements available. |
| 885 | unsigned N = Elements.getNumElements(); |
| 886 | if (N == 0) |
| 887 | break; |
| 888 | |
| 889 | // Add elements to structure type. |
| 890 | for (unsigned i = 0; i < N; ++i) { |
| 891 | DIDescriptor Element = Elements.getElement(i); |
| 892 | DIE *ElemDie = NULL; |
| 893 | if (Element.isSubprogram()) { |
| 894 | DISubprogram SP(Element); |
Devang Patel | dbc64af | 2011-08-15 17:24:54 +0000 | [diff] [blame] | 895 | ElemDie = getOrCreateSubprogramDIE(DISubprogram(Element)); |
Devang Patel | 161b2f4 | 2011-04-12 23:21:44 +0000 | [diff] [blame] | 896 | if (SP.isProtected()) |
Nick Lewycky | 13aaca5 | 2011-12-13 05:09:11 +0000 | [diff] [blame] | 897 | addUInt(ElemDie, dwarf::DW_AT_accessibility, dwarf::DW_FORM_data1, |
Devang Patel | 161b2f4 | 2011-04-12 23:21:44 +0000 | [diff] [blame] | 898 | dwarf::DW_ACCESS_protected); |
| 899 | else if (SP.isPrivate()) |
Nick Lewycky | 13aaca5 | 2011-12-13 05:09:11 +0000 | [diff] [blame] | 900 | addUInt(ElemDie, dwarf::DW_AT_accessibility, dwarf::DW_FORM_data1, |
Devang Patel | 161b2f4 | 2011-04-12 23:21:44 +0000 | [diff] [blame] | 901 | dwarf::DW_ACCESS_private); |
Eric Christopher | 8b4310b | 2012-11-21 00:34:38 +0000 | [diff] [blame] | 902 | else |
Nick Lewycky | 13aaca5 | 2011-12-13 05:09:11 +0000 | [diff] [blame] | 903 | addUInt(ElemDie, dwarf::DW_AT_accessibility, dwarf::DW_FORM_data1, |
Devang Patel | 161b2f4 | 2011-04-12 23:21:44 +0000 | [diff] [blame] | 904 | dwarf::DW_ACCESS_public); |
| 905 | if (SP.isExplicit()) |
Eric Christopher | 873cf0a | 2012-08-24 01:14:27 +0000 | [diff] [blame] | 906 | addFlag(ElemDie, dwarf::DW_AT_explicit); |
Devang Patel | 161b2f4 | 2011-04-12 23:21:44 +0000 | [diff] [blame] | 907 | } |
| 908 | else if (Element.isVariable()) { |
| 909 | DIVariable DV(Element); |
| 910 | ElemDie = new DIE(dwarf::DW_TAG_variable); |
Nick Lewycky | 390c40d | 2011-10-27 06:44:11 +0000 | [diff] [blame] | 911 | addString(ElemDie, dwarf::DW_AT_name, DV.getName()); |
Devang Patel | 161b2f4 | 2011-04-12 23:21:44 +0000 | [diff] [blame] | 912 | addType(ElemDie, DV.getType()); |
Eric Christopher | 873cf0a | 2012-08-24 01:14:27 +0000 | [diff] [blame] | 913 | addFlag(ElemDie, dwarf::DW_AT_declaration); |
| 914 | addFlag(ElemDie, dwarf::DW_AT_external); |
Devang Patel | 161b2f4 | 2011-04-12 23:21:44 +0000 | [diff] [blame] | 915 | addSourceLine(ElemDie, DV); |
Eric Christopher | 663e0cf | 2012-03-28 07:34:31 +0000 | [diff] [blame] | 916 | } else if (Element.isDerivedType()) { |
Eric Christopher | 4d069bf | 2012-05-22 18:45:24 +0000 | [diff] [blame] | 917 | DIDerivedType DDTy(Element); |
| 918 | if (DDTy.getTag() == dwarf::DW_TAG_friend) { |
| 919 | ElemDie = new DIE(dwarf::DW_TAG_friend); |
| 920 | addType(ElemDie, DDTy.getTypeDerivedFrom(), dwarf::DW_AT_friend); |
| 921 | } else |
| 922 | ElemDie = createMemberDIE(DIDerivedType(Element)); |
Eric Christopher | 663e0cf | 2012-03-28 07:34:31 +0000 | [diff] [blame] | 923 | } else if (Element.isObjCProperty()) { |
Devang Patel | 30d409c | 2012-02-07 23:33:58 +0000 | [diff] [blame] | 924 | DIObjCProperty Property(Element); |
| 925 | ElemDie = new DIE(Property.getTag()); |
| 926 | StringRef PropertyName = Property.getObjCPropertyName(); |
| 927 | addString(ElemDie, dwarf::DW_AT_APPLE_property_name, PropertyName); |
Eric Christopher | 4d069bf | 2012-05-22 18:45:24 +0000 | [diff] [blame] | 928 | addType(ElemDie, Property.getType()); |
| 929 | addSourceLine(ElemDie, Property); |
Devang Patel | 30d409c | 2012-02-07 23:33:58 +0000 | [diff] [blame] | 930 | StringRef GetterName = Property.getObjCPropertyGetterName(); |
| 931 | if (!GetterName.empty()) |
| 932 | addString(ElemDie, dwarf::DW_AT_APPLE_property_getter, GetterName); |
| 933 | StringRef SetterName = Property.getObjCPropertySetterName(); |
| 934 | if (!SetterName.empty()) |
| 935 | addString(ElemDie, dwarf::DW_AT_APPLE_property_setter, SetterName); |
| 936 | unsigned PropertyAttributes = 0; |
Devang Patel | 9e11eb1 | 2012-02-04 01:30:32 +0000 | [diff] [blame] | 937 | if (Property.isReadOnlyObjCProperty()) |
| 938 | PropertyAttributes |= dwarf::DW_APPLE_PROPERTY_readonly; |
| 939 | if (Property.isReadWriteObjCProperty()) |
| 940 | PropertyAttributes |= dwarf::DW_APPLE_PROPERTY_readwrite; |
| 941 | if (Property.isAssignObjCProperty()) |
| 942 | PropertyAttributes |= dwarf::DW_APPLE_PROPERTY_assign; |
| 943 | if (Property.isRetainObjCProperty()) |
| 944 | PropertyAttributes |= dwarf::DW_APPLE_PROPERTY_retain; |
| 945 | if (Property.isCopyObjCProperty()) |
| 946 | PropertyAttributes |= dwarf::DW_APPLE_PROPERTY_copy; |
| 947 | if (Property.isNonAtomicObjCProperty()) |
| 948 | PropertyAttributes |= dwarf::DW_APPLE_PROPERTY_nonatomic; |
| 949 | if (PropertyAttributes) |
Eric Christopher | 8b4310b | 2012-11-21 00:34:38 +0000 | [diff] [blame] | 950 | addUInt(ElemDie, dwarf::DW_AT_APPLE_property_attribute, 0, |
Devang Patel | 9e11eb1 | 2012-02-04 01:30:32 +0000 | [diff] [blame] | 951 | PropertyAttributes); |
Devang Patel | 6588abf | 2012-02-06 17:49:43 +0000 | [diff] [blame] | 952 | |
Devang Patel | 30d409c | 2012-02-07 23:33:58 +0000 | [diff] [blame] | 953 | DIEEntry *Entry = getDIEEntry(Element); |
| 954 | if (!Entry) { |
| 955 | Entry = createDIEEntry(ElemDie); |
| 956 | insertDIEEntry(Element, Entry); |
| 957 | } |
Devang Patel | 9e11eb1 | 2012-02-04 01:30:32 +0000 | [diff] [blame] | 958 | } else |
Devang Patel | 161b2f4 | 2011-04-12 23:21:44 +0000 | [diff] [blame] | 959 | continue; |
| 960 | Buffer.addChild(ElemDie); |
| 961 | } |
| 962 | |
| 963 | if (CTy.isAppleBlockExtension()) |
Eric Christopher | 873cf0a | 2012-08-24 01:14:27 +0000 | [diff] [blame] | 964 | addFlag(&Buffer, dwarf::DW_AT_APPLE_block); |
Devang Patel | 161b2f4 | 2011-04-12 23:21:44 +0000 | [diff] [blame] | 965 | |
Devang Patel | 161b2f4 | 2011-04-12 23:21:44 +0000 | [diff] [blame] | 966 | DICompositeType ContainingType = CTy.getContainingType(); |
| 967 | if (DIDescriptor(ContainingType).isCompositeType()) |
| 968 | addDIEEntry(&Buffer, dwarf::DW_AT_containing_type, dwarf::DW_FORM_ref4, |
| 969 | getOrCreateTypeDIE(DIType(ContainingType))); |
| 970 | else { |
| 971 | DIDescriptor Context = CTy.getContext(); |
| 972 | addToContextOwner(&Buffer, Context); |
| 973 | } |
| 974 | |
Devang Patel | 201e6cd | 2011-05-12 21:29:42 +0000 | [diff] [blame] | 975 | if (CTy.isObjcClassComplete()) |
Eric Christopher | 873cf0a | 2012-08-24 01:14:27 +0000 | [diff] [blame] | 976 | addFlag(&Buffer, dwarf::DW_AT_APPLE_objc_complete_type); |
Devang Patel | b11f80e | 2011-05-12 19:06:16 +0000 | [diff] [blame] | 977 | |
Eric Christopher | 1a8e886 | 2011-12-16 23:42:42 +0000 | [diff] [blame] | 978 | // Add template parameters to a class, structure or union types. |
| 979 | // FIXME: The support isn't in the metadata for this yet. |
| 980 | if (Tag == dwarf::DW_TAG_class_type || |
| 981 | Tag == dwarf::DW_TAG_structure_type || |
| 982 | Tag == dwarf::DW_TAG_union_type) |
Devang Patel | 161b2f4 | 2011-04-12 23:21:44 +0000 | [diff] [blame] | 983 | addTemplateParams(Buffer, CTy.getTemplateParams()); |
| 984 | |
| 985 | break; |
| 986 | } |
| 987 | default: |
| 988 | break; |
| 989 | } |
| 990 | |
| 991 | // Add name if not anonymous or intermediate type. |
| 992 | if (!Name.empty()) |
Nick Lewycky | 390c40d | 2011-10-27 06:44:11 +0000 | [diff] [blame] | 993 | addString(&Buffer, dwarf::DW_AT_name, Name); |
Devang Patel | 161b2f4 | 2011-04-12 23:21:44 +0000 | [diff] [blame] | 994 | |
Eric Christopher | 4a5d839 | 2012-05-22 18:45:18 +0000 | [diff] [blame] | 995 | if (Tag == dwarf::DW_TAG_enumeration_type || |
| 996 | Tag == dwarf::DW_TAG_class_type || |
| 997 | Tag == dwarf::DW_TAG_structure_type || |
| 998 | Tag == dwarf::DW_TAG_union_type) { |
Devang Patel | 161b2f4 | 2011-04-12 23:21:44 +0000 | [diff] [blame] | 999 | // Add size if non-zero (derived types might be zero-sized.) |
Eric Christopher | fc4199b | 2012-06-01 00:22:32 +0000 | [diff] [blame] | 1000 | // TODO: Do we care about size for enum forward declarations? |
Devang Patel | 161b2f4 | 2011-04-12 23:21:44 +0000 | [diff] [blame] | 1001 | if (Size) |
| 1002 | addUInt(&Buffer, dwarf::DW_AT_byte_size, 0, Size); |
Eric Christopher | fc4199b | 2012-06-01 00:22:32 +0000 | [diff] [blame] | 1003 | else if (!CTy.isForwardDecl()) |
Devang Patel | 161b2f4 | 2011-04-12 23:21:44 +0000 | [diff] [blame] | 1004 | // Add zero size if it is not a forward declaration. |
Eric Christopher | fc4199b | 2012-06-01 00:22:32 +0000 | [diff] [blame] | 1005 | addUInt(&Buffer, dwarf::DW_AT_byte_size, 0, 0); |
| 1006 | |
| 1007 | // If we're a forward decl, say so. |
| 1008 | if (CTy.isForwardDecl()) |
Eric Christopher | 873cf0a | 2012-08-24 01:14:27 +0000 | [diff] [blame] | 1009 | addFlag(&Buffer, dwarf::DW_AT_declaration); |
Devang Patel | 161b2f4 | 2011-04-12 23:21:44 +0000 | [diff] [blame] | 1010 | |
| 1011 | // Add source line info if available. |
| 1012 | if (!CTy.isForwardDecl()) |
| 1013 | addSourceLine(&Buffer, CTy); |
Eric Christopher | 8938895 | 2012-03-07 00:15:19 +0000 | [diff] [blame] | 1014 | |
| 1015 | // No harm in adding the runtime language to the declaration. |
| 1016 | unsigned RLang = CTy.getRunTimeLang(); |
| 1017 | if (RLang) |
| 1018 | addUInt(&Buffer, dwarf::DW_AT_APPLE_runtime_class, |
| 1019 | dwarf::DW_FORM_data1, RLang); |
Devang Patel | 161b2f4 | 2011-04-12 23:21:44 +0000 | [diff] [blame] | 1020 | } |
| 1021 | } |
| 1022 | |
Eric Christopher | 8b4310b | 2012-11-21 00:34:38 +0000 | [diff] [blame] | 1023 | /// getOrCreateTemplateTypeParameterDIE - Find existing DIE or create new DIE |
Devang Patel | 161b2f4 | 2011-04-12 23:21:44 +0000 | [diff] [blame] | 1024 | /// for the given DITemplateTypeParameter. |
| 1025 | DIE * |
| 1026 | CompileUnit::getOrCreateTemplateTypeParameterDIE(DITemplateTypeParameter TP) { |
| 1027 | DIE *ParamDIE = getDIE(TP); |
| 1028 | if (ParamDIE) |
| 1029 | return ParamDIE; |
| 1030 | |
| 1031 | ParamDIE = new DIE(dwarf::DW_TAG_template_type_parameter); |
| 1032 | addType(ParamDIE, TP.getType()); |
Nick Lewycky | 390c40d | 2011-10-27 06:44:11 +0000 | [diff] [blame] | 1033 | addString(ParamDIE, dwarf::DW_AT_name, TP.getName()); |
Devang Patel | 161b2f4 | 2011-04-12 23:21:44 +0000 | [diff] [blame] | 1034 | return ParamDIE; |
| 1035 | } |
| 1036 | |
Eric Christopher | 8b4310b | 2012-11-21 00:34:38 +0000 | [diff] [blame] | 1037 | /// getOrCreateTemplateValueParameterDIE - Find existing DIE or create new DIE |
Devang Patel | 161b2f4 | 2011-04-12 23:21:44 +0000 | [diff] [blame] | 1038 | /// for the given DITemplateValueParameter. |
| 1039 | DIE * |
Eric Christopher | 4d069bf | 2012-05-22 18:45:24 +0000 | [diff] [blame] | 1040 | CompileUnit::getOrCreateTemplateValueParameterDIE(DITemplateValueParameter TPV){ |
Devang Patel | 161b2f4 | 2011-04-12 23:21:44 +0000 | [diff] [blame] | 1041 | DIE *ParamDIE = getDIE(TPV); |
| 1042 | if (ParamDIE) |
| 1043 | return ParamDIE; |
| 1044 | |
| 1045 | ParamDIE = new DIE(dwarf::DW_TAG_template_value_parameter); |
| 1046 | addType(ParamDIE, TPV.getType()); |
| 1047 | if (!TPV.getName().empty()) |
Nick Lewycky | 390c40d | 2011-10-27 06:44:11 +0000 | [diff] [blame] | 1048 | addString(ParamDIE, dwarf::DW_AT_name, TPV.getName()); |
Eric Christopher | 8b4310b | 2012-11-21 00:34:38 +0000 | [diff] [blame] | 1049 | addUInt(ParamDIE, dwarf::DW_AT_const_value, dwarf::DW_FORM_udata, |
Devang Patel | 161b2f4 | 2011-04-12 23:21:44 +0000 | [diff] [blame] | 1050 | TPV.getValue()); |
| 1051 | return ParamDIE; |
| 1052 | } |
| 1053 | |
Devang Patel | 31c5d05 | 2011-05-06 16:57:54 +0000 | [diff] [blame] | 1054 | /// getOrCreateNameSpace - Create a DIE for DINameSpace. |
| 1055 | DIE *CompileUnit::getOrCreateNameSpace(DINameSpace NS) { |
| 1056 | DIE *NDie = getDIE(NS); |
| 1057 | if (NDie) |
| 1058 | return NDie; |
| 1059 | NDie = new DIE(dwarf::DW_TAG_namespace); |
| 1060 | insertDIE(NS, NDie); |
Eric Christopher | 09ac3d8 | 2011-11-07 09:24:32 +0000 | [diff] [blame] | 1061 | if (!NS.getName().empty()) { |
Nick Lewycky | 390c40d | 2011-10-27 06:44:11 +0000 | [diff] [blame] | 1062 | addString(NDie, dwarf::DW_AT_name, NS.getName()); |
Eric Christopher | 09ac3d8 | 2011-11-07 09:24:32 +0000 | [diff] [blame] | 1063 | addAccelNamespace(NS.getName(), NDie); |
| 1064 | } else |
| 1065 | addAccelNamespace("(anonymous namespace)", NDie); |
Devang Patel | 31c5d05 | 2011-05-06 16:57:54 +0000 | [diff] [blame] | 1066 | addSourceLine(NDie, NS); |
| 1067 | addToContextOwner(NDie, NS.getContext()); |
| 1068 | return NDie; |
| 1069 | } |
| 1070 | |
Devang Patel | dbc64af | 2011-08-15 17:24:54 +0000 | [diff] [blame] | 1071 | /// getRealLinkageName - If special LLVM prefix that is used to inform the asm |
| 1072 | /// printer to not emit usual symbol prefix before the symbol name is used then |
| 1073 | /// return linkage name after skipping this special LLVM prefix. |
| 1074 | static StringRef getRealLinkageName(StringRef LinkageName) { |
| 1075 | char One = '\1'; |
| 1076 | if (LinkageName.startswith(StringRef(&One, 1))) |
| 1077 | return LinkageName.substr(1); |
| 1078 | return LinkageName; |
| 1079 | } |
| 1080 | |
| 1081 | /// getOrCreateSubprogramDIE - Create new DIE using SP. |
| 1082 | DIE *CompileUnit::getOrCreateSubprogramDIE(DISubprogram SP) { |
| 1083 | DIE *SPDie = getDIE(SP); |
| 1084 | if (SPDie) |
| 1085 | return SPDie; |
| 1086 | |
Peter Collingbourne | 27302f0 | 2012-05-27 18:36:44 +0000 | [diff] [blame] | 1087 | SPDie = new DIE(dwarf::DW_TAG_subprogram); |
| 1088 | |
| 1089 | // DW_TAG_inlined_subroutine may refer to this DIE. |
| 1090 | insertDIE(SP, SPDie); |
| 1091 | |
Rafael Espindola | 01b55b4 | 2011-11-10 22:34:29 +0000 | [diff] [blame] | 1092 | DISubprogram SPDecl = SP.getFunctionDeclaration(); |
| 1093 | DIE *DeclDie = NULL; |
| 1094 | if (SPDecl.isSubprogram()) { |
| 1095 | DeclDie = getOrCreateSubprogramDIE(SPDecl); |
| 1096 | } |
| 1097 | |
Devang Patel | dbc64af | 2011-08-15 17:24:54 +0000 | [diff] [blame] | 1098 | // Add to context owner. |
| 1099 | addToContextOwner(SPDie, SP.getContext()); |
| 1100 | |
| 1101 | // Add function template parameters. |
| 1102 | addTemplateParams(*SPDie, SP.getTemplateParams()); |
| 1103 | |
Eric Christopher | e9722e1 | 2012-04-16 23:54:23 +0000 | [diff] [blame] | 1104 | // Unfortunately this code needs to stay here instead of below the |
| 1105 | // AT_specification code in order to work around a bug in older |
| 1106 | // gdbs that requires the linkage name to resolve multiple template |
| 1107 | // functions. |
Eric Christopher | cbbd5b1 | 2012-08-23 22:52:55 +0000 | [diff] [blame] | 1108 | // TODO: Remove this set of code when we get rid of the old gdb |
| 1109 | // compatibility. |
Eric Christopher | 8d101c3 | 2012-03-15 08:19:33 +0000 | [diff] [blame] | 1110 | StringRef LinkageName = SP.getLinkageName(); |
Eric Christopher | cbbd5b1 | 2012-08-23 22:52:55 +0000 | [diff] [blame] | 1111 | if (!LinkageName.empty() && DD->useDarwinGDBCompat()) |
Eric Christopher | 8d101c3 | 2012-03-15 08:19:33 +0000 | [diff] [blame] | 1112 | addString(SPDie, dwarf::DW_AT_MIPS_linkage_name, |
| 1113 | getRealLinkageName(LinkageName)); |
| 1114 | |
Devang Patel | dbc64af | 2011-08-15 17:24:54 +0000 | [diff] [blame] | 1115 | // If this DIE is going to refer declaration info using AT_specification |
| 1116 | // then there is no need to add other attributes. |
Rafael Espindola | 01b55b4 | 2011-11-10 22:34:29 +0000 | [diff] [blame] | 1117 | if (DeclDie) { |
| 1118 | // Refer function declaration directly. |
| 1119 | addDIEEntry(SPDie, dwarf::DW_AT_specification, dwarf::DW_FORM_ref4, |
| 1120 | DeclDie); |
| 1121 | |
Devang Patel | dbc64af | 2011-08-15 17:24:54 +0000 | [diff] [blame] | 1122 | return SPDie; |
Rafael Espindola | 01b55b4 | 2011-11-10 22:34:29 +0000 | [diff] [blame] | 1123 | } |
Devang Patel | dbc64af | 2011-08-15 17:24:54 +0000 | [diff] [blame] | 1124 | |
Eric Christopher | cbbd5b1 | 2012-08-23 22:52:55 +0000 | [diff] [blame] | 1125 | // Add the linkage name if we have one. |
| 1126 | if (!LinkageName.empty() && !DD->useDarwinGDBCompat()) |
| 1127 | addString(SPDie, dwarf::DW_AT_MIPS_linkage_name, |
| 1128 | getRealLinkageName(LinkageName)); |
| 1129 | |
Devang Patel | dbc64af | 2011-08-15 17:24:54 +0000 | [diff] [blame] | 1130 | // Constructors and operators for anonymous aggregates do not have names. |
| 1131 | if (!SP.getName().empty()) |
Nick Lewycky | 390c40d | 2011-10-27 06:44:11 +0000 | [diff] [blame] | 1132 | addString(SPDie, dwarf::DW_AT_name, SP.getName()); |
Devang Patel | dbc64af | 2011-08-15 17:24:54 +0000 | [diff] [blame] | 1133 | |
| 1134 | addSourceLine(SPDie, SP); |
| 1135 | |
Eric Christopher | 8b6fe6b | 2012-02-22 08:46:21 +0000 | [diff] [blame] | 1136 | // Add the prototype if we have a prototype and we have a C like |
| 1137 | // language. |
| 1138 | if (SP.isPrototyped() && |
| 1139 | (Language == dwarf::DW_LANG_C89 || |
| 1140 | Language == dwarf::DW_LANG_C99 || |
| 1141 | Language == dwarf::DW_LANG_ObjC)) |
Eric Christopher | 873cf0a | 2012-08-24 01:14:27 +0000 | [diff] [blame] | 1142 | addFlag(SPDie, dwarf::DW_AT_prototyped); |
Devang Patel | dbc64af | 2011-08-15 17:24:54 +0000 | [diff] [blame] | 1143 | |
| 1144 | // Add Return Type. |
| 1145 | DICompositeType SPTy = SP.getType(); |
| 1146 | DIArray Args = SPTy.getTypeArray(); |
| 1147 | unsigned SPTag = SPTy.getTag(); |
| 1148 | |
| 1149 | if (Args.getNumElements() == 0 || SPTag != dwarf::DW_TAG_subroutine_type) |
| 1150 | addType(SPDie, SPTy); |
| 1151 | else |
| 1152 | addType(SPDie, DIType(Args.getElement(0))); |
| 1153 | |
| 1154 | unsigned VK = SP.getVirtuality(); |
| 1155 | if (VK) { |
Nick Lewycky | 798313d | 2011-12-14 00:56:07 +0000 | [diff] [blame] | 1156 | addUInt(SPDie, dwarf::DW_AT_virtuality, dwarf::DW_FORM_data1, VK); |
Devang Patel | dbc64af | 2011-08-15 17:24:54 +0000 | [diff] [blame] | 1157 | DIEBlock *Block = getDIEBlock(); |
| 1158 | addUInt(Block, 0, dwarf::DW_FORM_data1, dwarf::DW_OP_constu); |
| 1159 | addUInt(Block, 0, dwarf::DW_FORM_udata, SP.getVirtualIndex()); |
| 1160 | addBlock(SPDie, dwarf::DW_AT_vtable_elem_location, 0, Block); |
| 1161 | ContainingTypeMap.insert(std::make_pair(SPDie, |
| 1162 | SP.getContainingType())); |
| 1163 | } |
| 1164 | |
| 1165 | if (!SP.isDefinition()) { |
Eric Christopher | 873cf0a | 2012-08-24 01:14:27 +0000 | [diff] [blame] | 1166 | addFlag(SPDie, dwarf::DW_AT_declaration); |
Eric Christopher | 8b4310b | 2012-11-21 00:34:38 +0000 | [diff] [blame] | 1167 | |
Devang Patel | dbc64af | 2011-08-15 17:24:54 +0000 | [diff] [blame] | 1168 | // Add arguments. Do not add arguments for subprogram definition. They will |
| 1169 | // be handled while processing variables. |
| 1170 | DICompositeType SPTy = SP.getType(); |
| 1171 | DIArray Args = SPTy.getTypeArray(); |
| 1172 | unsigned SPTag = SPTy.getTag(); |
| 1173 | |
| 1174 | if (SPTag == dwarf::DW_TAG_subroutine_type) |
| 1175 | for (unsigned i = 1, N = Args.getNumElements(); i < N; ++i) { |
| 1176 | DIE *Arg = new DIE(dwarf::DW_TAG_formal_parameter); |
Eric Christopher | 5c38de9 | 2012-09-10 23:33:57 +0000 | [diff] [blame] | 1177 | DIType ATy = DIType(Args.getElement(i)); |
Devang Patel | dbc64af | 2011-08-15 17:24:54 +0000 | [diff] [blame] | 1178 | addType(Arg, ATy); |
| 1179 | if (ATy.isArtificial()) |
Eric Christopher | 873cf0a | 2012-08-24 01:14:27 +0000 | [diff] [blame] | 1180 | addFlag(Arg, dwarf::DW_AT_artificial); |
Devang Patel | dbc64af | 2011-08-15 17:24:54 +0000 | [diff] [blame] | 1181 | SPDie->addChild(Arg); |
| 1182 | } |
| 1183 | } |
| 1184 | |
| 1185 | if (SP.isArtificial()) |
Eric Christopher | 873cf0a | 2012-08-24 01:14:27 +0000 | [diff] [blame] | 1186 | addFlag(SPDie, dwarf::DW_AT_artificial); |
Devang Patel | dbc64af | 2011-08-15 17:24:54 +0000 | [diff] [blame] | 1187 | |
| 1188 | if (!SP.isLocalToUnit()) |
Eric Christopher | 873cf0a | 2012-08-24 01:14:27 +0000 | [diff] [blame] | 1189 | addFlag(SPDie, dwarf::DW_AT_external); |
Devang Patel | dbc64af | 2011-08-15 17:24:54 +0000 | [diff] [blame] | 1190 | |
| 1191 | if (SP.isOptimized()) |
Eric Christopher | 873cf0a | 2012-08-24 01:14:27 +0000 | [diff] [blame] | 1192 | addFlag(SPDie, dwarf::DW_AT_APPLE_optimized); |
Devang Patel | dbc64af | 2011-08-15 17:24:54 +0000 | [diff] [blame] | 1193 | |
| 1194 | if (unsigned isa = Asm->getISAEncoding()) { |
| 1195 | addUInt(SPDie, dwarf::DW_AT_APPLE_isa, dwarf::DW_FORM_flag, isa); |
| 1196 | } |
| 1197 | |
| 1198 | return SPDie; |
| 1199 | } |
| 1200 | |
Devang Patel | 6f9d8ff | 2011-08-15 17:57:41 +0000 | [diff] [blame] | 1201 | // Return const expression if value is a GEP to access merged global |
| 1202 | // constant. e.g. |
| 1203 | // i8* getelementptr ({ i8, i8, i8, i8 }* @_MergedGlobals, i32 0, i32 0) |
| 1204 | static const ConstantExpr *getMergedGlobalExpr(const Value *V) { |
| 1205 | const ConstantExpr *CE = dyn_cast_or_null<ConstantExpr>(V); |
| 1206 | if (!CE || CE->getNumOperands() != 3 || |
| 1207 | CE->getOpcode() != Instruction::GetElementPtr) |
| 1208 | return NULL; |
| 1209 | |
| 1210 | // First operand points to a global struct. |
| 1211 | Value *Ptr = CE->getOperand(0); |
| 1212 | if (!isa<GlobalValue>(Ptr) || |
| 1213 | !isa<StructType>(cast<PointerType>(Ptr->getType())->getElementType())) |
| 1214 | return NULL; |
| 1215 | |
| 1216 | // Second operand is zero. |
| 1217 | const ConstantInt *CI = dyn_cast_or_null<ConstantInt>(CE->getOperand(1)); |
| 1218 | if (!CI || !CI->isZero()) |
| 1219 | return NULL; |
| 1220 | |
| 1221 | // Third operand is offset. |
| 1222 | if (!isa<ConstantInt>(CE->getOperand(2))) |
| 1223 | return NULL; |
| 1224 | |
| 1225 | return CE; |
| 1226 | } |
| 1227 | |
| 1228 | /// createGlobalVariableDIE - create global variable DIE. |
| 1229 | void CompileUnit::createGlobalVariableDIE(const MDNode *N) { |
Devang Patel | 6f9d8ff | 2011-08-15 17:57:41 +0000 | [diff] [blame] | 1230 | // Check for pre-existence. |
Devang Patel | 49e2f03 | 2011-08-18 22:21:50 +0000 | [diff] [blame] | 1231 | if (getDIE(N)) |
Devang Patel | 6f9d8ff | 2011-08-15 17:57:41 +0000 | [diff] [blame] | 1232 | return; |
| 1233 | |
Devang Patel | 49e2f03 | 2011-08-18 22:21:50 +0000 | [diff] [blame] | 1234 | DIGlobalVariable GV(N); |
Devang Patel | 28bea08 | 2011-08-18 23:17:55 +0000 | [diff] [blame] | 1235 | if (!GV.Verify()) |
| 1236 | return; |
| 1237 | |
Devang Patel | 6f9d8ff | 2011-08-15 17:57:41 +0000 | [diff] [blame] | 1238 | DIE *VariableDIE = new DIE(GV.getTag()); |
Devang Patel | 49e2f03 | 2011-08-18 22:21:50 +0000 | [diff] [blame] | 1239 | // Add to map. |
| 1240 | insertDIE(N, VariableDIE); |
Devang Patel | 6f9d8ff | 2011-08-15 17:57:41 +0000 | [diff] [blame] | 1241 | |
| 1242 | // Add name. |
Nick Lewycky | 390c40d | 2011-10-27 06:44:11 +0000 | [diff] [blame] | 1243 | addString(VariableDIE, dwarf::DW_AT_name, GV.getDisplayName()); |
Devang Patel | 6f9d8ff | 2011-08-15 17:57:41 +0000 | [diff] [blame] | 1244 | StringRef LinkageName = GV.getLinkageName(); |
Devang Patel | 49e2f03 | 2011-08-18 22:21:50 +0000 | [diff] [blame] | 1245 | bool isGlobalVariable = GV.getGlobal() != NULL; |
Devang Patel | 6f9d8ff | 2011-08-15 17:57:41 +0000 | [diff] [blame] | 1246 | if (!LinkageName.empty() && isGlobalVariable) |
Nick Lewycky | 746cb67 | 2011-10-26 22:55:33 +0000 | [diff] [blame] | 1247 | addString(VariableDIE, dwarf::DW_AT_MIPS_linkage_name, |
Nick Lewycky | 390c40d | 2011-10-27 06:44:11 +0000 | [diff] [blame] | 1248 | getRealLinkageName(LinkageName)); |
Devang Patel | 6f9d8ff | 2011-08-15 17:57:41 +0000 | [diff] [blame] | 1249 | // Add type. |
Devang Patel | 49e2f03 | 2011-08-18 22:21:50 +0000 | [diff] [blame] | 1250 | DIType GTy = GV.getType(); |
Devang Patel | 6f9d8ff | 2011-08-15 17:57:41 +0000 | [diff] [blame] | 1251 | addType(VariableDIE, GTy); |
| 1252 | |
| 1253 | // Add scoping info. |
Eric Christopher | dfa30e1 | 2011-11-09 05:24:07 +0000 | [diff] [blame] | 1254 | if (!GV.isLocalToUnit()) |
Eric Christopher | 873cf0a | 2012-08-24 01:14:27 +0000 | [diff] [blame] | 1255 | addFlag(VariableDIE, dwarf::DW_AT_external); |
Eric Christopher | dfa30e1 | 2011-11-09 05:24:07 +0000 | [diff] [blame] | 1256 | |
Devang Patel | 6f9d8ff | 2011-08-15 17:57:41 +0000 | [diff] [blame] | 1257 | // Add line number info. |
| 1258 | addSourceLine(VariableDIE, GV); |
Devang Patel | 6f9d8ff | 2011-08-15 17:57:41 +0000 | [diff] [blame] | 1259 | // Add to context owner. |
| 1260 | DIDescriptor GVContext = GV.getContext(); |
| 1261 | addToContextOwner(VariableDIE, GVContext); |
| 1262 | // Add location. |
Eric Christopher | 09ac3d8 | 2011-11-07 09:24:32 +0000 | [diff] [blame] | 1263 | bool addToAccelTable = false; |
Eric Christopher | d61c34b | 2011-11-11 03:16:32 +0000 | [diff] [blame] | 1264 | DIE *VariableSpecDIE = NULL; |
Devang Patel | 6f9d8ff | 2011-08-15 17:57:41 +0000 | [diff] [blame] | 1265 | if (isGlobalVariable) { |
Eric Christopher | 09ac3d8 | 2011-11-07 09:24:32 +0000 | [diff] [blame] | 1266 | addToAccelTable = true; |
Devang Patel | 6f9d8ff | 2011-08-15 17:57:41 +0000 | [diff] [blame] | 1267 | DIEBlock *Block = new (DIEValueAllocator) DIEBlock(); |
| 1268 | addUInt(Block, 0, dwarf::DW_FORM_data1, dwarf::DW_OP_addr); |
| 1269 | addLabel(Block, 0, dwarf::DW_FORM_udata, |
| 1270 | Asm->Mang->getSymbol(GV.getGlobal())); |
| 1271 | // Do not create specification DIE if context is either compile unit |
| 1272 | // or a subprogram. |
Devang Patel | 1dd4e56 | 2011-09-21 23:41:11 +0000 | [diff] [blame] | 1273 | if (GVContext && GV.isDefinition() && !GVContext.isCompileUnit() && |
Devang Patel | 6f9d8ff | 2011-08-15 17:57:41 +0000 | [diff] [blame] | 1274 | !GVContext.isFile() && !isSubprogramContext(GVContext)) { |
| 1275 | // Create specification DIE. |
Eric Christopher | d117fbb | 2011-11-11 01:55:22 +0000 | [diff] [blame] | 1276 | VariableSpecDIE = new DIE(dwarf::DW_TAG_variable); |
Devang Patel | 6f9d8ff | 2011-08-15 17:57:41 +0000 | [diff] [blame] | 1277 | addDIEEntry(VariableSpecDIE, dwarf::DW_AT_specification, |
| 1278 | dwarf::DW_FORM_ref4, VariableDIE); |
| 1279 | addBlock(VariableSpecDIE, dwarf::DW_AT_location, 0, Block); |
Eric Christopher | 873cf0a | 2012-08-24 01:14:27 +0000 | [diff] [blame] | 1280 | addFlag(VariableDIE, dwarf::DW_AT_declaration); |
Devang Patel | 6f9d8ff | 2011-08-15 17:57:41 +0000 | [diff] [blame] | 1281 | addDie(VariableSpecDIE); |
| 1282 | } else { |
| 1283 | addBlock(VariableDIE, dwarf::DW_AT_location, 0, Block); |
Eric Christopher | 09ac3d8 | 2011-11-07 09:24:32 +0000 | [diff] [blame] | 1284 | } |
Eric Christopher | 8b4310b | 2012-11-21 00:34:38 +0000 | [diff] [blame] | 1285 | } else if (const ConstantInt *CI = |
Devang Patel | 6f9d8ff | 2011-08-15 17:57:41 +0000 | [diff] [blame] | 1286 | dyn_cast_or_null<ConstantInt>(GV.getConstant())) |
| 1287 | addConstantValue(VariableDIE, CI, GTy.isUnsignedDIType()); |
| 1288 | else if (const ConstantExpr *CE = getMergedGlobalExpr(N->getOperand(11))) { |
Eric Christopher | 09ac3d8 | 2011-11-07 09:24:32 +0000 | [diff] [blame] | 1289 | addToAccelTable = true; |
Devang Patel | 6f9d8ff | 2011-08-15 17:57:41 +0000 | [diff] [blame] | 1290 | // GV is a merged global. |
| 1291 | DIEBlock *Block = new (DIEValueAllocator) DIEBlock(); |
| 1292 | Value *Ptr = CE->getOperand(0); |
| 1293 | addUInt(Block, 0, dwarf::DW_FORM_data1, dwarf::DW_OP_addr); |
| 1294 | addLabel(Block, 0, dwarf::DW_FORM_udata, |
| 1295 | Asm->Mang->getSymbol(cast<GlobalValue>(Ptr))); |
| 1296 | addUInt(Block, 0, dwarf::DW_FORM_data1, dwarf::DW_OP_constu); |
| 1297 | SmallVector<Value*, 3> Idx(CE->op_begin()+1, CE->op_end()); |
Eric Christopher | 8b4310b | 2012-11-21 00:34:38 +0000 | [diff] [blame] | 1298 | addUInt(Block, 0, dwarf::DW_FORM_udata, |
Micah Villmow | 3574eca | 2012-10-08 16:38:25 +0000 | [diff] [blame] | 1299 | Asm->getDataLayout().getIndexedOffset(Ptr->getType(), Idx)); |
Devang Patel | 6f9d8ff | 2011-08-15 17:57:41 +0000 | [diff] [blame] | 1300 | addUInt(Block, 0, dwarf::DW_FORM_data1, dwarf::DW_OP_plus); |
| 1301 | addBlock(VariableDIE, dwarf::DW_AT_location, 0, Block); |
| 1302 | } |
| 1303 | |
Eric Christopher | d117fbb | 2011-11-11 01:55:22 +0000 | [diff] [blame] | 1304 | if (addToAccelTable) { |
| 1305 | DIE *AddrDIE = VariableSpecDIE ? VariableSpecDIE : VariableDIE; |
| 1306 | addAccelName(GV.getName(), AddrDIE); |
Eric Christopher | 09ac3d8 | 2011-11-07 09:24:32 +0000 | [diff] [blame] | 1307 | |
Eric Christopher | d117fbb | 2011-11-11 01:55:22 +0000 | [diff] [blame] | 1308 | // If the linkage name is different than the name, go ahead and output |
| 1309 | // that as well into the name table. |
| 1310 | if (GV.getLinkageName() != "" && GV.getName() != GV.getLinkageName()) |
| 1311 | addAccelName(GV.getLinkageName(), AddrDIE); |
| 1312 | } |
Eric Christopher | 74d8a87 | 2011-11-08 21:56:23 +0000 | [diff] [blame] | 1313 | |
Devang Patel | 6f9d8ff | 2011-08-15 17:57:41 +0000 | [diff] [blame] | 1314 | return; |
| 1315 | } |
| 1316 | |
Devang Patel | 161b2f4 | 2011-04-12 23:21:44 +0000 | [diff] [blame] | 1317 | /// constructSubrangeDIE - Construct subrange DIE from DISubrange. |
Eric Christopher | 4d069bf | 2012-05-22 18:45:24 +0000 | [diff] [blame] | 1318 | void CompileUnit::constructSubrangeDIE(DIE &Buffer, DISubrange SR, |
| 1319 | DIE *IndexTy) { |
Devang Patel | 161b2f4 | 2011-04-12 23:21:44 +0000 | [diff] [blame] | 1320 | DIE *DW_Subrange = new DIE(dwarf::DW_TAG_subrange_type); |
| 1321 | addDIEEntry(DW_Subrange, dwarf::DW_AT_type, dwarf::DW_FORM_ref4, IndexTy); |
Devang Patel | 161b2f4 | 2011-04-12 23:21:44 +0000 | [diff] [blame] | 1322 | |
Bill Wendling | 222c2fd | 2012-12-06 07:38:10 +0000 | [diff] [blame] | 1323 | // The LowerBound value defines the lower bounds which is typically zero for |
| 1324 | // C/C++. The Count value is the number of elements. Values are 64 bit. If |
| 1325 | // Count == -1 then the array is unbounded and we do not emit |
| 1326 | // DW_AT_lower_bound and DW_AT_upper_bound attributes. If LowerBound == 0 and |
| 1327 | // Count == 0, then the array has zero elements in which case we do not emit |
| 1328 | // an upper bound. |
| 1329 | int64_t LowerBound = SR.getLo(); |
Bill Wendling | 6afe478 | 2012-12-06 07:55:19 +0000 | [diff] [blame] | 1330 | int64_t DefaultLowerBound = getDefaultLowerBound(); |
Bill Wendling | 9493dae | 2012-12-04 21:34:03 +0000 | [diff] [blame] | 1331 | int64_t Count = SR.getCount(); |
Devang Patel | 161b2f4 | 2011-04-12 23:21:44 +0000 | [diff] [blame] | 1332 | |
Bill Wendling | 6afe478 | 2012-12-06 07:55:19 +0000 | [diff] [blame] | 1333 | if (DefaultLowerBound == -1 || LowerBound != DefaultLowerBound) |
Bill Wendling | 222c2fd | 2012-12-06 07:38:10 +0000 | [diff] [blame] | 1334 | addUInt(DW_Subrange, dwarf::DW_AT_lower_bound, 0, LowerBound); |
| 1335 | |
| 1336 | if (Count != -1 && Count != 0) |
Bill Wendling | 9493dae | 2012-12-04 21:34:03 +0000 | [diff] [blame] | 1337 | // FIXME: An unbounded array should reference the expression that defines |
| 1338 | // the array. |
Bill Wendling | 222c2fd | 2012-12-06 07:38:10 +0000 | [diff] [blame] | 1339 | addUInt(DW_Subrange, dwarf::DW_AT_upper_bound, 0, LowerBound + Count - 1); |
Bill Wendling | 9493dae | 2012-12-04 21:34:03 +0000 | [diff] [blame] | 1340 | |
Devang Patel | 161b2f4 | 2011-04-12 23:21:44 +0000 | [diff] [blame] | 1341 | Buffer.addChild(DW_Subrange); |
| 1342 | } |
| 1343 | |
| 1344 | /// constructArrayTypeDIE - Construct array type DIE from DICompositeType. |
| 1345 | void CompileUnit::constructArrayTypeDIE(DIE &Buffer, |
| 1346 | DICompositeType *CTy) { |
| 1347 | Buffer.setTag(dwarf::DW_TAG_array_type); |
| 1348 | if (CTy->getTag() == dwarf::DW_TAG_vector_type) |
Eric Christopher | 873cf0a | 2012-08-24 01:14:27 +0000 | [diff] [blame] | 1349 | addFlag(&Buffer, dwarf::DW_AT_GNU_vector); |
Devang Patel | 161b2f4 | 2011-04-12 23:21:44 +0000 | [diff] [blame] | 1350 | |
| 1351 | // Emit derived type. |
| 1352 | addType(&Buffer, CTy->getTypeDerivedFrom()); |
| 1353 | DIArray Elements = CTy->getTypeArray(); |
| 1354 | |
| 1355 | // Get an anonymous type for index type. |
Eric Christopher | 8cab6ed | 2013-01-04 21:51:53 +0000 | [diff] [blame] | 1356 | // FIXME: This type should be passed down from the front end |
| 1357 | // as different languages may have different sizes for indexes. |
Devang Patel | 161b2f4 | 2011-04-12 23:21:44 +0000 | [diff] [blame] | 1358 | DIE *IdxTy = getIndexTyDie(); |
| 1359 | if (!IdxTy) { |
| 1360 | // Construct an anonymous type for index type. |
| 1361 | IdxTy = new DIE(dwarf::DW_TAG_base_type); |
Eric Christopher | 8cab6ed | 2013-01-04 21:51:53 +0000 | [diff] [blame] | 1362 | addString(IdxTy, dwarf::DW_AT_name, "int"); |
Devang Patel | 161b2f4 | 2011-04-12 23:21:44 +0000 | [diff] [blame] | 1363 | addUInt(IdxTy, dwarf::DW_AT_byte_size, 0, sizeof(int32_t)); |
| 1364 | addUInt(IdxTy, dwarf::DW_AT_encoding, dwarf::DW_FORM_data1, |
| 1365 | dwarf::DW_ATE_signed); |
| 1366 | addDie(IdxTy); |
| 1367 | setIndexTyDie(IdxTy); |
| 1368 | } |
| 1369 | |
| 1370 | // Add subranges to array type. |
| 1371 | for (unsigned i = 0, N = Elements.getNumElements(); i < N; ++i) { |
| 1372 | DIDescriptor Element = Elements.getElement(i); |
| 1373 | if (Element.getTag() == dwarf::DW_TAG_subrange_type) |
| 1374 | constructSubrangeDIE(Buffer, DISubrange(Element), IdxTy); |
| 1375 | } |
| 1376 | } |
| 1377 | |
| 1378 | /// constructEnumTypeDIE - Construct enum type DIE from DIEnumerator. |
| 1379 | DIE *CompileUnit::constructEnumTypeDIE(DIEnumerator ETy) { |
| 1380 | DIE *Enumerator = new DIE(dwarf::DW_TAG_enumerator); |
| 1381 | StringRef Name = ETy.getName(); |
Nick Lewycky | 390c40d | 2011-10-27 06:44:11 +0000 | [diff] [blame] | 1382 | addString(Enumerator, dwarf::DW_AT_name, Name); |
Devang Patel | 161b2f4 | 2011-04-12 23:21:44 +0000 | [diff] [blame] | 1383 | int64_t Value = ETy.getEnumValue(); |
| 1384 | addSInt(Enumerator, dwarf::DW_AT_const_value, dwarf::DW_FORM_sdata, Value); |
| 1385 | return Enumerator; |
| 1386 | } |
| 1387 | |
Devang Patel | dbc64af | 2011-08-15 17:24:54 +0000 | [diff] [blame] | 1388 | /// constructContainingTypeDIEs - Construct DIEs for types that contain |
| 1389 | /// vtables. |
| 1390 | void CompileUnit::constructContainingTypeDIEs() { |
| 1391 | for (DenseMap<DIE *, const MDNode *>::iterator CI = ContainingTypeMap.begin(), |
| 1392 | CE = ContainingTypeMap.end(); CI != CE; ++CI) { |
| 1393 | DIE *SPDie = CI->first; |
| 1394 | const MDNode *N = CI->second; |
| 1395 | if (!N) continue; |
| 1396 | DIE *NDie = getDIE(N); |
| 1397 | if (!NDie) continue; |
| 1398 | addDIEEntry(SPDie, dwarf::DW_AT_containing_type, dwarf::DW_FORM_ref4, NDie); |
| 1399 | } |
| 1400 | } |
| 1401 | |
Devang Patel | d0b5a5e | 2011-08-15 22:04:40 +0000 | [diff] [blame] | 1402 | /// constructVariableDIE - Construct a DIE for the given DbgVariable. |
| 1403 | DIE *CompileUnit::constructVariableDIE(DbgVariable *DV, bool isScopeAbstract) { |
| 1404 | StringRef Name = DV->getName(); |
Devang Patel | d0b5a5e | 2011-08-15 22:04:40 +0000 | [diff] [blame] | 1405 | |
| 1406 | // Translate tag to proper Dwarf tag. |
| 1407 | unsigned Tag = DV->getTag(); |
| 1408 | |
| 1409 | // Define variable debug information entry. |
| 1410 | DIE *VariableDie = new DIE(Tag); |
| 1411 | DbgVariable *AbsVar = DV->getAbstractVariable(); |
| 1412 | DIE *AbsDIE = AbsVar ? AbsVar->getDIE() : NULL; |
| 1413 | if (AbsDIE) |
| 1414 | addDIEEntry(VariableDie, dwarf::DW_AT_abstract_origin, |
| 1415 | dwarf::DW_FORM_ref4, AbsDIE); |
| 1416 | else { |
Nick Lewycky | 390c40d | 2011-10-27 06:44:11 +0000 | [diff] [blame] | 1417 | addString(VariableDie, dwarf::DW_AT_name, Name); |
Devang Patel | d0b5a5e | 2011-08-15 22:04:40 +0000 | [diff] [blame] | 1418 | addSourceLine(VariableDie, DV->getVariable()); |
| 1419 | addType(VariableDie, DV->getType()); |
| 1420 | } |
| 1421 | |
| 1422 | if (DV->isArtificial()) |
Eric Christopher | 873cf0a | 2012-08-24 01:14:27 +0000 | [diff] [blame] | 1423 | addFlag(VariableDie, dwarf::DW_AT_artificial); |
Devang Patel | d0b5a5e | 2011-08-15 22:04:40 +0000 | [diff] [blame] | 1424 | |
| 1425 | if (isScopeAbstract) { |
| 1426 | DV->setDIE(VariableDie); |
| 1427 | return VariableDie; |
| 1428 | } |
| 1429 | |
| 1430 | // Add variable address. |
| 1431 | |
| 1432 | unsigned Offset = DV->getDotDebugLocOffset(); |
| 1433 | if (Offset != ~0U) { |
| 1434 | addLabel(VariableDie, dwarf::DW_AT_location, |
| 1435 | dwarf::DW_FORM_data4, |
| 1436 | Asm->GetTempSymbol("debug_loc", Offset)); |
| 1437 | DV->setDIE(VariableDie); |
| 1438 | return VariableDie; |
| 1439 | } |
| 1440 | |
Eric Christopher | 8cf5e74 | 2011-10-03 15:49:20 +0000 | [diff] [blame] | 1441 | // Check if variable is described by a DBG_VALUE instruction. |
Devang Patel | d0b5a5e | 2011-08-15 22:04:40 +0000 | [diff] [blame] | 1442 | if (const MachineInstr *DVInsn = DV->getMInsn()) { |
| 1443 | bool updated = false; |
| 1444 | if (DVInsn->getNumOperands() == 3) { |
| 1445 | if (DVInsn->getOperand(0).isReg()) { |
| 1446 | const MachineOperand RegOp = DVInsn->getOperand(0); |
| 1447 | const TargetRegisterInfo *TRI = Asm->TM.getRegisterInfo(); |
| 1448 | if (DVInsn->getOperand(1).isImm() && |
| 1449 | TRI->getFrameRegister(*Asm->MF) == RegOp.getReg()) { |
| 1450 | unsigned FrameReg = 0; |
| 1451 | const TargetFrameLowering *TFI = Asm->TM.getFrameLowering(); |
Eric Christopher | 8b4310b | 2012-11-21 00:34:38 +0000 | [diff] [blame] | 1452 | int Offset = |
| 1453 | TFI->getFrameIndexReference(*Asm->MF, |
| 1454 | DVInsn->getOperand(1).getImm(), |
Devang Patel | d0b5a5e | 2011-08-15 22:04:40 +0000 | [diff] [blame] | 1455 | FrameReg); |
| 1456 | MachineLocation Location(FrameReg, Offset); |
| 1457 | addVariableAddress(DV, VariableDie, Location); |
Eric Christopher | 8b4310b | 2012-11-21 00:34:38 +0000 | [diff] [blame] | 1458 | |
Devang Patel | d0b5a5e | 2011-08-15 22:04:40 +0000 | [diff] [blame] | 1459 | } else if (RegOp.getReg()) |
Eric Christopher | 8b4310b | 2012-11-21 00:34:38 +0000 | [diff] [blame] | 1460 | addVariableAddress(DV, VariableDie, |
Devang Patel | d0b5a5e | 2011-08-15 22:04:40 +0000 | [diff] [blame] | 1461 | MachineLocation(RegOp.getReg())); |
| 1462 | updated = true; |
| 1463 | } |
| 1464 | else if (DVInsn->getOperand(0).isImm()) |
Eric Christopher | 8b4310b | 2012-11-21 00:34:38 +0000 | [diff] [blame] | 1465 | updated = |
Devang Patel | d0b5a5e | 2011-08-15 22:04:40 +0000 | [diff] [blame] | 1466 | addConstantValue(VariableDie, DVInsn->getOperand(0), |
| 1467 | DV->getType()); |
| 1468 | else if (DVInsn->getOperand(0).isFPImm()) |
| 1469 | updated = |
| 1470 | addConstantFPValue(VariableDie, DVInsn->getOperand(0)); |
| 1471 | else if (DVInsn->getOperand(0).isCImm()) |
| 1472 | updated = |
Eric Christopher | 8b4310b | 2012-11-21 00:34:38 +0000 | [diff] [blame] | 1473 | addConstantValue(VariableDie, |
Devang Patel | d0b5a5e | 2011-08-15 22:04:40 +0000 | [diff] [blame] | 1474 | DVInsn->getOperand(0).getCImm(), |
| 1475 | DV->getType().isUnsignedDIType()); |
| 1476 | } else { |
Eric Christopher | 8b4310b | 2012-11-21 00:34:38 +0000 | [diff] [blame] | 1477 | addVariableAddress(DV, VariableDie, |
Devang Patel | d0b5a5e | 2011-08-15 22:04:40 +0000 | [diff] [blame] | 1478 | Asm->getDebugValueLocation(DVInsn)); |
| 1479 | updated = true; |
| 1480 | } |
| 1481 | if (!updated) { |
| 1482 | // If variableDie is not updated then DBG_VALUE instruction does not |
| 1483 | // have valid variable info. |
| 1484 | delete VariableDie; |
| 1485 | return NULL; |
| 1486 | } |
| 1487 | DV->setDIE(VariableDie); |
| 1488 | return VariableDie; |
| 1489 | } else { |
| 1490 | // .. else use frame index. |
| 1491 | int FI = DV->getFrameIndex(); |
| 1492 | if (FI != ~0) { |
| 1493 | unsigned FrameReg = 0; |
| 1494 | const TargetFrameLowering *TFI = Asm->TM.getFrameLowering(); |
Eric Christopher | 8b4310b | 2012-11-21 00:34:38 +0000 | [diff] [blame] | 1495 | int Offset = |
Devang Patel | d0b5a5e | 2011-08-15 22:04:40 +0000 | [diff] [blame] | 1496 | TFI->getFrameIndexReference(*Asm->MF, FI, FrameReg); |
| 1497 | MachineLocation Location(FrameReg, Offset); |
| 1498 | addVariableAddress(DV, VariableDie, Location); |
| 1499 | } |
| 1500 | } |
| 1501 | |
| 1502 | DV->setDIE(VariableDie); |
| 1503 | return VariableDie; |
| 1504 | } |
| 1505 | |
Devang Patel | 161b2f4 | 2011-04-12 23:21:44 +0000 | [diff] [blame] | 1506 | /// createMemberDIE - Create new member DIE. |
| 1507 | DIE *CompileUnit::createMemberDIE(DIDerivedType DT) { |
| 1508 | DIE *MemberDie = new DIE(DT.getTag()); |
| 1509 | StringRef Name = DT.getName(); |
| 1510 | if (!Name.empty()) |
Nick Lewycky | 390c40d | 2011-10-27 06:44:11 +0000 | [diff] [blame] | 1511 | addString(MemberDie, dwarf::DW_AT_name, Name); |
Devang Patel | 161b2f4 | 2011-04-12 23:21:44 +0000 | [diff] [blame] | 1512 | |
| 1513 | addType(MemberDie, DT.getTypeDerivedFrom()); |
| 1514 | |
| 1515 | addSourceLine(MemberDie, DT); |
| 1516 | |
| 1517 | DIEBlock *MemLocationDie = new (DIEValueAllocator) DIEBlock(); |
| 1518 | addUInt(MemLocationDie, 0, dwarf::DW_FORM_data1, dwarf::DW_OP_plus_uconst); |
| 1519 | |
| 1520 | uint64_t Size = DT.getSizeInBits(); |
| 1521 | uint64_t FieldSize = DT.getOriginalTypeSize(); |
| 1522 | |
| 1523 | if (Size != FieldSize) { |
| 1524 | // Handle bitfield. |
| 1525 | addUInt(MemberDie, dwarf::DW_AT_byte_size, 0, DT.getOriginalTypeSize()>>3); |
| 1526 | addUInt(MemberDie, dwarf::DW_AT_bit_size, 0, DT.getSizeInBits()); |
| 1527 | |
| 1528 | uint64_t Offset = DT.getOffsetInBits(); |
| 1529 | uint64_t AlignMask = ~(DT.getAlignInBits() - 1); |
| 1530 | uint64_t HiMark = (Offset + FieldSize) & AlignMask; |
| 1531 | uint64_t FieldOffset = (HiMark - FieldSize); |
| 1532 | Offset -= FieldOffset; |
| 1533 | |
| 1534 | // Maybe we need to work from the other end. |
Micah Villmow | 3574eca | 2012-10-08 16:38:25 +0000 | [diff] [blame] | 1535 | if (Asm->getDataLayout().isLittleEndian()) |
Devang Patel | 161b2f4 | 2011-04-12 23:21:44 +0000 | [diff] [blame] | 1536 | Offset = FieldSize - (Offset + Size); |
| 1537 | addUInt(MemberDie, dwarf::DW_AT_bit_offset, 0, Offset); |
| 1538 | |
| 1539 | // Here WD_AT_data_member_location points to the anonymous |
| 1540 | // field that includes this bit field. |
| 1541 | addUInt(MemLocationDie, 0, dwarf::DW_FORM_udata, FieldOffset >> 3); |
| 1542 | |
| 1543 | } else |
| 1544 | // This is not a bitfield. |
| 1545 | addUInt(MemLocationDie, 0, dwarf::DW_FORM_udata, DT.getOffsetInBits() >> 3); |
| 1546 | |
| 1547 | if (DT.getTag() == dwarf::DW_TAG_inheritance |
| 1548 | && DT.isVirtual()) { |
| 1549 | |
| 1550 | // For C++, virtual base classes are not at fixed offset. Use following |
| 1551 | // expression to extract appropriate offset from vtable. |
| 1552 | // BaseAddr = ObAddr + *((*ObAddr) - Offset) |
| 1553 | |
| 1554 | DIEBlock *VBaseLocationDie = new (DIEValueAllocator) DIEBlock(); |
| 1555 | addUInt(VBaseLocationDie, 0, dwarf::DW_FORM_data1, dwarf::DW_OP_dup); |
| 1556 | addUInt(VBaseLocationDie, 0, dwarf::DW_FORM_data1, dwarf::DW_OP_deref); |
| 1557 | addUInt(VBaseLocationDie, 0, dwarf::DW_FORM_data1, dwarf::DW_OP_constu); |
| 1558 | addUInt(VBaseLocationDie, 0, dwarf::DW_FORM_udata, DT.getOffsetInBits()); |
| 1559 | addUInt(VBaseLocationDie, 0, dwarf::DW_FORM_data1, dwarf::DW_OP_minus); |
| 1560 | addUInt(VBaseLocationDie, 0, dwarf::DW_FORM_data1, dwarf::DW_OP_deref); |
| 1561 | addUInt(VBaseLocationDie, 0, dwarf::DW_FORM_data1, dwarf::DW_OP_plus); |
| 1562 | |
| 1563 | addBlock(MemberDie, dwarf::DW_AT_data_member_location, 0, |
| 1564 | VBaseLocationDie); |
| 1565 | } else |
| 1566 | addBlock(MemberDie, dwarf::DW_AT_data_member_location, 0, MemLocationDie); |
| 1567 | |
| 1568 | if (DT.isProtected()) |
Nick Lewycky | 13aaca5 | 2011-12-13 05:09:11 +0000 | [diff] [blame] | 1569 | addUInt(MemberDie, dwarf::DW_AT_accessibility, dwarf::DW_FORM_data1, |
Devang Patel | 161b2f4 | 2011-04-12 23:21:44 +0000 | [diff] [blame] | 1570 | dwarf::DW_ACCESS_protected); |
| 1571 | else if (DT.isPrivate()) |
Nick Lewycky | 13aaca5 | 2011-12-13 05:09:11 +0000 | [diff] [blame] | 1572 | addUInt(MemberDie, dwarf::DW_AT_accessibility, dwarf::DW_FORM_data1, |
Devang Patel | 161b2f4 | 2011-04-12 23:21:44 +0000 | [diff] [blame] | 1573 | dwarf::DW_ACCESS_private); |
| 1574 | // Otherwise C++ member and base classes are considered public. |
Eric Christopher | 8b4310b | 2012-11-21 00:34:38 +0000 | [diff] [blame] | 1575 | else |
Nick Lewycky | 13aaca5 | 2011-12-13 05:09:11 +0000 | [diff] [blame] | 1576 | addUInt(MemberDie, dwarf::DW_AT_accessibility, dwarf::DW_FORM_data1, |
Devang Patel | 161b2f4 | 2011-04-12 23:21:44 +0000 | [diff] [blame] | 1577 | dwarf::DW_ACCESS_public); |
| 1578 | if (DT.isVirtual()) |
Nick Lewycky | 798313d | 2011-12-14 00:56:07 +0000 | [diff] [blame] | 1579 | addUInt(MemberDie, dwarf::DW_AT_virtuality, dwarf::DW_FORM_data1, |
Devang Patel | 161b2f4 | 2011-04-12 23:21:44 +0000 | [diff] [blame] | 1580 | dwarf::DW_VIRTUALITY_virtual); |
Devang Patel | e9db5e2 | 2011-04-16 00:11:51 +0000 | [diff] [blame] | 1581 | |
| 1582 | // Objective-C properties. |
Devang Patel | 6588abf | 2012-02-06 17:49:43 +0000 | [diff] [blame] | 1583 | if (MDNode *PNode = DT.getObjCProperty()) |
| 1584 | if (DIEEntry *PropertyDie = getDIEEntry(PNode)) |
Eric Christopher | 8b4310b | 2012-11-21 00:34:38 +0000 | [diff] [blame] | 1585 | MemberDie->addValue(dwarf::DW_AT_APPLE_property, dwarf::DW_FORM_ref4, |
Devang Patel | 6588abf | 2012-02-06 17:49:43 +0000 | [diff] [blame] | 1586 | PropertyDie); |
| 1587 | |
David Blaikie | 01bc2b3 | 2012-12-13 22:43:07 +0000 | [diff] [blame] | 1588 | if (DT.isArtificial()) |
| 1589 | addFlag(MemberDie, dwarf::DW_AT_artificial); |
| 1590 | |
Devang Patel | 9e11eb1 | 2012-02-04 01:30:32 +0000 | [diff] [blame] | 1591 | // This is only for backward compatibility. |
Devang Patel | e9db5e2 | 2011-04-16 00:11:51 +0000 | [diff] [blame] | 1592 | StringRef PropertyName = DT.getObjCPropertyName(); |
| 1593 | if (!PropertyName.empty()) { |
Nick Lewycky | 390c40d | 2011-10-27 06:44:11 +0000 | [diff] [blame] | 1594 | addString(MemberDie, dwarf::DW_AT_APPLE_property_name, PropertyName); |
Devang Patel | e9db5e2 | 2011-04-16 00:11:51 +0000 | [diff] [blame] | 1595 | StringRef GetterName = DT.getObjCPropertyGetterName(); |
| 1596 | if (!GetterName.empty()) |
Nick Lewycky | 390c40d | 2011-10-27 06:44:11 +0000 | [diff] [blame] | 1597 | addString(MemberDie, dwarf::DW_AT_APPLE_property_getter, GetterName); |
Devang Patel | e9db5e2 | 2011-04-16 00:11:51 +0000 | [diff] [blame] | 1598 | StringRef SetterName = DT.getObjCPropertySetterName(); |
| 1599 | if (!SetterName.empty()) |
Nick Lewycky | 390c40d | 2011-10-27 06:44:11 +0000 | [diff] [blame] | 1600 | addString(MemberDie, dwarf::DW_AT_APPLE_property_setter, SetterName); |
Devang Patel | e9db5e2 | 2011-04-16 00:11:51 +0000 | [diff] [blame] | 1601 | unsigned PropertyAttributes = 0; |
| 1602 | if (DT.isReadOnlyObjCProperty()) |
| 1603 | PropertyAttributes |= dwarf::DW_APPLE_PROPERTY_readonly; |
| 1604 | if (DT.isReadWriteObjCProperty()) |
| 1605 | PropertyAttributes |= dwarf::DW_APPLE_PROPERTY_readwrite; |
| 1606 | if (DT.isAssignObjCProperty()) |
| 1607 | PropertyAttributes |= dwarf::DW_APPLE_PROPERTY_assign; |
| 1608 | if (DT.isRetainObjCProperty()) |
| 1609 | PropertyAttributes |= dwarf::DW_APPLE_PROPERTY_retain; |
| 1610 | if (DT.isCopyObjCProperty()) |
| 1611 | PropertyAttributes |= dwarf::DW_APPLE_PROPERTY_copy; |
| 1612 | if (DT.isNonAtomicObjCProperty()) |
| 1613 | PropertyAttributes |= dwarf::DW_APPLE_PROPERTY_nonatomic; |
| 1614 | if (PropertyAttributes) |
Eric Christopher | 8b4310b | 2012-11-21 00:34:38 +0000 | [diff] [blame] | 1615 | addUInt(MemberDie, dwarf::DW_AT_APPLE_property_attribute, 0, |
Devang Patel | e9db5e2 | 2011-04-16 00:11:51 +0000 | [diff] [blame] | 1616 | PropertyAttributes); |
| 1617 | } |
Devang Patel | 161b2f4 | 2011-04-12 23:21:44 +0000 | [diff] [blame] | 1618 | return MemberDie; |
| 1619 | } |