blob: 96f63ead89ce93207f714e58700f98cbd3e26227 [file] [log] [blame]
Greg Claytone996fd32011-03-08 22:40:15 +00001//===-- Platform.cpp --------------------------------------------*- C++ -*-===//
2//
3// The LLVM Compiler Infrastructure
4//
5// This file is distributed under the University of Illinois Open Source
6// License. See LICENSE.TXT for details.
7//
8//===----------------------------------------------------------------------===//
9
10#include "lldb/Target/Platform.h"
11
12// C Includes
13// C++ Includes
14// Other libraries and framework includes
15// Project includes
Greg Clayton4116e932012-05-15 02:33:01 +000016#include "lldb/Breakpoint/BreakpointIDList.h"
Greg Claytone996fd32011-03-08 22:40:15 +000017#include "lldb/Core/Error.h"
Greg Clayton8b82f082011-04-12 05:54:46 +000018#include "lldb/Core/Log.h"
Greg Clayton1f746072012-08-29 21:13:06 +000019#include "lldb/Core/ModuleSpec.h"
Greg Claytone996fd32011-03-08 22:40:15 +000020#include "lldb/Core/PluginManager.h"
21#include "lldb/Host/FileSpec.h"
Greg Claytonded470d2011-03-19 01:12:21 +000022#include "lldb/Host/Host.h"
Greg Clayton8b82f082011-04-12 05:54:46 +000023#include "lldb/Target/Process.h"
Greg Claytone996fd32011-03-08 22:40:15 +000024#include "lldb/Target/Target.h"
Daniel Maleae0f8f572013-08-26 23:57:52 +000025#include "lldb/Utility/Utils.h"
Greg Claytone996fd32011-03-08 22:40:15 +000026
27using namespace lldb;
28using namespace lldb_private;
29
30// Use a singleton function for g_local_platform_sp to avoid init
31// constructors since LLDB is often part of a shared library
32static PlatformSP&
33GetDefaultPlatformSP ()
34{
35 static PlatformSP g_default_platform_sp;
36 return g_default_platform_sp;
37}
38
Greg Claytone996fd32011-03-08 22:40:15 +000039static Mutex &
40GetConnectedPlatformListMutex ()
41{
42 static Mutex g_remote_connected_platforms_mutex (Mutex::eMutexTypeRecursive);
43 return g_remote_connected_platforms_mutex;
44}
45static std::vector<PlatformSP> &
46GetConnectedPlatformList ()
47{
48 static std::vector<PlatformSP> g_remote_connected_platforms;
49 return g_remote_connected_platforms;
50}
51
Greg Claytonab65b342011-04-13 22:47:15 +000052
53const char *
54Platform::GetHostPlatformName ()
55{
56 return "host";
57}
58
Greg Claytone996fd32011-03-08 22:40:15 +000059//------------------------------------------------------------------
60/// Get the native host platform plug-in.
61///
62/// There should only be one of these for each host that LLDB runs
63/// upon that should be statically compiled in and registered using
64/// preprocessor macros or other similar build mechanisms.
65///
66/// This platform will be used as the default platform when launching
67/// or attaching to processes unless another platform is specified.
68//------------------------------------------------------------------
69PlatformSP
70Platform::GetDefaultPlatform ()
71{
72 return GetDefaultPlatformSP ();
73}
74
75void
76Platform::SetDefaultPlatform (const lldb::PlatformSP &platform_sp)
77{
78 // The native platform should use its static void Platform::Initialize()
79 // function to register itself as the native platform.
80 GetDefaultPlatformSP () = platform_sp;
81}
82
Greg Claytone996fd32011-03-08 22:40:15 +000083Error
Steve Puccifc995722014-01-17 18:18:31 +000084Platform::GetFileWithUUID (const FileSpec &platform_file,
85 const UUID *uuid_ptr,
86 FileSpec &local_file)
Greg Claytone996fd32011-03-08 22:40:15 +000087{
88 // Default to the local case
89 local_file = platform_file;
90 return Error();
91}
92
Greg Clayton91c0e742013-01-11 23:44:27 +000093FileSpecList
94Platform::LocateExecutableScriptingResources (Target *target, Module &module)
Enrico Granata17598482012-11-08 02:22:02 +000095{
Greg Clayton91c0e742013-01-11 23:44:27 +000096 return FileSpecList();
Enrico Granata17598482012-11-08 02:22:02 +000097}
98
Jason Molenda1c627542013-04-05 01:03:25 +000099Platform*
Greg Clayton57abc5d2013-05-10 21:47:16 +0000100Platform::FindPlugin (Process *process, const ConstString &plugin_name)
Jason Molenda1c627542013-04-05 01:03:25 +0000101{
102 PlatformCreateInstance create_callback = NULL;
103 if (plugin_name)
104 {
105 create_callback = PluginManager::GetPlatformCreateCallbackForPluginName (plugin_name);
106 if (create_callback)
107 {
108 ArchSpec arch;
109 if (process)
110 {
111 arch = process->GetTarget().GetArchitecture();
112 }
Greg Clayton7b0992d2013-04-18 22:45:39 +0000113 std::unique_ptr<Platform> instance_ap(create_callback(process, &arch));
Jason Molenda1c627542013-04-05 01:03:25 +0000114 if (instance_ap.get())
115 return instance_ap.release();
116 }
117 }
118 else
119 {
120 for (uint32_t idx = 0; (create_callback = PluginManager::GetPlatformCreateCallbackAtIndex(idx)) != NULL; ++idx)
121 {
Matt Kopecef143712013-06-03 18:00:07 +0000122 std::unique_ptr<Platform> instance_ap(create_callback(process, nullptr));
Jason Molenda1c627542013-04-05 01:03:25 +0000123 if (instance_ap.get())
124 return instance_ap.release();
125 }
126 }
127 return NULL;
128}
129
Greg Clayton32e0a752011-03-30 18:16:51 +0000130Error
Greg Claytonb9a01b32012-02-26 05:51:37 +0000131Platform::GetSharedModule (const ModuleSpec &module_spec,
Greg Clayton32e0a752011-03-30 18:16:51 +0000132 ModuleSP &module_sp,
Greg Claytonc859e2d2012-02-13 23:10:39 +0000133 const FileSpecList *module_search_paths_ptr,
Greg Clayton32e0a752011-03-30 18:16:51 +0000134 ModuleSP *old_module_sp_ptr,
135 bool *did_create_ptr)
136{
137 // Don't do any path remapping for the default implementation
138 // of the platform GetSharedModule function, just call through
139 // to our static ModuleList function. Platform subclasses that
140 // implement remote debugging, might have a developer kits
141 // installed that have cached versions of the files for the
142 // remote target, or might implement a download and cache
143 // locally implementation.
144 const bool always_create = false;
Greg Claytonb9a01b32012-02-26 05:51:37 +0000145 return ModuleList::GetSharedModule (module_spec,
Greg Clayton32e0a752011-03-30 18:16:51 +0000146 module_sp,
Greg Claytonc859e2d2012-02-13 23:10:39 +0000147 module_search_paths_ptr,
Greg Clayton32e0a752011-03-30 18:16:51 +0000148 old_module_sp_ptr,
149 did_create_ptr,
150 always_create);
151}
152
Greg Claytone996fd32011-03-08 22:40:15 +0000153PlatformSP
Greg Claytonded470d2011-03-19 01:12:21 +0000154Platform::Create (const char *platform_name, Error &error)
Greg Claytone996fd32011-03-08 22:40:15 +0000155{
156 PlatformCreateInstance create_callback = NULL;
157 lldb::PlatformSP platform_sp;
Greg Claytonded470d2011-03-19 01:12:21 +0000158 if (platform_name && platform_name[0])
Greg Claytone996fd32011-03-08 22:40:15 +0000159 {
Greg Clayton57abc5d2013-05-10 21:47:16 +0000160 ConstString const_platform_name (platform_name);
161 create_callback = PluginManager::GetPlatformCreateCallbackForPluginName (const_platform_name);
Greg Claytone996fd32011-03-08 22:40:15 +0000162 if (create_callback)
Greg Claytonb3a40ba2012-03-20 18:34:04 +0000163 platform_sp.reset(create_callback(true, NULL));
Greg Claytone996fd32011-03-08 22:40:15 +0000164 else
Greg Claytonded470d2011-03-19 01:12:21 +0000165 error.SetErrorStringWithFormat ("unable to find a plug-in for the platform named \"%s\"", platform_name);
Greg Claytone996fd32011-03-08 22:40:15 +0000166 }
167 else
Greg Claytonded470d2011-03-19 01:12:21 +0000168 error.SetErrorString ("invalid platform name");
Greg Claytone996fd32011-03-08 22:40:15 +0000169 return platform_sp;
170}
171
Greg Claytonb3a40ba2012-03-20 18:34:04 +0000172
173PlatformSP
Greg Clayton70512312012-05-08 01:45:38 +0000174Platform::Create (const ArchSpec &arch, ArchSpec *platform_arch_ptr, Error &error)
Greg Claytonb3a40ba2012-03-20 18:34:04 +0000175{
176 lldb::PlatformSP platform_sp;
177 if (arch.IsValid())
178 {
Greg Clayton70512312012-05-08 01:45:38 +0000179 uint32_t idx;
Greg Claytonb3a40ba2012-03-20 18:34:04 +0000180 PlatformCreateInstance create_callback;
Greg Clayton1e0c8842013-01-11 20:49:54 +0000181 // First try exact arch matches across all platform plug-ins
182 bool exact = true;
Greg Clayton70512312012-05-08 01:45:38 +0000183 for (idx = 0; (create_callback = PluginManager::GetPlatformCreateCallbackAtIndex (idx)); ++idx)
Greg Claytonb3a40ba2012-03-20 18:34:04 +0000184 {
185 if (create_callback)
Greg Clayton1e0c8842013-01-11 20:49:54 +0000186 {
Greg Claytonb3a40ba2012-03-20 18:34:04 +0000187 platform_sp.reset(create_callback(false, &arch));
Greg Clayton1e0c8842013-01-11 20:49:54 +0000188 if (platform_sp && platform_sp->IsCompatibleArchitecture(arch, exact, platform_arch_ptr))
189 return platform_sp;
190 }
191 }
192 // Next try compatible arch matches across all platform plug-ins
193 exact = false;
194 for (idx = 0; (create_callback = PluginManager::GetPlatformCreateCallbackAtIndex (idx)); ++idx)
195 {
196 if (create_callback)
197 {
198 platform_sp.reset(create_callback(false, &arch));
199 if (platform_sp && platform_sp->IsCompatibleArchitecture(arch, exact, platform_arch_ptr))
200 return platform_sp;
201 }
Greg Claytonb3a40ba2012-03-20 18:34:04 +0000202 }
203 }
204 else
205 error.SetErrorString ("invalid platform name");
Greg Clayton70512312012-05-08 01:45:38 +0000206 if (platform_arch_ptr)
207 platform_arch_ptr->Clear();
208 platform_sp.reset();
Greg Claytonb3a40ba2012-03-20 18:34:04 +0000209 return platform_sp;
210}
211
Greg Claytone996fd32011-03-08 22:40:15 +0000212uint32_t
213Platform::GetNumConnectedRemotePlatforms ()
214{
215 Mutex::Locker locker (GetConnectedPlatformListMutex ());
216 return GetConnectedPlatformList().size();
217}
218
219PlatformSP
220Platform::GetConnectedRemotePlatformAtIndex (uint32_t idx)
221{
222 PlatformSP platform_sp;
223 {
224 Mutex::Locker locker (GetConnectedPlatformListMutex ());
225 if (idx < GetConnectedPlatformList().size())
226 platform_sp = GetConnectedPlatformList ()[idx];
227 }
228 return platform_sp;
229}
230
231//------------------------------------------------------------------
232/// Default Constructor
233//------------------------------------------------------------------
Greg Claytonded470d2011-03-19 01:12:21 +0000234Platform::Platform (bool is_host) :
235 m_is_host (is_host),
Greg Claytonded470d2011-03-19 01:12:21 +0000236 m_os_version_set_while_connected (false),
237 m_system_arch_set_while_connected (false),
Greg Claytonf3dd93c2011-06-17 03:31:01 +0000238 m_sdk_sysroot (),
239 m_sdk_build (),
Greg Claytonfbb76342013-11-20 21:07:01 +0000240 m_working_dir (),
Greg Claytonded470d2011-03-19 01:12:21 +0000241 m_remote_url (),
Greg Clayton1cb64962011-03-24 04:28:38 +0000242 m_name (),
Greg Claytonded470d2011-03-19 01:12:21 +0000243 m_major_os_version (UINT32_MAX),
244 m_minor_os_version (UINT32_MAX),
Greg Clayton32e0a752011-03-30 18:16:51 +0000245 m_update_os_version (UINT32_MAX),
246 m_system_arch(),
247 m_uid_map_mutex (Mutex::eMutexTypeNormal),
248 m_gid_map_mutex (Mutex::eMutexTypeNormal),
249 m_uid_map(),
250 m_gid_map(),
251 m_max_uid_name_len (0),
Daniel Maleae0f8f572013-08-26 23:57:52 +0000252 m_max_gid_name_len (0),
253 m_supports_rsync (false),
254 m_rsync_opts (),
255 m_rsync_prefix (),
256 m_supports_ssh (false),
257 m_ssh_opts (),
Jason Molenda6223db272014-02-13 07:11:08 +0000258 m_ignores_remote_hostname (false),
Jason Molenda2094dbf2014-02-13 23:11:45 +0000259 m_trap_handlers(),
Jason Molenda4da87062014-05-23 23:11:27 +0000260 m_calculated_trap_handlers (false),
261 m_trap_handler_mutex()
Greg Claytone996fd32011-03-08 22:40:15 +0000262{
Greg Clayton5160ce52013-03-27 23:08:40 +0000263 Log *log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_OBJECT));
Greg Clayton8b82f082011-04-12 05:54:46 +0000264 if (log)
Saleem Abdulrasool324a1032014-04-04 04:06:10 +0000265 log->Printf ("%p Platform::Platform()", static_cast<void*>(this));
Greg Claytone996fd32011-03-08 22:40:15 +0000266}
267
268//------------------------------------------------------------------
269/// Destructor.
270///
271/// The destructor is virtual since this class is designed to be
272/// inherited from by the plug-in instance.
273//------------------------------------------------------------------
274Platform::~Platform()
275{
Greg Clayton5160ce52013-03-27 23:08:40 +0000276 Log *log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_OBJECT));
Greg Clayton8b82f082011-04-12 05:54:46 +0000277 if (log)
Saleem Abdulrasool324a1032014-04-04 04:06:10 +0000278 log->Printf ("%p Platform::~Platform()", static_cast<void*>(this));
Greg Claytone996fd32011-03-08 22:40:15 +0000279}
280
Greg Clayton1cb64962011-03-24 04:28:38 +0000281void
282Platform::GetStatus (Stream &strm)
283{
284 uint32_t major = UINT32_MAX;
285 uint32_t minor = UINT32_MAX;
286 uint32_t update = UINT32_MAX;
287 std::string s;
Greg Clayton57abc5d2013-05-10 21:47:16 +0000288 strm.Printf (" Platform: %s\n", GetPluginName().GetCString());
Greg Clayton1cb64962011-03-24 04:28:38 +0000289
290 ArchSpec arch (GetSystemArchitecture());
291 if (arch.IsValid())
292 {
293 if (!arch.GetTriple().str().empty())
Greg Clayton32e0a752011-03-30 18:16:51 +0000294 strm.Printf(" Triple: %s\n", arch.GetTriple().str().c_str());
Greg Clayton1cb64962011-03-24 04:28:38 +0000295 }
296
297 if (GetOSVersion(major, minor, update))
298 {
Greg Clayton32e0a752011-03-30 18:16:51 +0000299 strm.Printf("OS Version: %u", major);
Greg Clayton1cb64962011-03-24 04:28:38 +0000300 if (minor != UINT32_MAX)
301 strm.Printf(".%u", minor);
302 if (update != UINT32_MAX)
303 strm.Printf(".%u", update);
304
305 if (GetOSBuildString (s))
306 strm.Printf(" (%s)", s.c_str());
307
308 strm.EOL();
309 }
310
311 if (GetOSKernelDescription (s))
Greg Clayton32e0a752011-03-30 18:16:51 +0000312 strm.Printf(" Kernel: %s\n", s.c_str());
Greg Clayton1cb64962011-03-24 04:28:38 +0000313
314 if (IsHost())
315 {
Greg Clayton32e0a752011-03-30 18:16:51 +0000316 strm.Printf(" Hostname: %s\n", GetHostname());
Greg Clayton1cb64962011-03-24 04:28:38 +0000317 }
318 else
319 {
Greg Clayton32e0a752011-03-30 18:16:51 +0000320 const bool is_connected = IsConnected();
321 if (is_connected)
322 strm.Printf(" Hostname: %s\n", GetHostname());
323 strm.Printf(" Connected: %s\n", is_connected ? "yes" : "no");
Greg Clayton1cb64962011-03-24 04:28:38 +0000324 }
Daniel Maleae0f8f572013-08-26 23:57:52 +0000325
Greg Claytonfbb76342013-11-20 21:07:01 +0000326 if (GetWorkingDirectory())
327 {
328 strm.Printf("WorkingDir: %s\n", GetWorkingDirectory().GetCString());
329 }
Daniel Maleae0f8f572013-08-26 23:57:52 +0000330 if (!IsConnected())
331 return;
332
333 std::string specific_info(GetPlatformSpecificConnectionInformation());
334
335 if (specific_info.empty() == false)
336 strm.Printf("Platform-specific connection: %s\n", specific_info.c_str());
Greg Clayton1cb64962011-03-24 04:28:38 +0000337}
338
Greg Claytonded470d2011-03-19 01:12:21 +0000339
340bool
341Platform::GetOSVersion (uint32_t &major,
342 uint32_t &minor,
343 uint32_t &update)
344{
345 bool success = m_major_os_version != UINT32_MAX;
346 if (IsHost())
347 {
348 if (!success)
349 {
350 // We have a local host platform
351 success = Host::GetOSVersion (m_major_os_version,
352 m_minor_os_version,
353 m_update_os_version);
354 m_os_version_set_while_connected = success;
355 }
356 }
357 else
358 {
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
361 // more than once.
362
363 const bool is_connected = IsConnected();
364
Greg Clayton1cb64962011-03-24 04:28:38 +0000365 bool fetch = false;
Greg Claytonded470d2011-03-19 01:12:21 +0000366 if (success)
367 {
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)
Greg Clayton1cb64962011-03-24 04:28:38 +0000373 fetch = true;
Greg Claytonded470d2011-03-19 01:12:21 +0000374 }
375 else
376 {
377 // We don't have valid OS version info, fetch it if we are connected
Greg Clayton1cb64962011-03-24 04:28:38 +0000378 fetch = is_connected;
Greg Claytonded470d2011-03-19 01:12:21 +0000379 }
380
Greg Clayton1cb64962011-03-24 04:28:38 +0000381 if (fetch)
Greg Claytonded470d2011-03-19 01:12:21 +0000382 {
Greg Clayton1cb64962011-03-24 04:28:38 +0000383 success = GetRemoteOSVersion ();
Greg Claytonded470d2011-03-19 01:12:21 +0000384 m_os_version_set_while_connected = success;
385 }
386 }
387
388 if (success)
389 {
390 major = m_major_os_version;
391 minor = m_minor_os_version;
392 update = m_update_os_version;
393 }
394 return success;
395}
Greg Clayton1cb64962011-03-24 04:28:38 +0000396
397bool
398Platform::GetOSBuildString (std::string &s)
399{
400 if (IsHost())
401 return Host::GetOSBuildString (s);
402 else
403 return GetRemoteOSBuildString (s);
404}
405
406bool
407Platform::GetOSKernelDescription (std::string &s)
408{
409 if (IsHost())
410 return Host::GetOSKernelDescription (s);
411 else
412 return GetRemoteOSKernelDescription (s);
413}
414
Greg Clayton57abc5d2013-05-10 21:47:16 +0000415ConstString
Greg Claytonfbb76342013-11-20 21:07:01 +0000416Platform::GetWorkingDirectory ()
417{
418 if (IsHost())
419 {
420 char cwd[PATH_MAX];
421 if (getcwd(cwd, sizeof(cwd)))
422 return ConstString(cwd);
423 else
424 return ConstString();
425 }
426 else
427 {
428 if (!m_working_dir)
429 m_working_dir = GetRemoteWorkingDirectory();
430 return m_working_dir;
431 }
432}
433
434
435struct RecurseCopyBaton
436{
437 const FileSpec& dst;
438 Platform *platform_ptr;
439 Error error;
440};
441
442
443static FileSpec::EnumerateDirectoryResult
444RecurseCopy_Callback (void *baton,
445 FileSpec::FileType file_type,
446 const FileSpec &src)
447{
448 RecurseCopyBaton* rc_baton = (RecurseCopyBaton*)baton;
449 switch (file_type)
450 {
451 case FileSpec::eFileTypePipe:
452 case FileSpec::eFileTypeSocket:
453 // we have no way to copy pipes and sockets - ignore them and continue
454 return FileSpec::eEnumerateDirectoryResultNext;
455 break;
456
457 case FileSpec::eFileTypeDirectory:
458 {
459 // make the new directory and get in there
460 FileSpec dst_dir = rc_baton->dst;
461 if (!dst_dir.GetFilename())
462 dst_dir.GetFilename() = src.GetLastPathComponent();
463 std::string dst_dir_path (dst_dir.GetPath());
464 Error error = rc_baton->platform_ptr->MakeDirectory(dst_dir_path.c_str(), lldb::eFilePermissionsDirectoryDefault);
465 if (error.Fail())
466 {
467 rc_baton->error.SetErrorStringWithFormat("unable to setup directory %s on remote end", dst_dir_path.c_str());
468 return FileSpec::eEnumerateDirectoryResultQuit; // got an error, bail out
469 }
470
471 // now recurse
472 std::string src_dir_path (src.GetPath());
473
474 // Make a filespec that only fills in the directory of a FileSpec so
475 // when we enumerate we can quickly fill in the filename for dst copies
476 FileSpec recurse_dst;
477 recurse_dst.GetDirectory().SetCString(dst_dir.GetPath().c_str());
478 RecurseCopyBaton rc_baton2 = { recurse_dst, rc_baton->platform_ptr, Error() };
479 FileSpec::EnumerateDirectory(src_dir_path.c_str(), true, true, true, RecurseCopy_Callback, &rc_baton2);
480 if (rc_baton2.error.Fail())
481 {
482 rc_baton->error.SetErrorString(rc_baton2.error.AsCString());
483 return FileSpec::eEnumerateDirectoryResultQuit; // got an error, bail out
484 }
485 return FileSpec::eEnumerateDirectoryResultNext;
486 }
487 break;
488
489 case FileSpec::eFileTypeSymbolicLink:
490 {
491 // copy the file and keep going
492 FileSpec dst_file = rc_baton->dst;
493 if (!dst_file.GetFilename())
494 dst_file.GetFilename() = src.GetFilename();
495
496 char buf[PATH_MAX];
497
498 rc_baton->error = Host::Readlink (src.GetPath().c_str(), buf, sizeof(buf));
499
500 if (rc_baton->error.Fail())
501 return FileSpec::eEnumerateDirectoryResultQuit; // got an error, bail out
502
503 rc_baton->error = rc_baton->platform_ptr->CreateSymlink(dst_file.GetPath().c_str(), buf);
504
505 if (rc_baton->error.Fail())
506 return FileSpec::eEnumerateDirectoryResultQuit; // got an error, bail out
507
508 return FileSpec::eEnumerateDirectoryResultNext;
509 }
510 break;
511 case FileSpec::eFileTypeRegular:
512 {
513 // copy the file and keep going
514 FileSpec dst_file = rc_baton->dst;
515 if (!dst_file.GetFilename())
516 dst_file.GetFilename() = src.GetFilename();
517 Error err = rc_baton->platform_ptr->PutFile(src, dst_file);
518 if (err.Fail())
519 {
520 rc_baton->error.SetErrorString(err.AsCString());
521 return FileSpec::eEnumerateDirectoryResultQuit; // got an error, bail out
522 }
523 return FileSpec::eEnumerateDirectoryResultNext;
524 }
525 break;
526
527 case FileSpec::eFileTypeInvalid:
528 case FileSpec::eFileTypeOther:
529 case FileSpec::eFileTypeUnknown:
530 rc_baton->error.SetErrorStringWithFormat("invalid file detected during copy: %s", src.GetPath().c_str());
531 return FileSpec::eEnumerateDirectoryResultQuit; // got an error, bail out
532 break;
533 }
534}
535
536Error
537Platform::Install (const FileSpec& src, const FileSpec& dst)
538{
539 Error error;
540
541 Log *log = GetLogIfAnyCategoriesSet(LIBLLDB_LOG_PLATFORM);
542 if (log)
543 log->Printf ("Platform::Install (src='%s', dst='%s')", src.GetPath().c_str(), dst.GetPath().c_str());
544 FileSpec fixed_dst(dst);
545
546 if (!fixed_dst.GetFilename())
547 fixed_dst.GetFilename() = src.GetFilename();
548
549 ConstString working_dir = GetWorkingDirectory();
550
551 if (dst)
552 {
553 if (dst.GetDirectory())
554 {
555 const char first_dst_dir_char = dst.GetDirectory().GetCString()[0];
556 if (first_dst_dir_char == '/' || first_dst_dir_char == '\\')
557 {
558 fixed_dst.GetDirectory() = dst.GetDirectory();
559 }
560 // If the fixed destination file doesn't have a directory yet,
561 // then we must have a relative path. We will resolve this relative
562 // path against the platform's working directory
563 if (!fixed_dst.GetDirectory())
564 {
565 FileSpec relative_spec;
566 std::string path;
567 if (working_dir)
568 {
569 relative_spec.SetFile(working_dir.GetCString(), false);
570 relative_spec.AppendPathComponent(dst.GetPath().c_str());
571 fixed_dst.GetDirectory() = relative_spec.GetDirectory();
572 }
573 else
574 {
575 error.SetErrorStringWithFormat("platform working directory must be valid for relative path '%s'", dst.GetPath().c_str());
576 return error;
577 }
578 }
579 }
580 else
581 {
582 if (working_dir)
583 {
584 fixed_dst.GetDirectory() = working_dir;
585 }
586 else
587 {
588 error.SetErrorStringWithFormat("platform working directory must be valid for relative path '%s'", dst.GetPath().c_str());
589 return error;
590 }
591 }
592 }
593 else
594 {
595 if (working_dir)
596 {
597 fixed_dst.GetDirectory() = working_dir;
598 }
599 else
600 {
601 error.SetErrorStringWithFormat("platform working directory must be valid when destination directory is empty");
602 return error;
603 }
604 }
605
606 if (log)
607 log->Printf ("Platform::Install (src='%s', dst='%s') fixed_dst='%s'", src.GetPath().c_str(), dst.GetPath().c_str(), fixed_dst.GetPath().c_str());
608
609 if (GetSupportsRSync())
610 {
611 error = PutFile(src, dst);
612 }
613 else
614 {
615 switch (src.GetFileType())
616 {
617 case FileSpec::eFileTypeDirectory:
618 {
619 if (GetFileExists (fixed_dst))
620 Unlink (fixed_dst.GetPath().c_str());
621 uint32_t permissions = src.GetPermissions();
622 if (permissions == 0)
623 permissions = eFilePermissionsDirectoryDefault;
624 std::string dst_dir_path(fixed_dst.GetPath());
625 error = MakeDirectory(dst_dir_path.c_str(), permissions);
626 if (error.Success())
627 {
628 // Make a filespec that only fills in the directory of a FileSpec so
629 // when we enumerate we can quickly fill in the filename for dst copies
630 FileSpec recurse_dst;
631 recurse_dst.GetDirectory().SetCString(dst_dir_path.c_str());
632 std::string src_dir_path (src.GetPath());
633 RecurseCopyBaton baton = { recurse_dst, this, Error() };
634 FileSpec::EnumerateDirectory(src_dir_path.c_str(), true, true, true, RecurseCopy_Callback, &baton);
635 return baton.error;
636 }
637 }
638 break;
639
640 case FileSpec::eFileTypeRegular:
641 if (GetFileExists (fixed_dst))
642 Unlink (fixed_dst.GetPath().c_str());
643 error = PutFile(src, fixed_dst);
644 break;
645
646 case FileSpec::eFileTypeSymbolicLink:
647 {
648 if (GetFileExists (fixed_dst))
649 Unlink (fixed_dst.GetPath().c_str());
650 char buf[PATH_MAX];
651 error = Host::Readlink(src.GetPath().c_str(), buf, sizeof(buf));
652 if (error.Success())
653 error = CreateSymlink(dst.GetPath().c_str(), buf);
654 }
655 break;
656 case FileSpec::eFileTypePipe:
657 error.SetErrorString("platform install doesn't handle pipes");
658 break;
659 case FileSpec::eFileTypeSocket:
660 error.SetErrorString("platform install doesn't handle sockets");
661 break;
662 case FileSpec::eFileTypeInvalid:
663 case FileSpec::eFileTypeUnknown:
664 case FileSpec::eFileTypeOther:
665 error.SetErrorString("platform install doesn't handle non file or directory items");
666 break;
667 }
668 }
669 return error;
670}
671
672bool
673Platform::SetWorkingDirectory (const ConstString &path)
674{
675 if (IsHost())
676 {
Greg Clayton5fb8f792013-12-02 19:35:49 +0000677 Log *log = GetLogIfAnyCategoriesSet(LIBLLDB_LOG_PLATFORM);
678 if (log)
679 log->Printf("Platform::SetWorkingDirectory('%s')", path.GetCString());
Colin Riley909bb7a2013-11-26 15:10:46 +0000680#ifdef _WIN32
681 // Not implemented on Windows
682 return false;
683#else
Greg Claytonfbb76342013-11-20 21:07:01 +0000684 if (path)
685 {
686 if (chdir(path.GetCString()) == 0)
687 return true;
688 }
689 return false;
Colin Riley909bb7a2013-11-26 15:10:46 +0000690#endif
Greg Claytonfbb76342013-11-20 21:07:01 +0000691 }
692 else
693 {
Greg Clayton5fb8f792013-12-02 19:35:49 +0000694 m_working_dir.Clear();
Greg Claytonfbb76342013-11-20 21:07:01 +0000695 return SetRemoteWorkingDirectory(path);
696 }
697}
698
699Error
700Platform::MakeDirectory (const char *path, uint32_t permissions)
701{
702 if (IsHost())
703 return Host::MakeDirectory (path, permissions);
704 else
705 {
706 Error error;
707 error.SetErrorStringWithFormat("remote platform %s doesn't support %s", GetPluginName().GetCString(), __PRETTY_FUNCTION__);
708 return error;
709 }
710}
711
712Error
713Platform::GetFilePermissions (const char *path, uint32_t &file_permissions)
714{
715 if (IsHost())
716 return Host::GetFilePermissions(path, file_permissions);
717 else
718 {
719 Error error;
720 error.SetErrorStringWithFormat("remote platform %s doesn't support %s", GetPluginName().GetCString(), __PRETTY_FUNCTION__);
721 return error;
722 }
723}
724
725Error
726Platform::SetFilePermissions (const char *path, uint32_t file_permissions)
727{
728 if (IsHost())
729 return Host::SetFilePermissions(path, file_permissions);
730 else
731 {
732 Error error;
733 error.SetErrorStringWithFormat("remote platform %s doesn't support %s", GetPluginName().GetCString(), __PRETTY_FUNCTION__);
734 return error;
735 }
736}
737
738ConstString
Greg Clayton8b82f082011-04-12 05:54:46 +0000739Platform::GetName ()
740{
Greg Claytonfbb76342013-11-20 21:07:01 +0000741 return GetPluginName();
Greg Clayton8b82f082011-04-12 05:54:46 +0000742}
743
744const char *
Greg Clayton1cb64962011-03-24 04:28:38 +0000745Platform::GetHostname ()
746{
Greg Claytonab65b342011-04-13 22:47:15 +0000747 if (IsHost())
Greg Clayton16810922014-02-27 19:38:18 +0000748 return "127.0.0.1";
Greg Clayton32e0a752011-03-30 18:16:51 +0000749
750 if (m_name.empty())
751 return NULL;
752 return m_name.c_str();
753}
754
Greg Clayton5fb8f792013-12-02 19:35:49 +0000755bool
756Platform::SetRemoteWorkingDirectory(const ConstString &path)
757{
758 Log *log = GetLogIfAnyCategoriesSet(LIBLLDB_LOG_PLATFORM);
759 if (log)
760 log->Printf("Platform::SetRemoteWorkingDirectory('%s')", path.GetCString());
761 m_working_dir = path;
762 return true;
763}
764
Greg Clayton32e0a752011-03-30 18:16:51 +0000765const char *
766Platform::GetUserName (uint32_t uid)
767{
768 const char *user_name = GetCachedUserName(uid);
769 if (user_name)
770 return user_name;
771 if (IsHost())
772 {
773 std::string name;
774 if (Host::GetUserName(uid, name))
775 return SetCachedUserName (uid, name.c_str(), name.size());
776 }
Greg Clayton1cb64962011-03-24 04:28:38 +0000777 return NULL;
778}
779
Greg Clayton32e0a752011-03-30 18:16:51 +0000780const char *
781Platform::GetGroupName (uint32_t gid)
782{
783 const char *group_name = GetCachedGroupName(gid);
784 if (group_name)
785 return group_name;
786 if (IsHost())
787 {
788 std::string name;
789 if (Host::GetGroupName(gid, name))
790 return SetCachedGroupName (gid, name.c_str(), name.size());
791 }
792 return NULL;
793}
Greg Clayton1cb64962011-03-24 04:28:38 +0000794
Greg Claytonded470d2011-03-19 01:12:21 +0000795bool
796Platform::SetOSVersion (uint32_t major,
797 uint32_t minor,
798 uint32_t update)
799{
800 if (IsHost())
801 {
802 // We don't need anyone setting the OS version for the host platform,
803 // we should be able to figure it out by calling Host::GetOSVersion(...).
804 return false;
805 }
806 else
807 {
808 // We have a remote platform, allow setting the target OS version if
809 // we aren't connected, since if we are connected, we should be able to
810 // request the remote OS version from the connected platform.
811 if (IsConnected())
812 return false;
813 else
814 {
815 // We aren't connected and we might want to set the OS version
816 // ahead of time before we connect so we can peruse files and
817 // use a local SDK or PDK cache of support files to disassemble
818 // or do other things.
819 m_major_os_version = major;
820 m_minor_os_version = minor;
821 m_update_os_version = update;
822 return true;
823 }
824 }
825 return false;
826}
827
828
Greg Claytone996fd32011-03-08 22:40:15 +0000829Error
830Platform::ResolveExecutable (const FileSpec &exe_file,
831 const ArchSpec &exe_arch,
Greg Claytonc859e2d2012-02-13 23:10:39 +0000832 lldb::ModuleSP &exe_module_sp,
833 const FileSpecList *module_search_paths_ptr)
Greg Claytone996fd32011-03-08 22:40:15 +0000834{
835 Error error;
836 if (exe_file.Exists())
837 {
Greg Claytonb9a01b32012-02-26 05:51:37 +0000838 ModuleSpec module_spec (exe_file, exe_arch);
839 if (module_spec.GetArchitecture().IsValid())
Greg Claytone996fd32011-03-08 22:40:15 +0000840 {
Greg Claytonb9a01b32012-02-26 05:51:37 +0000841 error = ModuleList::GetSharedModule (module_spec,
Greg Claytone996fd32011-03-08 22:40:15 +0000842 exe_module_sp,
Greg Claytonc859e2d2012-02-13 23:10:39 +0000843 module_search_paths_ptr,
Greg Claytone996fd32011-03-08 22:40:15 +0000844 NULL,
845 NULL);
846 }
847 else
848 {
849 // No valid architecture was specified, ask the platform for
850 // the architectures that we should be using (in the correct order)
851 // and see if we can find a match that way
Greg Claytonb9a01b32012-02-26 05:51:37 +0000852 for (uint32_t idx = 0; GetSupportedArchitectureAtIndex (idx, module_spec.GetArchitecture()); ++idx)
Greg Claytone996fd32011-03-08 22:40:15 +0000853 {
Greg Claytonb9a01b32012-02-26 05:51:37 +0000854 error = ModuleList::GetSharedModule (module_spec,
Greg Claytone996fd32011-03-08 22:40:15 +0000855 exe_module_sp,
Greg Claytonc859e2d2012-02-13 23:10:39 +0000856 module_search_paths_ptr,
Greg Claytone996fd32011-03-08 22:40:15 +0000857 NULL,
858 NULL);
859 // Did we find an executable using one of the
860 if (error.Success() && exe_module_sp)
861 break;
862 }
863 }
864 }
865 else
866 {
Greg Claytonb5ad4ec2013-04-29 17:25:54 +0000867 error.SetErrorStringWithFormat ("'%s' does not exist",
868 exe_file.GetPath().c_str());
Greg Claytone996fd32011-03-08 22:40:15 +0000869 }
870 return error;
871}
872
Greg Clayton103f0282012-09-12 02:03:59 +0000873Error
874Platform::ResolveSymbolFile (Target &target,
875 const ModuleSpec &sym_spec,
876 FileSpec &sym_file)
877{
878 Error error;
879 if (sym_spec.GetSymbolFileSpec().Exists())
880 sym_file = sym_spec.GetSymbolFileSpec();
881 else
882 error.SetErrorString("unable to resolve symbol file");
883 return error;
884
885}
886
887
888
Greg Claytonaa516842011-08-11 16:25:18 +0000889bool
890Platform::ResolveRemotePath (const FileSpec &platform_path,
891 FileSpec &resolved_platform_path)
892{
893 resolved_platform_path = platform_path;
894 return resolved_platform_path.ResolvePath();
895}
896
Greg Claytonded470d2011-03-19 01:12:21 +0000897
898const ArchSpec &
899Platform::GetSystemArchitecture()
900{
901 if (IsHost())
902 {
903 if (!m_system_arch.IsValid())
904 {
905 // We have a local host platform
906 m_system_arch = Host::GetArchitecture();
907 m_system_arch_set_while_connected = m_system_arch.IsValid();
908 }
909 }
910 else
911 {
912 // We have a remote platform. We can only fetch the remote
913 // system architecture if we are connected, and we don't want to do it
914 // more than once.
915
916 const bool is_connected = IsConnected();
917
918 bool fetch = false;
919 if (m_system_arch.IsValid())
920 {
921 // We have valid OS version info, check to make sure it wasn't
922 // manually set prior to connecting. If it was manually set prior
923 // to connecting, then lets fetch the actual OS version info
924 // if we are now connected.
925 if (is_connected && !m_system_arch_set_while_connected)
926 fetch = true;
927 }
928 else
929 {
930 // We don't have valid OS version info, fetch it if we are connected
931 fetch = is_connected;
932 }
933
934 if (fetch)
935 {
Greg Clayton1cb64962011-03-24 04:28:38 +0000936 m_system_arch = GetRemoteSystemArchitecture ();
Greg Claytonded470d2011-03-19 01:12:21 +0000937 m_system_arch_set_while_connected = m_system_arch.IsValid();
938 }
939 }
940 return m_system_arch;
941}
942
943
Greg Claytone996fd32011-03-08 22:40:15 +0000944Error
Greg Claytond314e812011-03-23 00:09:55 +0000945Platform::ConnectRemote (Args& args)
Greg Claytone996fd32011-03-08 22:40:15 +0000946{
947 Error error;
Greg Claytond314e812011-03-23 00:09:55 +0000948 if (IsHost())
Greg Clayton57abc5d2013-05-10 21:47:16 +0000949 error.SetErrorStringWithFormat ("The currently selected platform (%s) is the host platform and is always connected.", GetPluginName().GetCString());
Greg Claytond314e812011-03-23 00:09:55 +0000950 else
Greg Clayton57abc5d2013-05-10 21:47:16 +0000951 error.SetErrorStringWithFormat ("Platform::ConnectRemote() is not supported by %s", GetPluginName().GetCString());
Greg Claytone996fd32011-03-08 22:40:15 +0000952 return error;
953}
954
955Error
Greg Claytond314e812011-03-23 00:09:55 +0000956Platform::DisconnectRemote ()
Greg Claytone996fd32011-03-08 22:40:15 +0000957{
958 Error error;
Greg Claytond314e812011-03-23 00:09:55 +0000959 if (IsHost())
Greg Clayton57abc5d2013-05-10 21:47:16 +0000960 error.SetErrorStringWithFormat ("The currently selected platform (%s) is the host platform and is always connected.", GetPluginName().GetCString());
Greg Claytond314e812011-03-23 00:09:55 +0000961 else
Greg Clayton57abc5d2013-05-10 21:47:16 +0000962 error.SetErrorStringWithFormat ("Platform::DisconnectRemote() is not supported by %s", GetPluginName().GetCString());
Greg Claytone996fd32011-03-08 22:40:15 +0000963 return error;
964}
Greg Clayton32e0a752011-03-30 18:16:51 +0000965
966bool
Greg Clayton8b82f082011-04-12 05:54:46 +0000967Platform::GetProcessInfo (lldb::pid_t pid, ProcessInstanceInfo &process_info)
Greg Clayton32e0a752011-03-30 18:16:51 +0000968{
969 // Take care of the host case so that each subclass can just
Greg Clayton8b82f082011-04-12 05:54:46 +0000970 // call this function to get the host functionality.
Greg Clayton32e0a752011-03-30 18:16:51 +0000971 if (IsHost())
972 return Host::GetProcessInfo (pid, process_info);
973 return false;
974}
975
976uint32_t
Greg Clayton8b82f082011-04-12 05:54:46 +0000977Platform::FindProcesses (const ProcessInstanceInfoMatch &match_info,
978 ProcessInstanceInfoList &process_infos)
Greg Clayton32e0a752011-03-30 18:16:51 +0000979{
Greg Clayton8b82f082011-04-12 05:54:46 +0000980 // Take care of the host case so that each subclass can just
981 // call this function to get the host functionality.
Greg Clayton32e0a752011-03-30 18:16:51 +0000982 uint32_t match_count = 0;
983 if (IsHost())
984 match_count = Host::FindProcesses (match_info, process_infos);
985 return match_count;
986}
Greg Clayton8b82f082011-04-12 05:54:46 +0000987
988
989Error
990Platform::LaunchProcess (ProcessLaunchInfo &launch_info)
991{
992 Error error;
993 // Take care of the host case so that each subclass can just
994 // call this function to get the host functionality.
995 if (IsHost())
Greg Clayton84db9102012-03-26 23:03:23 +0000996 {
997 if (::getenv ("LLDB_LAUNCH_FLAG_LAUNCH_IN_TTY"))
998 launch_info.GetFlags().Set (eLaunchFlagLaunchInTTY);
999
1000 if (launch_info.GetFlags().Test (eLaunchFlagLaunchInShell))
1001 {
1002 const bool is_localhost = true;
Greg Claytond1cf11a2012-04-14 01:42:46 +00001003 const bool will_debug = launch_info.GetFlags().Test(eLaunchFlagDebug);
1004 const bool first_arg_is_full_shell_command = false;
Jim Inghamd3990792013-09-11 18:23:22 +00001005 uint32_t num_resumes = GetResumeCountForLaunchInfo (launch_info);
Greg Claytond1cf11a2012-04-14 01:42:46 +00001006 if (!launch_info.ConvertArgumentsForLaunchingInShell (error,
1007 is_localhost,
1008 will_debug,
Jim Inghamdf0ae222013-09-10 02:09:47 +00001009 first_arg_is_full_shell_command,
1010 num_resumes))
Greg Clayton84db9102012-03-26 23:03:23 +00001011 return error;
1012 }
1013
Greg Clayton8b82f082011-04-12 05:54:46 +00001014 error = Host::LaunchProcess (launch_info);
Greg Clayton84db9102012-03-26 23:03:23 +00001015 }
Greg Clayton8b82f082011-04-12 05:54:46 +00001016 else
1017 error.SetErrorString ("base lldb_private::Platform class can't launch remote processes");
1018 return error;
1019}
1020
1021lldb::ProcessSP
1022Platform::DebugProcess (ProcessLaunchInfo &launch_info,
1023 Debugger &debugger,
1024 Target *target, // Can be NULL, if NULL create a new target, else use existing one
1025 Listener &listener,
1026 Error &error)
1027{
1028 ProcessSP process_sp;
1029 // Make sure we stop at the entry point
1030 launch_info.GetFlags ().Set (eLaunchFlagDebug);
Jim Inghamb4451b12012-06-01 01:22:13 +00001031 // We always launch the process we are going to debug in a separate process
1032 // group, since then we can handle ^C interrupts ourselves w/o having to worry
1033 // about the target getting them as well.
1034 launch_info.SetLaunchInSeparateProcessGroup(true);
1035
Greg Clayton8b82f082011-04-12 05:54:46 +00001036 error = LaunchProcess (launch_info);
1037 if (error.Success())
1038 {
Greg Clayton144f3a92011-11-15 03:53:30 +00001039 if (launch_info.GetProcessID() != LLDB_INVALID_PROCESS_ID)
Greg Clayton8b82f082011-04-12 05:54:46 +00001040 {
Greg Clayton144f3a92011-11-15 03:53:30 +00001041 ProcessAttachInfo attach_info (launch_info);
1042 process_sp = Attach (attach_info, debugger, target, listener, error);
Greg Claytone24c4ac2011-11-17 04:46:02 +00001043 if (process_sp)
1044 {
Greg Clayton44d93782014-01-27 23:43:24 +00001045 launch_info.SetHijackListener(attach_info.GetHijackListener());
1046
Greg Claytone24c4ac2011-11-17 04:46:02 +00001047 // Since we attached to the process, it will think it needs to detach
1048 // if the process object just goes away without an explicit call to
1049 // Process::Kill() or Process::Detach(), so let it know to kill the
1050 // process if this happens.
1051 process_sp->SetShouldDetach (false);
Greg Claytonee95ed52011-11-17 22:14:31 +00001052
1053 // If we didn't have any file actions, the pseudo terminal might
1054 // have been used where the slave side was given as the file to
1055 // open for stdin/out/err after we have already opened the master
1056 // so we can read/write stdin/out/err.
1057 int pty_fd = launch_info.GetPTY().ReleaseMasterFileDescriptor();
1058 if (pty_fd != lldb_utility::PseudoTerminal::invalid_fd)
1059 {
1060 process_sp->SetSTDIOFileDescriptor(pty_fd);
1061 }
Greg Claytone24c4ac2011-11-17 04:46:02 +00001062 }
Greg Clayton8b82f082011-04-12 05:54:46 +00001063 }
1064 }
1065 return process_sp;
1066}
Greg Claytonb3a40ba2012-03-20 18:34:04 +00001067
1068
1069lldb::PlatformSP
Greg Clayton70512312012-05-08 01:45:38 +00001070Platform::GetPlatformForArchitecture (const ArchSpec &arch, ArchSpec *platform_arch_ptr)
Greg Claytonb3a40ba2012-03-20 18:34:04 +00001071{
1072 lldb::PlatformSP platform_sp;
1073 Error error;
1074 if (arch.IsValid())
Greg Clayton70512312012-05-08 01:45:38 +00001075 platform_sp = Platform::Create (arch, platform_arch_ptr, error);
Greg Claytonb3a40ba2012-03-20 18:34:04 +00001076 return platform_sp;
1077}
1078
1079
1080//------------------------------------------------------------------
1081/// Lets a platform answer if it is compatible with a given
1082/// architecture and the target triple contained within.
1083//------------------------------------------------------------------
1084bool
Greg Clayton1e0c8842013-01-11 20:49:54 +00001085Platform::IsCompatibleArchitecture (const ArchSpec &arch, bool exact_arch_match, ArchSpec *compatible_arch_ptr)
Greg Claytonb3a40ba2012-03-20 18:34:04 +00001086{
1087 // If the architecture is invalid, we must answer true...
Greg Clayton70512312012-05-08 01:45:38 +00001088 if (arch.IsValid())
Greg Claytonb3a40ba2012-03-20 18:34:04 +00001089 {
Greg Clayton70512312012-05-08 01:45:38 +00001090 ArchSpec platform_arch;
Greg Clayton1e0c8842013-01-11 20:49:54 +00001091 // Try for an exact architecture match first.
1092 if (exact_arch_match)
Greg Clayton70512312012-05-08 01:45:38 +00001093 {
Greg Clayton1e0c8842013-01-11 20:49:54 +00001094 for (uint32_t arch_idx=0; GetSupportedArchitectureAtIndex (arch_idx, platform_arch); ++arch_idx)
Greg Clayton70512312012-05-08 01:45:38 +00001095 {
Greg Clayton1e0c8842013-01-11 20:49:54 +00001096 if (arch.IsExactMatch(platform_arch))
1097 {
1098 if (compatible_arch_ptr)
1099 *compatible_arch_ptr = platform_arch;
1100 return true;
1101 }
1102 }
1103 }
1104 else
1105 {
1106 for (uint32_t arch_idx=0; GetSupportedArchitectureAtIndex (arch_idx, platform_arch); ++arch_idx)
1107 {
1108 if (arch.IsCompatibleMatch(platform_arch))
1109 {
1110 if (compatible_arch_ptr)
1111 *compatible_arch_ptr = platform_arch;
1112 return true;
1113 }
Greg Clayton70512312012-05-08 01:45:38 +00001114 }
1115 }
Greg Claytonb3a40ba2012-03-20 18:34:04 +00001116 }
Greg Clayton70512312012-05-08 01:45:38 +00001117 if (compatible_arch_ptr)
1118 compatible_arch_ptr->Clear();
Greg Claytonb3a40ba2012-03-20 18:34:04 +00001119 return false;
Greg Claytonb3a40ba2012-03-20 18:34:04 +00001120}
1121
Daniel Maleae0f8f572013-08-26 23:57:52 +00001122Error
1123Platform::PutFile (const FileSpec& source,
1124 const FileSpec& destination,
1125 uint32_t uid,
1126 uint32_t gid)
1127{
1128 Error error("unimplemented");
1129 return error;
1130}
1131
1132Error
1133Platform::GetFile (const FileSpec& source,
1134 const FileSpec& destination)
1135{
1136 Error error("unimplemented");
1137 return error;
1138}
1139
Greg Claytonfbb76342013-11-20 21:07:01 +00001140Error
1141Platform::CreateSymlink (const char *src, // The name of the link is in src
1142 const char *dst)// The symlink points to dst
1143{
1144 Error error("unimplemented");
1145 return error;
1146}
1147
Daniel Maleae0f8f572013-08-26 23:57:52 +00001148bool
1149Platform::GetFileExists (const lldb_private::FileSpec& file_spec)
1150{
1151 return false;
1152}
1153
Greg Claytonfbb76342013-11-20 21:07:01 +00001154Error
1155Platform::Unlink (const char *path)
1156{
1157 Error error("unimplemented");
1158 return error;
1159}
1160
1161
1162
Daniel Maleae0f8f572013-08-26 23:57:52 +00001163lldb_private::Error
1164Platform::RunShellCommand (const char *command, // Shouldn't be NULL
1165 const char *working_dir, // Pass NULL to use the current working directory
1166 int *status_ptr, // Pass NULL if you don't want the process exit status
1167 int *signo_ptr, // Pass NULL if you don't want the signal that caused the process to exit
1168 std::string *command_output, // Pass NULL if you don't want the command output
1169 uint32_t timeout_sec) // Timeout in seconds to wait for shell program to finish
1170{
1171 if (IsHost())
1172 return Host::RunShellCommand (command, working_dir, status_ptr, signo_ptr, command_output, timeout_sec);
1173 else
1174 return Error("unimplemented");
1175}
1176
1177
1178bool
1179Platform::CalculateMD5 (const FileSpec& file_spec,
1180 uint64_t &low,
1181 uint64_t &high)
1182{
1183 if (IsHost())
1184 return Host::CalculateMD5(file_spec, low, high);
1185 else
1186 return false;
1187}
1188
1189void
1190Platform::SetLocalCacheDirectory (const char* local)
1191{
1192 m_local_cache_directory.assign(local);
1193}
1194
1195const char*
1196Platform::GetLocalCacheDirectory ()
1197{
1198 return m_local_cache_directory.c_str();
1199}
1200
1201static OptionDefinition
1202g_rsync_option_table[] =
1203{
Virgile Belloe2607b52013-09-05 16:42:23 +00001204 { LLDB_OPT_SET_ALL, false, "rsync" , 'r', OptionParser::eNoArgument, NULL, 0, eArgTypeNone , "Enable rsync." },
1205 { LLDB_OPT_SET_ALL, false, "rsync-opts" , 'R', OptionParser::eRequiredArgument, NULL, 0, eArgTypeCommandName , "Platform-specific options required for rsync to work." },
1206 { LLDB_OPT_SET_ALL, false, "rsync-prefix" , 'P', OptionParser::eRequiredArgument, NULL, 0, eArgTypeCommandName , "Platform-specific rsync prefix put before the remote path." },
1207 { LLDB_OPT_SET_ALL, false, "ignore-remote-hostname" , 'i', OptionParser::eNoArgument, NULL, 0, eArgTypeNone , "Do not automatically fill in the remote hostname when composing the rsync command." },
Daniel Maleae0f8f572013-08-26 23:57:52 +00001208};
1209
1210static OptionDefinition
1211g_ssh_option_table[] =
1212{
Virgile Belloe2607b52013-09-05 16:42:23 +00001213 { LLDB_OPT_SET_ALL, false, "ssh" , 's', OptionParser::eNoArgument, NULL, 0, eArgTypeNone , "Enable SSH." },
1214 { LLDB_OPT_SET_ALL, false, "ssh-opts" , 'S', OptionParser::eRequiredArgument, NULL, 0, eArgTypeCommandName , "Platform-specific options required for SSH to work." },
Daniel Maleae0f8f572013-08-26 23:57:52 +00001215};
1216
1217static OptionDefinition
1218g_caching_option_table[] =
1219{
Virgile Belloe2607b52013-09-05 16:42:23 +00001220 { LLDB_OPT_SET_ALL, false, "local-cache-dir" , 'c', OptionParser::eRequiredArgument, NULL, 0, eArgTypePath , "Path in which to store local copies of files." },
Daniel Maleae0f8f572013-08-26 23:57:52 +00001221};
1222
1223OptionGroupPlatformRSync::OptionGroupPlatformRSync ()
1224{
1225}
1226
1227OptionGroupPlatformRSync::~OptionGroupPlatformRSync ()
1228{
1229}
1230
1231const lldb_private::OptionDefinition*
1232OptionGroupPlatformRSync::GetDefinitions ()
1233{
1234 return g_rsync_option_table;
1235}
1236
1237void
1238OptionGroupPlatformRSync::OptionParsingStarting (CommandInterpreter &interpreter)
1239{
1240 m_rsync = false;
1241 m_rsync_opts.clear();
1242 m_rsync_prefix.clear();
1243 m_ignores_remote_hostname = false;
1244}
1245
1246lldb_private::Error
1247OptionGroupPlatformRSync::SetOptionValue (CommandInterpreter &interpreter,
1248 uint32_t option_idx,
1249 const char *option_arg)
1250{
1251 Error error;
1252 char short_option = (char) GetDefinitions()[option_idx].short_option;
1253 switch (short_option)
1254 {
1255 case 'r':
1256 m_rsync = true;
1257 break;
1258
1259 case 'R':
1260 m_rsync_opts.assign(option_arg);
1261 break;
1262
1263 case 'P':
1264 m_rsync_prefix.assign(option_arg);
1265 break;
1266
1267 case 'i':
1268 m_ignores_remote_hostname = true;
1269 break;
1270
1271 default:
1272 error.SetErrorStringWithFormat ("unrecognized option '%c'", short_option);
1273 break;
1274 }
1275
1276 return error;
1277}
1278
1279uint32_t
1280OptionGroupPlatformRSync::GetNumDefinitions ()
1281{
1282 return llvm::array_lengthof(g_rsync_option_table);
1283}
Greg Clayton1e0c8842013-01-11 20:49:54 +00001284
Greg Clayton4116e932012-05-15 02:33:01 +00001285lldb::BreakpointSP
1286Platform::SetThreadCreationBreakpoint (lldb_private::Target &target)
1287{
1288 return lldb::BreakpointSP();
1289}
Greg Claytonb3a40ba2012-03-20 18:34:04 +00001290
Daniel Maleae0f8f572013-08-26 23:57:52 +00001291OptionGroupPlatformSSH::OptionGroupPlatformSSH ()
1292{
1293}
1294
1295OptionGroupPlatformSSH::~OptionGroupPlatformSSH ()
1296{
1297}
1298
1299const lldb_private::OptionDefinition*
1300OptionGroupPlatformSSH::GetDefinitions ()
1301{
1302 return g_ssh_option_table;
1303}
1304
1305void
1306OptionGroupPlatformSSH::OptionParsingStarting (CommandInterpreter &interpreter)
1307{
1308 m_ssh = false;
1309 m_ssh_opts.clear();
1310}
1311
1312lldb_private::Error
1313OptionGroupPlatformSSH::SetOptionValue (CommandInterpreter &interpreter,
1314 uint32_t option_idx,
1315 const char *option_arg)
1316{
1317 Error error;
1318 char short_option = (char) GetDefinitions()[option_idx].short_option;
1319 switch (short_option)
1320 {
1321 case 's':
1322 m_ssh = true;
1323 break;
1324
1325 case 'S':
1326 m_ssh_opts.assign(option_arg);
1327 break;
1328
1329 default:
1330 error.SetErrorStringWithFormat ("unrecognized option '%c'", short_option);
1331 break;
1332 }
1333
1334 return error;
1335}
1336
1337uint32_t
1338OptionGroupPlatformSSH::GetNumDefinitions ()
1339{
1340 return llvm::array_lengthof(g_ssh_option_table);
1341}
1342
1343OptionGroupPlatformCaching::OptionGroupPlatformCaching ()
1344{
1345}
1346
1347OptionGroupPlatformCaching::~OptionGroupPlatformCaching ()
1348{
1349}
1350
1351const lldb_private::OptionDefinition*
1352OptionGroupPlatformCaching::GetDefinitions ()
1353{
1354 return g_caching_option_table;
1355}
1356
1357void
1358OptionGroupPlatformCaching::OptionParsingStarting (CommandInterpreter &interpreter)
1359{
1360 m_cache_dir.clear();
1361}
1362
1363lldb_private::Error
1364OptionGroupPlatformCaching::SetOptionValue (CommandInterpreter &interpreter,
1365 uint32_t option_idx,
1366 const char *option_arg)
1367{
1368 Error error;
1369 char short_option = (char) GetDefinitions()[option_idx].short_option;
1370 switch (short_option)
1371 {
1372 case 'c':
1373 m_cache_dir.assign(option_arg);
1374 break;
1375
1376 default:
1377 error.SetErrorStringWithFormat ("unrecognized option '%c'", short_option);
1378 break;
1379 }
1380
1381 return error;
1382}
1383
1384uint32_t
1385OptionGroupPlatformCaching::GetNumDefinitions ()
1386{
1387 return llvm::array_lengthof(g_caching_option_table);
1388}
1389
Greg Clayton67cc0632012-08-22 17:17:09 +00001390size_t
1391Platform::GetEnvironment (StringList &environment)
1392{
1393 environment.Clear();
1394 return false;
1395}
Jason Molenda2094dbf2014-02-13 23:11:45 +00001396
1397const std::vector<ConstString> &
1398Platform::GetTrapHandlerSymbolNames ()
1399{
1400 if (!m_calculated_trap_handlers)
1401 {
Jason Molenda4da87062014-05-23 23:11:27 +00001402 Mutex::Locker locker (m_trap_handler_mutex);
1403 if (!m_calculated_trap_handlers)
1404 {
1405 CalculateTrapHandlerSymbolNames();
1406 m_calculated_trap_handlers = true;
1407 }
Jason Molenda2094dbf2014-02-13 23:11:45 +00001408 }
1409 return m_trap_handlers;
1410}
1411