@@ -723,10 +723,12 @@ class CompileUnit {
723
723
// / DescToDieMap - Tracks the mapping of unit level debug informaton
724
724
// / descriptors to debug information entries.
725
725
std::map<DebugInfoDesc *, DIE *> DescToDieMap;
726
+ DenseMap<GlobalVariable *, DIE *> GVToDieMap;
726
727
727
728
// / DescToDIEntryMap - Tracks the mapping of unit level debug informaton
728
729
// / descriptors to debug information entries using a DIEntry proxy.
729
730
std::map<DebugInfoDesc *, DIEntry *> DescToDIEntryMap;
731
+ DenseMap<GlobalVariable *, DIEntry *> GVToDIEntryMap;
730
732
731
733
// / Globals - A map of globally visible named entities for this unit.
732
734
// /
@@ -746,7 +748,9 @@ class CompileUnit {
746
748
, ID(I)
747
749
, Die(D)
748
750
, DescToDieMap()
751
+ , GVToDieMap()
749
752
, DescToDIEntryMap()
753
+ , GVToDIEntryMap()
750
754
, Globals()
751
755
, DiesSet(InitDiesSetSize)
752
756
, Dies()
@@ -782,12 +786,18 @@ class CompileUnit {
782
786
DIE *&getDieMapSlotFor (DebugInfoDesc *DID) {
783
787
return DescToDieMap[DID];
784
788
}
789
+ DIE *&getDieMapSlotFor (GlobalVariable *GV) {
790
+ return GVToDieMap[GV];
791
+ }
785
792
786
793
// / getDIEntrySlotFor - Returns the debug information entry proxy slot for the
787
794
// / specified debug descriptor.
788
795
DIEntry *&getDIEntrySlotFor (DebugInfoDesc *DID) {
789
796
return DescToDIEntryMap[DID];
790
797
}
798
+ DIEntry *&getDIEntrySlotFor (GlobalVariable *GV) {
799
+ return GVToDIEntryMap[GV];
800
+ }
791
801
792
802
// / AddDie - Adds or interns the DIE to the compile unit.
793
803
// /
@@ -1497,6 +1507,39 @@ class DwarfDebug : public Dwarf {
1497
1507
}
1498
1508
}
1499
1509
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
+
1500
1543
// / ConstructTypeDIE - Construct basic type die from DIBasicType.
1501
1544
void ConstructTypeDIE (CompileUnit *DW_Unit, DIE &Buffer,
1502
1545
DIBasicType *BTy) {
@@ -1526,7 +1569,7 @@ class DwarfDebug : public Dwarf {
1526
1569
Buffer.setTag (Tag);
1527
1570
// Map to main type, void will not have a type.
1528
1571
DIType FromTy = DTy->getTypeDerivedFrom ();
1529
- // FIXME - Enable this. AddType(&Buffer, FromTy, DW_Unit );
1572
+ AddType (DW_Unit, &Buffer, FromTy);
1530
1573
1531
1574
// Add name if not anonymous or intermediate type.
1532
1575
if (!Name.empty ()) AddString (&Buffer, DW_AT_name, DW_FORM_string, Name);
@@ -1567,11 +1610,25 @@ class DwarfDebug : public Dwarf {
1567
1610
AddUInt (&Buffer, DW_AT_prototyped, DW_FORM_flag, 1 );
1568
1611
DIArray Elements = CTy->getTypeArray ();
1569
1612
// 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));
1571
1622
// Add arguments.
1572
1623
for (unsigned i = 1 , N = Elements.getNumElements (); i < N; ++i) {
1573
1624
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);
1575
1632
Buffer.AddChild (Arg);
1576
1633
}
1577
1634
}
@@ -1642,7 +1699,7 @@ class DwarfDebug : public Dwarf {
1642
1699
1643
1700
DIArray Elements = CTy->getTypeArray ();
1644
1701
// FIXME - Enable this.
1645
- // AddType(&Buffer, CTy->getTypeDerivedFrom(), DW_Unit );
1702
+ AddType (DW_Unit, &Buffer, CTy->getTypeDerivedFrom ());
1646
1703
1647
1704
// Construct an anonymous type for index type.
1648
1705
DIE IdxBuffer (DW_TAG_base_type);
@@ -1680,7 +1737,7 @@ class DwarfDebug : public Dwarf {
1680
1737
AddString (VariableDie, DW_AT_MIPS_linkage_name, DW_FORM_string,
1681
1738
LinkageName);
1682
1739
// FIXME - Enable this. AddSourceLine(VariableDie, V);
1683
- // FIXME - Enable this. AddType(VariableDie, V->getType(), DW_Unit );
1740
+ AddType (DW_Unit, VariableDie, V->getType ());
1684
1741
if (!V->isLocalToUnit ())
1685
1742
AddUInt (VariableDie, DW_AT_external, DW_FORM_flag, 1 );
1686
1743
AddUInt (VariableDie, DW_AT_declaration, DW_FORM_flag, 1 );
@@ -1702,13 +1759,26 @@ class DwarfDebug : public Dwarf {
1702
1759
DIArray Args = MTy.getTypeArray ();
1703
1760
1704
1761
// 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
+ }
1707
1771
1708
1772
// Add arguments.
1709
1773
for (unsigned i = 1 , N = Args.getNumElements (); i < N; ++i) {
1710
1774
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);
1712
1782
AddUInt (Arg, DW_AT_artificial, DW_FORM_flag, 1 ); // ???
1713
1783
Method->AddChild (Arg);
1714
1784
}
@@ -1728,7 +1798,7 @@ class DwarfDebug : public Dwarf {
1728
1798
// FIXME - Enable this. AddSourceLine(MemberDie, DTy);
1729
1799
1730
1800
DIType FromTy = DTy->getTypeDerivedFrom ();
1731
- // FIXME - Enable this. AddType(MemberDie, FromTy, DW_Unit );
1801
+ AddType (DW_Unit, MemberDie, FromTy );
1732
1802
1733
1803
uint64_t Size = DTy->getSizeInBits ();
1734
1804
uint64_t Offset = DTy->getOffsetInBits ();
0 commit comments