diff --git a/ChangeLog b/ChangeLog index f130ffa..2738517 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,18 @@ +2008-12-22 18:36-EST Gregory John Casamento + + * English.lproj/ProjectCenter.gorm: Minor changes. + * Framework/PCEditorManager.m: Cleanup. + * Framework/PCProjectLauncher.m: Cleanup. + * GNUmakefile: New module. + * Headers/Protocols/CodeDebugger.h: New methods + * Modules/Debuggers/ProjectCenter/GNUmakefile: Added debugger + to resources. + * Modules/Debuggers/ProjectCenter/PCDebugger.h + * Modules/Debuggers/ProjectCenter/PCDebugger.m: Changes to talk to + debugger task + * Modules/Debuggers/ProjectCenter/Resources/PCDebugger.gorm: Debugger + gorm file. + 2008-12-23 Sergii Stoian * Documentatio/TODO: move unfinshed tasks from 0.5 to 0.6 release diff --git a/English.lproj/ProjectCenter.gorm/data.info b/English.lproj/ProjectCenter.gorm/data.info index e17240e..3bc8f05 100644 Binary files a/English.lproj/ProjectCenter.gorm/data.info and b/English.lproj/ProjectCenter.gorm/data.info differ diff --git a/English.lproj/ProjectCenter.gorm/objects.gorm b/English.lproj/ProjectCenter.gorm/objects.gorm index 97cc451..1f43102 100644 Binary files a/English.lproj/ProjectCenter.gorm/objects.gorm and b/English.lproj/ProjectCenter.gorm/objects.gorm differ diff --git a/Framework/PCEditorManager.m b/Framework/PCEditorManager.m index e8b423f..7886a96 100644 --- a/Framework/PCEditorManager.m +++ b/Framework/PCEditorManager.m @@ -179,7 +179,6 @@ NSString *PCEditorDidResignActiveNotification = protocol:@protocol(CodeParser) fileName:fileName]; [editor setParser:parser]; - [editor openFileAtPath:filePath editorManager:self editable:editable]; diff --git a/Framework/PCProjectLauncher.m b/Framework/PCProjectLauncher.m index 26c9594..cca3df3 100644 --- a/Framework/PCProjectLauncher.m +++ b/Framework/PCProjectLauncher.m @@ -29,11 +29,12 @@ #include #include #include - +#include #include - #include +#include + #ifndef NOTIFICATION_CENTER #define NOTIFICATION_CENTER [NSNotificationCenter defaultCenter] #endif @@ -208,9 +209,9 @@ enum { NSString *fp = nil; NSString *pn = nil; NSString *gdbPath = nil; - NSArray *args = nil; - NSDistantObject *terminal; NSFileManager *fm = [NSFileManager defaultManager]; + PCBundleManager *bundleManager = [[project projectManager] bundleManager]; + id debugger; // Check if project type is executable if (![project isExecutable]) @@ -222,23 +223,6 @@ enum { return; } - /* - * FIXME: Is it possible to somehow support users that don't have - * Terminal installed ? Maybe with reduced functionality. - */ - - // Get the Terminal application - terminal = (NSDistantObject *)[NSConnection - rootProxyForConnectionWithRegisteredName:@"Terminal" host:nil]; - - if (terminal == nil) - { - NSRunAlertPanel(@"Debug", - @"Run Terminal application first", - @"Close",nil,nil); - [debugButton setState:NSOffState]; - return; - } /* We try in the order: * xxx.debug/xxx (gnustep-make v1, application), @@ -263,17 +247,16 @@ enum { } } -// PCLogInfo(self, @"debug: %@", fp); - if ([fm isExecutableFileAtPath:fp] == NO) { NSRunAlertPanel(@"Debug", - @"Can't execute %@!", + @"No executable! Please build the project first.", @"Abort",nil,nil,pn); [debugButton setState:NSOffState]; return; } + // Debugger gdbPath = [[NSUserDefaults standardUserDefaults] objectForKey:Debugger]; if (gdbPath == nil) @@ -290,17 +273,16 @@ enum { return; } - // Task - args = [[NSArray alloc] initWithObjects:gdbPath, @"--args", fp, nil]; - [terminal terminalRunProgram:AUTORELEASE(gdbPath) - withArguments:args - inDirectory:nil - properties:nil]; + // Debugger + debugger = [bundleManager objectForBundleType: @"debugger" + protocol: @protocol(CodeDebugger) + fileName: [fp stringByDeletingLastPathComponent]]; + [debugger debugExecutableAtPath: fp + withDebugger: gdbPath]; - [debugButton setState:NSOffState]; - - AUTORELEASE(args); + // turn debug button off... + // [debugButton setState:NSOffState]; } - (void)run:(id)sender diff --git a/GNUmakefile b/GNUmakefile index 75e030f..6404779 100644 --- a/GNUmakefile +++ b/GNUmakefile @@ -89,7 +89,8 @@ Modules/Projects/Library/Library.project \ Modules/Projects/ResourceSet/ResourceSet.project \ Modules/Projects/Tool/Tool.project \ Modules/Editors/ProjectCenter/ProjectCenter.editor \ -Modules/Parsers/ProjectCenter/ProjectCenter.parser +Modules/Parsers/ProjectCenter/ProjectCenter.parser \ +Modules/Debuggers/ProjectCenter/ProjectCenter.debugger # # Localization diff --git a/Headers/Protocols/CodeDebugger.h b/Headers/Protocols/CodeDebugger.h index e932bb4..482a1a8 100644 --- a/Headers/Protocols/CodeDebugger.h +++ b/Headers/Protocols/CodeDebugger.h @@ -34,8 +34,7 @@ // ==== Initialization // =========================================================================== -- (id)initWithPath: (NSString *)filePath; -+ (id)debugExecutableAtPath:(NSString *)filePath; +- (void)debugExecutableAtPath:(NSString *)filePath withDebugger: (NSString *)debuggerPath; - (void)show; // =========================================================================== diff --git a/Modules/Debuggers/ProjectCenter/GNUmakefile b/Modules/Debuggers/ProjectCenter/GNUmakefile index a31b4f4..41c78c6 100644 --- a/Modules/Debuggers/ProjectCenter/GNUmakefile +++ b/Modules/Debuggers/ProjectCenter/GNUmakefile @@ -20,7 +20,8 @@ ProjectCenter_LIBRARIES_DEPEND_UPON += # Resource files # ProjectCenter_RESOURCE_FILES= \ - + Resources/PCDebugger.gorm \ + Resources/Info.table # # Header files # diff --git a/Modules/Debuggers/ProjectCenter/PCDebugger.h b/Modules/Debuggers/ProjectCenter/PCDebugger.h index 55bedbc..1ad0bb5 100644 --- a/Modules/Debuggers/ProjectCenter/PCDebugger.h +++ b/Modules/Debuggers/ProjectCenter/PCDebugger.h @@ -12,10 +12,15 @@ id debuggerView; id debuggerWindow; NSString *path; + NSString *debuggerPath; NSTask *debuggerTask; - NSFileHandle *standardInput; - NSFileHandle *standardOutput; - FILE *stdInStream; + NSPipe *standardInput; + NSPipe *standardOutput; + NSPipe *standardError; + NSFileHandle *readHandle; + NSFileHandle *errorReadHandle; + BOOL _isLogging; + BOOL _isErrorLogging; } - (void)putChar:(unichar)ch; diff --git a/Modules/Debuggers/ProjectCenter/PCDebugger.m b/Modules/Debuggers/ProjectCenter/PCDebugger.m index 1cd2546..3015f55 100644 --- a/Modules/Debuggers/ProjectCenter/PCDebugger.m +++ b/Modules/Debuggers/ProjectCenter/PCDebugger.m @@ -2,10 +2,14 @@ #include #include "PCDebugger.h" -#import "PCDebuggerView.h" +#include "PCDebuggerView.h" + +#ifndef NOTIFICATION_CENTER +#define NOTIFICATION_CENTER [NSNotificationCenter defaultCenter] +#endif @implementation PCDebugger -- (id) initWithPath: (NSString *)filePath +- (id) init { if((self = [super init]) != nil) { @@ -14,14 +18,19 @@ { return nil; } - [(PCDebuggerView *)debuggerView setDebugger:self]; + + [(PCDebuggerView *)debuggerView setDebugger:self]; } return self; } -+(id) debugExecutableAtPath: (NSString *)filePath +-(void) debugExecutableAtPath: (NSString *)filePath + withDebugger: (NSString *)debugger { - return [[self alloc] initWithPath: filePath]; + ASSIGN(path,filePath); + ASSIGN(debuggerPath,debugger); + [debuggerWindow setTitle: [NSString stringWithFormat: @"Debugger (%@)",filePath]]; + [self show]; } - (void) show @@ -30,19 +39,196 @@ [self startDebugger]; } +- (void)logErrorString:(NSString *)string +{ + /* + NSArray *items; + + items = [self parseErrorLine:string]; + if (items) + { + [errorArray addObjectsFromArray:items]; + [errorOutput reloadData]; + [errorOutput scrollRowToVisible:[errorArray count]-1]; + } + */ +} + +- (void)logString:(NSString *)str + error:(BOOL)yn + newLine:(BOOL)newLine +{ + NSTextView *out = debuggerView; + + [out replaceCharactersInRange: + NSMakeRange([[out string] length],0) withString:str]; + + if (newLine) + { + [out replaceCharactersInRange: + NSMakeRange([[out string] length], 0) withString:@"\n"]; + } + else + { + [out replaceCharactersInRange: + NSMakeRange([[out string] length], 0) withString:@" "]; + } + + [out scrollRangeToVisible:NSMakeRange([[out string] length], 0)]; + [out setNeedsDisplay:YES]; +} + +- (void)logData:(NSData *)data + error:(BOOL)yn +{ + NSString *dataString; + // NSRange newLineRange; + // NSRange lineRange; + // NSString *lineString; + + dataString = [[NSString alloc] + initWithData:data + encoding:[NSString defaultCStringEncoding]]; + + // Process new data + /* + lineRange.location = 0; + [errorString appendString:dataString]; + while (newLineRange.location != NSNotFound) + { + newLineRange = [errorString rangeOfString:@"\n"]; + if (newLineRange.location < [errorString length]) + { + lineRange.length = newLineRange.location+1; + lineString = [errorString substringWithRange:lineRange]; + [errorString deleteCharactersInRange:lineRange]; + + // [self parseBuildLine:lineString]; + // if (yn) + // { + // [self logErrorString:lineString]; + // } + + [self logString:lineString error:yn newLine:NO]; + } + else + { + newLineRange.location = NSNotFound; + continue; + } + } + */ + [self logString:dataString error:yn newLine:NO]; + + RELEASE(dataString); +} + +- (void)logStdOut:(NSNotification *)aNotif +{ + NSData *data; + + if ((data = [readHandle availableData]) && [data length] > 0) + { + [self logData:data error:NO]; + } + + if (debuggerTask) + { + [readHandle waitForDataInBackgroundAndNotify]; + } + else + { + _isLogging = NO; + [NOTIFICATION_CENTER removeObserver:self + name:NSFileHandleDataAvailableNotification + object:readHandle]; + } +} + +- (void)logErrOut:(NSNotification *)aNotif +{ + NSData *data; + + if ((data = [errorReadHandle availableData]) && [data length] > 0) + { + [self logData:data error:YES]; + } + + if (debuggerTask) + { + [errorReadHandle waitForDataInBackgroundAndNotify]; + } + else + { + _isErrorLogging = NO; + [NOTIFICATION_CENTER removeObserver:self + name:NSFileHandleDataAvailableNotification + object:errorReadHandle]; + } +} + - (void) startDebugger { - debuggerTask = [NSTask launchedTaskWithLaunchPath: @"/usr/bin/gdb" - arguments: NULL]; - standardInput = [debuggerTask standardInput]; - standardOutput = [debuggerTask standardOutput]; + standardOutput = [NSPipe pipe]; + standardError = [NSPipe pipe]; + + readHandle = [standardOutput fileHandleForReading]; + [readHandle waitForDataInBackgroundAndNotify]; - stdInStream = fdopen([standardInput fileDescriptor], "r"); - if (stdInStream == NULL) + [NOTIFICATION_CENTER addObserver:self + selector:@selector(logStdOut:) + name:NSFileHandleDataAvailableNotification + object:readHandle]; + + _isLogging = YES; + standardError = [NSPipe pipe]; + errorReadHandle = [standardError fileHandleForReading]; + [errorReadHandle waitForDataInBackgroundAndNotify]; + + [NOTIFICATION_CENTER addObserver:self + selector:@selector(logErrOut:) + name:NSFileHandleDataAvailableNotification + object:errorReadHandle]; + _isErrorLogging = YES; + + // [statusField setStringValue:buildStatus]; + + // Run make task + [debuggerView setString:@""]; + [NOTIFICATION_CENTER addObserver:self + selector:@selector(debuggerDidTerminate:) + name:NSTaskDidTerminateNotification + object:nil]; + + + debuggerTask = [[NSTask alloc] init]; + [debuggerTask setArguments: [[NSArray alloc] initWithObjects: @"--args", path, nil]]; + [debuggerTask setCurrentDirectoryPath: [path stringByDeletingLastPathComponent]]; + [debuggerTask setLaunchPath: debuggerPath]; + [debuggerTask setStandardOutput: standardOutput]; + [debuggerTask setStandardError: standardError]; + + NS_DURING { - NSLog(@"Error creating file stream input to debugger"); - return; + [debuggerTask launch]; } + NS_HANDLER + { + NSRunAlertPanel(@"Problem Launching Debugger", + [localException reason], + @"OK", nil, nil, nil); + + //Clean up after task is terminated + [[NSNotificationCenter defaultCenter] + postNotificationName:NSTaskDidTerminateNotification + object:debuggerTask]; + } + NS_ENDHANDLER +} + +- (void) debuggerDidTerminate: (NSNotification *)notif +{ + [self logString: @"=== Debugger Terminated ===" error: NO newLine:YES]; } - (void) awakeFromNib @@ -82,6 +268,6 @@ - (void)putChar:(unichar)ch { - fputc(ch, stdInStream); + // fputc(ch, stdInStream); } @end diff --git a/Modules/Debuggers/ProjectCenter/Resources/PCDebugger.gorm/objects.gorm b/Modules/Debuggers/ProjectCenter/Resources/PCDebugger.gorm/objects.gorm index c7aa81d..cf4483e 100644 Binary files a/Modules/Debuggers/ProjectCenter/Resources/PCDebugger.gorm/objects.gorm and b/Modules/Debuggers/ProjectCenter/Resources/PCDebugger.gorm/objects.gorm differ