Skip to content

Commit 7b30370

Browse files
committed
Move the sysroot attribute from DIModule to DICompileUnit
[this re-applies c017691 with the correct commit message and phabricator link] This addresses point 1 of PR44213. https://bugs.llvm.org/show_bug.cgi?id=44213 The DW_AT_LLVM_sysroot attribute is used for Clang module debug info, to allow LLDB to import a Clang module from source. Currently it is part of each DW_TAG_module, however, it is the same for all modules in a compile unit. It is more efficient and less ambiguous to store it once in the DW_TAG_compile_unit. This should have no effect on DWARF consumers other than LLDB. Differential Revision: https://reviews.llvm.org/D71732
1 parent c17aee6 commit 7b30370

File tree

29 files changed

+192
-147
lines changed

29 files changed

+192
-147
lines changed

clang/lib/CodeGen/CGDebugInfo.cpp

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -610,6 +610,10 @@ void CGDebugInfo::CreateCompileUnit() {
610610
remapDIPath(MainFileName), remapDIPath(getCurrentDirname()), CSInfo,
611611
getSource(SM, SM.getMainFileID()));
612612

613+
StringRef Sysroot;
614+
if (CGM.getCodeGenOpts().getDebuggerTuning() == llvm::DebuggerKind::LLDB)
615+
Sysroot = CGM.getHeaderSearchOpts().Sysroot;
616+
613617
// Create new compile unit.
614618
TheCU = DBuilder.createCompileUnit(
615619
LangTag, CUFile, CGOpts.EmitVersionIdentMetadata ? Producer : "",
@@ -620,7 +624,7 @@ void CGDebugInfo::CreateCompileUnit() {
620624
? llvm::DICompileUnit::DebugNameTableKind::None
621625
: static_cast<llvm::DICompileUnit::DebugNameTableKind>(
622626
CGOpts.DebugNameTable),
623-
CGOpts.DebugRangesBaseAddress);
627+
CGOpts.DebugRangesBaseAddress, Sysroot);
624628
}
625629

626630
llvm::DIType *CGDebugInfo::CreateType(const BuiltinType *BT) {
@@ -2471,7 +2475,7 @@ CGDebugInfo::getOrCreateModuleRef(ExternalASTSource::ASTSourceDescriptor Mod,
24712475
CreateSkeletonCU);
24722476
llvm::DIModule *DIMod =
24732477
DBuilder.createModule(Parent, Mod.getModuleName(), ConfigMacros,
2474-
Mod.getPath(), CGM.getHeaderSearchOpts().Sysroot);
2478+
Mod.getPath());
24752479
ModuleCache[M].reset(DIMod);
24762480
return DIMod;
24772481
}
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
// RUN: %clang_cc1 -debug-info-kind=limited -triple %itanium_abi_triple \
2+
// RUN: %s -isysroot /CLANG_SYSROOT -emit-llvm -o - \
3+
// RUN: -debugger-tuning=lldb | FileCheck %s --check-prefix=LLDB
4+
// RUN: %clang_cc1 -debug-info-kind=limited -triple %itanium_abi_triple \
5+
// RUN: %s -isysroot /CLANG_SYSROOT -emit-llvm -o - \
6+
// RUN: -debugger-tuning=gdb | FileCheck %s --check-prefix=GDB
7+
8+
void foo() {}
9+
10+
// The sysroot is an LLDB-tuning-specific attribute.
11+
12+
// LLDB: distinct !DICompileUnit({{.*}}sysroot: "/CLANG_SYSROOT"
13+
// GDB: distinct !DICompileUnit(
14+
// GDB-NOT: sysroot: "/CLANG_SYSROOT"
15+

clang/test/CodeGen/debug-nvptx.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
// RUN: %clang_cc1 -triple nvptx-unknown-unknown -S -o - -debug-info-kind=limited %s -emit-llvm | FileCheck %s
22

3-
// CHECK: DICompileUnit({{.*}}, nameTableKind: None)
3+
// CHECK: DICompileUnit({{.*}}, nameTableKind: None
44

55
void f1(void) {
66
}

clang/test/Modules/debug-info-moduleimport.m

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,14 +8,14 @@
88
// RUN: %clang_cc1 -debug-info-kind=limited -fmodules -DGREETING="Hello World" -UNDEBUG -fimplicit-module-maps -fmodules-cache-path=%t %s -I %S/Inputs -isysroot /tmp/.. -I %t -emit-llvm -debugger-tuning=lldb -o - | FileCheck %s
99

1010
// CHECK: ![[CU:.*]] = distinct !DICompileUnit
11+
// CHECK-SAME: sysroot: "/tmp/..")
1112
@import DebugObjC;
1213
// CHECK: !DIImportedEntity(tag: DW_TAG_imported_declaration, scope: ![[CU]],
1314
// CHECK-SAME: entity: ![[MODULE:.*]], file: ![[F:[0-9]+]],
1415
// CHECK-SAME: line: [[@LINE-3]])
1516
// CHECK: ![[MODULE]] = !DIModule(scope: null, name: "DebugObjC",
1617
// CHECK-SAME: configMacros: "\22-DGREETING=Hello World\22 \22-UNDEBUG\22",
17-
// CHECK-SAME: includePath: "{{.*}}test{{.*}}Modules{{.*}}Inputs",
18-
// CHECK-SAME: sysroot: "/tmp/..")
18+
// CHECK-SAME: includePath: "{{.*}}test{{.*}}Modules{{.*}}Inputs"
1919
// CHECK: ![[F]] = !DIFile(filename: {{.*}}debug-info-moduleimport.m
2020

2121
// RUN: %clang_cc1 -debug-info-kind=limited -fmodules -fimplicit-module-maps -fmodules-cache-path=%t \

