Deleted Added
sdiff udiff text old ( 195098 ) new ( 195340 )
full compact
1//===-- llvm/CodeGen/DwarfDebug.cpp - Dwarf Debug Framework ---------------===//
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//===----------------------------------------------------------------------===//

--- 207 unchanged lines hidden (view full) ---

216 delete Variables[j];
217 for (unsigned k = 0, O = ConcreteInsts.size(); k < O; ++k)
218 delete ConcreteInsts[k];
219}
220
221} // end llvm namespace
222
223DwarfDebug::DwarfDebug(raw_ostream &OS, AsmPrinter *A, const TargetAsmInfo *T)
224 : Dwarf(OS, A, T, "dbg"), ModuleCU(0),
225 AbbreviationsSet(InitAbbreviationsSetSize), Abbreviations(),
226 ValuesSet(InitValuesSetSize), Values(), StringPool(), SectionMap(),
227 SectionSourceLines(), didInitial(false), shouldEmit(false),
228 FunctionDbgScope(0), DebugTimer(0) {
229 if (TimePassesIsEnabled)
230 DebugTimer = new Timer("Dwarf Debug Writer",
231 getDwarfTimerGroup());
232}

--- 440 unchanged lines hidden (view full) ---

673
674 // Add elements to structure type.
675 for (unsigned i = 0, N = Elements.getNumElements(); i < N; ++i) {
676 DIDescriptor Element = Elements.getElement(i);
677 DIE *ElemDie = NULL;
678 if (Element.getTag() == dwarf::DW_TAG_subprogram)
679 ElemDie = CreateSubprogramDIE(DW_Unit,
680 DISubprogram(Element.getGV()));
681 else
682 ElemDie = CreateMemberDIE(DW_Unit,
683 DIDerivedType(Element.getGV()));
684 Buffer.AddChild(ElemDie);
685 }
686
687 // FIXME: We'd like an API to register additional attributes for the
688 // frontend to use while synthesizing, and then we'd use that api in clang

--- 396 unchanged lines hidden (view full) ---

