[Lldb-commits] [lldb] [lldb][XcodeSDK] Simplify logic that adjusts sysroot during XcodeSDK merging (PR #130640)

Michael Buch via lldb-commits lldb-commits at lists.llvm.org
Mon Mar 10 10:04:17 PDT 2025


https://github.com/Michael137 created https://github.com/llvm/llvm-project/pull/130640

The `DW_AT_APPLE_sdk` should always be equal to the filename of the `DW_AT_LLVM_sysroot`. We can use this property to simplify `XcodeSDK::Merge` to no longer manually adjust the sysroot filename. Instead we simply update the sysroot filename with merged SDK name.

This should be an NFC change.

>From 678c1785e8a143c1cc471cf8fee7d31a6c04a357 Mon Sep 17 00:00:00 2001
From: Michael Buch <michaelbuch12 at gmail.com>
Date: Mon, 10 Mar 2025 17:00:11 +0000
Subject: [PATCH] [lldb][XcodeSDK] Simplify logic that adjusts sysroot during
 XcodeSDK merging

The `DW_AT_APPLE_sdk` should always be equal to the filename of the `DW_AT_LLVM_sysroot`. We can use this property to simplify `XcodeSDK::Merge` to no longer manually adjust the sysroot filename. Instead we simply update the sysroot filename with merged SDK name.

This should be an NFC change.
---
 lldb/include/lldb/Utility/XcodeSDK.h |  4 +++-
 lldb/source/Utility/XcodeSDK.cpp     | 13 +++++--------
 2 files changed, 8 insertions(+), 9 deletions(-)

diff --git a/lldb/include/lldb/Utility/XcodeSDK.h b/lldb/include/lldb/Utility/XcodeSDK.h
index 3a6cbb9c98f6b..ceb8abb8c502d 100644
--- a/lldb/include/lldb/Utility/XcodeSDK.h
+++ b/lldb/include/lldb/Utility/XcodeSDK.h
@@ -65,7 +65,9 @@ class XcodeSDK {
   /// parameter. For example, "MacOSX.10.14.sdk".
   XcodeSDK(std::string &&name) : m_name(std::move(name)) {}
   XcodeSDK(std::string name, FileSpec sysroot)
-      : m_name(std::move(name)), m_sysroot(std::move(sysroot)) {}
+      : m_name(std::move(name)), m_sysroot(std::move(sysroot)) {
+    assert(!m_sysroot || m_name == m_sysroot.GetFilename().GetStringRef());
+  }
   static XcodeSDK GetAnyMacOS() { return XcodeSDK("MacOSX.sdk"); }
 
   /// The merge function follows a strict order to maintain monotonicity:
diff --git a/lldb/source/Utility/XcodeSDK.cpp b/lldb/source/Utility/XcodeSDK.cpp
index 02cf7866e22fb..59bf9a7b9e3b4 100644
--- a/lldb/source/Utility/XcodeSDK.cpp
+++ b/lldb/source/Utility/XcodeSDK.cpp
@@ -155,10 +155,6 @@ bool XcodeSDK::Info::operator==(const Info &other) const {
 }
 
 void XcodeSDK::Merge(const XcodeSDK &other) {
-  auto add_internal_sdk_suffix = [](llvm::StringRef sdk) {
-    return (sdk.substr(0, sdk.size() - 3) + "Internal.sdk").str();
-  };
-
   // The "bigger" SDK always wins.
   auto l = Parse();
   auto r = other.Parse();
@@ -168,12 +164,13 @@ void XcodeSDK::Merge(const XcodeSDK &other) {
     // The Internal flag always wins.
     if (!l.internal && r.internal) {
       if (llvm::StringRef(m_name).ends_with(".sdk"))
-        m_name = add_internal_sdk_suffix(m_name);
-
-      if (m_sysroot.GetFileNameExtension() == ".sdk")
-        m_sysroot.SetFilename(add_internal_sdk_suffix(m_sysroot.GetFilename()));
+        m_name = m_name.substr(m_name.size() - 3) + "Internal.sdk";
     }
   }
+
+  // We changed the SDK name. Adjust the sysroot accordingly.
+  if (m_sysroot && m_sysroot.GetFilename().GetStringRef() != m_name)
+    m_sysroot.SetFilename(m_name);
 }
 
 std::string XcodeSDK::GetCanonicalName(XcodeSDK::Info info) {



More information about the lldb-commits mailing list