47#include "llvm/ADT/ArrayRef.h"
48#include "llvm/ADT/STLExtras.h"
49#include "llvm/Support/FileSystem.h"
50#include "llvm/Support/FormatVariadic.h"
51#include "llvm/Support/Path.h"
56#define MAP_ANON 0x1000
72#define LLDB_PROPERTIES_platform
73#include "TargetProperties.inc"
76#define LLDB_PROPERTIES_platform
77#include "TargetPropertiesEnum.inc"
83 static constexpr llvm::StringLiteral g_setting_name(
"platform");
84 return g_setting_name;
95 llvm::SmallString<64> user_home_dir;
99 module_cache_dir =
FileSpec(user_home_dir.c_str());
100 module_cache_dir.AppendPathComponent(
".lldb");
101 module_cache_dir.AppendPathComponent(
"module_cache");
107 const auto idx = ePropertyUseModuleCache;
109 idx, g_platform_properties[idx].default_uint_value != 0);
121 return m_collection_sp->SetPropertyAtIndex(ePropertyModuleCacheDirectory,
126 const auto idx = ePropertyShellExpandTimeout;
128 idx, g_platform_properties[idx].default_uint_value);
131 return std::chrono::seconds(seconds);
136 auto f_spec_opt =
m_collection_sp->GetPropertyAtIndexAsOptionValueFileSpec(
137 ePropertyModuleCacheDirectory);
139 f_spec_opt->SetDefaultValue(dir_spec);
170 local_file = platform_file;
184 .value_or(default_load_style);
187llvm::SmallDenseMap<FileSpec, LoadScriptFromSymFile>
193 llvm::SmallDenseMap<FileSpec, LoadScriptFromSymFile> file_specs;
208 for (
FileSpec path : llvm::reverse(paths)) {
226 orig_script_fspec, script_fspec);
231 file_specs.try_emplace(std::move(script_fspec), load_style);
242llvm::SmallDenseMap<FileSpec, LoadScriptFromSymFile>
245 llvm::SmallDenseMap<FileSpec, LoadScriptFromSymFile> empty;
249llvm::SmallDenseMap<FileSpec, LoadScriptFromSymFile>
251 Stream &feedback_stream) {
252 llvm::SmallDenseMap<FileSpec, LoadScriptFromSymFile> empty;
258 target, module, feedback_stream);
262 const FileSpec &module_spec =
module.GetFileSpec();
267 module_spec, *target);
287 resolved_spec = spec;
296 if (!
error.Success()) {
297 resolved_spec = spec;
302 if (
error.Success() && module_sp)
303 module_sp->SetPlatformFileSpec(resolved_spec.
GetFileSpec());
328 return create_callback(
true,
nullptr);
335 return HostInfo::GetAugmentedArchSpec(triple);
348 LLDB_LOGF(log,
"%p Platform::Platform()",
static_cast<void *
>(
this));
366 if (!os_version.empty()) {
367 strm.
Format(
"OS Version: {0}", os_version.getAsString());
370 strm.
Format(
" ({0})", *s);
381 strm.
Printf(
" Connected: %s\n", is_connected ?
"yes" :
"no");
385 strm.
Format(
" Sysroot: {0}\n", sdk_root);
395 if (!specific_info.empty())
396 strm.
Printf(
"Platform-specific connection: %s\n", specific_info.c_str());
399 strm.
Format(
" Kernel: {0}\n", *s);
403 std::lock_guard<std::mutex> guard(
m_mutex);
427 fetch = is_connected;
441 return llvm::VersionTuple();
446 return HostInfo::GetOSBuildString();
452 return HostInfo::GetOSKernelDescription();
457 Target *target, std::vector<std::string> &options) {
458 std::vector<std::string> default_compilation_options = {
459 "-x",
"c++",
"-Xclang",
"-nostdsysteminc",
"-Xclang",
"-nostdsysteminc"};
461 options.insert(options.end(), default_compilation_options.begin(),
462 default_compilation_options.end());
467 llvm::SmallString<64> cwd;
468 if (llvm::sys::fs::current_path(cwd))
490 llvm::StringRef path) {
493 namespace fs = llvm::sys::fs;
495 case fs::file_type::fifo_file:
496 case fs::file_type::socket_file:
501 case fs::file_type::directory_file: {
507 dst_dir, lldb::eFilePermissionsDirectoryDefault);
510 "unable to setup directory {0} on remote end", dst_dir.
GetPath());
515 std::string src_dir_path(src.
GetPath());
532 case fs::file_type::symlink_file: {
554 case fs::file_type::regular_file: {
569 "invalid file detected during copy: %s", src.
GetPath().c_str());
573 llvm_unreachable(
"Unhandled file_type!");
580 LLDB_LOGF(log,
"Platform::Install (src='%s', dst='%s')",
591 const char first_dst_dir_char = dst.
GetDirectory().front();
592 if (first_dst_dir_char ==
'/' || first_dst_dir_char ==
'\\') {
601 relative_spec = working_dir;
606 "platform working directory must be valid for relative path '%s'",
616 "platform working directory must be valid for relative path '%s'",
627 "when destination directory is empty");
632 LLDB_LOGF(log,
"Platform::Install (src='%s', dst='%s') fixed_dst='%s'",
639 namespace fs = llvm::sys::fs;
640 switch (fs::get_file_type(src.
GetPath(),
false)) {
641 case fs::file_type::directory_file: {
642 llvm::sys::fs::remove(fixed_dst.
GetPath());
644 if (permissions == 0)
645 permissions = eFilePermissionsDirectoryDefault;
647 if (
error.Success()) {
652 std::string src_dir_path(src.
GetPath());
656 return std::move(baton.
error);
660 case fs::file_type::regular_file:
661 llvm::sys::fs::remove(fixed_dst.
GetPath());
665 case fs::file_type::symlink_file: {
666 llvm::sys::fs::remove(fixed_dst.
GetPath());
672 case fs::file_type::fifo_file:
675 case fs::file_type::socket_file:
681 "platform install doesn't handle non file or directory items");
692 if (std::error_code ec = llvm::sys::fs::set_current_path(file_spec.
GetPath())) {
693 LLDB_LOG(log,
"error: {0}", ec.message());
704 uint32_t permissions) {
706 return llvm::sys::fs::create_directory(file_spec.
GetPath(), permissions);
711 LLVM_PRETTY_FUNCTION);
717 uint32_t &file_permissions) {
719 auto Value = llvm::sys::fs::getPermissions(file_spec.
GetPath());
721 file_permissions =
Value.get();
727 LLVM_PRETTY_FUNCTION);
733 uint32_t file_permissions) {
735 auto Perms =
static_cast<llvm::sys::fs::perms
>(file_permissions);
736 return llvm::sys::fs::setPermissions(file_spec.
GetPath(), Perms);
741 LLVM_PRETTY_FUNCTION);
765 if (llvm::sys::fs::file_size(file_spec.
GetPath(), Size))
775 "Platform::ReadFile() is not supported in the {0} platform",
781 const void *src, uint64_t src_len,
Status &
error) {
785 "Platform::WriteFile() is not supported in the {0} platform",
792 return HostInfo::GetUserIDResolver();
806 return basename.str();
811 LLDB_LOGF(log,
"Platform::SetRemoteWorkingDirectory('%s')",
812 working_dir.
GetPath().c_str());
852 "'{0}' does not exist", resolved_module_spec.
GetFileSpec());
857 exe_module_sp,
nullptr,
nullptr);
859 if (exe_module_sp && exe_module_sp->GetObjectFile())
861 exe_module_sp.reset();
867 llvm::ListSeparator LS;
875 if (
error.Success()) {
876 if (exe_module_sp && exe_module_sp->GetObjectFile())
881 arch_names << LS << arch.GetArchitectureName();
884 if (exe_module_sp &&
error.Success())
889 "'{0}' is not readable", resolved_module_spec.
GetFileSpec());
893 "'{0}' is not a valid executable", resolved_module_spec.
GetFileSpec());
896 "'{0}' doesn't contain any '{1}' platform architectures: {2}",
913 resolved_platform_path = platform_path;
941 fetch = is_connected;
955 llvm::Triple normalized_triple(llvm::Triple::normalize(triple));
959 if (
auto kind = HostInfo::ParseArchitectureKind(triple))
960 return HostInfo::GetArchitecture(*kind);
968 if (!compatible_arch.
IsValid())
971 const llvm::Triple &compatible_triple = compatible_arch.
GetTriple();
972 if (normalized_triple.getVendorName().empty())
973 normalized_triple.setVendor(compatible_triple.getVendor());
974 if (normalized_triple.getOSName().empty())
975 normalized_triple.setOS(compatible_triple.getOS());
976 if (normalized_triple.getEnvironmentName().empty())
977 normalized_triple.setEnvironment(compatible_triple.getEnvironment());
985 "The currently selected platform ({0}) is "
986 "the host platform and is always connected.",
990 "Platform::ConnectRemote() is not supported by {0}",
GetPluginName());
998 "The currently selected platform ({0}) is "
999 "the host platform and is always connected.",
1003 "Platform::DisconnectRemote() is not supported by {0}",
1021 uint32_t match_count = 0;
1038 LLDB_LOGF(log,
"Platform::%s()", __FUNCTION__);
1043 if (::getenv(
"LLDB_LAUNCH_FLAG_LAUNCH_IN_TTY"))
1044 launch_info.
GetFlags().
Set(eLaunchFlagLaunchInTTY);
1046 if (launch_info.
GetFlags().
Test(eLaunchFlagLaunchInShell)) {
1047 const bool will_debug = launch_info.
GetFlags().
Test(eLaunchFlagDebug);
1048 const bool first_arg_is_full_shell_command =
false;
1052 std::string shell_str = (shell) ? shell.
GetPath() :
"<null>";
1054 "Platform::%s GetResumeCountForLaunchInfo() returned %" PRIu32
1056 __FUNCTION__, num_resumes, shell_str.c_str());
1060 error, will_debug, first_arg_is_full_shell_command, num_resumes))
1062 }
else if (launch_info.
GetFlags().
Test(eLaunchFlagShellExpandArguments)) {
1066 "shell expansion failed (reason: %s). "
1067 "consider launching with 'process "
1069 error.AsCString(
"unknown"));
1074 LLDB_LOGF(log,
"Platform::%s final launch_info resume count: %" PRIu32,
1080 "base lldb_private::Platform class can't launch remote processes");
1089 "base lldb_private::Platform class can't expand arguments");
1094 LLDB_LOGF(log,
"Platform::%s, pid %" PRIu64, __FUNCTION__, pid);
1098 "base lldb_private::Platform class can't kill remote processes");
1108 LLDB_LOG(log,
"target = {0}", &target);
1121 if (cbs.filter_callback) {
1123 error = (*cbs.filter_callback)(launch_info, &target);
1124 if (!
error.Success()) {
1126 "Platform::%s() StructuredDataPlugin launch "
1135 if (
error.Success()) {
1137 "Platform::%s LaunchProcess() call succeeded (pid=%" PRIu64
")",
1141 process_sp =
Attach(attach_info, debugger, &target,
error);
1143 LLDB_LOG(log,
"Attach() succeeded, Process plugin: {0}",
1144 process_sp->GetPluginName());
1151 process_sp->SetShouldDetach(
false);
1160 process_sp->SetSTDIOFileDescriptor(pty_fd);
1164 LLDB_LOGF(log,
"Platform::%s Attach() failed: %s", __FUNCTION__,
1169 "Platform::%s LaunchProcess() returned launch_info with "
1170 "invalid process id",
1174 LLDB_LOGF(log,
"Platform::%s LaunchProcess() failed: %s", __FUNCTION__,
1181std::vector<ArchSpec>
1183 llvm::Triple::OSType os) {
1184 std::vector<ArchSpec> list;
1185 for(
auto arch : archs) {
1186 llvm::Triple triple;
1187 triple.setArch(arch);
1203 for (
const ArchSpec &platform_arch :
1205 if (arch.
IsMatch(platform_arch, match)) {
1206 if (compatible_arch_ptr)
1207 *compatible_arch_ptr = platform_arch;
1212 if (compatible_arch_ptr)
1213 compatible_arch_ptr->
Clear();
1218 uint32_t uid, uint32_t gid) {
1220 LLDB_LOGF(log,
"[PutFile] Using block by block transfer....\n");
1222 auto source_open_options =
1224 namespace fs = llvm::sys::fs;
1225 if (fs::is_symlink_file(source.
GetPath()))
1229 lldb::eFilePermissionsUserRW);
1234 bool requires_upload =
true;
1235 llvm::ErrorOr<llvm::MD5::MD5Result> remote_md5 =
CalculateMD5(destination);
1236 if (std::error_code ec = remote_md5.getError()) {
1237 LLDB_LOG(log,
"[PutFile] couldn't get md5 sum of destination: {0}",
1240 llvm::ErrorOr<llvm::MD5::MD5Result> local_md5 =
1241 llvm::sys::fs::md5_contents(source.
GetPath());
1242 if (std::error_code ec = local_md5.getError()) {
1243 LLDB_LOG(log,
"[PutFile] couldn't get md5 sum of source: {0}",
1246 LLDB_LOGF(log,
"[PutFile] destination md5: %016" PRIx64
"%016" PRIx64,
1247 remote_md5->high(), remote_md5->low());
1248 LLDB_LOGF(log,
"[PutFile] local md5: %016" PRIx64
"%016" PRIx64,
1249 local_md5->high(), local_md5->low());
1250 requires_upload = *remote_md5 != *local_md5;
1254 if (!requires_upload) {
1255 LLDB_LOGF(log,
"[PutFile] skipping PutFile because md5sums match");
1259 uint32_t permissions = source_file.get()->GetPermissions(
error);
1260 if (permissions == 0)
1261 permissions = lldb::eFilePermissionsUserRWX;
1266 permissions,
error);
1267 LLDB_LOGF(log,
"dest_file = %" PRIu64
"\n", dest_file);
1274 uint64_t offset = 0;
1276 size_t bytes_read = buffer_sp->GetByteSize();
1277 error = source_file.get()->Read(buffer_sp->GetBytes(), bytes_read);
1278 if (
error.Fail() || bytes_read == 0)
1281 const uint64_t bytes_written =
1282 WriteFile(dest_file, offset, buffer_sp->GetBytes(), bytes_read,
error);
1286 offset += bytes_written;
1287 if (bytes_written != bytes_read) {
1290 source_file.get()->SeekFromStart(offset);
1324 return llvm::sys::fs::remove(path.
GetPath());
1329 addr_t length,
unsigned prot,
1330 unsigned flags,
addr_t fd,
1332 uint64_t flags_platform = 0;
1338 MmapArgList args({addr, length, prot, flags_platform, fd, offset});
1343 llvm::StringRef command,
1351 std::string *separated_error_output,
1354 return RunShellCommand(llvm::StringRef(), command, working_dir, status_ptr,
1355 signo_ptr, command_output, separated_error_output,
1360 llvm::StringRef shell,
1362 llvm::StringRef command,
1370 std::string *separated_error_output,
1375 signo_ptr, command_output,
1376 separated_error_output, timeout);
1378 "unable to run a remote command without a platform");
1381llvm::ErrorOr<llvm::MD5::MD5Result>
1384 return std::make_error_code(std::errc::not_supported);
1385 return llvm::sys::fs::md5_contents(file_spec.
GetPath());
1401 "Platform-specific options required for rsync to work."},
1404 "Platform-specific rsync prefix put before the remote path."},
1407 "Do not automatically fill in the remote hostname when composing the "
1416 "Platform-specific options required for SSH to work."},
1422 "Path in which to store local copies of files."},
1439 llvm::StringRef option_arg,
1442 char short_option = (char)
GetDefinitions()[option_idx].short_option;
1443 switch (short_option) {
1486 llvm::StringRef option_arg,
1489 char short_option = (char)
GetDefinitions()[option_idx].short_option;
1490 switch (short_option) {
1518 uint32_t option_idx, llvm::StringRef option_arg,
1521 char short_option = (char)
GetDefinitions()[option_idx].short_option;
1522 switch (short_option) {
1544 std::lock_guard<std::mutex> guard(
m_mutex);
1557 module_spec,
nullptr, module_sp,
1562 if (
error.Success()) {
1563 module_spec.
GetFileSpec() = module_sp->GetFileSpec();
1574 bool *did_create_ptr) {
1578 bool got_module_spec =
false;
1580 process_host_arch = process->GetSystemArchitecture();
1582 if (process->GetModuleSpec(module_spec.
GetFileSpec(),
1584 resolved_module_spec)) {
1587 got_module_spec =
true;
1603 if (
error.Success() && module_sp)
1607 resolved_module_spec = arch_module_spec;
1608 got_module_spec =
true;
1612 if (!got_module_spec) {
1615 resolved_module_spec)) {
1618 got_module_spec =
true;
1623 if (!got_module_spec) {
1626 return module_resolver(module_spec);
1645 symbol_file_spec, did_create_ptr);
1648 if (symbol_file_spec) {
1652 module_sp->SetSymbolFileFileSpec(symbol_file_spec);
1673 Status error = module_resolver(resolved_module_spec);
1674 if (
error.Success()) {
1675 if (module_sp && symbol_file_spec) {
1678 module_sp->SetSymbolFileFileSpec(symbol_file_spec);
1685 if (module_sp && symbol_file_spec) {
1688 module_sp->SetSymbolFileFileSpec(symbol_file_spec);
1694 "Failed to call GetCachedSharedModule");
1700 bool *did_create_ptr) {
1713 LLDB_LOGF(log,
"%s: locate module callback failed: %s",
1714 LLVM_PRETTY_FUNCTION,
error.AsCString());
1729 if (!module_file_spec && !symbol_file_spec) {
1733 "%s: locate module callback did not set both "
1734 "module_file_spec and symbol_file_spec",
1735 LLVM_PRETTY_FUNCTION);
1742 "%s: locate module callback set a non-existent file to "
1743 "module_file_spec: %s",
1744 LLVM_PRETTY_FUNCTION, module_file_spec.
GetPath().c_str());
1746 symbol_file_spec.
Clear();
1753 "%s: locate module callback set a non-existent file to "
1754 "symbol_file_spec: %s",
1755 LLVM_PRETTY_FUNCTION, symbol_file_spec.
GetPath().c_str());
1757 symbol_file_spec.
Clear();
1761 if (!module_file_spec && symbol_file_spec) {
1766 LLDB_LOGF(log,
"%s: locate module callback succeeded: symbol=%s",
1767 LLVM_PRETTY_FUNCTION, symbol_file_spec.
GetPath().c_str());
1777 auto cached_module_spec(module_spec);
1778 cached_module_spec.GetUUID().Clear();
1780 cached_module_spec.GetFileSpec() = module_file_spec;
1781 cached_module_spec.GetSymbolFileSpec() = symbol_file_spec;
1782 cached_module_spec.GetPlatformFileSpec() = module_spec.
GetFileSpec();
1783 cached_module_spec.SetObjectOffset(0);
1786 did_create_ptr,
false);
1787 if (
error.Success() && module_sp) {
1789 LLDB_LOGF(log,
"%s: locate module callback succeeded: module=%s symbol=%s",
1790 LLVM_PRETTY_FUNCTION, module_file_spec.
GetPath().c_str(),
1791 symbol_file_spec.
GetPath().c_str());
1794 "%s: locate module callback succeeded but failed to load: "
1795 "module=%s symbol=%s",
1796 LLVM_PRETTY_FUNCTION, module_file_spec.
GetPath().c_str(),
1797 symbol_file_spec.
GetPath().c_str());
1800 symbol_file_spec.
Clear();
1806 bool *did_create_ptr) {
1817 const FileSpec &tmp_download_file_spec) {
1824 const FileSpec &tmp_download_file_spec) {
1827 module_sp, did_create_ptr);
1828 if (
error.Success())
1831 LLDB_LOGF(log,
"Platform::%s - module %s not found in local cache: %s",
1838 const uint64_t src_offset,
1839 const uint64_t src_size,
1844 llvm::raw_fd_ostream dst(dst_file_spec.
GetPath(), EC, llvm::sys::fs::OF_None);
1847 "unable to open destination file: %s", dst_file_spec.
GetPath().c_str());
1852 lldb::eFilePermissionsFileDefault,
error);
1860 std::vector<char> buffer(512 * 1024);
1861 auto offset = src_offset;
1862 uint64_t total_bytes_read = 0;
1863 while (total_bytes_read < src_size) {
1864 const auto to_read = std::min(
static_cast<uint64_t
>(buffer.size()),
1865 src_size - total_bytes_read);
1866 const uint64_t n_read =
1875 total_bytes_read += n_read;
1876 dst.write(&buffer[0], n_read);
1888 "Symbol file downloading not supported by the default platform.");
1900 static const auto s_default_unix_signals_sp = std::make_shared<UnixSignals>();
1901 return s_default_unix_signals_sp;
1914 if (local_file && remote_file) {
1917 if (
IsRemote() || local_file != remote_file) {
1930 if (
IsRemote() || local_file != target_file) {
1950 const std::vector<std::string> *paths,
1954 "LoadImage is not supported on the current platform");
1960 const std::vector<std::string> &paths,
1969 file_to_use = remote_filename;
1975 uint32_t image_token) {
1977 "UnloadImage is not supported on the current platform");
1981 llvm::StringRef plugin_name,
1984 return DoConnectProcess(connect_url, plugin_name, debugger,
nullptr, target,
1989 llvm::StringRef connect_url, llvm::StringRef plugin_name,
1991 return DoConnectProcess(connect_url, plugin_name, debugger, &stream, target,
1996 llvm::StringRef plugin_name,
2004 const char *triple =
2011 target = new_target_sp.get();
2012 if (!target ||
error.Fail()) {
2024 const bool synchronous = stream !=
nullptr;
2029 process_sp->HijackProcessEvents(listener_sp);
2031 error = process_sp->ConnectRemote(connect_url);
2034 process_sp->RestoreProcessEvents();
2040 process_sp->WaitForProcessToStop(std::nullopt, &event_sp,
true, listener_sp,
2042 process_sp->RestoreProcessEvents();
2043 bool pop_process_io_handler =
false;
2060 llvm::ArrayRef<uint8_t> trap_opcode;
2063 case llvm::Triple::aarch64_32:
2064 case llvm::Triple::aarch64: {
2065 static const uint8_t g_aarch64_opcode[] = {0x00, 0x00, 0x20, 0xd4};
2067 llvm::ArrayRef<uint8_t>(g_aarch64_opcode,
sizeof(g_aarch64_opcode));
2070 case llvm::Triple::arc: {
2071 static const uint8_t g_hex_opcode[] = {0xff, 0x7f};
2072 trap_opcode = llvm::ArrayRef<uint8_t>(g_hex_opcode,
sizeof(g_hex_opcode));
2075 case llvm::Triple::arm: {
2079 static const uint8_t g_arm_breakpoint_opcode[] = {0xf0, 0x01, 0xf0, 0xe7};
2080 static const uint8_t g_thumb_breakpoint_opcode[] = {0x01, 0xde};
2082 if (size_hint == 2) {
2083 trap_opcode = llvm::ArrayRef<uint8_t>(g_thumb_breakpoint_opcode,
2084 sizeof(g_thumb_breakpoint_opcode));
2086 trap_opcode = llvm::ArrayRef<uint8_t>(g_arm_breakpoint_opcode,
2087 sizeof(g_arm_breakpoint_opcode));
2091 case llvm::Triple::avr: {
2092 static const uint8_t g_hex_opcode[] = {0x98, 0x95};
2093 trap_opcode = llvm::ArrayRef<uint8_t>(g_hex_opcode,
sizeof(g_hex_opcode));
2096 case llvm::Triple::mips:
2097 case llvm::Triple::mips64: {
2098 static const uint8_t g_hex_opcode[] = {0x00, 0x00, 0x00, 0x0d};
2099 trap_opcode = llvm::ArrayRef<uint8_t>(g_hex_opcode,
sizeof(g_hex_opcode));
2102 case llvm::Triple::mipsel:
2103 case llvm::Triple::mips64el: {
2104 static const uint8_t g_hex_opcode[] = {0x0d, 0x00, 0x00, 0x00};
2105 trap_opcode = llvm::ArrayRef<uint8_t>(g_hex_opcode,
sizeof(g_hex_opcode));
2108 case llvm::Triple::msp430: {
2109 static const uint8_t g_msp430_opcode[] = {0x43, 0x43};
2111 llvm::ArrayRef<uint8_t>(g_msp430_opcode,
sizeof(g_msp430_opcode));
2114 case llvm::Triple::systemz: {
2115 static const uint8_t g_hex_opcode[] = {0x00, 0x01};
2116 trap_opcode = llvm::ArrayRef<uint8_t>(g_hex_opcode,
sizeof(g_hex_opcode));
2119 case llvm::Triple::hexagon: {
2120 static const uint8_t g_hex_opcode[] = {0x0c, 0xdb, 0x00, 0x54};
2121 trap_opcode = llvm::ArrayRef<uint8_t>(g_hex_opcode,
sizeof(g_hex_opcode));
2124 case llvm::Triple::ppc:
2125 case llvm::Triple::ppc64: {
2126 static const uint8_t g_ppc_opcode[] = {0x7f, 0xe0, 0x00, 0x08};
2127 trap_opcode = llvm::ArrayRef<uint8_t>(g_ppc_opcode,
sizeof(g_ppc_opcode));
2130 case llvm::Triple::ppc64le: {
2131 static const uint8_t g_ppc64le_opcode[] = {0x08, 0x00, 0xe0, 0x7f};
2133 llvm::ArrayRef<uint8_t>(g_ppc64le_opcode,
sizeof(g_ppc64le_opcode));
2136 case llvm::Triple::x86:
2137 case llvm::Triple::x86_64: {
2138 static const uint8_t g_i386_opcode[] = {0xCC};
2139 trap_opcode = llvm::ArrayRef<uint8_t>(g_i386_opcode,
sizeof(g_i386_opcode));
2142 case llvm::Triple::riscv32:
2143 case llvm::Triple::riscv64: {
2144 static const uint8_t g_riscv_opcode[] = {0x73, 0x00, 0x10, 0x00};
2145 static const uint8_t g_riscv_opcode_c[] = {0x02, 0x90};
2146 if (size_hint == 2) {
2147 trap_opcode = g_riscv_opcode_c;
2150 llvm::ArrayRef<uint8_t>(g_riscv_opcode,
sizeof(g_riscv_opcode));
2154 case llvm::Triple::loongarch32:
2155 case llvm::Triple::loongarch64: {
2156 static const uint8_t g_loongarch_opcode[] = {0x05, 0x00, 0x2a,
2159 llvm::ArrayRef<uint8_t>(g_loongarch_opcode,
sizeof(g_loongarch_opcode));
2163 case llvm::Triple::wasm32: {
2164 static const uint8_t g_wasm_opcode[] = {0x00};
2165 trap_opcode = llvm::ArrayRef<uint8_t>(g_wasm_opcode,
sizeof(g_wasm_opcode));
2169 trap_opcode = llvm::ArrayRef<uint8_t>{};
2176 llvm::ArrayRef<uint8_t> bytes) {
2181 if (bytes.size() && triple.isRISCV()) {
2183 return (bytes[0] & 0b11) == 0b11 ? 4 : 2;
2186 if (triple.isARM()) {
2206 addr_class = bp_loc_sp->GetAddress().GetAddressClass();
2209 size_t size_hint = 0;
2217 bp_site->
SetTrapOpcode(trap_opcode.begin(), trap_opcode.size()))
2218 return trap_opcode.size();
2250 std::string reason_for_complaint =
2252 ? llvm::formatv(
"conflicts with the keyword '{0}'",
2255 :
"contains reserved characters";
2258 os.
Format(
"debug script '{0}' cannot be loaded because '{1}' {2}. "
2259 "Ignoring '{1}' and loading '{3}' instead.\n",
2261 std::move(reason_for_complaint), fspec.
GetFilename());
2263 os.
Format(
"debug script '{0}' cannot be loaded because '{1}' {2}. "
2264 "If you intend to have this script loaded, please rename it to "
2265 "'{3}' and retry.\n",
2267 std::move(reason_for_complaint), fspec.
GetFilename());
2270llvm::Expected<std::pair<XcodeSDKAndSysroot, bool>>
2272 SymbolFile *sym_file =
module.GetSymbolFile();
2274 return llvm::createStringError(
2275 llvm::formatv(
"No symbol file available for module '{0}'",
2279 return llvm::createStringError(
2280 llvm::formatv(
"Could not resolve SDK for module '{0}'. Symbol file has "
2281 "no compile units.",
2291 return std::pair{std::move(merged_sdk),
false};
2294llvm::Expected<std::string>
2298 return llvm::joinErrors(
2299 llvm::createStringError(
"could not parse SDK path from debug-info"),
2300 sdk_or_err.takeError());
2302 return sdk_or_err->first.GetSysroot().GetPath();
2305llvm::Expected<XcodeSDKAndSysroot>
2309 return llvm::createStringError(
"compile unit has no module");
2311 SymbolFile *sym_file = module_sp->GetSymbolFile();
2313 return llvm::createStringError(
2314 llvm::formatv(
"No symbol file available for module '{0}'",
2315 module_sp->GetFileSpec().GetFilename()));
2320llvm::Expected<std::string>
2324 return llvm::joinErrors(
2325 llvm::createStringError(
"could not parse SDK path from debug-info"),
2326 sdk_or_err.takeError());
2328 return sdk_or_err->GetSysroot().GetPath();
2332 std::lock_guard<std::recursive_mutex> guard(
m_mutex);
2334 if (platform_sp->GetName() == name)
2344 std::lock_guard<std::recursive_mutex> guard(
m_mutex);
2347 if (platform_sp->IsCompatibleArchitecture(
2354 if (platform_sp->IsCompatibleArchitecture(arch, process_host_arch,
2362 PlatformSP platform_sp = create_callback(
false, &arch);
2364 platform_sp->IsCompatibleArchitecture(
2372 PlatformSP platform_sp = create_callback(
false, &arch);
2373 if (platform_sp && platform_sp->IsCompatibleArchitecture(
2375 platform_arch_ptr)) {
2380 if (platform_arch_ptr)
2381 platform_arch_ptr->
Clear();
2396 std::vector<PlatformSP> &candidates) {
2398 candidates.reserve(archs.size());
2407 for (
const ArchSpec &arch : archs) {
2415 if (host_platform_sp) {
2416 for (
const ArchSpec &arch : archs) {
2417 if (host_platform_sp->IsCompatibleArchitecture(
2419 return host_platform_sp;
2424 for (
const ArchSpec &arch : archs) {
2426 candidates.push_back(platform);
2432 if (candidates.size() == archs.size()) {
2433 if (llvm::all_of(candidates, [&](
const PlatformSP &p) ->
bool {
2434 return p->GetName() == candidates.front()->GetName();
2436 return candidates.front();
2447 std::lock_guard<std::recursive_mutex> guard(
m_mutex);
2456 std::lock_guard<std::recursive_mutex> guard(
m_mutex);
2460 PlatformSP platform_sp = create_callback(
true, &arch);
2462 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,...)
A section + offset based address class.
AddressClass GetAddressClass() const
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.
A class that describes a compilation unit.
lldb::ModuleSP CalculateSymbolContextModule() override
Generic representation of a type in a programming language.
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::ScriptLanguage GetScriptLanguage() const
lldb::ListenerSP GetListener()
ScriptInterpreter * GetScriptInterpreter(bool can_create=true, std::optional< lldb::ScriptLanguage > language={})
"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)
llvm::StringRef GetFileNameStrippingExtension() const
Return the filename without the extension part.
void SetFilename(llvm::StringRef filename)
Filename string set accessor.
llvm::StringRef GetFilename() const
Filename string const get accessor.
bool IsAbsolute() const
Returns true if the filespec represents an absolute path.
Style GetPathStyle() const
void PrependPathComponent(llvm::StringRef component)
llvm::StringRef GetDirectory() const
Directory string const get accessor.
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.
void SetDirectory(llvm::StringRef directory)
Directory string set accessor.
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()
void Resolve(llvm::SmallVectorImpl< char > &path, bool force_make_absolute=false)
Resolve path to make it canonical.
@ 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, const Timeout< std::micro > &timeout)
Perform expansion of the command-line for this launch info This can potentially involve wildcard expa...
static Environment GetEnvironment()
static Status RunShellCommand(llvm::StringRef command, const FileSpec &working_dir, int *status_ptr, int *signo_ptr, std::string *command_output, std::string *error_output, const Timeout< std::micro > &timeout, bool run_in_shell=true)
Run a shell command.
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(llvm::StringRef name)
static Status GetSharedModule(const ModuleSpec &module_spec, lldb::ModuleSP &module_sp, llvm::SmallVectorImpl< lldb::ModuleSP > *old_modules, bool *did_create_ptr, bool invoke_locate_callback=true, bool invoke_symbol_locators=true)
bool FindMatchingModuleSpec(const ModuleSpec &module_spec, ModuleSpec &match_module_spec) const
uint64_t GetObjectOffset() const
FileSpec & GetPlatformFileSpec()
ArchSpec & GetArchitecture()
FileSpec & GetSymbolFileSpec()
void SetTarget(lldb::TargetSP target)
Set the target to be used when resolving a module.
uint64_t GetObjectSize() const
lldb::TargetSP GetTargetSP() const
A class that describes an executable image and its associated object and symbol files.
const FileSpec & GetFileSpec() const
Get const accessor for the module file specification.
static bool IsObjectFile(lldb_private::FileSpec file_spec)
static ModuleSpecList GetModuleSpecifications(const FileSpec &file, lldb::offset_t file_offset, lldb::offset_t file_size, lldb::DataExtractorSP=lldb::DataExtractorSP())
virtual llvm::StringRef GetPluginName()=0
static PlatformCreateInstance GetPlatformCreateCallbackForPluginName(llvm::StringRef name)
static llvm::SmallVector< StructuredDataPluginCallbacks > GetStructuredDataPluginCallbacks()
static llvm::SmallVector< PlatformCreateInstance > GetPlatformCreateCallbacks()
void SetHijackListener(const lldb::ListenerSP &listener_sp)
lldb::ListenerSP GetHijackListener() const
lldb::pid_t GetProcessID() const
bool MatchAllProcesses() const
const FileSpec & GetShell() const
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 llvm::VersionTuple GetHostOSVersion()
Sometimes the connection to a process can detect the host OS version that the process is running on.
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.
Holds an lldb_private::Module name and a "sanitized" version of it for the purposes of loading a scri...
bool RequiredSanitization() const
Returns true if the original name has been sanitized (i.e., required changes).
llvm::StringRef GetSanitizedName() const
llvm::StringRef GetConflictingKeyword() const
llvm::StringRef GetOriginalName() const
bool IsKeyword() const
Returns true if this name is a keyword in the associated scripting language.
virtual SanitizedScriptingModuleName GetSanitizedScriptingModuleName(llvm::StringRef name)
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)
Forwards the arguments to llvm::formatv and writes to the stream.
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 PutCString(llvm::StringRef cstr)
Output a C string to the stream.
size_t EOL()
Output and End of Line character to the stream.
Provides public interface for all SymbolFiles.
virtual uint32_t GetNumCompileUnits()=0
virtual lldb::CompUnitSP GetCompileUnitAtIndex(uint32_t idx)=0
virtual XcodeSDKAndSysroot ParseXcodeSDK(CompileUnit &comp_unit)
Return the Xcode SDK comp_unit was compiled against.
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.
std::optional< LoadScriptFromSymFile > GetAutoLoadScriptsForModule(llvm::StringRef module_name) const
LoadScriptFromSymFile GetLoadScriptFromSymbolFile() const
Debugger & GetDebugger() const
const lldb::ProcessSP & GetProcessSP() const
const lldb::ProcessSP & CreateProcess(lldb::ListenerSP listener_sp, llvm::StringRef plugin_name, const FileSpec *crash_file, bool can_connect)
FileSpecList GetSafeAutoLoadPaths() const
Get the list of paths that LLDB will consider automatically loading scripting resources from.
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.
An abstraction which groups an XcodeSDK with the sysroot it was used from.
void Merge(const XcodeSDKAndSysroot &other)
#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