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