From 2984e8452a841828056e44234aa340fc398eba78 Mon Sep 17 00:00:00 2001 From: Robert Sesek Date: Mon, 5 Dec 2016 23:40:46 -0500 Subject: [PATCH] Add support for call breakpoints to BreakpointManager. Also switch Breakpoint to using convience constructors. --- Source/Breakpoint.h | 4 ++-- Source/Breakpoint.m | 28 +++++++++++------------ Source/BreakpointController.m | 7 +++--- Source/BreakpointManager.h | 5 +++- Source/BreakpointManager.m | 43 ++++++++++++++++++----------------- Source/DebuggerController.m | 18 ++++++--------- 6 files changed, 52 insertions(+), 53 deletions(-) diff --git a/Source/Breakpoint.h b/Source/Breakpoint.h index f2e5fa9..faa4df8 100644 --- a/Source/Breakpoint.h +++ b/Source/Breakpoint.h @@ -39,8 +39,8 @@ extern NSString* const kBreakpointTypeFunctionEntry; // kBreakpointTypeFunctionEntry: @property (readonly) NSString* functionName; -- (instancetype)initWithLine:(unsigned long)l inFile:(NSString*)f; -- (instancetype)initWithFunctionNamed:(NSString*)function; ++ (instancetype)breakpointAtLine:(unsigned long)line inFile:(NSString*)file; ++ (instancetype)breakpointOnFunctionNamed:(NSString*)name; // Initializer from NSUserDefaults. - (instancetype)initWithDictionary:(NSDictionary*)dict; diff --git a/Source/Breakpoint.m b/Source/Breakpoint.m index 88ffdf3..7a7b55e 100644 --- a/Source/Breakpoint.m +++ b/Source/Breakpoint.m @@ -30,25 +30,24 @@ NSString* const kBreakpointTypeFunctionEntry = @"call"; NSString* _functionName; } -- (instancetype)initWithLine:(NSUInteger)l inFile:(NSString*)f ++ (instancetype)breakpointAtLine:(unsigned long)line inFile:(NSString*)file { - if ((self = [super init])) { - _type = kBreakpointTypeFile; - _file = [f copy]; - _line = l; - } - return self; + Breakpoint* breakpoint = [[[Breakpoint alloc] init] autorelease]; + breakpoint->_type = kBreakpointTypeFile; + breakpoint->_file = [file copy]; + breakpoint->_line = line; + return breakpoint; } -- (instancetype)initWithFunctionNamed:(NSString *)function { - if ((self = [super init])) { - _type = kBreakpointTypeFunctionEntry; - _functionName = [function copy]; - } - return self; ++ (instancetype)breakpointOnFunctionNamed:(NSString*)name +{ + Breakpoint* breakpoint = [[[Breakpoint alloc] init] autorelease]; + breakpoint->_type = kBreakpointTypeFunctionEntry; + breakpoint->_functionName = [name copy]; + return breakpoint; } -- (id)initWithDictionary:(NSDictionary*)dict +- (instancetype)initWithDictionary:(NSDictionary*)dict { if ((self = [super init])) { NSString* type = [dict valueForKey:@"type"]; @@ -84,6 +83,7 @@ NSString* const kBreakpointTypeFunctionEntry = @"call"; } else if (self.type == kBreakpointTypeFunctionEntry) { return [NSString stringWithFormat:@"%@()", self.functionName]; } + return nil; } /** diff --git a/Source/BreakpointController.m b/Source/BreakpointController.m index 9830b94..d4bd86d 100644 --- a/Source/BreakpointController.m +++ b/Source/BreakpointController.m @@ -74,7 +74,7 @@ - (IBAction)saveFunctionBreakpoint:(id)sender { - [_manager addBreakpoint:[[[Breakpoint alloc] initWithFunctionNamed:self.functionNameField.stringValue] autorelease]]; + [_manager addBreakpoint:[Breakpoint breakpointOnFunctionNamed:self.functionNameField.stringValue]]; [self.view.window endSheet:self.addFunctionBreakpointWindow]; } @@ -89,9 +89,8 @@ return; } - for (Breakpoint* bp in selection) - { - [_manager removeBreakpointAt:[bp line] inFile:[bp file]]; + for (Breakpoint* bp in selection) { + [_manager removeBreakpoint:bp]; } } diff --git a/Source/BreakpointManager.h b/Source/BreakpointManager.h index 7d41c28..3cb4a7d 100644 --- a/Source/BreakpointManager.h +++ b/Source/BreakpointManager.h @@ -24,7 +24,10 @@ @property(readonly) NSMutableArray* breakpoints; - (void)addBreakpoint:(Breakpoint*)bp; -- (Breakpoint*)removeBreakpointAt:(NSUInteger)line inFile:(NSString*)file; +- (Breakpoint*)removeBreakpoint:(Breakpoint*)bp; + +- (BOOL)hasBreakpoint:(Breakpoint*)bp; + - (NSSet*)breakpointsForFile:(NSString*)file; - (BOOL)hasBreakpointAt:(NSUInteger)line inFile:(NSString*)file; diff --git a/Source/BreakpointManager.m b/Source/BreakpointManager.m index 453b08e..e79dfac 100644 --- a/Source/BreakpointManager.m +++ b/Source/BreakpointManager.m @@ -74,31 +74,26 @@ } } -/** - * Removes a breakpoint at a given line/file combination, or nil if nothing was removed - */ -- (Breakpoint*)removeBreakpointAt:(NSUInteger)line inFile:(NSString*)file +- (Breakpoint*)removeBreakpoint:(Breakpoint*)bp { - for (Breakpoint* b in _breakpoints) - { - if ([b line] == line && [[b file] isEqualToString:file]) - { - // Keep the breakpoint alive after it is removed from the breakpoints - // array. - [[b retain] autorelease]; + if ([_breakpoints containsObject:bp]) { + // Keep the breakpoint alive after it is removed from the breakpoints + // array. + [[bp retain] autorelease]; + + [self willChangeValueForKey:@"breakpoints"]; + [_breakpoints removeObject:bp]; + [self didChangeValueForKey:@"breakpoints"]; - [self willChangeValueForKey:@"breakpoints"]; - [_breakpoints removeObject:b]; - [self didChangeValueForKey:@"breakpoints"]; + [_connection removeBreakpoint:bp]; - [_connection removeBreakpoint:b]; + [_savedBreakpoints removeObject:[bp dictionary]]; + [[NSUserDefaults standardUserDefaults] setObject:_savedBreakpoints forKey:kPrefBreakpoints]; - [_savedBreakpoints removeObject:[b dictionary]]; - [[NSUserDefaults standardUserDefaults] setObject:_savedBreakpoints forKey:kPrefBreakpoints]; + if (bp.file) + [self updateDisplaysForFile:bp.file]; - [self updateDisplaysForFile:file]; - return b; - } + return bp; } return nil; } @@ -118,12 +113,18 @@ return matches; } + +- (BOOL)hasBreakpoint:(Breakpoint*)breakpoint +{ + return [_breakpoints containsObject:breakpoint]; +} + /** * Checks to see if a given file has a breakpoint on a given line */ - (BOOL)hasBreakpointAt:(NSUInteger)line inFile:(NSString*)file { - return [_breakpoints containsObject:[[[Breakpoint alloc] initWithLine:line inFile:file] autorelease]]; + return [self hasBreakpoint:[Breakpoint breakpointAtLine:line inFile:file]]; } #pragma mark Private diff --git a/Source/DebuggerController.m b/Source/DebuggerController.m index ac97e51..b308bdf 100644 --- a/Source/DebuggerController.m +++ b/Source/DebuggerController.m @@ -415,20 +415,16 @@ */ - (void)gutterClickedAtLine:(int)line forFile:(NSString*)file { - BreakpointManager* mngr = _model.breakpointManager; + BreakpointManager* manager = _model.breakpointManager; + Breakpoint* breakpoint = [Breakpoint breakpointAtLine:line inFile:file]; - if ([mngr hasBreakpointAt:line inFile:file]) - { - [mngr removeBreakpointAt:line inFile:file]; - } - else - { - Breakpoint* bp = [[Breakpoint alloc] initWithLine:line inFile:file]; - [mngr addBreakpoint:bp]; - [bp release]; + if ([manager hasBreakpoint:breakpoint]) { + [manager removeBreakpoint:breakpoint]; + } else { + [manager addBreakpoint:breakpoint]; } - [sourceViewer setMarkers:[mngr breakpointsForFile:file]]; + [sourceViewer setMarkers:[manager breakpointsForFile:file]]; } @end -- 2.43.5