Skip to content

Commit 5935227

Browse files
committed
Add an explicit API to read the Xcode SDK DWARF attribute from compile units
When debugging from a SymbolMap the creation of CompileUnits for the individual object files is so lazy that RegisterXcodeSDK() is not invoked at all before the Swift TypeSystem wants to read it. This patch fixes this by introducing an explicit SymbolFile::ParseXcodeSDK() call that can be invoked deterministically before the result is required. <rdar://problem/62532151+62326862> https://reviews.llvm.org/D79273
1 parent 5e3ab8f commit 5935227

File tree

8 files changed

+42
-22
lines changed

8 files changed

+42
-22
lines changed

lldb/include/lldb/Core/Module.h

Lines changed: 0 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -512,7 +512,6 @@ class Module : public std::enable_shared_from_this<Module>,
512512

513513
/// This callback will be called by SymbolFile implementations when
514514
/// parsing a compile unit that contains SDK information.
515-
/// \param sdk will be merged with \p m_sdk.
516515
/// \param sysroot will be added to the path remapping dictionary.
517516
void RegisterXcodeSDK(llvm::StringRef sdk, llvm::StringRef sysroot);
518517

@@ -864,11 +863,6 @@ class Module : public std::enable_shared_from_this<Module>,
864863
bool RemapSourceFile(llvm::StringRef path, std::string &new_path) const;
865864
bool RemapSourceFile(const char *, std::string &) const = delete;
866865

867-
/// Return the Xcode SDK this module was compiled against. This
868-
/// is computed by merging the SDKs from each compilation unit in
869-
/// the module.
870-
XcodeSDK GetXcodeSDK() const { return m_xcode_sdk; }
871-
872866
/// Update the ArchSpec to a more specific variant.
873867
bool MergeArchitecture(const ArchSpec &arch_spec);
874868

@@ -984,9 +978,6 @@ class Module : public std::enable_shared_from_this<Module>,
984978
PathMappingList m_source_mappings =
985979
ModuleList::GetGlobalModuleListProperties().GetSymlinkMappings();
986980

987-
/// The (Xcode) SDK this module was compiled with.
988-
XcodeSDK m_xcode_sdk;
989-
990981
lldb::SectionListUP m_sections_up; ///< Unified section list for module that
991982
/// is used by the ObjectFile and and
992983
/// ObjectFile instances for the debug info

