Skip to content

Commit d406ce8

Browse files
authored
[lldb][macOS] Don't fetch settings in Host, to keep layering (llvm#181406)
I introduced a dependency from Host on Core without realizing it in an earlier PR, while adding a setting to disable the new shared cache binary blob scanning/reading in HostInfoMacOSX, which caused build problems. Thanks to Alex for figuring out the build failure I caused. Add a bool to the methods in HostInfoMacOSX, and have the callers (in Core and various plugins etc) all fetch the symbols.shared-cache-binary-loading setting from ModuleList, and pass the result in. The least obvious part of this is in ProcessGDBRemote where we first learn the shared cache filepath & uuid, it calls HostInfoMacOSX::SharedCacheIndexFiles() - this is only called when the shared cache binary loading is enabled, so I conditionalize the call to this method based on the setting. rdar://148939795
1 parent 58184df commit d406ce8

File tree

13 files changed

+115
-43
lines changed

13 files changed

+115
-43
lines changed

lldb/include/lldb/Core/ModuleList.h

Lines changed: 24 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,29 @@ static constexpr OptionEnumValueElement g_auto_download_enum_values[] = {
6868
},
6969
};
7070

71+
static constexpr OptionEnumValueElement g_shared_cache_use_enum_values[] = {
72+
{
73+
lldb::eSymbolSharedCacheUseHostLLDBMemory,
74+
"host-lldb-memory",
75+
"Get binaries from the host lldb in-memory shared cache.",
76+
},
77+
{
78+
lldb::eSymbolSharedCacheUseHostSharedCache,
79+
"host-shared-cache",
80+
"Get binaries from the host shared cache.",
81+
},
82+
{
83+
lldb::eSymbolSharedCacheUseHostAndInferiorSharedCache,
84+
"host-and-inferior-shared-cache",
85+
"Get binaries from the host and inferior's shared caches.",
86+
},
87+
{
88+
lldb::eSymbolSharedCacheUseInferiorSharedCacheOnly,
89+
"inferior-shared-cache-only",
90+
"Get binaries from inferior's shared cache only.",
91+
},
92+
};
93+
7194
class ModuleListProperties : public Properties {
7295
mutable llvm::sys::RWMutex m_symlink_paths_mutex;
7396
PathMappingList m_symlink_paths;
@@ -81,8 +104,7 @@ class ModuleListProperties : public Properties {
81104
bool SetClangModulesCachePath(const FileSpec &path);
82105
bool GetEnableExternalLookup() const;
83106
bool SetEnableExternalLookup(bool new_value);
84-
bool GetSharedCacheBinaryLoading() const;
85-
bool SetSharedCacheBinaryLoading(bool new_value);
107+
lldb::SymbolSharedCacheUse GetSharedCacheBinaryLoading() const;
86108
bool GetEnableLLDBIndexCache() const;
87109
bool SetEnableLLDBIndexCache(bool new_value);
88110
uint64_t GetLLDBIndexCacheMaxByteSize();

lldb/include/lldb/Host/HostInfoBase.h

Lines changed: 16 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -185,24 +185,37 @@ class HostInfoBase {
185185

186186
/// Return information about module \p image_name if it is loaded in
187187
/// the current process's address space.
188+
///
189+
/// \param[in] use_sc_binary_directly
190+
/// Flag to control if this method can try to read a shared
191+
/// cache binary blob directly, needed to keep user settings out of
192+
/// Host.
188193
static SharedCacheImageInfo
189-
GetSharedCacheImageInfo(llvm::StringRef image_name) {
194+
GetSharedCacheImageInfo(llvm::StringRef image_name,
195+
lldb::SymbolSharedCacheUse sc_mode) {
190196
return {};
191197
}
192198

193199
/// Return information about module \p image_name if it is loaded in
194200
/// the current process's address space using shared cache \p uuid.
195201
/// The shared cache UUID must have been previously indexed.
202+
///
203+
/// \param[in] use_sc_binary_directly
204+
/// Flag to control if this method can try to read a shared
205+
/// cache binary blob directly, needed to keep user settings out of
206+
/// Host.
196207
static SharedCacheImageInfo
197-
GetSharedCacheImageInfo(llvm::StringRef image_name, const UUID &uuid) {
208+
GetSharedCacheImageInfo(llvm::StringRef image_name, const UUID &uuid,
209+
lldb::SymbolSharedCacheUse sc_mode) {
198210
return {};
199211
}
200212

201213
/// Scan the files in a shared cache, if the filepath and uuid match
202214
/// on the debug host.
203215
/// Returns false if the shared cache filepath did not exist, or uuid
204216
/// did not match.
205-
static bool SharedCacheIndexFiles(FileSpec &filepath, UUID &uuid) {
217+
static bool SharedCacheIndexFiles(FileSpec &filepath, UUID &uuid,
218+
lldb::SymbolSharedCacheUse sc_mode) {
206219
return false;
207220
}
208221

lldb/include/lldb/Host/macosx/HostInfoMacOSX.h

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -43,12 +43,15 @@ class HostInfoMacOSX : public HostInfoPosix {
4343

4444
/// Shared cache utilities
4545
static SharedCacheImageInfo
46-
GetSharedCacheImageInfo(llvm::StringRef image_name);
46+
GetSharedCacheImageInfo(llvm::StringRef image_name,
47+
lldb::SymbolSharedCacheUse sc_mode);
4748

4849
static SharedCacheImageInfo
49-
GetSharedCacheImageInfo(llvm::StringRef image_name, const UUID &uuid);
50+
GetSharedCacheImageInfo(llvm::StringRef image_name, const UUID &uuid,
51+
lldb::SymbolSharedCacheUse sc_mode);
5052

51-
static bool SharedCacheIndexFiles(FileSpec &filepath, UUID &uuid);
53+
static bool SharedCacheIndexFiles(FileSpec &filepath, UUID &uuid,
54+
lldb::SymbolSharedCacheUse sc_mode);
5255

5356
protected:
5457
static bool ComputeSupportExeDirectory(FileSpec &file_spec);

lldb/include/lldb/lldb-enumerations.h

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1353,6 +1353,13 @@ enum SymbolDownload {
13531353
eSymbolDownloadForeground = 2,
13541354
};
13551355

1356+
enum SymbolSharedCacheUse {
1357+
eSymbolSharedCacheUseHostLLDBMemory = 1,
1358+
eSymbolSharedCacheUseHostSharedCache = 2,
1359+
eSymbolSharedCacheUseHostAndInferiorSharedCache = 3,
1360+
eSymbolSharedCacheUseInferiorSharedCacheOnly = 4,
1361+
};
1362+
13561363
/// Used in the SBProcess AddressMask/FixAddress methods.
13571364
enum AddressMaskType {
13581365
eAddressMaskTypeCode = 0,

lldb/source/Core/CoreProperties.td

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,10 +14,11 @@ let Definition = "modulelist", Path = "symbols" in {
1414
DefaultEnumValue<"eSymbolDownloadOff">,
1515
EnumValues<"OptionEnumValues(g_auto_download_enum_values)">,
1616
Desc<"On macOS, automatically download symbols with dsymForUUID (or an equivalent script/binary) for relevant images in the debug session.">;
17-
def SharedCacheBinaryLoading: Property<"shared-cache-binary-loading", "Boolean">,
17+
def SharedCacheBinaryLoading: Property<"shared-cache-binary-loading", "Enum">,
1818
Global,
19-
DefaultTrue,
20-
Desc<"On macOS, load the binaries from a shared cache blob directly, instead of loading them from lldb's own in-process shared cache.">;
19+
DefaultEnumValue<"eSymbolSharedCacheUseHostAndInferiorSharedCache">,
20+
EnumValues<"OptionEnumValues(g_shared_cache_use_enum_values)">,
21+
Desc<"On macOS, lldb can use its own in-memory shared cache, or operate on shared cache binaries directly, this setting controls which are used.">;
2122
def ClangModulesCachePath: Property<"clang-modules-cache-path", "FileSpec">,
2223
Global,
2324
DefaultStringValue<"">,

lldb/source/Core/ModuleList.cpp

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -118,14 +118,11 @@ SymbolDownload ModuleListProperties::GetSymbolAutoDownload() const {
118118
g_modulelist_properties[idx].default_uint_value));
119119
}
120120

121-
bool ModuleListProperties::GetSharedCacheBinaryLoading() const {
121+
SymbolSharedCacheUse ModuleListProperties::GetSharedCacheBinaryLoading() const {
122122
const uint32_t idx = ePropertySharedCacheBinaryLoading;
123-
return GetPropertyAtIndexAs<bool>(
124-
idx, g_modulelist_properties[idx].default_uint_value != 0);
125-
}
126-
127-
bool ModuleListProperties::SetSharedCacheBinaryLoading(bool new_value) {
128-
return SetPropertyAtIndex(ePropertySharedCacheBinaryLoading, new_value);
123+
return GetPropertyAtIndexAs<lldb::SymbolSharedCacheUse>(
124+
idx, static_cast<lldb::SymbolSharedCacheUse>(
125+
g_modulelist_properties[idx].default_uint_value));
129126
}
130127

131128
FileSpec ModuleListProperties::GetClangModulesCachePath() const {

lldb/source/Host/macosx/objcxx/CMakeLists.txt

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,6 @@ add_lldb_library(lldbHostMacOSXObjCXX NO_PLUGIN_DEPENDENCIES
1414
Support
1515
TargetParser
1616
LINK_LIBS
17-
lldbCore
1817
lldbUtility
1918
${EXTRA_LIBS}
2019
)

lldb/source/Host/macosx/objcxx/HostInfoMacOSX.mm

Lines changed: 30 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@
77
//===----------------------------------------------------------------------===//
88

99
#include "lldb/Host/macosx/HostInfoMacOSX.h"
10-
#include "lldb/Core/ModuleList.h"
1110
#include "lldb/Host/FileSystem.h"
1211
#include "lldb/Host/Host.h"
1312
#include "lldb/Host/HostInfo.h"
@@ -702,7 +701,7 @@ bool GetImages(llvm::StringMap<SharedCacheImageInfo> **images,
702701
/// system, open it and add all of the binary images to m_caches.
703702
bool CreateSharedCacheImageList(UUID uuid, std::string filepath);
704703

705-
SharedCacheInfo();
704+
SharedCacheInfo(SymbolSharedCacheUse sc_mode);
706705

707706
private:
708707
bool CreateSharedCacheInfoWithInstrospectionSPIs();
@@ -721,7 +720,7 @@ bool GetImages(llvm::StringMap<SharedCacheImageInfo> **images,
721720

722721
} // namespace
723722

724-
SharedCacheInfo::SharedCacheInfo() {
723+
SharedCacheInfo::SharedCacheInfo(SymbolSharedCacheUse sc_mode) {
725724
// macOS 26.4 and newer
726725
m_dyld_image_retain_4HWTrace =
727726
(void (*)(void *))dlsym(RTLD_DEFAULT, "dyld_image_retain_4HWTrace");
@@ -735,14 +734,25 @@ bool GetImages(llvm::StringMap<SharedCacheImageInfo> **images,
735734
_dyld_get_shared_cache_uuid(dsc_uuid);
736735
m_host_uuid = UUID(dsc_uuid);
737736

738-
if (ModuleList::GetGlobalModuleListProperties()
739-
.GetSharedCacheBinaryLoading() &&
740-
CreateHostSharedCacheImageList())
737+
// Don't scan/index lldb's own shared cache at all, in-memory or
738+
// via libdyld SPI.
739+
if (sc_mode == eSymbolSharedCacheUseInferiorSharedCacheOnly)
741740
return;
742741

742+
// Check if the settings allow the use of the libdyld SPI.
743+
bool use_libdyld_spi =
744+
sc_mode == eSymbolSharedCacheUseHostSharedCache ||
745+
sc_mode == eSymbolSharedCacheUseHostAndInferiorSharedCache;
746+
if (use_libdyld_spi && CreateHostSharedCacheImageList())
747+
return;
748+
749+
// Scan lldb's shared cache memory if we're built against the
750+
// internal SDK and have those headers.
743751
if (CreateSharedCacheInfoWithInstrospectionSPIs())
744752
return;
745753

754+
// Scan lldb's shared cache memory if we're built against the public
755+
// SDK.
746756
CreateSharedCacheInfoLLDBsVirtualMemory();
747757
}
748758

@@ -973,32 +983,38 @@ static dispatch_data_t (*g_dyld_image_segment_data_4HWTrace)(
973983
});
974984
}
975985

976-
SharedCacheInfo &GetSharedCacheSingleton() {
977-
static SharedCacheInfo g_shared_cache_info;
986+
SharedCacheInfo &GetSharedCacheSingleton(SymbolSharedCacheUse sc_mode) {
987+
static SharedCacheInfo g_shared_cache_info(sc_mode);
978988
return g_shared_cache_info;
979989
}
980990

981991
SharedCacheImageInfo
982-
HostInfoMacOSX::GetSharedCacheImageInfo(llvm::StringRef image_name) {
983-
return GetSharedCacheSingleton().GetImages().lookup(image_name);
992+
HostInfoMacOSX::GetSharedCacheImageInfo(llvm::StringRef image_name,
993+
SymbolSharedCacheUse sc_mode) {
994+
return GetSharedCacheSingleton(sc_mode).GetImages().lookup(image_name);
984995
}
985996

986997
SharedCacheImageInfo
987998
HostInfoMacOSX::GetSharedCacheImageInfo(llvm::StringRef image_name,
988-
const UUID &uuid) {
999+
const UUID &uuid,
1000+
SymbolSharedCacheUse sc_mode) {
9891001
llvm::StringMap<SharedCacheImageInfo> *shared_cache_info;
990-
if (GetSharedCacheSingleton().GetImages(&shared_cache_info, uuid))
1002+
if (GetSharedCacheSingleton(sc_mode).GetImages(&shared_cache_info, uuid))
9911003
return shared_cache_info->lookup(image_name);
9921004
return {};
9931005
}
9941006

995-
bool HostInfoMacOSX::SharedCacheIndexFiles(FileSpec &filepath, UUID &uuid) {
1007+
bool HostInfoMacOSX::SharedCacheIndexFiles(FileSpec &filepath, UUID &uuid,
1008+
SymbolSharedCacheUse sc_mode) {
1009+
if (sc_mode == eSymbolSharedCacheUseHostLLDBMemory)
1010+
return false;
1011+
9961012
// There is a libdyld SPI to iterate over all installed shared caches,
9971013
// but it can have performance problems if an older Simulator SDK shared
9981014
// cache is installed. So require that we are given a filepath of
9991015
// the shared cache.
10001016
if (FileSystem::Instance().Exists(filepath))
1001-
return GetSharedCacheSingleton().CreateSharedCacheImageList(
1017+
return GetSharedCacheSingleton(sc_mode).CreateSharedCacheImageList(
10021018
uuid, filepath.GetPath());
10031019
return false;
10041020
}

lldb/source/Plugins/DynamicLoader/MacOSX-DYLD/DynamicLoaderDarwin.cpp

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -141,14 +141,16 @@ ModuleSP DynamicLoaderDarwin::FindTargetModuleForImageInfo(
141141
LazyBool using_sc;
142142
LazyBool private_sc;
143143
FileSpec sc_path;
144+
SymbolSharedCacheUse sc_mode = ModuleList::GetGlobalModuleListProperties()
145+
.GetSharedCacheBinaryLoading();
144146
if (GetSharedCacheInformation(sc_base_addr, sc_uuid, using_sc, private_sc,
145147
sc_path) &&
146148
sc_uuid)
147149
image_info = HostInfo::GetSharedCacheImageInfo(
148-
module_spec.GetFileSpec().GetPath(), sc_uuid);
150+
module_spec.GetFileSpec().GetPath(), sc_uuid, sc_mode);
149151
else
150152
image_info = HostInfo::GetSharedCacheImageInfo(
151-
module_spec.GetFileSpec().GetPath());
153+
module_spec.GetFileSpec().GetPath(), sc_mode);
152154

153155
// If we found it and it has the correct UUID, let's proceed with
154156
// creating a module from the memory contents.

lldb/source/Plugins/Platform/MacOSX/PlatformDarwinDevice.cpp

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -319,6 +319,8 @@ lldb_private::Status PlatformDarwinDevice::GetSharedModuleWithLocalCache(
319319
// exist on the filesystem, so let's use the images in our own memory
320320
// to create the modules.
321321

322+
SymbolSharedCacheUse sc_mode = ModuleList::GetGlobalModuleListProperties()
323+
.GetSharedCacheBinaryLoading();
322324
SharedCacheImageInfo image_info;
323325
if (process && process->GetDynamicLoader()) {
324326
addr_t sc_base_addr;
@@ -328,12 +330,12 @@ lldb_private::Status PlatformDarwinDevice::GetSharedModuleWithLocalCache(
328330
if (process->GetDynamicLoader()->GetSharedCacheInformation(
329331
sc_base_addr, sc_uuid, using_sc, private_sc, sc_path))
330332
image_info = HostInfo::GetSharedCacheImageInfo(
331-
module_spec.GetFileSpec().GetPath(), sc_uuid);
333+
module_spec.GetFileSpec().GetPath(), sc_uuid, sc_mode);
332334
}
333335

334336
if (!image_info.GetUUID())
335337
image_info = HostInfo::GetSharedCacheImageInfo(
336-
module_spec.GetFileSpec().GetPath());
338+
module_spec.GetFileSpec().GetPath(), sc_mode);
337339

338340
// If we found it and it has the correct UUID, let's proceed with
339341
// creating a module from the memory contents.

0 commit comments

Comments
 (0)