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