llvm.org GIT mirror llvm / cf8a4a5
DebugInfo: Add metadata support for disabling DWARF pub sections In cases where the debugger load time is a worthwhile tradeoff (or less costly - such as loading from a DWP instead of a variety of DWOs (possibly over a high-latency/distributed filesystem)) against object file size, it can be reasonable to disable pubnames and corresponding gdb-index creation in the linker. A backend-flag version of this was implemented for NVPTX in D44385/r327994 - which was fine for NVPTX which wouldn't mix-and-match CUs. Now that it's going to be a user-facing option (likely powered by "-gno-pubnames", the same as GCC) it should be encoded in the DICompileUnit so it can vary per-CU. After this, likely the NVPTX support should be migrated to the metadata & the previous flag implementation should be removed. Reviewers: aprantl Differential Revision: https://reviews.llvm.org/D50213 git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@339939 91177308-0d34-0410-b5e6-96231b3b80d8 David Blaikie 2 years ago
27 changed file(s) with 298 addition(s) and 85 deletion(s). Raw diff Collapse all Expand all
133133 /// \param SplitDebugInlining Whether to emit inline debug info.
134134 /// \param DebugInfoForProfiling Whether to emit extra debug info for
135135 /// profile collection.
136 /// \param GnuPubnames Whether to emit .debug_gnu_pubnames section instead
137 /// of .debug_pubnames.
136 /// \param nameTableKind Whether to emit .debug_gnu_pubnames,
137 /// .debug_pubnames, or no pubnames at all.
138138 DICompileUnit *
139139 createCompileUnit(unsigned Lang, DIFile *File, StringRef Producer,
140140 bool isOptimized, StringRef Flags, unsigned RV,
143143 DICompileUnit::DebugEmissionKind::FullDebug,
144144 uint64_t DWOId = 0, bool SplitDebugInlining = true,
145145 bool DebugInfoForProfiling = false,
146 bool GnuPubnames = false);
146 DICompileUnit::DebugNameTableKind NameTableKind =
147 DICompileUnit::DebugNameTableKind::Default);
147148
148149 /// Create a file descriptor to hold debugging information for a file.
149150 /// \param Filename File name.
11701170 LastEmissionKind = DebugDirectivesOnly
11711171 };
11721172
1173 enum class DebugNameTableKind : unsigned {
1174 Default = 0,
1175 GNU = 1,
1176 None = 2,
1177 LastDebugNameTableKind = None
1178 };
1179
11731180 static Optional getEmissionKind(StringRef Str);
11741181 static const char *emissionKindString(DebugEmissionKind EK);
1182 static Optional getNameTableKind(StringRef Str);
1183 static const char *nameTableKindString(DebugNameTableKind PK);
11751184
11761185 private:
11771186 unsigned SourceLanguage;
11811190 uint64_t DWOId;
11821191 bool SplitDebugInlining;
11831192 bool DebugInfoForProfiling;
1184 bool GnuPubnames;
1193 unsigned NameTableKind;
11851194
11861195 DICompileUnit(LLVMContext &C, StorageType Storage, unsigned SourceLanguage,
11871196 bool IsOptimized, unsigned RuntimeVersion,
11881197 unsigned EmissionKind, uint64_t DWOId, bool SplitDebugInlining,
1189 bool DebugInfoForProfiling, bool GnuPubnames, ArrayRef Ops)
1198 bool DebugInfoForProfiling, unsigned NameTableKind,
1199 ArrayRef Ops)
11901200 : DIScope(C, DICompileUnitKind, Storage, dwarf::DW_TAG_compile_unit, Ops),
11911201 SourceLanguage(SourceLanguage), IsOptimized(IsOptimized),
11921202 RuntimeVersion(RuntimeVersion), EmissionKind(EmissionKind),
11931203 DWOId(DWOId), SplitDebugInlining(SplitDebugInlining),
1194 DebugInfoForProfiling(DebugInfoForProfiling), GnuPubnames(GnuPubnames) {
1204 DebugInfoForProfiling(DebugInfoForProfiling),
1205 NameTableKind(NameTableKind) {
11951206 assert(Storage != Uniqued);
11961207 }
11971208 ~DICompileUnit() = default;
12051216 DIGlobalVariableExpressionArray GlobalVariables,
12061217 DIImportedEntityArray ImportedEntities, DIMacroNodeArray Macros,
12071218 uint64_t DWOId, bool SplitDebugInlining, bool DebugInfoForProfiling,
1208 bool GnuPubnames, StorageType Storage, bool ShouldCreate = true) {
1219 unsigned NameTableKind, StorageType Storage,
1220 bool ShouldCreate = true) {
12091221 return getImpl(
12101222 Context, SourceLanguage, File, getCanonicalMDString(Context, Producer),
12111223 IsOptimized, getCanonicalMDString(Context, Flags), RuntimeVersion,
12121224 getCanonicalMDString(Context, SplitDebugFilename), EmissionKind,
12131225 EnumTypes.get(), RetainedTypes.get(), GlobalVariables.get(),
12141226 ImportedEntities.get(), Macros.get(), DWOId, SplitDebugInlining,
1215 DebugInfoForProfiling, GnuPubnames, Storage, ShouldCreate);
1227 DebugInfoForProfiling, NameTableKind, Storage, ShouldCreate);
12161228 }
12171229 static DICompileUnit *
12181230 getImpl(LLVMContext &Context, unsigned SourceLanguage, Metadata *File,
12211233 unsigned EmissionKind, Metadata *EnumTypes, Metadata *RetainedTypes,
12221234 Metadata *GlobalVariables, Metadata *ImportedEntities,
12231235 Metadata *Macros, uint64_t DWOId, bool SplitDebugInlining,
1224 bool DebugInfoForProfiling, bool GnuPubnames, StorageType Storage,
1225 bool ShouldCreate = true);
1236 bool DebugInfoForProfiling, unsigned NameTableKind,
1237 StorageType Storage, bool ShouldCreate = true);
12261238
12271239 TempDICompileUnit cloneImpl() const {
12281240 return getTemporary(getContext(), getSourceLanguage(), getFile(),
12311243 getEmissionKind(), getEnumTypes(), getRetainedTypes(),
12321244 getGlobalVariables(), getImportedEntities(),
12331245 getMacros(), DWOId, getSplitDebugInlining(),
1234 getDebugInfoForProfiling(), getGnuPubnames());
1246 getDebugInfoForProfiling(), getNameTableKind());
12351247 }
12361248
12371249 public:
12471259 DIGlobalVariableExpressionArray GlobalVariables,
12481260 DIImportedEntityArray ImportedEntities, DIMacroNodeArray Macros,
12491261 uint64_t DWOId, bool SplitDebugInlining, bool DebugInfoForProfiling,
1250 bool GnuPubnames),
1262 DebugNameTableKind NameTableKind),
12511263 (SourceLanguage, File, Producer, IsOptimized, Flags, RuntimeVersion,
12521264 SplitDebugFilename, EmissionKind, EnumTypes, RetainedTypes,
12531265 GlobalVariables, ImportedEntities, Macros, DWOId, SplitDebugInlining,
1254 DebugInfoForProfiling, GnuPubnames))
1266 DebugInfoForProfiling, (unsigned)NameTableKind))
12551267 DEFINE_MDNODE_GET_DISTINCT_TEMPORARY(
12561268 DICompileUnit,
12571269 (unsigned SourceLanguage, Metadata *File, MDString *Producer,
12591271 MDString *SplitDebugFilename, unsigned EmissionKind, Metadata *EnumTypes,
12601272 Metadata *RetainedTypes, Metadata *GlobalVariables,
12611273 Metadata *ImportedEntities, Metadata *Macros, uint64_t DWOId,
1262 bool SplitDebugInlining, bool DebugInfoForProfiling, bool GnuPubnames),
1274 bool SplitDebugInlining, bool DebugInfoForProfiling,
1275 unsigned NameTableKind),
12631276 (SourceLanguage, File, Producer, IsOptimized, Flags, RuntimeVersion,
12641277 SplitDebugFilename, EmissionKind, EnumTypes, RetainedTypes,
12651278 GlobalVariables, ImportedEntities, Macros, DWOId, SplitDebugInlining,
1266 DebugInfoForProfiling, GnuPubnames))
1279 DebugInfoForProfiling, NameTableKind))
12671280
12681281 TempDICompileUnit clone() const { return cloneImpl(); }
12691282
12771290 return EmissionKind == DebugDirectivesOnly;
12781291 }
12791292 bool getDebugInfoForProfiling() const { return DebugInfoForProfiling; }
1280 bool getGnuPubnames() const { return GnuPubnames; }
1293 DebugNameTableKind getNameTableKind() const {
1294 return (DebugNameTableKind)NameTableKind;
1295 }
12811296 StringRef getProducer() const { return getStringOperand(1); }
12821297 StringRef getFlags() const { return getStringOperand(2); }
12831298 StringRef getSplitDebugFilename() const { return getStringOperand(3); }
909909 return lltok::EmissionKind;
910910 }
911911
912 if (Keyword == "GNU" || Keyword == "None" || Keyword == "Default") {
913 StrVal.assign(Keyword.begin(), Keyword.end());
914 return lltok::NameTableKind;
915 }
916
912917 // Check for [us]0x[0-9A-Fa-f]+ which are Hexadecimal constant generated by
913918 // the CFE to avoid forcing it to deal with 64-bit numbers.
914919 if ((TokStart[0] == 'u' || TokStart[0] == 's') &&
37173717 EmissionKindField() : MDUnsignedField(0, DICompileUnit::LastEmissionKind) {}
37183718 };
37193719
3720 struct NameTableKindField : public MDUnsignedField {
3721 NameTableKindField()
3722 : MDUnsignedField(
3723 0, (unsigned)
3724 DICompileUnit::DebugNameTableKind::LastDebugNameTableKind) {}
3725 };
3726
37203727 struct DIFlagField : public MDFieldImpl {
37213728 DIFlagField() : MDFieldImpl(DINode::FlagZero) {}
37223729 };
39313938 "'");
39323939 assert(*Kind <= Result.Max && "Expected valid emission kind");
39333940 Result.assign(*Kind);
3941 Lex.Lex();
3942 return false;
3943 }
3944
3945 template <>
3946 bool LLParser::ParseMDField(LocTy Loc, StringRef Name,
3947 NameTableKindField &Result) {
3948 if (Lex.getKind() == lltok::APSInt)
3949 return ParseMDField(Loc, Name, static_cast(Result));
3950
3951 if (Lex.getKind() != lltok::NameTableKind)
3952 return TokError("expected nameTable kind");
3953
3954 auto Kind = DICompileUnit::getNameTableKind(Lex.getStrVal());
3955 if (!Kind)
3956 return TokError("invalid nameTable kind" + Twine(" '") + Lex.getStrVal() +
3957 "'");
3958 assert(((unsigned)*Kind) <= Result.Max && "Expected valid nameTable kind");
3959 Result.assign((unsigned)*Kind);
39343960 Lex.Lex();
39353961 return false;
39363962 }
44474473 OPTIONAL(dwoId, MDUnsignedField, ); \
44484474 OPTIONAL(splitDebugInlining, MDBoolField, = true); \
44494475 OPTIONAL(debugInfoForProfiling, MDBoolField, = false); \
4450 OPTIONAL(gnuPubnames, MDBoolField, = false);
4476 OPTIONAL(nameTableKind, NameTableKindField, );
44514477 PARSE_MD_FIELDS();
44524478 #undef VISIT_MD_FIELDS
44534479
44554481 Context, language.Val, file.Val, producer.Val, isOptimized.Val, flags.Val,
44564482 runtimeVersion.Val, splitDebugFilename.Val, emissionKind.Val, enums.Val,
44574483 retainedTypes.Val, globals.Val, imports.Val, macros.Val, dwoId.Val,
4458 splitDebugInlining.Val, debugInfoForProfiling.Val, gnuPubnames.Val);
4484 splitDebugInlining.Val, debugInfoForProfiling.Val, nameTableKind.Val);
44594485 return false;
44604486 }
44614487
433433 DwarfLang, // DW_LANG_foo
434434 DwarfCC, // DW_CC_foo
435435 EmissionKind, // lineTablesOnly
436 NameTableKind, // GNU
436437 DwarfOp, // DW_OP_foo
437438 DIFlag, // DIFlagFoo
438439 DwarfMacinfo, // DW_MACINFO_foo
13921392 Record.size() <= 14 ? 0 : Record[14],
13931393 Record.size() <= 16 ? true : Record[16],
13941394 Record.size() <= 17 ? false : Record[17],
1395 Record.size() <= 18 ? false : Record[18]);
1395 Record.size() <= 18 ? 0 : Record[18]);
13961396
13971397 MetadataList.assignValue(CU, NextMetadataNo);
13981398 NextMetadataNo++;
16021602 Record.push_back(VE.getMetadataOrNullID(N->getMacros().get()));
16031603 Record.push_back(N->getSplitDebugInlining());
16041604 Record.push_back(N->getDebugInfoForProfiling());
1605 Record.push_back(N->getGnuPubnames());
1605 Record.push_back((unsigned)N->getNameTableKind());
16061606
16071607 Stream.EmitRecord(bitc::METADATA_COMPILE_UNIT, Record, Abbrev);
16081608 Record.clear();
2222 #include "llvm/MC/MCStreamer.h"
2323 #include "llvm/MC/MCSymbol.h"
2424 #include "llvm/Support/raw_ostream.h"
25 #include "llvm/Target/TargetLoweringObjectFile.h"
2526 #include
2627 #include
2728 #include
553554 const DwarfDebug &DD, ArrayRef> CUs) {
554555 std::vector CompUnits;
555556 for (const auto &CU : enumerate(CUs)) {
557 if (CU.value()->getCUNode()->getNameTableKind() ==
558 DICompileUnit::DebugNameTableKind::None)
559 continue;
556560 assert(CU.index() == CU.value()->getUniqueID());
557561 const DwarfCompileUnit *MainCU =
558562 DD.useSplitDwarf() ? CU.value()->getSkeleton() : CU.value().get();
559563 CompUnits.push_back(MainCU->getLabelBegin());
560564 }
565
566 if (CompUnits.empty())
567 return;
568
569 Asm->OutStreamer->SwitchSection(
570 Asm->getObjFileLowering().getDwarfDebugNamesSection());
561571
562572 Contents.finalize(Asm, "names");
563573 Dwarf5AccelTableWriter(
248248 addLinkageName(*VariableDIE, GV->getLinkageName());
249249
250250 if (addToAccelTable) {
251 DD->addAccelName(GV->getName(), *VariableDIE);
251 DD->addAccelName(*CUNode, GV->getName(), *VariableDIE);
252252
253253 // If the linkage name is different than the name, go ahead and output
254254 // that as well into the name table.
255255 if (GV->getLinkageName() != "" && GV->getName() != GV->getLinkageName() &&
256256 DD->useAllLinkageNames())
257 DD->addAccelName(GV->getLinkageName(), *VariableDIE);
257 DD->addAccelName(*CUNode, GV->getLinkageName(), *VariableDIE);
258258 }
259259
260260 return VariableDIE;
347347
348348 // Add name to the name table, we do this here because we're guaranteed
349349 // to have concrete versions of our DW_TAG_subprogram nodes.
350 DD->addSubprogramNames(SP, *SPDie);
350 DD->addSubprogramNames(*CUNode, SP, *SPDie);
351351
352352 return *SPDie;
353353 }
485485
486486 // Add name to the name table, we do this here because we're guaranteed
487487 // to have concrete versions of our DW_TAG_inlined_subprogram nodes.
488 DD->addSubprogramNames(InlinedSP, *ScopeDIE);
488 DD->addSubprogramNames(*CUNode, InlinedSP, *ScopeDIE);
489489
490490 return ScopeDIE;
491491 }
882882 }
883883
884884 bool DwarfCompileUnit::hasDwarfPubSections() const {
885 // Opting in to GNU Pubnames/types overrides the default to ensure these are
886 // generated for things like Gold's gdb_index generation.
887 if (CUNode->getGnuPubnames())
885 switch (CUNode->getNameTableKind()) {
886 case DICompileUnit::DebugNameTableKind::None:
887 return false;
888 // Opting in to GNU Pubnames/types overrides the default to ensure these are
889 // generated for things like Gold's gdb_index generation.
890 case DICompileUnit::DebugNameTableKind::GNU:
888891 return true;
889
890 return DD->tuneForGDB() && DD->usePubSections() &&
891 !includeMinimalInlineScopes() && !CUNode->isDebugDirectivesOnly();
892 case DICompileUnit::DebugNameTableKind::Default:
893 return DD->tuneForGDB() && DD->usePubSections() &&
894 !includeMinimalInlineScopes() && !CUNode->isDebugDirectivesOnly();
895 }
892896 }
893897
894898 /// addGlobalName - Add a new global name to the compile unit.
420420 }
421421
422422 // Add the various names to the Dwarf accelerator table names.
423 void DwarfDebug::addSubprogramNames(const DISubprogram *SP, DIE &Die) {
423 void DwarfDebug::addSubprogramNames(const DICompileUnit &CU,
424 const DISubprogram *SP, DIE &Die) {
425 if (getAccelTableKind() != AccelTableKind::Apple &&
426 CU.getNameTableKind() == DICompileUnit::DebugNameTableKind::None)
427 return;
428
424429 if (!SP->isDefinition())
425430 return;
426431
427432 if (SP->getName() != "")
428 addAccelName(SP->getName(), Die);
433 addAccelName(CU, SP->getName(), Die);
429434
430435 // If the linkage name is different than the name, go ahead and output that as
431436 // well into the name table. Only do that if we are going to actually emit
432437 // that name.
433438 if (SP->getLinkageName() != "" && SP->getName() != SP->getLinkageName() &&
434439 (useAllLinkageNames() || InfoHolder.getAbstractSPDies().lookup(SP)))
435 addAccelName(SP->getLinkageName(), Die);
440 addAccelName(CU, SP->getLinkageName(), Die);
436441
437442 // If this is an Objective-C selector name add it to the ObjC accelerator
438443 // too.
439444 if (isObjCClass(SP->getName())) {
440445 StringRef Class, Category;
441446 getObjCClassCategory(SP->getName(), Class, Category);
442 addAccelObjC(Class, Die);
447 addAccelObjC(CU, Class, Die);
443448 if (Category != "")
444 addAccelObjC(Category, Die);
449 addAccelObjC(CU, Category, Die);
445450 // Also add the base method name to the name table.
446 addAccelName(getObjCMethodName(SP->getName()), Die);
451 addAccelName(CU, getObjCMethodName(SP->getName()), Die);
447452 }
448453 }
449454
15361541 if (getUnits().empty())
15371542 return;
15381543
1539 Asm->OutStreamer->SwitchSection(
1540 Asm->getObjFileLowering().getDwarfDebugNamesSection());
15411544 emitDWARF5AccelTable(Asm, AccelDebugNames, *this, getUnits());
15421545 }
15431546
16421645 if (!TheU->hasDwarfPubSections())
16431646 continue;
16441647
1645 bool GnuStyle = TheU->getCUNode()->getGnuPubnames();
1648 bool GnuStyle = TheU->getCUNode()->getNameTableKind() ==
1649 DICompileUnit::DebugNameTableKind::GNU;
16461650
16471651 Asm->OutStreamer->SwitchSection(
16481652 GnuStyle ? Asm->getObjFileLowering().getDwarfGnuPubNamesSection()
24302434 // AccelTableKind::Apple, we use the table we got as an argument). If
24312435 // accelerator tables are disabled, this function does nothing.
24322436 template
2433 void DwarfDebug::addAccelNameImpl(AccelTable &AppleAccel, StringRef Name,
2437 void DwarfDebug::addAccelNameImpl(const DICompileUnit &CU,
2438 AccelTable &AppleAccel, StringRef Name,
24342439 const DIE &Die) {
24352440 if (getAccelTableKind() == AccelTableKind::None)
2441 return;
2442
2443 if (getAccelTableKind() != AccelTableKind::Apple &&
2444 CU.getNameTableKind() == DICompileUnit::DebugNameTableKind::None)
24362445 return;
24372446
24382447 DwarfFile &Holder = useSplitDwarf() ? SkeletonHolder : InfoHolder;
24522461 }
24532462 }
24542463
2455 void DwarfDebug::addAccelName(StringRef Name, const DIE &Die) {
2456 addAccelNameImpl(AccelNames, Name, Die);
2457 }
2458
2459 void DwarfDebug::addAccelObjC(StringRef Name, const DIE &Die) {
2464 void DwarfDebug::addAccelName(const DICompileUnit &CU, StringRef Name,
2465 const DIE &Die) {
2466 addAccelNameImpl(CU, AccelNames, Name, Die);
2467 }
2468
2469 void DwarfDebug::addAccelObjC(const DICompileUnit &CU, StringRef Name,
2470 const DIE &Die) {
24602471 // ObjC names go only into the Apple accelerator tables.
24612472 if (getAccelTableKind() == AccelTableKind::Apple)
2462 addAccelNameImpl(AccelObjC, Name, Die);
2463 }
2464
2465 void DwarfDebug::addAccelNamespace(StringRef Name, const DIE &Die) {
2466 addAccelNameImpl(AccelNamespace, Name, Die);
2467 }
2468
2469 void DwarfDebug::addAccelType(StringRef Name, const DIE &Die, char Flags) {
2470 addAccelNameImpl(AccelTypes, Name, Die);
2473 addAccelNameImpl(CU, AccelObjC, Name, Die);
2474 }
2475
2476 void DwarfDebug::addAccelNamespace(const DICompileUnit &CU, StringRef Name,
2477 const DIE &Die) {
2478 addAccelNameImpl(CU, AccelNamespace, Name, Die);
2479 }
2480
2481 void DwarfDebug::addAccelType(const DICompileUnit &CU, StringRef Name,
2482 const DIE &Die, char Flags) {
2483 addAccelNameImpl(CU, AccelTypes, Name, Die);
24712484 }
24722485
24732486 uint16_t DwarfDebug::getDwarfVersion() const {
345345 void constructAbstractSubprogramScopeDIE(DwarfCompileUnit &SrcCU, LexicalScope *Scope);
346346
347347 template
348 void addAccelNameImpl(AccelTable &AppleAccel, StringRef Name,
349 const DIE &Die);
348 void addAccelNameImpl(const DICompileUnit &CU, AccelTable &AppleAccel,
349 StringRef Name, const DIE &Die);
350350
351351 void finishVariableDefinitions();
352352
607607 return Ref.resolve();
608608 }
609609
610 void addSubprogramNames(const DISubprogram *SP, DIE &Die);
610 void addSubprogramNames(const DICompileUnit &CU, const DISubprogram *SP,
611 DIE &Die);
611612
612613 AddressPool &getAddressPool() { return AddrPool; }
613614
614 void addAccelName(StringRef Name, const DIE &Die);
615
616 void addAccelObjC(StringRef Name, const DIE &Die);
617
618 void addAccelNamespace(StringRef Name, const DIE &Die);
619
620 void addAccelType(StringRef Name, const DIE &Die, char Flags);
615 void addAccelName(const DICompileUnit &CU, StringRef Name, const DIE &Die);
616
617 void addAccelObjC(const DICompileUnit &CU, StringRef Name, const DIE &Die);
618
619 void addAccelNamespace(const DICompileUnit &CU, StringRef Name,
620 const DIE &Die);
621
622 void addAccelType(const DICompileUnit &CU, StringRef Name, const DIE &Die,
623 char Flags);
621624
622625 const MachineFunction *getCurrentFunction() const { return CurFn; }
623626
794794 IsImplementation = CT->getRuntimeLang() == 0 || CT->isObjcClassComplete();
795795 }
796796 unsigned Flags = IsImplementation ? dwarf::DW_FLAG_type_implementation : 0;
797 DD->addAccelType(Ty->getName(), TyDIE, Flags);
797 DD->addAccelType(*CUNode, Ty->getName(), TyDIE, Flags);
798798
799799 if (!Context || isa(Context) || isa(Context) ||
800800 isa(Context))
11671167 addString(NDie, dwarf::DW_AT_name, NS->getName());
11681168 else
11691169 Name = "(anonymous namespace)";
1170 DD->addAccelNamespace(Name, NDie);
1170 DD->addAccelNamespace(*CUNode, Name, NDie);
11711171 addGlobalName(Name, NDie, NS->getScope());
11721172 if (NS->getExportSymbols())
11731173 addFlag(NDie, dwarf::DW_AT_export_symbols);
14161416 addUInt(*IndexTyDie, dwarf::DW_AT_byte_size, None, sizeof(int64_t));
14171417 addUInt(*IndexTyDie, dwarf::DW_AT_encoding, dwarf::DW_FORM_data1,
14181418 dwarf::DW_ATE_unsigned);
1419 DD->addAccelType(Name, *IndexTyDie, /*Flags*/ 0);
1419 DD->addAccelType(*CUNode, Name, *IndexTyDie, /*Flags*/ 0);
14201420 return IndexTyDie;
14211421 }
14221422
16031603 void printDwarfEnum(StringRef Name, IntTy Value, Stringifier toString,
16041604 bool ShouldSkipZero = true);
16051605 void printEmissionKind(StringRef Name, DICompileUnit::DebugEmissionKind EK);
1606 void printNameTableKind(StringRef Name,
1607 DICompileUnit::DebugNameTableKind NTK);
16061608 };
16071609
16081610 } // end anonymous namespace
16981700 void MDFieldPrinter::printEmissionKind(StringRef Name,
16991701 DICompileUnit::DebugEmissionKind EK) {
17001702 Out << FS << Name << ": " << DICompileUnit::emissionKindString(EK);
1703 }
1704
1705 void MDFieldPrinter::printNameTableKind(StringRef Name,
1706 DICompileUnit::DebugNameTableKind NTK) {
1707 if (NTK == DICompileUnit::DebugNameTableKind::Default)
1708 return;
1709 Out << FS << Name << ": " << DICompileUnit::nameTableKindString(NTK);
17011710 }
17021711
17031712 template
18901899 Printer.printBool("splitDebugInlining", N->getSplitDebugInlining(), true);
18911900 Printer.printBool("debugInfoForProfiling", N->getDebugInfoForProfiling(),
18921901 false);
1893 Printer.printBool("gnuPubnames", N->getGnuPubnames(), false);
1902 Printer.printNameTableKind("nameTableKind", N->getNameTableKind());
18941903 Out << ")";
18951904 }
18961905
138138 unsigned Lang, DIFile *File, StringRef Producer, bool isOptimized,
139139 StringRef Flags, unsigned RunTimeVer, StringRef SplitName,
140140 DICompileUnit::DebugEmissionKind Kind, uint64_t DWOId,
141 bool SplitDebugInlining, bool DebugInfoForProfiling, bool GnuPubnames) {
141 bool SplitDebugInlining, bool DebugInfoForProfiling,
142 DICompileUnit::DebugNameTableKind NameTableKind) {
142143
143144 assert(((Lang <= dwarf::DW_LANG_Fortran08 && Lang >= dwarf::DW_LANG_C89) ||
144145 (Lang <= dwarf::DW_LANG_hi_user && Lang >= dwarf::DW_LANG_lo_user)) &&
148149 CUNode = DICompileUnit::getDistinct(
149150 VMContext, Lang, File, Producer, isOptimized, Flags, RunTimeVer,
150151 SplitName, Kind, nullptr, nullptr, nullptr, nullptr, nullptr, DWOId,
151 SplitDebugInlining, DebugInfoForProfiling, GnuPubnames);
152 SplitDebugInlining, DebugInfoForProfiling, NameTableKind);
152153
153154 // Create a named metadata so that it is easier to find cu in a module.
154155 NamedMDNode *NMD = M.getOrInsertNamedMetadata("llvm.dbg.cu");
490490 CU->getSplitDebugFilename(), DICompileUnit::LineTablesOnly, EnumTypes,
491491 RetainedTypes, GlobalVariables, ImportedEntities, CU->getMacros(),
492492 CU->getDWOId(), CU->getSplitDebugInlining(),
493 CU->getDebugInfoForProfiling(), CU->getGnuPubnames());
493 CU->getDebugInfoForProfiling(), CU->getNameTableKind());
494494 }
495495
496496 DILocation *getReplacementMDLocation(DILocation *MLD) {
449449 unsigned EmissionKind, Metadata *EnumTypes, Metadata *RetainedTypes,
450450 Metadata *GlobalVariables, Metadata *ImportedEntities, Metadata *Macros,
451451 uint64_t DWOId, bool SplitDebugInlining, bool DebugInfoForProfiling,
452 bool GnuPubnames, StorageType Storage, bool ShouldCreate) {
452 unsigned NameTableKind, StorageType Storage, bool ShouldCreate) {
453453 assert(Storage != Uniqued && "Cannot unique DICompileUnit");
454454 assert(isCanonical(Producer) && "Expected canonical MDString");
455455 assert(isCanonical(Flags) && "Expected canonical MDString");
462462 return storeImpl(new (array_lengthof(Ops)) DICompileUnit(
463463 Context, Storage, SourceLanguage, IsOptimized,
464464 RuntimeVersion, EmissionKind, DWOId, SplitDebugInlining,
465 DebugInfoForProfiling, GnuPubnames, Ops),
465 DebugInfoForProfiling, NameTableKind, Ops),
466466 Storage);
467467 }
468468
476476 .Default(None);
477477 }
478478
479 Optional
480 DICompileUnit::getNameTableKind(StringRef Str) {
481 return StringSwitch>(Str)
482 .Case("Default", DebugNameTableKind::Default)
483 .Case("GNU", DebugNameTableKind::GNU)
484 .Case("None", DebugNameTableKind::None)
485 .Default(None);
486 }
487
479488 const char *DICompileUnit::emissionKindString(DebugEmissionKind EK) {
480489 switch (EK) {
481490 case NoDebug: return "NoDebug";
482491 case FullDebug: return "FullDebug";
483492 case LineTablesOnly: return "LineTablesOnly";
484493 case DebugDirectivesOnly: return "DebugDirectviesOnly";
494 }
495 return nullptr;
496 }
497
498 const char *DICompileUnit::nameTableKindString(DebugNameTableKind NTK) {
499 switch (NTK) {
500 case DebugNameTableKind::Default:
501 return nullptr;
502 case DebugNameTableKind::GNU:
503 return "GNU";
504 case DebugNameTableKind::None:
505 return "None";
485506 }
486507 return nullptr;
487508 }
0 ; RUN: llvm-as -disable-verify -o - %s | llvm-dis | FileCheck %s
11
22 !named = !{!0}
3 ; CHECK: !DICompileUnit({{.*}}, gnuPubnames: true)
4 !0 = distinct !DICompileUnit(language: 12, file: !1, gnuPubnames: true)
3 ; CHECK: !DICompileUnit({{.*}}, nameTableKind: GNU)
4 !0 = distinct !DICompileUnit(language: 12, file: !1, nameTableKind: GNU)
55 !1 = !DIFile(filename: "path/to/file", directory: "/path/to/dir")
0 ; REQUIRES: object-emission
1
2 ; Verify that no DWARF v5 names section is emitted when all CUs disable name tables.
3 ; RUN: llc -mtriple x86_64-pc-linux -filetype=obj < %s \
4 ; RUN: | llvm-objdump -h - | FileCheck %s
5
6 ; CHECK-NOT: debug_names
7
8 define dso_local i32 @main() !dbg !7 {
9 entry:
10 ret i32 0, !dbg !11
11 }
12
13 !llvm.dbg.cu = !{!0}
14 !llvm.module.flags = !{!3, !4, !5}
15 !llvm.ident = !{!6}
16
17 !0 = distinct !DICompileUnit(language: DW_LANG_C_plus_plus, file: !1, producer: "clang version 8.0.0 (trunk 339438) (llvm/trunk 339448)", isOptimized: false, runtimeVersion: 0, emissionKind: FullDebug, enums: !2, nameTableKind: None)
18 !1 = !DIFile(filename: "foo.cpp", directory: "/usr/local/google/home/blaikie/dev/scratch", checksumkind: CSK_MD5, checksum: "f881137628fc8dd673b761eb7a1e2432")
19 !2 = !{}
20 !3 = !{i32 2, !"Dwarf Version", i32 5}
21 !4 = !{i32 2, !"Debug Info Version", i32 3}
22 !5 = !{i32 1, !"wchar_size", i32 4}
23 !6 = !{!"clang version 8.0.0 (trunk 339438) (llvm/trunk 339448)"}
24 !7 = distinct !DISubprogram(name: "main", scope: !1, file: !1, line: 1, type: !8, isLocal: false, isDefinition: true, scopeLine: 1, flags: DIFlagPrototyped, isOptimized: false, unit: !0, retainedNodes: !2)
25 !8 = !DISubroutineType(types: !9)
26 !9 = !{!10}
27 !10 = !DIBasicType(name: "int", size: 32, encoding: DW_ATE_signed)
28 !11 = !DILocation(line: 1, column: 13, scope: !7)
0 ; REQUIRES: object-emission
1
2 ; Verify that DWARF v5 debug_names omit names from CUs that opt-out.
3 ; RUN: llc -mtriple x86_64-pc-linux -filetype=obj < %s \
4 ; RUN: | llvm-dwarfdump -debug-names - | FileCheck %s
5
6 ; CHECK: CU count: 1
7
8 ; Check that the one CU that is indexed has a non-zero.
9 ; Avoid checking for a specific offset to make the test more resilient.
10 ; CHECK: Compilation Unit offsets [
11 ; CHECK-NEXT: CU[0]: 0x{{[0-9]*[1-9][0-9]*}}
12 ; CHECK-NEXT: ]
13
14 define dso_local i32 @main() !dbg !9 {
15 entry:
16 ret i32 0, !dbg !13
17 }
18
19 define dso_local void @_Z2f1v() !dbg !14 {
20 entry:
21 ret void, !dbg !17
22 }
23
24 !llvm.dbg.cu = !{!0, !3}
25 !llvm.ident = !{!5, !5}
26 !llvm.module.flags = !{!6, !7, !8}
27
28 !0 = distinct !DICompileUnit(language: DW_LANG_C_plus_plus, file: !1, producer: "clang version 8.0.0 (trunk 339438) (llvm/trunk 339448)", isOptimized: false, runtimeVersion: 0, emissionKind: FullDebug, enums: !2, nameTableKind: None)
29 !1 = !DIFile(filename: "foo.cpp", directory: "/usr/local/google/home/blaikie/dev/scratch", checksumkind: CSK_MD5, checksum: "f881137628fc8dd673b761eb7a1e2432")
30 !2 = !{}
31 !3 = distinct !DICompileUnit(language: DW_LANG_C_plus_plus, file: !4, producer: "clang version 8.0.0 (trunk 339438) (llvm/trunk 339448)", isOptimized: false, runtimeVersion: 0, emissionKind: FullDebug, enums: !2)
32 !4 = !DIFile(filename: "bar.cpp", directory: "/usr/local/google/home/blaikie/dev/scratch", checksumkind: CSK_MD5, checksum: "ba8dae3bceaf6ef87728337164565a87")
33 !5 = !{!"clang version 8.0.0 (trunk 339438) (llvm/trunk 339448)"}
34 !6 = !{i32 2, !"Dwarf Version", i32 5}
35 !7 = !{i32 2, !"Debug Info Version", i32 3}
36 !8 = !{i32 1, !"wchar_size", i32 4}
37 !9 = distinct !DISubprogram(name: "main", scope: !1, file: !1, line: 1, type: !10, isLocal: false, isDefinition: true, scopeLine: 1, flags: DIFlagPrototyped, isOptimized: false, unit: !0, retainedNodes: !2)
38 !10 = !DISubroutineType(types: !11)
39 !11 = !{!12}
40 !12 = !DIBasicType(name: "int", size: 32, encoding: DW_ATE_signed)
41 !13 = !DILocation(line: 1, column: 13, scope: !9)
42 !14 = distinct !DISubprogram(name: "f1", linkageName: "_Z2f1v", scope: !4, file: !4, line: 1, type: !15, isLocal: false, isDefinition: true, scopeLine: 1, flags: DIFlagPrototyped, isOptimized: false, unit: !3, retainedNodes: !2)
43 !15 = !DISubroutineType(types: !16)
44 !16 = !{null}
45 !17 = !DILocation(line: 1, column: 12, scope: !14)
1616 !llvm.dbg.cu = !{!0}
1717 !llvm.module.flags = !{!3, !4}
1818
19 !0 = distinct !DICompileUnit(language: DW_LANG_C99, producer: "clang version 3.4 (trunk 191846) (llvm/trunk 191866)", isOptimized: false, emissionKind: FullDebug, file: !1, enums: !2, retainedTypes: !5, globals: !2, imports: !2, gnuPubnames: true)
19 !0 = distinct !DICompileUnit(language: DW_LANG_C99, producer: "clang version 3.4 (trunk 191846) (llvm/trunk 191866)", isOptimized: false, emissionKind: FullDebug, file: !1, enums: !2, retainedTypes: !5, globals: !2, imports: !2, nameTableKind: GNU)
2020 !1 = !DIFile(filename: "foo.c", directory: "/usr/local/google/home/echristo/tmp")
2121 !2 = !{}
2222 !3 = !{i32 2, !"Dwarf Version", i32 4}
None ; RUN: sed -e 's/gnuPubnames: false/gnuPubnames: true/' %s | llc -mtriple=x86_64-pc-linux-gnu -filetype=obj | llvm-dwarfdump -v - | FileCheck --check-prefix=GPUB %s
0 ; RUN: sed -e 's/nameTableKind: Default/nameTableKind: GNU/' %s | llc -mtriple=x86_64-pc-linux-gnu -filetype=obj | llvm-dwarfdump -v - | FileCheck --check-prefix=GPUB %s
11 ; RUN: llc -mtriple=x86_64-pc-linux-gnu -filetype=obj < %s | llvm-dwarfdump -v - | FileCheck --check-prefix=NONE %s
22
33 ; Generated from:
4545 !llvm.module.flags = !{!3, !4, !5}
4646 !llvm.ident = !{!6}
4747
48 !0 = distinct !DICompileUnit(language: DW_LANG_C_plus_plus, file: !1, producer: "clang version 5.0.0 (trunk 303768) (llvm/trunk 303774)", isOptimized: false, runtimeVersion: 0, emissionKind: LineTablesOnly, enums: !2, gnuPubnames: false)
48 !0 = distinct !DICompileUnit(language: DW_LANG_C_plus_plus, file: !1, producer: "clang version 5.0.0 (trunk 303768) (llvm/trunk 303774)", isOptimized: false, runtimeVersion: 0, emissionKind: LineTablesOnly, enums: !2, nameTableKind: Default)
4949 !1 = !DIFile(filename: "gnu-public-names-gmlt.cpp", directory: "/usr/local/google/home/blaikie/dev/scratch")
5050 !2 = !{}
5151 !3 = !{i32 2, !"Dwarf Version", i32 4}
2222 !8 = !DIGlobalVariableExpression(var: !9, expr: !DIExpression())
2323 !9 = !DIGlobalVariable(name: "b", scope: null, file: !2, line: 2, type: !3, isLocal: false, isDefinition: true)
2424 !10 = !{!8}
25 !11 = distinct !DICompileUnit(language: DW_LANG_C99, file: !2, producer: "clang", isOptimized: true, runtimeVersion: 0, emissionKind: FullDebug, enums: !5, retainedTypes: !5, globals: !10, gnuPubnames: true)
25 !11 = distinct !DICompileUnit(language: DW_LANG_C99, file: !2, producer: "clang", isOptimized: true, runtimeVersion: 0, emissionKind: FullDebug, enums: !5, retainedTypes: !5, globals: !10, nameTableKind: GNU)
3838
3939 !0 = !DIGlobalVariableExpression(var: !1, expr: !DIExpression())
4040 !1 = distinct !DIGlobalVariable(name: "b", scope: !2, file: !3, line: 8, type: !6, isLocal: false, isDefinition: true)
41 !2 = distinct !DICompileUnit(language: DW_LANG_C_plus_plus, file: !3, producer: "clang version 5.0.0 (trunk 293904) (llvm/trunk 293908)", isOptimized: false, runtimeVersion: 0, emissionKind: FullDebug, enums: !4, globals: !5, gnuPubnames: true)
41 !2 = distinct !DICompileUnit(language: DW_LANG_C_plus_plus, file: !3, producer: "clang version 5.0.0 (trunk 293904) (llvm/trunk 293908)", isOptimized: false, runtimeVersion: 0, emissionKind: FullDebug, enums: !4, globals: !5, nameTableKind: GNU)
4242 !3 = !DIFile(filename: "type.cpp", directory: "/tmp/dbginfo")
4343 !4 = !{}
4444 !5 = !{!0}
301301
302302 !0 = !DIGlobalVariableExpression(var: !1, expr: !DIExpression())
303303 !1 = !DIGlobalVariable(name: "static_member_variable", linkageName: "_ZN1C22static_member_variableE", scope: !2, file: !3, line: 7, type: !9, isLocal: false, isDefinition: true, declaration: !8)
304 !2 = distinct !DICompileUnit(language: DW_LANG_C_plus_plus, file: !3, producer: "clang version 3.7.0 (trunk 234897) (llvm/trunk 234911)", isOptimized: false, runtimeVersion: 0, emissionKind: FullDebug, enums: !4, retainedTypes: !5, globals: !21, imports: !44, gnuPubnames: true)
304 !2 = distinct !DICompileUnit(language: DW_LANG_C_plus_plus, file: !3, producer: "clang version 3.7.0 (trunk 234897) (llvm/trunk 234911)", isOptimized: false, runtimeVersion: 0, emissionKind: FullDebug, enums: !4, retainedTypes: !5, globals: !21, imports: !44, nameTableKind: GNU)
305305 !3 = !DIFile(filename: "gnu-public-names.cpp", directory: "/tmp/dbginfo")
306306 !4 = !{}
307307 !5 = !{!6, !17}
0 ; RUN: llc -mtriple=x86_64-pc-linux-gnu -debugger-tune=gdb -filetype=asm < %s | FileCheck %s --check-prefix=DISABLED
1
2 ; DISABLED-NOT: pub{{names|types}}
3
4 %struct.bar = type { %"struct.ns::foo" }
5 %"struct.ns::foo" = type { i8 }
6
7 @b = global %struct.bar zeroinitializer, align 1, !dbg !0
8
9 !llvm.dbg.cu = !{!2}
10 !llvm.module.flags = !{!11, !12}
11 !llvm.ident = !{!13}
12
13 !0 = !DIGlobalVariableExpression(var: !1, expr: !DIExpression())
14 !1 = distinct !DIGlobalVariable(name: "b", scope: !2, file: !3, line: 8, type: !6, isLocal: false, isDefinition: true)
15 !2 = distinct !DICompileUnit(language: DW_LANG_C_plus_plus, file: !3, producer: "clang", isOptimized: false, runtimeVersion: 0, emissionKind: FullDebug, enums: !4, globals: !5, nameTableKind: None)
16 !3 = !DIFile(filename: "type.cpp", directory: "/tmp/dbginfo")
17 !4 = !{}
18 !5 = !{!0}
19 !6 = distinct !DICompositeType(tag: DW_TAG_structure_type, name: "bar", file: !3, line: 5, size: 8, elements: !7, identifier: "_ZTS3bar")
20 !7 = !{!8}
21 !8 = !DIDerivedType(tag: DW_TAG_member, name: "f", scope: !6, file: !3, line: 6, baseType: !9, size: 8)
22 !9 = distinct !DICompositeType(tag: DW_TAG_structure_type, name: "foo", scope: !10, file: !3, line: 2, size: 8, elements: !4, identifier: "_ZTSN2ns3fooE")
23 !10 = !DINamespace(name: "ns", scope: null)
24 !11 = !{i32 2, !"Dwarf Version", i32 4}
25 !12 = !{i32 2, !"Debug Info Version", i32 3}
26 !13 = !{!"clang"}
27
1515
1616 !0 = !DIGlobalVariableExpression(var: !1, expr: !DIExpression())
1717 !1 = distinct !DIGlobalVariable(name: "b", scope: !2, file: !3, line: 8, type: !6, isLocal: false, isDefinition: true)
18 !2 = distinct !DICompileUnit(language: DW_LANG_C_plus_plus, file: !3, producer: "clang", isOptimized: false, runtimeVersion: 0, emissionKind: FullDebug, enums: !4, globals: !5, gnuPubnames: false)
18 !2 = distinct !DICompileUnit(language: DW_LANG_C_plus_plus, file: !3, producer: "clang", isOptimized: false, runtimeVersion: 0, emissionKind: FullDebug, enums: !4, globals: !5, nameTableKind: Default)
1919 !3 = !DIFile(filename: "type.cpp", directory: "/tmp/dbginfo")
2020 !4 = !{}
2121 !5 = !{!0}
9494 return DICompileUnit::getDistinct(
9595 Context, 1, getFile(), "clang", false, "-g", 2, "",
9696 DICompileUnit::FullDebug, getTuple(), getTuple(), getTuple(),
97 getTuple(), getTuple(), 0, true, false, false);
97 getTuple(), getTuple(), 0, true, false,
98 DICompileUnit::DebugNameTableKind::Default);
9899 }
99100 DIType *getBasicType(StringRef Name) {
100101 return DIBasicType::get(Context, dwarf::DW_TAG_unspecified_type, Name);
15061507 Context, SourceLanguage, File, Producer, IsOptimized, Flags,
15071508 RuntimeVersion, SplitDebugFilename, EmissionKind, EnumTypes,
15081509 RetainedTypes, GlobalVariables, ImportedEntities, Macros, DWOId, true,
1509 false, false);
1510 false, DICompileUnit::DebugNameTableKind::Default);
15101511
15111512 EXPECT_EQ(dwarf::DW_TAG_compile_unit, N->getTag());
15121513 EXPECT_EQ(SourceLanguage, N->getSourceLanguage());
15641565 Context, SourceLanguage, File, Producer, IsOptimized, Flags,
15651566 RuntimeVersion, SplitDebugFilename, EmissionKind, EnumTypes,
15661567 RetainedTypes, nullptr, ImportedEntities, nullptr, DWOId, true, false,
1567 false);
1568 DICompileUnit::DebugNameTableKind::Default);
15681569
15691570 auto *GlobalVariables = MDTuple::getDistinct(Context, None);
15701571 EXPECT_EQ(nullptr, N->getGlobalVariables().get());