The breakpoint manager now works -- breakpoints can be set from the main debugger...
[macgdbp.git] / Source / BreakpointManager.m
1 /*
2 * MacGDBp
3 * Copyright (c) 2007 - 2008, Blue Static <http://www.bluestatic.org>
4 *
5 * This program is free software; you can redistribute it and/or modify it under the terms of the GNU
6 * General Public License as published by the Free Software Foundation; either version 2 of the
7 * License, or (at your option) any later version.
8 *
9 * This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without
10 * even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
11 * General Public License for more details.
12 *
13 * You should have received a copy of the GNU General Public License along with this program; if not,
14 * write to the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
15 */
16
17 #import "BreakpointManager.h"
18 #import "AppDelegate.h"
19
20 @interface BreakpointManager (Private)
21 - (void)updateDisplaysForFile:(NSString *)file;
22 @end
23
24 @implementation BreakpointManager
25
26 @synthesize breakpoints, connection;
27
28 /**
29 * Initializer
30 */
31 - (id)init
32 {
33 if (self = [super init])
34 {
35 if (!breakpoints)
36 {
37 breakpoints = [[NSMutableArray alloc] init];
38 }
39 }
40 return self;
41 }
42
43 /**
44 * Returns the shared manager (singleton)
45 */
46 + (BreakpointManager *)sharedManager
47 {
48 static BreakpointManager *manager;
49 if (!manager)
50 {
51 manager = [[BreakpointManager alloc] init];
52 }
53 return manager;
54 }
55
56 /**
57 * Registers a breakpoint at a given line
58 */
59 - (void)addBreakpoint:(Breakpoint *)bp;
60 {
61 if (![breakpoints containsObject:bp])
62 {
63 [breakpoints addObject:bp];
64 [connection addBreakpoint:bp];
65
66 [self updateDisplaysForFile:[bp file]];
67 }
68 }
69
70 /**
71 * Removes a breakpoint at a given line/file combination, or nil if nothing was removed
72 */
73 - (Breakpoint *)removeBreakpointAt:(int)line inFile:(NSString *)file
74 {
75 for (Breakpoint *b in breakpoints)
76 {
77 if ([b line] == line && [[b file] isEqualToString:file])
78 {
79 [breakpoints removeObject:b];
80 [connection removeBreakpoint:b];
81 [self updateDisplaysForFile:file];
82 return b;
83 }
84 }
85 return nil;
86 }
87
88 /**
89 * Returns all the breakpoints for a given file
90 */
91 - (NSArray *)breakpointsForFile:(NSString *)file
92 {
93 NSMutableArray *matches = [NSMutableArray array];
94 for (Breakpoint *b in breakpoints)
95 {
96 if ([[b file] isEqualToString:file])
97 {
98 [matches addObject:b];
99 }
100 }
101
102 return matches;
103 }
104
105 /**
106 * Checks to see if a given file has a breakpoint on a given line
107 */
108 - (BOOL)hasBreakpointAt:(int)line inFile:(NSString *)file
109 {
110 return [breakpoints containsObject:[[Breakpoint alloc] initWithLine:line inFile:file]];
111 }
112
113 #pragma mark Private
114
115 /**
116 * This marks BSSourceView needsDisplay, rearranges the objects in the breakpoints controller,
117 * and sets the markers for the BSLineNumberView
118 */
119 - (void)updateDisplaysForFile:(NSString *)file
120 {
121 AppDelegate *appDel = [NSApp delegate];
122 [[[appDel breakpoint] arrayController] rearrangeObjects];
123 [[[appDel breakpoint] sourceView] setNeedsDisplay:YES];
124 [[[[appDel breakpoint] sourceView] numberView] setMarkers:[NSSet setWithArray:[self breakpointsForFile:file]]];
125 [[[appDel debugger] sourceViewer] setNeedsDisplay:YES];
126 [[[[appDel debugger] sourceViewer] numberView] setMarkers:[NSSet setWithArray:[self breakpointsForFile:file]]];
127 }
128
129 @end