summaryrefslogtreecommitdiffstats
path: root/lldb
diff options
context:
space:
mode:
authorGreg Clayton <gclayton@apple.com>2014-09-19 20:11:50 +0000
committerGreg Clayton <gclayton@apple.com>2014-09-19 20:11:50 +0000
commit615eb7e6097c035e0b64992798fda7c939e93303 (patch)
tree5ce9aa21d619eff5b07fba9b6f14cadbdb81b333 /lldb
parent4f1561a5dd875711fcb5018de791bf953d25c817 (diff)
downloadbcm5719-llvm-615eb7e6097c035e0b64992798fda7c939e93303.tar.gz
bcm5719-llvm-615eb7e6097c035e0b64992798fda7c939e93303.zip
Test suite runs better again after recent fixes that would select a platform if a "file a.out" auto selected a different platform than the selected one.
Changes include: - fix it so you can select the "host" platform using "platform select host" - change all callbacks that create platforms to returns shared pointers - fix TestImageListMultiArchitecture.py to restore the "host" platform by running "platform select host" - Add a new "PlatformSP Platform::Find(const ConstString &name)" method to get a cached platform - cache platforms that are created and re-use them instead of always creating a new one llvm-svn: 218145
Diffstat (limited to 'lldb')
-rw-r--r--lldb/include/lldb/Target/Platform.h14
-rw-r--r--lldb/include/lldb/lldb-private-interfaces.h2
-rw-r--r--lldb/source/API/SBDebugger.cpp35
-rw-r--r--lldb/source/API/SBPlatform.cpp3
-rw-r--r--lldb/source/Commands/CommandObjectPlatform.cpp2
-rw-r--r--lldb/source/Core/Debugger.cpp2
-rw-r--r--lldb/source/Host/common/Host.cpp2
-rw-r--r--lldb/source/Host/macosx/Host.mm2
-rw-r--r--lldb/source/Interpreter/OptionGroupPlatform.cpp2
-rw-r--r--lldb/source/Plugins/DynamicLoader/Darwin-Kernel/DynamicLoaderDarwinKernel.cpp3
-rw-r--r--lldb/source/Plugins/Platform/FreeBSD/PlatformFreeBSD.cpp10
-rw-r--r--lldb/source/Plugins/Platform/FreeBSD/PlatformFreeBSD.h2
-rw-r--r--lldb/source/Plugins/Platform/Kalimba/PlatformKalimba.cpp6
-rw-r--r--lldb/source/Plugins/Platform/Kalimba/PlatformKalimba.h2
-rw-r--r--lldb/source/Plugins/Platform/Linux/PlatformLinux.cpp8
-rw-r--r--lldb/source/Plugins/Platform/Linux/PlatformLinux.h2
-rw-r--r--lldb/source/Plugins/Platform/MacOSX/PlatformDarwinKernel.cpp8
-rw-r--r--lldb/source/Plugins/Platform/MacOSX/PlatformDarwinKernel.h2
-rw-r--r--lldb/source/Plugins/Platform/MacOSX/PlatformMacOSX.cpp8
-rw-r--r--lldb/source/Plugins/Platform/MacOSX/PlatformMacOSX.h2
-rw-r--r--lldb/source/Plugins/Platform/MacOSX/PlatformRemoteiOS.cpp6
-rw-r--r--lldb/source/Plugins/Platform/MacOSX/PlatformRemoteiOS.h2
-rw-r--r--lldb/source/Plugins/Platform/MacOSX/PlatformiOSSimulator.cpp6
-rw-r--r--lldb/source/Plugins/Platform/MacOSX/PlatformiOSSimulator.h2
-rw-r--r--lldb/source/Plugins/Platform/POSIX/PlatformPOSIX.cpp2
-rw-r--r--lldb/source/Plugins/Platform/Windows/PlatformWindows.cpp10
-rw-r--r--lldb/source/Plugins/Platform/Windows/PlatformWindows.h2
-rw-r--r--lldb/source/Plugins/Platform/gdb-server/PlatformRemoteGDBServer.cpp6
-rw-r--r--lldb/source/Plugins/Platform/gdb-server/PlatformRemoteGDBServer.h2
-rw-r--r--lldb/source/Plugins/Process/Linux/NativeProcessLinux.cpp4
-rw-r--r--lldb/source/Plugins/Process/gdb-remote/GDBRemoteCommunicationServer.cpp2
-rw-r--r--lldb/source/Target/Platform.cpp206
-rw-r--r--lldb/source/Target/TargetList.cpp2
-rw-r--r--lldb/test/functionalities/object-file/TestImageListMultiArchitecture.py2
-rw-r--r--lldb/tools/lldb-gdbserver/lldb-gdbserver.cpp10
35 files changed, 226 insertions, 155 deletions
diff --git a/lldb/include/lldb/Target/Platform.h b/lldb/include/lldb/Target/Platform.h
index e3d6abe3f39..fa54b4a1c62 100644
--- a/lldb/include/lldb/Target/Platform.h
+++ b/lldb/include/lldb/Target/Platform.h
@@ -62,7 +62,7 @@ namespace lldb_private {
/// or attaching to processes unless another platform is specified.
//------------------------------------------------------------------
static lldb::PlatformSP
- GetDefaultPlatform ();
+ GetHostPlatform ();
static lldb::PlatformSP
GetPlatformForArchitecture (const ArchSpec &arch,
@@ -72,10 +72,14 @@ namespace lldb_private {
GetHostPlatformName ();
static void
- SetDefaultPlatform (const lldb::PlatformSP &platform_sp);
+ SetHostPlatform (const lldb::PlatformSP &platform_sp);
+ // Find an existing platform plug-in by name
static lldb::PlatformSP
- Create (const char *platform_name, Error &error);
+ Find (const ConstString &name);
+
+ static lldb::PlatformSP
+ Create (const ConstString &name, Error &error);
static lldb::PlatformSP
Create (const ArchSpec &arch, ArchSpec *platform_arch_ptr, Error &error);
@@ -114,8 +118,8 @@ namespace lldb_private {
/// An optional name of a specific platform plug-in that
/// should be used. If NULL, pick the best plug-in.
//------------------------------------------------------------------
- static Platform*
- FindPlugin (Process *process, const ConstString &plugin_name);
+// static lldb::PlatformSP
+// FindPlugin (Process *process, const ConstString &plugin_name);
//------------------------------------------------------------------
/// Set the target's executable based off of the existing
diff --git a/lldb/include/lldb/lldb-private-interfaces.h b/lldb/include/lldb/lldb-private-interfaces.h
index 15a403858c4..db0c84ec9e4 100644
--- a/lldb/include/lldb/lldb-private-interfaces.h
+++ b/lldb/include/lldb/lldb-private-interfaces.h
@@ -30,7 +30,7 @@ namespace lldb_private
typedef OperatingSystem* (*OperatingSystemCreateInstance) (Process *process, bool force);
typedef LanguageRuntime *(*LanguageRuntimeCreateInstance) (Process *process, lldb::LanguageType language);
typedef SystemRuntime *(*SystemRuntimeCreateInstance) (Process *process);
- typedef Platform* (*PlatformCreateInstance) (bool force, const ArchSpec *arch);
+ typedef lldb::PlatformSP (*PlatformCreateInstance) (bool force, const ArchSpec *arch);
typedef lldb::ProcessSP (*ProcessCreateInstance) (Target &target, Listener &listener, const FileSpec *crash_file_path);
typedef SymbolFile* (*SymbolFileCreateInstance) (ObjectFile* obj_file);
typedef SymbolVendor* (*SymbolVendorCreateInstance) (const lldb::ModuleSP &module_sp, lldb_private::Stream *feedback_strm); // Module can be NULL for default system symbol vendor
diff --git a/lldb/source/API/SBDebugger.cpp b/lldb/source/API/SBDebugger.cpp
index dae567525a4..b53dec2a21d 100644
--- a/lldb/source/API/SBDebugger.cpp
+++ b/lldb/source/API/SBDebugger.cpp
@@ -1186,19 +1186,42 @@ SBDebugger::GetID()
SBError
-SBDebugger::SetCurrentPlatform (const char *platform_name)
+SBDebugger::SetCurrentPlatform (const char *platform_name_cstr)
{
SBError sb_error;
if (m_opaque_sp)
{
- PlatformSP platform_sp (Platform::Create (platform_name, sb_error.ref()));
-
- if (platform_sp)
+ if (platform_name_cstr && platform_name_cstr[0])
+ {
+ ConstString platform_name (platform_name_cstr);
+ PlatformSP platform_sp (Platform::Find (platform_name));
+
+ if (platform_sp)
+ {
+ // Already have a platform with this name, just select it
+ m_opaque_sp->GetPlatformList().SetSelectedPlatform(platform_sp);
+ }
+ else
+ {
+ // We don't have a platform by this name yet, create one
+ platform_sp = Platform::Create (platform_name, sb_error.ref());
+ if (platform_sp)
+ {
+ // We created the platform, now append and select it
+ bool make_selected = true;
+ m_opaque_sp->GetPlatformList().Append (platform_sp, make_selected);
+ }
+ }
+ }
+ else
{
- bool make_selected = true;
- m_opaque_sp->GetPlatformList().Append (platform_sp, make_selected);
+ sb_error.ref().SetErrorString("invalid platform name");
}
}
+ else
+ {
+ sb_error.ref().SetErrorString("invalid debugger");
+ }
return sb_error;
}
diff --git a/lldb/source/API/SBPlatform.cpp b/lldb/source/API/SBPlatform.cpp
index 9914852cead..d3e769ae675 100644
--- a/lldb/source/API/SBPlatform.cpp
+++ b/lldb/source/API/SBPlatform.cpp
@@ -269,7 +269,8 @@ SBPlatform::SBPlatform (const char *platform_name) :
m_opaque_sp ()
{
Error error;
- m_opaque_sp = Platform::Create (platform_name, error);
+ if (platform_name && platform_name[0])
+ m_opaque_sp = Platform::Create (ConstString(platform_name), error);
}
SBPlatform::~SBPlatform()
diff --git a/lldb/source/Commands/CommandObjectPlatform.cpp b/lldb/source/Commands/CommandObjectPlatform.cpp
index 9998dbdccda..45355a0dd2a 100644
--- a/lldb/source/Commands/CommandObjectPlatform.cpp
+++ b/lldb/source/Commands/CommandObjectPlatform.cpp
@@ -302,7 +302,7 @@ protected:
Stream &ostrm = result.GetOutputStream();
ostrm.Printf("Available platforms:\n");
- PlatformSP host_platform_sp (Platform::GetDefaultPlatform());
+ PlatformSP host_platform_sp (Platform::GetHostPlatform());
ostrm.Printf ("%s: %s\n",
host_platform_sp->GetPluginName().GetCString(),
host_platform_sp->GetDescription());
diff --git a/lldb/source/Core/Debugger.cpp b/lldb/source/Core/Debugger.cpp
index 3274b3c0023..69fae11dfbd 100644
--- a/lldb/source/Core/Debugger.cpp
+++ b/lldb/source/Core/Debugger.cpp
@@ -645,7 +645,7 @@ Debugger::Debugger(lldb::LogOutputCallback log_callback, void *baton) :
m_log_callback_stream_sp.reset (new StreamCallback (log_callback, baton));
m_command_interpreter_ap->Initialize ();
// Always add our default platform to the platform list
- PlatformSP default_platform_sp (Platform::GetDefaultPlatform());
+ PlatformSP default_platform_sp (Platform::GetHostPlatform());
assert (default_platform_sp.get());
m_platform_list.Append (default_platform_sp, true);
diff --git a/lldb/source/Host/common/Host.cpp b/lldb/source/Host/common/Host.cpp
index ce1af3288fc..828a5b7d34b 100644
--- a/lldb/source/Host/common/Host.cpp
+++ b/lldb/source/Host/common/Host.cpp
@@ -1039,7 +1039,7 @@ Host::LaunchProcess (ProcessLaunchInfo &launch_info)
Error error;
char exe_path[PATH_MAX];
- PlatformSP host_platform_sp (Platform::GetDefaultPlatform ());
+ PlatformSP host_platform_sp (Platform::GetHostPlatform ());
const ArchSpec &arch_spec = launch_info.GetArchitecture();
diff --git a/lldb/source/Host/macosx/Host.mm b/lldb/source/Host/macosx/Host.mm
index 37ff095817d..184c6f65b53 100644
--- a/lldb/source/Host/macosx/Host.mm
+++ b/lldb/source/Host/macosx/Host.mm
@@ -1305,7 +1305,7 @@ Host::LaunchProcess (ProcessLaunchInfo &launch_info)
{
Error error;
char exe_path[PATH_MAX];
- PlatformSP host_platform_sp (Platform::GetDefaultPlatform ());
+ PlatformSP host_platform_sp (Platform::GetHostPlatform ());
const ArchSpec &arch_spec = launch_info.GetArchitecture();
diff --git a/lldb/source/Interpreter/OptionGroupPlatform.cpp b/lldb/source/Interpreter/OptionGroupPlatform.cpp
index 9ffd5f072d9..7e5e1245a79 100644
--- a/lldb/source/Interpreter/OptionGroupPlatform.cpp
+++ b/lldb/source/Interpreter/OptionGroupPlatform.cpp
@@ -33,7 +33,7 @@ OptionGroupPlatform::CreatePlatformWithOptions (CommandInterpreter &interpreter,
if (!m_platform_name.empty())
{
- platform_sp = Platform::Create (m_platform_name.c_str(), error);
+ platform_sp = Platform::Create (ConstString(m_platform_name.c_str()), error);
if (platform_sp)
{
if (platform_arch.IsValid() && !platform_sp->IsCompatibleArchitecture(arch, false, &platform_arch))
diff --git a/lldb/source/Plugins/DynamicLoader/Darwin-Kernel/DynamicLoaderDarwinKernel.cpp b/lldb/source/Plugins/DynamicLoader/Darwin-Kernel/DynamicLoaderDarwinKernel.cpp
index fa518d30aec..5047b1f2cf0 100644
--- a/lldb/source/Plugins/DynamicLoader/Darwin-Kernel/DynamicLoaderDarwinKernel.cpp
+++ b/lldb/source/Plugins/DynamicLoader/Darwin-Kernel/DynamicLoaderDarwinKernel.cpp
@@ -467,7 +467,8 @@ DynamicLoaderDarwinKernel::DynamicLoaderDarwinKernel (Process* process, lldb::ad
m_mutex(Mutex::eMutexTypeRecursive),
m_break_id (LLDB_INVALID_BREAK_ID)
{
- PlatformSP platform_sp(Platform::FindPlugin (process, PlatformDarwinKernel::GetPluginNameStatic ()));
+ Error error;
+ PlatformSP platform_sp(Platform::Create(PlatformDarwinKernel::GetPluginNameStatic(), error));
// Only select the darwin-kernel Platform if we've been asked to load kexts.
// It can take some time to scan over all of the kext info.plists and that
// shouldn't be done if kext loading is explicitly disabled.
diff --git a/lldb/source/Plugins/Platform/FreeBSD/PlatformFreeBSD.cpp b/lldb/source/Plugins/Platform/FreeBSD/PlatformFreeBSD.cpp
index 7aa940a530b..cc086e3b120 100644
--- a/lldb/source/Plugins/Platform/FreeBSD/PlatformFreeBSD.cpp
+++ b/lldb/source/Plugins/Platform/FreeBSD/PlatformFreeBSD.cpp
@@ -32,7 +32,7 @@
using namespace lldb;
using namespace lldb_private;
-Platform *
+PlatformSP
PlatformFreeBSD::CreateInstance (bool force, const lldb_private::ArchSpec *arch)
{
// The only time we create an instance is when we are creating a remote
@@ -84,8 +84,8 @@ PlatformFreeBSD::CreateInstance (bool force, const lldb_private::ArchSpec *arch)
}
}
if (create)
- return new PlatformFreeBSD (is_host);
- return NULL;
+ return PlatformSP(new PlatformFreeBSD (is_host));
+ return PlatformSP();
}
@@ -124,7 +124,7 @@ PlatformFreeBSD::Initialize ()
// Force a host flag to true for the default platform object.
PlatformSP default_platform_sp (new PlatformFreeBSD(true));
default_platform_sp->SetSystemArchitecture(HostInfo::GetArchitecture());
- Platform::SetDefaultPlatform (default_platform_sp);
+ Platform::SetHostPlatform (default_platform_sp);
#endif
PluginManager::RegisterPlugin(PlatformFreeBSD::GetPluginNameStatic(false),
PlatformFreeBSD::GetDescriptionStatic(false),
@@ -404,7 +404,7 @@ PlatformFreeBSD::ConnectRemote (Args& args)
else
{
if (!m_remote_platform_sp)
- m_remote_platform_sp = Platform::Create ("remote-gdb-server", error);
+ m_remote_platform_sp = Platform::Create (ConstString("remote-gdb-server"), error);
if (m_remote_platform_sp)
{
diff --git a/lldb/source/Plugins/Platform/FreeBSD/PlatformFreeBSD.h b/lldb/source/Plugins/Platform/FreeBSD/PlatformFreeBSD.h
index 62958a08a9e..15591da889d 100644
--- a/lldb/source/Plugins/Platform/FreeBSD/PlatformFreeBSD.h
+++ b/lldb/source/Plugins/Platform/FreeBSD/PlatformFreeBSD.h
@@ -24,7 +24,7 @@ public:
//------------------------------------------------------------
// Class functions
//------------------------------------------------------------
- static lldb_private::Platform*
+ static lldb::PlatformSP
CreateInstance (bool force, const lldb_private::ArchSpec *arch);
static void
diff --git a/lldb/source/Plugins/Platform/Kalimba/PlatformKalimba.cpp b/lldb/source/Plugins/Platform/Kalimba/PlatformKalimba.cpp
index f1bfadd662a..068b1b10e72 100644
--- a/lldb/source/Plugins/Platform/Kalimba/PlatformKalimba.cpp
+++ b/lldb/source/Plugins/Platform/Kalimba/PlatformKalimba.cpp
@@ -32,7 +32,7 @@ using namespace lldb_private;
static uint32_t g_initialize_count = 0;
-Platform *
+PlatformSP
PlatformKalimba::CreateInstance (bool force, const ArchSpec *arch)
{
bool create = force;
@@ -50,8 +50,8 @@ PlatformKalimba::CreateInstance (bool force, const ArchSpec *arch)
}
}
if (create)
- return new PlatformKalimba(false);
- return NULL;
+ return PlatformSP(new PlatformKalimba(false));
+ return PlatformSP();
}
lldb_private::ConstString
diff --git a/lldb/source/Plugins/Platform/Kalimba/PlatformKalimba.h b/lldb/source/Plugins/Platform/Kalimba/PlatformKalimba.h
index b3e7d31cf42..6653ce1f054 100644
--- a/lldb/source/Plugins/Platform/Kalimba/PlatformKalimba.h
+++ b/lldb/source/Plugins/Platform/Kalimba/PlatformKalimba.h
@@ -36,7 +36,7 @@ namespace lldb_private {
//------------------------------------------------------------
// lldb_private::PluginInterface functions
//------------------------------------------------------------
- static Platform *
+ static lldb::PlatformSP
CreateInstance (bool force, const lldb_private::ArchSpec *arch);
static lldb_private::ConstString
diff --git a/lldb/source/Plugins/Platform/Linux/PlatformLinux.cpp b/lldb/source/Plugins/Platform/Linux/PlatformLinux.cpp
index 1d15d5cd01b..3b0aa5a4f80 100644
--- a/lldb/source/Plugins/Platform/Linux/PlatformLinux.cpp
+++ b/lldb/source/Plugins/Platform/Linux/PlatformLinux.cpp
@@ -118,7 +118,7 @@ PlatformLinux::DebuggerInitialize (lldb_private::Debugger &debugger)
//------------------------------------------------------------------
-Platform *
+PlatformSP
PlatformLinux::CreateInstance (bool force, const ArchSpec *arch)
{
Log *log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_PLATFORM));
@@ -183,13 +183,13 @@ PlatformLinux::CreateInstance (bool force, const ArchSpec *arch)
{
if (log)
log->Printf ("PlatformLinux::%s() creating remote-linux platform", __FUNCTION__);
- return new PlatformLinux(false);
+ return PlatformSP(new PlatformLinux(false));
}
if (log)
log->Printf ("PlatformLinux::%s() aborting creation of remote-linux platform", __FUNCTION__);
- return NULL;
+ return PlatformSP();
}
@@ -231,7 +231,7 @@ PlatformLinux::Initialize ()
#if defined(__linux__)
PlatformSP default_platform_sp (new PlatformLinux(true));
default_platform_sp->SetSystemArchitecture(HostInfo::GetArchitecture());
- Platform::SetDefaultPlatform (default_platform_sp);
+ Platform::SetHostPlatform (default_platform_sp);
#endif
PluginManager::RegisterPlugin(PlatformLinux::GetPluginNameStatic(false),
PlatformLinux::GetPluginDescriptionStatic(false),
diff --git a/lldb/source/Plugins/Platform/Linux/PlatformLinux.h b/lldb/source/Plugins/Platform/Linux/PlatformLinux.h
index bdfb66dea58..7c83d409e12 100644
--- a/lldb/source/Plugins/Platform/Linux/PlatformLinux.h
+++ b/lldb/source/Plugins/Platform/Linux/PlatformLinux.h
@@ -39,7 +39,7 @@ namespace lldb_private {
//------------------------------------------------------------
// lldb_private::PluginInterface functions
//------------------------------------------------------------
- static Platform *
+ static lldb::PlatformSP
CreateInstance (bool force, const lldb_private::ArchSpec *arch);
static lldb_private::ConstString
diff --git a/lldb/source/Plugins/Platform/MacOSX/PlatformDarwinKernel.cpp b/lldb/source/Plugins/Platform/MacOSX/PlatformDarwinKernel.cpp
index 4ed96c6dbc6..dc2217b3392 100644
--- a/lldb/source/Plugins/Platform/MacOSX/PlatformDarwinKernel.cpp
+++ b/lldb/source/Plugins/Platform/MacOSX/PlatformDarwinKernel.cpp
@@ -72,14 +72,14 @@ PlatformDarwinKernel::Terminate ()
}
}
-Platform*
+PlatformSP
PlatformDarwinKernel::CreateInstance (bool force, const ArchSpec *arch)
{
// This is a special plugin that we don't want to activate just based on an ArchSpec for normal
// userlnad debugging. It is only useful in kernel debug sessions and the DynamicLoaderDarwinPlugin
// (or a user doing 'platform select') will force the creation of this Platform plugin.
if (force == false)
- return NULL;
+ return PlatformSP();
bool create = force;
LazyBool is_ios_debug_session = eLazyBoolCalculate;
@@ -143,8 +143,8 @@ PlatformDarwinKernel::CreateInstance (bool force, const ArchSpec *arch)
}
}
if (create)
- return new PlatformDarwinKernel (is_ios_debug_session);
- return NULL;
+ return PlatformSP(new PlatformDarwinKernel (is_ios_debug_session));
+ return PlatformSP();
}
diff --git a/lldb/source/Plugins/Platform/MacOSX/PlatformDarwinKernel.h b/lldb/source/Plugins/Platform/MacOSX/PlatformDarwinKernel.h
index 6e45e100e5d..3a901d69331 100644
--- a/lldb/source/Plugins/Platform/MacOSX/PlatformDarwinKernel.h
+++ b/lldb/source/Plugins/Platform/MacOSX/PlatformDarwinKernel.h
@@ -30,7 +30,7 @@ public:
//------------------------------------------------------------
// Class Functions
//------------------------------------------------------------
- static lldb_private::Platform*
+ static lldb::PlatformSP
CreateInstance (bool force, const lldb_private::ArchSpec *arch);
static void
diff --git a/lldb/source/Plugins/Platform/MacOSX/PlatformMacOSX.cpp b/lldb/source/Plugins/Platform/MacOSX/PlatformMacOSX.cpp
index 50094f7f504..55a30bcc50c 100644
--- a/lldb/source/Plugins/Platform/MacOSX/PlatformMacOSX.cpp
+++ b/lldb/source/Plugins/Platform/MacOSX/PlatformMacOSX.cpp
@@ -45,7 +45,7 @@ PlatformMacOSX::Initialize ()
#if defined (__APPLE__)
PlatformSP default_platform_sp (new PlatformMacOSX(true));
default_platform_sp->SetSystemArchitecture(HostInfo::GetArchitecture());
- Platform::SetDefaultPlatform (default_platform_sp);
+ Platform::SetHostPlatform (default_platform_sp);
#endif
PluginManager::RegisterPlugin (PlatformMacOSX::GetPluginNameStatic(false),
PlatformMacOSX::GetDescriptionStatic(false),
@@ -66,7 +66,7 @@ PlatformMacOSX::Terminate ()
}
}
-Platform*
+PlatformSP
PlatformMacOSX::CreateInstance (bool force, const ArchSpec *arch)
{
// The only time we create an instance is when we are creating a remote
@@ -117,8 +117,8 @@ PlatformMacOSX::CreateInstance (bool force, const ArchSpec *arch)
}
}
if (create)
- return new PlatformMacOSX (is_host);
- return NULL;
+ return PlatformSP(new PlatformMacOSX (is_host));
+ return PlatformSP();
}
lldb_private::ConstString
diff --git a/lldb/source/Plugins/Platform/MacOSX/PlatformMacOSX.h b/lldb/source/Plugins/Platform/MacOSX/PlatformMacOSX.h
index 57e57e7b38e..3f5cef93a82 100644
--- a/lldb/source/Plugins/Platform/MacOSX/PlatformMacOSX.h
+++ b/lldb/source/Plugins/Platform/MacOSX/PlatformMacOSX.h
@@ -23,7 +23,7 @@ public:
//------------------------------------------------------------
// Class functions
//------------------------------------------------------------
- static lldb_private::Platform*
+ static lldb::PlatformSP
CreateInstance (bool force, const lldb_private::ArchSpec *arch);
static void
diff --git a/lldb/source/Plugins/Platform/MacOSX/PlatformRemoteiOS.cpp b/lldb/source/Plugins/Platform/MacOSX/PlatformRemoteiOS.cpp
index dd6d93815e5..8058efc9971 100644
--- a/lldb/source/Plugins/Platform/MacOSX/PlatformRemoteiOS.cpp
+++ b/lldb/source/Plugins/Platform/MacOSX/PlatformRemoteiOS.cpp
@@ -83,7 +83,7 @@ PlatformRemoteiOS::Terminate ()
}
}
-Platform*
+PlatformSP
PlatformRemoteiOS::CreateInstance (bool force, const ArchSpec *arch)
{
bool create = force;
@@ -144,8 +144,8 @@ PlatformRemoteiOS::CreateInstance (bool force, const ArchSpec *arch)
}
if (create)
- return new PlatformRemoteiOS ();
- return NULL;
+ return lldb::PlatformSP(new PlatformRemoteiOS ());
+ return lldb::PlatformSP();
}
diff --git a/lldb/source/Plugins/Platform/MacOSX/PlatformRemoteiOS.h b/lldb/source/Plugins/Platform/MacOSX/PlatformRemoteiOS.h
index 7eb2660dc6f..47ea6a6cc91 100644
--- a/lldb/source/Plugins/Platform/MacOSX/PlatformRemoteiOS.h
+++ b/lldb/source/Plugins/Platform/MacOSX/PlatformRemoteiOS.h
@@ -25,7 +25,7 @@ public:
//------------------------------------------------------------
// Class Functions
//------------------------------------------------------------
- static lldb_private::Platform*
+ static lldb::PlatformSP
CreateInstance (bool force, const lldb_private::ArchSpec *arch);
static void
diff --git a/lldb/source/Plugins/Platform/MacOSX/PlatformiOSSimulator.cpp b/lldb/source/Plugins/Platform/MacOSX/PlatformiOSSimulator.cpp
index 0d4523e46b0..caa4a303903 100644
--- a/lldb/source/Plugins/Platform/MacOSX/PlatformiOSSimulator.cpp
+++ b/lldb/source/Plugins/Platform/MacOSX/PlatformiOSSimulator.cpp
@@ -61,7 +61,7 @@ PlatformiOSSimulator::Terminate ()
}
}
-Platform*
+PlatformSP
PlatformiOSSimulator::CreateInstance (bool force, const ArchSpec *arch)
{
bool create = force;
@@ -120,8 +120,8 @@ PlatformiOSSimulator::CreateInstance (bool force, const ArchSpec *arch)
}
}
if (create)
- return new PlatformiOSSimulator ();
- return NULL;
+ return PlatformSP(new PlatformiOSSimulator ());
+ return PlatformSP();
}
diff --git a/lldb/source/Plugins/Platform/MacOSX/PlatformiOSSimulator.h b/lldb/source/Plugins/Platform/MacOSX/PlatformiOSSimulator.h
index 81394a44e02..37869754751 100644
--- a/lldb/source/Plugins/Platform/MacOSX/PlatformiOSSimulator.h
+++ b/lldb/source/Plugins/Platform/MacOSX/PlatformiOSSimulator.h
@@ -23,7 +23,7 @@ public:
//------------------------------------------------------------
// Class Functions
//------------------------------------------------------------
- static lldb_private::Platform*
+ static lldb::PlatformSP
CreateInstance (bool force, const lldb_private::ArchSpec *arch);
static void
diff --git a/lldb/source/Plugins/Platform/POSIX/PlatformPOSIX.cpp b/lldb/source/Plugins/Platform/POSIX/PlatformPOSIX.cpp
index 05e673f3296..0b06a6efd11 100644
--- a/lldb/source/Plugins/Platform/POSIX/PlatformPOSIX.cpp
+++ b/lldb/source/Plugins/Platform/POSIX/PlatformPOSIX.cpp
@@ -699,7 +699,7 @@ PlatformPOSIX::ConnectRemote (Args& args)
else
{
if (!m_remote_platform_sp)
- m_remote_platform_sp = Platform::Create ("remote-gdb-server", error);
+ m_remote_platform_sp = Platform::Create (ConstString("remote-gdb-server"), error);
if (m_remote_platform_sp && error.Success())
error = m_remote_platform_sp->ConnectRemote (args);
diff --git a/lldb/source/Plugins/Platform/Windows/PlatformWindows.cpp b/lldb/source/Plugins/Platform/Windows/PlatformWindows.cpp
index 82015e4613a..c6e79e4e190 100644
--- a/lldb/source/Plugins/Platform/Windows/PlatformWindows.cpp
+++ b/lldb/source/Plugins/Platform/Windows/PlatformWindows.cpp
@@ -66,7 +66,7 @@ namespace
};
}
-Platform *
+PlatformSP
PlatformWindows::CreateInstance (bool force, const lldb_private::ArchSpec *arch)
{
// The only time we create an instance is when we are creating a remote
@@ -109,8 +109,8 @@ PlatformWindows::CreateInstance (bool force, const lldb_private::ArchSpec *arch)
}
}
if (create)
- return new PlatformWindows (is_host);
- return NULL;
+ return PlatformSP(new PlatformWindows (is_host));
+ return PlatformSP();
}
@@ -154,7 +154,7 @@ PlatformWindows::Initialize(void)
// Force a host flag to true for the default platform object.
PlatformSP default_platform_sp (new PlatformWindows(true));
default_platform_sp->SetSystemArchitecture(HostInfo::GetArchitecture());
- Platform::SetDefaultPlatform (default_platform_sp);
+ Platform::SetHostPlatform (default_platform_sp);
#endif
PluginManager::RegisterPlugin(PlatformWindows::GetPluginNameStatic(false),
PlatformWindows::GetPluginDescriptionStatic(false),
@@ -417,7 +417,7 @@ PlatformWindows::ConnectRemote (Args& args)
else
{
if (!m_remote_platform_sp)
- m_remote_platform_sp = Platform::Create ("remote-gdb-server", error);
+ m_remote_platform_sp = Platform::Create (ConstString("remote-gdb-server"), error);
if (m_remote_platform_sp)
{
diff --git a/lldb/source/Plugins/Platform/Windows/PlatformWindows.h b/lldb/source/Plugins/Platform/Windows/PlatformWindows.h
index 062d5cdb949..a7d470cadf5 100644
--- a/lldb/source/Plugins/Platform/Windows/PlatformWindows.h
+++ b/lldb/source/Plugins/Platform/Windows/PlatformWindows.h
@@ -37,7 +37,7 @@ public:
//------------------------------------------------------------
// lldb_private::PluginInterface functions
//------------------------------------------------------------
- static lldb_private::Platform*
+ static lldb::PlatformSP
CreateInstance (bool force, const lldb_private::ArchSpec *arch);
diff --git a/lldb/source/Plugins/Platform/gdb-server/PlatformRemoteGDBServer.cpp b/lldb/source/Plugins/Platform/gdb-server/PlatformRemoteGDBServer.cpp
index af8fd9ed4cb..a2f6f43c586 100644
--- a/lldb/source/Plugins/Platform/gdb-server/PlatformRemoteGDBServer.cpp
+++ b/lldb/source/Plugins/Platform/gdb-server/PlatformRemoteGDBServer.cpp
@@ -56,7 +56,7 @@ PlatformRemoteGDBServer::Terminate ()
}
}
-Platform*
+PlatformSP
PlatformRemoteGDBServer::CreateInstance (bool force, const lldb_private::ArchSpec *arch)
{
bool create = force;
@@ -65,8 +65,8 @@ PlatformRemoteGDBServer::CreateInstance (bool force, const lldb_private::ArchSpe
create = !arch->TripleVendorWasSpecified() && !arch->TripleOSWasSpecified();
}
if (create)
- return new PlatformRemoteGDBServer ();
- return NULL;
+ return PlatformSP(new PlatformRemoteGDBServer());
+ return PlatformSP();
}
diff --git a/lldb/source/Plugins/Platform/gdb-server/PlatformRemoteGDBServer.h b/lldb/source/Plugins/Platform/gdb-server/PlatformRemoteGDBServer.h
index e236e97c8bb..6f358889907 100644
--- a/lldb/source/Plugins/Platform/gdb-server/PlatformRemoteGDBServer.h
+++ b/lldb/source/Plugins/Platform/gdb-server/PlatformRemoteGDBServer.h
@@ -29,7 +29,7 @@ public:
static void
Terminate ();
- static lldb_private::Platform*
+ static lldb::PlatformSP
CreateInstance (bool force, const lldb_private::ArchSpec *arch);
static lldb_private::ConstString
diff --git a/lldb/source/Plugins/Process/Linux/NativeProcessLinux.cpp b/lldb/source/Plugins/Process/Linux/NativeProcessLinux.cpp
index f77b73e5670..6a397361d2a 100644
--- a/lldb/source/Plugins/Process/Linux/NativeProcessLinux.cpp
+++ b/lldb/source/Plugins/Process/Linux/NativeProcessLinux.cpp
@@ -1278,7 +1278,7 @@ NativeProcessLinux::AttachToProcess (
// Grab the current platform architecture. This should be Linux,
// since this code is only intended to run on a Linux host.
- PlatformSP platform_sp (Platform::GetDefaultPlatform ());
+ PlatformSP platform_sp (Platform::GetHostPlatform ());
if (!platform_sp)
return Error("failed to get a valid default platform");
@@ -1412,7 +1412,7 @@ NativeProcessLinux::AttachToInferior (lldb::pid_t pid, lldb_private::Error &erro
log->Printf ("NativeProcessLinux::%s (pid = %" PRIi64 ")", __FUNCTION__, pid);
// We can use the Host for everything except the ResolveExecutable portion.
- PlatformSP platform_sp = Platform::GetDefaultPlatform ();
+ PlatformSP platform_sp = Platform::GetHostPlatform ();
if (!platform_sp)
{
if (log)
diff --git a/lldb/source/Plugins/Process/gdb-remote/GDBRemoteCommunicationServer.cpp b/lldb/source/Plugins/Process/gdb-remote/GDBRemoteCommunicationServer.cpp
index b20a8aba87a..7217cd5f897 100644
--- a/lldb/source/Plugins/Process/gdb-remote/GDBRemoteCommunicationServer.cpp
+++ b/lldb/source/Plugins/Process/gdb-remote/GDBRemoteCommunicationServer.cpp
@@ -71,7 +71,7 @@ namespace
//----------------------------------------------------------------------
GDBRemoteCommunicationServer::GDBRemoteCommunicationServer(bool is_platform) :
GDBRemoteCommunication ("gdb-remote.server", "gdb-remote.server.rx_packet", is_platform),
- m_platform_sp (Platform::GetDefaultPlatform ()),
+ m_platform_sp (Platform::GetHostPlatform ()),
m_async_thread (LLDB_INVALID_HOST_THREAD),
m_process_launch_info (),
m_process_launch_error (),
diff --git a/lldb/source/Target/Platform.cpp b/lldb/source/Target/Platform.cpp
index 96feb4ba004..4f449c5fd00 100644
--- a/lldb/source/Target/Platform.cpp
+++ b/lldb/source/Target/Platform.cpp
@@ -32,26 +32,12 @@ using namespace lldb_private;
// Use a singleton function for g_local_platform_sp to avoid init
// constructors since LLDB is often part of a shared library
static PlatformSP&
-GetDefaultPlatformSP ()
+GetHostPlatformSP ()
{
- static PlatformSP g_default_platform_sp;
- return g_default_platform_sp;
+ static PlatformSP g_platform_sp;
+ return g_platform_sp;
}
-static Mutex &
-GetConnectedPlatformListMutex ()
-{
- static Mutex g_remote_connected_platforms_mutex (Mutex::eMutexTypeRecursive);
- return g_remote_connected_platforms_mutex;
-}
-static std::vector<PlatformSP> &
-GetConnectedPlatformList ()
-{
- static std::vector<PlatformSP> g_remote_connected_platforms;
- return g_remote_connected_platforms;
-}
-
-
const char *
Platform::GetHostPlatformName ()
{
@@ -69,17 +55,37 @@ Platform::GetHostPlatformName ()
/// or attaching to processes unless another platform is specified.
//------------------------------------------------------------------
PlatformSP
-Platform::GetDefaultPlatform ()
+Platform::GetHostPlatform ()
{
- return GetDefaultPlatformSP ();
+ return GetHostPlatformSP ();
+}
+
+static std::vector<PlatformSP> &
+GetPlatformList()
+{
+ static std::vector<PlatformSP> g_platform_list;
+ return g_platform_list;
+}
+
+static Mutex &
+GetPlatformListMutex ()
+{
+ static Mutex g_mutex(Mutex::eMutexTypeRecursive);
+ return g_mutex;
}
void
-Platform::SetDefaultPlatform (const lldb::PlatformSP &platform_sp)
+Platform::SetHostPlatform (const lldb::PlatformSP &platform_sp)
{
// The native platform should use its static void Platform::Initialize()
// function to register itself as the native platform.
- GetDefaultPlatformSP () = platform_sp;
+ GetHostPlatformSP () = platform_sp;
+
+ if (platform_sp)
+ {
+ Mutex::Locker locker(GetPlatformListMutex ());
+ GetPlatformList().push_back(platform_sp);
+ }
}
Error
@@ -98,36 +104,36 @@ Platform::LocateExecutableScriptingResources (Target *target, Module &module, St
return FileSpecList();
}
-Platform*
-Platform::FindPlugin (Process *process, const ConstString &plugin_name)
-{
- PlatformCreateInstance create_callback = NULL;
- if (plugin_name)
- {
- create_callback = PluginManager::GetPlatformCreateCallbackForPluginName (plugin_name);
- if (create_callback)
- {
- ArchSpec arch;
- if (process)
- {
- arch = process->GetTarget().GetArchitecture();
- }
- std::unique_ptr<Platform> instance_ap(create_callback(process, &arch));
- if (instance_ap.get())
- return instance_ap.release();
- }
- }
- else
- {
- for (uint32_t idx = 0; (create_callback = PluginManager::GetPlatformCreateCallbackAtIndex(idx)) != NULL; ++idx)
- {
- std::unique_ptr<Platform> instance_ap(create_callback(process, nullptr));
- if (instance_ap.get())
- return instance_ap.release();
- }
- }
- return NULL;
-}
+//PlatformSP
+//Platform::FindPlugin (Process *process, const ConstString &plugin_name)
+//{
+// PlatformCreateInstance create_callback = NULL;
+// if (plugin_name)
+// {
+// create_callback = PluginManager::GetPlatformCreateCallbackForPluginName (plugin_name);
+// if (create_callback)
+// {
+// ArchSpec arch;
+// if (process)
+// {
+// arch = process->GetTarget().GetArchitecture();
+// }
+// PlatformSP platform_sp(create_callback(process, &arch));
+// if (platform_sp)
+// return platform_sp;
+// }
+// }
+// else
+// {
+// for (uint32_t idx = 0; (create_callback = PluginManager::GetPlatformCreateCallbackAtIndex(idx)) != NULL; ++idx)
+// {
+// PlatformSP platform_sp(create_callback(process, nullptr));
+// if (platform_sp)
+// return platform_sp;
+// }
+// }
+// return PlatformSP();
+//}
Error
Platform::GetSharedModule (const ModuleSpec &module_spec,
@@ -153,21 +159,50 @@ Platform::GetSharedModule (const ModuleSpec &module_spec,
}
PlatformSP
-Platform::Create (const char *platform_name, Error &error)
+Platform::Find (const ConstString &name)
+{
+ if (name)
+ {
+ static ConstString g_host_platform_name ("host");
+ if (name == g_host_platform_name)
+ return GetHostPlatform();
+
+ Mutex::Locker locker(GetPlatformListMutex ());
+ for (const auto &platform_sp : GetPlatformList())
+ {
+ if (platform_sp->GetName() == name)
+ return platform_sp;
+ }
+ }
+ return PlatformSP();
+}
+
+PlatformSP
+Platform::Create (const ConstString &name, Error &error)
{
PlatformCreateInstance create_callback = NULL;
lldb::PlatformSP platform_sp;
- if (platform_name && platform_name[0])
+ if (name)
{
- ConstString const_platform_name (platform_name);
- create_callback = PluginManager::GetPlatformCreateCallbackForPluginName (const_platform_name);
+ static ConstString g_host_platform_name ("host");
+ if (name == g_host_platform_name)
+ return GetHostPlatform();
+
+ create_callback = PluginManager::GetPlatformCreateCallbackForPluginName (name);
if (create_callback)
- platform_sp.reset(create_callback(true, NULL));
+ platform_sp = create_callback(true, NULL);
else
- error.SetErrorStringWithFormat ("unable to find a plug-in for the platform named \"%s\"", platform_name);
+ error.SetErrorStringWithFormat ("unable to find a plug-in for the platform named \"%s\"", name.GetCString());
}
else
error.SetErrorString ("invalid platform name");
+
+ if (platform_sp)
+ {
+ Mutex::Locker locker(GetPlatformListMutex ());
+ GetPlatformList().push_back(platform_sp);
+ }
+
return platform_sp;
}
@@ -178,28 +213,52 @@ Platform::Create (const ArchSpec &arch, ArchSpec *platform_arch_ptr, Error &erro
lldb::PlatformSP platform_sp;
if (arch.IsValid())
{
- uint32_t idx;
+ // Scope for locker
+ {
+ // First try exact arch matches across all platforms already created
+ Mutex::Locker locker(GetPlatformListMutex ());
+ for (const auto &platform_sp : GetPlatformList())
+ {
+ if (platform_sp->IsCompatibleArchitecture(arch, true, platform_arch_ptr))
+ return platform_sp;
+ }
+
+ // Next try compatible arch matches across all platforms already created
+ for (const auto &platform_sp : GetPlatformList())
+ {
+ if (platform_sp->IsCompatibleArchitecture(arch, false, platform_arch_ptr))
+ return platform_sp;
+ }
+ }
+
PlatformCreateInstance create_callback;
// First try exact arch matches across all platform plug-ins
- bool exact = true;
+ uint32_t idx;
for (idx = 0; (create_callback = PluginManager::GetPlatformCreateCallbackAtIndex (idx)); ++idx)
{
if (create_callback)
{
- platform_sp.reset(create_callback(false, &arch));
- if (platform_sp && platform_sp->IsCompatibleArchitecture(arch, exact, platform_arch_ptr))
+ platform_sp = create_callback(false, &arch);
+ if (platform_sp && platform_sp->IsCompatibleArchitecture(arch, true, platform_arch_ptr))
+ {
+ Mutex::Locker locker(GetPlatformListMutex ());
+ GetPlatformList().push_back(platform_sp);
return platform_sp;
+ }
}
}
// Next try compatible arch matches across all platform plug-ins
- exact = false;
for (idx = 0; (create_callback = PluginManager::GetPlatformCreateCallbackAtIndex (idx)); ++idx)
{
if (create_callback)
{
- platform_sp.reset(create_callback(false, &arch));
- if (platform_sp && platform_sp->IsCompatibleArchitecture(arch, exact, platform_arch_ptr))
+ platform_sp = create_callback(false, &arch);
+ if (platform_sp && platform_sp->IsCompatibleArchitecture(arch, false, platform_arch_ptr))
+ {
+ Mutex::Locker locker(GetPlatformListMutex ());
+ GetPlatformList().push_back(platform_sp);
return platform_sp;
+ }
}
}
}
@@ -211,25 +270,6 @@ Platform::Create (const ArchSpec &arch, ArchSpec *platform_arch_ptr, Error &erro
return platform_sp;
}
-uint32_t
-Platform::GetNumConnectedRemotePlatforms ()
-{
- Mutex::Locker locker (GetConnectedPlatformListMutex ());
- return GetConnectedPlatformList().size();
-}
-
-PlatformSP
-Platform::GetConnectedRemotePlatformAtIndex (uint32_t idx)
-{
- PlatformSP platform_sp;
- {
- Mutex::Locker locker (GetConnectedPlatformListMutex ());
- if (idx < GetConnectedPlatformList().size())
- platform_sp = GetConnectedPlatformList ()[idx];
- }
- return platform_sp;
-}
-
//------------------------------------------------------------------
/// Default Constructor
//------------------------------------------------------------------
diff --git a/lldb/source/Target/TargetList.cpp b/lldb/source/Target/TargetList.cpp
index 7cf31dc4d5d..5ba38560339 100644
--- a/lldb/source/Target/TargetList.cpp
+++ b/lldb/source/Target/TargetList.cpp
@@ -170,7 +170,7 @@ TargetList::CreateTarget (Debugger &debugger,
typedef std::vector<PlatformSP> PlatformList;
PlatformList platforms;
- PlatformSP host_platform_sp = Platform::GetDefaultPlatform();
+ PlatformSP host_platform_sp = Platform::GetHostPlatform();
for (size_t i=0; i<num_specs; ++i)
{
ModuleSpec module_spec;
diff --git a/lldb/test/functionalities/object-file/TestImageListMultiArchitecture.py b/lldb/test/functionalities/object-file/TestImageListMultiArchitecture.py
index b9bd95c0569..4a783e7530e 100644
--- a/lldb/test/functionalities/object-file/TestImageListMultiArchitecture.py
+++ b/lldb/test/functionalities/object-file/TestImageListMultiArchitecture.py
@@ -36,6 +36,8 @@ class TestImageListMultiArchitecture(TestBase):
self.runCmd("file {}".format(file_name))
self.match("image list -t -A", [expected_triple_and_arch_regex])
+ # Revert to the host platform after all of this is done
+ self.runCmd("platform select host")
if __name__ == '__main__':
import atexit
diff --git a/lldb/tools/lldb-gdbserver/lldb-gdbserver.cpp b/lldb/tools/lldb-gdbserver/lldb-gdbserver.cpp
index 2a301e5e653..368f8625fb2 100644
--- a/lldb/tools/lldb-gdbserver/lldb-gdbserver.cpp
+++ b/lldb/tools/lldb-gdbserver/lldb-gdbserver.cpp
@@ -142,12 +142,12 @@ dump_available_platforms (FILE *output_file)
fprintf (output_file, "%s\t%s\n", plugin_name, plugin_desc);
}
- if ( Platform::GetDefaultPlatform () )
+ if ( Platform::GetHostPlatform () )
{
// add this since the default platform doesn't necessarily get registered by
// the plugin name (e.g. 'host' doesn't show up as a
// registered platform plugin even though it's the default).
- fprintf (output_file, "%s\tDefault platform for this host.\n", Platform::GetDefaultPlatform ()->GetPluginName ().AsCString ());
+ fprintf (output_file, "%s\tDefault platform for this host.\n", Platform::GetHostPlatform ()->GetPluginName ().AsCString ());
}
}
@@ -174,7 +174,7 @@ setup_platform (const std::string platform_name)
if (platform_name.empty())
{
printf ("using the default platform: ");
- platform_sp = Platform::GetDefaultPlatform ();
+ platform_sp = Platform::GetHostPlatform ();
printf ("%s\n", platform_sp->GetPluginName ().AsCString ());
return platform_sp;
}
@@ -186,9 +186,9 @@ setup_platform (const std::string platform_name)
// the host platform isn't registered with that name (at
// least, not always. Check if the given name matches
// the default platform name. If so, use it.
- if ( Platform::GetDefaultPlatform () && ( Platform::GetDefaultPlatform ()->GetPluginName () == ConstString (platform_name.c_str()) ) )
+ if ( Platform::GetHostPlatform () && ( Platform::GetHostPlatform ()->GetPluginName () == ConstString (platform_name.c_str()) ) )
{
- platform_sp = Platform::GetDefaultPlatform ();
+ platform_sp = Platform::GetHostPlatform ();
}
else
{
OpenPOWER on IntegriCloud