Skip to content

Add an SDK attribute to DICompileUnit … #904

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 6 additions & 2 deletions clang/lib/CodeGen/CGDebugInfo.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -609,6 +609,10 @@ void CGDebugInfo::CreateCompileUnit() {
remapDIPath(MainFileName), remapDIPath(getCurrentDirname()), CSInfo,
getSource(SM, SM.getMainFileID()));

StringRef Sysroot;
if (CGM.getCodeGenOpts().getDebuggerTuning() == llvm::DebuggerKind::LLDB)
Sysroot = CGM.getHeaderSearchOpts().Sysroot;

// Create new compile unit.
TheCU = DBuilder.createCompileUnit(
LangTag, CUFile, CGOpts.EmitVersionIdentMetadata ? Producer : "",
Expand All @@ -619,7 +623,7 @@ void CGDebugInfo::CreateCompileUnit() {
? llvm::DICompileUnit::DebugNameTableKind::None
: static_cast<llvm::DICompileUnit::DebugNameTableKind>(
CGOpts.DebugNameTable),
CGOpts.DebugRangesBaseAddress);
CGOpts.DebugRangesBaseAddress, Sysroot);
}

llvm::DIType *CGDebugInfo::CreateType(const BuiltinType *BT) {
Expand Down Expand Up @@ -2461,7 +2465,7 @@ CGDebugInfo::getOrCreateModuleRef(ExternalASTSource::ASTSourceDescriptor Mod,
CreateSkeletonCU);
llvm::DIModule *DIMod =
DBuilder.createModule(Parent, Mod.getModuleName(), ConfigMacros,
Mod.getPath(), CGM.getHeaderSearchOpts().Sysroot);
Mod.getPath());
ModuleCache[M].reset(DIMod);
return DIMod;
}
Expand Down
15 changes: 15 additions & 0 deletions clang/test/CodeGen/debug-info-sysroot.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
// RUN: %clang_cc1 -debug-info-kind=limited -triple %itanium_abi_triple \
// RUN: %s -isysroot /CLANG_SYSROOT -emit-llvm -o - \
// RUN: -debugger-tuning=lldb | FileCheck %s --check-prefix=LLDB
// RUN: %clang_cc1 -debug-info-kind=limited -triple %itanium_abi_triple \
// RUN: %s -isysroot /CLANG_SYSROOT -emit-llvm -o - \
// RUN: -debugger-tuning=gdb | FileCheck %s --check-prefix=GDB

void foo() {}

// The sysroot is an LLDB-tuning-specific attribute.

// LLDB: distinct !DICompileUnit({{.*}}sysroot: "/CLANG_SYSROOT"
// GDB: distinct !DICompileUnit(
// GDB-NOT: sysroot: "/CLANG_SYSROOT"

2 changes: 1 addition & 1 deletion clang/test/CodeGen/debug-nvptx.c
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
// RUN: %clang_cc1 -triple nvptx-unknown-unknown -S -o - -debug-info-kind=limited %s -emit-llvm | FileCheck %s

// CHECK: DICompileUnit({{.*}}, nameTableKind: None)
// CHECK: DICompileUnit({{.*}}, nameTableKind: None

void f1(void) {
}
4 changes: 2 additions & 2 deletions clang/test/Modules/debug-info-moduleimport.m
Original file line number Diff line number Diff line change
Expand Up @@ -8,14 +8,14 @@
// 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

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

