-
Notifications
You must be signed in to change notification settings - Fork 13k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[lldb][Darwin] Change DynamicLoaderDarwin to default to new SPI #126171
[lldb][Darwin] Change DynamicLoaderDarwin to default to new SPI #126171
Conversation
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.
@llvm/pr-subscribers-lldb Author: Jason Molenda (jasonmolenda) ChangesIn 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. Full diff: https://github.com/llvm/llvm-project/pull/126171.diff 1 Files Affected:
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(
|
I originally removed the old DynamicLoader plugin except for corefiles. But it seemed unnecessary to break lldb from working on old macOS for no reason. I should probably remove the iOS/watchOS/tvOS cases, it's years outside Xcode's supported OS versions. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM
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)) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This seems ripe for a helper or lambda that takes a triple and an unsigned version :-)
… (NFC) I suggested using a lambda in llvm#126171 but I think Jason missed it.
… (NFC) (#126175) I suggested using a lambda in #126171 but @jasonmolenda missed it.
…#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.
… (NFC) (llvm#126175) I suggested using a lambda in llvm#126171 but @jasonmolenda missed it.
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.