Author: Jonas Devlieghere Date: 2020-11-30T19:37:12-08:00 New Revision: 173bb3c2eb094920708ab8f61dae2fe22d331773
URL: https://github.com/llvm/llvm-project/commit/173bb3c2eb094920708ab8f61dae2fe22d331773 DIFF: https://github.com/llvm/llvm-project/commit/173bb3c2eb094920708ab8f61dae2fe22d331773.diff LOG: [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. Added: Modified: lldb/source/Plugins/Platform/MacOSX/PlatformRemoteAppleBridge.cpp lldb/source/Plugins/Platform/MacOSX/PlatformRemoteAppleBridge.h lldb/source/Plugins/Platform/MacOSX/PlatformRemoteAppleTV.cpp lldb/source/Plugins/Platform/MacOSX/PlatformRemoteAppleTV.h lldb/source/Plugins/Platform/MacOSX/PlatformRemoteAppleWatch.cpp lldb/source/Plugins/Platform/MacOSX/PlatformRemoteAppleWatch.h lldb/source/Plugins/Platform/MacOSX/PlatformRemoteDarwinDevice.cpp lldb/source/Plugins/Platform/MacOSX/PlatformRemoteDarwinDevice.h lldb/source/Plugins/Platform/MacOSX/PlatformRemoteiOS.cpp lldb/source/Plugins/Platform/MacOSX/PlatformRemoteiOS.h Removed: ################################################################################ diff --git a/lldb/source/Plugins/Platform/MacOSX/PlatformRemoteAppleBridge.cpp b/lldb/source/Plugins/Platform/MacOSX/PlatformRemoteAppleBridge.cpp index 1cb8b9c37031..f3ee92a9d27b 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<std::string> &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 5e7420e2508b..2d574894a283 100644 --- a/lldb/source/Plugins/Platform/MacOSX/PlatformRemoteAppleBridge.h +++ b/lldb/source/Plugins/Platform/MacOSX/PlatformRemoteAppleBridge.h @@ -48,12 +48,8 @@ class PlatformRemoteAppleBridge : public PlatformRemoteDarwinDevice { lldb_private::ArchSpec &arch) override; protected: - - // lldb_private::PlatformRemoteDarwinDevice functions - - void GetDeviceSupportDirectoryNames (std::vector<std::string> &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 082ddcc0f568..15e91b239a35 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<std::string> &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 c556476340fc..15be923cca46 100644 --- a/lldb/source/Plugins/Platform/MacOSX/PlatformRemoteAppleTV.h +++ b/lldb/source/Plugins/Platform/MacOSX/PlatformRemoteAppleTV.h @@ -48,12 +48,8 @@ class PlatformRemoteAppleTV : public PlatformRemoteDarwinDevice { lldb_private::ArchSpec &arch) override; protected: - - // lldb_private::PlatformRemoteDarwinDevice functions - - void GetDeviceSupportDirectoryNames (std::vector<std::string> &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 6b40393ba5ba..29162e11ec59 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<std::string> &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 771e1ca53619..43be3317d9c5 100644 --- a/lldb/source/Plugins/Platform/MacOSX/PlatformRemoteAppleWatch.h +++ b/lldb/source/Plugins/Platform/MacOSX/PlatformRemoteAppleWatch.h @@ -51,12 +51,8 @@ class PlatformRemoteAppleWatch : public PlatformRemoteDarwinDevice { lldb_private::ArchSpec &arch) override; protected: - - // lldb_private::PlatformRemoteDarwinDevice functions - - void GetDeviceSupportDirectoryNames (std::vector<std::string> &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 065eefa48fea..8a11f40ba0ab 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<std::string> 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 cc5f286f3b25..6f6ede7c34b7 100644 --- a/lldb/source/Plugins/Platform/MacOSX/PlatformRemoteDarwinDevice.h +++ b/lldb/source/Plugins/Platform/MacOSX/PlatformRemoteDarwinDevice.h @@ -97,10 +97,8 @@ class PlatformRemoteDarwinDevice : public PlatformDarwin { // UINT32_MAX if that SDK not found. uint32_t GetSDKIndexBySDKDirectoryInfo(const SDKDirectoryInfo *sdk_info); - - virtual void GetDeviceSupportDirectoryNames (std::vector<std::string> &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 b37cdecd38c4..3269345f3549 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<std::string> &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 74454fc7c6ad..b6cf4d63f308 100644 --- a/lldb/source/Plugins/Platform/MacOSX/PlatformRemoteiOS.h +++ b/lldb/source/Plugins/Platform/MacOSX/PlatformRemoteiOS.h @@ -47,12 +47,8 @@ class PlatformRemoteiOS : public PlatformRemoteDarwinDevice { lldb_private::ArchSpec &arch) override; protected: - - // lldb_private::PlatformRemoteDarwinDevice functions - - void GetDeviceSupportDirectoryNames (std::vector<std::string> &dirnames) override; - - std::string GetPlatformName () override; + llvm::StringRef GetDeviceSupportDirectoryName() override; + llvm::StringRef GetPlatformName() override; }; #endif // LLDB_SOURCE_PLUGINS_PLATFORM_MACOSX_PLATFORMREMOTEIOS_H _______________________________________________ lldb-commits mailing list lldb-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits