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