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 16 #include "lldb/Breakpoint/BreakpointIDList.h" 17 #include "lldb/Core/Error.h" 18 #include "lldb/Core/Log.h" 19 #include "lldb/Core/ModuleSpec.h" 20 #include "lldb/Core/PluginManager.h" 21 #include "lldb/Host/FileSpec.h" 22 #include "lldb/Host/Host.h" 23 #include "lldb/Target/Process.h" 24 #include "lldb/Target/Target.h" 25 #include "lldb/Utility/Utils.h" 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 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 52 53 const char * 54 Platform::GetHostPlatformName () 55 { 56 return "host"; 57 } 58 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 83 Error 84 Platform::GetFile (const FileSpec &platform_file, 85 const UUID *uuid_ptr, 86 FileSpec &local_file) 87 { 88 // Default to the local case 89 local_file = platform_file; 90 return Error(); 91 } 92 93 FileSpecList 94 Platform::LocateExecutableScriptingResources (Target *target, Module &module) 95 { 96 return FileSpecList(); 97 } 98 99 Platform* 100 Platform::FindPlugin (Process *process, const ConstString &plugin_name) 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 } 113 std::unique_ptr<Platform> instance_ap(create_callback(process, &arch)); 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 { 122 std::unique_ptr<Platform> instance_ap(create_callback(process, nullptr)); 123 if (instance_ap.get()) 124 return instance_ap.release(); 125 } 126 } 127 return NULL; 128 } 129 130 Error 131 Platform::GetSharedModule (const ModuleSpec &module_spec, 132 ModuleSP &module_sp, 133 const FileSpecList *module_search_paths_ptr, 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; 145 return ModuleList::GetSharedModule (module_spec, 146 module_sp, 147 module_search_paths_ptr, 148 old_module_sp_ptr, 149 did_create_ptr, 150 always_create); 151 } 152 153 PlatformSP 154 Platform::Create (const char *platform_name, Error &error) 155 { 156 PlatformCreateInstance create_callback = NULL; 157 lldb::PlatformSP platform_sp; 158 if (platform_name && platform_name[0]) 159 { 160 ConstString const_platform_name (platform_name); 161 create_callback = PluginManager::GetPlatformCreateCallbackForPluginName (const_platform_name); 162 if (create_callback) 163 platform_sp.reset(create_callback(true, NULL)); 164 else 165 error.SetErrorStringWithFormat ("unable to find a plug-in for the platform named \"%s\"", platform_name); 166 } 167 else 168 error.SetErrorString ("invalid platform name"); 169 return platform_sp; 170 } 171 172 173 PlatformSP 174 Platform::Create (const ArchSpec &arch, ArchSpec *platform_arch_ptr, Error &error) 175 { 176 lldb::PlatformSP platform_sp; 177 if (arch.IsValid()) 178 { 179 uint32_t idx; 180 PlatformCreateInstance create_callback; 181 // First try exact arch matches across all platform plug-ins 182 bool exact = true; 183 for (idx = 0; (create_callback = PluginManager::GetPlatformCreateCallbackAtIndex (idx)); ++idx) 184 { 185 if (create_callback) 186 { 187 platform_sp.reset(create_callback(false, &arch)); 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 } 202 } 203 } 204 else 205 error.SetErrorString ("invalid platform name"); 206 if (platform_arch_ptr) 207 platform_arch_ptr->Clear(); 208 platform_sp.reset(); 209 return platform_sp; 210 } 211 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 //------------------------------------------------------------------ 234 Platform::Platform (bool is_host) : 235 m_is_host (is_host), 236 m_os_version_set_while_connected (false), 237 m_system_arch_set_while_connected (false), 238 m_sdk_sysroot (), 239 m_sdk_build (), 240 m_remote_url (), 241 m_name (), 242 m_major_os_version (UINT32_MAX), 243 m_minor_os_version (UINT32_MAX), 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), 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) 258 { 259 Log *log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_OBJECT)); 260 if (log) 261 log->Printf ("%p Platform::Platform()", this); 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 { 272 Log *log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_OBJECT)); 273 if (log) 274 log->Printf ("%p Platform::~Platform()", this); 275 } 276 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; 284 strm.Printf (" Platform: %s\n", GetPluginName().GetCString()); 285 286 ArchSpec arch (GetSystemArchitecture()); 287 if (arch.IsValid()) 288 { 289 if (!arch.GetTriple().str().empty()) 290 strm.Printf(" Triple: %s\n", arch.GetTriple().str().c_str()); 291 } 292 293 if (GetOSVersion(major, minor, update)) 294 { 295 strm.Printf("OS Version: %u", major); 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)) 308 strm.Printf(" Kernel: %s\n", s.c_str()); 309 310 if (IsHost()) 311 { 312 strm.Printf(" Hostname: %s\n", GetHostname()); 313 } 314 else 315 { 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"); 320 } 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()); 329 } 330 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 357 bool fetch = false; 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) 365 fetch = true; 366 } 367 else 368 { 369 // We don't have valid OS version info, fetch it if we are connected 370 fetch = is_connected; 371 } 372 373 if (fetch) 374 { 375 success = GetRemoteOSVersion (); 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 } 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 407 ConstString 408 Platform::GetName () 409 { 410 const char *name = GetHostname(); 411 if (name == NULL || name[0] == '\0') 412 return GetPluginName(); 413 return ConstString (name); 414 } 415 416 const char * 417 Platform::GetHostname () 418 { 419 if (IsHost()) 420 return "localhost"; 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 } 439 return NULL; 440 } 441 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 } 456 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 491 Error 492 Platform::ResolveExecutable (const FileSpec &exe_file, 493 const ArchSpec &exe_arch, 494 lldb::ModuleSP &exe_module_sp, 495 const FileSpecList *module_search_paths_ptr) 496 { 497 Error error; 498 if (exe_file.Exists()) 499 { 500 ModuleSpec module_spec (exe_file, exe_arch); 501 if (module_spec.GetArchitecture().IsValid()) 502 { 503 error = ModuleList::GetSharedModule (module_spec, 504 exe_module_sp, 505 module_search_paths_ptr, 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 514 for (uint32_t idx = 0; GetSupportedArchitectureAtIndex (idx, module_spec.GetArchitecture()); ++idx) 515 { 516 error = ModuleList::GetSharedModule (module_spec, 517 exe_module_sp, 518 module_search_paths_ptr, 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 { 529 error.SetErrorStringWithFormat ("'%s' does not exist", 530 exe_file.GetPath().c_str()); 531 } 532 return error; 533 } 534 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 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 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 { 598 m_system_arch = GetRemoteSystemArchitecture (); 599 m_system_arch_set_while_connected = m_system_arch.IsValid(); 600 } 601 } 602 return m_system_arch; 603 } 604 605 606 Error 607 Platform::ConnectRemote (Args& args) 608 { 609 Error error; 610 if (IsHost()) 611 error.SetErrorStringWithFormat ("The currently selected platform (%s) is the host platform and is always connected.", GetPluginName().GetCString()); 612 else 613 error.SetErrorStringWithFormat ("Platform::ConnectRemote() is not supported by %s", GetPluginName().GetCString()); 614 return error; 615 } 616 617 Error 618 Platform::DisconnectRemote () 619 { 620 Error error; 621 if (IsHost()) 622 error.SetErrorStringWithFormat ("The currently selected platform (%s) is the host platform and is always connected.", GetPluginName().GetCString()); 623 else 624 error.SetErrorStringWithFormat ("Platform::DisconnectRemote() is not supported by %s", GetPluginName().GetCString()); 625 return error; 626 } 627 628 bool 629 Platform::GetProcessInfo (lldb::pid_t pid, ProcessInstanceInfo &process_info) 630 { 631 // Take care of the host case so that each subclass can just 632 // call this function to get the host functionality. 633 if (IsHost()) 634 return Host::GetProcessInfo (pid, process_info); 635 return false; 636 } 637 638 uint32_t 639 Platform::FindProcesses (const ProcessInstanceInfoMatch &match_info, 640 ProcessInstanceInfoList &process_infos) 641 { 642 // Take care of the host case so that each subclass can just 643 // call this function to get the host functionality. 644 uint32_t match_count = 0; 645 if (IsHost()) 646 match_count = Host::FindProcesses (match_info, process_infos); 647 return match_count; 648 } 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()) 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; 665 const bool will_debug = launch_info.GetFlags().Test(eLaunchFlagDebug); 666 const bool first_arg_is_full_shell_command = false; 667 if (!launch_info.ConvertArgumentsForLaunchingInShell (error, 668 is_localhost, 669 will_debug, 670 first_arg_is_full_shell_command)) 671 return error; 672 } 673 674 error = Host::LaunchProcess (launch_info); 675 } 676 else 677 error.SetErrorString ("base lldb_private::Platform class can't launch remote processes"); 678 return error; 679 } 680 681 lldb::ProcessSP 682 Platform::DebugProcess (ProcessLaunchInfo &launch_info, 683 Debugger &debugger, 684 Target *target, // Can be NULL, if NULL create a new target, else use existing one 685 Listener &listener, 686 Error &error) 687 { 688 ProcessSP process_sp; 689 // Make sure we stop at the entry point 690 launch_info.GetFlags ().Set (eLaunchFlagDebug); 691 // We always launch the process we are going to debug in a separate process 692 // group, since then we can handle ^C interrupts ourselves w/o having to worry 693 // about the target getting them as well. 694 launch_info.SetLaunchInSeparateProcessGroup(true); 695 696 error = LaunchProcess (launch_info); 697 if (error.Success()) 698 { 699 if (launch_info.GetProcessID() != LLDB_INVALID_PROCESS_ID) 700 { 701 ProcessAttachInfo attach_info (launch_info); 702 process_sp = Attach (attach_info, debugger, target, listener, error); 703 if (process_sp) 704 { 705 // Since we attached to the process, it will think it needs to detach 706 // if the process object just goes away without an explicit call to 707 // Process::Kill() or Process::Detach(), so let it know to kill the 708 // process if this happens. 709 process_sp->SetShouldDetach (false); 710 711 // If we didn't have any file actions, the pseudo terminal might 712 // have been used where the slave side was given as the file to 713 // open for stdin/out/err after we have already opened the master 714 // so we can read/write stdin/out/err. 715 int pty_fd = launch_info.GetPTY().ReleaseMasterFileDescriptor(); 716 if (pty_fd != lldb_utility::PseudoTerminal::invalid_fd) 717 { 718 process_sp->SetSTDIOFileDescriptor(pty_fd); 719 } 720 } 721 } 722 } 723 return process_sp; 724 } 725 726 727 lldb::PlatformSP 728 Platform::GetPlatformForArchitecture (const ArchSpec &arch, ArchSpec *platform_arch_ptr) 729 { 730 lldb::PlatformSP platform_sp; 731 Error error; 732 if (arch.IsValid()) 733 platform_sp = Platform::Create (arch, platform_arch_ptr, error); 734 return platform_sp; 735 } 736 737 738 //------------------------------------------------------------------ 739 /// Lets a platform answer if it is compatible with a given 740 /// architecture and the target triple contained within. 741 //------------------------------------------------------------------ 742 bool 743 Platform::IsCompatibleArchitecture (const ArchSpec &arch, bool exact_arch_match, ArchSpec *compatible_arch_ptr) 744 { 745 // If the architecture is invalid, we must answer true... 746 if (arch.IsValid()) 747 { 748 ArchSpec platform_arch; 749 // Try for an exact architecture match first. 750 if (exact_arch_match) 751 { 752 for (uint32_t arch_idx=0; GetSupportedArchitectureAtIndex (arch_idx, platform_arch); ++arch_idx) 753 { 754 if (arch.IsExactMatch(platform_arch)) 755 { 756 if (compatible_arch_ptr) 757 *compatible_arch_ptr = platform_arch; 758 return true; 759 } 760 } 761 } 762 else 763 { 764 for (uint32_t arch_idx=0; GetSupportedArchitectureAtIndex (arch_idx, platform_arch); ++arch_idx) 765 { 766 if (arch.IsCompatibleMatch(platform_arch)) 767 { 768 if (compatible_arch_ptr) 769 *compatible_arch_ptr = platform_arch; 770 return true; 771 } 772 } 773 } 774 } 775 if (compatible_arch_ptr) 776 compatible_arch_ptr->Clear(); 777 return false; 778 } 779 780 uint32_t 781 Platform::MakeDirectory (const FileSpec &spec, 782 mode_t mode) 783 { 784 std::string path(spec.GetPath()); 785 return this->MakeDirectory(path,mode); 786 } 787 788 Error 789 Platform::PutFile (const FileSpec& source, 790 const FileSpec& destination, 791 uint32_t uid, 792 uint32_t gid) 793 { 794 Error error("unimplemented"); 795 return error; 796 } 797 798 Error 799 Platform::GetFile (const FileSpec& source, 800 const FileSpec& destination) 801 { 802 Error error("unimplemented"); 803 return error; 804 } 805 806 bool 807 Platform::GetFileExists (const lldb_private::FileSpec& file_spec) 808 { 809 return false; 810 } 811 812 lldb_private::Error 813 Platform::RunShellCommand (const char *command, // Shouldn't be NULL 814 const char *working_dir, // Pass NULL to use the current working directory 815 int *status_ptr, // Pass NULL if you don't want the process exit status 816 int *signo_ptr, // Pass NULL if you don't want the signal that caused the process to exit 817 std::string *command_output, // Pass NULL if you don't want the command output 818 uint32_t timeout_sec) // Timeout in seconds to wait for shell program to finish 819 { 820 if (IsHost()) 821 return Host::RunShellCommand (command, working_dir, status_ptr, signo_ptr, command_output, timeout_sec); 822 else 823 return Error("unimplemented"); 824 } 825 826 827 bool 828 Platform::CalculateMD5 (const FileSpec& file_spec, 829 uint64_t &low, 830 uint64_t &high) 831 { 832 if (IsHost()) 833 return Host::CalculateMD5(file_spec, low, high); 834 else 835 return false; 836 } 837 838 void 839 Platform::SetLocalCacheDirectory (const char* local) 840 { 841 m_local_cache_directory.assign(local); 842 } 843 844 const char* 845 Platform::GetLocalCacheDirectory () 846 { 847 return m_local_cache_directory.c_str(); 848 } 849 850 static OptionDefinition 851 g_rsync_option_table[] = 852 { 853 { LLDB_OPT_SET_ALL, false, "rsync" , 'r', OptionParser::eNoArgument, NULL, 0, eArgTypeNone , "Enable rsync." }, 854 { LLDB_OPT_SET_ALL, false, "rsync-opts" , 'R', OptionParser::eRequiredArgument, NULL, 0, eArgTypeCommandName , "Platform-specific options required for rsync to work." }, 855 { LLDB_OPT_SET_ALL, false, "rsync-prefix" , 'P', OptionParser::eRequiredArgument, NULL, 0, eArgTypeCommandName , "Platform-specific rsync prefix put before the remote path." }, 856 { 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." }, 857 }; 858 859 static OptionDefinition 860 g_ssh_option_table[] = 861 { 862 { LLDB_OPT_SET_ALL, false, "ssh" , 's', OptionParser::eNoArgument, NULL, 0, eArgTypeNone , "Enable SSH." }, 863 { LLDB_OPT_SET_ALL, false, "ssh-opts" , 'S', OptionParser::eRequiredArgument, NULL, 0, eArgTypeCommandName , "Platform-specific options required for SSH to work." }, 864 }; 865 866 static OptionDefinition 867 g_caching_option_table[] = 868 { 869 { LLDB_OPT_SET_ALL, false, "local-cache-dir" , 'c', OptionParser::eRequiredArgument, NULL, 0, eArgTypePath , "Path in which to store local copies of files." }, 870 }; 871 872 OptionGroupPlatformRSync::OptionGroupPlatformRSync () 873 { 874 } 875 876 OptionGroupPlatformRSync::~OptionGroupPlatformRSync () 877 { 878 } 879 880 const lldb_private::OptionDefinition* 881 OptionGroupPlatformRSync::GetDefinitions () 882 { 883 return g_rsync_option_table; 884 } 885 886 void 887 OptionGroupPlatformRSync::OptionParsingStarting (CommandInterpreter &interpreter) 888 { 889 m_rsync = false; 890 m_rsync_opts.clear(); 891 m_rsync_prefix.clear(); 892 m_ignores_remote_hostname = false; 893 } 894 895 lldb_private::Error 896 OptionGroupPlatformRSync::SetOptionValue (CommandInterpreter &interpreter, 897 uint32_t option_idx, 898 const char *option_arg) 899 { 900 Error error; 901 char short_option = (char) GetDefinitions()[option_idx].short_option; 902 switch (short_option) 903 { 904 case 'r': 905 m_rsync = true; 906 break; 907 908 case 'R': 909 m_rsync_opts.assign(option_arg); 910 break; 911 912 case 'P': 913 m_rsync_prefix.assign(option_arg); 914 break; 915 916 case 'i': 917 m_ignores_remote_hostname = true; 918 break; 919 920 default: 921 error.SetErrorStringWithFormat ("unrecognized option '%c'", short_option); 922 break; 923 } 924 925 return error; 926 } 927 928 uint32_t 929 OptionGroupPlatformRSync::GetNumDefinitions () 930 { 931 return llvm::array_lengthof(g_rsync_option_table); 932 } 933 934 lldb::BreakpointSP 935 Platform::SetThreadCreationBreakpoint (lldb_private::Target &target) 936 { 937 return lldb::BreakpointSP(); 938 } 939 940 OptionGroupPlatformSSH::OptionGroupPlatformSSH () 941 { 942 } 943 944 OptionGroupPlatformSSH::~OptionGroupPlatformSSH () 945 { 946 } 947 948 const lldb_private::OptionDefinition* 949 OptionGroupPlatformSSH::GetDefinitions () 950 { 951 return g_ssh_option_table; 952 } 953 954 void 955 OptionGroupPlatformSSH::OptionParsingStarting (CommandInterpreter &interpreter) 956 { 957 m_ssh = false; 958 m_ssh_opts.clear(); 959 } 960 961 lldb_private::Error 962 OptionGroupPlatformSSH::SetOptionValue (CommandInterpreter &interpreter, 963 uint32_t option_idx, 964 const char *option_arg) 965 { 966 Error error; 967 char short_option = (char) GetDefinitions()[option_idx].short_option; 968 switch (short_option) 969 { 970 case 's': 971 m_ssh = true; 972 break; 973 974 case 'S': 975 m_ssh_opts.assign(option_arg); 976 break; 977 978 default: 979 error.SetErrorStringWithFormat ("unrecognized option '%c'", short_option); 980 break; 981 } 982 983 return error; 984 } 985 986 uint32_t 987 OptionGroupPlatformSSH::GetNumDefinitions () 988 { 989 return llvm::array_lengthof(g_ssh_option_table); 990 } 991 992 OptionGroupPlatformCaching::OptionGroupPlatformCaching () 993 { 994 } 995 996 OptionGroupPlatformCaching::~OptionGroupPlatformCaching () 997 { 998 } 999 1000 const lldb_private::OptionDefinition* 1001 OptionGroupPlatformCaching::GetDefinitions () 1002 { 1003 return g_caching_option_table; 1004 } 1005 1006 void 1007 OptionGroupPlatformCaching::OptionParsingStarting (CommandInterpreter &interpreter) 1008 { 1009 m_cache_dir.clear(); 1010 } 1011 1012 lldb_private::Error 1013 OptionGroupPlatformCaching::SetOptionValue (CommandInterpreter &interpreter, 1014 uint32_t option_idx, 1015 const char *option_arg) 1016 { 1017 Error error; 1018 char short_option = (char) GetDefinitions()[option_idx].short_option; 1019 switch (short_option) 1020 { 1021 case 'c': 1022 m_cache_dir.assign(option_arg); 1023 break; 1024 1025 default: 1026 error.SetErrorStringWithFormat ("unrecognized option '%c'", short_option); 1027 break; 1028 } 1029 1030 return error; 1031 } 1032 1033 uint32_t 1034 OptionGroupPlatformCaching::GetNumDefinitions () 1035 { 1036 return llvm::array_lengthof(g_caching_option_table); 1037 } 1038 1039 size_t 1040 Platform::GetEnvironment (StringList &environment) 1041 { 1042 environment.Clear(); 1043 return false; 1044 } 1045