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