https://github.com/talkeren updated 
https://github.com/llvm/llvm-project/pull/140611

>From c385e9780e980865461f877c76acaa417b4d736c Mon Sep 17 00:00:00 2001
From: Tal Keren <t...@talon-sec.com>
Date: Mon, 19 May 2025 23:15:10 +0300
Subject: [PATCH 1/2] [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.
---
 lldb/tools/debugserver/source/MacOSX/MachProcess.h  | 2 +-
 lldb/tools/debugserver/source/MacOSX/MachProcess.mm | 8 ++++----
 2 files changed, 5 insertions(+), 5 deletions(-)

diff --git a/lldb/tools/debugserver/source/MacOSX/MachProcess.h 
b/lldb/tools/debugserver/source/MacOSX/MachProcess.h
index 56bc9d6c7461e..516a77c0bd6c8 100644
--- a/lldb/tools/debugserver/source/MacOSX/MachProcess.h
+++ b/lldb/tools/debugserver/source/MacOSX/MachProcess.h
@@ -398,7 +398,7 @@ class MachProcess {
 
   pid_t m_pid;           // Process ID of child process
   cpu_type_t m_cpu_type; // The CPU type of this process
-  uint32_t m_platform;   // The platform of this process
+  std::optional<uint32_t> m_platform;   // The platform of this process
   int m_child_stdin;
   int m_child_stdout;
   int m_child_stderr;
diff --git a/lldb/tools/debugserver/source/MacOSX/MachProcess.mm 
b/lldb/tools/debugserver/source/MacOSX/MachProcess.mm
index 3afaaa2f64c00..7f8b0efff28b3 100644
--- a/lldb/tools/debugserver/source/MacOSX/MachProcess.mm
+++ b/lldb/tools/debugserver/source/MacOSX/MachProcess.mm
@@ -1039,9 +1039,9 @@ static bool mach_header_validity_test(uint32_t magic, 
uint32_t cputype) {
 };
 
 uint32_t MachProcess::GetPlatform() {
-  if (m_platform == 0)
+  if (!m_platform)
     m_platform = MachProcess::GetProcessPlatformViaDYLDSPI();
-  return m_platform;
+  return *m_platform;
 }
 
 uint32_t MachProcess::GetProcessPlatformViaDYLDSPI() {
@@ -1323,7 +1323,7 @@ static bool mach_header_validity_test(uint32_t magic, 
uint32_t cputype) {
   // Clear any cached thread list while the pid and task are still valid
 
   m_task.Clear();
-  m_platform = 0;
+  m_platform.reset();
   // Now clear out all member variables
   m_pid = INVALID_NUB_PROCESS;
   if (!detaching)
@@ -1754,7 +1754,7 @@ static uint64_t bits(uint64_t value, uint32_t msbit, 
uint32_t lsbit) {
 
   // NULL our task out as we have already restored all exception ports
   m_task.Clear();
-  m_platform = 0;
+  m_platform.reset();
 
   // Clear out any notion of the process we once were
   const bool detaching = true;

>From bc775be48deda868a1df7dbe94a2c697dcb69739 Mon Sep 17 00:00:00 2001
From: Tal Keren <t...@talon-sec.com>
Date: Mon, 19 May 2025 23:35:15 +0300
Subject: [PATCH 2/2] fix formatting

---
 lldb/tools/debugserver/source/MacOSX/MachProcess.h | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/lldb/tools/debugserver/source/MacOSX/MachProcess.h 
b/lldb/tools/debugserver/source/MacOSX/MachProcess.h
index 516a77c0bd6c8..948fd5318465c 100644
--- a/lldb/tools/debugserver/source/MacOSX/MachProcess.h
+++ b/lldb/tools/debugserver/source/MacOSX/MachProcess.h
@@ -398,7 +398,7 @@ class MachProcess {
 
   pid_t m_pid;           // Process ID of child process
   cpu_type_t m_cpu_type; // The CPU type of this process
-  std::optional<uint32_t> m_platform;   // The platform of this process
+  std::optional<uint32_t> m_platform; // The platform of this process
   int m_child_stdin;
   int m_child_stdout;
   int m_child_stderr;

_______________________________________________
lldb-commits mailing list
lldb-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits

Reply via email to