Modernize Platform::GetOSKernelDescription
authorPavel Labath <pavel@labath.sk>
Tue, 26 Oct 2021 08:52:39 +0000 (10:52 +0200)
committerPavel Labath <pavel@labath.sk>
Wed, 27 Oct 2021 08:46:47 +0000 (10:46 +0200)
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

index adf6d86..1106ce8 100644 (file)
@@ -214,7 +214,7 @@ public:
 
   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 @@ public:
     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
index d8f7720..f2a4ffa 100644 (file)
@@ -65,7 +65,7 @@ public:
 
   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,
index 71d6b1c..d7a86f0 100644 (file)
@@ -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;
index 851d629..d0a8fc4 100644 (file)
@@ -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
index b5e52e0..f3d7ef1 100644 (file)
@@ -79,7 +79,7 @@ public:
 
   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;
index 11fd467..6fd5112 100644 (file)
@@ -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) {
index cdf512f..3fbe290 100644 (file)
@@ -241,7 +241,7 @@ public:
 
   llvm::Optional<std::string> GetOSBuildString();
 
-  bool GetOSKernelDescription(std::string &s);
+  llvm::Optional<std::string> GetOSKernelDescription();
 
   ArchSpec GetSystemArchitecture();
 
index 2d4c292..b7c691b 100644 (file)
@@ -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(
index cacacc7..6d38025 100644 (file)
@@ -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() {