From 173bb3c2eb094920708ab8f61dae2fe22d331773 Mon Sep 17 00:00:00 2001 From: Jonas Devlieghere Date: Mon, 30 Nov 2020 15:18:24 -0800 Subject: [PATCH] [lldb] Refactor GetDeviceSupportDirectoryNames and GetPlatformName (NFC) Both functions are effectively returning a single string literal. Change the interface to return a llvm::StringRef instead of populating a vector of std::strings or returning a std::string respectively. --- .../Platform/MacOSX/PlatformRemoteAppleBridge.cpp | 13 ++-- .../Platform/MacOSX/PlatformRemoteAppleBridge.h | 8 +-- .../Platform/MacOSX/PlatformRemoteAppleTV.cpp | 13 ++-- .../Platform/MacOSX/PlatformRemoteAppleTV.h | 8 +-- .../Platform/MacOSX/PlatformRemoteAppleWatch.cpp | 11 ++-- .../Platform/MacOSX/PlatformRemoteAppleWatch.h | 8 +-- .../Platform/MacOSX/PlatformRemoteDarwinDevice.cpp | 69 ++++++++++------------ .../Platform/MacOSX/PlatformRemoteDarwinDevice.h | 6 +- .../Plugins/Platform/MacOSX/PlatformRemoteiOS.cpp | 12 ++-- .../Plugins/Platform/MacOSX/PlatformRemoteiOS.h | 8 +-- 10 files changed, 58 insertions(+), 98 deletions(-) diff --git a/lldb/source/Plugins/Platform/MacOSX/PlatformRemoteAppleBridge.cpp b/lldb/source/Plugins/Platform/MacOSX/PlatformRemoteAppleBridge.cpp index 1cb8b9c..f3ee92a 100644 --- a/lldb/source/Plugins/Platform/MacOSX/PlatformRemoteAppleBridge.cpp +++ b/lldb/source/Plugins/Platform/MacOSX/PlatformRemoteAppleBridge.cpp @@ -172,15 +172,10 @@ bool PlatformRemoteAppleBridge::GetSupportedArchitectureAtIndex(uint32_t idx, return false; } - -void PlatformRemoteAppleBridge::GetDeviceSupportDirectoryNames (std::vector &dirnames) -{ - dirnames.clear(); - dirnames.push_back("BridgeOS DeviceSupport"); +llvm::StringRef PlatformRemoteAppleBridge::GetDeviceSupportDirectoryName() { + return "BridgeOS DeviceSupport"; } -std::string PlatformRemoteAppleBridge::GetPlatformName () -{ - return "BridgeOS.platform"; +llvm::StringRef PlatformRemoteAppleBridge::GetPlatformName() { + return "BridgeOS.platform"; } - diff --git a/lldb/source/Plugins/Platform/MacOSX/PlatformRemoteAppleBridge.h b/lldb/source/Plugins/Platform/MacOSX/PlatformRemoteAppleBridge.h index 5e7420e..2d57489 100644 --- a/lldb/source/Plugins/Platform/MacOSX/PlatformRemoteAppleBridge.h +++ b/lldb/source/Plugins/Platform/MacOSX/PlatformRemoteAppleBridge.h @@ -48,12 +48,8 @@ public: lldb_private::ArchSpec &arch) override; protected: - - // lldb_private::PlatformRemoteDarwinDevice functions - - void GetDeviceSupportDirectoryNames (std::vector &dirnames) override; - - std::string GetPlatformName () override; + llvm::StringRef GetDeviceSupportDirectoryName() override; + llvm::StringRef GetPlatformName() override; }; #endif // LLDB_SOURCE_PLUGINS_PLATFORM_MACOSX_PLATFORMREMOTEAPPLEBRIDGE_H diff --git a/lldb/source/Plugins/Platform/MacOSX/PlatformRemoteAppleTV.cpp b/lldb/source/Plugins/Platform/MacOSX/PlatformRemoteAppleTV.cpp index 082ddcc..15e91b2 100644 --- a/lldb/source/Plugins/Platform/MacOSX/PlatformRemoteAppleTV.cpp +++ b/lldb/source/Plugins/Platform/MacOSX/PlatformRemoteAppleTV.cpp @@ -223,15 +223,10 @@ bool PlatformRemoteAppleTV::GetSupportedArchitectureAtIndex(uint32_t idx, return false; } - -void PlatformRemoteAppleTV::GetDeviceSupportDirectoryNames (std::vector &dirnames) -{ - dirnames.clear(); - dirnames.push_back("tvOS DeviceSupport"); +llvm::StringRef PlatformRemoteAppleTV::GetDeviceSupportDirectoryName() { + return "tvOS DeviceSupport"; } -std::string PlatformRemoteAppleTV::GetPlatformName () -{ - return "AppleTVOS.platform"; +llvm::StringRef PlatformRemoteAppleTV::GetPlatformName() { + return "AppleTVOS.platform"; } - diff --git a/lldb/source/Plugins/Platform/MacOSX/PlatformRemoteAppleTV.h b/lldb/source/Plugins/Platform/MacOSX/PlatformRemoteAppleTV.h index c5564763..15be923 100644 --- a/lldb/source/Plugins/Platform/MacOSX/PlatformRemoteAppleTV.h +++ b/lldb/source/Plugins/Platform/MacOSX/PlatformRemoteAppleTV.h @@ -48,12 +48,8 @@ public: lldb_private::ArchSpec &arch) override; protected: - - // lldb_private::PlatformRemoteDarwinDevice functions - - void GetDeviceSupportDirectoryNames (std::vector &dirnames) override; - - std::string GetPlatformName () override; + llvm::StringRef GetDeviceSupportDirectoryName() override; + llvm::StringRef GetPlatformName() override; }; #endif // LLDB_SOURCE_PLUGINS_PLATFORM_MACOSX_PLATFORMREMOTEAPPLETV_H diff --git a/lldb/source/Plugins/Platform/MacOSX/PlatformRemoteAppleWatch.cpp b/lldb/source/Plugins/Platform/MacOSX/PlatformRemoteAppleWatch.cpp index 6b40393..29162e1 100644 --- a/lldb/source/Plugins/Platform/MacOSX/PlatformRemoteAppleWatch.cpp +++ b/lldb/source/Plugins/Platform/MacOSX/PlatformRemoteAppleWatch.cpp @@ -298,13 +298,10 @@ bool PlatformRemoteAppleWatch::GetSupportedArchitectureAtIndex(uint32_t idx, return false; } -void PlatformRemoteAppleWatch::GetDeviceSupportDirectoryNames (std::vector &dirnames) -{ - dirnames.clear(); - dirnames.push_back("watchOS DeviceSupport"); +llvm::StringRef PlatformRemoteAppleWatch::GetDeviceSupportDirectoryName() { + return "watchOS DeviceSupport"; } -std::string PlatformRemoteAppleWatch::GetPlatformName () -{ - return "WatchOS.platform"; +llvm::StringRef PlatformRemoteAppleWatch::GetPlatformName() { + return "WatchOS.platform"; } diff --git a/lldb/source/Plugins/Platform/MacOSX/PlatformRemoteAppleWatch.h b/lldb/source/Plugins/Platform/MacOSX/PlatformRemoteAppleWatch.h index 771e1ca..43be331 100644 --- a/lldb/source/Plugins/Platform/MacOSX/PlatformRemoteAppleWatch.h +++ b/lldb/source/Plugins/Platform/MacOSX/PlatformRemoteAppleWatch.h @@ -51,12 +51,8 @@ public: lldb_private::ArchSpec &arch) override; protected: - - // lldb_private::PlatformRemoteDarwinDevice functions - - void GetDeviceSupportDirectoryNames (std::vector &dirnames) override; - - std::string GetPlatformName () override; + llvm::StringRef GetDeviceSupportDirectoryName() override; + llvm::StringRef GetPlatformName() override; }; #endif // LLDB_SOURCE_PLUGINS_PLATFORM_MACOSX_PLATFORMREMOTEAPPLEWATCH_H diff --git a/lldb/source/Plugins/Platform/MacOSX/PlatformRemoteDarwinDevice.cpp b/lldb/source/Plugins/Platform/MacOSX/PlatformRemoteDarwinDevice.cpp index 065eefa..8a11f40 100644 --- a/lldb/source/Plugins/Platform/MacOSX/PlatformRemoteDarwinDevice.cpp +++ b/lldb/source/Plugins/Platform/MacOSX/PlatformRemoteDarwinDevice.cpp @@ -197,42 +197,36 @@ bool PlatformRemoteDarwinDevice::UpdateSDKDirectoryInfosIfNeeded() { } } - std::vector device_support_dirnames; - GetDeviceSupportDirectoryNames (device_support_dirnames); - - for (std::string &dirname : device_support_dirnames) - { - const uint32_t num_installed = m_sdk_directory_infos.size(); - std::string local_sdk_cache_str = "~/Library/Developer/Xcode/"; - local_sdk_cache_str += dirname; - FileSpec local_sdk_cache(local_sdk_cache_str.c_str()); - FileSystem::Instance().Resolve(local_sdk_cache); - if (FileSystem::Instance().Exists(local_sdk_cache)) { - if (log) { - LLDB_LOGF( - log, - "PlatformRemoteDarwinDevice::UpdateSDKDirectoryInfosIfNeeded " - "searching %s for additional SDKs", - local_sdk_cache.GetPath().c_str()); - } - char path[PATH_MAX]; - if (local_sdk_cache.GetPath(path, sizeof(path))) { - FileSystem::Instance().EnumerateDirectory( - path, find_directories, find_files, find_other, - GetContainedFilesIntoVectorOfStringsCallback, - &m_sdk_directory_infos); - const uint32_t num_sdk_infos = m_sdk_directory_infos.size(); - // First try for an exact match of major, minor and update - for (uint32_t i = num_installed; i < num_sdk_infos; ++i) { - m_sdk_directory_infos[i].user_cached = true; - if (log) { - LLDB_LOGF( - log, - "PlatformRemoteDarwinDevice::" - "UpdateSDKDirectoryInfosIfNeeded " - "user SDK directory %s", - m_sdk_directory_infos[i].directory.GetPath().c_str()); - } + const uint32_t num_installed = m_sdk_directory_infos.size(); + llvm::StringRef dirname = GetDeviceSupportDirectoryName(); + std::string local_sdk_cache_str = "~/Library/Developer/Xcode/"; + local_sdk_cache_str += std::string(dirname); + FileSpec local_sdk_cache(local_sdk_cache_str.c_str()); + FileSystem::Instance().Resolve(local_sdk_cache); + if (FileSystem::Instance().Exists(local_sdk_cache)) { + if (log) { + LLDB_LOGF( + log, + "PlatformRemoteDarwinDevice::UpdateSDKDirectoryInfosIfNeeded " + "searching %s for additional SDKs", + local_sdk_cache.GetPath().c_str()); + } + char path[PATH_MAX]; + if (local_sdk_cache.GetPath(path, sizeof(path))) { + FileSystem::Instance().EnumerateDirectory( + path, find_directories, find_files, find_other, + GetContainedFilesIntoVectorOfStringsCallback, + &m_sdk_directory_infos); + const uint32_t num_sdk_infos = m_sdk_directory_infos.size(); + // First try for an exact match of major, minor and update + for (uint32_t i = num_installed; i < num_sdk_infos; ++i) { + m_sdk_directory_infos[i].user_cached = true; + if (log) { + LLDB_LOGF(log, + "PlatformRemoteDarwinDevice::" + "UpdateSDKDirectoryInfosIfNeeded " + "user SDK directory %s", + m_sdk_directory_infos[i].directory.GetPath().c_str()); } } } @@ -341,7 +335,8 @@ PlatformRemoteDarwinDevice::GetSDKDirectoryForLatestOSVersion() { } const char *PlatformRemoteDarwinDevice::GetDeviceSupportDirectory() { - std::string platform_dir = "/Platforms/" + GetPlatformName() + "/DeviceSupport"; + std::string platform_dir = + ("/Platforms/" + GetPlatformName() + "/DeviceSupport").str(); if (m_device_support_directory.empty()) { if (FileSpec fspec = HostInfo::GetXcodeDeveloperDirectory()) { m_device_support_directory = fspec.GetPath(); diff --git a/lldb/source/Plugins/Platform/MacOSX/PlatformRemoteDarwinDevice.h b/lldb/source/Plugins/Platform/MacOSX/PlatformRemoteDarwinDevice.h index cc5f286..6f6ede7 100644 --- a/lldb/source/Plugins/Platform/MacOSX/PlatformRemoteDarwinDevice.h +++ b/lldb/source/Plugins/Platform/MacOSX/PlatformRemoteDarwinDevice.h @@ -97,10 +97,8 @@ protected: // UINT32_MAX if that SDK not found. uint32_t GetSDKIndexBySDKDirectoryInfo(const SDKDirectoryInfo *sdk_info); - - virtual void GetDeviceSupportDirectoryNames (std::vector &dirnames) = 0; - - virtual std::string GetPlatformName () = 0; + virtual llvm::StringRef GetDeviceSupportDirectoryName() = 0; + virtual llvm::StringRef GetPlatformName() = 0; private: PlatformRemoteDarwinDevice(const PlatformRemoteDarwinDevice &) = delete; diff --git a/lldb/source/Plugins/Platform/MacOSX/PlatformRemoteiOS.cpp b/lldb/source/Plugins/Platform/MacOSX/PlatformRemoteiOS.cpp index b37cdec..3269345 100644 --- a/lldb/source/Plugins/Platform/MacOSX/PlatformRemoteiOS.cpp +++ b/lldb/source/Plugins/Platform/MacOSX/PlatformRemoteiOS.cpp @@ -143,14 +143,10 @@ bool PlatformRemoteiOS::GetSupportedArchitectureAtIndex(uint32_t idx, return ARMGetSupportedArchitectureAtIndex(idx, arch); } - -void PlatformRemoteiOS::GetDeviceSupportDirectoryNames (std::vector &dirnames) -{ - dirnames.clear(); - dirnames.push_back("iOS DeviceSupport"); +llvm::StringRef PlatformRemoteiOS::GetDeviceSupportDirectoryName() { + return "iOS DeviceSupport"; } -std::string PlatformRemoteiOS::GetPlatformName () -{ - return "iPhoneOS.platform"; +llvm::StringRef PlatformRemoteiOS::GetPlatformName() { + return "iPhoneOS.platform"; } diff --git a/lldb/source/Plugins/Platform/MacOSX/PlatformRemoteiOS.h b/lldb/source/Plugins/Platform/MacOSX/PlatformRemoteiOS.h index 74454fc..b6cf4d6 100644 --- a/lldb/source/Plugins/Platform/MacOSX/PlatformRemoteiOS.h +++ b/lldb/source/Plugins/Platform/MacOSX/PlatformRemoteiOS.h @@ -47,12 +47,8 @@ public: lldb_private::ArchSpec &arch) override; protected: - - // lldb_private::PlatformRemoteDarwinDevice functions - - void GetDeviceSupportDirectoryNames (std::vector &dirnames) override; - - std::string GetPlatformName () override; + llvm::StringRef GetDeviceSupportDirectoryName() override; + llvm::StringRef GetPlatformName() override; }; #endif // LLDB_SOURCE_PLUGINS_PLATFORM_MACOSX_PLATFORMREMOTEIOS_H -- 2.7.4