From e6d56cb1670cf53944ec0ac7d6c745a0ca0e22c1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Eloy=20Dur=C3=A1n?= Date: Fri, 25 Oct 2013 19:57:49 +0200 Subject: [PATCH 1/3] [10.9] NSTask is unable to launch lldb. Replace with custom task for now. It appears that NSTask was re-written on 10.9 and others have similar issues as well. E.g. https://devforums.apple.com/message/863811#863811. Fixes http://hipbyte.myjetbrains.com/youtrack/issue/RM-295. --- bin/sim.m | 78 +++++++++++++++++++++++++++++++++++++++++++++++++++---- 1 file changed, 73 insertions(+), 5 deletions(-) diff --git a/bin/sim.m b/bin/sim.m index 9db25273..877a076d 100644 --- a/bin/sim.m +++ b/bin/sim.m @@ -27,6 +27,74 @@ - (NSString *)replEval:(NSString *)expression; @end +@interface RMTask : NSObject +@property (strong) NSDictionary *environment; +@property (strong) NSArray *arguments; +@property (strong) NSString *launchPath; +@property (assign) pid_t pid; +@property (assign) int terminationStatus; +@end + +@implementation RMTask + ++ (instancetype)launchedTaskWithLaunchPath:(NSString *)path arguments:(NSArray *)arguments; +{ + RMTask *task = [self new]; + task.launchPath = path; + task.arguments = arguments; + [task launch]; + return [task autorelease]; +} + +- (void)launch; +{ + // NSLog(@"LAUNCH: %@ - %@ - %@", self.launchPath, self.arguments, self.environment); + NSParameterAssert(self.launchPath); + NSDictionary *env = self.environment; + const char *cpath = [self.launchPath UTF8String]; + const char *cargs[self.arguments.count + 1]; + size_t i = 0; + for (NSString *arg in self.arguments) { + cargs[i++] = [arg UTF8String]; + } + cargs[i] = NULL; + pid_t pid = fork(); + if (pid == -1) { + assert(false && "failed to spawn process"); + } + else if (pid == 0) { + for (NSString *name in env) { + setenv([name UTF8String], [env[name] UTF8String], 1); + } + execvp(cpath, (char **)cargs); + assert(false && "failed to exec process"); + } + else { + self.pid = pid; + } +} + +- (void)terminate; +{ + kill(self.pid, SIGTERM); +} + +- (void)waitUntilExit; +{ + pid_t result = 0; + while (result >= 0 && errno != EINTR) { + result = waitpid(self.pid, NULL, 0); + } + self.terminationStatus = (int)result; +} + +- (int)processIdentifier; +{ + return (int)self.pid; +} + +@end + static bool spec_mode = false; static int debug_mode = -1; #define DEBUG_GDB 1 @@ -36,7 +104,7 @@ static int debug_mode = -1; static Delegate *delegate = nil; static NSMutableArray *app_windows_bounds = nil; #if defined(SIMULATOR_IOS) -static NSTask *gdb_task = nil; +static RMTask *gdb_task = nil; static id current_session = nil; static BOOL debugger_killed_session = NO; static NSString *xcode_path = nil; @@ -130,7 +198,7 @@ sigcleanup(int sig) #if defined(SIMULATOR_OSX) -static NSTask *osx_task = nil; +static RMTask *osx_task = nil; static void sigint_osx(int sig) @@ -1028,12 +1096,12 @@ lldb_commands_file(int pid) NSString *gdb_path = [xcode_path stringByAppendingPathComponent:@"Platforms/iPhoneSimulator.platform/Developer/usr/libexec/gdb/gdb-i386-apple-darwin"]; NSString *lldb_path = [xcode_path stringByAppendingPathComponent:@"Platforms/iPhoneSimulator.platform/Developer/usr/bin/lldb"]; if ([[NSFileManager defaultManager] fileExistsAtPath:gdb_path]) { - gdb_task = [[NSTask launchedTaskWithLaunchPath:gdb_path + gdb_task = [[RMTask launchedTaskWithLaunchPath:gdb_path arguments:[NSArray arrayWithObjects:@"--arch", @"i386", @"-q", @"--pid", [pidNumber description], @"-x", gdb_commands_file(), nil]] retain]; } else if ([[NSFileManager defaultManager] fileExistsAtPath:lldb_path]) { - gdb_task = [[NSTask launchedTaskWithLaunchPath:lldb_path + gdb_task = [[RMTask launchedTaskWithLaunchPath:lldb_path arguments:[NSArray arrayWithObjects:@"-a", @"i386", @"-s", lldb_commands_file([pidNumber intValue]), nil]] retain]; } @@ -1275,7 +1343,7 @@ main(int argc, char **argv) [NSThread detachNewThreadSelector:@selector(readEvalPrintLoop) toTarget:delegate withObject:nil]; - osx_task = [[NSTask alloc] init]; + osx_task = [[RMTask alloc] init]; [osx_task setEnvironment:appEnvironment]; [osx_task setLaunchPath:app_path]; [osx_task setArguments:app_args]; From ceeb1cbbf23ed4d23a25a94cb9271fd7beac63dc Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Eloy=20Dur=C3=A1n?= Date: Fri, 25 Oct 2013 20:06:38 +0200 Subject: [PATCH 2/3] [NEWS] 10.9 + iOS debugging --- NEWS | 1 + 1 file changed, 1 insertion(+) diff --git a/NEWS b/NEWS index e8d40754..9dfb172e 100644 --- a/NEWS +++ b/NEWS @@ -18,6 +18,7 @@ is currently experimental and will increase your application bundle size by about 28MB. * [iOS] Fixed a crash when using certain NSIndexPath objects (64-bit only). + * [iOS] Fixed `rake debug=1` on OS X 10.9 not working. = RubyMotion 2.11 = From ac34d37b06378187de4a247c7885518ad13c8cd3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Eloy=20Dur=C3=A1n?= Date: Mon, 28 Oct 2013 11:56:19 +0100 Subject: [PATCH 3/3] [sim] Although it's not leaking in practice, add -[RMTask dealloc] nonetheless. --- bin/sim.m | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/bin/sim.m b/bin/sim.m index 877a076d..b5c932b2 100644 --- a/bin/sim.m +++ b/bin/sim.m @@ -46,6 +46,14 @@ return [task autorelease]; } +- (void)dealloc; +{ + [_environment release]; _environment = nil; + [_arguments release]; _arguments = nil; + [_launchPath release]; _launchPath = nil; + [super dealloc]; +} + - (void)launch; { // NSLog(@"LAUNCH: %@ - %@ - %@", self.launchPath, self.arguments, self.environment);