Skip to content

Commit d74493d

Browse files
authored
Merge pull request #2983 from apple/🍒/ganymede/8dd106028b1533f0de03a1ffb4ea0dce40b5a2ff
[debugserver] Add platform cache support to improve performance.
2 parents d0bd409 + c038b80 commit d74493d

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,
@@ -375,6 +376,7 @@ class MachProcess {
375376

376377
pid_t m_pid; // Process ID of child process
377378
cpu_type_t m_cpu_type; // The CPU type of this process
379+
uint32_t m_platform; // The platform of this process
378380
int m_child_stdin;
379381
int m_child_stdout;
380382
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();
@@ -1103,6 +1103,12 @@ static bool FBSAddEventDataToOptions(NSMutableDictionary *options,
11031103
bool privateCache;
11041104
};
11051105

1106+
uint32_t MachProcess::GetPlatform() {
1107+
if (m_platform == 0)
1108+
m_platform = MachProcess::GetProcessPlatformViaDYLDSPI();
1109+
return m_platform;
1110+
}
1111+
11061112
uint32_t MachProcess::GetProcessPlatformViaDYLDSPI() {
11071113
kern_return_t kern_ret;
11081114
uint32_t platform = 0;
@@ -1158,7 +1164,7 @@ static bool FBSAddEventDataToOptions(NSMutableDictionary *options,
11581164

11591165
std::vector<struct binary_image_information> image_infos;
11601166
GetAllLoadedBinariesViaDYLDSPI(image_infos);
1161-
uint32_t platform = GetProcessPlatformViaDYLDSPI();
1167+
uint32_t platform = GetPlatform();
11621168
const size_t image_count = image_infos.size();
11631169
for (size_t i = 0; i < image_count; i++) {
11641170
GetMachOInformationFromMemory(platform,
@@ -1189,7 +1195,7 @@ static bool FBSAddEventDataToOptions(NSMutableDictionary *options,
11891195

11901196
std::vector<struct binary_image_information> all_image_infos;
11911197
GetAllLoadedBinariesViaDYLDSPI(all_image_infos);
1192-
uint32_t platform = GetProcessPlatformViaDYLDSPI();
1198+
uint32_t platform = GetPlatform();
11931199

11941200
std::vector<struct binary_image_information> image_infos;
11951201
const size_t macho_addresses_count = macho_addresses.size();
@@ -1355,6 +1361,7 @@ static bool FBSAddEventDataToOptions(NSMutableDictionary *options,
13551361
// Clear any cached thread list while the pid and task are still valid
13561362

13571363
m_task.Clear();
1364+
m_platform = 0;
13581365
// Now clear out all member variables
13591366
m_pid = INVALID_NUB_PROCESS;
13601367
if (!detaching)
@@ -1646,6 +1653,7 @@ static bool FBSAddEventDataToOptions(NSMutableDictionary *options,
16461653

16471654
// NULL our task out as we have already restored all exception ports
16481655
m_task.Clear();
1656+
m_platform = 0;
16491657

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

0 commit comments

Comments
 (0)