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