From 5242e2ceb6bcc0ce677580652c06548563701628 Mon Sep 17 00:00:00 2001 From: Robert Sesek Date: Wed, 2 Apr 2008 13:53:46 -0400 Subject: [PATCH] Initial breakpoint adding code * MacGDBp.xcodeproj: Project updates for Breakpoint.m/h * Source/AppDelegate.h: Add a breakpoints ivar * Source/AppDelegate.m: ([AppDelegate addBreakpoint:]): New method ([AppDelegate breakpointsForFile:]): New method * Source/BSLineNumberView.h: Add a markers ivar * Source/BSLineNumberView.m: ([BSLineNumberView drawRect:]): Add breakpoint-detecting code * Source/DebuggerWindowController.m: Making this the delegate of BSSourceView ([DebuggerWindowController gutterClickedAtLine:forFile:]): Implementing delegate method --- MacGDBp.xcodeproj/project.pbxproj | 6 +++ Source/AppDelegate.h | 8 +++- Source/AppDelegate.m | 32 +++++++++++++++- Source/BSLineNumberView.h | 2 + Source/BSLineNumberView.m | 9 ++++- Source/Breakpoint.h | 31 ++++++++++++++++ Source/Breakpoint.m | 61 +++++++++++++++++++++++++++++++ Source/DebuggerWindowController.m | 14 +++++++ 8 files changed, 159 insertions(+), 4 deletions(-) create mode 100644 Source/Breakpoint.h create mode 100644 Source/Breakpoint.m diff --git a/MacGDBp.xcodeproj/project.pbxproj b/MacGDBp.xcodeproj/project.pbxproj index dfc62d6..96425e9 100644 --- a/MacGDBp.xcodeproj/project.pbxproj +++ b/MacGDBp.xcodeproj/project.pbxproj @@ -21,6 +21,7 @@ 1E7188680D839F6300969277 /* BSLineNumberView.m in Sources */ = {isa = PBXBuildFile; fileRef = 1E7188630D839F6300969277 /* BSLineNumberView.m */; }; 1E7188690D839F6300969277 /* BSSourceView.m in Sources */ = {isa = PBXBuildFile; fileRef = 1E7188650D839F6300969277 /* BSSourceView.m */; }; 1E71886A0D839F6300969277 /* BSSourceViewTextView.m in Sources */ = {isa = PBXBuildFile; fileRef = 1E7188670D839F6300969277 /* BSSourceViewTextView.m */; }; + 1E822CDD0DA28AC30027A23F /* Breakpoint.m in Sources */ = {isa = PBXBuildFile; fileRef = 1E822CDC0DA28AC30027A23F /* Breakpoint.m */; }; 1EEBFBE50D34C793008F835B /* Debugger.xib in Resources */ = {isa = PBXBuildFile; fileRef = 1EEBFBE30D34C793008F835B /* Debugger.xib */; }; 1EEBFC2B0D358EBD008F835B /* StepIn.png in Resources */ = {isa = PBXBuildFile; fileRef = 1EEBFC2A0D358EBD008F835B /* StepIn.png */; }; 1EEBFC370D358F1B008F835B /* StepOut.png in Resources */ = {isa = PBXBuildFile; fileRef = 1EEBFC360D358F1B008F835B /* StepOut.png */; }; @@ -59,6 +60,8 @@ 1E7188650D839F6300969277 /* BSSourceView.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; name = BSSourceView.m; path = Source/BSSourceView.m; sourceTree = ""; }; 1E7188660D839F6300969277 /* BSSourceViewTextView.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = BSSourceViewTextView.h; path = Source/BSSourceViewTextView.h; sourceTree = ""; }; 1E7188670D839F6300969277 /* BSSourceViewTextView.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; name = BSSourceViewTextView.m; path = Source/BSSourceViewTextView.m; sourceTree = ""; }; + 1E822CDB0DA28AC30027A23F /* Breakpoint.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = Breakpoint.h; path = Source/Breakpoint.h; sourceTree = ""; }; + 1E822CDC0DA28AC30027A23F /* Breakpoint.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; name = Breakpoint.m; path = Source/Breakpoint.m; sourceTree = ""; }; 1EEBFBE40D34C793008F835B /* English */ = {isa = PBXFileReference; lastKnownFileType = file.xib; name = English; path = English.lproj/Debugger.xib; sourceTree = ""; }; 1EEBFC2A0D358EBD008F835B /* StepIn.png */ = {isa = PBXFileReference; lastKnownFileType = image.png; name = StepIn.png; path = Icons/StepIn.png; sourceTree = ""; }; 1EEBFC360D358F1B008F835B /* StepOut.png */ = {isa = PBXFileReference; lastKnownFileType = image.png; name = StepOut.png; path = Icons/StepOut.png; sourceTree = ""; }; @@ -104,6 +107,8 @@ 1E35FC750C6579CA0030F527 /* NSXMLElementAdditions.m */, 1EEBFD080D3599E8008F835B /* BSSplitView.h */, 1EEBFD070D3599E8008F835B /* BSSplitView.m */, + 1E822CDB0DA28AC30027A23F /* Breakpoint.h */, + 1E822CDC0DA28AC30027A23F /* Breakpoint.m */, 1E71886C0D839F6C00969277 /* Source View */, ); name = Classes; @@ -306,6 +311,7 @@ 1E7188680D839F6300969277 /* BSLineNumberView.m in Sources */, 1E7188690D839F6300969277 /* BSSourceView.m in Sources */, 1E71886A0D839F6300969277 /* BSSourceViewTextView.m in Sources */, + 1E822CDD0DA28AC30027A23F /* Breakpoint.m in Sources */, ); runOnlyForDeploymentPostprocessing = 0; }; diff --git a/Source/AppDelegate.h b/Source/AppDelegate.h index a53251b..389b221 100644 --- a/Source/AppDelegate.h +++ b/Source/AppDelegate.h @@ -16,10 +16,16 @@ #import #import "DebuggerConnection.h" +#import "Breakpoint.h" @interface AppDelegate : NSObject -{} +{ + NSMutableDictionary *breakpoints; +} - (IBAction)showConnectionWindow:(id)sender; +- (void)addBreakpoint:(Breakpoint *)bp; +- (NSSet *)breakpointsForFile:(NSString *)file; + @end diff --git a/Source/AppDelegate.m b/Source/AppDelegate.m index 5f647a7..a54961e 100644 --- a/Source/AppDelegate.m +++ b/Source/AppDelegate.m @@ -25,7 +25,9 @@ - (id)init { if (self = [super init]) - {} + { + breakpoints = [NSMutableDictionary dictionary]; + } return self; } @@ -45,4 +47,32 @@ [[[ConnectWindowController sharedController] window] makeKeyAndOrderFront:self]; } +#pragma mark Breakpoints + +/** + * Registers a breakpoint at a given line + */ +- (void)addBreakpoint:(Breakpoint *)bp; +{ + NSMutableSet *lines = [breakpoints valueForKey:[bp file]]; + if (lines == nil) + { + lines = [NSMutableSet setWithObject:bp]; + [breakpoints setValue:lines forKey:[bp file]]; + } + else + { + [lines addObject:bp]; + } + NSLog(@"breakpoints = %@", breakpoints); +} + +/** + * Returns all the breakpoints for a given file + */ +- (NSSet *)breakpointsForFile:(NSString *)file +{ + return [breakpoints valueForKey:file]; +} + @end diff --git a/Source/BSLineNumberView.h b/Source/BSLineNumberView.h index 70e93de..cf0c91d 100644 --- a/Source/BSLineNumberView.h +++ b/Source/BSLineNumberView.h @@ -22,9 +22,11 @@ { BSSourceView *sourceView; NSRange lineNumberRange; + NSSet *markers; } @property(readwrite, assign) BSSourceView *sourceView; @property(readonly) NSRange lineNumberRange; +@property(readwrite, assign) NSSet *markers; @end diff --git a/Source/BSLineNumberView.m b/Source/BSLineNumberView.m index c20f1f2..2b6a0cd 100644 --- a/Source/BSLineNumberView.m +++ b/Source/BSLineNumberView.m @@ -15,11 +15,12 @@ */ #import "BSLineNumberView.h" - +#import "Breakpoint.h" +#import "BSSourceView.h" @implementation BSLineNumberView -@synthesize sourceView, lineNumberRange; +@synthesize sourceView, lineNumberRange, markers; /** * Initializer for the line number view @@ -79,6 +80,10 @@ NSString *num = [NSString stringWithFormat:@"%u", line]; NSSize strSize = [num sizeWithAttributes:attrs]; [num drawAtPoint:NSMakePoint([self frame].size.width - strSize.width - 3, fragRect.origin.y + ((fragRect.size.height - strSize.height) / 2)) withAttributes:attrs]; + if ([markers containsObject:[[Breakpoint alloc] initWithLine:line inFile:[sourceView file]]]) + { + NSLog(@"marking %i", line); + } } i += fragRange.length; diff --git a/Source/Breakpoint.h b/Source/Breakpoint.h new file mode 100644 index 0000000..8ebceb1 --- /dev/null +++ b/Source/Breakpoint.h @@ -0,0 +1,31 @@ +/* + * MacGDBp + * Copyright (c) 2007 - 2008, Blue Static + * + * This program is free software; you can redistribute it and/or modify it under the terms of the GNU + * General Public License as published by the Free Software Foundation; either version 2 of the + * License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without + * even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * General Public License for more details. + * + * You should have received a copy of the GNU General Public License along with this program; if not, + * write to the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA + */ + +#import + + +@interface Breakpoint : NSObject +{ + NSString *file; + int line; +} + +@property(readonly) NSString *file; +@property(readonly) int line; + +- (id)initWithLine:(int)l inFile:(NSString *)f; + +@end diff --git a/Source/Breakpoint.m b/Source/Breakpoint.m new file mode 100644 index 0000000..4073d21 --- /dev/null +++ b/Source/Breakpoint.m @@ -0,0 +1,61 @@ +/* + * MacGDBp + * Copyright (c) 2007 - 2008, Blue Static + * + * This program is free software; you can redistribute it and/or modify it under the terms of the GNU + * General Public License as published by the Free Software Foundation; either version 2 of the + * License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without + * even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * General Public License for more details. + * + * You should have received a copy of the GNU General Public License along with this program; if not, + * write to the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA + */ + +#import "Breakpoint.h" + + +@implementation Breakpoint + +@synthesize file, line; + +/** + * Initializes a breakpoint with a file and line + */ +- (id)initWithLine:(int)l inFile:(NSString *)f +{ + if (self = [super init]) + { + file = f; + line = l; + } + return self; +} + +/** + * Determines if two breakpoints are equal + */ +- (BOOL)isEqual:(id)obj +{ + return ([[obj file] isEqualToString:file] && [obj line] == line); +} + +/** + * Returns the hash value of a breakpoint + */ +- (NSUInteger)hash +{ + return ([file hash] << 8) + line; +} + +/** + * Pretty-print + */ +- (NSString *)description +{ + return [NSString stringWithFormat:@"%@:%i", file, line]; +} + +@end diff --git a/Source/DebuggerWindowController.m b/Source/DebuggerWindowController.m index c5cd174..28c0fe9 100644 --- a/Source/DebuggerWindowController.m +++ b/Source/DebuggerWindowController.m @@ -18,6 +18,7 @@ #import "DebuggerConnection.h" #import "NSXMLElementAdditions.h" #import "AppDelegate.h" +#import "Breakpoint.h" @interface DebuggerWindowController (Private) @@ -49,6 +50,7 @@ - (void)awakeFromNib { [self setStatus:@"Connecting"]; + [sourceViewer setDelegate:self]; } /** @@ -264,4 +266,16 @@ [registerController rearrangeObjects]; } +#pragma mark BSSourceView Delegate + +/** + * The gutter was clicked, which indicates that a breakpoint needs to be changed + */ +- (void)gutterClickedAtLine:(int)line forFile:(NSString *)file +{ + [[NSApp delegate] addBreakpoint:[[Breakpoint alloc] initWithLine:line inFile:file]]; + [[sourceViewer numberView] setMarkers:[[NSApp delegate] breakpointsForFile:file]]; + [[sourceViewer numberView] setNeedsDisplay:YES]; +} + @end -- 2.43.5