diff options
Diffstat (limited to 'source/Target/Platform.cpp')
-rw-r--r-- | source/Target/Platform.cpp | 150 |
1 files changed, 70 insertions, 80 deletions
diff --git a/source/Target/Platform.cpp b/source/Target/Platform.cpp index 710f82eaefa9c..c9849a9e5f09f 100644 --- a/source/Target/Platform.cpp +++ b/source/Target/Platform.cpp @@ -63,13 +63,13 @@ const char *Platform::GetHostPlatformName() { return "host"; } namespace { -static constexpr PropertyDefinition g_properties[] = { - {"use-module-cache", OptionValue::eTypeBoolean, true, true, nullptr, - {}, "Use module cache."}, - {"module-cache-directory", OptionValue::eTypeFileSpec, true, 0, nullptr, - {}, "Root directory for cached modules."}}; +#define LLDB_PROPERTIES_platform +#include "TargetProperties.inc" -enum { ePropertyUseModuleCache, ePropertyModuleCacheDirectory }; +enum { +#define LLDB_PROPERTIES_platform +#include "TargetPropertiesEnum.inc" +}; } // namespace @@ -80,7 +80,7 @@ ConstString PlatformProperties::GetSettingName() { PlatformProperties::PlatformProperties() { m_collection_sp = std::make_shared<OptionValueProperties>(GetSettingName()); - m_collection_sp->Initialize(g_properties); + m_collection_sp->Initialize(g_platform_properties); auto module_cache_dir = GetModuleCacheDirectory(); if (module_cache_dir) @@ -99,7 +99,7 @@ PlatformProperties::PlatformProperties() { bool PlatformProperties::GetUseModuleCache() const { const auto idx = ePropertyUseModuleCache; return m_collection_sp->GetPropertyAtIndexAsBoolean( - nullptr, idx, g_properties[idx].default_uint_value != 0); + nullptr, idx, g_platform_properties[idx].default_uint_value != 0); } bool PlatformProperties::SetUseModuleCache(bool use_module_cache) { @@ -384,10 +384,9 @@ Platform::Platform(bool is_host) m_rsync_opts(), m_rsync_prefix(), m_supports_ssh(false), m_ssh_opts(), m_ignores_remote_hostname(false), m_trap_handlers(), m_calculated_trap_handlers(false), - m_module_cache(llvm::make_unique<ModuleCache>()) { + m_module_cache(std::make_unique<ModuleCache>()) { Log *log(lldb_private::GetLogIfAllCategoriesSet(LIBLLDB_LOG_OBJECT)); - if (log) - log->Printf("%p Platform::Platform()", static_cast<void *>(this)); + LLDB_LOGF(log, "%p Platform::Platform()", static_cast<void *>(this)); } /// Destructor. @@ -396,8 +395,7 @@ Platform::Platform(bool is_host) /// inherited from by the plug-in instance. Platform::~Platform() { Log *log(lldb_private::GetLogIfAllCategoriesSet(LIBLLDB_LOG_OBJECT)); - if (log) - log->Printf("%p Platform::~Platform()", static_cast<void *>(this)); + LLDB_LOGF(log, "%p Platform::~Platform()", static_cast<void *>(this)); } void Platform::GetStatus(Stream &strm) { @@ -637,9 +635,8 @@ Status Platform::Install(const FileSpec &src, const FileSpec &dst) { Status error; Log *log = GetLogIfAnyCategoriesSet(LIBLLDB_LOG_PLATFORM); - if (log) - log->Printf("Platform::Install (src='%s', dst='%s')", src.GetPath().c_str(), - dst.GetPath().c_str()); + LLDB_LOGF(log, "Platform::Install (src='%s', dst='%s')", + src.GetPath().c_str(), dst.GetPath().c_str()); FileSpec fixed_dst(dst); if (!fixed_dst.GetFilename()) @@ -690,10 +687,9 @@ Status Platform::Install(const FileSpec &src, const FileSpec &dst) { } } - if (log) - log->Printf("Platform::Install (src='%s', dst='%s') fixed_dst='%s'", - src.GetPath().c_str(), dst.GetPath().c_str(), - fixed_dst.GetPath().c_str()); + LLDB_LOGF(log, "Platform::Install (src='%s', dst='%s') fixed_dst='%s'", + src.GetPath().c_str(), dst.GetPath().c_str(), + fixed_dst.GetPath().c_str()); if (GetSupportsRSync()) { error = PutFile(src, dst); @@ -821,9 +817,8 @@ ConstString Platform::GetFullNameForDylib(ConstString basename) { bool Platform::SetRemoteWorkingDirectory(const FileSpec &working_dir) { Log *log = GetLogIfAnyCategoriesSet(LIBLLDB_LOG_PLATFORM); - if (log) - log->Printf("Platform::SetRemoteWorkingDirectory('%s')", - working_dir.GetCString()); + LLDB_LOGF(log, "Platform::SetRemoteWorkingDirectory('%s')", + working_dir.GetCString()); m_working_dir = working_dir; return true; } @@ -1010,8 +1005,7 @@ uint32_t Platform::FindProcesses(const ProcessInstanceInfoMatch &match_info, Status Platform::LaunchProcess(ProcessLaunchInfo &launch_info) { Status error; Log *log(lldb_private::GetLogIfAllCategoriesSet(LIBLLDB_LOG_PLATFORM)); - if (log) - log->Printf("Platform::%s()", __FUNCTION__); + LLDB_LOGF(log, "Platform::%s()", __FUNCTION__); // Take care of the host case so that each subclass can just call this // function to get the host functionality. @@ -1027,10 +1021,10 @@ Status Platform::LaunchProcess(ProcessLaunchInfo &launch_info) { if (log) { const FileSpec &shell = launch_info.GetShell(); std::string shell_str = (shell) ? shell.GetPath() : "<null>"; - log->Printf( - "Platform::%s GetResumeCountForLaunchInfo() returned %" PRIu32 - ", shell is '%s'", - __FUNCTION__, num_resumes, shell_str.c_str()); + LLDB_LOGF(log, + "Platform::%s GetResumeCountForLaunchInfo() returned %" PRIu32 + ", shell is '%s'", + __FUNCTION__, num_resumes, shell_str.c_str()); } if (!launch_info.ConvertArgumentsForLaunchingInShell( @@ -1048,9 +1042,8 @@ Status Platform::LaunchProcess(ProcessLaunchInfo &launch_info) { } } - if (log) - log->Printf("Platform::%s final launch_info resume count: %" PRIu32, - __FUNCTION__, launch_info.GetResumeCount()); + LLDB_LOGF(log, "Platform::%s final launch_info resume count: %" PRIu32, + __FUNCTION__, launch_info.GetResumeCount()); error = Host::LaunchProcess(launch_info); } else @@ -1067,8 +1060,7 @@ Status Platform::ShellExpandArguments(ProcessLaunchInfo &launch_info) { Status Platform::KillProcess(const lldb::pid_t pid) { Log *log(lldb_private::GetLogIfAllCategoriesSet(LIBLLDB_LOG_PLATFORM)); - if (log) - log->Printf("Platform::%s, pid %" PRIu64, __FUNCTION__, pid); + LLDB_LOGF(log, "Platform::%s, pid %" PRIu64, __FUNCTION__, pid); // Try to find a process plugin to handle this Kill request. If we can't, // fall back to the default OS implementation. @@ -1098,9 +1090,8 @@ Platform::DebugProcess(ProcessLaunchInfo &launch_info, Debugger &debugger, // new target, else use existing one Status &error) { Log *log(lldb_private::GetLogIfAllCategoriesSet(LIBLLDB_LOG_PLATFORM)); - if (log) - log->Printf("Platform::%s entered (target %p)", __FUNCTION__, - static_cast<void *>(target)); + LLDB_LOGF(log, "Platform::%s entered (target %p)", __FUNCTION__, + static_cast<void *>(target)); ProcessSP process_sp; // Make sure we stop at the entry point @@ -1124,10 +1115,10 @@ Platform::DebugProcess(ProcessLaunchInfo &launch_info, Debugger &debugger, // Give this ProcessLaunchInfo filter a chance to adjust the launch info. error = (*filter_callback)(launch_info, target); if (!error.Success()) { - if (log) - log->Printf("Platform::%s() StructuredDataPlugin launch " - "filter failed.", - __FUNCTION__); + LLDB_LOGF(log, + "Platform::%s() StructuredDataPlugin launch " + "filter failed.", + __FUNCTION__); return process_sp; } } @@ -1135,17 +1126,15 @@ Platform::DebugProcess(ProcessLaunchInfo &launch_info, Debugger &debugger, error = LaunchProcess(launch_info); if (error.Success()) { - if (log) - log->Printf("Platform::%s LaunchProcess() call succeeded (pid=%" PRIu64 - ")", - __FUNCTION__, launch_info.GetProcessID()); + LLDB_LOGF(log, + "Platform::%s LaunchProcess() call succeeded (pid=%" PRIu64 ")", + __FUNCTION__, launch_info.GetProcessID()); if (launch_info.GetProcessID() != LLDB_INVALID_PROCESS_ID) { ProcessAttachInfo attach_info(launch_info); process_sp = Attach(attach_info, debugger, target, error); if (process_sp) { - if (log) - log->Printf("Platform::%s Attach() succeeded, Process plugin: %s", - __FUNCTION__, process_sp->GetPluginName().AsCString()); + LLDB_LOGF(log, "Platform::%s Attach() succeeded, Process plugin: %s", + __FUNCTION__, process_sp->GetPluginName().AsCString()); launch_info.SetHijackListener(attach_info.GetHijackListener()); // Since we attached to the process, it will think it needs to detach @@ -1163,20 +1152,18 @@ Platform::DebugProcess(ProcessLaunchInfo &launch_info, Debugger &debugger, process_sp->SetSTDIOFileDescriptor(pty_fd); } } else { - if (log) - log->Printf("Platform::%s Attach() failed: %s", __FUNCTION__, - error.AsCString()); + LLDB_LOGF(log, "Platform::%s Attach() failed: %s", __FUNCTION__, + error.AsCString()); } } else { - if (log) - log->Printf("Platform::%s LaunchProcess() returned launch_info with " - "invalid process id", - __FUNCTION__); + LLDB_LOGF(log, + "Platform::%s LaunchProcess() returned launch_info with " + "invalid process id", + __FUNCTION__); } } else { - if (log) - log->Printf("Platform::%s LaunchProcess() failed: %s", __FUNCTION__, - error.AsCString()); + LLDB_LOGF(log, "Platform::%s LaunchProcess() failed: %s", __FUNCTION__, + error.AsCString()); } return process_sp; @@ -1231,30 +1218,28 @@ bool Platform::IsCompatibleArchitecture(const ArchSpec &arch, Status Platform::PutFile(const FileSpec &source, const FileSpec &destination, uint32_t uid, uint32_t gid) { Log *log(lldb_private::GetLogIfAllCategoriesSet(LIBLLDB_LOG_PLATFORM)); - if (log) - log->Printf("[PutFile] Using block by block transfer....\n"); + LLDB_LOGF(log, "[PutFile] Using block by block transfer....\n"); - uint32_t source_open_options = + auto source_open_options = File::eOpenOptionRead | File::eOpenOptionCloseOnExec; namespace fs = llvm::sys::fs; if (fs::is_symlink_file(source.GetPath())) source_open_options |= File::eOpenOptionDontFollowSymlinks; - File source_file; - Status error = FileSystem::Instance().Open( - source_file, source, source_open_options, lldb::eFilePermissionsUserRW); - uint32_t permissions = source_file.GetPermissions(error); + auto source_file = FileSystem::Instance().Open(source, source_open_options, + lldb::eFilePermissionsUserRW); + if (!source_file) + return Status(source_file.takeError()); + Status error; + uint32_t permissions = source_file.get()->GetPermissions(error); if (permissions == 0) permissions = lldb::eFilePermissionsFileDefault; - if (!source_file.IsValid()) - return Status("PutFile: unable to open source file"); lldb::user_id_t dest_file = OpenFile( destination, File::eOpenOptionCanCreate | File::eOpenOptionWrite | File::eOpenOptionTruncate | File::eOpenOptionCloseOnExec, permissions, error); - if (log) - log->Printf("dest_file = %" PRIu64 "\n", dest_file); + LLDB_LOGF(log, "dest_file = %" PRIu64 "\n", dest_file); if (error.Fail()) return error; @@ -1264,7 +1249,7 @@ Status Platform::PutFile(const FileSpec &source, const FileSpec &destination, uint64_t offset = 0; for (;;) { size_t bytes_read = buffer_sp->GetByteSize(); - error = source_file.Read(buffer_sp->GetBytes(), bytes_read); + error = source_file.get()->Read(buffer_sp->GetBytes(), bytes_read); if (error.Fail() || bytes_read == 0) break; @@ -1277,7 +1262,7 @@ Status Platform::PutFile(const FileSpec &source, const FileSpec &destination, if (bytes_written != bytes_read) { // We didn't write the correct number of bytes, so adjust the file // position in the source file we are reading from... - source_file.SeekFromStart(offset); + source_file.get()->SeekFromStart(offset); } } CloseFile(dest_file, error); @@ -1630,10 +1615,9 @@ bool Platform::GetCachedSharedModule(const ModuleSpec &module_spec, if (error.Success()) return true; - if (log) - log->Printf("Platform::%s - module %s not found in local cache: %s", - __FUNCTION__, module_spec.GetUUID().GetAsString().c_str(), - error.AsCString()); + LLDB_LOGF(log, "Platform::%s - module %s not found in local cache: %s", + __FUNCTION__, module_spec.GetUUID().GetAsString().c_str(), + error.AsCString()); return false; } @@ -1644,7 +1628,7 @@ Status Platform::DownloadModuleSlice(const FileSpec &src_file_spec, Status error; std::error_code EC; - llvm::raw_fd_ostream dst(dst_file_spec.GetPath(), EC, llvm::sys::fs::F_None); + llvm::raw_fd_ostream dst(dst_file_spec.GetPath(), EC, llvm::sys::fs::OF_None); if (EC) { error.SetErrorStringWithFormat("unable to open destination file: %s", dst_file_spec.GetPath().c_str()); @@ -1736,7 +1720,7 @@ uint32_t Platform::LoadImage(lldb_private::Process *process, return LLDB_INVALID_IMAGE_TOKEN; } return DoLoadImage(process, target_file, nullptr, error); - } + } if (remote_file) { // Only remote file was specified so we don't have to do any copying @@ -1769,7 +1753,7 @@ uint32_t Platform::LoadImageUsingPaths(lldb_private::Process *process, remote_filename.GetPathStyle()); else file_to_use = remote_filename; - + return DoLoadImage(process, file_to_use, &paths, error, loaded_path); } @@ -1812,8 +1796,7 @@ lldb::ProcessSP Platform::ConnectProcess(llvm::StringRef connect_url, if (!process_sp) return nullptr; - error = - process_sp->ConnectRemote(debugger.GetOutputFile().get(), connect_url); + error = process_sp->ConnectRemote(&debugger.GetOutputStream(), connect_url); if (error.Fail()) return nullptr; @@ -1833,12 +1816,19 @@ size_t Platform::GetSoftwareBreakpointTrapOpcode(Target &target, size_t trap_opcode_size = 0; switch (arch.GetMachine()) { + case llvm::Triple::aarch64_32: case llvm::Triple::aarch64: { static const uint8_t g_aarch64_opcode[] = {0x00, 0x00, 0x20, 0xd4}; trap_opcode = g_aarch64_opcode; trap_opcode_size = sizeof(g_aarch64_opcode); } break; + case llvm::Triple::arc: { + static const uint8_t g_hex_opcode[] = { 0xff, 0x7f }; + trap_opcode = g_hex_opcode; + trap_opcode_size = sizeof(g_hex_opcode); + } break; + // TODO: support big-endian arm and thumb trap codes. case llvm::Triple::arm: { // The ARM reference recommends the use of 0xe7fddefe and 0xdefe but the |