From cb0e666d1cd123318a3d2c54e7b34e8ad5656552 Mon Sep 17 00:00:00 2001 From: Robert Sesek Date: Mon, 7 Dec 2015 01:20:02 -0500 Subject: [PATCH] Inject autoAttach into DebuggerBackEnd's designated initializer. Also makes sure the header order matches implementation order. --- Source/DebuggerBackEnd.h | 19 ++++++++++--------- Source/DebuggerBackEnd.m | 15 +++++---------- Source/DebuggerController.m | 3 ++- 3 files changed, 17 insertions(+), 20 deletions(-) diff --git a/Source/DebuggerBackEnd.h b/Source/DebuggerBackEnd.h index 4fc834c..cf6bfc4 100644 --- a/Source/DebuggerBackEnd.h +++ b/Source/DebuggerBackEnd.h @@ -40,8 +40,9 @@ // The model object to update in response to changes in the debugger. @property(assign, nonatomic) DebuggerModel* model; -// initializer -- (id)initWithPort:(NSUInteger)aPort; +// Designated initializer. Sets up a connection on |aPort| and will +// initialize it if |autoAttach| is YES. +- (instancetype)initWithPort:(NSUInteger)aPort autoAttach:(BOOL)doAttach; // getter - (NSUInteger)port; @@ -54,13 +55,6 @@ - (void)stop; - (void)detach; -// Breakpoint management. -- (void)addBreakpoint:(Breakpoint*)bp; -- (void)removeBreakpoint:(Breakpoint*)bp; - -// Evaluates a given string in the current execution context. -- (void)evalScript:(NSString*)str callback:(void (^)(NSString*))callback; - // Takes a partially loaded stack frame and fetches the rest of the information. - (void)loadStackFrame:(StackFrame*)frame; @@ -69,4 +63,11 @@ - (void)loadVariableNode:(VariableNode*)variable forStackFrame:(StackFrame*)frame; +// Breakpoint management. +- (void)addBreakpoint:(Breakpoint*)bp; +- (void)removeBreakpoint:(Breakpoint*)bp; + +// Evaluates a given string in the current execution context. +- (void)evalScript:(NSString*)str callback:(void (^)(NSString*))callback; + @end diff --git a/Source/DebuggerBackEnd.m b/Source/DebuggerBackEnd.m index 717f8b9..b01fb89 100644 --- a/Source/DebuggerBackEnd.m +++ b/Source/DebuggerBackEnd.m @@ -30,16 +30,15 @@ @synthesize autoAttach = _autoAttach; @synthesize model = _model; -- (id)initWithPort:(NSUInteger)aPort +- (instancetype)initWithPort:(NSUInteger)aPort autoAttach:(BOOL)doAttach { if (self = [super init]) { [[BreakpointManager sharedManager] setConnection:self]; _port = aPort; _client = [[ProtocolClient alloc] initWithDelegate:self]; - _autoAttach = [[NSUserDefaults standardUserDefaults] boolForKey:@"DebuggerAttached"]; - - if (self.autoAttach) + _autoAttach = doAttach; + if (doAttach) [_client connectOnPort:_port]; } return self; @@ -324,12 +323,8 @@ - (void)rebuildStack:(NSXMLDocument*)response { NSUInteger depth = [[[[response rootElement] attributeForName:@"depth"] stringValue] intValue]; - // Start with frame 0. If this is a shifted frame, then only it needs to be - // re-loaded. If it is not shifted, see if another frame on the stack is equal - // to it; if so, then the frames up to that must be discarded. If not, this is - // a new stack frame that should be inserted at the top of the stack. Finally, - // the sice of the stack is trimmed to |depth| from the bottom. - + // Send a request to get each frame of the stack, which will be added to this + // array. When the final frame arrives, the |tempStack| is released. __block NSMutableArray* tempStack = [[NSMutableArray alloc] init]; for (NSUInteger i = 0; i < depth; ++i) { diff --git a/Source/DebuggerController.m b/Source/DebuggerController.m index 2f3b329..153ecbf 100644 --- a/Source/DebuggerController.m +++ b/Source/DebuggerController.m @@ -49,7 +49,8 @@ options:NSKeyValueObservingOptionNew context:nil]; - connection = [[DebuggerBackEnd alloc] initWithPort:[defaults integerForKey:@"Port"]]; + connection = [[DebuggerBackEnd alloc] initWithPort:[defaults integerForKey:@"Port"] + autoAttach:[defaults boolForKey:@"DebuggerAttached"]]; connection.model = _model; expandedVariables = [[NSMutableSet alloc] init]; [[self window] makeKeyAndOrderFront:nil]; -- 2.22.5