Raphael Isemann | 8081428 | 2020-01-24 08:23:27 +0100 | [diff] [blame] | 1 | //===-- Platform.cpp ------------------------------------------------------===// |
Greg Clayton | e996fd3 | 2011-03-08 22:40:15 +0000 | [diff] [blame] | 2 | // |
Chandler Carruth | 2946cd7 | 2019-01-19 08:50:56 +0000 | [diff] [blame] | 3 | // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. |
| 4 | // See https://llvm.org/LICENSE.txt for license information. |
| 5 | // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception |
Greg Clayton | e996fd3 | 2011-03-08 22:40:15 +0000 | [diff] [blame] | 6 | // |
| 7 | //===----------------------------------------------------------------------===// |
| 8 | |
Oleksiy Vyalov | 63acdfd | 2015-03-10 01:15:28 +0000 | [diff] [blame] | 9 | #include <algorithm> |
Pavel Labath | bc4987b | 2018-04-05 16:59:36 +0000 | [diff] [blame] | 10 | #include <csignal> |
Oleksiy Vyalov | 63acdfd | 2015-03-10 01:15:28 +0000 | [diff] [blame] | 11 | #include <fstream> |
Jonas Devlieghere | 796ac80 | 2019-02-11 23:13:08 +0000 | [diff] [blame] | 12 | #include <memory> |
Oleksiy Vyalov | 63acdfd | 2015-03-10 01:15:28 +0000 | [diff] [blame] | 13 | #include <vector> |
| 14 | |
Eugene Zelenko | 9394d772 | 2016-02-18 00:10:17 +0000 | [diff] [blame] | 15 | #include "llvm/Support/FileSystem.h" |
| 16 | #include "llvm/Support/Path.h" |
| 17 | |
Greg Clayton | 4116e93 | 2012-05-15 02:33:01 +0000 | [diff] [blame] | 18 | #include "lldb/Breakpoint/BreakpointIDList.h" |
Aidan Dodds | 933d8db | 2016-02-22 17:29:56 +0000 | [diff] [blame] | 19 | #include "lldb/Breakpoint/BreakpointLocation.h" |
Zachary Turner | 7271bab | 2015-05-13 19:44:24 +0000 | [diff] [blame] | 20 | #include "lldb/Core/Debugger.h" |
Oleksiy Vyalov | 63acdfd | 2015-03-10 01:15:28 +0000 | [diff] [blame] | 21 | #include "lldb/Core/Module.h" |
Greg Clayton | 1f74607 | 2012-08-29 21:13:06 +0000 | [diff] [blame] | 22 | #include "lldb/Core/ModuleSpec.h" |
Greg Clayton | e996fd3 | 2011-03-08 22:40:15 +0000 | [diff] [blame] | 23 | #include "lldb/Core/PluginManager.h" |
Tamas Berghammer | ccd6cff | 2015-12-08 14:08:19 +0000 | [diff] [blame] | 24 | #include "lldb/Core/StreamFile.h" |
Zachary Turner | c00cf4a | 2014-08-15 22:04:21 +0000 | [diff] [blame] | 25 | #include "lldb/Host/FileSystem.h" |
Greg Clayton | ded470d | 2011-03-19 01:12:21 +0000 | [diff] [blame] | 26 | #include "lldb/Host/Host.h" |
Zachary Turner | 97a14e6 | 2014-08-19 17:18:29 +0000 | [diff] [blame] | 27 | #include "lldb/Host/HostInfo.h" |
Zachary Turner | 3eb2b44 | 2017-03-22 23:33:16 +0000 | [diff] [blame] | 28 | #include "lldb/Host/OptionParser.h" |
Tatyana Krasnukha | fe74df0 | 2020-03-12 21:48:23 +0300 | [diff] [blame] | 29 | #include "lldb/Interpreter/OptionValueFileSpec.h" |
Oleksiy Vyalov | 63acdfd | 2015-03-10 01:15:28 +0000 | [diff] [blame] | 30 | #include "lldb/Interpreter/OptionValueProperties.h" |
| 31 | #include "lldb/Interpreter/Property.h" |
| 32 | #include "lldb/Symbol/ObjectFile.h" |
Zachary Turner | 01c3243 | 2017-02-14 19:06:07 +0000 | [diff] [blame] | 33 | #include "lldb/Target/ModuleCache.h" |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 34 | #include "lldb/Target/Platform.h" |
Greg Clayton | 8b82f08 | 2011-04-12 05:54:46 +0000 | [diff] [blame] | 35 | #include "lldb/Target/Process.h" |
Greg Clayton | e996fd3 | 2011-03-08 22:40:15 +0000 | [diff] [blame] | 36 | #include "lldb/Target/Target.h" |
Chaoren Lin | 98d0a4b | 2015-07-14 01:09:28 +0000 | [diff] [blame] | 37 | #include "lldb/Target/UnixSignals.h" |
Zachary Turner | 666cc0b | 2017-03-04 01:30:05 +0000 | [diff] [blame] | 38 | #include "lldb/Utility/DataBufferHeap.h" |
Zachary Turner | 5713a05 | 2017-03-22 18:40:07 +0000 | [diff] [blame] | 39 | #include "lldb/Utility/FileSpec.h" |
Zachary Turner | 6f9e690 | 2017-03-03 20:56:28 +0000 | [diff] [blame] | 40 | #include "lldb/Utility/Log.h" |
Zachary Turner | 97206d5 | 2017-05-12 04:51:55 +0000 | [diff] [blame] | 41 | #include "lldb/Utility/Status.h" |
Pavel Labath | f2a8bcc | 2017-06-27 10:45:31 +0000 | [diff] [blame] | 42 | #include "lldb/Utility/StructuredData.h" |
Greg Clayton | e996fd3 | 2011-03-08 22:40:15 +0000 | [diff] [blame] | 43 | |
Zachary Turner | 7d86ee5 | 2017-03-08 17:56:08 +0000 | [diff] [blame] | 44 | #include "llvm/Support/FileSystem.h" |
| 45 | |
Adrian Prantl | 0509724 | 2018-04-30 16:49:04 +0000 | [diff] [blame] | 46 | // Define these constants from POSIX mman.h rather than include the file so |
| 47 | // that they will be correct even when compiled on Linux. |
Robert Flack | 96ad3de | 2015-05-09 15:53:31 +0000 | [diff] [blame] | 48 | #define MAP_PRIVATE 2 |
| 49 | #define MAP_ANON 0x1000 |
| 50 | |
Greg Clayton | e996fd3 | 2011-03-08 22:40:15 +0000 | [diff] [blame] | 51 | using namespace lldb; |
| 52 | using namespace lldb_private; |
Tamas Berghammer | 3c4f89d | 2015-02-12 18:18:27 +0000 | [diff] [blame] | 53 | |
| 54 | static uint32_t g_initialize_count = 0; |
| 55 | |
Adrian Prantl | 0509724 | 2018-04-30 16:49:04 +0000 | [diff] [blame] | 56 | // Use a singleton function for g_local_platform_sp to avoid init constructors |
| 57 | // since LLDB is often part of a shared library |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 58 | static PlatformSP &GetHostPlatformSP() { |
| 59 | static PlatformSP g_platform_sp; |
| 60 | return g_platform_sp; |
Greg Clayton | e996fd3 | 2011-03-08 22:40:15 +0000 | [diff] [blame] | 61 | } |
| 62 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 63 | const char *Platform::GetHostPlatformName() { return "host"; } |
Greg Clayton | ab65b34 | 2011-04-13 22:47:15 +0000 | [diff] [blame] | 64 | |
Oleksiy Vyalov | 63acdfd | 2015-03-10 01:15:28 +0000 | [diff] [blame] | 65 | namespace { |
| 66 | |
Jonas Devlieghere | 971f9ca | 2019-07-25 21:36:37 +0000 | [diff] [blame] | 67 | #define LLDB_PROPERTIES_platform |
Jordan Rupprecht | 6a253d3 | 2019-07-29 17:22:10 +0000 | [diff] [blame] | 68 | #include "TargetProperties.inc" |
Oleksiy Vyalov | 63acdfd | 2015-03-10 01:15:28 +0000 | [diff] [blame] | 69 | |
Jonas Devlieghere | 971f9ca | 2019-07-25 21:36:37 +0000 | [diff] [blame] | 70 | enum { |
| 71 | #define LLDB_PROPERTIES_platform |
Jordan Rupprecht | 6a253d3 | 2019-07-29 17:22:10 +0000 | [diff] [blame] | 72 | #include "TargetPropertiesEnum.inc" |
Jonas Devlieghere | 971f9ca | 2019-07-25 21:36:37 +0000 | [diff] [blame] | 73 | }; |
Oleksiy Vyalov | 63acdfd | 2015-03-10 01:15:28 +0000 | [diff] [blame] | 74 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 75 | } // namespace |
Oleksiy Vyalov | 63acdfd | 2015-03-10 01:15:28 +0000 | [diff] [blame] | 76 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 77 | ConstString PlatformProperties::GetSettingName() { |
| 78 | static ConstString g_setting_name("platform"); |
| 79 | return g_setting_name; |
Oleksiy Vyalov | 63acdfd | 2015-03-10 01:15:28 +0000 | [diff] [blame] | 80 | } |
| 81 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 82 | PlatformProperties::PlatformProperties() { |
Jonas Devlieghere | 796ac80 | 2019-02-11 23:13:08 +0000 | [diff] [blame] | 83 | m_collection_sp = std::make_shared<OptionValueProperties>(GetSettingName()); |
Jonas Devlieghere | a8ea595 | 2019-07-29 16:41:30 +0000 | [diff] [blame] | 84 | m_collection_sp->Initialize(g_platform_properties); |
Oleksiy Vyalov | 63acdfd | 2015-03-10 01:15:28 +0000 | [diff] [blame] | 85 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 86 | auto module_cache_dir = GetModuleCacheDirectory(); |
| 87 | if (module_cache_dir) |
| 88 | return; |
Oleksiy Vyalov | d21ca28 | 2015-10-01 17:48:57 +0000 | [diff] [blame] | 89 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 90 | llvm::SmallString<64> user_home_dir; |
| 91 | if (!llvm::sys::path::home_directory(user_home_dir)) |
| 92 | return; |
Oleksiy Vyalov | d21ca28 | 2015-10-01 17:48:57 +0000 | [diff] [blame] | 93 | |
Jonas Devlieghere | 8f3be7a | 2018-11-01 21:05:36 +0000 | [diff] [blame] | 94 | module_cache_dir = FileSpec(user_home_dir.c_str()); |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 95 | module_cache_dir.AppendPathComponent(".lldb"); |
| 96 | module_cache_dir.AppendPathComponent("module_cache"); |
Tatyana Krasnukha | fe74df0 | 2020-03-12 21:48:23 +0300 | [diff] [blame] | 97 | SetDefaultModuleCacheDirectory(module_cache_dir); |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 98 | SetModuleCacheDirectory(module_cache_dir); |
Oleksiy Vyalov | 63acdfd | 2015-03-10 01:15:28 +0000 | [diff] [blame] | 99 | } |
| 100 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 101 | bool PlatformProperties::GetUseModuleCache() const { |
| 102 | const auto idx = ePropertyUseModuleCache; |
| 103 | return m_collection_sp->GetPropertyAtIndexAsBoolean( |
Jonas Devlieghere | a8ea595 | 2019-07-29 16:41:30 +0000 | [diff] [blame] | 104 | nullptr, idx, g_platform_properties[idx].default_uint_value != 0); |
Oleksiy Vyalov | 63acdfd | 2015-03-10 01:15:28 +0000 | [diff] [blame] | 105 | } |
| 106 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 107 | bool PlatformProperties::SetUseModuleCache(bool use_module_cache) { |
| 108 | return m_collection_sp->SetPropertyAtIndexAsBoolean( |
| 109 | nullptr, ePropertyUseModuleCache, use_module_cache); |
Oleksiy Vyalov | 63acdfd | 2015-03-10 01:15:28 +0000 | [diff] [blame] | 110 | } |
| 111 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 112 | FileSpec PlatformProperties::GetModuleCacheDirectory() const { |
| 113 | return m_collection_sp->GetPropertyAtIndexAsFileSpec( |
| 114 | nullptr, ePropertyModuleCacheDirectory); |
Oleksiy Vyalov | 63acdfd | 2015-03-10 01:15:28 +0000 | [diff] [blame] | 115 | } |
| 116 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 117 | bool PlatformProperties::SetModuleCacheDirectory(const FileSpec &dir_spec) { |
| 118 | return m_collection_sp->SetPropertyAtIndexAsFileSpec( |
| 119 | nullptr, ePropertyModuleCacheDirectory, dir_spec); |
Oleksiy Vyalov | 63acdfd | 2015-03-10 01:15:28 +0000 | [diff] [blame] | 120 | } |
| 121 | |
Tatyana Krasnukha | fe74df0 | 2020-03-12 21:48:23 +0300 | [diff] [blame] | 122 | void PlatformProperties::SetDefaultModuleCacheDirectory( |
| 123 | const FileSpec &dir_spec) { |
| 124 | auto f_spec_opt = m_collection_sp->GetPropertyAtIndexAsOptionValueFileSpec( |
| 125 | nullptr, false, ePropertyModuleCacheDirectory); |
| 126 | assert(f_spec_opt); |
| 127 | f_spec_opt->SetDefaultValue(dir_spec); |
| 128 | } |
| 129 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 130 | /// Get the native host platform plug-in. |
Greg Clayton | e996fd3 | 2011-03-08 22:40:15 +0000 | [diff] [blame] | 131 | /// |
| 132 | /// There should only be one of these for each host that LLDB runs |
| 133 | /// upon that should be statically compiled in and registered using |
| 134 | /// preprocessor macros or other similar build mechanisms. |
| 135 | /// |
| 136 | /// This platform will be used as the default platform when launching |
| 137 | /// or attaching to processes unless another platform is specified. |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 138 | PlatformSP Platform::GetHostPlatform() { return GetHostPlatformSP(); } |
| 139 | |
| 140 | static std::vector<PlatformSP> &GetPlatformList() { |
| 141 | static std::vector<PlatformSP> g_platform_list; |
| 142 | return g_platform_list; |
Greg Clayton | 615eb7e | 2014-09-19 20:11:50 +0000 | [diff] [blame] | 143 | } |
| 144 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 145 | static std::recursive_mutex &GetPlatformListMutex() { |
| 146 | static std::recursive_mutex g_mutex; |
| 147 | return g_mutex; |
Greg Clayton | 615eb7e | 2014-09-19 20:11:50 +0000 | [diff] [blame] | 148 | } |
| 149 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 150 | void Platform::Initialize() { g_initialize_count++; } |
Greg Clayton | e996fd3 | 2011-03-08 22:40:15 +0000 | [diff] [blame] | 151 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 152 | void Platform::Terminate() { |
| 153 | if (g_initialize_count > 0) { |
| 154 | if (--g_initialize_count == 0) { |
| 155 | std::lock_guard<std::recursive_mutex> guard(GetPlatformListMutex()); |
| 156 | GetPlatformList().clear(); |
Tamas Berghammer | 3c4f89d | 2015-02-12 18:18:27 +0000 | [diff] [blame] | 157 | } |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 158 | } |
Tamas Berghammer | 3c4f89d | 2015-02-12 18:18:27 +0000 | [diff] [blame] | 159 | } |
| 160 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 161 | const PlatformPropertiesSP &Platform::GetGlobalPlatformProperties() { |
| 162 | static const auto g_settings_sp(std::make_shared<PlatformProperties>()); |
| 163 | return g_settings_sp; |
Oleksiy Vyalov | 63acdfd | 2015-03-10 01:15:28 +0000 | [diff] [blame] | 164 | } |
| 165 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 166 | void Platform::SetHostPlatform(const lldb::PlatformSP &platform_sp) { |
| 167 | // The native platform should use its static void Platform::Initialize() |
| 168 | // function to register itself as the native platform. |
| 169 | GetHostPlatformSP() = platform_sp; |
Greg Clayton | 615eb7e | 2014-09-19 20:11:50 +0000 | [diff] [blame] | 170 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 171 | if (platform_sp) { |
| 172 | std::lock_guard<std::recursive_mutex> guard(GetPlatformListMutex()); |
| 173 | GetPlatformList().push_back(platform_sp); |
| 174 | } |
Greg Clayton | e996fd3 | 2011-03-08 22:40:15 +0000 | [diff] [blame] | 175 | } |
| 176 | |
Zachary Turner | 97206d5 | 2017-05-12 04:51:55 +0000 | [diff] [blame] | 177 | Status Platform::GetFileWithUUID(const FileSpec &platform_file, |
| 178 | const UUID *uuid_ptr, FileSpec &local_file) { |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 179 | // Default to the local case |
| 180 | local_file = platform_file; |
Zachary Turner | 97206d5 | 2017-05-12 04:51:55 +0000 | [diff] [blame] | 181 | return Status(); |
Greg Clayton | e996fd3 | 2011-03-08 22:40:15 +0000 | [diff] [blame] | 182 | } |
| 183 | |
Greg Clayton | 91c0e74 | 2013-01-11 23:44:27 +0000 | [diff] [blame] | 184 | FileSpecList |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 185 | Platform::LocateExecutableScriptingResources(Target *target, Module &module, |
| 186 | Stream *feedback_stream) { |
| 187 | return FileSpecList(); |
Enrico Granata | 1759848 | 2012-11-08 02:22:02 +0000 | [diff] [blame] | 188 | } |
| 189 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 190 | // PlatformSP |
Adrian Prantl | 0e4c482 | 2019-03-06 21:22:25 +0000 | [diff] [blame] | 191 | // Platform::FindPlugin (Process *process, ConstString plugin_name) |
Greg Clayton | 615eb7e | 2014-09-19 20:11:50 +0000 | [diff] [blame] | 192 | //{ |
Eugene Zelenko | 9394d772 | 2016-02-18 00:10:17 +0000 | [diff] [blame] | 193 | // PlatformCreateInstance create_callback = nullptr; |
Greg Clayton | 615eb7e | 2014-09-19 20:11:50 +0000 | [diff] [blame] | 194 | // if (plugin_name) |
| 195 | // { |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 196 | // create_callback = |
| 197 | // PluginManager::GetPlatformCreateCallbackForPluginName (plugin_name); |
Greg Clayton | 615eb7e | 2014-09-19 20:11:50 +0000 | [diff] [blame] | 198 | // if (create_callback) |
| 199 | // { |
| 200 | // ArchSpec arch; |
| 201 | // if (process) |
| 202 | // { |
| 203 | // arch = process->GetTarget().GetArchitecture(); |
| 204 | // } |
| 205 | // PlatformSP platform_sp(create_callback(process, &arch)); |
| 206 | // if (platform_sp) |
| 207 | // return platform_sp; |
| 208 | // } |
| 209 | // } |
| 210 | // else |
| 211 | // { |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 212 | // for (uint32_t idx = 0; (create_callback = |
| 213 | // PluginManager::GetPlatformCreateCallbackAtIndex(idx)) != nullptr; |
| 214 | // ++idx) |
Greg Clayton | 615eb7e | 2014-09-19 20:11:50 +0000 | [diff] [blame] | 215 | // { |
| 216 | // PlatformSP platform_sp(create_callback(process, nullptr)); |
| 217 | // if (platform_sp) |
| 218 | // return platform_sp; |
| 219 | // } |
| 220 | // } |
| 221 | // return PlatformSP(); |
| 222 | //} |
Jason Molenda | 1c62754 | 2013-04-05 01:03:25 +0000 | [diff] [blame] | 223 | |
Zachary Turner | 97206d5 | 2017-05-12 04:51:55 +0000 | [diff] [blame] | 224 | Status Platform::GetSharedModule(const ModuleSpec &module_spec, |
| 225 | Process *process, ModuleSP &module_sp, |
| 226 | const FileSpecList *module_search_paths_ptr, |
| 227 | ModuleSP *old_module_sp_ptr, |
| 228 | bool *did_create_ptr) { |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 229 | if (IsHost()) |
| 230 | return ModuleList::GetSharedModule( |
| 231 | module_spec, module_sp, module_search_paths_ptr, old_module_sp_ptr, |
| 232 | did_create_ptr, false); |
Oleksiy Vyalov | 63acdfd | 2015-03-10 01:15:28 +0000 | [diff] [blame] | 233 | |
Pavel Labath | 1f8639a | 2018-08-28 16:32:46 +0000 | [diff] [blame] | 234 | // Module resolver lambda. |
| 235 | auto resolver = [&](const ModuleSpec &spec) { |
| 236 | Status error(eErrorTypeGeneric); |
| 237 | ModuleSpec resolved_spec; |
| 238 | // Check if we have sysroot set. |
| 239 | if (m_sdk_sysroot) { |
| 240 | // Prepend sysroot to module spec. |
| 241 | resolved_spec = spec; |
| 242 | resolved_spec.GetFileSpec().PrependPathComponent( |
| 243 | m_sdk_sysroot.GetStringRef()); |
| 244 | // Try to get shared module with resolved spec. |
| 245 | error = ModuleList::GetSharedModule( |
| 246 | resolved_spec, module_sp, module_search_paths_ptr, old_module_sp_ptr, |
| 247 | did_create_ptr, false); |
| 248 | } |
| 249 | // If we don't have sysroot or it didn't work then |
| 250 | // try original module spec. |
| 251 | if (!error.Success()) { |
| 252 | resolved_spec = spec; |
| 253 | error = ModuleList::GetSharedModule( |
| 254 | resolved_spec, module_sp, module_search_paths_ptr, old_module_sp_ptr, |
| 255 | did_create_ptr, false); |
| 256 | } |
| 257 | if (error.Success() && module_sp) |
| 258 | module_sp->SetPlatformFileSpec(resolved_spec.GetFileSpec()); |
| 259 | return error; |
| 260 | }; |
| 261 | |
| 262 | return GetRemoteSharedModule(module_spec, process, module_sp, resolver, |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 263 | did_create_ptr); |
Oleksiy Vyalov | 63acdfd | 2015-03-10 01:15:28 +0000 | [diff] [blame] | 264 | } |
| 265 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 266 | bool Platform::GetModuleSpec(const FileSpec &module_file_spec, |
| 267 | const ArchSpec &arch, ModuleSpec &module_spec) { |
| 268 | ModuleSpecList module_specs; |
| 269 | if (ObjectFile::GetModuleSpecifications(module_file_spec, 0, 0, |
| 270 | module_specs) == 0) |
| 271 | return false; |
Oleksiy Vyalov | 63acdfd | 2015-03-10 01:15:28 +0000 | [diff] [blame] | 272 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 273 | ModuleSpec matched_module_spec; |
| 274 | return module_specs.FindMatchingModuleSpec(ModuleSpec(module_file_spec, arch), |
| 275 | module_spec); |
Greg Clayton | 32e0a75 | 2011-03-30 18:16:51 +0000 | [diff] [blame] | 276 | } |
| 277 | |
Adrian Prantl | 0e4c482 | 2019-03-06 21:22:25 +0000 | [diff] [blame] | 278 | PlatformSP Platform::Find(ConstString name) { |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 279 | if (name) { |
| 280 | static ConstString g_host_platform_name("host"); |
| 281 | if (name == g_host_platform_name) |
| 282 | return GetHostPlatform(); |
Greg Clayton | 615eb7e | 2014-09-19 20:11:50 +0000 | [diff] [blame] | 283 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 284 | std::lock_guard<std::recursive_mutex> guard(GetPlatformListMutex()); |
| 285 | for (const auto &platform_sp : GetPlatformList()) { |
| 286 | if (platform_sp->GetName() == name) |
| 287 | return platform_sp; |
Greg Clayton | 615eb7e | 2014-09-19 20:11:50 +0000 | [diff] [blame] | 288 | } |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 289 | } |
| 290 | return PlatformSP(); |
Greg Clayton | 615eb7e | 2014-09-19 20:11:50 +0000 | [diff] [blame] | 291 | } |
| 292 | |
Adrian Prantl | 0e4c482 | 2019-03-06 21:22:25 +0000 | [diff] [blame] | 293 | PlatformSP Platform::Create(ConstString name, Status &error) { |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 294 | PlatformCreateInstance create_callback = nullptr; |
| 295 | lldb::PlatformSP platform_sp; |
| 296 | if (name) { |
| 297 | static ConstString g_host_platform_name("host"); |
| 298 | if (name == g_host_platform_name) |
| 299 | return GetHostPlatform(); |
Greg Clayton | 615eb7e | 2014-09-19 20:11:50 +0000 | [diff] [blame] | 300 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 301 | create_callback = |
| 302 | PluginManager::GetPlatformCreateCallbackForPluginName(name); |
| 303 | if (create_callback) |
| 304 | platform_sp = create_callback(true, nullptr); |
Greg Clayton | e996fd3 | 2011-03-08 22:40:15 +0000 | [diff] [blame] | 305 | else |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 306 | error.SetErrorStringWithFormat( |
| 307 | "unable to find a plug-in for the platform named \"%s\"", |
| 308 | name.GetCString()); |
| 309 | } else |
| 310 | error.SetErrorString("invalid platform name"); |
Greg Clayton | 615eb7e | 2014-09-19 20:11:50 +0000 | [diff] [blame] | 311 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 312 | if (platform_sp) { |
| 313 | std::lock_guard<std::recursive_mutex> guard(GetPlatformListMutex()); |
| 314 | GetPlatformList().push_back(platform_sp); |
| 315 | } |
Greg Clayton | 615eb7e | 2014-09-19 20:11:50 +0000 | [diff] [blame] | 316 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 317 | return platform_sp; |
Greg Clayton | e996fd3 | 2011-03-08 22:40:15 +0000 | [diff] [blame] | 318 | } |
| 319 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 320 | PlatformSP Platform::Create(const ArchSpec &arch, ArchSpec *platform_arch_ptr, |
Zachary Turner | 97206d5 | 2017-05-12 04:51:55 +0000 | [diff] [blame] | 321 | Status &error) { |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 322 | lldb::PlatformSP platform_sp; |
| 323 | if (arch.IsValid()) { |
| 324 | // Scope for locker |
Greg Clayton | b3a40ba | 2012-03-20 18:34:04 +0000 | [diff] [blame] | 325 | { |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 326 | // First try exact arch matches across all platforms already created |
| 327 | std::lock_guard<std::recursive_mutex> guard(GetPlatformListMutex()); |
| 328 | for (const auto &platform_sp : GetPlatformList()) { |
| 329 | if (platform_sp->IsCompatibleArchitecture(arch, true, |
| 330 | platform_arch_ptr)) |
| 331 | return platform_sp; |
| 332 | } |
Greg Clayton | 615eb7e | 2014-09-19 20:11:50 +0000 | [diff] [blame] | 333 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 334 | // Next try compatible arch matches across all platforms already created |
| 335 | for (const auto &platform_sp : GetPlatformList()) { |
| 336 | if (platform_sp->IsCompatibleArchitecture(arch, false, |
| 337 | platform_arch_ptr)) |
| 338 | return platform_sp; |
| 339 | } |
Greg Clayton | b3a40ba | 2012-03-20 18:34:04 +0000 | [diff] [blame] | 340 | } |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 341 | |
| 342 | PlatformCreateInstance create_callback; |
| 343 | // First try exact arch matches across all platform plug-ins |
| 344 | uint32_t idx; |
| 345 | for (idx = 0; (create_callback = |
| 346 | PluginManager::GetPlatformCreateCallbackAtIndex(idx)); |
| 347 | ++idx) { |
| 348 | if (create_callback) { |
| 349 | platform_sp = create_callback(false, &arch); |
| 350 | if (platform_sp && |
| 351 | platform_sp->IsCompatibleArchitecture(arch, true, |
| 352 | platform_arch_ptr)) { |
| 353 | std::lock_guard<std::recursive_mutex> guard(GetPlatformListMutex()); |
| 354 | GetPlatformList().push_back(platform_sp); |
| 355 | return platform_sp; |
| 356 | } |
| 357 | } |
| 358 | } |
| 359 | // Next try compatible arch matches across all platform plug-ins |
| 360 | for (idx = 0; (create_callback = |
| 361 | PluginManager::GetPlatformCreateCallbackAtIndex(idx)); |
| 362 | ++idx) { |
| 363 | if (create_callback) { |
| 364 | platform_sp = create_callback(false, &arch); |
| 365 | if (platform_sp && |
| 366 | platform_sp->IsCompatibleArchitecture(arch, false, |
| 367 | platform_arch_ptr)) { |
| 368 | std::lock_guard<std::recursive_mutex> guard(GetPlatformListMutex()); |
| 369 | GetPlatformList().push_back(platform_sp); |
| 370 | return platform_sp; |
| 371 | } |
| 372 | } |
| 373 | } |
| 374 | } else |
| 375 | error.SetErrorString("invalid platform name"); |
| 376 | if (platform_arch_ptr) |
| 377 | platform_arch_ptr->Clear(); |
| 378 | platform_sp.reset(); |
| 379 | return platform_sp; |
Greg Clayton | b3a40ba | 2012-03-20 18:34:04 +0000 | [diff] [blame] | 380 | } |
| 381 | |
Pavel Labath | 7263f1b | 2017-10-31 10:56:03 +0000 | [diff] [blame] | 382 | ArchSpec Platform::GetAugmentedArchSpec(Platform *platform, llvm::StringRef triple) { |
| 383 | if (platform) |
| 384 | return platform->GetAugmentedArchSpec(triple); |
| 385 | return HostInfo::GetAugmentedArchSpec(triple); |
| 386 | } |
| 387 | |
Greg Clayton | e996fd3 | 2011-03-08 22:40:15 +0000 | [diff] [blame] | 388 | /// Default Constructor |
Saleem Abdulrasool | 16ff860 | 2016-05-18 01:59:10 +0000 | [diff] [blame] | 389 | Platform::Platform(bool is_host) |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 390 | : m_is_host(is_host), m_os_version_set_while_connected(false), |
| 391 | m_system_arch_set_while_connected(false), m_sdk_sysroot(), m_sdk_build(), |
Pavel Labath | 2272c48 | 2018-06-18 15:02:23 +0000 | [diff] [blame] | 392 | m_working_dir(), m_remote_url(), m_name(), m_system_arch(), m_mutex(), |
Pavel Labath | aa51e6a | 2019-03-04 18:48:00 +0000 | [diff] [blame] | 393 | m_max_uid_name_len(0), m_max_gid_name_len(0), m_supports_rsync(false), |
| 394 | m_rsync_opts(), m_rsync_prefix(), m_supports_ssh(false), m_ssh_opts(), |
| 395 | m_ignores_remote_hostname(false), m_trap_handlers(), |
| 396 | m_calculated_trap_handlers(false), |
Jonas Devlieghere | a8f3ae7 | 2019-08-14 22:19:23 +0000 | [diff] [blame] | 397 | m_module_cache(std::make_unique<ModuleCache>()) { |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 398 | Log *log(lldb_private::GetLogIfAllCategoriesSet(LIBLLDB_LOG_OBJECT)); |
Jonas Devlieghere | 63e5fb7 | 2019-07-24 17:56:10 +0000 | [diff] [blame] | 399 | LLDB_LOGF(log, "%p Platform::Platform()", static_cast<void *>(this)); |
Greg Clayton | e996fd3 | 2011-03-08 22:40:15 +0000 | [diff] [blame] | 400 | } |
| 401 | |
Greg Clayton | e996fd3 | 2011-03-08 22:40:15 +0000 | [diff] [blame] | 402 | /// Destructor. |
| 403 | /// |
| 404 | /// The destructor is virtual since this class is designed to be |
| 405 | /// inherited from by the plug-in instance. |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 406 | Platform::~Platform() { |
| 407 | Log *log(lldb_private::GetLogIfAllCategoriesSet(LIBLLDB_LOG_OBJECT)); |
Jonas Devlieghere | 63e5fb7 | 2019-07-24 17:56:10 +0000 | [diff] [blame] | 408 | LLDB_LOGF(log, "%p Platform::~Platform()", static_cast<void *>(this)); |
Greg Clayton | e996fd3 | 2011-03-08 22:40:15 +0000 | [diff] [blame] | 409 | } |
| 410 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 411 | void Platform::GetStatus(Stream &strm) { |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 412 | std::string s; |
| 413 | strm.Printf(" Platform: %s\n", GetPluginName().GetCString()); |
Greg Clayton | 1cb6496 | 2011-03-24 04:28:38 +0000 | [diff] [blame] | 414 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 415 | ArchSpec arch(GetSystemArchitecture()); |
| 416 | if (arch.IsValid()) { |
| 417 | if (!arch.GetTriple().str().empty()) { |
| 418 | strm.Printf(" Triple: "); |
Raphael Isemann | 2f1e7b3 | 2019-12-04 08:27:43 +0100 | [diff] [blame] | 419 | arch.DumpTriple(strm.AsRawOstream()); |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 420 | strm.EOL(); |
Greg Clayton | 1cb6496 | 2011-03-24 04:28:38 +0000 | [diff] [blame] | 421 | } |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 422 | } |
Greg Clayton | 1cb6496 | 2011-03-24 04:28:38 +0000 | [diff] [blame] | 423 | |
Pavel Labath | 2272c48 | 2018-06-18 15:02:23 +0000 | [diff] [blame] | 424 | llvm::VersionTuple os_version = GetOSVersion(); |
| 425 | if (!os_version.empty()) { |
| 426 | strm.Format("OS Version: {0}", os_version.getAsString()); |
Greg Clayton | 1cb6496 | 2011-03-24 04:28:38 +0000 | [diff] [blame] | 427 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 428 | if (GetOSBuildString(s)) |
| 429 | strm.Printf(" (%s)", s.c_str()); |
Greg Clayton | 1cb6496 | 2011-03-24 04:28:38 +0000 | [diff] [blame] | 430 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 431 | strm.EOL(); |
| 432 | } |
Greg Clayton | 1cb6496 | 2011-03-24 04:28:38 +0000 | [diff] [blame] | 433 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 434 | if (IsHost()) { |
| 435 | strm.Printf(" Hostname: %s\n", GetHostname()); |
| 436 | } else { |
| 437 | const bool is_connected = IsConnected(); |
| 438 | if (is_connected) |
| 439 | strm.Printf(" Hostname: %s\n", GetHostname()); |
| 440 | strm.Printf(" Connected: %s\n", is_connected ? "yes" : "no"); |
| 441 | } |
Daniel Malea | e0f8f57 | 2013-08-26 23:57:52 +0000 | [diff] [blame] | 442 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 443 | if (GetWorkingDirectory()) { |
| 444 | strm.Printf("WorkingDir: %s\n", GetWorkingDirectory().GetCString()); |
| 445 | } |
| 446 | if (!IsConnected()) |
| 447 | return; |
Daniel Malea | e0f8f57 | 2013-08-26 23:57:52 +0000 | [diff] [blame] | 448 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 449 | std::string specific_info(GetPlatformSpecificConnectionInformation()); |
| 450 | |
| 451 | if (!specific_info.empty()) |
| 452 | strm.Printf("Platform-specific connection: %s\n", specific_info.c_str()); |
Jonas Devlieghere | d3bdd51 | 2020-01-31 14:23:56 -0800 | [diff] [blame] | 453 | |
| 454 | if (GetOSKernelDescription(s)) |
| 455 | strm.Printf(" Kernel: %s\n", s.c_str()); |
Greg Clayton | 1cb6496 | 2011-03-24 04:28:38 +0000 | [diff] [blame] | 456 | } |
| 457 | |
Pavel Labath | 2272c48 | 2018-06-18 15:02:23 +0000 | [diff] [blame] | 458 | llvm::VersionTuple Platform::GetOSVersion(Process *process) { |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 459 | std::lock_guard<std::mutex> guard(m_mutex); |
Greg Clayton | 7597b35 | 2015-02-02 20:45:17 +0000 | [diff] [blame] | 460 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 461 | if (IsHost()) { |
Pavel Labath | 2272c48 | 2018-06-18 15:02:23 +0000 | [diff] [blame] | 462 | if (m_os_version.empty()) { |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 463 | // We have a local host platform |
Pavel Labath | 2272c48 | 2018-06-18 15:02:23 +0000 | [diff] [blame] | 464 | m_os_version = HostInfo::GetOSVersion(); |
| 465 | m_os_version_set_while_connected = !m_os_version.empty(); |
Greg Clayton | ded470d | 2011-03-19 01:12:21 +0000 | [diff] [blame] | 466 | } |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 467 | } else { |
| 468 | // We have a remote platform. We can only fetch the remote |
| 469 | // OS version if we are connected, and we don't want to do it |
| 470 | // more than once. |
Greg Clayton | ded470d | 2011-03-19 01:12:21 +0000 | [diff] [blame] | 471 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 472 | const bool is_connected = IsConnected(); |
Greg Clayton | ded470d | 2011-03-19 01:12:21 +0000 | [diff] [blame] | 473 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 474 | bool fetch = false; |
Pavel Labath | 2272c48 | 2018-06-18 15:02:23 +0000 | [diff] [blame] | 475 | if (!m_os_version.empty()) { |
Adrian Prantl | 0509724 | 2018-04-30 16:49:04 +0000 | [diff] [blame] | 476 | // We have valid OS version info, check to make sure it wasn't manually |
| 477 | // set prior to connecting. If it was manually set prior to connecting, |
| 478 | // then lets fetch the actual OS version info if we are now connected. |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 479 | if (is_connected && !m_os_version_set_while_connected) |
| 480 | fetch = true; |
| 481 | } else { |
| 482 | // We don't have valid OS version info, fetch it if we are connected |
| 483 | fetch = is_connected; |
Greg Clayton | ded470d | 2011-03-19 01:12:21 +0000 | [diff] [blame] | 484 | } |
| 485 | |
Pavel Labath | 2272c48 | 2018-06-18 15:02:23 +0000 | [diff] [blame] | 486 | if (fetch) |
| 487 | m_os_version_set_while_connected = GetRemoteOSVersion(); |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 488 | } |
| 489 | |
Pavel Labath | 2272c48 | 2018-06-18 15:02:23 +0000 | [diff] [blame] | 490 | if (!m_os_version.empty()) |
| 491 | return m_os_version; |
| 492 | if (process) { |
Adrian Prantl | 0509724 | 2018-04-30 16:49:04 +0000 | [diff] [blame] | 493 | // Check with the process in case it can answer the question if a process |
| 494 | // was provided |
Pavel Labath | 2272c48 | 2018-06-18 15:02:23 +0000 | [diff] [blame] | 495 | return process->GetHostOSVersion(); |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 496 | } |
Pavel Labath | 2272c48 | 2018-06-18 15:02:23 +0000 | [diff] [blame] | 497 | return llvm::VersionTuple(); |
Greg Clayton | ded470d | 2011-03-19 01:12:21 +0000 | [diff] [blame] | 498 | } |
Greg Clayton | 1cb6496 | 2011-03-24 04:28:38 +0000 | [diff] [blame] | 499 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 500 | bool Platform::GetOSBuildString(std::string &s) { |
| 501 | s.clear(); |
Zachary Turner | 97a14e6 | 2014-08-19 17:18:29 +0000 | [diff] [blame] | 502 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 503 | if (IsHost()) |
Zachary Turner | 97a14e6 | 2014-08-19 17:18:29 +0000 | [diff] [blame] | 504 | #if !defined(__linux__) |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 505 | return HostInfo::GetOSBuildString(s); |
Zachary Turner | 97a14e6 | 2014-08-19 17:18:29 +0000 | [diff] [blame] | 506 | #else |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 507 | return false; |
Zachary Turner | 97a14e6 | 2014-08-19 17:18:29 +0000 | [diff] [blame] | 508 | #endif |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 509 | else |
| 510 | return GetRemoteOSBuildString(s); |
Greg Clayton | 1cb6496 | 2011-03-24 04:28:38 +0000 | [diff] [blame] | 511 | } |
| 512 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 513 | bool Platform::GetOSKernelDescription(std::string &s) { |
| 514 | if (IsHost()) |
Zachary Turner | 97a14e6 | 2014-08-19 17:18:29 +0000 | [diff] [blame] | 515 | #if !defined(__linux__) |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 516 | return HostInfo::GetOSKernelDescription(s); |
Zachary Turner | 97a14e6 | 2014-08-19 17:18:29 +0000 | [diff] [blame] | 517 | #else |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 518 | return false; |
Zachary Turner | 97a14e6 | 2014-08-19 17:18:29 +0000 | [diff] [blame] | 519 | #endif |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 520 | else |
| 521 | return GetRemoteOSKernelDescription(s); |
| 522 | } |
| 523 | |
| 524 | void Platform::AddClangModuleCompilationOptions( |
| 525 | Target *target, std::vector<std::string> &options) { |
| 526 | std::vector<std::string> default_compilation_options = { |
| 527 | "-x", "c++", "-Xclang", "-nostdsysteminc", "-Xclang", "-nostdsysteminc"}; |
| 528 | |
| 529 | options.insert(options.end(), default_compilation_options.begin(), |
| 530 | default_compilation_options.end()); |
| 531 | } |
| 532 | |
| 533 | FileSpec Platform::GetWorkingDirectory() { |
| 534 | if (IsHost()) { |
Pavel Labath | 1d5855b | 2017-01-23 15:56:45 +0000 | [diff] [blame] | 535 | llvm::SmallString<64> cwd; |
| 536 | if (llvm::sys::fs::current_path(cwd)) |
Jonas Devlieghere | 8f3be7a | 2018-11-01 21:05:36 +0000 | [diff] [blame] | 537 | return {}; |
| 538 | else { |
| 539 | FileSpec file_spec(cwd); |
| 540 | FileSystem::Instance().Resolve(file_spec); |
| 541 | return file_spec; |
| 542 | } |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 543 | } else { |
| 544 | if (!m_working_dir) |
| 545 | m_working_dir = GetRemoteWorkingDirectory(); |
| 546 | return m_working_dir; |
| 547 | } |
Greg Clayton | 1cb6496 | 2011-03-24 04:28:38 +0000 | [diff] [blame] | 548 | } |
| 549 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 550 | struct RecurseCopyBaton { |
| 551 | const FileSpec &dst; |
| 552 | Platform *platform_ptr; |
Zachary Turner | 97206d5 | 2017-05-12 04:51:55 +0000 | [diff] [blame] | 553 | Status error; |
Greg Clayton | fbb7634 | 2013-11-20 21:07:01 +0000 | [diff] [blame] | 554 | }; |
| 555 | |
Jonas Devlieghere | 35e4c84 | 2018-11-01 00:33:27 +0000 | [diff] [blame] | 556 | static FileSystem::EnumerateDirectoryResult |
Zachary Turner | 7d86ee5 | 2017-03-08 17:56:08 +0000 | [diff] [blame] | 557 | RecurseCopy_Callback(void *baton, llvm::sys::fs::file_type ft, |
Jonas Devlieghere | 35e4c84 | 2018-11-01 00:33:27 +0000 | [diff] [blame] | 558 | llvm::StringRef path) { |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 559 | RecurseCopyBaton *rc_baton = (RecurseCopyBaton *)baton; |
Jonas Devlieghere | 8f3be7a | 2018-11-01 21:05:36 +0000 | [diff] [blame] | 560 | FileSpec src(path); |
Zachary Turner | 7d86ee5 | 2017-03-08 17:56:08 +0000 | [diff] [blame] | 561 | namespace fs = llvm::sys::fs; |
| 562 | switch (ft) { |
| 563 | case fs::file_type::fifo_file: |
| 564 | case fs::file_type::socket_file: |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 565 | // we have no way to copy pipes and sockets - ignore them and continue |
Jonas Devlieghere | 35e4c84 | 2018-11-01 00:33:27 +0000 | [diff] [blame] | 566 | return FileSystem::eEnumerateDirectoryResultNext; |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 567 | break; |
Zachary Turner | c00cf4a | 2014-08-15 22:04:21 +0000 | [diff] [blame] | 568 | |
Zachary Turner | 7d86ee5 | 2017-03-08 17:56:08 +0000 | [diff] [blame] | 569 | case fs::file_type::directory_file: { |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 570 | // make the new directory and get in there |
| 571 | FileSpec dst_dir = rc_baton->dst; |
| 572 | if (!dst_dir.GetFilename()) |
| 573 | dst_dir.GetFilename() = src.GetLastPathComponent(); |
Zachary Turner | 97206d5 | 2017-05-12 04:51:55 +0000 | [diff] [blame] | 574 | Status error = rc_baton->platform_ptr->MakeDirectory( |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 575 | dst_dir, lldb::eFilePermissionsDirectoryDefault); |
| 576 | if (error.Fail()) { |
| 577 | rc_baton->error.SetErrorStringWithFormat( |
| 578 | "unable to setup directory %s on remote end", dst_dir.GetCString()); |
Jonas Devlieghere | 35e4c84 | 2018-11-01 00:33:27 +0000 | [diff] [blame] | 579 | return FileSystem::eEnumerateDirectoryResultQuit; // got an error, bail out |
Greg Clayton | fbb7634 | 2013-11-20 21:07:01 +0000 | [diff] [blame] | 580 | } |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 581 | |
| 582 | // now recurse |
| 583 | std::string src_dir_path(src.GetPath()); |
| 584 | |
Adrian Prantl | 0509724 | 2018-04-30 16:49:04 +0000 | [diff] [blame] | 585 | // Make a filespec that only fills in the directory of a FileSpec so when |
| 586 | // we enumerate we can quickly fill in the filename for dst copies |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 587 | FileSpec recurse_dst; |
| 588 | recurse_dst.GetDirectory().SetCString(dst_dir.GetPath().c_str()); |
Zachary Turner | 97206d5 | 2017-05-12 04:51:55 +0000 | [diff] [blame] | 589 | RecurseCopyBaton rc_baton2 = {recurse_dst, rc_baton->platform_ptr, |
| 590 | Status()}; |
Jonas Devlieghere | 35e4c84 | 2018-11-01 00:33:27 +0000 | [diff] [blame] | 591 | FileSystem::Instance().EnumerateDirectory(src_dir_path, true, true, true, |
| 592 | RecurseCopy_Callback, &rc_baton2); |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 593 | if (rc_baton2.error.Fail()) { |
| 594 | rc_baton->error.SetErrorString(rc_baton2.error.AsCString()); |
Jonas Devlieghere | 35e4c84 | 2018-11-01 00:33:27 +0000 | [diff] [blame] | 595 | return FileSystem::eEnumerateDirectoryResultQuit; // got an error, bail out |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 596 | } |
Jonas Devlieghere | 35e4c84 | 2018-11-01 00:33:27 +0000 | [diff] [blame] | 597 | return FileSystem::eEnumerateDirectoryResultNext; |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 598 | } break; |
| 599 | |
Zachary Turner | 7d86ee5 | 2017-03-08 17:56:08 +0000 | [diff] [blame] | 600 | case fs::file_type::symlink_file: { |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 601 | // copy the file and keep going |
| 602 | FileSpec dst_file = rc_baton->dst; |
| 603 | if (!dst_file.GetFilename()) |
| 604 | dst_file.GetFilename() = src.GetFilename(); |
| 605 | |
| 606 | FileSpec src_resolved; |
| 607 | |
Jonas Devlieghere | 4637696 | 2018-10-31 21:49:27 +0000 | [diff] [blame] | 608 | rc_baton->error = FileSystem::Instance().Readlink(src, src_resolved); |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 609 | |
| 610 | if (rc_baton->error.Fail()) |
Jonas Devlieghere | 35e4c84 | 2018-11-01 00:33:27 +0000 | [diff] [blame] | 611 | return FileSystem::eEnumerateDirectoryResultQuit; // got an error, bail out |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 612 | |
| 613 | rc_baton->error = |
| 614 | rc_baton->platform_ptr->CreateSymlink(dst_file, src_resolved); |
| 615 | |
| 616 | if (rc_baton->error.Fail()) |
Jonas Devlieghere | 35e4c84 | 2018-11-01 00:33:27 +0000 | [diff] [blame] | 617 | return FileSystem::eEnumerateDirectoryResultQuit; // got an error, bail out |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 618 | |
Jonas Devlieghere | 35e4c84 | 2018-11-01 00:33:27 +0000 | [diff] [blame] | 619 | return FileSystem::eEnumerateDirectoryResultNext; |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 620 | } break; |
| 621 | |
Zachary Turner | 7d86ee5 | 2017-03-08 17:56:08 +0000 | [diff] [blame] | 622 | case fs::file_type::regular_file: { |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 623 | // copy the file and keep going |
| 624 | FileSpec dst_file = rc_baton->dst; |
| 625 | if (!dst_file.GetFilename()) |
| 626 | dst_file.GetFilename() = src.GetFilename(); |
Zachary Turner | 97206d5 | 2017-05-12 04:51:55 +0000 | [diff] [blame] | 627 | Status err = rc_baton->platform_ptr->PutFile(src, dst_file); |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 628 | if (err.Fail()) { |
| 629 | rc_baton->error.SetErrorString(err.AsCString()); |
Jonas Devlieghere | 35e4c84 | 2018-11-01 00:33:27 +0000 | [diff] [blame] | 630 | return FileSystem::eEnumerateDirectoryResultQuit; // got an error, bail out |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 631 | } |
Jonas Devlieghere | 35e4c84 | 2018-11-01 00:33:27 +0000 | [diff] [blame] | 632 | return FileSystem::eEnumerateDirectoryResultNext; |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 633 | } break; |
| 634 | |
Zachary Turner | 7d86ee5 | 2017-03-08 17:56:08 +0000 | [diff] [blame] | 635 | default: |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 636 | rc_baton->error.SetErrorStringWithFormat( |
| 637 | "invalid file detected during copy: %s", src.GetPath().c_str()); |
Jonas Devlieghere | 35e4c84 | 2018-11-01 00:33:27 +0000 | [diff] [blame] | 638 | return FileSystem::eEnumerateDirectoryResultQuit; // got an error, bail out |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 639 | break; |
| 640 | } |
Zachary Turner | 7d86ee5 | 2017-03-08 17:56:08 +0000 | [diff] [blame] | 641 | llvm_unreachable("Unhandled file_type!"); |
Greg Clayton | fbb7634 | 2013-11-20 21:07:01 +0000 | [diff] [blame] | 642 | } |
| 643 | |
Zachary Turner | 97206d5 | 2017-05-12 04:51:55 +0000 | [diff] [blame] | 644 | Status Platform::Install(const FileSpec &src, const FileSpec &dst) { |
| 645 | Status error; |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 646 | |
| 647 | Log *log = GetLogIfAnyCategoriesSet(LIBLLDB_LOG_PLATFORM); |
Jonas Devlieghere | 63e5fb7 | 2019-07-24 17:56:10 +0000 | [diff] [blame] | 648 | LLDB_LOGF(log, "Platform::Install (src='%s', dst='%s')", |
| 649 | src.GetPath().c_str(), dst.GetPath().c_str()); |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 650 | FileSpec fixed_dst(dst); |
| 651 | |
| 652 | if (!fixed_dst.GetFilename()) |
| 653 | fixed_dst.GetFilename() = src.GetFilename(); |
| 654 | |
| 655 | FileSpec working_dir = GetWorkingDirectory(); |
| 656 | |
| 657 | if (dst) { |
| 658 | if (dst.GetDirectory()) { |
| 659 | const char first_dst_dir_char = dst.GetDirectory().GetCString()[0]; |
| 660 | if (first_dst_dir_char == '/' || first_dst_dir_char == '\\') { |
| 661 | fixed_dst.GetDirectory() = dst.GetDirectory(); |
| 662 | } |
Adrian Prantl | 0509724 | 2018-04-30 16:49:04 +0000 | [diff] [blame] | 663 | // If the fixed destination file doesn't have a directory yet, then we |
| 664 | // must have a relative path. We will resolve this relative path against |
| 665 | // the platform's working directory |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 666 | if (!fixed_dst.GetDirectory()) { |
| 667 | FileSpec relative_spec; |
| 668 | std::string path; |
| 669 | if (working_dir) { |
| 670 | relative_spec = working_dir; |
| 671 | relative_spec.AppendPathComponent(dst.GetPath()); |
| 672 | fixed_dst.GetDirectory() = relative_spec.GetDirectory(); |
| 673 | } else { |
| 674 | error.SetErrorStringWithFormat( |
| 675 | "platform working directory must be valid for relative path '%s'", |
| 676 | dst.GetPath().c_str()); |
| 677 | return error; |
| 678 | } |
| 679 | } |
| 680 | } else { |
| 681 | if (working_dir) { |
| 682 | fixed_dst.GetDirectory().SetCString(working_dir.GetCString()); |
| 683 | } else { |
| 684 | error.SetErrorStringWithFormat( |
| 685 | "platform working directory must be valid for relative path '%s'", |
| 686 | dst.GetPath().c_str()); |
| 687 | return error; |
| 688 | } |
| 689 | } |
| 690 | } else { |
| 691 | if (working_dir) { |
| 692 | fixed_dst.GetDirectory().SetCString(working_dir.GetCString()); |
| 693 | } else { |
| 694 | error.SetErrorStringWithFormat("platform working directory must be valid " |
| 695 | "when destination directory is empty"); |
| 696 | return error; |
| 697 | } |
| 698 | } |
| 699 | |
Jonas Devlieghere | 63e5fb7 | 2019-07-24 17:56:10 +0000 | [diff] [blame] | 700 | LLDB_LOGF(log, "Platform::Install (src='%s', dst='%s') fixed_dst='%s'", |
| 701 | src.GetPath().c_str(), dst.GetPath().c_str(), |
| 702 | fixed_dst.GetPath().c_str()); |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 703 | |
| 704 | if (GetSupportsRSync()) { |
| 705 | error = PutFile(src, dst); |
| 706 | } else { |
Zachary Turner | 7d86ee5 | 2017-03-08 17:56:08 +0000 | [diff] [blame] | 707 | namespace fs = llvm::sys::fs; |
| 708 | switch (fs::get_file_type(src.GetPath(), false)) { |
| 709 | case fs::file_type::directory_file: { |
Zachary Turner | 07db3f7 | 2017-03-21 05:47:57 +0000 | [diff] [blame] | 710 | llvm::sys::fs::remove(fixed_dst.GetPath()); |
Jonas Devlieghere | 7c5310b | 2018-11-01 15:47:33 +0000 | [diff] [blame] | 711 | uint32_t permissions = FileSystem::Instance().GetPermissions(src); |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 712 | if (permissions == 0) |
| 713 | permissions = eFilePermissionsDirectoryDefault; |
| 714 | error = MakeDirectory(fixed_dst, permissions); |
| 715 | if (error.Success()) { |
| 716 | // Make a filespec that only fills in the directory of a FileSpec so |
| 717 | // when we enumerate we can quickly fill in the filename for dst copies |
| 718 | FileSpec recurse_dst; |
| 719 | recurse_dst.GetDirectory().SetCString(fixed_dst.GetCString()); |
| 720 | std::string src_dir_path(src.GetPath()); |
Zachary Turner | 97206d5 | 2017-05-12 04:51:55 +0000 | [diff] [blame] | 721 | RecurseCopyBaton baton = {recurse_dst, this, Status()}; |
Jonas Devlieghere | 35e4c84 | 2018-11-01 00:33:27 +0000 | [diff] [blame] | 722 | FileSystem::Instance().EnumerateDirectory( |
| 723 | src_dir_path, true, true, true, RecurseCopy_Callback, &baton); |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 724 | return baton.error; |
| 725 | } |
| 726 | } break; |
| 727 | |
Zachary Turner | 7d86ee5 | 2017-03-08 17:56:08 +0000 | [diff] [blame] | 728 | case fs::file_type::regular_file: |
Zachary Turner | 07db3f7 | 2017-03-21 05:47:57 +0000 | [diff] [blame] | 729 | llvm::sys::fs::remove(fixed_dst.GetPath()); |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 730 | error = PutFile(src, fixed_dst); |
| 731 | break; |
| 732 | |
Zachary Turner | 7d86ee5 | 2017-03-08 17:56:08 +0000 | [diff] [blame] | 733 | case fs::file_type::symlink_file: { |
Zachary Turner | 07db3f7 | 2017-03-21 05:47:57 +0000 | [diff] [blame] | 734 | llvm::sys::fs::remove(fixed_dst.GetPath()); |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 735 | FileSpec src_resolved; |
Jonas Devlieghere | 4637696 | 2018-10-31 21:49:27 +0000 | [diff] [blame] | 736 | error = FileSystem::Instance().Readlink(src, src_resolved); |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 737 | if (error.Success()) |
| 738 | error = CreateSymlink(dst, src_resolved); |
| 739 | } break; |
Zachary Turner | 7d86ee5 | 2017-03-08 17:56:08 +0000 | [diff] [blame] | 740 | case fs::file_type::fifo_file: |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 741 | error.SetErrorString("platform install doesn't handle pipes"); |
| 742 | break; |
Zachary Turner | 7d86ee5 | 2017-03-08 17:56:08 +0000 | [diff] [blame] | 743 | case fs::file_type::socket_file: |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 744 | error.SetErrorString("platform install doesn't handle sockets"); |
| 745 | break; |
Zachary Turner | 7d86ee5 | 2017-03-08 17:56:08 +0000 | [diff] [blame] | 746 | default: |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 747 | error.SetErrorString( |
| 748 | "platform install doesn't handle non file or directory items"); |
| 749 | break; |
| 750 | } |
| 751 | } |
| 752 | return error; |
| 753 | } |
| 754 | |
| 755 | bool Platform::SetWorkingDirectory(const FileSpec &file_spec) { |
| 756 | if (IsHost()) { |
| 757 | Log *log = GetLogIfAnyCategoriesSet(LIBLLDB_LOG_PLATFORM); |
Pavel Labath | 2d0c5b0 | 2017-01-25 11:10:52 +0000 | [diff] [blame] | 758 | LLDB_LOG(log, "{0}", file_spec); |
| 759 | if (std::error_code ec = llvm::sys::fs::set_current_path(file_spec.GetPath())) { |
| 760 | LLDB_LOG(log, "error: {0}", ec.message()); |
| 761 | return false; |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 762 | } |
Pavel Labath | 2d0c5b0 | 2017-01-25 11:10:52 +0000 | [diff] [blame] | 763 | return true; |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 764 | } else { |
| 765 | m_working_dir.Clear(); |
| 766 | return SetRemoteWorkingDirectory(file_spec); |
| 767 | } |
| 768 | } |
| 769 | |
Zachary Turner | 97206d5 | 2017-05-12 04:51:55 +0000 | [diff] [blame] | 770 | Status Platform::MakeDirectory(const FileSpec &file_spec, |
| 771 | uint32_t permissions) { |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 772 | if (IsHost()) |
Zachary Turner | d3d95fd | 2017-03-19 05:48:47 +0000 | [diff] [blame] | 773 | return llvm::sys::fs::create_directory(file_spec.GetPath(), permissions); |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 774 | else { |
Zachary Turner | 97206d5 | 2017-05-12 04:51:55 +0000 | [diff] [blame] | 775 | Status error; |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 776 | error.SetErrorStringWithFormat("remote platform %s doesn't support %s", |
| 777 | GetPluginName().GetCString(), |
| 778 | LLVM_PRETTY_FUNCTION); |
Greg Clayton | fbb7634 | 2013-11-20 21:07:01 +0000 | [diff] [blame] | 779 | return error; |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 780 | } |
Greg Clayton | fbb7634 | 2013-11-20 21:07:01 +0000 | [diff] [blame] | 781 | } |
| 782 | |
Zachary Turner | 97206d5 | 2017-05-12 04:51:55 +0000 | [diff] [blame] | 783 | Status Platform::GetFilePermissions(const FileSpec &file_spec, |
| 784 | uint32_t &file_permissions) { |
Zachary Turner | 6934e0a | 2017-03-19 05:49:43 +0000 | [diff] [blame] | 785 | if (IsHost()) { |
| 786 | auto Value = llvm::sys::fs::getPermissions(file_spec.GetPath()); |
| 787 | if (Value) |
| 788 | file_permissions = Value.get(); |
Zachary Turner | 97206d5 | 2017-05-12 04:51:55 +0000 | [diff] [blame] | 789 | return Status(Value.getError()); |
Zachary Turner | 6934e0a | 2017-03-19 05:49:43 +0000 | [diff] [blame] | 790 | } else { |
Zachary Turner | 97206d5 | 2017-05-12 04:51:55 +0000 | [diff] [blame] | 791 | Status error; |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 792 | error.SetErrorStringWithFormat("remote platform %s doesn't support %s", |
| 793 | GetPluginName().GetCString(), |
| 794 | LLVM_PRETTY_FUNCTION); |
| 795 | return error; |
| 796 | } |
Greg Clayton | fbb7634 | 2013-11-20 21:07:01 +0000 | [diff] [blame] | 797 | } |
| 798 | |
Zachary Turner | 97206d5 | 2017-05-12 04:51:55 +0000 | [diff] [blame] | 799 | Status Platform::SetFilePermissions(const FileSpec &file_spec, |
| 800 | uint32_t file_permissions) { |
Zachary Turner | 6934e0a | 2017-03-19 05:49:43 +0000 | [diff] [blame] | 801 | if (IsHost()) { |
| 802 | auto Perms = static_cast<llvm::sys::fs::perms>(file_permissions); |
| 803 | return llvm::sys::fs::setPermissions(file_spec.GetPath(), Perms); |
| 804 | } else { |
Zachary Turner | 97206d5 | 2017-05-12 04:51:55 +0000 | [diff] [blame] | 805 | Status error; |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 806 | error.SetErrorStringWithFormat("remote platform %s doesn't support %s", |
| 807 | GetPluginName().GetCString(), |
| 808 | LLVM_PRETTY_FUNCTION); |
| 809 | return error; |
| 810 | } |
Greg Clayton | fbb7634 | 2013-11-20 21:07:01 +0000 | [diff] [blame] | 811 | } |
| 812 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 813 | ConstString Platform::GetName() { return GetPluginName(); } |
| 814 | |
| 815 | const char *Platform::GetHostname() { |
| 816 | if (IsHost()) |
| 817 | return "127.0.0.1"; |
| 818 | |
| 819 | if (m_name.empty()) |
| 820 | return nullptr; |
| 821 | return m_name.c_str(); |
Greg Clayton | fbb7634 | 2013-11-20 21:07:01 +0000 | [diff] [blame] | 822 | } |
| 823 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 824 | ConstString Platform::GetFullNameForDylib(ConstString basename) { |
| 825 | return basename; |
Greg Clayton | fbb7634 | 2013-11-20 21:07:01 +0000 | [diff] [blame] | 826 | } |
| 827 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 828 | bool Platform::SetRemoteWorkingDirectory(const FileSpec &working_dir) { |
| 829 | Log *log = GetLogIfAnyCategoriesSet(LIBLLDB_LOG_PLATFORM); |
Jonas Devlieghere | 63e5fb7 | 2019-07-24 17:56:10 +0000 | [diff] [blame] | 830 | LLDB_LOGF(log, "Platform::SetRemoteWorkingDirectory('%s')", |
| 831 | working_dir.GetCString()); |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 832 | m_working_dir = working_dir; |
| 833 | return true; |
Greg Clayton | 5fb8f79 | 2013-12-02 19:35:49 +0000 | [diff] [blame] | 834 | } |
| 835 | |
Pavel Labath | 2272c48 | 2018-06-18 15:02:23 +0000 | [diff] [blame] | 836 | bool Platform::SetOSVersion(llvm::VersionTuple version) { |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 837 | if (IsHost()) { |
Adrian Prantl | 0509724 | 2018-04-30 16:49:04 +0000 | [diff] [blame] | 838 | // We don't need anyone setting the OS version for the host platform, we |
| 839 | // should be able to figure it out by calling HostInfo::GetOSVersion(...). |
Greg Clayton | ded470d | 2011-03-19 01:12:21 +0000 | [diff] [blame] | 840 | return false; |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 841 | } else { |
Adrian Prantl | 0509724 | 2018-04-30 16:49:04 +0000 | [diff] [blame] | 842 | // We have a remote platform, allow setting the target OS version if we |
| 843 | // aren't connected, since if we are connected, we should be able to |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 844 | // request the remote OS version from the connected platform. |
| 845 | if (IsConnected()) |
| 846 | return false; |
| 847 | else { |
Adrian Prantl | 0509724 | 2018-04-30 16:49:04 +0000 | [diff] [blame] | 848 | // We aren't connected and we might want to set the OS version ahead of |
| 849 | // time before we connect so we can peruse files and use a local SDK or |
| 850 | // PDK cache of support files to disassemble or do other things. |
Pavel Labath | 2272c48 | 2018-06-18 15:02:23 +0000 | [diff] [blame] | 851 | m_os_version = version; |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 852 | return true; |
Greg Clayton | e996fd3 | 2011-03-08 22:40:15 +0000 | [diff] [blame] | 853 | } |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 854 | } |
| 855 | return false; |
| 856 | } |
| 857 | |
Zachary Turner | 97206d5 | 2017-05-12 04:51:55 +0000 | [diff] [blame] | 858 | Status |
| 859 | Platform::ResolveExecutable(const ModuleSpec &module_spec, |
| 860 | lldb::ModuleSP &exe_module_sp, |
| 861 | const FileSpecList *module_search_paths_ptr) { |
| 862 | Status error; |
Jonas Devlieghere | dbd7fab | 2018-11-01 17:09:25 +0000 | [diff] [blame] | 863 | if (FileSystem::Instance().Exists(module_spec.GetFileSpec())) { |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 864 | if (module_spec.GetArchitecture().IsValid()) { |
| 865 | error = ModuleList::GetSharedModule(module_spec, exe_module_sp, |
| 866 | module_search_paths_ptr, nullptr, |
| 867 | nullptr); |
| 868 | } else { |
Adrian Prantl | 0509724 | 2018-04-30 16:49:04 +0000 | [diff] [blame] | 869 | // No valid architecture was specified, ask the platform for the |
| 870 | // architectures that we should be using (in the correct order) and see |
| 871 | // if we can find a match that way |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 872 | ModuleSpec arch_module_spec(module_spec); |
| 873 | for (uint32_t idx = 0; GetSupportedArchitectureAtIndex( |
| 874 | idx, arch_module_spec.GetArchitecture()); |
| 875 | ++idx) { |
| 876 | error = ModuleList::GetSharedModule(arch_module_spec, exe_module_sp, |
| 877 | module_search_paths_ptr, nullptr, |
| 878 | nullptr); |
| 879 | // Did we find an executable using one of the |
| 880 | if (error.Success() && exe_module_sp) |
| 881 | break; |
| 882 | } |
Greg Clayton | e996fd3 | 2011-03-08 22:40:15 +0000 | [diff] [blame] | 883 | } |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 884 | } else { |
| 885 | error.SetErrorStringWithFormat("'%s' does not exist", |
| 886 | module_spec.GetFileSpec().GetPath().c_str()); |
| 887 | } |
| 888 | return error; |
Greg Clayton | e996fd3 | 2011-03-08 22:40:15 +0000 | [diff] [blame] | 889 | } |
| 890 | |
Zachary Turner | 97206d5 | 2017-05-12 04:51:55 +0000 | [diff] [blame] | 891 | Status Platform::ResolveSymbolFile(Target &target, const ModuleSpec &sym_spec, |
| 892 | FileSpec &sym_file) { |
| 893 | Status error; |
Jonas Devlieghere | dbd7fab | 2018-11-01 17:09:25 +0000 | [diff] [blame] | 894 | if (FileSystem::Instance().Exists(sym_spec.GetSymbolFileSpec())) |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 895 | sym_file = sym_spec.GetSymbolFileSpec(); |
| 896 | else |
| 897 | error.SetErrorString("unable to resolve symbol file"); |
| 898 | return error; |
Greg Clayton | aa51684 | 2011-08-11 16:25:18 +0000 | [diff] [blame] | 899 | } |
| 900 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 901 | bool Platform::ResolveRemotePath(const FileSpec &platform_path, |
| 902 | FileSpec &resolved_platform_path) { |
| 903 | resolved_platform_path = platform_path; |
Jonas Devlieghere | 8f3be7a | 2018-11-01 21:05:36 +0000 | [diff] [blame] | 904 | FileSystem::Instance().Resolve(resolved_platform_path); |
| 905 | return true; |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 906 | } |
| 907 | |
| 908 | const ArchSpec &Platform::GetSystemArchitecture() { |
| 909 | if (IsHost()) { |
| 910 | if (!m_system_arch.IsValid()) { |
| 911 | // We have a local host platform |
| 912 | m_system_arch = HostInfo::GetArchitecture(); |
| 913 | m_system_arch_set_while_connected = m_system_arch.IsValid(); |
Greg Clayton | ded470d | 2011-03-19 01:12:21 +0000 | [diff] [blame] | 914 | } |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 915 | } else { |
Adrian Prantl | 0509724 | 2018-04-30 16:49:04 +0000 | [diff] [blame] | 916 | // We have a remote platform. We can only fetch the remote system |
| 917 | // architecture if we are connected, and we don't want to do it more than |
| 918 | // once. |
Greg Clayton | ded470d | 2011-03-19 01:12:21 +0000 | [diff] [blame] | 919 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 920 | const bool is_connected = IsConnected(); |
Greg Clayton | ded470d | 2011-03-19 01:12:21 +0000 | [diff] [blame] | 921 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 922 | bool fetch = false; |
| 923 | if (m_system_arch.IsValid()) { |
Adrian Prantl | 0509724 | 2018-04-30 16:49:04 +0000 | [diff] [blame] | 924 | // We have valid OS version info, check to make sure it wasn't manually |
| 925 | // set prior to connecting. If it was manually set prior to connecting, |
| 926 | // then lets fetch the actual OS version info if we are now connected. |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 927 | if (is_connected && !m_system_arch_set_while_connected) |
| 928 | fetch = true; |
| 929 | } else { |
| 930 | // We don't have valid OS version info, fetch it if we are connected |
| 931 | fetch = is_connected; |
Greg Clayton | ded470d | 2011-03-19 01:12:21 +0000 | [diff] [blame] | 932 | } |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 933 | |
| 934 | if (fetch) { |
| 935 | m_system_arch = GetRemoteSystemArchitecture(); |
| 936 | m_system_arch_set_while_connected = m_system_arch.IsValid(); |
| 937 | } |
| 938 | } |
| 939 | return m_system_arch; |
Greg Clayton | ded470d | 2011-03-19 01:12:21 +0000 | [diff] [blame] | 940 | } |
| 941 | |
Pavel Labath | 7263f1b | 2017-10-31 10:56:03 +0000 | [diff] [blame] | 942 | ArchSpec Platform::GetAugmentedArchSpec(llvm::StringRef triple) { |
| 943 | if (triple.empty()) |
| 944 | return ArchSpec(); |
| 945 | llvm::Triple normalized_triple(llvm::Triple::normalize(triple)); |
| 946 | if (!ArchSpec::ContainsOnlyArch(normalized_triple)) |
| 947 | return ArchSpec(triple); |
| 948 | |
Pavel Labath | 4ebb64b | 2017-11-13 15:57:20 +0000 | [diff] [blame] | 949 | if (auto kind = HostInfo::ParseArchitectureKind(triple)) |
| 950 | return HostInfo::GetArchitecture(*kind); |
| 951 | |
Pavel Labath | 7263f1b | 2017-10-31 10:56:03 +0000 | [diff] [blame] | 952 | ArchSpec compatible_arch; |
| 953 | ArchSpec raw_arch(triple); |
| 954 | if (!IsCompatibleArchitecture(raw_arch, false, &compatible_arch)) |
| 955 | return raw_arch; |
| 956 | |
| 957 | if (!compatible_arch.IsValid()) |
| 958 | return ArchSpec(normalized_triple); |
| 959 | |
| 960 | const llvm::Triple &compatible_triple = compatible_arch.GetTriple(); |
| 961 | if (normalized_triple.getVendorName().empty()) |
| 962 | normalized_triple.setVendor(compatible_triple.getVendor()); |
| 963 | if (normalized_triple.getOSName().empty()) |
| 964 | normalized_triple.setOS(compatible_triple.getOS()); |
| 965 | if (normalized_triple.getEnvironmentName().empty()) |
| 966 | normalized_triple.setEnvironment(compatible_triple.getEnvironment()); |
| 967 | return ArchSpec(normalized_triple); |
| 968 | } |
| 969 | |
Zachary Turner | 97206d5 | 2017-05-12 04:51:55 +0000 | [diff] [blame] | 970 | Status Platform::ConnectRemote(Args &args) { |
| 971 | Status error; |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 972 | if (IsHost()) |
| 973 | error.SetErrorStringWithFormat("The currently selected platform (%s) is " |
| 974 | "the host platform and is always connected.", |
| 975 | GetPluginName().GetCString()); |
| 976 | else |
| 977 | error.SetErrorStringWithFormat( |
| 978 | "Platform::ConnectRemote() is not supported by %s", |
| 979 | GetPluginName().GetCString()); |
| 980 | return error; |
Greg Clayton | e996fd3 | 2011-03-08 22:40:15 +0000 | [diff] [blame] | 981 | } |
| 982 | |
Zachary Turner | 97206d5 | 2017-05-12 04:51:55 +0000 | [diff] [blame] | 983 | Status Platform::DisconnectRemote() { |
| 984 | Status error; |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 985 | if (IsHost()) |
| 986 | error.SetErrorStringWithFormat("The currently selected platform (%s) is " |
| 987 | "the host platform and is always connected.", |
| 988 | GetPluginName().GetCString()); |
| 989 | else |
| 990 | error.SetErrorStringWithFormat( |
| 991 | "Platform::DisconnectRemote() is not supported by %s", |
| 992 | GetPluginName().GetCString()); |
| 993 | return error; |
Greg Clayton | e996fd3 | 2011-03-08 22:40:15 +0000 | [diff] [blame] | 994 | } |
Greg Clayton | 32e0a75 | 2011-03-30 18:16:51 +0000 | [diff] [blame] | 995 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 996 | bool Platform::GetProcessInfo(lldb::pid_t pid, |
| 997 | ProcessInstanceInfo &process_info) { |
Adrian Prantl | 0509724 | 2018-04-30 16:49:04 +0000 | [diff] [blame] | 998 | // Take care of the host case so that each subclass can just call this |
| 999 | // function to get the host functionality. |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 1000 | if (IsHost()) |
| 1001 | return Host::GetProcessInfo(pid, process_info); |
| 1002 | return false; |
Greg Clayton | 32e0a75 | 2011-03-30 18:16:51 +0000 | [diff] [blame] | 1003 | } |
| 1004 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 1005 | uint32_t Platform::FindProcesses(const ProcessInstanceInfoMatch &match_info, |
| 1006 | ProcessInstanceInfoList &process_infos) { |
Adrian Prantl | 0509724 | 2018-04-30 16:49:04 +0000 | [diff] [blame] | 1007 | // Take care of the host case so that each subclass can just call this |
| 1008 | // function to get the host functionality. |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 1009 | uint32_t match_count = 0; |
| 1010 | if (IsHost()) |
| 1011 | match_count = Host::FindProcesses(match_info, process_infos); |
| 1012 | return match_count; |
Greg Clayton | 32e0a75 | 2011-03-30 18:16:51 +0000 | [diff] [blame] | 1013 | } |
Greg Clayton | 8b82f08 | 2011-04-12 05:54:46 +0000 | [diff] [blame] | 1014 | |
Zachary Turner | 97206d5 | 2017-05-12 04:51:55 +0000 | [diff] [blame] | 1015 | Status Platform::LaunchProcess(ProcessLaunchInfo &launch_info) { |
| 1016 | Status error; |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 1017 | Log *log(lldb_private::GetLogIfAllCategoriesSet(LIBLLDB_LOG_PLATFORM)); |
Jonas Devlieghere | 63e5fb7 | 2019-07-24 17:56:10 +0000 | [diff] [blame] | 1018 | LLDB_LOGF(log, "Platform::%s()", __FUNCTION__); |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 1019 | |
Adrian Prantl | 0509724 | 2018-04-30 16:49:04 +0000 | [diff] [blame] | 1020 | // Take care of the host case so that each subclass can just call this |
| 1021 | // function to get the host functionality. |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 1022 | if (IsHost()) { |
| 1023 | if (::getenv("LLDB_LAUNCH_FLAG_LAUNCH_IN_TTY")) |
| 1024 | launch_info.GetFlags().Set(eLaunchFlagLaunchInTTY); |
| 1025 | |
| 1026 | if (launch_info.GetFlags().Test(eLaunchFlagLaunchInShell)) { |
| 1027 | const bool is_localhost = true; |
| 1028 | const bool will_debug = launch_info.GetFlags().Test(eLaunchFlagDebug); |
| 1029 | const bool first_arg_is_full_shell_command = false; |
| 1030 | uint32_t num_resumes = GetResumeCountForLaunchInfo(launch_info); |
| 1031 | if (log) { |
| 1032 | const FileSpec &shell = launch_info.GetShell(); |
Jason Molenda | 3b68761 | 2019-02-08 23:36:25 +0000 | [diff] [blame] | 1033 | std::string shell_str = (shell) ? shell.GetPath() : "<null>"; |
Jonas Devlieghere | 63e5fb7 | 2019-07-24 17:56:10 +0000 | [diff] [blame] | 1034 | LLDB_LOGF(log, |
| 1035 | "Platform::%s GetResumeCountForLaunchInfo() returned %" PRIu32 |
| 1036 | ", shell is '%s'", |
| 1037 | __FUNCTION__, num_resumes, shell_str.c_str()); |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 1038 | } |
| 1039 | |
| 1040 | if (!launch_info.ConvertArgumentsForLaunchingInShell( |
| 1041 | error, is_localhost, will_debug, first_arg_is_full_shell_command, |
| 1042 | num_resumes)) |
| 1043 | return error; |
| 1044 | } else if (launch_info.GetFlags().Test(eLaunchFlagShellExpandArguments)) { |
| 1045 | error = ShellExpandArguments(launch_info); |
| 1046 | if (error.Fail()) { |
| 1047 | error.SetErrorStringWithFormat("shell expansion failed (reason: %s). " |
| 1048 | "consider launching with 'process " |
| 1049 | "launch'.", |
| 1050 | error.AsCString("unknown")); |
| 1051 | return error; |
| 1052 | } |
| 1053 | } |
| 1054 | |
Jonas Devlieghere | 63e5fb7 | 2019-07-24 17:56:10 +0000 | [diff] [blame] | 1055 | LLDB_LOGF(log, "Platform::%s final launch_info resume count: %" PRIu32, |
| 1056 | __FUNCTION__, launch_info.GetResumeCount()); |
Todd Fiala | ac33cc9 | 2014-10-09 01:02:08 +0000 | [diff] [blame] | 1057 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 1058 | error = Host::LaunchProcess(launch_info); |
| 1059 | } else |
| 1060 | error.SetErrorString( |
| 1061 | "base lldb_private::Platform class can't launch remote processes"); |
| 1062 | return error; |
Greg Clayton | 8b82f08 | 2011-04-12 05:54:46 +0000 | [diff] [blame] | 1063 | } |
| 1064 | |
Zachary Turner | 97206d5 | 2017-05-12 04:51:55 +0000 | [diff] [blame] | 1065 | Status Platform::ShellExpandArguments(ProcessLaunchInfo &launch_info) { |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 1066 | if (IsHost()) |
| 1067 | return Host::ShellExpandArguments(launch_info); |
Zachary Turner | 97206d5 | 2017-05-12 04:51:55 +0000 | [diff] [blame] | 1068 | return Status("base lldb_private::Platform class can't expand arguments"); |
Enrico Granata | 83a1437 | 2015-02-20 21:48:38 +0000 | [diff] [blame] | 1069 | } |
| 1070 | |
Zachary Turner | 97206d5 | 2017-05-12 04:51:55 +0000 | [diff] [blame] | 1071 | Status Platform::KillProcess(const lldb::pid_t pid) { |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 1072 | Log *log(lldb_private::GetLogIfAllCategoriesSet(LIBLLDB_LOG_PLATFORM)); |
Jonas Devlieghere | 63e5fb7 | 2019-07-24 17:56:10 +0000 | [diff] [blame] | 1073 | LLDB_LOGF(log, "Platform::%s, pid %" PRIu64, __FUNCTION__, pid); |
Oleksiy Vyalov | 1ef7b2c | 2015-02-04 23:19:15 +0000 | [diff] [blame] | 1074 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 1075 | // Try to find a process plugin to handle this Kill request. If we can't, |
Adrian Prantl | 0509724 | 2018-04-30 16:49:04 +0000 | [diff] [blame] | 1076 | // fall back to the default OS implementation. |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 1077 | size_t num_debuggers = Debugger::GetNumDebuggers(); |
| 1078 | for (size_t didx = 0; didx < num_debuggers; ++didx) { |
| 1079 | DebuggerSP debugger = Debugger::GetDebuggerAtIndex(didx); |
| 1080 | lldb_private::TargetList &targets = debugger->GetTargetList(); |
| 1081 | for (int tidx = 0; tidx < targets.GetNumTargets(); ++tidx) { |
| 1082 | ProcessSP process = targets.GetTargetAtIndex(tidx)->GetProcessSP(); |
| 1083 | if (process->GetID() == pid) |
| 1084 | return process->Destroy(true); |
Zachary Turner | 7271bab | 2015-05-13 19:44:24 +0000 | [diff] [blame] | 1085 | } |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 1086 | } |
Oleksiy Vyalov | 1ef7b2c | 2015-02-04 23:19:15 +0000 | [diff] [blame] | 1087 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 1088 | if (!IsHost()) { |
Zachary Turner | 97206d5 | 2017-05-12 04:51:55 +0000 | [diff] [blame] | 1089 | return Status( |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 1090 | "base lldb_private::Platform class can't kill remote processes unless " |
| 1091 | "they are controlled by a process plugin"); |
| 1092 | } |
| 1093 | Host::Kill(pid, SIGTERM); |
Zachary Turner | 97206d5 | 2017-05-12 04:51:55 +0000 | [diff] [blame] | 1094 | return Status(); |
Oleksiy Vyalov | 1ef7b2c | 2015-02-04 23:19:15 +0000 | [diff] [blame] | 1095 | } |
| 1096 | |
Greg Clayton | 8b82f08 | 2011-04-12 05:54:46 +0000 | [diff] [blame] | 1097 | lldb::ProcessSP |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 1098 | Platform::DebugProcess(ProcessLaunchInfo &launch_info, Debugger &debugger, |
| 1099 | Target *target, // Can be nullptr, if nullptr create a |
| 1100 | // new target, else use existing one |
Zachary Turner | 97206d5 | 2017-05-12 04:51:55 +0000 | [diff] [blame] | 1101 | Status &error) { |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 1102 | Log *log(lldb_private::GetLogIfAllCategoriesSet(LIBLLDB_LOG_PLATFORM)); |
Jonas Devlieghere | 63e5fb7 | 2019-07-24 17:56:10 +0000 | [diff] [blame] | 1103 | LLDB_LOGF(log, "Platform::%s entered (target %p)", __FUNCTION__, |
| 1104 | static_cast<void *>(target)); |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 1105 | |
| 1106 | ProcessSP process_sp; |
| 1107 | // Make sure we stop at the entry point |
| 1108 | launch_info.GetFlags().Set(eLaunchFlagDebug); |
| 1109 | // We always launch the process we are going to debug in a separate process |
Adrian Prantl | 0509724 | 2018-04-30 16:49:04 +0000 | [diff] [blame] | 1110 | // group, since then we can handle ^C interrupts ourselves w/o having to |
| 1111 | // worry about the target getting them as well. |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 1112 | launch_info.SetLaunchInSeparateProcessGroup(true); |
| 1113 | |
| 1114 | // Allow any StructuredData process-bound plugins to adjust the launch info |
| 1115 | // if needed |
| 1116 | size_t i = 0; |
| 1117 | bool iteration_complete = false; |
Adrian Prantl | 0509724 | 2018-04-30 16:49:04 +0000 | [diff] [blame] | 1118 | // Note iteration can't simply go until a nullptr callback is returned, as it |
| 1119 | // is valid for a plugin to not supply a filter. |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 1120 | auto get_filter_func = PluginManager::GetStructuredDataFilterCallbackAtIndex; |
| 1121 | for (auto filter_callback = get_filter_func(i, iteration_complete); |
| 1122 | !iteration_complete; |
| 1123 | filter_callback = get_filter_func(++i, iteration_complete)) { |
| 1124 | if (filter_callback) { |
Adrian Prantl | 0509724 | 2018-04-30 16:49:04 +0000 | [diff] [blame] | 1125 | // Give this ProcessLaunchInfo filter a chance to adjust the launch info. |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 1126 | error = (*filter_callback)(launch_info, target); |
| 1127 | if (!error.Success()) { |
Jonas Devlieghere | 63e5fb7 | 2019-07-24 17:56:10 +0000 | [diff] [blame] | 1128 | LLDB_LOGF(log, |
| 1129 | "Platform::%s() StructuredDataPlugin launch " |
| 1130 | "filter failed.", |
| 1131 | __FUNCTION__); |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 1132 | return process_sp; |
| 1133 | } |
| 1134 | } |
| 1135 | } |
| 1136 | |
| 1137 | error = LaunchProcess(launch_info); |
| 1138 | if (error.Success()) { |
Jonas Devlieghere | 63e5fb7 | 2019-07-24 17:56:10 +0000 | [diff] [blame] | 1139 | LLDB_LOGF(log, |
| 1140 | "Platform::%s LaunchProcess() call succeeded (pid=%" PRIu64 ")", |
| 1141 | __FUNCTION__, launch_info.GetProcessID()); |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 1142 | if (launch_info.GetProcessID() != LLDB_INVALID_PROCESS_ID) { |
| 1143 | ProcessAttachInfo attach_info(launch_info); |
| 1144 | process_sp = Attach(attach_info, debugger, target, error); |
| 1145 | if (process_sp) { |
Jonas Devlieghere | 63e5fb7 | 2019-07-24 17:56:10 +0000 | [diff] [blame] | 1146 | LLDB_LOGF(log, "Platform::%s Attach() succeeded, Process plugin: %s", |
| 1147 | __FUNCTION__, process_sp->GetPluginName().AsCString()); |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 1148 | launch_info.SetHijackListener(attach_info.GetHijackListener()); |
Todd Fiala | ac33cc9 | 2014-10-09 01:02:08 +0000 | [diff] [blame] | 1149 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 1150 | // Since we attached to the process, it will think it needs to detach |
| 1151 | // if the process object just goes away without an explicit call to |
| 1152 | // Process::Kill() or Process::Detach(), so let it know to kill the |
| 1153 | // process if this happens. |
| 1154 | process_sp->SetShouldDetach(false); |
| 1155 | |
Adrian Prantl | 0509724 | 2018-04-30 16:49:04 +0000 | [diff] [blame] | 1156 | // If we didn't have any file actions, the pseudo terminal might have |
Jonas Devlieghere | 64ec505 | 2020-06-15 15:36:14 -0700 | [diff] [blame] | 1157 | // been used where the secondary side was given as the file to open for |
Adrian Prantl | 0509724 | 2018-04-30 16:49:04 +0000 | [diff] [blame] | 1158 | // stdin/out/err after we have already opened the master so we can |
| 1159 | // read/write stdin/out/err. |
Jonas Devlieghere | 64ec505 | 2020-06-15 15:36:14 -0700 | [diff] [blame] | 1160 | int pty_fd = launch_info.GetPTY().ReleasePrimaryFileDescriptor(); |
Pavel Labath | 07d6f88 | 2017-12-11 10:09:14 +0000 | [diff] [blame] | 1161 | if (pty_fd != PseudoTerminal::invalid_fd) { |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 1162 | process_sp->SetSTDIOFileDescriptor(pty_fd); |
| 1163 | } |
| 1164 | } else { |
Jonas Devlieghere | 63e5fb7 | 2019-07-24 17:56:10 +0000 | [diff] [blame] | 1165 | LLDB_LOGF(log, "Platform::%s Attach() failed: %s", __FUNCTION__, |
| 1166 | error.AsCString()); |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 1167 | } |
| 1168 | } else { |
Jonas Devlieghere | 63e5fb7 | 2019-07-24 17:56:10 +0000 | [diff] [blame] | 1169 | LLDB_LOGF(log, |
| 1170 | "Platform::%s LaunchProcess() returned launch_info with " |
| 1171 | "invalid process id", |
| 1172 | __FUNCTION__); |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 1173 | } |
| 1174 | } else { |
Jonas Devlieghere | 63e5fb7 | 2019-07-24 17:56:10 +0000 | [diff] [blame] | 1175 | LLDB_LOGF(log, "Platform::%s LaunchProcess() failed: %s", __FUNCTION__, |
| 1176 | error.AsCString()); |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 1177 | } |
| 1178 | |
| 1179 | return process_sp; |
Greg Clayton | 8b82f08 | 2011-04-12 05:54:46 +0000 | [diff] [blame] | 1180 | } |
Greg Clayton | b3a40ba | 2012-03-20 18:34:04 +0000 | [diff] [blame] | 1181 | |
Greg Clayton | b3a40ba | 2012-03-20 18:34:04 +0000 | [diff] [blame] | 1182 | lldb::PlatformSP |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 1183 | Platform::GetPlatformForArchitecture(const ArchSpec &arch, |
| 1184 | ArchSpec *platform_arch_ptr) { |
| 1185 | lldb::PlatformSP platform_sp; |
Zachary Turner | 97206d5 | 2017-05-12 04:51:55 +0000 | [diff] [blame] | 1186 | Status error; |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 1187 | if (arch.IsValid()) |
| 1188 | platform_sp = Platform::Create(arch, platform_arch_ptr, error); |
| 1189 | return platform_sp; |
Greg Clayton | b3a40ba | 2012-03-20 18:34:04 +0000 | [diff] [blame] | 1190 | } |
| 1191 | |
Greg Clayton | b3a40ba | 2012-03-20 18:34:04 +0000 | [diff] [blame] | 1192 | /// Lets a platform answer if it is compatible with a given |
| 1193 | /// architecture and the target triple contained within. |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 1194 | bool Platform::IsCompatibleArchitecture(const ArchSpec &arch, |
| 1195 | bool exact_arch_match, |
| 1196 | ArchSpec *compatible_arch_ptr) { |
| 1197 | // If the architecture is invalid, we must answer true... |
| 1198 | if (arch.IsValid()) { |
| 1199 | ArchSpec platform_arch; |
| 1200 | // Try for an exact architecture match first. |
| 1201 | if (exact_arch_match) { |
| 1202 | for (uint32_t arch_idx = 0; |
| 1203 | GetSupportedArchitectureAtIndex(arch_idx, platform_arch); |
| 1204 | ++arch_idx) { |
| 1205 | if (arch.IsExactMatch(platform_arch)) { |
| 1206 | if (compatible_arch_ptr) |
| 1207 | *compatible_arch_ptr = platform_arch; |
| 1208 | return true; |
Greg Clayton | 1e0c884 | 2013-01-11 20:49:54 +0000 | [diff] [blame] | 1209 | } |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 1210 | } |
| 1211 | } else { |
| 1212 | for (uint32_t arch_idx = 0; |
| 1213 | GetSupportedArchitectureAtIndex(arch_idx, platform_arch); |
| 1214 | ++arch_idx) { |
| 1215 | if (arch.IsCompatibleMatch(platform_arch)) { |
| 1216 | if (compatible_arch_ptr) |
| 1217 | *compatible_arch_ptr = platform_arch; |
| 1218 | return true; |
Greg Clayton | 7051231 | 2012-05-08 01:45:38 +0000 | [diff] [blame] | 1219 | } |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 1220 | } |
Greg Clayton | b3a40ba | 2012-03-20 18:34:04 +0000 | [diff] [blame] | 1221 | } |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 1222 | } |
| 1223 | if (compatible_arch_ptr) |
| 1224 | compatible_arch_ptr->Clear(); |
| 1225 | return false; |
Greg Clayton | b3a40ba | 2012-03-20 18:34:04 +0000 | [diff] [blame] | 1226 | } |
| 1227 | |
Zachary Turner | 97206d5 | 2017-05-12 04:51:55 +0000 | [diff] [blame] | 1228 | Status Platform::PutFile(const FileSpec &source, const FileSpec &destination, |
| 1229 | uint32_t uid, uint32_t gid) { |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 1230 | Log *log(lldb_private::GetLogIfAllCategoriesSet(LIBLLDB_LOG_PLATFORM)); |
Jonas Devlieghere | 63e5fb7 | 2019-07-24 17:56:10 +0000 | [diff] [blame] | 1231 | LLDB_LOGF(log, "[PutFile] Using block by block transfer....\n"); |
Vince Harron | 1b5a74e | 2015-01-21 22:42:49 +0000 | [diff] [blame] | 1232 | |
Lawrence D'Anna | 62c9fe4 | 2019-10-14 20:15:34 +0000 | [diff] [blame] | 1233 | auto source_open_options = |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 1234 | File::eOpenOptionRead | File::eOpenOptionCloseOnExec; |
Zachary Turner | 7d86ee5 | 2017-03-08 17:56:08 +0000 | [diff] [blame] | 1235 | namespace fs = llvm::sys::fs; |
| 1236 | if (fs::is_symlink_file(source.GetPath())) |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 1237 | source_open_options |= File::eOpenOptionDontFollowSymlinks; |
Vince Harron | 1b5a74e | 2015-01-21 22:42:49 +0000 | [diff] [blame] | 1238 | |
Lawrence D'Anna | 7ca15ba | 2019-09-27 14:33:35 +0000 | [diff] [blame] | 1239 | auto source_file = FileSystem::Instance().Open(source, source_open_options, |
| 1240 | lldb::eFilePermissionsUserRW); |
Lawrence D'Anna | 2fce113 | 2019-09-26 17:54:59 +0000 | [diff] [blame] | 1241 | if (!source_file) |
| 1242 | return Status(source_file.takeError()); |
| 1243 | Status error; |
| 1244 | uint32_t permissions = source_file.get()->GetPermissions(error); |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 1245 | if (permissions == 0) |
| 1246 | permissions = lldb::eFilePermissionsFileDefault; |
Vince Harron | 1b5a74e | 2015-01-21 22:42:49 +0000 | [diff] [blame] | 1247 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 1248 | lldb::user_id_t dest_file = OpenFile( |
| 1249 | destination, File::eOpenOptionCanCreate | File::eOpenOptionWrite | |
| 1250 | File::eOpenOptionTruncate | File::eOpenOptionCloseOnExec, |
| 1251 | permissions, error); |
Jonas Devlieghere | 63e5fb7 | 2019-07-24 17:56:10 +0000 | [diff] [blame] | 1252 | LLDB_LOGF(log, "dest_file = %" PRIu64 "\n", dest_file); |
Vince Harron | 1b5a74e | 2015-01-21 22:42:49 +0000 | [diff] [blame] | 1253 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 1254 | if (error.Fail()) |
| 1255 | return error; |
| 1256 | if (dest_file == UINT64_MAX) |
Zachary Turner | 97206d5 | 2017-05-12 04:51:55 +0000 | [diff] [blame] | 1257 | return Status("unable to open target file"); |
Jason Molenda | eb9902a | 2018-12-07 00:35:26 +0000 | [diff] [blame] | 1258 | lldb::DataBufferSP buffer_sp(new DataBufferHeap(1024 * 16, 0)); |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 1259 | uint64_t offset = 0; |
| 1260 | for (;;) { |
| 1261 | size_t bytes_read = buffer_sp->GetByteSize(); |
Lawrence D'Anna | 2fce113 | 2019-09-26 17:54:59 +0000 | [diff] [blame] | 1262 | error = source_file.get()->Read(buffer_sp->GetBytes(), bytes_read); |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 1263 | if (error.Fail() || bytes_read == 0) |
| 1264 | break; |
| 1265 | |
| 1266 | const uint64_t bytes_written = |
| 1267 | WriteFile(dest_file, offset, buffer_sp->GetBytes(), bytes_read, error); |
Vince Harron | 1b5a74e | 2015-01-21 22:42:49 +0000 | [diff] [blame] | 1268 | if (error.Fail()) |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 1269 | break; |
Vince Harron | 1b5a74e | 2015-01-21 22:42:49 +0000 | [diff] [blame] | 1270 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 1271 | offset += bytes_written; |
| 1272 | if (bytes_written != bytes_read) { |
Adrian Prantl | 0509724 | 2018-04-30 16:49:04 +0000 | [diff] [blame] | 1273 | // We didn't write the correct number of bytes, so adjust the file |
| 1274 | // position in the source file we are reading from... |
Lawrence D'Anna | 2fce113 | 2019-09-26 17:54:59 +0000 | [diff] [blame] | 1275 | source_file.get()->SeekFromStart(offset); |
Vince Harron | 1b5a74e | 2015-01-21 22:42:49 +0000 | [diff] [blame] | 1276 | } |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 1277 | } |
| 1278 | CloseFile(dest_file, error); |
Vince Harron | 1b5a74e | 2015-01-21 22:42:49 +0000 | [diff] [blame] | 1279 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 1280 | if (uid == UINT32_MAX && gid == UINT32_MAX) |
Daniel Malea | e0f8f57 | 2013-08-26 23:57:52 +0000 | [diff] [blame] | 1281 | return error; |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 1282 | |
| 1283 | // TODO: ChownFile? |
| 1284 | |
| 1285 | return error; |
Daniel Malea | e0f8f57 | 2013-08-26 23:57:52 +0000 | [diff] [blame] | 1286 | } |
| 1287 | |
Zachary Turner | 97206d5 | 2017-05-12 04:51:55 +0000 | [diff] [blame] | 1288 | Status Platform::GetFile(const FileSpec &source, const FileSpec &destination) { |
| 1289 | Status error("unimplemented"); |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 1290 | return error; |
Daniel Malea | e0f8f57 | 2013-08-26 23:57:52 +0000 | [diff] [blame] | 1291 | } |
| 1292 | |
Zachary Turner | 97206d5 | 2017-05-12 04:51:55 +0000 | [diff] [blame] | 1293 | Status |
| 1294 | Platform::CreateSymlink(const FileSpec &src, // The name of the link is in src |
| 1295 | const FileSpec &dst) // The symlink points to dst |
Greg Clayton | fbb7634 | 2013-11-20 21:07:01 +0000 | [diff] [blame] | 1296 | { |
Zachary Turner | 97206d5 | 2017-05-12 04:51:55 +0000 | [diff] [blame] | 1297 | Status error("unimplemented"); |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 1298 | return error; |
Greg Clayton | fbb7634 | 2013-11-20 21:07:01 +0000 | [diff] [blame] | 1299 | } |
| 1300 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 1301 | bool Platform::GetFileExists(const lldb_private::FileSpec &file_spec) { |
| 1302 | return false; |
| 1303 | } |
| 1304 | |
Zachary Turner | 97206d5 | 2017-05-12 04:51:55 +0000 | [diff] [blame] | 1305 | Status Platform::Unlink(const FileSpec &path) { |
| 1306 | Status error("unimplemented"); |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 1307 | return error; |
| 1308 | } |
| 1309 | |
Ed Maste | 37c40af | 2017-08-16 12:55:02 +0000 | [diff] [blame] | 1310 | MmapArgList Platform::GetMmapArgumentList(const ArchSpec &arch, addr_t addr, |
| 1311 | addr_t length, unsigned prot, |
| 1312 | unsigned flags, addr_t fd, |
| 1313 | addr_t offset) { |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 1314 | uint64_t flags_platform = 0; |
| 1315 | if (flags & eMmapFlagsPrivate) |
| 1316 | flags_platform |= MAP_PRIVATE; |
| 1317 | if (flags & eMmapFlagsAnon) |
| 1318 | flags_platform |= MAP_ANON; |
Ed Maste | 37c40af | 2017-08-16 12:55:02 +0000 | [diff] [blame] | 1319 | |
| 1320 | MmapArgList args({addr, length, prot, flags_platform, fd, offset}); |
| 1321 | return args; |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 1322 | } |
| 1323 | |
Zachary Turner | 97206d5 | 2017-05-12 04:51:55 +0000 | [diff] [blame] | 1324 | lldb_private::Status Platform::RunShellCommand( |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 1325 | const char *command, // Shouldn't be nullptr |
| 1326 | const FileSpec & |
| 1327 | working_dir, // Pass empty FileSpec to use the current working directory |
| 1328 | int *status_ptr, // Pass nullptr if you don't want the process exit status |
| 1329 | int *signo_ptr, // Pass nullptr if you don't want the signal that caused the |
| 1330 | // process to exit |
| 1331 | std::string |
| 1332 | *command_output, // Pass nullptr if you don't want the command output |
Pavel Labath | 19dd1a0 | 2018-05-10 10:46:03 +0000 | [diff] [blame] | 1333 | const Timeout<std::micro> &timeout) { |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 1334 | if (IsHost()) |
| 1335 | return Host::RunShellCommand(command, working_dir, status_ptr, signo_ptr, |
Pavel Labath | 19dd1a0 | 2018-05-10 10:46:03 +0000 | [diff] [blame] | 1336 | command_output, timeout); |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 1337 | else |
Zachary Turner | 97206d5 | 2017-05-12 04:51:55 +0000 | [diff] [blame] | 1338 | return Status("unimplemented"); |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 1339 | } |
| 1340 | |
| 1341 | bool Platform::CalculateMD5(const FileSpec &file_spec, uint64_t &low, |
| 1342 | uint64_t &high) { |
Zachary Turner | 076a259 | 2017-03-20 23:54:54 +0000 | [diff] [blame] | 1343 | if (!IsHost()) |
Daniel Malea | e0f8f57 | 2013-08-26 23:57:52 +0000 | [diff] [blame] | 1344 | return false; |
Zachary Turner | 076a259 | 2017-03-20 23:54:54 +0000 | [diff] [blame] | 1345 | auto Result = llvm::sys::fs::md5_contents(file_spec.GetPath()); |
| 1346 | if (!Result) |
| 1347 | return false; |
| 1348 | std::tie(high, low) = Result->words(); |
| 1349 | return true; |
Daniel Malea | e0f8f57 | 2013-08-26 23:57:52 +0000 | [diff] [blame] | 1350 | } |
| 1351 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 1352 | void Platform::SetLocalCacheDirectory(const char *local) { |
| 1353 | m_local_cache_directory.assign(local); |
Greg Clayton | fbb7634 | 2013-11-20 21:07:01 +0000 | [diff] [blame] | 1354 | } |
| 1355 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 1356 | const char *Platform::GetLocalCacheDirectory() { |
| 1357 | return m_local_cache_directory.c_str(); |
Robert Flack | 96ad3de | 2015-05-09 15:53:31 +0000 | [diff] [blame] | 1358 | } |
Greg Clayton | fbb7634 | 2013-11-20 21:07:01 +0000 | [diff] [blame] | 1359 | |
Tatyana Krasnukha | 8fe53c49 | 2018-09-26 18:50:19 +0000 | [diff] [blame] | 1360 | static constexpr OptionDefinition g_rsync_option_table[] = { |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 1361 | {LLDB_OPT_SET_ALL, false, "rsync", 'r', OptionParser::eNoArgument, nullptr, |
Tatyana Krasnukha | 8fe53c49 | 2018-09-26 18:50:19 +0000 | [diff] [blame] | 1362 | {}, 0, eArgTypeNone, "Enable rsync."}, |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 1363 | {LLDB_OPT_SET_ALL, false, "rsync-opts", 'R', |
Tatyana Krasnukha | 8fe53c49 | 2018-09-26 18:50:19 +0000 | [diff] [blame] | 1364 | OptionParser::eRequiredArgument, nullptr, {}, 0, eArgTypeCommandName, |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 1365 | "Platform-specific options required for rsync to work."}, |
| 1366 | {LLDB_OPT_SET_ALL, false, "rsync-prefix", 'P', |
Tatyana Krasnukha | 8fe53c49 | 2018-09-26 18:50:19 +0000 | [diff] [blame] | 1367 | OptionParser::eRequiredArgument, nullptr, {}, 0, eArgTypeCommandName, |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 1368 | "Platform-specific rsync prefix put before the remote path."}, |
| 1369 | {LLDB_OPT_SET_ALL, false, "ignore-remote-hostname", 'i', |
Tatyana Krasnukha | 8fe53c49 | 2018-09-26 18:50:19 +0000 | [diff] [blame] | 1370 | OptionParser::eNoArgument, nullptr, {}, 0, eArgTypeNone, |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 1371 | "Do not automatically fill in the remote hostname when composing the " |
| 1372 | "rsync command."}, |
Daniel Malea | e0f8f57 | 2013-08-26 23:57:52 +0000 | [diff] [blame] | 1373 | }; |
| 1374 | |
Tatyana Krasnukha | 8fe53c49 | 2018-09-26 18:50:19 +0000 | [diff] [blame] | 1375 | static constexpr OptionDefinition g_ssh_option_table[] = { |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 1376 | {LLDB_OPT_SET_ALL, false, "ssh", 's', OptionParser::eNoArgument, nullptr, |
Tatyana Krasnukha | 8fe53c49 | 2018-09-26 18:50:19 +0000 | [diff] [blame] | 1377 | {}, 0, eArgTypeNone, "Enable SSH."}, |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 1378 | {LLDB_OPT_SET_ALL, false, "ssh-opts", 'S', OptionParser::eRequiredArgument, |
Tatyana Krasnukha | 8fe53c49 | 2018-09-26 18:50:19 +0000 | [diff] [blame] | 1379 | nullptr, {}, 0, eArgTypeCommandName, |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 1380 | "Platform-specific options required for SSH to work."}, |
Daniel Malea | e0f8f57 | 2013-08-26 23:57:52 +0000 | [diff] [blame] | 1381 | }; |
| 1382 | |
Tatyana Krasnukha | 8fe53c49 | 2018-09-26 18:50:19 +0000 | [diff] [blame] | 1383 | static constexpr OptionDefinition g_caching_option_table[] = { |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 1384 | {LLDB_OPT_SET_ALL, false, "local-cache-dir", 'c', |
Tatyana Krasnukha | 8fe53c49 | 2018-09-26 18:50:19 +0000 | [diff] [blame] | 1385 | OptionParser::eRequiredArgument, nullptr, {}, 0, eArgTypePath, |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 1386 | "Path in which to store local copies of files."}, |
Daniel Malea | e0f8f57 | 2013-08-26 23:57:52 +0000 | [diff] [blame] | 1387 | }; |
| 1388 | |
Zachary Turner | 1f0f5b5 | 2016-09-22 20:22:55 +0000 | [diff] [blame] | 1389 | llvm::ArrayRef<OptionDefinition> OptionGroupPlatformRSync::GetDefinitions() { |
Zachary Turner | 7060243 | 2016-09-22 21:06:13 +0000 | [diff] [blame] | 1390 | return llvm::makeArrayRef(g_rsync_option_table); |
Daniel Malea | e0f8f57 | 2013-08-26 23:57:52 +0000 | [diff] [blame] | 1391 | } |
| 1392 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 1393 | void OptionGroupPlatformRSync::OptionParsingStarting( |
| 1394 | ExecutionContext *execution_context) { |
| 1395 | m_rsync = false; |
| 1396 | m_rsync_opts.clear(); |
| 1397 | m_rsync_prefix.clear(); |
| 1398 | m_ignores_remote_hostname = false; |
Daniel Malea | e0f8f57 | 2013-08-26 23:57:52 +0000 | [diff] [blame] | 1399 | } |
| 1400 | |
Zachary Turner | 97206d5 | 2017-05-12 04:51:55 +0000 | [diff] [blame] | 1401 | lldb_private::Status |
Todd Fiala | e1cfbc7 | 2016-08-11 23:51:28 +0000 | [diff] [blame] | 1402 | OptionGroupPlatformRSync::SetOptionValue(uint32_t option_idx, |
Zachary Turner | 8cef4b0 | 2016-09-23 17:48:13 +0000 | [diff] [blame] | 1403 | llvm::StringRef option_arg, |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 1404 | ExecutionContext *execution_context) { |
Zachary Turner | 97206d5 | 2017-05-12 04:51:55 +0000 | [diff] [blame] | 1405 | Status error; |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 1406 | char short_option = (char)GetDefinitions()[option_idx].short_option; |
| 1407 | switch (short_option) { |
| 1408 | case 'r': |
| 1409 | m_rsync = true; |
| 1410 | break; |
| 1411 | |
| 1412 | case 'R': |
Benjamin Kramer | adcd026 | 2020-01-28 20:23:46 +0100 | [diff] [blame] | 1413 | m_rsync_opts.assign(std::string(option_arg)); |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 1414 | break; |
| 1415 | |
| 1416 | case 'P': |
Benjamin Kramer | adcd026 | 2020-01-28 20:23:46 +0100 | [diff] [blame] | 1417 | m_rsync_prefix.assign(std::string(option_arg)); |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 1418 | break; |
| 1419 | |
| 1420 | case 'i': |
| 1421 | m_ignores_remote_hostname = true; |
| 1422 | break; |
| 1423 | |
| 1424 | default: |
| 1425 | error.SetErrorStringWithFormat("unrecognized option '%c'", short_option); |
| 1426 | break; |
| 1427 | } |
| 1428 | |
| 1429 | return error; |
Daniel Malea | e0f8f57 | 2013-08-26 23:57:52 +0000 | [diff] [blame] | 1430 | } |
| 1431 | |
Greg Clayton | 4116e93 | 2012-05-15 02:33:01 +0000 | [diff] [blame] | 1432 | lldb::BreakpointSP |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 1433 | Platform::SetThreadCreationBreakpoint(lldb_private::Target &target) { |
| 1434 | return lldb::BreakpointSP(); |
Greg Clayton | 4116e93 | 2012-05-15 02:33:01 +0000 | [diff] [blame] | 1435 | } |
Greg Clayton | b3a40ba | 2012-03-20 18:34:04 +0000 | [diff] [blame] | 1436 | |
Zachary Turner | 1f0f5b5 | 2016-09-22 20:22:55 +0000 | [diff] [blame] | 1437 | llvm::ArrayRef<OptionDefinition> OptionGroupPlatformSSH::GetDefinitions() { |
Zachary Turner | 7060243 | 2016-09-22 21:06:13 +0000 | [diff] [blame] | 1438 | return llvm::makeArrayRef(g_ssh_option_table); |
Daniel Malea | e0f8f57 | 2013-08-26 23:57:52 +0000 | [diff] [blame] | 1439 | } |
| 1440 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 1441 | void OptionGroupPlatformSSH::OptionParsingStarting( |
| 1442 | ExecutionContext *execution_context) { |
| 1443 | m_ssh = false; |
| 1444 | m_ssh_opts.clear(); |
Daniel Malea | e0f8f57 | 2013-08-26 23:57:52 +0000 | [diff] [blame] | 1445 | } |
| 1446 | |
Zachary Turner | 97206d5 | 2017-05-12 04:51:55 +0000 | [diff] [blame] | 1447 | lldb_private::Status |
Todd Fiala | e1cfbc7 | 2016-08-11 23:51:28 +0000 | [diff] [blame] | 1448 | OptionGroupPlatformSSH::SetOptionValue(uint32_t option_idx, |
Zachary Turner | 8cef4b0 | 2016-09-23 17:48:13 +0000 | [diff] [blame] | 1449 | llvm::StringRef option_arg, |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 1450 | ExecutionContext *execution_context) { |
Zachary Turner | 97206d5 | 2017-05-12 04:51:55 +0000 | [diff] [blame] | 1451 | Status error; |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 1452 | char short_option = (char)GetDefinitions()[option_idx].short_option; |
| 1453 | switch (short_option) { |
| 1454 | case 's': |
| 1455 | m_ssh = true; |
| 1456 | break; |
| 1457 | |
| 1458 | case 'S': |
Benjamin Kramer | adcd026 | 2020-01-28 20:23:46 +0100 | [diff] [blame] | 1459 | m_ssh_opts.assign(std::string(option_arg)); |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 1460 | break; |
| 1461 | |
| 1462 | default: |
| 1463 | error.SetErrorStringWithFormat("unrecognized option '%c'", short_option); |
| 1464 | break; |
| 1465 | } |
| 1466 | |
| 1467 | return error; |
| 1468 | } |
| 1469 | |
Zachary Turner | 1f0f5b5 | 2016-09-22 20:22:55 +0000 | [diff] [blame] | 1470 | llvm::ArrayRef<OptionDefinition> OptionGroupPlatformCaching::GetDefinitions() { |
Zachary Turner | 7060243 | 2016-09-22 21:06:13 +0000 | [diff] [blame] | 1471 | return llvm::makeArrayRef(g_caching_option_table); |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 1472 | } |
| 1473 | |
| 1474 | void OptionGroupPlatformCaching::OptionParsingStarting( |
| 1475 | ExecutionContext *execution_context) { |
| 1476 | m_cache_dir.clear(); |
| 1477 | } |
| 1478 | |
Zachary Turner | 97206d5 | 2017-05-12 04:51:55 +0000 | [diff] [blame] | 1479 | lldb_private::Status OptionGroupPlatformCaching::SetOptionValue( |
Zachary Turner | 8cef4b0 | 2016-09-23 17:48:13 +0000 | [diff] [blame] | 1480 | uint32_t option_idx, llvm::StringRef option_arg, |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 1481 | ExecutionContext *execution_context) { |
Zachary Turner | 97206d5 | 2017-05-12 04:51:55 +0000 | [diff] [blame] | 1482 | Status error; |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 1483 | char short_option = (char)GetDefinitions()[option_idx].short_option; |
| 1484 | switch (short_option) { |
| 1485 | case 'c': |
Benjamin Kramer | adcd026 | 2020-01-28 20:23:46 +0100 | [diff] [blame] | 1486 | m_cache_dir.assign(std::string(option_arg)); |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 1487 | break; |
| 1488 | |
| 1489 | default: |
| 1490 | error.SetErrorStringWithFormat("unrecognized option '%c'", short_option); |
| 1491 | break; |
| 1492 | } |
| 1493 | |
| 1494 | return error; |
| 1495 | } |
| 1496 | |
Pavel Labath | 62930e5 | 2018-01-10 11:57:31 +0000 | [diff] [blame] | 1497 | Environment Platform::GetEnvironment() { return Environment(); } |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 1498 | |
| 1499 | const std::vector<ConstString> &Platform::GetTrapHandlerSymbolNames() { |
| 1500 | if (!m_calculated_trap_handlers) { |
| 1501 | std::lock_guard<std::mutex> guard(m_mutex); |
| 1502 | if (!m_calculated_trap_handlers) { |
| 1503 | CalculateTrapHandlerSymbolNames(); |
| 1504 | m_calculated_trap_handlers = true; |
Daniel Malea | e0f8f57 | 2013-08-26 23:57:52 +0000 | [diff] [blame] | 1505 | } |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 1506 | } |
| 1507 | return m_trap_handlers; |
Daniel Malea | e0f8f57 | 2013-08-26 23:57:52 +0000 | [diff] [blame] | 1508 | } |
| 1509 | |
Zachary Turner | 97206d5 | 2017-05-12 04:51:55 +0000 | [diff] [blame] | 1510 | Status Platform::GetCachedExecutable( |
| 1511 | ModuleSpec &module_spec, lldb::ModuleSP &module_sp, |
| 1512 | const FileSpecList *module_search_paths_ptr, Platform &remote_platform) { |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 1513 | const auto platform_spec = module_spec.GetFileSpec(); |
| 1514 | const auto error = LoadCachedExecutable( |
| 1515 | module_spec, module_sp, module_search_paths_ptr, remote_platform); |
| 1516 | if (error.Success()) { |
| 1517 | module_spec.GetFileSpec() = module_sp->GetFileSpec(); |
| 1518 | module_spec.GetPlatformFileSpec() = platform_spec; |
| 1519 | } |
| 1520 | |
| 1521 | return error; |
Daniel Malea | e0f8f57 | 2013-08-26 23:57:52 +0000 | [diff] [blame] | 1522 | } |
| 1523 | |
Zachary Turner | 97206d5 | 2017-05-12 04:51:55 +0000 | [diff] [blame] | 1524 | Status Platform::LoadCachedExecutable( |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 1525 | const ModuleSpec &module_spec, lldb::ModuleSP &module_sp, |
| 1526 | const FileSpecList *module_search_paths_ptr, Platform &remote_platform) { |
| 1527 | return GetRemoteSharedModule(module_spec, nullptr, module_sp, |
| 1528 | [&](const ModuleSpec &spec) { |
| 1529 | return remote_platform.ResolveExecutable( |
| 1530 | spec, module_sp, module_search_paths_ptr); |
| 1531 | }, |
| 1532 | nullptr); |
Daniel Malea | e0f8f57 | 2013-08-26 23:57:52 +0000 | [diff] [blame] | 1533 | } |
| 1534 | |
Zachary Turner | 97206d5 | 2017-05-12 04:51:55 +0000 | [diff] [blame] | 1535 | Status Platform::GetRemoteSharedModule(const ModuleSpec &module_spec, |
| 1536 | Process *process, |
| 1537 | lldb::ModuleSP &module_sp, |
| 1538 | const ModuleResolver &module_resolver, |
| 1539 | bool *did_create_ptr) { |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 1540 | // Get module information from a target. |
| 1541 | ModuleSpec resolved_module_spec; |
| 1542 | bool got_module_spec = false; |
| 1543 | if (process) { |
| 1544 | // Try to get module information from the process |
| 1545 | if (process->GetModuleSpec(module_spec.GetFileSpec(), |
| 1546 | module_spec.GetArchitecture(), |
| 1547 | resolved_module_spec)) { |
Jonas Devlieghere | a6682a4 | 2018-12-15 00:15:33 +0000 | [diff] [blame] | 1548 | if (!module_spec.GetUUID().IsValid() || |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 1549 | module_spec.GetUUID() == resolved_module_spec.GetUUID()) { |
| 1550 | got_module_spec = true; |
| 1551 | } |
Daniel Malea | e0f8f57 | 2013-08-26 23:57:52 +0000 | [diff] [blame] | 1552 | } |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 1553 | } |
Daniel Malea | e0f8f57 | 2013-08-26 23:57:52 +0000 | [diff] [blame] | 1554 | |
Jonas Devlieghere | a6682a4 | 2018-12-15 00:15:33 +0000 | [diff] [blame] | 1555 | if (!module_spec.GetArchitecture().IsValid()) { |
Zachary Turner | 97206d5 | 2017-05-12 04:51:55 +0000 | [diff] [blame] | 1556 | Status error; |
Adrian Prantl | 0509724 | 2018-04-30 16:49:04 +0000 | [diff] [blame] | 1557 | // No valid architecture was specified, ask the platform for the |
| 1558 | // architectures that we should be using (in the correct order) and see if |
| 1559 | // we can find a match that way |
Jason Molenda | 3fce2fd | 2016-10-05 02:29:13 +0000 | [diff] [blame] | 1560 | ModuleSpec arch_module_spec(module_spec); |
| 1561 | for (uint32_t idx = 0; GetSupportedArchitectureAtIndex( |
| 1562 | idx, arch_module_spec.GetArchitecture()); |
| 1563 | ++idx) { |
| 1564 | error = ModuleList::GetSharedModule(arch_module_spec, module_sp, nullptr, |
| 1565 | nullptr, nullptr); |
| 1566 | // Did we find an executable using one of the |
| 1567 | if (error.Success() && module_sp) |
| 1568 | break; |
| 1569 | } |
| 1570 | if (module_sp) |
| 1571 | got_module_spec = true; |
| 1572 | } |
| 1573 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 1574 | if (!got_module_spec) { |
Oleksiy Vyalov | 037f6b9 | 2015-03-24 23:45:49 +0000 | [diff] [blame] | 1575 | // Get module information from a target. |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 1576 | if (!GetModuleSpec(module_spec.GetFileSpec(), module_spec.GetArchitecture(), |
| 1577 | resolved_module_spec)) { |
Jonas Devlieghere | a6682a4 | 2018-12-15 00:15:33 +0000 | [diff] [blame] | 1578 | if (!module_spec.GetUUID().IsValid() || |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 1579 | module_spec.GetUUID() == resolved_module_spec.GetUUID()) { |
| 1580 | return module_resolver(module_spec); |
| 1581 | } |
Tamas Berghammer | 7cb18bf | 2015-03-24 11:15:23 +0000 | [diff] [blame] | 1582 | } |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 1583 | } |
Tamas Berghammer | 7cb18bf | 2015-03-24 11:15:23 +0000 | [diff] [blame] | 1584 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 1585 | // If we are looking for a specific UUID, make sure resolved_module_spec has |
| 1586 | // the same one before we search. |
| 1587 | if (module_spec.GetUUID().IsValid()) { |
| 1588 | resolved_module_spec.GetUUID() = module_spec.GetUUID(); |
| 1589 | } |
Jason Molenda | 85967fa | 2016-07-12 03:25:22 +0000 | [diff] [blame] | 1590 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 1591 | // Trying to find a module by UUID on local file system. |
| 1592 | const auto error = module_resolver(resolved_module_spec); |
| 1593 | if (error.Fail()) { |
| 1594 | if (GetCachedSharedModule(resolved_module_spec, module_sp, did_create_ptr)) |
Zachary Turner | 97206d5 | 2017-05-12 04:51:55 +0000 | [diff] [blame] | 1595 | return Status(); |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 1596 | } |
Oleksiy Vyalov | 63acdfd | 2015-03-10 01:15:28 +0000 | [diff] [blame] | 1597 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 1598 | return error; |
Oleksiy Vyalov | 037f6b9 | 2015-03-24 23:45:49 +0000 | [diff] [blame] | 1599 | } |
| 1600 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 1601 | bool Platform::GetCachedSharedModule(const ModuleSpec &module_spec, |
| 1602 | lldb::ModuleSP &module_sp, |
| 1603 | bool *did_create_ptr) { |
| 1604 | if (IsHost() || !GetGlobalPlatformProperties()->GetUseModuleCache() || |
| 1605 | !GetGlobalPlatformProperties()->GetModuleCacheDirectory()) |
Oleksiy Vyalov | 280d8dc | 2015-04-15 14:35:10 +0000 | [diff] [blame] | 1606 | return false; |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 1607 | |
| 1608 | Log *log = GetLogIfAnyCategoriesSet(LIBLLDB_LOG_PLATFORM); |
| 1609 | |
| 1610 | // Check local cache for a module. |
| 1611 | auto error = m_module_cache->GetAndPut( |
| 1612 | GetModuleCacheRoot(), GetCacheHostname(), module_spec, |
| 1613 | [this](const ModuleSpec &module_spec, |
| 1614 | const FileSpec &tmp_download_file_spec) { |
| 1615 | return DownloadModuleSlice( |
| 1616 | module_spec.GetFileSpec(), module_spec.GetObjectOffset(), |
| 1617 | module_spec.GetObjectSize(), tmp_download_file_spec); |
| 1618 | |
| 1619 | }, |
| 1620 | [this](const ModuleSP &module_sp, |
| 1621 | const FileSpec &tmp_download_file_spec) { |
| 1622 | return DownloadSymbolFile(module_sp, tmp_download_file_spec); |
| 1623 | }, |
| 1624 | module_sp, did_create_ptr); |
| 1625 | if (error.Success()) |
| 1626 | return true; |
| 1627 | |
Jonas Devlieghere | 63e5fb7 | 2019-07-24 17:56:10 +0000 | [diff] [blame] | 1628 | LLDB_LOGF(log, "Platform::%s - module %s not found in local cache: %s", |
| 1629 | __FUNCTION__, module_spec.GetUUID().GetAsString().c_str(), |
| 1630 | error.AsCString()); |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 1631 | return false; |
Oleksiy Vyalov | 63acdfd | 2015-03-10 01:15:28 +0000 | [diff] [blame] | 1632 | } |
| 1633 | |
Zachary Turner | 97206d5 | 2017-05-12 04:51:55 +0000 | [diff] [blame] | 1634 | Status Platform::DownloadModuleSlice(const FileSpec &src_file_spec, |
| 1635 | const uint64_t src_offset, |
| 1636 | const uint64_t src_size, |
| 1637 | const FileSpec &dst_file_spec) { |
| 1638 | Status error; |
Oleksiy Vyalov | 63acdfd | 2015-03-10 01:15:28 +0000 | [diff] [blame] | 1639 | |
Pavel Labath | e3ad2e2 | 2017-03-21 13:49:50 +0000 | [diff] [blame] | 1640 | std::error_code EC; |
Fangrui Song | d9b948b | 2019-08-05 05:43:48 +0000 | [diff] [blame] | 1641 | llvm::raw_fd_ostream dst(dst_file_spec.GetPath(), EC, llvm::sys::fs::OF_None); |
Pavel Labath | e3ad2e2 | 2017-03-21 13:49:50 +0000 | [diff] [blame] | 1642 | if (EC) { |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 1643 | error.SetErrorStringWithFormat("unable to open destination file: %s", |
| 1644 | dst_file_spec.GetPath().c_str()); |
Oleksiy Vyalov | 63acdfd | 2015-03-10 01:15:28 +0000 | [diff] [blame] | 1645 | return error; |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 1646 | } |
Oleksiy Vyalov | 63acdfd | 2015-03-10 01:15:28 +0000 | [diff] [blame] | 1647 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 1648 | auto src_fd = OpenFile(src_file_spec, File::eOpenOptionRead, |
| 1649 | lldb::eFilePermissionsFileDefault, error); |
Tamas Berghammer | ec3f92a | 2015-08-12 11:10:25 +0000 | [diff] [blame] | 1650 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 1651 | if (error.Fail()) { |
| 1652 | error.SetErrorStringWithFormat("unable to open source file: %s", |
| 1653 | error.AsCString()); |
| 1654 | return error; |
| 1655 | } |
Oleksiy Vyalov | 6f00106 | 2015-03-25 17:58:13 +0000 | [diff] [blame] | 1656 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 1657 | std::vector<char> buffer(1024); |
| 1658 | auto offset = src_offset; |
| 1659 | uint64_t total_bytes_read = 0; |
| 1660 | while (total_bytes_read < src_size) { |
| 1661 | const auto to_read = std::min(static_cast<uint64_t>(buffer.size()), |
| 1662 | src_size - total_bytes_read); |
| 1663 | const uint64_t n_read = |
| 1664 | ReadFile(src_fd, offset, &buffer[0], to_read, error); |
Tamas Berghammer | ccd6cff | 2015-12-08 14:08:19 +0000 | [diff] [blame] | 1665 | if (error.Fail()) |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 1666 | break; |
| 1667 | if (n_read == 0) { |
| 1668 | error.SetErrorString("read 0 bytes"); |
| 1669 | break; |
| 1670 | } |
| 1671 | offset += n_read; |
| 1672 | total_bytes_read += n_read; |
| 1673 | dst.write(&buffer[0], n_read); |
| 1674 | } |
Tamas Berghammer | ccd6cff | 2015-12-08 14:08:19 +0000 | [diff] [blame] | 1675 | |
Zachary Turner | 97206d5 | 2017-05-12 04:51:55 +0000 | [diff] [blame] | 1676 | Status close_error; |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 1677 | CloseFile(src_fd, close_error); // Ignoring close error. |
| 1678 | |
| 1679 | return error; |
Tamas Berghammer | ccd6cff | 2015-12-08 14:08:19 +0000 | [diff] [blame] | 1680 | } |
| 1681 | |
Zachary Turner | 97206d5 | 2017-05-12 04:51:55 +0000 | [diff] [blame] | 1682 | Status Platform::DownloadSymbolFile(const lldb::ModuleSP &module_sp, |
| 1683 | const FileSpec &dst_file_spec) { |
| 1684 | return Status( |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 1685 | "Symbol file downloading not supported by the default platform."); |
Tamas Berghammer | ccd6cff | 2015-12-08 14:08:19 +0000 | [diff] [blame] | 1686 | } |
Aidan Dodds | 933d8db | 2016-02-22 17:29:56 +0000 | [diff] [blame] | 1687 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 1688 | FileSpec Platform::GetModuleCacheRoot() { |
| 1689 | auto dir_spec = GetGlobalPlatformProperties()->GetModuleCacheDirectory(); |
| 1690 | dir_spec.AppendPathComponent(GetName().AsCString()); |
| 1691 | return dir_spec; |
| 1692 | } |
Aidan Dodds | 933d8db | 2016-02-22 17:29:56 +0000 | [diff] [blame] | 1693 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 1694 | const char *Platform::GetCacheHostname() { return GetHostname(); } |
Aidan Dodds | 933d8db | 2016-02-22 17:29:56 +0000 | [diff] [blame] | 1695 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 1696 | const UnixSignalsSP &Platform::GetRemoteUnixSignals() { |
| 1697 | static const auto s_default_unix_signals_sp = std::make_shared<UnixSignals>(); |
| 1698 | return s_default_unix_signals_sp; |
| 1699 | } |
Aidan Dodds | 933d8db | 2016-02-22 17:29:56 +0000 | [diff] [blame] | 1700 | |
Zachary Turner | a89ce43 | 2019-03-06 18:20:23 +0000 | [diff] [blame] | 1701 | UnixSignalsSP Platform::GetUnixSignals() { |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 1702 | if (IsHost()) |
Zachary Turner | a89ce43 | 2019-03-06 18:20:23 +0000 | [diff] [blame] | 1703 | return UnixSignals::CreateForHost(); |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 1704 | return GetRemoteUnixSignals(); |
| 1705 | } |
Aidan Dodds | 933d8db | 2016-02-22 17:29:56 +0000 | [diff] [blame] | 1706 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 1707 | uint32_t Platform::LoadImage(lldb_private::Process *process, |
| 1708 | const lldb_private::FileSpec &local_file, |
| 1709 | const lldb_private::FileSpec &remote_file, |
Zachary Turner | 97206d5 | 2017-05-12 04:51:55 +0000 | [diff] [blame] | 1710 | lldb_private::Status &error) { |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 1711 | if (local_file && remote_file) { |
| 1712 | // Both local and remote file was specified. Install the local file to the |
| 1713 | // given location. |
| 1714 | if (IsRemote() || local_file != remote_file) { |
| 1715 | error = Install(local_file, remote_file); |
| 1716 | if (error.Fail()) |
| 1717 | return LLDB_INVALID_IMAGE_TOKEN; |
| 1718 | } |
Jim Ingham | 0d231f7 | 2018-06-28 20:02:11 +0000 | [diff] [blame] | 1719 | return DoLoadImage(process, remote_file, nullptr, error); |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 1720 | } |
Aidan Dodds | 933d8db | 2016-02-22 17:29:56 +0000 | [diff] [blame] | 1721 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 1722 | if (local_file) { |
| 1723 | // Only local file was specified. Install it to the current working |
| 1724 | // directory. |
| 1725 | FileSpec target_file = GetWorkingDirectory(); |
| 1726 | target_file.AppendPathComponent(local_file.GetFilename().AsCString()); |
| 1727 | if (IsRemote() || local_file != target_file) { |
| 1728 | error = Install(local_file, target_file); |
| 1729 | if (error.Fail()) |
| 1730 | return LLDB_INVALID_IMAGE_TOKEN; |
| 1731 | } |
Jim Ingham | 0d231f7 | 2018-06-28 20:02:11 +0000 | [diff] [blame] | 1732 | return DoLoadImage(process, target_file, nullptr, error); |
Jonas Devlieghere | 463a48e | 2019-07-26 18:14:08 +0000 | [diff] [blame] | 1733 | } |
Aidan Dodds | 933d8db | 2016-02-22 17:29:56 +0000 | [diff] [blame] | 1734 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 1735 | if (remote_file) { |
| 1736 | // Only remote file was specified so we don't have to do any copying |
Jim Ingham | 0d231f7 | 2018-06-28 20:02:11 +0000 | [diff] [blame] | 1737 | return DoLoadImage(process, remote_file, nullptr, error); |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 1738 | } |
Aidan Dodds | 933d8db | 2016-02-22 17:29:56 +0000 | [diff] [blame] | 1739 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 1740 | error.SetErrorString("Neither local nor remote file was specified"); |
| 1741 | return LLDB_INVALID_IMAGE_TOKEN; |
| 1742 | } |
Aidan Dodds | 933d8db | 2016-02-22 17:29:56 +0000 | [diff] [blame] | 1743 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 1744 | uint32_t Platform::DoLoadImage(lldb_private::Process *process, |
| 1745 | const lldb_private::FileSpec &remote_file, |
Jim Ingham | 0d231f7 | 2018-06-28 20:02:11 +0000 | [diff] [blame] | 1746 | const std::vector<std::string> *paths, |
| 1747 | lldb_private::Status &error, |
| 1748 | lldb_private::FileSpec *loaded_image) { |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 1749 | error.SetErrorString("LoadImage is not supported on the current platform"); |
| 1750 | return LLDB_INVALID_IMAGE_TOKEN; |
| 1751 | } |
Ulrich Weigand | bb00d0b | 2016-04-14 14:28:34 +0000 | [diff] [blame] | 1752 | |
Jim Ingham | 0d231f7 | 2018-06-28 20:02:11 +0000 | [diff] [blame] | 1753 | uint32_t Platform::LoadImageUsingPaths(lldb_private::Process *process, |
| 1754 | const lldb_private::FileSpec &remote_filename, |
| 1755 | const std::vector<std::string> &paths, |
| 1756 | lldb_private::Status &error, |
| 1757 | lldb_private::FileSpec *loaded_path) |
| 1758 | { |
| 1759 | FileSpec file_to_use; |
| 1760 | if (remote_filename.IsAbsolute()) |
Jonas Devlieghere | 8f3be7a | 2018-11-01 21:05:36 +0000 | [diff] [blame] | 1761 | file_to_use = FileSpec(remote_filename.GetFilename().GetStringRef(), |
| 1762 | |
| 1763 | remote_filename.GetPathStyle()); |
Jim Ingham | 0d231f7 | 2018-06-28 20:02:11 +0000 | [diff] [blame] | 1764 | else |
| 1765 | file_to_use = remote_filename; |
Jonas Devlieghere | 463a48e | 2019-07-26 18:14:08 +0000 | [diff] [blame] | 1766 | |
Jim Ingham | 0d231f7 | 2018-06-28 20:02:11 +0000 | [diff] [blame] | 1767 | return DoLoadImage(process, file_to_use, &paths, error, loaded_path); |
| 1768 | } |
| 1769 | |
Zachary Turner | 97206d5 | 2017-05-12 04:51:55 +0000 | [diff] [blame] | 1770 | Status Platform::UnloadImage(lldb_private::Process *process, |
| 1771 | uint32_t image_token) { |
| 1772 | return Status("UnloadImage is not supported on the current platform"); |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 1773 | } |
Aidan Dodds | 933d8db | 2016-02-22 17:29:56 +0000 | [diff] [blame] | 1774 | |
Zachary Turner | 3165945 | 2016-11-17 21:15:14 +0000 | [diff] [blame] | 1775 | lldb::ProcessSP Platform::ConnectProcess(llvm::StringRef connect_url, |
| 1776 | llvm::StringRef plugin_name, |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 1777 | lldb_private::Debugger &debugger, |
| 1778 | lldb_private::Target *target, |
Zachary Turner | 97206d5 | 2017-05-12 04:51:55 +0000 | [diff] [blame] | 1779 | lldb_private::Status &error) { |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 1780 | error.Clear(); |
Aidan Dodds | 933d8db | 2016-02-22 17:29:56 +0000 | [diff] [blame] | 1781 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 1782 | if (!target) { |
Jason Molenda | df9f796 | 2018-10-23 23:45:56 +0000 | [diff] [blame] | 1783 | ArchSpec arch; |
| 1784 | if (target && target->GetArchitecture().IsValid()) |
| 1785 | arch = target->GetArchitecture(); |
| 1786 | else |
| 1787 | arch = Target::GetDefaultArchitecture(); |
| 1788 | |
| 1789 | const char *triple = ""; |
| 1790 | if (arch.IsValid()) |
| 1791 | triple = arch.GetTriple().getTriple().c_str(); |
| 1792 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 1793 | TargetSP new_target_sp; |
Jonas Devlieghere | f9a07e9 | 2018-09-20 09:09:05 +0000 | [diff] [blame] | 1794 | error = debugger.GetTargetList().CreateTarget( |
Jason Molenda | df9f796 | 2018-10-23 23:45:56 +0000 | [diff] [blame] | 1795 | debugger, "", triple, eLoadDependentsNo, nullptr, new_target_sp); |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 1796 | target = new_target_sp.get(); |
| 1797 | } |
Aidan Dodds | 933d8db | 2016-02-22 17:29:56 +0000 | [diff] [blame] | 1798 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 1799 | if (!target || error.Fail()) |
| 1800 | return nullptr; |
| 1801 | |
| 1802 | debugger.GetTargetList().SetSelectedTarget(target); |
| 1803 | |
| 1804 | lldb::ProcessSP process_sp = |
| 1805 | target->CreateProcess(debugger.GetListener(), plugin_name, nullptr); |
| 1806 | if (!process_sp) |
| 1807 | return nullptr; |
| 1808 | |
Jonas Devlieghere | 32d35fb | 2020-07-13 13:44:01 -0700 | [diff] [blame^] | 1809 | error = process_sp->ConnectRemote(connect_url); |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 1810 | if (error.Fail()) |
| 1811 | return nullptr; |
| 1812 | |
| 1813 | return process_sp; |
| 1814 | } |
| 1815 | |
| 1816 | size_t Platform::ConnectToWaitingProcesses(lldb_private::Debugger &debugger, |
Zachary Turner | 97206d5 | 2017-05-12 04:51:55 +0000 | [diff] [blame] | 1817 | lldb_private::Status &error) { |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 1818 | error.Clear(); |
| 1819 | return 0; |
| 1820 | } |
| 1821 | |
| 1822 | size_t Platform::GetSoftwareBreakpointTrapOpcode(Target &target, |
| 1823 | BreakpointSite *bp_site) { |
| 1824 | ArchSpec arch = target.GetArchitecture(); |
Jonas Devlieghere | 1fcd234a | 2020-04-24 09:03:51 -0700 | [diff] [blame] | 1825 | assert(arch.IsValid()); |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 1826 | const uint8_t *trap_opcode = nullptr; |
| 1827 | size_t trap_opcode_size = 0; |
| 1828 | |
| 1829 | switch (arch.GetMachine()) { |
Jason Molenda | 7dd7a36 | 2019-10-16 19:14:49 +0000 | [diff] [blame] | 1830 | case llvm::Triple::aarch64_32: |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 1831 | case llvm::Triple::aarch64: { |
| 1832 | static const uint8_t g_aarch64_opcode[] = {0x00, 0x00, 0x20, 0xd4}; |
| 1833 | trap_opcode = g_aarch64_opcode; |
| 1834 | trap_opcode_size = sizeof(g_aarch64_opcode); |
| 1835 | } break; |
| 1836 | |
Tatyana Krasnukha | faf6b25 | 2019-10-17 15:16:21 +0000 | [diff] [blame] | 1837 | case llvm::Triple::arc: { |
| 1838 | static const uint8_t g_hex_opcode[] = { 0xff, 0x7f }; |
| 1839 | trap_opcode = g_hex_opcode; |
| 1840 | trap_opcode_size = sizeof(g_hex_opcode); |
| 1841 | } break; |
| 1842 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 1843 | // TODO: support big-endian arm and thumb trap codes. |
| 1844 | case llvm::Triple::arm: { |
Adrian Prantl | 0509724 | 2018-04-30 16:49:04 +0000 | [diff] [blame] | 1845 | // The ARM reference recommends the use of 0xe7fddefe and 0xdefe but the |
| 1846 | // linux kernel does otherwise. |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 1847 | static const uint8_t g_arm_breakpoint_opcode[] = {0xf0, 0x01, 0xf0, 0xe7}; |
| 1848 | static const uint8_t g_thumb_breakpoint_opcode[] = {0x01, 0xde}; |
| 1849 | |
| 1850 | lldb::BreakpointLocationSP bp_loc_sp(bp_site->GetOwnerAtIndex(0)); |
Tatyana Krasnukha | 04803b3 | 2018-06-26 13:06:54 +0000 | [diff] [blame] | 1851 | AddressClass addr_class = AddressClass::eUnknown; |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 1852 | |
| 1853 | if (bp_loc_sp) { |
| 1854 | addr_class = bp_loc_sp->GetAddress().GetAddressClass(); |
Tatyana Krasnukha | 04803b3 | 2018-06-26 13:06:54 +0000 | [diff] [blame] | 1855 | if (addr_class == AddressClass::eUnknown && |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 1856 | (bp_loc_sp->GetAddress().GetFileAddress() & 1)) |
Tatyana Krasnukha | 04803b3 | 2018-06-26 13:06:54 +0000 | [diff] [blame] | 1857 | addr_class = AddressClass::eCodeAlternateISA; |
Aidan Dodds | 933d8db | 2016-02-22 17:29:56 +0000 | [diff] [blame] | 1858 | } |
| 1859 | |
Tatyana Krasnukha | 04803b3 | 2018-06-26 13:06:54 +0000 | [diff] [blame] | 1860 | if (addr_class == AddressClass::eCodeAlternateISA) { |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 1861 | trap_opcode = g_thumb_breakpoint_opcode; |
| 1862 | trap_opcode_size = sizeof(g_thumb_breakpoint_opcode); |
| 1863 | } else { |
| 1864 | trap_opcode = g_arm_breakpoint_opcode; |
| 1865 | trap_opcode_size = sizeof(g_arm_breakpoint_opcode); |
| 1866 | } |
| 1867 | } break; |
Aidan Dodds | 933d8db | 2016-02-22 17:29:56 +0000 | [diff] [blame] | 1868 | |
Ayke van Laethem | 0818e6c | 2020-02-07 22:39:56 +0100 | [diff] [blame] | 1869 | case llvm::Triple::avr: { |
| 1870 | static const uint8_t g_hex_opcode[] = {0x98, 0x95}; |
| 1871 | trap_opcode = g_hex_opcode; |
| 1872 | trap_opcode_size = sizeof(g_hex_opcode); |
| 1873 | } break; |
| 1874 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 1875 | case llvm::Triple::mips: |
| 1876 | case llvm::Triple::mips64: { |
| 1877 | static const uint8_t g_hex_opcode[] = {0x00, 0x00, 0x00, 0x0d}; |
| 1878 | trap_opcode = g_hex_opcode; |
| 1879 | trap_opcode_size = sizeof(g_hex_opcode); |
| 1880 | } break; |
| 1881 | |
| 1882 | case llvm::Triple::mipsel: |
| 1883 | case llvm::Triple::mips64el: { |
| 1884 | static const uint8_t g_hex_opcode[] = {0x0d, 0x00, 0x00, 0x00}; |
| 1885 | trap_opcode = g_hex_opcode; |
| 1886 | trap_opcode_size = sizeof(g_hex_opcode); |
| 1887 | } break; |
| 1888 | |
| 1889 | case llvm::Triple::systemz: { |
| 1890 | static const uint8_t g_hex_opcode[] = {0x00, 0x01}; |
| 1891 | trap_opcode = g_hex_opcode; |
| 1892 | trap_opcode_size = sizeof(g_hex_opcode); |
| 1893 | } break; |
| 1894 | |
| 1895 | case llvm::Triple::hexagon: { |
| 1896 | static const uint8_t g_hex_opcode[] = {0x0c, 0xdb, 0x00, 0x54}; |
| 1897 | trap_opcode = g_hex_opcode; |
| 1898 | trap_opcode_size = sizeof(g_hex_opcode); |
| 1899 | } break; |
| 1900 | |
| 1901 | case llvm::Triple::ppc: |
| 1902 | case llvm::Triple::ppc64: { |
| 1903 | static const uint8_t g_ppc_opcode[] = {0x7f, 0xe0, 0x00, 0x08}; |
| 1904 | trap_opcode = g_ppc_opcode; |
| 1905 | trap_opcode_size = sizeof(g_ppc_opcode); |
| 1906 | } break; |
| 1907 | |
Eugene Zemtsov | aae0a75 | 2017-10-05 19:44:05 +0000 | [diff] [blame] | 1908 | case llvm::Triple::ppc64le: { |
| 1909 | static const uint8_t g_ppc64le_opcode[] = {0x08, 0x00, 0xe0, 0x7f}; // trap |
| 1910 | trap_opcode = g_ppc64le_opcode; |
| 1911 | trap_opcode_size = sizeof(g_ppc64le_opcode); |
| 1912 | } break; |
| 1913 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 1914 | case llvm::Triple::x86: |
| 1915 | case llvm::Triple::x86_64: { |
| 1916 | static const uint8_t g_i386_opcode[] = {0xCC}; |
| 1917 | trap_opcode = g_i386_opcode; |
| 1918 | trap_opcode_size = sizeof(g_i386_opcode); |
| 1919 | } break; |
| 1920 | |
| 1921 | default: |
Jonas Devlieghere | 1fcd234a | 2020-04-24 09:03:51 -0700 | [diff] [blame] | 1922 | return 0; |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 1923 | } |
| 1924 | |
| 1925 | assert(bp_site); |
| 1926 | if (bp_site->SetTrapOpcode(trap_opcode, trap_opcode_size)) |
| 1927 | return trap_opcode_size; |
| 1928 | |
| 1929 | return 0; |
Aidan Dodds | 933d8db | 2016-02-22 17:29:56 +0000 | [diff] [blame] | 1930 | } |