[Lldb-commits] [lldb] d2edca6 - [lldb/Platform] Prepare decouple instance and plugin names

Pavel Labath via lldb-commits lldb-commits at lists.llvm.org
Wed Mar 2 06:01:19 PST 2022


Author: Pavel Labath
Date: 2022-03-02T14:57:01+01:00
New Revision: d2edca6276d1715a02d1144eae577b3d79673d67

URL: https://github.com/llvm/llvm-project/commit/d2edca6276d1715a02d1144eae577b3d79673d67
DIFF: https://github.com/llvm/llvm-project/commit/d2edca6276d1715a02d1144eae577b3d79673d67.diff

LOG: [lldb/Platform] Prepare decouple instance and plugin names

This patch changes the return value of Platform::GetName() to a
StringRef, and uses the opportunity (compile errors) to change some
callsites to use GetPluginName() instead. The two methods still remain
hardwired to return the same thing, but this will change once the ideas
in
<https://discourse.llvm.org/t/multiple-platforms-with-the-same-name/59594>
are implemented.

Differential Revision: https://reviews.llvm.org/D119146

Added: 
    

Modified: 
    lldb/include/lldb/Target/Platform.h
    lldb/source/API/SBPlatform.cpp
    lldb/source/Commands/CommandObjectPlatform.cpp
    lldb/source/Commands/CommandObjectTarget.cpp
    lldb/source/Core/IOHandlerCursesGUI.cpp
    lldb/source/Interpreter/OptionGroupPlatform.cpp
    lldb/source/Plugins/Platform/Android/PlatformAndroidRemoteGDBServer.cpp
    lldb/source/Plugins/Platform/Android/PlatformAndroidRemoteGDBServer.h
    lldb/source/Plugins/Platform/MacOSX/PlatformDarwin.cpp
    lldb/source/Plugins/Platform/MacOSX/PlatformDarwin.h
    lldb/source/Plugins/Process/gdb-remote/ProcessGDBRemote.cpp
    lldb/source/Target/Platform.cpp
    lldb/source/Target/Process.cpp
    lldb/source/Target/TargetList.cpp

Removed: 
    


