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;
101 return GetPropertyAtIndexAs<bool>(
102 idx, g_platform_properties[idx].default_uint_value != 0);
110 return GetPropertyAtIndexAs<FileSpec>(ePropertyModuleCacheDirectory, {});
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) {
204 module_search_paths_ptr, old_modules,
205 did_create_ptr,
false);
214 resolved_spec = spec;
218 module_search_paths_ptr, old_modules,
219 did_create_ptr,
false);
223 if (!
error.Success()) {
224 resolved_spec = spec;
226 module_search_paths_ptr, old_modules,
227 did_create_ptr,
false);
229 if (
error.Success() && module_sp)
230 module_sp->SetPlatformFileSpec(resolved_spec.
GetFileSpec());
257 return create_callback(
true,
nullptr);
264 return HostInfo::GetAugmentedArchSpec(triple);
269 : m_is_host(is_host), m_os_version_set_while_connected(false),
270 m_system_arch_set_while_connected(false), m_max_uid_name_len(0),
271 m_max_gid_name_len(0), m_supports_rsync(false), m_rsync_opts(),
272 m_rsync_prefix(), m_supports_ssh(false), m_ssh_opts(),
273 m_ignores_remote_hostname(false), m_trap_handlers(),
274 m_calculated_trap_handlers(false),
277 LLDB_LOGF(log,
"%p Platform::Platform()",
static_cast<void *
>(
this));
295 if (!os_version.empty()) {
296 strm.
Format(
"OS Version: {0}", os_version.getAsString());
299 strm.
Format(
" ({0})", *s);
310 strm.
Printf(
" Connected: %s\n", is_connected ?
"yes" :
"no");
314 strm.
Format(
" Sysroot: {0}\n", sdk_root);
324 if (!specific_info.empty())
325 strm.
Printf(
"Platform-specific connection: %s\n", specific_info.c_str());
328 strm.
Format(
" Kernel: {0}\n", *s);
332 std::lock_guard<std::mutex> guard(
m_mutex);
356 fetch = is_connected;
370 return llvm::VersionTuple();
375 return HostInfo::GetOSBuildString();
381 return HostInfo::GetOSKernelDescription();
386 Target *target, std::vector<std::string> &options) {
387 std::vector<std::string> default_compilation_options = {
388 "-x",
"c++",
"-Xclang",
"-nostdsysteminc",
"-Xclang",
"-nostdsysteminc"};
390 options.insert(options.end(), default_compilation_options.begin(),
391 default_compilation_options.end());
396 llvm::SmallString<64> cwd;
397 if (llvm::sys::fs::current_path(cwd))
419 llvm::StringRef path) {
422 namespace fs = llvm::sys::fs;
424 case fs::file_type::fifo_file:
425 case fs::file_type::socket_file:
430 case fs::file_type::directory_file: {
436 dst_dir, lldb::eFilePermissionsDirectoryDefault);
439 "unable to setup directory %s on remote end",
445 std::string src_dir_path(src.
GetPath());
462 case fs::file_type::symlink_file: {
484 case fs::file_type::regular_file: {
499 "invalid file detected during copy: %s", src.
GetPath().c_str());
503 llvm_unreachable(
"Unhandled file_type!");
510 LLDB_LOGF(log,
"Platform::Install (src='%s', dst='%s')",
522 if (first_dst_dir_char ==
'/' || first_dst_dir_char ==
'\\') {
532 relative_spec = working_dir;
536 error.SetErrorStringWithFormat(
537 "platform working directory must be valid for relative path '%s'",
546 error.SetErrorStringWithFormat(
547 "platform working directory must be valid for relative path '%s'",
556 error.SetErrorStringWithFormat(
"platform working directory must be valid "
557 "when destination directory is empty");
562 LLDB_LOGF(log,
"Platform::Install (src='%s', dst='%s') fixed_dst='%s'",
569 namespace fs = llvm::sys::fs;
570 switch (fs::get_file_type(src.
GetPath(),
false)) {
571 case fs::file_type::directory_file: {
572 llvm::sys::fs::remove(fixed_dst.
GetPath());
574 if (permissions == 0)
575 permissions = eFilePermissionsDirectoryDefault;
577 if (
error.Success()) {
582 std::string src_dir_path(src.
GetPath());
590 case fs::file_type::regular_file:
591 llvm::sys::fs::remove(fixed_dst.
GetPath());
595 case fs::file_type::symlink_file: {
596 llvm::sys::fs::remove(fixed_dst.
GetPath());
602 case fs::file_type::fifo_file:
603 error.SetErrorString(
"platform install doesn't handle pipes");
605 case fs::file_type::socket_file:
606 error.SetErrorString(
"platform install doesn't handle sockets");
609 error.SetErrorString(
610 "platform install doesn't handle non file or directory items");
621 if (std::error_code ec = llvm::sys::fs::set_current_path(file_spec.
GetPath())) {
622 LLDB_LOG(log,
"error: {0}", ec.message());
633 uint32_t permissions) {
635 return llvm::sys::fs::create_directory(file_spec.
GetPath(), permissions);
638 error.SetErrorStringWithFormatv(
"remote platform {0} doesn't support {1}",
645 uint32_t &file_permissions) {
647 auto Value = llvm::sys::fs::getPermissions(file_spec.
GetPath());
649 file_permissions =
Value.get();
653 error.SetErrorStringWithFormatv(
"remote platform {0} doesn't support {1}",
660 uint32_t file_permissions) {
662 auto Perms =
static_cast<llvm::sys::fs::perms
>(file_permissions);
663 return llvm::sys::fs::setPermissions(file_spec.
GetPath(), Perms);
666 error.SetErrorStringWithFormatv(
"remote platform {0} doesn't support {1}",
691 if (llvm::sys::fs::file_size(file_spec.
GetPath(), Size))
700 error.SetErrorStringWithFormatv(
701 "Platform::ReadFile() is not supported in the {0} platform",
707 const void *src, uint64_t src_len,
Status &
error) {
710 error.SetErrorStringWithFormatv(
711 "Platform::WriteFile() is not supported in the {0} platform",
718 return HostInfo::GetUserIDResolver();
737 LLDB_LOGF(log,
"Platform::SetRemoteWorkingDirectory('%s')",
738 working_dir.
GetPath().c_str());
774 module_search_paths_ptr,
nullptr,
786 module_search_paths_ptr,
nullptr,
789 if (
error.Success() && exe_module_sp)
794 error.SetErrorStringWithFormat(
818 module_search_paths_ptr,
nullptr,
821 if (exe_module_sp && exe_module_sp->GetObjectFile())
823 exe_module_sp.reset();
829 llvm::ListSeparator LS;
834 module_search_paths_ptr,
nullptr,
837 if (
error.Success()) {
838 if (exe_module_sp && exe_module_sp->GetObjectFile())
841 error.SetErrorToGenericError();
844 arch_names << LS << arch.GetArchitectureName();
847 if (
error.Fail() || !exe_module_sp) {
849 error.SetErrorStringWithFormatv(
850 "'{0}' doesn't contain any '{1}' platform architectures: {2}",
854 error.SetErrorStringWithFormatv(
"'{0}' is not readable",
859 error.SetErrorStringWithFormatv(
"'{0}' does not exist",
872 error.SetErrorString(
"unable to resolve symbol file");
878 resolved_platform_path = platform_path;
906 fetch = is_connected;
920 llvm::Triple normalized_triple(llvm::Triple::normalize(triple));
924 if (
auto kind = HostInfo::ParseArchitectureKind(triple))
925 return HostInfo::GetArchitecture(*kind);
933 if (!compatible_arch.
IsValid())
936 const llvm::Triple &compatible_triple = compatible_arch.
GetTriple();
937 if (normalized_triple.getVendorName().empty())
938 normalized_triple.setVendor(compatible_triple.getVendor());
939 if (normalized_triple.getOSName().empty())
940 normalized_triple.setOS(compatible_triple.getOS());
941 if (normalized_triple.getEnvironmentName().empty())
942 normalized_triple.setEnvironment(compatible_triple.getEnvironment());
949 error.SetErrorStringWithFormatv(
950 "The currently selected platform ({0}) is "
951 "the host platform and is always connected.",
954 error.SetErrorStringWithFormatv(
955 "Platform::ConnectRemote() is not supported by {0}",
GetPluginName());
962 error.SetErrorStringWithFormatv(
963 "The currently selected platform ({0}) is "
964 "the host platform and is always connected.",
967 error.SetErrorStringWithFormatv(
968 "Platform::DisconnectRemote() is not supported by {0}",
986 uint32_t match_count = 0;
1003 LLDB_LOGF(log,
"Platform::%s()", __FUNCTION__);
1008 if (::getenv(
"LLDB_LAUNCH_FLAG_LAUNCH_IN_TTY"))
1009 launch_info.
GetFlags().
Set(eLaunchFlagLaunchInTTY);
1011 if (launch_info.
GetFlags().
Test(eLaunchFlagLaunchInShell)) {
1012 const bool will_debug = launch_info.
GetFlags().
Test(eLaunchFlagDebug);
1013 const bool first_arg_is_full_shell_command =
false;
1017 std::string shell_str = (shell) ? shell.
GetPath() :
"<null>";
1019 "Platform::%s GetResumeCountForLaunchInfo() returned %" PRIu32
1021 __FUNCTION__, num_resumes, shell_str.c_str());
1025 error, will_debug, first_arg_is_full_shell_command, num_resumes))
1027 }
else if (launch_info.
GetFlags().
Test(eLaunchFlagShellExpandArguments)) {
1030 error.SetErrorStringWithFormat(
"shell expansion failed (reason: %s). "
1031 "consider launching with 'process "
1033 error.AsCString(
"unknown"));
1038 LLDB_LOGF(log,
"Platform::%s final launch_info resume count: %" PRIu32,
1043 error.SetErrorString(
1044 "base lldb_private::Platform class can't launch remote processes");
1051 return Status(
"base lldb_private::Platform class can't expand arguments");
1056 LLDB_LOGF(log,
"Platform::%s, pid %" PRIu64, __FUNCTION__, pid);
1060 "base lldb_private::Platform class can't kill remote processes");
1070 LLDB_LOG(log,
"target = {0}", &target);
1083 bool iteration_complete =
false;
1087 for (
auto filter_callback = get_filter_func(i, iteration_complete);
1088 !iteration_complete;
1089 filter_callback = get_filter_func(++i, iteration_complete)) {
1090 if (filter_callback) {
1092 error = (*filter_callback)(launch_info, &target);
1093 if (!
error.Success()) {
1095 "Platform::%s() StructuredDataPlugin launch "
1104 if (
error.Success()) {
1106 "Platform::%s LaunchProcess() call succeeded (pid=%" PRIu64
")",
1110 process_sp =
Attach(attach_info, debugger, &target,
error);
1112 LLDB_LOG(log,
"Attach() succeeded, Process plugin: {0}",
1113 process_sp->GetPluginName());
1120 process_sp->SetShouldDetach(
false);
1128 process_sp->SetSTDIOFileDescriptor(pty_fd);
1131 LLDB_LOGF(log,
"Platform::%s Attach() failed: %s", __FUNCTION__,
1136 "Platform::%s LaunchProcess() returned launch_info with "
1137 "invalid process id",
1141 LLDB_LOGF(log,
"Platform::%s LaunchProcess() failed: %s", __FUNCTION__,
1148std::vector<ArchSpec>
1150 llvm::Triple::OSType os) {
1151 std::vector<ArchSpec> list;
1152 for(
auto arch : archs) {
1153 llvm::Triple triple;
1154 triple.setArch(arch);
1170 for (
const ArchSpec &platform_arch :
1172 if (arch.
IsMatch(platform_arch, match)) {
1173 if (compatible_arch_ptr)
1174 *compatible_arch_ptr = platform_arch;
1179 if (compatible_arch_ptr)
1180 compatible_arch_ptr->
Clear();
1185 uint32_t uid, uint32_t gid) {
1187 LLDB_LOGF(log,
"[PutFile] Using block by block transfer....\n");
1189 auto source_open_options =
1191 namespace fs = llvm::sys::fs;
1192 if (fs::is_symlink_file(source.
GetPath()))
1196 lldb::eFilePermissionsUserRW);
1198 return Status(source_file.takeError());
1200 uint32_t permissions = source_file.get()->GetPermissions(
error);
1201 if (permissions == 0)
1202 permissions = lldb::eFilePermissionsFileDefault;
1207 permissions,
error);
1208 LLDB_LOGF(log,
"dest_file = %" PRIu64
"\n", dest_file);
1213 return Status(
"unable to open target file");
1215 uint64_t offset = 0;
1217 size_t bytes_read = buffer_sp->GetByteSize();
1218 error = source_file.get()->Read(buffer_sp->GetBytes(), bytes_read);
1219 if (
error.Fail() || bytes_read == 0)
1222 const uint64_t bytes_written =
1223 WriteFile(dest_file, offset, buffer_sp->GetBytes(), bytes_read,
error);
1227 offset += bytes_written;
1228 if (bytes_written != bytes_read) {
1231 source_file.get()->SeekFromStart(offset);
1255 return Status(
"unimplemented");
1266 return llvm::sys::fs::remove(path.
GetPath());
1267 return Status(
"unimplemented");
1271 addr_t length,
unsigned prot,
1272 unsigned flags,
addr_t fd,
1274 uint64_t flags_platform = 0;
1280 MmapArgList args({addr, length, prot, flags_platform, fd, offset});
1285 llvm::StringRef command,
1294 return RunShellCommand(llvm::StringRef(), command, working_dir, status_ptr,
1295 signo_ptr, command_output, timeout);
1299 llvm::StringRef shell,
1301 llvm::StringRef command,
1312 signo_ptr, command_output, timeout);
1313 return Status(
"unable to run a remote command without a platform");
1320 auto Result = llvm::sys::fs::md5_contents(file_spec.
GetPath());
1323 std::tie(high, low) = Result->words();
1340 "Platform-specific options required for rsync to work."},
1343 "Platform-specific rsync prefix put before the remote path."},
1346 "Do not automatically fill in the remote hostname when composing the "
1355 "Platform-specific options required for SSH to work."},
1361 "Path in which to store local copies of files."},
1378 llvm::StringRef option_arg,
1381 char short_option = (char)
GetDefinitions()[option_idx].short_option;
1382 switch (short_option) {
1400 error.SetErrorStringWithFormat(
"unrecognized option '%c'", short_option);
1424 llvm::StringRef option_arg,
1427 char short_option = (char)
GetDefinitions()[option_idx].short_option;
1428 switch (short_option) {
1438 error.SetErrorStringWithFormat(
"unrecognized option '%c'", short_option);
1455 uint32_t option_idx, llvm::StringRef option_arg,
1458 char short_option = (char)
GetDefinitions()[option_idx].short_option;
1459 switch (short_option) {
1465 error.SetErrorStringWithFormat(
"unrecognized option '%c'", short_option);
1480 std::lock_guard<std::mutex> guard(
m_mutex);
1495 module_spec,
nullptr, module_sp,
1498 module_search_paths_ptr);
1501 if (
error.Success()) {
1502 module_spec.
GetFileSpec() = module_sp->GetFileSpec();
1513 bool *did_create_ptr) {
1517 bool got_module_spec =
false;
1523 resolved_module_spec)) {
1526 got_module_spec =
true;
1542 if (
error.Success() && module_sp)
1546 resolved_module_spec = arch_module_spec;
1547 got_module_spec =
true;
1551 if (!got_module_spec) {
1554 resolved_module_spec)) {
1557 got_module_spec =
true;
1562 if (!got_module_spec) {
1565 return module_resolver(module_spec);
1580 symbol_file_spec, did_create_ptr);
1583 if (symbol_file_spec) {
1587 module_sp->SetSymbolFileFileSpec(symbol_file_spec);
1608 const Status error = module_resolver(resolved_module_spec);
1609 if (
error.Success()) {
1610 if (module_sp && symbol_file_spec) {
1613 module_sp->SetSymbolFileFileSpec(symbol_file_spec);
1620 if (module_sp && symbol_file_spec) {
1623 module_sp->SetSymbolFileFileSpec(symbol_file_spec);
1628 return Status(
"Failed to call GetCachedSharedModule");
1634 bool *did_create_ptr) {
1647 LLDB_LOGF(log,
"%s: locate module callback failed: %s",
1648 LLVM_PRETTY_FUNCTION,
error.AsCString());
1663 if (!module_file_spec && !symbol_file_spec) {
1667 "%s: locate module callback did not set both "
1668 "module_file_spec and symbol_file_spec",
1669 LLVM_PRETTY_FUNCTION);
1676 "%s: locate module callback set a non-existent file to "
1677 "module_file_spec: %s",
1678 LLVM_PRETTY_FUNCTION, module_file_spec.
GetPath().c_str());
1680 symbol_file_spec.
Clear();
1687 "%s: locate module callback set a non-existent file to "
1688 "symbol_file_spec: %s",
1689 LLVM_PRETTY_FUNCTION, symbol_file_spec.
GetPath().c_str());
1691 symbol_file_spec.
Clear();
1695 if (!module_file_spec && symbol_file_spec) {
1700 LLDB_LOGF(log,
"%s: locate module callback succeeded: symbol=%s",
1701 LLVM_PRETTY_FUNCTION, symbol_file_spec.
GetPath().c_str());
1711 auto cached_module_spec(module_spec);
1712 cached_module_spec.GetUUID().Clear();
1714 cached_module_spec.GetFileSpec() = module_file_spec;
1715 cached_module_spec.GetPlatformFileSpec() = module_spec.
GetFileSpec();
1716 cached_module_spec.SetObjectOffset(0);
1719 nullptr, did_create_ptr,
false);
1720 if (
error.Success() && module_sp) {
1722 LLDB_LOGF(log,
"%s: locate module callback succeeded: module=%s symbol=%s",
1723 LLVM_PRETTY_FUNCTION, module_file_spec.
GetPath().c_str(),
1724 symbol_file_spec.
GetPath().c_str());
1727 "%s: locate module callback succeeded but failed to load: "
1728 "module=%s symbol=%s",
1729 LLVM_PRETTY_FUNCTION, module_file_spec.
GetPath().c_str(),
1730 symbol_file_spec.
GetPath().c_str());
1733 symbol_file_spec.
Clear();
1739 bool *did_create_ptr) {
1750 const FileSpec &tmp_download_file_spec) {
1757 const FileSpec &tmp_download_file_spec) {
1760 module_sp, did_create_ptr);
1761 if (
error.Success())
1764 LLDB_LOGF(log,
"Platform::%s - module %s not found in local cache: %s",
1771 const uint64_t src_offset,
1772 const uint64_t src_size,
1777 llvm::raw_fd_ostream dst(dst_file_spec.
GetPath(), EC, llvm::sys::fs::OF_None);
1779 error.SetErrorStringWithFormat(
"unable to open destination file: %s",
1780 dst_file_spec.
GetPath().c_str());
1785 lldb::eFilePermissionsFileDefault,
error);
1788 error.SetErrorStringWithFormat(
"unable to open source file: %s",
1793 std::vector<char> buffer(512 * 1024);
1794 auto offset = src_offset;
1795 uint64_t total_bytes_read = 0;
1796 while (total_bytes_read < src_size) {
1797 const auto to_read = std::min(
static_cast<uint64_t
>(buffer.size()),
1798 src_size - total_bytes_read);
1799 const uint64_t n_read =
1804 error.SetErrorString(
"read 0 bytes");
1808 total_bytes_read += n_read;
1809 dst.write(&buffer[0], n_read);
1821 "Symbol file downloading not supported by the default platform.");
1833 static const auto s_default_unix_signals_sp = std::make_shared<UnixSignals>();
1834 return s_default_unix_signals_sp;
1847 if (local_file && remote_file) {
1850 if (
IsRemote() || local_file != remote_file) {
1863 if (
IsRemote() || local_file != target_file) {
1876 error.SetErrorString(
"Neither local nor remote file was specified");
1882 const std::vector<std::string> *paths,
1885 error.SetErrorString(
"LoadImage is not supported on the current platform");
1891 const std::vector<std::string> &paths,
1901 file_to_use = remote_filename;
1907 uint32_t image_token) {
1908 return Status(
"UnloadImage is not supported on the current platform");
1912 llvm::StringRef plugin_name,
1915 return DoConnectProcess(connect_url, plugin_name, debugger,
nullptr, target,
1920 llvm::StringRef connect_url, llvm::StringRef plugin_name,
1922 return DoConnectProcess(connect_url, plugin_name, debugger, &stream, target,
1927 llvm::StringRef plugin_name,
1935 const char *triple =
1942 target = new_target_sp.get();
1943 if (!target ||
error.Fail()) {
1955 const bool synchronous = stream !=
nullptr;
1960 process_sp->HijackProcessEvents(listener_sp);
1962 error = process_sp->ConnectRemote(connect_url);
1965 process_sp->RestoreProcessEvents();
1971 process_sp->WaitForProcessToStop(std::nullopt, &event_sp,
true, listener_sp,
1973 process_sp->RestoreProcessEvents();
1974 bool pop_process_io_handler =
false;
1993 const uint8_t *trap_opcode =
nullptr;
1994 size_t trap_opcode_size = 0;
1997 case llvm::Triple::aarch64_32:
1998 case llvm::Triple::aarch64: {
1999 static const uint8_t g_aarch64_opcode[] = {0x00, 0x00, 0x20, 0xd4};
2000 trap_opcode = g_aarch64_opcode;
2001 trap_opcode_size =
sizeof(g_aarch64_opcode);
2004 case llvm::Triple::arc: {
2005 static const uint8_t g_hex_opcode[] = { 0xff, 0x7f };
2006 trap_opcode = g_hex_opcode;
2007 trap_opcode_size =
sizeof(g_hex_opcode);
2011 case llvm::Triple::arm: {
2014 static const uint8_t g_arm_breakpoint_opcode[] = {0xf0, 0x01, 0xf0, 0xe7};
2015 static const uint8_t g_thumb_breakpoint_opcode[] = {0x01, 0xde};
2021 addr_class = bp_loc_sp->GetAddress().GetAddressClass();
2023 (bp_loc_sp->GetAddress().GetFileAddress() & 1))
2028 trap_opcode = g_thumb_breakpoint_opcode;
2029 trap_opcode_size =
sizeof(g_thumb_breakpoint_opcode);
2031 trap_opcode = g_arm_breakpoint_opcode;
2032 trap_opcode_size =
sizeof(g_arm_breakpoint_opcode);
2036 case llvm::Triple::avr: {
2037 static const uint8_t g_hex_opcode[] = {0x98, 0x95};
2038 trap_opcode = g_hex_opcode;
2039 trap_opcode_size =
sizeof(g_hex_opcode);
2042 case llvm::Triple::mips:
2043 case llvm::Triple::mips64: {
2044 static const uint8_t g_hex_opcode[] = {0x00, 0x00, 0x00, 0x0d};
2045 trap_opcode = g_hex_opcode;
2046 trap_opcode_size =
sizeof(g_hex_opcode);
2049 case llvm::Triple::mipsel:
2050 case llvm::Triple::mips64el: {
2051 static const uint8_t g_hex_opcode[] = {0x0d, 0x00, 0x00, 0x00};
2052 trap_opcode = g_hex_opcode;
2053 trap_opcode_size =
sizeof(g_hex_opcode);
2056 case llvm::Triple::msp430: {
2057 static const uint8_t g_msp430_opcode[] = {0x43, 0x43};
2058 trap_opcode = g_msp430_opcode;
2059 trap_opcode_size =
sizeof(g_msp430_opcode);
2062 case llvm::Triple::systemz: {
2063 static const uint8_t g_hex_opcode[] = {0x00, 0x01};
2064 trap_opcode = g_hex_opcode;
2065 trap_opcode_size =
sizeof(g_hex_opcode);
2068 case llvm::Triple::hexagon: {
2069 static const uint8_t g_hex_opcode[] = {0x0c, 0xdb, 0x00, 0x54};
2070 trap_opcode = g_hex_opcode;
2071 trap_opcode_size =
sizeof(g_hex_opcode);
2074 case llvm::Triple::ppc:
2075 case llvm::Triple::ppc64: {
2076 static const uint8_t g_ppc_opcode[] = {0x7f, 0xe0, 0x00, 0x08};
2077 trap_opcode = g_ppc_opcode;
2078 trap_opcode_size =
sizeof(g_ppc_opcode);
2081 case llvm::Triple::ppc64le: {
2082 static const uint8_t g_ppc64le_opcode[] = {0x08, 0x00, 0xe0, 0x7f};
2083 trap_opcode = g_ppc64le_opcode;
2084 trap_opcode_size =
sizeof(g_ppc64le_opcode);
2087 case llvm::Triple::x86:
2088 case llvm::Triple::x86_64: {
2089 static const uint8_t g_i386_opcode[] = {0xCC};
2090 trap_opcode = g_i386_opcode;
2091 trap_opcode_size =
sizeof(g_i386_opcode);
2094 case llvm::Triple::riscv32:
2095 case llvm::Triple::riscv64: {
2096 static const uint8_t g_riscv_opcode[] = {0x73, 0x00, 0x10, 0x00};
2097 static const uint8_t g_riscv_opcode_c[] = {0x02, 0x90};
2099 trap_opcode = g_riscv_opcode_c;
2100 trap_opcode_size =
sizeof(g_riscv_opcode_c);
2102 trap_opcode = g_riscv_opcode;
2103 trap_opcode_size =
sizeof(g_riscv_opcode);
2107 case llvm::Triple::loongarch32:
2108 case llvm::Triple::loongarch64: {
2109 static const uint8_t g_loongarch_opcode[] = {0x05, 0x00, 0x2a,
2111 trap_opcode = g_loongarch_opcode;
2112 trap_opcode_size =
sizeof(g_loongarch_opcode);
2121 return trap_opcode_size;
2143 std::lock_guard<std::recursive_mutex> guard(
m_mutex);
2145 if (platform_sp->GetName() == name)
2155 std::lock_guard<std::recursive_mutex> guard(
m_mutex);
2158 if (platform_sp->IsCompatibleArchitecture(
2165 if (platform_sp->IsCompatibleArchitecture(arch, process_host_arch,
2177 PlatformSP platform_sp = create_callback(
false, &arch);
2179 platform_sp->IsCompatibleArchitecture(
2189 PlatformSP platform_sp = create_callback(
false, &arch);
2190 if (platform_sp && platform_sp->IsCompatibleArchitecture(
2192 platform_arch_ptr)) {
2197 if (platform_arch_ptr)
2198 platform_arch_ptr->
Clear();
2213 std::vector<PlatformSP> &candidates) {
2215 candidates.reserve(archs.size());
2224 for (
const ArchSpec &arch : archs) {
2232 if (host_platform_sp) {
2233 for (
const ArchSpec &arch : archs) {
2234 if (host_platform_sp->IsCompatibleArchitecture(
2236 return host_platform_sp;
2241 for (
const ArchSpec &arch : archs) {
2243 candidates.push_back(platform);
2249 if (candidates.size() == archs.size()) {
2250 if (llvm::all_of(candidates, [&](
const PlatformSP &p) ->
bool {
2251 return p->GetName() == candidates.front()->GetName();
2253 return candidates.front();
2264 std::lock_guard<std::recursive_mutex> guard(
m_mutex);
2272 std::lock_guard<std::recursive_mutex> guard(
m_mutex);
2279 PlatformSP platform_sp = create_callback(
true, &arch);
2281 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, const FileSpecList *module_search_paths_ptr, llvm::SmallVectorImpl< lldb::ModuleSP > *old_modules, bool *did_create_ptr, bool always_create=false)
bool FindMatchingModuleSpec(const ModuleSpec &module_spec, ModuleSpec &match_module_spec) const
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 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
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.
int SetErrorStringWithFormat(const char *format,...) __attribute__((format(printf
Set the current error string to a formatted error string.
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.
void SetErrorString(llvm::StringRef err_str)
Set the current error string to err_str.
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
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