Remove -[DebuggerBackEndDelegate errorEncountered:].
[macgdbp.git] / Source / DebuggerModel.m
1 /*
2 * MacGDBp
3 * Copyright (c) 2015, Blue Static <https://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 "DebuggerModel.h"
18
19 #import "StackFrame.h"
20
21 @implementation DebuggerModel {
22 NSMutableArray* _stack;
23 }
24
25 - (instancetype)init {
26 if (self = [super init]) {
27 _stack = [NSMutableArray new];
28 }
29 return self;
30 }
31
32 - (void)dealloc {
33 [_status release];
34 [_stack release];
35 [super dealloc];
36 }
37
38 - (NSUInteger)stackDepth {
39 return self.stack.count;
40 }
41
42 - (void)onNewConnection {
43 self.status = nil;
44 _connected = YES;
45 [_stack removeAllObjects];
46 }
47
48 - (void)onDisconnect {
49 _connected = NO;
50 }
51
52 - (void)updateStack:(NSArray<StackFrame*>*)newStack {
53 // Iterate, in reverse order from the bottom to the top, both stacks to find
54 // the point of divergence.
55 NSEnumerator* itNewStack = [newStack reverseObjectEnumerator];
56 NSEnumerator* itOldStack = [self.stack reverseObjectEnumerator];
57
58 StackFrame* frameNew;
59 StackFrame* frameOld = [itOldStack nextObject];
60 NSUInteger oldStackOffset = self.stack.count;
61 while (frameNew = [itNewStack nextObject]) {
62 if ([frameNew isEqual:frameOld]) {
63 --oldStackOffset;
64 frameOld = [itOldStack nextObject];
65 } else {
66 break;
67 }
68 }
69
70 [self willChangeValueForKey:@"stack"];
71
72 // Remove any frames from the top of the stack that are not shared with the
73 // new stack.
74 [_stack removeObjectsInRange:NSMakeRange(0, oldStackOffset)];
75
76 // Continue inserting objects to update the stack with the new frames.
77 while (frameNew) {
78 [_stack insertObject:frameNew atIndex:0];
79 frameNew = [itNewStack nextObject];
80 }
81
82 // Renumber the stack.
83 for (NSUInteger i = 0; i < self.stack.count; ++i)
84 self.stack[i].index = i;
85
86 [self didChangeValueForKey:@"stack"];
87 }
88
89 @end