Home | History | Annotate | Download | only in MacOSX
      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::GetPluginNameStatic(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 lldb_private::ConstString
    119 PlatformMacOSX::GetPluginNameStatic (bool is_host)
    120 {
    121     if (is_host)
    122     {
    123         static ConstString g_host_name(Platform::GetHostPlatformName ());
    124         return g_host_name;
    125     }
    126     else
    127     {
    128         static ConstString g_remote_name("remote-macosx");
    129         return g_remote_name;
    130     }
    131 }
    132 
    133 const char *
    134 PlatformMacOSX::GetDescriptionStatic (bool is_host)
    135 {
    136     if (is_host)
    137         return "Local Mac OS X user platform plug-in.";
    138     else
    139         return "Remote Mac OS X user platform plug-in.";
    140 }
    141 
    142 //------------------------------------------------------------------
    143 /// Default Constructor
    144 //------------------------------------------------------------------
    145 PlatformMacOSX::PlatformMacOSX (bool is_host) :
    146     PlatformDarwin (is_host)
    147 {
    148 }
    149 
    150 //------------------------------------------------------------------
    151 /// Destructor.
    152 ///
    153 /// The destructor is virtual since this class is designed to be
    154 /// inherited from by the plug-in instance.
    155 //------------------------------------------------------------------
    156 PlatformMacOSX::~PlatformMacOSX()
    157 {
    158 }
    159 
    160 Error
    161 PlatformMacOSX::GetFile (const FileSpec &platform_file,
    162                          const UUID *uuid_ptr,
    163                          FileSpec &local_file)
    164 {
    165     if (IsRemote())
    166     {
    167         if (m_remote_platform_sp)
    168             return m_remote_platform_sp->GetFile (platform_file, uuid_ptr, local_file);
    169     }
    170 
    171     // Default to the local case
    172     local_file = platform_file;
    173     return Error();
    174 }
    175 
    176 bool
    177 PlatformMacOSX::GetSupportedArchitectureAtIndex (uint32_t idx, ArchSpec &arch)
    178 {
    179 #if defined (__arm__)
    180     return ARMGetSupportedArchitectureAtIndex (idx, arch);
    181 #else
    182     return x86GetSupportedArchitectureAtIndex (idx, arch);
    183 #endif
    184 }
    185 
    186