43 #include "llvm/ADT/STLExtras.h"
44 #include "llvm/Support/FileSystem.h"
45 #include "llvm/Support/Path.h"
50 #define MAP_ANON 0x1000
58 static PlatformSP g_platform_sp;
62 const char *Platform::GetHostPlatformName() {
return "host"; }
66 #define LLDB_PROPERTIES_platform
67 #include "TargetProperties.inc"
70 #define LLDB_PROPERTIES_platform
71 #include "TargetPropertiesEnum.inc"
78 return g_setting_name;
81 PlatformProperties::PlatformProperties() {
82 m_collection_sp = std::make_shared<OptionValueProperties>(GetSettingName());
83 m_collection_sp->Initialize(g_platform_properties);
85 auto module_cache_dir = GetModuleCacheDirectory();
89 llvm::SmallString<64> user_home_dir;
90 if (!FileSystem::Instance().GetHomeDirectory(user_home_dir))
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);
100 bool PlatformProperties::GetUseModuleCache()
const {
101 const auto idx = ePropertyUseModuleCache;
102 return m_collection_sp->GetPropertyAtIndexAsBoolean(
103 nullptr, idx, g_platform_properties[idx].default_uint_value != 0);
106 bool PlatformProperties::SetUseModuleCache(
bool use_module_cache) {
107 return m_collection_sp->SetPropertyAtIndexAsBoolean(
108 nullptr, ePropertyUseModuleCache, use_module_cache);
111 FileSpec PlatformProperties::GetModuleCacheDirectory()
const {
112 return m_collection_sp->GetPropertyAtIndexAsFileSpec(
113 nullptr, ePropertyModuleCacheDirectory);
116 bool PlatformProperties::SetModuleCacheDirectory(
const FileSpec &dir_spec) {
117 return m_collection_sp->SetPropertyAtIndexAsFileSpec(
118 nullptr, ePropertyModuleCacheDirectory, dir_spec);
121 void PlatformProperties::SetDefaultModuleCacheDirectory(
123 auto f_spec_opt = m_collection_sp->GetPropertyAtIndexAsOptionValueFileSpec(
124 nullptr,
false, ePropertyModuleCacheDirectory);
126 f_spec_opt->SetDefaultValue(dir_spec);
139 void Platform::Initialize() {}
141 void Platform::Terminate() {}
148 void Platform::SetHostPlatform(
const lldb::PlatformSP &platform_sp) {
157 local_file = platform_file;
162 Platform::LocateExecutableScriptingResources(
Target *target,
Module &module,
163 Stream *feedback_stream) {
164 return FileSpecList();
203 const FileSpecList *module_search_paths_ptr,
206 return ModuleList::GetSharedModule(module_spec, module_sp,
207 module_search_paths_ptr, old_modules,
208 did_create_ptr,
false);
217 resolved_spec = spec;
219 m_sdk_sysroot.GetStringRef());
221 error = ModuleList::GetSharedModule(resolved_spec, module_sp,
222 module_search_paths_ptr, old_modules,
223 did_create_ptr,
false);
227 if (!
error.Success()) {
228 resolved_spec = spec;
229 error = ModuleList::GetSharedModule(resolved_spec, module_sp,
230 module_search_paths_ptr, old_modules,
231 did_create_ptr,
false);
233 if (
error.Success() && module_sp)
234 module_sp->SetPlatformFileSpec(resolved_spec.
GetFileSpec());
238 return GetRemoteSharedModule(module_spec, process, module_sp, resolver,
242 bool Platform::GetModuleSpec(
const FileSpec &module_file_spec,
245 if (ObjectFile::GetModuleSpecifications(module_file_spec, 0, 0,
254 PlatformSP Platform::Create(llvm::StringRef name) {
255 lldb::PlatformSP platform_sp;
256 if (name == GetHostPlatformName())
257 return GetHostPlatform();
259 if (PlatformCreateInstance create_callback =
260 PluginManager::GetPlatformCreateCallbackForPluginName(name))
261 return create_callback(
true,
nullptr);
268 return HostInfo::GetAugmentedArchSpec(triple);
272 Platform::Platform(
bool is_host)
273 : m_is_host(is_host), m_os_version_set_while_connected(false),
274 m_system_arch_set_while_connected(false), m_max_uid_name_len(0),
275 m_max_gid_name_len(0), m_supports_rsync(false), m_rsync_opts(),
276 m_rsync_prefix(), m_supports_ssh(false), m_ssh_opts(),
277 m_ignores_remote_hostname(false), m_trap_handlers(),
278 m_calculated_trap_handlers(false),
281 LLDB_LOGF(log,
"%p Platform::Platform()",
static_cast<void *
>(
this));
299 if (!os_version.empty()) {
300 strm.
Format(
"OS Version: {0}", os_version.getAsString());
303 strm.
Format(
" ({0})", *s);
314 strm.
Printf(
" Connected: %s\n", is_connected ?
"yes" :
"no");
328 if (!specific_info.empty())
329 strm.
Printf(
"Platform-specific connection: %s\n", specific_info.c_str());
332 strm.
Format(
" Kernel: {0}\n", *s);
336 std::lock_guard<std::mutex> guard(
m_mutex);
360 fetch = is_connected;
374 return llvm::VersionTuple();
379 return HostInfo::GetOSBuildString();
385 return HostInfo::GetOSKernelDescription();
390 Target *target, std::vector<std::string> &options) {
391 std::vector<std::string> default_compilation_options = {
392 "-x",
"c++",
"-Xclang",
"-nostdsysteminc",
"-Xclang",
"-nostdsysteminc"};
394 options.insert(options.end(), default_compilation_options.begin(),
395 default_compilation_options.end());
400 llvm::SmallString<64> cwd;
401 if (llvm::sys::fs::current_path(cwd))
423 llvm::StringRef path) {
426 namespace fs = llvm::sys::fs;
428 case fs::file_type::fifo_file:
429 case fs::file_type::socket_file:
434 case fs::file_type::directory_file: {
440 dst_dir, lldb::eFilePermissionsDirectoryDefault);
443 "unable to setup directory %s on remote end",
466 case fs::file_type::symlink_file: {
488 case fs::file_type::regular_file: {
503 "invalid file detected during copy: %s", src.
GetPath().c_str());
507 llvm_unreachable(
"Unhandled file_type!");
514 LLDB_LOGF(log,
"Platform::Install (src='%s', dst='%s')",
526 if (first_dst_dir_char ==
'/' || first_dst_dir_char ==
'\\') {
536 relative_spec = working_dir;
540 error.SetErrorStringWithFormat(
541 "platform working directory must be valid for relative path '%s'",
550 error.SetErrorStringWithFormat(
551 "platform working directory must be valid for relative path '%s'",
560 error.SetErrorStringWithFormat(
"platform working directory must be valid "
561 "when destination directory is empty");
566 LLDB_LOGF(log,
"Platform::Install (src='%s', dst='%s') fixed_dst='%s'",
573 namespace fs = llvm::sys::fs;
574 switch (fs::get_file_type(src.
GetPath(),
false)) {
575 case fs::file_type::directory_file: {
576 llvm::sys::fs::remove(fixed_dst.
GetPath());
578 if (permissions == 0)
579 permissions = eFilePermissionsDirectoryDefault;
581 if (
error.Success()) {
594 case fs::file_type::regular_file:
595 llvm::sys::fs::remove(fixed_dst.
GetPath());
599 case fs::file_type::symlink_file: {
600 llvm::sys::fs::remove(fixed_dst.
GetPath());
606 case fs::file_type::fifo_file:
607 error.SetErrorString(
"platform install doesn't handle pipes");
609 case fs::file_type::socket_file:
610 error.SetErrorString(
"platform install doesn't handle sockets");
613 error.SetErrorString(
614 "platform install doesn't handle non file or directory items");
625 if (std::error_code ec = llvm::sys::fs::set_current_path(file_spec.
GetPath())) {
626 LLDB_LOG(log,
"error: {0}", ec.message());
639 return llvm::sys::fs::create_directory(file_spec.
GetPath(), permissions);
642 error.SetErrorStringWithFormatv(
"remote platform {0} doesn't support {1}",
651 auto Value = llvm::sys::fs::getPermissions(file_spec.
GetPath());
653 file_permissions =
Value.get();
657 error.SetErrorStringWithFormatv(
"remote platform {0} doesn't support {1}",
666 auto Perms =
static_cast<llvm::sys::fs::perms
>(file_permissions);
667 return llvm::sys::fs::setPermissions(file_spec.
GetPath(), Perms);
670 error.SetErrorStringWithFormatv(
"remote platform {0} doesn't support {1}",
695 if (llvm::sys::fs::file_size(file_spec.
GetPath(), Size))
704 error.SetErrorStringWithFormatv(
705 "Platform::ReadFile() is not supported in the {0} platform",
711 const void *src, uint64_t src_len,
Status &
error) {
714 error.SetErrorStringWithFormatv(
715 "Platform::WriteFile() is not supported in the {0} platform",
722 return HostInfo::GetUserIDResolver();
741 LLDB_LOGF(log,
"Platform::SetRemoteWorkingDirectory('%s')",
742 working_dir.
GetPath().c_str());
771 lldb::ModuleSP &exe_module_sp,
772 const FileSpecList *module_search_paths_ptr) {
778 module_search_paths_ptr,
nullptr,
790 module_search_paths_ptr,
nullptr,
793 if (
error.Success() && exe_module_sp)
798 error.SetErrorStringWithFormat(
806 lldb::ModuleSP &exe_module_sp,
807 const FileSpecList *module_search_paths_ptr) {
822 module_search_paths_ptr,
nullptr,
825 if (exe_module_sp && exe_module_sp->GetObjectFile())
827 exe_module_sp.reset();
833 llvm::ListSeparator LS;
838 module_search_paths_ptr,
nullptr,
841 if (
error.Success()) {
842 if (exe_module_sp && exe_module_sp->GetObjectFile())
845 error.SetErrorToGenericError();
848 arch_names << LS << arch.GetArchitectureName();
851 if (
error.Fail() || !exe_module_sp) {
853 error.SetErrorStringWithFormatv(
854 "'{0}' doesn't contain any '{1}' platform architectures: {2}",
858 error.SetErrorStringWithFormatv(
"'{0}' is not readable",
863 error.SetErrorStringWithFormatv(
"'{0}' does not exist",
876 error.SetErrorString(
"unable to resolve symbol file");
882 resolved_platform_path = platform_path;
910 fetch = is_connected;
924 llvm::Triple normalized_triple(llvm::Triple::normalize(triple));
928 if (
auto kind = HostInfo::ParseArchitectureKind(triple))
929 return HostInfo::GetArchitecture(*kind);
937 if (!compatible_arch.
IsValid())
940 const llvm::Triple &compatible_triple = compatible_arch.
GetTriple();
941 if (normalized_triple.getVendorName().empty())
942 normalized_triple.setVendor(compatible_triple.getVendor());
943 if (normalized_triple.getOSName().empty())
944 normalized_triple.setOS(compatible_triple.getOS());
945 if (normalized_triple.getEnvironmentName().empty())
946 normalized_triple.setEnvironment(compatible_triple.getEnvironment());
953 error.SetErrorStringWithFormatv(
954 "The currently selected platform ({0}) is "
955 "the host platform and is always connected.",
958 error.SetErrorStringWithFormatv(
959 "Platform::ConnectRemote() is not supported by {0}",
GetPluginName());
966 error.SetErrorStringWithFormatv(
967 "The currently selected platform ({0}) is "
968 "the host platform and is always connected.",
971 error.SetErrorStringWithFormatv(
972 "Platform::DisconnectRemote() is not supported by {0}",
999 LLDB_LOGF(log,
"Platform::%s()", __FUNCTION__);
1004 if (::getenv(
"LLDB_LAUNCH_FLAG_LAUNCH_IN_TTY"))
1005 launch_info.
GetFlags().
Set(eLaunchFlagLaunchInTTY);
1007 if (launch_info.
GetFlags().
Test(eLaunchFlagLaunchInShell)) {
1008 const bool will_debug = launch_info.
GetFlags().
Test(eLaunchFlagDebug);
1009 const bool first_arg_is_full_shell_command =
false;
1015 "Platform::%s GetResumeCountForLaunchInfo() returned %" PRIu32
1017 __FUNCTION__, num_resumes, shell_str.c_str());
1021 error, will_debug, first_arg_is_full_shell_command, num_resumes))
1023 }
else if (launch_info.
GetFlags().
Test(eLaunchFlagShellExpandArguments)) {
1026 error.SetErrorStringWithFormat(
"shell expansion failed (reason: %s). "
1027 "consider launching with 'process "
1029 error.AsCString(
"unknown"));
1034 LLDB_LOGF(log,
"Platform::%s final launch_info resume count: %" PRIu32,
1039 error.SetErrorString(
1040 "base lldb_private::Platform class can't launch remote processes");
1047 return Status(
"base lldb_private::Platform class can't expand arguments");
1052 LLDB_LOGF(log,
"Platform::%s, pid %" PRIu64, __FUNCTION__, pid);
1056 "base lldb_private::Platform class can't kill remote processes");
1066 LLDB_LOG(log,
"target = {0})", &target);
1068 ProcessSP process_sp;
1079 bool iteration_complete =
false;
1083 for (
auto filter_callback = get_filter_func(i, iteration_complete);
1084 !iteration_complete;
1085 filter_callback = get_filter_func(++i, iteration_complete)) {
1086 if (filter_callback) {
1088 error = (*filter_callback)(launch_info, &target);
1089 if (!
error.Success()) {
1091 "Platform::%s() StructuredDataPlugin launch "
1100 if (
error.Success()) {
1102 "Platform::%s LaunchProcess() call succeeded (pid=%" PRIu64
")",
1106 process_sp =
Attach(attach_info, debugger, &target,
error);
1108 LLDB_LOG(log,
"Attach() succeeded, Process plugin: {0}",
1109 process_sp->GetPluginName());
1116 process_sp->SetShouldDetach(
false);
1124 process_sp->SetSTDIOFileDescriptor(pty_fd);
1127 LLDB_LOGF(log,
"Platform::%s Attach() failed: %s", __FUNCTION__,
1132 "Platform::%s LaunchProcess() returned launch_info with "
1133 "invalid process id",
1137 LLDB_LOGF(log,
"Platform::%s LaunchProcess() failed: %s", __FUNCTION__,
1144 std::vector<ArchSpec>
1146 llvm::Triple::OSType os) {
1147 std::vector<ArchSpec>
list;
1148 for(
auto arch : archs) {
1149 llvm::Triple triple;
1150 triple.setArch(arch);
1166 for (
const ArchSpec &platform_arch :
1168 if (arch.
IsMatch(platform_arch, match)) {
1169 if (compatible_arch_ptr)
1170 *compatible_arch_ptr = platform_arch;
1175 if (compatible_arch_ptr)
1176 compatible_arch_ptr->
Clear();
1183 LLDB_LOGF(log,
"[PutFile] Using block by block transfer....\n");
1185 auto source_open_options =
1187 namespace fs = llvm::sys::fs;
1188 if (fs::is_symlink_file(source.
GetPath()))
1192 lldb::eFilePermissionsUserRW);
1194 return Status(source_file.takeError());
1196 uint32_t permissions = source_file.get()->GetPermissions(
error);
1197 if (permissions == 0)
1198 permissions = lldb::eFilePermissionsFileDefault;
1203 permissions,
error);
1204 LLDB_LOGF(log,
"dest_file = %" PRIu64
"\n", dest_file);
1209 return Status(
"unable to open target file");
1210 lldb::WritableDataBufferSP buffer_sp(
new DataBufferHeap(1024 * 16, 0));
1211 uint64_t offset = 0;
1213 size_t bytes_read = buffer_sp->GetByteSize();
1214 error = source_file.get()->Read(buffer_sp->GetBytes(), bytes_read);
1215 if (
error.Fail() || bytes_read == 0)
1218 const uint64_t bytes_written =
1219 WriteFile(dest_file, offset, buffer_sp->GetBytes(), bytes_read,
error);
1223 offset += bytes_written;
1224 if (bytes_written != bytes_read) {
1227 source_file.get()->SeekFromStart(offset);
1251 return Status(
"unimplemented");
1262 return llvm::sys::fs::remove(path.
GetPath());
1263 return Status(
"unimplemented");
1267 addr_t length,
unsigned prot,
1268 unsigned flags,
addr_t fd,
1270 uint64_t flags_platform = 0;
1276 MmapArgList args({addr, length, prot, flags_platform, fd, offset});
1281 llvm::StringRef command,
1290 return RunShellCommand(llvm::StringRef(), command, working_dir, status_ptr,
1291 signo_ptr, command_output, timeout);
1295 llvm::StringRef shell,
1297 llvm::StringRef command,
1308 signo_ptr, command_output, timeout);
1309 return Status(
"unable to run a remote command without a platform");
1316 auto Result = llvm::sys::fs::md5_contents(file_spec.
GetPath());
1319 std::tie(high, low) = Result->words();
1336 "Platform-specific options required for rsync to work."},
1339 "Platform-specific rsync prefix put before the remote path."},
1342 "Do not automatically fill in the remote hostname when composing the "
1351 "Platform-specific options required for SSH to work."},
1357 "Path in which to store local copies of files."},
1374 llvm::StringRef option_arg,
1377 char short_option = (char)
GetDefinitions()[option_idx].short_option;
1378 switch (short_option) {
1396 error.SetErrorStringWithFormat(
"unrecognized option '%c'", short_option);
1405 return lldb::BreakpointSP();
1420 llvm::StringRef option_arg,
1423 char short_option = (char)
GetDefinitions()[option_idx].short_option;
1424 switch (short_option) {
1434 error.SetErrorStringWithFormat(
"unrecognized option '%c'", short_option);
1451 uint32_t option_idx, llvm::StringRef option_arg,
1454 char short_option = (char)
GetDefinitions()[option_idx].short_option;
1455 switch (short_option) {
1461 error.SetErrorStringWithFormat(
"unrecognized option '%c'", short_option);
1476 std::lock_guard<std::mutex> guard(
m_mutex);
1487 lldb::ModuleSP &module_sp,
1488 const FileSpecList *module_search_paths_ptr) {
1491 module_spec,
nullptr, module_sp,
1494 module_search_paths_ptr);
1497 if (
error.Success()) {
1498 module_spec.
GetFileSpec() = module_sp->GetFileSpec();
1507 lldb::ModuleSP &module_sp,
1509 bool *did_create_ptr) {
1513 bool got_module_spec =
false;
1519 resolved_module_spec)) {
1522 got_module_spec =
true;
1538 if (
error.Success() && module_sp)
1542 resolved_module_spec = arch_module_spec;
1543 got_module_spec =
true;
1547 if (!got_module_spec) {
1550 resolved_module_spec)) {
1553 got_module_spec =
true;
1558 if (!got_module_spec) {
1561 return module_resolver(module_spec);
1571 const auto error = module_resolver(resolved_module_spec);
1581 lldb::ModuleSP &module_sp,
1582 bool *did_create_ptr) {
1593 const FileSpec &tmp_download_file_spec) {
1599 [
this](
const ModuleSP &module_sp,
1600 const FileSpec &tmp_download_file_spec) {
1603 module_sp, did_create_ptr);
1604 if (
error.Success())
1607 LLDB_LOGF(log,
"Platform::%s - module %s not found in local cache: %s",
1614 const uint64_t src_offset,
1615 const uint64_t src_size,
1620 llvm::raw_fd_ostream dst(dst_file_spec.
GetPath(), EC, llvm::sys::fs::OF_None);
1622 error.SetErrorStringWithFormat(
"unable to open destination file: %s",
1623 dst_file_spec.
GetPath().c_str());
1628 lldb::eFilePermissionsFileDefault,
error);
1631 error.SetErrorStringWithFormat(
"unable to open source file: %s",
1636 std::vector<char> buffer(1024);
1637 auto offset = src_offset;
1638 uint64_t total_bytes_read = 0;
1639 while (total_bytes_read < src_size) {
1640 const auto to_read = std::min(
static_cast<uint64_t
>(buffer.size()),
1641 src_size - total_bytes_read);
1642 const uint64_t n_read =
1647 error.SetErrorString(
"read 0 bytes");
1651 total_bytes_read += n_read;
1652 dst.write(&buffer[0], n_read);
1664 "Symbol file downloading not supported by the default platform.");
1676 static const auto s_default_unix_signals_sp = std::make_shared<UnixSignals>();
1677 return s_default_unix_signals_sp;
1690 if (local_file && remote_file) {
1693 if (
IsRemote() || local_file != remote_file) {
1706 if (
IsRemote() || local_file != target_file) {
1719 error.SetErrorString(
"Neither local nor remote file was specified");
1725 const std::vector<std::string> *paths,
1728 error.SetErrorString(
"LoadImage is not supported on the current platform");
1734 const std::vector<std::string> &paths,
1744 file_to_use = remote_filename;
1751 return Status(
"UnloadImage is not supported on the current platform");
1755 llvm::StringRef plugin_name,
1758 return DoConnectProcess(connect_url, plugin_name, debugger,
nullptr, target,
1763 llvm::StringRef connect_url, llvm::StringRef plugin_name,
1765 return DoConnectProcess(connect_url, plugin_name, debugger, &stream, target,
1770 llvm::StringRef plugin_name,
1778 const char *triple =
1781 TargetSP new_target_sp;
1785 target = new_target_sp.get();
1786 if (!target ||
error.Fail()) {
1791 lldb::ProcessSP process_sp =
1798 const bool synchronous = stream !=
nullptr;
1800 ListenerSP listener_sp(
1803 process_sp->HijackProcessEvents(listener_sp);
1805 error = process_sp->ConnectRemote(connect_url);
1808 process_sp->RestoreProcessEvents();
1814 process_sp->WaitForProcessToStop(std::nullopt, &event_sp,
true, listener_sp,
1816 process_sp->RestoreProcessEvents();
1817 bool pop_process_io_handler =
false;
1819 pop_process_io_handler);
1835 const uint8_t *trap_opcode =
nullptr;
1836 size_t trap_opcode_size = 0;
1839 case llvm::Triple::aarch64_32:
1840 case llvm::Triple::aarch64: {
1841 static const uint8_t g_aarch64_opcode[] = {0x00, 0x00, 0x20, 0xd4};
1842 trap_opcode = g_aarch64_opcode;
1843 trap_opcode_size =
sizeof(g_aarch64_opcode);
1846 case llvm::Triple::arc: {
1847 static const uint8_t g_hex_opcode[] = { 0xff, 0x7f };
1848 trap_opcode = g_hex_opcode;
1849 trap_opcode_size =
sizeof(g_hex_opcode);
1853 case llvm::Triple::arm: {
1856 static const uint8_t g_arm_breakpoint_opcode[] = {0xf0, 0x01, 0xf0, 0xe7};
1857 static const uint8_t g_thumb_breakpoint_opcode[] = {0x01, 0xde};
1863 addr_class = bp_loc_sp->GetAddress().GetAddressClass();
1865 (bp_loc_sp->GetAddress().GetFileAddress() & 1))
1870 trap_opcode = g_thumb_breakpoint_opcode;
1871 trap_opcode_size =
sizeof(g_thumb_breakpoint_opcode);
1873 trap_opcode = g_arm_breakpoint_opcode;
1874 trap_opcode_size =
sizeof(g_arm_breakpoint_opcode);
1878 case llvm::Triple::avr: {
1879 static const uint8_t g_hex_opcode[] = {0x98, 0x95};
1880 trap_opcode = g_hex_opcode;
1881 trap_opcode_size =
sizeof(g_hex_opcode);
1884 case llvm::Triple::mips:
1885 case llvm::Triple::mips64: {
1886 static const uint8_t g_hex_opcode[] = {0x00, 0x00, 0x00, 0x0d};
1887 trap_opcode = g_hex_opcode;
1888 trap_opcode_size =
sizeof(g_hex_opcode);
1891 case llvm::Triple::mipsel:
1892 case llvm::Triple::mips64el: {
1893 static const uint8_t g_hex_opcode[] = {0x0d, 0x00, 0x00, 0x00};
1894 trap_opcode = g_hex_opcode;
1895 trap_opcode_size =
sizeof(g_hex_opcode);
1898 case llvm::Triple::systemz: {
1899 static const uint8_t g_hex_opcode[] = {0x00, 0x01};
1900 trap_opcode = g_hex_opcode;
1901 trap_opcode_size =
sizeof(g_hex_opcode);
1904 case llvm::Triple::hexagon: {
1905 static const uint8_t g_hex_opcode[] = {0x0c, 0xdb, 0x00, 0x54};
1906 trap_opcode = g_hex_opcode;
1907 trap_opcode_size =
sizeof(g_hex_opcode);
1910 case llvm::Triple::ppc:
1911 case llvm::Triple::ppc64: {
1912 static const uint8_t g_ppc_opcode[] = {0x7f, 0xe0, 0x00, 0x08};
1913 trap_opcode = g_ppc_opcode;
1914 trap_opcode_size =
sizeof(g_ppc_opcode);
1917 case llvm::Triple::ppc64le: {
1918 static const uint8_t g_ppc64le_opcode[] = {0x08, 0x00, 0xe0, 0x7f};
1919 trap_opcode = g_ppc64le_opcode;
1920 trap_opcode_size =
sizeof(g_ppc64le_opcode);
1923 case llvm::Triple::x86:
1924 case llvm::Triple::x86_64: {
1925 static const uint8_t g_i386_opcode[] = {0xCC};
1926 trap_opcode = g_i386_opcode;
1927 trap_opcode_size =
sizeof(g_i386_opcode);
1930 case llvm::Triple::riscv32:
1931 case llvm::Triple::riscv64: {
1932 static const uint8_t g_riscv_opcode[] = {0x73, 0x00, 0x10, 0x00};
1933 static const uint8_t g_riscv_opcode_c[] = {0x02, 0x90};
1935 trap_opcode = g_riscv_opcode_c;
1936 trap_opcode_size =
sizeof(g_riscv_opcode_c);
1938 trap_opcode = g_riscv_opcode;
1939 trap_opcode_size =
sizeof(g_riscv_opcode);
1943 case llvm::Triple::loongarch32:
1944 case llvm::Triple::loongarch64: {
1945 static const uint8_t g_loongarch_opcode[] = {0x05, 0x00, 0x2a,
1947 trap_opcode = g_loongarch_opcode;
1948 trap_opcode_size =
sizeof(g_loongarch_opcode);
1957 return trap_opcode_size;
1971 std::lock_guard<std::recursive_mutex> guard(
m_mutex);
1972 for (
const PlatformSP &platform_sp :
m_platforms) {
1973 if (platform_sp->GetName() == name)
1983 std::lock_guard<std::recursive_mutex> guard(
m_mutex);
1986 if (platform_sp->IsCompatibleArchitecture(
1993 if (platform_sp->IsCompatibleArchitecture(arch, process_host_arch,
1999 PlatformCreateInstance create_callback;
2005 PlatformSP platform_sp = create_callback(
false, &arch);
2007 platform_sp->IsCompatibleArchitecture(
2017 PlatformSP platform_sp = create_callback(
false, &arch);
2018 if (platform_sp && platform_sp->IsCompatibleArchitecture(
2020 platform_arch_ptr)) {
2025 if (platform_arch_ptr)
2026 platform_arch_ptr->
Clear();
2041 std::vector<PlatformSP> &candidates) {
2043 candidates.reserve(archs.size());
2052 for (
const ArchSpec &arch : archs) {
2060 if (host_platform_sp) {
2061 for (
const ArchSpec &arch : archs) {
2062 if (host_platform_sp->IsCompatibleArchitecture(
2064 return host_platform_sp;
2069 for (
const ArchSpec &arch : archs) {
2070 if (PlatformSP platform =
GetOrCreate(arch, process_host_arch,
nullptr))
2071 candidates.push_back(platform);
2077 if (candidates.size() == archs.size()) {
2078 if (llvm::all_of(candidates, [&](
const PlatformSP &p) ->
bool {
2079 return p->GetName() == candidates.front()->GetName();
2081 return candidates.front();
2092 std::lock_guard<std::recursive_mutex> guard(
m_mutex);
2100 std::lock_guard<std::recursive_mutex> guard(
m_mutex);
2102 PlatformCreateInstance create_callback;
2107 PlatformSP platform_sp = create_callback(
true, &arch);
2109 if (platform_sp->LoadPlatformBinaryAndSetup(process, addr, notify))