LLDB  mainline
Platform.cpp
Go to the documentation of this file.
1 //===-- Platform.cpp ------------------------------------------------------===//
2 //
3 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4 // See https://llvm.org/LICENSE.txt for license information.
5 // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6 //
7 //===----------------------------------------------------------------------===//
8 
9 #include <algorithm>
10 #include <csignal>
11 #include <fstream>
12 #include <memory>
13 #include <vector>
14 
17 #include "lldb/Core/Debugger.h"
18 #include "lldb/Core/Module.h"
19 #include "lldb/Core/ModuleSpec.h"
21 #include "lldb/Core/StreamFile.h"
22 #include "lldb/Host/FileSystem.h"
23 #include "lldb/Host/Host.h"
24 #include "lldb/Host/HostInfo.h"
25 #include "lldb/Host/OptionParser.h"
29 #include "lldb/Symbol/ObjectFile.h"
31 #include "lldb/Target/Platform.h"
32 #include "lldb/Target/Process.h"
33 #include "lldb/Target/Target.h"
36 #include "lldb/Utility/FileSpec.h"
37 #include "lldb/Utility/Log.h"
38 #include "lldb/Utility/Status.h"
40 #include "llvm/Support/FileSystem.h"
41 #include "llvm/Support/Path.h"
42 
43 // Define these constants from POSIX mman.h rather than include the file so
44 // that they will be correct even when compiled on Linux.
45 #define MAP_PRIVATE 2
46 #define MAP_ANON 0x1000
47 
48 using namespace lldb;
49 using namespace lldb_private;
50 
52 
53 // Use a singleton function for g_local_platform_sp to avoid init constructors
54 // since LLDB is often part of a shared library
55 static PlatformSP &GetHostPlatformSP() {
56  static PlatformSP g_platform_sp;
57  return g_platform_sp;
58 }
59 
60 const char *Platform::GetHostPlatformName() { return "host"; }
61 
62 namespace {
63 
64 #define LLDB_PROPERTIES_platform
65 #include "TargetProperties.inc"
66 
67 enum {
68 #define LLDB_PROPERTIES_platform
69 #include "TargetPropertiesEnum.inc"
70 };
71 
72 } // namespace
73 
74 ConstString PlatformProperties::GetSettingName() {
75  static ConstString g_setting_name("platform");
76  return g_setting_name;
77 }
78 
79 PlatformProperties::PlatformProperties() {
80  m_collection_sp = std::make_shared<OptionValueProperties>(GetSettingName());
81  m_collection_sp->Initialize(g_platform_properties);
82 
83  auto module_cache_dir = GetModuleCacheDirectory();
84  if (module_cache_dir)
85  return;
86 
87  llvm::SmallString<64> user_home_dir;
88  if (!FileSystem::Instance().GetHomeDirectory(user_home_dir))
89  return;
90 
91  module_cache_dir = FileSpec(user_home_dir.c_str());
92  module_cache_dir.AppendPathComponent(".lldb");
93  module_cache_dir.AppendPathComponent("module_cache");
94  SetDefaultModuleCacheDirectory(module_cache_dir);
95  SetModuleCacheDirectory(module_cache_dir);
96 }
97 
98 bool PlatformProperties::GetUseModuleCache() const {
99  const auto idx = ePropertyUseModuleCache;
100  return m_collection_sp->GetPropertyAtIndexAsBoolean(
101  nullptr, idx, g_platform_properties[idx].default_uint_value != 0);
102 }
103 
104 bool PlatformProperties::SetUseModuleCache(bool use_module_cache) {
105  return m_collection_sp->SetPropertyAtIndexAsBoolean(
106  nullptr, ePropertyUseModuleCache, use_module_cache);
107 }
108 
109 FileSpec PlatformProperties::GetModuleCacheDirectory() const {
110  return m_collection_sp->GetPropertyAtIndexAsFileSpec(
111  nullptr, ePropertyModuleCacheDirectory);
112 }
113 
114 bool PlatformProperties::SetModuleCacheDirectory(const FileSpec &dir_spec) {
115  return m_collection_sp->SetPropertyAtIndexAsFileSpec(
116  nullptr, ePropertyModuleCacheDirectory, dir_spec);
117 }
118 
119 void PlatformProperties::SetDefaultModuleCacheDirectory(
120  const FileSpec &dir_spec) {
121  auto f_spec_opt = m_collection_sp->GetPropertyAtIndexAsOptionValueFileSpec(
122  nullptr, false, ePropertyModuleCacheDirectory);
123  assert(f_spec_opt);
124  f_spec_opt->SetDefaultValue(dir_spec);
125 }
126 
127 /// Get the native host platform plug-in.
128 ///
129 /// There should only be one of these for each host that LLDB runs
130 /// upon that should be statically compiled in and registered using
131 /// preprocessor macros or other similar build mechanisms.
132 ///
133 /// This platform will be used as the default platform when launching
134 /// or attaching to processes unless another platform is specified.
135 PlatformSP Platform::GetHostPlatform() { return GetHostPlatformSP(); }
136 
137 static std::vector<PlatformSP> &GetPlatformList() {
138  static std::vector<PlatformSP> g_platform_list;
139  return g_platform_list;
140 }
141 
142 static std::recursive_mutex &GetPlatformListMutex() {
143  static std::recursive_mutex g_mutex;
144  return g_mutex;
145 }
146 
147 void Platform::Initialize() { g_initialize_count++; }
148 
149 void Platform::Terminate() {
150  if (g_initialize_count > 0) {
151  if (--g_initialize_count == 0) {
152  std::lock_guard<std::recursive_mutex> guard(GetPlatformListMutex());
153  GetPlatformList().clear();
154  }
155  }
156 }
157 
158 PlatformProperties &Platform::GetGlobalPlatformProperties() {
159  static PlatformProperties g_settings;
160  return g_settings;
161 }
162 
163 void Platform::SetHostPlatform(const lldb::PlatformSP &platform_sp) {
164  // The native platform should use its static void Platform::Initialize()
165  // function to register itself as the native platform.
166  GetHostPlatformSP() = platform_sp;
167 
168  if (platform_sp) {
169  std::lock_guard<std::recursive_mutex> guard(GetPlatformListMutex());
170  GetPlatformList().push_back(platform_sp);
171  }
172 }
173 
174 Status Platform::GetFileWithUUID(const FileSpec &platform_file,
175  const UUID *uuid_ptr, FileSpec &local_file) {
176  // Default to the local case
177  local_file = platform_file;
178  return Status();
179 }
180 
181 FileSpecList
182 Platform::LocateExecutableScriptingResources(Target *target, Module &module,
183  Stream *feedback_stream) {
184  return FileSpecList();
185 }
186 
187 // PlatformSP
188 // Platform::FindPlugin (Process *process, ConstString plugin_name)
189 //{
190 // PlatformCreateInstance create_callback = nullptr;
191 // if (plugin_name)
192 // {
193 // create_callback =
194 // PluginManager::GetPlatformCreateCallbackForPluginName (plugin_name);
195 // if (create_callback)
196 // {
197 // ArchSpec arch;
198 // if (process)
199 // {
200 // arch = process->GetTarget().GetArchitecture();
201 // }
202 // PlatformSP platform_sp(create_callback(process, &arch));
203 // if (platform_sp)
204 // return platform_sp;
205 // }
206 // }
207 // else
208 // {
209 // for (uint32_t idx = 0; (create_callback =
210 // PluginManager::GetPlatformCreateCallbackAtIndex(idx)) != nullptr;
211 // ++idx)
212 // {
213 // PlatformSP platform_sp(create_callback(process, nullptr));
214 // if (platform_sp)
215 // return platform_sp;
216 // }
217 // }
218 // return PlatformSP();
219 //}
220 
221 Status Platform::GetSharedModule(
222  const ModuleSpec &module_spec, Process *process, ModuleSP &module_sp,
223  const FileSpecList *module_search_paths_ptr,
224  llvm::SmallVectorImpl<lldb::ModuleSP> *old_modules, bool *did_create_ptr) {
225  if (IsHost())
226  return ModuleList::GetSharedModule(module_spec, module_sp,
227  module_search_paths_ptr, old_modules,
228  did_create_ptr, false);
229 
230  // Module resolver lambda.
231  auto resolver = [&](const ModuleSpec &spec) {
233  ModuleSpec resolved_spec;
234  // Check if we have sysroot set.
235  if (m_sdk_sysroot) {
236  // Prepend sysroot to module spec.
237  resolved_spec = spec;
238  resolved_spec.GetFileSpec().PrependPathComponent(
239  m_sdk_sysroot.GetStringRef());
240  // Try to get shared module with resolved spec.
241  error = ModuleList::GetSharedModule(resolved_spec, module_sp,
242  module_search_paths_ptr, old_modules,
243  did_create_ptr, false);
244  }
245  // If we don't have sysroot or it didn't work then
246  // try original module spec.
247  if (!error.Success()) {
248  resolved_spec = spec;
249  error = ModuleList::GetSharedModule(resolved_spec, module_sp,
250  module_search_paths_ptr, old_modules,
251  did_create_ptr, false);
252  }
253  if (error.Success() && module_sp)
254  module_sp->SetPlatformFileSpec(resolved_spec.GetFileSpec());
255  return error;
256  };
257 
258  return GetRemoteSharedModule(module_spec, process, module_sp, resolver,
259  did_create_ptr);
260 }
261 
262 bool Platform::GetModuleSpec(const FileSpec &module_file_spec,
263  const ArchSpec &arch, ModuleSpec &module_spec) {
264  ModuleSpecList module_specs;
265  if (ObjectFile::GetModuleSpecifications(module_file_spec, 0, 0,
266  module_specs) == 0)
267  return false;
268 
269  ModuleSpec matched_module_spec;
270  return module_specs.FindMatchingModuleSpec(ModuleSpec(module_file_spec, arch),
271  module_spec);
272 }
273 
274 PlatformSP Platform::Find(ConstString name) {
275  if (name) {
276  static ConstString g_host_platform_name("host");
277  if (name == g_host_platform_name)
278  return GetHostPlatform();
279 
280  std::lock_guard<std::recursive_mutex> guard(GetPlatformListMutex());
281  for (const auto &platform_sp : GetPlatformList()) {
282  if (platform_sp->GetName() == name)
283  return platform_sp;
284  }
285  }
286  return PlatformSP();
287 }
288 
289 PlatformSP Platform::Create(ConstString name, Status &error) {
290  PlatformCreateInstance create_callback = nullptr;
291  lldb::PlatformSP platform_sp;
292  if (name) {
293  static ConstString g_host_platform_name("host");
294  if (name == g_host_platform_name)
295  return GetHostPlatform();
296 
297  create_callback = PluginManager::GetPlatformCreateCallbackForPluginName(
298  name.GetStringRef());
299  if (create_callback)
300  platform_sp = create_callback(true, nullptr);
301  else
302  error.SetErrorStringWithFormat(
303  "unable to find a plug-in for the platform named \"%s\"",
304  name.GetCString());
305  } else
306  error.SetErrorString("invalid platform name");
307 
308  if (platform_sp) {
309  std::lock_guard<std::recursive_mutex> guard(GetPlatformListMutex());
310  GetPlatformList().push_back(platform_sp);
311  }
312 
313  return platform_sp;
314 }
315 
316 PlatformSP Platform::Create(const ArchSpec &arch, ArchSpec *platform_arch_ptr,
317  Status &error) {
318  lldb::PlatformSP platform_sp;
319  if (arch.IsValid()) {
320  // Scope for locker
321  {
322  // First try exact arch matches across all platforms already created
323  std::lock_guard<std::recursive_mutex> guard(GetPlatformListMutex());
324  for (const auto &platform_sp : GetPlatformList()) {
325  if (platform_sp->IsCompatibleArchitecture(arch, true,
326  platform_arch_ptr))
327  return platform_sp;
328  }
329 
330  // Next try compatible arch matches across all platforms already created
331  for (const auto &platform_sp : GetPlatformList()) {
332  if (platform_sp->IsCompatibleArchitecture(arch, false,
333  platform_arch_ptr))
334  return platform_sp;
335  }
336  }
337 
338  PlatformCreateInstance create_callback;
339  // First try exact arch matches across all platform plug-ins
340  uint32_t idx;
341  for (idx = 0; (create_callback =
342  PluginManager::GetPlatformCreateCallbackAtIndex(idx));
343  ++idx) {
344  if (create_callback) {
345  platform_sp = create_callback(false, &arch);
346  if (platform_sp &&
347  platform_sp->IsCompatibleArchitecture(arch, true,
348  platform_arch_ptr)) {
349  std::lock_guard<std::recursive_mutex> guard(GetPlatformListMutex());
350  GetPlatformList().push_back(platform_sp);
351  return platform_sp;
352  }
353  }
354  }
355  // Next try compatible arch matches across all platform plug-ins
356  for (idx = 0; (create_callback =
357  PluginManager::GetPlatformCreateCallbackAtIndex(idx));
358  ++idx) {
359  if (create_callback) {
360  platform_sp = create_callback(false, &arch);
361  if (platform_sp &&
362  platform_sp->IsCompatibleArchitecture(arch, false,
363  platform_arch_ptr)) {
364  std::lock_guard<std::recursive_mutex> guard(GetPlatformListMutex());
365  GetPlatformList().push_back(platform_sp);
366  return platform_sp;
367  }
368  }
369  }
370  } else
371  error.SetErrorString("invalid platform name");
372  if (platform_arch_ptr)
373  platform_arch_ptr->Clear();
374  platform_sp.reset();
375  return platform_sp;
376 }
377 
378 ArchSpec Platform::GetAugmentedArchSpec(Platform *platform, llvm::StringRef triple) {
379  if (platform)
380  return platform->GetAugmentedArchSpec(triple);
381  return HostInfo::GetAugmentedArchSpec(triple);
382 }
383 
384 /// Default Constructor
385 Platform::Platform(bool is_host)
386  : m_is_host(is_host), m_os_version_set_while_connected(false),
387  m_system_arch_set_while_connected(false), m_sdk_sysroot(), m_sdk_build(),
388  m_working_dir(), m_remote_url(), m_name(), m_system_arch(), m_mutex(),
389  m_max_uid_name_len(0), m_max_gid_name_len(0), m_supports_rsync(false),
390  m_rsync_opts(), m_rsync_prefix(), m_supports_ssh(false), m_ssh_opts(),
391  m_ignores_remote_hostname(false), m_trap_handlers(),
392  m_calculated_trap_handlers(false),
393  m_module_cache(std::make_unique<ModuleCache>()) {
395  LLDB_LOGF(log, "%p Platform::Platform()", static_cast<void *>(this));
396 }
397 
398 Platform::~Platform() = default;
399 
401  strm.Format(" Platform: {0}\n", GetPluginName());
402 
404  if (arch.IsValid()) {
405  if (!arch.GetTriple().str().empty()) {
406  strm.Printf(" Triple: ");
407  arch.DumpTriple(strm.AsRawOstream());
408  strm.EOL();
409  }
410  }
411 
412  llvm::VersionTuple os_version = GetOSVersion();
413  if (!os_version.empty()) {
414  strm.Format("OS Version: {0}", os_version.getAsString());
415 
416  if (llvm::Optional<std::string> s = GetOSBuildString())
417  strm.Format(" ({0})", *s);
418 
419  strm.EOL();
420  }
421 
422  if (IsHost()) {
423  strm.Printf(" Hostname: %s\n", GetHostname());
424  } else {
425  const bool is_connected = IsConnected();
426  if (is_connected)
427  strm.Printf(" Hostname: %s\n", GetHostname());
428  strm.Printf(" Connected: %s\n", is_connected ? "yes" : "no");
429  }
430 
431  if (GetWorkingDirectory()) {
432  strm.Printf("WorkingDir: %s\n", GetWorkingDirectory().GetCString());
433  }
434  if (!IsConnected())
435  return;
436 
438 
439  if (!specific_info.empty())
440  strm.Printf("Platform-specific connection: %s\n", specific_info.c_str());
441 
442  if (llvm::Optional<std::string> s = GetOSKernelDescription())
443  strm.Format(" Kernel: {0}\n", *s);
444 }
445 
446 llvm::VersionTuple Platform::GetOSVersion(Process *process) {
447  std::lock_guard<std::mutex> guard(m_mutex);
448 
449  if (IsHost()) {
450  if (m_os_version.empty()) {
451  // We have a local host platform
452  m_os_version = HostInfo::GetOSVersion();
454  }
455  } else {
456  // We have a remote platform. We can only fetch the remote
457  // OS version if we are connected, and we don't want to do it
458  // more than once.
459 
460  const bool is_connected = IsConnected();
461 
462  bool fetch = false;
463  if (!m_os_version.empty()) {
464  // We have valid OS version info, check to make sure it wasn't manually
465  // set prior to connecting. If it was manually set prior to connecting,
466  // then lets fetch the actual OS version info if we are now connected.
467  if (is_connected && !m_os_version_set_while_connected)
468  fetch = true;
469  } else {
470  // We don't have valid OS version info, fetch it if we are connected
471  fetch = is_connected;
472  }
473 
474  if (fetch)
476  }
477 
478  if (!m_os_version.empty())
479  return m_os_version;
480  if (process) {
481  // Check with the process in case it can answer the question if a process
482  // was provided
483  return process->GetHostOSVersion();
484  }
485  return llvm::VersionTuple();
486 }
487 
488 llvm::Optional<std::string> Platform::GetOSBuildString() {
489  if (IsHost())
490  return HostInfo::GetOSBuildString();
491  return GetRemoteOSBuildString();
492 }
493 
494 llvm::Optional<std::string> Platform::GetOSKernelDescription() {
495  if (IsHost())
496  return HostInfo::GetOSKernelDescription();
498 }
499 
501  Target *target, std::vector<std::string> &options) {
502  std::vector<std::string> default_compilation_options = {
503  "-x", "c++", "-Xclang", "-nostdsysteminc", "-Xclang", "-nostdsysteminc"};
504 
505  options.insert(options.end(), default_compilation_options.begin(),
506  default_compilation_options.end());
507 }
508 
510  if (IsHost()) {
511  llvm::SmallString<64> cwd;
512  if (llvm::sys::fs::current_path(cwd))
513  return {};
514  else {
515  FileSpec file_spec(cwd);
516  FileSystem::Instance().Resolve(file_spec);
517  return file_spec;
518  }
519  } else {
520  if (!m_working_dir)
522  return m_working_dir;
523  }
524 }
525 
527  const FileSpec &dst;
530 };
531 
533 RecurseCopy_Callback(void *baton, llvm::sys::fs::file_type ft,
534  llvm::StringRef path) {
535  RecurseCopyBaton *rc_baton = (RecurseCopyBaton *)baton;
536  FileSpec src(path);
537  namespace fs = llvm::sys::fs;
538  switch (ft) {
539  case fs::file_type::fifo_file:
540  case fs::file_type::socket_file:
541  // we have no way to copy pipes and sockets - ignore them and continue
543  break;
544 
545  case fs::file_type::directory_file: {
546  // make the new directory and get in there
547  FileSpec dst_dir = rc_baton->dst;
548  if (!dst_dir.GetFilename())
549  dst_dir.GetFilename() = src.GetLastPathComponent();
550  Status error = rc_baton->platform_ptr->MakeDirectory(
551  dst_dir, lldb::eFilePermissionsDirectoryDefault);
552  if (error.Fail()) {
554  "unable to setup directory %s on remote end", dst_dir.GetCString());
555  return FileSystem::eEnumerateDirectoryResultQuit; // got an error, bail out
556  }
557 
558  // now recurse
559  std::string src_dir_path(src.GetPath());
560 
561  // Make a filespec that only fills in the directory of a FileSpec so when
562  // we enumerate we can quickly fill in the filename for dst copies
563  FileSpec recurse_dst;
564  recurse_dst.GetDirectory().SetCString(dst_dir.GetPath().c_str());
565  RecurseCopyBaton rc_baton2 = {recurse_dst, rc_baton->platform_ptr,
566  Status()};
567  FileSystem::Instance().EnumerateDirectory(src_dir_path, true, true, true,
568  RecurseCopy_Callback, &rc_baton2);
569  if (rc_baton2.error.Fail()) {
570  rc_baton->error.SetErrorString(rc_baton2.error.AsCString());
571  return FileSystem::eEnumerateDirectoryResultQuit; // got an error, bail out
572  }
574  } break;
575 
576  case fs::file_type::symlink_file: {
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  FileSpec src_resolved;
583 
584  rc_baton->error = FileSystem::Instance().Readlink(src, src_resolved);
585 
586  if (rc_baton->error.Fail())
587  return FileSystem::eEnumerateDirectoryResultQuit; // got an error, bail out
588 
589  rc_baton->error =
590  rc_baton->platform_ptr->CreateSymlink(dst_file, src_resolved);
591 
592  if (rc_baton->error.Fail())
593  return FileSystem::eEnumerateDirectoryResultQuit; // got an error, bail out
594 
596  } break;
597 
598  case fs::file_type::regular_file: {
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  Status err = rc_baton->platform_ptr->PutFile(src, dst_file);
604  if (err.Fail()) {
605  rc_baton->error.SetErrorString(err.AsCString());
606  return FileSystem::eEnumerateDirectoryResultQuit; // got an error, bail out
607  }
609  } break;
610 
611  default:
613  "invalid file detected during copy: %s", src.GetPath().c_str());
614  return FileSystem::eEnumerateDirectoryResultQuit; // got an error, bail out
615  break;
616  }
617  llvm_unreachable("Unhandled file_type!");
618 }
619 
620 Status Platform::Install(const FileSpec &src, const FileSpec &dst) {
621  Status error;
622 
624  LLDB_LOGF(log, "Platform::Install (src='%s', dst='%s')",
625  src.GetPath().c_str(), dst.GetPath().c_str());
626  FileSpec fixed_dst(dst);
627 
628  if (!fixed_dst.GetFilename())
629  fixed_dst.GetFilename() = src.GetFilename();
630 
631  FileSpec working_dir = GetWorkingDirectory();
632 
633  if (dst) {
634  if (dst.GetDirectory()) {
635  const char first_dst_dir_char = dst.GetDirectory().GetCString()[0];
636  if (first_dst_dir_char == '/' || first_dst_dir_char == '\\') {
637  fixed_dst.GetDirectory() = dst.GetDirectory();
638  }
639  // If the fixed destination file doesn't have a directory yet, then we
640  // must have a relative path. We will resolve this relative path against
641  // the platform's working directory
642  if (!fixed_dst.GetDirectory()) {
643  FileSpec relative_spec;
644  std::string path;
645  if (working_dir) {
646  relative_spec = working_dir;
647  relative_spec.AppendPathComponent(dst.GetPath());
648  fixed_dst.GetDirectory() = relative_spec.GetDirectory();
649  } else {
650  error.SetErrorStringWithFormat(
651  "platform working directory must be valid for relative path '%s'",
652  dst.GetPath().c_str());
653  return error;
654  }
655  }
656  } else {
657  if (working_dir) {
658  fixed_dst.GetDirectory().SetCString(working_dir.GetCString());
659  } else {
660  error.SetErrorStringWithFormat(
661  "platform working directory must be valid for relative path '%s'",
662  dst.GetPath().c_str());
663  return error;
664  }
665  }
666  } else {
667  if (working_dir) {
668  fixed_dst.GetDirectory().SetCString(working_dir.GetCString());
669  } else {
670  error.SetErrorStringWithFormat("platform working directory must be valid "
671  "when destination directory is empty");
672  return error;
673  }
674  }
675 
676  LLDB_LOGF(log, "Platform::Install (src='%s', dst='%s') fixed_dst='%s'",
677  src.GetPath().c_str(), dst.GetPath().c_str(),
678  fixed_dst.GetPath().c_str());
679 
680  if (GetSupportsRSync()) {
681  error = PutFile(src, dst);
682  } else {
683  namespace fs = llvm::sys::fs;
684  switch (fs::get_file_type(src.GetPath(), false)) {
685  case fs::file_type::directory_file: {
686  llvm::sys::fs::remove(fixed_dst.GetPath());
687  uint32_t permissions = FileSystem::Instance().GetPermissions(src);
688  if (permissions == 0)
689  permissions = eFilePermissionsDirectoryDefault;
690  error = MakeDirectory(fixed_dst, permissions);
691  if (error.Success()) {
692  // Make a filespec that only fills in the directory of a FileSpec so
693  // when we enumerate we can quickly fill in the filename for dst copies
694  FileSpec recurse_dst;
695  recurse_dst.GetDirectory().SetCString(fixed_dst.GetCString());
696  std::string src_dir_path(src.GetPath());
697  RecurseCopyBaton baton = {recurse_dst, this, Status()};
699  src_dir_path, true, true, true, RecurseCopy_Callback, &baton);
700  return baton.error;
701  }
702  } break;
703 
704  case fs::file_type::regular_file:
705  llvm::sys::fs::remove(fixed_dst.GetPath());
706  error = PutFile(src, fixed_dst);
707  break;
708 
709  case fs::file_type::symlink_file: {
710  llvm::sys::fs::remove(fixed_dst.GetPath());
711  FileSpec src_resolved;
712  error = FileSystem::Instance().Readlink(src, src_resolved);
713  if (error.Success())
714  error = CreateSymlink(dst, src_resolved);
715  } break;
716  case fs::file_type::fifo_file:
717  error.SetErrorString("platform install doesn't handle pipes");
718  break;
719  case fs::file_type::socket_file:
720  error.SetErrorString("platform install doesn't handle sockets");
721  break;
722  default:
723  error.SetErrorString(
724  "platform install doesn't handle non file or directory items");
725  break;
726  }
727  }
728  return error;
729 }
730 
731 bool Platform::SetWorkingDirectory(const FileSpec &file_spec) {
732  if (IsHost()) {
734  LLDB_LOG(log, "{0}", file_spec);
735  if (std::error_code ec = llvm::sys::fs::set_current_path(file_spec.GetPath())) {
736  LLDB_LOG(log, "error: {0}", ec.message());
737  return false;
738  }
739  return true;
740  } else {
742  return SetRemoteWorkingDirectory(file_spec);
743  }
744 }
745 
747  uint32_t permissions) {
748  if (IsHost())
749  return llvm::sys::fs::create_directory(file_spec.GetPath(), permissions);
750  else {
751  Status error;
752  error.SetErrorStringWithFormatv("remote platform {0} doesn't support {1}",
753  GetPluginName(), LLVM_PRETTY_FUNCTION);
754  return error;
755  }
756 }
757 
759  uint32_t &file_permissions) {
760  if (IsHost()) {
761  auto Value = llvm::sys::fs::getPermissions(file_spec.GetPath());
762  if (Value)
763  file_permissions = Value.get();
764  return Status(Value.getError());
765  } else {
766  Status error;
767  error.SetErrorStringWithFormatv("remote platform {0} doesn't support {1}",
768  GetPluginName(), LLVM_PRETTY_FUNCTION);
769  return error;
770  }
771 }
772 
774  uint32_t file_permissions) {
775  if (IsHost()) {
776  auto Perms = static_cast<llvm::sys::fs::perms>(file_permissions);
777  return llvm::sys::fs::setPermissions(file_spec.GetPath(), Perms);
778  } else {
779  Status error;
780  error.SetErrorStringWithFormatv("remote platform {0} doesn't support {1}",
781  GetPluginName(), LLVM_PRETTY_FUNCTION);
782  return error;
783  }
784 }
785 
787 
788 const char *Platform::GetHostname() {
789  if (IsHost())
790  return "127.0.0.1";
791 
792  if (m_name.empty())
793  return nullptr;
794  return m_name.c_str();
795 }
796 
798  return basename;
799 }
800 
803  LLDB_LOGF(log, "Platform::SetRemoteWorkingDirectory('%s')",
804  working_dir.GetCString());
805  m_working_dir = working_dir;
806  return true;
807 }
808 
809 bool Platform::SetOSVersion(llvm::VersionTuple version) {
810  if (IsHost()) {
811  // We don't need anyone setting the OS version for the host platform, we
812  // should be able to figure it out by calling HostInfo::GetOSVersion(...).
813  return false;
814  } else {
815  // We have a remote platform, allow setting the target OS version if we
816  // aren't connected, since if we are connected, we should be able to
817  // request the remote OS version from the connected platform.
818  if (IsConnected())
819  return false;
820  else {
821  // We aren't connected and we might want to set the OS version ahead of
822  // time before we connect so we can peruse files and use a local SDK or
823  // PDK cache of support files to disassemble or do other things.
824  m_os_version = version;
825  return true;
826  }
827  }
828  return false;
829 }
830 
831 Status
833  lldb::ModuleSP &exe_module_sp,
834  const FileSpecList *module_search_paths_ptr) {
835  Status error;
836 
837  if (FileSystem::Instance().Exists(module_spec.GetFileSpec())) {
838  if (module_spec.GetArchitecture().IsValid()) {
839  error = ModuleList::GetSharedModule(module_spec, exe_module_sp,
840  module_search_paths_ptr, nullptr,
841  nullptr);
842  } else {
843  // No valid architecture was specified, ask the platform for the
844  // architectures that we should be using (in the correct order) and see
845  // if we can find a match that way
846  ModuleSpec arch_module_spec(module_spec);
847  for (const ArchSpec &arch : GetSupportedArchitectures()) {
848  arch_module_spec.GetArchitecture() = arch;
849  error = ModuleList::GetSharedModule(arch_module_spec, exe_module_sp,
850  module_search_paths_ptr, nullptr,
851  nullptr);
852  // Did we find an executable using one of the
853  if (error.Success() && exe_module_sp)
854  break;
855  }
856  }
857  } else {
858  error.SetErrorStringWithFormat(
859  "'%s' does not exist", module_spec.GetFileSpec().GetPath().c_str());
860  }
861  return error;
862 }
863 
864 Status
866  lldb::ModuleSP &exe_module_sp,
867  const FileSpecList *module_search_paths_ptr) {
868  Status error;
869 
870  // We may connect to a process and use the provided executable (Don't use
871  // local $PATH).
872  ModuleSpec resolved_module_spec(module_spec);
873 
874  // Resolve any executable within a bundle on MacOSX
875  Host::ResolveExecutableInBundle(resolved_module_spec.GetFileSpec());
876 
877  if (FileSystem::Instance().Exists(resolved_module_spec.GetFileSpec()) ||
878  module_spec.GetUUID().IsValid()) {
879  if (resolved_module_spec.GetArchitecture().IsValid() ||
880  resolved_module_spec.GetUUID().IsValid()) {
881  error = ModuleList::GetSharedModule(resolved_module_spec, exe_module_sp,
882  module_search_paths_ptr, nullptr,
883  nullptr);
884 
885  if (exe_module_sp && exe_module_sp->GetObjectFile())
886  return error;
887  exe_module_sp.reset();
888  }
889  // No valid architecture was specified or the exact arch wasn't found so
890  // ask the platform for the architectures that we should be using (in the
891  // correct order) and see if we can find a match that way
892  StreamString arch_names;
893  llvm::ListSeparator LS;
894  for (const ArchSpec &arch : GetSupportedArchitectures()) {
895  resolved_module_spec.GetArchitecture() = arch;
896  error = ModuleList::GetSharedModule(resolved_module_spec, exe_module_sp,
897  module_search_paths_ptr, nullptr,
898  nullptr);
899  // Did we find an executable using one of the
900  if (error.Success()) {
901  if (exe_module_sp && exe_module_sp->GetObjectFile())
902  break;
903  else
904  error.SetErrorToGenericError();
905  }
906 
907  arch_names << LS << arch.GetArchitectureName();
908  }
909 
910  if (error.Fail() || !exe_module_sp) {
911  if (FileSystem::Instance().Readable(resolved_module_spec.GetFileSpec())) {
912  error.SetErrorStringWithFormatv(
913  "'{0}' doesn't contain any '{1}' platform architectures: {2}",
914  resolved_module_spec.GetFileSpec(), GetPluginName(),
915  arch_names.GetData());
916  } else {
917  error.SetErrorStringWithFormatv("'{0}' is not readable",
918  resolved_module_spec.GetFileSpec());
919  }
920  }
921  } else {
922  error.SetErrorStringWithFormatv("'{0}' does not exist",
923  resolved_module_spec.GetFileSpec());
924  }
925 
926  return error;
927 }
928 
930  FileSpec &sym_file) {
931  Status error;
932  if (FileSystem::Instance().Exists(sym_spec.GetSymbolFileSpec()))
933  sym_file = sym_spec.GetSymbolFileSpec();
934  else
935  error.SetErrorString("unable to resolve symbol file");
936  return error;
937 }
938 
939 bool Platform::ResolveRemotePath(const FileSpec &platform_path,
940  FileSpec &resolved_platform_path) {
941  resolved_platform_path = platform_path;
942  FileSystem::Instance().Resolve(resolved_platform_path);
943  return true;
944 }
945 
947  if (IsHost()) {
948  if (!m_system_arch.IsValid()) {
949  // We have a local host platform
950  m_system_arch = HostInfo::GetArchitecture();
952  }
953  } else {
954  // We have a remote platform. We can only fetch the remote system
955  // architecture if we are connected, and we don't want to do it more than
956  // once.
957 
958  const bool is_connected = IsConnected();
959 
960  bool fetch = false;
961  if (m_system_arch.IsValid()) {
962  // We have valid OS version info, check to make sure it wasn't manually
963  // set prior to connecting. If it was manually set prior to connecting,
964  // then lets fetch the actual OS version info if we are now connected.
965  if (is_connected && !m_system_arch_set_while_connected)
966  fetch = true;
967  } else {
968  // We don't have valid OS version info, fetch it if we are connected
969  fetch = is_connected;
970  }
971 
972  if (fetch) {
975  }
976  }
977  return m_system_arch;
978 }
979 
980 ArchSpec Platform::GetAugmentedArchSpec(llvm::StringRef triple) {
981  if (triple.empty())
982  return ArchSpec();
983  llvm::Triple normalized_triple(llvm::Triple::normalize(triple));
984  if (!ArchSpec::ContainsOnlyArch(normalized_triple))
985  return ArchSpec(triple);
986 
987  if (auto kind = HostInfo::ParseArchitectureKind(triple))
988  return HostInfo::GetArchitecture(*kind);
989 
990  ArchSpec compatible_arch;
991  ArchSpec raw_arch(triple);
992  if (!IsCompatibleArchitecture(raw_arch, false, &compatible_arch))
993  return raw_arch;
994 
995  if (!compatible_arch.IsValid())
996  return ArchSpec(normalized_triple);
997 
998  const llvm::Triple &compatible_triple = compatible_arch.GetTriple();
999  if (normalized_triple.getVendorName().empty())
1000  normalized_triple.setVendor(compatible_triple.getVendor());
1001  if (normalized_triple.getOSName().empty())
1002  normalized_triple.setOS(compatible_triple.getOS());
1003  if (normalized_triple.getEnvironmentName().empty())
1004  normalized_triple.setEnvironment(compatible_triple.getEnvironment());
1005  return ArchSpec(normalized_triple);
1006 }
1007 
1009  Status error;
1010  if (IsHost())
1011  error.SetErrorStringWithFormatv(
1012  "The currently selected platform ({0}) is "
1013  "the host platform and is always connected.",
1014  GetPluginName());
1015  else
1016  error.SetErrorStringWithFormatv(
1017  "Platform::ConnectRemote() is not supported by {0}", GetPluginName());
1018  return error;
1019 }
1020 
1022  Status error;
1023  if (IsHost())
1024  error.SetErrorStringWithFormatv(
1025  "The currently selected platform ({0}) is "
1026  "the host platform and is always connected.",
1027  GetPluginName());
1028  else
1029  error.SetErrorStringWithFormatv(
1030  "Platform::DisconnectRemote() is not supported by {0}",
1031  GetPluginName());
1032  return error;
1033 }
1034 
1036  ProcessInstanceInfo &process_info) {
1037  // Take care of the host case so that each subclass can just call this
1038  // function to get the host functionality.
1039  if (IsHost())
1040  return Host::GetProcessInfo(pid, process_info);
1041  return false;
1042 }
1043 
1045  ProcessInstanceInfoList &process_infos) {
1046  // Take care of the host case so that each subclass can just call this
1047  // function to get the host functionality.
1048  uint32_t match_count = 0;
1049  if (IsHost())
1050  match_count = Host::FindProcesses(match_info, process_infos);
1051  return match_count;
1052 }
1053 
1055  Status error;
1057  LLDB_LOGF(log, "Platform::%s()", __FUNCTION__);
1058 
1059  // Take care of the host case so that each subclass can just call this
1060  // function to get the host functionality.
1061  if (IsHost()) {
1062  if (::getenv("LLDB_LAUNCH_FLAG_LAUNCH_IN_TTY"))
1063  launch_info.GetFlags().Set(eLaunchFlagLaunchInTTY);
1064 
1065  if (launch_info.GetFlags().Test(eLaunchFlagLaunchInShell)) {
1066  const bool will_debug = launch_info.GetFlags().Test(eLaunchFlagDebug);
1067  const bool first_arg_is_full_shell_command = false;
1068  uint32_t num_resumes = GetResumeCountForLaunchInfo(launch_info);
1069  if (log) {
1070  const FileSpec &shell = launch_info.GetShell();
1071  std::string shell_str = (shell) ? shell.GetPath() : "<null>";
1072  LLDB_LOGF(log,
1073  "Platform::%s GetResumeCountForLaunchInfo() returned %" PRIu32
1074  ", shell is '%s'",
1075  __FUNCTION__, num_resumes, shell_str.c_str());
1076  }
1077 
1078  if (!launch_info.ConvertArgumentsForLaunchingInShell(
1079  error, will_debug, first_arg_is_full_shell_command, num_resumes))
1080  return error;
1081  } else if (launch_info.GetFlags().Test(eLaunchFlagShellExpandArguments)) {
1082  error = ShellExpandArguments(launch_info);
1083  if (error.Fail()) {
1084  error.SetErrorStringWithFormat("shell expansion failed (reason: %s). "
1085  "consider launching with 'process "
1086  "launch'.",
1087  error.AsCString("unknown"));
1088  return error;
1089  }
1090  }
1091 
1092  LLDB_LOGF(log, "Platform::%s final launch_info resume count: %" PRIu32,
1093  __FUNCTION__, launch_info.GetResumeCount());
1094 
1095  error = Host::LaunchProcess(launch_info);
1096  } else
1097  error.SetErrorString(
1098  "base lldb_private::Platform class can't launch remote processes");
1099  return error;
1100 }
1101 
1103  if (IsHost())
1104  return Host::ShellExpandArguments(launch_info);
1105  return Status("base lldb_private::Platform class can't expand arguments");
1106 }
1107 
1110  LLDB_LOGF(log, "Platform::%s, pid %" PRIu64, __FUNCTION__, pid);
1111 
1112  if (!IsHost()) {
1113  return Status(
1114  "base lldb_private::Platform class can't kill remote processes");
1115  }
1116  Host::Kill(pid, SIGKILL);
1117  return Status();
1118 }
1119 
1120 lldb::ProcessSP Platform::DebugProcess(ProcessLaunchInfo &launch_info,
1121  Debugger &debugger, Target &target,
1122  Status &error) {
1124  LLDB_LOG(log, "target = {0})", &target);
1125 
1126  ProcessSP process_sp;
1127  // Make sure we stop at the entry point
1128  launch_info.GetFlags().Set(eLaunchFlagDebug);
1129  // We always launch the process we are going to debug in a separate process
1130  // group, since then we can handle ^C interrupts ourselves w/o having to
1131  // worry about the target getting them as well.
1132  launch_info.SetLaunchInSeparateProcessGroup(true);
1133 
1134  // Allow any StructuredData process-bound plugins to adjust the launch info
1135  // if needed
1136  size_t i = 0;
1137  bool iteration_complete = false;
1138  // Note iteration can't simply go until a nullptr callback is returned, as it
1139  // is valid for a plugin to not supply a filter.
1141  for (auto filter_callback = get_filter_func(i, iteration_complete);
1142  !iteration_complete;
1143  filter_callback = get_filter_func(++i, iteration_complete)) {
1144  if (filter_callback) {
1145  // Give this ProcessLaunchInfo filter a chance to adjust the launch info.
1146  error = (*filter_callback)(launch_info, &target);
1147  if (!error.Success()) {
1148  LLDB_LOGF(log,
1149  "Platform::%s() StructuredDataPlugin launch "
1150  "filter failed.",
1151  __FUNCTION__);
1152  return process_sp;
1153  }
1154  }
1155  }
1156 
1157  error = LaunchProcess(launch_info);
1158  if (error.Success()) {
1159  LLDB_LOGF(log,
1160  "Platform::%s LaunchProcess() call succeeded (pid=%" PRIu64 ")",
1161  __FUNCTION__, launch_info.GetProcessID());
1162  if (launch_info.GetProcessID() != LLDB_INVALID_PROCESS_ID) {
1163  ProcessAttachInfo attach_info(launch_info);
1164  process_sp = Attach(attach_info, debugger, &target, error);
1165  if (process_sp) {
1166  LLDB_LOG(log, "Attach() succeeded, Process plugin: {0}",
1167  process_sp->GetPluginName());
1168  launch_info.SetHijackListener(attach_info.GetHijackListener());
1169 
1170  // Since we attached to the process, it will think it needs to detach
1171  // if the process object just goes away without an explicit call to
1172  // Process::Kill() or Process::Detach(), so let it know to kill the
1173  // process if this happens.
1174  process_sp->SetShouldDetach(false);
1175 
1176  // If we didn't have any file actions, the pseudo terminal might have
1177  // been used where the secondary side was given as the file to open for
1178  // stdin/out/err after we have already opened the primary so we can
1179  // read/write stdin/out/err.
1180  int pty_fd = launch_info.GetPTY().ReleasePrimaryFileDescriptor();
1181  if (pty_fd != PseudoTerminal::invalid_fd) {
1182  process_sp->SetSTDIOFileDescriptor(pty_fd);
1183  }
1184  } else {
1185  LLDB_LOGF(log, "Platform::%s Attach() failed: %s", __FUNCTION__,
1186  error.AsCString());
1187  }
1188  } else {
1189  LLDB_LOGF(log,
1190  "Platform::%s LaunchProcess() returned launch_info with "
1191  "invalid process id",
1192  __FUNCTION__);
1193  }
1194  } else {
1195  LLDB_LOGF(log, "Platform::%s LaunchProcess() failed: %s", __FUNCTION__,
1196  error.AsCString());
1197  }
1198 
1199  return process_sp;
1200 }
1201 
1202 lldb::PlatformSP
1204  ArchSpec *platform_arch_ptr) {
1205  lldb::PlatformSP platform_sp;
1206  Status error;
1207  if (arch.IsValid())
1208  platform_sp = Platform::Create(arch, platform_arch_ptr, error);
1209  return platform_sp;
1210 }
1211 
1212 std::vector<ArchSpec>
1213 Platform::CreateArchList(llvm::ArrayRef<llvm::Triple::ArchType> archs,
1214  llvm::Triple::OSType os) {
1215  std::vector<ArchSpec> list;
1216  for(auto arch : archs) {
1217  llvm::Triple triple;
1218  triple.setArch(arch);
1219  triple.setOS(os);
1220  list.push_back(ArchSpec(triple));
1221  }
1222  return list;
1223 }
1224 
1225 /// Lets a platform answer if it is compatible with a given
1226 /// architecture and the target triple contained within.
1228  bool exact_arch_match,
1229  ArchSpec *compatible_arch_ptr) {
1230  // If the architecture is invalid, we must answer true...
1231  if (arch.IsValid()) {
1232  ArchSpec platform_arch;
1233  auto match = exact_arch_match ? &ArchSpec::IsExactMatch
1235  for (const ArchSpec &platform_arch : GetSupportedArchitectures()) {
1236  if ((arch.*match)(platform_arch)) {
1237  if (compatible_arch_ptr)
1238  *compatible_arch_ptr = platform_arch;
1239  return true;
1240  }
1241  }
1242  }
1243  if (compatible_arch_ptr)
1244  compatible_arch_ptr->Clear();
1245  return false;
1246 }
1247 
1248 Status Platform::PutFile(const FileSpec &source, const FileSpec &destination,
1249  uint32_t uid, uint32_t gid) {
1251  LLDB_LOGF(log, "[PutFile] Using block by block transfer....\n");
1252 
1253  auto source_open_options =
1255  namespace fs = llvm::sys::fs;
1256  if (fs::is_symlink_file(source.GetPath()))
1257  source_open_options |= File::eOpenOptionDontFollowSymlinks;
1258 
1259  auto source_file = FileSystem::Instance().Open(source, source_open_options,
1260  lldb::eFilePermissionsUserRW);
1261  if (!source_file)
1262  return Status(source_file.takeError());
1263  Status error;
1264  uint32_t permissions = source_file.get()->GetPermissions(error);
1265  if (permissions == 0)
1266  permissions = lldb::eFilePermissionsFileDefault;
1267 
1268  lldb::user_id_t dest_file = OpenFile(
1271  permissions, error);
1272  LLDB_LOGF(log, "dest_file = %" PRIu64 "\n", dest_file);
1273 
1274  if (error.Fail())
1275  return error;
1276  if (dest_file == UINT64_MAX)
1277  return Status("unable to open target file");
1278  lldb::DataBufferSP buffer_sp(new DataBufferHeap(1024 * 16, 0));
1279  uint64_t offset = 0;
1280  for (;;) {
1281  size_t bytes_read = buffer_sp->GetByteSize();
1282  error = source_file.get()->Read(buffer_sp->GetBytes(), bytes_read);
1283  if (error.Fail() || bytes_read == 0)
1284  break;
1285 
1286  const uint64_t bytes_written =
1287  WriteFile(dest_file, offset, buffer_sp->GetBytes(), bytes_read, error);
1288  if (error.Fail())
1289  break;
1290 
1291  offset += bytes_written;
1292  if (bytes_written != bytes_read) {
1293  // We didn't write the correct number of bytes, so adjust the file
1294  // position in the source file we are reading from...
1295  source_file.get()->SeekFromStart(offset);
1296  }
1297  }
1298  CloseFile(dest_file, error);
1299 
1300  if (uid == UINT32_MAX && gid == UINT32_MAX)
1301  return error;
1302 
1303  // TODO: ChownFile?
1304 
1305  return error;
1306 }
1307 
1308 Status Platform::GetFile(const FileSpec &source, const FileSpec &destination) {
1309  Status error("unimplemented");
1310  return error;
1311 }
1312 
1313 Status
1314 Platform::CreateSymlink(const FileSpec &src, // The name of the link is in src
1315  const FileSpec &dst) // The symlink points to dst
1316 {
1317  Status error("unimplemented");
1318  return error;
1319 }
1320 
1322  return false;
1323 }
1324 
1326  Status error("unimplemented");
1327  return error;
1328 }
1329 
1331  addr_t length, unsigned prot,
1332  unsigned flags, addr_t fd,
1333  addr_t offset) {
1334  uint64_t flags_platform = 0;
1335  if (flags & eMmapFlagsPrivate)
1336  flags_platform |= MAP_PRIVATE;
1337  if (flags & eMmapFlagsAnon)
1338  flags_platform |= MAP_ANON;
1339 
1340  MmapArgList args({addr, length, prot, flags_platform, fd, offset});
1341  return args;
1342 }
1343 
1345  llvm::StringRef command,
1346  const FileSpec &
1347  working_dir, // Pass empty FileSpec to use the current working directory
1348  int *status_ptr, // Pass nullptr if you don't want the process exit status
1349  int *signo_ptr, // Pass nullptr if you don't want the signal that caused the
1350  // process to exit
1351  std::string
1352  *command_output, // Pass nullptr if you don't want the command output
1353  const Timeout<std::micro> &timeout) {
1354  return RunShellCommand(llvm::StringRef(), command, working_dir, status_ptr,
1355  signo_ptr, command_output, timeout);
1356 }
1357 
1359  llvm::StringRef shell, // Pass empty if you want to use the default
1360  // shell interpreter
1361  llvm::StringRef command, // Shouldn't be empty
1362  const FileSpec &
1363  working_dir, // Pass empty FileSpec to use the current working directory
1364  int *status_ptr, // Pass nullptr if you don't want the process exit status
1365  int *signo_ptr, // Pass nullptr if you don't want the signal that caused the
1366  // process to exit
1367  std::string
1368  *command_output, // Pass nullptr if you don't want the command output
1369  const Timeout<std::micro> &timeout) {
1370  if (IsHost())
1371  return Host::RunShellCommand(shell, command, working_dir, status_ptr,
1372  signo_ptr, command_output, timeout);
1373  else
1374  return Status("unimplemented");
1375 }
1376 
1377 bool Platform::CalculateMD5(const FileSpec &file_spec, uint64_t &low,
1378  uint64_t &high) {
1379  if (!IsHost())
1380  return false;
1381  auto Result = llvm::sys::fs::md5_contents(file_spec.GetPath());
1382  if (!Result)
1383  return false;
1384  std::tie(high, low) = Result->words();
1385  return true;
1386 }
1387 
1388 void Platform::SetLocalCacheDirectory(const char *local) {
1389  m_local_cache_directory.assign(local);
1390 }
1391 
1393  return m_local_cache_directory.c_str();
1394 }
1395 
1397  {LLDB_OPT_SET_ALL, false, "rsync", 'r', OptionParser::eNoArgument, nullptr,
1398  {}, 0, eArgTypeNone, "Enable rsync."},
1399  {LLDB_OPT_SET_ALL, false, "rsync-opts", 'R',
1401  "Platform-specific options required for rsync to work."},
1402  {LLDB_OPT_SET_ALL, false, "rsync-prefix", 'P',
1404  "Platform-specific rsync prefix put before the remote path."},
1405  {LLDB_OPT_SET_ALL, false, "ignore-remote-hostname", 'i',
1406  OptionParser::eNoArgument, nullptr, {}, 0, eArgTypeNone,
1407  "Do not automatically fill in the remote hostname when composing the "
1408  "rsync command."},
1409 };
1410 
1411 static constexpr OptionDefinition g_ssh_option_table[] = {
1412  {LLDB_OPT_SET_ALL, false, "ssh", 's', OptionParser::eNoArgument, nullptr,
1413  {}, 0, eArgTypeNone, "Enable SSH."},
1414  {LLDB_OPT_SET_ALL, false, "ssh-opts", 'S', OptionParser::eRequiredArgument,
1415  nullptr, {}, 0, eArgTypeCommandName,
1416  "Platform-specific options required for SSH to work."},
1417 };
1418 
1420  {LLDB_OPT_SET_ALL, false, "local-cache-dir", 'c',
1422  "Path in which to store local copies of files."},
1423 };
1424 
1425 llvm::ArrayRef<OptionDefinition> OptionGroupPlatformRSync::GetDefinitions() {
1426  return llvm::makeArrayRef(g_rsync_option_table);
1427 }
1428 
1430  ExecutionContext *execution_context) {
1431  m_rsync = false;
1432  m_rsync_opts.clear();
1433  m_rsync_prefix.clear();
1434  m_ignores_remote_hostname = false;
1435 }
1436 
1439  llvm::StringRef option_arg,
1440  ExecutionContext *execution_context) {
1441  Status error;
1442  char short_option = (char)GetDefinitions()[option_idx].short_option;
1443  switch (short_option) {
1444  case 'r':
1445  m_rsync = true;
1446  break;
1447 
1448  case 'R':
1449  m_rsync_opts.assign(std::string(option_arg));
1450  break;
1451 
1452  case 'P':
1453  m_rsync_prefix.assign(std::string(option_arg));
1454  break;
1455 
1456  case 'i':
1458  break;
1459 
1460  default:
1461  error.SetErrorStringWithFormat("unrecognized option '%c'", short_option);
1462  break;
1463  }
1464 
1465  return error;
1466 }
1467 
1468 lldb::BreakpointSP
1470  return lldb::BreakpointSP();
1471 }
1472 
1473 llvm::ArrayRef<OptionDefinition> OptionGroupPlatformSSH::GetDefinitions() {
1474  return llvm::makeArrayRef(g_ssh_option_table);
1475 }
1476 
1478  ExecutionContext *execution_context) {
1479  m_ssh = false;
1480  m_ssh_opts.clear();
1481 }
1482 
1485  llvm::StringRef option_arg,
1486  ExecutionContext *execution_context) {
1487  Status error;
1488  char short_option = (char)GetDefinitions()[option_idx].short_option;
1489  switch (short_option) {
1490  case 's':
1491  m_ssh = true;
1492  break;
1493 
1494  case 'S':
1495  m_ssh_opts.assign(std::string(option_arg));
1496  break;
1497 
1498  default:
1499  error.SetErrorStringWithFormat("unrecognized option '%c'", short_option);
1500  break;
1501  }
1502 
1503  return error;
1504 }
1505 
1506 llvm::ArrayRef<OptionDefinition> OptionGroupPlatformCaching::GetDefinitions() {
1507  return llvm::makeArrayRef(g_caching_option_table);
1508 }
1509 
1511  ExecutionContext *execution_context) {
1512  m_cache_dir.clear();
1513 }
1514 
1516  uint32_t option_idx, llvm::StringRef option_arg,
1517  ExecutionContext *execution_context) {
1518  Status error;
1519  char short_option = (char)GetDefinitions()[option_idx].short_option;
1520  switch (short_option) {
1521  case 'c':
1522  m_cache_dir.assign(std::string(option_arg));
1523  break;
1524 
1525  default:
1526  error.SetErrorStringWithFormat("unrecognized option '%c'", short_option);
1527  break;
1528  }
1529 
1530  return error;
1531 }
1532 
1534 
1535 const std::vector<ConstString> &Platform::GetTrapHandlerSymbolNames() {
1537  std::lock_guard<std::mutex> guard(m_mutex);
1541  }
1542  }
1543  return m_trap_handlers;
1544 }
1545 
1546 Status
1548  lldb::ModuleSP &module_sp,
1549  const FileSpecList *module_search_paths_ptr) {
1550  FileSpec platform_spec = module_spec.GetFileSpec();
1552  module_spec, nullptr, module_sp,
1553  [&](const ModuleSpec &spec) {
1554  return ResolveRemoteExecutable(spec, module_sp,
1555  module_search_paths_ptr);
1556  },
1557  nullptr);
1558  if (error.Success()) {
1559  module_spec.GetFileSpec() = module_sp->GetFileSpec();
1560  module_spec.GetPlatformFileSpec() = platform_spec;
1561  }
1562 
1563  return error;
1564 }
1565 
1567  Process *process,
1568  lldb::ModuleSP &module_sp,
1569  const ModuleResolver &module_resolver,
1570  bool *did_create_ptr) {
1571  // Get module information from a target.
1572  ModuleSpec resolved_module_spec;
1573  bool got_module_spec = false;
1574  if (process) {
1575  // Try to get module information from the process
1576  if (process->GetModuleSpec(module_spec.GetFileSpec(),
1577  module_spec.GetArchitecture(),
1578  resolved_module_spec)) {
1579  if (!module_spec.GetUUID().IsValid() ||
1580  module_spec.GetUUID() == resolved_module_spec.GetUUID()) {
1581  got_module_spec = true;
1582  }
1583  }
1584  }
1585 
1586  if (!module_spec.GetArchitecture().IsValid()) {
1587  Status error;
1588  // No valid architecture was specified, ask the platform for the
1589  // architectures that we should be using (in the correct order) and see if
1590  // we can find a match that way
1591  ModuleSpec arch_module_spec(module_spec);
1592  for (const ArchSpec &arch : GetSupportedArchitectures()) {
1593  arch_module_spec.GetArchitecture() = arch;
1594  error = ModuleList::GetSharedModule(arch_module_spec, module_sp, nullptr,
1595  nullptr, nullptr);
1596  // Did we find an executable using one of the
1597  if (error.Success() && module_sp)
1598  break;
1599  }
1600  if (module_sp) {
1601  resolved_module_spec = arch_module_spec;
1602  got_module_spec = true;
1603  }
1604  }
1605 
1606  if (!got_module_spec) {
1607  // Get module information from a target.
1608  if (GetModuleSpec(module_spec.GetFileSpec(), module_spec.GetArchitecture(),
1609  resolved_module_spec)) {
1610  if (!module_spec.GetUUID().IsValid() ||
1611  module_spec.GetUUID() == resolved_module_spec.GetUUID()) {
1612  got_module_spec = true;
1613  }
1614  }
1615  }
1616 
1617  if (!got_module_spec) {
1618  // Fall back to the given module resolver, which may have its own
1619  // search logic.
1620  return module_resolver(module_spec);
1621  }
1622 
1623  // If we are looking for a specific UUID, make sure resolved_module_spec has
1624  // the same one before we search.
1625  if (module_spec.GetUUID().IsValid()) {
1626  resolved_module_spec.GetUUID() = module_spec.GetUUID();
1627  }
1628 
1629  // Trying to find a module by UUID on local file system.
1630  const auto error = module_resolver(resolved_module_spec);
1631  if (error.Fail()) {
1632  if (GetCachedSharedModule(resolved_module_spec, module_sp, did_create_ptr))
1633  return Status();
1634  }
1635 
1636  return error;
1637 }
1638 
1640  lldb::ModuleSP &module_sp,
1641  bool *did_create_ptr) {
1642  if (IsHost() || !GetGlobalPlatformProperties().GetUseModuleCache() ||
1643  !GetGlobalPlatformProperties().GetModuleCacheDirectory())
1644  return false;
1645 
1647 
1648  // Check local cache for a module.
1649  auto error = m_module_cache->GetAndPut(
1650  GetModuleCacheRoot(), GetCacheHostname(), module_spec,
1651  [this](const ModuleSpec &module_spec,
1652  const FileSpec &tmp_download_file_spec) {
1653  return DownloadModuleSlice(
1654  module_spec.GetFileSpec(), module_spec.GetObjectOffset(),
1655  module_spec.GetObjectSize(), tmp_download_file_spec);
1656 
1657  },
1658  [this](const ModuleSP &module_sp,
1659  const FileSpec &tmp_download_file_spec) {
1660  return DownloadSymbolFile(module_sp, tmp_download_file_spec);
1661  },
1662  module_sp, did_create_ptr);
1663  if (error.Success())
1664  return true;
1665 
1666  LLDB_LOGF(log, "Platform::%s - module %s not found in local cache: %s",
1667  __FUNCTION__, module_spec.GetUUID().GetAsString().c_str(),
1668  error.AsCString());
1669  return false;
1670 }
1671 
1673  const uint64_t src_offset,
1674  const uint64_t src_size,
1675  const FileSpec &dst_file_spec) {
1676  Status error;
1677 
1678  std::error_code EC;
1679  llvm::raw_fd_ostream dst(dst_file_spec.GetPath(), EC, llvm::sys::fs::OF_None);
1680  if (EC) {
1681  error.SetErrorStringWithFormat("unable to open destination file: %s",
1682  dst_file_spec.GetPath().c_str());
1683  return error;
1684  }
1685 
1686  auto src_fd = OpenFile(src_file_spec, File::eOpenOptionReadOnly,
1687  lldb::eFilePermissionsFileDefault, error);
1688 
1689  if (error.Fail()) {
1690  error.SetErrorStringWithFormat("unable to open source file: %s",
1691  error.AsCString());
1692  return error;
1693  }
1694 
1695  std::vector<char> buffer(1024);
1696  auto offset = src_offset;
1697  uint64_t total_bytes_read = 0;
1698  while (total_bytes_read < src_size) {
1699  const auto to_read = std::min(static_cast<uint64_t>(buffer.size()),
1700  src_size - total_bytes_read);
1701  const uint64_t n_read =
1702  ReadFile(src_fd, offset, &buffer[0], to_read, error);
1703  if (error.Fail())
1704  break;
1705  if (n_read == 0) {
1706  error.SetErrorString("read 0 bytes");
1707  break;
1708  }
1709  offset += n_read;
1710  total_bytes_read += n_read;
1711  dst.write(&buffer[0], n_read);
1712  }
1713 
1714  Status close_error;
1715  CloseFile(src_fd, close_error); // Ignoring close error.
1716 
1717  return error;
1718 }
1719 
1720 Status Platform::DownloadSymbolFile(const lldb::ModuleSP &module_sp,
1721  const FileSpec &dst_file_spec) {
1722  return Status(
1723  "Symbol file downloading not supported by the default platform.");
1724 }
1725 
1728  dir_spec.AppendPathComponent(GetName().AsCString());
1729  return dir_spec;
1730 }
1731 
1732 const char *Platform::GetCacheHostname() { return GetHostname(); }
1733 
1734 const UnixSignalsSP &Platform::GetRemoteUnixSignals() {
1735  static const auto s_default_unix_signals_sp = std::make_shared<UnixSignals>();
1736  return s_default_unix_signals_sp;
1737 }
1738 
1739 UnixSignalsSP Platform::GetUnixSignals() {
1740  if (IsHost())
1741  return UnixSignals::CreateForHost();
1742  return GetRemoteUnixSignals();
1743 }
1744 
1746  const lldb_private::FileSpec &local_file,
1747  const lldb_private::FileSpec &remote_file,
1749  if (local_file && remote_file) {
1750  // Both local and remote file was specified. Install the local file to the
1751  // given location.
1752  if (IsRemote() || local_file != remote_file) {
1753  error = Install(local_file, remote_file);
1754  if (error.Fail())
1755  return LLDB_INVALID_IMAGE_TOKEN;
1756  }
1757  return DoLoadImage(process, remote_file, nullptr, error);
1758  }
1759 
1760  if (local_file) {
1761  // Only local file was specified. Install it to the current working
1762  // directory.
1763  FileSpec target_file = GetWorkingDirectory();
1764  target_file.AppendPathComponent(local_file.GetFilename().AsCString());
1765  if (IsRemote() || local_file != target_file) {
1766  error = Install(local_file, target_file);
1767  if (error.Fail())
1768  return LLDB_INVALID_IMAGE_TOKEN;
1769  }
1770  return DoLoadImage(process, target_file, nullptr, error);
1771  }
1772 
1773  if (remote_file) {
1774  // Only remote file was specified so we don't have to do any copying
1775  return DoLoadImage(process, remote_file, nullptr, error);
1776  }
1777 
1778  error.SetErrorString("Neither local nor remote file was specified");
1779  return LLDB_INVALID_IMAGE_TOKEN;
1780 }
1781 
1783  const lldb_private::FileSpec &remote_file,
1784  const std::vector<std::string> *paths,
1786  lldb_private::FileSpec *loaded_image) {
1787  error.SetErrorString("LoadImage is not supported on the current platform");
1788  return LLDB_INVALID_IMAGE_TOKEN;
1789 }
1790 
1792  const lldb_private::FileSpec &remote_filename,
1793  const std::vector<std::string> &paths,
1795  lldb_private::FileSpec *loaded_path)
1796 {
1797  FileSpec file_to_use;
1798  if (remote_filename.IsAbsolute())
1799  file_to_use = FileSpec(remote_filename.GetFilename().GetStringRef(),
1800 
1801  remote_filename.GetPathStyle());
1802  else
1803  file_to_use = remote_filename;
1804 
1805  return DoLoadImage(process, file_to_use, &paths, error, loaded_path);
1806 }
1807 
1809  uint32_t image_token) {
1810  return Status("UnloadImage is not supported on the current platform");
1811 }
1812 
1813 lldb::ProcessSP Platform::ConnectProcess(llvm::StringRef connect_url,
1814  llvm::StringRef plugin_name,
1815  Debugger &debugger, Target *target,
1816  Status &error) {
1817  return DoConnectProcess(connect_url, plugin_name, debugger, nullptr, target,
1818  error);
1819 }
1820 
1822  llvm::StringRef connect_url, llvm::StringRef plugin_name,
1823  Debugger &debugger, Stream &stream, Target *target, Status &error) {
1824  return DoConnectProcess(connect_url, plugin_name, debugger, &stream, target,
1825  error);
1826 }
1827 
1828 lldb::ProcessSP Platform::DoConnectProcess(llvm::StringRef connect_url,
1829  llvm::StringRef plugin_name,
1830  Debugger &debugger, Stream *stream,
1831  Target *target, Status &error) {
1832  error.Clear();
1833 
1834  if (!target) {
1835  ArchSpec arch;
1836  if (target && target->GetArchitecture().IsValid())
1837  arch = target->GetArchitecture();
1838  else
1840 
1841  const char *triple = "";
1842  if (arch.IsValid())
1843  triple = arch.GetTriple().getTriple().c_str();
1844 
1845  TargetSP new_target_sp;
1846  error = debugger.GetTargetList().CreateTarget(
1847  debugger, "", triple, eLoadDependentsNo, nullptr, new_target_sp);
1848  target = new_target_sp.get();
1849  }
1850 
1851  if (!target || error.Fail())
1852  return nullptr;
1853 
1854  lldb::ProcessSP process_sp =
1855  target->CreateProcess(debugger.GetListener(), plugin_name, nullptr, true);
1856 
1857  if (!process_sp)
1858  return nullptr;
1859 
1860  // If this private method is called with a stream we are synchronous.
1861  const bool synchronous = stream != nullptr;
1862 
1863  ListenerSP listener_sp(
1864  Listener::MakeListener("lldb.Process.ConnectProcess.hijack"));
1865  if (synchronous)
1866  process_sp->HijackProcessEvents(listener_sp);
1867 
1868  error = process_sp->ConnectRemote(connect_url);
1869  if (error.Fail()) {
1870  if (synchronous)
1871  process_sp->RestoreProcessEvents();
1872  return nullptr;
1873  }
1874 
1875  if (synchronous) {
1876  EventSP event_sp;
1877  process_sp->WaitForProcessToStop(llvm::None, &event_sp, true, listener_sp,
1878  nullptr);
1879  process_sp->RestoreProcessEvents();
1880  bool pop_process_io_handler = false;
1881  Process::HandleProcessStateChangedEvent(event_sp, stream,
1882  pop_process_io_handler);
1883  }
1884 
1885  return process_sp;
1886 }
1887 
1890  error.Clear();
1891  return 0;
1892 }
1893 
1895  BreakpointSite *bp_site) {
1896  ArchSpec arch = target.GetArchitecture();
1897  assert(arch.IsValid());
1898  const uint8_t *trap_opcode = nullptr;
1899  size_t trap_opcode_size = 0;
1900 
1901  switch (arch.GetMachine()) {
1902  case llvm::Triple::aarch64_32:
1903  case llvm::Triple::aarch64: {
1904  static const uint8_t g_aarch64_opcode[] = {0x00, 0x00, 0x20, 0xd4};
1905  trap_opcode = g_aarch64_opcode;
1906  trap_opcode_size = sizeof(g_aarch64_opcode);
1907  } break;
1908 
1909  case llvm::Triple::arc: {
1910  static const uint8_t g_hex_opcode[] = { 0xff, 0x7f };
1911  trap_opcode = g_hex_opcode;
1912  trap_opcode_size = sizeof(g_hex_opcode);
1913  } break;
1914 
1915  // TODO: support big-endian arm and thumb trap codes.
1916  case llvm::Triple::arm: {
1917  // The ARM reference recommends the use of 0xe7fddefe and 0xdefe but the
1918  // linux kernel does otherwise.
1919  static const uint8_t g_arm_breakpoint_opcode[] = {0xf0, 0x01, 0xf0, 0xe7};
1920  static const uint8_t g_thumb_breakpoint_opcode[] = {0x01, 0xde};
1921 
1922  lldb::BreakpointLocationSP bp_loc_sp(bp_site->GetOwnerAtIndex(0));
1923  AddressClass addr_class = AddressClass::eUnknown;
1924 
1925  if (bp_loc_sp) {
1926  addr_class = bp_loc_sp->GetAddress().GetAddressClass();
1927  if (addr_class == AddressClass::eUnknown &&
1928  (bp_loc_sp->GetAddress().GetFileAddress() & 1))
1929  addr_class = AddressClass::eCodeAlternateISA;
1930  }
1931 
1932  if (addr_class == AddressClass::eCodeAlternateISA) {
1933  trap_opcode = g_thumb_breakpoint_opcode;
1934  trap_opcode_size = sizeof(g_thumb_breakpoint_opcode);
1935  } else {
1936  trap_opcode = g_arm_breakpoint_opcode;
1937  trap_opcode_size = sizeof(g_arm_breakpoint_opcode);
1938  }
1939  } break;
1940 
1941  case llvm::Triple::avr: {
1942  static const uint8_t g_hex_opcode[] = {0x98, 0x95};
1943  trap_opcode = g_hex_opcode;
1944  trap_opcode_size = sizeof(g_hex_opcode);
1945  } break;
1946 
1947  case llvm::Triple::mips:
1948  case llvm::Triple::mips64: {
1949  static const uint8_t g_hex_opcode[] = {0x00, 0x00, 0x00, 0x0d};
1950  trap_opcode = g_hex_opcode;
1951  trap_opcode_size = sizeof(g_hex_opcode);
1952  } break;
1953 
1954  case llvm::Triple::mipsel:
1955  case llvm::Triple::mips64el: {
1956  static const uint8_t g_hex_opcode[] = {0x0d, 0x00, 0x00, 0x00};
1957  trap_opcode = g_hex_opcode;
1958  trap_opcode_size = sizeof(g_hex_opcode);
1959  } break;
1960 
1961  case llvm::Triple::systemz: {
1962  static const uint8_t g_hex_opcode[] = {0x00, 0x01};
1963  trap_opcode = g_hex_opcode;
1964  trap_opcode_size = sizeof(g_hex_opcode);
1965  } break;
1966 
1967  case llvm::Triple::hexagon: {
1968  static const uint8_t g_hex_opcode[] = {0x0c, 0xdb, 0x00, 0x54};
1969  trap_opcode = g_hex_opcode;
1970  trap_opcode_size = sizeof(g_hex_opcode);
1971  } break;
1972 
1973  case llvm::Triple::ppc:
1974  case llvm::Triple::ppc64: {
1975  static const uint8_t g_ppc_opcode[] = {0x7f, 0xe0, 0x00, 0x08};
1976  trap_opcode = g_ppc_opcode;
1977  trap_opcode_size = sizeof(g_ppc_opcode);
1978  } break;
1979 
1980  case llvm::Triple::ppc64le: {
1981  static const uint8_t g_ppc64le_opcode[] = {0x08, 0x00, 0xe0, 0x7f}; // trap
1982  trap_opcode = g_ppc64le_opcode;
1983  trap_opcode_size = sizeof(g_ppc64le_opcode);
1984  } break;
1985 
1986  case llvm::Triple::x86:
1987  case llvm::Triple::x86_64: {
1988  static const uint8_t g_i386_opcode[] = {0xCC};
1989  trap_opcode = g_i386_opcode;
1990  trap_opcode_size = sizeof(g_i386_opcode);
1991  } break;
1992 
1993  default:
1994  return 0;
1995  }
1996 
1997  assert(bp_site);
1998  if (bp_site->SetTrapOpcode(trap_opcode, trap_opcode_size))
1999  return trap_opcode_size;
2000 
2001  return 0;
2002 }
lldb_private::Platform::GetRemoteSystemArchitecture
virtual ArchSpec GetRemoteSystemArchitecture()
Definition: Platform.h:252
lldb_private::Stream::Format
void Format(const char *format, Args &&... args)
Definition: Stream.h:309
lldb_private::ProcessInstanceInfo
Definition: ProcessInfo.h:108
lldb_private::UUID
Definition: UUID.h:23
lldb_private::Host::ResolveExecutableInBundle
static bool ResolveExecutableInBundle(FileSpec &file)
When executable files may live within a directory, where the directory represents an executable bundl...
Definition: common/Host.cpp:417
lldb_private::FileSystem::Open
int Open(const char *path, int flags, int mode)
Wraps ::open in a platform-independent way.
Definition: FileSystemPosix.cpp:79
lldb_private::Platform::ResolveExecutable
virtual Status ResolveExecutable(const ModuleSpec &module_spec, lldb::ModuleSP &module_sp, const FileSpecList *module_search_paths_ptr)
Find a platform plugin for a given process.
Definition: Platform.cpp:832
lldb_private::ExecutionContext
Definition: ExecutionContext.h:292
lldb_private::Host::FindProcesses
static uint32_t FindProcesses(const ProcessInstanceInfoMatch &match_info, ProcessInstanceInfoList &proc_infos)
Definition: common/Host.cpp:705
lldb_private::FileSpec::GetLastPathComponent
ConstString GetLastPathComponent() const
Definition: FileSpec.cpp:413
RecurseCopyBaton::error
Status error
Definition: Platform.cpp:529
lldb_private::ArchSpec
Definition: ArchSpec.h:33
GetPlatformListMutex
static std::recursive_mutex & GetPlatformListMutex()
Definition: Platform.cpp:142
lldb_private::PlatformProperties::GetModuleCacheDirectory
FileSpec GetModuleCacheDirectory() const
Definition: Platform.cpp:109
lldb_private::Host::LaunchProcess
static Status LaunchProcess(ProcessLaunchInfo &launch_info)
Launch the process specified in launch_info.
Definition: common/Host.cpp:616
lldb_private::MmapArgList
llvm::SmallVector< lldb::addr_t, 6 > MmapArgList
Definition: Platform.h:58
lldb_private::ModuleSpec::GetPlatformFileSpec
FileSpec & GetPlatformFileSpec()
Definition: ModuleSpec.h:70
FileSystem.h
lldb_private::Platform::WriteFile
virtual uint64_t WriteFile(lldb::user_id_t fd, uint64_t offset, const void *src, uint64_t src_len, Status &error)
Definition: Platform.h:517
lldb_private::Platform::GetEnvironment
virtual Environment GetEnvironment()
Definition: Platform.cpp:1533
MAP_PRIVATE
#define MAP_PRIVATE
Definition: Platform.cpp:45
lldb_private::Platform::GetRemoteSharedModule
Status GetRemoteSharedModule(const ModuleSpec &module_spec, Process *process, lldb::ModuleSP &module_sp, const ModuleResolver &module_resolver, bool *did_create_ptr)
Definition: Platform.cpp:1566
LLDB_INVALID_PROCESS_ID
#define LLDB_INVALID_PROCESS_ID
Definition: lldb-defines.h:93
g_rsync_option_table
static constexpr OptionDefinition g_rsync_option_table[]
Definition: Platform.cpp:1396
lldb_private::ArchSpec::GetMachine
llvm::Triple::ArchType GetMachine() const
Returns a machine family for the current architecture.
Definition: ArchSpec.cpp:667
lldb_private::Platform::CalculateTrapHandlerSymbolNames
virtual void CalculateTrapHandlerSymbolNames()=0
Ask the Platform subclass to fill in the list of trap handler names.
ModuleSpec.h
lldb_private::Platform::LoadImage
uint32_t LoadImage(lldb_private::Process *process, const lldb_private::FileSpec &local_file, const lldb_private::FileSpec &remote_file, lldb_private::Status &error)
Load a shared library into this process.
Definition: Platform.cpp:1745
lldb_private::Value
Definition: Value.h:38
lldb_private::AddressClass
AddressClass
Definition: lldb-private-enumerations.h:48
lldb_private::Platform::SetLocalCacheDirectory
virtual void SetLocalCacheDirectory(const char *local)
Definition: Platform.cpp:1388
StructuredData.h
g_ssh_option_table
static constexpr OptionDefinition g_ssh_option_table[]
Definition: Platform.cpp:1411
Host.h
lldb_private::Platform::ConnectRemote
virtual Status ConnectRemote(Args &args)
Definition: Platform.cpp:1008
lldb_private::Platform::PutFile
virtual Status PutFile(const FileSpec &source, const FileSpec &destination, uint32_t uid=UINT32_MAX, uint32_t gid=UINT32_MAX)
Definition: Platform.cpp:1248
lldb_private::OptionGroupPlatformSSH::m_ssh
bool m_ssh
Definition: Platform.h:1070
lldb_private::Platform::UnloadImage
virtual Status UnloadImage(lldb_private::Process *process, uint32_t image_token)
Definition: Platform.cpp:1808
lldb_private::Platform::GetGlobalPlatformProperties
static PlatformProperties & GetGlobalPlatformProperties()
Definition: Platform.cpp:158
lldb_private::OptionParser::eNoArgument
@ eNoArgument
Definition: OptionParser.h:35
lldb_private::Platform::GetMmapArgumentList
virtual MmapArgList GetMmapArgumentList(const ArchSpec &arch, lldb::addr_t addr, lldb::addr_t length, unsigned prot, unsigned flags, lldb::addr_t fd, lldb::addr_t offset)
Definition: Platform.cpp:1330
lldb_private::UUID::IsValid
bool IsValid() const
Definition: UUID.h:79
lldb_private::Platform::MakeDirectory
virtual Status MakeDirectory(const FileSpec &file_spec, uint32_t permissions)
Definition: Platform.cpp:746
RecurseCopy_Callback
static FileSystem::EnumerateDirectoryResult RecurseCopy_Callback(void *baton, llvm::sys::fs::file_type ft, llvm::StringRef path)
Definition: Platform.cpp:533
lldb_private::Platform::GetModuleSpec
virtual bool GetModuleSpec(const FileSpec &module_file_spec, const ArchSpec &arch, ModuleSpec &module_spec)
Definition: Platform.cpp:262
lldb_private::ModuleSpecList
Definition: ModuleSpec.h:280
lldb_private::Platform::Install
virtual Status Install(const FileSpec &src, const FileSpec &dst)
Install a file or directory to the remote system.
Definition: Platform.cpp:620
lldb_private::Platform::DisconnectRemote
virtual Status DisconnectRemote()
Definition: Platform.cpp:1021
LLDB_LOGF
#define LLDB_LOGF(log,...)
Definition: Log.h:249
lldb_private::Process
Definition: Process.h:341
lldb_private::Platform::SetWorkingDirectory
bool SetWorkingDirectory(const FileSpec &working_dir)
Definition: Platform.cpp:731
lldb_private::ArchSpec::ContainsOnlyArch
static bool ContainsOnlyArch(const llvm::Triple &normalized_triple)
Returns true if the OS, vendor and environment fields of the triple are unset.
Definition: ArchSpec.cpp:794
lldb_private::Platform::GetRemoteOSBuildString
virtual llvm::Optional< std::string > GetRemoteOSBuildString()
Definition: Platform.h:243
lldb_private::Platform::GetLocalCacheDirectory
virtual const char * GetLocalCacheDirectory()
Definition: Platform.cpp:1392
Module.h
lldb_private::BreakpointSite::GetOwnerAtIndex
lldb::BreakpointLocationSP GetOwnerAtIndex(size_t idx)
This method returns the breakpoint location at index index located at this breakpoint site.
Definition: BreakpointSite.cpp:142
lldb_private::FileSpec::GetPathStyle
Style GetPathStyle() const
Definition: FileSpec.cpp:330
BreakpointLocation.h
lldb::eArgTypeCommandName
@ eArgTypeCommandName
Definition: lldb-enumerations.h:527
LIBLLDB_LOG_PLATFORM
#define LIBLLDB_LOG_PLATFORM
Definition: Logging.h:39
lldb_private::OptionGroupPlatformRSync::m_rsync_prefix
std::string m_rsync_prefix
Definition: Platform.h:1045
lldb_private::Platform::GetName
ConstString GetName()
Definition: Platform.cpp:786
lldb_private::ProcessInstanceInfoMatch
Definition: ProcessInfo.h:163
lldb_private::Platform::m_os_version
llvm::VersionTuple m_os_version
Definition: Platform.h:894
lldb_private::ConstString::SetCString
void SetCString(const char *cstr)
Set the C string value.
Definition: ConstString.cpp:302
lldb_private::Module
Definition: Module.h:85
lldb_private::Platform::KillProcess
virtual Status KillProcess(const lldb::pid_t pid)
Kill process on a platform.
Definition: Platform.cpp:1108
lldb_private::ProcessInfo::GetProcessID
lldb::pid_t GetProcessID() const
Definition: ProcessInfo.h:67
lldb_private::ConstString::AsCString
const char * AsCString(const char *value_if_empty=nullptr) const
Get the string value as a C string.
Definition: ConstString.h:193
lldb_private::OptionGroupPlatformSSH::m_ssh_opts
std::string m_ssh_opts
Definition: Platform.h:1071
lldb_private::Platform::SetThreadCreationBreakpoint
virtual lldb::BreakpointSP SetThreadCreationBreakpoint(Target &target)
Definition: Platform.cpp:1469
lldb_private::Platform::m_trap_handlers
std::vector< ConstString > m_trap_handlers
Definition: Platform.h:910
lldb_private::Flags::Test
bool Test(ValueType bit) const
Test a single flag bit.
Definition: Flags.h:96
RecurseCopyBaton
Definition: Platform.cpp:526
lldb_private::ProcessLaunchInfo::GetFlags
Flags & GetFlags()
Definition: ProcessLaunchInfo.h:64
lldb_private::Platform::~Platform
~Platform() override
The destructor is virtual since this class is designed to be inherited from by the plug-in instance.
g_caching_option_table
static constexpr OptionDefinition g_caching_option_table[]
Definition: Platform.cpp:1419
lldb_private::Stream
Definition: Stream.h:28
lldb_private::Args
Definition: Args.h:33
lldb_private::ArchSpec::GetTriple
llvm::Triple & GetTriple()
Architecture triple accessor.
Definition: ArchSpec.h:444
lldb::addr_t
uint64_t addr_t
Definition: lldb-types.h:83
lldb_private::Platform::IsCompatibleArchitecture
virtual bool IsCompatibleArchitecture(const ArchSpec &arch, bool exact_arch_match, ArchSpec *compatible_arch_ptr)
Lets a platform answer if it is compatible with a given architecture and the target triple contained ...
Definition: Platform.cpp:1227
lldb_private::Platform::GetModuleCacheRoot
FileSpec GetModuleCacheRoot()
Definition: Platform.cpp:1726
lldb_private::Platform::GetOSKernelDescription
llvm::Optional< std::string > GetOSKernelDescription()
Definition: Platform.cpp:494
lldb_private::Platform::DebugProcess
virtual lldb::ProcessSP DebugProcess(ProcessLaunchInfo &launch_info, Debugger &debugger, Target &target, Status &error)
Subclasses do not need to implement this function as it uses the Platform::LaunchProcess() followed b...
Definition: Platform.cpp:1120
lldb_private::Platform::SetFilePermissions
virtual Status SetFilePermissions(const FileSpec &file_spec, uint32_t file_permissions)
Definition: Platform.cpp:773
Debugger.h
lldb_private::Target
Definition: Target.h:451
lldb_private::ProcessLaunchInfo::SetHijackListener
void SetHijackListener(const lldb::ListenerSP &listener_sp)
Definition: ProcessLaunchInfo.h:136
lldb_private::Debugger::GetListener
lldb::ListenerSP GetListener()
Definition: Debugger.h:208
lldb::eArgTypePath
@ eArgTypePath
Definition: lldb-enumerations.h:558
lldb_private::Target::CreateProcess
const lldb::ProcessSP & CreateProcess(lldb::ListenerSP listener_sp, llvm::StringRef plugin_name, const FileSpec *crash_file, bool can_connect)
Definition: Target.cpp:199
lldb_private::PluginInterface::GetPluginName
virtual llvm::StringRef GetPluginName()=0
lldb_private::PseudoTerminal::invalid_fd
@ invalid_fd
Invalid file descriptor value.
Definition: PseudoTerminal.h:27
lldb_private::Platform::GetFilePermissions
virtual Status GetFilePermissions(const FileSpec &file_spec, uint32_t &file_permissions)
Definition: Platform.cpp:758
lldb_private::UUID::GetAsString
std::string GetAsString(llvm::StringRef separator="-") const
Definition: UUID.cpp:48
lldb_private::AddressClass::eUnknown
@ eUnknown
lldb_private::Platform::LoadImageUsingPaths
uint32_t LoadImageUsingPaths(lldb_private::Process *process, const lldb_private::FileSpec &library_name, const std::vector< std::string > &paths, lldb_private::Status &error, lldb_private::FileSpec *loaded_path)
Load a shared library specified by base name into this process, looking by hand along a set of paths.
Definition: Platform.cpp:1791
lldb_private::Platform::m_mutex
std::mutex m_mutex
Definition: Platform.h:900
lldb_private::ModuleSpec::GetSymbolFileSpec
FileSpec & GetSymbolFileSpec()
Definition: ModuleSpec.h:82
lldb_private::FileSpec::PrependPathComponent
void PrependPathComponent(llvm::StringRef component)
Definition: FileSpec.cpp:419
Process.h
lldb_private::Platform::ReadFile
virtual uint64_t ReadFile(lldb::user_id_t fd, uint64_t offset, void *dst, uint64_t dst_len, Status &error)
Definition: Platform.h:509
lldb_private::Platform::RunShellCommand
virtual lldb_private::Status RunShellCommand(llvm::StringRef command, const FileSpec &working_dir, int *status_ptr, int *signo_ptr, std::string *command_output, const Timeout< std::micro > &timeout)
Definition: Platform.cpp:1344
lldb_private::FileSpec::GetCString
const char * GetCString(bool denormalize=true) const
Definition: FileSpec.cpp:362
lldb_private::ArchSpec::IsCompatibleMatch
bool IsCompatibleMatch(const ArchSpec &rhs) const
Compare an ArchSpec to another ArchSpec, requiring a compatible cpu type match between them.
Definition: ArchSpec.cpp:934
Target.h
lldb_private::ModuleSpec::GetUUID
UUID & GetUUID()
Definition: ModuleSpec.h:104
lldb_private::ArchSpec::DumpTriple
void DumpTriple(llvm::raw_ostream &s) const
Definition: ArchSpec.cpp:1461
lldb_private::Process::HandleProcessStateChangedEvent
static bool HandleProcessStateChangedEvent(const lldb::EventSP &event_sp, Stream *stream, bool &pop_process_io_handler)
Centralize the code that handles and prints descriptions for process state changes.
Definition: Process.cpp:713
lldb_private::Platform::OpenFile
virtual lldb::user_id_t OpenFile(const FileSpec &file_spec, File::OpenOptions flags, uint32_t mode, Status &error)
Definition: Platform.h:494
lldb_private::OptionGroupPlatformSSH::SetOptionValue
lldb_private::Status SetOptionValue(uint32_t option_idx, llvm::StringRef option_value, ExecutionContext *execution_context) override
Definition: Platform.cpp:1484
lldb_private::OptionGroupPlatformSSH::GetDefinitions
llvm::ArrayRef< OptionDefinition > GetDefinitions() override
Definition: Platform.cpp:1473
lldb_private::File::eOpenOptionTruncate
@ eOpenOptionTruncate
Definition: File.h:56
lldb_private::Platform::GetSystemArchitecture
const ArchSpec & GetSystemArchitecture()
Definition: Platform.cpp:946
lldb_private::File::eOpenOptionCanCreate
@ eOpenOptionCanCreate
Definition: File.h:55
Platform.h
lldb_private::FileSpec
Definition: FileSpec.h:56
lldb_private::File::eOpenOptionCloseOnExec
@ eOpenOptionCloseOnExec
Definition: File.h:62
error
static llvm::raw_ostream & error(Stream &strm)
Definition: CommandReturnObject.cpp:17
lldb_private::OptionGroupPlatformRSync::m_rsync
bool m_rsync
Definition: Platform.h:1043
lldb_private::OptionGroupPlatformCaching::GetDefinitions
llvm::ArrayRef< OptionDefinition > GetDefinitions() override
Definition: Platform.cpp:1506
lldb_private::Platform::m_local_cache_directory
std::string m_local_cache_directory
Definition: Platform.h:909
lldb_private::BreakpointSite
Definition: BreakpointSite.h:35
SIGKILL
#define SIGKILL
Definition: windows/PosixApi.h:31
lldb_private::ProcessLaunchInfo
Definition: ProcessLaunchInfo.h:31
lldb_private::Platform::GetResumeCountForLaunchInfo
virtual uint32_t GetResumeCountForLaunchInfo(ProcessLaunchInfo &launch_info)
Definition: Platform.h:634
lldb_private::ConstString::GetStringRef
llvm::StringRef GetStringRef() const
Get the string value as a llvm::StringRef.
Definition: ConstString.h:202
lldb_private::Platform::GetRemoteOSKernelDescription
virtual llvm::Optional< std::string > GetRemoteOSKernelDescription()
Definition: Platform.h:247
lldb_private::Platform::AddClangModuleCompilationOptions
virtual void AddClangModuleCompilationOptions(Target *target, std::vector< std::string > &options)
Definition: Platform.cpp:500
g_initialize_count
static uint32_t g_initialize_count
Definition: Platform.cpp:51
Log.h
lldb_private::Platform::GetRemoteWorkingDirectory
virtual FileSpec GetRemoteWorkingDirectory()
Definition: Platform.h:256
lldb_private::eLoadDependentsNo
@ eLoadDependentsNo
Definition: Target.h:64
lldb_private::Platform::CreateSymlink
virtual Status CreateSymlink(const FileSpec &src, const FileSpec &dst)
Definition: Platform.cpp:1314
lldb_private::OptionGroupPlatformRSync::GetDefinitions
llvm::ArrayRef< OptionDefinition > GetDefinitions() override
Definition: Platform.cpp:1425
lldb_private::Platform::GetOSBuildString
llvm::Optional< std::string > GetOSBuildString()
Definition: Platform.cpp:488
UnixSignals.h
lldb_private::Host::RunShellCommand
static Status RunShellCommand(llvm::StringRef command, const FileSpec &working_dir, int *status_ptr, int *signo_ptr, std::string *command_output, const Timeout< std::micro > &timeout, bool run_in_shell=true, bool hide_stderr=false)
Run a shell command.
Definition: common/Host.cpp:468
lldb_private::Status::Fail
bool Fail() const
Test for error condition.
Definition: Status.cpp:182
lldb_private::StreamString::GetData
const char * GetData() const
Definition: StreamString.h:43
lldb_private::Platform::ConnectToWaitingProcesses
virtual size_t ConnectToWaitingProcesses(lldb_private::Debugger &debugger, lldb_private::Status &error)
Connect to all processes waiting for a debugger to attach.
Definition: Platform.cpp:1888
lldb_private::Platform::SetRemoteWorkingDirectory
virtual bool SetRemoteWorkingDirectory(const FileSpec &working_dir)
Definition: Platform.cpp:801
lldb_private::Status::SetErrorStringWithFormat
int SetErrorStringWithFormat(const char *format,...) __attribute__((format(printf
Set the current error string to a formatted error string.
Definition: Status.cpp:256
lldb_private::UnixSignals::CreateForHost
static lldb::UnixSignalsSP CreateForHost()
Definition: UnixSignals.cpp:54
lldb_private::OptionGroupPlatformCaching::OptionParsingStarting
void OptionParsingStarting(ExecutionContext *execution_context) override
Definition: Platform.cpp:1510
LLDB_OPT_SET_ALL
#define LLDB_OPT_SET_ALL
Definition: lldb-defines.h:112
lldb_private::FileSystem::EnumerateDirectoryResult
EnumerateDirectoryResult
Definition: FileSystem.h:162
Property.h
lldb_private::ConstString
Definition: ConstString.h:40
lldb_private::Platform::GetSoftwareBreakpointTrapOpcode
virtual size_t GetSoftwareBreakpointTrapOpcode(Target &target, BreakpointSite *bp_site)
Definition: Platform.cpp:1894
lldb_private::Platform::GetPlatformSpecificConnectionInformation
virtual std::string GetPlatformSpecificConnectionInformation()
Definition: Platform.h:629
lldb_private::StreamString
Definition: StreamString.h:23
lldb_private::Platform::CalculateMD5
virtual bool CalculateMD5(const FileSpec &file_spec, uint64_t &low, uint64_t &high)
Definition: Platform.cpp:1377
lldb_private::Platform::GetSupportsRSync
virtual bool GetSupportsRSync()
Definition: Platform.h:570
lldb_private::GetLogIfAllCategoriesSet
Log * GetLogIfAllCategoriesSet(uint32_t mask)
Definition: Logging.cpp:58
lldb_private::Platform::m_working_dir
FileSpec m_working_dir
Definition: Platform.h:890
lldb_private::TargetList::CreateTarget
Status CreateTarget(Debugger &debugger, llvm::StringRef user_exe_path, llvm::StringRef triple_str, LoadDependentFiles get_dependent_modules, const OptionGroupPlatform *platform_options, lldb::TargetSP &target_sp)
Create a new Target.
lldb_private::OptionGroupPlatformCaching::m_cache_dir
std::string m_cache_dir
Definition: Platform.h:1095
lldb_private::OptionGroupPlatformRSync::SetOptionValue
lldb_private::Status SetOptionValue(uint32_t option_idx, llvm::StringRef option_value, ExecutionContext *execution_context) override
Definition: Platform.cpp:1438
lldb_private::Platform::GetCachedSharedModule
bool GetCachedSharedModule(const ModuleSpec &module_spec, lldb::ModuleSP &module_sp, bool *did_create_ptr)
Definition: Platform.cpp:1639
lldb_private::FileSystem::eEnumerateDirectoryResultQuit
@ eEnumerateDirectoryResultQuit
Stop directory enumerations at any level.
Definition: FileSystem.h:169
lldb_private::OptionGroupPlatformRSync::OptionParsingStarting
void OptionParsingStarting(ExecutionContext *execution_context) override
Definition: Platform.cpp:1429
lldb::eErrorTypeGeneric
@ eErrorTypeGeneric
Generic errors that can be any value.
Definition: lldb-enumerations.h:308
lldb_private::File::eOpenOptionReadOnly
@ eOpenOptionReadOnly
Definition: File.h:50
lldb_private::Debugger
Definition: Debugger.h:70
ModuleCache.h
HostInfo.h
MAP_ANON
#define MAP_ANON
Definition: Platform.cpp:46
string
string(SUBSTRING ${p} 10 -1 pStripped) if($
Definition: Plugins/CMakeLists.txt:40
lldb_private::FileSystem::Resolve
void Resolve(llvm::SmallVectorImpl< char > &path)
Resolve path to make it canonical.
Definition: common/FileSystem.cpp:255
lldb_private::ArchSpec::IsValid
bool IsValid() const
Tests if this ArchSpec is valid.
Definition: ArchSpec.h:342
lldb_private::ModuleSpecList::FindMatchingModuleSpec
bool FindMatchingModuleSpec(const ModuleSpec &module_spec, ModuleSpec &match_module_spec) const
Definition: ModuleSpec.h:338
lldb_private::Platform::DownloadSymbolFile
virtual Status DownloadSymbolFile(const lldb::ModuleSP &module_sp, const FileSpec &dst_file_spec)
Definition: Platform.cpp:1720
lldb_private::Host::ShellExpandArguments
static Status ShellExpandArguments(ProcessLaunchInfo &launch_info)
Perform expansion of the command-line for this launch info This can potentially involve wildcard expa...
Definition: freebsd/Host.cpp:246
lldb_private::OptionGroupPlatformCaching::SetOptionValue
lldb_private::Status SetOptionValue(uint32_t option_idx, llvm::StringRef option_value, ExecutionContext *execution_context) override
Definition: Platform.cpp:1515
lldb_private::Platform::GetRemoteUnixSignals
virtual const lldb::UnixSignalsSP & GetRemoteUnixSignals()
Definition: Platform.cpp:1734
lldb_private::OptionGroupPlatformRSync::m_rsync_opts
std::string m_rsync_opts
Definition: Platform.h:1044
lldb_private::ProcessLaunchInfo::SetLaunchInSeparateProcessGroup
void SetLaunchInSeparateProcessGroup(bool separate)
Definition: ProcessLaunchInfo.cpp:151
lldb_private::ProcessLaunchInfo::GetPTY
PseudoTerminal & GetPTY()
Definition: ProcessLaunchInfo.h:125
OptionValueProperties.h
lldb_private::FileSystem::Readlink
Status Readlink(const FileSpec &src, FileSpec &dst)
Definition: FileSystemPosix.cpp:43
lldb_private::File::eOpenOptionDontFollowSymlinks
@ eOpenOptionDontFollowSymlinks
Definition: File.h:61
lldb_private::ProcessAttachInfo
Definition: Process.h:113
ObjectFile.h
lldb_private::Debugger::GetTargetList
TargetList & GetTargetList()
Get accessor for the target list.
Definition: Debugger.h:229
lldb_private::Platform::IsRemote
bool IsRemote() const
Definition: Platform.h:427
lldb_private::ModuleCache
Definition: ModuleCache.h:47
lldb_private::FileSpec::IsAbsolute
bool IsAbsolute() const
Returns true if the filespec represents an absolute path.
Definition: FileSpec.cpp:477
lldb_private::FileSpec::Clear
void Clear()
Clears the object state.
Definition: FileSpec.cpp:259
lldb_private::Platform::ModuleResolver
std::function< Status(const ModuleSpec &)> ModuleResolver
Definition: Platform.h:946
StreamFile.h
RecurseCopyBaton::platform_ptr
Platform * platform_ptr
Definition: Platform.cpp:528
lldb_private::ModuleSpec::GetFileSpec
FileSpec & GetFileSpec()
Definition: ModuleSpec.h:58
lldb_private::ModuleSpec
Definition: ModuleSpec.h:26
lldb_private::Platform::GetUnixSignals
lldb::UnixSignalsSP GetUnixSignals()
Definition: Platform.cpp:1739
lldb_private::File::eOpenOptionWriteOnly
@ eOpenOptionWriteOnly
Definition: File.h:51
lldb_private::Target::GetArchitecture
const ArchSpec & GetArchitecture() const
Definition: Target.h:967
lldb_private::Platform::GetOSVersion
virtual llvm::VersionTuple GetOSVersion(Process *process=nullptr)
Get the OS version from a connected platform.
Definition: Platform.cpp:446
lldb_private::FileSystem::eEnumerateDirectoryResultNext
@ eEnumerateDirectoryResultNext
Enumerate next entry in the current directory.
Definition: FileSystem.h:164
lldb_private::Status
Definition: Status.h:44
lldb_private::ProcessLaunchInfo::GetResumeCount
uint32_t GetResumeCount() const
Definition: ProcessLaunchInfo.h:80
lldb_private::Platform::m_os_version_set_while_connected
bool m_os_version_set_while_connected
Definition: Platform.h:885
LIBLLDB_LOG_OBJECT
#define LIBLLDB_LOG_OBJECT
Definition: Logging.h:25
lldb_private::PseudoTerminal::ReleasePrimaryFileDescriptor
int ReleasePrimaryFileDescriptor()
Release the primary file descriptor.
Definition: PseudoTerminal.cpp:184
lldb_private::Timeout< std::micro >
lldb_private::Target::GetDefaultArchitecture
static ArchSpec GetDefaultArchitecture()
Definition: Target.cpp:2418
lldb_private::Platform::GetPlatformForArchitecture
static lldb::PlatformSP GetPlatformForArchitecture(const ArchSpec &arch, ArchSpec *platform_arch_ptr)
Definition: Platform.cpp:1203
lldb_private::Process::GetHostOSVersion
virtual llvm::VersionTuple GetHostOSVersion()
Sometimes the connection to a process can detect the host OS version that the process is running on.
Definition: Process.h:1199
lldb_private::Platform::GetWorkingDirectory
FileSpec GetWorkingDirectory()
Definition: Platform.cpp:509
lldb_private::Platform::GetCacheHostname
virtual const char * GetCacheHostname()
Definition: Platform.cpp:1732
lldb_private::Platform::m_calculated_trap_handlers
bool m_calculated_trap_handlers
Definition: Platform.h:911
BreakpointIDList.h
uint32_t
LLDB_INVALID_IMAGE_TOKEN
#define LLDB_INVALID_IMAGE_TOKEN
Definition: lldb-defines.h:89
lldb_private::Platform::GetAugmentedArchSpec
static ArchSpec GetAugmentedArchSpec(Platform *platform, llvm::StringRef triple)
Augments the triple either with information from platform or the host system (if platform is null).
Definition: Platform.cpp:378
lldb::eArgTypeNone
@ eArgTypeNone
Definition: lldb-enumerations.h:595
lldb::pid_t
uint64_t pid_t
Definition: lldb-types.h:85
lldb_private::Platform::GetCachedExecutable
Status GetCachedExecutable(ModuleSpec &module_spec, lldb::ModuleSP &module_sp, const FileSpecList *module_search_paths_ptr)
Definition: Platform.cpp:1547
lldb_private::Stream::EOL
size_t EOL()
Output and End of Line character to the stream.
Definition: Stream.cpp:128
lldb_private::OptionGroupPlatformRSync::m_ignores_remote_hostname
bool m_ignores_remote_hostname
Definition: Platform.h:1046
lldb_private::PlatformProperties
Definition: Platform.h:42
lldb_private::Process::GetModuleSpec
virtual bool GetModuleSpec(const FileSpec &module_file_spec, const ArchSpec &arch, ModuleSpec &module_spec)
Try to fetch the module specification for a module with the given file name and architecture.
Definition: Process.cpp:5785
lldb_private::Platform::m_name
std::string m_name
Definition: Platform.h:893
lldb_private::Status::SetErrorString
void SetErrorString(llvm::StringRef err_str)
Set the current error string to err_str.
Definition: Status.cpp:242
lldb_private::Host::GetProcessInfo
static bool GetProcessInfo(lldb::pid_t pid, ProcessInstanceInfo &proc_info)
Definition: freebsd/Host.cpp:230
lldb_private::FileSystem::EnumerateDirectory
void EnumerateDirectory(llvm::Twine path, bool find_directories, bool find_files, bool find_other, EnumerateDirectoryCallbackType callback, void *callback_baton)
Definition: common/FileSystem.cpp:203
lldb_private::Stream::AsRawOstream
llvm::raw_ostream & AsRawOstream()
Returns a raw_ostream that forwards the data to this Stream object.
Definition: Stream.h:357
UINT32_MAX
#define UINT32_MAX
Definition: lldb-defines.h:31
lldb_private::ProcessLaunchInfo::GetShell
const FileSpec & GetShell() const
Definition: ProcessLaunchInfo.cpp:140
lldb_private::Environment
Definition: Environment.h:18
RecurseCopyBaton::dst
const FileSpec & dst
Definition: Platform.cpp:527
GetHostPlatformSP
static PlatformSP & GetHostPlatformSP()
Definition: Platform.cpp:55
lldb_private::Platform::GetTrapHandlerSymbolNames
virtual const std::vector< ConstString > & GetTrapHandlerSymbolNames()
Provide a list of trap handler function names for this platform.
Definition: Platform.cpp:1535
lldb_private::Platform::ResolveSymbolFile
virtual Status ResolveSymbolFile(Target &target, const ModuleSpec &sym_spec, FileSpec &sym_file)
Find a symbol file given a symbol file module specification.
Definition: Platform.cpp:929
lldb_private::Platform::DoLoadImage
virtual uint32_t DoLoadImage(lldb_private::Process *process, const lldb_private::FileSpec &remote_file, const std::vector< std::string > *paths, lldb_private::Status &error, lldb_private::FileSpec *loaded_path=nullptr)
Definition: Platform.cpp:1782
lldb_private::Platform::FindProcesses
virtual uint32_t FindProcesses(const ProcessInstanceInfoMatch &match_info, ProcessInstanceInfoList &proc_infos)
Attach to an existing process by process name.
Definition: Platform.cpp:1044
lldb_private::FileSystem::GetPermissions
uint32_t GetPermissions(const FileSpec &file_spec) const
Return the current permissions of the given file.
Definition: common/FileSystem.cpp:142
PluginManager.h
lldb_private::ConstString::GetCString
const char * GetCString() const
Get the string value as a C string.
Definition: ConstString.h:216
lldb_private::ModuleSpec::GetArchitecture
ArchSpec & GetArchitecture()
Definition: ModuleSpec.h:94
LLDB_LOG
#define LLDB_LOG(log,...)
The LLDB_LOG* macros defined below are the way to emit log messages.
Definition: Log.h:242
lldb_private::Platform
Definition: Platform.h:71
lldb_private::Platform::GetFullNameForDylib
virtual ConstString GetFullNameForDylib(ConstString basename)
Definition: Platform.cpp:797
lldb_private::PluginManager::GetStructuredDataFilterCallbackAtIndex
static StructuredDataFilterLaunchInfo GetStructuredDataFilterCallbackAtIndex(uint32_t idx, bool &iteration_complete)
Definition: PluginManager.cpp:965
lldb_private::Platform::m_module_cache
const std::unique_ptr< ModuleCache > m_module_cache
Definition: Platform.h:912
lldb_private::Stream::Printf
size_t Printf(const char *format,...) __attribute__((format(printf
Output printf formatted output to the stream.
Definition: Stream.cpp:107
lldb_private::Platform::IsConnected
virtual bool IsConnected() const
Definition: Platform.h:429
lldb_private::Platform::ShellExpandArguments
virtual Status ShellExpandArguments(ProcessLaunchInfo &launch_info)
Perform expansion of the command-line for this launch info This can potentially involve wildcard expa...
Definition: Platform.cpp:1102
lldb_private::FileSystem::Instance
static FileSystem & Instance()
Definition: common/FileSystem.cpp:45
lldb_private::Platform::GetProcessInfo
virtual bool GetProcessInfo(lldb::pid_t pid, ProcessInstanceInfo &proc_info)
Definition: Platform.cpp:1035
lldb_private::AddressClass::eCodeAlternateISA
@ eCodeAlternateISA
lldb_private::OptionGroupPlatformSSH::OptionParsingStarting
void OptionParsingStarting(ExecutionContext *execution_context) override
Definition: Platform.cpp:1477
Status.h
lldb::user_id_t
uint64_t user_id_t
Definition: lldb-types.h:84
OptionParser.h
lldb_private::FileSpec::AppendPathComponent
void AppendPathComponent(llvm::StringRef component)
Definition: FileSpec.cpp:433
lldb_private::Platform::CreateArchList
static std::vector< ArchSpec > CreateArchList(llvm::ArrayRef< llvm::Triple::ArchType > archs, llvm::Triple::OSType os)
Create a list of ArchSpecs with the given OS and a architectures.
Definition: Platform.cpp:1213
lldb_private
A class that represents a running process on the host machine.
Definition: SBCommandInterpreterRunOptions.h:16
lldb_private::Platform::ResolveRemotePath
virtual bool ResolveRemotePath(const FileSpec &platform_path, FileSpec &resolved_platform_path)
Resolves the FileSpec to a (possibly) remote path.
Definition: Platform.cpp:939
lldb_private::Platform::GetFileExists
virtual bool GetFileExists(const lldb_private::FileSpec &file_spec)
Definition: Platform.cpp:1321
lldb_private::eMmapFlagsAnon
@ eMmapFlagsAnon
Definition: Platform.h:40
lldb_private::OptionDefinition
Definition: OptionDefinition.h:20
lldb_private::BreakpointSite::SetTrapOpcode
bool SetTrapOpcode(const uint8_t *trap_opcode, uint32_t trap_opcode_size)
Sets the trap opcode.
Definition: BreakpointSite.cpp:104
lldb_private::Platform::Attach
virtual lldb::ProcessSP Attach(ProcessAttachInfo &attach_info, Debugger &debugger, Target *target, Status &error)=0
Attach to an existing process using a process ID.
FileSpec.h
lldb_private::Platform::LaunchProcess
virtual Status LaunchProcess(ProcessLaunchInfo &launch_info)
Launch a new process on a platform, not necessarily for debugging, it could be just for running the p...
Definition: Platform.cpp:1054
lldb_private::Platform::ResolveRemoteExecutable
virtual Status ResolveRemoteExecutable(const ModuleSpec &module_spec, lldb::ModuleSP &exe_module_sp, const FileSpecList *module_search_paths_ptr)
Definition: Platform.cpp:865
lldb_private::Flags::Set
ValueType Set(ValueType mask)
Set one or more flags by logical OR'ing mask with the current flags.
Definition: Flags.h:73
lldb_private::Platform::SetOSVersion
bool SetOSVersion(llvm::VersionTuple os_version)
Definition: Platform.cpp:809
lldb_private::FileSpec::GetDirectory
ConstString & GetDirectory()
Directory string get accessor.
Definition: FileSpec.cpp:333
lldb_private::Platform::CloseFile
virtual bool CloseFile(lldb::user_id_t fd, Status &error)
Definition: Platform.h:500
lldb_private::Platform::m_system_arch
ArchSpec m_system_arch
Definition: Platform.h:896
lldb_private::Platform::GetStatus
virtual void GetStatus(Stream &strm)
Report the current status for this platform.
Definition: Platform.cpp:400
lldb_private::Platform::Unlink
virtual Status Unlink(const FileSpec &file_spec)
Definition: Platform.cpp:1325
lldb_private::Platform::DownloadModuleSlice
virtual Status DownloadModuleSlice(const FileSpec &src_file_spec, const uint64_t src_offset, const uint64_t src_size, const FileSpec &dst_file_spec)
Definition: Platform.cpp:1672
lldb_private::Log
Definition: Log.h:49
llvm::SmallVectorImpl
Definition: Disassembler.h:42
lldb_private::Platform::GetRemoteOSVersion
virtual bool GetRemoteOSVersion()
Definition: Platform.h:241
lldb_private::GetLogIfAnyCategoriesSet
Log * GetLogIfAnyCategoriesSet(uint32_t mask)
Definition: Logging.cpp:62
lldb_private::Platform::IsHost
bool IsHost() const
Definition: Platform.h:423
lldb_private::Listener::MakeListener
static lldb::ListenerSP MakeListener(const char *name)
Definition: Listener.cpp:464
lldb_private::ModuleSpec::GetObjectOffset
uint64_t GetObjectOffset() const
Definition: ModuleSpec.h:112
lldb_private::ArchSpec::Clear
void Clear()
Clears the object state.
Definition: ArchSpec.cpp:527
lldb_private::FileSpec::GetPath
size_t GetPath(char *path, size_t max_path_length, bool denormalize=true) const
Extract the full path to the file.
Definition: FileSpec.cpp:346
lldb_private::Platform::GetSupportedArchitectures
virtual std::vector< ArchSpec > GetSupportedArchitectures()=0
Get the platform's supported architectures in the order in which they should be searched.
lldb_private::eMmapFlagsPrivate
@ eMmapFlagsPrivate
Definition: Platform.h:40
lldb_private::Host::Kill
static void Kill(lldb::pid_t pid, int signo)
Definition: common/Host.cpp:637
lldb_private::ProcessAttachInfo::GetHijackListener
lldb::ListenerSP GetHijackListener() const
Definition: Process.h:179
lldb_private::DataBufferHeap
Definition: DataBufferHeap.h:30
lldb_private::ProcessInstanceInfoList
std::vector< ProcessInstanceInfo > ProcessInstanceInfoList
Definition: Host.h:30
OptionValueFileSpec.h
lldb
Definition: SBAddress.h:15
lldb_private::ModuleList::GetSharedModule
static Status GetSharedModule(const ModuleSpec &module_spec, lldb::ModuleSP &module_sp, const FileSpecList *module_search_paths_ptr, llvm::SmallVectorImpl< lldb::ModuleSP > *old_modules, bool *did_create_ptr, bool always_create=false)
Definition: ModuleList.cpp:723
lldb_private::Platform::m_system_arch_set_while_connected
bool m_system_arch_set_while_connected
Definition: Platform.h:886
lldb_private::OptionParser::eRequiredArgument
@ eRequiredArgument
Definition: OptionParser.h:35
lldb_private::FileSpec::GetFilename
ConstString & GetFilename()
Filename string get accessor.
Definition: FileSpec.cpp:339
lldb_private::Platform::ConnectProcess
virtual lldb::ProcessSP ConnectProcess(llvm::StringRef connect_url, llvm::StringRef plugin_name, Debugger &debugger, Target *target, Status &error)
Definition: Platform.cpp:1813
lldb_private::Platform::GetFile
virtual Status GetFile(const FileSpec &source, const FileSpec &destination)
Definition: Platform.cpp:1308
lldb_private::Platform::ConnectProcessSynchronous
virtual lldb::ProcessSP ConnectProcessSynchronous(llvm::StringRef connect_url, llvm::StringRef plugin_name, Debugger &debugger, Stream &stream, Target *target, Status &error)
Definition: Platform.cpp:1821
DataBufferHeap.h
GetPlatformList
static std::vector< PlatformSP > & GetPlatformList()
Definition: Platform.cpp:137
lldb_private::ProcessLaunchInfo::ConvertArgumentsForLaunchingInShell
bool ConvertArgumentsForLaunchingInShell(Status &error, bool will_debug, bool first_arg_is_full_shell_command, uint32_t num_resumes)
Definition: ProcessLaunchInfo.cpp:248
UINT64_MAX
#define UINT64_MAX
Definition: lldb-defines.h:35
lldb_private::Platform::GetHostname
virtual const char * GetHostname()
Definition: Platform.cpp:788
lldb_private::ArchSpec::IsExactMatch
bool IsExactMatch(const ArchSpec &rhs) const
Compare an ArchSpec to another ArchSpec, requiring an exact cpu type match between them.
Definition: ArchSpec.cpp:930
lldb_private::ModuleSpec::GetObjectSize
uint64_t GetObjectSize() const
Definition: ModuleSpec.h:118
lldb_private::Platform::DoConnectProcess
lldb::ProcessSP DoConnectProcess(llvm::StringRef connect_url, llvm::StringRef plugin_name, Debugger &debugger, Stream *stream, Target *target, Status &error)
Private implementation of connecting to a process.
Definition: Platform.cpp:1828
lldb_private::Status::AsCString
const char * AsCString(const char *default_error_str="unknown error") const
Get the error string associated with the current error.
Definition: Status.cpp:131
lldb_private::Platform::Create
static lldb::PlatformSP Create(ConstString name, Status &error)
Definition: Platform.cpp:289