################################################################################
diff  --git a/lldb/include/lldb/Target/Platform.h b/lldb/include/lldb/Target/Platform.h
index b804d4877c59c..b3855f0bb5071 100644
--- a/lldb/include/lldb/Target/Platform.h
+++ b/lldb/include/lldb/Target/Platform.h
@@ -217,7 +217,7 @@ class Platform : public PluginInterface {
   llvm::Optional<std::string> GetOSKernelDescription();
 
   // Returns the name of the platform
-  ConstString GetName();
+  llvm::StringRef GetName() { return GetPluginName(); }
 
   virtual const char *GetHostname();
 
@@ -508,17 +508,17 @@ class Platform : public PluginInterface {
 
   virtual uint64_t ReadFile(lldb::user_id_t fd, uint64_t offset, void *dst,
                             uint64_t dst_len, Status &error) {
-    error.SetErrorStringWithFormat(
-        "Platform::ReadFile() is not supported in the %s platform",
-        GetName().GetCString());
+    error.SetErrorStringWithFormatv(
+        "Platform::ReadFile() is not supported in the {0} platform",
+        GetPluginName());
     return -1;
   }
 
   virtual uint64_t WriteFile(lldb::user_id_t fd, uint64_t offset,
                              const void *src, uint64_t src_len, Status &error) {
-    error.SetErrorStringWithFormat(
-        "Platform::WriteFile() is not supported in the %s platform",
-        GetName().GetCString());
+    error.SetErrorStringWithFormatv(
+        "Platform::WriteFile() is not supported in the {0} platform",
+        GetPluginName());
     return -1;
   }
 

diff  --git a/lldb/source/API/SBPlatform.cpp b/lldb/source/API/SBPlatform.cpp
index d521a38b30e8d..eeb56e9c6ed9b 100644
--- a/lldb/source/API/SBPlatform.cpp
+++ b/lldb/source/API/SBPlatform.cpp
@@ -342,7 +342,7 @@ const char *SBPlatform::GetName() {
 
   PlatformSP platform_sp(GetSP());
   if (platform_sp)
-    return platform_sp->GetName().GetCString();
+    return ConstString(platform_sp->GetName()).AsCString();
   return nullptr;
 }
 

diff  --git a/lldb/source/Commands/CommandObjectPlatform.cpp b/lldb/source/Commands/CommandObjectPlatform.cpp
index 4c18465c868a0..bf586adb2bbd1 100644
--- a/lldb/source/Commands/CommandObjectPlatform.cpp
+++ b/lldb/source/Commands/CommandObjectPlatform.cpp
@@ -1281,16 +1281,15 @@ class CommandObjectPlatformProcessList : public CommandObjectParsed {
                 result.AppendErrorWithFormatv(
                     "no processes were found that {0} \"{1}\" on the \"{2}\" "
                     "platform\n",
-                    match_desc, match_name, platform_sp->GetPluginName());
+                    match_desc, match_name, platform_sp->GetName());
               else
                 result.AppendErrorWithFormatv(
                     "no processes were found on the \"{0}\" platform\n",
-                    platform_sp->GetPluginName());
+                    platform_sp->GetName());
             } else {
-              result.AppendMessageWithFormat(
-                  "%u matching process%s found on \"%s\"", matches,
-                  matches > 1 ? "es were" : " was",
-                  platform_sp->GetName().GetCString());
+              result.AppendMessageWithFormatv(
+                  "{0} matching process{1} found on \"{2}\"", matches,
+                  matches > 1 ? "es were" : " was", platform_sp->GetName());
               if (match_desc)
                 result.AppendMessageWithFormat(" whose name %s \"%s\"",
                                                match_desc, match_name);

diff  --git a/lldb/source/Commands/CommandObjectTarget.cpp b/lldb/source/Commands/CommandObjectTarget.cpp
index cda30a0d7902a..38aa841e50400 100644
--- a/lldb/source/Commands/CommandObjectTarget.cpp
+++ b/lldb/source/Commands/CommandObjectTarget.cpp
@@ -84,8 +84,8 @@ static void DumpTargetInfo(uint32_t target_idx, Target *target,
   }
   PlatformSP platform_sp(target->GetPlatform());
   if (platform_sp)
-    strm.Printf("%splatform=%s", properties++ > 0 ? ", " : " ( ",
-                platform_sp->GetName().GetCString());
+    strm.Format("{0}platform={1}", properties++ > 0 ? ", " : " ( ",
+                platform_sp->GetName());
 
   ProcessSP process_sp(target->GetProcessSP());
   bool show_process_status = false;

diff  --git a/lldb/source/Core/IOHandlerCursesGUI.cpp b/lldb/source/Core/IOHandlerCursesGUI.cpp
index b37e84a13c5e4..fd8cd51e30610 100644
--- a/lldb/source/Core/IOHandlerCursesGUI.cpp
+++ b/lldb/source/Core/IOHandlerCursesGUI.cpp
@@ -1609,7 +1609,7 @@ class ChoicesFieldDelegate : public FieldDelegate {
   // Returns the index of the choice.
   int GetChoice() { return m_choice; }
 
-  void SetChoice(const std::string &choice) {
+  void SetChoice(llvm::StringRef choice) {
     for (int i = 0; i < GetNumberOfChoices(); i++) {
       if (choice == m_choices[i]) {
         m_choice = i;
@@ -1634,7 +1634,7 @@ class PlatformPluginFieldDelegate : public ChoicesFieldDelegate {
       : ChoicesFieldDelegate("Platform Plugin", 3, GetPossiblePluginNames()) {
     PlatformSP platform_sp = debugger.GetPlatformList().GetSelectedPlatform();
     if (platform_sp)
-      SetChoice(platform_sp->GetName().AsCString());
+      SetChoice(platform_sp->GetPluginName());
   }
 
   std::vector<std::string> GetPossiblePluginNames() {

diff  --git a/lldb/source/Interpreter/OptionGroupPlatform.cpp b/lldb/source/Interpreter/OptionGroupPlatform.cpp
index 4242e010fa64e..c30293a6db36f 100644
--- a/lldb/source/Interpreter/OptionGroupPlatform.cpp
+++ b/lldb/source/Interpreter/OptionGroupPlatform.cpp
@@ -25,9 +25,9 @@ PlatformSP OptionGroupPlatform::CreatePlatformWithOptions(
     if (platform_sp) {
       if (platform_arch.IsValid() &&
           !platform_sp->IsCompatibleArchitecture(arch, false, &platform_arch)) {
-        error.SetErrorStringWithFormat("platform '%s' doesn't support '%s'",
-                                       platform_sp->GetName().GetCString(),
-                                       arch.GetTriple().getTriple().c_str());
+        error.SetErrorStringWithFormatv("platform '{0}' doesn't support '{1}'",
+                                        platform_sp->GetPluginName(),
+                                        arch.GetTriple().getTriple());
         platform_sp.reset();
         return platform_sp;
       }
@@ -122,7 +122,7 @@ bool OptionGroupPlatform::PlatformMatches(
     const lldb::PlatformSP &platform_sp) const {
   if (platform_sp) {
     if (!m_platform_name.empty()) {
-      if (platform_sp->GetName() != ConstString(m_platform_name.c_str()))
+      if (platform_sp->GetName() != m_platform_name)
         return false;
     }
 

diff  --git a/lldb/source/Plugins/Platform/Android/PlatformAndroidRemoteGDBServer.cpp b/lldb/source/Plugins/Platform/Android/PlatformAndroidRemoteGDBServer.cpp
index 231319575a21c..dbbfb5b5df0d5 100644
--- a/lldb/source/Plugins/Platform/Android/PlatformAndroidRemoteGDBServer.cpp
+++ b/lldb/source/Plugins/Platform/Android/PlatformAndroidRemoteGDBServer.cpp
@@ -74,8 +74,6 @@ static Status FindUnusedPort(uint16_t &port) {
   return error;
 }
 
-PlatformAndroidRemoteGDBServer::PlatformAndroidRemoteGDBServer() = default;
-
 PlatformAndroidRemoteGDBServer::~PlatformAndroidRemoteGDBServer() {
   for (const auto &it : m_port_forwards)
     DeleteForwardPortWithAdb(it.second, m_device_id);

diff  --git a/lldb/source/Plugins/Platform/Android/PlatformAndroidRemoteGDBServer.h b/lldb/source/Plugins/Platform/Android/PlatformAndroidRemoteGDBServer.h
index c3e0d0f66e8dc..675cdc3d74e94 100644
--- a/lldb/source/Plugins/Platform/Android/PlatformAndroidRemoteGDBServer.h
+++ b/lldb/source/Plugins/Platform/Android/PlatformAndroidRemoteGDBServer.h
@@ -24,7 +24,7 @@ namespace platform_android {
 class PlatformAndroidRemoteGDBServer
     : public platform_gdb_server::PlatformRemoteGDBServer {
 public:
-  PlatformAndroidRemoteGDBServer();
+  using PlatformRemoteGDBServer::PlatformRemoteGDBServer;
 
   ~PlatformAndroidRemoteGDBServer() override;
 

diff  --git a/lldb/source/Plugins/Platform/MacOSX/PlatformDarwin.cpp b/lldb/source/Plugins/Platform/MacOSX/PlatformDarwin.cpp
index 706f3ae71bb3c..176607f36941a 100644
--- a/lldb/source/Plugins/Platform/MacOSX/PlatformDarwin.cpp
+++ b/lldb/source/Plugins/Platform/MacOSX/PlatformDarwin.cpp
@@ -48,9 +48,6 @@
 using namespace lldb;
 using namespace lldb_private;
 
-/// Default Constructor
-PlatformDarwin::PlatformDarwin(bool is_host) : PlatformPOSIX(is_host) {}
-
 /// Destructor.
 ///
 /// The destructor is virtual since this class is designed to be

diff  --git a/lldb/source/Plugins/Platform/MacOSX/PlatformDarwin.h b/lldb/source/Plugins/Platform/MacOSX/PlatformDarwin.h
index 7d5968c48f254..be336fde542f2 100644
--- a/lldb/source/Plugins/Platform/MacOSX/PlatformDarwin.h
+++ b/lldb/source/Plugins/Platform/MacOSX/PlatformDarwin.h
@@ -24,7 +24,7 @@
 
 class PlatformDarwin : public PlatformPOSIX {
 public:
-  PlatformDarwin(bool is_host);
+  using PlatformPOSIX::PlatformPOSIX;
 
   ~PlatformDarwin() override;
 

diff  --git a/lldb/source/Plugins/Process/gdb-remote/ProcessGDBRemote.cpp b/lldb/source/Plugins/Process/gdb-remote/ProcessGDBRemote.cpp
index ebd5f7370264a..ed72fb8ab670b 100644
--- a/lldb/source/Plugins/Process/gdb-remote/ProcessGDBRemote.cpp
+++ b/lldb/source/Plugins/Process/gdb-remote/ProcessGDBRemote.cpp
@@ -2404,9 +2404,8 @@ Status ProcessGDBRemote::DoDestroy() {
       m_public_state.GetValue() != eStateRunning) {
     PlatformSP platform_sp = GetTarget().GetPlatform();
 
-    if (platform_sp && platform_sp->GetName() &&
-        platform_sp->GetName().GetStringRef() ==
-            PlatformRemoteiOS::GetPluginNameStatic()) {
+    if (platform_sp && platform_sp->GetPluginName() ==
+                           PlatformRemoteiOS::GetPluginNameStatic()) {
       if (m_destroy_tried_resuming) {
         if (log)
           log->PutCString("ProcessGDBRemote::DoDestroy() - Tried resuming to "

diff  --git a/lldb/source/Target/Platform.cpp b/lldb/source/Target/Platform.cpp
index 3331235afa8b0..4440a44bd40f0 100644
--- a/lldb/source/Target/Platform.cpp
+++ b/lldb/source/Target/Platform.cpp
@@ -280,7 +280,7 @@ PlatformSP Platform::Find(ConstString name) {
 
     std::lock_guard<std::recursive_mutex> guard(GetPlatformListMutex());
     for (const auto &platform_sp : GetPlatformList()) {
-      if (platform_sp->GetName() == name)
+      if (platform_sp->GetName() == name.GetStringRef())
         return platform_sp;
     }
   }
@@ -786,8 +786,6 @@ Status Platform::SetFilePermissions(const FileSpec &file_spec,
   }
 }
 
-ConstString Platform::GetName() { return ConstString(GetPluginName()); }
-
 const char *Platform::GetHostname() {
   if (IsHost())
     return "127.0.0.1";
@@ -1728,7 +1726,7 @@ Status Platform::DownloadSymbolFile(const lldb::ModuleSP &module_sp,
 
 FileSpec Platform::GetModuleCacheRoot() {
   auto dir_spec = GetGlobalPlatformProperties().GetModuleCacheDirectory();
-  dir_spec.AppendPathComponent(GetName().AsCString());
+  dir_spec.AppendPathComponent(GetPluginName());
   return dir_spec;
 }
 

diff  --git a/lldb/source/Target/Process.cpp b/lldb/source/Target/Process.cpp
index cbb10a0ac8506..70717b332b755 100644
--- a/lldb/source/Target/Process.cpp
+++ b/lldb/source/Target/Process.cpp
@@ -2895,11 +2895,10 @@ void Process::CompleteAttach() {
       if (platform_sp) {
         GetTarget().SetPlatform(platform_sp);
         GetTarget().SetArchitecture(platform_arch);
-        LLDB_LOGF(log,
-                  "Process::%s switching platform to %s and architecture "
-                  "to %s based on info from attach",
-                  __FUNCTION__, platform_sp->GetName().AsCString(""),
-                  platform_arch.GetTriple().getTriple().c_str());
+        LLDB_LOG(log,
+                 "switching platform to {0} and architecture to {1} based on "
+                 "info from attach",
+                 platform_sp->GetName(), platform_arch.GetTriple().getTriple());
       }
     } else if (!process_arch.IsValid()) {
       ProcessInstanceInfo process_info;

diff  --git a/lldb/source/Target/TargetList.cpp b/lldb/source/Target/TargetList.cpp
index 595799cfc92aa..7badb0cdcead5 100644
--- a/lldb/source/Target/TargetList.cpp
+++ b/lldb/source/Target/TargetList.cpp
@@ -242,7 +242,7 @@ Status TargetList::CreateTargetInternal(
                 platform_set.end()) {
               if (!platform_set.empty())
                 error_strm.PutCString(", ");
-              error_strm.PutCString(the_platform_sp->GetName().GetCString());
+              error_strm.PutCString(the_platform_sp->GetName());
               platform_set.insert(the_platform_sp.get());
             }
           }


        


More information about the lldb-commits mailing list