27#include "llvm/Support/Threading.h"
35#if !defined(__APPLE__)
36#define UNSUPPORTED_ERROR ("Apple simulators aren't supported on this platform")
41 const char *class_name,
const char *description,
ConstString plugin_name,
42 llvm::Triple::OSType preferred_os,
43 llvm::SmallVector<llvm::StringRef, 4> supported_triples,
44 std::string sdk_name_primary, std::string sdk_name_secondary,
48 m_description(description), m_plugin_name(plugin_name), m_kind(kind),
49 m_os_type(preferred_os), m_supported_triples(supported_triples),
50 m_sdk_name_primary(std::move(sdk_name_primary)),
51 m_sdk_name_secondary(std::move(sdk_name_secondary)),
52 m_sdk_type(sdk_type) {}
68 device.
Boot(boot_err);
73 auto spawned = device.
Spawn(launch_info);
79 return spawned.GetError();
91 strm <<
" SDK Path: \"" << sdk <<
"\"\n";
93 strm <<
" SDK Path: error: unable to locate SDK\n";
100 std::string developer_dir = HostInfo::GetXcodeDeveloperDirectory().GetPath();
103 developer_dir.c_str());
106 strm.
Printf(
"Available devices:\n");
107 for (
size_t i = 0; i < num_devices; ++i) {
109 strm <<
" " << device.
GetUDID() <<
": " << device.
GetName() <<
"\n";
113 strm <<
"Current device: " <<
m_device->GetUDID() <<
": "
116 strm <<
" state = booted";
118 strm <<
"\nType \"platform connect <ARG>\" where <ARG> is a device "
119 "UDID or a device name to disconnect and connect to a "
120 "different device.\n";
123 strm <<
"No current device is selected, \"platform connect <ARG>\" "
124 "where <ARG> is a device UDID or a device name to connect to "
125 "a specific device.\n";
129 strm <<
"No devices are available.\n";
137#if defined(__APPLE__)
145 std::string arg_str(arg_cstr);
146 std::string developer_dir = HostInfo::GetXcodeDeveloperDirectory().GetPath();
149 developer_dir.c_str());
160 error.SetErrorStringWithFormat(
161 "no device with UDID or name '%s' was found", arg_cstr);
164 error.SetErrorString(
"this command take a single UDID argument of the "
165 "device you want to connect to.");
176#if defined(__APPLE__)
190#if defined(__APPLE__)
200 if (
error.Success()) {
203 process_sp =
Attach(attach_info, debugger, &target,
error);
211 process_sp->SetShouldDetach(
false);
219 process_sp->SetSTDIOFileDescriptor(pty_fd);
232#if defined(__APPLE__)
236 FileSpec(
"/Library/Developer/PrivateFrameworks/CoreSimulator.framework/"
247#if defined(__APPLE__)
248 static llvm::once_flag g_load_core_sim_flag;
249 llvm::call_once(g_load_core_sim_flag, [
this] {
251 if (core_sim_path.size())
252 dlopen(core_sim_path.c_str(), RTLD_LAZY);
257#if defined(__APPLE__)
261 std::string developer_dir =
262 HostInfo::GetXcodeDeveloperDirectory().GetPath();
264 developer_dir.c_str())
276 const ArchSpec &process_host_arch) {
279 [](llvm::StringRef triple) { return ArchSpec(triple); });
284 std::string secondary) {
286 auto get_sdk = [&](std::string sdk) -> llvm::StringRef {
287 auto sdk_path_or_err =
288 HostInfo::GetSDKRoot(HostInfo::SDKOptions{
XcodeSDK(std::move(sdk))});
289 if (!sdk_path_or_err) {
291 toString(sdk_path_or_err.takeError()));
294 return *sdk_path_or_err;
297 sdk = get_sdk(preferred);
299 sdk = get_sdk(secondary);
312 const char *class_name,
const char *description,
ConstString plugin_name,
313 llvm::SmallVector<llvm::Triple::ArchType, 4> supported_arch,
314 llvm::Triple::OSType preferred_os,
315 llvm::SmallVector<llvm::Triple::OSType, 4> supported_os,
316 llvm::SmallVector<llvm::StringRef, 4> supported_triples,
317 std::string sdk_name_primary, std::string sdk_name_secondary,
323 const char *arch_name;
327 arch_name =
"<null>";
329 const char *triple_cstr =
330 arch ? arch->
GetTriple().getTriple().c_str() :
"<null>";
332 LLDB_LOGF(log,
"%s::%s(force=%s, arch={%s,%s})", class_name, __FUNCTION__,
333 force ?
"true" :
"false", arch_name, triple_cstr);
337 if (!create && arch && arch->
IsValid()) {
338 if (llvm::is_contained(supported_arch, arch->
GetMachine())) {
339 const llvm::Triple &triple = arch->
GetTriple();
340 switch (triple.getVendor()) {
341 case llvm::Triple::Apple:
345#if defined(__APPLE__)
349 case llvm::Triple::UnknownVendor:
358 if (llvm::is_contained(supported_os, triple.getOS()))
360#if defined(__APPLE__)
364 else if (triple.getOS() == llvm::Triple::UnknownOS)
373 LLDB_LOGF(log,
"%s::%s() creating platform", class_name, __FUNCTION__);
376 class_name, description, plugin_name, preferred_os, supported_triples,
377 sdk_name_primary, sdk_name_secondary, sdk_type, kind));
380 LLDB_LOGF(log,
"%s::%s() aborting creation of platform", class_name,
387 const UUID *uuid_ptr,
391 if (platform_file.
GetPath(platform_file_path,
sizeof(platform_file_path))) {
396 ::snprintf(resolved_path,
sizeof(resolved_path),
"%s/%s",
397 sdk.str().c_str(), platform_file_path);
400 local_file.
SetFile(resolved_path, FileSpec::Style::native);
406 local_file.
SetFile(platform_file_path, FileSpec::Style::native);
411 error.SetErrorStringWithFormatv(
412 "unable to locate a platform file for '{0}' in platform '{1}'",
415 error.SetErrorString(
"invalid platform file argument");
433 if (
error.Success()) {
435 module_search_paths_ptr);
437 const bool always_create =
false;
439 module_search_paths_ptr, old_modules,
440 did_create_ptr, always_create);
443 module_sp->SetPlatformFileSpec(platform_file);
456 for (uint32_t i = 0; i < n; ++i) {
460 triple.getEnvironment() == llvm::Triple::Simulator) {
461 process_infos.push_back(proc_info);
464 return process_infos.size();
473 return !force && arch && arch->
IsValid() &&
498 {llvm::Triple::aarch64, llvm::Triple::x86_64, llvm::Triple::x86},
501 llvm::Triple::Darwin, llvm::Triple::MacOSX,
508 "arm64e-apple-ios-simulator",
"arm64-apple-ios-simulator",
509 "x86_64-apple-ios-simulator",
"x86_64h-apple-ios-simulator",
511 "x86_64h-apple-ios-simulator",
"x86_64-apple-ios-simulator",
512 "i386-apple-ios-simulator",
516 "iPhoneSimulator.Internal.sdk",
"iPhoneSimulator.sdk",
517 XcodeSDK::Type::iPhoneSimulator,
542 {llvm::Triple::aarch64, llvm::Triple::x86_64}, llvm::Triple::TvOS,
543 {llvm::Triple::TvOS},
547 "arm64e-apple-tvos-simulator",
"arm64-apple-tvos-simulator",
548 "x86_64h-apple-tvos-simulator",
"x86_64-apple-tvos-simulator",
550 "x86_64h-apple-tvos-simulator",
"x86_64-apple-tvos-simulator",
554 "AppleTVSimulator.Internal.sdk",
"AppleTVSimulator.sdk",
555 XcodeSDK::Type::AppleTVSimulator,
564 "Apple Watch simulator platform plug-in.";
584 {llvm::Triple::aarch64, llvm::Triple::x86_64, llvm::Triple::x86},
585 llvm::Triple::WatchOS, {llvm::Triple::WatchOS},
589 "arm64e-apple-watchos-simulator",
"arm64-apple-watchos-simulator",
591 "x86_64-apple-watchos-simulator",
"x86_64h-apple-watchos-simulator",
592 "i386-apple-watchos-simulator",
596 "WatchSimulator.Internal.sdk",
"WatchSimulator.sdk",
597 XcodeSDK::Type::WatchSimulator,
621 {llvm::Triple::aarch64, llvm::Triple::x86_64, llvm::Triple::x86},
622 llvm::Triple::XROS, {llvm::Triple::XROS},
626 "arm64e-apple-xros-simulator",
"arm64-apple-xros-simulator",
628 "x86_64-apple-xros-simulator",
"x86_64h-apple-xros-simulator",
632 "XRSimulator.Internal.sdk",
"XRSimulator.sdk",
633 XcodeSDK::Type::XRSimulator,
static llvm::raw_ostream & error(Stream &strm)
#define LLDB_LOGF(log,...)
static DeviceSet GetAvailableDevices(const char *developer_dir)
Device GetFanciest(DeviceType::ProductFamilyID dev_id)
void ForEach(std::function< bool(const Device &)> f)
Device GetDeviceAtIndex(size_t idx)
Process Spawn(lldb_private::ProcessLaunchInfo &launch_info)
std::string GetUDID() const
std::string GetName() const
bool Boot(lldb_private::Status &err)
An architecture specification class.
bool IsValid() const
Tests if this ArchSpec is valid.
llvm::Triple & GetTriple()
Architecture triple accessor.
bool TripleEnvironmentWasSpecified() const
llvm::Triple::ArchType GetMachine() const
Returns a machine family for the current architecture.
bool TripleVendorWasSpecified() const
bool TripleOSWasSpecified() const
const char * GetArchitectureName() const
Returns a static string representing the current architecture.
A command line argument class.
size_t GetArgumentCount() const
Gets the number of arguments left in this command object.
const char * GetArgumentAtIndex(size_t idx) const
Gets the NULL terminated C string argument pointer for the argument at index idx.
A uniqued constant string class.
A class to manage flag bits.
static void ReportError(std::string message, std::optional< lldb::user_id_t > debugger_id=std::nullopt, std::once_flag *once=nullptr)
Report error events.
void SetFile(llvm::StringRef path, Style style)
Change the file specified with a new path.
size_t GetPath(char *path, size_t max_path_length, bool denormalize=true) const
Extract the full path to the file.
void Resolve(llvm::SmallVectorImpl< char > &path)
Resolve path to make it canonical.
static FileSystem & Instance()
ValueType Set(ValueType mask)
Set one or more flags by logical OR'ing mask with the current flags.
static uint32_t FindProcesses(const ProcessInstanceInfoMatch &match_info, ProcessInstanceInfoList &proc_infos)
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)
static bool RegisterPlugin(llvm::StringRef name, llvm::StringRef description, ABICreateInstance create_callback)
static bool UnregisterPlugin(ABICreateInstance create_callback)
void SetHijackListener(const lldb::ListenerSP &listener_sp)
lldb::ListenerSP GetHijackListener() const
lldb::pid_t GetProcessID() const
void SetProcessID(lldb::pid_t pid)
ArchSpec & GetArchitecture()
PseudoTerminal & GetPTY()
void SetLaunchInSeparateProcessGroup(bool separate)
A plug-in interface definition class for debugging a process.
int ReleasePrimaryFileDescriptor()
Release the primary file descriptor.
@ invalid_fd
Invalid file descriptor value.
bool Fail() const
Test for error condition.
void SetErrorString(llvm::StringRef err_str)
Set the current error string to err_str.
A stream class that can stream formatted output to a file.
size_t Printf(const char *format,...) __attribute__((format(printf
Output printf formatted output to the stream.
An abstraction for Xcode-style SDKs that works like ArchSpec.
Type
Different types of Xcode SDKs.
#define LLDB_INVALID_PROCESS_ID
A class that represents a running process on the host machine.
Log * GetLog(Cat mask)
Retrieve the Log object for the channel associated with the given log enum.
std::vector< ProcessInstanceInfo > ProcessInstanceInfoList
const char * toString(AppleArm64ExceptionClass EC)
std::shared_ptr< lldb_private::Platform > PlatformSP
std::shared_ptr< lldb_private::Process > ProcessSP
std::shared_ptr< lldb_private::Module > ModuleSP