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 switch (triple.getVendor()) 75 { 76 case llvm::Triple::Apple: 77 create = true; 78 break; 79 80 #if defined(__APPLE__) 81 // Only accept "unknown" for vendor if the host is Apple and 82 // it "unknown" wasn't specified (it was just returned becasue it 83 // was NOT specified) 84 case llvm::Triple::UnknownArch: 85 create = !arch->TripleVendorWasSpecified(); 86 break; 87 #endif 88 default: 89 break; 90 } 91 92 if (create) 93 { 94 switch (triple.getOS()) 95 { 96 case llvm::Triple::Darwin: // Deprecated, but still support Darwin for historical reasons 97 case llvm::Triple::MacOSX: 98 break; 99 #if defined(__APPLE__) 100 // Only accept "vendor" for vendor if the host is Apple and 101 // it "unknown" wasn't specified (it was just returned becasue it 102 // was NOT specified) 103 case llvm::Triple::UnknownOS: 104 create = !arch->TripleOSWasSpecified(); 105 break; 106 #endif 107 default: 108 create = false; 109 break; 110 } 111 } 112 } 113 if (create) 114 return new PlatformMacOSX (is_host); 115 return NULL; 116 } 117 118 119 const char * 120 PlatformMacOSX::GetPluginNameStatic () 121 { 122 return "PlatformMacOSX"; 123 } 124 125 const char * 126 PlatformMacOSX::GetShortPluginNameStatic (bool is_host) 127 { 128 if (is_host) 129 return Platform::GetHostPlatformName (); 130 else 131 return "remote-macosx"; 132 } 133 134 const char * 135 PlatformMacOSX::GetDescriptionStatic (bool is_host) 136 { 137 if (is_host) 138 return "Local Mac OS X user platform plug-in."; 139 else 140 return "Remote Mac OS X user platform plug-in."; 141 } 142 143 //------------------------------------------------------------------ 144 /// Default Constructor 145 //------------------------------------------------------------------ 146 PlatformMacOSX::PlatformMacOSX (bool is_host) : 147 PlatformDarwin (is_host) 148 { 149 } 150 151 //------------------------------------------------------------------ 152 /// Destructor. 153 /// 154 /// The destructor is virtual since this class is designed to be 155 /// inherited from by the plug-in instance. 156 //------------------------------------------------------------------ 157 PlatformMacOSX::~PlatformMacOSX() 158 { 159 } 160 161 Error 162 PlatformMacOSX::GetFile (const FileSpec &platform_file, 163 const UUID *uuid_ptr, 164 FileSpec &local_file) 165 { 166 if (IsRemote()) 167 { 168 if (m_remote_platform_sp) 169 return m_remote_platform_sp->GetFile (platform_file, uuid_ptr, local_file); 170 } 171 172 // Default to the local case 173 local_file = platform_file; 174 return Error(); 175 } 176 177 bool 178 PlatformMacOSX::GetSupportedArchitectureAtIndex (uint32_t idx, ArchSpec &arch) 179 { 180 #if defined (__arm__) 181 return ARMGetSupportedArchitectureAtIndex (idx, arch); 182 #else 183 return x86GetSupportedArchitectureAtIndex (idx, arch); 184 #endif 185 } 186 187