diff options
Diffstat (limited to 'source/Target/Platform.cpp')
-rw-r--r-- | source/Target/Platform.cpp | 281 |
1 files changed, 187 insertions, 94 deletions
diff --git a/source/Target/Platform.cpp b/source/Target/Platform.cpp index fe73be2d05b9..4ebd18b8bfd0 100644 --- a/source/Target/Platform.cpp +++ b/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 //------------------------------------------------------------------ @@ -422,6 +462,20 @@ Platform::GetOSKernelDescription (std::string &s) return GetRemoteOSKernelDescription (s); } +void +Platform::AddClangModuleCompilationOptions (std::vector<std::string> &options) +{ + std::vector<std::string> default_compilation_options = + { + "-x", "c++", "-Xclang", "-nostdsysteminc", "-Xclang", "-nostdsysteminc" + }; + + options.insert(options.end(), + default_compilation_options.begin(), + default_compilation_options.end()); +} + + ConstString Platform::GetWorkingDirectory () { @@ -537,11 +591,11 @@ RecurseCopy_Callback (void *baton, case FileSpec::eFileTypeInvalid: case FileSpec::eFileTypeOther: case FileSpec::eFileTypeUnknown: - default: rc_baton->error.SetErrorStringWithFormat("invalid file detected during copy: %s", src.GetPath().c_str()); return FileSpec::eEnumerateDirectoryResultQuit; // got an error, bail out break; } + llvm_unreachable("Unhandled FileSpec::FileType!"); } Error @@ -842,15 +896,13 @@ Platform::SetOSVersion (uint32_t major, Error -Platform::ResolveExecutable (const FileSpec &exe_file, - const ArchSpec &exe_arch, +Platform::ResolveExecutable (const ModuleSpec &module_spec, lldb::ModuleSP &exe_module_sp, const FileSpecList *module_search_paths_ptr) { Error error; - if (exe_file.Exists()) + if (module_spec.GetFileSpec().Exists()) { - ModuleSpec module_spec (exe_file, exe_arch); if (module_spec.GetArchitecture().IsValid()) { error = ModuleList::GetSharedModule (module_spec, @@ -864,9 +916,10 @@ Platform::ResolveExecutable (const FileSpec &exe_file, // No valid architecture was specified, ask the platform for // the architectures that we should be using (in the correct order) // and see if we can find a match that way - for (uint32_t idx = 0; GetSupportedArchitectureAtIndex (idx, module_spec.GetArchitecture()); ++idx) + ModuleSpec arch_module_spec(module_spec); + for (uint32_t idx = 0; GetSupportedArchitectureAtIndex (idx, arch_module_spec.GetArchitecture()); ++idx) { - error = ModuleList::GetSharedModule (module_spec, + error = ModuleList::GetSharedModule (arch_module_spec, exe_module_sp, module_search_paths_ptr, NULL, @@ -880,7 +933,7 @@ Platform::ResolveExecutable (const FileSpec &exe_file, else { error.SetErrorStringWithFormat ("'%s' does not exist", - exe_file.GetPath().c_str()); + module_spec.GetFileSpec().GetPath().c_str()); } return error; } @@ -1005,7 +1058,11 @@ Error Platform::LaunchProcess (ProcessLaunchInfo &launch_info) { Error error; - // Take care of the host case so that each subclass can just + Log *log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_PLATFORM)); + if (log) + log->Printf ("Platform::%s()", __FUNCTION__); + + // Take care of the host case so that each subclass can just // call this function to get the host functionality. if (IsHost()) { @@ -1018,6 +1075,16 @@ Platform::LaunchProcess (ProcessLaunchInfo &launch_info) const bool will_debug = launch_info.GetFlags().Test(eLaunchFlagDebug); const bool first_arg_is_full_shell_command = false; uint32_t num_resumes = GetResumeCountForLaunchInfo (launch_info); + if (log) + { + const FileSpec &shell = launch_info.GetShell(); + const char *shell_str = (shell) ? shell.GetPath().c_str() : "<null>"; + log->Printf ("Platform::%s GetResumeCountForLaunchInfo() returned %" PRIu32 ", shell is '%s'", + __FUNCTION__, + num_resumes, + shell_str); + } + if (!launch_info.ConvertArgumentsForLaunchingInShell (error, is_localhost, will_debug, @@ -1026,6 +1093,9 @@ Platform::LaunchProcess (ProcessLaunchInfo &launch_info) return error; } + if (log) + log->Printf ("Platform::%s final launch_info resume count: %" PRIu32, __FUNCTION__, launch_info.GetResumeCount ()); + error = Host::LaunchProcess (launch_info); } else @@ -1037,9 +1107,12 @@ lldb::ProcessSP Platform::DebugProcess (ProcessLaunchInfo &launch_info, Debugger &debugger, Target *target, // Can be NULL, if NULL create a new target, else use existing one - Listener &listener, Error &error) { + Log *log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_PLATFORM)); + if (log) + log->Printf ("Platform::%s entered (target %p)", __FUNCTION__, static_cast<void*>(target)); + ProcessSP process_sp; // Make sure we stop at the entry point launch_info.GetFlags ().Set (eLaunchFlagDebug); @@ -1051,12 +1124,16 @@ Platform::DebugProcess (ProcessLaunchInfo &launch_info, error = LaunchProcess (launch_info); if (error.Success()) { + if (log) + log->Printf ("Platform::%s LaunchProcess() call succeeded (pid=%" PRIu64 ")", __FUNCTION__, launch_info.GetProcessID ()); if (launch_info.GetProcessID() != LLDB_INVALID_PROCESS_ID) { ProcessAttachInfo attach_info (launch_info); - process_sp = Attach (attach_info, debugger, target, listener, error); + process_sp = Attach (attach_info, debugger, target, error); if (process_sp) { + if (log) + log->Printf ("Platform::%s Attach() succeeded, Process plugin: %s", __FUNCTION__, process_sp->GetPluginName ().AsCString ()); launch_info.SetHijackListener(attach_info.GetHijackListener()); // Since we attached to the process, it will think it needs to detach @@ -1075,8 +1152,24 @@ Platform::DebugProcess (ProcessLaunchInfo &launch_info, process_sp->SetSTDIOFileDescriptor(pty_fd); } } + else + { + if (log) + log->Printf ("Platform::%s Attach() failed: %s", __FUNCTION__, error.AsCString ()); + } } + else + { + if (log) + log->Printf ("Platform::%s LaunchProcess() returned launch_info with invalid process id", __FUNCTION__); + } + } + else + { + if (log) + log->Printf ("Platform::%s LaunchProcess() failed: %s", __FUNCTION__, error.AsCString ()); } + return process_sp; } |