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" |
Zachary Turner | c00cf4a | 2014-08-15 22:04:21 +0000 | [diff] [blame] | 22 | #include "lldb/Host/FileSystem.h" |
Greg Clayton | ded470d | 2011-03-19 01:12:21 +0000 | [diff] [blame] | 23 | #include "lldb/Host/Host.h" |
Greg Clayton | 8b82f08 | 2011-04-12 05:54:46 +0000 | [diff] [blame] | 24 | #include "lldb/Target/Process.h" |
Greg Clayton | e996fd3 | 2011-03-08 22:40:15 +0000 | [diff] [blame] | 25 | #include "lldb/Target/Target.h" |
Daniel Malea | e0f8f57 | 2013-08-26 23:57:52 +0000 | [diff] [blame] | 26 | #include "lldb/Utility/Utils.h" |
Greg Clayton | e996fd3 | 2011-03-08 22:40:15 +0000 | [diff] [blame] | 27 | |
| 28 | using namespace lldb; |
| 29 | using namespace lldb_private; |
| 30 | |
| 31 | // Use a singleton function for g_local_platform_sp to avoid init |
| 32 | // constructors since LLDB is often part of a shared library |
| 33 | static PlatformSP& |
| 34 | GetDefaultPlatformSP () |
| 35 | { |
| 36 | static PlatformSP g_default_platform_sp; |
| 37 | return g_default_platform_sp; |
| 38 | } |
| 39 | |
Greg Clayton | e996fd3 | 2011-03-08 22:40:15 +0000 | [diff] [blame] | 40 | static Mutex & |
| 41 | GetConnectedPlatformListMutex () |
| 42 | { |
| 43 | static Mutex g_remote_connected_platforms_mutex (Mutex::eMutexTypeRecursive); |
| 44 | return g_remote_connected_platforms_mutex; |
| 45 | } |
| 46 | static std::vector<PlatformSP> & |
| 47 | GetConnectedPlatformList () |
| 48 | { |
| 49 | static std::vector<PlatformSP> g_remote_connected_platforms; |
| 50 | return g_remote_connected_platforms; |
| 51 | } |
| 52 | |
Greg Clayton | ab65b34 | 2011-04-13 22:47:15 +0000 | [diff] [blame] | 53 | |
| 54 | const char * |
| 55 | Platform::GetHostPlatformName () |
| 56 | { |
| 57 | return "host"; |
| 58 | } |
| 59 | |
Greg Clayton | e996fd3 | 2011-03-08 22:40:15 +0000 | [diff] [blame] | 60 | //------------------------------------------------------------------ |
| 61 | /// Get the native host platform plug-in. |
| 62 | /// |
| 63 | /// There should only be one of these for each host that LLDB runs |
| 64 | /// upon that should be statically compiled in and registered using |
| 65 | /// preprocessor macros or other similar build mechanisms. |
| 66 | /// |
| 67 | /// This platform will be used as the default platform when launching |
| 68 | /// or attaching to processes unless another platform is specified. |
| 69 | //------------------------------------------------------------------ |
| 70 | PlatformSP |
| 71 | Platform::GetDefaultPlatform () |
| 72 | { |
| 73 | return GetDefaultPlatformSP (); |
| 74 | } |
| 75 | |
| 76 | void |
| 77 | Platform::SetDefaultPlatform (const lldb::PlatformSP &platform_sp) |
| 78 | { |
| 79 | // The native platform should use its static void Platform::Initialize() |
| 80 | // function to register itself as the native platform. |
| 81 | GetDefaultPlatformSP () = platform_sp; |
| 82 | } |
| 83 | |
Greg Clayton | e996fd3 | 2011-03-08 22:40:15 +0000 | [diff] [blame] | 84 | Error |
Steve Pucci | fc99572 | 2014-01-17 18:18:31 +0000 | [diff] [blame] | 85 | Platform::GetFileWithUUID (const FileSpec &platform_file, |
| 86 | const UUID *uuid_ptr, |
| 87 | FileSpec &local_file) |
Greg Clayton | e996fd3 | 2011-03-08 22:40:15 +0000 | [diff] [blame] | 88 | { |
| 89 | // Default to the local case |
| 90 | local_file = platform_file; |
| 91 | return Error(); |
| 92 | } |
| 93 | |
Greg Clayton | 91c0e74 | 2013-01-11 23:44:27 +0000 | [diff] [blame] | 94 | FileSpecList |
Enrico Granata | fe7295d | 2014-08-16 00:32:58 +0000 | [diff] [blame^] | 95 | Platform::LocateExecutableScriptingResources (Target *target, Module &module, Stream* feedback_stream) |
Enrico Granata | 1759848 | 2012-11-08 02:22:02 +0000 | [diff] [blame] | 96 | { |
Greg Clayton | 91c0e74 | 2013-01-11 23:44:27 +0000 | [diff] [blame] | 97 | return FileSpecList(); |
Enrico Granata | 1759848 | 2012-11-08 02:22:02 +0000 | [diff] [blame] | 98 | } |
| 99 | |
Jason Molenda | 1c62754 | 2013-04-05 01:03:25 +0000 | [diff] [blame] | 100 | Platform* |
Greg Clayton | 57abc5d | 2013-05-10 21:47:16 +0000 | [diff] [blame] | 101 | Platform::FindPlugin (Process *process, const ConstString &plugin_name) |
Jason Molenda | 1c62754 | 2013-04-05 01:03:25 +0000 | [diff] [blame] | 102 | { |
| 103 | PlatformCreateInstance create_callback = NULL; |
| 104 | if (plugin_name) |
| 105 | { |
| 106 | create_callback = PluginManager::GetPlatformCreateCallbackForPluginName (plugin_name); |
| 107 | if (create_callback) |
| 108 | { |
| 109 | ArchSpec arch; |
| 110 | if (process) |
| 111 | { |
| 112 | arch = process->GetTarget().GetArchitecture(); |
| 113 | } |
Greg Clayton | 7b0992d | 2013-04-18 22:45:39 +0000 | [diff] [blame] | 114 | std::unique_ptr<Platform> instance_ap(create_callback(process, &arch)); |
Jason Molenda | 1c62754 | 2013-04-05 01:03:25 +0000 | [diff] [blame] | 115 | if (instance_ap.get()) |
| 116 | return instance_ap.release(); |
| 117 | } |
| 118 | } |
| 119 | else |
| 120 | { |
| 121 | for (uint32_t idx = 0; (create_callback = PluginManager::GetPlatformCreateCallbackAtIndex(idx)) != NULL; ++idx) |
| 122 | { |
Matt Kopec | ef14371 | 2013-06-03 18:00:07 +0000 | [diff] [blame] | 123 | std::unique_ptr<Platform> instance_ap(create_callback(process, nullptr)); |
Jason Molenda | 1c62754 | 2013-04-05 01:03:25 +0000 | [diff] [blame] | 124 | if (instance_ap.get()) |
| 125 | return instance_ap.release(); |
| 126 | } |
| 127 | } |
| 128 | return NULL; |
| 129 | } |
| 130 | |
Greg Clayton | 32e0a75 | 2011-03-30 18:16:51 +0000 | [diff] [blame] | 131 | Error |
Greg Clayton | b9a01b3 | 2012-02-26 05:51:37 +0000 | [diff] [blame] | 132 | Platform::GetSharedModule (const ModuleSpec &module_spec, |
Greg Clayton | 32e0a75 | 2011-03-30 18:16:51 +0000 | [diff] [blame] | 133 | ModuleSP &module_sp, |
Greg Clayton | c859e2d | 2012-02-13 23:10:39 +0000 | [diff] [blame] | 134 | const FileSpecList *module_search_paths_ptr, |
Greg Clayton | 32e0a75 | 2011-03-30 18:16:51 +0000 | [diff] [blame] | 135 | ModuleSP *old_module_sp_ptr, |
| 136 | bool *did_create_ptr) |
| 137 | { |
| 138 | // Don't do any path remapping for the default implementation |
| 139 | // of the platform GetSharedModule function, just call through |
| 140 | // to our static ModuleList function. Platform subclasses that |
| 141 | // implement remote debugging, might have a developer kits |
| 142 | // installed that have cached versions of the files for the |
| 143 | // remote target, or might implement a download and cache |
| 144 | // locally implementation. |
| 145 | const bool always_create = false; |
Greg Clayton | b9a01b3 | 2012-02-26 05:51:37 +0000 | [diff] [blame] | 146 | return ModuleList::GetSharedModule (module_spec, |
Greg Clayton | 32e0a75 | 2011-03-30 18:16:51 +0000 | [diff] [blame] | 147 | module_sp, |
Greg Clayton | c859e2d | 2012-02-13 23:10:39 +0000 | [diff] [blame] | 148 | module_search_paths_ptr, |
Greg Clayton | 32e0a75 | 2011-03-30 18:16:51 +0000 | [diff] [blame] | 149 | old_module_sp_ptr, |
| 150 | did_create_ptr, |
| 151 | always_create); |
| 152 | } |
| 153 | |
Greg Clayton | e996fd3 | 2011-03-08 22:40:15 +0000 | [diff] [blame] | 154 | PlatformSP |
Greg Clayton | ded470d | 2011-03-19 01:12:21 +0000 | [diff] [blame] | 155 | Platform::Create (const char *platform_name, Error &error) |
Greg Clayton | e996fd3 | 2011-03-08 22:40:15 +0000 | [diff] [blame] | 156 | { |
| 157 | PlatformCreateInstance create_callback = NULL; |
| 158 | lldb::PlatformSP platform_sp; |
Greg Clayton | ded470d | 2011-03-19 01:12:21 +0000 | [diff] [blame] | 159 | if (platform_name && platform_name[0]) |
Greg Clayton | e996fd3 | 2011-03-08 22:40:15 +0000 | [diff] [blame] | 160 | { |
Greg Clayton | 57abc5d | 2013-05-10 21:47:16 +0000 | [diff] [blame] | 161 | ConstString const_platform_name (platform_name); |
| 162 | create_callback = PluginManager::GetPlatformCreateCallbackForPluginName (const_platform_name); |
Greg Clayton | e996fd3 | 2011-03-08 22:40:15 +0000 | [diff] [blame] | 163 | if (create_callback) |
Greg Clayton | b3a40ba | 2012-03-20 18:34:04 +0000 | [diff] [blame] | 164 | platform_sp.reset(create_callback(true, NULL)); |
Greg Clayton | e996fd3 | 2011-03-08 22:40:15 +0000 | [diff] [blame] | 165 | else |
Greg Clayton | ded470d | 2011-03-19 01:12:21 +0000 | [diff] [blame] | 166 | 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] | 167 | } |
| 168 | else |
Greg Clayton | ded470d | 2011-03-19 01:12:21 +0000 | [diff] [blame] | 169 | error.SetErrorString ("invalid platform name"); |
Greg Clayton | e996fd3 | 2011-03-08 22:40:15 +0000 | [diff] [blame] | 170 | return platform_sp; |
| 171 | } |
| 172 | |
Greg Clayton | b3a40ba | 2012-03-20 18:34:04 +0000 | [diff] [blame] | 173 | |
| 174 | PlatformSP |
Greg Clayton | 7051231 | 2012-05-08 01:45:38 +0000 | [diff] [blame] | 175 | Platform::Create (const ArchSpec &arch, ArchSpec *platform_arch_ptr, Error &error) |
Greg Clayton | b3a40ba | 2012-03-20 18:34:04 +0000 | [diff] [blame] | 176 | { |
| 177 | lldb::PlatformSP platform_sp; |
| 178 | if (arch.IsValid()) |
| 179 | { |
Greg Clayton | 7051231 | 2012-05-08 01:45:38 +0000 | [diff] [blame] | 180 | uint32_t idx; |
Greg Clayton | b3a40ba | 2012-03-20 18:34:04 +0000 | [diff] [blame] | 181 | PlatformCreateInstance create_callback; |
Greg Clayton | 1e0c884 | 2013-01-11 20:49:54 +0000 | [diff] [blame] | 182 | // First try exact arch matches across all platform plug-ins |
| 183 | bool exact = true; |
Greg Clayton | 7051231 | 2012-05-08 01:45:38 +0000 | [diff] [blame] | 184 | for (idx = 0; (create_callback = PluginManager::GetPlatformCreateCallbackAtIndex (idx)); ++idx) |
Greg Clayton | b3a40ba | 2012-03-20 18:34:04 +0000 | [diff] [blame] | 185 | { |
| 186 | if (create_callback) |
Greg Clayton | 1e0c884 | 2013-01-11 20:49:54 +0000 | [diff] [blame] | 187 | { |
Greg Clayton | b3a40ba | 2012-03-20 18:34:04 +0000 | [diff] [blame] | 188 | platform_sp.reset(create_callback(false, &arch)); |
Greg Clayton | 1e0c884 | 2013-01-11 20:49:54 +0000 | [diff] [blame] | 189 | if (platform_sp && platform_sp->IsCompatibleArchitecture(arch, exact, platform_arch_ptr)) |
| 190 | return platform_sp; |
| 191 | } |
| 192 | } |
| 193 | // Next try compatible arch matches across all platform plug-ins |
| 194 | exact = false; |
| 195 | for (idx = 0; (create_callback = PluginManager::GetPlatformCreateCallbackAtIndex (idx)); ++idx) |
| 196 | { |
| 197 | if (create_callback) |
| 198 | { |
| 199 | platform_sp.reset(create_callback(false, &arch)); |
| 200 | if (platform_sp && platform_sp->IsCompatibleArchitecture(arch, exact, platform_arch_ptr)) |
| 201 | return platform_sp; |
| 202 | } |
Greg Clayton | b3a40ba | 2012-03-20 18:34:04 +0000 | [diff] [blame] | 203 | } |
| 204 | } |
| 205 | else |
| 206 | error.SetErrorString ("invalid platform name"); |
Greg Clayton | 7051231 | 2012-05-08 01:45:38 +0000 | [diff] [blame] | 207 | if (platform_arch_ptr) |
| 208 | platform_arch_ptr->Clear(); |
| 209 | platform_sp.reset(); |
Greg Clayton | b3a40ba | 2012-03-20 18:34:04 +0000 | [diff] [blame] | 210 | return platform_sp; |
| 211 | } |
| 212 | |
Greg Clayton | e996fd3 | 2011-03-08 22:40:15 +0000 | [diff] [blame] | 213 | uint32_t |
| 214 | Platform::GetNumConnectedRemotePlatforms () |
| 215 | { |
| 216 | Mutex::Locker locker (GetConnectedPlatformListMutex ()); |
| 217 | return GetConnectedPlatformList().size(); |
| 218 | } |
| 219 | |
| 220 | PlatformSP |
| 221 | Platform::GetConnectedRemotePlatformAtIndex (uint32_t idx) |
| 222 | { |
| 223 | PlatformSP platform_sp; |
| 224 | { |
| 225 | Mutex::Locker locker (GetConnectedPlatformListMutex ()); |
| 226 | if (idx < GetConnectedPlatformList().size()) |
| 227 | platform_sp = GetConnectedPlatformList ()[idx]; |
| 228 | } |
| 229 | return platform_sp; |
| 230 | } |
| 231 | |
| 232 | //------------------------------------------------------------------ |
| 233 | /// Default Constructor |
| 234 | //------------------------------------------------------------------ |
Greg Clayton | ded470d | 2011-03-19 01:12:21 +0000 | [diff] [blame] | 235 | Platform::Platform (bool is_host) : |
| 236 | m_is_host (is_host), |
Greg Clayton | ded470d | 2011-03-19 01:12:21 +0000 | [diff] [blame] | 237 | m_os_version_set_while_connected (false), |
| 238 | m_system_arch_set_while_connected (false), |
Greg Clayton | f3dd93c | 2011-06-17 03:31:01 +0000 | [diff] [blame] | 239 | m_sdk_sysroot (), |
| 240 | m_sdk_build (), |
Greg Clayton | fbb7634 | 2013-11-20 21:07:01 +0000 | [diff] [blame] | 241 | m_working_dir (), |
Greg Clayton | ded470d | 2011-03-19 01:12:21 +0000 | [diff] [blame] | 242 | m_remote_url (), |
Greg Clayton | 1cb6496 | 2011-03-24 04:28:38 +0000 | [diff] [blame] | 243 | m_name (), |
Greg Clayton | ded470d | 2011-03-19 01:12:21 +0000 | [diff] [blame] | 244 | m_major_os_version (UINT32_MAX), |
| 245 | m_minor_os_version (UINT32_MAX), |
Greg Clayton | 32e0a75 | 2011-03-30 18:16:51 +0000 | [diff] [blame] | 246 | m_update_os_version (UINT32_MAX), |
| 247 | m_system_arch(), |
| 248 | m_uid_map_mutex (Mutex::eMutexTypeNormal), |
| 249 | m_gid_map_mutex (Mutex::eMutexTypeNormal), |
| 250 | m_uid_map(), |
| 251 | m_gid_map(), |
| 252 | m_max_uid_name_len (0), |
Daniel Malea | e0f8f57 | 2013-08-26 23:57:52 +0000 | [diff] [blame] | 253 | m_max_gid_name_len (0), |
| 254 | m_supports_rsync (false), |
| 255 | m_rsync_opts (), |
| 256 | m_rsync_prefix (), |
| 257 | m_supports_ssh (false), |
| 258 | m_ssh_opts (), |
Jason Molenda | 6223db27 | 2014-02-13 07:11:08 +0000 | [diff] [blame] | 259 | m_ignores_remote_hostname (false), |
Jason Molenda | 2094dbf | 2014-02-13 23:11:45 +0000 | [diff] [blame] | 260 | m_trap_handlers(), |
Jason Molenda | 4da8706 | 2014-05-23 23:11:27 +0000 | [diff] [blame] | 261 | m_calculated_trap_handlers (false), |
| 262 | m_trap_handler_mutex() |
Greg Clayton | e996fd3 | 2011-03-08 22:40:15 +0000 | [diff] [blame] | 263 | { |
Greg Clayton | 5160ce5 | 2013-03-27 23:08:40 +0000 | [diff] [blame] | 264 | Log *log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_OBJECT)); |
Greg Clayton | 8b82f08 | 2011-04-12 05:54:46 +0000 | [diff] [blame] | 265 | if (log) |
Saleem Abdulrasool | 324a103 | 2014-04-04 04:06:10 +0000 | [diff] [blame] | 266 | log->Printf ("%p Platform::Platform()", static_cast<void*>(this)); |
Greg Clayton | e996fd3 | 2011-03-08 22:40:15 +0000 | [diff] [blame] | 267 | } |
| 268 | |
| 269 | //------------------------------------------------------------------ |
| 270 | /// Destructor. |
| 271 | /// |
| 272 | /// The destructor is virtual since this class is designed to be |
| 273 | /// inherited from by the plug-in instance. |
| 274 | //------------------------------------------------------------------ |
| 275 | Platform::~Platform() |
| 276 | { |
Greg Clayton | 5160ce5 | 2013-03-27 23:08:40 +0000 | [diff] [blame] | 277 | Log *log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_OBJECT)); |
Greg Clayton | 8b82f08 | 2011-04-12 05:54:46 +0000 | [diff] [blame] | 278 | if (log) |
Saleem Abdulrasool | 324a103 | 2014-04-04 04:06:10 +0000 | [diff] [blame] | 279 | log->Printf ("%p Platform::~Platform()", static_cast<void*>(this)); |
Greg Clayton | e996fd3 | 2011-03-08 22:40:15 +0000 | [diff] [blame] | 280 | } |
| 281 | |
Greg Clayton | 1cb6496 | 2011-03-24 04:28:38 +0000 | [diff] [blame] | 282 | void |
| 283 | Platform::GetStatus (Stream &strm) |
| 284 | { |
| 285 | uint32_t major = UINT32_MAX; |
| 286 | uint32_t minor = UINT32_MAX; |
| 287 | uint32_t update = UINT32_MAX; |
| 288 | std::string s; |
Greg Clayton | 57abc5d | 2013-05-10 21:47:16 +0000 | [diff] [blame] | 289 | strm.Printf (" Platform: %s\n", GetPluginName().GetCString()); |
Greg Clayton | 1cb6496 | 2011-03-24 04:28:38 +0000 | [diff] [blame] | 290 | |
| 291 | ArchSpec arch (GetSystemArchitecture()); |
| 292 | if (arch.IsValid()) |
| 293 | { |
| 294 | if (!arch.GetTriple().str().empty()) |
Greg Clayton | 32e0a75 | 2011-03-30 18:16:51 +0000 | [diff] [blame] | 295 | strm.Printf(" Triple: %s\n", arch.GetTriple().str().c_str()); |
Greg Clayton | 1cb6496 | 2011-03-24 04:28:38 +0000 | [diff] [blame] | 296 | } |
| 297 | |
| 298 | if (GetOSVersion(major, minor, update)) |
| 299 | { |
Greg Clayton | 32e0a75 | 2011-03-30 18:16:51 +0000 | [diff] [blame] | 300 | strm.Printf("OS Version: %u", major); |
Greg Clayton | 1cb6496 | 2011-03-24 04:28:38 +0000 | [diff] [blame] | 301 | if (minor != UINT32_MAX) |
| 302 | strm.Printf(".%u", minor); |
| 303 | if (update != UINT32_MAX) |
| 304 | strm.Printf(".%u", update); |
| 305 | |
| 306 | if (GetOSBuildString (s)) |
| 307 | strm.Printf(" (%s)", s.c_str()); |
| 308 | |
| 309 | strm.EOL(); |
| 310 | } |
| 311 | |
| 312 | if (GetOSKernelDescription (s)) |
Greg Clayton | 32e0a75 | 2011-03-30 18:16:51 +0000 | [diff] [blame] | 313 | strm.Printf(" Kernel: %s\n", s.c_str()); |
Greg Clayton | 1cb6496 | 2011-03-24 04:28:38 +0000 | [diff] [blame] | 314 | |
| 315 | if (IsHost()) |
| 316 | { |
Greg Clayton | 32e0a75 | 2011-03-30 18:16:51 +0000 | [diff] [blame] | 317 | strm.Printf(" Hostname: %s\n", GetHostname()); |
Greg Clayton | 1cb6496 | 2011-03-24 04:28:38 +0000 | [diff] [blame] | 318 | } |
| 319 | else |
| 320 | { |
Greg Clayton | 32e0a75 | 2011-03-30 18:16:51 +0000 | [diff] [blame] | 321 | const bool is_connected = IsConnected(); |
| 322 | if (is_connected) |
| 323 | strm.Printf(" Hostname: %s\n", GetHostname()); |
| 324 | strm.Printf(" Connected: %s\n", is_connected ? "yes" : "no"); |
Greg Clayton | 1cb6496 | 2011-03-24 04:28:38 +0000 | [diff] [blame] | 325 | } |
Daniel Malea | e0f8f57 | 2013-08-26 23:57:52 +0000 | [diff] [blame] | 326 | |
Greg Clayton | fbb7634 | 2013-11-20 21:07:01 +0000 | [diff] [blame] | 327 | if (GetWorkingDirectory()) |
| 328 | { |
| 329 | strm.Printf("WorkingDir: %s\n", GetWorkingDirectory().GetCString()); |
| 330 | } |
Daniel Malea | e0f8f57 | 2013-08-26 23:57:52 +0000 | [diff] [blame] | 331 | if (!IsConnected()) |
| 332 | return; |
| 333 | |
| 334 | std::string specific_info(GetPlatformSpecificConnectionInformation()); |
| 335 | |
| 336 | if (specific_info.empty() == false) |
| 337 | strm.Printf("Platform-specific connection: %s\n", specific_info.c_str()); |
Greg Clayton | 1cb6496 | 2011-03-24 04:28:38 +0000 | [diff] [blame] | 338 | } |
| 339 | |
Greg Clayton | ded470d | 2011-03-19 01:12:21 +0000 | [diff] [blame] | 340 | |
| 341 | bool |
| 342 | Platform::GetOSVersion (uint32_t &major, |
| 343 | uint32_t &minor, |
| 344 | uint32_t &update) |
| 345 | { |
| 346 | bool success = m_major_os_version != UINT32_MAX; |
| 347 | if (IsHost()) |
| 348 | { |
| 349 | if (!success) |
| 350 | { |
| 351 | // We have a local host platform |
| 352 | success = Host::GetOSVersion (m_major_os_version, |
| 353 | m_minor_os_version, |
| 354 | m_update_os_version); |
| 355 | m_os_version_set_while_connected = success; |
| 356 | } |
| 357 | } |
| 358 | else |
| 359 | { |
| 360 | // We have a remote platform. We can only fetch the remote |
| 361 | // OS version if we are connected, and we don't want to do it |
| 362 | // more than once. |
| 363 | |
| 364 | const bool is_connected = IsConnected(); |
| 365 | |
Greg Clayton | 1cb6496 | 2011-03-24 04:28:38 +0000 | [diff] [blame] | 366 | bool fetch = false; |
Greg Clayton | ded470d | 2011-03-19 01:12:21 +0000 | [diff] [blame] | 367 | if (success) |
| 368 | { |
| 369 | // We have valid OS version info, check to make sure it wasn't |
| 370 | // manually set prior to connecting. If it was manually set prior |
| 371 | // to connecting, then lets fetch the actual OS version info |
| 372 | // if we are now connected. |
| 373 | if (is_connected && !m_os_version_set_while_connected) |
Greg Clayton | 1cb6496 | 2011-03-24 04:28:38 +0000 | [diff] [blame] | 374 | fetch = true; |
Greg Clayton | ded470d | 2011-03-19 01:12:21 +0000 | [diff] [blame] | 375 | } |
| 376 | else |
| 377 | { |
| 378 | // 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] | 379 | fetch = is_connected; |
Greg Clayton | ded470d | 2011-03-19 01:12:21 +0000 | [diff] [blame] | 380 | } |
| 381 | |
Greg Clayton | 1cb6496 | 2011-03-24 04:28:38 +0000 | [diff] [blame] | 382 | if (fetch) |
Greg Clayton | ded470d | 2011-03-19 01:12:21 +0000 | [diff] [blame] | 383 | { |
Greg Clayton | 1cb6496 | 2011-03-24 04:28:38 +0000 | [diff] [blame] | 384 | success = GetRemoteOSVersion (); |
Greg Clayton | ded470d | 2011-03-19 01:12:21 +0000 | [diff] [blame] | 385 | m_os_version_set_while_connected = success; |
| 386 | } |
| 387 | } |
| 388 | |
| 389 | if (success) |
| 390 | { |
| 391 | major = m_major_os_version; |
| 392 | minor = m_minor_os_version; |
| 393 | update = m_update_os_version; |
| 394 | } |
| 395 | return success; |
| 396 | } |
Greg Clayton | 1cb6496 | 2011-03-24 04:28:38 +0000 | [diff] [blame] | 397 | |
| 398 | bool |
| 399 | Platform::GetOSBuildString (std::string &s) |
| 400 | { |
| 401 | if (IsHost()) |
| 402 | return Host::GetOSBuildString (s); |
| 403 | else |
| 404 | return GetRemoteOSBuildString (s); |
| 405 | } |
| 406 | |
| 407 | bool |
| 408 | Platform::GetOSKernelDescription (std::string &s) |
| 409 | { |
| 410 | if (IsHost()) |
| 411 | return Host::GetOSKernelDescription (s); |
| 412 | else |
| 413 | return GetRemoteOSKernelDescription (s); |
| 414 | } |
| 415 | |
Greg Clayton | 57abc5d | 2013-05-10 21:47:16 +0000 | [diff] [blame] | 416 | ConstString |
Greg Clayton | fbb7634 | 2013-11-20 21:07:01 +0000 | [diff] [blame] | 417 | Platform::GetWorkingDirectory () |
| 418 | { |
| 419 | if (IsHost()) |
| 420 | { |
| 421 | char cwd[PATH_MAX]; |
| 422 | if (getcwd(cwd, sizeof(cwd))) |
| 423 | return ConstString(cwd); |
| 424 | else |
| 425 | return ConstString(); |
| 426 | } |
| 427 | else |
| 428 | { |
| 429 | if (!m_working_dir) |
| 430 | m_working_dir = GetRemoteWorkingDirectory(); |
| 431 | return m_working_dir; |
| 432 | } |
| 433 | } |
| 434 | |
| 435 | |
| 436 | struct RecurseCopyBaton |
| 437 | { |
| 438 | const FileSpec& dst; |
| 439 | Platform *platform_ptr; |
| 440 | Error error; |
| 441 | }; |
| 442 | |
| 443 | |
| 444 | static FileSpec::EnumerateDirectoryResult |
| 445 | RecurseCopy_Callback (void *baton, |
| 446 | FileSpec::FileType file_type, |
| 447 | const FileSpec &src) |
| 448 | { |
| 449 | RecurseCopyBaton* rc_baton = (RecurseCopyBaton*)baton; |
| 450 | switch (file_type) |
| 451 | { |
| 452 | case FileSpec::eFileTypePipe: |
| 453 | case FileSpec::eFileTypeSocket: |
| 454 | // we have no way to copy pipes and sockets - ignore them and continue |
| 455 | return FileSpec::eEnumerateDirectoryResultNext; |
| 456 | break; |
| 457 | |
| 458 | case FileSpec::eFileTypeDirectory: |
| 459 | { |
| 460 | // make the new directory and get in there |
| 461 | FileSpec dst_dir = rc_baton->dst; |
| 462 | if (!dst_dir.GetFilename()) |
| 463 | dst_dir.GetFilename() = src.GetLastPathComponent(); |
| 464 | std::string dst_dir_path (dst_dir.GetPath()); |
| 465 | Error error = rc_baton->platform_ptr->MakeDirectory(dst_dir_path.c_str(), lldb::eFilePermissionsDirectoryDefault); |
| 466 | if (error.Fail()) |
| 467 | { |
| 468 | rc_baton->error.SetErrorStringWithFormat("unable to setup directory %s on remote end", dst_dir_path.c_str()); |
| 469 | return FileSpec::eEnumerateDirectoryResultQuit; // got an error, bail out |
| 470 | } |
| 471 | |
| 472 | // now recurse |
| 473 | std::string src_dir_path (src.GetPath()); |
| 474 | |
| 475 | // Make a filespec that only fills in the directory of a FileSpec so |
| 476 | // when we enumerate we can quickly fill in the filename for dst copies |
| 477 | FileSpec recurse_dst; |
| 478 | recurse_dst.GetDirectory().SetCString(dst_dir.GetPath().c_str()); |
| 479 | RecurseCopyBaton rc_baton2 = { recurse_dst, rc_baton->platform_ptr, Error() }; |
| 480 | FileSpec::EnumerateDirectory(src_dir_path.c_str(), true, true, true, RecurseCopy_Callback, &rc_baton2); |
| 481 | if (rc_baton2.error.Fail()) |
| 482 | { |
| 483 | rc_baton->error.SetErrorString(rc_baton2.error.AsCString()); |
| 484 | return FileSpec::eEnumerateDirectoryResultQuit; // got an error, bail out |
| 485 | } |
| 486 | return FileSpec::eEnumerateDirectoryResultNext; |
| 487 | } |
| 488 | break; |
| 489 | |
| 490 | case FileSpec::eFileTypeSymbolicLink: |
| 491 | { |
| 492 | // copy the file and keep going |
| 493 | FileSpec dst_file = rc_baton->dst; |
| 494 | if (!dst_file.GetFilename()) |
| 495 | dst_file.GetFilename() = src.GetFilename(); |
| 496 | |
| 497 | char buf[PATH_MAX]; |
Zachary Turner | c00cf4a | 2014-08-15 22:04:21 +0000 | [diff] [blame] | 498 | |
| 499 | rc_baton->error = FileSystem::Readlink(src.GetPath().c_str(), buf, sizeof(buf)); |
Greg Clayton | fbb7634 | 2013-11-20 21:07:01 +0000 | [diff] [blame] | 500 | |
| 501 | if (rc_baton->error.Fail()) |
| 502 | return FileSpec::eEnumerateDirectoryResultQuit; // got an error, bail out |
| 503 | |
| 504 | rc_baton->error = rc_baton->platform_ptr->CreateSymlink(dst_file.GetPath().c_str(), buf); |
| 505 | |
| 506 | if (rc_baton->error.Fail()) |
| 507 | return FileSpec::eEnumerateDirectoryResultQuit; // got an error, bail out |
| 508 | |
| 509 | return FileSpec::eEnumerateDirectoryResultNext; |
| 510 | } |
| 511 | break; |
| 512 | case FileSpec::eFileTypeRegular: |
| 513 | { |
| 514 | // copy the file and keep going |
| 515 | FileSpec dst_file = rc_baton->dst; |
| 516 | if (!dst_file.GetFilename()) |
| 517 | dst_file.GetFilename() = src.GetFilename(); |
| 518 | Error err = rc_baton->platform_ptr->PutFile(src, dst_file); |
| 519 | if (err.Fail()) |
| 520 | { |
| 521 | rc_baton->error.SetErrorString(err.AsCString()); |
| 522 | return FileSpec::eEnumerateDirectoryResultQuit; // got an error, bail out |
| 523 | } |
| 524 | return FileSpec::eEnumerateDirectoryResultNext; |
| 525 | } |
| 526 | break; |
| 527 | |
| 528 | case FileSpec::eFileTypeInvalid: |
| 529 | case FileSpec::eFileTypeOther: |
| 530 | case FileSpec::eFileTypeUnknown: |
Todd Fiala | af245d1 | 2014-06-30 21:05:18 +0000 | [diff] [blame] | 531 | default: |
Greg Clayton | fbb7634 | 2013-11-20 21:07:01 +0000 | [diff] [blame] | 532 | rc_baton->error.SetErrorStringWithFormat("invalid file detected during copy: %s", src.GetPath().c_str()); |
| 533 | return FileSpec::eEnumerateDirectoryResultQuit; // got an error, bail out |
| 534 | break; |
| 535 | } |
| 536 | } |
| 537 | |
| 538 | Error |
| 539 | Platform::Install (const FileSpec& src, const FileSpec& dst) |
| 540 | { |
| 541 | Error error; |
| 542 | |
| 543 | Log *log = GetLogIfAnyCategoriesSet(LIBLLDB_LOG_PLATFORM); |
| 544 | if (log) |
| 545 | log->Printf ("Platform::Install (src='%s', dst='%s')", src.GetPath().c_str(), dst.GetPath().c_str()); |
| 546 | FileSpec fixed_dst(dst); |
| 547 | |
| 548 | if (!fixed_dst.GetFilename()) |
| 549 | fixed_dst.GetFilename() = src.GetFilename(); |
| 550 | |
| 551 | ConstString working_dir = GetWorkingDirectory(); |
| 552 | |
| 553 | if (dst) |
| 554 | { |
| 555 | if (dst.GetDirectory()) |
| 556 | { |
| 557 | const char first_dst_dir_char = dst.GetDirectory().GetCString()[0]; |
| 558 | if (first_dst_dir_char == '/' || first_dst_dir_char == '\\') |
| 559 | { |
| 560 | fixed_dst.GetDirectory() = dst.GetDirectory(); |
| 561 | } |
| 562 | // If the fixed destination file doesn't have a directory yet, |
| 563 | // then we must have a relative path. We will resolve this relative |
| 564 | // path against the platform's working directory |
| 565 | if (!fixed_dst.GetDirectory()) |
| 566 | { |
| 567 | FileSpec relative_spec; |
| 568 | std::string path; |
| 569 | if (working_dir) |
| 570 | { |
| 571 | relative_spec.SetFile(working_dir.GetCString(), false); |
| 572 | relative_spec.AppendPathComponent(dst.GetPath().c_str()); |
| 573 | fixed_dst.GetDirectory() = relative_spec.GetDirectory(); |
| 574 | } |
| 575 | else |
| 576 | { |
| 577 | error.SetErrorStringWithFormat("platform working directory must be valid for relative path '%s'", dst.GetPath().c_str()); |
| 578 | return error; |
| 579 | } |
| 580 | } |
| 581 | } |
| 582 | else |
| 583 | { |
| 584 | if (working_dir) |
| 585 | { |
| 586 | fixed_dst.GetDirectory() = working_dir; |
| 587 | } |
| 588 | else |
| 589 | { |
| 590 | error.SetErrorStringWithFormat("platform working directory must be valid for relative path '%s'", dst.GetPath().c_str()); |
| 591 | return error; |
| 592 | } |
| 593 | } |
| 594 | } |
| 595 | else |
| 596 | { |
| 597 | if (working_dir) |
| 598 | { |
| 599 | fixed_dst.GetDirectory() = working_dir; |
| 600 | } |
| 601 | else |
| 602 | { |
| 603 | error.SetErrorStringWithFormat("platform working directory must be valid when destination directory is empty"); |
| 604 | return error; |
| 605 | } |
| 606 | } |
| 607 | |
| 608 | if (log) |
| 609 | log->Printf ("Platform::Install (src='%s', dst='%s') fixed_dst='%s'", src.GetPath().c_str(), dst.GetPath().c_str(), fixed_dst.GetPath().c_str()); |
| 610 | |
| 611 | if (GetSupportsRSync()) |
| 612 | { |
| 613 | error = PutFile(src, dst); |
| 614 | } |
| 615 | else |
| 616 | { |
| 617 | switch (src.GetFileType()) |
| 618 | { |
| 619 | case FileSpec::eFileTypeDirectory: |
| 620 | { |
| 621 | if (GetFileExists (fixed_dst)) |
| 622 | Unlink (fixed_dst.GetPath().c_str()); |
| 623 | uint32_t permissions = src.GetPermissions(); |
| 624 | if (permissions == 0) |
| 625 | permissions = eFilePermissionsDirectoryDefault; |
| 626 | std::string dst_dir_path(fixed_dst.GetPath()); |
| 627 | error = MakeDirectory(dst_dir_path.c_str(), permissions); |
| 628 | if (error.Success()) |
| 629 | { |
| 630 | // Make a filespec that only fills in the directory of a FileSpec so |
| 631 | // when we enumerate we can quickly fill in the filename for dst copies |
| 632 | FileSpec recurse_dst; |
| 633 | recurse_dst.GetDirectory().SetCString(dst_dir_path.c_str()); |
| 634 | std::string src_dir_path (src.GetPath()); |
| 635 | RecurseCopyBaton baton = { recurse_dst, this, Error() }; |
| 636 | FileSpec::EnumerateDirectory(src_dir_path.c_str(), true, true, true, RecurseCopy_Callback, &baton); |
| 637 | return baton.error; |
| 638 | } |
| 639 | } |
| 640 | break; |
| 641 | |
| 642 | case FileSpec::eFileTypeRegular: |
| 643 | if (GetFileExists (fixed_dst)) |
| 644 | Unlink (fixed_dst.GetPath().c_str()); |
| 645 | error = PutFile(src, fixed_dst); |
| 646 | break; |
| 647 | |
| 648 | case FileSpec::eFileTypeSymbolicLink: |
| 649 | { |
| 650 | if (GetFileExists (fixed_dst)) |
| 651 | Unlink (fixed_dst.GetPath().c_str()); |
| 652 | char buf[PATH_MAX]; |
Zachary Turner | c00cf4a | 2014-08-15 22:04:21 +0000 | [diff] [blame] | 653 | error = FileSystem::Readlink(src.GetPath().c_str(), buf, sizeof(buf)); |
Greg Clayton | fbb7634 | 2013-11-20 21:07:01 +0000 | [diff] [blame] | 654 | if (error.Success()) |
| 655 | error = CreateSymlink(dst.GetPath().c_str(), buf); |
| 656 | } |
| 657 | break; |
| 658 | case FileSpec::eFileTypePipe: |
| 659 | error.SetErrorString("platform install doesn't handle pipes"); |
| 660 | break; |
| 661 | case FileSpec::eFileTypeSocket: |
| 662 | error.SetErrorString("platform install doesn't handle sockets"); |
| 663 | break; |
| 664 | case FileSpec::eFileTypeInvalid: |
| 665 | case FileSpec::eFileTypeUnknown: |
| 666 | case FileSpec::eFileTypeOther: |
| 667 | error.SetErrorString("platform install doesn't handle non file or directory items"); |
| 668 | break; |
| 669 | } |
| 670 | } |
| 671 | return error; |
| 672 | } |
| 673 | |
| 674 | bool |
| 675 | Platform::SetWorkingDirectory (const ConstString &path) |
| 676 | { |
| 677 | if (IsHost()) |
| 678 | { |
Greg Clayton | 5fb8f79 | 2013-12-02 19:35:49 +0000 | [diff] [blame] | 679 | Log *log = GetLogIfAnyCategoriesSet(LIBLLDB_LOG_PLATFORM); |
| 680 | if (log) |
| 681 | log->Printf("Platform::SetWorkingDirectory('%s')", path.GetCString()); |
Colin Riley | 909bb7a | 2013-11-26 15:10:46 +0000 | [diff] [blame] | 682 | #ifdef _WIN32 |
| 683 | // Not implemented on Windows |
| 684 | return false; |
| 685 | #else |
Greg Clayton | fbb7634 | 2013-11-20 21:07:01 +0000 | [diff] [blame] | 686 | if (path) |
| 687 | { |
| 688 | if (chdir(path.GetCString()) == 0) |
| 689 | return true; |
| 690 | } |
| 691 | return false; |
Colin Riley | 909bb7a | 2013-11-26 15:10:46 +0000 | [diff] [blame] | 692 | #endif |
Greg Clayton | fbb7634 | 2013-11-20 21:07:01 +0000 | [diff] [blame] | 693 | } |
| 694 | else |
| 695 | { |
Greg Clayton | 5fb8f79 | 2013-12-02 19:35:49 +0000 | [diff] [blame] | 696 | m_working_dir.Clear(); |
Greg Clayton | fbb7634 | 2013-11-20 21:07:01 +0000 | [diff] [blame] | 697 | return SetRemoteWorkingDirectory(path); |
| 698 | } |
| 699 | } |
| 700 | |
| 701 | Error |
| 702 | Platform::MakeDirectory (const char *path, uint32_t permissions) |
| 703 | { |
| 704 | if (IsHost()) |
Zachary Turner | c00cf4a | 2014-08-15 22:04:21 +0000 | [diff] [blame] | 705 | return FileSystem::MakeDirectory(path, permissions); |
Greg Clayton | fbb7634 | 2013-11-20 21:07:01 +0000 | [diff] [blame] | 706 | else |
| 707 | { |
| 708 | Error error; |
| 709 | error.SetErrorStringWithFormat("remote platform %s doesn't support %s", GetPluginName().GetCString(), __PRETTY_FUNCTION__); |
| 710 | return error; |
| 711 | } |
| 712 | } |
| 713 | |
| 714 | Error |
| 715 | Platform::GetFilePermissions (const char *path, uint32_t &file_permissions) |
| 716 | { |
| 717 | if (IsHost()) |
Zachary Turner | c00cf4a | 2014-08-15 22:04:21 +0000 | [diff] [blame] | 718 | return FileSystem::GetFilePermissions(path, file_permissions); |
Greg Clayton | fbb7634 | 2013-11-20 21:07:01 +0000 | [diff] [blame] | 719 | else |
| 720 | { |
| 721 | Error error; |
| 722 | error.SetErrorStringWithFormat("remote platform %s doesn't support %s", GetPluginName().GetCString(), __PRETTY_FUNCTION__); |
| 723 | return error; |
| 724 | } |
| 725 | } |
| 726 | |
| 727 | Error |
| 728 | Platform::SetFilePermissions (const char *path, uint32_t file_permissions) |
| 729 | { |
| 730 | if (IsHost()) |
Zachary Turner | c00cf4a | 2014-08-15 22:04:21 +0000 | [diff] [blame] | 731 | return FileSystem::SetFilePermissions(path, file_permissions); |
Greg Clayton | fbb7634 | 2013-11-20 21:07:01 +0000 | [diff] [blame] | 732 | else |
| 733 | { |
| 734 | Error error; |
| 735 | error.SetErrorStringWithFormat("remote platform %s doesn't support %s", GetPluginName().GetCString(), __PRETTY_FUNCTION__); |
| 736 | return error; |
| 737 | } |
| 738 | } |
| 739 | |
| 740 | ConstString |
Greg Clayton | 8b82f08 | 2011-04-12 05:54:46 +0000 | [diff] [blame] | 741 | Platform::GetName () |
| 742 | { |
Greg Clayton | fbb7634 | 2013-11-20 21:07:01 +0000 | [diff] [blame] | 743 | return GetPluginName(); |
Greg Clayton | 8b82f08 | 2011-04-12 05:54:46 +0000 | [diff] [blame] | 744 | } |
| 745 | |
| 746 | const char * |
Greg Clayton | 1cb6496 | 2011-03-24 04:28:38 +0000 | [diff] [blame] | 747 | Platform::GetHostname () |
| 748 | { |
Greg Clayton | ab65b34 | 2011-04-13 22:47:15 +0000 | [diff] [blame] | 749 | if (IsHost()) |
Greg Clayton | 1681092 | 2014-02-27 19:38:18 +0000 | [diff] [blame] | 750 | return "127.0.0.1"; |
Greg Clayton | 32e0a75 | 2011-03-30 18:16:51 +0000 | [diff] [blame] | 751 | |
| 752 | if (m_name.empty()) |
| 753 | return NULL; |
| 754 | return m_name.c_str(); |
| 755 | } |
| 756 | |
Greg Clayton | 5fb8f79 | 2013-12-02 19:35:49 +0000 | [diff] [blame] | 757 | bool |
| 758 | Platform::SetRemoteWorkingDirectory(const ConstString &path) |
| 759 | { |
| 760 | Log *log = GetLogIfAnyCategoriesSet(LIBLLDB_LOG_PLATFORM); |
| 761 | if (log) |
| 762 | log->Printf("Platform::SetRemoteWorkingDirectory('%s')", path.GetCString()); |
| 763 | m_working_dir = path; |
| 764 | return true; |
| 765 | } |
| 766 | |
Greg Clayton | 32e0a75 | 2011-03-30 18:16:51 +0000 | [diff] [blame] | 767 | const char * |
| 768 | Platform::GetUserName (uint32_t uid) |
| 769 | { |
| 770 | const char *user_name = GetCachedUserName(uid); |
| 771 | if (user_name) |
| 772 | return user_name; |
| 773 | if (IsHost()) |
| 774 | { |
| 775 | std::string name; |
| 776 | if (Host::GetUserName(uid, name)) |
| 777 | return SetCachedUserName (uid, name.c_str(), name.size()); |
| 778 | } |
Greg Clayton | 1cb6496 | 2011-03-24 04:28:38 +0000 | [diff] [blame] | 779 | return NULL; |
| 780 | } |
| 781 | |
Greg Clayton | 32e0a75 | 2011-03-30 18:16:51 +0000 | [diff] [blame] | 782 | const char * |
| 783 | Platform::GetGroupName (uint32_t gid) |
| 784 | { |
| 785 | const char *group_name = GetCachedGroupName(gid); |
| 786 | if (group_name) |
| 787 | return group_name; |
| 788 | if (IsHost()) |
| 789 | { |
| 790 | std::string name; |
| 791 | if (Host::GetGroupName(gid, name)) |
| 792 | return SetCachedGroupName (gid, name.c_str(), name.size()); |
| 793 | } |
| 794 | return NULL; |
| 795 | } |
Greg Clayton | 1cb6496 | 2011-03-24 04:28:38 +0000 | [diff] [blame] | 796 | |
Greg Clayton | ded470d | 2011-03-19 01:12:21 +0000 | [diff] [blame] | 797 | bool |
| 798 | Platform::SetOSVersion (uint32_t major, |
| 799 | uint32_t minor, |
| 800 | uint32_t update) |
| 801 | { |
| 802 | if (IsHost()) |
| 803 | { |
| 804 | // We don't need anyone setting the OS version for the host platform, |
| 805 | // we should be able to figure it out by calling Host::GetOSVersion(...). |
| 806 | return false; |
| 807 | } |
| 808 | else |
| 809 | { |
| 810 | // We have a remote platform, allow setting the target OS version if |
| 811 | // we aren't connected, since if we are connected, we should be able to |
| 812 | // request the remote OS version from the connected platform. |
| 813 | if (IsConnected()) |
| 814 | return false; |
| 815 | else |
| 816 | { |
| 817 | // We aren't connected and we might want to set the OS version |
| 818 | // ahead of time before we connect so we can peruse files and |
| 819 | // use a local SDK or PDK cache of support files to disassemble |
| 820 | // or do other things. |
| 821 | m_major_os_version = major; |
| 822 | m_minor_os_version = minor; |
| 823 | m_update_os_version = update; |
| 824 | return true; |
| 825 | } |
| 826 | } |
| 827 | return false; |
| 828 | } |
| 829 | |
| 830 | |
Greg Clayton | e996fd3 | 2011-03-08 22:40:15 +0000 | [diff] [blame] | 831 | Error |
| 832 | Platform::ResolveExecutable (const FileSpec &exe_file, |
| 833 | const ArchSpec &exe_arch, |
Greg Clayton | c859e2d | 2012-02-13 23:10:39 +0000 | [diff] [blame] | 834 | lldb::ModuleSP &exe_module_sp, |
| 835 | const FileSpecList *module_search_paths_ptr) |
Greg Clayton | e996fd3 | 2011-03-08 22:40:15 +0000 | [diff] [blame] | 836 | { |
| 837 | Error error; |
| 838 | if (exe_file.Exists()) |
| 839 | { |
Greg Clayton | b9a01b3 | 2012-02-26 05:51:37 +0000 | [diff] [blame] | 840 | ModuleSpec module_spec (exe_file, exe_arch); |
| 841 | if (module_spec.GetArchitecture().IsValid()) |
Greg Clayton | e996fd3 | 2011-03-08 22:40:15 +0000 | [diff] [blame] | 842 | { |
Greg Clayton | b9a01b3 | 2012-02-26 05:51:37 +0000 | [diff] [blame] | 843 | error = ModuleList::GetSharedModule (module_spec, |
Greg Clayton | e996fd3 | 2011-03-08 22:40:15 +0000 | [diff] [blame] | 844 | exe_module_sp, |
Greg Clayton | c859e2d | 2012-02-13 23:10:39 +0000 | [diff] [blame] | 845 | module_search_paths_ptr, |
Greg Clayton | e996fd3 | 2011-03-08 22:40:15 +0000 | [diff] [blame] | 846 | NULL, |
| 847 | NULL); |
| 848 | } |
| 849 | else |
| 850 | { |
| 851 | // No valid architecture was specified, ask the platform for |
| 852 | // the architectures that we should be using (in the correct order) |
| 853 | // and see if we can find a match that way |
Greg Clayton | b9a01b3 | 2012-02-26 05:51:37 +0000 | [diff] [blame] | 854 | for (uint32_t idx = 0; GetSupportedArchitectureAtIndex (idx, module_spec.GetArchitecture()); ++idx) |
Greg Clayton | e996fd3 | 2011-03-08 22:40:15 +0000 | [diff] [blame] | 855 | { |
Greg Clayton | b9a01b3 | 2012-02-26 05:51:37 +0000 | [diff] [blame] | 856 | error = ModuleList::GetSharedModule (module_spec, |
Greg Clayton | e996fd3 | 2011-03-08 22:40:15 +0000 | [diff] [blame] | 857 | exe_module_sp, |
Greg Clayton | c859e2d | 2012-02-13 23:10:39 +0000 | [diff] [blame] | 858 | module_search_paths_ptr, |
Greg Clayton | e996fd3 | 2011-03-08 22:40:15 +0000 | [diff] [blame] | 859 | NULL, |
| 860 | NULL); |
| 861 | // Did we find an executable using one of the |
| 862 | if (error.Success() && exe_module_sp) |
| 863 | break; |
| 864 | } |
| 865 | } |
| 866 | } |
| 867 | else |
| 868 | { |
Greg Clayton | b5ad4ec | 2013-04-29 17:25:54 +0000 | [diff] [blame] | 869 | error.SetErrorStringWithFormat ("'%s' does not exist", |
| 870 | exe_file.GetPath().c_str()); |
Greg Clayton | e996fd3 | 2011-03-08 22:40:15 +0000 | [diff] [blame] | 871 | } |
| 872 | return error; |
| 873 | } |
| 874 | |
Greg Clayton | 103f028 | 2012-09-12 02:03:59 +0000 | [diff] [blame] | 875 | Error |
| 876 | Platform::ResolveSymbolFile (Target &target, |
| 877 | const ModuleSpec &sym_spec, |
| 878 | FileSpec &sym_file) |
| 879 | { |
| 880 | Error error; |
| 881 | if (sym_spec.GetSymbolFileSpec().Exists()) |
| 882 | sym_file = sym_spec.GetSymbolFileSpec(); |
| 883 | else |
| 884 | error.SetErrorString("unable to resolve symbol file"); |
| 885 | return error; |
| 886 | |
| 887 | } |
| 888 | |
| 889 | |
| 890 | |
Greg Clayton | aa51684 | 2011-08-11 16:25:18 +0000 | [diff] [blame] | 891 | bool |
| 892 | Platform::ResolveRemotePath (const FileSpec &platform_path, |
| 893 | FileSpec &resolved_platform_path) |
| 894 | { |
| 895 | resolved_platform_path = platform_path; |
| 896 | return resolved_platform_path.ResolvePath(); |
| 897 | } |
| 898 | |
Greg Clayton | ded470d | 2011-03-19 01:12:21 +0000 | [diff] [blame] | 899 | |
| 900 | const ArchSpec & |
| 901 | Platform::GetSystemArchitecture() |
| 902 | { |
| 903 | if (IsHost()) |
| 904 | { |
| 905 | if (!m_system_arch.IsValid()) |
| 906 | { |
| 907 | // We have a local host platform |
| 908 | m_system_arch = Host::GetArchitecture(); |
| 909 | m_system_arch_set_while_connected = m_system_arch.IsValid(); |
| 910 | } |
| 911 | } |
| 912 | else |
| 913 | { |
| 914 | // We have a remote platform. We can only fetch the remote |
| 915 | // system architecture if we are connected, and we don't want to do it |
| 916 | // more than once. |
| 917 | |
| 918 | const bool is_connected = IsConnected(); |
| 919 | |
| 920 | bool fetch = false; |
| 921 | if (m_system_arch.IsValid()) |
| 922 | { |
| 923 | // We have valid OS version info, check to make sure it wasn't |
| 924 | // manually set prior to connecting. If it was manually set prior |
| 925 | // to connecting, then lets fetch the actual OS version info |
| 926 | // if we are now connected. |
| 927 | if (is_connected && !m_system_arch_set_while_connected) |
| 928 | fetch = true; |
| 929 | } |
| 930 | else |
| 931 | { |
| 932 | // We don't have valid OS version info, fetch it if we are connected |
| 933 | fetch = is_connected; |
| 934 | } |
| 935 | |
| 936 | if (fetch) |
| 937 | { |
Greg Clayton | 1cb6496 | 2011-03-24 04:28:38 +0000 | [diff] [blame] | 938 | m_system_arch = GetRemoteSystemArchitecture (); |
Greg Clayton | ded470d | 2011-03-19 01:12:21 +0000 | [diff] [blame] | 939 | m_system_arch_set_while_connected = m_system_arch.IsValid(); |
| 940 | } |
| 941 | } |
| 942 | return m_system_arch; |
| 943 | } |
| 944 | |
| 945 | |
Greg Clayton | e996fd3 | 2011-03-08 22:40:15 +0000 | [diff] [blame] | 946 | Error |
Greg Clayton | d314e81 | 2011-03-23 00:09:55 +0000 | [diff] [blame] | 947 | Platform::ConnectRemote (Args& args) |
Greg Clayton | e996fd3 | 2011-03-08 22:40:15 +0000 | [diff] [blame] | 948 | { |
| 949 | Error error; |
Greg Clayton | d314e81 | 2011-03-23 00:09:55 +0000 | [diff] [blame] | 950 | if (IsHost()) |
Greg Clayton | 57abc5d | 2013-05-10 21:47:16 +0000 | [diff] [blame] | 951 | 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] | 952 | else |
Greg Clayton | 57abc5d | 2013-05-10 21:47:16 +0000 | [diff] [blame] | 953 | error.SetErrorStringWithFormat ("Platform::ConnectRemote() is not supported by %s", GetPluginName().GetCString()); |
Greg Clayton | e996fd3 | 2011-03-08 22:40:15 +0000 | [diff] [blame] | 954 | return error; |
| 955 | } |
| 956 | |
| 957 | Error |
Greg Clayton | d314e81 | 2011-03-23 00:09:55 +0000 | [diff] [blame] | 958 | Platform::DisconnectRemote () |
Greg Clayton | e996fd3 | 2011-03-08 22:40:15 +0000 | [diff] [blame] | 959 | { |
| 960 | Error error; |
Greg Clayton | d314e81 | 2011-03-23 00:09:55 +0000 | [diff] [blame] | 961 | if (IsHost()) |
Greg Clayton | 57abc5d | 2013-05-10 21:47:16 +0000 | [diff] [blame] | 962 | 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] | 963 | else |
Greg Clayton | 57abc5d | 2013-05-10 21:47:16 +0000 | [diff] [blame] | 964 | error.SetErrorStringWithFormat ("Platform::DisconnectRemote() is not supported by %s", GetPluginName().GetCString()); |
Greg Clayton | e996fd3 | 2011-03-08 22:40:15 +0000 | [diff] [blame] | 965 | return error; |
| 966 | } |
Greg Clayton | 32e0a75 | 2011-03-30 18:16:51 +0000 | [diff] [blame] | 967 | |
| 968 | bool |
Greg Clayton | 8b82f08 | 2011-04-12 05:54:46 +0000 | [diff] [blame] | 969 | Platform::GetProcessInfo (lldb::pid_t pid, ProcessInstanceInfo &process_info) |
Greg Clayton | 32e0a75 | 2011-03-30 18:16:51 +0000 | [diff] [blame] | 970 | { |
| 971 | // Take care of the host case so that each subclass can just |
Greg Clayton | 8b82f08 | 2011-04-12 05:54:46 +0000 | [diff] [blame] | 972 | // call this function to get the host functionality. |
Greg Clayton | 32e0a75 | 2011-03-30 18:16:51 +0000 | [diff] [blame] | 973 | if (IsHost()) |
| 974 | return Host::GetProcessInfo (pid, process_info); |
| 975 | return false; |
| 976 | } |
| 977 | |
| 978 | uint32_t |
Greg Clayton | 8b82f08 | 2011-04-12 05:54:46 +0000 | [diff] [blame] | 979 | Platform::FindProcesses (const ProcessInstanceInfoMatch &match_info, |
| 980 | ProcessInstanceInfoList &process_infos) |
Greg Clayton | 32e0a75 | 2011-03-30 18:16:51 +0000 | [diff] [blame] | 981 | { |
Greg Clayton | 8b82f08 | 2011-04-12 05:54:46 +0000 | [diff] [blame] | 982 | // Take care of the host case so that each subclass can just |
| 983 | // call this function to get the host functionality. |
Greg Clayton | 32e0a75 | 2011-03-30 18:16:51 +0000 | [diff] [blame] | 984 | uint32_t match_count = 0; |
| 985 | if (IsHost()) |
| 986 | match_count = Host::FindProcesses (match_info, process_infos); |
| 987 | return match_count; |
| 988 | } |
Greg Clayton | 8b82f08 | 2011-04-12 05:54:46 +0000 | [diff] [blame] | 989 | |
| 990 | |
| 991 | Error |
| 992 | Platform::LaunchProcess (ProcessLaunchInfo &launch_info) |
| 993 | { |
| 994 | Error error; |
| 995 | // Take care of the host case so that each subclass can just |
| 996 | // call this function to get the host functionality. |
| 997 | if (IsHost()) |
Greg Clayton | 84db910 | 2012-03-26 23:03:23 +0000 | [diff] [blame] | 998 | { |
| 999 | if (::getenv ("LLDB_LAUNCH_FLAG_LAUNCH_IN_TTY")) |
| 1000 | launch_info.GetFlags().Set (eLaunchFlagLaunchInTTY); |
| 1001 | |
| 1002 | if (launch_info.GetFlags().Test (eLaunchFlagLaunchInShell)) |
| 1003 | { |
| 1004 | const bool is_localhost = true; |
Greg Clayton | d1cf11a | 2012-04-14 01:42:46 +0000 | [diff] [blame] | 1005 | const bool will_debug = launch_info.GetFlags().Test(eLaunchFlagDebug); |
| 1006 | const bool first_arg_is_full_shell_command = false; |
Jim Ingham | d399079 | 2013-09-11 18:23:22 +0000 | [diff] [blame] | 1007 | uint32_t num_resumes = GetResumeCountForLaunchInfo (launch_info); |
Greg Clayton | d1cf11a | 2012-04-14 01:42:46 +0000 | [diff] [blame] | 1008 | if (!launch_info.ConvertArgumentsForLaunchingInShell (error, |
| 1009 | is_localhost, |
| 1010 | will_debug, |
Jim Ingham | df0ae22 | 2013-09-10 02:09:47 +0000 | [diff] [blame] | 1011 | first_arg_is_full_shell_command, |
| 1012 | num_resumes)) |
Greg Clayton | 84db910 | 2012-03-26 23:03:23 +0000 | [diff] [blame] | 1013 | return error; |
| 1014 | } |
| 1015 | |
Greg Clayton | 8b82f08 | 2011-04-12 05:54:46 +0000 | [diff] [blame] | 1016 | error = Host::LaunchProcess (launch_info); |
Greg Clayton | 84db910 | 2012-03-26 23:03:23 +0000 | [diff] [blame] | 1017 | } |
Greg Clayton | 8b82f08 | 2011-04-12 05:54:46 +0000 | [diff] [blame] | 1018 | else |
| 1019 | error.SetErrorString ("base lldb_private::Platform class can't launch remote processes"); |
| 1020 | return error; |
| 1021 | } |
| 1022 | |
| 1023 | lldb::ProcessSP |
| 1024 | Platform::DebugProcess (ProcessLaunchInfo &launch_info, |
| 1025 | Debugger &debugger, |
| 1026 | Target *target, // Can be NULL, if NULL create a new target, else use existing one |
| 1027 | Listener &listener, |
| 1028 | Error &error) |
| 1029 | { |
| 1030 | ProcessSP process_sp; |
| 1031 | // Make sure we stop at the entry point |
| 1032 | launch_info.GetFlags ().Set (eLaunchFlagDebug); |
Jim Ingham | b4451b1 | 2012-06-01 01:22:13 +0000 | [diff] [blame] | 1033 | // We always launch the process we are going to debug in a separate process |
| 1034 | // group, since then we can handle ^C interrupts ourselves w/o having to worry |
| 1035 | // about the target getting them as well. |
| 1036 | launch_info.SetLaunchInSeparateProcessGroup(true); |
| 1037 | |
Greg Clayton | 8b82f08 | 2011-04-12 05:54:46 +0000 | [diff] [blame] | 1038 | error = LaunchProcess (launch_info); |
| 1039 | if (error.Success()) |
| 1040 | { |
Greg Clayton | 144f3a9 | 2011-11-15 03:53:30 +0000 | [diff] [blame] | 1041 | if (launch_info.GetProcessID() != LLDB_INVALID_PROCESS_ID) |
Greg Clayton | 8b82f08 | 2011-04-12 05:54:46 +0000 | [diff] [blame] | 1042 | { |
Greg Clayton | 144f3a9 | 2011-11-15 03:53:30 +0000 | [diff] [blame] | 1043 | ProcessAttachInfo attach_info (launch_info); |
| 1044 | process_sp = Attach (attach_info, debugger, target, listener, error); |
Greg Clayton | e24c4ac | 2011-11-17 04:46:02 +0000 | [diff] [blame] | 1045 | if (process_sp) |
| 1046 | { |
Greg Clayton | 44d9378 | 2014-01-27 23:43:24 +0000 | [diff] [blame] | 1047 | launch_info.SetHijackListener(attach_info.GetHijackListener()); |
| 1048 | |
Greg Clayton | e24c4ac | 2011-11-17 04:46:02 +0000 | [diff] [blame] | 1049 | // Since we attached to the process, it will think it needs to detach |
| 1050 | // if the process object just goes away without an explicit call to |
| 1051 | // Process::Kill() or Process::Detach(), so let it know to kill the |
| 1052 | // process if this happens. |
| 1053 | process_sp->SetShouldDetach (false); |
Greg Clayton | ee95ed5 | 2011-11-17 22:14:31 +0000 | [diff] [blame] | 1054 | |
| 1055 | // If we didn't have any file actions, the pseudo terminal might |
| 1056 | // have been used where the slave side was given as the file to |
| 1057 | // open for stdin/out/err after we have already opened the master |
| 1058 | // so we can read/write stdin/out/err. |
| 1059 | int pty_fd = launch_info.GetPTY().ReleaseMasterFileDescriptor(); |
| 1060 | if (pty_fd != lldb_utility::PseudoTerminal::invalid_fd) |
| 1061 | { |
| 1062 | process_sp->SetSTDIOFileDescriptor(pty_fd); |
| 1063 | } |
Greg Clayton | e24c4ac | 2011-11-17 04:46:02 +0000 | [diff] [blame] | 1064 | } |
Greg Clayton | 8b82f08 | 2011-04-12 05:54:46 +0000 | [diff] [blame] | 1065 | } |
| 1066 | } |
| 1067 | return process_sp; |
| 1068 | } |
Greg Clayton | b3a40ba | 2012-03-20 18:34:04 +0000 | [diff] [blame] | 1069 | |
| 1070 | |
| 1071 | lldb::PlatformSP |
Greg Clayton | 7051231 | 2012-05-08 01:45:38 +0000 | [diff] [blame] | 1072 | Platform::GetPlatformForArchitecture (const ArchSpec &arch, ArchSpec *platform_arch_ptr) |
Greg Clayton | b3a40ba | 2012-03-20 18:34:04 +0000 | [diff] [blame] | 1073 | { |
| 1074 | lldb::PlatformSP platform_sp; |
| 1075 | Error error; |
| 1076 | if (arch.IsValid()) |
Greg Clayton | 7051231 | 2012-05-08 01:45:38 +0000 | [diff] [blame] | 1077 | platform_sp = Platform::Create (arch, platform_arch_ptr, error); |
Greg Clayton | b3a40ba | 2012-03-20 18:34:04 +0000 | [diff] [blame] | 1078 | return platform_sp; |
| 1079 | } |
| 1080 | |
| 1081 | |
| 1082 | //------------------------------------------------------------------ |
| 1083 | /// Lets a platform answer if it is compatible with a given |
| 1084 | /// architecture and the target triple contained within. |
| 1085 | //------------------------------------------------------------------ |
| 1086 | bool |
Greg Clayton | 1e0c884 | 2013-01-11 20:49:54 +0000 | [diff] [blame] | 1087 | 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] | 1088 | { |
| 1089 | // If the architecture is invalid, we must answer true... |
Greg Clayton | 7051231 | 2012-05-08 01:45:38 +0000 | [diff] [blame] | 1090 | if (arch.IsValid()) |
Greg Clayton | b3a40ba | 2012-03-20 18:34:04 +0000 | [diff] [blame] | 1091 | { |
Greg Clayton | 7051231 | 2012-05-08 01:45:38 +0000 | [diff] [blame] | 1092 | ArchSpec platform_arch; |
Greg Clayton | 1e0c884 | 2013-01-11 20:49:54 +0000 | [diff] [blame] | 1093 | // Try for an exact architecture match first. |
| 1094 | if (exact_arch_match) |
Greg Clayton | 7051231 | 2012-05-08 01:45:38 +0000 | [diff] [blame] | 1095 | { |
Greg Clayton | 1e0c884 | 2013-01-11 20:49:54 +0000 | [diff] [blame] | 1096 | 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] | 1097 | { |
Greg Clayton | 1e0c884 | 2013-01-11 20:49:54 +0000 | [diff] [blame] | 1098 | if (arch.IsExactMatch(platform_arch)) |
| 1099 | { |
| 1100 | if (compatible_arch_ptr) |
| 1101 | *compatible_arch_ptr = platform_arch; |
| 1102 | return true; |
| 1103 | } |
| 1104 | } |
| 1105 | } |
| 1106 | else |
| 1107 | { |
| 1108 | for (uint32_t arch_idx=0; GetSupportedArchitectureAtIndex (arch_idx, platform_arch); ++arch_idx) |
| 1109 | { |
| 1110 | if (arch.IsCompatibleMatch(platform_arch)) |
| 1111 | { |
| 1112 | if (compatible_arch_ptr) |
| 1113 | *compatible_arch_ptr = platform_arch; |
| 1114 | return true; |
| 1115 | } |
Greg Clayton | 7051231 | 2012-05-08 01:45:38 +0000 | [diff] [blame] | 1116 | } |
| 1117 | } |
Greg Clayton | b3a40ba | 2012-03-20 18:34:04 +0000 | [diff] [blame] | 1118 | } |
Greg Clayton | 7051231 | 2012-05-08 01:45:38 +0000 | [diff] [blame] | 1119 | if (compatible_arch_ptr) |
| 1120 | compatible_arch_ptr->Clear(); |
Greg Clayton | b3a40ba | 2012-03-20 18:34:04 +0000 | [diff] [blame] | 1121 | return false; |
Greg Clayton | b3a40ba | 2012-03-20 18:34:04 +0000 | [diff] [blame] | 1122 | } |
| 1123 | |
Daniel Malea | e0f8f57 | 2013-08-26 23:57:52 +0000 | [diff] [blame] | 1124 | Error |
| 1125 | Platform::PutFile (const FileSpec& source, |
| 1126 | const FileSpec& destination, |
| 1127 | uint32_t uid, |
| 1128 | uint32_t gid) |
| 1129 | { |
| 1130 | Error error("unimplemented"); |
| 1131 | return error; |
| 1132 | } |
| 1133 | |
| 1134 | Error |
| 1135 | Platform::GetFile (const FileSpec& source, |
| 1136 | const FileSpec& destination) |
| 1137 | { |
| 1138 | Error error("unimplemented"); |
| 1139 | return error; |
| 1140 | } |
| 1141 | |
Greg Clayton | fbb7634 | 2013-11-20 21:07:01 +0000 | [diff] [blame] | 1142 | Error |
| 1143 | Platform::CreateSymlink (const char *src, // The name of the link is in src |
| 1144 | const char *dst)// The symlink points to dst |
| 1145 | { |
| 1146 | Error error("unimplemented"); |
| 1147 | return error; |
| 1148 | } |
| 1149 | |
Daniel Malea | e0f8f57 | 2013-08-26 23:57:52 +0000 | [diff] [blame] | 1150 | bool |
| 1151 | Platform::GetFileExists (const lldb_private::FileSpec& file_spec) |
| 1152 | { |
| 1153 | return false; |
| 1154 | } |
| 1155 | |
Greg Clayton | fbb7634 | 2013-11-20 21:07:01 +0000 | [diff] [blame] | 1156 | Error |
| 1157 | Platform::Unlink (const char *path) |
| 1158 | { |
| 1159 | Error error("unimplemented"); |
| 1160 | return error; |
| 1161 | } |
| 1162 | |
| 1163 | |
| 1164 | |
Daniel Malea | e0f8f57 | 2013-08-26 23:57:52 +0000 | [diff] [blame] | 1165 | lldb_private::Error |
| 1166 | Platform::RunShellCommand (const char *command, // Shouldn't be NULL |
| 1167 | const char *working_dir, // Pass NULL to use the current working directory |
| 1168 | int *status_ptr, // Pass NULL if you don't want the process exit status |
| 1169 | int *signo_ptr, // Pass NULL if you don't want the signal that caused the process to exit |
| 1170 | std::string *command_output, // Pass NULL if you don't want the command output |
| 1171 | uint32_t timeout_sec) // Timeout in seconds to wait for shell program to finish |
| 1172 | { |
| 1173 | if (IsHost()) |
| 1174 | return Host::RunShellCommand (command, working_dir, status_ptr, signo_ptr, command_output, timeout_sec); |
| 1175 | else |
| 1176 | return Error("unimplemented"); |
| 1177 | } |
| 1178 | |
| 1179 | |
| 1180 | bool |
| 1181 | Platform::CalculateMD5 (const FileSpec& file_spec, |
| 1182 | uint64_t &low, |
| 1183 | uint64_t &high) |
| 1184 | { |
| 1185 | if (IsHost()) |
Zachary Turner | c00cf4a | 2014-08-15 22:04:21 +0000 | [diff] [blame] | 1186 | return FileSystem::CalculateMD5(file_spec, low, high); |
Daniel Malea | e0f8f57 | 2013-08-26 23:57:52 +0000 | [diff] [blame] | 1187 | else |
| 1188 | return false; |
| 1189 | } |
| 1190 | |
Todd Fiala | af245d1 | 2014-06-30 21:05:18 +0000 | [diff] [blame] | 1191 | Error |
| 1192 | Platform::LaunchNativeProcess ( |
| 1193 | ProcessLaunchInfo &launch_info, |
| 1194 | lldb_private::NativeProcessProtocol::NativeDelegate &native_delegate, |
| 1195 | NativeProcessProtocolSP &process_sp) |
| 1196 | { |
| 1197 | // Platforms should override this implementation if they want to |
| 1198 | // support lldb-gdbserver. |
| 1199 | return Error("unimplemented"); |
| 1200 | } |
| 1201 | |
| 1202 | Error |
| 1203 | Platform::AttachNativeProcess (lldb::pid_t pid, |
| 1204 | lldb_private::NativeProcessProtocol::NativeDelegate &native_delegate, |
| 1205 | NativeProcessProtocolSP &process_sp) |
| 1206 | { |
| 1207 | // Platforms should override this implementation if they want to |
| 1208 | // support lldb-gdbserver. |
| 1209 | return Error("unimplemented"); |
| 1210 | } |
| 1211 | |
Daniel Malea | e0f8f57 | 2013-08-26 23:57:52 +0000 | [diff] [blame] | 1212 | void |
| 1213 | Platform::SetLocalCacheDirectory (const char* local) |
| 1214 | { |
| 1215 | m_local_cache_directory.assign(local); |
| 1216 | } |
| 1217 | |
| 1218 | const char* |
| 1219 | Platform::GetLocalCacheDirectory () |
| 1220 | { |
| 1221 | return m_local_cache_directory.c_str(); |
| 1222 | } |
| 1223 | |
| 1224 | static OptionDefinition |
| 1225 | g_rsync_option_table[] = |
| 1226 | { |
Zachary Turner | d37221d | 2014-07-09 16:31:49 +0000 | [diff] [blame] | 1227 | { LLDB_OPT_SET_ALL, false, "rsync" , 'r', OptionParser::eNoArgument, NULL, NULL, 0, eArgTypeNone , "Enable rsync." }, |
| 1228 | { LLDB_OPT_SET_ALL, false, "rsync-opts" , 'R', OptionParser::eRequiredArgument, NULL, NULL, 0, eArgTypeCommandName , "Platform-specific options required for rsync to work." }, |
| 1229 | { LLDB_OPT_SET_ALL, false, "rsync-prefix" , 'P', OptionParser::eRequiredArgument, NULL, NULL, 0, eArgTypeCommandName , "Platform-specific rsync prefix put before the remote path." }, |
| 1230 | { LLDB_OPT_SET_ALL, false, "ignore-remote-hostname" , 'i', OptionParser::eNoArgument, NULL, 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] | 1231 | }; |
| 1232 | |
| 1233 | static OptionDefinition |
| 1234 | g_ssh_option_table[] = |
| 1235 | { |
Zachary Turner | d37221d | 2014-07-09 16:31:49 +0000 | [diff] [blame] | 1236 | { LLDB_OPT_SET_ALL, false, "ssh" , 's', OptionParser::eNoArgument, NULL, NULL, 0, eArgTypeNone , "Enable SSH." }, |
| 1237 | { LLDB_OPT_SET_ALL, false, "ssh-opts" , 'S', OptionParser::eRequiredArgument, NULL, NULL, 0, eArgTypeCommandName , "Platform-specific options required for SSH to work." }, |
Daniel Malea | e0f8f57 | 2013-08-26 23:57:52 +0000 | [diff] [blame] | 1238 | }; |
| 1239 | |
| 1240 | static OptionDefinition |
| 1241 | g_caching_option_table[] = |
| 1242 | { |
Zachary Turner | d37221d | 2014-07-09 16:31:49 +0000 | [diff] [blame] | 1243 | { LLDB_OPT_SET_ALL, false, "local-cache-dir" , 'c', OptionParser::eRequiredArgument, NULL, NULL, 0, eArgTypePath , "Path in which to store local copies of files." }, |
Daniel Malea | e0f8f57 | 2013-08-26 23:57:52 +0000 | [diff] [blame] | 1244 | }; |
| 1245 | |
| 1246 | OptionGroupPlatformRSync::OptionGroupPlatformRSync () |
| 1247 | { |
| 1248 | } |
| 1249 | |
| 1250 | OptionGroupPlatformRSync::~OptionGroupPlatformRSync () |
| 1251 | { |
| 1252 | } |
| 1253 | |
| 1254 | const lldb_private::OptionDefinition* |
| 1255 | OptionGroupPlatformRSync::GetDefinitions () |
| 1256 | { |
| 1257 | return g_rsync_option_table; |
| 1258 | } |
| 1259 | |
| 1260 | void |
| 1261 | OptionGroupPlatformRSync::OptionParsingStarting (CommandInterpreter &interpreter) |
| 1262 | { |
| 1263 | m_rsync = false; |
| 1264 | m_rsync_opts.clear(); |
| 1265 | m_rsync_prefix.clear(); |
| 1266 | m_ignores_remote_hostname = false; |
| 1267 | } |
| 1268 | |
| 1269 | lldb_private::Error |
| 1270 | OptionGroupPlatformRSync::SetOptionValue (CommandInterpreter &interpreter, |
| 1271 | uint32_t option_idx, |
| 1272 | const char *option_arg) |
| 1273 | { |
| 1274 | Error error; |
| 1275 | char short_option = (char) GetDefinitions()[option_idx].short_option; |
| 1276 | switch (short_option) |
| 1277 | { |
| 1278 | case 'r': |
| 1279 | m_rsync = true; |
| 1280 | break; |
| 1281 | |
| 1282 | case 'R': |
| 1283 | m_rsync_opts.assign(option_arg); |
| 1284 | break; |
| 1285 | |
| 1286 | case 'P': |
| 1287 | m_rsync_prefix.assign(option_arg); |
| 1288 | break; |
| 1289 | |
| 1290 | case 'i': |
| 1291 | m_ignores_remote_hostname = true; |
| 1292 | break; |
| 1293 | |
| 1294 | default: |
| 1295 | error.SetErrorStringWithFormat ("unrecognized option '%c'", short_option); |
| 1296 | break; |
| 1297 | } |
| 1298 | |
| 1299 | return error; |
| 1300 | } |
| 1301 | |
| 1302 | uint32_t |
| 1303 | OptionGroupPlatformRSync::GetNumDefinitions () |
| 1304 | { |
| 1305 | return llvm::array_lengthof(g_rsync_option_table); |
| 1306 | } |
Greg Clayton | 1e0c884 | 2013-01-11 20:49:54 +0000 | [diff] [blame] | 1307 | |
Greg Clayton | 4116e93 | 2012-05-15 02:33:01 +0000 | [diff] [blame] | 1308 | lldb::BreakpointSP |
| 1309 | Platform::SetThreadCreationBreakpoint (lldb_private::Target &target) |
| 1310 | { |
| 1311 | return lldb::BreakpointSP(); |
| 1312 | } |
Greg Clayton | b3a40ba | 2012-03-20 18:34:04 +0000 | [diff] [blame] | 1313 | |
Daniel Malea | e0f8f57 | 2013-08-26 23:57:52 +0000 | [diff] [blame] | 1314 | OptionGroupPlatformSSH::OptionGroupPlatformSSH () |
| 1315 | { |
| 1316 | } |
| 1317 | |
| 1318 | OptionGroupPlatformSSH::~OptionGroupPlatformSSH () |
| 1319 | { |
| 1320 | } |
| 1321 | |
| 1322 | const lldb_private::OptionDefinition* |
| 1323 | OptionGroupPlatformSSH::GetDefinitions () |
| 1324 | { |
| 1325 | return g_ssh_option_table; |
| 1326 | } |
| 1327 | |
| 1328 | void |
| 1329 | OptionGroupPlatformSSH::OptionParsingStarting (CommandInterpreter &interpreter) |
| 1330 | { |
| 1331 | m_ssh = false; |
| 1332 | m_ssh_opts.clear(); |
| 1333 | } |
| 1334 | |
| 1335 | lldb_private::Error |
| 1336 | OptionGroupPlatformSSH::SetOptionValue (CommandInterpreter &interpreter, |
| 1337 | uint32_t option_idx, |
| 1338 | const char *option_arg) |
| 1339 | { |
| 1340 | Error error; |
| 1341 | char short_option = (char) GetDefinitions()[option_idx].short_option; |
| 1342 | switch (short_option) |
| 1343 | { |
| 1344 | case 's': |
| 1345 | m_ssh = true; |
| 1346 | break; |
| 1347 | |
| 1348 | case 'S': |
| 1349 | m_ssh_opts.assign(option_arg); |
| 1350 | break; |
| 1351 | |
| 1352 | default: |
| 1353 | error.SetErrorStringWithFormat ("unrecognized option '%c'", short_option); |
| 1354 | break; |
| 1355 | } |
| 1356 | |
| 1357 | return error; |
| 1358 | } |
| 1359 | |
| 1360 | uint32_t |
| 1361 | OptionGroupPlatformSSH::GetNumDefinitions () |
| 1362 | { |
| 1363 | return llvm::array_lengthof(g_ssh_option_table); |
| 1364 | } |
| 1365 | |
| 1366 | OptionGroupPlatformCaching::OptionGroupPlatformCaching () |
| 1367 | { |
| 1368 | } |
| 1369 | |
| 1370 | OptionGroupPlatformCaching::~OptionGroupPlatformCaching () |
| 1371 | { |
| 1372 | } |
| 1373 | |
| 1374 | const lldb_private::OptionDefinition* |
| 1375 | OptionGroupPlatformCaching::GetDefinitions () |
| 1376 | { |
| 1377 | return g_caching_option_table; |
| 1378 | } |
| 1379 | |
| 1380 | void |
| 1381 | OptionGroupPlatformCaching::OptionParsingStarting (CommandInterpreter &interpreter) |
| 1382 | { |
| 1383 | m_cache_dir.clear(); |
| 1384 | } |
| 1385 | |
| 1386 | lldb_private::Error |
| 1387 | OptionGroupPlatformCaching::SetOptionValue (CommandInterpreter &interpreter, |
| 1388 | uint32_t option_idx, |
| 1389 | const char *option_arg) |
| 1390 | { |
| 1391 | Error error; |
| 1392 | char short_option = (char) GetDefinitions()[option_idx].short_option; |
| 1393 | switch (short_option) |
| 1394 | { |
| 1395 | case 'c': |
| 1396 | m_cache_dir.assign(option_arg); |
| 1397 | break; |
| 1398 | |
| 1399 | default: |
| 1400 | error.SetErrorStringWithFormat ("unrecognized option '%c'", short_option); |
| 1401 | break; |
| 1402 | } |
| 1403 | |
| 1404 | return error; |
| 1405 | } |
| 1406 | |
| 1407 | uint32_t |
| 1408 | OptionGroupPlatformCaching::GetNumDefinitions () |
| 1409 | { |
| 1410 | return llvm::array_lengthof(g_caching_option_table); |
| 1411 | } |
| 1412 | |
Greg Clayton | 67cc063 | 2012-08-22 17:17:09 +0000 | [diff] [blame] | 1413 | size_t |
| 1414 | Platform::GetEnvironment (StringList &environment) |
| 1415 | { |
| 1416 | environment.Clear(); |
| 1417 | return false; |
| 1418 | } |
Jason Molenda | 2094dbf | 2014-02-13 23:11:45 +0000 | [diff] [blame] | 1419 | |
| 1420 | const std::vector<ConstString> & |
| 1421 | Platform::GetTrapHandlerSymbolNames () |
| 1422 | { |
| 1423 | if (!m_calculated_trap_handlers) |
| 1424 | { |
Jason Molenda | 4da8706 | 2014-05-23 23:11:27 +0000 | [diff] [blame] | 1425 | Mutex::Locker locker (m_trap_handler_mutex); |
| 1426 | if (!m_calculated_trap_handlers) |
| 1427 | { |
| 1428 | CalculateTrapHandlerSymbolNames(); |
| 1429 | m_calculated_trap_handlers = true; |
| 1430 | } |
Jason Molenda | 2094dbf | 2014-02-13 23:11:45 +0000 | [diff] [blame] | 1431 | } |
| 1432 | return m_trap_handlers; |
| 1433 | } |
| 1434 | |