@@ -1123,6 +1123,33 @@ class Dwarf {
1123
1123
1124
1124
};
1125
1125
1126
+ // ===----------------------------------------------------------------------===//
1127
+ // / SrcFileInfo - This class is used to track source information.
1128
+ // /
1129
+ class SrcFileInfo {
1130
+ unsigned DirectoryID; // Directory ID number.
1131
+ std::string Name; // File name (not including directory.)
1132
+ public:
1133
+ SrcFileInfo (unsigned D, const std::string &N) : DirectoryID(D), Name(N) {}
1134
+
1135
+ // Accessors
1136
+ unsigned getDirectoryID () const { return DirectoryID; }
1137
+ const std::string &getName () const { return Name; }
1138
+
1139
+ // / operator== - Used by UniqueVector to locate entry.
1140
+ // /
1141
+ bool operator ==(const SourceFileInfo &SI) const {
1142
+ return getDirectoryID () == SI.getDirectoryID () && getName () == SI.getName ();
1143
+ }
1144
+
1145
+ // / operator< - Used by UniqueVector to locate entry.
1146
+ // /
1147
+ bool operator <(const SrcFileInfo &SI) const {
1148
+ return getDirectoryID () < SI.getDirectoryID () ||
1149
+ (getDirectoryID () == SI.getDirectoryID () && getName () < SI.getName ());
1150
+ }
1151
+ };
1152
+
1126
1153
// ===----------------------------------------------------------------------===//
1127
1154
// / DwarfDebug - Emits Dwarf debug directives.
1128
1155
// /
@@ -1136,6 +1163,7 @@ class DwarfDebug : public Dwarf {
1136
1163
// / CompileUnits - All the compile units involved in this build. The index
1137
1164
// / of each entry in this vector corresponds to the sources in MMI.
1138
1165
std::vector<CompileUnit *> CompileUnits;
1166
+ DenseMap<GlobalVariable *, CompileUnit *> DW_CUs;
1139
1167
1140
1168
// / AbbreviationsSet - Used to uniquely define abbreviations.
1141
1169
// /
@@ -1147,6 +1175,12 @@ class DwarfDebug : public Dwarf {
1147
1175
1148
1176
// / ValuesSet - Used to uniquely define values.
1149
1177
// /
1178
+ // Directories - Uniquing vector for directories.
1179
+ UniqueVector<std::string> Directories;
1180
+
1181
+ // SourceFiles - Uniquing vector for source files.
1182
+ UniqueVector<SrcFileInfo> SrcFiles;
1183
+
1150
1184
FoldingSet<DIEValue> ValuesSet;
1151
1185
1152
1186
// / Values - A list of all the unique values in use.
@@ -1416,6 +1450,42 @@ class DwarfDebug : public Dwarf {
1416
1450
}
1417
1451
}
1418
1452
1453
+ // / AddSourceLine - Add location information to specified debug information
1454
+ // / entry.
1455
+ void AddSourceLine (DIE *Die, DIGlobal *G) {
1456
+ unsigned FileID = 0 ;
1457
+ unsigned Line = G->getLineNumber ();
1458
+ if (G->getVersion () < DIDescriptor::Version7) {
1459
+ // Version6 or earlier. Use compile unit info to get file id.
1460
+ CompileUnit *Unit = FindCompileUnit (G->getCompileUnit ());
1461
+ FileID = Unit->getID ();
1462
+ } else {
1463
+ // Version7 or newer, use filename and directory info from DIGlobal
1464
+ // directly.
1465
+ unsigned DID = Directories.idFor (G->getDirectory ());
1466
+ FileID = SrcFiles.idFor (SrcFileInfo (DID, G->getFilename ()));
1467
+ }
1468
+ AddUInt (Die, DW_AT_decl_file, 0 , FileID);
1469
+ AddUInt (Die, DW_AT_decl_line, 0 , Line);
1470
+ }
1471
+
1472
+ void AddSourceLine (DIE *Die, DIType *G) {
1473
+ unsigned FileID = 0 ;
1474
+ unsigned Line = G->getLineNumber ();
1475
+ if (G->getVersion () < DIDescriptor::Version7) {
1476
+ // Version6 or earlier. Use compile unit info to get file id.
1477
+ CompileUnit *Unit = FindCompileUnit (G->getCompileUnit ());
1478
+ FileID = Unit->getID ();
1479
+ } else {
1480
+ // Version7 or newer, use filename and directory info from DIGlobal
1481
+ // directly.
1482
+ unsigned DID = Directories.idFor (G->getDirectory ());
1483
+ FileID = SrcFiles.idFor (SrcFileInfo (DID, G->getFilename ()));
1484
+ }
1485
+ AddUInt (Die, DW_AT_decl_file, 0 , FileID);
1486
+ AddUInt (Die, DW_AT_decl_line, 0 , Line);
1487
+ }
1488
+
1419
1489
// / AddAddress - Add an address attribute to a die based on the location
1420
1490
// / provided.
1421
1491
void AddAddress (DIE *Die, unsigned Attribute,
@@ -2144,6 +2214,14 @@ class DwarfDebug : public Dwarf {
2144
2214
return Unit;
2145
2215
}
2146
2216
2217
+ // / FindCompileUnit - Get the compile unit for the given descriptor.
2218
+ // /
2219
+ CompileUnit *FindCompileUnit (DICompileUnit Unit) {
2220
+ CompileUnit *DW_Unit = DW_CUs[Unit.getGV ()];
2221
+ assert (DW_Unit && " Missing compile unit." );
2222
+ return DW_Unit;
2223
+ }
2224
+
2147
2225
// / NewGlobalVariable - Add a new global variable DIE.
2148
2226
// /
2149
2227
DIE *NewGlobalVariable (GlobalVariableDesc *GVD) {
0 commit comments