Author: Pavel Labath Date: 2021-10-27T10:46:47+02:00 New Revision: f5158ca48c260dd29136ab19ba8573226f087fb3
URL: https://github.com/llvm/llvm-project/commit/f5158ca48c260dd29136ab19ba8573226f087fb3 DIFF: https://github.com/llvm/llvm-project/commit/f5158ca48c260dd29136ab19ba8573226f087fb3.diff LOG: Modernize Platform::GetOSKernelDescription Added: Modified: lldb/include/lldb/Target/Platform.h lldb/include/lldb/Target/RemoteAwarePlatform.h lldb/source/API/SBPlatform.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 adf6d865ab184..1106ce868761c 100644 --- a/lldb/include/lldb/Target/Platform.h +++ b/lldb/include/lldb/Target/Platform.h @@ -214,7 +214,7 @@ class Platform : public PluginInterface { llvm::Optional<std::string> GetOSBuildString(); - bool GetOSKernelDescription(std::string &s); + llvm::Optional<std::string> GetOSKernelDescription(); // Returns the name of the platform ConstString GetName(); @@ -244,9 +244,8 @@ class Platform : public PluginInterface { return llvm::None; } - virtual bool GetRemoteOSKernelDescription(std::string &s) { - s.clear(); - return false; + virtual llvm::Optional<std::string> GetRemoteOSKernelDescription() { + return llvm::None; } // Remote Platform subclasses need to override this function diff --git a/lldb/include/lldb/Target/RemoteAwarePlatform.h b/lldb/include/lldb/Target/RemoteAwarePlatform.h index d8f7720d2fd96..f2a4ffae2aae3 100644 --- a/lldb/include/lldb/Target/RemoteAwarePlatform.h +++ b/lldb/include/lldb/Target/RemoteAwarePlatform.h @@ -65,7 +65,7 @@ class RemoteAwarePlatform : public Platform { bool GetRemoteOSVersion() override; llvm::Optional<std::string> GetRemoteOSBuildString() override; - bool GetRemoteOSKernelDescription(std::string &s) override; + llvm::Optional<std::string> GetRemoteOSKernelDescription() override; ArchSpec GetRemoteSystemArchitecture() override; Status RunShellCommand(llvm::StringRef command, const FileSpec &working_dir, diff --git a/lldb/source/API/SBPlatform.cpp b/lldb/source/API/SBPlatform.cpp index 71d6b1c41e32f..d7a86f0ad1ddc 100644 --- a/lldb/source/API/SBPlatform.cpp +++ b/lldb/source/API/SBPlatform.cpp @@ -473,13 +473,11 @@ const char *SBPlatform::GetOSDescription() { PlatformSP platform_sp(GetSP()); if (platform_sp) { - std::string s; - if (platform_sp->GetOSKernelDescription(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->GetOSKernelDescription().getValueOr(""); + 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(); } } return nullptr; diff --git a/lldb/source/Plugins/Platform/gdb-server/PlatformRemoteGDBServer.cpp b/lldb/source/Plugins/Platform/gdb-server/PlatformRemoteGDBServer.cpp index 851d6291591a8..d0a8fc4ebf381 100644 --- a/lldb/source/Plugins/Platform/gdb-server/PlatformRemoteGDBServer.cpp +++ b/lldb/source/Plugins/Platform/gdb-server/PlatformRemoteGDBServer.cpp @@ -240,8 +240,9 @@ llvm::Optional<std::string> PlatformRemoteGDBServer::GetRemoteOSBuildString() { return m_gdb_client.GetOSBuildString(); } -bool PlatformRemoteGDBServer::GetRemoteOSKernelDescription(std::string &s) { - return m_gdb_client.GetOSKernelDescription(s); +llvm::Optional<std::string> +PlatformRemoteGDBServer::GetRemoteOSKernelDescription() { + return m_gdb_client.GetOSKernelDescription(); } // Remote Platform subclasses need to override this function diff --git a/lldb/source/Plugins/Platform/gdb-server/PlatformRemoteGDBServer.h b/lldb/source/Plugins/Platform/gdb-server/PlatformRemoteGDBServer.h index b5e52e0219828..f3d7ef17ccabb 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 { llvm::Optional<std::string> GetRemoteOSBuildString() override; - bool GetRemoteOSKernelDescription(std::string &s) override; + llvm::Optional<std::string> GetRemoteOSKernelDescription() override; // Remote Platform subclasses need to override this function ArchSpec GetRemoteSystemArchitecture() override; diff --git a/lldb/source/Plugins/Process/gdb-remote/GDBRemoteCommunicationClient.cpp b/lldb/source/Plugins/Process/gdb-remote/GDBRemoteCommunicationClient.cpp index 11fd467b4c402..6fd51126762eb 100644 --- a/lldb/source/Plugins/Process/gdb-remote/GDBRemoteCommunicationClient.cpp +++ b/lldb/source/Plugins/Process/gdb-remote/GDBRemoteCommunicationClient.cpp @@ -978,15 +978,13 @@ llvm::Optional<std::string> GDBRemoteCommunicationClient::GetOSBuildString() { return llvm::None; } -bool GDBRemoteCommunicationClient::GetOSKernelDescription(std::string &s) { +llvm::Optional<std::string> +GDBRemoteCommunicationClient::GetOSKernelDescription() { if (GetHostInfo()) { - if (!m_os_kernel.empty()) { - s = m_os_kernel; - return true; - } + if (!m_os_kernel.empty()) + return m_os_kernel; } - s.clear(); - return false; + return llvm::None; } bool GDBRemoteCommunicationClient::GetHostname(std::string &s) { diff --git a/lldb/source/Plugins/Process/gdb-remote/GDBRemoteCommunicationClient.h b/lldb/source/Plugins/Process/gdb-remote/GDBRemoteCommunicationClient.h index cdf512f5f78c5..3fbe2908bf3fd 100644 --- a/lldb/source/Plugins/Process/gdb-remote/GDBRemoteCommunicationClient.h +++ b/lldb/source/Plugins/Process/gdb-remote/GDBRemoteCommunicationClient.h @@ -241,7 +241,7 @@ class GDBRemoteCommunicationClient : public GDBRemoteClientBase { llvm::Optional<std::string> GetOSBuildString(); - bool GetOSKernelDescription(std::string &s); + llvm::Optional<std::string> GetOSKernelDescription(); ArchSpec GetSystemArchitecture(); diff --git a/lldb/source/Target/Platform.cpp b/lldb/source/Target/Platform.cpp index 2d4c292c7510e..b7c691b058be5 100644 --- a/lldb/source/Target/Platform.cpp +++ b/lldb/source/Target/Platform.cpp @@ -439,9 +439,8 @@ 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()); + if (llvm::Optional<std::string> s = GetOSKernelDescription()) + strm.Format(" Kernel: {0}\n", *s); } llvm::VersionTuple Platform::GetOSVersion(Process *process) { @@ -492,13 +491,10 @@ llvm::Optional<std::string> Platform::GetOSBuildString() { return GetRemoteOSBuildString(); } -bool Platform::GetOSKernelDescription(std::string &s) { - if (IsHost()) { - llvm::Optional<std::string> desc = HostInfo::GetOSKernelDescription(); - s = desc.getValueOr(""); - return desc.hasValue(); - } - return GetRemoteOSKernelDescription(s); +llvm::Optional<std::string> Platform::GetOSKernelDescription() { + if (IsHost()) + return HostInfo::GetOSKernelDescription(); + return GetRemoteOSKernelDescription(); } void Platform::AddClangModuleCompilationOptions( diff --git a/lldb/source/Target/RemoteAwarePlatform.cpp b/lldb/source/Target/RemoteAwarePlatform.cpp index cacacc7373305..6d38025408b29 100644 --- a/lldb/source/Target/RemoteAwarePlatform.cpp +++ b/lldb/source/Target/RemoteAwarePlatform.cpp @@ -338,11 +338,10 @@ llvm::Optional<std::string> RemoteAwarePlatform::GetRemoteOSBuildString() { return llvm::None; } -bool RemoteAwarePlatform::GetRemoteOSKernelDescription(std::string &s) { +llvm::Optional<std::string> RemoteAwarePlatform::GetRemoteOSKernelDescription() { if (m_remote_platform_sp) - return m_remote_platform_sp->GetRemoteOSKernelDescription(s); - s.clear(); - return false; + return m_remote_platform_sp->GetRemoteOSKernelDescription(); + return llvm::None; } ArchSpec RemoteAwarePlatform::GetRemoteSystemArchitecture() { _______________________________________________ lldb-commits mailing list lldb-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits