From 71a0c53576c39b2a7ba80d9d9ab86ff10fee3661 Mon Sep 17 00:00:00 2001 From: Gregory John Casamento Date: Tue, 3 May 2016 23:41:18 +0000 Subject: [PATCH] Parser code for MI output git-svn-id: svn+ssh://svn.gna.org/svn/gnustep/apps/projectcenter/trunk@39720 72102866-910b-0410-8b05-ffd578937521 --- ChangeLog | 7 ++ .../Debuggers/ProjectCenter/PipeDelegate.h | 16 +++ .../Debuggers/ProjectCenter/PipeDelegate.m | 102 ++++++++++++++++-- 3 files changed, 114 insertions(+), 11 deletions(-) diff --git a/ChangeLog b/ChangeLog index 6099032..a05e89f 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,10 @@ +2016-05-03 19:40-EDT Gregory John Casamento + + * Modules/Debuggers/ProjectCenter/PipeDelegate.h + * Modules/Debuggers/ProjectCenter/PipeDelegate.m: Add parsers + to handle output from various types of MI data. Code to handle + each individual case is being written. + 2016-05-03 18:00-EDT Gregory John Casamento * Modules/Debuggers/ProjectCenter/PCDebugger.m diff --git a/Modules/Debuggers/ProjectCenter/PipeDelegate.h b/Modules/Debuggers/ProjectCenter/PipeDelegate.h index 94e9d9f..48708ac 100644 --- a/Modules/Debuggers/ProjectCenter/PipeDelegate.h +++ b/Modules/Debuggers/ProjectCenter/PipeDelegate.h @@ -26,6 +26,21 @@ #import "PCDebuggerViewDelegateProtocol.h" +typedef enum PCDebuggerOutputType_enum { + PCDBNotFoundRecord = 0, + PCDBPromptRecord, + PCDBResultRecord, + PCDBConsoleStreamRecord, + PCDBTargetStreamRecord, + PCDBDebugStreamRecord, + PCDBAsyncStatusRecord, + PCDBAsyncInfoRecord, + PCDBBreakpointRecord, + PCDBFrameRecord, + PCDBThreadRecord, + PCDBAdaExceptionRecord +} PCDebuggerOutputTypes; + @interface PipeDelegate : NSObject { PCDebugger *debugger; @@ -39,6 +54,7 @@ NSColor *debuggerColor; NSColor *messageColor; NSColor *errorColor; + NSColor *promptColor; } - (void)logStdOut:(NSNotification *)aNotif; diff --git a/Modules/Debuggers/ProjectCenter/PipeDelegate.m b/Modules/Debuggers/ProjectCenter/PipeDelegate.m index eb0d272..a493c38 100644 --- a/Modules/Debuggers/ProjectCenter/PipeDelegate.m +++ b/Modules/Debuggers/ProjectCenter/PipeDelegate.m @@ -42,7 +42,6 @@ #define NOTIFICATION_CENTER [NSNotificationCenter defaultCenter] #endif - @implementation PipeDelegate @@ -54,6 +53,7 @@ debuggerColor = [[NSColor blackColor] retain]; messageColor = [[NSColor brownColor] retain]; errorColor = [[NSColor redColor] retain]; + promptColor = [[NSColor purpleColor] retain]; } return self; } @@ -118,6 +118,7 @@ NSMutableDictionary *textAttributes; NSAttributedString *attrStr; + if (newLine) { str = [str stringByAppendingString:@"\n"]; @@ -142,13 +143,20 @@ [tView setNeedsDisplay:YES]; } -- (BOOL) parseStringLine: (NSString *)stringInput +- (PCDebuggerOutputTypes) parseStringLine: (NSString *)stringInput { BOOL found = NO; NSScanner *stringScanner = [NSScanner scannerWithString: stringInput]; - NSString *command = NULL; - [stringScanner scanString: @"=" intoString: &command]; - if(command != nil) + NSString *prefix = NULL; + + [stringScanner scanString: @"(gdb)" intoString: &prefix]; + if(prefix != nil) + { + return PCDBPromptRecord; + } + + [stringScanner scanString: @"=" intoString: &prefix]; + if(prefix != nil) { NSString *dictionaryName = NULL; found = YES; @@ -181,9 +189,64 @@ } } } + return PCDBAsyncInfoRecord; } - return found; + [stringScanner scanString: @"*" intoString: &prefix]; + if(prefix != nil) + { + return PCDBAsyncStatusRecord; + } + + [stringScanner scanString: @"<-" intoString: &prefix]; + if(prefix != nil) + { + return PCDBBreakpointRecord; + } + + [stringScanner scanString: @"->" intoString: &prefix]; + if(prefix != nil) + { + return PCDBBreakpointRecord; + } + + [stringScanner scanString: @"~" intoString: &prefix]; + if(prefix != nil) + { + return PCDBConsoleStreamRecord; + } + + [stringScanner scanString: @"@" intoString: &prefix]; + if(prefix != nil) + { + return PCDBTargetStreamRecord; + } + + [stringScanner scanString: @"&" intoString: &prefix]; + if(prefix != nil) + { + return PCDBDebugStreamRecord; + } + + [stringScanner scanString: @"^" intoString: &prefix]; + if(prefix != nil) + { + return PCDBResultRecord; + } + + return PCDBNotFoundRecord; +} + +- (NSString *)unescapeOutputRecord: (NSString *)recordString +{ + NSString *unescapedString = [recordString copy]; + + unescapedString = [unescapedString stringByReplacingOccurrencesOfString: @"~\"" withString: @""]; + unescapedString = [unescapedString substringToIndex: [unescapedString length] - 1]; + unescapedString = [unescapedString stringByReplacingOccurrencesOfString: @"\"" withString: @"\""]; + unescapedString = [unescapedString stringByReplacingOccurrencesOfString: @"\\n" withString: @"\n"]; + + return unescapedString; } - (void) parseString: (NSString *)inputString @@ -191,15 +254,32 @@ NSArray *components = [inputString componentsSeparatedByString:@"\n"]; NSEnumerator *en = [components objectEnumerator]; NSString *item = nil; - + while((item = [en nextObject]) != nil) { - BOOL command = [self parseStringLine: item]; - if(!command) + PCDebuggerOutputTypes outtype = [self parseStringLine: item]; + if(outtype == PCDBConsoleStreamRecord || + outtype == PCDBTargetStreamRecord) { - [self logString: item newLine: YES withColor:debuggerColor]; + NSString *unescapedString = [self unescapeOutputRecord: item]; + [self logString: unescapedString newLine: NO withColor:debuggerColor]; + } + else if(outtype == PCDBPromptRecord) + { + [self logString: item newLine: NO withColor:promptColor]; } } + + /* + stringRange = [inputString rangeOfString: "(gdb)" options: NULL]; + if(stringRange.location == NSNotFound) + { + [self logString: inputString newLine: NO withColor:debuggerColor]; + } + else + { + } + */ } /** @@ -366,7 +446,7 @@ NSLog(@"Task Terminated Unexpectedly..."); [self logString: @"\n=== Task Terminated Unexpectedly ===\n" - newLine:YES + newLine:NO withColor:messageColor]; //Clean up after task is terminated