https://github.com/jasonmolenda created 
https://github.com/llvm/llvm-project/pull/126171

In Sep 2016 and newer Darwin releases, debugserver uses libdyld SPI to gather 
information about the binaries loaded in a process.  Before Sep 2016, lldb 
would inspect the dyld internal data structures directly itself to find this 
information.

DynamicLoaderDarwin::UseDYLDSPI currently defaults to the old 
inspect-dyld-internal-structures method for binaries (DynamicLoaderMacOSXDYLD). 
 If it detects that the Process' host OS version is new enough, it enables the 
newer libdyld SPI methods in debugserver (DynamicLoaderMacOS).

This patch changes the default to use the new libdyld SPI interfaces. If the 
Process has a HostOS and it is one of the four specific OSes that existed in 
2015 (Mac OS X, iOS, tvOS, watchOS) with an old version number, then we will 
enable the old DynamicLoader plugin.

If this debug session is a corefile, we will always use the old DynamicLoader 
plugin -- the libdyld SPI cannot run against a corefile, lldb must read 
metadata or the dyld internal data structures in the corefile to find the 
loaded binaries.

>From af2fa2e17ceb527dd9a2b8c5d7e72da374b4512b Mon Sep 17 00:00:00 2001
From: Jason Molenda <jmole...@apple.com>
Date: Thu, 6 Feb 2025 18:48:02 -0800
Subject: [PATCH] [lldb][Darwin] Change DynamicLoaderDarwin to default to new
 SPI

In Sep 2016 and newer Darwin releases, debugserver uses libdyld SPI
to gather information about the binaries loaded in a process.  Before
Sep 2016, lldb would inspect the dyld internal data structures
directly itself to find this information.

DynamicLoaderDarwin::UseDYLDSPI currently defaults to the old
inspect-dyld-internal-structures method for binaries
(DynamicLoaderMacOSXDYLD).  If it detects that the Process' host
OS version is new enough, it enables the newer libdyld SPI methods
in debugserver (DynamicLoaderMacOS).

This patch changes the default to use the new libdyld SPI interfaces.
If the Process has a HostOS and it is one of the four specific OSes
that existed in 2015 (Mac OS X, iOS, tvOS, watchOS) with an old
version number, then we will enable the old DynamicLoader plugin.

If this debug session is a corefile, we will always use the old
DynamicLoader plugin -- the libdyld SPI cannot run against a corefile,
lldb must read metadata or the dyld internal data structures in the
corefile to find the loaded binaries.
---
 .../MacOSX-DYLD/DynamicLoaderDarwin.cpp       | 43 +++++++++++--------
 1 file changed, 26 insertions(+), 17 deletions(-)

diff --git 
a/lldb/source/Plugins/DynamicLoader/MacOSX-DYLD/DynamicLoaderDarwin.cpp 
b/lldb/source/Plugins/DynamicLoader/MacOSX-DYLD/DynamicLoaderDarwin.cpp
index b5cf0d62b976f19..6362d0ca6027afc 100644
--- a/lldb/source/Plugins/DynamicLoader/MacOSX-DYLD/DynamicLoaderDarwin.cpp
+++ b/lldb/source/Plugins/DynamicLoader/MacOSX-DYLD/DynamicLoaderDarwin.cpp
@@ -1208,35 +1208,44 @@ DynamicLoaderDarwin::GetThreadLocalData(const 
lldb::ModuleSP module_sp,
 
 bool DynamicLoaderDarwin::UseDYLDSPI(Process *process) {
   Log *log = GetLog(LLDBLog::DynamicLoader);
-  bool use_new_spi_interface = false;
+  bool use_new_spi_interface = true;
 
   llvm::VersionTuple version = process->GetHostOSVersion();
   if (!version.empty()) {
     const llvm::Triple::OSType os_type =
         process->GetTarget().GetArchitecture().GetTriple().getOS();
 
-    // macOS 10.12 and newer
-    if (os_type == llvm::Triple::MacOSX &&
-        version >= llvm::VersionTuple(10, 12))
-      use_new_spi_interface = true;
+    // Older than macOS 10.12
+    if (os_type == llvm::Triple::MacOSX && version < llvm::VersionTuple(10, 
12))
+      use_new_spi_interface = false;
 
-    // iOS 10 and newer
-    if (os_type == llvm::Triple::IOS && version >= llvm::VersionTuple(10))
-      use_new_spi_interface = true;
+    // Older than iOS 10
+    if (os_type == llvm::Triple::IOS && version < llvm::VersionTuple(10))
+      use_new_spi_interface = false;
 
-    // tvOS 10 and newer
-    if (os_type == llvm::Triple::TvOS && version >= llvm::VersionTuple(10))
-      use_new_spi_interface = true;
+    // Older than tvOS 10
+    if (os_type == llvm::Triple::TvOS && version < llvm::VersionTuple(10))
+      use_new_spi_interface = false;
 
-    // watchOS 3 and newer
-    if (os_type == llvm::Triple::WatchOS && version >= llvm::VersionTuple(3))
-      use_new_spi_interface = true;
+    // Older than watchOS 3
+    if (os_type == llvm::Triple::WatchOS && version < llvm::VersionTuple(3))
+      use_new_spi_interface = false;
 
-    // NEED_BRIDGEOS_TRIPLE // Any BridgeOS
-    // NEED_BRIDGEOS_TRIPLE if (os_type == llvm::Triple::BridgeOS)
-    // NEED_BRIDGEOS_TRIPLE   use_new_spi_interface = true;
+    // llvm::Triple::BridgeOS and llvm::Triple::XROS always use the new
+    // libdyld SPI interface.
+  } else {
+    // We could not get an OS version string, we are likely not
+    // connected to debugserver and the packets to call the libdyld SPI
+    // will not exist.
+    use_new_spi_interface = false;
   }
 
+  // Corefiles cannot use the dyld SPI to get the inferior's
+  // binaries, we must find it through metadata or a scan
+  // of the corefile memory.
+  if (!process->IsLiveDebugSession())
+    use_new_spi_interface = false;
+
   if (log) {
     if (use_new_spi_interface)
       LLDB_LOGF(

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

Reply via email to