[Lldb-commits] [PATCH] D21649: Don't create unnecessary remote platforms

Francis Ricci via lldb-commits lldb-commits at lists.llvm.org
Thu Jun 23 09:54:54 PDT 2016


fjricci created this revision.
fjricci added reviewers: clayborg, jingham, vharron.
fjricci added subscribers: sas, lldb-commits.

When using 'platform select', re-use an existing platform
which matches the remote platform specs, rather than creating a new one.

Without this patch, repeating the following sequence of commands will generate a
large number of platforms which are unused (and inaccessible):
platform select remote-linux
platform connect <url>
platform select host
platform select remote-linux

http://reviews.llvm.org/D21649

Files:
  source/Commands/CommandObjectPlatform.cpp

Index: source/Commands/CommandObjectPlatform.cpp
===================================================================
--- source/Commands/CommandObjectPlatform.cpp
+++ source/Commands/CommandObjectPlatform.cpp
@@ -237,20 +237,41 @@
             {
                 const bool select = true;
                 m_platform_options.SetPlatformName (platform_name);
-                Error error;
-                ArchSpec platform_arch;
-                PlatformSP platform_sp (m_platform_options.CreatePlatformWithOptions (m_interpreter, ArchSpec(), select, error, platform_arch));
-                if (platform_sp)
+
+                bool found = false;
+                PlatformList &list = m_interpreter.GetDebugger().GetPlatformList();
+                for (size_t i = 0; i <  list.GetSize(); ++i)
                 {
-                    m_interpreter.GetDebugger().GetPlatformList().SetSelectedPlatform(platform_sp);
+                    PlatformSP platform_sp = list.GetAtIndex(i);
+                    if (m_platform_options.PlatformMatches(platform_sp))
+                    {
+                        list.SetSelectedPlatform(platform_sp);
 
-                    platform_sp->GetStatus (result.GetOutputStream());
-                    result.SetStatus (eReturnStatusSuccessFinishResult);
+                        platform_sp->GetStatus (result.GetOutputStream());
+                        result.SetStatus (eReturnStatusSuccessFinishResult);
+
+                        found = true;
+                        break;
+                    }
                 }
-                else
+
+                if (!found)
                 {
-                    result.AppendError(error.AsCString());
-                    result.SetStatus (eReturnStatusFailed);
+                    Error error;
+                    ArchSpec platform_arch;
+                    PlatformSP platform_sp (m_platform_options.CreatePlatformWithOptions (m_interpreter, ArchSpec(), select, error, platform_arch));
+                    if (platform_sp)
+                    {
+                        list.SetSelectedPlatform(platform_sp);
+
+                        platform_sp->GetStatus (result.GetOutputStream());
+                        result.SetStatus (eReturnStatusSuccessFinishResult);
+                    }
+                    else
+                    {
+                        result.AppendError(error.AsCString());
+                        result.SetStatus (eReturnStatusFailed);
+                    }
                 }
             }
             else


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D21649.61690.patch
Type: text/x-patch
Size: 2538 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/lldb-commits/attachments/20160623/cfb5eb7f/attachment.bin>


More information about the lldb-commits mailing list