blob: a27c91a67443755fec14ab683dbce00e25af54f5 [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),
259 m_trap_handlers()
Greg Claytone996fd32011-03-08 22:40:15 +0000260{
Greg Clayton5160ce52013-03-27 23:08:40 +0000261 Log *log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_OBJECT));
Greg Clayton8b82f082011-04-12 05:54:46 +0000262 if (log)
263 log->Printf ("%p Platform::Platform()", this);
Greg Claytone996fd32011-03-08 22:40:15 +0000264}
265
266//------------------------------------------------------------------
267/// Destructor.
268///
269/// The destructor is virtual since this class is designed to be
270/// inherited from by the plug-in instance.
271//------------------------------------------------------------------
272Platform::~Platform()
273{
Greg Clayton5160ce52013-03-27 23:08:40 +0000274 Log *log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_OBJECT));
Greg Clayton8b82f082011-04-12 05:54:46 +0000275 if (log)
276 log->Printf ("%p Platform::~Platform()", this);
Greg Claytone996fd32011-03-08 22:40:15 +0000277}
278
Greg Clayton1cb64962011-03-24 04:28:38 +0000279void
280Platform::GetStatus (Stream &strm)
281{
282 uint32_t major = UINT32_MAX;
283 uint32_t minor = UINT32_MAX;
284 uint32_t update = UINT32_MAX;
285 std::string s;
Greg Clayton57abc5d2013-05-10 21:47:16 +0000286 strm.Printf (" Platform: %s\n", GetPluginName().GetCString());
Greg Clayton1cb64962011-03-24 04:28:38 +0000287
288 ArchSpec arch (GetSystemArchitecture());
289 if (arch.IsValid())
290 {
291 if (!arch.GetTriple().str().empty())
Greg Clayton32e0a752011-03-30 18:16:51 +0000292 strm.Printf(" Triple: %s\n", arch.GetTriple().str().c_str());
Greg Clayton1cb64962011-03-24 04:28:38 +0000293 }
294
295 if (GetOSVersion(major, minor, update))
296 {
Greg Clayton32e0a752011-03-30 18:16:51 +0000297 strm.Printf("OS Version: %u", major);
Greg Clayton1cb64962011-03-24 04:28:38 +0000298 if (minor != UINT32_MAX)
299 strm.Printf(".%u", minor);
300 if (update != UINT32_MAX)
301 strm.Printf(".%u", update);
302
303 if (GetOSBuildString (s))
304 strm.Printf(" (%s)", s.c_str());
305
306 strm.EOL();
307 }
308
309 if (GetOSKernelDescription (s))
Greg Clayton32e0a752011-03-30 18:16:51 +0000310 strm.Printf(" Kernel: %s\n", s.c_str());
Greg Clayton1cb64962011-03-24 04:28:38 +0000311
312 if (IsHost())
313 {
Greg Clayton32e0a752011-03-30 18:16:51 +0000314 strm.Printf(" Hostname: %s\n", GetHostname());
Greg Clayton1cb64962011-03-24 04:28:38 +0000315 }
316 else
317 {
Greg Clayton32e0a752011-03-30 18:16:51 +0000318 const bool is_connected = IsConnected();
319 if (is_connected)
320 strm.Printf(" Hostname: %s\n", GetHostname());
321 strm.Printf(" Connected: %s\n", is_connected ? "yes" : "no");
Greg Clayton1cb64962011-03-24 04:28:38 +0000322 }
Daniel Maleae0f8f572013-08-26 23:57:52 +0000323
Greg Claytonfbb76342013-11-20 21:07:01 +0000324 if (GetWorkingDirectory())
325 {
326 strm.Printf("WorkingDir: %s\n", GetWorkingDirectory().GetCString());
327 }
Daniel Maleae0f8f572013-08-26 23:57:52 +0000328 if (!IsConnected())
329 return;
330
331 std::string specific_info(GetPlatformSpecificConnectionInformation());
332
333 if (specific_info.empty() == false)
334 strm.Printf("Platform-specific connection: %s\n", specific_info.c_str());
Greg Clayton1cb64962011-03-24 04:28:38 +0000335}
336
Greg Claytonded470d2011-03-19 01:12:21 +0000337
338bool
339Platform::GetOSVersion (uint32_t &major,
340 uint32_t &minor,
341 uint32_t &update)
342{
343 bool success = m_major_os_version != UINT32_MAX;
344 if (IsHost())
345 {
346 if (!success)
347 {
348 // We have a local host platform
349 success = Host::GetOSVersion (m_major_os_version,
350 m_minor_os_version,
351 m_update_os_version);
352 m_os_version_set_while_connected = success;
353 }
354 }
355 else
356 {
357 // We have a remote platform. We can only fetch the remote
358 // OS version if we are connected, and we don't want to do it
359 // more than once.
360
361 const bool is_connected = IsConnected();
362
Greg Clayton1cb64962011-03-24 04:28:38 +0000363 bool fetch = false;
Greg Claytonded470d2011-03-19 01:12:21 +0000364 if (success)
365 {
366 // We have valid OS version info, check to make sure it wasn't
367 // manually set prior to connecting. If it was manually set prior
368 // to connecting, then lets fetch the actual OS version info
369 // if we are now connected.
370 if (is_connected && !m_os_version_set_while_connected)
Greg Clayton1cb64962011-03-24 04:28:38 +0000371 fetch = true;
Greg Claytonded470d2011-03-19 01:12:21 +0000372 }
373 else
374 {
375 // We don't have valid OS version info, fetch it if we are connected
Greg Clayton1cb64962011-03-24 04:28:38 +0000376 fetch = is_connected;
Greg Claytonded470d2011-03-19 01:12:21 +0000377 }
378
Greg Clayton1cb64962011-03-24 04:28:38 +0000379 if (fetch)
Greg Claytonded470d2011-03-19 01:12:21 +0000380 {
Greg Clayton1cb64962011-03-24 04:28:38 +0000381 success = GetRemoteOSVersion ();
Greg Claytonded470d2011-03-19 01:12:21 +0000382 m_os_version_set_while_connected = success;
383 }
384 }
385
386 if (success)
387 {
388 major = m_major_os_version;
389 minor = m_minor_os_version;
390 update = m_update_os_version;
391 }
392 return success;
393}
Greg Clayton1cb64962011-03-24 04:28:38 +0000394
395bool
396Platform::GetOSBuildString (std::string &s)
397{
398 if (IsHost())
399 return Host::GetOSBuildString (s);
400 else
401 return GetRemoteOSBuildString (s);
402}
403
404bool
405Platform::GetOSKernelDescription (std::string &s)
406{
407 if (IsHost())
408 return Host::GetOSKernelDescription (s);
409 else
410 return GetRemoteOSKernelDescription (s);
411}
412
Greg Clayton57abc5d2013-05-10 21:47:16 +0000413ConstString
Greg Claytonfbb76342013-11-20 21:07:01 +0000414Platform::GetWorkingDirectory ()
415{
416 if (IsHost())
417 {
418 char cwd[PATH_MAX];
419 if (getcwd(cwd, sizeof(cwd)))
420 return ConstString(cwd);
421 else
422 return ConstString();
423 }
424 else
425 {
426 if (!m_working_dir)
427 m_working_dir = GetRemoteWorkingDirectory();
428 return m_working_dir;
429 }
430}
431
432
433struct RecurseCopyBaton
434{
435 const FileSpec& dst;
436 Platform *platform_ptr;
437 Error error;
438};
439
440
441static FileSpec::EnumerateDirectoryResult
442RecurseCopy_Callback (void *baton,
443 FileSpec::FileType file_type,
444 const FileSpec &src)
445{
446 RecurseCopyBaton* rc_baton = (RecurseCopyBaton*)baton;
447 switch (file_type)
448 {
449 case FileSpec::eFileTypePipe:
450 case FileSpec::eFileTypeSocket:
451 // we have no way to copy pipes and sockets - ignore them and continue
452 return FileSpec::eEnumerateDirectoryResultNext;
453 break;
454
455 case FileSpec::eFileTypeDirectory:
456 {
457 // make the new directory and get in there
458 FileSpec dst_dir = rc_baton->dst;
459 if (!dst_dir.GetFilename())
460 dst_dir.GetFilename() = src.GetLastPathComponent();
461 std::string dst_dir_path (dst_dir.GetPath());
462 Error error = rc_baton->platform_ptr->MakeDirectory(dst_dir_path.c_str(), lldb::eFilePermissionsDirectoryDefault);
463 if (error.Fail())
464 {
465 rc_baton->error.SetErrorStringWithFormat("unable to setup directory %s on remote end", dst_dir_path.c_str());
466 return FileSpec::eEnumerateDirectoryResultQuit; // got an error, bail out
467 }
468
469 // now recurse
470 std::string src_dir_path (src.GetPath());
471
472 // Make a filespec that only fills in the directory of a FileSpec so
473 // when we enumerate we can quickly fill in the filename for dst copies
474 FileSpec recurse_dst;
475 recurse_dst.GetDirectory().SetCString(dst_dir.GetPath().c_str());
476 RecurseCopyBaton rc_baton2 = { recurse_dst, rc_baton->platform_ptr, Error() };
477 FileSpec::EnumerateDirectory(src_dir_path.c_str(), true, true, true, RecurseCopy_Callback, &rc_baton2);
478 if (rc_baton2.error.Fail())
479 {
480 rc_baton->error.SetErrorString(rc_baton2.error.AsCString());
481 return FileSpec::eEnumerateDirectoryResultQuit; // got an error, bail out
482 }
483 return FileSpec::eEnumerateDirectoryResultNext;
484 }
485 break;
486
487 case FileSpec::eFileTypeSymbolicLink:
488 {
489 // copy the file and keep going
490 FileSpec dst_file = rc_baton->dst;
491 if (!dst_file.GetFilename())
492 dst_file.GetFilename() = src.GetFilename();
493
494 char buf[PATH_MAX];
495
496 rc_baton->error = Host::Readlink (src.GetPath().c_str(), buf, sizeof(buf));
497
498 if (rc_baton->error.Fail())
499 return FileSpec::eEnumerateDirectoryResultQuit; // got an error, bail out
500
501 rc_baton->error = rc_baton->platform_ptr->CreateSymlink(dst_file.GetPath().c_str(), buf);
502
503 if (rc_baton->error.Fail())
504 return FileSpec::eEnumerateDirectoryResultQuit; // got an error, bail out
505
506 return FileSpec::eEnumerateDirectoryResultNext;
507 }
508 break;
509 case FileSpec::eFileTypeRegular:
510 {
511 // copy the file and keep going
512 FileSpec dst_file = rc_baton->dst;
513 if (!dst_file.GetFilename())
514 dst_file.GetFilename() = src.GetFilename();
515 Error err = rc_baton->platform_ptr->PutFile(src, dst_file);
516 if (err.Fail())
517 {
518 rc_baton->error.SetErrorString(err.AsCString());
519 return FileSpec::eEnumerateDirectoryResultQuit; // got an error, bail out
520 }
521 return FileSpec::eEnumerateDirectoryResultNext;
522 }
523 break;
524
525 case FileSpec::eFileTypeInvalid:
526 case FileSpec::eFileTypeOther:
527 case FileSpec::eFileTypeUnknown:
528 rc_baton->error.SetErrorStringWithFormat("invalid file detected during copy: %s", src.GetPath().c_str());
529 return FileSpec::eEnumerateDirectoryResultQuit; // got an error, bail out
530 break;
531 }
532}
533
534Error
535Platform::Install (const FileSpec& src, const FileSpec& dst)
536{
537 Error error;
538
539 Log *log = GetLogIfAnyCategoriesSet(LIBLLDB_LOG_PLATFORM);
540 if (log)
541 log->Printf ("Platform::Install (src='%s', dst='%s')", src.GetPath().c_str(), dst.GetPath().c_str());
542 FileSpec fixed_dst(dst);
543
544 if (!fixed_dst.GetFilename())
545 fixed_dst.GetFilename() = src.GetFilename();
546
547 ConstString working_dir = GetWorkingDirectory();
548
549 if (dst)
550 {
551 if (dst.GetDirectory())
552 {
553 const char first_dst_dir_char = dst.GetDirectory().GetCString()[0];
554 if (first_dst_dir_char == '/' || first_dst_dir_char == '\\')
555 {
556 fixed_dst.GetDirectory() = dst.GetDirectory();
557 }
558 // If the fixed destination file doesn't have a directory yet,
559 // then we must have a relative path. We will resolve this relative
560 // path against the platform's working directory
561 if (!fixed_dst.GetDirectory())
562 {
563 FileSpec relative_spec;
564 std::string path;
565 if (working_dir)
566 {
567 relative_spec.SetFile(working_dir.GetCString(), false);
568 relative_spec.AppendPathComponent(dst.GetPath().c_str());
569 fixed_dst.GetDirectory() = relative_spec.GetDirectory();
570 }
571 else
572 {
573 error.SetErrorStringWithFormat("platform working directory must be valid for relative path '%s'", dst.GetPath().c_str());
574 return error;
575 }
576 }
577 }
578 else
579 {
580 if (working_dir)
581 {
582 fixed_dst.GetDirectory() = working_dir;
583 }
584 else
585 {
586 error.SetErrorStringWithFormat("platform working directory must be valid for relative path '%s'", dst.GetPath().c_str());
587 return error;
588 }
589 }
590 }
591 else
592 {
593 if (working_dir)
594 {
595 fixed_dst.GetDirectory() = working_dir;
596 }
597 else
598 {
599 error.SetErrorStringWithFormat("platform working directory must be valid when destination directory is empty");
600 return error;
601 }
602 }
603
604 if (log)
605 log->Printf ("Platform::Install (src='%s', dst='%s') fixed_dst='%s'", src.GetPath().c_str(), dst.GetPath().c_str(), fixed_dst.GetPath().c_str());
606
607 if (GetSupportsRSync())
608 {
609 error = PutFile(src, dst);
610 }
611 else
612 {
613 switch (src.GetFileType())
614 {
615 case FileSpec::eFileTypeDirectory:
616 {
617 if (GetFileExists (fixed_dst))
618 Unlink (fixed_dst.GetPath().c_str());
619 uint32_t permissions = src.GetPermissions();
620 if (permissions == 0)
621 permissions = eFilePermissionsDirectoryDefault;
622 std::string dst_dir_path(fixed_dst.GetPath());
623 error = MakeDirectory(dst_dir_path.c_str(), permissions);
624 if (error.Success())
625 {
626 // Make a filespec that only fills in the directory of a FileSpec so
627 // when we enumerate we can quickly fill in the filename for dst copies
628 FileSpec recurse_dst;
629 recurse_dst.GetDirectory().SetCString(dst_dir_path.c_str());
630 std::string src_dir_path (src.GetPath());
631 RecurseCopyBaton baton = { recurse_dst, this, Error() };
632 FileSpec::EnumerateDirectory(src_dir_path.c_str(), true, true, true, RecurseCopy_Callback, &baton);
633 return baton.error;
634 }
635 }
636 break;
637
638 case FileSpec::eFileTypeRegular:
639 if (GetFileExists (fixed_dst))
640 Unlink (fixed_dst.GetPath().c_str());
641 error = PutFile(src, fixed_dst);
642 break;
643
644 case FileSpec::eFileTypeSymbolicLink:
645 {
646 if (GetFileExists (fixed_dst))
647 Unlink (fixed_dst.GetPath().c_str());
648 char buf[PATH_MAX];
649 error = Host::Readlink(src.GetPath().c_str(), buf, sizeof(buf));
650 if (error.Success())
651 error = CreateSymlink(dst.GetPath().c_str(), buf);
652 }
653 break;
654 case FileSpec::eFileTypePipe:
655 error.SetErrorString("platform install doesn't handle pipes");
656 break;
657 case FileSpec::eFileTypeSocket:
658 error.SetErrorString("platform install doesn't handle sockets");
659 break;
660 case FileSpec::eFileTypeInvalid:
661 case FileSpec::eFileTypeUnknown:
662 case FileSpec::eFileTypeOther:
663 error.SetErrorString("platform install doesn't handle non file or directory items");
664 break;
665 }
666 }
667 return error;
668}
669
670bool
671Platform::SetWorkingDirectory (const ConstString &path)
672{
673 if (IsHost())
674 {
Greg Clayton5fb8f792013-12-02 19:35:49 +0000675 Log *log = GetLogIfAnyCategoriesSet(LIBLLDB_LOG_PLATFORM);
676 if (log)
677 log->Printf("Platform::SetWorkingDirectory('%s')", path.GetCString());
Colin Riley909bb7a2013-11-26 15:10:46 +0000678#ifdef _WIN32
679 // Not implemented on Windows
680 return false;
681#else
Greg Claytonfbb76342013-11-20 21:07:01 +0000682 if (path)
683 {
684 if (chdir(path.GetCString()) == 0)
685 return true;
686 }
687 return false;
Colin Riley909bb7a2013-11-26 15:10:46 +0000688#endif
Greg Claytonfbb76342013-11-20 21:07:01 +0000689 }
690 else
691 {
Greg Clayton5fb8f792013-12-02 19:35:49 +0000692 m_working_dir.Clear();
Greg Claytonfbb76342013-11-20 21:07:01 +0000693 return SetRemoteWorkingDirectory(path);
694 }
695}
696
697Error
698Platform::MakeDirectory (const char *path, uint32_t permissions)
699{
700 if (IsHost())
701 return Host::MakeDirectory (path, permissions);
702 else
703 {
704 Error error;
705 error.SetErrorStringWithFormat("remote platform %s doesn't support %s", GetPluginName().GetCString(), __PRETTY_FUNCTION__);
706 return error;
707 }
708}
709
710Error
711Platform::GetFilePermissions (const char *path, uint32_t &file_permissions)
712{
713 if (IsHost())
714 return Host::GetFilePermissions(path, file_permissions);
715 else
716 {
717 Error error;
718 error.SetErrorStringWithFormat("remote platform %s doesn't support %s", GetPluginName().GetCString(), __PRETTY_FUNCTION__);
719 return error;
720 }
721}
722
723Error
724Platform::SetFilePermissions (const char *path, uint32_t file_permissions)
725{
726 if (IsHost())
727 return Host::SetFilePermissions(path, file_permissions);
728 else
729 {
730 Error error;
731 error.SetErrorStringWithFormat("remote platform %s doesn't support %s", GetPluginName().GetCString(), __PRETTY_FUNCTION__);
732 return error;
733 }
734}
735
736ConstString
Greg Clayton8b82f082011-04-12 05:54:46 +0000737Platform::GetName ()
738{
Greg Claytonfbb76342013-11-20 21:07:01 +0000739 return GetPluginName();
Greg Clayton8b82f082011-04-12 05:54:46 +0000740}
741
742const char *
Greg Clayton1cb64962011-03-24 04:28:38 +0000743Platform::GetHostname ()
744{
Greg Claytonab65b342011-04-13 22:47:15 +0000745 if (IsHost())
746 return "localhost";
Greg Clayton32e0a752011-03-30 18:16:51 +0000747
748 if (m_name.empty())
749 return NULL;
750 return m_name.c_str();
751}
752
Greg Clayton5fb8f792013-12-02 19:35:49 +0000753bool
754Platform::SetRemoteWorkingDirectory(const ConstString &path)
755{
756 Log *log = GetLogIfAnyCategoriesSet(LIBLLDB_LOG_PLATFORM);
757 if (log)
758 log->Printf("Platform::SetRemoteWorkingDirectory('%s')", path.GetCString());
759 m_working_dir = path;
760 return true;
761}
762
Greg Clayton32e0a752011-03-30 18:16:51 +0000763const char *
764Platform::GetUserName (uint32_t uid)
765{
766 const char *user_name = GetCachedUserName(uid);
767 if (user_name)
768 return user_name;
769 if (IsHost())
770 {
771 std::string name;
772 if (Host::GetUserName(uid, name))
773 return SetCachedUserName (uid, name.c_str(), name.size());
774 }
Greg Clayton1cb64962011-03-24 04:28:38 +0000775 return NULL;
776}
777
Greg Clayton32e0a752011-03-30 18:16:51 +0000778const char *
779Platform::GetGroupName (uint32_t gid)
780{
781 const char *group_name = GetCachedGroupName(gid);
782 if (group_name)
783 return group_name;
784 if (IsHost())
785 {
786 std::string name;
787 if (Host::GetGroupName(gid, name))
788 return SetCachedGroupName (gid, name.c_str(), name.size());
789 }
790 return NULL;
791}
Greg Clayton1cb64962011-03-24 04:28:38 +0000792
Greg Claytonded470d2011-03-19 01:12:21 +0000793bool
794Platform::SetOSVersion (uint32_t major,
795 uint32_t minor,
796 uint32_t update)
797{
798 if (IsHost())
799 {
800 // We don't need anyone setting the OS version for the host platform,
801 // we should be able to figure it out by calling Host::GetOSVersion(...).
802 return false;
803 }
804 else
805 {
806 // We have a remote platform, allow setting the target OS version if
807 // we aren't connected, since if we are connected, we should be able to
808 // request the remote OS version from the connected platform.
809 if (IsConnected())
810 return false;
811 else
812 {
813 // We aren't connected and we might want to set the OS version
814 // ahead of time before we connect so we can peruse files and
815 // use a local SDK or PDK cache of support files to disassemble
816 // or do other things.
817 m_major_os_version = major;
818 m_minor_os_version = minor;
819 m_update_os_version = update;
820 return true;
821 }
822 }
823 return false;
824}
825
826
Greg Claytone996fd32011-03-08 22:40:15 +0000827Error
828Platform::ResolveExecutable (const FileSpec &exe_file,
829 const ArchSpec &exe_arch,
Greg Claytonc859e2d2012-02-13 23:10:39 +0000830 lldb::ModuleSP &exe_module_sp,
831 const FileSpecList *module_search_paths_ptr)
Greg Claytone996fd32011-03-08 22:40:15 +0000832{
833 Error error;
834 if (exe_file.Exists())
835 {
Greg Claytonb9a01b32012-02-26 05:51:37 +0000836 ModuleSpec module_spec (exe_file, exe_arch);
837 if (module_spec.GetArchitecture().IsValid())
Greg Claytone996fd32011-03-08 22:40:15 +0000838 {
Greg Claytonb9a01b32012-02-26 05:51:37 +0000839 error = ModuleList::GetSharedModule (module_spec,
Greg Claytone996fd32011-03-08 22:40:15 +0000840 exe_module_sp,
Greg Claytonc859e2d2012-02-13 23:10:39 +0000841 module_search_paths_ptr,
Greg Claytone996fd32011-03-08 22:40:15 +0000842 NULL,
843 NULL);
844 }
845 else
846 {
847 // No valid architecture was specified, ask the platform for
848 // the architectures that we should be using (in the correct order)
849 // and see if we can find a match that way
Greg Claytonb9a01b32012-02-26 05:51:37 +0000850 for (uint32_t idx = 0; GetSupportedArchitectureAtIndex (idx, module_spec.GetArchitecture()); ++idx)
Greg Claytone996fd32011-03-08 22:40:15 +0000851 {
Greg Claytonb9a01b32012-02-26 05:51:37 +0000852 error = ModuleList::GetSharedModule (module_spec,
Greg Claytone996fd32011-03-08 22:40:15 +0000853 exe_module_sp,
Greg Claytonc859e2d2012-02-13 23:10:39 +0000854 module_search_paths_ptr,
Greg Claytone996fd32011-03-08 22:40:15 +0000855 NULL,
856 NULL);
857 // Did we find an executable using one of the
858 if (error.Success() && exe_module_sp)
859 break;
860 }
861 }
862 }
863 else
864 {
Greg Claytonb5ad4ec2013-04-29 17:25:54 +0000865 error.SetErrorStringWithFormat ("'%s' does not exist",
866 exe_file.GetPath().c_str());
Greg Claytone996fd32011-03-08 22:40:15 +0000867 }
868 return error;
869}
870
Greg Clayton103f0282012-09-12 02:03:59 +0000871Error
872Platform::ResolveSymbolFile (Target &target,
873 const ModuleSpec &sym_spec,
874 FileSpec &sym_file)
875{
876 Error error;
877 if (sym_spec.GetSymbolFileSpec().Exists())
878 sym_file = sym_spec.GetSymbolFileSpec();
879 else
880 error.SetErrorString("unable to resolve symbol file");
881 return error;
882
883}
884
885
886
Greg Claytonaa516842011-08-11 16:25:18 +0000887bool
888Platform::ResolveRemotePath (const FileSpec &platform_path,
889 FileSpec &resolved_platform_path)
890{
891 resolved_platform_path = platform_path;
892 return resolved_platform_path.ResolvePath();
893}
894
Greg Claytonded470d2011-03-19 01:12:21 +0000895
896const ArchSpec &
897Platform::GetSystemArchitecture()
898{
899 if (IsHost())
900 {
901 if (!m_system_arch.IsValid())
902 {
903 // We have a local host platform
904 m_system_arch = Host::GetArchitecture();
905 m_system_arch_set_while_connected = m_system_arch.IsValid();
906 }
907 }
908 else
909 {
910 // We have a remote platform. We can only fetch the remote
911 // system architecture if we are connected, and we don't want to do it
912 // more than once.
913
914 const bool is_connected = IsConnected();
915
916 bool fetch = false;
917 if (m_system_arch.IsValid())
918 {
919 // We have valid OS version info, check to make sure it wasn't
920 // manually set prior to connecting. If it was manually set prior
921 // to connecting, then lets fetch the actual OS version info
922 // if we are now connected.
923 if (is_connected && !m_system_arch_set_while_connected)
924 fetch = true;
925 }
926 else
927 {
928 // We don't have valid OS version info, fetch it if we are connected
929 fetch = is_connected;
930 }
931
932 if (fetch)
933 {
Greg Clayton1cb64962011-03-24 04:28:38 +0000934 m_system_arch = GetRemoteSystemArchitecture ();
Greg Claytonded470d2011-03-19 01:12:21 +0000935 m_system_arch_set_while_connected = m_system_arch.IsValid();
936 }
937 }
938 return m_system_arch;
939}
940
941
Greg Claytone996fd32011-03-08 22:40:15 +0000942Error
Greg Claytond314e812011-03-23 00:09:55 +0000943Platform::ConnectRemote (Args& args)
Greg Claytone996fd32011-03-08 22:40:15 +0000944{
945 Error error;
Greg Claytond314e812011-03-23 00:09:55 +0000946 if (IsHost())
Greg Clayton57abc5d2013-05-10 21:47:16 +0000947 error.SetErrorStringWithFormat ("The currently selected platform (%s) is the host platform and is always connected.", GetPluginName().GetCString());
Greg Claytond314e812011-03-23 00:09:55 +0000948 else
Greg Clayton57abc5d2013-05-10 21:47:16 +0000949 error.SetErrorStringWithFormat ("Platform::ConnectRemote() is not supported by %s", GetPluginName().GetCString());
Greg Claytone996fd32011-03-08 22:40:15 +0000950 return error;
951}
952
953Error
Greg Claytond314e812011-03-23 00:09:55 +0000954Platform::DisconnectRemote ()
Greg Claytone996fd32011-03-08 22:40:15 +0000955{
956 Error error;
Greg Claytond314e812011-03-23 00:09:55 +0000957 if (IsHost())
Greg Clayton57abc5d2013-05-10 21:47:16 +0000958 error.SetErrorStringWithFormat ("The currently selected platform (%s) is the host platform and is always connected.", GetPluginName().GetCString());
Greg Claytond314e812011-03-23 00:09:55 +0000959 else
Greg Clayton57abc5d2013-05-10 21:47:16 +0000960 error.SetErrorStringWithFormat ("Platform::DisconnectRemote() is not supported by %s", GetPluginName().GetCString());
Greg Claytone996fd32011-03-08 22:40:15 +0000961 return error;
962}
Greg Clayton32e0a752011-03-30 18:16:51 +0000963
964bool
Greg Clayton8b82f082011-04-12 05:54:46 +0000965Platform::GetProcessInfo (lldb::pid_t pid, ProcessInstanceInfo &process_info)
Greg Clayton32e0a752011-03-30 18:16:51 +0000966{
967 // Take care of the host case so that each subclass can just
Greg Clayton8b82f082011-04-12 05:54:46 +0000968 // call this function to get the host functionality.
Greg Clayton32e0a752011-03-30 18:16:51 +0000969 if (IsHost())
970 return Host::GetProcessInfo (pid, process_info);
971 return false;
972}
973
974uint32_t
Greg Clayton8b82f082011-04-12 05:54:46 +0000975Platform::FindProcesses (const ProcessInstanceInfoMatch &match_info,
976 ProcessInstanceInfoList &process_infos)
Greg Clayton32e0a752011-03-30 18:16:51 +0000977{
Greg Clayton8b82f082011-04-12 05:54:46 +0000978 // Take care of the host case so that each subclass can just
979 // call this function to get the host functionality.
Greg Clayton32e0a752011-03-30 18:16:51 +0000980 uint32_t match_count = 0;
981 if (IsHost())
982 match_count = Host::FindProcesses (match_info, process_infos);
983 return match_count;
984}
Greg Clayton8b82f082011-04-12 05:54:46 +0000985
986
987Error
988Platform::LaunchProcess (ProcessLaunchInfo &launch_info)
989{
990 Error error;
991 // Take care of the host case so that each subclass can just
992 // call this function to get the host functionality.
993 if (IsHost())
Greg Clayton84db9102012-03-26 23:03:23 +0000994 {
995 if (::getenv ("LLDB_LAUNCH_FLAG_LAUNCH_IN_TTY"))
996 launch_info.GetFlags().Set (eLaunchFlagLaunchInTTY);
997
998 if (launch_info.GetFlags().Test (eLaunchFlagLaunchInShell))
999 {
1000 const bool is_localhost = true;
Greg Claytond1cf11a2012-04-14 01:42:46 +00001001 const bool will_debug = launch_info.GetFlags().Test(eLaunchFlagDebug);
1002 const bool first_arg_is_full_shell_command = false;
Jim Inghamd3990792013-09-11 18:23:22 +00001003 uint32_t num_resumes = GetResumeCountForLaunchInfo (launch_info);
Greg Claytond1cf11a2012-04-14 01:42:46 +00001004 if (!launch_info.ConvertArgumentsForLaunchingInShell (error,
1005 is_localhost,
1006 will_debug,
Jim Inghamdf0ae222013-09-10 02:09:47 +00001007 first_arg_is_full_shell_command,
1008 num_resumes))
Greg Clayton84db9102012-03-26 23:03:23 +00001009 return error;
1010 }
1011
Greg Clayton8b82f082011-04-12 05:54:46 +00001012 error = Host::LaunchProcess (launch_info);
Greg Clayton84db9102012-03-26 23:03:23 +00001013 }
Greg Clayton8b82f082011-04-12 05:54:46 +00001014 else
1015 error.SetErrorString ("base lldb_private::Platform class can't launch remote processes");
1016 return error;
1017}
1018
1019lldb::ProcessSP
1020Platform::DebugProcess (ProcessLaunchInfo &launch_info,
1021 Debugger &debugger,
1022 Target *target, // Can be NULL, if NULL create a new target, else use existing one
1023 Listener &listener,
1024 Error &error)
1025{
1026 ProcessSP process_sp;
1027 // Make sure we stop at the entry point
1028 launch_info.GetFlags ().Set (eLaunchFlagDebug);
Jim Inghamb4451b12012-06-01 01:22:13 +00001029 // We always launch the process we are going to debug in a separate process
1030 // group, since then we can handle ^C interrupts ourselves w/o having to worry
1031 // about the target getting them as well.
1032 launch_info.SetLaunchInSeparateProcessGroup(true);
1033
Greg Clayton8b82f082011-04-12 05:54:46 +00001034 error = LaunchProcess (launch_info);
1035 if (error.Success())
1036 {
Greg Clayton144f3a92011-11-15 03:53:30 +00001037 if (launch_info.GetProcessID() != LLDB_INVALID_PROCESS_ID)
Greg Clayton8b82f082011-04-12 05:54:46 +00001038 {
Greg Clayton144f3a92011-11-15 03:53:30 +00001039 ProcessAttachInfo attach_info (launch_info);
1040 process_sp = Attach (attach_info, debugger, target, listener, error);
Greg Claytone24c4ac2011-11-17 04:46:02 +00001041 if (process_sp)
1042 {
Greg Clayton44d93782014-01-27 23:43:24 +00001043 launch_info.SetHijackListener(attach_info.GetHijackListener());
1044
Greg Claytone24c4ac2011-11-17 04:46:02 +00001045 // Since we attached to the process, it will think it needs to detach
1046 // if the process object just goes away without an explicit call to
1047 // Process::Kill() or Process::Detach(), so let it know to kill the
1048 // process if this happens.
1049 process_sp->SetShouldDetach (false);
Greg Claytonee95ed52011-11-17 22:14:31 +00001050
1051 // If we didn't have any file actions, the pseudo terminal might
1052 // have been used where the slave side was given as the file to
1053 // open for stdin/out/err after we have already opened the master
1054 // so we can read/write stdin/out/err.
1055 int pty_fd = launch_info.GetPTY().ReleaseMasterFileDescriptor();
1056 if (pty_fd != lldb_utility::PseudoTerminal::invalid_fd)
1057 {
1058 process_sp->SetSTDIOFileDescriptor(pty_fd);
1059 }
Greg Claytone24c4ac2011-11-17 04:46:02 +00001060 }
Greg Clayton8b82f082011-04-12 05:54:46 +00001061 }
1062 }
1063 return process_sp;
1064}
Greg Claytonb3a40ba2012-03-20 18:34:04 +00001065
1066
1067lldb::PlatformSP
Greg Clayton70512312012-05-08 01:45:38 +00001068Platform::GetPlatformForArchitecture (const ArchSpec &arch, ArchSpec *platform_arch_ptr)
Greg Claytonb3a40ba2012-03-20 18:34:04 +00001069{
1070 lldb::PlatformSP platform_sp;
1071 Error error;
1072 if (arch.IsValid())
Greg Clayton70512312012-05-08 01:45:38 +00001073 platform_sp = Platform::Create (arch, platform_arch_ptr, error);
Greg Claytonb3a40ba2012-03-20 18:34:04 +00001074 return platform_sp;
1075}
1076
1077
1078//------------------------------------------------------------------
1079/// Lets a platform answer if it is compatible with a given
1080/// architecture and the target triple contained within.
1081//------------------------------------------------------------------
1082bool
Greg Clayton1e0c8842013-01-11 20:49:54 +00001083Platform::IsCompatibleArchitecture (const ArchSpec &arch, bool exact_arch_match, ArchSpec *compatible_arch_ptr)
Greg Claytonb3a40ba2012-03-20 18:34:04 +00001084{
1085 // If the architecture is invalid, we must answer true...
Greg Clayton70512312012-05-08 01:45:38 +00001086 if (arch.IsValid())
Greg Claytonb3a40ba2012-03-20 18:34:04 +00001087 {
Greg Clayton70512312012-05-08 01:45:38 +00001088 ArchSpec platform_arch;
Greg Clayton1e0c8842013-01-11 20:49:54 +00001089 // Try for an exact architecture match first.
1090 if (exact_arch_match)
Greg Clayton70512312012-05-08 01:45:38 +00001091 {
Greg Clayton1e0c8842013-01-11 20:49:54 +00001092 for (uint32_t arch_idx=0; GetSupportedArchitectureAtIndex (arch_idx, platform_arch); ++arch_idx)
Greg Clayton70512312012-05-08 01:45:38 +00001093 {
Greg Clayton1e0c8842013-01-11 20:49:54 +00001094 if (arch.IsExactMatch(platform_arch))
1095 {
1096 if (compatible_arch_ptr)
1097 *compatible_arch_ptr = platform_arch;
1098 return true;
1099 }
1100 }
1101 }
1102 else
1103 {
1104 for (uint32_t arch_idx=0; GetSupportedArchitectureAtIndex (arch_idx, platform_arch); ++arch_idx)
1105 {
1106 if (arch.IsCompatibleMatch(platform_arch))
1107 {
1108 if (compatible_arch_ptr)
1109 *compatible_arch_ptr = platform_arch;
1110 return true;
1111 }
Greg Clayton70512312012-05-08 01:45:38 +00001112 }
1113 }
Greg Claytonb3a40ba2012-03-20 18:34:04 +00001114 }
Greg Clayton70512312012-05-08 01:45:38 +00001115 if (compatible_arch_ptr)
1116 compatible_arch_ptr->Clear();
Greg Claytonb3a40ba2012-03-20 18:34:04 +00001117 return false;
Greg Claytonb3a40ba2012-03-20 18:34:04 +00001118}
1119
Daniel Maleae0f8f572013-08-26 23:57:52 +00001120Error
1121Platform::PutFile (const FileSpec& source,
1122 const FileSpec& destination,
1123 uint32_t uid,
1124 uint32_t gid)
1125{
1126 Error error("unimplemented");
1127 return error;
1128}
1129
1130Error
1131Platform::GetFile (const FileSpec& source,
1132 const FileSpec& destination)
1133{
1134 Error error("unimplemented");
1135 return error;
1136}
1137
Greg Claytonfbb76342013-11-20 21:07:01 +00001138Error
1139Platform::CreateSymlink (const char *src, // The name of the link is in src
1140 const char *dst)// The symlink points to dst
1141{
1142 Error error("unimplemented");
1143 return error;
1144}
1145
Daniel Maleae0f8f572013-08-26 23:57:52 +00001146bool
1147Platform::GetFileExists (const lldb_private::FileSpec& file_spec)
1148{
1149 return false;
1150}
1151
Greg Claytonfbb76342013-11-20 21:07:01 +00001152Error
1153Platform::Unlink (const char *path)
1154{
1155 Error error("unimplemented");
1156 return error;
1157}
1158
1159
1160
Daniel Maleae0f8f572013-08-26 23:57:52 +00001161lldb_private::Error
1162Platform::RunShellCommand (const char *command, // Shouldn't be NULL
1163 const char *working_dir, // Pass NULL to use the current working directory
1164 int *status_ptr, // Pass NULL if you don't want the process exit status
1165 int *signo_ptr, // Pass NULL if you don't want the signal that caused the process to exit
1166 std::string *command_output, // Pass NULL if you don't want the command output
1167 uint32_t timeout_sec) // Timeout in seconds to wait for shell program to finish
1168{
1169 if (IsHost())
1170 return Host::RunShellCommand (command, working_dir, status_ptr, signo_ptr, command_output, timeout_sec);
1171 else
1172 return Error("unimplemented");
1173}
1174
1175
1176bool
1177Platform::CalculateMD5 (const FileSpec& file_spec,
1178 uint64_t &low,
1179 uint64_t &high)
1180{
1181 if (IsHost())
1182 return Host::CalculateMD5(file_spec, low, high);
1183 else
1184 return false;
1185}
1186
1187void
1188Platform::SetLocalCacheDirectory (const char* local)
1189{
1190 m_local_cache_directory.assign(local);
1191}
1192
1193const char*
1194Platform::GetLocalCacheDirectory ()
1195{
1196 return m_local_cache_directory.c_str();
1197}
1198
1199static OptionDefinition
1200g_rsync_option_table[] =
1201{
Virgile Belloe2607b52013-09-05 16:42:23 +00001202 { LLDB_OPT_SET_ALL, false, "rsync" , 'r', OptionParser::eNoArgument, NULL, 0, eArgTypeNone , "Enable rsync." },
1203 { LLDB_OPT_SET_ALL, false, "rsync-opts" , 'R', OptionParser::eRequiredArgument, NULL, 0, eArgTypeCommandName , "Platform-specific options required for rsync to work." },
1204 { LLDB_OPT_SET_ALL, false, "rsync-prefix" , 'P', OptionParser::eRequiredArgument, NULL, 0, eArgTypeCommandName , "Platform-specific rsync prefix put before the remote path." },
1205 { 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 +00001206};
1207
1208static OptionDefinition
1209g_ssh_option_table[] =
1210{
Virgile Belloe2607b52013-09-05 16:42:23 +00001211 { LLDB_OPT_SET_ALL, false, "ssh" , 's', OptionParser::eNoArgument, NULL, 0, eArgTypeNone , "Enable SSH." },
1212 { 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 +00001213};
1214
1215static OptionDefinition
1216g_caching_option_table[] =
1217{
Virgile Belloe2607b52013-09-05 16:42:23 +00001218 { 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 +00001219};
1220
1221OptionGroupPlatformRSync::OptionGroupPlatformRSync ()
1222{
1223}
1224
1225OptionGroupPlatformRSync::~OptionGroupPlatformRSync ()
1226{
1227}
1228
1229const lldb_private::OptionDefinition*
1230OptionGroupPlatformRSync::GetDefinitions ()
1231{
1232 return g_rsync_option_table;
1233}
1234
1235void
1236OptionGroupPlatformRSync::OptionParsingStarting (CommandInterpreter &interpreter)
1237{
1238 m_rsync = false;
1239 m_rsync_opts.clear();
1240 m_rsync_prefix.clear();
1241 m_ignores_remote_hostname = false;
1242}
1243
1244lldb_private::Error
1245OptionGroupPlatformRSync::SetOptionValue (CommandInterpreter &interpreter,
1246 uint32_t option_idx,
1247 const char *option_arg)
1248{
1249 Error error;
1250 char short_option = (char) GetDefinitions()[option_idx].short_option;
1251 switch (short_option)
1252 {
1253 case 'r':
1254 m_rsync = true;
1255 break;
1256
1257 case 'R':
1258 m_rsync_opts.assign(option_arg);
1259 break;
1260
1261 case 'P':
1262 m_rsync_prefix.assign(option_arg);
1263 break;
1264
1265 case 'i':
1266 m_ignores_remote_hostname = true;
1267 break;
1268
1269 default:
1270 error.SetErrorStringWithFormat ("unrecognized option '%c'", short_option);
1271 break;
1272 }
1273
1274 return error;
1275}
1276
1277uint32_t
1278OptionGroupPlatformRSync::GetNumDefinitions ()
1279{
1280 return llvm::array_lengthof(g_rsync_option_table);
1281}
Greg Clayton1e0c8842013-01-11 20:49:54 +00001282
Greg Clayton4116e932012-05-15 02:33:01 +00001283lldb::BreakpointSP
1284Platform::SetThreadCreationBreakpoint (lldb_private::Target &target)
1285{
1286 return lldb::BreakpointSP();
1287}
Greg Claytonb3a40ba2012-03-20 18:34:04 +00001288
Daniel Maleae0f8f572013-08-26 23:57:52 +00001289OptionGroupPlatformSSH::OptionGroupPlatformSSH ()
1290{
1291}
1292
1293OptionGroupPlatformSSH::~OptionGroupPlatformSSH ()
1294{
1295}
1296
1297const lldb_private::OptionDefinition*
1298OptionGroupPlatformSSH::GetDefinitions ()
1299{
1300 return g_ssh_option_table;
1301}
1302
1303void
1304OptionGroupPlatformSSH::OptionParsingStarting (CommandInterpreter &interpreter)
1305{
1306 m_ssh = false;
1307 m_ssh_opts.clear();
1308}
1309
1310lldb_private::Error
1311OptionGroupPlatformSSH::SetOptionValue (CommandInterpreter &interpreter,
1312 uint32_t option_idx,
1313 const char *option_arg)
1314{
1315 Error error;
1316 char short_option = (char) GetDefinitions()[option_idx].short_option;
1317 switch (short_option)
1318 {
1319 case 's':
1320 m_ssh = true;
1321 break;
1322
1323 case 'S':
1324 m_ssh_opts.assign(option_arg);
1325 break;
1326
1327 default:
1328 error.SetErrorStringWithFormat ("unrecognized option '%c'", short_option);
1329 break;
1330 }
1331
1332 return error;
1333}
1334
1335uint32_t
1336OptionGroupPlatformSSH::GetNumDefinitions ()
1337{
1338 return llvm::array_lengthof(g_ssh_option_table);
1339}
1340
1341OptionGroupPlatformCaching::OptionGroupPlatformCaching ()
1342{
1343}
1344
1345OptionGroupPlatformCaching::~OptionGroupPlatformCaching ()
1346{
1347}
1348
1349const lldb_private::OptionDefinition*
1350OptionGroupPlatformCaching::GetDefinitions ()
1351{
1352 return g_caching_option_table;
1353}
1354
1355void
1356OptionGroupPlatformCaching::OptionParsingStarting (CommandInterpreter &interpreter)
1357{
1358 m_cache_dir.clear();
1359}
1360
1361lldb_private::Error
1362OptionGroupPlatformCaching::SetOptionValue (CommandInterpreter &interpreter,
1363 uint32_t option_idx,
1364 const char *option_arg)
1365{
1366 Error error;
1367 char short_option = (char) GetDefinitions()[option_idx].short_option;
1368 switch (short_option)
1369 {
1370 case 'c':
1371 m_cache_dir.assign(option_arg);
1372 break;
1373
1374 default:
1375 error.SetErrorStringWithFormat ("unrecognized option '%c'", short_option);
1376 break;
1377 }
1378
1379 return error;
1380}
1381
1382uint32_t
1383OptionGroupPlatformCaching::GetNumDefinitions ()
1384{
1385 return llvm::array_lengthof(g_caching_option_table);
1386}
1387
Greg Clayton67cc0632012-08-22 17:17:09 +00001388size_t
1389Platform::GetEnvironment (StringList &environment)
1390{
1391 environment.Clear();
1392 return false;
1393}