Skip to content

Commit c385e97

Browse files
committed
[lldb] Properly cache the result of MachProcess::GetPlatform #140610
If `MachProcess::GetProcessPlatformViaDYLDSPI` fails and return 0, we don't want to call it everytime as it won't change the result. So use std::optional to cache wether we already calculated the value.
1 parent 72b2219 commit c385e97

File tree

2 files changed

+5
-5
lines changed

2 files changed

+5
-5
lines changed

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -398,7 +398,7 @@ class MachProcess {
398398

399399
pid_t m_pid; // Process ID of child process
400400
cpu_type_t m_cpu_type; // The CPU type of this process
401-
uint32_t m_platform; // The platform of this process
401+
std::optional<uint32_t> m_platform; // The platform of this process
402402
int m_child_stdin;
403403
int m_child_stdout;
404404
int m_child_stderr;

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

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1039,9 +1039,9 @@ static bool mach_header_validity_test(uint32_t magic, uint32_t cputype) {
10391039
};
10401040

10411041
uint32_t MachProcess::GetPlatform() {
1042-
if (m_platform == 0)
1042+
if (!m_platform)
10431043
m_platform = MachProcess::GetProcessPlatformViaDYLDSPI();
1044-
return m_platform;
1044+
return *m_platform;
10451045
}
10461046

10471047
uint32_t MachProcess::GetProcessPlatformViaDYLDSPI() {
@@ -1323,7 +1323,7 @@ static bool mach_header_validity_test(uint32_t magic, uint32_t cputype) {
13231323
// Clear any cached thread list while the pid and task are still valid
13241324

13251325
m_task.Clear();
1326-
m_platform = 0;
1326+
m_platform.reset();
13271327
// Now clear out all member variables
13281328
m_pid = INVALID_NUB_PROCESS;
13291329
if (!detaching)
@@ -1754,7 +1754,7 @@ static uint64_t bits(uint64_t value, uint32_t msbit, uint32_t lsbit) {
17541754

17551755
// NULL our task out as we have already restored all exception ports
17561756
m_task.Clear();
1757-
m_platform = 0;
1757+
m_platform.reset();
17581758

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

0 commit comments

Comments
 (0)