llvm.org GIT mirror llvm / 163a9f7
Enable multiple Compile Units in one module. This means now 'llvm-ld a.bc b.bc' will preserve debug info appropriately. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@103439 91177308-0d34-0410-b5e6-96231b3b80d8 Devang Patel 10 years ago
3 changed file(s) with 262 addition(s) and 166 deletion(s). Raw diff Collapse all Expand all
325325 }
326326
327327 DwarfDebug::DwarfDebug(AsmPrinter *A, Module *M)
328 : Asm(A), MMI(Asm->MMI), ModuleCU(0),
328 : Asm(A), MMI(Asm->MMI), FirstCU(0),
329329 AbbreviationsSet(InitAbbreviationsSetSize),
330330 CurrentFnDbgScope(0), PrevLabel(NULL) {
331331 NextStringPoolNumber = 0;
880880 } else if (Context.isNameSpace()) {
881881 DIE *ContextDIE = getOrCreateNameSpace(DINameSpace(Context));
882882 ContextDIE->addChild(Die);
883 } else if (DIE *ContextDIE = ModuleCU->getDIE(Context))
883 } else if (DIE *ContextDIE = getCompileUnit(Context)->getDIE(Context))
884884 ContextDIE->addChild(Die);
885885 else
886 ModuleCU->addDie(Die);
886 getCompileUnit(Context)->addDie(Die);
887887 }
888888
889889 /// getOrCreateTypeDIE - Find existing DIE or create new DIE for the
890890 /// given DIType.
891891 DIE *DwarfDebug::getOrCreateTypeDIE(DIType Ty) {
892 DIE *TyDIE = ModuleCU->getDIE(Ty);
892 CompileUnit *TypeCU = getCompileUnit(Ty);
893 DIE *TyDIE = TypeCU->getDIE(Ty);
893894 if (TyDIE)
894895 return TyDIE;
895896
896897 // Create new type.
897898 TyDIE = new DIE(dwarf::DW_TAG_base_type);
898 ModuleCU->insertDIE(Ty, TyDIE);
899 TypeCU->insertDIE(Ty, TyDIE);
899900 if (Ty.isBasicType())
900901 constructTypeDIE(*TyDIE, DIBasicType(Ty));
901902 else if (Ty.isCompositeType())
915916 return;
916917
917918 // Check for pre-existence.
918 DIEEntry *Entry = ModuleCU->getDIEEntry(Ty);
919 CompileUnit *TypeCU = getCompileUnit(Ty);
920 DIEEntry *Entry = TypeCU->getDIEEntry(Ty);
919921 // If it exists then use the existing value.
920922 if (Entry) {
921923 Entity->addValue(dwarf::DW_AT_type, dwarf::DW_FORM_ref4, Entry);
927929
928930 // Set up proxy.
929931 Entry = createDIEEntry(Buffer);
930 ModuleCU->insertDIEEntry(Ty, Entry);
932 TypeCU->insertDIEEntry(Ty, Entry);
931933
932934 Entity->addValue(dwarf::DW_AT_type, dwarf::DW_FORM_ref4, Entry);
933935 }
11221124 DIArray Elements = CTy->getTypeArray();
11231125
11241126 // Get an anonymous type for index type.
1125 DIE *IdxTy = ModuleCU->getIndexTyDie();
1127 CompileUnit *TheCU = getCompileUnit(*CTy);
1128 DIE *IdxTy = TheCU->getIndexTyDie();
11261129 if (!IdxTy) {
11271130 // Construct an anonymous type for index type.
11281131 IdxTy = new DIE(dwarf::DW_TAG_base_type);
11291132 addUInt(IdxTy, dwarf::DW_AT_byte_size, 0, sizeof(int32_t));
11301133 addUInt(IdxTy, dwarf::DW_AT_encoding, dwarf::DW_FORM_data1,
11311134 dwarf::DW_ATE_signed);
1132 ModuleCU->addDie(IdxTy);
1133 ModuleCU->setIndexTyDie(IdxTy);
1135 TheCU->addDie(IdxTy);
1136 TheCU->setIndexTyDie(IdxTy);
11341137 }
11351138
11361139 // Add subranges to array type.
12641267
12651268 /// createSubprogramDIE - Create new DIE using SP.
12661269 DIE *DwarfDebug::createSubprogramDIE(const DISubprogram &SP, bool MakeDecl) {
1267 DIE *SPDie = ModuleCU->getDIE(SP);
1270 CompileUnit *SPCU = getCompileUnit(SP);
1271 DIE *SPDie = SPCU->getDIE(SP);
12681272 if (SPDie)
12691273 return SPDie;
12701274
13371341 addUInt(SPDie, dwarf::DW_AT_APPLE_optimized, dwarf::DW_FORM_flag, 1);
13381342
13391343 // DW_TAG_inlined_subroutine may refer to this DIE.
1340 ModuleCU->insertDIE(SP, SPDie);
1344 SPCU->insertDIE(SP, SPDie);
13411345
13421346 return SPDie;
13431347 }
13871391 /// If there are global variables in this scope then create and insert
13881392 /// DIEs for these variables.
13891393 DIE *DwarfDebug::updateSubprogramScopeDIE(const MDNode *SPNode) {
1390 DIE *SPDie = ModuleCU->getDIE(SPNode);
1394 CompileUnit *SPCU = getCompileUnit(SPNode);
1395 DIE *SPDie = SPCU->getDIE(SPNode);
13911396 assert(SPDie && "Unable to find subprogram DIE!");
13921397 DISubprogram SP(SPNode);
13931398
14181423 SPDie = new DIE(dwarf::DW_TAG_subprogram);
14191424 addDIEEntry(SPDie, dwarf::DW_AT_specification, dwarf::DW_FORM_ref4,
14201425 SPDeclDie);
1421 ModuleCU->addDie(SPDie);
1426 SPCU->addDie(SPDie);
14221427 }
14231428
14241429 addLabel(SPDie, dwarf::DW_AT_low_pc, dwarf::DW_FORM_addr,
15071512 DIE *ScopeDIE = new DIE(dwarf::DW_TAG_inlined_subroutine);
15081513
15091514 DISubprogram InlinedSP = getDISubprogram(DS);
1510 DIE *OriginDIE = ModuleCU->getDIE(InlinedSP);
1515 CompileUnit *TheCU = getCompileUnit(InlinedSP);
1516 DIE *OriginDIE = TheCU->getDIE(InlinedSP);
15111517 assert(OriginDIE && "Unable to find Origin DIE!");
15121518 addDIEEntry(ScopeDIE, dwarf::DW_AT_abstract_origin,
15131519 dwarf::DW_FORM_ref4, OriginDIE);
15291535 I->second.push_back(std::make_pair(StartLabel, ScopeDIE));
15301536
15311537 DILocation DL(Scope->getInlinedAt());
1532 addUInt(ScopeDIE, dwarf::DW_AT_call_file, 0, ModuleCU->getID());
1538 addUInt(ScopeDIE, dwarf::DW_AT_call_file, 0, TheCU->getID());
15331539 addUInt(ScopeDIE, dwarf::DW_AT_call_line, 0, DL.getLineNumber());
15341540
15351541 return ScopeDIE;
15701576 if (AbsDIE) {
15711577 DIScope DS(Scope->getScopeNode());
15721578 DISubprogram InlinedSP = getDISubprogram(DS);
1573 DIE *OriginSPDIE = ModuleCU->getDIE(InlinedSP);
1579 DIE *OriginSPDIE = getCompileUnit(InlinedSP)->getDIE(InlinedSP);
15741580 (void) OriginSPDIE;
15751581 assert(OriginSPDIE && "Unable to find Origin DIE for the SP!");
15761582 DIE *AbsDIE = DV->getAbstractVariable()->getDIE();
16591665 DICompositeType CATy = getDICompositeType(ATy);
16601666 if (DIDescriptor(CATy).Verify() && !CATy.getName().empty()
16611667 && !CATy.isForwardDecl()) {
1662 if (DIEEntry *Entry = ModuleCU->getDIEEntry(CATy))
1663 ModuleCU->addGlobalType(CATy.getName(), Entry->getEntry());
1668 CompileUnit *TheCU = getCompileUnit(CATy);
1669 if (DIEEntry *Entry = TheCU->getDIEEntry(CATy))
1670 TheCU->addGlobalType(CATy.getName(), Entry->getEntry());
16641671 }
16651672 }
16661673 }
16761683 ScopeDIE = constructInlinedScopeDIE(Scope);
16771684 else if (DS.isSubprogram()) {
16781685 if (Scope->isAbstractScope())
1679 ScopeDIE = ModuleCU->getDIE(DS);
1686 ScopeDIE = getCompileUnit(DS)->getDIE(DS);
16801687 else
16811688 ScopeDIE = updateSubprogramScopeDIE(DS);
16821689 }
17461753
17471754 /// getOrCreateNameSpace - Create a DIE for DINameSpace.
17481755 DIE *DwarfDebug::getOrCreateNameSpace(DINameSpace NS) {
1749 DIE *NDie = ModuleCU->getDIE(NS);
1756 CompileUnit *TheCU = getCompileUnit(NS);
1757 DIE *NDie = TheCU->getDIE(NS);
17501758 if (NDie)
17511759 return NDie;
17521760 NDie = new DIE(dwarf::DW_TAG_namespace);
1753 ModuleCU->insertDIE(NS, NDie);
1761 TheCU->insertDIE(NS, NDie);
17541762 if (!NS.getName().empty())
17551763 addString(NDie, dwarf::DW_AT_name, dwarf::DW_FORM_string, NS.getName());
17561764 addSourceLine(NDie, &NS);
17581766 return NDie;
17591767 }
17601768
1769 /// constructCompileUnit - Create new CompileUnit for the given
1770 /// metadata node with tag DW_TAG_compile_unit.
17611771 void DwarfDebug::constructCompileUnit(const MDNode *N) {
17621772 DICompileUnit DIUnit(N);
1763 // Use first compile unit marked as isMain as the compile unit for this
1764 // module.
1765 if (ModuleCU || !DIUnit.isMain())
1766 return;
17671773 StringRef FN = DIUnit.getFilename();
17681774 StringRef Dir = DIUnit.getDirectory();
17691775 unsigned ID = GetOrCreateSourceID(Dir, FN);
17961802 addUInt(Die, dwarf::DW_AT_APPLE_major_runtime_vers,
17971803 dwarf::DW_FORM_data1, RVer);
17981804
1799 assert(!ModuleCU &&
1800 "ModuleCU assigned since the top of constructCompileUnit");
1801 ModuleCU = new CompileUnit(ID, Die);
1802 }
1803
1805 CompileUnit *NewCU = new CompileUnit(ID, Die);
1806 if (!FirstCU)
1807 FirstCU = NewCU;
1808 CUMap.insert(std::make_pair(N, NewCU));
1809 }
1810
1811 /// getCompielUnit - Get CompileUnit DIE.
1812 CompileUnit *DwarfDebug::getCompileUnit(const MDNode *N) const {
1813 assert (N && "Invalid DwarfDebug::getCompileUnit argument!");
1814 DIDescriptor D(N);
1815 const MDNode *CUNode = NULL;
1816 if (D.isCompileUnit())
1817 CUNode = N;
1818 else if (D.isSubprogram())
1819 CUNode = DISubprogram(N).getCompileUnit();
1820 else if (D.isType())
1821 CUNode = DIType(N).getCompileUnit();
1822 else if (D.isGlobalVariable())
1823 CUNode = DIGlobalVariable(N).getCompileUnit();
1824 else if (D.isVariable())
1825 CUNode = DIVariable(N).getCompileUnit();
1826 else if (D.isNameSpace())
1827 CUNode = DINameSpace(N).getCompileUnit();
1828 else if (D.isFile())
1829 CUNode = DIFile(N).getCompileUnit();
1830 else
1831 return FirstCU;
1832
1833 DenseMap::const_iterator I
1834 = CUMap.find(CUNode);
1835 if (I == CUMap.end())
1836 return FirstCU;
1837 return I->second;
1838 }
1839
1840
1841 /// constructGlobalVariableDIE - Construct global variable DIE.
18041842 void DwarfDebug::constructGlobalVariableDIE(const MDNode *N) {
18051843 DIGlobalVariable DI_GV(N);
18061844
18091847 return;
18101848
18111849 // Check for pre-existence.
1812 if (ModuleCU->getDIE(DI_GV))
1850 CompileUnit *TheCU = getCompileUnit(N);
1851 if (TheCU->getDIE(DI_GV))
18131852 return;
18141853
18151854 DIE *VariableDie = createGlobalVariableDIE(DI_GV);
18171856 return;
18181857
18191858 // Add to map.
1820 ModuleCU->insertDIE(N, VariableDie);
1859 TheCU->insertDIE(N, VariableDie);
18211860
18221861 // Add to context owner.
18231862 DIDescriptor GVContext = DI_GV.getContext();
18361875 Asm->Mang->getSymbol(DI_GV.getGlobal()));
18371876 addBlock(VariableSpecDIE, dwarf::DW_AT_location, 0, Block);
18381877 addUInt(VariableDie, dwarf::DW_AT_declaration, dwarf::DW_FORM_flag, 1);
1839 ModuleCU->addDie(VariableSpecDIE);
1878 TheCU->addDie(VariableSpecDIE);
18401879 } else {
18411880 DIEBlock *Block = new (DIEValueAllocator) DIEBlock();
18421881 addUInt(Block, 0, dwarf::DW_FORM_data1, dwarf::DW_OP_addr);
18471886 addToContextOwner(VariableDie, GVContext);
18481887
18491888 // Expose as global. FIXME - need to check external flag.
1850 ModuleCU->addGlobal(DI_GV.getName(), VariableDie);
1889 TheCU->addGlobal(DI_GV.getName(), VariableDie);
18511890
18521891 DIType GTy = DI_GV.getType();
18531892 if (GTy.isCompositeType() && !GTy.getName().empty()
18541893 && !GTy.isForwardDecl()) {
1855 DIEEntry *Entry = ModuleCU->getDIEEntry(GTy);
1894 DIEEntry *Entry = TheCU->getDIEEntry(GTy);
18561895 assert(Entry && "Missing global type!");
1857 ModuleCU->addGlobalType(GTy.getName(), Entry->getEntry());
1896 TheCU->addGlobalType(GTy.getName(), Entry->getEntry());
18581897 }
18591898 return;
18601899 }
18611900
1901 /// construct SubprogramDIE - Construct subprogram DIE.
18621902 void DwarfDebug::constructSubprogramDIE(const MDNode *N) {
18631903 DISubprogram SP(N);
18641904
18651905 // Check for pre-existence.
1866 if (ModuleCU->getDIE(N))
1906 CompileUnit *TheCU = getCompileUnit(N);
1907 if (TheCU->getDIE(N))
18671908 return;
18681909
18691910 if (!SP.isDefinition())
18741915 DIE *SubprogramDie = createSubprogramDIE(SP);
18751916
18761917 // Add to map.
1877 ModuleCU->insertDIE(N, SubprogramDie);
1918 TheCU->insertDIE(N, SubprogramDie);
18781919
18791920 // Add to context owner.
18801921 addToContextOwner(SubprogramDie, SP.getContext());
18811922
18821923 // Expose as global.
1883 ModuleCU->addGlobal(SP.getName(), SubprogramDie);
1924 TheCU->addGlobal(SP.getName(), SubprogramDie);
18841925
18851926 return;
18861927 }
19541995 /// endModule - Emit all Dwarf sections that should come after the content.
19551996 ///
19561997 void DwarfDebug::endModule() {
1957 if (!ModuleCU) return;
1998 if (!FirstCU) return;
19581999
19592000 // Attach DW_AT_inline attribute with inlined subprogram DIEs.
19602001 for (SmallPtrSet::iterator AI = InlinedSubprogramDIEs.begin(),
19682009 DIE *SPDie = CI->first;
19692010 const MDNode *N = dyn_cast_or_null(CI->second);
19702011 if (!N) continue;
1971 DIE *NDie = ModuleCU->getDIE(N);
2012 DIE *NDie = getCompileUnit(N)->getDIE(N);
19722013 if (!NDie) continue;
19732014 addDIEEntry(SPDie, dwarf::DW_AT_containing_type, dwarf::DW_FORM_ref4, NDie);
19742015 }
20292070 // Emit info into a debug str section.
20302071 emitDebugStr();
20312072
2032 delete ModuleCU;
2033 ModuleCU = NULL; // Reset for the next Module, if any.
2073 for (DenseMap::iterator I = CUMap.begin(),
2074 E = CUMap.end(); I != E; ++I)
2075 delete I->second;
2076 FirstCU = NULL; // Reset for the next Module, if any.
20342077 }
20352078
20362079 /// findAbstractVariable - Find abstract variable, if any, associated with Var.
26692712 /// computeSizeAndOffsets - Compute the size and offset of all the DIEs.
26702713 ///
26712714 void DwarfDebug::computeSizeAndOffsets() {
2672 // Compute size of compile unit header.
2673 static unsigned Offset =
2674 sizeof(int32_t) + // Length of Compilation Unit Info
2675 sizeof(int16_t) + // DWARF version number
2676 sizeof(int32_t) + // Offset Into Abbrev. Section
2677 sizeof(int8_t); // Pointer Size (in bytes)
2678
2679 computeSizeAndOffset(ModuleCU->getCUDie(), Offset, true);
2715 unsigned PrevOffset = 0;
2716 for (DenseMap::iterator I = CUMap.begin(),
2717 E = CUMap.end(); I != E; ++I) {
2718 // Compute size of compile unit header.
2719 static unsigned Offset = PrevOffset +
2720 sizeof(int32_t) + // Length of Compilation Unit Info
2721 sizeof(int16_t) + // DWARF version number
2722 sizeof(int32_t) + // Offset Into Abbrev. Section
2723 sizeof(int8_t); // Pointer Size (in bytes)
2724 computeSizeAndOffset(I->second->getCUDie(), Offset, true);
2725 PrevOffset = Offset;
2726 }
26802727 }
26812728
26822729 /// EmitSectionSym - Switch to the specified MCSection and emit an assembler
27972844 // Start debug info section.
27982845 Asm->OutStreamer.SwitchSection(
27992846 Asm->getObjFileLowering().getDwarfInfoSection());
2800 DIE *Die = ModuleCU->getCUDie();
2801
2802 // Emit the compile units header.
2803 Asm->OutStreamer.EmitLabel(Asm->GetTempSymbol("info_begin",
2804 ModuleCU->getID()));
2805
2806 // Emit size of content not including length itself
2807 unsigned ContentSize = Die->getSize() +
2808 sizeof(int16_t) + // DWARF version number
2809 sizeof(int32_t) + // Offset Into Abbrev. Section
2810 sizeof(int8_t) + // Pointer Size (in bytes)
2811 sizeof(int32_t); // FIXME - extra pad for gdb bug.
2812
2813 Asm->OutStreamer.AddComment("Length of Compilation Unit Info");
2814 Asm->EmitInt32(ContentSize);
2815 Asm->OutStreamer.AddComment("DWARF version number");
2816 Asm->EmitInt16(dwarf::DWARF_VERSION);
2817 Asm->OutStreamer.AddComment("Offset Into Abbrev. Section");
2818 Asm->EmitSectionOffset(Asm->GetTempSymbol("abbrev_begin"),
2819 DwarfAbbrevSectionSym);
2820 Asm->OutStreamer.AddComment("Address Size (in bytes)");
2821 Asm->EmitInt8(Asm->getTargetData().getPointerSize());
2822
2823 emitDIE(Die);
2824 // FIXME - extra padding for gdb bug.
2825 Asm->OutStreamer.AddComment("4 extra padding bytes for GDB");
2826 Asm->EmitInt8(0);
2827 Asm->EmitInt8(0);
2828 Asm->EmitInt8(0);
2829 Asm->EmitInt8(0);
2830 Asm->OutStreamer.EmitLabel(Asm->GetTempSymbol("info_end", ModuleCU->getID()));
2847 for (DenseMap::iterator I = CUMap.begin(),
2848 E = CUMap.end(); I != E; ++I) {
2849 CompileUnit *TheCU = I->second;
2850 DIE *Die = TheCU->getCUDie();
2851
2852 // Emit the compile units header.
2853 Asm->OutStreamer.EmitLabel(Asm->GetTempSymbol("info_begin",
2854 TheCU->getID()));
2855
2856 // Emit size of content not including length itself
2857 unsigned ContentSize = Die->getSize() +
2858 sizeof(int16_t) + // DWARF version number
2859 sizeof(int32_t) + // Offset Into Abbrev. Section
2860 sizeof(int8_t) + // Pointer Size (in bytes)
2861 sizeof(int32_t); // FIXME - extra pad for gdb bug.
2862
2863 Asm->OutStreamer.AddComment("Length of Compilation Unit Info");
2864 Asm->EmitInt32(ContentSize);
2865 Asm->OutStreamer.AddComment("DWARF version number");
2866 Asm->EmitInt16(dwarf::DWARF_VERSION);
2867 Asm->OutStreamer.AddComment("Offset Into Abbrev. Section");
2868 Asm->EmitSectionOffset(Asm->GetTempSymbol("abbrev_begin"),
2869 DwarfAbbrevSectionSym);
2870 Asm->OutStreamer.AddComment("Address Size (in bytes)");
2871 Asm->EmitInt8(Asm->getTargetData().getPointerSize());
2872
2873 emitDIE(Die);
2874 // FIXME - extra padding for gdb bug.
2875 Asm->OutStreamer.AddComment("4 extra padding bytes for GDB");
2876 Asm->EmitInt8(0);
2877 Asm->EmitInt8(0);
2878 Asm->EmitInt8(0);
2879 Asm->EmitInt8(0);
2880 Asm->OutStreamer.EmitLabel(Asm->GetTempSymbol("info_end", TheCU->getID()));
2881 }
28312882 }
28322883
28332884 /// emitAbbreviations - Emit the abbreviation section.
31523203 /// emitDebugPubNames - Emit visible names into a debug pubnames section.
31533204 ///
31543205 void DwarfDebug::emitDebugPubNames() {
3155 // Start the dwarf pubnames section.
3156 Asm->OutStreamer.SwitchSection(
3157 Asm->getObjFileLowering().getDwarfPubNamesSection());
3158
3159 Asm->OutStreamer.AddComment("Length of Public Names Info");
3160 Asm->EmitLabelDifference(
3161 Asm->GetTempSymbol("pubnames_end", ModuleCU->getID()),
3162 Asm->GetTempSymbol("pubnames_begin", ModuleCU->getID()), 4);
3163
3164 Asm->OutStreamer.EmitLabel(Asm->GetTempSymbol("pubnames_begin",
3165 ModuleCU->getID()));
3166
3167 Asm->OutStreamer.AddComment("DWARF Version");
3168 Asm->EmitInt16(dwarf::DWARF_VERSION);
3169
3170 Asm->OutStreamer.AddComment("Offset of Compilation Unit Info");
3171 Asm->EmitSectionOffset(Asm->GetTempSymbol("info_begin", ModuleCU->getID()),
3172 DwarfInfoSectionSym);
3173
3174 Asm->OutStreamer.AddComment("Compilation Unit Length");
3175 Asm->EmitLabelDifference(Asm->GetTempSymbol("info_end", ModuleCU->getID()),
3176 Asm->GetTempSymbol("info_begin", ModuleCU->getID()),
3177 4);
3178
3179 const StringMap &Globals = ModuleCU->getGlobals();
3180 for (StringMap::const_iterator
3181 GI = Globals.begin(), GE = Globals.end(); GI != GE; ++GI) {
3182 const char *Name = GI->getKeyData();
3183 DIE *Entity = GI->second;
3184
3185 Asm->OutStreamer.AddComment("DIE offset");
3186 Asm->EmitInt32(Entity->getOffset());
3206 for (DenseMap::iterator I = CUMap.begin(),
3207 E = CUMap.end(); I != E; ++I) {
3208 CompileUnit *TheCU = I->second;
3209 // Start the dwarf pubnames section.
3210 Asm->OutStreamer.SwitchSection(
3211 Asm->getObjFileLowering().getDwarfPubNamesSection());
31873212
3188 if (Asm->isVerbose())
3189 Asm->OutStreamer.AddComment("External Name");
3190 Asm->OutStreamer.EmitBytes(StringRef(Name, strlen(Name)+1), 0);
3191 }
3192
3193 Asm->OutStreamer.AddComment("End Mark");
3194 Asm->EmitInt32(0);
3195 Asm->OutStreamer.EmitLabel(Asm->GetTempSymbol("pubnames_end",
3196 ModuleCU->getID()));
3213 Asm->OutStreamer.AddComment("Length of Public Names Info");
3214 Asm->EmitLabelDifference(
3215 Asm->GetTempSymbol("pubnames_end", TheCU->getID()),
3216 Asm->GetTempSymbol("pubnames_begin", TheCU->getID()), 4);
3217
3218 Asm->OutStreamer.EmitLabel(Asm->GetTempSymbol("pubnames_begin",
3219 TheCU->getID()));
3220
3221 Asm->OutStreamer.AddComment("DWARF Version");
3222 Asm->EmitInt16(dwarf::DWARF_VERSION);
3223
3224 Asm->OutStreamer.AddComment("Offset of Compilation Unit Info");
3225 Asm->EmitSectionOffset(Asm->GetTempSymbol("info_begin", TheCU->getID()),
3226 DwarfInfoSectionSym);
3227
3228 Asm->OutStreamer.AddComment("Compilation Unit Length");
3229 Asm->EmitLabelDifference(Asm->GetTempSymbol("info_end", TheCU->getID()),
3230 Asm->GetTempSymbol("info_begin", TheCU->getID()),
3231 4);
3232
3233 const StringMap &Globals = TheCU->getGlobals();
3234 for (StringMap::const_iterator
3235 GI = Globals.begin(), GE = Globals.end(); GI != GE; ++GI) {
3236 const char *Name = GI->getKeyData();
3237 DIE *Entity = GI->second;
3238
3239 Asm->OutStreamer.AddComment("DIE offset");
3240 Asm->EmitInt32(Entity->getOffset());
3241
3242 if (Asm->isVerbose())
3243 Asm->OutStreamer.AddComment("External Name");
3244 Asm->OutStreamer.EmitBytes(StringRef(Name, strlen(Name)+1), 0);
3245 }
3246
3247 Asm->OutStreamer.AddComment("End Mark");
3248 Asm->EmitInt32(0);
3249 Asm->OutStreamer.EmitLabel(Asm->GetTempSymbol("pubnames_end",
3250 TheCU->getID()));
3251 }
31973252 }
31983253
31993254 void DwarfDebug::emitDebugPubTypes() {
3200 // Start the dwarf pubnames section.
3201 Asm->OutStreamer.SwitchSection(
3202 Asm->getObjFileLowering().getDwarfPubTypesSection());
3203 Asm->OutStreamer.AddComment("Length of Public Types Info");
3204 Asm->EmitLabelDifference(
3205 Asm->GetTempSymbol("pubtypes_end", ModuleCU->getID()),
3206 Asm->GetTempSymbol("pubtypes_begin", ModuleCU->getID()), 4);
3207
3208 Asm->OutStreamer.EmitLabel(Asm->GetTempSymbol("pubtypes_begin",
3209 ModuleCU->getID()));
3210
3211 if (Asm->isVerbose()) Asm->OutStreamer.AddComment("DWARF Version");
3212 Asm->EmitInt16(dwarf::DWARF_VERSION);
3213
3214 Asm->OutStreamer.AddComment("Offset of Compilation ModuleCU Info");
3215 Asm->EmitSectionOffset(Asm->GetTempSymbol("info_begin", ModuleCU->getID()),
3216 DwarfInfoSectionSym);
3217
3218 Asm->OutStreamer.AddComment("Compilation ModuleCU Length");
3219 Asm->EmitLabelDifference(Asm->GetTempSymbol("info_end", ModuleCU->getID()),
3220 Asm->GetTempSymbol("info_begin", ModuleCU->getID()),
3221 4);
3222
3223 const StringMap &Globals = ModuleCU->getGlobalTypes();
3224 for (StringMap::const_iterator
3225 GI = Globals.begin(), GE = Globals.end(); GI != GE; ++GI) {
3226 const char *Name = GI->getKeyData();
3227 DIE * Entity = GI->second;
3228
3229 if (Asm->isVerbose()) Asm->OutStreamer.AddComment("DIE offset");
3230 Asm->EmitInt32(Entity->getOffset());
3255 for (DenseMap::iterator I = CUMap.begin(),
3256 E = CUMap.end(); I != E; ++I) {
3257 CompileUnit *TheCU = I->second;
3258 // Start the dwarf pubnames section.
3259 Asm->OutStreamer.SwitchSection(
3260 Asm->getObjFileLowering().getDwarfPubTypesSection());
3261 Asm->OutStreamer.AddComment("Length of Public Types Info");
3262 Asm->EmitLabelDifference(
3263 Asm->GetTempSymbol("pubtypes_end", TheCU->getID()),
3264 Asm->GetTempSymbol("pubtypes_begin", TheCU->getID()), 4);
32313265
3232 if (Asm->isVerbose()) Asm->OutStreamer.AddComment("External Name");
3233 Asm->OutStreamer.EmitBytes(StringRef(Name, GI->getKeyLength()+1), 0);
3234 }
3235
3236 Asm->OutStreamer.AddComment("End Mark");
3237 Asm->EmitInt32(0);
3238 Asm->OutStreamer.EmitLabel(Asm->GetTempSymbol("pubtypes_end",
3239 ModuleCU->getID()));
3266 Asm->OutStreamer.EmitLabel(Asm->GetTempSymbol("pubtypes_begin",
3267 TheCU->getID()));
3268
3269 if (Asm->isVerbose()) Asm->OutStreamer.AddComment("DWARF Version");
3270 Asm->EmitInt16(dwarf::DWARF_VERSION);
3271
3272 Asm->OutStreamer.AddComment("Offset of Compilation Unit Info");
3273 Asm->EmitSectionOffset(Asm->GetTempSymbol("info_begin", TheCU->getID()),
3274 DwarfInfoSectionSym);
3275
3276 Asm->OutStreamer.AddComment("Compilation Unit Length");
3277 Asm->EmitLabelDifference(Asm->GetTempSymbol("info_end", TheCU->getID()),
3278 Asm->GetTempSymbol("info_begin", TheCU->getID()),
3279 4);
3280
3281 const StringMap &Globals = TheCU->getGlobalTypes();
3282 for (StringMap::const_iterator
3283 GI = Globals.begin(), GE = Globals.end(); GI != GE; ++GI) {
3284 const char *Name = GI->getKeyData();
3285 DIE * Entity = GI->second;
3286
3287 if (Asm->isVerbose()) Asm->OutStreamer.AddComment("DIE offset");
3288 Asm->EmitInt32(Entity->getOffset());
3289
3290 if (Asm->isVerbose()) Asm->OutStreamer.AddComment("External Name");
3291 Asm->OutStreamer.EmitBytes(StringRef(Name, GI->getKeyLength()+1), 0);
3292 }
3293
3294 Asm->OutStreamer.AddComment("End Mark");
3295 Asm->EmitInt32(0);
3296 Asm->OutStreamer.EmitLabel(Asm->GetTempSymbol("pubtypes_end",
3297 TheCU->getID()));
3298 }
32403299 }
32413300
32423301 /// emitDebugStr - Emit visible names into a debug str section.
33343393 if (!Asm->MAI->doesDwarfUsesInlineInfoSection())
33353394 return;
33363395
3337 if (!ModuleCU)
3396 if (!FirstCU)
33383397 return;
33393398
33403399 Asm->OutStreamer.SwitchSection(
8181 // Attributes used to construct specific Dwarf sections.
8282 //
8383
84 /// ModuleCU - All DIEs are inserted in ModuleCU.
85 CompileUnit *ModuleCU;
84 CompileUnit *FirstCU;
85 DenseMap CUMap;
8686
8787 /// AbbreviationsSet - Used to uniquely define abbreviations.
8888 ///
505505 /// maps as well.
506506 unsigned GetOrCreateSourceID(StringRef DirName, StringRef FileName);
507507
508 /// constructCompileUnit - Create new CompileUnit for the given
509 /// metadata node with tag DW_TAG_compile_unit.
508510 void constructCompileUnit(const MDNode *N);
509511
512 /// getCompielUnit - Get CompileUnit DIE.
513 CompileUnit *getCompileUnit(const MDNode *N) const;
514
515 /// constructGlobalVariableDIE - Construct global variable DIE.
510516 void constructGlobalVariableDIE(const MDNode *N);
511517
518 /// construct SubprogramDIE - Construct subprogram DIE.
512519 void constructSubprogramDIE(const MDNode *N);
513520
514521 // FIXME: This should go away in favor of complex addresses.
0 ; RUN: llc -O0 -asm-verbose %s -o %t
1 ; RUN: grep DW_TAG_compile_unit %t | count 3
2 ; One for a.c, second one for b.c and third one for abbrev.
3
4 define i32 @foo() nounwind readnone ssp {
5 return:
6 ret i32 42, !dbg !0
7 }
8
9 define i32 @bar() nounwind readnone ssp {
10 return:
11 ret i32 21, !dbg !8
12 }
13
14 !0 = metadata !{i32 3, i32 0, metadata !1, null}
15 !1 = metadata !{i32 524299, metadata !2, i32 2, i32 0} ; [ DW_TAG_lexical_block ]
16 !2 = metadata !{i32 524334, i32 0, metadata !3, metadata !"foo", metadata !"foo", metadata !"foo", metadata !3, i32 2, metadata !5, i1 false, i1 true, i32 0, i32 0, null, i1 false, i1 false} ; [ DW_TAG_subprogram ]
17 !3 = metadata !{i32 524329, metadata !"a.c", metadata !"/tmp/", metadata !4} ; [ DW_TAG_file_type ]
18 !4 = metadata !{i32 524305, i32 0, i32 1, metadata !"a.c", metadata !"/tmp/", metadata !"4.2.1 (Based on Apple Inc. build 5658) (LLVM build)", i1 true, i1 false, metadata !"", i32 0} ; [ DW_TAG_compile_unit ]
19 !5 = metadata !{i32 524309, metadata !3, metadata !"", metadata !3, i32 0, i64 0, i64 0, i64 0, i32 0, null, metadata !6, i32 0, null} ; [ DW_TAG_subroutine_type ]
20 !6 = metadata !{metadata !7}
21 !7 = metadata !{i32 524324, metadata !3, metadata !"int", metadata !3, i32 0, i64 32, i64 32, i64 0, i32 0, i32 5} ; [ DW_TAG_base_type ]
22 !8 = metadata !{i32 3, i32 0, metadata !9, null}
23 !9 = metadata !{i32 524299, metadata !10, i32 2, i32 0} ; [ DW_TAG_lexical_block ]
24 !10 = metadata !{i32 524334, i32 0, metadata !11, metadata !"bar", metadata !"bar", metadata !"bar", metadata !11, i32 2, metadata !13, i1 false, i1 true, i32 0, i32 0, null, i1 false, i1 false} ; [ DW_TAG_subprogram ]
25 !11 = metadata !{i32 524329, metadata !"b.c", metadata !"/tmp/", metadata !12} ; [ DW_TAG_file_type ]
26 !12 = metadata !{i32 524305, i32 0, i32 1, metadata !"b.c", metadata !"/tmp/", metadata !"4.2.1 (Based on Apple Inc. build 5658) (LLVM build)", i1 true, i1 false, metadata !"", i32 0} ; [ DW_TAG_compile_unit ]
27 !13 = metadata !{i32 524309, metadata !11, metadata !"", metadata !11, i32 0, i64 0, i64 0, i64 0, i32 0, null, metadata !14, i32 0, null} ; [ DW_TAG_subroutine_type ]
28 !14 = metadata !{metadata !15}
29 !15 = metadata !{i32 524324, metadata !11, metadata !"int", metadata !11, i32 0, i64 32, i64 32, i64 0, i32 0, i32 5} ; [ DW_TAG_base_type ]