1
0
mirror of https://github.com/RPCS3/llvm-mirror.git synced 2024-10-18 10:32:48 +02:00

Add an SDK attribute to DICompileUnit

This is part of PR44213 https://bugs.llvm.org/show_bug.cgi?id=44213

When importing (system) Clang modules, LLDB needs to know which SDK
(e.g., MacOSX, iPhoneSimulator, ...) they came from. While the sysroot
attribute contains the absolute path to the SDK, this doesn't work
well when the debugger is run on a different machine than the
compiler, and the SDKs are installed in different directories. It thus
makes sense to just store the name of the SDK instead of the absolute
path, so it can be found relative to LLDB.

rdar://problem/51645582

Differential Revision: https://reviews.llvm.org/D75646
This commit is contained in:
Adrian Prantl 2020-03-04 14:12:54 -08:00
parent 699a46fa8b
commit ebfa474806
16 changed files with 67 additions and 31 deletions

View File

@ -118,6 +118,7 @@ type DICompileUnit struct {
Flags string
RuntimeVersion int
SysRoot string
SDK string
}
// CreateCompileUnit creates compile unit debug metadata.
@ -132,6 +133,8 @@ func (d *DIBuilder) CreateCompileUnit(cu DICompileUnit) Metadata {
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),
@ -146,6 +149,7 @@ func (d *DIBuilder) CreateCompileUnit(cu DICompileUnit) Metadata {
/*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}
}

View File

@ -252,6 +252,8 @@ void LLVMDIBuilderFinalize(LLVMDIBuilderRef Builder);
* 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,
@ -259,7 +261,8 @@ LLVMMetadataRef LLVMDIBuilderCreateCompileUnit(
LLVMBool isOptimized, const char *Flags, size_t FlagsLen,
unsigned RuntimeVer, const char *SplitName, size_t SplitNameLen,
LLVMDWARFEmissionKind Kind, unsigned DWOId, LLVMBool SplitDebugInlining,
LLVMBool DebugInfoForProfiling, const char *SysRoot, size_t SysRootLen);
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.

View File

@ -427,6 +427,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)

View File

@ -136,6 +136,8 @@ namespace llvm {
/// \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,
@ -146,7 +148,8 @@ namespace llvm {
bool DebugInfoForProfiling = false,
DICompileUnit::DebugNameTableKind NameTableKind =
DICompileUnit::DebugNameTableKind::Default,
bool RangesBaseAddress = false, StringRef SysRoot = {});
bool RangesBaseAddress = false, StringRef SysRoot = {},
StringRef SDK = {});
/// Create a file descriptor to hold debugging information for a file.
/// \param Filename File name.

View File

@ -1173,7 +1173,7 @@ private:
DIImportedEntityArray ImportedEntities, DIMacroNodeArray Macros,
uint64_t DWOId, bool SplitDebugInlining, bool DebugInfoForProfiling,
unsigned NameTableKind, bool RangesBaseAddress, StringRef SysRoot,
StorageType Storage, bool ShouldCreate = true) {
StringRef SDK, StorageType Storage, bool ShouldCreate = true) {
return getImpl(
Context, SourceLanguage, File, getCanonicalMDString(Context, Producer),
IsOptimized, getCanonicalMDString(Context, Flags), RuntimeVersion,
@ -1181,7 +1181,8 @@ private:
EnumTypes.get(), RetainedTypes.get(), GlobalVariables.get(),
ImportedEntities.get(), Macros.get(), DWOId, SplitDebugInlining,
DebugInfoForProfiling, NameTableKind, RangesBaseAddress,
getCanonicalMDString(Context, SysRoot), Storage, ShouldCreate);
getCanonicalMDString(Context, SysRoot),
getCanonicalMDString(Context, SDK), Storage, ShouldCreate);
}
static DICompileUnit *
getImpl(LLVMContext &Context, unsigned SourceLanguage, Metadata *File,
@ -1191,8 +1192,8 @@ private:
Metadata *GlobalVariables, Metadata *ImportedEntities,
Metadata *Macros, uint64_t DWOId, bool SplitDebugInlining,
bool DebugInfoForProfiling, unsigned NameTableKind,
bool RangesBaseAddress, MDString *SysRoot, StorageType Storage,
bool ShouldCreate = true);
bool RangesBaseAddress, MDString *SysRoot, MDString *SDK,
StorageType Storage, bool ShouldCreate = true);
TempDICompileUnit cloneImpl() const {
return getTemporary(
@ -1201,7 +1202,7 @@ private:
getEmissionKind(), getEnumTypes(), getRetainedTypes(),
getGlobalVariables(), getImportedEntities(), getMacros(), DWOId,
getSplitDebugInlining(), getDebugInfoForProfiling(), getNameTableKind(),
getRangesBaseAddress(), getSysRoot());
getRangesBaseAddress(), getSysRoot(), getSDK());
}
public:
@ -1218,12 +1219,12 @@ public:
DIImportedEntityArray ImportedEntities, DIMacroNodeArray Macros,
uint64_t DWOId, bool SplitDebugInlining, bool DebugInfoForProfiling,
DebugNameTableKind NameTableKind, bool RangesBaseAddress,
StringRef SysRoot),
StringRef SysRoot, StringRef SDK),
(SourceLanguage, File, Producer, IsOptimized, Flags, RuntimeVersion,
SplitDebugFilename, EmissionKind, EnumTypes, RetainedTypes,
GlobalVariables, ImportedEntities, Macros, DWOId, SplitDebugInlining,
DebugInfoForProfiling, (unsigned)NameTableKind, RangesBaseAddress,
SysRoot))
SysRoot, SDK))
DEFINE_MDNODE_GET_DISTINCT_TEMPORARY(
DICompileUnit,
(unsigned SourceLanguage, Metadata *File, MDString *Producer,
@ -1232,11 +1233,12 @@ public:
Metadata *RetainedTypes, Metadata *GlobalVariables,
Metadata *ImportedEntities, Metadata *Macros, uint64_t DWOId,
bool SplitDebugInlining, bool DebugInfoForProfiling,
unsigned NameTableKind, bool RangesBaseAddress, MDString *SysRoot),
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, SysRoot))
DebugInfoForProfiling, NameTableKind, RangesBaseAddress, SysRoot, SDK))
TempDICompileUnit clone() const { return cloneImpl(); }
@ -1279,6 +1281,7 @@ public:
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); }
@ -1291,6 +1294,7 @@ public:
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.
///

View File

@ -4637,7 +4637,7 @@ bool LLParser::ParseDIFile(MDNode *&Result, bool IsDistinct) {
/// splitDebugFilename: "abc.debug",
/// emissionKind: FullDebug, enums: !1, retainedTypes: !2,
/// globals: !4, imports: !5, macros: !6, dwoId: 0x0abcd,
/// sysroot: "/")
/// sysroot: "/", sdk: "MacOSX.sdk")
bool LLParser::ParseDICompileUnit(MDNode *&Result, bool IsDistinct) {
if (!IsDistinct)
return Lex.Error("missing 'distinct', required for !DICompileUnit");
@ -4661,7 +4661,8 @@ bool LLParser::ParseDICompileUnit(MDNode *&Result, bool IsDistinct) {
OPTIONAL(debugInfoForProfiling, MDBoolField, = false); \
OPTIONAL(nameTableKind, NameTableKindField, ); \
OPTIONAL(debugBaseAddress, MDBoolField, = false); \
OPTIONAL(sysroot, MDStringField, );
OPTIONAL(sysroot, MDStringField, ); \
OPTIONAL(sdk, MDStringField, );
PARSE_MD_FIELDS();
#undef VISIT_MD_FIELDS
@ -4670,7 +4671,7 @@ bool LLParser::ParseDICompileUnit(MDNode *&Result, bool IsDistinct) {
runtimeVersion.Val, splitDebugFilename.Val, emissionKind.Val, enums.Val,
retainedTypes.Val, globals.Val, imports.Val, macros.Val, dwoId.Val,
splitDebugInlining.Val, debugInfoForProfiling.Val, nameTableKind.Val,
debugBaseAddress.Val, sysroot.Val);
debugBaseAddress.Val, sysroot.Val, sdk.Val);
return false;
}

View File

@ -1456,7 +1456,7 @@ Error MetadataLoader::MetadataLoaderImpl::parseOneMetadata(
break;
}
case bitc::METADATA_COMPILE_UNIT: {
if (Record.size() < 14 || Record.size() > 21)
if (Record.size() < 14 || Record.size() > 22)
return error("Invalid record");
// Ignore Record[0], which indicates whether this compile unit is
@ -1474,7 +1474,8 @@ Error MetadataLoader::MetadataLoaderImpl::parseOneMetadata(
Record.size() <= 18 ? 0 : Record[18],
false, // FIXME: https://reviews.llvm.org/rGc51b45e32ef7f35c11891f60871aa9c2c04cd991
// Record.size() <= 19 ? 0 : Record[19],
Record.size() <= 20 ? nullptr : getMDString(Record[20]));
Record.size() <= 20 ? nullptr : getMDString(Record[20]),
Record.size() <= 21 ? nullptr : getMDString(Record[21]));
MetadataList.assignValue(CU, NextMetadataNo);
NextMetadataNo++;

View File

@ -1669,6 +1669,7 @@ void ModuleBitcodeWriter::writeDICompileUnit(const DICompileUnit *N,
Record.push_back((unsigned)N->getNameTableKind());
Record.push_back(N->getRangesBaseAddress());
Record.push_back(VE.getMetadataOrNullID(N->getRawSysRoot()));
Record.push_back(VE.getMetadataOrNullID(N->getRawSDK()));
Stream.EmitRecord(bitc::METADATA_COMPILE_UNIT, Record, Abbrev);
Record.clear();

View File

@ -930,6 +930,9 @@ void DwarfDebug::finishUnitAttributes(const DICompileUnit *DIUnit,
StringRef SysRoot = DIUnit->getSysRoot();
if (!SysRoot.empty())
NewCU.addString(Die, dwarf::DW_AT_LLVM_sysroot, SysRoot);
StringRef SDK = DIUnit->getSDK();
if (!SDK.empty())
NewCU.addString(Die, dwarf::DW_AT_APPLE_sdk, SDK);
// Add DW_str_offsets_base to the unit DIE, except for split units.
if (useSegmentedStringOffsetsTable() && !useSplitDwarf())

View File

@ -1948,6 +1948,7 @@ static void writeDICompileUnit(raw_ostream &Out, const DICompileUnit *N,
Printer.printNameTableKind("nameTableKind", N->getNameTableKind());
Printer.printBool("rangesBaseAddress", N->getRangesBaseAddress(), false);
Printer.printString("sysroot", N->getSysRoot());
Printer.printString("sdk", N->getSDK());
Out << ")";
}

View File

@ -141,7 +141,7 @@ DICompileUnit *DIBuilder::createCompileUnit(
DICompileUnit::DebugEmissionKind Kind, uint64_t DWOId,
bool SplitDebugInlining, bool DebugInfoForProfiling,
DICompileUnit::DebugNameTableKind NameTableKind, bool RangesBaseAddress,
StringRef SysRoot) {
StringRef SysRoot, StringRef SDK) {
assert(((Lang <= dwarf::DW_LANG_Fortran08 && Lang >= dwarf::DW_LANG_C89) ||
(Lang <= dwarf::DW_LANG_hi_user && Lang >= dwarf::DW_LANG_lo_user)) &&
@ -152,7 +152,7 @@ DICompileUnit *DIBuilder::createCompileUnit(
VMContext, Lang, File, Producer, isOptimized, Flags, RunTimeVer,
SplitName, Kind, nullptr, nullptr, nullptr, nullptr, nullptr, DWOId,
SplitDebugInlining, DebugInfoForProfiling, NameTableKind,
RangesBaseAddress, SysRoot);
RangesBaseAddress, SysRoot, SDK);
// Create a named metadata so that it is easier to find cu in a module.
NamedMDNode *NMD = M.getOrInsertNamedMetadata("llvm.dbg.cu");

View File

@ -497,7 +497,7 @@ private:
RetainedTypes, GlobalVariables, ImportedEntities, CU->getMacros(),
CU->getDWOId(), CU->getSplitDebugInlining(),
CU->getDebugInfoForProfiling(), CU->getNameTableKind(),
CU->getRangesBaseAddress(), CU->getSysRoot());
CU->getRangesBaseAddress(), CU->getSysRoot(), CU->getSDK());
}
DILocation *getReplacementMDLocation(DILocation *MLD) {
@ -765,7 +765,8 @@ LLVMMetadataRef LLVMDIBuilderCreateCompileUnit(
LLVMBool isOptimized, const char *Flags, size_t FlagsLen,
unsigned RuntimeVer, const char *SplitName, size_t SplitNameLen,
LLVMDWARFEmissionKind Kind, unsigned DWOId, LLVMBool SplitDebugInlining,
LLVMBool DebugInfoForProfiling, const char *SysRoot, size_t SysRootLen) {
LLVMBool DebugInfoForProfiling, const char *SysRoot, size_t SysRootLen,
const char *SDK, size_t SDKLen) {
auto File = unwrapDI<DIFile>(FileRef);
return wrap(unwrap(Builder)->createCompileUnit(
@ -775,7 +776,7 @@ LLVMMetadataRef LLVMDIBuilderCreateCompileUnit(
static_cast<DICompileUnit::DebugEmissionKind>(Kind), DWOId,
SplitDebugInlining, DebugInfoForProfiling,
DICompileUnit::DebugNameTableKind::Default, false,
StringRef(SysRoot, SysRootLen)));
StringRef(SysRoot, SysRootLen), StringRef(SDK, SDKLen)));
}
LLVMMetadataRef

View File

@ -521,16 +521,23 @@ DICompileUnit *DICompileUnit::getImpl(
Metadata *GlobalVariables, Metadata *ImportedEntities, Metadata *Macros,
uint64_t DWOId, bool SplitDebugInlining, bool DebugInfoForProfiling,
unsigned NameTableKind, bool RangesBaseAddress, MDString *SysRoot,
StorageType Storage, bool ShouldCreate) {
MDString *SDK, StorageType Storage, bool ShouldCreate) {
assert(Storage != Uniqued && "Cannot unique DICompileUnit");
assert(isCanonical(Producer) && "Expected canonical MDString");
assert(isCanonical(Flags) && "Expected canonical MDString");
assert(isCanonical(SplitDebugFilename) && "Expected canonical MDString");
Metadata *Ops[] = {
File, Producer, Flags, SplitDebugFilename,
EnumTypes, RetainedTypes, GlobalVariables, ImportedEntities,
Macros, SysRoot};
Metadata *Ops[] = {File,
Producer,
Flags,
SplitDebugFilename,
EnumTypes,
RetainedTypes,
GlobalVariables,
ImportedEntities,
Macros,
SysRoot,
SDK};
return storeImpl(new (array_lengthof(Ops)) DICompileUnit(
Context, Storage, SourceLanguage, IsOptimized,
RuntimeVersion, EmissionKind, DWOId, SplitDebugInlining,

View File

@ -4,9 +4,11 @@
; CHECK: DW_TAG_skeleton_unit
; CHECK-NOT: DW_AT_LLVM_sysroot
; CHECK-NOT: DW_AT_LLVM_sdk
; CHECK: DW_TAG_compile_unit
; CHECK-NOT: DW_TAG
; CHECK: DW_AT_LLVM_sysroot ("/opt/clang-root")
; CHECK: DW_AT_APPLE_sdk ("Linux.sdk")
target triple = "x86_64-pc-linux"
@ -21,7 +23,7 @@ entry:
!llvm.dbg.cu = !{!0}
!llvm.module.flags = !{!6, !7, !8}
!0 = distinct !DICompileUnit(language: DW_LANG_C, file: !1, emissionKind: FullDebug, enums: !2, sysroot: "/opt/clang-root")
!0 = distinct !DICompileUnit(language: DW_LANG_C, file: !1, emissionKind: FullDebug, enums: !2, sysroot: "/opt/clang-root", sdk: "Linux.sdk")
!1 = !DIFile(filename: "a.c", directory: "/")
!2 = !{}
!6 = !{i32 2, !"Dwarf Version", i32 5}

View File

@ -38,7 +38,7 @@ int llvm_test_dibuilder(void) {
LLVMMetadataRef CompileUnit = LLVMDIBuilderCreateCompileUnit(
DIB, LLVMDWARFSourceLanguageC, File, "llvm-c-test", 11, 0, NULL, 0, 0,
NULL, 0, LLVMDWARFEmissionFull, 0, 0, 0, "/", 1);
NULL, 0, LLVMDWARFEmissionFull, 0, 0, 0, "/", 1, "", 0);
LLVMMetadataRef Module =
LLVMDIBuilderCreateModule(DIB, CompileUnit,

View File

@ -96,7 +96,7 @@ protected:
Context, 1, getFile(), "clang", false, "-g", 2, "",
DICompileUnit::FullDebug, getTuple(), getTuple(), getTuple(),
getTuple(), getTuple(), 0, true, false,
DICompileUnit::DebugNameTableKind::Default, false, "/");
DICompileUnit::DebugNameTableKind::Default, false, "/", "");
}
DIType *getBasicType(StringRef Name) {
return DIBasicType::get(Context, dwarf::DW_TAG_unspecified_type, Name);
@ -1710,11 +1710,12 @@ TEST_F(DICompileUnitTest, get) {
uint64_t DWOId = 0x10000000c0ffee;
MDTuple *Macros = getTuple();
StringRef SysRoot = "/";
StringRef SDK = "MacOSX.sdk";
auto *N = DICompileUnit::getDistinct(
Context, SourceLanguage, File, Producer, IsOptimized, Flags,
RuntimeVersion, SplitDebugFilename, EmissionKind, EnumTypes,
RetainedTypes, GlobalVariables, ImportedEntities, Macros, DWOId, true,
false, DICompileUnit::DebugNameTableKind::Default, false, SysRoot);
false, DICompileUnit::DebugNameTableKind::Default, false, SysRoot, SDK);
EXPECT_EQ(dwarf::DW_TAG_compile_unit, N->getTag());
EXPECT_EQ(SourceLanguage, N->getSourceLanguage());
@ -1732,6 +1733,7 @@ TEST_F(DICompileUnitTest, get) {
EXPECT_EQ(Macros, N->getMacros().get());
EXPECT_EQ(DWOId, N->getDWOId());
EXPECT_EQ(SysRoot, N->getSysRoot());
EXPECT_EQ(SDK, N->getSDK());
TempDICompileUnit Temp = N->clone();
EXPECT_EQ(dwarf::DW_TAG_compile_unit, Temp->getTag());
@ -1749,6 +1751,7 @@ TEST_F(DICompileUnitTest, get) {
EXPECT_EQ(ImportedEntities, Temp->getImportedEntities().get());
EXPECT_EQ(Macros, Temp->getMacros().get());
EXPECT_EQ(SysRoot, Temp->getSysRoot());
EXPECT_EQ(SDK, Temp->getSDK());
auto *TempAddress = Temp.get();
auto *Clone = MDNode::replaceWithPermanent(std::move(Temp));
@ -1770,11 +1773,12 @@ TEST_F(DICompileUnitTest, replaceArrays) {
MDTuple *ImportedEntities = MDTuple::getDistinct(Context, None);
uint64_t DWOId = 0xc0ffee;
StringRef SysRoot = "/";
StringRef SDK = "MacOSX.sdk";
auto *N = DICompileUnit::getDistinct(
Context, SourceLanguage, File, Producer, IsOptimized, Flags,
RuntimeVersion, SplitDebugFilename, EmissionKind, EnumTypes,
RetainedTypes, nullptr, ImportedEntities, nullptr, DWOId, true, false,
DICompileUnit::DebugNameTableKind::Default, false, SysRoot);
DICompileUnit::DebugNameTableKind::Default, false, SysRoot, SDK);
auto *GlobalVariables = MDTuple::getDistinct(Context, None);
EXPECT_EQ(nullptr, N->getGlobalVariables().get());