Platforms can now auto-select themselves if you specify a full target triple when doing a "target create" command.
Each platform now knows if it can handle an architecture and a platform can be found using an architecture. Each platform can look at the arch, vendor and OS and know if it should be used or not.
git-svn-id: https://llvm.org/svn/llvm-project/lldb/trunk@153104 91177308-0d34-0410-b5e6-96231b3b80d8
diff --git a/source/Target/Platform.cpp b/source/Target/Platform.cpp
index 403b10e..cc8070d 100644
--- a/source/Target/Platform.cpp
+++ b/source/Target/Platform.cpp
@@ -110,7 +110,6 @@
always_create);
}
-
PlatformSP
Platform::Create (const char *platform_name, Error &error)
{
@@ -120,7 +119,7 @@
{
create_callback = PluginManager::GetPlatformCreateCallbackForPluginName (platform_name);
if (create_callback)
- platform_sp.reset(create_callback());
+ platform_sp.reset(create_callback(true, NULL));
else
error.SetErrorStringWithFormat ("unable to find a plug-in for the platform named \"%s\"", platform_name);
}
@@ -129,6 +128,27 @@
return platform_sp;
}
+
+PlatformSP
+Platform::Create (const ArchSpec &arch, Error &error)
+{
+ lldb::PlatformSP platform_sp;
+ if (arch.IsValid())
+ {
+ PlatformCreateInstance create_callback;
+ for (uint32_t idx = 0; (create_callback = PluginManager::GetPlatformCreateCallbackAtIndex (idx)); ++idx)
+ {
+ if (create_callback)
+ platform_sp.reset(create_callback(false, &arch));
+ if (platform_sp && platform_sp->IsCompatibleWithArchitecture(arch))
+ break;
+ }
+ }
+ else
+ error.SetErrorString ("invalid platform name");
+ return platform_sp;
+}
+
uint32_t
Platform::GetNumConnectedRemotePlatforms ()
{
@@ -592,3 +612,38 @@
}
return process_sp;
}
+
+
+lldb::PlatformSP
+Platform::GetPlatformForArchitecture (const ArchSpec &arch)
+{
+ lldb::PlatformSP platform_sp;
+ Error error;
+ if (arch.IsValid())
+ platform_sp = Platform::Create (arch, error);
+ return platform_sp;
+}
+
+
+//------------------------------------------------------------------
+/// Lets a platform answer if it is compatible with a given
+/// architecture and the target triple contained within.
+//------------------------------------------------------------------
+bool
+Platform::IsCompatibleWithArchitecture (const ArchSpec &arch)
+{
+ // If the architecture is invalid, we must answer true...
+ if (!arch.IsValid())
+ return true;
+
+ ArchSpec platform_arch;
+ for (uint32_t arch_idx=0; GetSupportedArchitectureAtIndex (arch_idx, platform_arch); ++arch_idx)
+ {
+ if (arch == platform_arch)
+ return true;
+ }
+ return false;
+
+}
+
+