// RUN: %clang_cc1 -debug-info-kind=limited -fmodules -fimplicit-module-maps -fmodules-cache-path=%t \
Expand Down
2 changes: 1 addition & 1 deletion lldb/source/Plugins/SymbolFile/DWARF/SymbolFileDWARF.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -985,7 +985,7 @@ bool SymbolFileDWARF::ParseImportedModules(
if (const char *include_path = module_die.GetAttributeValueAsString(
DW_AT_LLVM_include_path, nullptr))
module.search_path = ConstString(include_path);
if (const char *sysroot = module_die.GetAttributeValueAsString(
if (const char *sysroot = dwarf_cu->DIE().GetAttributeValueAsString(
DW_AT_LLVM_sysroot, nullptr))
module.sysroot = ConstString(sysroot);
imported_modules.push_back(module);
Expand Down
8 changes: 8 additions & 0 deletions llvm/bindings/go/llvm/dibuilder.go
Original file line number Diff line number Diff line change
Expand Up @@ -117,6 +117,8 @@ type DICompileUnit struct {
Optimized bool
Flags string
RuntimeVersion int
SysRoot string
SDK string
}

// CreateCompileUnit creates compile unit debug metadata.
Expand All @@ -129,6 +131,10 @@ func (d *DIBuilder) CreateCompileUnit(cu DICompileUnit) Metadata {
defer C.free(unsafe.Pointer(producer))
flags := C.CString(cu.Flags)
defer C.free(unsafe.Pointer(flags))
sysroot := C.CString(cu.SysRoot)
defer C.free(unsafe.Pointer(sysroot))
sdk := C.CString(cu.SDK)
defer C.free(unsafe.Pointer(sdk))
result := C.LLVMDIBuilderCreateCompileUnit(
d.ref,
C.LLVMDWARFSourceLanguage(cu.Language),
Expand All @@ -142,6 +148,8 @@ func (d *DIBuilder) CreateCompileUnit(cu DICompileUnit) Metadata {
/*DWOId=*/ 0,
/*SplitDebugInlining*/ C.LLVMBool(boolToCInt(true)),
/*DebugInfoForProfiling*/ C.LLVMBool(boolToCInt(false)),
sysroot, C.size_t(len(cu.SysRoot)),
sdk, C.size_t(len(cu.SDK)),
)
return Metadata{C: result}
}
Expand Down
12 changes: 7 additions & 5 deletions llvm/include/llvm-c/DebugInfo.h
Original file line number Diff line number Diff line change
Expand Up @@ -250,14 +250,19 @@ void LLVMDIBuilderFinalize(LLVMDIBuilderRef Builder);
* \param SplitDebugInlining Whether to emit inline debug info.
* \param DebugInfoForProfiling Whether to emit extra debug info for
* profile collection.
* \param SysRoot The Clang system root (value of -isysroot).
* \param SysRootLen The length of the C string passed to \c SysRoot.
* \param SDK The SDK. On Darwin, the last component of the sysroot.
* \param SDKLen The length of the C string passed to \c SDK.
*/
LLVMMetadataRef LLVMDIBuilderCreateCompileUnit(
LLVMDIBuilderRef Builder, LLVMDWARFSourceLanguage Lang,
LLVMMetadataRef FileRef, const char *Producer, size_t ProducerLen,
LLVMBool isOptimized, const char *Flags, size_t FlagsLen,
unsigned RuntimeVer, const char *SplitName, size_t SplitNameLen,
LLVMDWARFEmissionKind Kind, unsigned DWOId, LLVMBool SplitDebugInlining,
LLVMBool DebugInfoForProfiling);
LLVMBool DebugInfoForProfiling, const char *SysRoot, size_t SysRootLen,
const char *SDK, size_t SDKLen);

/**
* Create a file descriptor to hold debugging information for a file.
Expand All @@ -283,15 +288,12 @@ LLVMDIBuilderCreateFile(LLVMDIBuilderRef Builder, const char *Filename,
* \param ConfigMacrosLen The length of the C string passed to \c ConfigMacros.
* \param IncludePath The path to the module map file.
* \param IncludePathLen The length of the C string passed to \c IncludePath.
* \param SysRoot The Clang system root (value of -isysroot).
* \param SysRootLen The length of the C string passed to \c SysRoot.
*/
LLVMMetadataRef
LLVMDIBuilderCreateModule(LLVMDIBuilderRef Builder, LLVMMetadataRef ParentScope,
const char *Name, size_t NameLen,
const char *ConfigMacros, size_t ConfigMacrosLen,
const char *IncludePath, size_t IncludePathLen,
const char *SysRoot, size_t SysRootLen);
const char *IncludePath, size_t IncludePathLen);

/**
* Creates a new descriptor for a namespace with the specified parent scope.
Expand Down
1 change: 1 addition & 0 deletions llvm/include/llvm/BinaryFormat/Dwarf.def
Original file line number Diff line number Diff line change
Expand Up @@ -426,6 +426,7 @@ HANDLE_DW_AT(0x3feb, APPLE_property_attribute, 0, APPLE)
HANDLE_DW_AT(0x3fec, APPLE_objc_complete_type, 0, APPLE)
HANDLE_DW_AT(0x3fed, APPLE_property, 0, APPLE)
HANDLE_DW_AT(0x3fee, APPLE_objc_direct, 0, APPLE)
HANDLE_DW_AT(0x3fef, APPLE_sdk, 0, APPLE)

// Attribute form encodings.
HANDLE_DW_FORM(0x01, addr, 2, DWARF)
Expand Down
10 changes: 6 additions & 4 deletions llvm/include/llvm/IR/DIBuilder.h
Original file line number Diff line number Diff line change
Expand Up @@ -135,6 +135,9 @@ namespace llvm {
/// profile collection.
/// \param NameTableKind Whether to emit .debug_gnu_pubnames,
/// .debug_pubnames, or no pubnames at all.
/// \param SysRoot The clang system root (value of -isysroot).
/// \param SDK The SDK name. On Darwin, this is the last component
/// of the sysroot.
DICompileUnit *
createCompileUnit(unsigned Lang, DIFile *File, StringRef Producer,
bool isOptimized, StringRef Flags, unsigned RV,
Expand All @@ -145,7 +148,8 @@ namespace llvm {
bool DebugInfoForProfiling = false,
DICompileUnit::DebugNameTableKind NameTableKind =
DICompileUnit::DebugNameTableKind::Default,
bool RangesBaseAddress = false);
bool RangesBaseAddress = false, StringRef SysRoot = {},
StringRef SDK = {});

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

/// This creates a descriptor for a lexical block with a new file
/// attached. This merely extends the existing
Expand Down
80 changes: 40 additions & 40 deletions llvm/include/llvm/IR/DebugInfoMetadata.h
Original file line number Diff line number Diff line change
Expand Up @@ -1228,16 +1228,17 @@ class DICompileUnit : public DIScope {
DIGlobalVariableExpressionArray GlobalVariables,
DIImportedEntityArray ImportedEntities, DIMacroNodeArray Macros,
uint64_t DWOId, bool SplitDebugInlining, bool DebugInfoForProfiling,
unsigned NameTableKind, bool RangesBaseAddress, StorageType Storage,
bool ShouldCreate = true) {
return getImpl(Context, SourceLanguage, File,
getCanonicalMDString(Context, Producer), IsOptimized,
getCanonicalMDString(Context, Flags), RuntimeVersion,
getCanonicalMDString(Context, SplitDebugFilename),
EmissionKind, EnumTypes.get(), RetainedTypes.get(),
GlobalVariables.get(), ImportedEntities.get(), Macros.get(),
DWOId, SplitDebugInlining, DebugInfoForProfiling,
NameTableKind, RangesBaseAddress, Storage, ShouldCreate);
unsigned NameTableKind, bool RangesBaseAddress, StringRef SysRoot,
StringRef SDK, StorageType Storage, bool ShouldCreate = true) {
return getImpl(
Context, SourceLanguage, File, getCanonicalMDString(Context, Producer),
IsOptimized, getCanonicalMDString(Context, Flags), RuntimeVersion,
getCanonicalMDString(Context, SplitDebugFilename), EmissionKind,
EnumTypes.get(), RetainedTypes.get(), GlobalVariables.get(),
ImportedEntities.get(), Macros.get(), DWOId, SplitDebugInlining,
DebugInfoForProfiling, NameTableKind, RangesBaseAddress,
getCanonicalMDString(Context, SysRoot),
getCanonicalMDString(Context, SDK), Storage, ShouldCreate);
}
static DICompileUnit *
getImpl(LLVMContext &Context, unsigned SourceLanguage, Metadata *File,
Expand All @@ -1247,7 +1248,8 @@ class DICompileUnit : public DIScope {
Metadata *GlobalVariables, Metadata *ImportedEntities,
Metadata *Macros, uint64_t DWOId, bool SplitDebugInlining,
bool DebugInfoForProfiling, unsigned NameTableKind,
bool RangesBaseAddress, StorageType Storage, bool ShouldCreate = true);
bool RangesBaseAddress, MDString *SysRoot, MDString *SDK,
StorageType Storage, bool ShouldCreate = true);

TempDICompileUnit cloneImpl() const {
return getTemporary(
Expand All @@ -1256,7 +1258,7 @@ class DICompileUnit : public DIScope {
getEmissionKind(), getEnumTypes(), getRetainedTypes(),
getGlobalVariables(), getImportedEntities(), getMacros(), DWOId,
getSplitDebugInlining(), getDebugInfoForProfiling(), getNameTableKind(),
getRangesBaseAddress());
getRangesBaseAddress(), getSysRoot(), getSDK());
}

public:
Expand All @@ -1272,11 +1274,13 @@ class DICompileUnit : public DIScope {
DIGlobalVariableExpressionArray GlobalVariables,
DIImportedEntityArray ImportedEntities, DIMacroNodeArray Macros,
uint64_t DWOId, bool SplitDebugInlining, bool DebugInfoForProfiling,
DebugNameTableKind NameTableKind, bool RangesBaseAddress),
DebugNameTableKind NameTableKind, bool RangesBaseAddress,
StringRef SysRoot, StringRef SDK),
(SourceLanguage, File, Producer, IsOptimized, Flags, RuntimeVersion,
SplitDebugFilename, EmissionKind, EnumTypes, RetainedTypes,
GlobalVariables, ImportedEntities, Macros, DWOId, SplitDebugInlining,
DebugInfoForProfiling, (unsigned)NameTableKind, RangesBaseAddress))
DebugInfoForProfiling, (unsigned)NameTableKind, RangesBaseAddress,
SysRoot, SDK))
DEFINE_MDNODE_GET_DISTINCT_TEMPORARY(
DICompileUnit,
(unsigned SourceLanguage, Metadata *File, MDString *Producer,
Expand All @@ -1285,11 +1289,12 @@ class DICompileUnit : public DIScope {
Metadata *RetainedTypes, Metadata *GlobalVariables,
Metadata *ImportedEntities, Metadata *Macros, uint64_t DWOId,
bool SplitDebugInlining, bool DebugInfoForProfiling,
unsigned NameTableKind, bool RangesBaseAddress),
unsigned NameTableKind, bool RangesBaseAddress, MDString *SysRoot,
MDString *SDK),
(SourceLanguage, File, Producer, IsOptimized, Flags, RuntimeVersion,
SplitDebugFilename, EmissionKind, EnumTypes, RetainedTypes,
GlobalVariables, ImportedEntities, Macros, DWOId, SplitDebugInlining,
DebugInfoForProfiling, NameTableKind, RangesBaseAddress))
DebugInfoForProfiling, NameTableKind, RangesBaseAddress, SysRoot, SDK))

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

Expand All @@ -1306,14 +1311,10 @@ class DICompileUnit : public DIScope {
DebugNameTableKind getNameTableKind() const {
return (DebugNameTableKind)NameTableKind;
}
bool getRangesBaseAddress() const {
return RangesBaseAddress; }
StringRef getProducer() const {
return getStringOperand(1); }
StringRef getFlags() const {
return getStringOperand(2); }
StringRef getSplitDebugFilename() const {
return getStringOperand(3); }
bool getRangesBaseAddress() const { return RangesBaseAddress; }
StringRef getProducer() const { return getStringOperand(1); }
StringRef getFlags() const { return getStringOperand(2); }
StringRef getSplitDebugFilename() const { return getStringOperand(3); }
DICompositeTypeArray getEnumTypes() const {
return cast_or_null<MDTuple>(getRawEnumTypes());
}
Expand All @@ -1335,6 +1336,8 @@ class DICompileUnit : public DIScope {
void setSplitDebugInlining(bool SplitDebugInlining) {
this->SplitDebugInlining = SplitDebugInlining;
}
StringRef getSysRoot() const { return getStringOperand(9); }
StringRef getSDK() const { return getStringOperand(10); }

MDString *getRawProducer() const { return getOperandAs<MDString>(1); }
MDString *getRawFlags() const { return getOperandAs<MDString>(2); }
Expand All @@ -1346,6 +1349,8 @@ class DICompileUnit : public DIScope {
Metadata *getRawGlobalVariables() const { return getOperand(6); }
Metadata *getRawImportedEntities() const { return getOperand(7); }
Metadata *getRawMacros() const { return getOperand(8); }
MDString *getRawSysRoot() const { return getOperandAs<MDString>(9); }
MDString *getRawSDK() const { return getOperandAs<MDString>(10); }

/// Replace arrays.
///
Expand Down Expand Up @@ -2138,50 +2143,45 @@ class DIModule : public DIScope {
: DIScope(Context, DIModuleKind, Storage, dwarf::DW_TAG_module, Ops) {}
~DIModule() = default;

static DIModule *getImpl(LLVMContext &Context, DIScope *Scope,
StringRef Name, StringRef ConfigurationMacros,
StringRef IncludePath, StringRef SysRoot,
static DIModule *getImpl(LLVMContext &Context, DIScope *Scope, StringRef Name,
StringRef ConfigurationMacros, StringRef IncludePath,
StorageType Storage, bool ShouldCreate = true) {
return getImpl(Context, Scope, getCanonicalMDString(Context, Name),
getCanonicalMDString(Context, ConfigurationMacros),
getCanonicalMDString(Context, IncludePath),
getCanonicalMDString(Context, SysRoot),
Storage, ShouldCreate);
}
static DIModule *getImpl(LLVMContext &Context, Metadata *Scope,
MDString *Name, MDString *ConfigurationMacros,
MDString *IncludePath, MDString *SysRoot,
StorageType Storage, bool ShouldCreate = true);
MDString *IncludePath, StorageType Storage,
bool ShouldCreate = true);

TempDIModule cloneImpl() const {
return getTemporary(getContext(), getScope(), getName(),
getConfigurationMacros(), getIncludePath(),
getSysRoot());
getConfigurationMacros(), getIncludePath());
}

public:
DEFINE_MDNODE_GET(DIModule, (DIScope *Scope, StringRef Name,
StringRef ConfigurationMacros, StringRef IncludePath,
StringRef SysRoot),
(Scope, Name, ConfigurationMacros, IncludePath, SysRoot))
DEFINE_MDNODE_GET(DIModule,
(DIScope * Scope, StringRef Name,
StringRef ConfigurationMacros, StringRef IncludePath),
(Scope, Name, ConfigurationMacros, IncludePath))
DEFINE_MDNODE_GET(DIModule,
(Metadata *Scope, MDString *Name, MDString *ConfigurationMacros,
MDString *IncludePath, MDString *SysRoot),
(Scope, Name, ConfigurationMacros, IncludePath, SysRoot))
MDString *IncludePath),
(Scope, Name, ConfigurationMacros, IncludePath))

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

DIScope *getScope() const { return cast_or_null<DIScope>(getRawScope()); }
StringRef getName() const { return getStringOperand(1); }
StringRef getConfigurationMacros() const { return getStringOperand(2); }
StringRef getIncludePath() const { return getStringOperand(3); }
StringRef getSysRoot() const { return getStringOperand(4); }

Metadata *getRawScope() const { return getOperand(0); }
MDString *getRawName() const { return getOperandAs<MDString>(1); }
MDString *getRawConfigurationMacros() const { return getOperandAs<MDString>(2); }
MDString *getRawIncludePath() const { return getOperandAs<MDString>(3); }
MDString *getRawSysRoot() const { return getOperandAs<MDString>(4); }

static bool classof(const Metadata *MD) {
return MD->getMetadataID() == DIModuleKind;
Expand Down
Loading