and delete a bunch (but not all) redundant code. If you compare the remaining implementations of Platform*Simulator.cpp, there is still an obvious leftover cleanup task.
Specifically, this patch
- removes SDK initialization from dotest (there is equivalent but more
complete code in Makefile.rules)
- make Platform*Simulator inherit the generic implementation of
PlatformAppleSimulator (more can be done here)
- simplify the platform logic in Makefile.rules
- replace the custom SDK finding logic in Platform*Simulator with XcodeSDK
- adds a test for each supported simulator
Differential Revision: https://reviews.llvm.org/D81980
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
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(
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)" ""
+ ifeq "$(SDK_NAME)" ""
+ $(error "SDK_NAME is empty")
endif
+ TRIPLE_VERSION := $(shell xcrun --sdk $(SDK_NAME) --show-sdk-version)
+ 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
# Use this one if you want to build one part of the result without debug information:
ifeq "$(OS)" "Darwin"
- CFLAGS_NO_DEBUG = -O0 $(ARCHFLAG) $(ARCH) $(FRAMEWORK_INCLUDES) $(ARCH_CFLAGS) $(CFLAGS_EXTRAS)
+ CFLAGS_NO_DEBUG = -O0 $(ARCHFLAG) $(ARCH) $(FRAMEWORK_INCLUDES) $(ARCH_CFLAGS) $(CFLAGS_EXTRAS) -isysroot "$(SDKROOT)"
else
CFLAGS_NO_DEBUG = -O0 $(ARCHFLAG)$(ARCH) $(FRAMEWORK_INCLUDES) $(ARCH_CFLAGS) $(CFLAGS_EXTRAS)
endif
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.
///
#if defined(__APPLE__)
std::lock_guard<std::mutex> 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();
#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())
static void Terminate();
// Class Methods
- PlatformAppleSimulator();
+ PlatformAppleSimulator(
+ CoreSimulatorSupport::DeviceType::ProductFamilyID kind);
virtual ~PlatformAppleSimulator();
std::mutex m_core_sim_path_mutex;
llvm::Optional<lldb_private::FileSpec> m_core_simulator_framework_path;
llvm::Optional<CoreSimulatorSupport::Device> m_device;
+ CoreSimulatorSupport::DeviceType::ProductFamilyID m_kind;
lldb_private::FileSpec GetCoreSimulatorPath();
/// Default Constructor
PlatformAppleTVSimulator::PlatformAppleTVSimulator()
- : PlatformDarwin(true), m_sdk_dir_mutex(), m_sdk_directory() {}
+ : PlatformAppleSimulator(
+ CoreSimulatorSupport::DeviceType::ProductFamilyID::appleTV) {}
/// Destructor.
///
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");
}
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<std::mutex> 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,
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);
arch = platform_arch;
if (arch.IsValid()) {
arch.GetTriple().setOS(llvm::Triple::TvOS);
+ arch.GetTriple().setEnvironment(llvm::Triple::Simulator);
return true;
}
}
#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,
std::string m_sdk_directory;
std::string m_build_update;
- const char *GetSDKDirectoryAsCString();
+ llvm::StringRef GetSDKDirectoryAsCString();
private:
PlatformAppleTVSimulator(const PlatformAppleTVSimulator &) = delete;
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:
/// Default Constructor
PlatformAppleWatchSimulator::PlatformAppleWatchSimulator()
- : PlatformDarwin(true), m_sdk_directory() {}
+ : PlatformAppleSimulator(
+ CoreSimulatorSupport::DeviceType::ProductFamilyID::appleWatch) {}
/// Destructor.
///
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");
}
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<std::mutex> 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,
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);
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;
}
}
#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,
std::string m_sdk_directory;
std::string m_build_update;
- const char *GetSDKDirectoryAsCString();
+ llvm::StringRef GetSDKDirectoryAsCString();
private:
PlatformAppleWatchSimulator(const PlatformAppleWatchSimulator &) = delete;
/// Default Constructor
PlatformiOSSimulator::PlatformiOSSimulator()
- : PlatformAppleSimulator(), m_sdk_dir_mutex(), m_sdk_directory(),
- m_build_update() {}
+ : PlatformAppleSimulator(
+ CoreSimulatorSupport::DeviceType::ProductFamilyID::iPhone) {}
/// Destructor.
///
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);
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<std::mutex> 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,
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);
arch = platform_arch;
if (arch.IsValid()) {
arch.GetTriple().setOS(llvm::Triple::IOS);
+ arch.GetTriple().setEnvironment(llvm::Triple::Simulator);
return true;
}
} else {
std::string m_sdk_directory;
std::string m_build_update;
- const char *GetSDKDirectoryAsCString();
+ llvm::StringRef GetSDKDirectoryAsCString();
private:
PlatformiOSSimulator(const PlatformiOSSimulator &) = delete;
-//===-- 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.
- (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<NSString *, id> *)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() {}
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];
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");
}
-SRCDIR := $(shell dirname $(realpath $(lastword $(MAKEFILE_LIST))))/
-all: a.c clean
- $(CC) -arch i386 -g -c $(SRCDIR)/a.c
+all: clean $(EXE)
+
+include Makefile.rules
+
+$(EXE): a.c clean
+ $(CC) -isysroot "$(SDKROOT)" -arch i386 -g -c $(SRCDIR)/a.c
ar -q liba-i386.a a.o
ranlib liba-i386.a
- $(CC) -arch x86_64 -g -c $(SRCDIR)/a.c
+ $(CC) -isysroot "$(SDKROOT)" -arch x86_64 -g -c $(SRCDIR)/a.c
ar -q liba-x86_64.a a.o
ranlib liba-x86_64.a
lipo -create -output liba.a liba-i386.a liba-x86_64.a
- $(CC) -g -c $(SRCDIR)/main.c
- $(CC) -o a.out main.o -L. -la
+ $(CC) -isysroot "$(SDKROOT)" -g -c $(SRCDIR)/main.c
+ $(CC) -isysroot "$(SDKROOT)" -o a.out main.o -L. -la
-clean:
+clean::
rm -rf a.o a.out liba-i386.a liba-x86_64.a liba.a $(wildcard *un~ .*un~ main.o *.pyc)
OBJCXX_SOURCES := main.mm myobject.mm
include Makefile.rules
-CFLAGS_NO_DEBUG =
-ifeq "$(OS)" "Darwin"
- CFLAGS_NO_DEBUG += -arch $(ARCH)
-endif
# myobject.o needs to be built without debug info
myobject.o: myobject.mm
-SRCDIR := $(shell dirname $(realpath $(lastword $(MAKEFILE_LIST))))/
-CC ?= clang
+C_SOURCES := main.c
+EXE := TestApp
+all: clean TestApp.app/Contents/MacOS/TestApp
-ifeq "$(ARCH)" ""
- ARCH = x86_64
-endif
+include Makefile.rules
-CFLAGS ?= -g -O0 -arch $(ARCH)
-
-all: TestApp.app/Contents/MacOS/TestApp
-
-TestApp.app/Contents/MacOS/TestApp: $(SRCDIR)/main.c
- $(CC) $(CFLAGS) -o TestApp $<
- rm -rf TestApp.app
+TestApp.app/Contents/MacOS/TestApp: $(EXE) $(DSYM)
cp -r $(SRCDIR)/TestApp.app .
mv TestApp TestApp.app/Contents/MacOS/TestApp
mv TestApp.dSYM TestApp.app.dSYM
+
+clean::
+ rm -rf $(EXE) TestApp.app TestApp.app.dSYM
Make sure we can find the binary inside an app bundle.
"""
-
-
import lldb
from lldbsuite.test.decorators import *
import lldbsuite.test.lldbutil as lldbutil
NO_DEBUG_INFO_TESTCASE = True
def test_find_app_in_bundle(self):
- """There can be many tests in a test case - describe this test here."""
- self.build()
- self.main_source_file = lldb.SBFileSpec("main.c")
- self.find_app_in_bundle_test()
-
- def find_app_in_bundle_test(self):
"""This reads in the .app, makes sure we get the right binary and can run it."""
-
- # This function starts a process, "a.out" by default, sets a source
- # breakpoint, runs to it, and returns the thread, process & target.
- # It optionally takes an SBLaunchOption argument if you want to pass
- # arguments or environment variables.
- exe = self.getBuildArtifact("TestApp.app")
- error = lldb.SBError()
- target = self.dbg.CreateTarget(exe, None, None, False, error)
- self.assertTrue(error.Success(), "Could not create target: %s"%(error.GetCString()))
- self.assertTrue(target.IsValid(), "Target: TestApp.app is not valid.")
- exe_module_spec = target.GetExecutable()
- self.assertTrue(exe_module_spec.GetFilename(), "TestApp")
-
- bkpt = target.BreakpointCreateBySourceRegex("Set a breakpoint here", self.main_source_file)
- self.assertEquals(bkpt.GetNumLocations(), 1, "Couldn't set a breakpoint in the main app")
-
- if lldbplatformutil.getPlatform() == "macosx":
- launch_info = lldb.SBLaunchInfo(None)
- launch_info.SetWorkingDirectory(self.get_process_working_directory())
-
- error = lldb.SBError()
- process = target.Launch(launch_info, error)
-
- self.assertTrue(process.IsValid(), "Could not create a valid process for TestApp: %s"%(error.GetCString()))
-
- # Frame #0 should be at our breakpoint.
- threads = lldbutil.get_threads_stopped_at_breakpoint(process, bkpt)
-
- self.assertEquals(len(threads), 1, "Expected 1 thread to stop at breakpoint, %d did."%(len(threads)))
-
-
+ self.build()
+ lldbutil.run_to_source_breakpoint(
+ self, 'breakpoint here', lldb.SBFileSpec('main.c'),
+ exe_name=self.getBuildArtifact("TestApp.app"))
-SRCDIR := $(shell dirname $(realpath $(lastword $(MAKEFILE_LIST))))/
-CC ?= clang
+EXE := find-bundle-with-dots-in-fn
-ifeq "$(ARCH)" ""
- ARCH = x86_64
-endif
+all: clean $(EXE)
-CFLAGS ?= -g -O0 -arch $(ARCH)
+include Makefile.rules
-all: clean
+$(EXE):
$(CC) $(CFLAGS) -dynamiclib -o com.apple.sbd $(SRCDIR)/bundle.c
mkdir com.apple.sbd.xpc
mv com.apple.sbd com.apple.sbd.xpc/
tar cf - com.apple.sbd.xpc com.apple.sbd.xpc.dSYM | ( cd hide.app;tar xBpf -)
$(CC) $(CFLAGS) -o find-bundle-with-dots-in-fn $(SRCDIR)/main.c
-clean:
+clean::
rm -rf a.out a.out.dSYM hide.app com.apple.sbd com.apple.sbd.dSYM com.apple.sbd.xpc com.apple.sbd.xpc.dSYM find-bundle-with-dots-in-fn find-bundle-with-dots-in-fn.dSYM
mydir = TestBase.compute_mydir(__file__)
- @skipIfRemote
- @skipUnlessDarwin
- # This test is explicitly a dSYM test, it doesn't need to run for any other config, but
- # the following doesn't work, fixme.
- # @skipIf(debug_info=no_match(["dsym"]), bugnumber="This test is looking explicitly for a dSYM")
-
def setUp(self):
TestBase.setUp(self)
self.source = 'main.c'
# Call super's tearDown().
TestBase.tearDown(self)
+ @skipIfRemote
+ @skipUnlessDarwin
+ # This test is explicitly a dSYM test, it doesn't need to run for any other config.
+ @skipIf(debug_info=no_match(["dsym"]))
def test_attach_and_check_dsyms(self):
"""Test attach to binary, see if the bundle dSYM is found"""
exe = self.getBuildArtifact(exe_name)
-SRCDIR := $(shell dirname $(realpath $(lastword $(MAKEFILE_LIST))))/
-CC ?= clang
+EXE := deep-bundle
+all: clean $(EXE)
-ifeq "$(ARCH)" ""
- ARCH = x86_64
-endif
+include Makefile.rules
-CFLAGS ?= -g -O0 -arch $(ARCH)
-
-all: clean
+$(EXE):
$(CC) $(CFLAGS) -install_name $(shell pwd)/MyFramework.framework/Versions/A/MyFramework -dynamiclib -o MyFramework $(SRCDIR)/myframework.c
mkdir -p MyFramework.framework/Versions/A/Headers
mkdir -p MyFramework.framework/Versions/A/Resources
tar cf - MyFramework.framework MyFramework.framework.dSYM | ( cd hide.app;tar xBpf -)
$(CC) $(CFLAGS) -o deep-bundle $(SRCDIR)/main.c -F. -framework MyFramework
-
-clean:
+clean::
rm -rf a.out a.out.dSYM deep-bundle deep-bundle.dSYM MyFramework.framework MyFramework.framework.dSYM MyFramework MyFramework.dSYM hide.app
mydir = TestBase.compute_mydir(__file__)
- @skipIfRemote
- @skipUnlessDarwin
- # This test is explicitly a dSYM test, it doesn't need to run for any other config, but
- # the following doesn't work, fixme.
- # @skipIf(debug_info=no_match(["dsym"]), bugnumber="This test is looking explicitly for a dSYM")
-
def setUp(self):
TestBase.setUp(self)
self.source = 'main.c'
# Call super's tearDown().
TestBase.tearDown(self)
+ @skipIfRemote
+ @skipUnlessDarwin
+ # This test is explicitly a dSYM test, it doesn't need to run for any other config.
+ @skipIf(debug_info=no_match(["dsym"]))
def test_attach_and_check_dsyms(self):
"""Test attach to binary, see if the framework dSYM is found"""
exe = self.getBuildArtifact(exe_name)
i=i+1
self.assertTrue(found_module, "Check that we found the framework loaded in lldb's image list")
-
-if __name__ == '__main__':
- unittest.main()
--- /dev/null
+C_SOURCES := hello.c
+
+include Makefile.rules
--- /dev/null
+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')
--- /dev/null
+void puts(char *);
+int main(int argc, char **argv) {
+ puts("break here\n");
+ return 0;
+}
lipo -create -o testit $^
testit.x86_64h: testit.x86_64h.o
- $(CC) -arch x86_64h -o testit.x86_64h $<
+ $(CC) -isysroot $(SDKROOT) -arch x86_64h -o testit.x86_64h $<
testit.x86_64: testit.x86_64.o
- $(CC) -arch x86_64 -o testit.x86_64 $<
+ $(CC) -isysroot $(SDKROOT) -arch x86_64 -o testit.x86_64 $<
testit.x86_64h.o: main.c
- $(CC) -g -O0 -arch x86_64h -c -o testit.x86_64h.o $<
+ $(CC) -isysroot $(SDKROOT) -g -O0 -arch x86_64h -c -o testit.x86_64h.o $<
testit.x86_64.o: main.c
- $(CC) -g -O0 -arch x86_64 -c -o testit.x86_64.o $<
+ $(CC) -isysroot $(SDKROOT) -g -O0 -arch x86_64 -c -o testit.x86_64.o $<