1 //===-- PlatformRemoteiOS.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 "PlatformRemoteiOS.h"
11 
12 #include "lldb/Breakpoint/BreakpointLocation.h"
13 #include "lldb/Core/Module.h"
14 #include "lldb/Core/ModuleList.h"
15 #include "lldb/Core/ModuleSpec.h"
16 #include "lldb/Core/PluginManager.h"
17 #include "lldb/Host/Host.h"
18 #include "lldb/Target/Process.h"
19 #include "lldb/Target/Target.h"
20 #include "lldb/Utility/ArchSpec.h"
21 #include "lldb/Utility/FileSpec.h"
22 #include "lldb/Utility/Log.h"
23 #include "lldb/Utility/Status.h"
24 #include "lldb/Utility/StreamString.h"
25 
26 using namespace lldb;
27 using namespace lldb_private;
28 
29 //------------------------------------------------------------------
30 // Static Variables
31 //------------------------------------------------------------------
32 static uint32_t g_initialize_count = 0;
33 
34 //------------------------------------------------------------------
35 // Static Functions
36 //------------------------------------------------------------------
37 void PlatformRemoteiOS::Initialize() {
38   PlatformDarwin::Initialize();
39 
40   if (g_initialize_count++ == 0) {
41     PluginManager::RegisterPlugin(PlatformRemoteiOS::GetPluginNameStatic(),
42                                   PlatformRemoteiOS::GetDescriptionStatic(),
43                                   PlatformRemoteiOS::CreateInstance);
44   }
45 }
46 
47 void PlatformRemoteiOS::Terminate() {
48   if (g_initialize_count > 0) {
49     if (--g_initialize_count == 0) {
50       PluginManager::UnregisterPlugin(PlatformRemoteiOS::CreateInstance);
51     }
52   }
53 
54   PlatformDarwin::Terminate();
55 }
56 
57 PlatformSP PlatformRemoteiOS::CreateInstance(bool force, const ArchSpec *arch) {
58   Log *log(GetLogIfAllCategoriesSet(LIBLLDB_LOG_PLATFORM));
59   if (log) {
60     const char *arch_name;
61     if (arch && arch->GetArchitectureName())
62       arch_name = arch->GetArchitectureName();
63     else
64       arch_name = "<null>";
65 
66     const char *triple_cstr =
67         arch ? arch->GetTriple().getTriple().c_str() : "<null>";
68 
69     log->Printf("PlatformRemoteiOS::%s(force=%s, arch={%s,%s})", __FUNCTION__,
70                 force ? "true" : "false", arch_name, triple_cstr);
71   }
72 
73   bool create = force;
74   if (!create && arch && arch->IsValid()) {
75     switch (arch->GetMachine()) {
76     case llvm::Triple::arm:
77     case llvm::Triple::aarch64:
78     case llvm::Triple::thumb: {
79       const llvm::Triple &triple = arch->GetTriple();
80       llvm::Triple::VendorType vendor = triple.getVendor();
81       switch (vendor) {
82       case llvm::Triple::Apple:
83         create = true;
84         break;
85 
86 #if defined(__APPLE__)
87       // Only accept "unknown" for the vendor if the host is Apple and
88       // "unknown" wasn't specified (it was just returned because it was NOT
89       // specified)
90       case llvm::Triple::UnknownVendor:
91         create = !arch->TripleVendorWasSpecified();
92         break;
93 
94 #endif
95       default:
96         break;
97       }
98       if (create) {
99         switch (triple.getOS()) {
100         case llvm::Triple::Darwin: // Deprecated, but still support Darwin for
101                                    // historical reasons
102         case llvm::Triple::IOS:    // This is the right triple value for iOS
103                                    // debugging
104           break;
105 
106         default:
107           create = false;
108           break;
109         }
110       }
111     } break;
112     default:
113       break;
114     }
115   }
116 
117   if (create) {
118     if (log)
119       log->Printf("PlatformRemoteiOS::%s() creating platform", __FUNCTION__);
120 
121     return lldb::PlatformSP(new PlatformRemoteiOS());
122   }
123 
124   if (log)
125     log->Printf("PlatformRemoteiOS::%s() aborting creation of platform",
126                 __FUNCTION__);
127 
128   return lldb::PlatformSP();
129 }
130 
131 lldb_private::ConstString PlatformRemoteiOS::GetPluginNameStatic() {
132   static ConstString g_name("remote-ios");
133   return g_name;
134 }
135 
136 const char *PlatformRemoteiOS::GetDescriptionStatic() {
137   return "Remote iOS platform plug-in.";
138 }
139 
140 //------------------------------------------------------------------
141 /// Default Constructor
142 //------------------------------------------------------------------
143 PlatformRemoteiOS::PlatformRemoteiOS()
144     : PlatformRemoteDarwinDevice() {}
145 
146 bool PlatformRemoteiOS::GetSupportedArchitectureAtIndex(uint32_t idx,
147                                                         ArchSpec &arch) {
148   return ARMGetSupportedArchitectureAtIndex(idx, arch);
149 }
150 
151 
152 void PlatformRemoteiOS::GetDeviceSupportDirectoryNames (std::vector<std::string> &dirnames)
153 {
154     dirnames.clear();
155     dirnames.push_back("iOS DeviceSupport");
156 }
157 
158 std::string PlatformRemoteiOS::GetPlatformName ()
159 {
160     return "iPhoneOS.platform";
161 }
162