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