1 //===-- PlatformMacOSX.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 "PlatformMacOSX.h" 11 12 // C Includes 13 #include <sys/sysctl.h> 14 15 // C++ Includes 16 // Other libraries and framework includes 17 // Project includes 18 #include "lldb/Core/Error.h" 19 #include "lldb/Breakpoint/BreakpointLocation.h" 20 #include "lldb/Core/Module.h" 21 #include "lldb/Core/ModuleList.h" 22 #include "lldb/Core/PluginManager.h" 23 #include "lldb/Core/StreamString.h" 24 #include "lldb/Host/FileSpec.h" 25 #include "lldb/Host/Host.h" 26 #include "lldb/Target/Process.h" 27 #include "lldb/Target/Target.h" 28 29 using namespace lldb; 30 using namespace lldb_private; 31 32 static uint32_t g_initialize_count = 0; 33 34 void 35 PlatformMacOSX::Initialize () 36 { 37 if (g_initialize_count++ == 0) 38 { 39 #if defined (__APPLE__) 40 PlatformSP default_platform_sp (new PlatformMacOSX(true)); 41 default_platform_sp->SetSystemArchitecture (Host::GetArchitecture()); 42 Platform::SetDefaultPlatform (default_platform_sp); 43 #endif 44 PluginManager::RegisterPlugin (PlatformMacOSX::GetShortPluginNameStatic(false), 45 PlatformMacOSX::GetDescriptionStatic(false), 46 PlatformMacOSX::CreateInstance); 47 } 48 49 } 50 51 void 52 PlatformMacOSX::Terminate () 53 { 54 if (g_initialize_count > 0) 55 { 56 if (--g_initialize_count == 0) 57 { 58 PluginManager::UnregisterPlugin (PlatformMacOSX::CreateInstance); 59 } 60 } 61 } 62 63 Platform* 64 PlatformMacOSX::CreateInstance (bool force, const ArchSpec *arch) 65 { 66 // The only time we create an instance is when we are creating a remote 67 // macosx platform 68 const bool is_host = false; 69 70 bool create = force; 71 if (create == false && arch && arch->IsValid()) 72 { 73 const llvm::Triple &triple = arch->GetTriple(); 74 const llvm::Triple::OSType os = triple.getOS(); 75 const llvm::Triple::VendorType vendor = triple.getVendor(); 76 if (os == llvm::Triple::Darwin && vendor == llvm::Triple::Apple) 77 create = true; 78 } 79 if (create) 80 return new PlatformMacOSX (is_host); 81 return NULL; 82 } 83 84 85 const char * 86 PlatformMacOSX::GetPluginNameStatic () 87 { 88 return "PlatformMacOSX"; 89 } 90 91 const char * 92 PlatformMacOSX::GetShortPluginNameStatic (bool is_host) 93 { 94 if (is_host) 95 return Platform::GetHostPlatformName (); 96 else 97 return "remote-macosx"; 98 } 99 100 const char * 101 PlatformMacOSX::GetDescriptionStatic (bool is_host) 102 { 103 if (is_host) 104 return "Local Mac OS X user platform plug-in."; 105 else 106 return "Remote Mac OS X user platform plug-in."; 107 } 108 109 //------------------------------------------------------------------ 110 /// Default Constructor 111 //------------------------------------------------------------------ 112 PlatformMacOSX::PlatformMacOSX (bool is_host) : 113 PlatformDarwin (is_host) 114 { 115 } 116 117 //------------------------------------------------------------------ 118 /// Destructor. 119 /// 120 /// The destructor is virtual since this class is designed to be 121 /// inherited from by the plug-in instance. 122 //------------------------------------------------------------------ 123 PlatformMacOSX::~PlatformMacOSX() 124 { 125 } 126 127 Error 128 PlatformMacOSX::GetFile (const FileSpec &platform_file, 129 const UUID *uuid_ptr, 130 FileSpec &local_file) 131 { 132 if (IsRemote()) 133 { 134 if (m_remote_platform_sp) 135 return m_remote_platform_sp->GetFile (platform_file, uuid_ptr, local_file); 136 } 137 138 // Default to the local case 139 local_file = platform_file; 140 return Error(); 141 } 142 143 bool 144 PlatformMacOSX::GetSupportedArchitectureAtIndex (uint32_t idx, ArchSpec &arch) 145 { 146 #if defined (__arm__) 147 return ARMGetSupportedArchitectureAtIndex (idx, arch); 148 #else 149 return x86GetSupportedArchitectureAtIndex (idx, arch); 150 #endif 151 } 152 153