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;
66#define LLDB_PROPERTIES_platform
67#include "TargetProperties.inc"
70#define LLDB_PROPERTIES_platform
71#include "TargetPropertiesEnum.inc"
78 return g_setting_name;
89 llvm::SmallString<64> 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");
101 const auto idx = ePropertyUseModuleCache;
102 return GetPropertyAtIndexAs<bool>(
103 idx, g_platform_properties[idx].default_uint_value != 0);
111 return GetPropertyAtIndexAs<FileSpec>(ePropertyModuleCacheDirectory, {});
115 return m_collection_sp->SetPropertyAtIndex(ePropertyModuleCacheDirectory,
121 auto f_spec_opt =
m_collection_sp->GetPropertyAtIndexAsOptionValueFileSpec(
122 ePropertyModuleCacheDirectory);
124 f_spec_opt->SetDefaultValue(dir_spec);
155 local_file = platform_file;
161 Stream *feedback_stream) {
205 module_search_paths_ptr, old_modules,
206 did_create_ptr,
false);
215 resolved_spec = spec;
220 module_search_paths_ptr, old_modules,
221 did_create_ptr,
false);
225 if (!
error.Success()) {
226 resolved_spec = spec;
228 module_search_paths_ptr, old_modules,
229 did_create_ptr,
false);
231 if (
error.Success() && module_sp)
232 module_sp->SetPlatformFileSpec(resolved_spec.
GetFileSpec());
253 lldb::PlatformSP platform_sp;
257 if (PlatformCreateInstance create_callback =
259 return create_callback(
true,
nullptr);
266 return HostInfo::GetAugmentedArchSpec(triple);
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),
279 LLDB_LOGF(log,
"%p Platform::Platform()",
static_cast<void *
>(
this));
297 if (!os_version.empty()) {
298 strm.
Format(
"OS Version: {0}", os_version.getAsString());
301 strm.
Format(
" ({0})", *s);
312 strm.
Printf(
" Connected: %s\n", is_connected ?
"yes" :
"no");
326 if (!specific_info.empty())
327 strm.
Printf(
"Platform-specific connection: %s\n", specific_info.c_str());
330 strm.
Format(
" Kernel: {0}\n", *s);
334 std::lock_guard<std::mutex> guard(
m_mutex);
358 fetch = is_connected;
372 return llvm::VersionTuple();
377 return HostInfo::GetOSBuildString();
383 return HostInfo::GetOSKernelDescription();
388 Target *target, std::vector<std::string> &options) {
389 std::vector<std::string> default_compilation_options = {
390 "-x",
"c++",
"-Xclang",
"-nostdsysteminc",
"-Xclang",
"-nostdsysteminc"};
392 options.insert(options.end(), default_compilation_options.begin(),
393 default_compilation_options.end());
398 llvm::SmallString<64> cwd;
399 if (llvm::sys::fs::current_path(cwd))
421 llvm::StringRef path) {
424 namespace fs = llvm::sys::fs;
426 case fs::file_type::fifo_file:
427 case fs::file_type::socket_file:
432 case fs::file_type::directory_file: {
438 dst_dir, lldb::eFilePermissionsDirectoryDefault);
441 "unable to setup directory %s on remote end",
447 std::string src_dir_path(src.
GetPath());
464 case fs::file_type::symlink_file: {
486 case fs::file_type::regular_file: {
501 "invalid file detected during copy: %s", src.
GetPath().c_str());
505 llvm_unreachable(
"Unhandled file_type!");
512 LLDB_LOGF(log,
"Platform::Install (src='%s', dst='%s')",
524 if (first_dst_dir_char ==
'/' || first_dst_dir_char ==
'\\') {
534 relative_spec = working_dir;
538 error.SetErrorStringWithFormat(
539 "platform working directory must be valid for relative path '%s'",
548 error.SetErrorStringWithFormat(
549 "platform working directory must be valid for relative path '%s'",
558 error.SetErrorStringWithFormat(
"platform working directory must be valid "
559 "when destination directory is empty");
564 LLDB_LOGF(log,
"Platform::Install (src='%s', dst='%s') fixed_dst='%s'",
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());
576 if (permissions == 0)
577 permissions = eFilePermissionsDirectoryDefault;
579 if (
error.Success()) {
584 std::string src_dir_path(src.
GetPath());
592 case fs::file_type::regular_file:
593 llvm::sys::fs::remove(fixed_dst.
GetPath());
597 case fs::file_type::symlink_file: {
598 llvm::sys::fs::remove(fixed_dst.
GetPath());
604 case fs::file_type::fifo_file:
605 error.SetErrorString(
"platform install doesn't handle pipes");
607 case fs::file_type::socket_file:
608 error.SetErrorString(
"platform install doesn't handle sockets");
611 error.SetErrorString(
612 "platform install doesn't handle non file or directory items");
623 if (std::error_code ec = llvm::sys::fs::set_current_path(file_spec.
GetPath())) {
624 LLDB_LOG(log,
"error: {0}", ec.message());
637 return llvm::sys::fs::create_directory(file_spec.
GetPath(), permissions);
640 error.SetErrorStringWithFormatv(
"remote platform {0} doesn't support {1}",
649 auto Value = llvm::sys::fs::getPermissions(file_spec.
GetPath());
651 file_permissions =
Value.get();
655 error.SetErrorStringWithFormatv(
"remote platform {0} doesn't support {1}",
664 auto Perms =
static_cast<llvm::sys::fs::perms
>(file_permissions);
665 return llvm::sys::fs::setPermissions(file_spec.
GetPath(), Perms);
668 error.SetErrorStringWithFormatv(
"remote platform {0} doesn't support {1}",
693 if (llvm::sys::fs::file_size(file_spec.
GetPath(), Size))
702 error.SetErrorStringWithFormatv(
703 "Platform::ReadFile() is not supported in the {0} platform",
709 const void *src, uint64_t src_len,
Status &
error) {
712 error.SetErrorStringWithFormatv(
713 "Platform::WriteFile() is not supported in the {0} platform",
720 return HostInfo::GetUserIDResolver();
739 LLDB_LOGF(log,
"Platform::SetRemoteWorkingDirectory('%s')",
740 working_dir.
GetPath().c_str());
769 lldb::ModuleSP &exe_module_sp,
776 module_search_paths_ptr,
nullptr,
788 module_search_paths_ptr,
nullptr,
791 if (
error.Success() && exe_module_sp)
796 error.SetErrorStringWithFormat(
804 lldb::ModuleSP &exe_module_sp,
820 module_search_paths_ptr,
nullptr,
823 if (exe_module_sp && exe_module_sp->GetObjectFile())
825 exe_module_sp.reset();
831 llvm::ListSeparator LS;
836 module_search_paths_ptr,
nullptr,
839 if (
error.Success()) {
840 if (exe_module_sp && exe_module_sp->GetObjectFile())
843 error.SetErrorToGenericError();
846 arch_names << LS << arch.GetArchitectureName();
849 if (
error.Fail() || !exe_module_sp) {
851 error.SetErrorStringWithFormatv(
852 "'{0}' doesn't contain any '{1}' platform architectures: {2}",
856 error.SetErrorStringWithFormatv(
"'{0}' is not readable",
861 error.SetErrorStringWithFormatv(
"'{0}' does not exist",
874 error.SetErrorString(
"unable to resolve symbol file");
880 resolved_platform_path = platform_path;
908 fetch = is_connected;
922 llvm::Triple normalized_triple(llvm::Triple::normalize(triple));
926 if (
auto kind = HostInfo::ParseArchitectureKind(triple))
927 return HostInfo::GetArchitecture(*kind);
935 if (!compatible_arch.
IsValid())
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());
951 error.SetErrorStringWithFormatv(
952 "The currently selected platform ({0}) is "
953 "the host platform and is always connected.",
956 error.SetErrorStringWithFormatv(
957 "Platform::ConnectRemote() is not supported by {0}",
GetPluginName());
964 error.SetErrorStringWithFormatv(
965 "The currently selected platform ({0}) is "
966 "the host platform and is always connected.",
969 error.SetErrorStringWithFormatv(
970 "Platform::DisconnectRemote() is not supported by {0}",
997 LLDB_LOGF(log,
"Platform::%s()", __FUNCTION__);
1002 if (::getenv(
"LLDB_LAUNCH_FLAG_LAUNCH_IN_TTY"))
1003 launch_info.
GetFlags().
Set(eLaunchFlagLaunchInTTY);
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;
1011 std::string shell_str = (shell) ? shell.
GetPath() :
"<null>";
1013 "Platform::%s GetResumeCountForLaunchInfo() returned %" PRIu32
1015 __FUNCTION__, num_resumes, shell_str.c_str());
1019 error, will_debug, first_arg_is_full_shell_command, num_resumes))
1021 }
else if (launch_info.
GetFlags().
Test(eLaunchFlagShellExpandArguments)) {
1024 error.SetErrorStringWithFormat(
"shell expansion failed (reason: %s). "
1025 "consider launching with 'process "
1027 error.AsCString(
"unknown"));
1032 LLDB_LOGF(log,
"Platform::%s final launch_info resume count: %" PRIu32,
1037 error.SetErrorString(
1038 "base lldb_private::Platform class can't launch remote processes");
1045 return Status(
"base lldb_private::Platform class can't expand arguments");
1050 LLDB_LOGF(log,
"Platform::%s, pid %" PRIu64, __FUNCTION__, pid);
1054 "base lldb_private::Platform class can't kill remote processes");
1064 LLDB_LOG(log,
"target = {0})", &target);
1066 ProcessSP process_sp;
1077 bool iteration_complete =
false;
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) {
1086 error = (*filter_callback)(launch_info, &target);
1087 if (!
error.Success()) {
1089 "Platform::%s() StructuredDataPlugin launch "
1098 if (
error.Success()) {
1100 "Platform::%s LaunchProcess() call succeeded (pid=%" PRIu64
")",
1104 process_sp =
Attach(attach_info, debugger, &target,
error);
1106 LLDB_LOG(log,
"Attach() succeeded, Process plugin: {0}",
1107 process_sp->GetPluginName());
1114 process_sp->SetShouldDetach(
false);
1122 process_sp->SetSTDIOFileDescriptor(pty_fd);
1125 LLDB_LOGF(log,
"Platform::%s Attach() failed: %s", __FUNCTION__,
1130 "Platform::%s LaunchProcess() returned launch_info with "
1131 "invalid process id",
1135 LLDB_LOGF(log,
"Platform::%s LaunchProcess() failed: %s", __FUNCTION__,
1142std::vector<ArchSpec>
1144 llvm::Triple::OSType os) {
1145 std::vector<ArchSpec> list;
1146 for(
auto arch : archs) {
1147 llvm::Triple triple;
1148 triple.setArch(arch);
1164 for (
const ArchSpec &platform_arch :
1166 if (arch.
IsMatch(platform_arch, match)) {
1167 if (compatible_arch_ptr)
1168 *compatible_arch_ptr = platform_arch;
1173 if (compatible_arch_ptr)
1174 compatible_arch_ptr->
Clear();
1181 LLDB_LOGF(log,
"[PutFile] Using block by block transfer....\n");
1183 auto source_open_options =
1185 namespace fs = llvm::sys::fs;
1186 if (fs::is_symlink_file(source.
GetPath()))
1190 lldb::eFilePermissionsUserRW);
1192 return Status(source_file.takeError());
1194 uint32_t permissions = source_file.get()->GetPermissions(
error);
1195 if (permissions == 0)
1196 permissions = lldb::eFilePermissionsFileDefault;
1201 permissions,
error);
1202 LLDB_LOGF(log,
"dest_file = %" PRIu64
"\n", dest_file);
1207 return Status(
"unable to open target file");
1208 lldb::WritableDataBufferSP buffer_sp(
new DataBufferHeap(1024 * 16, 0));
1209 uint64_t offset = 0;
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)
1216 const uint64_t bytes_written =
1217 WriteFile(dest_file, offset, buffer_sp->GetBytes(), bytes_read,
error);
1221 offset += bytes_written;
1222 if (bytes_written != bytes_read) {
1225 source_file.get()->SeekFromStart(offset);
1249 return Status(
"unimplemented");
1260 return llvm::sys::fs::remove(path.
GetPath());
1261 return Status(
"unimplemented");
1265 addr_t length,
unsigned prot,
1266 unsigned flags,
addr_t fd,
1268 uint64_t flags_platform = 0;
1274 MmapArgList args({addr, length, prot, flags_platform, fd, offset});
1279 llvm::StringRef command,
1288 return RunShellCommand(llvm::StringRef(), command, working_dir, status_ptr,
1289 signo_ptr, command_output, timeout);
1293 llvm::StringRef shell,
1295 llvm::StringRef command,
1306 signo_ptr, command_output, timeout);
1307 return Status(
"unable to run a remote command without a platform");
1314 auto Result = llvm::sys::fs::md5_contents(file_spec.
GetPath());
1317 std::tie(high, low) = Result->words();
1334 "Platform-specific options required for rsync to work."},
1337 "Platform-specific rsync prefix put before the remote path."},
1340 "Do not automatically fill in the remote hostname when composing the "
1349 "Platform-specific options required for SSH to work."},
1355 "Path in which to store local copies of files."},
1372 llvm::StringRef option_arg,
1375 char short_option = (char)
GetDefinitions()[option_idx].short_option;
1376 switch (short_option) {
1394 error.SetErrorStringWithFormat(
"unrecognized option '%c'", short_option);
1403 return lldb::BreakpointSP();
1418 llvm::StringRef option_arg,
1421 char short_option = (char)
GetDefinitions()[option_idx].short_option;
1422 switch (short_option) {
1432 error.SetErrorStringWithFormat(
"unrecognized option '%c'", short_option);
1449 uint32_t option_idx, llvm::StringRef option_arg,
1452 char short_option = (char)
GetDefinitions()[option_idx].short_option;
1453 switch (short_option) {
1459 error.SetErrorStringWithFormat(
"unrecognized option '%c'", short_option);
1474 std::lock_guard<std::mutex> guard(
m_mutex);
1485 lldb::ModuleSP &module_sp,
1489 module_spec,
nullptr, module_sp,
1492 module_search_paths_ptr);
1495 if (
error.Success()) {
1496 module_spec.
GetFileSpec() = module_sp->GetFileSpec();
1505 lldb::ModuleSP &module_sp,
1507 bool *did_create_ptr) {
1511 bool got_module_spec =
false;
1517 resolved_module_spec)) {
1520 got_module_spec =
true;
1536 if (
error.Success() && module_sp)
1540 resolved_module_spec = arch_module_spec;
1541 got_module_spec =
true;
1545 if (!got_module_spec) {
1548 resolved_module_spec)) {
1551 got_module_spec =
true;
1556 if (!got_module_spec) {
1559 return module_resolver(module_spec);
1569 const auto error = module_resolver(resolved_module_spec);
1579 lldb::ModuleSP &module_sp,
1580 bool *did_create_ptr) {
1591 const FileSpec &tmp_download_file_spec) {
1597 [
this](
const ModuleSP &module_sp,
1598 const FileSpec &tmp_download_file_spec) {
1601 module_sp, did_create_ptr);
1602 if (
error.Success())
1605 LLDB_LOGF(log,
"Platform::%s - module %s not found in local cache: %s",
1612 const uint64_t src_offset,
1613 const uint64_t src_size,
1618 llvm::raw_fd_ostream dst(dst_file_spec.
GetPath(), EC, llvm::sys::fs::OF_None);
1620 error.SetErrorStringWithFormat(
"unable to open destination file: %s",
1621 dst_file_spec.
GetPath().c_str());
1626 lldb::eFilePermissionsFileDefault,
error);
1629 error.SetErrorStringWithFormat(
"unable to open source file: %s",
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 =
1645 error.SetErrorString(
"read 0 bytes");
1649 total_bytes_read += n_read;
1650 dst.write(&buffer[0], n_read);
1662 "Symbol file downloading not supported by the default platform.");
1674 static const auto s_default_unix_signals_sp = std::make_shared<UnixSignals>();
1675 return s_default_unix_signals_sp;
1688 if (local_file && remote_file) {
1691 if (
IsRemote() || local_file != remote_file) {
1704 if (
IsRemote() || local_file != target_file) {
1717 error.SetErrorString(
"Neither local nor remote file was specified");
1723 const std::vector<std::string> *paths,
1726 error.SetErrorString(
"LoadImage is not supported on the current platform");
1732 const std::vector<std::string> &paths,
1742 file_to_use = remote_filename;
1749 return Status(
"UnloadImage is not supported on the current platform");
1753 llvm::StringRef plugin_name,
1756 return DoConnectProcess(connect_url, plugin_name, debugger,
nullptr, target,
1761 llvm::StringRef connect_url, llvm::StringRef plugin_name,
1763 return DoConnectProcess(connect_url, plugin_name, debugger, &stream, target,
1768 llvm::StringRef plugin_name,
1776 const char *triple =
1779 TargetSP new_target_sp;
1783 target = new_target_sp.get();
1784 if (!target ||
error.Fail()) {
1789 lldb::ProcessSP process_sp =
1796 const bool synchronous = stream !=
nullptr;
1798 ListenerSP listener_sp(
1801 process_sp->HijackProcessEvents(listener_sp);
1803 error = process_sp->ConnectRemote(connect_url);
1806 process_sp->RestoreProcessEvents();
1812 process_sp->WaitForProcessToStop(std::nullopt, &event_sp,
true, listener_sp,
1814 process_sp->RestoreProcessEvents();
1815 bool pop_process_io_handler =
false;
1834 const uint8_t *trap_opcode =
nullptr;
1835 size_t trap_opcode_size = 0;
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);
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);
1852 case llvm::Triple::arm: {
1855 static const uint8_t g_arm_breakpoint_opcode[] = {0xf0, 0x01, 0xf0, 0xe7};
1856 static const uint8_t g_thumb_breakpoint_opcode[] = {0x01, 0xde};
1862 addr_class = bp_loc_sp->GetAddress().GetAddressClass();
1864 (bp_loc_sp->GetAddress().GetFileAddress() & 1))
1869 trap_opcode = g_thumb_breakpoint_opcode;
1870 trap_opcode_size =
sizeof(g_thumb_breakpoint_opcode);
1872 trap_opcode = g_arm_breakpoint_opcode;
1873 trap_opcode_size =
sizeof(g_arm_breakpoint_opcode);
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);
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);
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);
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);
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);
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);
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);
1922 case llvm::Triple::ppc64le: {
1923 static const uint8_t g_ppc64le_opcode[] = {0x08, 0x00, 0xe0, 0x7f};
1924 trap_opcode = g_ppc64le_opcode;
1925 trap_opcode_size =
sizeof(g_ppc64le_opcode);
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);
1935 case llvm::Triple::riscv32:
1936 case llvm::Triple::riscv64: {
1937 static const uint8_t g_riscv_opcode[] = {0x73, 0x00, 0x10, 0x00};
1938 static const uint8_t g_riscv_opcode_c[] = {0x02, 0x90};
1940 trap_opcode = g_riscv_opcode_c;
1941 trap_opcode_size =
sizeof(g_riscv_opcode_c);
1943 trap_opcode = g_riscv_opcode;
1944 trap_opcode_size =
sizeof(g_riscv_opcode);
1948 case llvm::Triple::loongarch32:
1949 case llvm::Triple::loongarch64: {
1950 static const uint8_t g_loongarch_opcode[] = {0x05, 0x00, 0x2a,
1952 trap_opcode = g_loongarch_opcode;
1953 trap_opcode_size =
sizeof(g_loongarch_opcode);
1962 return trap_opcode_size;
1976 std::lock_guard<std::recursive_mutex> guard(
m_mutex);
1977 for (
const PlatformSP &platform_sp :
m_platforms) {
1978 if (platform_sp->GetName() == name)
1988 std::lock_guard<std::recursive_mutex> guard(
m_mutex);
1991 if (platform_sp->IsCompatibleArchitecture(
1998 if (platform_sp->IsCompatibleArchitecture(arch, process_host_arch,
2004 PlatformCreateInstance create_callback;
2010 PlatformSP platform_sp = create_callback(
false, &arch);
2012 platform_sp->IsCompatibleArchitecture(
2022 PlatformSP platform_sp = create_callback(
false, &arch);
2023 if (platform_sp && platform_sp->IsCompatibleArchitecture(
2025 platform_arch_ptr)) {
2030 if (platform_arch_ptr)
2031 platform_arch_ptr->
Clear();
2046 std::vector<PlatformSP> &candidates) {
2048 candidates.reserve(archs.size());
2057 for (
const ArchSpec &arch : archs) {
2065 if (host_platform_sp) {
2066 for (
const ArchSpec &arch : archs) {
2067 if (host_platform_sp->IsCompatibleArchitecture(
2069 return host_platform_sp;
2074 for (
const ArchSpec &arch : archs) {
2075 if (PlatformSP platform =
GetOrCreate(arch, process_host_arch,
nullptr))
2076 candidates.push_back(platform);
2082 if (candidates.size() == archs.size()) {
2083 if (llvm::all_of(candidates, [&](
const PlatformSP &p) ->
bool {
2084 return p->GetName() == candidates.front()->GetName();
2086 return candidates.front();
2097 std::lock_guard<std::recursive_mutex> guard(
m_mutex);
2105 std::lock_guard<std::recursive_mutex> guard(
m_mutex);
2107 PlatformCreateInstance create_callback;
2112 PlatformSP platform_sp = create_callback(
true, &arch);
2114 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 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.
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.
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()
@ 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
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
std::vector< ProcessInstanceInfo > ProcessInstanceInfoList
@ eErrorTypeGeneric
Generic errors that can be any value.