Skip to content

Commit 8dd1060

Browse files
cooperxuJDevlieghere
authored andcommitted
[debugserver] Add platform cache support to improve performance.
The dyld SPI used by debugserver (_dyld_process_info_create) has become much slower in macOS BigSur 11.3 causing a significant performance regression when attaching. This commit mitigates that by caching the result when calling the SPI to compute the platform. Differential revision: https://reviews.llvm.org/D102833
1 parent a888e49 commit 8dd1060

File tree

2 files changed

+13
-3
lines changed

2 files changed

+13
-3
lines changed

lldb/tools/debugserver/source/MacOSX/MachProcess.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -252,6 +252,7 @@ class MachProcess {
252252
struct mach_o_information &inf);
253253
JSONGenerator::ObjectSP FormatDynamicLibrariesIntoJSON(
254254
const std::vector<struct binary_image_information> &image_infos);
255+
uint32_t GetPlatform();
255256
/// Get the runtime platform from DYLD via SPI.
256257
uint32_t GetProcessPlatformViaDYLDSPI();
257258
/// Use the dyld SPI present in macOS 10.12, iOS 10, tvOS 10,
@@ -378,6 +379,7 @@ class MachProcess {
378379

379380
pid_t m_pid; // Process ID of child process
380381
cpu_type_t m_cpu_type; // The CPU type of this process
382+
uint32_t m_platform; // The platform of this process
381383
int m_child_stdin;
382384
int m_child_stdout;
383385
int m_child_stderr;

lldb/tools/debugserver/source/MacOSX/MachProcess.mm

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -701,7 +701,7 @@ static bool FBSAddEventDataToOptions(NSMutableDictionary *options,
701701
// DYLD_FORCE_PLATFORM=6. In that case, force the platform to
702702
// macCatalyst and use the macCatalyst version of the host OS
703703
// instead of the macOS deployment target.
704-
if (is_executable && GetProcessPlatformViaDYLDSPI() == PLATFORM_MACCATALYST) {
704+
if (is_executable && GetPlatform() == PLATFORM_MACCATALYST) {
705705
info.platform = PLATFORM_MACCATALYST;
706706
std::string catalyst_version = GetMacCatalystVersionString();
707707
const char *major = catalyst_version.c_str();
@@ -1094,6 +1094,12 @@ static bool FBSAddEventDataToOptions(NSMutableDictionary *options,
10941094
bool privateCache;
10951095
};
10961096

1097+
uint32_t MachProcess::GetPlatform() {
1098+
if (m_platform == 0)
1099+
m_platform = MachProcess::GetProcessPlatformViaDYLDSPI();
1100+
return m_platform;
1101+
}
1102+
10971103
uint32_t MachProcess::GetProcessPlatformViaDYLDSPI() {
10981104
kern_return_t kern_ret;
10991105
uint32_t platform = 0;
@@ -1140,7 +1146,7 @@ static bool FBSAddEventDataToOptions(NSMutableDictionary *options,
11401146
int pointer_size = GetInferiorAddrSize(pid);
11411147
std::vector<struct binary_image_information> image_infos;
11421148
GetAllLoadedBinariesViaDYLDSPI(image_infos);
1143-
uint32_t platform = GetProcessPlatformViaDYLDSPI();
1149+
uint32_t platform = GetPlatform();
11441150
const size_t image_count = image_infos.size();
11451151
for (size_t i = 0; i < image_count; i++) {
11461152
GetMachOInformationFromMemory(platform, image_infos[i].load_address,
@@ -1160,7 +1166,7 @@ static bool FBSAddEventDataToOptions(NSMutableDictionary *options,
11601166

11611167
std::vector<struct binary_image_information> all_image_infos;
11621168
GetAllLoadedBinariesViaDYLDSPI(all_image_infos);
1163-
uint32_t platform = GetProcessPlatformViaDYLDSPI();
1169+
uint32_t platform = GetPlatform();
11641170

11651171
std::vector<struct binary_image_information> image_infos;
11661172
const size_t macho_addresses_count = macho_addresses.size();
@@ -1324,6 +1330,7 @@ static bool FBSAddEventDataToOptions(NSMutableDictionary *options,
13241330
// Clear any cached thread list while the pid and task are still valid
13251331

13261332
m_task.Clear();
1333+
m_platform = 0;
13271334
// Now clear out all member variables
13281335
m_pid = INVALID_NUB_PROCESS;
13291336
if (!detaching)
@@ -1615,6 +1622,7 @@ static bool FBSAddEventDataToOptions(NSMutableDictionary *options,
16151622

16161623
// NULL our task out as we have already restored all exception ports
16171624
m_task.Clear();
1625+
m_platform = 0;
16181626

16191627
// Clear out any notion of the process we once were
16201628
const bool detaching = true;

0 commit comments

Comments
 (0)