From 2b3e345aeabc5138b7f8a11db12dad94554f8f7d Mon Sep 17 00:00:00 2001 From: Robert Sesek Date: Sat, 19 Jun 2010 12:26:58 -0400 Subject: [PATCH] Lazily load the complete stack frame for anything but the current one. --- Source/DebuggerController.m | 7 ++++++- Source/DebuggerProcessor.h | 4 ++++ Source/DebuggerProcessor.m | 34 ++++++++++++++++++++++++---------- Source/StackFrame.h | 6 ++++++ Source/StackFrame.m | 1 + 5 files changed, 41 insertions(+), 11 deletions(-) diff --git a/Source/DebuggerController.m b/Source/DebuggerController.m index 365401e..3fa729d 100644 --- a/Source/DebuggerController.m +++ b/Source/DebuggerController.m @@ -252,7 +252,12 @@ if ([selection count] > 1) NSLog(@"INVALID SELECTION"); StackFrame* frame = [selection objectAtIndex:0]; - + + if (!frame.loaded) { + [connection loadStackFrame:frame]; + return; + } + // Get the filename. NSString* filename = [[NSURL URLWithString:frame.filename] path]; if ([filename isEqualToString:@""]) diff --git a/Source/DebuggerProcessor.h b/Source/DebuggerProcessor.h index f567af3..bc0acf5 100644 --- a/Source/DebuggerProcessor.h +++ b/Source/DebuggerProcessor.h @@ -82,6 +82,9 @@ // which used in the delegate callback. - (NSInteger)getProperty:(NSString*)property; +// Takes a partially loaded stack frame and fetches the rest of the information. +- (void)loadStackFrame:(StackFrame*)frame; + @end // Delegate //////////////////////////////////////////////////////////////////// @@ -105,6 +108,7 @@ - (void)newStackFrame:(StackFrame*)frame; // Tells the debugger that new source is available for the given frame. +// TODO: rename to |-frameUpdated:|. - (void)sourceUpdated:(StackFrame*)frame; // Callback from |-getProperty:|. diff --git a/Source/DebuggerProcessor.m b/Source/DebuggerProcessor.m index d51b6e6..42af132 100644 --- a/Source/DebuggerProcessor.m +++ b/Source/DebuggerProcessor.m @@ -167,6 +167,28 @@ [self recordCallback:@selector(propertiesReceived:) forTransaction:tx]; } +- (void)loadStackFrame:(StackFrame*)frame +{ + if (frame.loaded) + return; + + NSNumber* routingNumber = [NSNumber numberWithInt:frame.routingID]; + + // Get the source code of the file. Escape % in URL chars. + NSString* escapedFilename = [frame.filename stringByReplacingOccurrencesOfString:@"%" withString:@"%%"]; + NSNumber* transaction = [connection_ sendCommandWithFormat:@"source -f %@", escapedFilename]; + [self recordCallback:@selector(setSource:) forTransaction:transaction]; + [callbackContext_ setObject:routingNumber forKey:transaction]; + + // Get the names of all the contexts. + transaction = [connection_ sendCommandWithFormat:@"context_names -d %d", frame.index]; + [self recordCallback:@selector(contextsReceived:) forTransaction:transaction]; + [callbackContext_ setObject:routingNumber forKey:transaction]; + + // This frame will be fully loaded. + frame.loaded = YES; +} + // Breakpoint Management /////////////////////////////////////////////////////// #pragma mark Breakpoints @@ -314,20 +336,12 @@ atLine:[[[xmlframe attributeForName:@"lineno"] stringValue] intValue] inFunction:[[xmlframe attributeForName:@"where"] stringValue] withVariables:nil]; + frame.routingID = routingID; // Only get the complete frame for the first level. The other frames will get // information loaded lazily when the user clicks on one. if (frame.index == 0) { - // Get the source code of the file. Escape % in URL chars. - NSString* escapedFilename = [frame.filename stringByReplacingOccurrencesOfString:@"%" withString:@"%%"]; - NSNumber* transaction = [connection_ sendCommandWithFormat:@"source -f %@", escapedFilename]; - [self recordCallback:@selector(setSource:) forTransaction:transaction]; - [callbackContext_ setObject:routingNumber forKey:transaction]; - - // Get the names of all the contexts. - transaction = [connection_ sendCommandWithFormat:@"context_names -d %d", frame.index]; - [self recordCallback:@selector(contextsReceived:) forTransaction:transaction]; - [callbackContext_ setObject:routingNumber forKey:transaction]; + [self loadStackFrame:frame]; } if ([delegate respondsToSelector:@selector(newStackFrame:)]) diff --git a/Source/StackFrame.h b/Source/StackFrame.h index ac31ad0..591d8e0 100644 --- a/Source/StackFrame.h +++ b/Source/StackFrame.h @@ -18,6 +18,11 @@ @interface StackFrame : NSObject { + /** + * Whether or not the stack frame has been fully loaded. + */ + BOOL loaded_; + /** * The routing ID used to receive response information from the engine. */ @@ -54,6 +59,7 @@ NSArray* variables; } +@property BOOL loaded; @property NSUInteger routingID; @property (readwrite) int index; @property (readonly, copy) NSString* filename; diff --git a/Source/StackFrame.m b/Source/StackFrame.m index f00dab3..bdb9193 100644 --- a/Source/StackFrame.m +++ b/Source/StackFrame.m @@ -26,6 +26,7 @@ @implementation StackFrame +@synthesize loaded = loaded_; @synthesize routingID = routingID_; @synthesize index, filename, source, lineNumber, function, variables; -- 2.43.5