blob: 5077ca23bf74674644881b7241dbaff23db6262c [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
Oleksiy Vyalov63acdfd2015-03-10 01:15:28 +000013
Greg Claytone996fd32011-03-08 22:40:15 +000014// C++ Includes
Oleksiy Vyalov63acdfd2015-03-10 01:15:28 +000015#include <algorithm>
16#include <fstream>
17#include <vector>
18
Greg Claytone996fd32011-03-08 22:40:15 +000019// Other libraries and framework includes
20// Project includes
Greg Clayton4116e932012-05-15 02:33:01 +000021#include "lldb/Breakpoint/BreakpointIDList.h"
Zachary Turneraf0f45f2015-03-03 21:05:17 +000022#include "lldb/Core/DataBufferHeap.h"
Zachary Turner7271bab2015-05-13 19:44:24 +000023#include "lldb/Core/Debugger.h"
Greg Claytone996fd32011-03-08 22:40:15 +000024#include "lldb/Core/Error.h"
Greg Clayton8b82f082011-04-12 05:54:46 +000025#include "lldb/Core/Log.h"
Oleksiy Vyalov63acdfd2015-03-10 01:15:28 +000026#include "lldb/Core/Module.h"
Greg Clayton1f746072012-08-29 21:13:06 +000027#include "lldb/Core/ModuleSpec.h"
Greg Claytone996fd32011-03-08 22:40:15 +000028#include "lldb/Core/PluginManager.h"
Tamas Berghammerccd6cff2015-12-08 14:08:19 +000029#include "lldb/Core/StreamFile.h"
Enrico Granatad7a83a92015-02-10 03:06:24 +000030#include "lldb/Core/StructuredData.h"
Greg Claytone996fd32011-03-08 22:40:15 +000031#include "lldb/Host/FileSpec.h"
Zachary Turnerc00cf4a2014-08-15 22:04:21 +000032#include "lldb/Host/FileSystem.h"
Greg Claytonded470d2011-03-19 01:12:21 +000033#include "lldb/Host/Host.h"
Zachary Turner97a14e62014-08-19 17:18:29 +000034#include "lldb/Host/HostInfo.h"
Oleksiy Vyalov63acdfd2015-03-10 01:15:28 +000035#include "lldb/Interpreter/OptionValueProperties.h"
36#include "lldb/Interpreter/Property.h"
37#include "lldb/Symbol/ObjectFile.h"
Greg Clayton8b82f082011-04-12 05:54:46 +000038#include "lldb/Target/Process.h"
Greg Claytone996fd32011-03-08 22:40:15 +000039#include "lldb/Target/Target.h"
Chaoren Lin98d0a4b2015-07-14 01:09:28 +000040#include "lldb/Target/UnixSignals.h"
Daniel Maleae0f8f572013-08-26 23:57:52 +000041#include "lldb/Utility/Utils.h"
Oleksiy Vyalov63acdfd2015-03-10 01:15:28 +000042#include "llvm/Support/FileSystem.h"
Oleksiy Vyalovd21ca282015-10-01 17:48:57 +000043#include "llvm/Support/Path.h"
Oleksiy Vyalov63acdfd2015-03-10 01:15:28 +000044
45#include "Utility/ModuleCache.h"
Greg Claytone996fd32011-03-08 22:40:15 +000046
Adrian McCarthy3f989d42015-10-26 21:38:41 +000047
Robert Flack96ad3de2015-05-09 15:53:31 +000048// Define these constants from POSIX mman.h rather than include the file
49// so that they will be correct even when compiled on Linux.
50#define MAP_PRIVATE 2
51#define MAP_ANON 0x1000
52
Greg Claytone996fd32011-03-08 22:40:15 +000053using namespace lldb;
54using namespace lldb_private;
Tamas Berghammer3c4f89d2015-02-12 18:18:27 +000055
56static uint32_t g_initialize_count = 0;
57
Greg Claytone996fd32011-03-08 22:40:15 +000058// Use a singleton function for g_local_platform_sp to avoid init
59// constructors since LLDB is often part of a shared library
60static PlatformSP&
Greg Clayton615eb7e2014-09-19 20:11:50 +000061GetHostPlatformSP ()
Greg Claytone996fd32011-03-08 22:40:15 +000062{
Greg Clayton615eb7e2014-09-19 20:11:50 +000063 static PlatformSP g_platform_sp;
64 return g_platform_sp;
Greg Claytone996fd32011-03-08 22:40:15 +000065}
66
Greg Claytonab65b342011-04-13 22:47:15 +000067const char *
68Platform::GetHostPlatformName ()
69{
70 return "host";
71}
72
Oleksiy Vyalov63acdfd2015-03-10 01:15:28 +000073namespace {
74
75 PropertyDefinition
76 g_properties[] =
77 {
78 { "use-module-cache" , OptionValue::eTypeBoolean , true, true, nullptr, nullptr, "Use module cache." },
79 { "module-cache-directory", OptionValue::eTypeFileSpec, true, 0 , nullptr, nullptr, "Root directory for cached modules." },
80 { nullptr , OptionValue::eTypeInvalid , false, 0, nullptr, nullptr, nullptr }
81 };
82
83 enum
84 {
85 ePropertyUseModuleCache,
86 ePropertyModuleCacheDirectory
87 };
88
89} // namespace
90
91
92ConstString
93PlatformProperties::GetSettingName ()
94{
95 static ConstString g_setting_name("platform");
96 return g_setting_name;
97}
98
99PlatformProperties::PlatformProperties ()
100{
101 m_collection_sp.reset (new OptionValueProperties (GetSettingName ()));
102 m_collection_sp->Initialize (g_properties);
103
104 auto module_cache_dir = GetModuleCacheDirectory ();
Oleksiy Vyalovd21ca282015-10-01 17:48:57 +0000105 if (module_cache_dir)
106 return;
107
108 llvm::SmallString<64> user_home_dir;
109 if (!llvm::sys::path::home_directory (user_home_dir))
110 return;
111
112 module_cache_dir = FileSpec (user_home_dir.c_str(), false);
113 module_cache_dir.AppendPathComponent (".lldb");
114 module_cache_dir.AppendPathComponent ("module_cache");
115 SetModuleCacheDirectory (module_cache_dir);
Oleksiy Vyalov63acdfd2015-03-10 01:15:28 +0000116}
117
118bool
119PlatformProperties::GetUseModuleCache () const
120{
121 const auto idx = ePropertyUseModuleCache;
122 return m_collection_sp->GetPropertyAtIndexAsBoolean (
123 nullptr, idx, g_properties[idx].default_uint_value != 0);
124}
125
126bool
127PlatformProperties::SetUseModuleCache (bool use_module_cache)
128{
129 return m_collection_sp->SetPropertyAtIndexAsBoolean (nullptr, ePropertyUseModuleCache, use_module_cache);
130}
131
132FileSpec
133PlatformProperties::GetModuleCacheDirectory () const
134{
135 return m_collection_sp->GetPropertyAtIndexAsFileSpec (nullptr, ePropertyModuleCacheDirectory);
136}
137
138bool
139PlatformProperties::SetModuleCacheDirectory (const FileSpec& dir_spec)
140{
141 return m_collection_sp->SetPropertyAtIndexAsFileSpec (nullptr, ePropertyModuleCacheDirectory, dir_spec);
142}
143
Greg Claytone996fd32011-03-08 22:40:15 +0000144//------------------------------------------------------------------
145/// Get the native host platform plug-in.
146///
147/// There should only be one of these for each host that LLDB runs
148/// upon that should be statically compiled in and registered using
149/// preprocessor macros or other similar build mechanisms.
150///
151/// This platform will be used as the default platform when launching
152/// or attaching to processes unless another platform is specified.
153//------------------------------------------------------------------
154PlatformSP
Greg Clayton615eb7e2014-09-19 20:11:50 +0000155Platform::GetHostPlatform ()
Greg Claytone996fd32011-03-08 22:40:15 +0000156{
Greg Clayton615eb7e2014-09-19 20:11:50 +0000157 return GetHostPlatformSP ();
158}
159
160static std::vector<PlatformSP> &
161GetPlatformList()
162{
163 static std::vector<PlatformSP> g_platform_list;
164 return g_platform_list;
165}
166
167static Mutex &
168GetPlatformListMutex ()
169{
170 static Mutex g_mutex(Mutex::eMutexTypeRecursive);
171 return g_mutex;
Greg Claytone996fd32011-03-08 22:40:15 +0000172}
173
174void
Tamas Berghammer3c4f89d2015-02-12 18:18:27 +0000175Platform::Initialize ()
176{
177 g_initialize_count++;
178}
179
180void
181Platform::Terminate ()
182{
183 if (g_initialize_count > 0)
184 {
185 if (--g_initialize_count == 0)
186 {
187 Mutex::Locker locker(GetPlatformListMutex ());
188 GetPlatformList().clear();
189 }
190 }
191}
192
Oleksiy Vyalov63acdfd2015-03-10 01:15:28 +0000193const PlatformPropertiesSP &
194Platform::GetGlobalPlatformProperties ()
195{
196 static const auto g_settings_sp (std::make_shared<PlatformProperties> ());
197 return g_settings_sp;
198}
199
Tamas Berghammer3c4f89d2015-02-12 18:18:27 +0000200void
Greg Clayton615eb7e2014-09-19 20:11:50 +0000201Platform::SetHostPlatform (const lldb::PlatformSP &platform_sp)
Greg Claytone996fd32011-03-08 22:40:15 +0000202{
203 // The native platform should use its static void Platform::Initialize()
204 // function to register itself as the native platform.
Greg Clayton615eb7e2014-09-19 20:11:50 +0000205 GetHostPlatformSP () = platform_sp;
206
207 if (platform_sp)
208 {
209 Mutex::Locker locker(GetPlatformListMutex ());
210 GetPlatformList().push_back(platform_sp);
211 }
Greg Claytone996fd32011-03-08 22:40:15 +0000212}
213
Greg Claytone996fd32011-03-08 22:40:15 +0000214Error
Steve Puccifc995722014-01-17 18:18:31 +0000215Platform::GetFileWithUUID (const FileSpec &platform_file,
216 const UUID *uuid_ptr,
217 FileSpec &local_file)
Greg Claytone996fd32011-03-08 22:40:15 +0000218{
219 // Default to the local case
220 local_file = platform_file;
221 return Error();
222}
223
Greg Clayton91c0e742013-01-11 23:44:27 +0000224FileSpecList
Enrico Granatafe7295d2014-08-16 00:32:58 +0000225Platform::LocateExecutableScriptingResources (Target *target, Module &module, Stream* feedback_stream)
Enrico Granata17598482012-11-08 02:22:02 +0000226{
Greg Clayton91c0e742013-01-11 23:44:27 +0000227 return FileSpecList();
Enrico Granata17598482012-11-08 02:22:02 +0000228}
229
Greg Clayton615eb7e2014-09-19 20:11:50 +0000230//PlatformSP
231//Platform::FindPlugin (Process *process, const ConstString &plugin_name)
232//{
233// PlatformCreateInstance create_callback = NULL;
234// if (plugin_name)
235// {
236// create_callback = PluginManager::GetPlatformCreateCallbackForPluginName (plugin_name);
237// if (create_callback)
238// {
239// ArchSpec arch;
240// if (process)
241// {
242// arch = process->GetTarget().GetArchitecture();
243// }
244// PlatformSP platform_sp(create_callback(process, &arch));
245// if (platform_sp)
246// return platform_sp;
247// }
248// }
249// else
250// {
251// for (uint32_t idx = 0; (create_callback = PluginManager::GetPlatformCreateCallbackAtIndex(idx)) != NULL; ++idx)
252// {
253// PlatformSP platform_sp(create_callback(process, nullptr));
254// if (platform_sp)
255// return platform_sp;
256// }
257// }
258// return PlatformSP();
259//}
Jason Molenda1c627542013-04-05 01:03:25 +0000260
Greg Clayton32e0a752011-03-30 18:16:51 +0000261Error
Greg Claytonb9a01b32012-02-26 05:51:37 +0000262Platform::GetSharedModule (const ModuleSpec &module_spec,
Tamas Berghammer7cb18bf2015-03-24 11:15:23 +0000263 Process* process,
Greg Clayton32e0a752011-03-30 18:16:51 +0000264 ModuleSP &module_sp,
Greg Claytonc859e2d2012-02-13 23:10:39 +0000265 const FileSpecList *module_search_paths_ptr,
Greg Clayton32e0a752011-03-30 18:16:51 +0000266 ModuleSP *old_module_sp_ptr,
267 bool *did_create_ptr)
268{
Oleksiy Vyalov037f6b92015-03-24 23:45:49 +0000269 if (IsHost ())
270 return ModuleList::GetSharedModule (module_spec,
271 module_sp,
272 module_search_paths_ptr,
273 old_module_sp_ptr,
274 did_create_ptr,
275 false);
Oleksiy Vyalov63acdfd2015-03-10 01:15:28 +0000276
Oleksiy Vyalov037f6b92015-03-24 23:45:49 +0000277 return GetRemoteSharedModule (module_spec,
278 process,
279 module_sp,
280 [&](const ModuleSpec &spec)
281 {
Tamas Berghammer980662e2015-09-04 12:42:41 +0000282 Error error = ModuleList::GetSharedModule (
Oleksiy Vyalov037f6b92015-03-24 23:45:49 +0000283 spec, module_sp, module_search_paths_ptr, old_module_sp_ptr, did_create_ptr, false);
Tamas Berghammer980662e2015-09-04 12:42:41 +0000284 if (error.Success() && module_sp)
285 module_sp->SetPlatformFileSpec(spec.GetFileSpec());
286 return error;
Oleksiy Vyalov037f6b92015-03-24 23:45:49 +0000287 },
288 did_create_ptr);
Oleksiy Vyalov63acdfd2015-03-10 01:15:28 +0000289}
290
291bool
292Platform::GetModuleSpec (const FileSpec& module_file_spec,
293 const ArchSpec& arch,
294 ModuleSpec &module_spec)
295{
296 ModuleSpecList module_specs;
297 if (ObjectFile::GetModuleSpecifications (module_file_spec, 0, 0, module_specs) == 0)
298 return false;
299
300 ModuleSpec matched_module_spec;
301 return module_specs.FindMatchingModuleSpec (ModuleSpec (module_file_spec, arch),
302 module_spec);
Greg Clayton32e0a752011-03-30 18:16:51 +0000303}
304
Greg Claytone996fd32011-03-08 22:40:15 +0000305PlatformSP
Greg Clayton615eb7e2014-09-19 20:11:50 +0000306Platform::Find (const ConstString &name)
307{
308 if (name)
309 {
310 static ConstString g_host_platform_name ("host");
311 if (name == g_host_platform_name)
312 return GetHostPlatform();
313
314 Mutex::Locker locker(GetPlatformListMutex ());
315 for (const auto &platform_sp : GetPlatformList())
316 {
317 if (platform_sp->GetName() == name)
318 return platform_sp;
319 }
320 }
321 return PlatformSP();
322}
323
324PlatformSP
325Platform::Create (const ConstString &name, Error &error)
Greg Claytone996fd32011-03-08 22:40:15 +0000326{
327 PlatformCreateInstance create_callback = NULL;
328 lldb::PlatformSP platform_sp;
Greg Clayton615eb7e2014-09-19 20:11:50 +0000329 if (name)
Greg Claytone996fd32011-03-08 22:40:15 +0000330 {
Greg Clayton615eb7e2014-09-19 20:11:50 +0000331 static ConstString g_host_platform_name ("host");
332 if (name == g_host_platform_name)
333 return GetHostPlatform();
334
335 create_callback = PluginManager::GetPlatformCreateCallbackForPluginName (name);
Greg Claytone996fd32011-03-08 22:40:15 +0000336 if (create_callback)
Greg Clayton615eb7e2014-09-19 20:11:50 +0000337 platform_sp = create_callback(true, NULL);
Greg Claytone996fd32011-03-08 22:40:15 +0000338 else
Greg Clayton615eb7e2014-09-19 20:11:50 +0000339 error.SetErrorStringWithFormat ("unable to find a plug-in for the platform named \"%s\"", name.GetCString());
Greg Claytone996fd32011-03-08 22:40:15 +0000340 }
341 else
Greg Claytonded470d2011-03-19 01:12:21 +0000342 error.SetErrorString ("invalid platform name");
Greg Clayton615eb7e2014-09-19 20:11:50 +0000343
344 if (platform_sp)
345 {
346 Mutex::Locker locker(GetPlatformListMutex ());
347 GetPlatformList().push_back(platform_sp);
348 }
349
Greg Claytone996fd32011-03-08 22:40:15 +0000350 return platform_sp;
351}
352
Greg Claytonb3a40ba2012-03-20 18:34:04 +0000353
354PlatformSP
Greg Clayton70512312012-05-08 01:45:38 +0000355Platform::Create (const ArchSpec &arch, ArchSpec *platform_arch_ptr, Error &error)
Greg Claytonb3a40ba2012-03-20 18:34:04 +0000356{
357 lldb::PlatformSP platform_sp;
358 if (arch.IsValid())
359 {
Greg Clayton615eb7e2014-09-19 20:11:50 +0000360 // Scope for locker
Greg Claytonb3a40ba2012-03-20 18:34:04 +0000361 {
Greg Clayton615eb7e2014-09-19 20:11:50 +0000362 // First try exact arch matches across all platforms already created
363 Mutex::Locker locker(GetPlatformListMutex ());
364 for (const auto &platform_sp : GetPlatformList())
Greg Clayton1e0c8842013-01-11 20:49:54 +0000365 {
Greg Clayton615eb7e2014-09-19 20:11:50 +0000366 if (platform_sp->IsCompatibleArchitecture(arch, true, platform_arch_ptr))
367 return platform_sp;
368 }
369
370 // Next try compatible arch matches across all platforms already created
371 for (const auto &platform_sp : GetPlatformList())
372 {
373 if (platform_sp->IsCompatibleArchitecture(arch, false, platform_arch_ptr))
Greg Clayton1e0c8842013-01-11 20:49:54 +0000374 return platform_sp;
375 }
376 }
Greg Clayton615eb7e2014-09-19 20:11:50 +0000377
378 PlatformCreateInstance create_callback;
379 // First try exact arch matches across all platform plug-ins
380 uint32_t idx;
Greg Clayton1e0c8842013-01-11 20:49:54 +0000381 for (idx = 0; (create_callback = PluginManager::GetPlatformCreateCallbackAtIndex (idx)); ++idx)
382 {
383 if (create_callback)
384 {
Greg Clayton615eb7e2014-09-19 20:11:50 +0000385 platform_sp = create_callback(false, &arch);
386 if (platform_sp && platform_sp->IsCompatibleArchitecture(arch, true, platform_arch_ptr))
387 {
388 Mutex::Locker locker(GetPlatformListMutex ());
389 GetPlatformList().push_back(platform_sp);
Greg Clayton1e0c8842013-01-11 20:49:54 +0000390 return platform_sp;
Greg Clayton615eb7e2014-09-19 20:11:50 +0000391 }
392 }
393 }
394 // Next try compatible arch matches across all platform plug-ins
395 for (idx = 0; (create_callback = PluginManager::GetPlatformCreateCallbackAtIndex (idx)); ++idx)
396 {
397 if (create_callback)
398 {
399 platform_sp = create_callback(false, &arch);
400 if (platform_sp && platform_sp->IsCompatibleArchitecture(arch, false, platform_arch_ptr))
401 {
402 Mutex::Locker locker(GetPlatformListMutex ());
403 GetPlatformList().push_back(platform_sp);
404 return platform_sp;
405 }
Greg Clayton1e0c8842013-01-11 20:49:54 +0000406 }
Greg Claytonb3a40ba2012-03-20 18:34:04 +0000407 }
408 }
409 else
410 error.SetErrorString ("invalid platform name");
Greg Clayton70512312012-05-08 01:45:38 +0000411 if (platform_arch_ptr)
412 platform_arch_ptr->Clear();
413 platform_sp.reset();
Greg Claytonb3a40ba2012-03-20 18:34:04 +0000414 return platform_sp;
415}
416
Greg Claytone996fd32011-03-08 22:40:15 +0000417//------------------------------------------------------------------
418/// Default Constructor
419//------------------------------------------------------------------
Greg Claytonded470d2011-03-19 01:12:21 +0000420Platform::Platform (bool is_host) :
421 m_is_host (is_host),
Greg Claytonded470d2011-03-19 01:12:21 +0000422 m_os_version_set_while_connected (false),
423 m_system_arch_set_while_connected (false),
Greg Claytonf3dd93c2011-06-17 03:31:01 +0000424 m_sdk_sysroot (),
425 m_sdk_build (),
Greg Claytonfbb76342013-11-20 21:07:01 +0000426 m_working_dir (),
Greg Claytonded470d2011-03-19 01:12:21 +0000427 m_remote_url (),
Greg Clayton1cb64962011-03-24 04:28:38 +0000428 m_name (),
Greg Claytonded470d2011-03-19 01:12:21 +0000429 m_major_os_version (UINT32_MAX),
430 m_minor_os_version (UINT32_MAX),
Greg Clayton32e0a752011-03-30 18:16:51 +0000431 m_update_os_version (UINT32_MAX),
432 m_system_arch(),
Greg Clayton7597b352015-02-02 20:45:17 +0000433 m_mutex (Mutex::eMutexTypeRecursive),
Greg Clayton32e0a752011-03-30 18:16:51 +0000434 m_uid_map(),
435 m_gid_map(),
436 m_max_uid_name_len (0),
Daniel Maleae0f8f572013-08-26 23:57:52 +0000437 m_max_gid_name_len (0),
438 m_supports_rsync (false),
439 m_rsync_opts (),
440 m_rsync_prefix (),
441 m_supports_ssh (false),
442 m_ssh_opts (),
Jason Molenda6223db272014-02-13 07:11:08 +0000443 m_ignores_remote_hostname (false),
Jason Molenda2094dbf2014-02-13 23:11:45 +0000444 m_trap_handlers(),
Oleksiy Vyalov63acdfd2015-03-10 01:15:28 +0000445 m_calculated_trap_handlers (false),
446 m_module_cache (llvm::make_unique<ModuleCache> ())
Greg Claytone996fd32011-03-08 22:40:15 +0000447{
Greg Clayton5160ce52013-03-27 23:08:40 +0000448 Log *log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_OBJECT));
Greg Clayton8b82f082011-04-12 05:54:46 +0000449 if (log)
Saleem Abdulrasool324a1032014-04-04 04:06:10 +0000450 log->Printf ("%p Platform::Platform()", static_cast<void*>(this));
Greg Claytone996fd32011-03-08 22:40:15 +0000451}
452
453//------------------------------------------------------------------
454/// Destructor.
455///
456/// The destructor is virtual since this class is designed to be
457/// inherited from by the plug-in instance.
458//------------------------------------------------------------------
459Platform::~Platform()
460{
Greg Clayton5160ce52013-03-27 23:08:40 +0000461 Log *log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_OBJECT));
Greg Clayton8b82f082011-04-12 05:54:46 +0000462 if (log)
Saleem Abdulrasool324a1032014-04-04 04:06:10 +0000463 log->Printf ("%p Platform::~Platform()", static_cast<void*>(this));
Greg Claytone996fd32011-03-08 22:40:15 +0000464}
465
Greg Clayton1cb64962011-03-24 04:28:38 +0000466void
467Platform::GetStatus (Stream &strm)
468{
469 uint32_t major = UINT32_MAX;
470 uint32_t minor = UINT32_MAX;
471 uint32_t update = UINT32_MAX;
472 std::string s;
Greg Clayton57abc5d2013-05-10 21:47:16 +0000473 strm.Printf (" Platform: %s\n", GetPluginName().GetCString());
Greg Clayton1cb64962011-03-24 04:28:38 +0000474
475 ArchSpec arch (GetSystemArchitecture());
476 if (arch.IsValid())
477 {
478 if (!arch.GetTriple().str().empty())
Todd Fiala7df337f2015-10-13 23:41:19 +0000479 {
480 strm.Printf(" Triple: ");
481 arch.DumpTriple(strm);
482 strm.EOL();
483 }
Greg Clayton1cb64962011-03-24 04:28:38 +0000484 }
485
486 if (GetOSVersion(major, minor, update))
487 {
Greg Clayton32e0a752011-03-30 18:16:51 +0000488 strm.Printf("OS Version: %u", major);
Greg Clayton1cb64962011-03-24 04:28:38 +0000489 if (minor != UINT32_MAX)
490 strm.Printf(".%u", minor);
491 if (update != UINT32_MAX)
492 strm.Printf(".%u", update);
493
494 if (GetOSBuildString (s))
495 strm.Printf(" (%s)", s.c_str());
496
497 strm.EOL();
498 }
499
500 if (GetOSKernelDescription (s))
Greg Clayton32e0a752011-03-30 18:16:51 +0000501 strm.Printf(" Kernel: %s\n", s.c_str());
Greg Clayton1cb64962011-03-24 04:28:38 +0000502
503 if (IsHost())
504 {
Greg Clayton32e0a752011-03-30 18:16:51 +0000505 strm.Printf(" Hostname: %s\n", GetHostname());
Greg Clayton1cb64962011-03-24 04:28:38 +0000506 }
507 else
508 {
Greg Clayton32e0a752011-03-30 18:16:51 +0000509 const bool is_connected = IsConnected();
510 if (is_connected)
511 strm.Printf(" Hostname: %s\n", GetHostname());
512 strm.Printf(" Connected: %s\n", is_connected ? "yes" : "no");
Greg Clayton1cb64962011-03-24 04:28:38 +0000513 }
Daniel Maleae0f8f572013-08-26 23:57:52 +0000514
Greg Claytonfbb76342013-11-20 21:07:01 +0000515 if (GetWorkingDirectory())
516 {
517 strm.Printf("WorkingDir: %s\n", GetWorkingDirectory().GetCString());
518 }
Daniel Maleae0f8f572013-08-26 23:57:52 +0000519 if (!IsConnected())
520 return;
521
522 std::string specific_info(GetPlatformSpecificConnectionInformation());
523
524 if (specific_info.empty() == false)
525 strm.Printf("Platform-specific connection: %s\n", specific_info.c_str());
Greg Clayton1cb64962011-03-24 04:28:38 +0000526}
527
Greg Claytonded470d2011-03-19 01:12:21 +0000528
529bool
530Platform::GetOSVersion (uint32_t &major,
531 uint32_t &minor,
Jim Ingham13c30d22015-11-05 22:33:17 +0000532 uint32_t &update,
533 Process *process)
Greg Claytonded470d2011-03-19 01:12:21 +0000534{
Greg Clayton7597b352015-02-02 20:45:17 +0000535 Mutex::Locker locker (m_mutex);
536
Greg Claytonded470d2011-03-19 01:12:21 +0000537 bool success = m_major_os_version != UINT32_MAX;
538 if (IsHost())
539 {
540 if (!success)
541 {
542 // We have a local host platform
Zachary Turner97a14e62014-08-19 17:18:29 +0000543 success = HostInfo::GetOSVersion(m_major_os_version, m_minor_os_version, m_update_os_version);
Greg Claytonded470d2011-03-19 01:12:21 +0000544 m_os_version_set_while_connected = success;
545 }
546 }
547 else
548 {
549 // We have a remote platform. We can only fetch the remote
550 // OS version if we are connected, and we don't want to do it
551 // more than once.
552
553 const bool is_connected = IsConnected();
554
Greg Clayton1cb64962011-03-24 04:28:38 +0000555 bool fetch = false;
Greg Claytonded470d2011-03-19 01:12:21 +0000556 if (success)
557 {
558 // We have valid OS version info, check to make sure it wasn't
559 // manually set prior to connecting. If it was manually set prior
560 // to connecting, then lets fetch the actual OS version info
561 // if we are now connected.
562 if (is_connected && !m_os_version_set_while_connected)
Greg Clayton1cb64962011-03-24 04:28:38 +0000563 fetch = true;
Greg Claytonded470d2011-03-19 01:12:21 +0000564 }
565 else
566 {
567 // We don't have valid OS version info, fetch it if we are connected
Greg Clayton1cb64962011-03-24 04:28:38 +0000568 fetch = is_connected;
Greg Claytonded470d2011-03-19 01:12:21 +0000569 }
570
Greg Clayton1cb64962011-03-24 04:28:38 +0000571 if (fetch)
Greg Claytonded470d2011-03-19 01:12:21 +0000572 {
Greg Clayton1cb64962011-03-24 04:28:38 +0000573 success = GetRemoteOSVersion ();
Greg Claytonded470d2011-03-19 01:12:21 +0000574 m_os_version_set_while_connected = success;
575 }
576 }
577
578 if (success)
579 {
580 major = m_major_os_version;
581 minor = m_minor_os_version;
582 update = m_update_os_version;
583 }
Jim Ingham13c30d22015-11-05 22:33:17 +0000584 else if (process)
585 {
586 // Check with the process in case it can answer the question if
587 // a process was provided
588 return process->GetHostOSVersion(major, minor, update);
589 }
Greg Claytonded470d2011-03-19 01:12:21 +0000590 return success;
591}
Greg Clayton1cb64962011-03-24 04:28:38 +0000592
593bool
594Platform::GetOSBuildString (std::string &s)
595{
Zachary Turner97a14e62014-08-19 17:18:29 +0000596 s.clear();
597
Greg Clayton1cb64962011-03-24 04:28:38 +0000598 if (IsHost())
Zachary Turner97a14e62014-08-19 17:18:29 +0000599#if !defined(__linux__)
600 return HostInfo::GetOSBuildString(s);
601#else
602 return false;
603#endif
Greg Clayton1cb64962011-03-24 04:28:38 +0000604 else
605 return GetRemoteOSBuildString (s);
606}
607
608bool
609Platform::GetOSKernelDescription (std::string &s)
610{
611 if (IsHost())
Zachary Turner97a14e62014-08-19 17:18:29 +0000612#if !defined(__linux__)
613 return HostInfo::GetOSKernelDescription(s);
614#else
615 return false;
616#endif
Greg Clayton1cb64962011-03-24 04:28:38 +0000617 else
618 return GetRemoteOSKernelDescription (s);
619}
620
Sean Callanan5dc29812014-12-05 01:16:31 +0000621void
Greg Claytoncd6bbba2015-01-22 18:25:49 +0000622Platform::AddClangModuleCompilationOptions (Target *target, std::vector<std::string> &options)
Sean Callanan5dc29812014-12-05 01:16:31 +0000623{
624 std::vector<std::string> default_compilation_options =
625 {
626 "-x", "c++", "-Xclang", "-nostdsysteminc", "-Xclang", "-nostdsysteminc"
627 };
628
629 options.insert(options.end(),
630 default_compilation_options.begin(),
631 default_compilation_options.end());
632}
633
634
Chaoren Lind3173f32015-05-29 19:52:29 +0000635FileSpec
Greg Claytonfbb76342013-11-20 21:07:01 +0000636Platform::GetWorkingDirectory ()
637{
638 if (IsHost())
639 {
640 char cwd[PATH_MAX];
641 if (getcwd(cwd, sizeof(cwd)))
Chaoren Lind3173f32015-05-29 19:52:29 +0000642 return FileSpec{cwd, true};
Greg Claytonfbb76342013-11-20 21:07:01 +0000643 else
Chaoren Lind3173f32015-05-29 19:52:29 +0000644 return FileSpec{};
Greg Claytonfbb76342013-11-20 21:07:01 +0000645 }
646 else
647 {
648 if (!m_working_dir)
649 m_working_dir = GetRemoteWorkingDirectory();
650 return m_working_dir;
651 }
652}
653
654
655struct RecurseCopyBaton
656{
657 const FileSpec& dst;
658 Platform *platform_ptr;
659 Error error;
660};
661
662
663static FileSpec::EnumerateDirectoryResult
664RecurseCopy_Callback (void *baton,
665 FileSpec::FileType file_type,
666 const FileSpec &src)
667{
668 RecurseCopyBaton* rc_baton = (RecurseCopyBaton*)baton;
669 switch (file_type)
670 {
671 case FileSpec::eFileTypePipe:
672 case FileSpec::eFileTypeSocket:
673 // we have no way to copy pipes and sockets - ignore them and continue
674 return FileSpec::eEnumerateDirectoryResultNext;
675 break;
676
677 case FileSpec::eFileTypeDirectory:
678 {
679 // make the new directory and get in there
680 FileSpec dst_dir = rc_baton->dst;
681 if (!dst_dir.GetFilename())
682 dst_dir.GetFilename() = src.GetLastPathComponent();
Chaoren Lind3173f32015-05-29 19:52:29 +0000683 Error error = rc_baton->platform_ptr->MakeDirectory(dst_dir, lldb::eFilePermissionsDirectoryDefault);
Greg Claytonfbb76342013-11-20 21:07:01 +0000684 if (error.Fail())
685 {
Chaoren Lind3173f32015-05-29 19:52:29 +0000686 rc_baton->error.SetErrorStringWithFormat("unable to setup directory %s on remote end",
687 dst_dir.GetCString());
Greg Claytonfbb76342013-11-20 21:07:01 +0000688 return FileSpec::eEnumerateDirectoryResultQuit; // got an error, bail out
689 }
690
691 // now recurse
692 std::string src_dir_path (src.GetPath());
693
694 // Make a filespec that only fills in the directory of a FileSpec so
695 // when we enumerate we can quickly fill in the filename for dst copies
696 FileSpec recurse_dst;
697 recurse_dst.GetDirectory().SetCString(dst_dir.GetPath().c_str());
698 RecurseCopyBaton rc_baton2 = { recurse_dst, rc_baton->platform_ptr, Error() };
699 FileSpec::EnumerateDirectory(src_dir_path.c_str(), true, true, true, RecurseCopy_Callback, &rc_baton2);
700 if (rc_baton2.error.Fail())
701 {
702 rc_baton->error.SetErrorString(rc_baton2.error.AsCString());
703 return FileSpec::eEnumerateDirectoryResultQuit; // got an error, bail out
704 }
705 return FileSpec::eEnumerateDirectoryResultNext;
706 }
707 break;
708
709 case FileSpec::eFileTypeSymbolicLink:
710 {
711 // copy the file and keep going
712 FileSpec dst_file = rc_baton->dst;
713 if (!dst_file.GetFilename())
714 dst_file.GetFilename() = src.GetFilename();
Zachary Turnerc00cf4a2014-08-15 22:04:21 +0000715
Chaoren Lind3173f32015-05-29 19:52:29 +0000716 FileSpec src_resolved;
717
718 rc_baton->error = FileSystem::Readlink(src, src_resolved);
Greg Claytonfbb76342013-11-20 21:07:01 +0000719
720 if (rc_baton->error.Fail())
721 return FileSpec::eEnumerateDirectoryResultQuit; // got an error, bail out
Chaoren Lind3173f32015-05-29 19:52:29 +0000722
723 rc_baton->error = rc_baton->platform_ptr->CreateSymlink(dst_file, src_resolved);
Greg Claytonfbb76342013-11-20 21:07:01 +0000724
725 if (rc_baton->error.Fail())
726 return FileSpec::eEnumerateDirectoryResultQuit; // got an error, bail out
727
728 return FileSpec::eEnumerateDirectoryResultNext;
729 }
730 break;
731 case FileSpec::eFileTypeRegular:
732 {
733 // copy the file and keep going
734 FileSpec dst_file = rc_baton->dst;
735 if (!dst_file.GetFilename())
736 dst_file.GetFilename() = src.GetFilename();
737 Error err = rc_baton->platform_ptr->PutFile(src, dst_file);
738 if (err.Fail())
739 {
740 rc_baton->error.SetErrorString(err.AsCString());
741 return FileSpec::eEnumerateDirectoryResultQuit; // got an error, bail out
742 }
743 return FileSpec::eEnumerateDirectoryResultNext;
744 }
745 break;
746
747 case FileSpec::eFileTypeInvalid:
748 case FileSpec::eFileTypeOther:
749 case FileSpec::eFileTypeUnknown:
750 rc_baton->error.SetErrorStringWithFormat("invalid file detected during copy: %s", src.GetPath().c_str());
751 return FileSpec::eEnumerateDirectoryResultQuit; // got an error, bail out
752 break;
753 }
David Majnemer8faf9372014-09-16 06:34:29 +0000754 llvm_unreachable("Unhandled FileSpec::FileType!");
Greg Claytonfbb76342013-11-20 21:07:01 +0000755}
756
757Error
758Platform::Install (const FileSpec& src, const FileSpec& dst)
759{
760 Error error;
761
762 Log *log = GetLogIfAnyCategoriesSet(LIBLLDB_LOG_PLATFORM);
763 if (log)
764 log->Printf ("Platform::Install (src='%s', dst='%s')", src.GetPath().c_str(), dst.GetPath().c_str());
765 FileSpec fixed_dst(dst);
766
767 if (!fixed_dst.GetFilename())
768 fixed_dst.GetFilename() = src.GetFilename();
769
Chaoren Lind3173f32015-05-29 19:52:29 +0000770 FileSpec working_dir = GetWorkingDirectory();
Greg Claytonfbb76342013-11-20 21:07:01 +0000771
772 if (dst)
773 {
774 if (dst.GetDirectory())
775 {
776 const char first_dst_dir_char = dst.GetDirectory().GetCString()[0];
777 if (first_dst_dir_char == '/' || first_dst_dir_char == '\\')
778 {
779 fixed_dst.GetDirectory() = dst.GetDirectory();
780 }
781 // If the fixed destination file doesn't have a directory yet,
782 // then we must have a relative path. We will resolve this relative
783 // path against the platform's working directory
784 if (!fixed_dst.GetDirectory())
785 {
786 FileSpec relative_spec;
787 std::string path;
788 if (working_dir)
789 {
Chaoren Lind3173f32015-05-29 19:52:29 +0000790 relative_spec = working_dir;
791 relative_spec.AppendPathComponent(dst.GetPath());
Greg Claytonfbb76342013-11-20 21:07:01 +0000792 fixed_dst.GetDirectory() = relative_spec.GetDirectory();
793 }
794 else
795 {
796 error.SetErrorStringWithFormat("platform working directory must be valid for relative path '%s'", dst.GetPath().c_str());
797 return error;
798 }
799 }
800 }
801 else
802 {
803 if (working_dir)
804 {
Chaoren Lind3173f32015-05-29 19:52:29 +0000805 fixed_dst.GetDirectory().SetCString(working_dir.GetCString());
Greg Claytonfbb76342013-11-20 21:07:01 +0000806 }
807 else
808 {
809 error.SetErrorStringWithFormat("platform working directory must be valid for relative path '%s'", dst.GetPath().c_str());
810 return error;
811 }
812 }
813 }
814 else
815 {
816 if (working_dir)
817 {
Chaoren Lind3173f32015-05-29 19:52:29 +0000818 fixed_dst.GetDirectory().SetCString(working_dir.GetCString());
Greg Claytonfbb76342013-11-20 21:07:01 +0000819 }
820 else
821 {
822 error.SetErrorStringWithFormat("platform working directory must be valid when destination directory is empty");
823 return error;
824 }
825 }
826
827 if (log)
828 log->Printf ("Platform::Install (src='%s', dst='%s') fixed_dst='%s'", src.GetPath().c_str(), dst.GetPath().c_str(), fixed_dst.GetPath().c_str());
829
830 if (GetSupportsRSync())
831 {
832 error = PutFile(src, dst);
833 }
834 else
835 {
836 switch (src.GetFileType())
837 {
838 case FileSpec::eFileTypeDirectory:
839 {
840 if (GetFileExists (fixed_dst))
Chaoren Lind3173f32015-05-29 19:52:29 +0000841 Unlink(fixed_dst);
Greg Claytonfbb76342013-11-20 21:07:01 +0000842 uint32_t permissions = src.GetPermissions();
843 if (permissions == 0)
844 permissions = eFilePermissionsDirectoryDefault;
Chaoren Lind3173f32015-05-29 19:52:29 +0000845 error = MakeDirectory(fixed_dst, permissions);
Greg Claytonfbb76342013-11-20 21:07:01 +0000846 if (error.Success())
847 {
848 // Make a filespec that only fills in the directory of a FileSpec so
849 // when we enumerate we can quickly fill in the filename for dst copies
850 FileSpec recurse_dst;
Chaoren Lind3173f32015-05-29 19:52:29 +0000851 recurse_dst.GetDirectory().SetCString(fixed_dst.GetCString());
Greg Claytonfbb76342013-11-20 21:07:01 +0000852 std::string src_dir_path (src.GetPath());
853 RecurseCopyBaton baton = { recurse_dst, this, Error() };
854 FileSpec::EnumerateDirectory(src_dir_path.c_str(), true, true, true, RecurseCopy_Callback, &baton);
855 return baton.error;
856 }
857 }
858 break;
859
860 case FileSpec::eFileTypeRegular:
861 if (GetFileExists (fixed_dst))
Chaoren Lind3173f32015-05-29 19:52:29 +0000862 Unlink(fixed_dst);
Greg Claytonfbb76342013-11-20 21:07:01 +0000863 error = PutFile(src, fixed_dst);
864 break;
865
866 case FileSpec::eFileTypeSymbolicLink:
867 {
868 if (GetFileExists (fixed_dst))
Chaoren Lind3173f32015-05-29 19:52:29 +0000869 Unlink(fixed_dst);
870 FileSpec src_resolved;
871 error = FileSystem::Readlink(src, src_resolved);
Greg Claytonfbb76342013-11-20 21:07:01 +0000872 if (error.Success())
Chaoren Lind3173f32015-05-29 19:52:29 +0000873 error = CreateSymlink(dst, src_resolved);
Greg Claytonfbb76342013-11-20 21:07:01 +0000874 }
875 break;
876 case FileSpec::eFileTypePipe:
877 error.SetErrorString("platform install doesn't handle pipes");
878 break;
879 case FileSpec::eFileTypeSocket:
880 error.SetErrorString("platform install doesn't handle sockets");
881 break;
882 case FileSpec::eFileTypeInvalid:
883 case FileSpec::eFileTypeUnknown:
884 case FileSpec::eFileTypeOther:
885 error.SetErrorString("platform install doesn't handle non file or directory items");
886 break;
887 }
888 }
889 return error;
890}
891
892bool
Chaoren Lind3173f32015-05-29 19:52:29 +0000893Platform::SetWorkingDirectory(const FileSpec &file_spec)
Greg Claytonfbb76342013-11-20 21:07:01 +0000894{
895 if (IsHost())
896 {
Greg Clayton5fb8f792013-12-02 19:35:49 +0000897 Log *log = GetLogIfAnyCategoriesSet(LIBLLDB_LOG_PLATFORM);
898 if (log)
Chaoren Lind3173f32015-05-29 19:52:29 +0000899 log->Printf("Platform::SetWorkingDirectory('%s')",
900 file_spec.GetCString());
901 if (file_spec)
Greg Claytonfbb76342013-11-20 21:07:01 +0000902 {
Chaoren Lind3173f32015-05-29 19:52:29 +0000903 if (::chdir(file_spec.GetCString()) == 0)
Greg Claytonfbb76342013-11-20 21:07:01 +0000904 return true;
905 }
906 return false;
907 }
908 else
909 {
Greg Clayton5fb8f792013-12-02 19:35:49 +0000910 m_working_dir.Clear();
Chaoren Lind3173f32015-05-29 19:52:29 +0000911 return SetRemoteWorkingDirectory(file_spec);
Greg Claytonfbb76342013-11-20 21:07:01 +0000912 }
913}
914
915Error
Chaoren Lind3173f32015-05-29 19:52:29 +0000916Platform::MakeDirectory(const FileSpec &file_spec, uint32_t permissions)
Greg Claytonfbb76342013-11-20 21:07:01 +0000917{
918 if (IsHost())
Chaoren Lind3173f32015-05-29 19:52:29 +0000919 return FileSystem::MakeDirectory(file_spec, permissions);
Greg Claytonfbb76342013-11-20 21:07:01 +0000920 else
921 {
922 Error error;
923 error.SetErrorStringWithFormat("remote platform %s doesn't support %s", GetPluginName().GetCString(), __PRETTY_FUNCTION__);
924 return error;
925 }
926}
927
928Error
Chaoren Lind3173f32015-05-29 19:52:29 +0000929Platform::GetFilePermissions(const FileSpec &file_spec, uint32_t &file_permissions)
Greg Claytonfbb76342013-11-20 21:07:01 +0000930{
931 if (IsHost())
Chaoren Lind3173f32015-05-29 19:52:29 +0000932 return FileSystem::GetFilePermissions(file_spec, file_permissions);
Greg Claytonfbb76342013-11-20 21:07:01 +0000933 else
934 {
935 Error error;
936 error.SetErrorStringWithFormat("remote platform %s doesn't support %s", GetPluginName().GetCString(), __PRETTY_FUNCTION__);
937 return error;
938 }
939}
940
941Error
Chaoren Lind3173f32015-05-29 19:52:29 +0000942Platform::SetFilePermissions(const FileSpec &file_spec, uint32_t file_permissions)
Greg Claytonfbb76342013-11-20 21:07:01 +0000943{
944 if (IsHost())
Chaoren Lind3173f32015-05-29 19:52:29 +0000945 return FileSystem::SetFilePermissions(file_spec, file_permissions);
Greg Claytonfbb76342013-11-20 21:07:01 +0000946 else
947 {
948 Error error;
949 error.SetErrorStringWithFormat("remote platform %s doesn't support %s", GetPluginName().GetCString(), __PRETTY_FUNCTION__);
950 return error;
951 }
952}
953
954ConstString
Greg Clayton8b82f082011-04-12 05:54:46 +0000955Platform::GetName ()
956{
Greg Claytonfbb76342013-11-20 21:07:01 +0000957 return GetPluginName();
Greg Clayton8b82f082011-04-12 05:54:46 +0000958}
959
960const char *
Greg Clayton1cb64962011-03-24 04:28:38 +0000961Platform::GetHostname ()
962{
Greg Claytonab65b342011-04-13 22:47:15 +0000963 if (IsHost())
Greg Clayton16810922014-02-27 19:38:18 +0000964 return "127.0.0.1";
Greg Clayton32e0a752011-03-30 18:16:51 +0000965
966 if (m_name.empty())
967 return NULL;
968 return m_name.c_str();
969}
970
Enrico Granata6e25aee2015-08-27 00:53:57 +0000971ConstString
972Platform::GetFullNameForDylib (ConstString basename)
973{
974 return basename;
975}
976
Greg Clayton5fb8f792013-12-02 19:35:49 +0000977bool
Chaoren Lind3173f32015-05-29 19:52:29 +0000978Platform::SetRemoteWorkingDirectory(const FileSpec &working_dir)
Greg Clayton5fb8f792013-12-02 19:35:49 +0000979{
980 Log *log = GetLogIfAnyCategoriesSet(LIBLLDB_LOG_PLATFORM);
981 if (log)
Chaoren Lind3173f32015-05-29 19:52:29 +0000982 log->Printf("Platform::SetRemoteWorkingDirectory('%s')",
983 working_dir.GetCString());
984 m_working_dir = working_dir;
Greg Clayton5fb8f792013-12-02 19:35:49 +0000985 return true;
986}
987
Greg Clayton32e0a752011-03-30 18:16:51 +0000988const char *
989Platform::GetUserName (uint32_t uid)
990{
Zachary Turnerb245eca2014-08-21 20:02:17 +0000991#if !defined(LLDB_DISABLE_POSIX)
Greg Clayton32e0a752011-03-30 18:16:51 +0000992 const char *user_name = GetCachedUserName(uid);
993 if (user_name)
994 return user_name;
995 if (IsHost())
996 {
997 std::string name;
Zachary Turnerb245eca2014-08-21 20:02:17 +0000998 if (HostInfo::LookupUserName(uid, name))
Greg Clayton32e0a752011-03-30 18:16:51 +0000999 return SetCachedUserName (uid, name.c_str(), name.size());
1000 }
Zachary Turnerb245eca2014-08-21 20:02:17 +00001001#endif
Greg Clayton1cb64962011-03-24 04:28:38 +00001002 return NULL;
1003}
1004
Greg Clayton32e0a752011-03-30 18:16:51 +00001005const char *
1006Platform::GetGroupName (uint32_t gid)
1007{
Zachary Turnerb245eca2014-08-21 20:02:17 +00001008#if !defined(LLDB_DISABLE_POSIX)
Greg Clayton32e0a752011-03-30 18:16:51 +00001009 const char *group_name = GetCachedGroupName(gid);
1010 if (group_name)
1011 return group_name;
1012 if (IsHost())
1013 {
1014 std::string name;
Zachary Turnerb245eca2014-08-21 20:02:17 +00001015 if (HostInfo::LookupGroupName(gid, name))
Greg Clayton32e0a752011-03-30 18:16:51 +00001016 return SetCachedGroupName (gid, name.c_str(), name.size());
1017 }
Zachary Turnerb245eca2014-08-21 20:02:17 +00001018#endif
Greg Clayton32e0a752011-03-30 18:16:51 +00001019 return NULL;
1020}
Greg Clayton1cb64962011-03-24 04:28:38 +00001021
Greg Claytonded470d2011-03-19 01:12:21 +00001022bool
1023Platform::SetOSVersion (uint32_t major,
1024 uint32_t minor,
1025 uint32_t update)
1026{
1027 if (IsHost())
1028 {
Zachary Turner97a14e62014-08-19 17:18:29 +00001029 // We don't need anyone setting the OS version for the host platform,
1030 // we should be able to figure it out by calling HostInfo::GetOSVersion(...).
Greg Claytonded470d2011-03-19 01:12:21 +00001031 return false;
1032 }
1033 else
1034 {
1035 // We have a remote platform, allow setting the target OS version if
1036 // we aren't connected, since if we are connected, we should be able to
1037 // request the remote OS version from the connected platform.
1038 if (IsConnected())
1039 return false;
1040 else
1041 {
1042 // We aren't connected and we might want to set the OS version
1043 // ahead of time before we connect so we can peruse files and
1044 // use a local SDK or PDK cache of support files to disassemble
1045 // or do other things.
1046 m_major_os_version = major;
1047 m_minor_os_version = minor;
1048 m_update_os_version = update;
1049 return true;
1050 }
1051 }
1052 return false;
1053}
1054
1055
Greg Claytone996fd32011-03-08 22:40:15 +00001056Error
Greg Clayton8012cad2014-11-17 19:39:20 +00001057Platform::ResolveExecutable (const ModuleSpec &module_spec,
Greg Claytonc859e2d2012-02-13 23:10:39 +00001058 lldb::ModuleSP &exe_module_sp,
1059 const FileSpecList *module_search_paths_ptr)
Greg Claytone996fd32011-03-08 22:40:15 +00001060{
1061 Error error;
Greg Clayton8012cad2014-11-17 19:39:20 +00001062 if (module_spec.GetFileSpec().Exists())
Greg Claytone996fd32011-03-08 22:40:15 +00001063 {
Greg Claytonb9a01b32012-02-26 05:51:37 +00001064 if (module_spec.GetArchitecture().IsValid())
Greg Claytone996fd32011-03-08 22:40:15 +00001065 {
Greg Claytonb9a01b32012-02-26 05:51:37 +00001066 error = ModuleList::GetSharedModule (module_spec,
Greg Claytone996fd32011-03-08 22:40:15 +00001067 exe_module_sp,
Greg Claytonc859e2d2012-02-13 23:10:39 +00001068 module_search_paths_ptr,
Greg Claytone996fd32011-03-08 22:40:15 +00001069 NULL,
1070 NULL);
1071 }
1072 else
1073 {
1074 // No valid architecture was specified, ask the platform for
1075 // the architectures that we should be using (in the correct order)
1076 // and see if we can find a match that way
Greg Clayton8012cad2014-11-17 19:39:20 +00001077 ModuleSpec arch_module_spec(module_spec);
1078 for (uint32_t idx = 0; GetSupportedArchitectureAtIndex (idx, arch_module_spec.GetArchitecture()); ++idx)
Greg Claytone996fd32011-03-08 22:40:15 +00001079 {
Greg Clayton8012cad2014-11-17 19:39:20 +00001080 error = ModuleList::GetSharedModule (arch_module_spec,
Greg Claytone996fd32011-03-08 22:40:15 +00001081 exe_module_sp,
Greg Claytonc859e2d2012-02-13 23:10:39 +00001082 module_search_paths_ptr,
Greg Claytone996fd32011-03-08 22:40:15 +00001083 NULL,
1084 NULL);
1085 // Did we find an executable using one of the
1086 if (error.Success() && exe_module_sp)
1087 break;
1088 }
1089 }
1090 }
1091 else
1092 {
Greg Claytonb5ad4ec2013-04-29 17:25:54 +00001093 error.SetErrorStringWithFormat ("'%s' does not exist",
Greg Clayton8012cad2014-11-17 19:39:20 +00001094 module_spec.GetFileSpec().GetPath().c_str());
Greg Claytone996fd32011-03-08 22:40:15 +00001095 }
1096 return error;
1097}
1098
Greg Clayton103f0282012-09-12 02:03:59 +00001099Error
1100Platform::ResolveSymbolFile (Target &target,
1101 const ModuleSpec &sym_spec,
1102 FileSpec &sym_file)
1103{
1104 Error error;
1105 if (sym_spec.GetSymbolFileSpec().Exists())
1106 sym_file = sym_spec.GetSymbolFileSpec();
1107 else
1108 error.SetErrorString("unable to resolve symbol file");
1109 return error;
1110
1111}
1112
1113
1114
Greg Claytonaa516842011-08-11 16:25:18 +00001115bool
1116Platform::ResolveRemotePath (const FileSpec &platform_path,
1117 FileSpec &resolved_platform_path)
1118{
1119 resolved_platform_path = platform_path;
1120 return resolved_platform_path.ResolvePath();
1121}
1122
Greg Claytonded470d2011-03-19 01:12:21 +00001123
1124const ArchSpec &
1125Platform::GetSystemArchitecture()
1126{
1127 if (IsHost())
1128 {
1129 if (!m_system_arch.IsValid())
1130 {
1131 // We have a local host platform
Zachary Turner13b18262014-08-20 16:42:51 +00001132 m_system_arch = HostInfo::GetArchitecture();
Greg Claytonded470d2011-03-19 01:12:21 +00001133 m_system_arch_set_while_connected = m_system_arch.IsValid();
1134 }
1135 }
1136 else
1137 {
1138 // We have a remote platform. We can only fetch the remote
1139 // system architecture if we are connected, and we don't want to do it
1140 // more than once.
1141
1142 const bool is_connected = IsConnected();
1143
1144 bool fetch = false;
1145 if (m_system_arch.IsValid())
1146 {
1147 // We have valid OS version info, check to make sure it wasn't
1148 // manually set prior to connecting. If it was manually set prior
1149 // to connecting, then lets fetch the actual OS version info
1150 // if we are now connected.
1151 if (is_connected && !m_system_arch_set_while_connected)
1152 fetch = true;
1153 }
1154 else
1155 {
1156 // We don't have valid OS version info, fetch it if we are connected
1157 fetch = is_connected;
1158 }
1159
1160 if (fetch)
1161 {
Greg Clayton1cb64962011-03-24 04:28:38 +00001162 m_system_arch = GetRemoteSystemArchitecture ();
Greg Claytonded470d2011-03-19 01:12:21 +00001163 m_system_arch_set_while_connected = m_system_arch.IsValid();
1164 }
1165 }
1166 return m_system_arch;
1167}
1168
1169
Greg Claytone996fd32011-03-08 22:40:15 +00001170Error
Greg Claytond314e812011-03-23 00:09:55 +00001171Platform::ConnectRemote (Args& args)
Greg Claytone996fd32011-03-08 22:40:15 +00001172{
1173 Error error;
Greg Claytond314e812011-03-23 00:09:55 +00001174 if (IsHost())
Greg Clayton57abc5d2013-05-10 21:47:16 +00001175 error.SetErrorStringWithFormat ("The currently selected platform (%s) is the host platform and is always connected.", GetPluginName().GetCString());
Greg Claytond314e812011-03-23 00:09:55 +00001176 else
Greg Clayton57abc5d2013-05-10 21:47:16 +00001177 error.SetErrorStringWithFormat ("Platform::ConnectRemote() is not supported by %s", GetPluginName().GetCString());
Greg Claytone996fd32011-03-08 22:40:15 +00001178 return error;
1179}
1180
1181Error
Greg Claytond314e812011-03-23 00:09:55 +00001182Platform::DisconnectRemote ()
Greg Claytone996fd32011-03-08 22:40:15 +00001183{
1184 Error error;
Greg Claytond314e812011-03-23 00:09:55 +00001185 if (IsHost())
Greg Clayton57abc5d2013-05-10 21:47:16 +00001186 error.SetErrorStringWithFormat ("The currently selected platform (%s) is the host platform and is always connected.", GetPluginName().GetCString());
Greg Claytond314e812011-03-23 00:09:55 +00001187 else
Greg Clayton57abc5d2013-05-10 21:47:16 +00001188 error.SetErrorStringWithFormat ("Platform::DisconnectRemote() is not supported by %s", GetPluginName().GetCString());
Greg Claytone996fd32011-03-08 22:40:15 +00001189 return error;
1190}
Greg Clayton32e0a752011-03-30 18:16:51 +00001191
1192bool
Greg Clayton8b82f082011-04-12 05:54:46 +00001193Platform::GetProcessInfo (lldb::pid_t pid, ProcessInstanceInfo &process_info)
Greg Clayton32e0a752011-03-30 18:16:51 +00001194{
1195 // Take care of the host case so that each subclass can just
Greg Clayton8b82f082011-04-12 05:54:46 +00001196 // call this function to get the host functionality.
Greg Clayton32e0a752011-03-30 18:16:51 +00001197 if (IsHost())
1198 return Host::GetProcessInfo (pid, process_info);
1199 return false;
1200}
1201
1202uint32_t
Greg Clayton8b82f082011-04-12 05:54:46 +00001203Platform::FindProcesses (const ProcessInstanceInfoMatch &match_info,
1204 ProcessInstanceInfoList &process_infos)
Greg Clayton32e0a752011-03-30 18:16:51 +00001205{
Greg Clayton8b82f082011-04-12 05:54:46 +00001206 // Take care of the host case so that each subclass can just
1207 // call this function to get the host functionality.
Greg Clayton32e0a752011-03-30 18:16:51 +00001208 uint32_t match_count = 0;
1209 if (IsHost())
1210 match_count = Host::FindProcesses (match_info, process_infos);
1211 return match_count;
1212}
Greg Clayton8b82f082011-04-12 05:54:46 +00001213
1214
1215Error
1216Platform::LaunchProcess (ProcessLaunchInfo &launch_info)
1217{
1218 Error error;
Todd Fialaac33cc92014-10-09 01:02:08 +00001219 Log *log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_PLATFORM));
1220 if (log)
1221 log->Printf ("Platform::%s()", __FUNCTION__);
1222
1223 // Take care of the host case so that each subclass can just
Greg Clayton8b82f082011-04-12 05:54:46 +00001224 // call this function to get the host functionality.
1225 if (IsHost())
Greg Clayton84db9102012-03-26 23:03:23 +00001226 {
1227 if (::getenv ("LLDB_LAUNCH_FLAG_LAUNCH_IN_TTY"))
1228 launch_info.GetFlags().Set (eLaunchFlagLaunchInTTY);
1229
1230 if (launch_info.GetFlags().Test (eLaunchFlagLaunchInShell))
1231 {
1232 const bool is_localhost = true;
Greg Claytond1cf11a2012-04-14 01:42:46 +00001233 const bool will_debug = launch_info.GetFlags().Test(eLaunchFlagDebug);
1234 const bool first_arg_is_full_shell_command = false;
Jim Inghamd3990792013-09-11 18:23:22 +00001235 uint32_t num_resumes = GetResumeCountForLaunchInfo (launch_info);
Todd Fialaac33cc92014-10-09 01:02:08 +00001236 if (log)
Zachary Turner10687b02014-10-20 17:46:43 +00001237 {
1238 const FileSpec &shell = launch_info.GetShell();
1239 const char *shell_str = (shell) ? shell.GetPath().c_str() : "<null>";
Todd Fialaac33cc92014-10-09 01:02:08 +00001240 log->Printf ("Platform::%s GetResumeCountForLaunchInfo() returned %" PRIu32 ", shell is '%s'",
1241 __FUNCTION__,
1242 num_resumes,
Zachary Turner10687b02014-10-20 17:46:43 +00001243 shell_str);
1244 }
Todd Fialaac33cc92014-10-09 01:02:08 +00001245
Greg Claytond1cf11a2012-04-14 01:42:46 +00001246 if (!launch_info.ConvertArgumentsForLaunchingInShell (error,
1247 is_localhost,
1248 will_debug,
Jim Inghamdf0ae222013-09-10 02:09:47 +00001249 first_arg_is_full_shell_command,
1250 num_resumes))
Greg Clayton84db9102012-03-26 23:03:23 +00001251 return error;
1252 }
Enrico Granatab38ef8c2015-02-20 22:20:30 +00001253 else if (launch_info.GetFlags().Test(eLaunchFlagShellExpandArguments))
Enrico Granatad7a83a92015-02-10 03:06:24 +00001254 {
Enrico Granatab38ef8c2015-02-20 22:20:30 +00001255 error = ShellExpandArguments(launch_info);
Enrico Granata83a14372015-02-20 21:48:38 +00001256 if (error.Fail())
Enrico Granatad7a83a92015-02-10 03:06:24 +00001257 return error;
Enrico Granatad7a83a92015-02-10 03:06:24 +00001258 }
Greg Clayton84db9102012-03-26 23:03:23 +00001259
Todd Fialaac33cc92014-10-09 01:02:08 +00001260 if (log)
1261 log->Printf ("Platform::%s final launch_info resume count: %" PRIu32, __FUNCTION__, launch_info.GetResumeCount ());
1262
Greg Clayton8b82f082011-04-12 05:54:46 +00001263 error = Host::LaunchProcess (launch_info);
Greg Clayton84db9102012-03-26 23:03:23 +00001264 }
Greg Clayton8b82f082011-04-12 05:54:46 +00001265 else
1266 error.SetErrorString ("base lldb_private::Platform class can't launch remote processes");
1267 return error;
1268}
1269
Oleksiy Vyalov1ef7b2c2015-02-04 23:19:15 +00001270Error
Enrico Granatab38ef8c2015-02-20 22:20:30 +00001271Platform::ShellExpandArguments (ProcessLaunchInfo &launch_info)
Enrico Granata83a14372015-02-20 21:48:38 +00001272{
1273 if (IsHost())
Enrico Granatab38ef8c2015-02-20 22:20:30 +00001274 return Host::ShellExpandArguments(launch_info);
1275 return Error("base lldb_private::Platform class can't expand arguments");
Enrico Granata83a14372015-02-20 21:48:38 +00001276}
1277
1278Error
Oleksiy Vyalov1ef7b2c2015-02-04 23:19:15 +00001279Platform::KillProcess (const lldb::pid_t pid)
1280{
1281 Log *log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_PLATFORM));
1282 if (log)
1283 log->Printf ("Platform::%s, pid %" PRIu64, __FUNCTION__, pid);
1284
Zachary Turner7271bab2015-05-13 19:44:24 +00001285 // Try to find a process plugin to handle this Kill request. If we can't, fall back to
1286 // the default OS implementation.
1287 size_t num_debuggers = Debugger::GetNumDebuggers();
1288 for (size_t didx = 0; didx < num_debuggers; ++didx)
1289 {
1290 DebuggerSP debugger = Debugger::GetDebuggerAtIndex(didx);
1291 lldb_private::TargetList &targets = debugger->GetTargetList();
1292 for (int tidx = 0; tidx < targets.GetNumTargets(); ++tidx)
1293 {
1294 ProcessSP process = targets.GetTargetAtIndex(tidx)->GetProcessSP();
1295 if (process->GetID() == pid)
1296 return process->Destroy(true);
1297 }
1298 }
Oleksiy Vyalov1ef7b2c2015-02-04 23:19:15 +00001299
Zachary Turner7271bab2015-05-13 19:44:24 +00001300 if (!IsHost())
1301 {
1302 return Error("base lldb_private::Platform class can't kill remote processes unless "
1303 "they are controlled by a process plugin");
1304 }
1305 Host::Kill(pid, SIGTERM);
Oleksiy Vyalov1ef7b2c2015-02-04 23:19:15 +00001306 return Error();
1307}
1308
Greg Clayton8b82f082011-04-12 05:54:46 +00001309lldb::ProcessSP
1310Platform::DebugProcess (ProcessLaunchInfo &launch_info,
1311 Debugger &debugger,
1312 Target *target, // Can be NULL, if NULL create a new target, else use existing one
Greg Clayton8b82f082011-04-12 05:54:46 +00001313 Error &error)
1314{
Todd Fialaac33cc92014-10-09 01:02:08 +00001315 Log *log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_PLATFORM));
1316 if (log)
1317 log->Printf ("Platform::%s entered (target %p)", __FUNCTION__, static_cast<void*>(target));
1318
Greg Clayton8b82f082011-04-12 05:54:46 +00001319 ProcessSP process_sp;
1320 // Make sure we stop at the entry point
1321 launch_info.GetFlags ().Set (eLaunchFlagDebug);
Jim Inghamb4451b12012-06-01 01:22:13 +00001322 // We always launch the process we are going to debug in a separate process
1323 // group, since then we can handle ^C interrupts ourselves w/o having to worry
1324 // about the target getting them as well.
1325 launch_info.SetLaunchInSeparateProcessGroup(true);
1326
Greg Clayton8b82f082011-04-12 05:54:46 +00001327 error = LaunchProcess (launch_info);
1328 if (error.Success())
1329 {
Todd Fialaac33cc92014-10-09 01:02:08 +00001330 if (log)
1331 log->Printf ("Platform::%s LaunchProcess() call succeeded (pid=%" PRIu64 ")", __FUNCTION__, launch_info.GetProcessID ());
Greg Clayton144f3a92011-11-15 03:53:30 +00001332 if (launch_info.GetProcessID() != LLDB_INVALID_PROCESS_ID)
Greg Clayton8b82f082011-04-12 05:54:46 +00001333 {
Greg Clayton144f3a92011-11-15 03:53:30 +00001334 ProcessAttachInfo attach_info (launch_info);
Greg Clayton8012cad2014-11-17 19:39:20 +00001335 process_sp = Attach (attach_info, debugger, target, error);
Greg Claytone24c4ac2011-11-17 04:46:02 +00001336 if (process_sp)
1337 {
Todd Fialaac33cc92014-10-09 01:02:08 +00001338 if (log)
1339 log->Printf ("Platform::%s Attach() succeeded, Process plugin: %s", __FUNCTION__, process_sp->GetPluginName ().AsCString ());
Greg Clayton44d93782014-01-27 23:43:24 +00001340 launch_info.SetHijackListener(attach_info.GetHijackListener());
1341
Greg Claytone24c4ac2011-11-17 04:46:02 +00001342 // Since we attached to the process, it will think it needs to detach
1343 // if the process object just goes away without an explicit call to
1344 // Process::Kill() or Process::Detach(), so let it know to kill the
1345 // process if this happens.
1346 process_sp->SetShouldDetach (false);
Greg Claytonee95ed52011-11-17 22:14:31 +00001347
1348 // If we didn't have any file actions, the pseudo terminal might
1349 // have been used where the slave side was given as the file to
1350 // open for stdin/out/err after we have already opened the master
1351 // so we can read/write stdin/out/err.
1352 int pty_fd = launch_info.GetPTY().ReleaseMasterFileDescriptor();
1353 if (pty_fd != lldb_utility::PseudoTerminal::invalid_fd)
1354 {
1355 process_sp->SetSTDIOFileDescriptor(pty_fd);
1356 }
Greg Claytone24c4ac2011-11-17 04:46:02 +00001357 }
Todd Fialaac33cc92014-10-09 01:02:08 +00001358 else
1359 {
1360 if (log)
1361 log->Printf ("Platform::%s Attach() failed: %s", __FUNCTION__, error.AsCString ());
1362 }
1363 }
1364 else
1365 {
1366 if (log)
1367 log->Printf ("Platform::%s LaunchProcess() returned launch_info with invalid process id", __FUNCTION__);
Greg Clayton8b82f082011-04-12 05:54:46 +00001368 }
1369 }
Todd Fialaac33cc92014-10-09 01:02:08 +00001370 else
1371 {
1372 if (log)
1373 log->Printf ("Platform::%s LaunchProcess() failed: %s", __FUNCTION__, error.AsCString ());
1374 }
1375
Greg Clayton8b82f082011-04-12 05:54:46 +00001376 return process_sp;
1377}
Greg Claytonb3a40ba2012-03-20 18:34:04 +00001378
1379
1380lldb::PlatformSP
Greg Clayton70512312012-05-08 01:45:38 +00001381Platform::GetPlatformForArchitecture (const ArchSpec &arch, ArchSpec *platform_arch_ptr)
Greg Claytonb3a40ba2012-03-20 18:34:04 +00001382{
1383 lldb::PlatformSP platform_sp;
1384 Error error;
1385 if (arch.IsValid())
Greg Clayton70512312012-05-08 01:45:38 +00001386 platform_sp = Platform::Create (arch, platform_arch_ptr, error);
Greg Claytonb3a40ba2012-03-20 18:34:04 +00001387 return platform_sp;
1388}
1389
1390
1391//------------------------------------------------------------------
1392/// Lets a platform answer if it is compatible with a given
1393/// architecture and the target triple contained within.
1394//------------------------------------------------------------------
1395bool
Greg Clayton1e0c8842013-01-11 20:49:54 +00001396Platform::IsCompatibleArchitecture (const ArchSpec &arch, bool exact_arch_match, ArchSpec *compatible_arch_ptr)
Greg Claytonb3a40ba2012-03-20 18:34:04 +00001397{
1398 // If the architecture is invalid, we must answer true...
Greg Clayton70512312012-05-08 01:45:38 +00001399 if (arch.IsValid())
Greg Claytonb3a40ba2012-03-20 18:34:04 +00001400 {
Greg Clayton70512312012-05-08 01:45:38 +00001401 ArchSpec platform_arch;
Greg Clayton1e0c8842013-01-11 20:49:54 +00001402 // Try for an exact architecture match first.
1403 if (exact_arch_match)
Greg Clayton70512312012-05-08 01:45:38 +00001404 {
Greg Clayton1e0c8842013-01-11 20:49:54 +00001405 for (uint32_t arch_idx=0; GetSupportedArchitectureAtIndex (arch_idx, platform_arch); ++arch_idx)
Greg Clayton70512312012-05-08 01:45:38 +00001406 {
Greg Clayton1e0c8842013-01-11 20:49:54 +00001407 if (arch.IsExactMatch(platform_arch))
1408 {
1409 if (compatible_arch_ptr)
1410 *compatible_arch_ptr = platform_arch;
1411 return true;
1412 }
1413 }
1414 }
1415 else
1416 {
1417 for (uint32_t arch_idx=0; GetSupportedArchitectureAtIndex (arch_idx, platform_arch); ++arch_idx)
1418 {
1419 if (arch.IsCompatibleMatch(platform_arch))
1420 {
1421 if (compatible_arch_ptr)
1422 *compatible_arch_ptr = platform_arch;
1423 return true;
1424 }
Greg Clayton70512312012-05-08 01:45:38 +00001425 }
1426 }
Greg Claytonb3a40ba2012-03-20 18:34:04 +00001427 }
Greg Clayton70512312012-05-08 01:45:38 +00001428 if (compatible_arch_ptr)
1429 compatible_arch_ptr->Clear();
Greg Claytonb3a40ba2012-03-20 18:34:04 +00001430 return false;
Greg Claytonb3a40ba2012-03-20 18:34:04 +00001431}
1432
Daniel Maleae0f8f572013-08-26 23:57:52 +00001433Error
1434Platform::PutFile (const FileSpec& source,
1435 const FileSpec& destination,
1436 uint32_t uid,
1437 uint32_t gid)
1438{
Vince Harron1b5a74e2015-01-21 22:42:49 +00001439 Log *log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_PLATFORM));
1440 if (log)
1441 log->Printf("[PutFile] Using block by block transfer....\n");
1442
Pavel Labath646b0642015-02-17 16:07:52 +00001443 uint32_t source_open_options = File::eOpenOptionRead | File::eOpenOptionCloseOnExec;
Vince Harron1b5a74e2015-01-21 22:42:49 +00001444 if (source.GetFileType() == FileSpec::eFileTypeSymbolicLink)
1445 source_open_options |= File::eOpenoptionDontFollowSymlinks;
1446
1447 File source_file(source, source_open_options, lldb::eFilePermissionsUserRW);
1448 Error error;
1449 uint32_t permissions = source_file.GetPermissions(error);
1450 if (permissions == 0)
1451 permissions = lldb::eFilePermissionsFileDefault;
1452
1453 if (!source_file.IsValid())
1454 return Error("PutFile: unable to open source file");
1455 lldb::user_id_t dest_file = OpenFile (destination,
1456 File::eOpenOptionCanCreate |
1457 File::eOpenOptionWrite |
Pavel Labath646b0642015-02-17 16:07:52 +00001458 File::eOpenOptionTruncate |
1459 File::eOpenOptionCloseOnExec,
Vince Harron1b5a74e2015-01-21 22:42:49 +00001460 permissions,
1461 error);
1462 if (log)
1463 log->Printf ("dest_file = %" PRIu64 "\n", dest_file);
1464
1465 if (error.Fail())
1466 return error;
1467 if (dest_file == UINT64_MAX)
1468 return Error("unable to open target file");
1469 lldb::DataBufferSP buffer_sp(new DataBufferHeap(1024, 0));
1470 uint64_t offset = 0;
1471 for (;;)
1472 {
1473 size_t bytes_read = buffer_sp->GetByteSize();
1474 error = source_file.Read(buffer_sp->GetBytes(), bytes_read);
1475 if (error.Fail() || bytes_read == 0)
1476 break;
1477
1478 const uint64_t bytes_written = WriteFile(dest_file, offset,
1479 buffer_sp->GetBytes(), bytes_read, error);
1480 if (error.Fail())
1481 break;
1482
1483 offset += bytes_written;
1484 if (bytes_written != bytes_read)
1485 {
1486 // We didn't write the correct number of bytes, so adjust
1487 // the file position in the source file we are reading from...
1488 source_file.SeekFromStart(offset);
1489 }
1490 }
1491 CloseFile(dest_file, error);
1492
1493 if (uid == UINT32_MAX && gid == UINT32_MAX)
1494 return error;
1495
1496 // TODO: ChownFile?
1497
Daniel Maleae0f8f572013-08-26 23:57:52 +00001498 return error;
1499}
1500
1501Error
Chaoren Lind3173f32015-05-29 19:52:29 +00001502Platform::GetFile(const FileSpec &source,
1503 const FileSpec &destination)
Daniel Maleae0f8f572013-08-26 23:57:52 +00001504{
1505 Error error("unimplemented");
1506 return error;
1507}
1508
Greg Claytonfbb76342013-11-20 21:07:01 +00001509Error
Chaoren Lind3173f32015-05-29 19:52:29 +00001510Platform::CreateSymlink(const FileSpec &src, // The name of the link is in src
1511 const FileSpec &dst) // The symlink points to dst
Greg Claytonfbb76342013-11-20 21:07:01 +00001512{
1513 Error error("unimplemented");
1514 return error;
1515}
1516
Daniel Maleae0f8f572013-08-26 23:57:52 +00001517bool
Chaoren Lind3173f32015-05-29 19:52:29 +00001518Platform::GetFileExists(const lldb_private::FileSpec &file_spec)
Daniel Maleae0f8f572013-08-26 23:57:52 +00001519{
1520 return false;
1521}
1522
Greg Claytonfbb76342013-11-20 21:07:01 +00001523Error
Chaoren Lind3173f32015-05-29 19:52:29 +00001524Platform::Unlink(const FileSpec &path)
Greg Claytonfbb76342013-11-20 21:07:01 +00001525{
1526 Error error("unimplemented");
1527 return error;
1528}
1529
Robert Flack96ad3de2015-05-09 15:53:31 +00001530uint64_t
Mohit K. Bhakkade0d8c422015-06-30 06:29:12 +00001531Platform::ConvertMmapFlagsToPlatform(const ArchSpec &arch, unsigned flags)
Robert Flack96ad3de2015-05-09 15:53:31 +00001532{
1533 uint64_t flags_platform = 0;
1534 if (flags & eMmapFlagsPrivate)
1535 flags_platform |= MAP_PRIVATE;
1536 if (flags & eMmapFlagsAnon)
1537 flags_platform |= MAP_ANON;
1538 return flags_platform;
1539}
Greg Claytonfbb76342013-11-20 21:07:01 +00001540
Daniel Maleae0f8f572013-08-26 23:57:52 +00001541lldb_private::Error
Chaoren Lind3173f32015-05-29 19:52:29 +00001542Platform::RunShellCommand(const char *command, // Shouldn't be NULL
1543 const FileSpec &working_dir, // Pass empty FileSpec to use the current working directory
1544 int *status_ptr, // Pass NULL if you don't want the process exit status
1545 int *signo_ptr, // Pass NULL if you don't want the signal that caused the process to exit
1546 std::string *command_output, // Pass NULL if you don't want the command output
1547 uint32_t timeout_sec) // Timeout in seconds to wait for shell program to finish
Daniel Maleae0f8f572013-08-26 23:57:52 +00001548{
1549 if (IsHost())
1550 return Host::RunShellCommand (command, working_dir, status_ptr, signo_ptr, command_output, timeout_sec);
1551 else
1552 return Error("unimplemented");
1553}
1554
1555
1556bool
1557Platform::CalculateMD5 (const FileSpec& file_spec,
1558 uint64_t &low,
1559 uint64_t &high)
1560{
1561 if (IsHost())
Zachary Turnerc00cf4a2014-08-15 22:04:21 +00001562 return FileSystem::CalculateMD5(file_spec, low, high);
Daniel Maleae0f8f572013-08-26 23:57:52 +00001563 else
1564 return false;
1565}
1566
1567void
1568Platform::SetLocalCacheDirectory (const char* local)
1569{
1570 m_local_cache_directory.assign(local);
1571}
1572
1573const char*
1574Platform::GetLocalCacheDirectory ()
1575{
1576 return m_local_cache_directory.c_str();
1577}
1578
1579static OptionDefinition
1580g_rsync_option_table[] =
1581{
Zachary Turnerd37221d2014-07-09 16:31:49 +00001582 { LLDB_OPT_SET_ALL, false, "rsync" , 'r', OptionParser::eNoArgument, NULL, NULL, 0, eArgTypeNone , "Enable rsync." },
1583 { LLDB_OPT_SET_ALL, false, "rsync-opts" , 'R', OptionParser::eRequiredArgument, NULL, NULL, 0, eArgTypeCommandName , "Platform-specific options required for rsync to work." },
1584 { LLDB_OPT_SET_ALL, false, "rsync-prefix" , 'P', OptionParser::eRequiredArgument, NULL, NULL, 0, eArgTypeCommandName , "Platform-specific rsync prefix put before the remote path." },
1585 { 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 +00001586};
1587
1588static OptionDefinition
1589g_ssh_option_table[] =
1590{
Zachary Turnerd37221d2014-07-09 16:31:49 +00001591 { LLDB_OPT_SET_ALL, false, "ssh" , 's', OptionParser::eNoArgument, NULL, NULL, 0, eArgTypeNone , "Enable SSH." },
1592 { 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 +00001593};
1594
1595static OptionDefinition
1596g_caching_option_table[] =
1597{
Zachary Turnerd37221d2014-07-09 16:31:49 +00001598 { 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 +00001599};
1600
1601OptionGroupPlatformRSync::OptionGroupPlatformRSync ()
1602{
1603}
1604
1605OptionGroupPlatformRSync::~OptionGroupPlatformRSync ()
1606{
1607}
1608
1609const lldb_private::OptionDefinition*
1610OptionGroupPlatformRSync::GetDefinitions ()
1611{
1612 return g_rsync_option_table;
1613}
1614
1615void
1616OptionGroupPlatformRSync::OptionParsingStarting (CommandInterpreter &interpreter)
1617{
1618 m_rsync = false;
1619 m_rsync_opts.clear();
1620 m_rsync_prefix.clear();
1621 m_ignores_remote_hostname = false;
1622}
1623
1624lldb_private::Error
1625OptionGroupPlatformRSync::SetOptionValue (CommandInterpreter &interpreter,
1626 uint32_t option_idx,
1627 const char *option_arg)
1628{
1629 Error error;
1630 char short_option = (char) GetDefinitions()[option_idx].short_option;
1631 switch (short_option)
1632 {
1633 case 'r':
1634 m_rsync = true;
1635 break;
1636
1637 case 'R':
1638 m_rsync_opts.assign(option_arg);
1639 break;
1640
1641 case 'P':
1642 m_rsync_prefix.assign(option_arg);
1643 break;
1644
1645 case 'i':
1646 m_ignores_remote_hostname = true;
1647 break;
1648
1649 default:
1650 error.SetErrorStringWithFormat ("unrecognized option '%c'", short_option);
1651 break;
1652 }
1653
1654 return error;
1655}
1656
1657uint32_t
1658OptionGroupPlatformRSync::GetNumDefinitions ()
1659{
1660 return llvm::array_lengthof(g_rsync_option_table);
1661}
Greg Clayton1e0c8842013-01-11 20:49:54 +00001662
Greg Clayton4116e932012-05-15 02:33:01 +00001663lldb::BreakpointSP
1664Platform::SetThreadCreationBreakpoint (lldb_private::Target &target)
1665{
1666 return lldb::BreakpointSP();
1667}
Greg Claytonb3a40ba2012-03-20 18:34:04 +00001668
Daniel Maleae0f8f572013-08-26 23:57:52 +00001669OptionGroupPlatformSSH::OptionGroupPlatformSSH ()
1670{
1671}
1672
1673OptionGroupPlatformSSH::~OptionGroupPlatformSSH ()
1674{
1675}
1676
1677const lldb_private::OptionDefinition*
1678OptionGroupPlatformSSH::GetDefinitions ()
1679{
1680 return g_ssh_option_table;
1681}
1682
1683void
1684OptionGroupPlatformSSH::OptionParsingStarting (CommandInterpreter &interpreter)
1685{
1686 m_ssh = false;
1687 m_ssh_opts.clear();
1688}
1689
1690lldb_private::Error
1691OptionGroupPlatformSSH::SetOptionValue (CommandInterpreter &interpreter,
1692 uint32_t option_idx,
1693 const char *option_arg)
1694{
1695 Error error;
1696 char short_option = (char) GetDefinitions()[option_idx].short_option;
1697 switch (short_option)
1698 {
1699 case 's':
1700 m_ssh = true;
1701 break;
1702
1703 case 'S':
1704 m_ssh_opts.assign(option_arg);
1705 break;
1706
1707 default:
1708 error.SetErrorStringWithFormat ("unrecognized option '%c'", short_option);
1709 break;
1710 }
1711
1712 return error;
1713}
1714
1715uint32_t
1716OptionGroupPlatformSSH::GetNumDefinitions ()
1717{
1718 return llvm::array_lengthof(g_ssh_option_table);
1719}
1720
1721OptionGroupPlatformCaching::OptionGroupPlatformCaching ()
1722{
1723}
1724
1725OptionGroupPlatformCaching::~OptionGroupPlatformCaching ()
1726{
1727}
1728
1729const lldb_private::OptionDefinition*
1730OptionGroupPlatformCaching::GetDefinitions ()
1731{
1732 return g_caching_option_table;
1733}
1734
1735void
1736OptionGroupPlatformCaching::OptionParsingStarting (CommandInterpreter &interpreter)
1737{
1738 m_cache_dir.clear();
1739}
1740
1741lldb_private::Error
1742OptionGroupPlatformCaching::SetOptionValue (CommandInterpreter &interpreter,
1743 uint32_t option_idx,
1744 const char *option_arg)
1745{
1746 Error error;
1747 char short_option = (char) GetDefinitions()[option_idx].short_option;
1748 switch (short_option)
1749 {
1750 case 'c':
1751 m_cache_dir.assign(option_arg);
1752 break;
1753
1754 default:
1755 error.SetErrorStringWithFormat ("unrecognized option '%c'", short_option);
1756 break;
1757 }
1758
1759 return error;
1760}
1761
1762uint32_t
1763OptionGroupPlatformCaching::GetNumDefinitions ()
1764{
1765 return llvm::array_lengthof(g_caching_option_table);
1766}
1767
Greg Clayton67cc0632012-08-22 17:17:09 +00001768size_t
1769Platform::GetEnvironment (StringList &environment)
1770{
1771 environment.Clear();
1772 return false;
1773}
Jason Molenda2094dbf2014-02-13 23:11:45 +00001774
1775const std::vector<ConstString> &
1776Platform::GetTrapHandlerSymbolNames ()
1777{
1778 if (!m_calculated_trap_handlers)
1779 {
Greg Clayton7597b352015-02-02 20:45:17 +00001780 Mutex::Locker locker (m_mutex);
Jason Molenda4da87062014-05-23 23:11:27 +00001781 if (!m_calculated_trap_handlers)
1782 {
1783 CalculateTrapHandlerSymbolNames();
1784 m_calculated_trap_handlers = true;
1785 }
Jason Molenda2094dbf2014-02-13 23:11:45 +00001786 }
1787 return m_trap_handlers;
1788}
1789
Oleksiy Vyalov64747212015-03-13 18:44:56 +00001790Error
1791Platform::GetCachedExecutable (ModuleSpec &module_spec,
1792 lldb::ModuleSP &module_sp,
1793 const FileSpecList *module_search_paths_ptr,
1794 Platform &remote_platform)
1795{
1796 const auto platform_spec = module_spec.GetFileSpec ();
1797 const auto error = LoadCachedExecutable (module_spec,
1798 module_sp,
1799 module_search_paths_ptr,
1800 remote_platform);
1801 if (error.Success ())
1802 {
1803 module_spec.GetFileSpec () = module_sp->GetFileSpec ();
1804 module_spec.GetPlatformFileSpec () = platform_spec;
1805 }
1806
1807 return error;
1808}
1809
1810Error
1811Platform::LoadCachedExecutable (const ModuleSpec &module_spec,
1812 lldb::ModuleSP &module_sp,
1813 const FileSpecList *module_search_paths_ptr,
1814 Platform &remote_platform)
1815{
Oleksiy Vyalov037f6b92015-03-24 23:45:49 +00001816 return GetRemoteSharedModule (module_spec,
1817 nullptr,
1818 module_sp,
1819 [&](const ModuleSpec &spec)
1820 {
1821 return remote_platform.ResolveExecutable (
1822 spec, module_sp, module_search_paths_ptr);
1823 },
1824 nullptr);
Oleksiy Vyalov64747212015-03-13 18:44:56 +00001825}
1826
Oleksiy Vyalov037f6b92015-03-24 23:45:49 +00001827Error
1828Platform::GetRemoteSharedModule (const ModuleSpec &module_spec,
Tamas Berghammer7cb18bf2015-03-24 11:15:23 +00001829 Process* process,
Oleksiy Vyalov037f6b92015-03-24 23:45:49 +00001830 lldb::ModuleSP &module_sp,
1831 const ModuleResolver &module_resolver,
1832 bool *did_create_ptr)
Oleksiy Vyalov63acdfd2015-03-10 01:15:28 +00001833{
Oleksiy Vyalov037f6b92015-03-24 23:45:49 +00001834 // Get module information from a target.
Oleksiy Vyalov63acdfd2015-03-10 01:15:28 +00001835 ModuleSpec resolved_module_spec;
Tamas Berghammer7cb18bf2015-03-24 11:15:23 +00001836 bool got_module_spec = false;
Tamas Berghammer7cb18bf2015-03-24 11:15:23 +00001837 if (process)
1838 {
1839 // Try to get module information from the process
1840 if (process->GetModuleSpec (module_spec.GetFileSpec (), module_spec.GetArchitecture (), resolved_module_spec))
Tamas Berghammerec3f92a2015-08-12 11:10:25 +00001841 got_module_spec = true;
Tamas Berghammer7cb18bf2015-03-24 11:15:23 +00001842 }
1843
1844 if (!got_module_spec)
1845 {
1846 // Get module information from a target.
1847 if (!GetModuleSpec (module_spec.GetFileSpec (), module_spec.GetArchitecture (), resolved_module_spec))
Oleksiy Vyalov037f6b92015-03-24 23:45:49 +00001848 return module_resolver (module_spec);
Tamas Berghammer7cb18bf2015-03-24 11:15:23 +00001849 }
Oleksiy Vyalov63acdfd2015-03-10 01:15:28 +00001850
Oleksiy Vyalov037f6b92015-03-24 23:45:49 +00001851 // Trying to find a module by UUID on local file system.
1852 const auto error = module_resolver (resolved_module_spec);
1853 if (error.Fail ())
1854 {
1855 if (GetCachedSharedModule (resolved_module_spec, module_sp, did_create_ptr))
1856 return Error ();
1857 }
1858
1859 return error;
1860}
1861
1862bool
1863Platform::GetCachedSharedModule (const ModuleSpec &module_spec,
1864 lldb::ModuleSP &module_sp,
1865 bool *did_create_ptr)
1866{
1867 if (IsHost() ||
Oleksiy Vyalovd21ca282015-10-01 17:48:57 +00001868 !GetGlobalPlatformProperties ()->GetUseModuleCache () ||
1869 !GetGlobalPlatformProperties ()->GetModuleCacheDirectory ())
Oleksiy Vyalov037f6b92015-03-24 23:45:49 +00001870 return false;
1871
1872 Log *log = GetLogIfAnyCategoriesSet (LIBLLDB_LOG_PLATFORM);
1873
Oleksiy Vyalov63acdfd2015-03-10 01:15:28 +00001874 // Check local cache for a module.
Oleksiy Vyalov280d8dc2015-04-15 14:35:10 +00001875 auto error = m_module_cache->GetAndPut (
1876 GetModuleCacheRoot (),
1877 GetCacheHostname (),
1878 module_spec,
Tamas Berghammerec3f92a2015-08-12 11:10:25 +00001879 [this](const ModuleSpec &module_spec, const FileSpec &tmp_download_file_spec)
Oleksiy Vyalov280d8dc2015-04-15 14:35:10 +00001880 {
Oleksiy Vyalov280d8dc2015-04-15 14:35:10 +00001881 return DownloadModuleSlice (module_spec.GetFileSpec (),
1882 module_spec.GetObjectOffset (),
1883 module_spec.GetObjectSize (),
1884 tmp_download_file_spec);
1885
1886 },
Tamas Berghammerec3f92a2015-08-12 11:10:25 +00001887 [this](const ModuleSP& module_sp, const FileSpec& tmp_download_file_spec)
1888 {
1889 return DownloadSymbolFile (module_sp, tmp_download_file_spec);
1890 },
Oleksiy Vyalov280d8dc2015-04-15 14:35:10 +00001891 module_sp,
1892 did_create_ptr);
Oleksiy Vyalov63acdfd2015-03-10 01:15:28 +00001893 if (error.Success ())
1894 return true;
1895
1896 if (log)
1897 log->Printf("Platform::%s - module %s not found in local cache: %s",
Oleksiy Vyalov037f6b92015-03-24 23:45:49 +00001898 __FUNCTION__, module_spec.GetUUID ().GetAsString ().c_str (), error.AsCString ());
Oleksiy Vyalov280d8dc2015-04-15 14:35:10 +00001899 return false;
Oleksiy Vyalov63acdfd2015-03-10 01:15:28 +00001900}
1901
1902Error
1903Platform::DownloadModuleSlice (const FileSpec& src_file_spec,
1904 const uint64_t src_offset,
1905 const uint64_t src_size,
1906 const FileSpec& dst_file_spec)
1907{
1908 Error error;
1909
1910 std::ofstream dst (dst_file_spec.GetPath(), std::ios::out | std::ios::binary);
1911 if (!dst.is_open())
1912 {
1913 error.SetErrorStringWithFormat ("unable to open destination file: %s", dst_file_spec.GetPath ().c_str ());
1914 return error;
1915 }
1916
1917 auto src_fd = OpenFile (src_file_spec,
1918 File::eOpenOptionRead,
1919 lldb::eFilePermissionsFileDefault,
1920 error);
1921
1922 if (error.Fail ())
1923 {
1924 error.SetErrorStringWithFormat ("unable to open source file: %s", error.AsCString ());
1925 return error;
1926 }
1927
1928 std::vector<char> buffer (1024);
1929 auto offset = src_offset;
1930 uint64_t total_bytes_read = 0;
1931 while (total_bytes_read < src_size)
1932 {
1933 const auto to_read = std::min (static_cast<uint64_t>(buffer.size ()), src_size - total_bytes_read);
1934 const uint64_t n_read = ReadFile (src_fd, offset, &buffer[0], to_read, error);
1935 if (error.Fail ())
1936 break;
1937 if (n_read == 0)
1938 {
1939 error.SetErrorString ("read 0 bytes");
1940 break;
1941 }
1942 offset += n_read;
1943 total_bytes_read += n_read;
1944 dst.write (&buffer[0], n_read);
1945 }
1946
1947 Error close_error;
1948 CloseFile (src_fd, close_error); // Ignoring close error.
1949
1950 return error;
1951}
1952
Tamas Berghammerec3f92a2015-08-12 11:10:25 +00001953Error
1954Platform::DownloadSymbolFile (const lldb::ModuleSP& module_sp, const FileSpec& dst_file_spec)
1955{
1956 return Error ("Symbol file downloading not supported by the default platform.");
1957}
1958
Oleksiy Vyalov63acdfd2015-03-10 01:15:28 +00001959FileSpec
1960Platform::GetModuleCacheRoot ()
1961{
1962 auto dir_spec = GetGlobalPlatformProperties ()->GetModuleCacheDirectory ();
1963 dir_spec.AppendPathComponent (GetName ().AsCString ());
1964 return dir_spec;
1965}
Oleksiy Vyalov6f001062015-03-25 17:58:13 +00001966
1967const char *
1968Platform::GetCacheHostname ()
1969{
1970 return GetHostname ();
1971}
Chaoren Lin98d0a4b2015-07-14 01:09:28 +00001972
1973const UnixSignalsSP &
1974Platform::GetRemoteUnixSignals()
1975{
1976 static const auto s_default_unix_signals_sp = std::make_shared<UnixSignals>();
1977 return s_default_unix_signals_sp;
1978}
1979
1980const UnixSignalsSP &
1981Platform::GetUnixSignals()
1982{
1983 if (IsHost())
1984 return Host::GetUnixSignals();
1985 return GetRemoteUnixSignals();
1986}
Tamas Berghammer3cb132a2015-12-02 11:58:51 +00001987
1988uint32_t
Tamas Berghammer4fbd67a2015-12-08 13:43:59 +00001989Platform::LoadImage(lldb_private::Process* process,
1990 const lldb_private::FileSpec& local_file,
1991 const lldb_private::FileSpec& remote_file,
1992 lldb_private::Error& error)
1993{
1994 if (local_file && remote_file)
1995 {
1996 // Both local and remote file was specified. Install the local file to the given location.
1997 if (IsRemote() || local_file != remote_file)
1998 {
1999 error = Install(local_file, remote_file);
2000 if (error.Fail())
2001 return LLDB_INVALID_IMAGE_TOKEN;
2002 }
2003 return DoLoadImage(process, remote_file, error);
2004 }
2005
2006 if (local_file)
2007 {
2008 // Only local file was specified. Install it to the current working directory.
2009 FileSpec target_file = GetWorkingDirectory();
2010 target_file.AppendPathComponent(local_file.GetFilename().AsCString());
2011 if (IsRemote() || local_file != target_file)
2012 {
2013 error = Install(local_file, target_file);
2014 if (error.Fail())
2015 return LLDB_INVALID_IMAGE_TOKEN;
2016 }
2017 return DoLoadImage(process, target_file, error);
2018 }
2019
2020 if (remote_file)
2021 {
2022 // Only remote file was specified so we don't have to do any copying
2023 return DoLoadImage(process, remote_file, error);
2024 }
2025
2026 error.SetErrorString("Neither local nor remote file was specified");
2027 return LLDB_INVALID_IMAGE_TOKEN;
2028}
2029
2030uint32_t
2031Platform::DoLoadImage (lldb_private::Process* process,
2032 const lldb_private::FileSpec& remote_file,
2033 lldb_private::Error& error)
Tamas Berghammer3cb132a2015-12-02 11:58:51 +00002034{
2035 error.SetErrorString("LoadImage is not supported on the current platform");
2036 return LLDB_INVALID_IMAGE_TOKEN;
2037}
2038
2039Error
2040Platform::UnloadImage(lldb_private::Process* process, uint32_t image_token)
2041{
Tamas Berghammer4fbd67a2015-12-08 13:43:59 +00002042 return Error("UnloadImage is not supported on the current platform");
Tamas Berghammer3cb132a2015-12-02 11:58:51 +00002043}
Tamas Berghammerccd6cff2015-12-08 14:08:19 +00002044
2045lldb::ProcessSP
2046Platform::ConnectProcess(const char* connect_url,
2047 const char* plugin_name,
2048 lldb_private::Debugger &debugger,
2049 lldb_private::Target *target,
2050 lldb_private::Error &error)
2051{
2052 error.Clear();
2053
2054 if (!target)
2055 {
2056 TargetSP new_target_sp;
2057 error = debugger.GetTargetList().CreateTarget(debugger,
2058 nullptr,
2059 nullptr,
2060 false,
2061 nullptr,
2062 new_target_sp);
2063 target = new_target_sp.get();
2064 }
2065
2066 if (!target || error.Fail())
2067 return nullptr;
2068
2069 debugger.GetTargetList().SetSelectedTarget(target);
2070
2071 lldb::ProcessSP process_sp = target->CreateProcess(debugger.GetListener(),
2072 plugin_name,
2073 nullptr);
2074 if (!process_sp)
2075 return nullptr;
2076
2077 error = process_sp->ConnectRemote(debugger.GetOutputFile().get(), connect_url);
2078 if (error.Fail())
2079 return nullptr;
2080
2081 return process_sp;
2082}
2083
2084size_t
2085Platform::ConnectToWaitingProcesses(lldb_private::Debugger& debugger, lldb_private::Error& error)
2086{
2087 error.Clear();
2088 return 0;
2089}