lldb/include/lldb/Symbol/SymbolFile.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818
#include "lldb/Symbol/Type.h"
1919
#include "lldb/Symbol/TypeList.h"
2020
#include "lldb/Symbol/TypeSystem.h"
21+
#include "lldb/Utility/XcodeSDK.h"
2122
#include "lldb/lldb-private.h"
2223
#include "llvm/ADT/DenseSet.h"
2324
#include "llvm/Support/Errc.h"
@@ -128,6 +129,8 @@ class SymbolFile : public PluginInterface {
128129
Symtab *GetSymtab();
129130

130131
virtual lldb::LanguageType ParseLanguage(CompileUnit &comp_unit) = 0;
132+
/// Return the Xcode SDK comp_unit was compiled against.
133+
virtual XcodeSDK ParseXcodeSDK(CompileUnit &comp_unit) { return {}; }
131134
virtual size_t ParseFunctions(CompileUnit &comp_unit) = 0;
132135
virtual bool ParseLineTable(CompileUnit &comp_unit) = 0;
133136
virtual bool ParseDebugMacros(CompileUnit &comp_unit) = 0;

lldb/source/Core/Module.cpp

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1598,9 +1598,6 @@ bool Module::RemapSourceFile(llvm::StringRef path,
15981598

15991599
void Module::RegisterXcodeSDK(llvm::StringRef sdk_name, llvm::StringRef sysroot) {
16001600
XcodeSDK sdk(sdk_name.str());
1601-
if (m_xcode_sdk == sdk)
1602-
return;
1603-
m_xcode_sdk.Merge(sdk);
16041601
PlatformSP module_platform =
16051602
Platform::GetPlatformForArchitecture(GetArchitecture(), nullptr);
16061603
ConstString sdk_path(module_platform->GetSDKPath(sdk));

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

Lines changed: 20 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -664,12 +664,6 @@ lldb::CompUnitSP SymbolFileDWARF::ParseCompileUnit(DWARFCompileUnit &dwarf_cu) {
664664
const DWARFBaseDIE cu_die =
665665
dwarf_cu.GetNonSkeletonUnit().GetUnitDIEOnly();
666666
if (cu_die) {
667-
if (const char *sdk =
668-
cu_die.GetAttributeValueAsString(DW_AT_APPLE_sdk, nullptr)) {
669-
const char *sysroot =
670-
cu_die.GetAttributeValueAsString(DW_AT_LLVM_sysroot, "");
671-
module_sp->RegisterXcodeSDK(sdk, sysroot);
672-
}
673667
FileSpec cu_file_spec(cu_die.GetName(), dwarf_cu.GetPathStyle());
674668
MakeAbsoluteAndRemap(cu_file_spec, dwarf_cu, module_sp);
675669

@@ -778,6 +772,26 @@ lldb::LanguageType SymbolFileDWARF::ParseLanguage(CompileUnit &comp_unit) {
778772
return eLanguageTypeUnknown;
779773
}
780774

775+
XcodeSDK SymbolFileDWARF::ParseXcodeSDK(CompileUnit &comp_unit) {
776+
std::lock_guard<std::recursive_mutex> guard(GetModuleMutex());
777+
DWARFUnit *dwarf_cu = GetDWARFCompileUnit(&comp_unit);
778+
if (!dwarf_cu)
779+
return {};
780+
ModuleSP module_sp = m_objfile_sp->GetModule();
781+
if (!module_sp)
782+
return {};
783+
const DWARFBaseDIE cu_die = dwarf_cu->GetNonSkeletonUnit().GetUnitDIEOnly();
784+
if (!cu_die)
785+
return {};
786+
const char *sdk = cu_die.GetAttributeValueAsString(DW_AT_APPLE_sdk, nullptr);
787+
if (!sdk)
788+
return {};
789+
const char *sysroot =
790+
cu_die.GetAttributeValueAsString(DW_AT_LLVM_sysroot, "");
791+
module_sp->RegisterXcodeSDK(sdk, sysroot);
792+
return {sdk};
793+
}
794+
781795
size_t SymbolFileDWARF::ParseFunctions(CompileUnit &comp_unit) {
782796
static Timer::Category func_cat(LLVM_PRETTY_FUNCTION);
783797
Timer scoped_timer(func_cat, "SymbolFileDWARF::ParseFunctions");

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

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -106,6 +106,9 @@ class SymbolFileDWARF : public lldb_private::SymbolFile,
106106
lldb::LanguageType
107107
ParseLanguage(lldb_private::CompileUnit &comp_unit) override;
108108

109+
lldb_private::XcodeSDK
110+
ParseXcodeSDK(lldb_private::CompileUnit &comp_unit) override;
111+
109112
size_t ParseFunctions(lldb_private::CompileUnit &comp_unit) override;
110113

111114
bool ParseLineTable(lldb_private::CompileUnit &comp_unit) override;

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

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -628,6 +628,15 @@ SymbolFileDWARFDebugMap::ParseLanguage(CompileUnit &comp_unit) {
628628
return eLanguageTypeUnknown;
629629
}
630630

631+
XcodeSDK
632+
SymbolFileDWARFDebugMap::ParseXcodeSDK(CompileUnit &comp_unit) {
633+
std::lock_guard<std::recursive_mutex> guard(GetModuleMutex());
634+
SymbolFileDWARF *oso_dwarf = GetSymbolFile(comp_unit);
635+
if (oso_dwarf)
636+
return oso_dwarf->ParseXcodeSDK(comp_unit);
637+
return {};
638+
}
639+
631640
size_t SymbolFileDWARFDebugMap::ParseFunctions(CompileUnit &comp_unit) {
632641
std::lock_guard<std::recursive_mutex> guard(GetModuleMutex());
633642
SymbolFileDWARF *oso_dwarf = GetSymbolFile(comp_unit);

lldb/source/Plugins/SymbolFile/DWARF/SymbolFileDWARFDebugMap.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,9 @@ class SymbolFileDWARFDebugMap : public lldb_private::SymbolFile {
5858
lldb::LanguageType
5959
ParseLanguage(lldb_private::CompileUnit &comp_unit) override;
6060

61+
lldb_private::XcodeSDK
62+
ParseXcodeSDK(lldb_private::CompileUnit &comp_unit) override;
63+
6164
size_t ParseFunctions(lldb_private::CompileUnit &comp_unit) override;
6265

6366
bool ParseLineTable(lldb_private::CompileUnit &comp_unit) override;

lldb/unittests/SymbolFile/DWARF/XcodeSDKModuleTests.cpp

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -64,13 +64,13 @@ TEST_F(XcodeSDKModuleTests, TestModuleGetXcodeSDK) {
6464

6565
auto triple = "x86_64-apple-macosx";
6666
YAMLModuleTester t(yamldata, triple);
67-
auto module = t.GetModule();
6867
auto dwarf_unit_sp = t.GetDwarfUnit();
6968
auto *dwarf_cu = llvm::cast<DWARFCompileUnit>(dwarf_unit_sp.get());
7069
ASSERT_TRUE((bool)dwarf_cu);
71-
ASSERT_TRUE((bool)dwarf_cu->GetSymbolFileDWARF().GetCompUnitForDWARFCompUnit(
72-
*dwarf_cu));
73-
XcodeSDK sdk = module->GetXcodeSDK();
70+
SymbolFileDWARF &sym_file = dwarf_cu->GetSymbolFileDWARF();
71+
CompUnitSP comp_unit = sym_file.GetCompileUnitAtIndex(0);
72+
ASSERT_TRUE((bool)comp_unit.get());
73+
XcodeSDK sdk = sym_file.ParseXcodeSDK(*comp_unit);
7474
ASSERT_EQ(sdk.GetType(), XcodeSDK::Type::MacOSX);
7575
}
7676
#endif

0 commit comments

Comments
 (0)