1085 if (!RootScope) return;
1086 DIDescriptor Desc = RootScope->getDesc();
1087 if (Desc.isNull())
1088 return;
1089
1090 // Get the subprogram debug information entry.
1091 DISubprogram SPD(Desc.getGV());
1092
1093 // Get the subprogram die.
1094 DIE *SPDie = ModuleCU->getDieMapSlotFor(SPD.getGV());
1095 assert(SPDie && "Missing subprogram descriptor");
1096
1097 if (!AbstractScope) {
1098 // Add the function bounds.
1099 AddLabel(SPDie, dwarf::DW_AT_low_pc, dwarf::DW_FORM_addr,
1100 DWLabel("func_begin", SubprogramCount));
1101 AddLabel(SPDie, dwarf::DW_AT_high_pc, dwarf::DW_FORM_addr,
1102 DWLabel("func_end", SubprogramCount));
1103 MachineLocation Location(RI->getFrameRegister(*MF));
1104 AddAddress(SPDie, dwarf::DW_AT_frame_base, Location);
1105 }
1106
1107 ConstructDbgScope(RootScope, 0, 0, SPDie, ModuleCU);
1108}
1109
1110/// ConstructDefaultDbgScope - Construct a default scope for the subprogram.
1111///
1112void DwarfDebug::ConstructDefaultDbgScope(MachineFunction *MF) {
1113 const char *FnName = MF->getFunction()->getNameStart();
1114 StringMap<DIE*> &Globals = ModuleCU->getGlobals();
1115 StringMap<DIE*>::iterator GI = Globals.find(FnName);
1116 if (GI != Globals.end()) {
1117 DIE *SPDie = GI->second;
1118
1119 // Add the function bounds.
1120 AddLabel(SPDie, dwarf::DW_AT_low_pc, dwarf::DW_FORM_addr,
1121 DWLabel("func_begin", SubprogramCount));
1122 AddLabel(SPDie, dwarf::DW_AT_high_pc, dwarf::DW_FORM_addr,
1123 DWLabel("func_end", SubprogramCount));
1124
1125 MachineLocation Location(RI->getFrameRegister(*MF));
1126 AddAddress(SPDie, dwarf::DW_AT_frame_base, Location);
1127 }
1128}
1129
1130/// GetOrCreateSourceID - Look up the source id with the given directory and
1131/// source file names. If none currently exists, create a new id and insert it
1132/// in the SourceIds map. This can update DirectoryNames and SourceFileNames
1133/// maps as well.
1134unsigned DwarfDebug::GetOrCreateSourceID(const std::string &DirName,
1135 const std::string &FileName) {

--- 56 unchanged lines hidden (view full) ---

1192 AddString(Die, dwarf::DW_AT_APPLE_flags, dwarf::DW_FORM_string, Flags);
1193
1194 unsigned RVer = DIUnit.getRunTimeVersion();
1195 if (RVer)
1196 AddUInt(Die, dwarf::DW_AT_APPLE_major_runtime_vers,
1197 dwarf::DW_FORM_data1, RVer);
1198
1199 CompileUnit *Unit = new CompileUnit(ID, Die);
1200 if (!ModuleCU && DIUnit.isMain()) {
1201 // Use first compile unit marked as isMain as the compile unit
1202 // for this module.
1203 ModuleCU = Unit;
1204 }
1205
1206 CompileUnitMap[DIUnit.getGV()] = Unit;
1207 CompileUnits.push_back(Unit);
1208}
1209
1210void DwarfDebug::ConstructGlobalVariableDIE(GlobalVariable *GV) {
1211 DIGlobalVariable DI_GV(GV);
1212
1213 // Check for pre-existence.
1214 DIE *&Slot = ModuleCU->getDieMapSlotFor(DI_GV.getGV());
1215 if (Slot)
1216 return;
1217
1218 DIE *VariableDie = CreateGlobalVariableDIE(ModuleCU, DI_GV);
1219
1220 // Add address.
1221 DIEBlock *Block = new DIEBlock();
1222 AddUInt(Block, 0, dwarf::DW_FORM_data1, dwarf::DW_OP_addr);
1223 std::string GLN;
1224 AddObjectLabel(Block, 0, dwarf::DW_FORM_udata,
1225 Asm->getGlobalLinkName(DI_GV.getGlobal(), GLN));
1226 AddBlock(VariableDie, dwarf::DW_AT_location, 0, Block);
1227
1228 // Add to map.
1229 Slot = VariableDie;
1230
1231 // Add to context owner.
1232 ModuleCU->getDie()->AddChild(VariableDie);
1233
1234 // Expose as global. FIXME - need to check external flag.
1235 std::string Name;
1236 ModuleCU->AddGlobal(DI_GV.getName(Name), VariableDie);
1237 return;
1238}
1239
1240void DwarfDebug::ConstructSubprogram(GlobalVariable *GV) {
1241 DISubprogram SP(GV);
1242
1243 // Check for pre-existence.
1244 DIE *&Slot = ModuleCU->getDieMapSlotFor(GV);
1245 if (Slot)
1246 return;
1247
1248 if (!SP.isDefinition())
1249 // This is a method declaration which will be handled while constructing
1250 // class type.
1251 return;
1252
1253 DIE *SubprogramDie = CreateSubprogramDIE(ModuleCU, SP);
1254
1255 // Add to map.
1256 Slot = SubprogramDie;
1257
1258 // Add to context owner.
1259 ModuleCU->getDie()->AddChild(SubprogramDie);
1260
1261 // Expose as global.
1262 std::string Name;
1263 ModuleCU->AddGlobal(SP.getName(Name), SubprogramDie);
1264 return;
1265}
1266
1267 /// BeginModule - Emit all Dwarf sections that should come prior to the
1268 /// content. Create global DIEs and emit initial debug info sections.
1269 /// This is inovked by the target AsmPrinter.
1270void DwarfDebug::BeginModule(Module *M, MachineModuleInfo *mmi) {
1271 this->M = M;

--- 13 unchanged lines hidden (view full) ---

1285
1286 if (CompileUnits.empty()) {
1287 if (TimePassesIsEnabled)
1288 DebugTimer->stopTimer();
1289
1290 return;
1291 }
1292
1293 // If main compile unit for this module is not seen than randomly
1294 // select first compile unit.
1295 if (!ModuleCU)
1296 ModuleCU = CompileUnits[0];
1297
1298 // If there is not any debug info available for any global variables and any
1299 // subprograms then there is not any debug info to emit.
1300 if (GVs.empty() && SPs.empty()) {
1301 if (TimePassesIsEnabled)
1302 DebugTimer->stopTimer();
1303
1304 return;
1305 }

--- 360 unchanged lines hidden (view full) ---

1666 unsigned LabelID = MMI->NextLabelID();
1667
1668 if (!TAI->doesDwarfUsesInlineInfoSection())
1669 return LabelID;
1670
1671 if (TimePassesIsEnabled)
1672 DebugTimer->startTimer();
1673
1674 GlobalVariable *GV = SP.getGV();
1675 DenseMap<const GlobalVariable *, DbgScope *>::iterator
1676 II = AbstractInstanceRootMap.find(GV);
1677
1678 if (II == AbstractInstanceRootMap.end()) {
1679 // Create an abstract instance entry for this inlined function if it doesn't
1680 // already exist.
1681 DbgScope *Scope = new DbgScope(NULL, DIDescriptor(GV));
1682
1683 // Get the compile unit context.
1684 DIE *SPDie = ModuleCU->getDieMapSlotFor(GV);
1685 if (!SPDie)
1686 SPDie = CreateSubprogramDIE(ModuleCU, SP, false, true);
1687
1688 // Mark as being inlined. This makes this subprogram entry an abstract
1689 // instance root.
1690 // FIXME: Our debugger doesn't care about the value of DW_AT_inline, only
1691 // that it's defined. That probably won't change in the future. However,
1692 // this could be more elegant.
1693 AddUInt(SPDie, dwarf::DW_AT_inline, 0, dwarf::DW_INL_declared_not_inlined);
1694
1695 // Keep track of the abstract scope for this function.
1696 DbgAbstractScopeMap[GV] = Scope;
1697
1698 AbstractInstanceRootMap[GV] = Scope;
1699 AbstractInstanceRootList.push_back(Scope);
1700 }
1701
1702 // Create a concrete inlined instance for this inlined function.
1703 DbgConcreteScope *ConcreteScope = new DbgConcreteScope(DIDescriptor(GV));
1704 DIE *ScopeDie = new DIE(dwarf::DW_TAG_inlined_subroutine);
1705 ScopeDie->setAbstractCompileUnit(ModuleCU);
1706
1707 DIE *Origin = ModuleCU->getDieMapSlotFor(GV);
1708 AddDIEEntry(ScopeDie, dwarf::DW_AT_abstract_origin,
1709 dwarf::DW_FORM_ref4, Origin);
1710 AddUInt(ScopeDie, dwarf::DW_AT_call_file, 0, ModuleCU->getID());
1711 AddUInt(ScopeDie, dwarf::DW_AT_call_line, 0, Line);
1712 AddUInt(ScopeDie, dwarf::DW_AT_call_column, 0, Col);
1713
1714 ConcreteScope->setDie(ScopeDie);
1715 ConcreteScope->setStartLabelID(LabelID);
1716 MMI->RecordUsedDbgLabel(LabelID);
1717
1718 LexicalScopeStack.back()->AddConcreteInst(ConcreteScope);

--- 144 unchanged lines hidden (view full) ---

1863void DwarfDebug::SizeAndOffsets() {
1864 // Compute size of compile unit header.
1865 static unsigned Offset =
1866 sizeof(int32_t) + // Length of Compilation Unit Info
1867 sizeof(int16_t) + // DWARF version number
1868 sizeof(int32_t) + // Offset Into Abbrev. Section
1869 sizeof(int8_t); // Pointer Size (in bytes)
1870
1871 SizeAndOffsetDie(ModuleCU->getDie(), Offset, true);
1872 CompileUnitOffsets[ModuleCU] = 0;
1873}
1874
1875/// EmitInitial - Emit initial Dwarf declarations. This is necessary for cc
1876/// tools to recognize the object file contains Dwarf information.
1877void DwarfDebug::EmitInitial() {
1878 // Check to see if we already emitted intial headers.
1879 if (didInitial) return;
1880 didInitial = true;

--- 128 unchanged lines hidden (view full) ---

2009
2010 Asm->EOL();
2011}
2012
2013void DwarfDebug::EmitDebugInfo() {
2014 // Start debug info section.
2015 Asm->SwitchToDataSection(TAI->getDwarfInfoSection());
2016
2017 EmitDebugInfoPerCU(ModuleCU);
2018}
2019
2020/// EmitAbbreviations - Emit the abbreviation section.
2021///
2022void DwarfDebug::EmitAbbreviations() const {
2023 // Check to see if it is worth the effort.
2024 if (!Abbreviations.empty()) {
2025 // Start the debug abbrev section.

--- 315 unchanged lines hidden (view full) ---

2341}
2342
2343/// EmitDebugPubNames - Emit visible names into a debug pubnames section.
2344///
2345void DwarfDebug::EmitDebugPubNames() {
2346 // Start the dwarf pubnames section.
2347 Asm->SwitchToDataSection(TAI->getDwarfPubNamesSection());
2348
2349 EmitDebugPubNamesPerCU(ModuleCU);
2350}
2351
2352/// EmitDebugStr - Emit visible names into a debug str section.
2353///
2354void DwarfDebug::EmitDebugStr() {
2355 // Check to see if it is worth the effort.
2356 if (!StringPool.empty()) {
2357 // Start the dwarf str section.

--- 93 unchanged lines hidden (view full) ---

2451/// The rest of the entry consists of a {die_offset, low_pc} pair for each
2452/// inlined instance; the die_offset points to the inlined_subroutine die in the
2453/// __debug_info section, and the low_pc is the starting address for the
2454/// inlining instance.
2455void DwarfDebug::EmitDebugInlineInfo() {
2456 if (!TAI->doesDwarfUsesInlineInfoSection())
2457 return;
2458
2459 if (!ModuleCU)
2460 return;
2461
2462 Asm->SwitchToDataSection(TAI->getDwarfDebugInlineSection());
2463 Asm->EOL();
2464 EmitDifference("debug_inlined_end", 1,
2465 "debug_inlined_begin", 1, true);
2466 Asm->EOL("Length of Debug Inlined Information Entry");
2467

--- 17 unchanged lines hidden (view full) ---

2485 Asm->EOL("MIPS linkage name");
2486
2487 Asm->EmitString(Name); Asm->EOL("Function name");
2488
2489 Asm->EmitULEB128Bytes(Labels.size()); Asm->EOL("Inline count");
2490
2491 for (SmallVector<unsigned, 4>::iterator LI = Labels.begin(),
2492 LE = Labels.end(); LI != LE; ++LI) {
2493 DIE *SP = ModuleCU->getDieMapSlotFor(GV);
2494 Asm->EmitInt32(SP->getOffset()); Asm->EOL("DIE offset");
2495
2496 if (TD->getPointerSize() == sizeof(int32_t))
2497 O << TAI->getData32bitsDirective();
2498 else
2499 O << TAI->getData64bitsDirective();
2500
2501 PrintLabelName("label", *LI); Asm->EOL("low_pc");
2502 }
2503 }
2504
2505 EmitLabel("debug_inlined_end", 1);
2506 Asm->EOL();
2507}