diff --git a/lldb/include/lldb/Target/Platform.h b/lldb/include/lldb/Target/Platform.h index 7cb534afe6ec..d1351d5c729b 100644 --- a/lldb/include/lldb/Target/Platform.h +++ b/lldb/include/lldb/Target/Platform.h @@ -212,7 +212,7 @@ public: bool SetOSVersion(llvm::VersionTuple os_version); - bool GetOSBuildString(std::string &s); + llvm::Optional GetOSBuildString(); bool GetOSKernelDescription(std::string &s); @@ -240,9 +240,8 @@ public: // HostInfo::GetOSVersion(). virtual bool GetRemoteOSVersion() { return false; } - virtual bool GetRemoteOSBuildString(std::string &s) { - s.clear(); - return false; + virtual llvm::Optional 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 269d15299889..d8f7720d2fd9 100644 --- a/lldb/include/lldb/Target/RemoteAwarePlatform.h +++ b/lldb/include/lldb/Target/RemoteAwarePlatform.h @@ -64,7 +64,7 @@ public: FileSpec &local_file) override; bool GetRemoteOSVersion() override; - bool GetRemoteOSBuildString(std::string &s) override; + llvm::Optional 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 496c40a0678f..71d6b1c41e32 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 236eacebf714..97b2b4a3b740 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 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 ea93d9944879..c654f3c4264f 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 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 f09511b032bb..cc3d79cef10c 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 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 0c8584a7388c..ff487b3d1064 100644 --- a/lldb/source/Plugins/Platform/gdb-server/PlatformRemoteGDBServer.h +++ b/lldb/source/Plugins/Platform/gdb-server/PlatformRemoteGDBServer.h @@ -79,7 +79,7 @@ public: bool GetRemoteOSVersion() override; - bool GetRemoteOSBuildString(std::string &s) override; + llvm::Optional 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 a43f8c004aaa..11fd467b4c40 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 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 a199ef9708ac..cdf512f5f78c 100644 --- a/lldb/source/Plugins/Process/gdb-remote/GDBRemoteCommunicationClient.h +++ b/lldb/source/Plugins/Process/gdb-remote/GDBRemoteCommunicationClient.h @@ -239,7 +239,7 @@ public: llvm::VersionTuple GetMacCatalystVersion(); - bool GetOSBuildString(std::string &s); + llvm::Optional GetOSBuildString(); bool GetOSKernelDescription(std::string &s); diff --git a/lldb/source/Target/Platform.cpp b/lldb/source/Target/Platform.cpp index 0f2eee893fe6..24ea8c47e0cb 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 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 str = HostInfo::GetOSBuildString(); - s = str.getValueOr(""); - return str.hasValue(); - } - s.clear(); - return GetRemoteOSBuildString(s); +llvm::Optional 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 61a84e878c66..cacacc737330 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 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) {