lldb/source/Plugins/SymbolFile/DWARF/SymbolFileDWARF.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -970,7 +970,7 @@ bool SymbolFileDWARF::ParseImportedModules(
970970
if (const char *include_path = module_die.GetAttributeValueAsString(
971971
DW_AT_LLVM_include_path, nullptr))
972972
module.search_path = ConstString(include_path);
973-
if (const char *sysroot = module_die.GetAttributeValueAsString(
973+
if (const char *sysroot = dwarf_cu->DIE().GetAttributeValueAsString(
974974
DW_AT_LLVM_sysroot, nullptr))
975975
module.sysroot = ConstString(sysroot);
976976
imported_modules.push_back(module);

llvm/bindings/go/llvm/dibuilder.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -117,6 +117,7 @@ type DICompileUnit struct {
117117
Optimized bool
118118
Flags string
119119
RuntimeVersion int
120+
SysRoot string
120121
}
121122

122123
// CreateCompileUnit creates compile unit debug metadata.
@@ -129,6 +130,8 @@ func (d *DIBuilder) CreateCompileUnit(cu DICompileUnit) Metadata {
129130
defer C.free(unsafe.Pointer(producer))
130131
flags := C.CString(cu.Flags)
131132
defer C.free(unsafe.Pointer(flags))
133+
sysroot := C.CString(cu.SysRoot)
134+
defer C.free(unsafe.Pointer(sysroot))
132135
result := C.LLVMDIBuilderCreateCompileUnit(
133136
d.ref,
134137
C.LLVMDWARFSourceLanguage(cu.Language),
@@ -142,6 +145,7 @@ func (d *DIBuilder) CreateCompileUnit(cu DICompileUnit) Metadata {
142145
/*DWOId=*/ 0,
143146
/*SplitDebugInlining*/ C.LLVMBool(boolToCInt(true)),
144147
/*DebugInfoForProfiling*/ C.LLVMBool(boolToCInt(false)),
148+
sysroot,
145149
)
146150
return Metadata{C: result}
147151
}

llvm/include/llvm-c/DebugInfo.h

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -250,14 +250,16 @@ void LLVMDIBuilderFinalize(LLVMDIBuilderRef Builder);
250250
* \param SplitDebugInlining Whether to emit inline debug info.
251251
* \param DebugInfoForProfiling Whether to emit extra debug info for
252252
* profile collection.
253+
* \param SysRoot The Clang system root (value of -isysroot).
254+
* \param SysRootLen The length of the C string passed to \c SysRoot.
253255
*/
254256
LLVMMetadataRef LLVMDIBuilderCreateCompileUnit(
255257
LLVMDIBuilderRef Builder, LLVMDWARFSourceLanguage Lang,
256258
LLVMMetadataRef FileRef, const char *Producer, size_t ProducerLen,
257259
LLVMBool isOptimized, const char *Flags, size_t FlagsLen,
258260
unsigned RuntimeVer, const char *SplitName, size_t SplitNameLen,
259261
LLVMDWARFEmissionKind Kind, unsigned DWOId, LLVMBool SplitDebugInlining,
260-
LLVMBool DebugInfoForProfiling);
262+
LLVMBool DebugInfoForProfiling, const char *SysRoot, size_t SysRootLen);
261263

262264
/**
263265
* Create a file descriptor to hold debugging information for a file.
@@ -283,15 +285,12 @@ LLVMDIBuilderCreateFile(LLVMDIBuilderRef Builder, const char *Filename,
283285
* \param ConfigMacrosLen The length of the C string passed to \c ConfigMacros.
284286
* \param IncludePath The path to the module map file.
285287
* \param IncludePathLen The length of the C string passed to \c IncludePath.
286-
* \param SysRoot The Clang system root (value of -isysroot).
287-
* \param SysRootLen The length of the C string passed to \c SysRoot.
288288
*/
289289
LLVMMetadataRef
290290
LLVMDIBuilderCreateModule(LLVMDIBuilderRef Builder, LLVMMetadataRef ParentScope,
291291
const char *Name, size_t NameLen,
292292
const char *ConfigMacros, size_t ConfigMacrosLen,
293-
const char *IncludePath, size_t IncludePathLen,
294-
const char *SysRoot, size_t SysRootLen);
293+
const char *IncludePath, size_t IncludePathLen);
295294

296295
/**
297296
* Creates a new descriptor for a namespace with the specified parent scope.

llvm/include/llvm/IR/DIBuilder.h

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -135,6 +135,7 @@ namespace llvm {
135135
/// profile collection.
136136
/// \param NameTableKind Whether to emit .debug_gnu_pubnames,
137137
/// .debug_pubnames, or no pubnames at all.
138+
/// \param SysRoot The clang system root (value of -isysroot).
138139
DICompileUnit *
139140
createCompileUnit(unsigned Lang, DIFile *File, StringRef Producer,
140141
bool isOptimized, StringRef Flags, unsigned RV,
@@ -145,7 +146,7 @@ namespace llvm {
145146
bool DebugInfoForProfiling = false,
146147
DICompileUnit::DebugNameTableKind NameTableKind =
147148
DICompileUnit::DebugNameTableKind::Default,
148-
bool RangesBaseAddress = false);
149+
bool RangesBaseAddress = false, StringRef SysRoot = {});
149150

150151
/// Create a file descriptor to hold debugging information for a file.
151152
/// \param Filename File name.
@@ -734,11 +735,9 @@ namespace llvm {
734735
/// A space-separated shell-quoted list of -D macro
735736
/// definitions as they would appear on a command line.
736737
/// \param IncludePath The path to the module map file.
737-
/// \param SysRoot The clang system root (value of -isysroot).
738738
DIModule *createModule(DIScope *Scope, StringRef Name,
739739
StringRef ConfigurationMacros,
740-
StringRef IncludePath,
741-
StringRef SysRoot);
740+
StringRef IncludePath);
742741

743742
/// This creates a descriptor for a lexical block with a new file
744743
/// attached. This merely extends the existing

llvm/include/llvm/IR/DebugInfoMetadata.h

Lines changed: 36 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -1172,16 +1172,16 @@ class DICompileUnit : public DIScope {
11721172
DIGlobalVariableExpressionArray GlobalVariables,
11731173
DIImportedEntityArray ImportedEntities, DIMacroNodeArray Macros,
11741174
uint64_t DWOId, bool SplitDebugInlining, bool DebugInfoForProfiling,
1175-
unsigned NameTableKind, bool RangesBaseAddress, StorageType Storage,
1176-
bool ShouldCreate = true) {
1177-
return getImpl(Context, SourceLanguage, File,
1178-
getCanonicalMDString(Context, Producer), IsOptimized,
1179-
getCanonicalMDString(Context, Flags), RuntimeVersion,
1180-
getCanonicalMDString(Context, SplitDebugFilename),
1181-
EmissionKind, EnumTypes.get(), RetainedTypes.get(),
1182-
GlobalVariables.get(), ImportedEntities.get(), Macros.get(),
1183-
DWOId, SplitDebugInlining, DebugInfoForProfiling,
1184-
NameTableKind, RangesBaseAddress, Storage, ShouldCreate);
1175+
unsigned NameTableKind, bool RangesBaseAddress, StringRef SysRoot,
1176+
StorageType Storage, bool ShouldCreate = true) {
1177+
return getImpl(
1178+
Context, SourceLanguage, File, getCanonicalMDString(Context, Producer),
1179+
IsOptimized, getCanonicalMDString(Context, Flags), RuntimeVersion,
1180+
getCanonicalMDString(Context, SplitDebugFilename), EmissionKind,
1181+
EnumTypes.get(), RetainedTypes.get(), GlobalVariables.get(),
1182+
ImportedEntities.get(), Macros.get(), DWOId, SplitDebugInlining,
1183+
DebugInfoForProfiling, NameTableKind, RangesBaseAddress,
1184+
getCanonicalMDString(Context, SysRoot), Storage, ShouldCreate);
11851185
}
11861186
static DICompileUnit *
11871187
getImpl(LLVMContext &Context, unsigned SourceLanguage, Metadata *File,
@@ -1191,7 +1191,8 @@ class DICompileUnit : public DIScope {
11911191
Metadata *GlobalVariables, Metadata *ImportedEntities,
11921192
Metadata *Macros, uint64_t DWOId, bool SplitDebugInlining,
11931193
bool DebugInfoForProfiling, unsigned NameTableKind,
1194-
bool RangesBaseAddress, StorageType Storage, bool ShouldCreate = true);
1194+
bool RangesBaseAddress, MDString *SysRoot, StorageType Storage,
1195+
bool ShouldCreate = true);
11951196

11961197
TempDICompileUnit cloneImpl() const {
11971198
return getTemporary(
@@ -1200,7 +1201,7 @@ class DICompileUnit : public DIScope {
12001201
getEmissionKind(), getEnumTypes(), getRetainedTypes(),
12011202
getGlobalVariables(), getImportedEntities(), getMacros(), DWOId,
12021203
getSplitDebugInlining(), getDebugInfoForProfiling(), getNameTableKind(),
1203-
getRangesBaseAddress());
1204+
getRangesBaseAddress(), getSysRoot());
12041205
}
12051206

12061207
public:
@@ -1216,11 +1217,13 @@ class DICompileUnit : public DIScope {
12161217
DIGlobalVariableExpressionArray GlobalVariables,
12171218
DIImportedEntityArray ImportedEntities, DIMacroNodeArray Macros,
12181219
uint64_t DWOId, bool SplitDebugInlining, bool DebugInfoForProfiling,
1219-
DebugNameTableKind NameTableKind, bool RangesBaseAddress),
1220+
DebugNameTableKind NameTableKind, bool RangesBaseAddress,
1221+
StringRef SysRoot),
12201222
(SourceLanguage, File, Producer, IsOptimized, Flags, RuntimeVersion,
12211223
SplitDebugFilename, EmissionKind, EnumTypes, RetainedTypes,
12221224
GlobalVariables, ImportedEntities, Macros, DWOId, SplitDebugInlining,
1223-
DebugInfoForProfiling, (unsigned)NameTableKind, RangesBaseAddress))
1225+
DebugInfoForProfiling, (unsigned)NameTableKind, RangesBaseAddress,
1226+
SysRoot))
12241227
DEFINE_MDNODE_GET_DISTINCT_TEMPORARY(
12251228
DICompileUnit,
12261229
(unsigned SourceLanguage, Metadata *File, MDString *Producer,
@@ -1229,11 +1232,11 @@ class DICompileUnit : public DIScope {
12291232
Metadata *RetainedTypes, Metadata *GlobalVariables,
12301233
Metadata *ImportedEntities, Metadata *Macros, uint64_t DWOId,
12311234
bool SplitDebugInlining, bool DebugInfoForProfiling,
1232-
unsigned NameTableKind, bool RangesBaseAddress),
1235+
unsigned NameTableKind, bool RangesBaseAddress, MDString *SysRoot),
12331236
(SourceLanguage, File, Producer, IsOptimized, Flags, RuntimeVersion,
12341237
SplitDebugFilename, EmissionKind, EnumTypes, RetainedTypes,
12351238
GlobalVariables, ImportedEntities, Macros, DWOId, SplitDebugInlining,
1236-
DebugInfoForProfiling, NameTableKind, RangesBaseAddress))
1239+
DebugInfoForProfiling, NameTableKind, RangesBaseAddress, SysRoot))
12371240

12381241
TempDICompileUnit clone() const { return cloneImpl(); }
12391242

@@ -1250,14 +1253,10 @@ class DICompileUnit : public DIScope {
12501253
DebugNameTableKind getNameTableKind() const {
12511254
return (DebugNameTableKind)NameTableKind;
12521255
}
1253-
bool getRangesBaseAddress() const {
1254-
return RangesBaseAddress; }
1255-
StringRef getProducer() const {
1256-
return getStringOperand(1); }
1257-
StringRef getFlags() const {
1258-
return getStringOperand(2); }
1259-
StringRef getSplitDebugFilename() const {
1260-
return getStringOperand(3); }
1256+
bool getRangesBaseAddress() const { return RangesBaseAddress; }
1257+
StringRef getProducer() const { return getStringOperand(1); }
1258+
StringRef getFlags() const { return getStringOperand(2); }
1259+
StringRef getSplitDebugFilename() const { return getStringOperand(3); }
12611260
DICompositeTypeArray getEnumTypes() const {
12621261
return cast_or_null<MDTuple>(getRawEnumTypes());
12631262
}
@@ -1279,6 +1278,7 @@ class DICompileUnit : public DIScope {
12791278
void setSplitDebugInlining(bool SplitDebugInlining) {
12801279
this->SplitDebugInlining = SplitDebugInlining;
12811280
}
1281+
StringRef getSysRoot() const { return getStringOperand(9); }
12821282

12831283
MDString *getRawProducer() const { return getOperandAs<MDString>(1); }
12841284
MDString *getRawFlags() const { return getOperandAs<MDString>(2); }
@@ -1290,6 +1290,7 @@ class DICompileUnit : public DIScope {
12901290
Metadata *getRawGlobalVariables() const { return getOperand(6); }
12911291
Metadata *getRawImportedEntities() const { return getOperand(7); }
12921292
Metadata *getRawMacros() const { return getOperand(8); }
1293+
MDString *getRawSysRoot() const { return getOperandAs<MDString>(9); }
12931294

12941295
/// Replace arrays.
12951296
///
@@ -2082,50 +2083,45 @@ class DIModule : public DIScope {
20822083
: DIScope(Context, DIModuleKind, Storage, dwarf::DW_TAG_module, Ops) {}
20832084
~DIModule() = default;
20842085

2085-
static DIModule *getImpl(LLVMContext &Context, DIScope *Scope,
2086-
StringRef Name, StringRef ConfigurationMacros,
2087-
StringRef IncludePath, StringRef SysRoot,
2086+
static DIModule *getImpl(LLVMContext &Context, DIScope *Scope, StringRef Name,
2087+
StringRef ConfigurationMacros, StringRef IncludePath,
20882088
StorageType Storage, bool ShouldCreate = true) {
20892089
return getImpl(Context, Scope, getCanonicalMDString(Context, Name),
20902090
getCanonicalMDString(Context, ConfigurationMacros),
20912091
getCanonicalMDString(Context, IncludePath),
2092-
getCanonicalMDString(Context, SysRoot),
20932092
Storage, ShouldCreate);
20942093
}
20952094
static DIModule *getImpl(LLVMContext &Context, Metadata *Scope,
20962095
MDString *Name, MDString *ConfigurationMacros,
2097-
MDString *IncludePath, MDString *SysRoot,
2098-
StorageType Storage, bool ShouldCreate = true);
2096+
MDString *IncludePath, StorageType Storage,
2097+
bool ShouldCreate = true);
20992098

21002099
TempDIModule cloneImpl() const {
21012100
return getTemporary(getContext(), getScope(), getName(),
2102-
getConfigurationMacros(), getIncludePath(),
2103-
getSysRoot());
2101+
getConfigurationMacros(), getIncludePath());
21042102
}
21052103

21062104
public:
2107-
DEFINE_MDNODE_GET(DIModule, (DIScope *Scope, StringRef Name,
2108-
StringRef ConfigurationMacros, StringRef IncludePath,
2109-
StringRef SysRoot),
2110-
(Scope, Name, ConfigurationMacros, IncludePath, SysRoot))
2105+
DEFINE_MDNODE_GET(DIModule,
2106+
(DIScope * Scope, StringRef Name,
2107+
StringRef ConfigurationMacros, StringRef IncludePath),
2108+
(Scope, Name, ConfigurationMacros, IncludePath))
21112109
DEFINE_MDNODE_GET(DIModule,
21122110
(Metadata *Scope, MDString *Name, MDString *ConfigurationMacros,
2113-
MDString *IncludePath, MDString *SysRoot),
2114-
(Scope, Name, ConfigurationMacros, IncludePath, SysRoot))
2111+
MDString *IncludePath),
2112+
(Scope, Name, ConfigurationMacros, IncludePath))
21152113

21162114
TempDIModule clone() const { return cloneImpl(); }
21172115

21182116
DIScope *getScope() const { return cast_or_null<DIScope>(getRawScope()); }
21192117
StringRef getName() const { return getStringOperand(1); }
21202118
StringRef getConfigurationMacros() const { return getStringOperand(2); }
21212119
StringRef getIncludePath() const { return getStringOperand(3); }
2122-
StringRef getSysRoot() const { return getStringOperand(4); }
21232120

21242121
Metadata *getRawScope() const { return getOperand(0); }
21252122
MDString *getRawName() const { return getOperandAs<MDString>(1); }
21262123
MDString *getRawConfigurationMacros() const { return getOperandAs<MDString>(2); }
21272124
MDString *getRawIncludePath() const { return getOperandAs<MDString>(3); }
2128-
MDString *getRawSysRoot() const { return getOperandAs<MDString>(4); }
21292125

21302126
static bool classof(const Metadata *MD) {
21312127
return MD->getMetadataID() == DIModuleKind;

0 commit comments

Comments
 (0)