Skip to content

Commit c48ec72

Browse files
authored
Merge pull request #904 from adrian-prantl/sdk-cherry-pick
Add an SDK attribute to DICompileUnit …
2 parents b5f8344 + 0b6b1c3 commit c48ec72

File tree

30 files changed

+231
-166
lines changed

30 files changed

+231
-166
lines changed

clang/lib/CodeGen/CGDebugInfo.cpp

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

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

625629
llvm::DIType *CGDebugInfo::CreateType(const BuiltinType *BT) {
@@ -2461,7 +2465,7 @@ CGDebugInfo::getOrCreateModuleRef(ExternalASTSource::ASTSourceDescriptor Mod,
24612465
CreateSkeletonCU);
24622466
llvm::DIModule *DIMod =
24632467
DBuilder.createModule(Parent, Mod.getModuleName(), ConfigMacros,
2464-
Mod.getPath(), CGM.getHeaderSearchOpts().Sysroot);
2468+
Mod.getPath());
24652469
ModuleCache[M].reset(DIMod);
24662470
return DIMod;
24672471
}
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
@@ -985,7 +985,7 @@ bool SymbolFileDWARF::ParseImportedModules(
985985
if (const char *include_path = module_die.GetAttributeValueAsString(
986986
DW_AT_LLVM_include_path, nullptr))
987987
module.search_path = ConstString(include_path);
988-
if (const char *sysroot = module_die.GetAttributeValueAsString(
988+
if (const char *sysroot = dwarf_cu->DIE().GetAttributeValueAsString(
989989
DW_AT_LLVM_sysroot, nullptr))
990990
module.sysroot = ConstString(sysroot);
991991
imported_modules.push_back(module);

llvm/bindings/go/llvm/dibuilder.go

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -117,6 +117,8 @@ type DICompileUnit struct {
117117
Optimized bool
118118
Flags string
119119
RuntimeVersion int
120+
SysRoot string
121+
SDK string
120122
}
121123

122124
// CreateCompileUnit creates compile unit debug metadata.
@@ -129,6 +131,10 @@ func (d *DIBuilder) CreateCompileUnit(cu DICompileUnit) Metadata {
129131
defer C.free(unsafe.Pointer(producer))
130132
flags := C.CString(cu.Flags)
131133
defer C.free(unsafe.Pointer(flags))
134+
sysroot := C.CString(cu.SysRoot)
135+
defer C.free(unsafe.Pointer(sysroot))
136+
sdk := C.CString(cu.SDK)
137+
defer C.free(unsafe.Pointer(sdk))
132138
result := C.LLVMDIBuilderCreateCompileUnit(
133139
d.ref,
134140
C.LLVMDWARFSourceLanguage(cu.Language),
@@ -142,6 +148,8 @@ func (d *DIBuilder) CreateCompileUnit(cu DICompileUnit) Metadata {
142148
/*DWOId=*/ 0,
143149
/*SplitDebugInlining*/ C.LLVMBool(boolToCInt(true)),
144150
/*DebugInfoForProfiling*/ C.LLVMBool(boolToCInt(false)),
151+
sysroot, C.size_t(len(cu.SysRoot)),
152+
sdk, C.size_t(len(cu.SDK)),
145153
)
146154
return Metadata{C: result}
147155
}

llvm/include/llvm-c/DebugInfo.h

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -250,14 +250,19 @@ 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.
255+
* \param SDK The SDK. On Darwin, the last component of the sysroot.
256+
* \param SDKLen The length of the C string passed to \c SDK.
253257
*/
254258
LLVMMetadataRef LLVMDIBuilderCreateCompileUnit(
255259
LLVMDIBuilderRef Builder, LLVMDWARFSourceLanguage Lang,
256260
LLVMMetadataRef FileRef, const char *Producer, size_t ProducerLen,
257261
LLVMBool isOptimized, const char *Flags, size_t FlagsLen,
258262
unsigned RuntimeVer, const char *SplitName, size_t SplitNameLen,
259263
LLVMDWARFEmissionKind Kind, unsigned DWOId, LLVMBool SplitDebugInlining,
260-
LLVMBool DebugInfoForProfiling);
264+
LLVMBool DebugInfoForProfiling, const char *SysRoot, size_t SysRootLen,
265+
const char *SDK, size_t SDKLen);
261266

262267
/**
263268
* Create a file descriptor to hold debugging information for a file.
@@ -283,15 +288,12 @@ LLVMDIBuilderCreateFile(LLVMDIBuilderRef Builder, const char *Filename,
283288
* \param ConfigMacrosLen The length of the C string passed to \c ConfigMacros.
284289
* \param IncludePath The path to the module map file.
285290
* \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.
288291
*/
289292
LLVMMetadataRef
290293
LLVMDIBuilderCreateModule(LLVMDIBuilderRef Builder, LLVMMetadataRef ParentScope,
291294
const char *Name, size_t NameLen,
292295
const char *ConfigMacros, size_t ConfigMacrosLen,
293-
const char *IncludePath, size_t IncludePathLen,
294-
const char *SysRoot, size_t SysRootLen);
296+
const char *IncludePath, size_t IncludePathLen);
295297

296298
/**
297299
* Creates a new descriptor for a namespace with the specified parent scope.

llvm/include/llvm/BinaryFormat/Dwarf.def

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -426,6 +426,7 @@ HANDLE_DW_AT(0x3feb, APPLE_property_attribute, 0, APPLE)
426426
HANDLE_DW_AT(0x3fec, APPLE_objc_complete_type, 0, APPLE)
427427
HANDLE_DW_AT(0x3fed, APPLE_property, 0, APPLE)
428428
HANDLE_DW_AT(0x3fee, APPLE_objc_direct, 0, APPLE)
429+
HANDLE_DW_AT(0x3fef, APPLE_sdk, 0, APPLE)
429430

430431
// Attribute form encodings.
431432
HANDLE_DW_FORM(0x01, addr, 2, DWARF)

llvm/include/llvm/IR/DIBuilder.h

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -135,6 +135,9 @@ 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).
139+
/// \param SDK The SDK name. On Darwin, this is the last component
140+
/// of the sysroot.
138141
DICompileUnit *
139142
createCompileUnit(unsigned Lang, DIFile *File, StringRef Producer,
140143
bool isOptimized, StringRef Flags, unsigned RV,
@@ -145,7 +148,8 @@ namespace llvm {
145148
bool DebugInfoForProfiling = false,
146149
DICompileUnit::DebugNameTableKind NameTableKind =
147150
DICompileUnit::DebugNameTableKind::Default,
148-
bool RangesBaseAddress = false);
151+
bool RangesBaseAddress = false, StringRef SysRoot = {},
152+
StringRef SDK = {});
149153

150154
/// Create a file descriptor to hold debugging information for a file.
151155
/// \param Filename File name.
@@ -737,11 +741,9 @@ namespace llvm {
737741
/// A space-separated shell-quoted list of -D macro
738742
/// definitions as they would appear on a command line.
739743
/// \param IncludePath The path to the module map file.
740-
/// \param SysRoot The clang system root (value of -isysroot).
741744
DIModule *createModule(DIScope *Scope, StringRef Name,
742745
StringRef ConfigurationMacros,
743-
StringRef IncludePath,
744-
StringRef SysRoot);
746+
StringRef IncludePath);
745747

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

llvm/include/llvm/IR/DebugInfoMetadata.h

Lines changed: 40 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -1228,16 +1228,17 @@ class DICompileUnit : public DIScope {
12281228
DIGlobalVariableExpressionArray GlobalVariables,
12291229
DIImportedEntityArray ImportedEntities, DIMacroNodeArray Macros,
12301230
uint64_t DWOId, bool SplitDebugInlining, bool DebugInfoForProfiling,
1231-
unsigned NameTableKind, bool RangesBaseAddress, StorageType Storage,
1232-
bool ShouldCreate = true) {
1233-
return getImpl(Context, SourceLanguage, File,
1234-
getCanonicalMDString(Context, Producer), IsOptimized,
1235-
getCanonicalMDString(Context, Flags), RuntimeVersion,
1236-
getCanonicalMDString(Context, SplitDebugFilename),
1237-
EmissionKind, EnumTypes.get(), RetainedTypes.get(),
1238-
GlobalVariables.get(), ImportedEntities.get(), Macros.get(),
1239-
DWOId, SplitDebugInlining, DebugInfoForProfiling,
1240-
NameTableKind, RangesBaseAddress, Storage, ShouldCreate);
1231+
unsigned NameTableKind, bool RangesBaseAddress, StringRef SysRoot,
1232+
StringRef SDK, StorageType Storage, bool ShouldCreate = true) {
1233+
return getImpl(
1234+
Context, SourceLanguage, File, getCanonicalMDString(Context, Producer),
1235+
IsOptimized, getCanonicalMDString(Context, Flags), RuntimeVersion,
1236+
getCanonicalMDString(Context, SplitDebugFilename), EmissionKind,
1237+
EnumTypes.get(), RetainedTypes.get(), GlobalVariables.get(),
1238+
ImportedEntities.get(), Macros.get(), DWOId, SplitDebugInlining,
1239+
DebugInfoForProfiling, NameTableKind, RangesBaseAddress,
1240+
getCanonicalMDString(Context, SysRoot),
1241+
getCanonicalMDString(Context, SDK), Storage, ShouldCreate);
12411242
}
12421243
static DICompileUnit *
12431244
getImpl(LLVMContext &Context, unsigned SourceLanguage, Metadata *File,
@@ -1247,7 +1248,8 @@ class DICompileUnit : public DIScope {
12471248
Metadata *GlobalVariables, Metadata *ImportedEntities,
12481249
Metadata *Macros, uint64_t DWOId, bool SplitDebugInlining,
12491250
bool DebugInfoForProfiling, unsigned NameTableKind,
1250-
bool RangesBaseAddress, StorageType Storage, bool ShouldCreate = true);
1251+
bool RangesBaseAddress, MDString *SysRoot, MDString *SDK,
1252+
StorageType Storage, bool ShouldCreate = true);
12511253

12521254
TempDICompileUnit cloneImpl() const {
12531255
return getTemporary(
@@ -1256,7 +1258,7 @@ class DICompileUnit : public DIScope {
12561258
getEmissionKind(), getEnumTypes(), getRetainedTypes(),
12571259
getGlobalVariables(), getImportedEntities(), getMacros(), DWOId,
12581260
getSplitDebugInlining(), getDebugInfoForProfiling(), getNameTableKind(),
1259-
getRangesBaseAddress());
1261+
getRangesBaseAddress(), getSysRoot(), getSDK());
12601262
}
12611263

12621264
public:
@@ -1272,11 +1274,13 @@ class DICompileUnit : public DIScope {
12721274
DIGlobalVariableExpressionArray GlobalVariables,
12731275
DIImportedEntityArray ImportedEntities, DIMacroNodeArray Macros,
12741276
uint64_t DWOId, bool SplitDebugInlining, bool DebugInfoForProfiling,
1275-
DebugNameTableKind NameTableKind, bool RangesBaseAddress),
1277+
DebugNameTableKind NameTableKind, bool RangesBaseAddress,
1278+
StringRef SysRoot, StringRef SDK),
12761279
(SourceLanguage, File, Producer, IsOptimized, Flags, RuntimeVersion,
12771280
SplitDebugFilename, EmissionKind, EnumTypes, RetainedTypes,
12781281
GlobalVariables, ImportedEntities, Macros, DWOId, SplitDebugInlining,
1279-
DebugInfoForProfiling, (unsigned)NameTableKind, RangesBaseAddress))
1282+
DebugInfoForProfiling, (unsigned)NameTableKind, RangesBaseAddress,
1283+
SysRoot, SDK))
12801284
DEFINE_MDNODE_GET_DISTINCT_TEMPORARY(
12811285
DICompileUnit,
12821286
(unsigned SourceLanguage, Metadata *File, MDString *Producer,
@@ -1285,11 +1289,12 @@ class DICompileUnit : public DIScope {
12851289
Metadata *RetainedTypes, Metadata *GlobalVariables,
12861290
Metadata *ImportedEntities, Metadata *Macros, uint64_t DWOId,
12871291
bool SplitDebugInlining, bool DebugInfoForProfiling,
1288-
unsigned NameTableKind, bool RangesBaseAddress),
1292+
unsigned NameTableKind, bool RangesBaseAddress, MDString *SysRoot,
1293+
MDString *SDK),
12891294
(SourceLanguage, File, Producer, IsOptimized, Flags, RuntimeVersion,
12901295
SplitDebugFilename, EmissionKind, EnumTypes, RetainedTypes,
12911296
GlobalVariables, ImportedEntities, Macros, DWOId, SplitDebugInlining,
1292-
DebugInfoForProfiling, NameTableKind, RangesBaseAddress))
1297+
DebugInfoForProfiling, NameTableKind, RangesBaseAddress, SysRoot, SDK))
12931298

12941299
TempDICompileUnit clone() const { return cloneImpl(); }
12951300

@@ -1306,14 +1311,10 @@ class DICompileUnit : public DIScope {
13061311
DebugNameTableKind getNameTableKind() const {
13071312
return (DebugNameTableKind)NameTableKind;
13081313
}
1309-
bool getRangesBaseAddress() const {
1310-
return RangesBaseAddress; }
1311-
StringRef getProducer() const {
1312-
return getStringOperand(1); }
1313-
StringRef getFlags() const {
1314-
return getStringOperand(2); }
1315-
StringRef getSplitDebugFilename() const {
1316-
return getStringOperand(3); }
1314+
bool getRangesBaseAddress() const { return RangesBaseAddress; }
1315+
StringRef getProducer() const { return getStringOperand(1); }
1316+
StringRef getFlags() const { return getStringOperand(2); }
1317+
StringRef getSplitDebugFilename() const { return getStringOperand(3); }
13171318
DICompositeTypeArray getEnumTypes() const {
13181319
return cast_or_null<MDTuple>(getRawEnumTypes());
13191320
}
@@ -1335,6 +1336,8 @@ class DICompileUnit : public DIScope {
13351336
void setSplitDebugInlining(bool SplitDebugInlining) {
13361337
this->SplitDebugInlining = SplitDebugInlining;
13371338
}
1339+
StringRef getSysRoot() const { return getStringOperand(9); }
1340+
StringRef getSDK() const { return getStringOperand(10); }
13381341

13391342
MDString *getRawProducer() const { return getOperandAs<MDString>(1); }
13401343
MDString *getRawFlags() const { return getOperandAs<MDString>(2); }
@@ -1346,6 +1349,8 @@ class DICompileUnit : public DIScope {
13461349
Metadata *getRawGlobalVariables() const { return getOperand(6); }
13471350
Metadata *getRawImportedEntities() const { return getOperand(7); }
13481351
Metadata *getRawMacros() const { return getOperand(8); }
1352+
MDString *getRawSysRoot() const { return getOperandAs<MDString>(9); }
1353+
MDString *getRawSDK() const { return getOperandAs<MDString>(10); }
13491354

13501355
/// Replace arrays.
13511356
///
@@ -2138,50 +2143,45 @@ class DIModule : public DIScope {
21382143
: DIScope(Context, DIModuleKind, Storage, dwarf::DW_TAG_module, Ops) {}
21392144
~DIModule() = default;
21402145

2141-
static DIModule *getImpl(LLVMContext &Context, DIScope *Scope,
2142-
StringRef Name, StringRef ConfigurationMacros,
2143-
StringRef IncludePath, StringRef SysRoot,
2146+
static DIModule *getImpl(LLVMContext &Context, DIScope *Scope, StringRef Name,
2147+
StringRef ConfigurationMacros, StringRef IncludePath,
21442148
StorageType Storage, bool ShouldCreate = true) {
21452149
return getImpl(Context, Scope, getCanonicalMDString(Context, Name),
21462150
getCanonicalMDString(Context, ConfigurationMacros),
21472151
getCanonicalMDString(Context, IncludePath),
2148-
getCanonicalMDString(Context, SysRoot),
21492152
Storage, ShouldCreate);
21502153
}
21512154
static DIModule *getImpl(LLVMContext &Context, Metadata *Scope,
21522155
MDString *Name, MDString *ConfigurationMacros,
2153-
MDString *IncludePath, MDString *SysRoot,
2154-
StorageType Storage, bool ShouldCreate = true);
2156+
MDString *IncludePath, StorageType Storage,
2157+
bool ShouldCreate = true);
21552158

21562159
TempDIModule cloneImpl() const {
21572160
return getTemporary(getContext(), getScope(), getName(),
2158-
getConfigurationMacros(), getIncludePath(),
2159-
getSysRoot());
2161+
getConfigurationMacros(), getIncludePath());
21602162
}
21612163

21622164
public:
2163-
DEFINE_MDNODE_GET(DIModule, (DIScope *Scope, StringRef Name,
2164-
StringRef ConfigurationMacros, StringRef IncludePath,
2165-
StringRef SysRoot),
2166-
(Scope, Name, ConfigurationMacros, IncludePath, SysRoot))
2165+
DEFINE_MDNODE_GET(DIModule,
2166+
(DIScope * Scope, StringRef Name,
2167+
StringRef ConfigurationMacros, StringRef IncludePath),
2168+
(Scope, Name, ConfigurationMacros, IncludePath))
21672169
DEFINE_MDNODE_GET(DIModule,
21682170
(Metadata *Scope, MDString *Name, MDString *ConfigurationMacros,
2169-
MDString *IncludePath, MDString *SysRoot),
2170-
(Scope, Name, ConfigurationMacros, IncludePath, SysRoot))
2171+
MDString *IncludePath),
2172+
(Scope, Name, ConfigurationMacros, IncludePath))
21712173

21722174
TempDIModule clone() const { return cloneImpl(); }
21732175

21742176
DIScope *getScope() const { return cast_or_null<DIScope>(getRawScope()); }
21752177
StringRef getName() const { return getStringOperand(1); }
21762178
StringRef getConfigurationMacros() const { return getStringOperand(2); }
21772179
StringRef getIncludePath() const { return getStringOperand(3); }
2178-
StringRef getSysRoot() const { return getStringOperand(4); }
21792180

21802181
Metadata *getRawScope() const { return getOperand(0); }
21812182
MDString *getRawName() const { return getOperandAs<MDString>(1); }
21822183
MDString *getRawConfigurationMacros() const { return getOperandAs<MDString>(2); }
21832184
MDString *getRawIncludePath() const { return getOperandAs<MDString>(3); }
2184-
MDString *getRawSysRoot() const { return getOperandAs<MDString>(4); }
21852185

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

0 commit comments

Comments
 (0)