42#include "llvm/ADT/STLExtras.h"
43#include "llvm/Support/FileSystem.h"
44#include "llvm/Support/Path.h"
49#define MAP_ANON 0x1000
65#define LLDB_PROPERTIES_platform
66#include "TargetProperties.inc"
69#define LLDB_PROPERTIES_platform
70#include "TargetPropertiesEnum.inc"
76 static constexpr llvm::StringLiteral g_setting_name(
"platform");
77 return g_setting_name;
88 llvm::SmallString<64> user_home_dir;
92 module_cache_dir =
FileSpec(user_home_dir.c_str());
93 module_cache_dir.AppendPathComponent(
".lldb");
94 module_cache_dir.AppendPathComponent(
"module_cache");
100 const auto idx = ePropertyUseModuleCache;
102 idx, g_platform_properties[idx].default_uint_value != 0);
114 return m_collection_sp->SetPropertyAtIndex(ePropertyModuleCacheDirectory,
120 auto f_spec_opt =
m_collection_sp->GetPropertyAtIndexAsOptionValueFileSpec(
121 ePropertyModuleCacheDirectory);
123 f_spec_opt->SetDefaultValue(dir_spec);
154 local_file = platform_file;
160 Stream &feedback_stream) {
172 did_create_ptr,
false);
181 resolved_spec = spec;
185 did_create_ptr,
false);
189 if (!
error.Success()) {
190 resolved_spec = spec;
192 did_create_ptr,
false);
194 if (
error.Success() && module_sp)
195 module_sp->SetPlatformFileSpec(resolved_spec.
GetFileSpec());
222 return create_callback(
true,
nullptr);
229 return HostInfo::GetAugmentedArchSpec(triple);
242 LLDB_LOGF(log,
"%p Platform::Platform()",
static_cast<void *
>(
this));
260 if (!os_version.empty()) {
261 strm.
Format(
"OS Version: {0}", os_version.getAsString());
264 strm.
Format(
" ({0})", *s);
275 strm.
Printf(
" Connected: %s\n", is_connected ?
"yes" :
"no");
279 strm.
Format(
" Sysroot: {0}\n", sdk_root);
289 if (!specific_info.empty())
290 strm.
Printf(
"Platform-specific connection: %s\n", specific_info.c_str());
293 strm.
Format(
" Kernel: {0}\n", *s);
297 std::lock_guard<std::mutex> guard(
m_mutex);
321 fetch = is_connected;
335 return llvm::VersionTuple();
340 return HostInfo::GetOSBuildString();
346 return HostInfo::GetOSKernelDescription();
351 Target *target, std::vector<std::string> &options) {
352 std::vector<std::string> default_compilation_options = {
353 "-x",
"c++",
"-Xclang",
"-nostdsysteminc",
"-Xclang",
"-nostdsysteminc"};
355 options.insert(options.end(), default_compilation_options.begin(),
356 default_compilation_options.end());
361 llvm::SmallString<64> cwd;
362 if (llvm::sys::fs::current_path(cwd))
384 llvm::StringRef path) {
387 namespace fs = llvm::sys::fs;
389 case fs::file_type::fifo_file:
390 case fs::file_type::socket_file:
395 case fs::file_type::directory_file: {
401 dst_dir, lldb::eFilePermissionsDirectoryDefault);
404 "unable to setup directory {0} on remote end", dst_dir.
GetPath());
409 std::string src_dir_path(src.
GetPath());
426 case fs::file_type::symlink_file: {
448 case fs::file_type::regular_file: {
463 "invalid file detected during copy: %s", src.
GetPath().c_str());
467 llvm_unreachable(
"Unhandled file_type!");
474 LLDB_LOGF(log,
"Platform::Install (src='%s', dst='%s')",
486 if (first_dst_dir_char ==
'/' || first_dst_dir_char ==
'\\') {
495 relative_spec = working_dir;
500 "platform working directory must be valid for relative path '%s'",
510 "platform working directory must be valid for relative path '%s'",
521 "when destination directory is empty");
526 LLDB_LOGF(log,
"Platform::Install (src='%s', dst='%s') fixed_dst='%s'",
533 namespace fs = llvm::sys::fs;
534 switch (fs::get_file_type(src.
GetPath(),
false)) {
535 case fs::file_type::directory_file: {
536 llvm::sys::fs::remove(fixed_dst.
GetPath());
538 if (permissions == 0)
539 permissions = eFilePermissionsDirectoryDefault;
541 if (
error.Success()) {
546 std::string src_dir_path(src.
GetPath());
550 return std::move(baton.
error);
554 case fs::file_type::regular_file:
555 llvm::sys::fs::remove(fixed_dst.
GetPath());
559 case fs::file_type::symlink_file: {
560 llvm::sys::fs::remove(fixed_dst.
GetPath());
566 case fs::file_type::fifo_file:
569 case fs::file_type::socket_file:
575 "platform install doesn't handle non file or directory items");
586 if (std::error_code ec = llvm::sys::fs::set_current_path(file_spec.
GetPath())) {
587 LLDB_LOG(log,
"error: {0}", ec.message());
598 uint32_t permissions) {
600 return llvm::sys::fs::create_directory(file_spec.
GetPath(), permissions);
605 LLVM_PRETTY_FUNCTION);
611 uint32_t &file_permissions) {
613 auto Value = llvm::sys::fs::getPermissions(file_spec.
GetPath());
615 file_permissions =
Value.get();
621 LLVM_PRETTY_FUNCTION);
627 uint32_t file_permissions) {
629 auto Perms =
static_cast<llvm::sys::fs::perms
>(file_permissions);
630 return llvm::sys::fs::setPermissions(file_spec.
GetPath(), Perms);
635 LLVM_PRETTY_FUNCTION);
659 if (llvm::sys::fs::file_size(file_spec.
GetPath(), Size))
669 "Platform::ReadFile() is not supported in the {0} platform",
675 const void *src, uint64_t src_len,
Status &
error) {
679 "Platform::WriteFile() is not supported in the {0} platform",
686 return HostInfo::GetUserIDResolver();
705 LLDB_LOGF(log,
"Platform::SetRemoteWorkingDirectory('%s')",
706 working_dir.
GetPath().c_str());
746 "'{0}' does not exist", resolved_module_spec.
GetFileSpec());
751 exe_module_sp,
nullptr,
nullptr);
753 if (exe_module_sp && exe_module_sp->GetObjectFile())
755 exe_module_sp.reset();
761 llvm::ListSeparator LS;
769 if (
error.Success()) {
770 if (exe_module_sp && exe_module_sp->GetObjectFile())
775 arch_names << LS << arch.GetArchitectureName();
778 if (exe_module_sp &&
error.Success())
783 "'{0}' is not readable", resolved_module_spec.
GetFileSpec());
787 "'{0}' is not a valid executable", resolved_module_spec.
GetFileSpec());
790 "'{0}' doesn't contain any '{1}' platform architectures: {2}",
807 resolved_platform_path = platform_path;
835 fetch = is_connected;
849 llvm::Triple normalized_triple(llvm::Triple::normalize(triple));
853 if (
auto kind = HostInfo::ParseArchitectureKind(triple))
854 return HostInfo::GetArchitecture(*kind);
862 if (!compatible_arch.
IsValid())
865 const llvm::Triple &compatible_triple = compatible_arch.
GetTriple();
866 if (normalized_triple.getVendorName().empty())
867 normalized_triple.setVendor(compatible_triple.getVendor());
868 if (normalized_triple.getOSName().empty())
869 normalized_triple.setOS(compatible_triple.getOS());
870 if (normalized_triple.getEnvironmentName().empty())
871 normalized_triple.setEnvironment(compatible_triple.getEnvironment());
879 "The currently selected platform ({0}) is "
880 "the host platform and is always connected.",
884 "Platform::ConnectRemote() is not supported by {0}",
GetPluginName());
892 "The currently selected platform ({0}) is "
893 "the host platform and is always connected.",
897 "Platform::DisconnectRemote() is not supported by {0}",
915 uint32_t match_count = 0;
932 LLDB_LOGF(log,
"Platform::%s()", __FUNCTION__);
937 if (::getenv(
"LLDB_LAUNCH_FLAG_LAUNCH_IN_TTY"))
938 launch_info.
GetFlags().
Set(eLaunchFlagLaunchInTTY);
940 if (launch_info.
GetFlags().
Test(eLaunchFlagLaunchInShell)) {
941 const bool will_debug = launch_info.
GetFlags().
Test(eLaunchFlagDebug);
942 const bool first_arg_is_full_shell_command =
false;
946 std::string shell_str = (shell) ? shell.
GetPath() :
"<null>";
948 "Platform::%s GetResumeCountForLaunchInfo() returned %" PRIu32
950 __FUNCTION__, num_resumes, shell_str.c_str());
954 error, will_debug, first_arg_is_full_shell_command, num_resumes))
956 }
else if (launch_info.
GetFlags().
Test(eLaunchFlagShellExpandArguments)) {
960 "shell expansion failed (reason: %s). "
961 "consider launching with 'process "
963 error.AsCString(
"unknown"));
968 LLDB_LOGF(log,
"Platform::%s final launch_info resume count: %" PRIu32,
974 "base lldb_private::Platform class can't launch remote processes");
982 "base lldb_private::Platform class can't expand arguments");
987 LLDB_LOGF(log,
"Platform::%s, pid %" PRIu64, __FUNCTION__, pid);
991 "base lldb_private::Platform class can't kill remote processes");
1001 LLDB_LOG(log,
"target = {0}", &target);
1014 bool iteration_complete =
false;
1018 for (
auto filter_callback = get_filter_func(i, iteration_complete);
1019 !iteration_complete;
1020 filter_callback = get_filter_func(++i, iteration_complete)) {
1021 if (filter_callback) {
1023 error = (*filter_callback)(launch_info, &target);
1024 if (!
error.Success()) {
1026 "Platform::%s() StructuredDataPlugin launch "
1035 if (
error.Success()) {
1037 "Platform::%s LaunchProcess() call succeeded (pid=%" PRIu64
")",
1041 process_sp =
Attach(attach_info, debugger, &target,
error);
1043 LLDB_LOG(log,
"Attach() succeeded, Process plugin: {0}",
1044 process_sp->GetPluginName());
1051 process_sp->SetShouldDetach(
false);
1059 process_sp->SetSTDIOFileDescriptor(pty_fd);
1062 LLDB_LOGF(log,
"Platform::%s Attach() failed: %s", __FUNCTION__,
1067 "Platform::%s LaunchProcess() returned launch_info with "
1068 "invalid process id",
1072 LLDB_LOGF(log,
"Platform::%s LaunchProcess() failed: %s", __FUNCTION__,
1079std::vector<ArchSpec>
1081 llvm::Triple::OSType os) {
1082 std::vector<ArchSpec> list;
1083 for(
auto arch : archs) {
1084 llvm::Triple triple;
1085 triple.setArch(arch);
1101 for (
const ArchSpec &platform_arch :
1103 if (arch.
IsMatch(platform_arch, match)) {
1104 if (compatible_arch_ptr)
1105 *compatible_arch_ptr = platform_arch;
1110 if (compatible_arch_ptr)
1111 compatible_arch_ptr->
Clear();
1116 uint32_t uid, uint32_t gid) {
1118 LLDB_LOGF(log,
"[PutFile] Using block by block transfer....\n");
1120 auto source_open_options =
1122 namespace fs = llvm::sys::fs;
1123 if (fs::is_symlink_file(source.
GetPath()))
1127 lldb::eFilePermissionsUserRW);
1132 bool requires_upload =
true;
1133 llvm::ErrorOr<llvm::MD5::MD5Result> remote_md5 =
CalculateMD5(destination);
1134 if (std::error_code ec = remote_md5.getError()) {
1135 LLDB_LOG(log,
"[PutFile] couldn't get md5 sum of destination: {0}",
1138 llvm::ErrorOr<llvm::MD5::MD5Result> local_md5 =
1139 llvm::sys::fs::md5_contents(source.
GetPath());
1140 if (std::error_code ec = local_md5.getError()) {
1141 LLDB_LOG(log,
"[PutFile] couldn't get md5 sum of source: {0}",
1144 LLDB_LOGF(log,
"[PutFile] destination md5: %016" PRIx64
"%016" PRIx64,
1145 remote_md5->high(), remote_md5->low());
1146 LLDB_LOGF(log,
"[PutFile] local md5: %016" PRIx64
"%016" PRIx64,
1147 local_md5->high(), local_md5->low());
1148 requires_upload = *remote_md5 != *local_md5;
1152 if (!requires_upload) {
1153 LLDB_LOGF(log,
"[PutFile] skipping PutFile because md5sums match");
1157 uint32_t permissions = source_file.get()->GetPermissions(
error);
1158 if (permissions == 0)
1159 permissions = lldb::eFilePermissionsUserRWX;
1164 permissions,
error);
1165 LLDB_LOGF(log,
"dest_file = %" PRIu64
"\n", dest_file);
1172 uint64_t offset = 0;
1174 size_t bytes_read = buffer_sp->GetByteSize();
1175 error = source_file.get()->Read(buffer_sp->GetBytes(), bytes_read);
1176 if (
error.Fail() || bytes_read == 0)
1179 const uint64_t bytes_written =
1180 WriteFile(dest_file, offset, buffer_sp->GetBytes(), bytes_read,
error);
1184 offset += bytes_written;
1185 if (bytes_written != bytes_read) {
1188 source_file.get()->SeekFromStart(offset);
1222 return llvm::sys::fs::remove(path.
GetPath());
1227 addr_t length,
unsigned prot,
1228 unsigned flags,
addr_t fd,
1230 uint64_t flags_platform = 0;
1236 MmapArgList args({addr, length, prot, flags_platform, fd, offset});
1241 llvm::StringRef command,
1250 return RunShellCommand(llvm::StringRef(), command, working_dir, status_ptr,
1251 signo_ptr, command_output, timeout);
1255 llvm::StringRef shell,
1257 llvm::StringRef command,
1268 signo_ptr, command_output, timeout);
1270 "unable to run a remote command without a platform");
1273llvm::ErrorOr<llvm::MD5::MD5Result>
1276 return std::make_error_code(std::errc::not_supported);
1277 return llvm::sys::fs::md5_contents(file_spec.
GetPath());
1293 "Platform-specific options required for rsync to work."},
1296 "Platform-specific rsync prefix put before the remote path."},
1299 "Do not automatically fill in the remote hostname when composing the "
1308 "Platform-specific options required for SSH to work."},
1314 "Path in which to store local copies of files."},
1331 llvm::StringRef option_arg,
1334 char short_option = (char)
GetDefinitions()[option_idx].short_option;
1335 switch (short_option) {
1378 llvm::StringRef option_arg,
1381 char short_option = (char)
GetDefinitions()[option_idx].short_option;
1382 switch (short_option) {
1410 uint32_t option_idx, llvm::StringRef option_arg,
1413 char short_option = (char)
GetDefinitions()[option_idx].short_option;
1414 switch (short_option) {
1436 std::lock_guard<std::mutex> guard(
m_mutex);
1449 module_spec,
nullptr, module_sp,
1454 if (
error.Success()) {
1455 module_spec.
GetFileSpec() = module_sp->GetFileSpec();
1466 bool *did_create_ptr) {
1470 bool got_module_spec =
false;
1476 resolved_module_spec)) {
1479 got_module_spec =
true;
1495 if (
error.Success() && module_sp)
1499 resolved_module_spec = arch_module_spec;
1500 got_module_spec =
true;
1504 if (!got_module_spec) {
1507 resolved_module_spec)) {
1510 got_module_spec =
true;
1515 if (!got_module_spec) {
1518 return module_resolver(module_spec);
1533 symbol_file_spec, did_create_ptr);
1536 if (symbol_file_spec) {
1540 module_sp->SetSymbolFileFileSpec(symbol_file_spec);
1561 Status error = module_resolver(resolved_module_spec);
1562 if (
error.Success()) {
1563 if (module_sp && symbol_file_spec) {
1566 module_sp->SetSymbolFileFileSpec(symbol_file_spec);
1573 if (module_sp && symbol_file_spec) {
1576 module_sp->SetSymbolFileFileSpec(symbol_file_spec);
1582 "Failed to call GetCachedSharedModule");
1588 bool *did_create_ptr) {
1601 LLDB_LOGF(log,
"%s: locate module callback failed: %s",
1602 LLVM_PRETTY_FUNCTION,
error.AsCString());
1617 if (!module_file_spec && !symbol_file_spec) {
1621 "%s: locate module callback did not set both "
1622 "module_file_spec and symbol_file_spec",
1623 LLVM_PRETTY_FUNCTION);
1630 "%s: locate module callback set a non-existent file to "
1631 "module_file_spec: %s",
1632 LLVM_PRETTY_FUNCTION, module_file_spec.
GetPath().c_str());
1634 symbol_file_spec.
Clear();
1641 "%s: locate module callback set a non-existent file to "
1642 "symbol_file_spec: %s",
1643 LLVM_PRETTY_FUNCTION, symbol_file_spec.
GetPath().c_str());
1645 symbol_file_spec.
Clear();
1649 if (!module_file_spec && symbol_file_spec) {
1654 LLDB_LOGF(log,
"%s: locate module callback succeeded: symbol=%s",
1655 LLVM_PRETTY_FUNCTION, symbol_file_spec.
GetPath().c_str());
1665 auto cached_module_spec(module_spec);
1666 cached_module_spec.GetUUID().Clear();
1668 cached_module_spec.GetFileSpec() = module_file_spec;
1669 cached_module_spec.GetSymbolFileSpec() = symbol_file_spec;
1670 cached_module_spec.GetPlatformFileSpec() = module_spec.
GetFileSpec();
1671 cached_module_spec.SetObjectOffset(0);
1674 did_create_ptr,
false,
false);
1675 if (
error.Success() && module_sp) {
1677 LLDB_LOGF(log,
"%s: locate module callback succeeded: module=%s symbol=%s",
1678 LLVM_PRETTY_FUNCTION, module_file_spec.
GetPath().c_str(),
1679 symbol_file_spec.
GetPath().c_str());
1682 "%s: locate module callback succeeded but failed to load: "
1683 "module=%s symbol=%s",
1684 LLVM_PRETTY_FUNCTION, module_file_spec.
GetPath().c_str(),
1685 symbol_file_spec.
GetPath().c_str());
1688 symbol_file_spec.
Clear();
1694 bool *did_create_ptr) {
1705 const FileSpec &tmp_download_file_spec) {
1712 const FileSpec &tmp_download_file_spec) {
1715 module_sp, did_create_ptr);
1716 if (
error.Success())
1719 LLDB_LOGF(log,
"Platform::%s - module %s not found in local cache: %s",
1726 const uint64_t src_offset,
1727 const uint64_t src_size,
1732 llvm::raw_fd_ostream dst(dst_file_spec.
GetPath(), EC, llvm::sys::fs::OF_None);
1735 "unable to open destination file: %s", dst_file_spec.
GetPath().c_str());
1740 lldb::eFilePermissionsFileDefault,
error);
1748 std::vector<char> buffer(512 * 1024);
1749 auto offset = src_offset;
1750 uint64_t total_bytes_read = 0;
1751 while (total_bytes_read < src_size) {
1752 const auto to_read = std::min(
static_cast<uint64_t
>(buffer.size()),
1753 src_size - total_bytes_read);
1754 const uint64_t n_read =
1763 total_bytes_read += n_read;
1764 dst.write(&buffer[0], n_read);
1776 "Symbol file downloading not supported by the default platform.");
1788 static const auto s_default_unix_signals_sp = std::make_shared<UnixSignals>();
1789 return s_default_unix_signals_sp;
1802 if (local_file && remote_file) {
1805 if (
IsRemote() || local_file != remote_file) {
1818 if (
IsRemote() || local_file != target_file) {
1838 const std::vector<std::string> *paths,
1842 "LoadImage is not supported on the current platform");
1848 const std::vector<std::string> &paths,
1858 file_to_use = remote_filename;
1864 uint32_t image_token) {
1866 "UnloadImage is not supported on the current platform");
1870 llvm::StringRef plugin_name,
1873 return DoConnectProcess(connect_url, plugin_name, debugger,
nullptr, target,
1878 llvm::StringRef connect_url, llvm::StringRef plugin_name,
1880 return DoConnectProcess(connect_url, plugin_name, debugger, &stream, target,
1885 llvm::StringRef plugin_name,
1893 const char *triple =
1900 target = new_target_sp.get();
1901 if (!target ||
error.Fail()) {
1913 const bool synchronous = stream !=
nullptr;
1918 process_sp->HijackProcessEvents(listener_sp);
1920 error = process_sp->ConnectRemote(connect_url);
1923 process_sp->RestoreProcessEvents();
1929 process_sp->WaitForProcessToStop(std::nullopt, &event_sp,
true, listener_sp,
1931 process_sp->RestoreProcessEvents();
1932 bool pop_process_io_handler =
false;
1951 const uint8_t *trap_opcode =
nullptr;
1952 size_t trap_opcode_size = 0;
1955 case llvm::Triple::aarch64_32:
1956 case llvm::Triple::aarch64: {
1957 static const uint8_t g_aarch64_opcode[] = {0x00, 0x00, 0x20, 0xd4};
1958 trap_opcode = g_aarch64_opcode;
1959 trap_opcode_size =
sizeof(g_aarch64_opcode);
1962 case llvm::Triple::arc: {
1963 static const uint8_t g_hex_opcode[] = { 0xff, 0x7f };
1964 trap_opcode = g_hex_opcode;
1965 trap_opcode_size =
sizeof(g_hex_opcode);
1969 case llvm::Triple::arm: {
1972 static const uint8_t g_arm_breakpoint_opcode[] = {0xf0, 0x01, 0xf0, 0xe7};
1973 static const uint8_t g_thumb_breakpoint_opcode[] = {0x01, 0xde};
1979 addr_class = bp_loc_sp->GetAddress().GetAddressClass();
1981 (bp_loc_sp->GetAddress().GetFileAddress() & 1))
1986 trap_opcode = g_thumb_breakpoint_opcode;
1987 trap_opcode_size =
sizeof(g_thumb_breakpoint_opcode);
1989 trap_opcode = g_arm_breakpoint_opcode;
1990 trap_opcode_size =
sizeof(g_arm_breakpoint_opcode);
1994 case llvm::Triple::avr: {
1995 static const uint8_t g_hex_opcode[] = {0x98, 0x95};
1996 trap_opcode = g_hex_opcode;
1997 trap_opcode_size =
sizeof(g_hex_opcode);
2000 case llvm::Triple::mips:
2001 case llvm::Triple::mips64: {
2002 static const uint8_t g_hex_opcode[] = {0x00, 0x00, 0x00, 0x0d};
2003 trap_opcode = g_hex_opcode;
2004 trap_opcode_size =
sizeof(g_hex_opcode);
2007 case llvm::Triple::mipsel:
2008 case llvm::Triple::mips64el: {
2009 static const uint8_t g_hex_opcode[] = {0x0d, 0x00, 0x00, 0x00};
2010 trap_opcode = g_hex_opcode;
2011 trap_opcode_size =
sizeof(g_hex_opcode);
2014 case llvm::Triple::msp430: {
2015 static const uint8_t g_msp430_opcode[] = {0x43, 0x43};
2016 trap_opcode = g_msp430_opcode;
2017 trap_opcode_size =
sizeof(g_msp430_opcode);
2020 case llvm::Triple::systemz: {
2021 static const uint8_t g_hex_opcode[] = {0x00, 0x01};
2022 trap_opcode = g_hex_opcode;
2023 trap_opcode_size =
sizeof(g_hex_opcode);
2026 case llvm::Triple::hexagon: {
2027 static const uint8_t g_hex_opcode[] = {0x0c, 0xdb, 0x00, 0x54};
2028 trap_opcode = g_hex_opcode;
2029 trap_opcode_size =
sizeof(g_hex_opcode);
2032 case llvm::Triple::ppc:
2033 case llvm::Triple::ppc64: {
2034 static const uint8_t g_ppc_opcode[] = {0x7f, 0xe0, 0x00, 0x08};
2035 trap_opcode = g_ppc_opcode;
2036 trap_opcode_size =
sizeof(g_ppc_opcode);
2039 case llvm::Triple::ppc64le: {
2040 static const uint8_t g_ppc64le_opcode[] = {0x08, 0x00, 0xe0, 0x7f};
2041 trap_opcode = g_ppc64le_opcode;
2042 trap_opcode_size =
sizeof(g_ppc64le_opcode);
2045 case llvm::Triple::x86:
2046 case llvm::Triple::x86_64: {
2047 static const uint8_t g_i386_opcode[] = {0xCC};
2048 trap_opcode = g_i386_opcode;
2049 trap_opcode_size =
sizeof(g_i386_opcode);
2052 case llvm::Triple::riscv32:
2053 case llvm::Triple::riscv64: {
2054 static const uint8_t g_riscv_opcode[] = {0x73, 0x00, 0x10, 0x00};
2055 static const uint8_t g_riscv_opcode_c[] = {0x02, 0x90};
2057 trap_opcode = g_riscv_opcode_c;
2058 trap_opcode_size =
sizeof(g_riscv_opcode_c);
2060 trap_opcode = g_riscv_opcode;
2061 trap_opcode_size =
sizeof(g_riscv_opcode);
2065 case llvm::Triple::loongarch32:
2066 case llvm::Triple::loongarch64: {
2067 static const uint8_t g_loongarch_opcode[] = {0x05, 0x00, 0x2a,
2069 trap_opcode = g_loongarch_opcode;
2070 trap_opcode_size =
sizeof(g_loongarch_opcode);
2073 case llvm::Triple::wasm32: {
2075 static const uint8_t g_wasm_opcode[] = {0x00};
2076 trap_opcode = g_wasm_opcode;
2077 trap_opcode_size =
sizeof(g_wasm_opcode);
2086 return trap_opcode_size;
2108 std::lock_guard<std::recursive_mutex> guard(
m_mutex);
2110 if (platform_sp->GetName() == name)
2120 std::lock_guard<std::recursive_mutex> guard(
m_mutex);
2123 if (platform_sp->IsCompatibleArchitecture(
2130 if (platform_sp->IsCompatibleArchitecture(arch, process_host_arch,
2142 PlatformSP platform_sp = create_callback(
false, &arch);
2144 platform_sp->IsCompatibleArchitecture(
2154 PlatformSP platform_sp = create_callback(
false, &arch);
2155 if (platform_sp && platform_sp->IsCompatibleArchitecture(
2157 platform_arch_ptr)) {
2162 if (platform_arch_ptr)
2163 platform_arch_ptr->
Clear();
2178 std::vector<PlatformSP> &candidates) {
2180 candidates.reserve(archs.size());
2189 for (
const ArchSpec &arch : archs) {
2197 if (host_platform_sp) {
2198 for (
const ArchSpec &arch : archs) {
2199 if (host_platform_sp->IsCompatibleArchitecture(
2201 return host_platform_sp;
2206 for (
const ArchSpec &arch : archs) {
2208 candidates.push_back(platform);
2214 if (candidates.size() == archs.size()) {
2215 if (llvm::all_of(candidates, [&](
const PlatformSP &p) ->
bool {
2216 return p->GetName() == candidates.front()->GetName();
2218 return candidates.front();
2229 std::lock_guard<std::recursive_mutex> guard(
m_mutex);
2238 std::lock_guard<std::recursive_mutex> guard(
m_mutex);
2245 PlatformSP platform_sp = create_callback(
true, &arch);
2247 if (platform_sp->LoadPlatformBinaryAndSetup(process, addr, notify))
static llvm::raw_ostream & error(Stream &strm)
#define LLDB_LOG(log,...)
The LLDB_LOG* macros defined below are the way to emit log messages.
#define LLDB_LOGF(log,...)
An architecture specification class.
bool IsValid() const
Tests if this ArchSpec is valid.
void Clear()
Clears the object state.
llvm::Triple & GetTriple()
Architecture triple accessor.
bool IsMatch(const ArchSpec &rhs, MatchType match) const
Compare this ArchSpec to another ArchSpec.
void DumpTriple(llvm::raw_ostream &s) const
uint32_t GetFlags() const
llvm::Triple::ArchType GetMachine() const
Returns a machine family for the current architecture.
static bool ContainsOnlyArch(const llvm::Triple &normalized_triple)
Returns true if the OS, vendor and environment fields of the triple are unset.
A command line argument class.
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.
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.
TargetList & GetTargetList()
Get accessor for the target list.
lldb::ListenerSP GetListener()
"lldb/Target/ExecutionContext.h" A class that contains an execution context.
bool CloseFile(lldb::user_id_t fd, Status &error)
uint64_t ReadFile(lldb::user_id_t fd, uint64_t offset, void *dst, uint64_t dst_len, Status &error)
lldb::user_id_t OpenFile(const FileSpec &file_spec, File::OpenOptions flags, uint32_t mode, Status &error)
uint64_t WriteFile(lldb::user_id_t fd, uint64_t offset, const void *src, uint64_t src_len, Status &error)
static FileCache & GetInstance()
void AppendPathComponent(llvm::StringRef component)
void SetDirectory(ConstString directory)
Directory string set accessor.
const ConstString & GetFilename() const
Filename string const get accessor.
const ConstString & GetDirectory() const
Directory string const get accessor.
bool IsAbsolute() const
Returns true if the filespec represents an absolute path.
Style GetPathStyle() const
void PrependPathComponent(llvm::StringRef component)
size_t GetPath(char *path, size_t max_path_length, bool denormalize=true) const
Extract the full path to the file.
void Clear()
Clears the object state.
ConstString GetPathAsConstString(bool denormalize=true) const
Get the full path as a ConstString.
void SetFilename(ConstString filename)
Filename string set accessor.
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.
@ eEnumerateDirectoryResultQuit
Stop directory enumerations at any level.
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()
@ eOpenOptionDontFollowSymlinks
bool Test(ValueType bit) const
Test a single flag bit.
ValueType Set(ValueType mask)
Set one or more flags by logical OR'ing mask with the current flags.
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)
static Status GetSharedModule(const ModuleSpec &module_spec, lldb::ModuleSP &module_sp, llvm::SmallVectorImpl< lldb::ModuleSP > *old_modules, bool *did_create_ptr, bool always_create=false, bool invoke_locate_callback=true)
bool FindMatchingModuleSpec(const ModuleSpec &module_spec, ModuleSpec &match_module_spec) const
uint64_t GetObjectOffset() const
FileSpec & GetPlatformFileSpec()
ArchSpec & GetArchitecture()
FileSpec & GetSymbolFileSpec()
uint64_t GetObjectSize() const
A class that describes an executable image and its associated object and symbol files.
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())
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
bool MatchAllProcesses() const
const FileSpec & GetShell() const
PseudoTerminal & GetPTY()
uint32_t GetResumeCount() 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.
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.
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.
virtual llvm::VersionTuple GetHostOSVersion()
Sometimes the connection to a process can detect the host OS version that the process is running on.
virtual ArchSpec GetSystemArchitecture()
Get the system architecture for this process.
lldb::OptionValuePropertiesSP m_collection_sp
T GetPropertyAtIndexAs(uint32_t idx, T default_value, const ExecutionContext *exe_ctx=nullptr) const
bool SetPropertyAtIndex(uint32_t idx, T t, const ExecutionContext *exe_ctx=nullptr) const
@ invalid_fd
Invalid file descriptor value.
int ReleasePrimaryFileDescriptor()
Release the primary file descriptor.
static Status FromErrorStringWithFormat(const char *format,...) __attribute__((format(printf
static Status FromErrorString(const char *str)
bool Fail() const
Test for error condition.
const char * AsCString(const char *default_error_str="unknown error") const
Get the error string associated with the current error.
static Status static Status FromErrorStringWithFormatv(const char *format, Args &&...args)
static Status FromError(llvm::Error error)
Avoid using this in new code. Migrate APIs to llvm::Expected instead.
const char * GetData() const
A stream class that can stream formatted output to a file.
void Format(const char *format, Args &&... args)
llvm::raw_ostream & AsRawOstream()
Returns a raw_ostream that forwards the data to this Stream object.
size_t Printf(const char *format,...) __attribute__((format(printf
Output printf formatted output to the stream.
size_t EOL()
Output and End of Line character to the stream.
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)
static ArchSpec GetDefaultArchitecture()
const ArchSpec & GetArchitecture() const
Represents UUID's of various sizes.
std::string GetAsString(llvm::StringRef separator="-") const
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 LLDB_INVALID_IMAGE_TOKEN
#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.
llvm::SmallVector< lldb::addr_t, 6 > MmapArgList
lldb::PlatformSP(* PlatformCreateInstance)(bool force, const ArchSpec *arch)
std::vector< ProcessInstanceInfo > ProcessInstanceInfoList
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
std::shared_ptr< lldb_private::Listener > ListenerSP
std::shared_ptr< lldb_private::WritableDataBuffer > WritableDataBufferSP
std::shared_ptr< lldb_private::Target > TargetSP
std::shared_ptr< lldb_private::Module > ModuleSP