blob: 6b98ab89f11140d1da532c2c58738690899f65e2 [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"
Enrico Granatad7a83a92015-02-10 03:06:24 +000021#include "lldb/Core/StructuredData.h"
Greg Claytone996fd32011-03-08 22:40:15 +000022#include "lldb/Host/FileSpec.h"
Zachary Turnerc00cf4a2014-08-15 22:04:21 +000023#include "lldb/Host/FileSystem.h"
Greg Claytonded470d2011-03-19 01:12:21 +000024#include "lldb/Host/Host.h"
Zachary Turner97a14e62014-08-19 17:18:29 +000025#include "lldb/Host/HostInfo.h"
Greg Clayton8b82f082011-04-12 05:54:46 +000026#include "lldb/Target/Process.h"
Greg Claytone996fd32011-03-08 22:40:15 +000027#include "lldb/Target/Target.h"
Daniel Maleae0f8f572013-08-26 23:57:52 +000028#include "lldb/Utility/Utils.h"
Greg Claytone996fd32011-03-08 22:40:15 +000029
30using namespace lldb;
31using namespace lldb_private;
Tamas Berghammer3c4f89d2015-02-12 18:18:27 +000032
33static uint32_t g_initialize_count = 0;
34
Greg Claytone996fd32011-03-08 22:40:15 +000035// Use a singleton function for g_local_platform_sp to avoid init
36// constructors since LLDB is often part of a shared library
37static PlatformSP&
Greg Clayton615eb7e2014-09-19 20:11:50 +000038GetHostPlatformSP ()
Greg Claytone996fd32011-03-08 22:40:15 +000039{
Greg Clayton615eb7e2014-09-19 20:11:50 +000040 static PlatformSP g_platform_sp;
41 return g_platform_sp;
Greg Claytone996fd32011-03-08 22:40:15 +000042}
43
Greg Claytonab65b342011-04-13 22:47:15 +000044const char *
45Platform::GetHostPlatformName ()
46{
47 return "host";
48}
49
Greg Claytone996fd32011-03-08 22:40:15 +000050//------------------------------------------------------------------
51/// Get the native host platform plug-in.
52///
53/// There should only be one of these for each host that LLDB runs
54/// upon that should be statically compiled in and registered using
55/// preprocessor macros or other similar build mechanisms.
56///
57/// This platform will be used as the default platform when launching
58/// or attaching to processes unless another platform is specified.
59//------------------------------------------------------------------
60PlatformSP
Greg Clayton615eb7e2014-09-19 20:11:50 +000061Platform::GetHostPlatform ()
Greg Claytone996fd32011-03-08 22:40:15 +000062{
Greg Clayton615eb7e2014-09-19 20:11:50 +000063 return GetHostPlatformSP ();
64}
65
66static std::vector<PlatformSP> &
67GetPlatformList()
68{
69 static std::vector<PlatformSP> g_platform_list;
70 return g_platform_list;
71}
72
73static Mutex &
74GetPlatformListMutex ()
75{
76 static Mutex g_mutex(Mutex::eMutexTypeRecursive);
77 return g_mutex;
Greg Claytone996fd32011-03-08 22:40:15 +000078}
79
80void
Tamas Berghammer3c4f89d2015-02-12 18:18:27 +000081Platform::Initialize ()
82{
83 g_initialize_count++;
84}
85
86void
87Platform::Terminate ()
88{
89 if (g_initialize_count > 0)
90 {
91 if (--g_initialize_count == 0)
92 {
93 Mutex::Locker locker(GetPlatformListMutex ());
94 GetPlatformList().clear();
95 }
96 }
97}
98
99void
Greg Clayton615eb7e2014-09-19 20:11:50 +0000100Platform::SetHostPlatform (const lldb::PlatformSP &platform_sp)
Greg Claytone996fd32011-03-08 22:40:15 +0000101{
102 // The native platform should use its static void Platform::Initialize()
103 // function to register itself as the native platform.
Greg Clayton615eb7e2014-09-19 20:11:50 +0000104 GetHostPlatformSP () = platform_sp;
105
106 if (platform_sp)
107 {
108 Mutex::Locker locker(GetPlatformListMutex ());
109 GetPlatformList().push_back(platform_sp);
110 }
Greg Claytone996fd32011-03-08 22:40:15 +0000111}
112
Greg Claytone996fd32011-03-08 22:40:15 +0000113Error
Steve Puccifc995722014-01-17 18:18:31 +0000114Platform::GetFileWithUUID (const FileSpec &platform_file,
115 const UUID *uuid_ptr,
116 FileSpec &local_file)
Greg Claytone996fd32011-03-08 22:40:15 +0000117{
118 // Default to the local case
119 local_file = platform_file;
120 return Error();
121}
122
Greg Clayton91c0e742013-01-11 23:44:27 +0000123FileSpecList
Enrico Granatafe7295d2014-08-16 00:32:58 +0000124Platform::LocateExecutableScriptingResources (Target *target, Module &module, Stream* feedback_stream)
Enrico Granata17598482012-11-08 02:22:02 +0000125{
Greg Clayton91c0e742013-01-11 23:44:27 +0000126 return FileSpecList();
Enrico Granata17598482012-11-08 02:22:02 +0000127}
128
Greg Clayton615eb7e2014-09-19 20:11:50 +0000129//PlatformSP
130//Platform::FindPlugin (Process *process, const ConstString &plugin_name)
131//{
132// PlatformCreateInstance create_callback = NULL;
133// if (plugin_name)
134// {
135// create_callback = PluginManager::GetPlatformCreateCallbackForPluginName (plugin_name);
136// if (create_callback)
137// {
138// ArchSpec arch;
139// if (process)
140// {
141// arch = process->GetTarget().GetArchitecture();
142// }
143// PlatformSP platform_sp(create_callback(process, &arch));
144// if (platform_sp)
145// return platform_sp;
146// }
147// }
148// else
149// {
150// for (uint32_t idx = 0; (create_callback = PluginManager::GetPlatformCreateCallbackAtIndex(idx)) != NULL; ++idx)
151// {
152// PlatformSP platform_sp(create_callback(process, nullptr));
153// if (platform_sp)
154// return platform_sp;
155// }
156// }
157// return PlatformSP();
158//}
Jason Molenda1c627542013-04-05 01:03:25 +0000159
Greg Clayton32e0a752011-03-30 18:16:51 +0000160Error
Greg Claytonb9a01b32012-02-26 05:51:37 +0000161Platform::GetSharedModule (const ModuleSpec &module_spec,
Greg Clayton32e0a752011-03-30 18:16:51 +0000162 ModuleSP &module_sp,
Greg Claytonc859e2d2012-02-13 23:10:39 +0000163 const FileSpecList *module_search_paths_ptr,
Greg Clayton32e0a752011-03-30 18:16:51 +0000164 ModuleSP *old_module_sp_ptr,
165 bool *did_create_ptr)
166{
167 // Don't do any path remapping for the default implementation
168 // of the platform GetSharedModule function, just call through
169 // to our static ModuleList function. Platform subclasses that
170 // implement remote debugging, might have a developer kits
171 // installed that have cached versions of the files for the
172 // remote target, or might implement a download and cache
173 // locally implementation.
174 const bool always_create = false;
Greg Claytonb9a01b32012-02-26 05:51:37 +0000175 return ModuleList::GetSharedModule (module_spec,
Greg Clayton32e0a752011-03-30 18:16:51 +0000176 module_sp,
Greg Claytonc859e2d2012-02-13 23:10:39 +0000177 module_search_paths_ptr,
Greg Clayton32e0a752011-03-30 18:16:51 +0000178 old_module_sp_ptr,
179 did_create_ptr,
180 always_create);
181}
182
Greg Claytone996fd32011-03-08 22:40:15 +0000183PlatformSP
Greg Clayton615eb7e2014-09-19 20:11:50 +0000184Platform::Find (const ConstString &name)
185{
186 if (name)
187 {
188 static ConstString g_host_platform_name ("host");
189 if (name == g_host_platform_name)
190 return GetHostPlatform();
191
192 Mutex::Locker locker(GetPlatformListMutex ());
193 for (const auto &platform_sp : GetPlatformList())
194 {
195 if (platform_sp->GetName() == name)
196 return platform_sp;
197 }
198 }
199 return PlatformSP();
200}
201
202PlatformSP
203Platform::Create (const ConstString &name, Error &error)
Greg Claytone996fd32011-03-08 22:40:15 +0000204{
205 PlatformCreateInstance create_callback = NULL;
206 lldb::PlatformSP platform_sp;
Greg Clayton615eb7e2014-09-19 20:11:50 +0000207 if (name)
Greg Claytone996fd32011-03-08 22:40:15 +0000208 {
Greg Clayton615eb7e2014-09-19 20:11:50 +0000209 static ConstString g_host_platform_name ("host");
210 if (name == g_host_platform_name)
211 return GetHostPlatform();
212
213 create_callback = PluginManager::GetPlatformCreateCallbackForPluginName (name);
Greg Claytone996fd32011-03-08 22:40:15 +0000214 if (create_callback)
Greg Clayton615eb7e2014-09-19 20:11:50 +0000215 platform_sp = create_callback(true, NULL);
Greg Claytone996fd32011-03-08 22:40:15 +0000216 else
Greg Clayton615eb7e2014-09-19 20:11:50 +0000217 error.SetErrorStringWithFormat ("unable to find a plug-in for the platform named \"%s\"", name.GetCString());
Greg Claytone996fd32011-03-08 22:40:15 +0000218 }
219 else
Greg Claytonded470d2011-03-19 01:12:21 +0000220 error.SetErrorString ("invalid platform name");
Greg Clayton615eb7e2014-09-19 20:11:50 +0000221
222 if (platform_sp)
223 {
224 Mutex::Locker locker(GetPlatformListMutex ());
225 GetPlatformList().push_back(platform_sp);
226 }
227
Greg Claytone996fd32011-03-08 22:40:15 +0000228 return platform_sp;
229}
230
Greg Claytonb3a40ba2012-03-20 18:34:04 +0000231
232PlatformSP
Greg Clayton70512312012-05-08 01:45:38 +0000233Platform::Create (const ArchSpec &arch, ArchSpec *platform_arch_ptr, Error &error)
Greg Claytonb3a40ba2012-03-20 18:34:04 +0000234{
235 lldb::PlatformSP platform_sp;
236 if (arch.IsValid())
237 {
Greg Clayton615eb7e2014-09-19 20:11:50 +0000238 // Scope for locker
Greg Claytonb3a40ba2012-03-20 18:34:04 +0000239 {
Greg Clayton615eb7e2014-09-19 20:11:50 +0000240 // First try exact arch matches across all platforms already created
241 Mutex::Locker locker(GetPlatformListMutex ());
242 for (const auto &platform_sp : GetPlatformList())
Greg Clayton1e0c8842013-01-11 20:49:54 +0000243 {
Greg Clayton615eb7e2014-09-19 20:11:50 +0000244 if (platform_sp->IsCompatibleArchitecture(arch, true, platform_arch_ptr))
245 return platform_sp;
246 }
247
248 // Next try compatible arch matches across all platforms already created
249 for (const auto &platform_sp : GetPlatformList())
250 {
251 if (platform_sp->IsCompatibleArchitecture(arch, false, platform_arch_ptr))
Greg Clayton1e0c8842013-01-11 20:49:54 +0000252 return platform_sp;
253 }
254 }
Greg Clayton615eb7e2014-09-19 20:11:50 +0000255
256 PlatformCreateInstance create_callback;
257 // First try exact arch matches across all platform plug-ins
258 uint32_t idx;
Greg Clayton1e0c8842013-01-11 20:49:54 +0000259 for (idx = 0; (create_callback = PluginManager::GetPlatformCreateCallbackAtIndex (idx)); ++idx)
260 {
261 if (create_callback)
262 {
Greg Clayton615eb7e2014-09-19 20:11:50 +0000263 platform_sp = create_callback(false, &arch);
264 if (platform_sp && platform_sp->IsCompatibleArchitecture(arch, true, platform_arch_ptr))
265 {
266 Mutex::Locker locker(GetPlatformListMutex ());
267 GetPlatformList().push_back(platform_sp);
Greg Clayton1e0c8842013-01-11 20:49:54 +0000268 return platform_sp;
Greg Clayton615eb7e2014-09-19 20:11:50 +0000269 }
270 }
271 }
272 // Next try compatible arch matches across all platform plug-ins
273 for (idx = 0; (create_callback = PluginManager::GetPlatformCreateCallbackAtIndex (idx)); ++idx)
274 {
275 if (create_callback)
276 {
277 platform_sp = create_callback(false, &arch);
278 if (platform_sp && platform_sp->IsCompatibleArchitecture(arch, false, platform_arch_ptr))
279 {
280 Mutex::Locker locker(GetPlatformListMutex ());
281 GetPlatformList().push_back(platform_sp);
282 return platform_sp;
283 }
Greg Clayton1e0c8842013-01-11 20:49:54 +0000284 }
Greg Claytonb3a40ba2012-03-20 18:34:04 +0000285 }
286 }
287 else
288 error.SetErrorString ("invalid platform name");
Greg Clayton70512312012-05-08 01:45:38 +0000289 if (platform_arch_ptr)
290 platform_arch_ptr->Clear();
291 platform_sp.reset();
Greg Claytonb3a40ba2012-03-20 18:34:04 +0000292 return platform_sp;
293}
294
Greg Claytone996fd32011-03-08 22:40:15 +0000295//------------------------------------------------------------------
296/// Default Constructor
297//------------------------------------------------------------------
Greg Claytonded470d2011-03-19 01:12:21 +0000298Platform::Platform (bool is_host) :
299 m_is_host (is_host),
Greg Claytonded470d2011-03-19 01:12:21 +0000300 m_os_version_set_while_connected (false),
301 m_system_arch_set_while_connected (false),
Greg Claytonf3dd93c2011-06-17 03:31:01 +0000302 m_sdk_sysroot (),
303 m_sdk_build (),
Greg Claytonfbb76342013-11-20 21:07:01 +0000304 m_working_dir (),
Greg Claytonded470d2011-03-19 01:12:21 +0000305 m_remote_url (),
Greg Clayton1cb64962011-03-24 04:28:38 +0000306 m_name (),
Greg Claytonded470d2011-03-19 01:12:21 +0000307 m_major_os_version (UINT32_MAX),
308 m_minor_os_version (UINT32_MAX),
Greg Clayton32e0a752011-03-30 18:16:51 +0000309 m_update_os_version (UINT32_MAX),
310 m_system_arch(),
Greg Clayton7597b352015-02-02 20:45:17 +0000311 m_mutex (Mutex::eMutexTypeRecursive),
Greg Clayton32e0a752011-03-30 18:16:51 +0000312 m_uid_map(),
313 m_gid_map(),
314 m_max_uid_name_len (0),
Daniel Maleae0f8f572013-08-26 23:57:52 +0000315 m_max_gid_name_len (0),
316 m_supports_rsync (false),
317 m_rsync_opts (),
318 m_rsync_prefix (),
319 m_supports_ssh (false),
320 m_ssh_opts (),
Jason Molenda6223db272014-02-13 07:11:08 +0000321 m_ignores_remote_hostname (false),
Jason Molenda2094dbf2014-02-13 23:11:45 +0000322 m_trap_handlers(),
Greg Clayton7597b352015-02-02 20:45:17 +0000323 m_calculated_trap_handlers (false)
Greg Claytone996fd32011-03-08 22:40:15 +0000324{
Greg Clayton5160ce52013-03-27 23:08:40 +0000325 Log *log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_OBJECT));
Greg Clayton8b82f082011-04-12 05:54:46 +0000326 if (log)
Saleem Abdulrasool324a1032014-04-04 04:06:10 +0000327 log->Printf ("%p Platform::Platform()", static_cast<void*>(this));
Greg Claytone996fd32011-03-08 22:40:15 +0000328}
329
330//------------------------------------------------------------------
331/// Destructor.
332///
333/// The destructor is virtual since this class is designed to be
334/// inherited from by the plug-in instance.
335//------------------------------------------------------------------
336Platform::~Platform()
337{
Greg Clayton5160ce52013-03-27 23:08:40 +0000338 Log *log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_OBJECT));
Greg Clayton8b82f082011-04-12 05:54:46 +0000339 if (log)
Saleem Abdulrasool324a1032014-04-04 04:06:10 +0000340 log->Printf ("%p Platform::~Platform()", static_cast<void*>(this));
Greg Claytone996fd32011-03-08 22:40:15 +0000341}
342
Greg Clayton1cb64962011-03-24 04:28:38 +0000343void
344Platform::GetStatus (Stream &strm)
345{
346 uint32_t major = UINT32_MAX;
347 uint32_t minor = UINT32_MAX;
348 uint32_t update = UINT32_MAX;
349 std::string s;
Greg Clayton57abc5d2013-05-10 21:47:16 +0000350 strm.Printf (" Platform: %s\n", GetPluginName().GetCString());
Greg Clayton1cb64962011-03-24 04:28:38 +0000351
352 ArchSpec arch (GetSystemArchitecture());
353 if (arch.IsValid())
354 {
355 if (!arch.GetTriple().str().empty())
Greg Clayton32e0a752011-03-30 18:16:51 +0000356 strm.Printf(" Triple: %s\n", arch.GetTriple().str().c_str());
Greg Clayton1cb64962011-03-24 04:28:38 +0000357 }
358
359 if (GetOSVersion(major, minor, update))
360 {
Greg Clayton32e0a752011-03-30 18:16:51 +0000361 strm.Printf("OS Version: %u", major);
Greg Clayton1cb64962011-03-24 04:28:38 +0000362 if (minor != UINT32_MAX)
363 strm.Printf(".%u", minor);
364 if (update != UINT32_MAX)
365 strm.Printf(".%u", update);
366
367 if (GetOSBuildString (s))
368 strm.Printf(" (%s)", s.c_str());
369
370 strm.EOL();
371 }
372
373 if (GetOSKernelDescription (s))
Greg Clayton32e0a752011-03-30 18:16:51 +0000374 strm.Printf(" Kernel: %s\n", s.c_str());
Greg Clayton1cb64962011-03-24 04:28:38 +0000375
376 if (IsHost())
377 {
Greg Clayton32e0a752011-03-30 18:16:51 +0000378 strm.Printf(" Hostname: %s\n", GetHostname());
Greg Clayton1cb64962011-03-24 04:28:38 +0000379 }
380 else
381 {
Greg Clayton32e0a752011-03-30 18:16:51 +0000382 const bool is_connected = IsConnected();
383 if (is_connected)
384 strm.Printf(" Hostname: %s\n", GetHostname());
385 strm.Printf(" Connected: %s\n", is_connected ? "yes" : "no");
Greg Clayton1cb64962011-03-24 04:28:38 +0000386 }
Daniel Maleae0f8f572013-08-26 23:57:52 +0000387
Greg Claytonfbb76342013-11-20 21:07:01 +0000388 if (GetWorkingDirectory())
389 {
390 strm.Printf("WorkingDir: %s\n", GetWorkingDirectory().GetCString());
391 }
Daniel Maleae0f8f572013-08-26 23:57:52 +0000392 if (!IsConnected())
393 return;
394
395 std::string specific_info(GetPlatformSpecificConnectionInformation());
396
397 if (specific_info.empty() == false)
398 strm.Printf("Platform-specific connection: %s\n", specific_info.c_str());
Greg Clayton1cb64962011-03-24 04:28:38 +0000399}
400
Greg Claytonded470d2011-03-19 01:12:21 +0000401
402bool
403Platform::GetOSVersion (uint32_t &major,
404 uint32_t &minor,
405 uint32_t &update)
406{
Greg Clayton7597b352015-02-02 20:45:17 +0000407 Mutex::Locker locker (m_mutex);
408
Greg Claytonded470d2011-03-19 01:12:21 +0000409 bool success = m_major_os_version != UINT32_MAX;
410 if (IsHost())
411 {
412 if (!success)
413 {
414 // We have a local host platform
Zachary Turner97a14e62014-08-19 17:18:29 +0000415 success = HostInfo::GetOSVersion(m_major_os_version, m_minor_os_version, m_update_os_version);
Greg Claytonded470d2011-03-19 01:12:21 +0000416 m_os_version_set_while_connected = success;
417 }
418 }
419 else
420 {
421 // We have a remote platform. We can only fetch the remote
422 // OS version if we are connected, and we don't want to do it
423 // more than once.
424
425 const bool is_connected = IsConnected();
426
Greg Clayton1cb64962011-03-24 04:28:38 +0000427 bool fetch = false;
Greg Claytonded470d2011-03-19 01:12:21 +0000428 if (success)
429 {
430 // We have valid OS version info, check to make sure it wasn't
431 // manually set prior to connecting. If it was manually set prior
432 // to connecting, then lets fetch the actual OS version info
433 // if we are now connected.
434 if (is_connected && !m_os_version_set_while_connected)
Greg Clayton1cb64962011-03-24 04:28:38 +0000435 fetch = true;
Greg Claytonded470d2011-03-19 01:12:21 +0000436 }
437 else
438 {
439 // We don't have valid OS version info, fetch it if we are connected
Greg Clayton1cb64962011-03-24 04:28:38 +0000440 fetch = is_connected;
Greg Claytonded470d2011-03-19 01:12:21 +0000441 }
442
Greg Clayton1cb64962011-03-24 04:28:38 +0000443 if (fetch)
Greg Claytonded470d2011-03-19 01:12:21 +0000444 {
Greg Clayton1cb64962011-03-24 04:28:38 +0000445 success = GetRemoteOSVersion ();
Greg Claytonded470d2011-03-19 01:12:21 +0000446 m_os_version_set_while_connected = success;
447 }
448 }
449
450 if (success)
451 {
452 major = m_major_os_version;
453 minor = m_minor_os_version;
454 update = m_update_os_version;
455 }
456 return success;
457}
Greg Clayton1cb64962011-03-24 04:28:38 +0000458
459bool
460Platform::GetOSBuildString (std::string &s)
461{
Zachary Turner97a14e62014-08-19 17:18:29 +0000462 s.clear();
463
Greg Clayton1cb64962011-03-24 04:28:38 +0000464 if (IsHost())
Zachary Turner97a14e62014-08-19 17:18:29 +0000465#if !defined(__linux__)
466 return HostInfo::GetOSBuildString(s);
467#else
468 return false;
469#endif
Greg Clayton1cb64962011-03-24 04:28:38 +0000470 else
471 return GetRemoteOSBuildString (s);
472}
473
474bool
475Platform::GetOSKernelDescription (std::string &s)
476{
477 if (IsHost())
Zachary Turner97a14e62014-08-19 17:18:29 +0000478#if !defined(__linux__)
479 return HostInfo::GetOSKernelDescription(s);
480#else
481 return false;
482#endif
Greg Clayton1cb64962011-03-24 04:28:38 +0000483 else
484 return GetRemoteOSKernelDescription (s);
485}
486
Sean Callanan5dc29812014-12-05 01:16:31 +0000487void
Greg Claytoncd6bbba2015-01-22 18:25:49 +0000488Platform::AddClangModuleCompilationOptions (Target *target, std::vector<std::string> &options)
Sean Callanan5dc29812014-12-05 01:16:31 +0000489{
490 std::vector<std::string> default_compilation_options =
491 {
492 "-x", "c++", "-Xclang", "-nostdsysteminc", "-Xclang", "-nostdsysteminc"
493 };
494
495 options.insert(options.end(),
496 default_compilation_options.begin(),
497 default_compilation_options.end());
498}
499
500
Greg Clayton57abc5d2013-05-10 21:47:16 +0000501ConstString
Greg Claytonfbb76342013-11-20 21:07:01 +0000502Platform::GetWorkingDirectory ()
503{
504 if (IsHost())
505 {
506 char cwd[PATH_MAX];
507 if (getcwd(cwd, sizeof(cwd)))
508 return ConstString(cwd);
509 else
510 return ConstString();
511 }
512 else
513 {
514 if (!m_working_dir)
515 m_working_dir = GetRemoteWorkingDirectory();
516 return m_working_dir;
517 }
518}
519
520
521struct RecurseCopyBaton
522{
523 const FileSpec& dst;
524 Platform *platform_ptr;
525 Error error;
526};
527
528
529static FileSpec::EnumerateDirectoryResult
530RecurseCopy_Callback (void *baton,
531 FileSpec::FileType file_type,
532 const FileSpec &src)
533{
534 RecurseCopyBaton* rc_baton = (RecurseCopyBaton*)baton;
535 switch (file_type)
536 {
537 case FileSpec::eFileTypePipe:
538 case FileSpec::eFileTypeSocket:
539 // we have no way to copy pipes and sockets - ignore them and continue
540 return FileSpec::eEnumerateDirectoryResultNext;
541 break;
542
543 case FileSpec::eFileTypeDirectory:
544 {
545 // make the new directory and get in there
546 FileSpec dst_dir = rc_baton->dst;
547 if (!dst_dir.GetFilename())
548 dst_dir.GetFilename() = src.GetLastPathComponent();
549 std::string dst_dir_path (dst_dir.GetPath());
550 Error error = rc_baton->platform_ptr->MakeDirectory(dst_dir_path.c_str(), lldb::eFilePermissionsDirectoryDefault);
551 if (error.Fail())
552 {
553 rc_baton->error.SetErrorStringWithFormat("unable to setup directory %s on remote end", dst_dir_path.c_str());
554 return FileSpec::eEnumerateDirectoryResultQuit; // got an error, bail out
555 }
556
557 // now recurse
558 std::string src_dir_path (src.GetPath());
559
560 // Make a filespec that only fills in the directory of a FileSpec so
561 // when we enumerate we can quickly fill in the filename for dst copies
562 FileSpec recurse_dst;
563 recurse_dst.GetDirectory().SetCString(dst_dir.GetPath().c_str());
564 RecurseCopyBaton rc_baton2 = { recurse_dst, rc_baton->platform_ptr, Error() };
565 FileSpec::EnumerateDirectory(src_dir_path.c_str(), true, true, true, RecurseCopy_Callback, &rc_baton2);
566 if (rc_baton2.error.Fail())
567 {
568 rc_baton->error.SetErrorString(rc_baton2.error.AsCString());
569 return FileSpec::eEnumerateDirectoryResultQuit; // got an error, bail out
570 }
571 return FileSpec::eEnumerateDirectoryResultNext;
572 }
573 break;
574
575 case FileSpec::eFileTypeSymbolicLink:
576 {
577 // copy the file and keep going
578 FileSpec dst_file = rc_baton->dst;
579 if (!dst_file.GetFilename())
580 dst_file.GetFilename() = src.GetFilename();
581
582 char buf[PATH_MAX];
Zachary Turnerc00cf4a2014-08-15 22:04:21 +0000583
584 rc_baton->error = FileSystem::Readlink(src.GetPath().c_str(), buf, sizeof(buf));
Greg Claytonfbb76342013-11-20 21:07:01 +0000585
586 if (rc_baton->error.Fail())
587 return FileSpec::eEnumerateDirectoryResultQuit; // got an error, bail out
588
589 rc_baton->error = rc_baton->platform_ptr->CreateSymlink(dst_file.GetPath().c_str(), buf);
590
591 if (rc_baton->error.Fail())
592 return FileSpec::eEnumerateDirectoryResultQuit; // got an error, bail out
593
594 return FileSpec::eEnumerateDirectoryResultNext;
595 }
596 break;
597 case FileSpec::eFileTypeRegular:
598 {
599 // copy the file and keep going
600 FileSpec dst_file = rc_baton->dst;
601 if (!dst_file.GetFilename())
602 dst_file.GetFilename() = src.GetFilename();
603 Error err = rc_baton->platform_ptr->PutFile(src, dst_file);
604 if (err.Fail())
605 {
606 rc_baton->error.SetErrorString(err.AsCString());
607 return FileSpec::eEnumerateDirectoryResultQuit; // got an error, bail out
608 }
609 return FileSpec::eEnumerateDirectoryResultNext;
610 }
611 break;
612
613 case FileSpec::eFileTypeInvalid:
614 case FileSpec::eFileTypeOther:
615 case FileSpec::eFileTypeUnknown:
616 rc_baton->error.SetErrorStringWithFormat("invalid file detected during copy: %s", src.GetPath().c_str());
617 return FileSpec::eEnumerateDirectoryResultQuit; // got an error, bail out
618 break;
619 }
David Majnemer8faf9372014-09-16 06:34:29 +0000620 llvm_unreachable("Unhandled FileSpec::FileType!");
Greg Claytonfbb76342013-11-20 21:07:01 +0000621}
622
623Error
624Platform::Install (const FileSpec& src, const FileSpec& dst)
625{
626 Error error;
627
628 Log *log = GetLogIfAnyCategoriesSet(LIBLLDB_LOG_PLATFORM);
629 if (log)
630 log->Printf ("Platform::Install (src='%s', dst='%s')", src.GetPath().c_str(), dst.GetPath().c_str());
631 FileSpec fixed_dst(dst);
632
633 if (!fixed_dst.GetFilename())
634 fixed_dst.GetFilename() = src.GetFilename();
635
636 ConstString working_dir = GetWorkingDirectory();
637
638 if (dst)
639 {
640 if (dst.GetDirectory())
641 {
642 const char first_dst_dir_char = dst.GetDirectory().GetCString()[0];
643 if (first_dst_dir_char == '/' || first_dst_dir_char == '\\')
644 {
645 fixed_dst.GetDirectory() = dst.GetDirectory();
646 }
647 // If the fixed destination file doesn't have a directory yet,
648 // then we must have a relative path. We will resolve this relative
649 // path against the platform's working directory
650 if (!fixed_dst.GetDirectory())
651 {
652 FileSpec relative_spec;
653 std::string path;
654 if (working_dir)
655 {
656 relative_spec.SetFile(working_dir.GetCString(), false);
657 relative_spec.AppendPathComponent(dst.GetPath().c_str());
658 fixed_dst.GetDirectory() = relative_spec.GetDirectory();
659 }
660 else
661 {
662 error.SetErrorStringWithFormat("platform working directory must be valid for relative path '%s'", dst.GetPath().c_str());
663 return error;
664 }
665 }
666 }
667 else
668 {
669 if (working_dir)
670 {
671 fixed_dst.GetDirectory() = working_dir;
672 }
673 else
674 {
675 error.SetErrorStringWithFormat("platform working directory must be valid for relative path '%s'", dst.GetPath().c_str());
676 return error;
677 }
678 }
679 }
680 else
681 {
682 if (working_dir)
683 {
684 fixed_dst.GetDirectory() = working_dir;
685 }
686 else
687 {
688 error.SetErrorStringWithFormat("platform working directory must be valid when destination directory is empty");
689 return error;
690 }
691 }
692
693 if (log)
694 log->Printf ("Platform::Install (src='%s', dst='%s') fixed_dst='%s'", src.GetPath().c_str(), dst.GetPath().c_str(), fixed_dst.GetPath().c_str());
695
696 if (GetSupportsRSync())
697 {
698 error = PutFile(src, dst);
699 }
700 else
701 {
702 switch (src.GetFileType())
703 {
704 case FileSpec::eFileTypeDirectory:
705 {
706 if (GetFileExists (fixed_dst))
707 Unlink (fixed_dst.GetPath().c_str());
708 uint32_t permissions = src.GetPermissions();
709 if (permissions == 0)
710 permissions = eFilePermissionsDirectoryDefault;
711 std::string dst_dir_path(fixed_dst.GetPath());
712 error = MakeDirectory(dst_dir_path.c_str(), permissions);
713 if (error.Success())
714 {
715 // Make a filespec that only fills in the directory of a FileSpec so
716 // when we enumerate we can quickly fill in the filename for dst copies
717 FileSpec recurse_dst;
718 recurse_dst.GetDirectory().SetCString(dst_dir_path.c_str());
719 std::string src_dir_path (src.GetPath());
720 RecurseCopyBaton baton = { recurse_dst, this, Error() };
721 FileSpec::EnumerateDirectory(src_dir_path.c_str(), true, true, true, RecurseCopy_Callback, &baton);
722 return baton.error;
723 }
724 }
725 break;
726
727 case FileSpec::eFileTypeRegular:
728 if (GetFileExists (fixed_dst))
729 Unlink (fixed_dst.GetPath().c_str());
730 error = PutFile(src, fixed_dst);
731 break;
732
733 case FileSpec::eFileTypeSymbolicLink:
734 {
735 if (GetFileExists (fixed_dst))
736 Unlink (fixed_dst.GetPath().c_str());
737 char buf[PATH_MAX];
Zachary Turnerc00cf4a2014-08-15 22:04:21 +0000738 error = FileSystem::Readlink(src.GetPath().c_str(), buf, sizeof(buf));
Greg Claytonfbb76342013-11-20 21:07:01 +0000739 if (error.Success())
740 error = CreateSymlink(dst.GetPath().c_str(), buf);
741 }
742 break;
743 case FileSpec::eFileTypePipe:
744 error.SetErrorString("platform install doesn't handle pipes");
745 break;
746 case FileSpec::eFileTypeSocket:
747 error.SetErrorString("platform install doesn't handle sockets");
748 break;
749 case FileSpec::eFileTypeInvalid:
750 case FileSpec::eFileTypeUnknown:
751 case FileSpec::eFileTypeOther:
752 error.SetErrorString("platform install doesn't handle non file or directory items");
753 break;
754 }
755 }
756 return error;
757}
758
759bool
760Platform::SetWorkingDirectory (const ConstString &path)
761{
762 if (IsHost())
763 {
Greg Clayton5fb8f792013-12-02 19:35:49 +0000764 Log *log = GetLogIfAnyCategoriesSet(LIBLLDB_LOG_PLATFORM);
765 if (log)
766 log->Printf("Platform::SetWorkingDirectory('%s')", path.GetCString());
Colin Riley909bb7a2013-11-26 15:10:46 +0000767#ifdef _WIN32
768 // Not implemented on Windows
769 return false;
770#else
Greg Claytonfbb76342013-11-20 21:07:01 +0000771 if (path)
772 {
773 if (chdir(path.GetCString()) == 0)
774 return true;
775 }
776 return false;
Colin Riley909bb7a2013-11-26 15:10:46 +0000777#endif
Greg Claytonfbb76342013-11-20 21:07:01 +0000778 }
779 else
780 {
Greg Clayton5fb8f792013-12-02 19:35:49 +0000781 m_working_dir.Clear();
Greg Claytonfbb76342013-11-20 21:07:01 +0000782 return SetRemoteWorkingDirectory(path);
783 }
784}
785
786Error
787Platform::MakeDirectory (const char *path, uint32_t permissions)
788{
789 if (IsHost())
Zachary Turnerc00cf4a2014-08-15 22:04:21 +0000790 return FileSystem::MakeDirectory(path, permissions);
Greg Claytonfbb76342013-11-20 21:07:01 +0000791 else
792 {
793 Error error;
794 error.SetErrorStringWithFormat("remote platform %s doesn't support %s", GetPluginName().GetCString(), __PRETTY_FUNCTION__);
795 return error;
796 }
797}
798
799Error
800Platform::GetFilePermissions (const char *path, uint32_t &file_permissions)
801{
802 if (IsHost())
Zachary Turnerc00cf4a2014-08-15 22:04:21 +0000803 return FileSystem::GetFilePermissions(path, file_permissions);
Greg Claytonfbb76342013-11-20 21:07:01 +0000804 else
805 {
806 Error error;
807 error.SetErrorStringWithFormat("remote platform %s doesn't support %s", GetPluginName().GetCString(), __PRETTY_FUNCTION__);
808 return error;
809 }
810}
811
812Error
813Platform::SetFilePermissions (const char *path, uint32_t file_permissions)
814{
815 if (IsHost())
Zachary Turnerc00cf4a2014-08-15 22:04:21 +0000816 return FileSystem::SetFilePermissions(path, file_permissions);
Greg Claytonfbb76342013-11-20 21:07:01 +0000817 else
818 {
819 Error error;
820 error.SetErrorStringWithFormat("remote platform %s doesn't support %s", GetPluginName().GetCString(), __PRETTY_FUNCTION__);
821 return error;
822 }
823}
824
825ConstString
Greg Clayton8b82f082011-04-12 05:54:46 +0000826Platform::GetName ()
827{
Greg Claytonfbb76342013-11-20 21:07:01 +0000828 return GetPluginName();
Greg Clayton8b82f082011-04-12 05:54:46 +0000829}
830
831const char *
Greg Clayton1cb64962011-03-24 04:28:38 +0000832Platform::GetHostname ()
833{
Greg Claytonab65b342011-04-13 22:47:15 +0000834 if (IsHost())
Greg Clayton16810922014-02-27 19:38:18 +0000835 return "127.0.0.1";
Greg Clayton32e0a752011-03-30 18:16:51 +0000836
837 if (m_name.empty())
838 return NULL;
839 return m_name.c_str();
840}
841
Greg Clayton5fb8f792013-12-02 19:35:49 +0000842bool
843Platform::SetRemoteWorkingDirectory(const ConstString &path)
844{
845 Log *log = GetLogIfAnyCategoriesSet(LIBLLDB_LOG_PLATFORM);
846 if (log)
847 log->Printf("Platform::SetRemoteWorkingDirectory('%s')", path.GetCString());
848 m_working_dir = path;
849 return true;
850}
851
Greg Clayton32e0a752011-03-30 18:16:51 +0000852const char *
853Platform::GetUserName (uint32_t uid)
854{
Zachary Turnerb245eca2014-08-21 20:02:17 +0000855#if !defined(LLDB_DISABLE_POSIX)
Greg Clayton32e0a752011-03-30 18:16:51 +0000856 const char *user_name = GetCachedUserName(uid);
857 if (user_name)
858 return user_name;
859 if (IsHost())
860 {
861 std::string name;
Zachary Turnerb245eca2014-08-21 20:02:17 +0000862 if (HostInfo::LookupUserName(uid, name))
Greg Clayton32e0a752011-03-30 18:16:51 +0000863 return SetCachedUserName (uid, name.c_str(), name.size());
864 }
Zachary Turnerb245eca2014-08-21 20:02:17 +0000865#endif
Greg Clayton1cb64962011-03-24 04:28:38 +0000866 return NULL;
867}
868
Greg Clayton32e0a752011-03-30 18:16:51 +0000869const char *
870Platform::GetGroupName (uint32_t gid)
871{
Zachary Turnerb245eca2014-08-21 20:02:17 +0000872#if !defined(LLDB_DISABLE_POSIX)
Greg Clayton32e0a752011-03-30 18:16:51 +0000873 const char *group_name = GetCachedGroupName(gid);
874 if (group_name)
875 return group_name;
876 if (IsHost())
877 {
878 std::string name;
Zachary Turnerb245eca2014-08-21 20:02:17 +0000879 if (HostInfo::LookupGroupName(gid, name))
Greg Clayton32e0a752011-03-30 18:16:51 +0000880 return SetCachedGroupName (gid, name.c_str(), name.size());
881 }
Zachary Turnerb245eca2014-08-21 20:02:17 +0000882#endif
Greg Clayton32e0a752011-03-30 18:16:51 +0000883 return NULL;
884}
Greg Clayton1cb64962011-03-24 04:28:38 +0000885
Greg Claytonded470d2011-03-19 01:12:21 +0000886bool
887Platform::SetOSVersion (uint32_t major,
888 uint32_t minor,
889 uint32_t update)
890{
891 if (IsHost())
892 {
Zachary Turner97a14e62014-08-19 17:18:29 +0000893 // We don't need anyone setting the OS version for the host platform,
894 // we should be able to figure it out by calling HostInfo::GetOSVersion(...).
Greg Claytonded470d2011-03-19 01:12:21 +0000895 return false;
896 }
897 else
898 {
899 // We have a remote platform, allow setting the target OS version if
900 // we aren't connected, since if we are connected, we should be able to
901 // request the remote OS version from the connected platform.
902 if (IsConnected())
903 return false;
904 else
905 {
906 // We aren't connected and we might want to set the OS version
907 // ahead of time before we connect so we can peruse files and
908 // use a local SDK or PDK cache of support files to disassemble
909 // or do other things.
910 m_major_os_version = major;
911 m_minor_os_version = minor;
912 m_update_os_version = update;
913 return true;
914 }
915 }
916 return false;
917}
918
919
Greg Claytone996fd32011-03-08 22:40:15 +0000920Error
Greg Clayton8012cad2014-11-17 19:39:20 +0000921Platform::ResolveExecutable (const ModuleSpec &module_spec,
Greg Claytonc859e2d2012-02-13 23:10:39 +0000922 lldb::ModuleSP &exe_module_sp,
923 const FileSpecList *module_search_paths_ptr)
Greg Claytone996fd32011-03-08 22:40:15 +0000924{
925 Error error;
Greg Clayton8012cad2014-11-17 19:39:20 +0000926 if (module_spec.GetFileSpec().Exists())
Greg Claytone996fd32011-03-08 22:40:15 +0000927 {
Greg Claytonb9a01b32012-02-26 05:51:37 +0000928 if (module_spec.GetArchitecture().IsValid())
Greg Claytone996fd32011-03-08 22:40:15 +0000929 {
Greg Claytonb9a01b32012-02-26 05:51:37 +0000930 error = ModuleList::GetSharedModule (module_spec,
Greg Claytone996fd32011-03-08 22:40:15 +0000931 exe_module_sp,
Greg Claytonc859e2d2012-02-13 23:10:39 +0000932 module_search_paths_ptr,
Greg Claytone996fd32011-03-08 22:40:15 +0000933 NULL,
934 NULL);
935 }
936 else
937 {
938 // No valid architecture was specified, ask the platform for
939 // the architectures that we should be using (in the correct order)
940 // and see if we can find a match that way
Greg Clayton8012cad2014-11-17 19:39:20 +0000941 ModuleSpec arch_module_spec(module_spec);
942 for (uint32_t idx = 0; GetSupportedArchitectureAtIndex (idx, arch_module_spec.GetArchitecture()); ++idx)
Greg Claytone996fd32011-03-08 22:40:15 +0000943 {
Greg Clayton8012cad2014-11-17 19:39:20 +0000944 error = ModuleList::GetSharedModule (arch_module_spec,
Greg Claytone996fd32011-03-08 22:40:15 +0000945 exe_module_sp,
Greg Claytonc859e2d2012-02-13 23:10:39 +0000946 module_search_paths_ptr,
Greg Claytone996fd32011-03-08 22:40:15 +0000947 NULL,
948 NULL);
949 // Did we find an executable using one of the
950 if (error.Success() && exe_module_sp)
951 break;
952 }
953 }
954 }
955 else
956 {
Greg Claytonb5ad4ec2013-04-29 17:25:54 +0000957 error.SetErrorStringWithFormat ("'%s' does not exist",
Greg Clayton8012cad2014-11-17 19:39:20 +0000958 module_spec.GetFileSpec().GetPath().c_str());
Greg Claytone996fd32011-03-08 22:40:15 +0000959 }
960 return error;
961}
962
Greg Clayton103f0282012-09-12 02:03:59 +0000963Error
964Platform::ResolveSymbolFile (Target &target,
965 const ModuleSpec &sym_spec,
966 FileSpec &sym_file)
967{
968 Error error;
969 if (sym_spec.GetSymbolFileSpec().Exists())
970 sym_file = sym_spec.GetSymbolFileSpec();
971 else
972 error.SetErrorString("unable to resolve symbol file");
973 return error;
974
975}
976
977
978
Greg Claytonaa516842011-08-11 16:25:18 +0000979bool
980Platform::ResolveRemotePath (const FileSpec &platform_path,
981 FileSpec &resolved_platform_path)
982{
983 resolved_platform_path = platform_path;
984 return resolved_platform_path.ResolvePath();
985}
986
Greg Claytonded470d2011-03-19 01:12:21 +0000987
988const ArchSpec &
989Platform::GetSystemArchitecture()
990{
991 if (IsHost())
992 {
993 if (!m_system_arch.IsValid())
994 {
995 // We have a local host platform
Zachary Turner13b18262014-08-20 16:42:51 +0000996 m_system_arch = HostInfo::GetArchitecture();
Greg Claytonded470d2011-03-19 01:12:21 +0000997 m_system_arch_set_while_connected = m_system_arch.IsValid();
998 }
999 }
1000 else
1001 {
1002 // We have a remote platform. We can only fetch the remote
1003 // system architecture if we are connected, and we don't want to do it
1004 // more than once.
1005
1006 const bool is_connected = IsConnected();
1007
1008 bool fetch = false;
1009 if (m_system_arch.IsValid())
1010 {
1011 // We have valid OS version info, check to make sure it wasn't
1012 // manually set prior to connecting. If it was manually set prior
1013 // to connecting, then lets fetch the actual OS version info
1014 // if we are now connected.
1015 if (is_connected && !m_system_arch_set_while_connected)
1016 fetch = true;
1017 }
1018 else
1019 {
1020 // We don't have valid OS version info, fetch it if we are connected
1021 fetch = is_connected;
1022 }
1023
1024 if (fetch)
1025 {
Greg Clayton1cb64962011-03-24 04:28:38 +00001026 m_system_arch = GetRemoteSystemArchitecture ();
Greg Claytonded470d2011-03-19 01:12:21 +00001027 m_system_arch_set_while_connected = m_system_arch.IsValid();
1028 }
1029 }
1030 return m_system_arch;
1031}
1032
1033
Greg Claytone996fd32011-03-08 22:40:15 +00001034Error
Greg Claytond314e812011-03-23 00:09:55 +00001035Platform::ConnectRemote (Args& args)
Greg Claytone996fd32011-03-08 22:40:15 +00001036{
1037 Error error;
Greg Claytond314e812011-03-23 00:09:55 +00001038 if (IsHost())
Greg Clayton57abc5d2013-05-10 21:47:16 +00001039 error.SetErrorStringWithFormat ("The currently selected platform (%s) is the host platform and is always connected.", GetPluginName().GetCString());
Greg Claytond314e812011-03-23 00:09:55 +00001040 else
Greg Clayton57abc5d2013-05-10 21:47:16 +00001041 error.SetErrorStringWithFormat ("Platform::ConnectRemote() is not supported by %s", GetPluginName().GetCString());
Greg Claytone996fd32011-03-08 22:40:15 +00001042 return error;
1043}
1044
1045Error
Greg Claytond314e812011-03-23 00:09:55 +00001046Platform::DisconnectRemote ()
Greg Claytone996fd32011-03-08 22:40:15 +00001047{
1048 Error error;
Greg Claytond314e812011-03-23 00:09:55 +00001049 if (IsHost())
Greg Clayton57abc5d2013-05-10 21:47:16 +00001050 error.SetErrorStringWithFormat ("The currently selected platform (%s) is the host platform and is always connected.", GetPluginName().GetCString());
Greg Claytond314e812011-03-23 00:09:55 +00001051 else
Greg Clayton57abc5d2013-05-10 21:47:16 +00001052 error.SetErrorStringWithFormat ("Platform::DisconnectRemote() is not supported by %s", GetPluginName().GetCString());
Greg Claytone996fd32011-03-08 22:40:15 +00001053 return error;
1054}
Greg Clayton32e0a752011-03-30 18:16:51 +00001055
1056bool
Greg Clayton8b82f082011-04-12 05:54:46 +00001057Platform::GetProcessInfo (lldb::pid_t pid, ProcessInstanceInfo &process_info)
Greg Clayton32e0a752011-03-30 18:16:51 +00001058{
1059 // Take care of the host case so that each subclass can just
Greg Clayton8b82f082011-04-12 05:54:46 +00001060 // call this function to get the host functionality.
Greg Clayton32e0a752011-03-30 18:16:51 +00001061 if (IsHost())
1062 return Host::GetProcessInfo (pid, process_info);
1063 return false;
1064}
1065
1066uint32_t
Greg Clayton8b82f082011-04-12 05:54:46 +00001067Platform::FindProcesses (const ProcessInstanceInfoMatch &match_info,
1068 ProcessInstanceInfoList &process_infos)
Greg Clayton32e0a752011-03-30 18:16:51 +00001069{
Greg Clayton8b82f082011-04-12 05:54:46 +00001070 // Take care of the host case so that each subclass can just
1071 // call this function to get the host functionality.
Greg Clayton32e0a752011-03-30 18:16:51 +00001072 uint32_t match_count = 0;
1073 if (IsHost())
1074 match_count = Host::FindProcesses (match_info, process_infos);
1075 return match_count;
1076}
Greg Clayton8b82f082011-04-12 05:54:46 +00001077
1078
1079Error
1080Platform::LaunchProcess (ProcessLaunchInfo &launch_info)
1081{
1082 Error error;
Todd Fialaac33cc92014-10-09 01:02:08 +00001083 Log *log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_PLATFORM));
1084 if (log)
1085 log->Printf ("Platform::%s()", __FUNCTION__);
1086
1087 // Take care of the host case so that each subclass can just
Greg Clayton8b82f082011-04-12 05:54:46 +00001088 // call this function to get the host functionality.
1089 if (IsHost())
Greg Clayton84db9102012-03-26 23:03:23 +00001090 {
1091 if (::getenv ("LLDB_LAUNCH_FLAG_LAUNCH_IN_TTY"))
1092 launch_info.GetFlags().Set (eLaunchFlagLaunchInTTY);
1093
1094 if (launch_info.GetFlags().Test (eLaunchFlagLaunchInShell))
1095 {
1096 const bool is_localhost = true;
Greg Claytond1cf11a2012-04-14 01:42:46 +00001097 const bool will_debug = launch_info.GetFlags().Test(eLaunchFlagDebug);
1098 const bool first_arg_is_full_shell_command = false;
Jim Inghamd3990792013-09-11 18:23:22 +00001099 uint32_t num_resumes = GetResumeCountForLaunchInfo (launch_info);
Todd Fialaac33cc92014-10-09 01:02:08 +00001100 if (log)
Zachary Turner10687b02014-10-20 17:46:43 +00001101 {
1102 const FileSpec &shell = launch_info.GetShell();
1103 const char *shell_str = (shell) ? shell.GetPath().c_str() : "<null>";
Todd Fialaac33cc92014-10-09 01:02:08 +00001104 log->Printf ("Platform::%s GetResumeCountForLaunchInfo() returned %" PRIu32 ", shell is '%s'",
1105 __FUNCTION__,
1106 num_resumes,
Zachary Turner10687b02014-10-20 17:46:43 +00001107 shell_str);
1108 }
Todd Fialaac33cc92014-10-09 01:02:08 +00001109
Greg Claytond1cf11a2012-04-14 01:42:46 +00001110 if (!launch_info.ConvertArgumentsForLaunchingInShell (error,
1111 is_localhost,
1112 will_debug,
Jim Inghamdf0ae222013-09-10 02:09:47 +00001113 first_arg_is_full_shell_command,
1114 num_resumes))
Greg Clayton84db9102012-03-26 23:03:23 +00001115 return error;
1116 }
Enrico Granatad7a83a92015-02-10 03:06:24 +00001117 else if (launch_info.GetFlags().Test(eLaunchFlagGlobArguments))
1118 {
1119 FileSpec glob_tool_spec;
1120 if (!HostInfo::GetLLDBPath(lldb::ePathTypeSupportExecutableDir, glob_tool_spec))
1121 {
1122 error.SetErrorString("could not find argdumper tool");
1123 return error;
1124 }
1125 glob_tool_spec.AppendPathComponent("argdumper");
1126 if (!glob_tool_spec.Exists())
1127 {
1128 error.SetErrorString("could not find argdumper tool");
1129 return error;
1130 }
1131
1132 std::string quoted_cmd_string;
1133 launch_info.GetArguments().GetQuotedCommandString(quoted_cmd_string);
1134
1135 StreamString glob_command;
1136
1137 glob_command.Printf("%s %s",
1138 glob_tool_spec.GetPath().c_str(),
1139 quoted_cmd_string.c_str());
1140
1141 int status;
1142 std::string output;
1143 RunShellCommand(glob_command.GetData(), launch_info.GetWorkingDirectory(), &status, nullptr, &output, 10);
1144
1145 if (status != 0)
1146 {
1147 error.SetErrorStringWithFormat("argdumper exited with error %d", status);
1148 return error;
1149 }
1150
1151 auto data_sp = StructuredData::ParseJSON(output);
1152 if (!data_sp)
1153 {
1154 error.SetErrorString("invalid JSON");
1155 return error;
1156 }
1157
1158 auto dict_sp = data_sp->GetAsDictionary();
1159 if (!data_sp)
1160 {
1161 error.SetErrorString("invalid JSON");
1162 return error;
1163 }
1164
1165 auto args_sp = dict_sp->GetObjectForDotSeparatedPath("arguments");
1166 if (!args_sp)
1167 {
1168 error.SetErrorString("invalid JSON");
1169 return error;
1170 }
1171
1172 auto args_array_sp = args_sp->GetAsArray();
1173 if (!args_array_sp)
1174 {
1175 error.SetErrorString("invalid JSON");
1176 return error;
1177 }
1178
1179 launch_info.GetArguments().Clear();
1180
1181 for (size_t i = 0;
1182 i < args_array_sp->GetSize();
1183 i++)
1184 {
1185 auto item_sp = args_array_sp->GetItemAtIndex(i);
1186 if (!item_sp)
1187 continue;
1188 auto str_sp = item_sp->GetAsString();
1189 if (!str_sp)
1190 continue;
1191
1192 launch_info.GetArguments().AppendArgument(str_sp->GetValue().c_str());
1193 }
1194 }
Greg Clayton84db9102012-03-26 23:03:23 +00001195
Todd Fialaac33cc92014-10-09 01:02:08 +00001196 if (log)
1197 log->Printf ("Platform::%s final launch_info resume count: %" PRIu32, __FUNCTION__, launch_info.GetResumeCount ());
1198
Greg Clayton8b82f082011-04-12 05:54:46 +00001199 error = Host::LaunchProcess (launch_info);
Greg Clayton84db9102012-03-26 23:03:23 +00001200 }
Greg Clayton8b82f082011-04-12 05:54:46 +00001201 else
1202 error.SetErrorString ("base lldb_private::Platform class can't launch remote processes");
1203 return error;
1204}
1205
Oleksiy Vyalov1ef7b2c2015-02-04 23:19:15 +00001206Error
1207Platform::KillProcess (const lldb::pid_t pid)
1208{
1209 Log *log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_PLATFORM));
1210 if (log)
1211 log->Printf ("Platform::%s, pid %" PRIu64, __FUNCTION__, pid);
1212
1213 if (!IsHost ())
1214 return Error ("base lldb_private::Platform class can't launch remote processes");
1215
1216 Host::Kill (pid, SIGTERM);
1217 return Error();
1218}
1219
Greg Clayton8b82f082011-04-12 05:54:46 +00001220lldb::ProcessSP
1221Platform::DebugProcess (ProcessLaunchInfo &launch_info,
1222 Debugger &debugger,
1223 Target *target, // Can be NULL, if NULL create a new target, else use existing one
Greg Clayton8b82f082011-04-12 05:54:46 +00001224 Error &error)
1225{
Todd Fialaac33cc92014-10-09 01:02:08 +00001226 Log *log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_PLATFORM));
1227 if (log)
1228 log->Printf ("Platform::%s entered (target %p)", __FUNCTION__, static_cast<void*>(target));
1229
Greg Clayton8b82f082011-04-12 05:54:46 +00001230 ProcessSP process_sp;
1231 // Make sure we stop at the entry point
1232 launch_info.GetFlags ().Set (eLaunchFlagDebug);
Jim Inghamb4451b12012-06-01 01:22:13 +00001233 // We always launch the process we are going to debug in a separate process
1234 // group, since then we can handle ^C interrupts ourselves w/o having to worry
1235 // about the target getting them as well.
1236 launch_info.SetLaunchInSeparateProcessGroup(true);
1237
Greg Clayton8b82f082011-04-12 05:54:46 +00001238 error = LaunchProcess (launch_info);
1239 if (error.Success())
1240 {
Todd Fialaac33cc92014-10-09 01:02:08 +00001241 if (log)
1242 log->Printf ("Platform::%s LaunchProcess() call succeeded (pid=%" PRIu64 ")", __FUNCTION__, launch_info.GetProcessID ());
Greg Clayton144f3a92011-11-15 03:53:30 +00001243 if (launch_info.GetProcessID() != LLDB_INVALID_PROCESS_ID)
Greg Clayton8b82f082011-04-12 05:54:46 +00001244 {
Greg Clayton144f3a92011-11-15 03:53:30 +00001245 ProcessAttachInfo attach_info (launch_info);
Greg Clayton8012cad2014-11-17 19:39:20 +00001246 process_sp = Attach (attach_info, debugger, target, error);
Greg Claytone24c4ac2011-11-17 04:46:02 +00001247 if (process_sp)
1248 {
Todd Fialaac33cc92014-10-09 01:02:08 +00001249 if (log)
1250 log->Printf ("Platform::%s Attach() succeeded, Process plugin: %s", __FUNCTION__, process_sp->GetPluginName ().AsCString ());
Greg Clayton44d93782014-01-27 23:43:24 +00001251 launch_info.SetHijackListener(attach_info.GetHijackListener());
1252
Greg Claytone24c4ac2011-11-17 04:46:02 +00001253 // Since we attached to the process, it will think it needs to detach
1254 // if the process object just goes away without an explicit call to
1255 // Process::Kill() or Process::Detach(), so let it know to kill the
1256 // process if this happens.
1257 process_sp->SetShouldDetach (false);
Greg Claytonee95ed52011-11-17 22:14:31 +00001258
1259 // If we didn't have any file actions, the pseudo terminal might
1260 // have been used where the slave side was given as the file to
1261 // open for stdin/out/err after we have already opened the master
1262 // so we can read/write stdin/out/err.
1263 int pty_fd = launch_info.GetPTY().ReleaseMasterFileDescriptor();
1264 if (pty_fd != lldb_utility::PseudoTerminal::invalid_fd)
1265 {
1266 process_sp->SetSTDIOFileDescriptor(pty_fd);
1267 }
Greg Claytone24c4ac2011-11-17 04:46:02 +00001268 }
Todd Fialaac33cc92014-10-09 01:02:08 +00001269 else
1270 {
1271 if (log)
1272 log->Printf ("Platform::%s Attach() failed: %s", __FUNCTION__, error.AsCString ());
1273 }
1274 }
1275 else
1276 {
1277 if (log)
1278 log->Printf ("Platform::%s LaunchProcess() returned launch_info with invalid process id", __FUNCTION__);
Greg Clayton8b82f082011-04-12 05:54:46 +00001279 }
1280 }
Todd Fialaac33cc92014-10-09 01:02:08 +00001281 else
1282 {
1283 if (log)
1284 log->Printf ("Platform::%s LaunchProcess() failed: %s", __FUNCTION__, error.AsCString ());
1285 }
1286
Greg Clayton8b82f082011-04-12 05:54:46 +00001287 return process_sp;
1288}
Greg Claytonb3a40ba2012-03-20 18:34:04 +00001289
1290
1291lldb::PlatformSP
Greg Clayton70512312012-05-08 01:45:38 +00001292Platform::GetPlatformForArchitecture (const ArchSpec &arch, ArchSpec *platform_arch_ptr)
Greg Claytonb3a40ba2012-03-20 18:34:04 +00001293{
1294 lldb::PlatformSP platform_sp;
1295 Error error;
1296 if (arch.IsValid())
Greg Clayton70512312012-05-08 01:45:38 +00001297 platform_sp = Platform::Create (arch, platform_arch_ptr, error);
Greg Claytonb3a40ba2012-03-20 18:34:04 +00001298 return platform_sp;
1299}
1300
1301
1302//------------------------------------------------------------------
1303/// Lets a platform answer if it is compatible with a given
1304/// architecture and the target triple contained within.
1305//------------------------------------------------------------------
1306bool
Greg Clayton1e0c8842013-01-11 20:49:54 +00001307Platform::IsCompatibleArchitecture (const ArchSpec &arch, bool exact_arch_match, ArchSpec *compatible_arch_ptr)
Greg Claytonb3a40ba2012-03-20 18:34:04 +00001308{
1309 // If the architecture is invalid, we must answer true...
Greg Clayton70512312012-05-08 01:45:38 +00001310 if (arch.IsValid())
Greg Claytonb3a40ba2012-03-20 18:34:04 +00001311 {
Greg Clayton70512312012-05-08 01:45:38 +00001312 ArchSpec platform_arch;
Greg Clayton1e0c8842013-01-11 20:49:54 +00001313 // Try for an exact architecture match first.
1314 if (exact_arch_match)
Greg Clayton70512312012-05-08 01:45:38 +00001315 {
Greg Clayton1e0c8842013-01-11 20:49:54 +00001316 for (uint32_t arch_idx=0; GetSupportedArchitectureAtIndex (arch_idx, platform_arch); ++arch_idx)
Greg Clayton70512312012-05-08 01:45:38 +00001317 {
Greg Clayton1e0c8842013-01-11 20:49:54 +00001318 if (arch.IsExactMatch(platform_arch))
1319 {
1320 if (compatible_arch_ptr)
1321 *compatible_arch_ptr = platform_arch;
1322 return true;
1323 }
1324 }
1325 }
1326 else
1327 {
1328 for (uint32_t arch_idx=0; GetSupportedArchitectureAtIndex (arch_idx, platform_arch); ++arch_idx)
1329 {
1330 if (arch.IsCompatibleMatch(platform_arch))
1331 {
1332 if (compatible_arch_ptr)
1333 *compatible_arch_ptr = platform_arch;
1334 return true;
1335 }
Greg Clayton70512312012-05-08 01:45:38 +00001336 }
1337 }
Greg Claytonb3a40ba2012-03-20 18:34:04 +00001338 }
Greg Clayton70512312012-05-08 01:45:38 +00001339 if (compatible_arch_ptr)
1340 compatible_arch_ptr->Clear();
Greg Claytonb3a40ba2012-03-20 18:34:04 +00001341 return false;
Greg Claytonb3a40ba2012-03-20 18:34:04 +00001342}
1343
Daniel Maleae0f8f572013-08-26 23:57:52 +00001344Error
1345Platform::PutFile (const FileSpec& source,
1346 const FileSpec& destination,
1347 uint32_t uid,
1348 uint32_t gid)
1349{
Vince Harron1b5a74e2015-01-21 22:42:49 +00001350 Log *log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_PLATFORM));
1351 if (log)
1352 log->Printf("[PutFile] Using block by block transfer....\n");
1353
Pavel Labath646b0642015-02-17 16:07:52 +00001354 uint32_t source_open_options = File::eOpenOptionRead | File::eOpenOptionCloseOnExec;
Vince Harron1b5a74e2015-01-21 22:42:49 +00001355 if (source.GetFileType() == FileSpec::eFileTypeSymbolicLink)
1356 source_open_options |= File::eOpenoptionDontFollowSymlinks;
1357
1358 File source_file(source, source_open_options, lldb::eFilePermissionsUserRW);
1359 Error error;
1360 uint32_t permissions = source_file.GetPermissions(error);
1361 if (permissions == 0)
1362 permissions = lldb::eFilePermissionsFileDefault;
1363
1364 if (!source_file.IsValid())
1365 return Error("PutFile: unable to open source file");
1366 lldb::user_id_t dest_file = OpenFile (destination,
1367 File::eOpenOptionCanCreate |
1368 File::eOpenOptionWrite |
Pavel Labath646b0642015-02-17 16:07:52 +00001369 File::eOpenOptionTruncate |
1370 File::eOpenOptionCloseOnExec,
Vince Harron1b5a74e2015-01-21 22:42:49 +00001371 permissions,
1372 error);
1373 if (log)
1374 log->Printf ("dest_file = %" PRIu64 "\n", dest_file);
1375
1376 if (error.Fail())
1377 return error;
1378 if (dest_file == UINT64_MAX)
1379 return Error("unable to open target file");
1380 lldb::DataBufferSP buffer_sp(new DataBufferHeap(1024, 0));
1381 uint64_t offset = 0;
1382 for (;;)
1383 {
1384 size_t bytes_read = buffer_sp->GetByteSize();
1385 error = source_file.Read(buffer_sp->GetBytes(), bytes_read);
1386 if (error.Fail() || bytes_read == 0)
1387 break;
1388
1389 const uint64_t bytes_written = WriteFile(dest_file, offset,
1390 buffer_sp->GetBytes(), bytes_read, error);
1391 if (error.Fail())
1392 break;
1393
1394 offset += bytes_written;
1395 if (bytes_written != bytes_read)
1396 {
1397 // We didn't write the correct number of bytes, so adjust
1398 // the file position in the source file we are reading from...
1399 source_file.SeekFromStart(offset);
1400 }
1401 }
1402 CloseFile(dest_file, error);
1403
1404 if (uid == UINT32_MAX && gid == UINT32_MAX)
1405 return error;
1406
1407 // TODO: ChownFile?
1408
Daniel Maleae0f8f572013-08-26 23:57:52 +00001409 return error;
1410}
1411
1412Error
1413Platform::GetFile (const FileSpec& source,
1414 const FileSpec& destination)
1415{
1416 Error error("unimplemented");
1417 return error;
1418}
1419
Greg Claytonfbb76342013-11-20 21:07:01 +00001420Error
1421Platform::CreateSymlink (const char *src, // The name of the link is in src
1422 const char *dst)// The symlink points to dst
1423{
1424 Error error("unimplemented");
1425 return error;
1426}
1427
Daniel Maleae0f8f572013-08-26 23:57:52 +00001428bool
1429Platform::GetFileExists (const lldb_private::FileSpec& file_spec)
1430{
1431 return false;
1432}
1433
Greg Claytonfbb76342013-11-20 21:07:01 +00001434Error
1435Platform::Unlink (const char *path)
1436{
1437 Error error("unimplemented");
1438 return error;
1439}
1440
1441
1442
Daniel Maleae0f8f572013-08-26 23:57:52 +00001443lldb_private::Error
1444Platform::RunShellCommand (const char *command, // Shouldn't be NULL
1445 const char *working_dir, // Pass NULL to use the current working directory
1446 int *status_ptr, // Pass NULL if you don't want the process exit status
1447 int *signo_ptr, // Pass NULL if you don't want the signal that caused the process to exit
1448 std::string *command_output, // Pass NULL if you don't want the command output
1449 uint32_t timeout_sec) // Timeout in seconds to wait for shell program to finish
1450{
1451 if (IsHost())
1452 return Host::RunShellCommand (command, working_dir, status_ptr, signo_ptr, command_output, timeout_sec);
1453 else
1454 return Error("unimplemented");
1455}
1456
1457
1458bool
1459Platform::CalculateMD5 (const FileSpec& file_spec,
1460 uint64_t &low,
1461 uint64_t &high)
1462{
1463 if (IsHost())
Zachary Turnerc00cf4a2014-08-15 22:04:21 +00001464 return FileSystem::CalculateMD5(file_spec, low, high);
Daniel Maleae0f8f572013-08-26 23:57:52 +00001465 else
1466 return false;
1467}
1468
Todd Fialaaf245d12014-06-30 21:05:18 +00001469Error
1470Platform::LaunchNativeProcess (
1471 ProcessLaunchInfo &launch_info,
1472 lldb_private::NativeProcessProtocol::NativeDelegate &native_delegate,
1473 NativeProcessProtocolSP &process_sp)
1474{
1475 // Platforms should override this implementation if they want to
1476 // support lldb-gdbserver.
1477 return Error("unimplemented");
1478}
1479
1480Error
1481Platform::AttachNativeProcess (lldb::pid_t pid,
1482 lldb_private::NativeProcessProtocol::NativeDelegate &native_delegate,
1483 NativeProcessProtocolSP &process_sp)
1484{
1485 // Platforms should override this implementation if they want to
1486 // support lldb-gdbserver.
1487 return Error("unimplemented");
1488}
1489
Daniel Maleae0f8f572013-08-26 23:57:52 +00001490void
1491Platform::SetLocalCacheDirectory (const char* local)
1492{
1493 m_local_cache_directory.assign(local);
1494}
1495
1496const char*
1497Platform::GetLocalCacheDirectory ()
1498{
1499 return m_local_cache_directory.c_str();
1500}
1501
1502static OptionDefinition
1503g_rsync_option_table[] =
1504{
Zachary Turnerd37221d2014-07-09 16:31:49 +00001505 { LLDB_OPT_SET_ALL, false, "rsync" , 'r', OptionParser::eNoArgument, NULL, NULL, 0, eArgTypeNone , "Enable rsync." },
1506 { LLDB_OPT_SET_ALL, false, "rsync-opts" , 'R', OptionParser::eRequiredArgument, NULL, NULL, 0, eArgTypeCommandName , "Platform-specific options required for rsync to work." },
1507 { LLDB_OPT_SET_ALL, false, "rsync-prefix" , 'P', OptionParser::eRequiredArgument, NULL, NULL, 0, eArgTypeCommandName , "Platform-specific rsync prefix put before the remote path." },
1508 { LLDB_OPT_SET_ALL, false, "ignore-remote-hostname" , 'i', OptionParser::eNoArgument, NULL, NULL, 0, eArgTypeNone , "Do not automatically fill in the remote hostname when composing the rsync command." },
Daniel Maleae0f8f572013-08-26 23:57:52 +00001509};
1510
1511static OptionDefinition
1512g_ssh_option_table[] =
1513{
Zachary Turnerd37221d2014-07-09 16:31:49 +00001514 { LLDB_OPT_SET_ALL, false, "ssh" , 's', OptionParser::eNoArgument, NULL, NULL, 0, eArgTypeNone , "Enable SSH." },
1515 { LLDB_OPT_SET_ALL, false, "ssh-opts" , 'S', OptionParser::eRequiredArgument, NULL, NULL, 0, eArgTypeCommandName , "Platform-specific options required for SSH to work." },
Daniel Maleae0f8f572013-08-26 23:57:52 +00001516};
1517
1518static OptionDefinition
1519g_caching_option_table[] =
1520{
Zachary Turnerd37221d2014-07-09 16:31:49 +00001521 { LLDB_OPT_SET_ALL, false, "local-cache-dir" , 'c', OptionParser::eRequiredArgument, NULL, NULL, 0, eArgTypePath , "Path in which to store local copies of files." },
Daniel Maleae0f8f572013-08-26 23:57:52 +00001522};
1523
1524OptionGroupPlatformRSync::OptionGroupPlatformRSync ()
1525{
1526}
1527
1528OptionGroupPlatformRSync::~OptionGroupPlatformRSync ()
1529{
1530}
1531
1532const lldb_private::OptionDefinition*
1533OptionGroupPlatformRSync::GetDefinitions ()
1534{
1535 return g_rsync_option_table;
1536}
1537
1538void
1539OptionGroupPlatformRSync::OptionParsingStarting (CommandInterpreter &interpreter)
1540{
1541 m_rsync = false;
1542 m_rsync_opts.clear();
1543 m_rsync_prefix.clear();
1544 m_ignores_remote_hostname = false;
1545}
1546
1547lldb_private::Error
1548OptionGroupPlatformRSync::SetOptionValue (CommandInterpreter &interpreter,
1549 uint32_t option_idx,
1550 const char *option_arg)
1551{
1552 Error error;
1553 char short_option = (char) GetDefinitions()[option_idx].short_option;
1554 switch (short_option)
1555 {
1556 case 'r':
1557 m_rsync = true;
1558 break;
1559
1560 case 'R':
1561 m_rsync_opts.assign(option_arg);
1562 break;
1563
1564 case 'P':
1565 m_rsync_prefix.assign(option_arg);
1566 break;
1567
1568 case 'i':
1569 m_ignores_remote_hostname = true;
1570 break;
1571
1572 default:
1573 error.SetErrorStringWithFormat ("unrecognized option '%c'", short_option);
1574 break;
1575 }
1576
1577 return error;
1578}
1579
1580uint32_t
1581OptionGroupPlatformRSync::GetNumDefinitions ()
1582{
1583 return llvm::array_lengthof(g_rsync_option_table);
1584}
Greg Clayton1e0c8842013-01-11 20:49:54 +00001585
Greg Clayton4116e932012-05-15 02:33:01 +00001586lldb::BreakpointSP
1587Platform::SetThreadCreationBreakpoint (lldb_private::Target &target)
1588{
1589 return lldb::BreakpointSP();
1590}
Greg Claytonb3a40ba2012-03-20 18:34:04 +00001591
Daniel Maleae0f8f572013-08-26 23:57:52 +00001592OptionGroupPlatformSSH::OptionGroupPlatformSSH ()
1593{
1594}
1595
1596OptionGroupPlatformSSH::~OptionGroupPlatformSSH ()
1597{
1598}
1599
1600const lldb_private::OptionDefinition*
1601OptionGroupPlatformSSH::GetDefinitions ()
1602{
1603 return g_ssh_option_table;
1604}
1605
1606void
1607OptionGroupPlatformSSH::OptionParsingStarting (CommandInterpreter &interpreter)
1608{
1609 m_ssh = false;
1610 m_ssh_opts.clear();
1611}
1612
1613lldb_private::Error
1614OptionGroupPlatformSSH::SetOptionValue (CommandInterpreter &interpreter,
1615 uint32_t option_idx,
1616 const char *option_arg)
1617{
1618 Error error;
1619 char short_option = (char) GetDefinitions()[option_idx].short_option;
1620 switch (short_option)
1621 {
1622 case 's':
1623 m_ssh = true;
1624 break;
1625
1626 case 'S':
1627 m_ssh_opts.assign(option_arg);
1628 break;
1629
1630 default:
1631 error.SetErrorStringWithFormat ("unrecognized option '%c'", short_option);
1632 break;
1633 }
1634
1635 return error;
1636}
1637
1638uint32_t
1639OptionGroupPlatformSSH::GetNumDefinitions ()
1640{
1641 return llvm::array_lengthof(g_ssh_option_table);
1642}
1643
1644OptionGroupPlatformCaching::OptionGroupPlatformCaching ()
1645{
1646}
1647
1648OptionGroupPlatformCaching::~OptionGroupPlatformCaching ()
1649{
1650}
1651
1652const lldb_private::OptionDefinition*
1653OptionGroupPlatformCaching::GetDefinitions ()
1654{
1655 return g_caching_option_table;
1656}
1657
1658void
1659OptionGroupPlatformCaching::OptionParsingStarting (CommandInterpreter &interpreter)
1660{
1661 m_cache_dir.clear();
1662}
1663
1664lldb_private::Error
1665OptionGroupPlatformCaching::SetOptionValue (CommandInterpreter &interpreter,
1666 uint32_t option_idx,
1667 const char *option_arg)
1668{
1669 Error error;
1670 char short_option = (char) GetDefinitions()[option_idx].short_option;
1671 switch (short_option)
1672 {
1673 case 'c':
1674 m_cache_dir.assign(option_arg);
1675 break;
1676
1677 default:
1678 error.SetErrorStringWithFormat ("unrecognized option '%c'", short_option);
1679 break;
1680 }
1681
1682 return error;
1683}
1684
1685uint32_t
1686OptionGroupPlatformCaching::GetNumDefinitions ()
1687{
1688 return llvm::array_lengthof(g_caching_option_table);
1689}
1690
Greg Clayton67cc0632012-08-22 17:17:09 +00001691size_t
1692Platform::GetEnvironment (StringList &environment)
1693{
1694 environment.Clear();
1695 return false;
1696}
Jason Molenda2094dbf2014-02-13 23:11:45 +00001697
1698const std::vector<ConstString> &
1699Platform::GetTrapHandlerSymbolNames ()
1700{
1701 if (!m_calculated_trap_handlers)
1702 {
Greg Clayton7597b352015-02-02 20:45:17 +00001703 Mutex::Locker locker (m_mutex);
Jason Molenda4da87062014-05-23 23:11:27 +00001704 if (!m_calculated_trap_handlers)
1705 {
1706 CalculateTrapHandlerSymbolNames();
1707 m_calculated_trap_handlers = true;
1708 }
Jason Molenda2094dbf2014-02-13 23:11:45 +00001709 }
1710 return m_trap_handlers;
1711}
1712