1 //===-- Platform.cpp --------------------------------------------*- C++ -*-===//
3 // The LLVM Compiler Infrastructure
5 // This file is distributed under the University of Illinois Open Source
6 // License. See LICENSE.TXT for details.
8 //===----------------------------------------------------------------------===//
10 #include "lldb/Target/Platform.h"
14 // Other libraries and framework includes
16 #include "lldb/Breakpoint/BreakpointIDList.h"
17 #include "lldb/Core/Error.h"
18 #include "lldb/Core/Log.h"
19 #include "lldb/Core/ModuleSpec.h"
20 #include "lldb/Core/PluginManager.h"
21 #include "lldb/Host/FileSpec.h"
22 #include "lldb/Host/FileSystem.h"
23 #include "lldb/Host/Host.h"
24 #include "lldb/Host/HostInfo.h"
25 #include "lldb/Target/Process.h"
26 #include "lldb/Target/Target.h"
27 #include "lldb/Utility/Utils.h"
30 using namespace lldb_private;
32 // Use a singleton function for g_local_platform_sp to avoid init
33 // constructors since LLDB is often part of a shared library
35 GetDefaultPlatformSP ()
37 static PlatformSP g_default_platform_sp;
38 return g_default_platform_sp;
42 GetConnectedPlatformListMutex ()
44 static Mutex g_remote_connected_platforms_mutex (Mutex::eMutexTypeRecursive);
45 return g_remote_connected_platforms_mutex;
47 static std::vector<PlatformSP> &
48 GetConnectedPlatformList ()
50 static std::vector<PlatformSP> g_remote_connected_platforms;
51 return g_remote_connected_platforms;
56 Platform::GetHostPlatformName ()
61 //------------------------------------------------------------------
62 /// Get the native host platform plug-in.
64 /// There should only be one of these for each host that LLDB runs
65 /// upon that should be statically compiled in and registered using
66 /// preprocessor macros or other similar build mechanisms.
68 /// This platform will be used as the default platform when launching
69 /// or attaching to processes unless another platform is specified.
70 //------------------------------------------------------------------
72 Platform::GetDefaultPlatform ()
74 return GetDefaultPlatformSP ();
78 Platform::SetDefaultPlatform (const lldb::PlatformSP &platform_sp)
80 // The native platform should use its static void Platform::Initialize()
81 // function to register itself as the native platform.
82 GetDefaultPlatformSP () = platform_sp;
86 Platform::GetFileWithUUID (const FileSpec &platform_file,
90 // Default to the local case
91 local_file = platform_file;
96 Platform::LocateExecutableScriptingResources (Target *target, Module &module, Stream* feedback_stream)
98 return FileSpecList();
102 Platform::FindPlugin (Process *process, const ConstString &plugin_name)
104 PlatformCreateInstance create_callback = NULL;
107 create_callback = PluginManager::GetPlatformCreateCallbackForPluginName (plugin_name);
113 arch = process->GetTarget().GetArchitecture();
115 std::unique_ptr<Platform> instance_ap(create_callback(process, &arch));
116 if (instance_ap.get())
117 return instance_ap.release();
122 for (uint32_t idx = 0; (create_callback = PluginManager::GetPlatformCreateCallbackAtIndex(idx)) != NULL; ++idx)
124 std::unique_ptr<Platform> instance_ap(create_callback(process, nullptr));
125 if (instance_ap.get())
126 return instance_ap.release();
133 Platform::GetSharedModule (const ModuleSpec &module_spec,
135 const FileSpecList *module_search_paths_ptr,
136 ModuleSP *old_module_sp_ptr,
137 bool *did_create_ptr)
139 // Don't do any path remapping for the default implementation
140 // of the platform GetSharedModule function, just call through
141 // to our static ModuleList function. Platform subclasses that
142 // implement remote debugging, might have a developer kits
143 // installed that have cached versions of the files for the
144 // remote target, or might implement a download and cache
145 // locally implementation.
146 const bool always_create = false;
147 return ModuleList::GetSharedModule (module_spec,
149 module_search_paths_ptr,
156 Platform::Create (const char *platform_name, Error &error)
158 PlatformCreateInstance create_callback = NULL;
159 lldb::PlatformSP platform_sp;
160 if (platform_name && platform_name[0])
162 ConstString const_platform_name (platform_name);
163 create_callback = PluginManager::GetPlatformCreateCallbackForPluginName (const_platform_name);
165 platform_sp.reset(create_callback(true, NULL));
167 error.SetErrorStringWithFormat ("unable to find a plug-in for the platform named \"%s\"", platform_name);
170 error.SetErrorString ("invalid platform name");
176 Platform::Create (const ArchSpec &arch, ArchSpec *platform_arch_ptr, Error &error)
178 lldb::PlatformSP platform_sp;
182 PlatformCreateInstance create_callback;
183 // First try exact arch matches across all platform plug-ins
185 for (idx = 0; (create_callback = PluginManager::GetPlatformCreateCallbackAtIndex (idx)); ++idx)
189 platform_sp.reset(create_callback(false, &arch));
190 if (platform_sp && platform_sp->IsCompatibleArchitecture(arch, exact, platform_arch_ptr))
194 // Next try compatible arch matches across all platform plug-ins
196 for (idx = 0; (create_callback = PluginManager::GetPlatformCreateCallbackAtIndex (idx)); ++idx)
200 platform_sp.reset(create_callback(false, &arch));
201 if (platform_sp && platform_sp->IsCompatibleArchitecture(arch, exact, platform_arch_ptr))
207 error.SetErrorString ("invalid platform name");
208 if (platform_arch_ptr)
209 platform_arch_ptr->Clear();
215 Platform::GetNumConnectedRemotePlatforms ()
217 Mutex::Locker locker (GetConnectedPlatformListMutex ());
218 return GetConnectedPlatformList().size();
222 Platform::GetConnectedRemotePlatformAtIndex (uint32_t idx)
224 PlatformSP platform_sp;
226 Mutex::Locker locker (GetConnectedPlatformListMutex ());
227 if (idx < GetConnectedPlatformList().size())
228 platform_sp = GetConnectedPlatformList ()[idx];
233 //------------------------------------------------------------------
234 /// Default Constructor
235 //------------------------------------------------------------------
236 Platform::Platform (bool is_host) :
238 m_os_version_set_while_connected (false),
239 m_system_arch_set_while_connected (false),
245 m_major_os_version (UINT32_MAX),
246 m_minor_os_version (UINT32_MAX),
247 m_update_os_version (UINT32_MAX),
249 m_uid_map_mutex (Mutex::eMutexTypeNormal),
250 m_gid_map_mutex (Mutex::eMutexTypeNormal),
253 m_max_uid_name_len (0),
254 m_max_gid_name_len (0),
255 m_supports_rsync (false),
258 m_supports_ssh (false),
260 m_ignores_remote_hostname (false),
262 m_calculated_trap_handlers (false),
263 m_trap_handler_mutex()
265 Log *log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_OBJECT));
267 log->Printf ("%p Platform::Platform()", static_cast<void*>(this));
270 //------------------------------------------------------------------
273 /// The destructor is virtual since this class is designed to be
274 /// inherited from by the plug-in instance.
275 //------------------------------------------------------------------
276 Platform::~Platform()
278 Log *log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_OBJECT));
280 log->Printf ("%p Platform::~Platform()", static_cast<void*>(this));
284 Platform::GetStatus (Stream &strm)
286 uint32_t major = UINT32_MAX;
287 uint32_t minor = UINT32_MAX;
288 uint32_t update = UINT32_MAX;
290 strm.Printf (" Platform: %s\n", GetPluginName().GetCString());
292 ArchSpec arch (GetSystemArchitecture());
295 if (!arch.GetTriple().str().empty())
296 strm.Printf(" Triple: %s\n", arch.GetTriple().str().c_str());
299 if (GetOSVersion(major, minor, update))
301 strm.Printf("OS Version: %u", major);
302 if (minor != UINT32_MAX)
303 strm.Printf(".%u", minor);
304 if (update != UINT32_MAX)
305 strm.Printf(".%u", update);
307 if (GetOSBuildString (s))
308 strm.Printf(" (%s)", s.c_str());
313 if (GetOSKernelDescription (s))
314 strm.Printf(" Kernel: %s\n", s.c_str());
318 strm.Printf(" Hostname: %s\n", GetHostname());
322 const bool is_connected = IsConnected();
324 strm.Printf(" Hostname: %s\n", GetHostname());
325 strm.Printf(" Connected: %s\n", is_connected ? "yes" : "no");
328 if (GetWorkingDirectory())
330 strm.Printf("WorkingDir: %s\n", GetWorkingDirectory().GetCString());
335 std::string specific_info(GetPlatformSpecificConnectionInformation());
337 if (specific_info.empty() == false)
338 strm.Printf("Platform-specific connection: %s\n", specific_info.c_str());
343 Platform::GetOSVersion (uint32_t &major,
347 bool success = m_major_os_version != UINT32_MAX;
352 // We have a local host platform
353 success = HostInfo::GetOSVersion(m_major_os_version, m_minor_os_version, m_update_os_version);
354 m_os_version_set_while_connected = success;
359 // We have a remote platform. We can only fetch the remote
360 // OS version if we are connected, and we don't want to do it
363 const bool is_connected = IsConnected();
368 // We have valid OS version info, check to make sure it wasn't
369 // manually set prior to connecting. If it was manually set prior
370 // to connecting, then lets fetch the actual OS version info
371 // if we are now connected.
372 if (is_connected && !m_os_version_set_while_connected)
377 // We don't have valid OS version info, fetch it if we are connected
378 fetch = is_connected;
383 success = GetRemoteOSVersion ();
384 m_os_version_set_while_connected = success;
390 major = m_major_os_version;
391 minor = m_minor_os_version;
392 update = m_update_os_version;
398 Platform::GetOSBuildString (std::string &s)
403 #if !defined(__linux__)
404 return HostInfo::GetOSBuildString(s);
409 return GetRemoteOSBuildString (s);
413 Platform::GetOSKernelDescription (std::string &s)
416 #if !defined(__linux__)
417 return HostInfo::GetOSKernelDescription(s);
422 return GetRemoteOSKernelDescription (s);
426 Platform::GetWorkingDirectory ()
431 if (getcwd(cwd, sizeof(cwd)))
432 return ConstString(cwd);
434 return ConstString();
439 m_working_dir = GetRemoteWorkingDirectory();
440 return m_working_dir;
445 struct RecurseCopyBaton
448 Platform *platform_ptr;
453 static FileSpec::EnumerateDirectoryResult
454 RecurseCopy_Callback (void *baton,
455 FileSpec::FileType file_type,
458 RecurseCopyBaton* rc_baton = (RecurseCopyBaton*)baton;
461 case FileSpec::eFileTypePipe:
462 case FileSpec::eFileTypeSocket:
463 // we have no way to copy pipes and sockets - ignore them and continue
464 return FileSpec::eEnumerateDirectoryResultNext;
467 case FileSpec::eFileTypeDirectory:
469 // make the new directory and get in there
470 FileSpec dst_dir = rc_baton->dst;
471 if (!dst_dir.GetFilename())
472 dst_dir.GetFilename() = src.GetLastPathComponent();
473 std::string dst_dir_path (dst_dir.GetPath());
474 Error error = rc_baton->platform_ptr->MakeDirectory(dst_dir_path.c_str(), lldb::eFilePermissionsDirectoryDefault);
477 rc_baton->error.SetErrorStringWithFormat("unable to setup directory %s on remote end", dst_dir_path.c_str());
478 return FileSpec::eEnumerateDirectoryResultQuit; // got an error, bail out
482 std::string src_dir_path (src.GetPath());
484 // Make a filespec that only fills in the directory of a FileSpec so
485 // when we enumerate we can quickly fill in the filename for dst copies
486 FileSpec recurse_dst;
487 recurse_dst.GetDirectory().SetCString(dst_dir.GetPath().c_str());
488 RecurseCopyBaton rc_baton2 = { recurse_dst, rc_baton->platform_ptr, Error() };
489 FileSpec::EnumerateDirectory(src_dir_path.c_str(), true, true, true, RecurseCopy_Callback, &rc_baton2);
490 if (rc_baton2.error.Fail())
492 rc_baton->error.SetErrorString(rc_baton2.error.AsCString());
493 return FileSpec::eEnumerateDirectoryResultQuit; // got an error, bail out
495 return FileSpec::eEnumerateDirectoryResultNext;
499 case FileSpec::eFileTypeSymbolicLink:
501 // copy the file and keep going
502 FileSpec dst_file = rc_baton->dst;
503 if (!dst_file.GetFilename())
504 dst_file.GetFilename() = src.GetFilename();
508 rc_baton->error = FileSystem::Readlink(src.GetPath().c_str(), buf, sizeof(buf));
510 if (rc_baton->error.Fail())
511 return FileSpec::eEnumerateDirectoryResultQuit; // got an error, bail out
513 rc_baton->error = rc_baton->platform_ptr->CreateSymlink(dst_file.GetPath().c_str(), buf);
515 if (rc_baton->error.Fail())
516 return FileSpec::eEnumerateDirectoryResultQuit; // got an error, bail out
518 return FileSpec::eEnumerateDirectoryResultNext;
521 case FileSpec::eFileTypeRegular:
523 // copy the file and keep going
524 FileSpec dst_file = rc_baton->dst;
525 if (!dst_file.GetFilename())
526 dst_file.GetFilename() = src.GetFilename();
527 Error err = rc_baton->platform_ptr->PutFile(src, dst_file);
530 rc_baton->error.SetErrorString(err.AsCString());
531 return FileSpec::eEnumerateDirectoryResultQuit; // got an error, bail out
533 return FileSpec::eEnumerateDirectoryResultNext;
537 case FileSpec::eFileTypeInvalid:
538 case FileSpec::eFileTypeOther:
539 case FileSpec::eFileTypeUnknown:
541 rc_baton->error.SetErrorStringWithFormat("invalid file detected during copy: %s", src.GetPath().c_str());
542 return FileSpec::eEnumerateDirectoryResultQuit; // got an error, bail out
548 Platform::Install (const FileSpec& src, const FileSpec& dst)
552 Log *log = GetLogIfAnyCategoriesSet(LIBLLDB_LOG_PLATFORM);
554 log->Printf ("Platform::Install (src='%s', dst='%s')", src.GetPath().c_str(), dst.GetPath().c_str());
555 FileSpec fixed_dst(dst);
557 if (!fixed_dst.GetFilename())
558 fixed_dst.GetFilename() = src.GetFilename();
560 ConstString working_dir = GetWorkingDirectory();
564 if (dst.GetDirectory())
566 const char first_dst_dir_char = dst.GetDirectory().GetCString()[0];
567 if (first_dst_dir_char == '/' || first_dst_dir_char == '\\')
569 fixed_dst.GetDirectory() = dst.GetDirectory();
571 // If the fixed destination file doesn't have a directory yet,
572 // then we must have a relative path. We will resolve this relative
573 // path against the platform's working directory
574 if (!fixed_dst.GetDirectory())
576 FileSpec relative_spec;
580 relative_spec.SetFile(working_dir.GetCString(), false);
581 relative_spec.AppendPathComponent(dst.GetPath().c_str());
582 fixed_dst.GetDirectory() = relative_spec.GetDirectory();
586 error.SetErrorStringWithFormat("platform working directory must be valid for relative path '%s'", dst.GetPath().c_str());
595 fixed_dst.GetDirectory() = working_dir;
599 error.SetErrorStringWithFormat("platform working directory must be valid for relative path '%s'", dst.GetPath().c_str());
608 fixed_dst.GetDirectory() = working_dir;
612 error.SetErrorStringWithFormat("platform working directory must be valid when destination directory is empty");
618 log->Printf ("Platform::Install (src='%s', dst='%s') fixed_dst='%s'", src.GetPath().c_str(), dst.GetPath().c_str(), fixed_dst.GetPath().c_str());
620 if (GetSupportsRSync())
622 error = PutFile(src, dst);
626 switch (src.GetFileType())
628 case FileSpec::eFileTypeDirectory:
630 if (GetFileExists (fixed_dst))
631 Unlink (fixed_dst.GetPath().c_str());
632 uint32_t permissions = src.GetPermissions();
633 if (permissions == 0)
634 permissions = eFilePermissionsDirectoryDefault;
635 std::string dst_dir_path(fixed_dst.GetPath());
636 error = MakeDirectory(dst_dir_path.c_str(), permissions);
639 // Make a filespec that only fills in the directory of a FileSpec so
640 // when we enumerate we can quickly fill in the filename for dst copies
641 FileSpec recurse_dst;
642 recurse_dst.GetDirectory().SetCString(dst_dir_path.c_str());
643 std::string src_dir_path (src.GetPath());
644 RecurseCopyBaton baton = { recurse_dst, this, Error() };
645 FileSpec::EnumerateDirectory(src_dir_path.c_str(), true, true, true, RecurseCopy_Callback, &baton);
651 case FileSpec::eFileTypeRegular:
652 if (GetFileExists (fixed_dst))
653 Unlink (fixed_dst.GetPath().c_str());
654 error = PutFile(src, fixed_dst);
657 case FileSpec::eFileTypeSymbolicLink:
659 if (GetFileExists (fixed_dst))
660 Unlink (fixed_dst.GetPath().c_str());
662 error = FileSystem::Readlink(src.GetPath().c_str(), buf, sizeof(buf));
664 error = CreateSymlink(dst.GetPath().c_str(), buf);
667 case FileSpec::eFileTypePipe:
668 error.SetErrorString("platform install doesn't handle pipes");
670 case FileSpec::eFileTypeSocket:
671 error.SetErrorString("platform install doesn't handle sockets");
673 case FileSpec::eFileTypeInvalid:
674 case FileSpec::eFileTypeUnknown:
675 case FileSpec::eFileTypeOther:
676 error.SetErrorString("platform install doesn't handle non file or directory items");
684 Platform::SetWorkingDirectory (const ConstString &path)
688 Log *log = GetLogIfAnyCategoriesSet(LIBLLDB_LOG_PLATFORM);
690 log->Printf("Platform::SetWorkingDirectory('%s')", path.GetCString());
692 // Not implemented on Windows
697 if (chdir(path.GetCString()) == 0)
705 m_working_dir.Clear();
706 return SetRemoteWorkingDirectory(path);
711 Platform::MakeDirectory (const char *path, uint32_t permissions)
714 return FileSystem::MakeDirectory(path, permissions);
718 error.SetErrorStringWithFormat("remote platform %s doesn't support %s", GetPluginName().GetCString(), __PRETTY_FUNCTION__);
724 Platform::GetFilePermissions (const char *path, uint32_t &file_permissions)
727 return FileSystem::GetFilePermissions(path, file_permissions);
731 error.SetErrorStringWithFormat("remote platform %s doesn't support %s", GetPluginName().GetCString(), __PRETTY_FUNCTION__);
737 Platform::SetFilePermissions (const char *path, uint32_t file_permissions)
740 return FileSystem::SetFilePermissions(path, file_permissions);
744 error.SetErrorStringWithFormat("remote platform %s doesn't support %s", GetPluginName().GetCString(), __PRETTY_FUNCTION__);
752 return GetPluginName();
756 Platform::GetHostname ()
763 return m_name.c_str();
767 Platform::SetRemoteWorkingDirectory(const ConstString &path)
769 Log *log = GetLogIfAnyCategoriesSet(LIBLLDB_LOG_PLATFORM);
771 log->Printf("Platform::SetRemoteWorkingDirectory('%s')", path.GetCString());
772 m_working_dir = path;
777 Platform::GetUserName (uint32_t uid)
779 #if !defined(LLDB_DISABLE_POSIX)
780 const char *user_name = GetCachedUserName(uid);
786 if (HostInfo::LookupUserName(uid, name))
787 return SetCachedUserName (uid, name.c_str(), name.size());
794 Platform::GetGroupName (uint32_t gid)
796 #if !defined(LLDB_DISABLE_POSIX)
797 const char *group_name = GetCachedGroupName(gid);
803 if (HostInfo::LookupGroupName(gid, name))
804 return SetCachedGroupName (gid, name.c_str(), name.size());
811 Platform::SetOSVersion (uint32_t major,
817 // We don't need anyone setting the OS version for the host platform,
818 // we should be able to figure it out by calling HostInfo::GetOSVersion(...).
823 // We have a remote platform, allow setting the target OS version if
824 // we aren't connected, since if we are connected, we should be able to
825 // request the remote OS version from the connected platform.
830 // We aren't connected and we might want to set the OS version
831 // ahead of time before we connect so we can peruse files and
832 // use a local SDK or PDK cache of support files to disassemble
833 // or do other things.
834 m_major_os_version = major;
835 m_minor_os_version = minor;
836 m_update_os_version = update;
845 Platform::ResolveExecutable (const FileSpec &exe_file,
846 const ArchSpec &exe_arch,
847 lldb::ModuleSP &exe_module_sp,
848 const FileSpecList *module_search_paths_ptr)
851 if (exe_file.Exists())
853 ModuleSpec module_spec (exe_file, exe_arch);
854 if (module_spec.GetArchitecture().IsValid())
856 error = ModuleList::GetSharedModule (module_spec,
858 module_search_paths_ptr,
864 // No valid architecture was specified, ask the platform for
865 // the architectures that we should be using (in the correct order)
866 // and see if we can find a match that way
867 for (uint32_t idx = 0; GetSupportedArchitectureAtIndex (idx, module_spec.GetArchitecture()); ++idx)
869 error = ModuleList::GetSharedModule (module_spec,
871 module_search_paths_ptr,
874 // Did we find an executable using one of the
875 if (error.Success() && exe_module_sp)
882 error.SetErrorStringWithFormat ("'%s' does not exist",
883 exe_file.GetPath().c_str());
889 Platform::ResolveSymbolFile (Target &target,
890 const ModuleSpec &sym_spec,
894 if (sym_spec.GetSymbolFileSpec().Exists())
895 sym_file = sym_spec.GetSymbolFileSpec();
897 error.SetErrorString("unable to resolve symbol file");
905 Platform::ResolveRemotePath (const FileSpec &platform_path,
906 FileSpec &resolved_platform_path)
908 resolved_platform_path = platform_path;
909 return resolved_platform_path.ResolvePath();
914 Platform::GetSystemArchitecture()
918 if (!m_system_arch.IsValid())
920 // We have a local host platform
921 m_system_arch = HostInfo::GetArchitecture();
922 m_system_arch_set_while_connected = m_system_arch.IsValid();
927 // We have a remote platform. We can only fetch the remote
928 // system architecture if we are connected, and we don't want to do it
931 const bool is_connected = IsConnected();
934 if (m_system_arch.IsValid())
936 // We have valid OS version info, check to make sure it wasn't
937 // manually set prior to connecting. If it was manually set prior
938 // to connecting, then lets fetch the actual OS version info
939 // if we are now connected.
940 if (is_connected && !m_system_arch_set_while_connected)
945 // We don't have valid OS version info, fetch it if we are connected
946 fetch = is_connected;
951 m_system_arch = GetRemoteSystemArchitecture ();
952 m_system_arch_set_while_connected = m_system_arch.IsValid();
955 return m_system_arch;
960 Platform::ConnectRemote (Args& args)
964 error.SetErrorStringWithFormat ("The currently selected platform (%s) is the host platform and is always connected.", GetPluginName().GetCString());
966 error.SetErrorStringWithFormat ("Platform::ConnectRemote() is not supported by %s", GetPluginName().GetCString());
971 Platform::DisconnectRemote ()
975 error.SetErrorStringWithFormat ("The currently selected platform (%s) is the host platform and is always connected.", GetPluginName().GetCString());
977 error.SetErrorStringWithFormat ("Platform::DisconnectRemote() is not supported by %s", GetPluginName().GetCString());
982 Platform::GetProcessInfo (lldb::pid_t pid, ProcessInstanceInfo &process_info)
984 // Take care of the host case so that each subclass can just
985 // call this function to get the host functionality.
987 return Host::GetProcessInfo (pid, process_info);
992 Platform::FindProcesses (const ProcessInstanceInfoMatch &match_info,
993 ProcessInstanceInfoList &process_infos)
995 // Take care of the host case so that each subclass can just
996 // call this function to get the host functionality.
997 uint32_t match_count = 0;
999 match_count = Host::FindProcesses (match_info, process_infos);
1005 Platform::LaunchProcess (ProcessLaunchInfo &launch_info)
1008 // Take care of the host case so that each subclass can just
1009 // call this function to get the host functionality.
1012 if (::getenv ("LLDB_LAUNCH_FLAG_LAUNCH_IN_TTY"))
1013 launch_info.GetFlags().Set (eLaunchFlagLaunchInTTY);
1015 if (launch_info.GetFlags().Test (eLaunchFlagLaunchInShell))
1017 const bool is_localhost = true;
1018 const bool will_debug = launch_info.GetFlags().Test(eLaunchFlagDebug);
1019 const bool first_arg_is_full_shell_command = false;
1020 uint32_t num_resumes = GetResumeCountForLaunchInfo (launch_info);
1021 if (!launch_info.ConvertArgumentsForLaunchingInShell (error,
1024 first_arg_is_full_shell_command,
1029 error = Host::LaunchProcess (launch_info);
1032 error.SetErrorString ("base lldb_private::Platform class can't launch remote processes");
1037 Platform::DebugProcess (ProcessLaunchInfo &launch_info,
1039 Target *target, // Can be NULL, if NULL create a new target, else use existing one
1043 ProcessSP process_sp;
1044 // Make sure we stop at the entry point
1045 launch_info.GetFlags ().Set (eLaunchFlagDebug);
1046 // We always launch the process we are going to debug in a separate process
1047 // group, since then we can handle ^C interrupts ourselves w/o having to worry
1048 // about the target getting them as well.
1049 launch_info.SetLaunchInSeparateProcessGroup(true);
1051 error = LaunchProcess (launch_info);
1052 if (error.Success())
1054 if (launch_info.GetProcessID() != LLDB_INVALID_PROCESS_ID)
1056 ProcessAttachInfo attach_info (launch_info);
1057 process_sp = Attach (attach_info, debugger, target, listener, error);
1060 launch_info.SetHijackListener(attach_info.GetHijackListener());
1062 // Since we attached to the process, it will think it needs to detach
1063 // if the process object just goes away without an explicit call to
1064 // Process::Kill() or Process::Detach(), so let it know to kill the
1065 // process if this happens.
1066 process_sp->SetShouldDetach (false);
1068 // If we didn't have any file actions, the pseudo terminal might
1069 // have been used where the slave side was given as the file to
1070 // open for stdin/out/err after we have already opened the master
1071 // so we can read/write stdin/out/err.
1072 int pty_fd = launch_info.GetPTY().ReleaseMasterFileDescriptor();
1073 if (pty_fd != lldb_utility::PseudoTerminal::invalid_fd)
1075 process_sp->SetSTDIOFileDescriptor(pty_fd);
1085 Platform::GetPlatformForArchitecture (const ArchSpec &arch, ArchSpec *platform_arch_ptr)
1087 lldb::PlatformSP platform_sp;
1090 platform_sp = Platform::Create (arch, platform_arch_ptr, error);
1095 //------------------------------------------------------------------
1096 /// Lets a platform answer if it is compatible with a given
1097 /// architecture and the target triple contained within.
1098 //------------------------------------------------------------------
1100 Platform::IsCompatibleArchitecture (const ArchSpec &arch, bool exact_arch_match, ArchSpec *compatible_arch_ptr)
1102 // If the architecture is invalid, we must answer true...
1105 ArchSpec platform_arch;
1106 // Try for an exact architecture match first.
1107 if (exact_arch_match)
1109 for (uint32_t arch_idx=0; GetSupportedArchitectureAtIndex (arch_idx, platform_arch); ++arch_idx)
1111 if (arch.IsExactMatch(platform_arch))
1113 if (compatible_arch_ptr)
1114 *compatible_arch_ptr = platform_arch;
1121 for (uint32_t arch_idx=0; GetSupportedArchitectureAtIndex (arch_idx, platform_arch); ++arch_idx)
1123 if (arch.IsCompatibleMatch(platform_arch))
1125 if (compatible_arch_ptr)
1126 *compatible_arch_ptr = platform_arch;
1132 if (compatible_arch_ptr)
1133 compatible_arch_ptr->Clear();
1138 Platform::PutFile (const FileSpec& source,
1139 const FileSpec& destination,
1143 Error error("unimplemented");
1148 Platform::GetFile (const FileSpec& source,
1149 const FileSpec& destination)
1151 Error error("unimplemented");
1156 Platform::CreateSymlink (const char *src, // The name of the link is in src
1157 const char *dst)// The symlink points to dst
1159 Error error("unimplemented");
1164 Platform::GetFileExists (const lldb_private::FileSpec& file_spec)
1170 Platform::Unlink (const char *path)
1172 Error error("unimplemented");
1179 Platform::RunShellCommand (const char *command, // Shouldn't be NULL
1180 const char *working_dir, // Pass NULL to use the current working directory
1181 int *status_ptr, // Pass NULL if you don't want the process exit status
1182 int *signo_ptr, // Pass NULL if you don't want the signal that caused the process to exit
1183 std::string *command_output, // Pass NULL if you don't want the command output
1184 uint32_t timeout_sec) // Timeout in seconds to wait for shell program to finish
1187 return Host::RunShellCommand (command, working_dir, status_ptr, signo_ptr, command_output, timeout_sec);
1189 return Error("unimplemented");
1194 Platform::CalculateMD5 (const FileSpec& file_spec,
1199 return FileSystem::CalculateMD5(file_spec, low, high);
1205 Platform::LaunchNativeProcess (
1206 ProcessLaunchInfo &launch_info,
1207 lldb_private::NativeProcessProtocol::NativeDelegate &native_delegate,
1208 NativeProcessProtocolSP &process_sp)
1210 // Platforms should override this implementation if they want to
1211 // support lldb-gdbserver.
1212 return Error("unimplemented");
1216 Platform::AttachNativeProcess (lldb::pid_t pid,
1217 lldb_private::NativeProcessProtocol::NativeDelegate &native_delegate,
1218 NativeProcessProtocolSP &process_sp)
1220 // Platforms should override this implementation if they want to
1221 // support lldb-gdbserver.
1222 return Error("unimplemented");
1226 Platform::SetLocalCacheDirectory (const char* local)
1228 m_local_cache_directory.assign(local);
1232 Platform::GetLocalCacheDirectory ()
1234 return m_local_cache_directory.c_str();
1237 static OptionDefinition
1238 g_rsync_option_table[] =
1240 { LLDB_OPT_SET_ALL, false, "rsync" , 'r', OptionParser::eNoArgument, NULL, NULL, 0, eArgTypeNone , "Enable rsync." },
1241 { LLDB_OPT_SET_ALL, false, "rsync-opts" , 'R', OptionParser::eRequiredArgument, NULL, NULL, 0, eArgTypeCommandName , "Platform-specific options required for rsync to work." },
1242 { LLDB_OPT_SET_ALL, false, "rsync-prefix" , 'P', OptionParser::eRequiredArgument, NULL, NULL, 0, eArgTypeCommandName , "Platform-specific rsync prefix put before the remote path." },
1243 { LLDB_OPT_SET_ALL, false, "ignore-remote-hostname" , 'i', OptionParser::eNoArgument, NULL, NULL, 0, eArgTypeNone , "Do not automatically fill in the remote hostname when composing the rsync command." },
1246 static OptionDefinition
1247 g_ssh_option_table[] =
1249 { LLDB_OPT_SET_ALL, false, "ssh" , 's', OptionParser::eNoArgument, NULL, NULL, 0, eArgTypeNone , "Enable SSH." },
1250 { LLDB_OPT_SET_ALL, false, "ssh-opts" , 'S', OptionParser::eRequiredArgument, NULL, NULL, 0, eArgTypeCommandName , "Platform-specific options required for SSH to work." },
1253 static OptionDefinition
1254 g_caching_option_table[] =
1256 { LLDB_OPT_SET_ALL, false, "local-cache-dir" , 'c', OptionParser::eRequiredArgument, NULL, NULL, 0, eArgTypePath , "Path in which to store local copies of files." },
1259 OptionGroupPlatformRSync::OptionGroupPlatformRSync ()
1263 OptionGroupPlatformRSync::~OptionGroupPlatformRSync ()
1267 const lldb_private::OptionDefinition*
1268 OptionGroupPlatformRSync::GetDefinitions ()
1270 return g_rsync_option_table;
1274 OptionGroupPlatformRSync::OptionParsingStarting (CommandInterpreter &interpreter)
1277 m_rsync_opts.clear();
1278 m_rsync_prefix.clear();
1279 m_ignores_remote_hostname = false;
1283 OptionGroupPlatformRSync::SetOptionValue (CommandInterpreter &interpreter,
1284 uint32_t option_idx,
1285 const char *option_arg)
1288 char short_option = (char) GetDefinitions()[option_idx].short_option;
1289 switch (short_option)
1296 m_rsync_opts.assign(option_arg);
1300 m_rsync_prefix.assign(option_arg);
1304 m_ignores_remote_hostname = true;
1308 error.SetErrorStringWithFormat ("unrecognized option '%c'", short_option);
1316 OptionGroupPlatformRSync::GetNumDefinitions ()
1318 return llvm::array_lengthof(g_rsync_option_table);
1322 Platform::SetThreadCreationBreakpoint (lldb_private::Target &target)
1324 return lldb::BreakpointSP();
1327 OptionGroupPlatformSSH::OptionGroupPlatformSSH ()
1331 OptionGroupPlatformSSH::~OptionGroupPlatformSSH ()
1335 const lldb_private::OptionDefinition*
1336 OptionGroupPlatformSSH::GetDefinitions ()
1338 return g_ssh_option_table;
1342 OptionGroupPlatformSSH::OptionParsingStarting (CommandInterpreter &interpreter)
1349 OptionGroupPlatformSSH::SetOptionValue (CommandInterpreter &interpreter,
1350 uint32_t option_idx,
1351 const char *option_arg)
1354 char short_option = (char) GetDefinitions()[option_idx].short_option;
1355 switch (short_option)
1362 m_ssh_opts.assign(option_arg);
1366 error.SetErrorStringWithFormat ("unrecognized option '%c'", short_option);
1374 OptionGroupPlatformSSH::GetNumDefinitions ()
1376 return llvm::array_lengthof(g_ssh_option_table);
1379 OptionGroupPlatformCaching::OptionGroupPlatformCaching ()
1383 OptionGroupPlatformCaching::~OptionGroupPlatformCaching ()
1387 const lldb_private::OptionDefinition*
1388 OptionGroupPlatformCaching::GetDefinitions ()
1390 return g_caching_option_table;
1394 OptionGroupPlatformCaching::OptionParsingStarting (CommandInterpreter &interpreter)
1396 m_cache_dir.clear();
1400 OptionGroupPlatformCaching::SetOptionValue (CommandInterpreter &interpreter,
1401 uint32_t option_idx,
1402 const char *option_arg)
1405 char short_option = (char) GetDefinitions()[option_idx].short_option;
1406 switch (short_option)
1409 m_cache_dir.assign(option_arg);
1413 error.SetErrorStringWithFormat ("unrecognized option '%c'", short_option);
1421 OptionGroupPlatformCaching::GetNumDefinitions ()
1423 return llvm::array_lengthof(g_caching_option_table);
1427 Platform::GetEnvironment (StringList &environment)
1429 environment.Clear();
1433 const std::vector<ConstString> &
1434 Platform::GetTrapHandlerSymbolNames ()
1436 if (!m_calculated_trap_handlers)
1438 Mutex::Locker locker (m_trap_handler_mutex);
1439 if (!m_calculated_trap_handlers)
1441 CalculateTrapHandlerSymbolNames();
1442 m_calculated_trap_handlers = true;
1445 return m_trap_handlers;