llvm.org GIT mirror llvm / 172515f
DIEEntry: Refer to the specified DIE via reference rather than pointer. Makes some more cases (the unit tests, specifically), lexically compatible with a change to unique_ptr. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@207261 91177308-0d34-0410-b5e6-96231b3b80d8 David Blaikie 6 years ago
7 changed file(s) with 62 addition(s) and 63 deletion(s). Raw diff Collapse all Expand all
375375
376376 if (Form == dwarf::DW_FORM_ref_addr) {
377377 const DwarfDebug *DD = AP->getDwarfDebug();
378 unsigned Addr = Entry->getOffset();
378 unsigned Addr = Entry.getOffset();
379379 assert(!DD->useSplitDwarf() && "TODO: dwo files can't have relocations.");
380380 // For DW_FORM_ref_addr, output the offset from beginning of debug info
381381 // section. Entry->getOffset() returns the offset from start of the
382382 // compile unit.
383 DwarfCompileUnit *CU = DD->lookupUnit(Entry->getUnit());
383 DwarfCompileUnit *CU = DD->lookupUnit(Entry.getUnit());
384384 assert(CU && "CUDie should belong to a CU.");
385385 Addr += CU->getDebugInfoOffset();
386386 if (AP->MAI->doesDwarfUseRelocationsAcrossSections())
391391 CU->getSectionSym(),
392392 DIEEntry::getRefAddrSize(AP));
393393 } else
394 AP->EmitInt32(Entry->getOffset());
394 AP->EmitInt32(Entry.getOffset());
395395 }
396396
397397 unsigned DIEEntry::getRefAddrSize(AsmPrinter *AP) {
408408
409409 #ifndef NDEBUG
410410 void DIEEntry::print(raw_ostream &O) const {
411 O << format("Die: 0x%lx", (long)(intptr_t)Entry);
411 O << format("Die: 0x%lx", (long)(intptr_t)&Entry);
412412 }
413413 #endif
414414
404404 /// this class can also be used as a proxy for a debug information entry not
405405 /// yet defined (ie. types.)
406406 class DIEEntry : public DIEValue {
407 DIE *const Entry;
408
409 public:
410 explicit DIEEntry(DIE *E) : DIEValue(isEntry), Entry(E) {
411 assert(E && "Cannot construct a DIEEntry with a null DIE");
412 }
413
414 DIE *getEntry() const { return Entry; }
407 DIE &Entry;
408
409 public:
410 explicit DIEEntry(DIE &E) : DIEValue(isEntry), Entry(E) {
411 }
412
413 DIE &getEntry() const { return Entry; }
415414
416415 /// EmitValue - Emit debug information entry offset.
417416 ///
308308 // ... An attribute that refers to another type entry T is processed as
309309 // follows:
310310 case DIEValue::isEntry:
311 hashDIEEntry(Attribute, Tag, *cast(Value)->getEntry());
311 hashDIEEntry(Attribute, Tag, cast(Value)->getEntry());
312312 break;
313313 case DIEValue::isInteger: {
314314 addULEB128('A');
322322 if (DIE *AbsSPDIE = AbstractSPDies.lookup(SP)) {
323323 // Pick up abstract subprogram DIE.
324324 SPDie = &SPCU.createAndAddDIE(dwarf::DW_TAG_subprogram, SPCU.getUnitDie());
325 SPCU.addDIEEntry(*SPDie, dwarf::DW_AT_abstract_origin, AbsSPDIE);
325 SPCU.addDIEEntry(*SPDie, dwarf::DW_AT_abstract_origin, *AbsSPDIE);
326326 } else {
327327 DISubprogram SPDecl = SP.getFunctionDeclaration();
328328 if (!SPDecl.isSubprogram()) {
345345 DIE *SPDeclDie = SPDie;
346346 SPDie =
347347 &SPCU.createAndAddDIE(dwarf::DW_TAG_subprogram, SPCU.getUnitDie());
348 SPCU.addDIEEntry(*SPDie, dwarf::DW_AT_specification, SPDeclDie);
348 SPCU.addDIEEntry(*SPDie, dwarf::DW_AT_specification, *SPDeclDie);
349349 }
350350 }
351351 }
470470 }
471471
472472 DIE *ScopeDIE = new DIE(dwarf::DW_TAG_inlined_subroutine);
473 TheCU.addDIEEntry(*ScopeDIE, dwarf::DW_AT_abstract_origin, OriginDIE);
473 TheCU.addDIEEntry(*ScopeDIE, dwarf::DW_AT_abstract_origin, *OriginDIE);
474474
475475 // If we have multiple ranges, emit them into the range section.
476476 if (ScopeRanges.size() > 1)
613613 ScopeDIE->addChild(I);
614614
615615 if (DS.isSubprogram() && ObjectPointer != nullptr)
616 TheCU.addDIEEntry(*ScopeDIE, dwarf::DW_AT_object_pointer, ObjectPointer);
616 TheCU.addDIEEntry(*ScopeDIE, dwarf::DW_AT_object_pointer, *ObjectPointer);
617617
618618 return ScopeDIE;
619619 }
747747 TheCU.addSourceLine(IMDie, Module.getLineNumber(),
748748 Module.getContext().getFilename(),
749749 Module.getContext().getDirectory());
750 TheCU.addDIEEntry(IMDie, dwarf::DW_AT_import, EntityDie);
750 TheCU.addDIEEntry(IMDie, dwarf::DW_AT_import, *EntityDie);
751751 StringRef Name = Module.getName();
752752 if (!Name.empty())
753753 TheCU.addString(IMDie, dwarf::DW_AT_name, Name);
19381938 // look for that now.
19391939 DIEValue *SpecVal = Die->findAttribute(dwarf::DW_AT_specification);
19401940 if (SpecVal) {
1941 DIE *SpecDIE = cast(SpecVal)->getEntry();
1942 if (SpecDIE->findAttribute(dwarf::DW_AT_external))
1941 DIE &SpecDIE = cast(SpecVal)->getEntry();
1942 if (SpecDIE.findAttribute(dwarf::DW_AT_external))
19431943 Linkage = dwarf::GIEL_EXTERNAL;
19441944 } else if (Die->findAttribute(dwarf::DW_AT_external))
19451945 Linkage = dwarf::GIEL_EXTERNAL;
7474
7575 /// createDIEEntry - Creates a new DIEEntry to be a proxy for a debug
7676 /// information entry.
77 DIEEntry *DwarfUnit::createDIEEntry(DIE *Entry) {
77 DIEEntry *DwarfUnit::createDIEEntry(DIE &Entry) {
7878 DIEEntry *Value = new (DIEValueAllocator) DIEEntry(Entry);
7979 return Value;
8080 }
354354
355355 /// addDIEEntry - Add a DIE attribute data and value.
356356 ///
357 void DwarfUnit::addDIEEntry(DIE &Die, dwarf::Attribute Attribute, DIE *Entry) {
357 void DwarfUnit::addDIEEntry(DIE &Die, dwarf::Attribute Attribute, DIE &Entry) {
358358 addDIEEntry(Die, Attribute, createDIEEntry(Entry));
359359 }
360360
366366 void DwarfUnit::addDIEEntry(DIE &Die, dwarf::Attribute Attribute,
367367 DIEEntry *Entry) {
368368 const DIE *DieCU = Die.getUnitOrNull();
369 const DIE *EntryCU = Entry->getEntry()->getUnitOrNull();
369 const DIE *EntryCU = Entry->getEntry().getUnitOrNull();
370370 if (!DieCU)
371371 // We assume that Die belongs to this CU, if it is not linked to any CU yet.
372372 DieCU = &getUnitDie();
10541054 DIE *Buffer = getOrCreateTypeDIE(Ty);
10551055
10561056 // Set up proxy.
1057 Entry = createDIEEntry(Buffer);
1057 Entry = createDIEEntry(*Buffer);
10581058 insertDIEEntry(Ty, Entry);
10591059 addDIEEntry(Entity, Attribute, Entry);
10601060 }
11481148
11491149 if (Tag == dwarf::DW_TAG_ptr_to_member_type)
11501150 addDIEEntry(Buffer, dwarf::DW_AT_containing_type,
1151 getOrCreateTypeDIE(resolve(DTy.getClassType())));
1151 *getOrCreateTypeDIE(resolve(DTy.getClassType())));
11521152 // Add source line info if available and TyDesc is not a forward declaration.
11531153 if (!DTy.isForwardDecl())
11541154 addSourceLine(Buffer, DTy);
12661266
12671267 DIEEntry *Entry = getDIEEntry(Element);
12681268 if (!Entry) {
1269 Entry = createDIEEntry(&ElemDie);
1269 Entry = createDIEEntry(ElemDie);
12701270 insertDIEEntry(Element, Entry);
12711271 }
12721272 } else
12791279 DICompositeType ContainingType(resolve(CTy.getContainingType()));
12801280 if (ContainingType)
12811281 addDIEEntry(Buffer, dwarf::DW_AT_containing_type,
1282 getOrCreateTypeDIE(ContainingType));
1282 *getOrCreateTypeDIE(ContainingType));
12831283
12841284 if (CTy.isObjcClassComplete())
12851285 addFlag(Buffer, dwarf::DW_AT_APPLE_objc_complete_type);
14301430
14311431 if (DeclDie)
14321432 // Refer function declaration directly.
1433 addDIEEntry(SPDie, dwarf::DW_AT_specification, DeclDie);
1433 addDIEEntry(SPDie, dwarf::DW_AT_specification, *DeclDie);
14341434
14351435 // Add the linkage name if we have one and it isn't in the Decl.
14361436 StringRef LinkageName = SP.getLinkageName();
16371637 !GVContext.isFile() && !DD->isSubprogramContext(GVContext)) {
16381638 // Create specification DIE.
16391639 VariableSpecDIE = &createAndAddDIE(dwarf::DW_TAG_variable, *UnitDie);
1640 addDIEEntry(*VariableSpecDIE, dwarf::DW_AT_specification, VariableDIE);
1640 addDIEEntry(*VariableSpecDIE, dwarf::DW_AT_specification, *VariableDIE);
16411641 addBlock(*VariableSpecDIE, dwarf::DW_AT_location, Loc);
16421642 // A static member's declaration is already flagged as such.
16431643 if (!SDMDecl.Verify())
16981698 /// constructSubrangeDIE - Construct subrange DIE from DISubrange.
16991699 void DwarfUnit::constructSubrangeDIE(DIE &Buffer, DISubrange SR, DIE *IndexTy) {
17001700 DIE &DW_Subrange = createAndAddDIE(dwarf::DW_TAG_subrange_type, Buffer);
1701 addDIEEntry(DW_Subrange, dwarf::DW_AT_type, IndexTy);
1701 addDIEEntry(DW_Subrange, dwarf::DW_AT_type, *IndexTy);
17021702
17031703 // The LowerBound value defines the lower bounds which is typically zero for
17041704 // C/C++. The Count value is the number of elements. Values are 64 bit. If
17871787 DIE *NDie = getDIE(D);
17881788 if (!NDie)
17891789 continue;
1790 addDIEEntry(SPDie, dwarf::DW_AT_containing_type, NDie);
1790 addDIEEntry(SPDie, dwarf::DW_AT_containing_type, *NDie);
17911791 }
17921792 }
17931793
18071807 DbgVariable *AbsVar = DV.getAbstractVariable();
18081808 DIE *AbsDIE = AbsVar ? AbsVar->getDIE() : nullptr;
18091809 if (AbsDIE)
1810 addDIEEntry(*VariableDie, dwarf::DW_AT_abstract_origin, AbsDIE);
1810 addDIEEntry(*VariableDie, dwarf::DW_AT_abstract_origin, *AbsDIE);
18111811 else {
18121812 if (!Name.empty())
18131813 addString(*VariableDie, dwarf::DW_AT_name, Name);
327327 const MCSymbol *Lo);
328328
329329 /// addDIEEntry - Add a DIE attribute data and value.
330 void addDIEEntry(DIE &Die, dwarf::Attribute Attribute, DIE *Entry);
330 void addDIEEntry(DIE &Die, dwarf::Attribute Attribute, DIE &Entry);
331331
332332 /// addDIEEntry - Add a DIE attribute data and value.
333333 void addDIEEntry(DIE &Die, dwarf::Attribute Attribute, DIEEntry *Entry);
515515
516516 /// createDIEEntry - Creates a new DIEEntry to be a proxy for a debug
517517 /// information entry.
518 DIEEntry *createDIEEntry(DIE *Entry);
518 DIEEntry *createDIEEntry(DIE &Entry);
519519
520520 /// resolve - Look in the DwarfDebug map for the MDNode that
521521 /// corresponds to the reference.
102102 DIEInteger Five(5);
103103 Int.addValue(dwarf::DW_AT_encoding, dwarf::DW_FORM_data1, &Five);
104104
105 DIEEntry IntRef(&Int);
105 DIEEntry IntRef(Int);
106106 Member->addValue(dwarf::DW_AT_type, dwarf::DW_FORM_ref4, &IntRef);
107107
108108 uint64_t MD5Res = DIEHash().computeTypeSignature(Unnamed);
141141 DIEInteger Five(5);
142142 Int.addValue(dwarf::DW_AT_encoding, dwarf::DW_FORM_data1, &Five);
143143
144 DIEEntry IntRef(&Int);
144 DIEEntry IntRef(Int);
145145 Mem1->addValue(dwarf::DW_AT_type, dwarf::DW_FORM_ref4, &IntRef);
146146 Mem2->addValue(dwarf::DW_AT_type, dwarf::DW_FORM_ref4, &IntRef);
147147
161161 DIE *Mem = new DIE(dwarf::DW_TAG_member);
162162 DIEString MemStr(&One, "mem");
163163 Mem->addValue(dwarf::DW_AT_name, dwarf::DW_FORM_strp, &MemStr);
164 DIEEntry FooRef(&Foo);
164 DIEEntry FooRef(Foo);
165165 Mem->addValue(dwarf::DW_AT_type, dwarf::DW_FORM_ref4, &FooRef);
166166 // DW_AT_external and DW_AT_declaration are ignored anyway, so skip them.
167167
188188
189189 DIE FooPtr(dwarf::DW_TAG_pointer_type);
190190 FooPtr.addValue(dwarf::DW_AT_byte_size, dwarf::DW_FORM_data1, &Eight);
191 DIEEntry FooRef(&Foo);
191 DIEEntry FooRef(Foo);
192192 FooPtr.addValue(dwarf::DW_AT_type, dwarf::DW_FORM_ref4, &FooRef);
193193
194 DIEEntry FooPtrRef(&FooPtr);
194 DIEEntry FooPtrRef(FooPtr);
195195 Mem->addValue(dwarf::DW_AT_type, dwarf::DW_FORM_ref4, &FooPtrRef);
196196
197197 Foo.addChild(Mem);
217217
218218 DIE FooRef(dwarf::DW_TAG_reference_type);
219219 FooRef.addValue(dwarf::DW_AT_byte_size, dwarf::DW_FORM_data1, &Eight);
220 DIEEntry FooEntry(&Foo);
220 DIEEntry FooEntry(Foo);
221221 FooRef.addValue(dwarf::DW_AT_type, dwarf::DW_FORM_ref4, &FooEntry);
222222
223223 DIE FooRefConst(dwarf::DW_TAG_const_type);
224 DIEEntry FooRefRef(&FooRef);
224 DIEEntry FooRefRef(FooRef);
225225 FooRefConst.addValue(dwarf::DW_AT_type, dwarf::DW_FORM_ref4, &FooRefRef);
226226
227 DIEEntry FooRefConstRef(&FooRefConst);
227 DIEEntry FooRefConstRef(FooRefConst);
228228 Mem->addValue(dwarf::DW_AT_type, dwarf::DW_FORM_ref4, &FooRefConstRef);
229229
230230 Foo.addChild(Mem);
250250
251251 DIE FooRef(dwarf::DW_TAG_rvalue_reference_type);
252252 FooRef.addValue(dwarf::DW_AT_byte_size, dwarf::DW_FORM_data1, &Eight);
253 DIEEntry FooEntry(&Foo);
253 DIEEntry FooEntry(Foo);
254254 FooRef.addValue(dwarf::DW_AT_type, dwarf::DW_FORM_ref4, &FooEntry);
255255
256256 DIE FooRefConst(dwarf::DW_TAG_const_type);
257 DIEEntry FooRefRef(&FooRef);
257 DIEEntry FooRefRef(FooRef);
258258 FooRefConst.addValue(dwarf::DW_AT_type, dwarf::DW_FORM_ref4, &FooRefRef);
259259
260 DIEEntry FooRefConstRef(&FooRefConst);
260 DIEEntry FooRefConstRef(FooRefConst);
261261 Mem->addValue(dwarf::DW_AT_type, dwarf::DW_FORM_ref4, &FooRefConstRef);
262262
263263 Foo.addChild(Mem);
282282 Mem->addValue(dwarf::DW_AT_data_member_location, dwarf::DW_FORM_data1, &Zero);
283283
284284 DIE PtrToFooMem(dwarf::DW_TAG_ptr_to_member_type);
285 DIEEntry FooEntry(&Foo);
285 DIEEntry FooEntry(Foo);
286286 PtrToFooMem.addValue(dwarf::DW_AT_type, dwarf::DW_FORM_ref4, &FooEntry);
287287 PtrToFooMem.addValue(dwarf::DW_AT_containing_type, dwarf::DW_FORM_ref4,
288288 &FooEntry);
289289
290 DIEEntry PtrToFooMemRef(&PtrToFooMem);
290 DIEEntry PtrToFooMemRef(PtrToFooMem);
291291 Mem->addValue(dwarf::DW_AT_type, dwarf::DW_FORM_ref4, &PtrToFooMemRef);
292292
293293 Foo.addChild(Mem);
325325 &Zero);
326326
327327 DIE PtrToFooMem(dwarf::DW_TAG_ptr_to_member_type);
328 DIEEntry BarEntry(&Bar);
328 DIEEntry BarEntry(Bar);
329329 PtrToFooMem.addValue(dwarf::DW_AT_type, dwarf::DW_FORM_ref4, &BarEntry);
330 DIEEntry FooEntry(&Foo);
330 DIEEntry FooEntry(Foo);
331331 PtrToFooMem.addValue(dwarf::DW_AT_containing_type, dwarf::DW_FORM_ref4,
332332 &FooEntry);
333333
334 DIEEntry PtrToFooMemRef(&PtrToFooMem);
334 DIEEntry PtrToFooMemRef(PtrToFooMem);
335335 Mem->addValue(dwarf::DW_AT_type, dwarf::DW_FORM_ref4, &PtrToFooMemRef);
336336
337337 Foo.addChild(Mem);
354354 &Zero);
355355
356356 DIE PtrToFooMem(dwarf::DW_TAG_ptr_to_member_type);
357 DIEEntry BarEntry(&Bar);
357 DIEEntry BarEntry(Bar);
358358 PtrToFooMem.addValue(dwarf::DW_AT_type, dwarf::DW_FORM_ref4, &BarEntry);
359 DIEEntry FooEntry(&Foo);
359 DIEEntry FooEntry(Foo);
360360 PtrToFooMem.addValue(dwarf::DW_AT_containing_type, dwarf::DW_FORM_ref4,
361361 &FooEntry);
362362
363 DIEEntry PtrToFooMemRef(&PtrToFooMem);
363 DIEEntry PtrToFooMemRef(PtrToFooMem);
364364 Mem->addValue(dwarf::DW_AT_type, dwarf::DW_FORM_ref4, &PtrToFooMemRef);
365365
366366 Foo.addChild(Mem);
398398 &Zero);
399399
400400 DIE PtrToFooMem(dwarf::DW_TAG_ptr_to_member_type);
401 DIEEntry BarEntry(&Bar);
401 DIEEntry BarEntry(Bar);
402402 PtrToFooMem.addValue(dwarf::DW_AT_type, dwarf::DW_FORM_ref4, &BarEntry);
403403 PtrToFooMem.addValue(dwarf::DW_AT_containing_type, dwarf::DW_FORM_ref4,
404404 &BarEntry);
405405
406 DIEEntry PtrToFooMemRef(&PtrToFooMem);
406 DIEEntry PtrToFooMemRef(PtrToFooMem);
407407 Mem->addValue(dwarf::DW_AT_type, dwarf::DW_FORM_ref4, &PtrToFooMemRef);
408408
409409 Foo.addChild(Mem);
426426 &Zero);
427427
428428 DIE PtrToFooMem(dwarf::DW_TAG_ptr_to_member_type);
429 DIEEntry BarEntry(&Bar);
429 DIEEntry BarEntry(Bar);
430430 PtrToFooMem.addValue(dwarf::DW_AT_type, dwarf::DW_FORM_ref4, &BarEntry);
431431 PtrToFooMem.addValue(dwarf::DW_AT_containing_type, dwarf::DW_FORM_ref4,
432432 &BarEntry);
433433
434 DIEEntry PtrToFooMemRef(&PtrToFooMem);
434 DIEEntry PtrToFooMemRef(PtrToFooMem);
435435 Mem->addValue(dwarf::DW_AT_type, dwarf::DW_FORM_ref4, &PtrToFooMemRef);
436436
437437 Foo.addChild(Mem);
468468
469469 DIE UnnamedPtr(dwarf::DW_TAG_pointer_type);
470470 UnnamedPtr.addValue(dwarf::DW_AT_byte_size, dwarf::DW_FORM_data1, &Eight);
471 DIEEntry UnnamedRef(&Unnamed);
471 DIEEntry UnnamedRef(Unnamed);
472472 UnnamedPtr.addValue(dwarf::DW_AT_type, dwarf::DW_FORM_ref4, &UnnamedRef);
473473
474 DIEEntry UnnamedPtrRef(&UnnamedPtr);
474 DIEEntry UnnamedPtrRef(UnnamedPtr);
475475 Mem->addValue(dwarf::DW_AT_type, dwarf::DW_FORM_ref4, &UnnamedPtrRef);
476476
477477 Foo.addChild(Mem);
571571 IntTyDIE.addValue(dwarf::DW_AT_encoding, dwarf::DW_FORM_data1, &Five);
572572 IntTyDIE.addValue(dwarf::DW_AT_name, dwarf::DW_FORM_strp, &FStr);
573573
574 DIEEntry IntTy(&IntTyDIE);
574 DIEEntry IntTy(IntTyDIE);
575575 DIE *PITyDIE = new DIE(dwarf::DW_TAG_const_type);
576576 PITyDIE->addValue(dwarf::DW_AT_type, dwarf::DW_FORM_ref4, &IntTy);
577577
578 DIEEntry PITy(PITyDIE);
578 DIEEntry PITy(*PITyDIE);
579579 DIE *PI = new DIE(dwarf::DW_TAG_member);
580580 DIEString PIStr(&One, "PI");
581581 DIEInteger Two(2);
615615 FloatTyDIE->addValue(dwarf::DW_AT_encoding, dwarf::DW_FORM_data1, &Four);
616616 FloatTyDIE->addValue(dwarf::DW_AT_name, dwarf::DW_FORM_strp, &FStr);
617617
618 DIEEntry FloatTy(FloatTyDIE);
618 DIEEntry FloatTy(*FloatTyDIE);
619619 DIE *PITyDIE = new DIE(dwarf::DW_TAG_const_type);
620620 PITyDIE->addValue(dwarf::DW_AT_type, dwarf::DW_FORM_ref4, &FloatTy);
621621
622 DIEEntry PITy(PITyDIE);
622 DIEEntry PITy(*PITyDIE);
623623 DIE *PI = new DIE(dwarf::DW_TAG_member);
624624 DIEString PIStr(&One, "PI");
625625 DIEInteger Two(2);