Go to the documentation of this file.
11 #if defined(__APPLE__)
26 #include "llvm/Support/Threading.h"
34 #if !defined(__APPLE__)
35 #define UNSUPPORTED_ERROR ("Apple simulators aren't supported on this platform")
39 PlatformAppleSimulator::PlatformAppleSimulator(
40 const char *class_name,
const char *description,
ConstString plugin_name,
41 llvm::Triple::OSType preferred_os,
42 llvm::SmallVector<llvm::StringRef, 4> supported_triples,
46 m_description(description), m_plugin_name(plugin_name), m_kind(kind),
47 m_os_type(preferred_os), m_supported_triples(supported_triples),
48 m_sdk(sdk), m_sdk_type(sdk_type) {}
58 #if defined(__APPLE__)
64 device.
Boot(boot_err);
69 auto spawned = device.
Spawn(launch_info);
75 return spawned.GetError();
86 strm <<
" SDK Path: \"" <<
m_sdk <<
"\"\n";
88 strm <<
" SDK Path: error: unable to locate SDK\n";
90 #if defined(__APPLE__)
95 std::string developer_dir = HostInfo::GetXcodeDeveloperDirectory().GetPath();
98 developer_dir.c_str());
101 strm.
Printf(
"Available devices:\n");
102 for (
size_t i = 0; i < num_devices; ++i) {
104 strm <<
" " << device.
GetUDID() <<
": " << device.
GetName() <<
"\n";
108 strm <<
"Current device: " <<
m_device->GetUDID() <<
": "
111 strm <<
" state = booted";
113 strm <<
"\nType \"platform connect <ARG>\" where <ARG> is a device "
114 "UDID or a device name to disconnect and connect to a "
115 "different device.\n";
118 strm <<
"No current device is selected, \"platform connect <ARG>\" "
119 "where <ARG> is a device UDID or a device name to connect to "
120 "a specific device.\n";
124 strm <<
"No devices are available.\n";
132 #if defined(__APPLE__)
141 std::string developer_dir = HostInfo::GetXcodeDeveloperDirectory().GetPath();
144 developer_dir.c_str());
155 error.SetErrorStringWithFormat(
156 "no device with UDID or name '%s' was found", arg_cstr);
159 error.SetErrorString(
"this command take a single UDID argument of the "
160 "device you want to connect to.");
171 #if defined(__APPLE__)
185 #if defined(__APPLE__)
186 ProcessSP process_sp;
195 if (
error.Success()) {
198 process_sp =
Attach(attach_info, debugger, &target,
error);
206 process_sp->SetShouldDetach(
false);
214 process_sp->SetSTDIOFileDescriptor(pty_fd);
227 #if defined(__APPLE__)
231 FileSpec(
"/Library/Developer/PrivateFrameworks/CoreSimulator.framework/"
242 #if defined(__APPLE__)
243 static llvm::once_flag g_load_core_sim_flag;
244 llvm::call_once(g_load_core_sim_flag, [
this] {
246 if (core_sim_path.size())
247 dlopen(core_sim_path.c_str(), RTLD_LAZY);
252 #if defined(__APPLE__)
256 std::string developer_dir = HostInfo::GetXcodeDeveloperDirectory().GetPath();
258 developer_dir.c_str())
270 const ArchSpec &process_host_arch) {
273 [](llvm::StringRef triple) { return ArchSpec(triple); });
280 sdk = HostInfo::GetXcodeSDKPath(
XcodeSDK(std::move(preferred)));
282 sdk = HostInfo::GetXcodeSDKPath(
XcodeSDK(std::move(secondary)));
287 const char *class_name,
const char *description,
ConstString plugin_name,
288 llvm::SmallVector<llvm::Triple::ArchType, 4> supported_arch,
289 llvm::Triple::OSType preferred_os,
290 llvm::SmallVector<llvm::Triple::OSType, 4> supported_os,
291 llvm::SmallVector<llvm::StringRef, 4> supported_triples,
298 const char *arch_name;
302 arch_name =
"<null>";
304 const char *triple_cstr =
305 arch ? arch->
GetTriple().getTriple().c_str() :
"<null>";
307 LLDB_LOGF(log,
"%s::%s(force=%s, arch={%s,%s})", class_name, __FUNCTION__,
308 force ?
"true" :
"false", arch_name, triple_cstr);
312 if (!create && arch && arch->
IsValid()) {
313 if (std::count(supported_arch.begin(), supported_arch.end(),
315 const llvm::Triple &triple = arch->
GetTriple();
316 switch (triple.getVendor()) {
317 case llvm::Triple::Apple:
321 #if defined(__APPLE__)
325 case llvm::Triple::UnknownVendor:
334 if (std::count(supported_os.begin(), supported_os.end(), triple.getOS()))
336 #if defined(__APPLE__)
340 else if (triple.getOS() == llvm::Triple::UnknownOS)
349 LLDB_LOGF(log,
"%s::%s() creating platform", class_name, __FUNCTION__);
351 llvm::StringRef sdk =
354 class_name, description, plugin_name, preferred_os, supported_triples,
355 sdk, sdk_type, kind));
358 LLDB_LOGF(log,
"%s::%s() aborting creation of platform", class_name,
365 const ModuleSpec &module_spec, lldb::ModuleSP &exe_module_sp,
366 const FileSpecList *module_search_paths_ptr) {
388 if (exe_module_sp && exe_module_sp->GetObjectFile())
390 exe_module_sp.reset();
396 llvm::ListSeparator LS;
408 if (
error.Success()) {
409 if (exe_module_sp && exe_module_sp->GetObjectFile())
412 error.SetErrorToGenericError();
419 if (
error.Fail() || !exe_module_sp) {
421 error.SetErrorStringWithFormatv(
422 "'{0}' doesn't contain any '{1}' platform architectures: {2}",
426 error.SetErrorStringWithFormat(
427 "'%s' is not readable",
432 error.SetErrorStringWithFormat(
"'%s' does not exist",
440 const UUID *uuid_ptr,
444 if (platform_file.
GetPath(platform_file_path,
sizeof(platform_file_path))) {
447 if (!
m_sdk.empty()) {
448 ::snprintf(resolved_path,
sizeof(resolved_path),
"%s/%s",
449 m_sdk.str().c_str(), platform_file_path);
452 local_file.
SetFile(resolved_path, FileSpec::Style::native);
458 local_file.
SetFile(platform_file_path, FileSpec::Style::native);
463 error.SetErrorStringWithFormatv(
464 "unable to locate a platform file for '{0}' in platform '{1}'",
467 error.SetErrorString(
"invalid platform file argument");
474 const FileSpecList *module_search_paths_ptr,
485 if (
error.Success()) {
487 module_search_paths_ptr);
489 const bool always_create =
false;
491 module_search_paths_ptr, old_modules,
492 did_create_ptr, always_create);
495 module_sp->SetPlatformFileSpec(platform_file);
512 triple.getEnvironment() == llvm::Triple::Simulator) {
513 process_infos.push_back(proc_info);
516 return process_infos.size();
525 return !force && arch && arch->
IsValid() &&
550 {llvm::Triple::aarch64, llvm::Triple::x86_64, llvm::Triple::x86},
553 llvm::Triple::Darwin, llvm::Triple::MacOSX,
560 "arm64e-apple-ios-simulator",
"arm64-apple-ios-simulator",
561 "x86_64-apple-ios-simulator",
"x86_64h-apple-ios-simulator",
563 "x86_64h-apple-ios-simulator",
"x86_64-apple-ios-simulator",
564 "i386-apple-ios-simulator",
568 "iPhoneSimulator.Internal.sdk",
"iPhoneSimulator.sdk",
569 XcodeSDK::Type::iPhoneSimulator,
594 {llvm::Triple::aarch64, llvm::Triple::x86_64}, llvm::Triple::TvOS,
595 {llvm::Triple::TvOS},
599 "arm64e-apple-tvos-simulator",
"arm64-apple-tvos-simulator",
600 "x86_64h-apple-tvos-simulator",
"x86_64-apple-tvos-simulator",
602 "x86_64h-apple-tvos-simulator",
"x86_64-apple-tvos-simulator",
606 "AppleTVSimulator.Internal.sdk",
"AppleTVSimulator.sdk",
607 XcodeSDK::Type::AppleTVSimulator,
616 "Apple Watch simulator platform plug-in.";
636 {llvm::Triple::aarch64, llvm::Triple::x86_64, llvm::Triple::x86},
637 llvm::Triple::WatchOS, {llvm::Triple::WatchOS},
641 "arm64e-apple-watchos-simulator",
"arm64-apple-watchos-simulator",
643 "x86_64-apple-watchos-simulator",
"x86_64h-apple-watchos-simulator",
644 "i386-apple-watchos-simulator",
648 "WatchSimulator.Internal.sdk",
"WatchSimulator.sdk",
649 XcodeSDK::Type::WatchSimulator,
static bool ResolveExecutableInBundle(FileSpec &file)
When executable files may live within a directory, where the directory represents an executable bundl...
std::string GetName() const
static uint32_t FindProcesses(const ProcessInstanceInfoMatch &match_info, ProcessInstanceInfoList &proc_infos)
bool TripleVendorWasSpecified() const
#define LLDB_INVALID_PROCESS_ID
llvm::Triple::ArchType GetMachine() const
Returns a machine family for the current architecture.
void ForEach(std::function< bool(const Device &)> f)
Process Spawn(lldb_private::ProcessLaunchInfo &launch_info)
@ invalid_fd
Invalid file descriptor value.
#define LLDB_LOGF(log,...)
An abstraction for Xcode-style SDKs that works like ArchSpec.
lldb::pid_t GetProcessID() const
void SetProcessID(lldb::pid_t pid)
llvm::Triple & GetTriple()
Architecture triple accessor.
void SetHijackListener(const lldb::ListenerSP &listener_sp)
llvm::StringRef GetString() const
static llvm::raw_ostream & error(Stream &strm)
Device GetFanciest(DeviceType::ProductFamilyID dev_id)
static bool UnregisterPlugin(ABICreateInstance create_callback)
bool Fail() const
Test for error condition.
Device GetDeviceAtIndex(size_t idx)
std::string GetUDID() const
bool TripleOSWasSpecified() const
string(SUBSTRING ${p} 10 -1 pStripped) if($
void Resolve(llvm::SmallVectorImpl< char > &path)
Resolve path to make it canonical.
bool IsValid() const
Tests if this ArchSpec is valid.
void SetLaunchInSeparateProcessGroup(bool separate)
PseudoTerminal & GetPTY()
bool TripleEnvironmentWasSpecified() const
int ReleasePrimaryFileDescriptor()
Release the primary file descriptor.
const char * GetArgumentAtIndex(size_t idx) const
Gets the NULL terminated C string argument pointer for the argument at index idx.
const char * GetArchitectureName() const
Returns a static string representing the current architecture.
static DeviceSet GetAvailableDevices(const char *developer_dir)
Type
Different types of Xcode SDKs.
bool Boot(lldb_private::Status &err)
void SetErrorString(llvm::StringRef err_str)
Set the current error string to err_str.
ArchSpec & GetArchitecture()
size_t Printf(const char *format,...) __attribute__((format(printf
Output printf formatted output to the stream.
static FileSystem & Instance()
static bool RegisterPlugin(llvm::StringRef name, llvm::StringRef description, ABICreateInstance create_callback)
ArchSpec & GetArchitecture()
A class that represents a running process on the host machine.
ValueType Set(ValueType mask)
Set one or more flags by logical OR'ing mask with the current flags.
void SetFile(llvm::StringRef path, Style style)
Change the file specified with a new path.
Log * GetLog(Cat mask)
Retrieve the Log object for the channel associated with the given log enum.
size_t GetPath(char *path, size_t max_path_length, bool denormalize=true) const
Extract the full path to the file.
lldb::ListenerSP GetHijackListener() const
size_t GetArgumentCount() const
Gets the number of arguments left in this command object.
std::vector< ProcessInstanceInfo > ProcessInstanceInfoList
static Status GetSharedModule(const ModuleSpec &module_spec, lldb::ModuleSP &module_sp, const FileSpecList *module_search_paths_ptr, llvm::SmallVectorImpl< lldb::ModuleSP > *old_modules, bool *did_create_ptr, bool always_create=false)