Greg Clayton | e996fd3 | 2011-03-08 22:40:15 +0000 | [diff] [blame] | 1 | //===-- Platform.cpp --------------------------------------------*- C++ -*-===// |
| 2 | // |
| 3 | // The LLVM Compiler Infrastructure |
| 4 | // |
| 5 | // This file is distributed under the University of Illinois Open Source |
| 6 | // License. See LICENSE.TXT for details. |
| 7 | // |
| 8 | //===----------------------------------------------------------------------===// |
| 9 | |
| 10 | #include "lldb/Target/Platform.h" |
| 11 | |
| 12 | // C Includes |
| 13 | // C++ Includes |
| 14 | // Other libraries and framework includes |
| 15 | // Project includes |
Greg Clayton | 4116e93 | 2012-05-15 02:33:01 +0000 | [diff] [blame] | 16 | #include "lldb/Breakpoint/BreakpointIDList.h" |
Greg Clayton | e996fd3 | 2011-03-08 22:40:15 +0000 | [diff] [blame] | 17 | #include "lldb/Core/Error.h" |
Greg Clayton | 8b82f08 | 2011-04-12 05:54:46 +0000 | [diff] [blame] | 18 | #include "lldb/Core/Log.h" |
Greg Clayton | 1f74607 | 2012-08-29 21:13:06 +0000 | [diff] [blame] | 19 | #include "lldb/Core/ModuleSpec.h" |
Greg Clayton | e996fd3 | 2011-03-08 22:40:15 +0000 | [diff] [blame] | 20 | #include "lldb/Core/PluginManager.h" |
| 21 | #include "lldb/Host/FileSpec.h" |
Greg Clayton | ded470d | 2011-03-19 01:12:21 +0000 | [diff] [blame] | 22 | #include "lldb/Host/Host.h" |
Greg Clayton | 8b82f08 | 2011-04-12 05:54:46 +0000 | [diff] [blame] | 23 | #include "lldb/Target/Process.h" |
Greg Clayton | e996fd3 | 2011-03-08 22:40:15 +0000 | [diff] [blame] | 24 | #include "lldb/Target/Target.h" |
Daniel Malea | e0f8f57 | 2013-08-26 23:57:52 +0000 | [diff] [blame] | 25 | #include "lldb/Utility/Utils.h" |
Greg Clayton | e996fd3 | 2011-03-08 22:40:15 +0000 | [diff] [blame] | 26 | |
| 27 | using namespace lldb; |
| 28 | using namespace lldb_private; |
| 29 | |
| 30 | // Use a singleton function for g_local_platform_sp to avoid init |
| 31 | // constructors since LLDB is often part of a shared library |
| 32 | static PlatformSP& |
| 33 | GetDefaultPlatformSP () |
| 34 | { |
| 35 | static PlatformSP g_default_platform_sp; |
| 36 | return g_default_platform_sp; |
| 37 | } |
| 38 | |
Greg Clayton | e996fd3 | 2011-03-08 22:40:15 +0000 | [diff] [blame] | 39 | static Mutex & |
| 40 | GetConnectedPlatformListMutex () |
| 41 | { |
| 42 | static Mutex g_remote_connected_platforms_mutex (Mutex::eMutexTypeRecursive); |
| 43 | return g_remote_connected_platforms_mutex; |
| 44 | } |
| 45 | static std::vector<PlatformSP> & |
| 46 | GetConnectedPlatformList () |
| 47 | { |
| 48 | static std::vector<PlatformSP> g_remote_connected_platforms; |
| 49 | return g_remote_connected_platforms; |
| 50 | } |
| 51 | |
Greg Clayton | ab65b34 | 2011-04-13 22:47:15 +0000 | [diff] [blame] | 52 | |
| 53 | const char * |
| 54 | Platform::GetHostPlatformName () |
| 55 | { |
| 56 | return "host"; |
| 57 | } |
| 58 | |
Greg Clayton | e996fd3 | 2011-03-08 22:40:15 +0000 | [diff] [blame] | 59 | //------------------------------------------------------------------ |
| 60 | /// Get the native host platform plug-in. |
| 61 | /// |
| 62 | /// There should only be one of these for each host that LLDB runs |
| 63 | /// upon that should be statically compiled in and registered using |
| 64 | /// preprocessor macros or other similar build mechanisms. |
| 65 | /// |
| 66 | /// This platform will be used as the default platform when launching |
| 67 | /// or attaching to processes unless another platform is specified. |
| 68 | //------------------------------------------------------------------ |
| 69 | PlatformSP |
| 70 | Platform::GetDefaultPlatform () |
| 71 | { |
| 72 | return GetDefaultPlatformSP (); |
| 73 | } |
| 74 | |
| 75 | void |
| 76 | Platform::SetDefaultPlatform (const lldb::PlatformSP &platform_sp) |
| 77 | { |
| 78 | // The native platform should use its static void Platform::Initialize() |
| 79 | // function to register itself as the native platform. |
| 80 | GetDefaultPlatformSP () = platform_sp; |
| 81 | } |
| 82 | |
Greg Clayton | e996fd3 | 2011-03-08 22:40:15 +0000 | [diff] [blame] | 83 | Error |
Greg Clayton | d314e81 | 2011-03-23 00:09:55 +0000 | [diff] [blame] | 84 | Platform::GetFile (const FileSpec &platform_file, |
| 85 | const UUID *uuid_ptr, |
| 86 | FileSpec &local_file) |
Greg Clayton | e996fd3 | 2011-03-08 22:40:15 +0000 | [diff] [blame] | 87 | { |
| 88 | // Default to the local case |
| 89 | local_file = platform_file; |
| 90 | return Error(); |
| 91 | } |
| 92 | |
Greg Clayton | 91c0e74 | 2013-01-11 23:44:27 +0000 | [diff] [blame] | 93 | FileSpecList |
| 94 | Platform::LocateExecutableScriptingResources (Target *target, Module &module) |
Enrico Granata | 1759848 | 2012-11-08 02:22:02 +0000 | [diff] [blame] | 95 | { |
Greg Clayton | 91c0e74 | 2013-01-11 23:44:27 +0000 | [diff] [blame] | 96 | return FileSpecList(); |
Enrico Granata | 1759848 | 2012-11-08 02:22:02 +0000 | [diff] [blame] | 97 | } |
| 98 | |
Jason Molenda | 1c62754 | 2013-04-05 01:03:25 +0000 | [diff] [blame] | 99 | Platform* |
Greg Clayton | 57abc5d | 2013-05-10 21:47:16 +0000 | [diff] [blame] | 100 | Platform::FindPlugin (Process *process, const ConstString &plugin_name) |
Jason Molenda | 1c62754 | 2013-04-05 01:03:25 +0000 | [diff] [blame] | 101 | { |
| 102 | PlatformCreateInstance create_callback = NULL; |
| 103 | if (plugin_name) |
| 104 | { |
| 105 | create_callback = PluginManager::GetPlatformCreateCallbackForPluginName (plugin_name); |
| 106 | if (create_callback) |
| 107 | { |
| 108 | ArchSpec arch; |
| 109 | if (process) |
| 110 | { |
| 111 | arch = process->GetTarget().GetArchitecture(); |
| 112 | } |
Greg Clayton | 7b0992d | 2013-04-18 22:45:39 +0000 | [diff] [blame] | 113 | std::unique_ptr<Platform> instance_ap(create_callback(process, &arch)); |
Jason Molenda | 1c62754 | 2013-04-05 01:03:25 +0000 | [diff] [blame] | 114 | if (instance_ap.get()) |
| 115 | return instance_ap.release(); |
| 116 | } |
| 117 | } |
| 118 | else |
| 119 | { |
| 120 | for (uint32_t idx = 0; (create_callback = PluginManager::GetPlatformCreateCallbackAtIndex(idx)) != NULL; ++idx) |
| 121 | { |
Matt Kopec | ef14371 | 2013-06-03 18:00:07 +0000 | [diff] [blame] | 122 | std::unique_ptr<Platform> instance_ap(create_callback(process, nullptr)); |
Jason Molenda | 1c62754 | 2013-04-05 01:03:25 +0000 | [diff] [blame] | 123 | if (instance_ap.get()) |
| 124 | return instance_ap.release(); |
| 125 | } |
| 126 | } |
| 127 | return NULL; |
| 128 | } |
| 129 | |
Greg Clayton | 32e0a75 | 2011-03-30 18:16:51 +0000 | [diff] [blame] | 130 | Error |
Greg Clayton | b9a01b3 | 2012-02-26 05:51:37 +0000 | [diff] [blame] | 131 | Platform::GetSharedModule (const ModuleSpec &module_spec, |
Greg Clayton | 32e0a75 | 2011-03-30 18:16:51 +0000 | [diff] [blame] | 132 | ModuleSP &module_sp, |
Greg Clayton | c859e2d | 2012-02-13 23:10:39 +0000 | [diff] [blame] | 133 | const FileSpecList *module_search_paths_ptr, |
Greg Clayton | 32e0a75 | 2011-03-30 18:16:51 +0000 | [diff] [blame] | 134 | ModuleSP *old_module_sp_ptr, |
| 135 | bool *did_create_ptr) |
| 136 | { |
| 137 | // Don't do any path remapping for the default implementation |
| 138 | // of the platform GetSharedModule function, just call through |
| 139 | // to our static ModuleList function. Platform subclasses that |
| 140 | // implement remote debugging, might have a developer kits |
| 141 | // installed that have cached versions of the files for the |
| 142 | // remote target, or might implement a download and cache |
| 143 | // locally implementation. |
| 144 | const bool always_create = false; |
Greg Clayton | b9a01b3 | 2012-02-26 05:51:37 +0000 | [diff] [blame] | 145 | return ModuleList::GetSharedModule (module_spec, |
Greg Clayton | 32e0a75 | 2011-03-30 18:16:51 +0000 | [diff] [blame] | 146 | module_sp, |
Greg Clayton | c859e2d | 2012-02-13 23:10:39 +0000 | [diff] [blame] | 147 | module_search_paths_ptr, |
Greg Clayton | 32e0a75 | 2011-03-30 18:16:51 +0000 | [diff] [blame] | 148 | old_module_sp_ptr, |
| 149 | did_create_ptr, |
| 150 | always_create); |
| 151 | } |
| 152 | |
Greg Clayton | e996fd3 | 2011-03-08 22:40:15 +0000 | [diff] [blame] | 153 | PlatformSP |
Greg Clayton | ded470d | 2011-03-19 01:12:21 +0000 | [diff] [blame] | 154 | Platform::Create (const char *platform_name, Error &error) |
Greg Clayton | e996fd3 | 2011-03-08 22:40:15 +0000 | [diff] [blame] | 155 | { |
| 156 | PlatformCreateInstance create_callback = NULL; |
| 157 | lldb::PlatformSP platform_sp; |
Greg Clayton | ded470d | 2011-03-19 01:12:21 +0000 | [diff] [blame] | 158 | if (platform_name && platform_name[0]) |
Greg Clayton | e996fd3 | 2011-03-08 22:40:15 +0000 | [diff] [blame] | 159 | { |
Greg Clayton | 57abc5d | 2013-05-10 21:47:16 +0000 | [diff] [blame] | 160 | ConstString const_platform_name (platform_name); |
| 161 | create_callback = PluginManager::GetPlatformCreateCallbackForPluginName (const_platform_name); |
Greg Clayton | e996fd3 | 2011-03-08 22:40:15 +0000 | [diff] [blame] | 162 | if (create_callback) |
Greg Clayton | b3a40ba | 2012-03-20 18:34:04 +0000 | [diff] [blame] | 163 | platform_sp.reset(create_callback(true, NULL)); |
Greg Clayton | e996fd3 | 2011-03-08 22:40:15 +0000 | [diff] [blame] | 164 | else |
Greg Clayton | ded470d | 2011-03-19 01:12:21 +0000 | [diff] [blame] | 165 | error.SetErrorStringWithFormat ("unable to find a plug-in for the platform named \"%s\"", platform_name); |
Greg Clayton | e996fd3 | 2011-03-08 22:40:15 +0000 | [diff] [blame] | 166 | } |
| 167 | else |
Greg Clayton | ded470d | 2011-03-19 01:12:21 +0000 | [diff] [blame] | 168 | error.SetErrorString ("invalid platform name"); |
Greg Clayton | e996fd3 | 2011-03-08 22:40:15 +0000 | [diff] [blame] | 169 | return platform_sp; |
| 170 | } |
| 171 | |
Greg Clayton | b3a40ba | 2012-03-20 18:34:04 +0000 | [diff] [blame] | 172 | |
| 173 | PlatformSP |
Greg Clayton | 7051231 | 2012-05-08 01:45:38 +0000 | [diff] [blame] | 174 | Platform::Create (const ArchSpec &arch, ArchSpec *platform_arch_ptr, Error &error) |
Greg Clayton | b3a40ba | 2012-03-20 18:34:04 +0000 | [diff] [blame] | 175 | { |
| 176 | lldb::PlatformSP platform_sp; |
| 177 | if (arch.IsValid()) |
| 178 | { |
Greg Clayton | 7051231 | 2012-05-08 01:45:38 +0000 | [diff] [blame] | 179 | uint32_t idx; |
Greg Clayton | b3a40ba | 2012-03-20 18:34:04 +0000 | [diff] [blame] | 180 | PlatformCreateInstance create_callback; |
Greg Clayton | 1e0c884 | 2013-01-11 20:49:54 +0000 | [diff] [blame] | 181 | // First try exact arch matches across all platform plug-ins |
| 182 | bool exact = true; |
Greg Clayton | 7051231 | 2012-05-08 01:45:38 +0000 | [diff] [blame] | 183 | for (idx = 0; (create_callback = PluginManager::GetPlatformCreateCallbackAtIndex (idx)); ++idx) |
Greg Clayton | b3a40ba | 2012-03-20 18:34:04 +0000 | [diff] [blame] | 184 | { |
| 185 | if (create_callback) |
Greg Clayton | 1e0c884 | 2013-01-11 20:49:54 +0000 | [diff] [blame] | 186 | { |
Greg Clayton | b3a40ba | 2012-03-20 18:34:04 +0000 | [diff] [blame] | 187 | platform_sp.reset(create_callback(false, &arch)); |
Greg Clayton | 1e0c884 | 2013-01-11 20:49:54 +0000 | [diff] [blame] | 188 | if (platform_sp && platform_sp->IsCompatibleArchitecture(arch, exact, platform_arch_ptr)) |
| 189 | return platform_sp; |
| 190 | } |
| 191 | } |
| 192 | // Next try compatible arch matches across all platform plug-ins |
| 193 | exact = false; |
| 194 | for (idx = 0; (create_callback = PluginManager::GetPlatformCreateCallbackAtIndex (idx)); ++idx) |
| 195 | { |
| 196 | if (create_callback) |
| 197 | { |
| 198 | platform_sp.reset(create_callback(false, &arch)); |
| 199 | if (platform_sp && platform_sp->IsCompatibleArchitecture(arch, exact, platform_arch_ptr)) |
| 200 | return platform_sp; |
| 201 | } |
Greg Clayton | b3a40ba | 2012-03-20 18:34:04 +0000 | [diff] [blame] | 202 | } |
| 203 | } |
| 204 | else |
| 205 | error.SetErrorString ("invalid platform name"); |
Greg Clayton | 7051231 | 2012-05-08 01:45:38 +0000 | [diff] [blame] | 206 | if (platform_arch_ptr) |
| 207 | platform_arch_ptr->Clear(); |
| 208 | platform_sp.reset(); |
Greg Clayton | b3a40ba | 2012-03-20 18:34:04 +0000 | [diff] [blame] | 209 | return platform_sp; |
| 210 | } |
| 211 | |
Greg Clayton | e996fd3 | 2011-03-08 22:40:15 +0000 | [diff] [blame] | 212 | uint32_t |
| 213 | Platform::GetNumConnectedRemotePlatforms () |
| 214 | { |
| 215 | Mutex::Locker locker (GetConnectedPlatformListMutex ()); |
| 216 | return GetConnectedPlatformList().size(); |
| 217 | } |
| 218 | |
| 219 | PlatformSP |
| 220 | Platform::GetConnectedRemotePlatformAtIndex (uint32_t idx) |
| 221 | { |
| 222 | PlatformSP platform_sp; |
| 223 | { |
| 224 | Mutex::Locker locker (GetConnectedPlatformListMutex ()); |
| 225 | if (idx < GetConnectedPlatformList().size()) |
| 226 | platform_sp = GetConnectedPlatformList ()[idx]; |
| 227 | } |
| 228 | return platform_sp; |
| 229 | } |
| 230 | |
| 231 | //------------------------------------------------------------------ |
| 232 | /// Default Constructor |
| 233 | //------------------------------------------------------------------ |
Greg Clayton | ded470d | 2011-03-19 01:12:21 +0000 | [diff] [blame] | 234 | Platform::Platform (bool is_host) : |
| 235 | m_is_host (is_host), |
Greg Clayton | ded470d | 2011-03-19 01:12:21 +0000 | [diff] [blame] | 236 | m_os_version_set_while_connected (false), |
| 237 | m_system_arch_set_while_connected (false), |
Greg Clayton | f3dd93c | 2011-06-17 03:31:01 +0000 | [diff] [blame] | 238 | m_sdk_sysroot (), |
| 239 | m_sdk_build (), |
Greg Clayton | ded470d | 2011-03-19 01:12:21 +0000 | [diff] [blame] | 240 | m_remote_url (), |
Greg Clayton | 1cb6496 | 2011-03-24 04:28:38 +0000 | [diff] [blame] | 241 | m_name (), |
Greg Clayton | ded470d | 2011-03-19 01:12:21 +0000 | [diff] [blame] | 242 | m_major_os_version (UINT32_MAX), |
| 243 | m_minor_os_version (UINT32_MAX), |
Greg Clayton | 32e0a75 | 2011-03-30 18:16:51 +0000 | [diff] [blame] | 244 | m_update_os_version (UINT32_MAX), |
| 245 | m_system_arch(), |
| 246 | m_uid_map_mutex (Mutex::eMutexTypeNormal), |
| 247 | m_gid_map_mutex (Mutex::eMutexTypeNormal), |
| 248 | m_uid_map(), |
| 249 | m_gid_map(), |
| 250 | m_max_uid_name_len (0), |
Daniel Malea | e0f8f57 | 2013-08-26 23:57:52 +0000 | [diff] [blame] | 251 | m_max_gid_name_len (0), |
| 252 | m_supports_rsync (false), |
| 253 | m_rsync_opts (), |
| 254 | m_rsync_prefix (), |
| 255 | m_supports_ssh (false), |
| 256 | m_ssh_opts (), |
| 257 | m_ignores_remote_hostname (false) |
Greg Clayton | e996fd3 | 2011-03-08 22:40:15 +0000 | [diff] [blame] | 258 | { |
Greg Clayton | 5160ce5 | 2013-03-27 23:08:40 +0000 | [diff] [blame] | 259 | Log *log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_OBJECT)); |
Greg Clayton | 8b82f08 | 2011-04-12 05:54:46 +0000 | [diff] [blame] | 260 | if (log) |
| 261 | log->Printf ("%p Platform::Platform()", this); |
Greg Clayton | e996fd3 | 2011-03-08 22:40:15 +0000 | [diff] [blame] | 262 | } |
| 263 | |
| 264 | //------------------------------------------------------------------ |
| 265 | /// Destructor. |
| 266 | /// |
| 267 | /// The destructor is virtual since this class is designed to be |
| 268 | /// inherited from by the plug-in instance. |
| 269 | //------------------------------------------------------------------ |
| 270 | Platform::~Platform() |
| 271 | { |
Greg Clayton | 5160ce5 | 2013-03-27 23:08:40 +0000 | [diff] [blame] | 272 | Log *log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_OBJECT)); |
Greg Clayton | 8b82f08 | 2011-04-12 05:54:46 +0000 | [diff] [blame] | 273 | if (log) |
| 274 | log->Printf ("%p Platform::~Platform()", this); |
Greg Clayton | e996fd3 | 2011-03-08 22:40:15 +0000 | [diff] [blame] | 275 | } |
| 276 | |
Greg Clayton | 1cb6496 | 2011-03-24 04:28:38 +0000 | [diff] [blame] | 277 | void |
| 278 | Platform::GetStatus (Stream &strm) |
| 279 | { |
| 280 | uint32_t major = UINT32_MAX; |
| 281 | uint32_t minor = UINT32_MAX; |
| 282 | uint32_t update = UINT32_MAX; |
| 283 | std::string s; |
Greg Clayton | 57abc5d | 2013-05-10 21:47:16 +0000 | [diff] [blame] | 284 | strm.Printf (" Platform: %s\n", GetPluginName().GetCString()); |
Greg Clayton | 1cb6496 | 2011-03-24 04:28:38 +0000 | [diff] [blame] | 285 | |
| 286 | ArchSpec arch (GetSystemArchitecture()); |
| 287 | if (arch.IsValid()) |
| 288 | { |
| 289 | if (!arch.GetTriple().str().empty()) |
Greg Clayton | 32e0a75 | 2011-03-30 18:16:51 +0000 | [diff] [blame] | 290 | strm.Printf(" Triple: %s\n", arch.GetTriple().str().c_str()); |
Greg Clayton | 1cb6496 | 2011-03-24 04:28:38 +0000 | [diff] [blame] | 291 | } |
| 292 | |
| 293 | if (GetOSVersion(major, minor, update)) |
| 294 | { |
Greg Clayton | 32e0a75 | 2011-03-30 18:16:51 +0000 | [diff] [blame] | 295 | strm.Printf("OS Version: %u", major); |
Greg Clayton | 1cb6496 | 2011-03-24 04:28:38 +0000 | [diff] [blame] | 296 | if (minor != UINT32_MAX) |
| 297 | strm.Printf(".%u", minor); |
| 298 | if (update != UINT32_MAX) |
| 299 | strm.Printf(".%u", update); |
| 300 | |
| 301 | if (GetOSBuildString (s)) |
| 302 | strm.Printf(" (%s)", s.c_str()); |
| 303 | |
| 304 | strm.EOL(); |
| 305 | } |
| 306 | |
| 307 | if (GetOSKernelDescription (s)) |
Greg Clayton | 32e0a75 | 2011-03-30 18:16:51 +0000 | [diff] [blame] | 308 | strm.Printf(" Kernel: %s\n", s.c_str()); |
Greg Clayton | 1cb6496 | 2011-03-24 04:28:38 +0000 | [diff] [blame] | 309 | |
| 310 | if (IsHost()) |
| 311 | { |
Greg Clayton | 32e0a75 | 2011-03-30 18:16:51 +0000 | [diff] [blame] | 312 | strm.Printf(" Hostname: %s\n", GetHostname()); |
Greg Clayton | 1cb6496 | 2011-03-24 04:28:38 +0000 | [diff] [blame] | 313 | } |
| 314 | else |
| 315 | { |
Greg Clayton | 32e0a75 | 2011-03-30 18:16:51 +0000 | [diff] [blame] | 316 | const bool is_connected = IsConnected(); |
| 317 | if (is_connected) |
| 318 | strm.Printf(" Hostname: %s\n", GetHostname()); |
| 319 | strm.Printf(" Connected: %s\n", is_connected ? "yes" : "no"); |
Greg Clayton | 1cb6496 | 2011-03-24 04:28:38 +0000 | [diff] [blame] | 320 | } |
Daniel Malea | e0f8f57 | 2013-08-26 23:57:52 +0000 | [diff] [blame] | 321 | |
| 322 | if (!IsConnected()) |
| 323 | return; |
| 324 | |
| 325 | std::string specific_info(GetPlatformSpecificConnectionInformation()); |
| 326 | |
| 327 | if (specific_info.empty() == false) |
| 328 | strm.Printf("Platform-specific connection: %s\n", specific_info.c_str()); |
Greg Clayton | 1cb6496 | 2011-03-24 04:28:38 +0000 | [diff] [blame] | 329 | } |
| 330 | |
Greg Clayton | ded470d | 2011-03-19 01:12:21 +0000 | [diff] [blame] | 331 | |
| 332 | bool |
| 333 | Platform::GetOSVersion (uint32_t &major, |
| 334 | uint32_t &minor, |
| 335 | uint32_t &update) |
| 336 | { |
| 337 | bool success = m_major_os_version != UINT32_MAX; |
| 338 | if (IsHost()) |
| 339 | { |
| 340 | if (!success) |
| 341 | { |
| 342 | // We have a local host platform |
| 343 | success = Host::GetOSVersion (m_major_os_version, |
| 344 | m_minor_os_version, |
| 345 | m_update_os_version); |
| 346 | m_os_version_set_while_connected = success; |
| 347 | } |
| 348 | } |
| 349 | else |
| 350 | { |
| 351 | // We have a remote platform. We can only fetch the remote |
| 352 | // OS version if we are connected, and we don't want to do it |
| 353 | // more than once. |
| 354 | |
| 355 | const bool is_connected = IsConnected(); |
| 356 | |
Greg Clayton | 1cb6496 | 2011-03-24 04:28:38 +0000 | [diff] [blame] | 357 | bool fetch = false; |
Greg Clayton | ded470d | 2011-03-19 01:12:21 +0000 | [diff] [blame] | 358 | if (success) |
| 359 | { |
| 360 | // We have valid OS version info, check to make sure it wasn't |
| 361 | // manually set prior to connecting. If it was manually set prior |
| 362 | // to connecting, then lets fetch the actual OS version info |
| 363 | // if we are now connected. |
| 364 | if (is_connected && !m_os_version_set_while_connected) |
Greg Clayton | 1cb6496 | 2011-03-24 04:28:38 +0000 | [diff] [blame] | 365 | fetch = true; |
Greg Clayton | ded470d | 2011-03-19 01:12:21 +0000 | [diff] [blame] | 366 | } |
| 367 | else |
| 368 | { |
| 369 | // We don't have valid OS version info, fetch it if we are connected |
Greg Clayton | 1cb6496 | 2011-03-24 04:28:38 +0000 | [diff] [blame] | 370 | fetch = is_connected; |
Greg Clayton | ded470d | 2011-03-19 01:12:21 +0000 | [diff] [blame] | 371 | } |
| 372 | |
Greg Clayton | 1cb6496 | 2011-03-24 04:28:38 +0000 | [diff] [blame] | 373 | if (fetch) |
Greg Clayton | ded470d | 2011-03-19 01:12:21 +0000 | [diff] [blame] | 374 | { |
Greg Clayton | 1cb6496 | 2011-03-24 04:28:38 +0000 | [diff] [blame] | 375 | success = GetRemoteOSVersion (); |
Greg Clayton | ded470d | 2011-03-19 01:12:21 +0000 | [diff] [blame] | 376 | m_os_version_set_while_connected = success; |
| 377 | } |
| 378 | } |
| 379 | |
| 380 | if (success) |
| 381 | { |
| 382 | major = m_major_os_version; |
| 383 | minor = m_minor_os_version; |
| 384 | update = m_update_os_version; |
| 385 | } |
| 386 | return success; |
| 387 | } |
Greg Clayton | 1cb6496 | 2011-03-24 04:28:38 +0000 | [diff] [blame] | 388 | |
| 389 | bool |
| 390 | Platform::GetOSBuildString (std::string &s) |
| 391 | { |
| 392 | if (IsHost()) |
| 393 | return Host::GetOSBuildString (s); |
| 394 | else |
| 395 | return GetRemoteOSBuildString (s); |
| 396 | } |
| 397 | |
| 398 | bool |
| 399 | Platform::GetOSKernelDescription (std::string &s) |
| 400 | { |
| 401 | if (IsHost()) |
| 402 | return Host::GetOSKernelDescription (s); |
| 403 | else |
| 404 | return GetRemoteOSKernelDescription (s); |
| 405 | } |
| 406 | |
Greg Clayton | 57abc5d | 2013-05-10 21:47:16 +0000 | [diff] [blame] | 407 | ConstString |
Greg Clayton | 8b82f08 | 2011-04-12 05:54:46 +0000 | [diff] [blame] | 408 | Platform::GetName () |
| 409 | { |
| 410 | const char *name = GetHostname(); |
| 411 | if (name == NULL || name[0] == '\0') |
Greg Clayton | 57abc5d | 2013-05-10 21:47:16 +0000 | [diff] [blame] | 412 | return GetPluginName(); |
| 413 | return ConstString (name); |
Greg Clayton | 8b82f08 | 2011-04-12 05:54:46 +0000 | [diff] [blame] | 414 | } |
| 415 | |
| 416 | const char * |
Greg Clayton | 1cb6496 | 2011-03-24 04:28:38 +0000 | [diff] [blame] | 417 | Platform::GetHostname () |
| 418 | { |
Greg Clayton | ab65b34 | 2011-04-13 22:47:15 +0000 | [diff] [blame] | 419 | if (IsHost()) |
| 420 | return "localhost"; |
Greg Clayton | 32e0a75 | 2011-03-30 18:16:51 +0000 | [diff] [blame] | 421 | |
| 422 | if (m_name.empty()) |
| 423 | return NULL; |
| 424 | return m_name.c_str(); |
| 425 | } |
| 426 | |
| 427 | const char * |
| 428 | Platform::GetUserName (uint32_t uid) |
| 429 | { |
| 430 | const char *user_name = GetCachedUserName(uid); |
| 431 | if (user_name) |
| 432 | return user_name; |
| 433 | if (IsHost()) |
| 434 | { |
| 435 | std::string name; |
| 436 | if (Host::GetUserName(uid, name)) |
| 437 | return SetCachedUserName (uid, name.c_str(), name.size()); |
| 438 | } |
Greg Clayton | 1cb6496 | 2011-03-24 04:28:38 +0000 | [diff] [blame] | 439 | return NULL; |
| 440 | } |
| 441 | |
Greg Clayton | 32e0a75 | 2011-03-30 18:16:51 +0000 | [diff] [blame] | 442 | const char * |
| 443 | Platform::GetGroupName (uint32_t gid) |
| 444 | { |
| 445 | const char *group_name = GetCachedGroupName(gid); |
| 446 | if (group_name) |
| 447 | return group_name; |
| 448 | if (IsHost()) |
| 449 | { |
| 450 | std::string name; |
| 451 | if (Host::GetGroupName(gid, name)) |
| 452 | return SetCachedGroupName (gid, name.c_str(), name.size()); |
| 453 | } |
| 454 | return NULL; |
| 455 | } |
Greg Clayton | 1cb6496 | 2011-03-24 04:28:38 +0000 | [diff] [blame] | 456 | |
Greg Clayton | ded470d | 2011-03-19 01:12:21 +0000 | [diff] [blame] | 457 | bool |
| 458 | Platform::SetOSVersion (uint32_t major, |
| 459 | uint32_t minor, |
| 460 | uint32_t update) |
| 461 | { |
| 462 | if (IsHost()) |
| 463 | { |
| 464 | // We don't need anyone setting the OS version for the host platform, |
| 465 | // we should be able to figure it out by calling Host::GetOSVersion(...). |
| 466 | return false; |
| 467 | } |
| 468 | else |
| 469 | { |
| 470 | // We have a remote platform, allow setting the target OS version if |
| 471 | // we aren't connected, since if we are connected, we should be able to |
| 472 | // request the remote OS version from the connected platform. |
| 473 | if (IsConnected()) |
| 474 | return false; |
| 475 | else |
| 476 | { |
| 477 | // We aren't connected and we might want to set the OS version |
| 478 | // ahead of time before we connect so we can peruse files and |
| 479 | // use a local SDK or PDK cache of support files to disassemble |
| 480 | // or do other things. |
| 481 | m_major_os_version = major; |
| 482 | m_minor_os_version = minor; |
| 483 | m_update_os_version = update; |
| 484 | return true; |
| 485 | } |
| 486 | } |
| 487 | return false; |
| 488 | } |
| 489 | |
| 490 | |
Greg Clayton | e996fd3 | 2011-03-08 22:40:15 +0000 | [diff] [blame] | 491 | Error |
| 492 | Platform::ResolveExecutable (const FileSpec &exe_file, |
| 493 | const ArchSpec &exe_arch, |
Greg Clayton | c859e2d | 2012-02-13 23:10:39 +0000 | [diff] [blame] | 494 | lldb::ModuleSP &exe_module_sp, |
| 495 | const FileSpecList *module_search_paths_ptr) |
Greg Clayton | e996fd3 | 2011-03-08 22:40:15 +0000 | [diff] [blame] | 496 | { |
| 497 | Error error; |
| 498 | if (exe_file.Exists()) |
| 499 | { |
Greg Clayton | b9a01b3 | 2012-02-26 05:51:37 +0000 | [diff] [blame] | 500 | ModuleSpec module_spec (exe_file, exe_arch); |
| 501 | if (module_spec.GetArchitecture().IsValid()) |
Greg Clayton | e996fd3 | 2011-03-08 22:40:15 +0000 | [diff] [blame] | 502 | { |
Greg Clayton | b9a01b3 | 2012-02-26 05:51:37 +0000 | [diff] [blame] | 503 | error = ModuleList::GetSharedModule (module_spec, |
Greg Clayton | e996fd3 | 2011-03-08 22:40:15 +0000 | [diff] [blame] | 504 | exe_module_sp, |
Greg Clayton | c859e2d | 2012-02-13 23:10:39 +0000 | [diff] [blame] | 505 | module_search_paths_ptr, |
Greg Clayton | e996fd3 | 2011-03-08 22:40:15 +0000 | [diff] [blame] | 506 | NULL, |
| 507 | NULL); |
| 508 | } |
| 509 | else |
| 510 | { |
| 511 | // No valid architecture was specified, ask the platform for |
| 512 | // the architectures that we should be using (in the correct order) |
| 513 | // and see if we can find a match that way |
Greg Clayton | b9a01b3 | 2012-02-26 05:51:37 +0000 | [diff] [blame] | 514 | for (uint32_t idx = 0; GetSupportedArchitectureAtIndex (idx, module_spec.GetArchitecture()); ++idx) |
Greg Clayton | e996fd3 | 2011-03-08 22:40:15 +0000 | [diff] [blame] | 515 | { |
Greg Clayton | b9a01b3 | 2012-02-26 05:51:37 +0000 | [diff] [blame] | 516 | error = ModuleList::GetSharedModule (module_spec, |
Greg Clayton | e996fd3 | 2011-03-08 22:40:15 +0000 | [diff] [blame] | 517 | exe_module_sp, |
Greg Clayton | c859e2d | 2012-02-13 23:10:39 +0000 | [diff] [blame] | 518 | module_search_paths_ptr, |
Greg Clayton | e996fd3 | 2011-03-08 22:40:15 +0000 | [diff] [blame] | 519 | NULL, |
| 520 | NULL); |
| 521 | // Did we find an executable using one of the |
| 522 | if (error.Success() && exe_module_sp) |
| 523 | break; |
| 524 | } |
| 525 | } |
| 526 | } |
| 527 | else |
| 528 | { |
Greg Clayton | b5ad4ec | 2013-04-29 17:25:54 +0000 | [diff] [blame] | 529 | error.SetErrorStringWithFormat ("'%s' does not exist", |
| 530 | exe_file.GetPath().c_str()); |
Greg Clayton | e996fd3 | 2011-03-08 22:40:15 +0000 | [diff] [blame] | 531 | } |
| 532 | return error; |
| 533 | } |
| 534 | |
Greg Clayton | 103f028 | 2012-09-12 02:03:59 +0000 | [diff] [blame] | 535 | Error |
| 536 | Platform::ResolveSymbolFile (Target &target, |
| 537 | const ModuleSpec &sym_spec, |
| 538 | FileSpec &sym_file) |
| 539 | { |
| 540 | Error error; |
| 541 | if (sym_spec.GetSymbolFileSpec().Exists()) |
| 542 | sym_file = sym_spec.GetSymbolFileSpec(); |
| 543 | else |
| 544 | error.SetErrorString("unable to resolve symbol file"); |
| 545 | return error; |
| 546 | |
| 547 | } |
| 548 | |
| 549 | |
| 550 | |
Greg Clayton | aa51684 | 2011-08-11 16:25:18 +0000 | [diff] [blame] | 551 | bool |
| 552 | Platform::ResolveRemotePath (const FileSpec &platform_path, |
| 553 | FileSpec &resolved_platform_path) |
| 554 | { |
| 555 | resolved_platform_path = platform_path; |
| 556 | return resolved_platform_path.ResolvePath(); |
| 557 | } |
| 558 | |
Greg Clayton | ded470d | 2011-03-19 01:12:21 +0000 | [diff] [blame] | 559 | |
| 560 | const ArchSpec & |
| 561 | Platform::GetSystemArchitecture() |
| 562 | { |
| 563 | if (IsHost()) |
| 564 | { |
| 565 | if (!m_system_arch.IsValid()) |
| 566 | { |
| 567 | // We have a local host platform |
| 568 | m_system_arch = Host::GetArchitecture(); |
| 569 | m_system_arch_set_while_connected = m_system_arch.IsValid(); |
| 570 | } |
| 571 | } |
| 572 | else |
| 573 | { |
| 574 | // We have a remote platform. We can only fetch the remote |
| 575 | // system architecture if we are connected, and we don't want to do it |
| 576 | // more than once. |
| 577 | |
| 578 | const bool is_connected = IsConnected(); |
| 579 | |
| 580 | bool fetch = false; |
| 581 | if (m_system_arch.IsValid()) |
| 582 | { |
| 583 | // We have valid OS version info, check to make sure it wasn't |
| 584 | // manually set prior to connecting. If it was manually set prior |
| 585 | // to connecting, then lets fetch the actual OS version info |
| 586 | // if we are now connected. |
| 587 | if (is_connected && !m_system_arch_set_while_connected) |
| 588 | fetch = true; |
| 589 | } |
| 590 | else |
| 591 | { |
| 592 | // We don't have valid OS version info, fetch it if we are connected |
| 593 | fetch = is_connected; |
| 594 | } |
| 595 | |
| 596 | if (fetch) |
| 597 | { |
Greg Clayton | 1cb6496 | 2011-03-24 04:28:38 +0000 | [diff] [blame] | 598 | m_system_arch = GetRemoteSystemArchitecture (); |
Greg Clayton | ded470d | 2011-03-19 01:12:21 +0000 | [diff] [blame] | 599 | m_system_arch_set_while_connected = m_system_arch.IsValid(); |
| 600 | } |
| 601 | } |
| 602 | return m_system_arch; |
| 603 | } |
| 604 | |
| 605 | |
Greg Clayton | e996fd3 | 2011-03-08 22:40:15 +0000 | [diff] [blame] | 606 | Error |
Greg Clayton | d314e81 | 2011-03-23 00:09:55 +0000 | [diff] [blame] | 607 | Platform::ConnectRemote (Args& args) |
Greg Clayton | e996fd3 | 2011-03-08 22:40:15 +0000 | [diff] [blame] | 608 | { |
| 609 | Error error; |
Greg Clayton | d314e81 | 2011-03-23 00:09:55 +0000 | [diff] [blame] | 610 | if (IsHost()) |
Greg Clayton | 57abc5d | 2013-05-10 21:47:16 +0000 | [diff] [blame] | 611 | error.SetErrorStringWithFormat ("The currently selected platform (%s) is the host platform and is always connected.", GetPluginName().GetCString()); |
Greg Clayton | d314e81 | 2011-03-23 00:09:55 +0000 | [diff] [blame] | 612 | else |
Greg Clayton | 57abc5d | 2013-05-10 21:47:16 +0000 | [diff] [blame] | 613 | error.SetErrorStringWithFormat ("Platform::ConnectRemote() is not supported by %s", GetPluginName().GetCString()); |
Greg Clayton | e996fd3 | 2011-03-08 22:40:15 +0000 | [diff] [blame] | 614 | return error; |
| 615 | } |
| 616 | |
| 617 | Error |
Greg Clayton | d314e81 | 2011-03-23 00:09:55 +0000 | [diff] [blame] | 618 | Platform::DisconnectRemote () |
Greg Clayton | e996fd3 | 2011-03-08 22:40:15 +0000 | [diff] [blame] | 619 | { |
| 620 | Error error; |
Greg Clayton | d314e81 | 2011-03-23 00:09:55 +0000 | [diff] [blame] | 621 | if (IsHost()) |
Greg Clayton | 57abc5d | 2013-05-10 21:47:16 +0000 | [diff] [blame] | 622 | error.SetErrorStringWithFormat ("The currently selected platform (%s) is the host platform and is always connected.", GetPluginName().GetCString()); |
Greg Clayton | d314e81 | 2011-03-23 00:09:55 +0000 | [diff] [blame] | 623 | else |
Greg Clayton | 57abc5d | 2013-05-10 21:47:16 +0000 | [diff] [blame] | 624 | error.SetErrorStringWithFormat ("Platform::DisconnectRemote() is not supported by %s", GetPluginName().GetCString()); |
Greg Clayton | e996fd3 | 2011-03-08 22:40:15 +0000 | [diff] [blame] | 625 | return error; |
| 626 | } |
Greg Clayton | 32e0a75 | 2011-03-30 18:16:51 +0000 | [diff] [blame] | 627 | |
| 628 | bool |
Greg Clayton | 8b82f08 | 2011-04-12 05:54:46 +0000 | [diff] [blame] | 629 | Platform::GetProcessInfo (lldb::pid_t pid, ProcessInstanceInfo &process_info) |
Greg Clayton | 32e0a75 | 2011-03-30 18:16:51 +0000 | [diff] [blame] | 630 | { |
| 631 | // Take care of the host case so that each subclass can just |
Greg Clayton | 8b82f08 | 2011-04-12 05:54:46 +0000 | [diff] [blame] | 632 | // call this function to get the host functionality. |
Greg Clayton | 32e0a75 | 2011-03-30 18:16:51 +0000 | [diff] [blame] | 633 | if (IsHost()) |
| 634 | return Host::GetProcessInfo (pid, process_info); |
| 635 | return false; |
| 636 | } |
| 637 | |
| 638 | uint32_t |
Greg Clayton | 8b82f08 | 2011-04-12 05:54:46 +0000 | [diff] [blame] | 639 | Platform::FindProcesses (const ProcessInstanceInfoMatch &match_info, |
| 640 | ProcessInstanceInfoList &process_infos) |
Greg Clayton | 32e0a75 | 2011-03-30 18:16:51 +0000 | [diff] [blame] | 641 | { |
Greg Clayton | 8b82f08 | 2011-04-12 05:54:46 +0000 | [diff] [blame] | 642 | // Take care of the host case so that each subclass can just |
| 643 | // call this function to get the host functionality. |
Greg Clayton | 32e0a75 | 2011-03-30 18:16:51 +0000 | [diff] [blame] | 644 | uint32_t match_count = 0; |
| 645 | if (IsHost()) |
| 646 | match_count = Host::FindProcesses (match_info, process_infos); |
| 647 | return match_count; |
| 648 | } |
Greg Clayton | 8b82f08 | 2011-04-12 05:54:46 +0000 | [diff] [blame] | 649 | |
| 650 | |
| 651 | Error |
| 652 | Platform::LaunchProcess (ProcessLaunchInfo &launch_info) |
| 653 | { |
| 654 | Error error; |
| 655 | // Take care of the host case so that each subclass can just |
| 656 | // call this function to get the host functionality. |
| 657 | if (IsHost()) |
Greg Clayton | 84db910 | 2012-03-26 23:03:23 +0000 | [diff] [blame] | 658 | { |
| 659 | if (::getenv ("LLDB_LAUNCH_FLAG_LAUNCH_IN_TTY")) |
| 660 | launch_info.GetFlags().Set (eLaunchFlagLaunchInTTY); |
| 661 | |
| 662 | if (launch_info.GetFlags().Test (eLaunchFlagLaunchInShell)) |
| 663 | { |
| 664 | const bool is_localhost = true; |
Greg Clayton | d1cf11a | 2012-04-14 01:42:46 +0000 | [diff] [blame] | 665 | const bool will_debug = launch_info.GetFlags().Test(eLaunchFlagDebug); |
| 666 | const bool first_arg_is_full_shell_command = false; |
Jim Ingham | d399079 | 2013-09-11 18:23:22 +0000 | [diff] [blame^] | 667 | uint32_t num_resumes = GetResumeCountForLaunchInfo (launch_info); |
Greg Clayton | d1cf11a | 2012-04-14 01:42:46 +0000 | [diff] [blame] | 668 | if (!launch_info.ConvertArgumentsForLaunchingInShell (error, |
| 669 | is_localhost, |
| 670 | will_debug, |
Jim Ingham | df0ae22 | 2013-09-10 02:09:47 +0000 | [diff] [blame] | 671 | first_arg_is_full_shell_command, |
| 672 | num_resumes)) |
Greg Clayton | 84db910 | 2012-03-26 23:03:23 +0000 | [diff] [blame] | 673 | return error; |
| 674 | } |
| 675 | |
Greg Clayton | 8b82f08 | 2011-04-12 05:54:46 +0000 | [diff] [blame] | 676 | error = Host::LaunchProcess (launch_info); |
Greg Clayton | 84db910 | 2012-03-26 23:03:23 +0000 | [diff] [blame] | 677 | } |
Greg Clayton | 8b82f08 | 2011-04-12 05:54:46 +0000 | [diff] [blame] | 678 | else |
| 679 | error.SetErrorString ("base lldb_private::Platform class can't launch remote processes"); |
| 680 | return error; |
| 681 | } |
| 682 | |
| 683 | lldb::ProcessSP |
| 684 | Platform::DebugProcess (ProcessLaunchInfo &launch_info, |
| 685 | Debugger &debugger, |
| 686 | Target *target, // Can be NULL, if NULL create a new target, else use existing one |
| 687 | Listener &listener, |
| 688 | Error &error) |
| 689 | { |
| 690 | ProcessSP process_sp; |
| 691 | // Make sure we stop at the entry point |
| 692 | launch_info.GetFlags ().Set (eLaunchFlagDebug); |
Jim Ingham | b4451b1 | 2012-06-01 01:22:13 +0000 | [diff] [blame] | 693 | // We always launch the process we are going to debug in a separate process |
| 694 | // group, since then we can handle ^C interrupts ourselves w/o having to worry |
| 695 | // about the target getting them as well. |
| 696 | launch_info.SetLaunchInSeparateProcessGroup(true); |
| 697 | |
Greg Clayton | 8b82f08 | 2011-04-12 05:54:46 +0000 | [diff] [blame] | 698 | error = LaunchProcess (launch_info); |
| 699 | if (error.Success()) |
| 700 | { |
Greg Clayton | 144f3a9 | 2011-11-15 03:53:30 +0000 | [diff] [blame] | 701 | if (launch_info.GetProcessID() != LLDB_INVALID_PROCESS_ID) |
Greg Clayton | 8b82f08 | 2011-04-12 05:54:46 +0000 | [diff] [blame] | 702 | { |
Greg Clayton | 144f3a9 | 2011-11-15 03:53:30 +0000 | [diff] [blame] | 703 | ProcessAttachInfo attach_info (launch_info); |
| 704 | process_sp = Attach (attach_info, debugger, target, listener, error); |
Greg Clayton | e24c4ac | 2011-11-17 04:46:02 +0000 | [diff] [blame] | 705 | if (process_sp) |
| 706 | { |
| 707 | // Since we attached to the process, it will think it needs to detach |
| 708 | // if the process object just goes away without an explicit call to |
| 709 | // Process::Kill() or Process::Detach(), so let it know to kill the |
| 710 | // process if this happens. |
| 711 | process_sp->SetShouldDetach (false); |
Greg Clayton | ee95ed5 | 2011-11-17 22:14:31 +0000 | [diff] [blame] | 712 | |
| 713 | // If we didn't have any file actions, the pseudo terminal might |
| 714 | // have been used where the slave side was given as the file to |
| 715 | // open for stdin/out/err after we have already opened the master |
| 716 | // so we can read/write stdin/out/err. |
| 717 | int pty_fd = launch_info.GetPTY().ReleaseMasterFileDescriptor(); |
| 718 | if (pty_fd != lldb_utility::PseudoTerminal::invalid_fd) |
| 719 | { |
| 720 | process_sp->SetSTDIOFileDescriptor(pty_fd); |
| 721 | } |
Greg Clayton | e24c4ac | 2011-11-17 04:46:02 +0000 | [diff] [blame] | 722 | } |
Greg Clayton | 8b82f08 | 2011-04-12 05:54:46 +0000 | [diff] [blame] | 723 | } |
| 724 | } |
| 725 | return process_sp; |
| 726 | } |
Greg Clayton | b3a40ba | 2012-03-20 18:34:04 +0000 | [diff] [blame] | 727 | |
| 728 | |
| 729 | lldb::PlatformSP |
Greg Clayton | 7051231 | 2012-05-08 01:45:38 +0000 | [diff] [blame] | 730 | Platform::GetPlatformForArchitecture (const ArchSpec &arch, ArchSpec *platform_arch_ptr) |
Greg Clayton | b3a40ba | 2012-03-20 18:34:04 +0000 | [diff] [blame] | 731 | { |
| 732 | lldb::PlatformSP platform_sp; |
| 733 | Error error; |
| 734 | if (arch.IsValid()) |
Greg Clayton | 7051231 | 2012-05-08 01:45:38 +0000 | [diff] [blame] | 735 | platform_sp = Platform::Create (arch, platform_arch_ptr, error); |
Greg Clayton | b3a40ba | 2012-03-20 18:34:04 +0000 | [diff] [blame] | 736 | return platform_sp; |
| 737 | } |
| 738 | |
| 739 | |
| 740 | //------------------------------------------------------------------ |
| 741 | /// Lets a platform answer if it is compatible with a given |
| 742 | /// architecture and the target triple contained within. |
| 743 | //------------------------------------------------------------------ |
| 744 | bool |
Greg Clayton | 1e0c884 | 2013-01-11 20:49:54 +0000 | [diff] [blame] | 745 | Platform::IsCompatibleArchitecture (const ArchSpec &arch, bool exact_arch_match, ArchSpec *compatible_arch_ptr) |
Greg Clayton | b3a40ba | 2012-03-20 18:34:04 +0000 | [diff] [blame] | 746 | { |
| 747 | // If the architecture is invalid, we must answer true... |
Greg Clayton | 7051231 | 2012-05-08 01:45:38 +0000 | [diff] [blame] | 748 | if (arch.IsValid()) |
Greg Clayton | b3a40ba | 2012-03-20 18:34:04 +0000 | [diff] [blame] | 749 | { |
Greg Clayton | 7051231 | 2012-05-08 01:45:38 +0000 | [diff] [blame] | 750 | ArchSpec platform_arch; |
Greg Clayton | 1e0c884 | 2013-01-11 20:49:54 +0000 | [diff] [blame] | 751 | // Try for an exact architecture match first. |
| 752 | if (exact_arch_match) |
Greg Clayton | 7051231 | 2012-05-08 01:45:38 +0000 | [diff] [blame] | 753 | { |
Greg Clayton | 1e0c884 | 2013-01-11 20:49:54 +0000 | [diff] [blame] | 754 | for (uint32_t arch_idx=0; GetSupportedArchitectureAtIndex (arch_idx, platform_arch); ++arch_idx) |
Greg Clayton | 7051231 | 2012-05-08 01:45:38 +0000 | [diff] [blame] | 755 | { |
Greg Clayton | 1e0c884 | 2013-01-11 20:49:54 +0000 | [diff] [blame] | 756 | if (arch.IsExactMatch(platform_arch)) |
| 757 | { |
| 758 | if (compatible_arch_ptr) |
| 759 | *compatible_arch_ptr = platform_arch; |
| 760 | return true; |
| 761 | } |
| 762 | } |
| 763 | } |
| 764 | else |
| 765 | { |
| 766 | for (uint32_t arch_idx=0; GetSupportedArchitectureAtIndex (arch_idx, platform_arch); ++arch_idx) |
| 767 | { |
| 768 | if (arch.IsCompatibleMatch(platform_arch)) |
| 769 | { |
| 770 | if (compatible_arch_ptr) |
| 771 | *compatible_arch_ptr = platform_arch; |
| 772 | return true; |
| 773 | } |
Greg Clayton | 7051231 | 2012-05-08 01:45:38 +0000 | [diff] [blame] | 774 | } |
| 775 | } |
Greg Clayton | b3a40ba | 2012-03-20 18:34:04 +0000 | [diff] [blame] | 776 | } |
Greg Clayton | 7051231 | 2012-05-08 01:45:38 +0000 | [diff] [blame] | 777 | if (compatible_arch_ptr) |
| 778 | compatible_arch_ptr->Clear(); |
Greg Clayton | b3a40ba | 2012-03-20 18:34:04 +0000 | [diff] [blame] | 779 | return false; |
Greg Clayton | b3a40ba | 2012-03-20 18:34:04 +0000 | [diff] [blame] | 780 | } |
| 781 | |
Daniel Malea | e0f8f57 | 2013-08-26 23:57:52 +0000 | [diff] [blame] | 782 | uint32_t |
| 783 | Platform::MakeDirectory (const FileSpec &spec, |
| 784 | mode_t mode) |
| 785 | { |
| 786 | std::string path(spec.GetPath()); |
| 787 | return this->MakeDirectory(path,mode); |
| 788 | } |
| 789 | |
| 790 | Error |
| 791 | Platform::PutFile (const FileSpec& source, |
| 792 | const FileSpec& destination, |
| 793 | uint32_t uid, |
| 794 | uint32_t gid) |
| 795 | { |
| 796 | Error error("unimplemented"); |
| 797 | return error; |
| 798 | } |
| 799 | |
| 800 | Error |
| 801 | Platform::GetFile (const FileSpec& source, |
| 802 | const FileSpec& destination) |
| 803 | { |
| 804 | Error error("unimplemented"); |
| 805 | return error; |
| 806 | } |
| 807 | |
| 808 | bool |
| 809 | Platform::GetFileExists (const lldb_private::FileSpec& file_spec) |
| 810 | { |
| 811 | return false; |
| 812 | } |
| 813 | |
| 814 | lldb_private::Error |
| 815 | Platform::RunShellCommand (const char *command, // Shouldn't be NULL |
| 816 | const char *working_dir, // Pass NULL to use the current working directory |
| 817 | int *status_ptr, // Pass NULL if you don't want the process exit status |
| 818 | int *signo_ptr, // Pass NULL if you don't want the signal that caused the process to exit |
| 819 | std::string *command_output, // Pass NULL if you don't want the command output |
| 820 | uint32_t timeout_sec) // Timeout in seconds to wait for shell program to finish |
| 821 | { |
| 822 | if (IsHost()) |
| 823 | return Host::RunShellCommand (command, working_dir, status_ptr, signo_ptr, command_output, timeout_sec); |
| 824 | else |
| 825 | return Error("unimplemented"); |
| 826 | } |
| 827 | |
| 828 | |
| 829 | bool |
| 830 | Platform::CalculateMD5 (const FileSpec& file_spec, |
| 831 | uint64_t &low, |
| 832 | uint64_t &high) |
| 833 | { |
| 834 | if (IsHost()) |
| 835 | return Host::CalculateMD5(file_spec, low, high); |
| 836 | else |
| 837 | return false; |
| 838 | } |
| 839 | |
| 840 | void |
| 841 | Platform::SetLocalCacheDirectory (const char* local) |
| 842 | { |
| 843 | m_local_cache_directory.assign(local); |
| 844 | } |
| 845 | |
| 846 | const char* |
| 847 | Platform::GetLocalCacheDirectory () |
| 848 | { |
| 849 | return m_local_cache_directory.c_str(); |
| 850 | } |
| 851 | |
| 852 | static OptionDefinition |
| 853 | g_rsync_option_table[] = |
| 854 | { |
Virgile Bello | e2607b5 | 2013-09-05 16:42:23 +0000 | [diff] [blame] | 855 | { LLDB_OPT_SET_ALL, false, "rsync" , 'r', OptionParser::eNoArgument, NULL, 0, eArgTypeNone , "Enable rsync." }, |
| 856 | { LLDB_OPT_SET_ALL, false, "rsync-opts" , 'R', OptionParser::eRequiredArgument, NULL, 0, eArgTypeCommandName , "Platform-specific options required for rsync to work." }, |
| 857 | { LLDB_OPT_SET_ALL, false, "rsync-prefix" , 'P', OptionParser::eRequiredArgument, NULL, 0, eArgTypeCommandName , "Platform-specific rsync prefix put before the remote path." }, |
| 858 | { LLDB_OPT_SET_ALL, false, "ignore-remote-hostname" , 'i', OptionParser::eNoArgument, NULL, 0, eArgTypeNone , "Do not automatically fill in the remote hostname when composing the rsync command." }, |
Daniel Malea | e0f8f57 | 2013-08-26 23:57:52 +0000 | [diff] [blame] | 859 | }; |
| 860 | |
| 861 | static OptionDefinition |
| 862 | g_ssh_option_table[] = |
| 863 | { |
Virgile Bello | e2607b5 | 2013-09-05 16:42:23 +0000 | [diff] [blame] | 864 | { LLDB_OPT_SET_ALL, false, "ssh" , 's', OptionParser::eNoArgument, NULL, 0, eArgTypeNone , "Enable SSH." }, |
| 865 | { LLDB_OPT_SET_ALL, false, "ssh-opts" , 'S', OptionParser::eRequiredArgument, NULL, 0, eArgTypeCommandName , "Platform-specific options required for SSH to work." }, |
Daniel Malea | e0f8f57 | 2013-08-26 23:57:52 +0000 | [diff] [blame] | 866 | }; |
| 867 | |
| 868 | static OptionDefinition |
| 869 | g_caching_option_table[] = |
| 870 | { |
Virgile Bello | e2607b5 | 2013-09-05 16:42:23 +0000 | [diff] [blame] | 871 | { LLDB_OPT_SET_ALL, false, "local-cache-dir" , 'c', OptionParser::eRequiredArgument, NULL, 0, eArgTypePath , "Path in which to store local copies of files." }, |
Daniel Malea | e0f8f57 | 2013-08-26 23:57:52 +0000 | [diff] [blame] | 872 | }; |
| 873 | |
| 874 | OptionGroupPlatformRSync::OptionGroupPlatformRSync () |
| 875 | { |
| 876 | } |
| 877 | |
| 878 | OptionGroupPlatformRSync::~OptionGroupPlatformRSync () |
| 879 | { |
| 880 | } |
| 881 | |
| 882 | const lldb_private::OptionDefinition* |
| 883 | OptionGroupPlatformRSync::GetDefinitions () |
| 884 | { |
| 885 | return g_rsync_option_table; |
| 886 | } |
| 887 | |
| 888 | void |
| 889 | OptionGroupPlatformRSync::OptionParsingStarting (CommandInterpreter &interpreter) |
| 890 | { |
| 891 | m_rsync = false; |
| 892 | m_rsync_opts.clear(); |
| 893 | m_rsync_prefix.clear(); |
| 894 | m_ignores_remote_hostname = false; |
| 895 | } |
| 896 | |
| 897 | lldb_private::Error |
| 898 | OptionGroupPlatformRSync::SetOptionValue (CommandInterpreter &interpreter, |
| 899 | uint32_t option_idx, |
| 900 | const char *option_arg) |
| 901 | { |
| 902 | Error error; |
| 903 | char short_option = (char) GetDefinitions()[option_idx].short_option; |
| 904 | switch (short_option) |
| 905 | { |
| 906 | case 'r': |
| 907 | m_rsync = true; |
| 908 | break; |
| 909 | |
| 910 | case 'R': |
| 911 | m_rsync_opts.assign(option_arg); |
| 912 | break; |
| 913 | |
| 914 | case 'P': |
| 915 | m_rsync_prefix.assign(option_arg); |
| 916 | break; |
| 917 | |
| 918 | case 'i': |
| 919 | m_ignores_remote_hostname = true; |
| 920 | break; |
| 921 | |
| 922 | default: |
| 923 | error.SetErrorStringWithFormat ("unrecognized option '%c'", short_option); |
| 924 | break; |
| 925 | } |
| 926 | |
| 927 | return error; |
| 928 | } |
| 929 | |
| 930 | uint32_t |
| 931 | OptionGroupPlatformRSync::GetNumDefinitions () |
| 932 | { |
| 933 | return llvm::array_lengthof(g_rsync_option_table); |
| 934 | } |
Greg Clayton | 1e0c884 | 2013-01-11 20:49:54 +0000 | [diff] [blame] | 935 | |
Greg Clayton | 4116e93 | 2012-05-15 02:33:01 +0000 | [diff] [blame] | 936 | lldb::BreakpointSP |
| 937 | Platform::SetThreadCreationBreakpoint (lldb_private::Target &target) |
| 938 | { |
| 939 | return lldb::BreakpointSP(); |
| 940 | } |
Greg Clayton | b3a40ba | 2012-03-20 18:34:04 +0000 | [diff] [blame] | 941 | |
Daniel Malea | e0f8f57 | 2013-08-26 23:57:52 +0000 | [diff] [blame] | 942 | OptionGroupPlatformSSH::OptionGroupPlatformSSH () |
| 943 | { |
| 944 | } |
| 945 | |
| 946 | OptionGroupPlatformSSH::~OptionGroupPlatformSSH () |
| 947 | { |
| 948 | } |
| 949 | |
| 950 | const lldb_private::OptionDefinition* |
| 951 | OptionGroupPlatformSSH::GetDefinitions () |
| 952 | { |
| 953 | return g_ssh_option_table; |
| 954 | } |
| 955 | |
| 956 | void |
| 957 | OptionGroupPlatformSSH::OptionParsingStarting (CommandInterpreter &interpreter) |
| 958 | { |
| 959 | m_ssh = false; |
| 960 | m_ssh_opts.clear(); |
| 961 | } |
| 962 | |
| 963 | lldb_private::Error |
| 964 | OptionGroupPlatformSSH::SetOptionValue (CommandInterpreter &interpreter, |
| 965 | uint32_t option_idx, |
| 966 | const char *option_arg) |
| 967 | { |
| 968 | Error error; |
| 969 | char short_option = (char) GetDefinitions()[option_idx].short_option; |
| 970 | switch (short_option) |
| 971 | { |
| 972 | case 's': |
| 973 | m_ssh = true; |
| 974 | break; |
| 975 | |
| 976 | case 'S': |
| 977 | m_ssh_opts.assign(option_arg); |
| 978 | break; |
| 979 | |
| 980 | default: |
| 981 | error.SetErrorStringWithFormat ("unrecognized option '%c'", short_option); |
| 982 | break; |
| 983 | } |
| 984 | |
| 985 | return error; |
| 986 | } |
| 987 | |
| 988 | uint32_t |
| 989 | OptionGroupPlatformSSH::GetNumDefinitions () |
| 990 | { |
| 991 | return llvm::array_lengthof(g_ssh_option_table); |
| 992 | } |
| 993 | |
| 994 | OptionGroupPlatformCaching::OptionGroupPlatformCaching () |
| 995 | { |
| 996 | } |
| 997 | |
| 998 | OptionGroupPlatformCaching::~OptionGroupPlatformCaching () |
| 999 | { |
| 1000 | } |
| 1001 | |
| 1002 | const lldb_private::OptionDefinition* |
| 1003 | OptionGroupPlatformCaching::GetDefinitions () |
| 1004 | { |
| 1005 | return g_caching_option_table; |
| 1006 | } |
| 1007 | |
| 1008 | void |
| 1009 | OptionGroupPlatformCaching::OptionParsingStarting (CommandInterpreter &interpreter) |
| 1010 | { |
| 1011 | m_cache_dir.clear(); |
| 1012 | } |
| 1013 | |
| 1014 | lldb_private::Error |
| 1015 | OptionGroupPlatformCaching::SetOptionValue (CommandInterpreter &interpreter, |
| 1016 | uint32_t option_idx, |
| 1017 | const char *option_arg) |
| 1018 | { |
| 1019 | Error error; |
| 1020 | char short_option = (char) GetDefinitions()[option_idx].short_option; |
| 1021 | switch (short_option) |
| 1022 | { |
| 1023 | case 'c': |
| 1024 | m_cache_dir.assign(option_arg); |
| 1025 | break; |
| 1026 | |
| 1027 | default: |
| 1028 | error.SetErrorStringWithFormat ("unrecognized option '%c'", short_option); |
| 1029 | break; |
| 1030 | } |
| 1031 | |
| 1032 | return error; |
| 1033 | } |
| 1034 | |
| 1035 | uint32_t |
| 1036 | OptionGroupPlatformCaching::GetNumDefinitions () |
| 1037 | { |
| 1038 | return llvm::array_lengthof(g_caching_option_table); |
| 1039 | } |
| 1040 | |
Greg Clayton | 67cc063 | 2012-08-22 17:17:09 +0000 | [diff] [blame] | 1041 | size_t |
| 1042 | Platform::GetEnvironment (StringList &environment) |
| 1043 | { |
| 1044 | environment.Clear(); |
| 1045 | return false; |
| 1046 | } |