diff --git a/lldb/source/Commands/CommandObjectPlatform.cpp b/lldb/source/Commands/CommandObjectPlatform.cpp --- a/lldb/source/Commands/CommandObjectPlatform.cpp +++ b/lldb/source/Commands/CommandObjectPlatform.cpp @@ -21,7 +21,7 @@ #include "lldb/Target/Platform.h" #include "lldb/Target/Process.h" #include "lldb/Utility/Args.h" - +#include "llvm/ADT/MapVector.h" #include "llvm/ADT/SmallString.h" using namespace lldb; @@ -205,13 +205,19 @@ ~CommandObjectPlatformList() override = default; protected: + struct PluginInfo { + llvm::StringRef description; + std::vector instances; + }; + bool DoExecute(Args &args, CommandReturnObject &result) override { - Stream &ostrm = result.GetOutputStream(); - ostrm.Printf("Available platforms:\n"); + llvm::MapVector plugin_map; PlatformSP host_platform_sp(Platform::GetHostPlatform()); - ostrm.Format("{0}: {1}\n", host_platform_sp->GetPluginName(), - host_platform_sp->GetDescription()); + plugin_map[host_platform_sp->GetPluginName()] = + PluginInfo{host_platform_sp->GetDescription(), {}}; + PlatformSP current_platform_sp = + GetDebugger().GetPlatformList().GetSelectedPlatform(); uint32_t idx; for (idx = 0; true; ++idx) { @@ -219,15 +225,31 @@ PluginManager::GetPlatformPluginNameAtIndex(idx); if (plugin_name.empty()) break; - llvm::StringRef plugin_desc = + plugin_map[plugin_name].description = PluginManager::GetPlatformPluginDescriptionAtIndex(idx); - ostrm.Format("{0}: {1}\n", plugin_name, plugin_desc); + } + for (idx = 0; idx < GetDebugger().GetPlatformList().GetSize(); ++idx) { + PlatformSP platform_sp = GetDebugger().GetPlatformList().GetAtIndex(idx); + plugin_map[platform_sp->GetPluginName()].instances.push_back(platform_sp); } - if (idx == 0) { - result.AppendError("no platforms are available\n"); - } else - result.SetStatus(eReturnStatusSuccessFinishResult); + llvm::raw_ostream &OS = result.GetOutputStream().AsRawOstream(); + OS << "Available platform plugins and their active instances:\n"; + + for (const auto &info: plugin_map) { + OS << llvm::formatv("{0}: {1}\n", info.first, info.second.description); + if (!info.second.instances.empty()) { + OS << " "; + llvm::ListSeparator LS; + for (const PlatformSP &platform_sp : info.second.instances) { + OS << LS << platform_sp->GetName(); + if (platform_sp == current_platform_sp) + OS << " (*)"; + } + } + OS << "\n"; + } + result.SetStatus(eReturnStatusSuccessFinishResult); return result.Succeeded(); } }; diff --git a/lldb/source/Plugins/Platform/MacOSX/PlatformMacOSX.h b/lldb/source/Plugins/Platform/MacOSX/PlatformMacOSX.h --- a/lldb/source/Plugins/Platform/MacOSX/PlatformMacOSX.h +++ b/lldb/source/Plugins/Platform/MacOSX/PlatformMacOSX.h @@ -16,9 +16,6 @@ PlatformMacOSX(); // Class functions - static lldb::PlatformSP CreateInstance(bool force, - const lldb_private::ArchSpec *arch); - static void Initialize(); static void Terminate(); diff --git a/lldb/source/Plugins/Platform/MacOSX/PlatformMacOSX.cpp b/lldb/source/Plugins/Platform/MacOSX/PlatformMacOSX.cpp --- a/lldb/source/Plugins/Platform/MacOSX/PlatformMacOSX.cpp +++ b/lldb/source/Plugins/Platform/MacOSX/PlatformMacOSX.cpp @@ -60,18 +60,11 @@ default_platform_sp->SetSystemArchitecture(HostInfo::GetArchitecture()); Platform::SetHostPlatform(default_platform_sp); #endif - PluginManager::RegisterPlugin(PlatformMacOSX::GetPluginNameStatic(), - PlatformMacOSX::GetDescriptionStatic(), - PlatformMacOSX::CreateInstance); } } void PlatformMacOSX::Terminate() { - if (g_initialize_count > 0) { - if (--g_initialize_count == 0) { - PluginManager::UnregisterPlugin(PlatformMacOSX::CreateInstance); - } - } + --g_initialize_count; #if defined(__APPLE__) PlatformRemoteAppleBridge::Terminate(); @@ -89,12 +82,6 @@ return "Local Mac OS X user platform plug-in."; } -PlatformSP PlatformMacOSX::CreateInstance(bool force, const ArchSpec *arch) { - // The only time we create an instance is when we are creating a remote - // macosx platform which is handled by PlatformRemoteMacOSX. - return PlatformSP(); -} - /// Default Constructor PlatformMacOSX::PlatformMacOSX() : PlatformDarwin(true) {} diff --git a/lldb/test/API/commands/platform/basic/TestPlatformCommand.py b/lldb/test/API/commands/platform/basic/TestPlatformCommand.py --- a/lldb/test/API/commands/platform/basic/TestPlatformCommand.py +++ b/lldb/test/API/commands/platform/basic/TestPlatformCommand.py @@ -30,7 +30,7 @@ @no_debug_info_test def test_list(self): self.expect("platform list", - patterns=['^Available platforms:']) + patterns=['^Available platform plugins']) @no_debug_info_test def test_process_list(self): diff --git a/lldb/test/Shell/Commands/command-platform-list.test b/lldb/test/Shell/Commands/command-platform-list.test new file mode 100644 --- /dev/null +++ b/lldb/test/Shell/Commands/command-platform-list.test @@ -0,0 +1,24 @@ +# RUN: %lldb -s %s -o exit | FileCheck %s + +platform list +# CHECK-LABEL: platform list +# CHECK: host: +# CHECK-NEXT: host (*) +# CHECK: remote-linux: Remote Linux user platform plug-in. +# CHECK-EMPTY: + +platform select remote-linux +platform list +# CHECK-LABEL: platform list +# CHECK: host: +# CHECK-NEXT: host +# CHECK: remote-linux: Remote Linux user platform plug-in. +# CHECK-NEXT: remote-linux (*) + +platform select remote-linux +platform list +# CHECK-LABEL: platform list +# CHECK: host: +# CHECK-NEXT: host +# CHECK: remote-linux: Remote Linux user platform plug-in. +# CHECK-NEXT: remote-linux, remote-linux (*)