3 * Copyright (c) 2007 - 2011, Blue Static <http://www.bluestatic.org>
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.
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.
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
17 #import "BreakpointManager.h"
19 #import "PreferenceNames.h"
21 @implementation BreakpointManager
{
22 NSMutableArray
* _breakpoints
;
23 NSMutableArray
* _savedBreakpoints
;
25 DebuggerBackEnd
* __weak _connection
;
30 if (self = [super init
])
32 _breakpoints
= [[NSMutableArray alloc
] init
];
33 _savedBreakpoints
= [[NSMutableArray alloc
] init
];
35 NSArray
* savedBreakpoints
= [[NSUserDefaults standardUserDefaults
] arrayForKey
:kPrefBreakpoints
];
36 if (savedBreakpoints
) {
37 for (NSDictionary
* d
in savedBreakpoints
) {
38 Breakpoint
* bp
= [[Breakpoint alloc
] initWithDictionary
:d
];
39 [_breakpoints addObject
:bp
];
40 [_savedBreakpoints addObject
:[bp dictionary
]];
48 * Registers a breakpoint at a given line
50 - (void)addBreakpoint
:(Breakpoint
*)bp
;
52 if ([_breakpoints containsObject
:bp
])
55 [self willChangeValueForKey
:@
"breakpoints"];
56 [_breakpoints addObject
:bp
];
57 [self didChangeValueForKey
:@
"breakpoints"];
59 [_connection addBreakpoint
:bp
];
61 [_savedBreakpoints addObject
:[bp dictionary
]];
62 [[NSUserDefaults standardUserDefaults
] setObject
:_savedBreakpoints forKey
:kPrefBreakpoints
];
65 - (Breakpoint
*)removeBreakpoint
:(Breakpoint
*)bp
67 // Use the -isEqual: test to find the object in |_breakpoints| that also has
68 // the debugger id and secure bookmark data.
69 NSUInteger idx
= [_breakpoints indexOfObject
:bp
];
70 if (idx
== NSNotFound
)
73 bp
= [_breakpoints objectAtIndex
:idx
];
75 [self willChangeValueForKey
:@
"breakpoints"];
76 [_breakpoints removeObject
:bp
];
77 [self didChangeValueForKey
:@
"breakpoints"];
79 [_connection removeBreakpoint
:bp
];
81 [_savedBreakpoints removeObject
:[bp dictionary
]];
82 [[NSUserDefaults standardUserDefaults
] setObject
:_savedBreakpoints forKey
:kPrefBreakpoints
];
88 * Returns all the breakpoints for a given file
90 - (NSSet
<NSNumber
*>*)breakpointsForFile
:(NSString
*)file
92 NSMutableSet
<NSNumber
*>* matches
= [NSMutableSet set
];
93 for (Breakpoint
* b
in _breakpoints
) {
94 if ([b.file isEqualToString
:file
]) {
95 [matches addObject
:@
(b.line
)];
103 - (BOOL)hasBreakpoint
:(Breakpoint
*)breakpoint
105 return [_breakpoints containsObject
:breakpoint
];