Author: Pavel Labath Date: 2021-10-25T15:58:58+02:00 New Revision: 40e4ac3e5b3548aa77367da37aba52f2556b855e
URL: https://github.com/llvm/llvm-project/commit/40e4ac3e5b3548aa77367da37aba52f2556b855e DIFF: https://github.com/llvm/llvm-project/commit/40e4ac3e5b3548aa77367da37aba52f2556b855e.diff LOG: [lldb] Modernize Platform::GetOSBuildString Added: Modified: lldb/include/lldb/Target/Platform.h lldb/include/lldb/Target/RemoteAwarePlatform.h lldb/source/API/SBPlatform.cpp lldb/source/Plugins/Platform/MacOSX/PlatformRemoteDarwinDevice.cpp lldb/source/Plugins/Platform/MacOSX/PlatformRemoteMacOSX.cpp lldb/source/Plugins/Platform/gdb-server/PlatformRemoteGDBServer.cpp lldb/source/Plugins/Platform/gdb-server/PlatformRemoteGDBServer.h lldb/source/Plugins/Process/gdb-remote/GDBRemoteCommunicationClient.cpp lldb/source/Plugins/Process/gdb-remote/GDBRemoteCommunicationClient.h lldb/source/Target/Platform.cpp lldb/source/Target/RemoteAwarePlatform.cpp Removed: ################################################################################ diff --git a/lldb/include/lldb/Target/Platform.h b/lldb/include/lldb/Target/Platform.h index 7cb534afe6ecc..d1351d5c729b4 100644 --- a/lldb/include/lldb/Target/Platform.h +++ b/lldb/include/lldb/Target/Platform.h @@ -212,7 +212,7 @@ class Platform : public PluginInterface { bool SetOSVersion(llvm::VersionTuple os_version); - bool GetOSBuildString(std::string &s); + llvm::Optional<std::string> GetOSBuildString(); bool GetOSKernelDescription(std::string &s); @@ -240,9 +240,8 @@ class Platform : public PluginInterface { // HostInfo::GetOSVersion(). virtual bool GetRemoteOSVersion() { return false; } - virtual bool GetRemoteOSBuildString(std::string &s) { - s.clear(); - return false; + virtual llvm::Optional<std::string> GetRemoteOSBuildString() { + return llvm::None; } virtual bool GetRemoteOSKernelDescription(std::string &s) { diff --git a/lldb/include/lldb/Target/RemoteAwarePlatform.h b/lldb/include/lldb/Target/RemoteAwarePlatform.h index 269d152998897..d8f7720d2fd96 100644 --- a/lldb/include/lldb/Target/RemoteAwarePlatform.h +++ b/lldb/include/lldb/Target/RemoteAwarePlatform.h @@ -64,7 +64,7 @@ class RemoteAwarePlatform : public Platform { FileSpec &local_file) override; bool GetRemoteOSVersion() override; - bool GetRemoteOSBuildString(std::string &s) override; + llvm::Optional<std::string> GetRemoteOSBuildString() override; bool GetRemoteOSKernelDescription(std::string &s) override; ArchSpec GetRemoteSystemArchitecture() override; diff --git a/lldb/source/API/SBPlatform.cpp b/lldb/source/API/SBPlatform.cpp index 496c40a0678fe..71d6b1c41e32f 100644 --- a/lldb/source/API/SBPlatform.cpp +++ b/lldb/source/API/SBPlatform.cpp @@ -458,13 +458,11 @@ const char *SBPlatform::GetOSBuild() { PlatformSP platform_sp(GetSP()); if (platform_sp) { - std::string s; - if (platform_sp->GetOSBuildString(s)) { - if (!s.empty()) { - // Const-ify the string so we don't need to worry about the lifetime of - // the string - return ConstString(s.c_str()).GetCString(); - } + std::string s = platform_sp->GetOSBuildString().getValueOr(""); + if (!s.empty()) { + // Const-ify the string so we don't need to worry about the lifetime of + // the string + return ConstString(s).GetCString(); } } return nullptr; diff --git a/lldb/source/Plugins/Platform/MacOSX/PlatformRemoteDarwinDevice.cpp b/lldb/source/Plugins/Platform/MacOSX/PlatformRemoteDarwinDevice.cpp index 236eacebf7148..97b2b4a3b7401 100644 --- a/lldb/source/Plugins/Platform/MacOSX/PlatformRemoteDarwinDevice.cpp +++ b/lldb/source/Plugins/Platform/MacOSX/PlatformRemoteDarwinDevice.cpp @@ -630,13 +630,12 @@ Status PlatformRemoteDarwinDevice::GetSharedModule( uint32_t PlatformRemoteDarwinDevice::GetConnectedSDKIndex() { if (IsConnected()) { if (m_connected_module_sdk_idx == UINT32_MAX) { - std::string build; - if (GetRemoteOSBuildString(build)) { + if (llvm::Optional<std::string> build = GetRemoteOSBuildString()) { const uint32_t num_sdk_infos = m_sdk_directory_infos.size(); for (uint32_t i = 0; i < num_sdk_infos; ++i) { const SDKDirectoryInfo &sdk_dir_info = m_sdk_directory_infos[i]; if (strstr(sdk_dir_info.directory.GetFilename().AsCString(""), - build.c_str())) { + build->c_str())) { m_connected_module_sdk_idx = i; } } diff --git a/lldb/source/Plugins/Platform/MacOSX/PlatformRemoteMacOSX.cpp b/lldb/source/Plugins/Platform/MacOSX/PlatformRemoteMacOSX.cpp index ea93d9944879c..c654f3c4264f9 100644 --- a/lldb/source/Plugins/Platform/MacOSX/PlatformRemoteMacOSX.cpp +++ b/lldb/source/Plugins/Platform/MacOSX/PlatformRemoteMacOSX.cpp @@ -163,8 +163,8 @@ lldb_private::Status PlatformRemoteMacOSX::GetFileWithUUID( #if !defined(__linux__) local_os_build = HostInfo::GetOSBuildString().getValueOr(""); #endif - std::string remote_os_build; - m_remote_platform_sp->GetOSBuildString(remote_os_build); + llvm::Optional<std::string> remote_os_build = + m_remote_platform_sp->GetOSBuildString(); if (local_os_build == remote_os_build) { // same OS version: the local file is good enough local_file = platform_file; diff --git a/lldb/source/Plugins/Platform/gdb-server/PlatformRemoteGDBServer.cpp b/lldb/source/Plugins/Platform/gdb-server/PlatformRemoteGDBServer.cpp index f09511b032bb7..cc3d79cef10c6 100644 --- a/lldb/source/Plugins/Platform/gdb-server/PlatformRemoteGDBServer.cpp +++ b/lldb/source/Plugins/Platform/gdb-server/PlatformRemoteGDBServer.cpp @@ -241,8 +241,8 @@ bool PlatformRemoteGDBServer::GetRemoteOSVersion() { return !m_os_version.empty(); } -bool PlatformRemoteGDBServer::GetRemoteOSBuildString(std::string &s) { - return m_gdb_client.GetOSBuildString(s); +llvm::Optional<std::string> PlatformRemoteGDBServer::GetRemoteOSBuildString() { + return m_gdb_client.GetOSBuildString(); } bool PlatformRemoteGDBServer::GetRemoteOSKernelDescription(std::string &s) { diff --git a/lldb/source/Plugins/Platform/gdb-server/PlatformRemoteGDBServer.h b/lldb/source/Plugins/Platform/gdb-server/PlatformRemoteGDBServer.h index 0c8584a7388c6..ff487b3d1064b 100644 --- a/lldb/source/Plugins/Platform/gdb-server/PlatformRemoteGDBServer.h +++ b/lldb/source/Plugins/Platform/gdb-server/PlatformRemoteGDBServer.h @@ -79,7 +79,7 @@ class PlatformRemoteGDBServer : public Platform, private UserIDResolver { bool GetRemoteOSVersion() override; - bool GetRemoteOSBuildString(std::string &s) override; + llvm::Optional<std::string> GetRemoteOSBuildString() override; bool GetRemoteOSKernelDescription(std::string &s) override; diff --git a/lldb/source/Plugins/Process/gdb-remote/GDBRemoteCommunicationClient.cpp b/lldb/source/Plugins/Process/gdb-remote/GDBRemoteCommunicationClient.cpp index a43f8c004aaae..11fd467b4c402 100644 --- a/lldb/source/Plugins/Process/gdb-remote/GDBRemoteCommunicationClient.cpp +++ b/lldb/source/Plugins/Process/gdb-remote/GDBRemoteCommunicationClient.cpp @@ -970,15 +970,12 @@ llvm::VersionTuple GDBRemoteCommunicationClient::GetMacCatalystVersion() { return m_maccatalyst_version; } -bool GDBRemoteCommunicationClient::GetOSBuildString(std::string &s) { +llvm::Optional<std::string> GDBRemoteCommunicationClient::GetOSBuildString() { if (GetHostInfo()) { - if (!m_os_build.empty()) { - s = m_os_build; - return true; - } + if (!m_os_build.empty()) + return m_os_build; } - s.clear(); - return false; + return llvm::None; } bool GDBRemoteCommunicationClient::GetOSKernelDescription(std::string &s) { diff --git a/lldb/source/Plugins/Process/gdb-remote/GDBRemoteCommunicationClient.h b/lldb/source/Plugins/Process/gdb-remote/GDBRemoteCommunicationClient.h index a199ef9708ac1..cdf512f5f78c5 100644 --- a/lldb/source/Plugins/Process/gdb-remote/GDBRemoteCommunicationClient.h +++ b/lldb/source/Plugins/Process/gdb-remote/GDBRemoteCommunicationClient.h @@ -239,7 +239,7 @@ class GDBRemoteCommunicationClient : public GDBRemoteClientBase { llvm::VersionTuple GetMacCatalystVersion(); - bool GetOSBuildString(std::string &s); + llvm::Optional<std::string> GetOSBuildString(); bool GetOSKernelDescription(std::string &s); diff --git a/lldb/source/Target/Platform.cpp b/lldb/source/Target/Platform.cpp index 0f2eee893fe6e..24ea8c47e0cb1 100644 --- a/lldb/source/Target/Platform.cpp +++ b/lldb/source/Target/Platform.cpp @@ -398,7 +398,6 @@ Platform::Platform(bool is_host) Platform::~Platform() = default; void Platform::GetStatus(Stream &strm) { - std::string s; strm.Format(" Platform: {0}\n", GetPluginName()); ArchSpec arch(GetSystemArchitecture()); @@ -414,8 +413,8 @@ void Platform::GetStatus(Stream &strm) { if (!os_version.empty()) { strm.Format("OS Version: {0}", os_version.getAsString()); - if (GetOSBuildString(s)) - strm.Printf(" (%s)", s.c_str()); + if (llvm::Optional<std::string> s = GetOSBuildString()) + strm.Format(" ({0})", *s); strm.EOL(); } @@ -440,6 +439,7 @@ void Platform::GetStatus(Stream &strm) { if (!specific_info.empty()) strm.Printf("Platform-specific connection: %s\n", specific_info.c_str()); + std::string s; if (GetOSKernelDescription(s)) strm.Printf(" Kernel: %s\n", s.c_str()); } @@ -486,14 +486,10 @@ llvm::VersionTuple Platform::GetOSVersion(Process *process) { return llvm::VersionTuple(); } -bool Platform::GetOSBuildString(std::string &s) { - if (IsHost()) { - llvm::Optional<std::string> str = HostInfo::GetOSBuildString(); - s = str.getValueOr(""); - return str.hasValue(); - } - s.clear(); - return GetRemoteOSBuildString(s); +llvm::Optional<std::string> Platform::GetOSBuildString() { + if (IsHost()) + return HostInfo::GetOSBuildString(); + return GetRemoteOSBuildString(); } bool Platform::GetOSKernelDescription(std::string &s) { diff --git a/lldb/source/Target/RemoteAwarePlatform.cpp b/lldb/source/Target/RemoteAwarePlatform.cpp index 61a84e878c668..cacacc7373305 100644 --- a/lldb/source/Target/RemoteAwarePlatform.cpp +++ b/lldb/source/Target/RemoteAwarePlatform.cpp @@ -332,11 +332,10 @@ bool RemoteAwarePlatform::GetRemoteOSVersion() { return false; } -bool RemoteAwarePlatform::GetRemoteOSBuildString(std::string &s) { +llvm::Optional<std::string> RemoteAwarePlatform::GetRemoteOSBuildString() { if (m_remote_platform_sp) - return m_remote_platform_sp->GetRemoteOSBuildString(s); - s.clear(); - return false; + return m_remote_platform_sp->GetRemoteOSBuildString(); + return llvm::None; } bool RemoteAwarePlatform::GetRemoteOSKernelDescription(std::string &s) { _______________________________________________ lldb-commits mailing list lldb-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits