Skip to content

Commit c0a1900

Browse files
author
Devang Patel
committed
Add type DIEs using DebugInfo.
llvm-svn: 61757
1 parent cd6f51c commit c0a1900

File tree

1 file changed

+79
-9
lines changed

1 file changed

+79
-9
lines changed

llvm/lib/CodeGen/AsmPrinter/DwarfWriter.cpp

Lines changed: 79 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -723,10 +723,12 @@ class CompileUnit {
723723
/// DescToDieMap - Tracks the mapping of unit level debug informaton
724724
/// descriptors to debug information entries.
725725
std::map<DebugInfoDesc *, DIE *> DescToDieMap;
726+
DenseMap<GlobalVariable *, DIE *> GVToDieMap;
726727

727728
/// DescToDIEntryMap - Tracks the mapping of unit level debug informaton
728729
/// descriptors to debug information entries using a DIEntry proxy.
729730
std::map<DebugInfoDesc *, DIEntry *> DescToDIEntryMap;
731+
DenseMap<GlobalVariable *, DIEntry *> GVToDIEntryMap;
730732

731733
/// Globals - A map of globally visible named entities for this unit.
732734
///
@@ -746,7 +748,9 @@ class CompileUnit {
746748
, ID(I)
747749
, Die(D)
748750
, DescToDieMap()
751+
, GVToDieMap()
749752
, DescToDIEntryMap()
753+
, GVToDIEntryMap()
750754
, Globals()
751755
, DiesSet(InitDiesSetSize)
752756
, Dies()
@@ -782,12 +786,18 @@ class CompileUnit {
782786
DIE *&getDieMapSlotFor(DebugInfoDesc *DID) {
783787
return DescToDieMap[DID];
784788
}
789+
DIE *&getDieMapSlotFor(GlobalVariable *GV) {
790+
return GVToDieMap[GV];
791+
}
785792

786793
/// getDIEntrySlotFor - Returns the debug information entry proxy slot for the
787794
/// specified debug descriptor.
788795
DIEntry *&getDIEntrySlotFor(DebugInfoDesc *DID) {
789796
return DescToDIEntryMap[DID];
790797
}
798+
DIEntry *&getDIEntrySlotFor(GlobalVariable *GV) {
799+
return GVToDIEntryMap[GV];
800+
}
791801

792802
/// AddDie - Adds or interns the DIE to the compile unit.
793803
///
@@ -1497,6 +1507,39 @@ class DwarfDebug : public Dwarf {
14971507
}
14981508
}
14991509

1510+
/// AddType - Add a new type attribute to the specified entity.
1511+
void AddType(CompileUnit *DW_Unit, DIE *Entity, DIType Ty) {
1512+
if (Ty.isNull()) {
1513+
AddBasicType(Entity, DW_Unit, "", DW_ATE_signed, sizeof(int32_t));
1514+
return;
1515+
}
1516+
1517+
// Check for pre-existence.
1518+
DIEntry *&Slot = DW_Unit->getDIEntrySlotFor(Ty.getGV());
1519+
// If it exists then use the existing value.
1520+
if (Slot) {
1521+
Entity->AddValue(DW_AT_type, DW_FORM_ref4, Slot);
1522+
return;
1523+
}
1524+
1525+
// Set up proxy.
1526+
Slot = NewDIEntry();
1527+
1528+
// Construct type.
1529+
DIE Buffer(DW_TAG_base_type);
1530+
if (DIBasicType *BT = dyn_cast<DIBasicType>(&Ty))
1531+
ConstructTypeDIE(DW_Unit, Buffer, BT);
1532+
else if (DIDerivedType *DT = dyn_cast<DIDerivedType>(&Ty))
1533+
ConstructTypeDIE(DW_Unit, Buffer, DT);
1534+
else if (DICompositeType *CT = dyn_cast<DICompositeType>(&Ty))
1535+
ConstructTypeDIE(DW_Unit, Buffer, CT);
1536+
1537+
// Add debug information entry to entity and unit.
1538+
DIE *Die = DW_Unit->AddDie(Buffer);
1539+
SetDIEntry(Slot, Die);
1540+
Entity->AddValue(DW_AT_type, DW_FORM_ref4, Slot);
1541+
}
1542+
15001543
/// ConstructTypeDIE - Construct basic type die from DIBasicType.
15011544
void ConstructTypeDIE(CompileUnit *DW_Unit, DIE &Buffer,
15021545
DIBasicType *BTy) {
@@ -1526,7 +1569,7 @@ class DwarfDebug : public Dwarf {
15261569
Buffer.setTag(Tag);
15271570
// Map to main type, void will not have a type.
15281571
DIType FromTy = DTy->getTypeDerivedFrom();
1529-
// FIXME - Enable this. AddType(&Buffer, FromTy, DW_Unit);
1572+
AddType(DW_Unit, &Buffer, FromTy);
15301573

15311574
// Add name if not anonymous or intermediate type.
15321575
if (!Name.empty()) AddString(&Buffer, DW_AT_name, DW_FORM_string, Name);
@@ -1567,11 +1610,25 @@ class DwarfDebug : public Dwarf {
15671610
AddUInt(&Buffer, DW_AT_prototyped, DW_FORM_flag, 1);
15681611
DIArray Elements = CTy->getTypeArray();
15691612
// Add return type.
1570-
// FIXME - Enable this.AddType(&Buffer, Elements.getElement(0), DW_Unit);
1613+
DIDescriptor RTy = Elements.getElement(0);
1614+
if (DIBasicType *BT = dyn_cast<DIBasicType>(&RTy))
1615+
AddType(DW_Unit, &Buffer, *BT);
1616+
else if (DIDerivedType *DT = dyn_cast<DIDerivedType>(&RTy))
1617+
AddType(DW_Unit, &Buffer, *DT);
1618+
else if (DICompositeType *CT = dyn_cast<DICompositeType>(&RTy))
1619+
AddType(DW_Unit, &Buffer, *CT);
1620+
1621+
//AddType(DW_Unit, &Buffer, Elements.getElement(0));
15711622
// Add arguments.
15721623
for (unsigned i = 1, N = Elements.getNumElements(); i < N; ++i) {
15731624
DIE *Arg = new DIE(DW_TAG_formal_parameter);
1574-
// FIXME - Enable this.AddType(Arg, Elements.getElement(i), DW_Unit);
1625+
DIDescriptor Ty = Elements.getElement(i);
1626+
if (DIBasicType *BT = dyn_cast<DIBasicType>(&Ty))
1627+
AddType(DW_Unit, &Buffer, *BT);
1628+
else if (DIDerivedType *DT = dyn_cast<DIDerivedType>(&Ty))
1629+
AddType(DW_Unit, &Buffer, *DT);
1630+
else if (DICompositeType *CT = dyn_cast<DICompositeType>(&Ty))
1631+
AddType(DW_Unit, &Buffer, *CT);
15751632
Buffer.AddChild(Arg);
15761633
}
15771634
}
@@ -1642,7 +1699,7 @@ class DwarfDebug : public Dwarf {
16421699

16431700
DIArray Elements = CTy->getTypeArray();
16441701
// FIXME - Enable this.
1645-
// AddType(&Buffer, CTy->getTypeDerivedFrom(), DW_Unit);
1702+
AddType(DW_Unit, &Buffer, CTy->getTypeDerivedFrom());
16461703

16471704
// Construct an anonymous type for index type.
16481705
DIE IdxBuffer(DW_TAG_base_type);
@@ -1680,7 +1737,7 @@ class DwarfDebug : public Dwarf {
16801737
AddString(VariableDie, DW_AT_MIPS_linkage_name, DW_FORM_string,
16811738
LinkageName);
16821739
// FIXME - Enable this. AddSourceLine(VariableDie, V);
1683-
// FIXME - Enable this. AddType(VariableDie, V->getType(), DW_Unit);
1740+
AddType(DW_Unit, VariableDie, V->getType());
16841741
if (!V->isLocalToUnit())
16851742
AddUInt(VariableDie, DW_AT_external, DW_FORM_flag, 1);
16861743
AddUInt(VariableDie, DW_AT_declaration, DW_FORM_flag, 1);
@@ -1702,13 +1759,26 @@ class DwarfDebug : public Dwarf {
17021759
DIArray Args = MTy.getTypeArray();
17031760

17041761
// Add Return Type.
1705-
// FIXME - Enable this. if (!IsConstructor)
1706-
// Fixme - Enable this. AddType(Method, Args.getElement(0), DW_Unit);
1762+
if (!IsConstructor) {
1763+
DIDescriptor Ty = Args.getElement(0);
1764+
if (DIBasicType *BT = dyn_cast<DIBasicType>(&Ty))
1765+
AddType(DW_Unit, Method, *BT);
1766+
else if (DIDerivedType *DT = dyn_cast<DIDerivedType>(&Ty))
1767+
AddType(DW_Unit, Method, *DT);
1768+
else if (DICompositeType *CT = dyn_cast<DICompositeType>(&Ty))
1769+
AddType(DW_Unit, Method, *CT);
1770+
}
17071771

17081772
// Add arguments.
17091773
for (unsigned i = 1, N = Args.getNumElements(); i < N; ++i) {
17101774
DIE *Arg = new DIE(DW_TAG_formal_parameter);
1711-
// FIXME - Enable this. AddType(Arg, Args.getElement(i), DW_Unit);
1775+
DIDescriptor Ty = Args.getElement(i);
1776+
if (DIBasicType *BT = dyn_cast<DIBasicType>(&Ty))
1777+
AddType(DW_Unit, Method, *BT);
1778+
else if (DIDerivedType *DT = dyn_cast<DIDerivedType>(&Ty))
1779+
AddType(DW_Unit, Method, *DT);
1780+
else if (DICompositeType *CT = dyn_cast<DICompositeType>(&Ty))
1781+
AddType(DW_Unit, Method, *CT);
17121782
AddUInt(Arg, DW_AT_artificial, DW_FORM_flag, 1); // ???
17131783
Method->AddChild(Arg);
17141784
}
@@ -1728,7 +1798,7 @@ class DwarfDebug : public Dwarf {
17281798
// FIXME - Enable this. AddSourceLine(MemberDie, DTy);
17291799

17301800
DIType FromTy = DTy->getTypeDerivedFrom();
1731-
// FIXME - Enable this. AddType(MemberDie, FromTy, DW_Unit);
1801+
AddType(DW_Unit, MemberDie, FromTy);
17321802

17331803
uint64_t Size = DTy->getSizeInBits();
17341804
uint64_t Offset = DTy->getOffsetInBits();

0 commit comments

Comments
 (0)