Index: lldb/packages/Python/lldbsuite/test/dotest.py =================================================================== --- lldb/packages/Python/lldbsuite/test/dotest.py +++ lldb/packages/Python/lldbsuite/test/dotest.py @@ -300,13 +300,6 @@ if args.arch: configuration.arch = args.arch - if configuration.arch.startswith( - 'arm') and platform_system == 'Darwin' and not args.apple_sdk: - configuration.sdkroot = seven.get_command_output( - 'xcrun --sdk iphoneos.internal --show-sdk-path 2> /dev/null') - if not os.path.exists(configuration.sdkroot): - configuration.sdkroot = seven.get_command_output( - 'xcrun --sdk iphoneos --show-sdk-path 2> /dev/null') else: configuration.arch = platform_machine Index: lldb/packages/Python/lldbsuite/test/dotest_args.py =================================================================== --- lldb/packages/Python/lldbsuite/test/dotest_args.py +++ lldb/packages/Python/lldbsuite/test/dotest_args.py @@ -41,7 +41,7 @@ group.add_argument('-C', '--compiler', metavar='compiler', dest='compiler', help=textwrap.dedent( '''Specify the compiler(s) used to build the inferior executables. The compiler path can be an executable basename or a full path to a compiler executable. This option can be specified multiple times.''')) if sys.platform == 'darwin': - group.add_argument('--apple-sdk', metavar='apple_sdk', dest='apple_sdk', default="macosx", help=textwrap.dedent( + group.add_argument('--apple-sdk', metavar='apple_sdk', dest='apple_sdk', default="", help=textwrap.dedent( '''Specify the name of the Apple SDK (macosx, macosx.internal, iphoneos, iphoneos.internal, or path to SDK) and use the appropriate tools from that SDK's toolchain.''')) # FIXME? This won't work for different extra flags according to each arch. group.add_argument( Index: lldb/packages/Python/lldbsuite/test/make/Makefile.rules =================================================================== --- lldb/packages/Python/lldbsuite/test/make/Makefile.rules +++ lldb/packages/Python/lldbsuite/test/make/Makefile.rules @@ -106,52 +106,51 @@ TRIPLE_ENV =$(word 4, $(triple_space)) ifeq "$(TRIPLE_VENDOR)" "apple" ifeq "$(TRIPLE_OS)" "ios" - CODESIGN := codesign - ifeq "$(SDKROOT)" "" - # Set SDKROOT if it wasn't set - ifneq (,$(findstring arm,$(ARCH))) - SDKROOT = $(shell xcrun --sdk iphoneos --show-sdk-path) - ifeq "$(TRIPLE_VERSION)" "" - TRIPLE_VERSION =$(shell echo $(notdir $(SDKROOT)) | sed -e 's/.*\([0-9]\.[0-9]\).*/\1/') - endif - ARCH_CFLAGS :=-mios-version-min=$(TRIPLE_VERSION) -isysroot "$(SDKROOT)" - else - ifeq "$(TRIPLE_ENV)" "macabi" - SDKROOT = $(shell xcrun --sdk macosx --show-sdk-path) - else - SDKROOT = $(shell xcrun --sdk iphonesimulator --show-sdk-path) - endif - ifeq "$(TRIPLE_VERSION)" "" - TRIPLE_VERSION =$(shell echo $(notdir $(SDKROOT)) | sed -e 's/.*\([0-9]\.[0-9]\).*/\1/') - endif - ifeq "$(TRIPLE_ENV)" "macabi" - ARCH_CFLAGS :=-mios-version-min=$(TRIPLE_VERSION) -isysroot "$(SDKROOT)" - else - ARCH_CFLAGS :=-mios-simulator-version-min=$(TRIPLE_VERSION) -isysroot "$(SDKROOT)" - endif - endif + ifeq "$(TRIPLE_ENV)" "simulator" + SDK_NAME := iphonesimulator + else + ifeq "$(TRIPLE_ENV)" "macabi" + SDK_NAME := macosx + else + SDK_NAME := iphoneos + endif + endif + endif + ifeq "$(TRIPLE_OS)" "tvos" + ifeq "$(TRIPLE_ENV)" "simulator" + SDK_NAME := appletvsimulator + else + SDK_NAME := appletvos endif endif ifeq "$(TRIPLE_OS)" "watchos" - CODESIGN := codesign - ifeq "$(SDKROOT)" "" - # Set SDKROOT if it wasn't set - ifneq (,$(findstring arm,$(ARCH))) - SDKROOT = $(shell xcrun --sdk watchos --show-sdk-path) - ifeq "$(TRIPLE_VERSION)" "" - TRIPLE_VERSION =$(shell echo $(notdir $(SDKROOT)) | sed -e 's/.*\([0-9]\.[0-9]\).*/\1/') - endif - ARCH_CFLAGS :=-mwatchos-version-min=$(TRIPLE_VERSION) -isysroot "$(SDKROOT)" - else - SDKROOT = $(shell xcrun --sdk watchsimulator --show-sdk-path) - ifeq "$(TRIPLE_VERSION)" "" - TRIPLE_VERSION =$(shell echo $(notdir $(SDKROOT)) | sed -e 's/.*\([0-9]\.[0-9]\).*/\1/') - endif - ARCH_CFLAGS :=-mwatchos-simulator-version-min=$(TRIPLE_VERSION) -isysroot "$(SDKROOT)" - endif + ifeq "$(TRIPLE_ENV)" "simulator" + SDK_NAME := watchsimulator + else + SDK_NAME := watchos endif endif + ifneq "$(TRIPLE_OS)" "macosx" + ifeq "$(TRIPLE_ENV)" "" + CODESIGN := codesign + endif + endif + + ifeq "$(SDKROOT)" "" + SDKROOT := $(shell xcrun --sdk $(SDK_NAME) --show-sdk-path) + endif + ifeq "$(TRIPLE_VERSION)" "" + TRIPLE_VERSION := $(shell echo $(notdir $(SDKROOT)) | grep -E -o -e '[0-9]+\.[0-9]') + endif + ifeq "$(TRIPLE_ENV)" "simulator" + ARCH_CFLAGS := -m$(TRIPLE_OS)-simulator-version-min=$(TRIPLE_VERSION) + else + ifneq "$(TRIPLE_OS)" "macosx" + ARCH_CFLAGS := -m$(TRIPLE_OS)-version-min=$(TRIPLE_VERSION) + endif + endif endif + ARCH_CFLAGS += -target $(TRIPLE) endif ifeq "$(OS)" "Android" include $(THIS_FILE_DIR)/Android.rules Index: lldb/source/Plugins/Platform/MacOSX/PlatformAppleSimulator.h =================================================================== --- lldb/source/Plugins/Platform/MacOSX/PlatformAppleSimulator.h +++ lldb/source/Plugins/Platform/MacOSX/PlatformAppleSimulator.h @@ -25,7 +25,8 @@ static void Terminate(); // Class Methods - PlatformAppleSimulator(); + PlatformAppleSimulator( + CoreSimulatorSupport::DeviceType::ProductFamilyID kind); virtual ~PlatformAppleSimulator(); @@ -47,6 +48,7 @@ std::mutex m_core_sim_path_mutex; llvm::Optional m_core_simulator_framework_path; llvm::Optional m_device; + CoreSimulatorSupport::DeviceType::ProductFamilyID m_kind; lldb_private::FileSpec GetCoreSimulatorPath(); Index: lldb/source/Plugins/Platform/MacOSX/PlatformAppleSimulator.cpp =================================================================== --- lldb/source/Plugins/Platform/MacOSX/PlatformAppleSimulator.cpp +++ lldb/source/Plugins/Platform/MacOSX/PlatformAppleSimulator.cpp @@ -35,9 +35,9 @@ void PlatformAppleSimulator::Terminate() { PlatformDarwin::Terminate(); } /// Default Constructor -PlatformAppleSimulator::PlatformAppleSimulator() - : PlatformDarwin(true), m_core_sim_path_mutex(), - m_core_simulator_framework_path(), m_device() {} +PlatformAppleSimulator::PlatformAppleSimulator( + CoreSimulatorSupport::DeviceType::ProductFamilyID kind) + : PlatformDarwin(true), m_kind(kind) {} /// Destructor. /// @@ -215,18 +215,11 @@ #if defined(__APPLE__) std::lock_guard guard(m_core_sim_path_mutex); if (!m_core_simulator_framework_path.hasValue()) { - if (FileSpec fspec = HostInfo::GetXcodeDeveloperDirectory()) { - std::string developer_dir = fspec.GetPath(); - StreamString cs_path; - cs_path.Printf( - "%s/Library/PrivateFrameworks/CoreSimulator.framework/CoreSimulator", - developer_dir.c_str()); - m_core_simulator_framework_path = FileSpec(cs_path.GetData()); - FileSystem::Instance().Resolve(*m_core_simulator_framework_path); - } else - m_core_simulator_framework_path = FileSpec(); + m_core_simulator_framework_path = + FileSpec("/Library/Developer/PrivateFrameworks/CoreSimulator.framework/" + "CoreSimulator"); + FileSystem::Instance().Resolve(*m_core_simulator_framework_path); } - return m_core_simulator_framework_path.getValue(); #else return FileSpec(); @@ -247,8 +240,7 @@ #if defined(__APPLE__) CoreSimulatorSupport::Device PlatformAppleSimulator::GetSimulatorDevice() { if (!m_device.hasValue()) { - const CoreSimulatorSupport::DeviceType::ProductFamilyID dev_id = - CoreSimulatorSupport::DeviceType::ProductFamilyID::iPhone; + const CoreSimulatorSupport::DeviceType::ProductFamilyID dev_id = m_kind; std::string developer_dir = HostInfo::GetXcodeDeveloperDirectory().GetPath(); m_device = CoreSimulatorSupport::DeviceSet::GetAvailableDevices( developer_dir.c_str()) Index: lldb/source/Plugins/Platform/MacOSX/PlatformAppleTVSimulator.h =================================================================== --- lldb/source/Plugins/Platform/MacOSX/PlatformAppleTVSimulator.h +++ lldb/source/Plugins/Platform/MacOSX/PlatformAppleTVSimulator.h @@ -9,9 +9,9 @@ #ifndef LLDB_SOURCE_PLUGINS_PLATFORM_MACOSX_PLATFORMAPPLETVSIMULATOR_H #define LLDB_SOURCE_PLUGINS_PLATFORM_MACOSX_PLATFORMAPPLETVSIMULATOR_H -#include "PlatformDarwin.h" +#include "PlatformAppleSimulator.h" -class PlatformAppleTVSimulator : public PlatformDarwin { +class PlatformAppleTVSimulator : public PlatformAppleSimulator { public: // Class Functions static lldb::PlatformSP CreateInstance(bool force, @@ -77,7 +77,7 @@ std::string m_sdk_directory; std::string m_build_update; - const char *GetSDKDirectoryAsCString(); + llvm::StringRef GetSDKDirectoryAsCString(); private: PlatformAppleTVSimulator(const PlatformAppleTVSimulator &) = delete; Index: lldb/source/Plugins/Platform/MacOSX/PlatformAppleTVSimulator.cpp =================================================================== --- lldb/source/Plugins/Platform/MacOSX/PlatformAppleTVSimulator.cpp +++ lldb/source/Plugins/Platform/MacOSX/PlatformAppleTVSimulator.cpp @@ -143,7 +143,8 @@ /// Default Constructor PlatformAppleTVSimulator::PlatformAppleTVSimulator() - : PlatformDarwin(true), m_sdk_dir_mutex(), m_sdk_directory() {} + : PlatformAppleSimulator( + CoreSimulatorSupport::DeviceType::ProductFamilyID::appleTV) {} /// Destructor. /// @@ -153,9 +154,9 @@ void PlatformAppleTVSimulator::GetStatus(Stream &strm) { Platform::GetStatus(strm); - const char *sdk_directory = GetSDKDirectoryAsCString(); - if (sdk_directory) - strm.Printf(" SDK Path: \"%s\"\n", sdk_directory); + llvm::StringRef sdk_directory = GetSDKDirectoryAsCString(); + if (!sdk_directory.empty()) + strm.Printf(" SDK Path: \"%s\"\n", sdk_directory.str().c_str()); else strm.PutCString(" SDK Path: error: unable to locate SDK\n"); } @@ -236,59 +237,12 @@ return error; } -static FileSystem::EnumerateDirectoryResult -EnumerateDirectoryCallback(void *baton, llvm::sys::fs::file_type ft, - llvm::StringRef path) { - if (ft == llvm::sys::fs::file_type::directory_file) { - FileSpec file_spec(path); - const char *filename = file_spec.GetFilename().GetCString(); - if (filename && - strncmp(filename, "AppleTVSimulator", strlen("AppleTVSimulator")) == - 0) { - ::snprintf((char *)baton, PATH_MAX, "%s", filename); - return FileSystem::eEnumerateDirectoryResultQuit; - } - } - return FileSystem::eEnumerateDirectoryResultNext; -} - -const char *PlatformAppleTVSimulator::GetSDKDirectoryAsCString() { - std::lock_guard guard(m_sdk_dir_mutex); - if (m_sdk_directory.empty()) { - if (FileSpec fspec = HostInfo::GetXcodeDeveloperDirectory()) { - std::string developer_dir = fspec.GetPath(); - char sdks_directory[PATH_MAX]; - char sdk_dirname[PATH_MAX]; - sdk_dirname[0] = '\0'; - snprintf(sdks_directory, sizeof(sdks_directory), - "%s/Platforms/AppleTVSimulator.platform/Developer/SDKs", - developer_dir.c_str()); - FileSpec simulator_sdk_spec; - bool find_directories = true; - bool find_files = false; - bool find_other = false; - FileSystem::Instance().EnumerateDirectory( - sdks_directory, find_directories, find_files, find_other, - EnumerateDirectoryCallback, sdk_dirname); - - if (sdk_dirname[0]) { - m_sdk_directory = sdks_directory; - m_sdk_directory.append(1, '/'); - m_sdk_directory.append(sdk_dirname); - return m_sdk_directory.c_str(); - } - } - // Assign a single NULL character so we know we tried to find the device - // support directory and we don't keep trying to find it over and over. - m_sdk_directory.assign(1, '\0'); - } - - // We should have put a single NULL character into m_sdk_directory or it - // should have a valid path if the code gets here - assert(m_sdk_directory.empty() == false); - if (m_sdk_directory[0]) - return m_sdk_directory.c_str(); - return NULL; +llvm::StringRef PlatformAppleTVSimulator::GetSDKDirectoryAsCString() { + llvm::StringRef sdk; + sdk = HostInfo::GetXcodeSDKPath(XcodeSDK("AppleTVSimulator.Internal.sdk")); + if (sdk.empty()) + sdk = HostInfo::GetXcodeSDKPath(XcodeSDK("AppleTVSimulator.sdk")); + return sdk; } Status PlatformAppleTVSimulator::GetSymbolFile(const FileSpec &platform_file, @@ -299,10 +253,10 @@ if (platform_file.GetPath(platform_file_path, sizeof(platform_file_path))) { char resolved_path[PATH_MAX]; - const char *sdk_dir = GetSDKDirectoryAsCString(); - if (sdk_dir) { - ::snprintf(resolved_path, sizeof(resolved_path), "%s/%s", sdk_dir, - platform_file_path); + llvm::StringRef sdk_dir = GetSDKDirectoryAsCString(); + if (!sdk_dir.empty()) { + ::snprintf(resolved_path, sizeof(resolved_path), "%s/%s", + sdk_dir.str().c_str(), platform_file_path); // First try in the SDK and see if the file is in there local_file.SetFile(resolved_path, FileSpec::Style::native); @@ -378,6 +332,7 @@ arch = platform_arch; if (arch.IsValid()) { arch.GetTriple().setOS(llvm::Triple::TvOS); + arch.GetTriple().setEnvironment(llvm::Triple::Simulator); return true; } } Index: lldb/source/Plugins/Platform/MacOSX/PlatformAppleWatchSimulator.h =================================================================== --- lldb/source/Plugins/Platform/MacOSX/PlatformAppleWatchSimulator.h +++ lldb/source/Plugins/Platform/MacOSX/PlatformAppleWatchSimulator.h @@ -9,9 +9,9 @@ #ifndef LLDB_SOURCE_PLUGINS_PLATFORM_MACOSX_PLATFORMAPPLEWATCHSIMULATOR_H #define LLDB_SOURCE_PLUGINS_PLATFORM_MACOSX_PLATFORMAPPLEWATCHSIMULATOR_H -#include "PlatformDarwin.h" +#include "PlatformAppleSimulator.h" -class PlatformAppleWatchSimulator : public PlatformDarwin { +class PlatformAppleWatchSimulator : public PlatformAppleSimulator { public: // Class Functions static lldb::PlatformSP CreateInstance(bool force, @@ -77,7 +77,7 @@ std::string m_sdk_directory; std::string m_build_update; - const char *GetSDKDirectoryAsCString(); + llvm::StringRef GetSDKDirectoryAsCString(); private: PlatformAppleWatchSimulator(const PlatformAppleWatchSimulator &) = delete; Index: lldb/source/Plugins/Platform/MacOSX/PlatformAppleWatchSimulator.cpp =================================================================== --- lldb/source/Plugins/Platform/MacOSX/PlatformAppleWatchSimulator.cpp +++ lldb/source/Plugins/Platform/MacOSX/PlatformAppleWatchSimulator.cpp @@ -76,7 +76,8 @@ bool create = force; if (!create && arch && arch->IsValid()) { switch (arch->GetMachine()) { - case llvm::Triple::x86_64: { + case llvm::Triple::x86_64: + case llvm::Triple::x86: { const llvm::Triple &triple = arch->GetTriple(); switch (triple.getVendor()) { case llvm::Triple::Apple: @@ -143,7 +144,8 @@ /// Default Constructor PlatformAppleWatchSimulator::PlatformAppleWatchSimulator() - : PlatformDarwin(true), m_sdk_directory() {} + : PlatformAppleSimulator( + CoreSimulatorSupport::DeviceType::ProductFamilyID::appleWatch) {} /// Destructor. /// @@ -153,9 +155,9 @@ void PlatformAppleWatchSimulator::GetStatus(Stream &strm) { Platform::GetStatus(strm); - const char *sdk_directory = GetSDKDirectoryAsCString(); - if (sdk_directory) - strm.Printf(" SDK Path: \"%s\"\n", sdk_directory); + llvm::StringRef sdk_directory = GetSDKDirectoryAsCString(); + if (!sdk_directory.empty()) + strm.Printf(" SDK Path: \"%s\"\n", sdk_directory.str().c_str()); else strm.PutCString(" SDK Path: error: unable to locate SDK\n"); } @@ -236,59 +238,12 @@ return error; } -static FileSystem::EnumerateDirectoryResult -EnumerateDirectoryCallback(void *baton, llvm::sys::fs::file_type ft, - llvm::StringRef path) { - if (ft == llvm::sys::fs::file_type::directory_file) { - FileSpec file_spec(path); - const char *filename = file_spec.GetFilename().GetCString(); - if (filename && - strncmp(filename, "AppleWatchSimulator", - strlen("AppleWatchSimulator")) == 0) { - ::snprintf((char *)baton, PATH_MAX, "%s", filename); - return FileSystem::eEnumerateDirectoryResultQuit; - } - } - return FileSystem::eEnumerateDirectoryResultNext; -} - -const char *PlatformAppleWatchSimulator::GetSDKDirectoryAsCString() { - std::lock_guard guard(m_sdk_dir_mutex); - if (m_sdk_directory.empty()) { - if (FileSpec fspec = HostInfo::GetXcodeDeveloperDirectory()) { - std::string developer_dir = fspec.GetPath(); - char sdks_directory[PATH_MAX]; - char sdk_dirname[PATH_MAX]; - sdk_dirname[0] = '\0'; - snprintf(sdks_directory, sizeof(sdks_directory), - "%s/Platforms/AppleWatchSimulator.platform/Developer/SDKs", - developer_dir.c_str()); - FileSpec simulator_sdk_spec; - bool find_directories = true; - bool find_files = false; - bool find_other = false; - FileSystem::Instance().EnumerateDirectory( - sdks_directory, find_directories, find_files, find_other, - EnumerateDirectoryCallback, sdk_dirname); - - if (sdk_dirname[0]) { - m_sdk_directory = sdks_directory; - m_sdk_directory.append(1, '/'); - m_sdk_directory.append(sdk_dirname); - return m_sdk_directory.c_str(); - } - } - // Assign a single NULL character so we know we tried to find the device - // support directory and we don't keep trying to find it over and over. - m_sdk_directory.assign(1, '\0'); - } - - // We should have put a single NULL character into m_sdk_directory or it - // should have a valid path if the code gets here - assert(m_sdk_directory.empty() == false); - if (m_sdk_directory[0]) - return m_sdk_directory.c_str(); - return NULL; +llvm::StringRef PlatformAppleWatchSimulator::GetSDKDirectoryAsCString() { + llvm::StringRef sdk; + sdk = HostInfo::GetXcodeSDKPath(XcodeSDK("WatchSimulator.Internal.sdk")); + if (sdk.empty()) + sdk = HostInfo::GetXcodeSDKPath(XcodeSDK("WatchSimulator.sdk")); + return sdk; } Status PlatformAppleWatchSimulator::GetSymbolFile(const FileSpec &platform_file, @@ -299,10 +254,10 @@ if (platform_file.GetPath(platform_file_path, sizeof(platform_file_path))) { char resolved_path[PATH_MAX]; - const char *sdk_dir = GetSDKDirectoryAsCString(); - if (sdk_dir) { - ::snprintf(resolved_path, sizeof(resolved_path), "%s/%s", sdk_dir, - platform_file_path); + llvm::StringRef sdk_dir = GetSDKDirectoryAsCString(); + if (!sdk_dir.empty()) { + ::snprintf(resolved_path, sizeof(resolved_path), "%s/%s", + sdk_dir.str().c_str(), platform_file_path); // First try in the SDK and see if the file is in there local_file.SetFile(resolved_path, FileSpec::Style::native); @@ -372,13 +327,20 @@ bool PlatformAppleWatchSimulator::GetSupportedArchitectureAtIndex( uint32_t idx, ArchSpec &arch) { - static const ArchSpec platform_arch( - HostInfo::GetArchitecture(HostInfo::eArchKind64)); - if (idx == 0) { - arch = platform_arch; + arch = HostInfo::GetArchitecture(HostInfo::eArchKind32); + if (arch.IsValid()) { + arch.GetTriple().setOS(llvm::Triple::WatchOS); + arch.GetTriple().setEnvironment(llvm::Triple::Simulator); + return true; + } + } + + if (idx == 1) { + arch = HostInfo::GetArchitecture(HostInfo::eArchKind64); if (arch.IsValid()) { arch.GetTriple().setOS(llvm::Triple::WatchOS); + arch.GetTriple().setEnvironment(llvm::Triple::Simulator); return true; } } Index: lldb/source/Plugins/Platform/MacOSX/PlatformiOSSimulator.h =================================================================== --- lldb/source/Plugins/Platform/MacOSX/PlatformiOSSimulator.h +++ lldb/source/Plugins/Platform/MacOSX/PlatformiOSSimulator.h @@ -79,7 +79,7 @@ std::string m_sdk_directory; std::string m_build_update; - const char *GetSDKDirectoryAsCString(); + llvm::StringRef GetSDKDirectoryAsCString(); private: PlatformiOSSimulator(const PlatformiOSSimulator &) = delete; Index: lldb/source/Plugins/Platform/MacOSX/PlatformiOSSimulator.cpp =================================================================== --- lldb/source/Plugins/Platform/MacOSX/PlatformiOSSimulator.cpp +++ lldb/source/Plugins/Platform/MacOSX/PlatformiOSSimulator.cpp @@ -147,8 +147,8 @@ /// Default Constructor PlatformiOSSimulator::PlatformiOSSimulator() - : PlatformAppleSimulator(), m_sdk_dir_mutex(), m_sdk_directory(), - m_build_update() {} + : PlatformAppleSimulator( + CoreSimulatorSupport::DeviceType::ProductFamilyID::iPhone) {} /// Destructor. /// @@ -158,9 +158,9 @@ void PlatformiOSSimulator::GetStatus(Stream &strm) { Platform::GetStatus(strm); - const char *sdk_directory = GetSDKDirectoryAsCString(); - if (sdk_directory) - strm.Printf(" SDK Path: \"%s\"\n", sdk_directory); + llvm::StringRef sdk_directory = GetSDKDirectoryAsCString(); + if (!sdk_directory.empty()) + strm.Printf(" SDK Path: \"%s\"\n", sdk_directory.str().c_str()); else strm.PutCString(" SDK Path: error: unable to locate SDK\n"); PlatformAppleSimulator::GetStatus(strm); @@ -242,58 +242,12 @@ return error; } -static FileSystem::EnumerateDirectoryResult -EnumerateDirectoryCallback(void *baton, llvm::sys::fs::file_type ft, - llvm::StringRef path) { - if (ft == llvm::sys::fs::file_type::directory_file) { - FileSpec file_spec(path); - const char *filename = file_spec.GetFilename().GetCString(); - if (filename && - strncmp(filename, "iPhoneSimulator", strlen("iPhoneSimulator")) == 0) { - ::snprintf((char *)baton, PATH_MAX, "%s", filename); - return FileSystem::eEnumerateDirectoryResultQuit; - } - } - return FileSystem::eEnumerateDirectoryResultNext; -} - -const char *PlatformiOSSimulator::GetSDKDirectoryAsCString() { - std::lock_guard guard(m_sdk_dir_mutex); - if (m_sdk_directory.empty()) { - if (FileSpec fspec = HostInfo::GetXcodeDeveloperDirectory()) { - std::string developer_dir = fspec.GetPath(); - char sdks_directory[PATH_MAX]; - char sdk_dirname[PATH_MAX]; - sdk_dirname[0] = '\0'; - snprintf(sdks_directory, sizeof(sdks_directory), - "%s/Platforms/iPhoneSimulator.platform/Developer/SDKs", - developer_dir.c_str()); - FileSpec simulator_sdk_spec; - bool find_directories = true; - bool find_files = false; - bool find_other = false; - FileSystem::Instance().EnumerateDirectory( - sdks_directory, find_directories, find_files, find_other, - EnumerateDirectoryCallback, sdk_dirname); - - if (sdk_dirname[0]) { - m_sdk_directory = sdks_directory; - m_sdk_directory.append(1, '/'); - m_sdk_directory.append(sdk_dirname); - return m_sdk_directory.c_str(); - } - } - // Assign a single NULL character so we know we tried to find the device - // support directory and we don't keep trying to find it over and over. - m_sdk_directory.assign(1, '\0'); - } - - // We should have put a single NULL character into m_sdk_directory or it - // should have a valid path if the code gets here - assert(m_sdk_directory.empty() == false); - if (m_sdk_directory[0]) - return m_sdk_directory.c_str(); - return NULL; +llvm::StringRef PlatformiOSSimulator::GetSDKDirectoryAsCString() { + llvm::StringRef sdk; + sdk = HostInfo::GetXcodeSDKPath(XcodeSDK("iPhoneSimulator.Internal.sdk")); + if (sdk.empty()) + sdk = HostInfo::GetXcodeSDKPath(XcodeSDK("iPhoneSimulator.sdk")); + return sdk; } Status PlatformiOSSimulator::GetSymbolFile(const FileSpec &platform_file, @@ -304,10 +258,10 @@ if (platform_file.GetPath(platform_file_path, sizeof(platform_file_path))) { char resolved_path[PATH_MAX]; - const char *sdk_dir = GetSDKDirectoryAsCString(); - if (sdk_dir) { - ::snprintf(resolved_path, sizeof(resolved_path), "%s/%s", sdk_dir, - platform_file_path); + llvm::StringRef sdk_dir = GetSDKDirectoryAsCString(); + if (!sdk_dir.empty()) { + ::snprintf(resolved_path, sizeof(resolved_path), "%s/%s", + sdk_dir.str().c_str(), platform_file_path); // First try in the SDK and see if the file is in there local_file.SetFile(resolved_path, FileSpec::Style::native); @@ -385,6 +339,7 @@ arch = platform_arch; if (arch.IsValid()) { arch.GetTriple().setOS(llvm::Triple::IOS); + arch.GetTriple().setEnvironment(llvm::Triple::Simulator); return true; } } else { Index: lldb/source/Plugins/Platform/MacOSX/objcxx/PlatformiOSSimulatorCoreSimulatorSupport.mm =================================================================== --- lldb/source/Plugins/Platform/MacOSX/objcxx/PlatformiOSSimulatorCoreSimulatorSupport.mm +++ lldb/source/Plugins/Platform/MacOSX/objcxx/PlatformiOSSimulatorCoreSimulatorSupport.mm @@ -1,5 +1,4 @@ -//===-- PlatformiOSSimulatorCoreSimulatorSupport.cpp ---------------*- C++ -//-*-===// +//===-- PlatformiOSSimulatorCoreSimulatorSupport.cpp ----------------------===// // // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. // See https://llvm.org/LICENSE.txt for license information. @@ -51,10 +50,12 @@ - (NSUInteger)state; - (BOOL)shutdownWithError:(NSError **)error; - (NSUUID *)UDID; -- (pid_t)spawnWithPath:(NSString *)path - options:(NSDictionary *)options - terminationHandler:(void (^)(int status))terminationHandler - error:(NSError **)error; +- (BOOL)spawnWithPath:(NSString *)path + options:(nullable NSDictionary *)options + terminationQueue:(nullable dispatch_queue_t)terminationQueue + terminationHandler:(nullable void (^)(int status))terminationHandler + pid:(pid_t *_Nullable)pid + error:(NSError *__autoreleasing _Nullable *_Nullable)error; @end CoreSimulatorSupport::Process::Process(lldb::pid_t p) : m_pid(p), m_error() {} @@ -468,9 +469,12 @@ provided, path will be argv[0] */ #define kSimDeviceSpawnWaitForDebugger \ @"wait_for_debugger" /* An NSNumber (bool) */ +#define kSimDeviceSpawnStandalone @"standalone" NSMutableDictionary *options = [[NSMutableDictionary alloc] init]; + options[kSimDeviceSpawnStandalone] = @(YES); + if (launch_info.GetFlags().Test(lldb::eLaunchFlagDebug)) [options setObject:@YES forKey:kSimDeviceSpawnWaitForDebugger]; @@ -527,16 +531,19 @@ NSError *nserror; - pid_t pid = [m_dev + pid_t pid; + BOOL success = [m_dev spawnWithPath:[NSString stringWithUTF8String:launch_info .GetExecutableFile() .GetPath() .c_str()] options:options + terminationQueue:nil terminationHandler:nil + pid:&pid error:&nserror]; - if (pid < 0) { + if (!success) { const char *nserror_string = [[nserror description] UTF8String]; error.SetErrorString(nserror_string ? nserror_string : "unable to launch"); } Index: lldb/test/API/macosx/simulator/Makefile =================================================================== --- /dev/null +++ lldb/test/API/macosx/simulator/Makefile @@ -0,0 +1,3 @@ +C_SOURCES := hello.c + +include Makefile.rules Index: lldb/test/API/macosx/simulator/TestSimulatorPlatform.py =================================================================== --- /dev/null +++ lldb/test/API/macosx/simulator/TestSimulatorPlatform.py @@ -0,0 +1,46 @@ +import lldb +from lldbsuite.test.lldbtest import * +from lldbsuite.test.decorators import * +import lldbsuite.test.lldbutil as lldbutil +import json +import unittest2 + + +class TestSimulatorPlatformLaunching(TestBase): + + mydir = TestBase.compute_mydir(__file__) + NO_DEBUG_INFO_TESTCASE = True + + def run_with(self, arch, platform, os, env): + self.build(dictionary={'TRIPLE': arch+'-apple-'+os+'-'+env, 'ARCH': arch}) + lldbutil.run_to_source_breakpoint(self, "break here", + lldb.SBFileSpec("hello.c")) + self.expect('image list -b -t', + patterns=['a\.out '+arch+'-apple-'+os+'.*-'+env]) + + @skipUnlessDarwin + @skipIfDarwinEmbedded + @apple_simulator_test('iphone') + def test_ios(self): + """Test running an iOS simulator binary""" + self.run_with(arch=self.getArchitecture(), + os='ios', env='simulator', + platform='iphonesimulator') + + @skipUnlessDarwin + @skipIfDarwinEmbedded + @apple_simulator_test('appletv') + def test_tvos(self): + """Test running an tvOS simulator binary""" + self.run_with(arch=self.getArchitecture(), + os='tvos', env='simulator', + platform='appletvsimulator') + + @skipUnlessDarwin + @skipIfDarwinEmbedded + @apple_simulator_test('watch') + def test_watchos(self): + """Test running a 32-bit watchOS simulator binary""" + self.run_with(arch='i386', + os='watchos', env='simulator', + platform='watchsimulator') Index: lldb/test/API/macosx/simulator/hello.c =================================================================== --- /dev/null +++ lldb/test/API/macosx/simulator/hello.c @@ -0,0 +1,5 @@ +void puts(char *); +int main(int argc, char **argv) { + puts("break here\n"); + return 0; +}