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