LLDB mainline
PlatformMacOSX.cpp
Go to the documentation of this file.
1//===-- PlatformMacOSX.cpp ------------------------------------------------===//
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 "PlatformMacOSX.h"
11#include "PlatformRemoteiOS.h"
12#if defined(__APPLE__)
19#endif
21#include "lldb/Core/Debugger.h"
22#include "lldb/Core/Module.h"
26#include "lldb/Host/Config.h"
27#include "lldb/Host/Host.h"
28#include "lldb/Host/HostInfo.h"
30#include "lldb/Target/Process.h"
31#include "lldb/Target/Target.h"
34#include "lldb/Utility/Log.h"
35#include "lldb/Utility/Status.h"
37
38#include <sstream>
39
40using namespace lldb;
41using namespace lldb_private;
42
44
45static uint32_t g_initialize_count = 0;
46
51#if defined(__APPLE__)
53 PlatformDarwinKernel::Initialize();
58#endif
59
60 if (g_initialize_count++ == 0) {
61#if defined(__APPLE__)
62 PlatformSP default_platform_sp(new PlatformMacOSX());
63 default_platform_sp->SetSystemArchitecture(HostInfo::GetArchitecture());
64 Platform::SetHostPlatform(default_platform_sp);
65#endif
69 }
70}
71
91
93 return "Local Mac OS X user platform plug-in.";
94}
95
97 // The only time we create an instance is when we are creating a remote
98 // macosx platform which is handled by PlatformRemoteMacOSX.
99 return PlatformSP();
100}
101
102/// Default Constructor
104
105std::vector<ArchSpec>
107 std::vector<ArchSpec> result;
108#if defined(__arm__) || defined(__arm64__) || defined(__aarch64__)
109 // When cmdline lldb is run on iOS, watchOS, etc, it is still
110 // using "PlatformMacOSX".
111 llvm::Triple::OSType host_os = GetHostOSType();
112 ARMGetSupportedArchitectures(result, host_os);
113
114 if (host_os == llvm::Triple::MacOSX) {
115 // We can't use x86GetSupportedArchitectures() because it uses
116 // the system architecture for some of its return values and also
117 // has a 32bits variant.
118 result.push_back(ArchSpec("x86_64-apple-macosx"));
119 result.push_back(ArchSpec("x86_64-apple-ios-macabi"));
120 result.push_back(ArchSpec("arm64-apple-ios-macabi"));
121 result.push_back(ArchSpec("arm64e-apple-ios-macabi"));
122
123 // On Apple Silicon, the host platform is compatible with iOS triples to
124 // support unmodified "iPhone and iPad Apps on Apple Silicon Macs". Because
125 // the binaries are identical, we must rely on the host architecture to
126 // tell them apart and mark the host platform as compatible or not.
127 if (!process_host_arch ||
128 process_host_arch.GetTriple().getOS() == llvm::Triple::MacOSX) {
129 result.push_back(ArchSpec("arm64-apple-ios"));
130 result.push_back(ArchSpec("arm64e-apple-ios"));
131 }
132 }
133#else
135 result.push_back(ArchSpec("x86_64-apple-ios-macabi"));
136#endif
137 return result;
138}
139
141 const lldb_private::ModuleSpec &module_spec, Target &target,
142 lldb::ModuleSP &module_sp,
143 llvm::SmallVectorImpl<lldb::ModuleSP> *old_modules, bool *did_create_ptr) {
145 module_spec, module_sp, old_modules, did_create_ptr, target);
146
147 if (module_sp) {
148 if (module_spec.GetArchitecture().GetCore() ==
150 ObjectFile *objfile = module_sp->GetObjectFile();
151 if (objfile == nullptr) {
152 // We didn't find an x86_64h slice, fall back to a x86_64 slice
153 ModuleSpec module_spec_x86_64(module_spec);
154 module_spec_x86_64.GetArchitecture() = ArchSpec("x86_64-apple-macosx");
155 lldb::ModuleSP x86_64_module_sp;
156 llvm::SmallVector<lldb::ModuleSP, 1> old_x86_64_modules;
157 bool did_create = false;
159 module_spec_x86_64, x86_64_module_sp, &old_x86_64_modules,
160 &did_create, target);
161 if (x86_64_module_sp && x86_64_module_sp->GetObjectFile()) {
162 module_sp = x86_64_module_sp;
163 if (old_modules)
164 old_modules->append(old_x86_64_modules.begin(),
165 old_x86_64_modules.end());
166 if (did_create_ptr)
167 *did_create_ptr = did_create;
168 return x86_64_error;
169 }
170 }
171 }
172 }
173
174 if (!module_sp) {
175 error = FindBundleBinaryInExecSearchPaths(module_spec, target, module_sp,
176 old_modules, did_create_ptr);
177 }
178 return error;
179}
180
181llvm::SmallVector<llvm::StringRef>
183 return {"macOS DeviceSupport"};
184}
185
186llvm::StringRef PlatformMacOSX::GetPlatformName() { return "MacOSX.platform"; }
static llvm::raw_ostream & error(Stream &strm)
static uint32_t g_initialize_count
#define LLDB_PLUGIN_DEFINE(PluginName)
An architecture specification class.
Definition ArchSpec.h:32
llvm::Triple & GetTriple()
Architecture triple accessor.
Definition ArchSpec.h:545
Core GetCore() const
Definition ArchSpec.h:534
ArchSpec & GetArchitecture()
Definition ModuleSpec.h:93
A plug-in interface definition class for object file parsers.
Definition ObjectFile.h:46
Abstract Darwin platform with a potential device support directory.
virtual Status GetSharedModuleWithLocalCache(const ModuleSpec &module_spec, lldb::ModuleSP &module_sp, llvm::SmallVectorImpl< lldb::ModuleSP > *old_modules, bool *did_create_ptr, Target &target)
Status FindBundleBinaryInExecSearchPaths(const ModuleSpec &module_spec, Target &target, lldb::ModuleSP &module_sp, llvm::SmallVectorImpl< lldb::ModuleSP > *old_modules, bool *did_create_ptr)
static llvm::Triple::OSType GetHostOSType()
void x86GetSupportedArchitectures(std::vector< ArchSpec > &archs)
void ARMGetSupportedArchitectures(std::vector< ArchSpec > &archs, std::optional< llvm::Triple::OSType > os={})
The architecture selection rules for arm processors These cpu subtypes have distinct names (e....
llvm::SmallVector< llvm::StringRef > GetDeviceSupportDirectoryNames() override
static llvm::StringRef GetDescriptionStatic()
Status GetSharedModule(const ModuleSpec &module_spec, Target &target, lldb::ModuleSP &module_sp, llvm::SmallVectorImpl< lldb::ModuleSP > *old_modules, bool *did_create_ptr) override
llvm::StringRef GetPlatformName() override
static llvm::StringRef GetPluginNameStatic()
static lldb::PlatformSP CreateInstance(bool force, const ArchSpec *arch)
std::vector< ArchSpec > GetSupportedArchitectures(const ArchSpec &process_host_arch) override
Get the platform's supported architectures in the order in which they should be searched.
PlatformMacOSX()
Default Constructor.
static void SetHostPlatform(const lldb::PlatformSP &platform_sp)
Definition Platform.cpp:161
static bool RegisterPlugin(llvm::StringRef name, llvm::StringRef description, ABICreateInstance create_callback)
static bool UnregisterPlugin(ABICreateInstance create_callback)
An error handling class.
Definition Status.h:118
A class that represents a running process on the host machine.
std::shared_ptr< lldb_private::Platform > PlatformSP
std::shared_ptr< lldb_private::Module > ModuleSP