From 5aa4b5813ceb82ea1eb42a71ba221d73e87230f2 Mon Sep 17 00:00:00 2001 From: Riccardo Mottola Date: Mon, 5 Jul 2021 02:26:30 +0200 Subject: [PATCH] Make the parser much more recursive and use it also for AsyncStatus records --- Modules/Debuggers/ProjectCenter/GDBWrapper.m | 140 +++++++++---------- 1 file changed, 68 insertions(+), 72 deletions(-) diff --git a/Modules/Debuggers/ProjectCenter/GDBWrapper.m b/Modules/Debuggers/ProjectCenter/GDBWrapper.m index 7c1c4cd..ad514f8 100644 --- a/Modules/Debuggers/ProjectCenter/GDBWrapper.m +++ b/Modules/Debuggers/ProjectCenter/GDBWrapper.m @@ -201,8 +201,9 @@ NSMutableDictionary *mdict; NSScanner *stringScanner; NSString *key = NULL; - NSString *value = NULL; + id value = nil; + NSLog(@"scanning KV: %@", stringInput); mdict = [[NSMutableDictionary alloc] init]; stringScanner = [NSScanner scannerWithString: stringInput]; @@ -210,14 +211,23 @@ { [stringScanner scanUpToString: @"=" intoString: &key]; [stringScanner scanString: @"=" intoString: NULL]; - + NSLog(@"key found: %@", key); if ([stringInput characterAtIndex:[stringScanner scanLocation]] == '[') { [stringScanner scanString: @"[" intoString: NULL]; [stringScanner scanUpToString: @"]" intoString: &value]; [stringScanner scanString: @"]" intoString: NULL]; + [stringScanner scanString: @"," intoString: NULL]; value = [self parseArray: value]; } + else if ([stringInput characterAtIndex:[stringScanner scanLocation]] == '{') + { + [stringScanner scanString: @"{" intoString: NULL]; + [stringScanner scanUpToString: @"}" intoString: &value]; + [stringScanner scanString: @"}" intoString: NULL]; + [stringScanner scanString: @"," intoString: NULL]; + value = [self parseKeyValueString: value]; + } else { [stringScanner scanString: @"\"" intoString: NULL]; @@ -225,7 +235,6 @@ [stringScanner scanString: @"\"" intoString: NULL]; [stringScanner scanString: @"," intoString: NULL]; } - // NSLog(@"parse KVS: key %@ value %@", key, value); if (key != nil && value != nil) [mdict setObject:value forKey:key]; } @@ -235,7 +244,7 @@ } /* - Parses a line coming from the debugger. It could be eiher a stanard outpu or it may come from the machine + Parses a line coming from the debugger. It could be eiher a stanard output or it may come from the machine interface of gdb. */ - (PCDebuggerOutputTypes) parseStringLine: (NSString *)stringInput @@ -248,7 +257,7 @@ stringScanner = [NSScanner scannerWithString: stringInput]; - //NSLog(@"parsing: |%@|", stringInput); + NSLog(@"parsing: |%@|", stringInput); [stringScanner scanString: @"(gdb)" intoString: &prefix]; if(prefix != nil) { @@ -266,80 +275,78 @@ { NSString *dictionaryName = NULL; - NSLog(@"scanning MI |%@|", stringInput); + NSLog(@"scanning AsyncInfo |%@|", stringInput); [stringScanner scanUpToString: @"," intoString: &dictionaryName]; - if([dictionaryName isEqualToString: @"thread-group-started"]) - { - NSLog(@"%@",dictionaryName); - } - if(dictionaryName != nil) - { - NSString *key = NULL; + { + NSString *key = nil; id value = nil; + NSDictionary *dict; - while([stringScanner isAtEnd] == NO) + [stringScanner scanString: @"," intoString: NULL]; + dict = [self parseKeyValueString: [stringInput substringFromIndex:[stringScanner scanLocation]]]; + NSLog(@"type %@ value %@", dictionaryName, dict); + + if([dict objectForKey:@"pid"] != nil && + [dictionaryName isEqualToString: @"thread-group-started"]) { - [stringScanner scanString: @"," intoString: NULL]; - [stringScanner scanUpToString: @"=" intoString: &key]; - [stringScanner scanString: @"=" intoString: NULL]; - if ([stringInput characterAtIndex:[stringScanner scanLocation]] == '[') + [debugger setSubProcessId: [[dict objectForKey:@"pid"] intValue]]; + } + else if ([dict objectForKey:@"bkpt"] != nil) + { + NSDictionary *bkpDict; + // gdb specific + NSString *fileName; + NSString *lineNum; + + bkpDict = [value objectForKey:@"bkpt"]; + fileName = [bkpDict objectForKey:@"file"]; + lineNum = [bkpDict objectForKey:@"line"]; + NSLog(@"parsed from GDB bkpt: %@:%@", fileName, lineNum); + if (fileName != nil && lineNum != nil) { - [stringScanner scanString: @"[" intoString: NULL]; - [stringScanner scanUpToString: @"]" intoString: &value]; - [stringScanner scanString: @"]" intoString: NULL]; - value = [self parseArray: value]; - } - else if ([stringInput characterAtIndex:[stringScanner scanLocation]] == '{') - { - [stringScanner scanString: @"{" intoString: NULL]; - [stringScanner scanUpToString: @"}" intoString: &value]; - [stringScanner scanString: @"}" intoString: NULL]; - value = [self parseKeyValueString: value]; + [debugger setLastFileNameParsed: fileName]; + [debugger setLastLineNumberParsed: [lineNum intValue]]; } else { - [stringScanner scanString: @"\"" intoString: NULL]; - [stringScanner scanUpToString: @"\"" intoString: &value]; - [stringScanner scanString: @"\"" intoString: NULL]; - } - NSLog(@"key %@ value %@", key, value); - - if([key isEqualToString:@"pid"] && - [dictionaryName isEqualToString: @"thread-group-started"]) - { - [debugger setSubProcessId: [value intValue]]; - } - else if ([key isEqualToString:@"bkpt"]) - { - // gdb specific - NSString *fileName; - NSString *lineNum; - - fileName = [value objectForKey:@"file"]; - lineNum = [value objectForKey:@"line"]; - NSLog(@"parsed from GDB bkpt: %@:%@", fileName, lineNum); - if (fileName != nil && lineNum != nil) - { - [debugger setLastFileNameParsed: fileName]; - [debugger setLastLineNumberParsed: [lineNum intValue]]; - } - else - { - [debugger setLastFileNameParsed: nil]; - [debugger setLastLineNumberParsed: NSNotFound]; - } + [debugger setLastFileNameParsed: nil]; + [debugger setLastLineNumberParsed: NSNotFound]; } } } + else + { + NSLog(@"error parsing type of: %@", stringInput); + } return PCDBAsyncInfoRecord; } [stringScanner scanString: @"*" intoString: &prefix]; if(prefix != nil) { + NSString *dictionaryName = NULL; + NSDictionary *dict = nil; + + NSLog(@"scanning AsyncStatus |%@|", stringInput); + + [stringScanner scanUpToString: @"," intoString: &dictionaryName]; + + if(dictionaryName != nil) + { + id value = nil; + + [stringScanner scanString: @"," intoString: NULL]; + value = [self parseKeyValueString: [stringInput substringFromIndex:[stringScanner scanLocation]]]; + NSLog(@"type %@ value %@", dictionaryName, dict); + } + + if ([dictionaryName isEqualToString:@"stopped"]) + { + [debugger setStatus:@"Stopped"]; + } return PCDBAsyncStatusRecord; } @@ -380,7 +387,7 @@ } } } - if (([debugger debuggerVersion] < 7) && [debugger subProcessId] == 0) + if ((debuggerVersion < 7) && [debugger subProcessId] == 0) { NSString *str1; // we attempt to parse: [New thread 6800.0x18ec] @@ -447,7 +454,7 @@ } return PCDBResultRecord; } - NSLog(@"No match found parse: |%@|", stringInput); + NSLog(@"No match found parsing: |%@|", stringInput); return PCDBNotFoundRecord; } @@ -500,17 +507,6 @@ } */ } - - /* - stringRange = [inputString rangeOfString: "(gdb)" options: NULL]; - if(stringRange.location == NSNotFound) - { - [self logString: inputString newLine: NO withColor:debuggerColor]; - } - else - { - } - */ } /**