6
** Author: Gregory Casamento <greg_casamento@yahoo.com>
8
** This program is free software; you can redistribute it and/or modify
9
** it under the terms of the GNU General Public License as published by
10
** the Free Software Foundation; either version 2 of the License, or
11
** (at your option) any later version.
13
** This program is distributed in the hope that it will be useful,
14
** but WITHOUT ANY WARRANTY; without even the implied warranty of
15
** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16
** GNU General Public License for more details.
18
** You should have received a copy of the GNU General Public License
19
** along with this program; if not, write to the Free Software
20
** Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
23
#import <AppKit/AppKit.h>
24
#import "PCDebugger.h"
25
#import "PCDebuggerView.h"
27
#ifndef NOTIFICATION_CENTER
28
#define NOTIFICATION_CENTER [NSNotificationCenter defaultCenter]
31
static NSImage *goImage = nil;
32
static NSImage *pauseImage = nil;
33
static NSImage *continueImage = nil;
34
static NSImage *restartImage = nil;
35
static NSImage *nextImage = nil;
36
static NSImage *stepInImage = nil;
37
static NSImage *stepOutImage = nil;
38
static NSImage *upImage = nil;
39
static NSImage *downImage = nil;
41
@implementation PCDebugger
44
if (self == [PCDebugger class])
49
bundle = [NSBundle bundleForClass: self];
50
path = [bundle pathForImageResource: @"go_button"];
53
goImage = [[NSImage alloc] initWithContentsOfFile: path];
55
path = [bundle pathForImageResource: @"pause_button"];
58
pauseImage = [[NSImage alloc] initWithContentsOfFile: path];
60
path = [bundle pathForImageResource: @"continue_button"];
63
continueImage = [[NSImage alloc] initWithContentsOfFile: path];
65
path = [bundle pathForImageResource: @"restart_button"];
68
restartImage = [[NSImage alloc] initWithContentsOfFile: path];
70
path = [bundle pathForImageResource: @"next_button"];
73
nextImage = [[NSImage alloc] initWithContentsOfFile: path];
75
path = [bundle pathForImageResource: @"stepin_button"];
78
stepInImage = [[NSImage alloc] initWithContentsOfFile: path];
80
path = [bundle pathForImageResource: @"stepout_button"];
83
stepOutImage = [[NSImage alloc] initWithContentsOfFile: path];
85
path = [bundle pathForImageResource: @"up_button"];
88
upImage = [[NSImage alloc] initWithContentsOfFile: path];
90
path = [bundle pathForImageResource: @"down_button"];
93
downImage = [[NSImage alloc] initWithContentsOfFile: path];
100
if((self = [super init]) != nil)
102
// initialization here...
103
if([NSBundle loadNibNamed: @"PCDebugger" owner: self] == NO)
108
[(PCDebuggerView *)debuggerView setDebugger:self];
113
-(void) debugExecutableAtPath: (NSString *)filePath
114
withDebugger: (NSString *)debugger
116
ASSIGN(path,filePath);
117
ASSIGN(debuggerPath,debugger);
118
[debuggerWindow setTitle: [NSString stringWithFormat: @"Debugger (%@)",filePath]];
124
[debuggerWindow makeKeyAndOrderFront: self];
125
[self startDebugger];
128
- (void) startDebugger
130
[debuggerView runProgram: debuggerPath
131
inCurrentDirectory: [path stringByDeletingLastPathComponent]
132
withArguments: [[NSArray alloc] initWithObjects: @"-f", path, nil]
133
logStandardError: YES];
136
- (void) awakeFromNib
138
NSToolbar *toolbar = [(NSToolbar *)[NSToolbar alloc] initWithIdentifier: @"PCDebuggerToolbar"];
139
[toolbar setAllowsUserCustomization: NO];
140
[toolbar setDelegate: self];
141
[debuggerWindow setToolbar: toolbar];
144
[debuggerView setFont: [NSFont userFixedPitchFontOfSize: 0]];
145
[debuggerWindow setFrameAutosaveName: @"PCDebuggerWindow"];
146
[self setStatus: @"Idle."];
149
- (NSWindow *)debuggerWindow
151
return debuggerWindow;
154
- (void)setDebuggerWindow: (NSWindow *)window
156
debuggerWindow = window;
159
- (NSView *)debuggerView
164
- (void)setDebuggerView: (id)view
174
- (void)setPath:(NSString *)p
179
// action methods for toolbar...
180
- (void) go: (id) sender
182
[self setStatus: @"Running..."];
183
[debuggerView putString: @"run\n"];
186
- (void) pause: (id) sender
188
[self setStatus: @"Stopped."];
189
[debuggerView interrupt];
192
- (void) continue: (id) sender
194
[self setStatus: @"Continue..."];
195
[debuggerView putString: @"continue\n"];
198
- (void) restart: (id) sender
200
[self setStatus: @"Restarting..."];
201
[debuggerView interrupt];
202
[debuggerView putString: @"run\n"];
203
[self setStatus: @"Running..."];
206
- (void) next: (id) sender
208
[self setStatus: @"Going to next line."];
209
[debuggerView putString: @"next\n"];
212
- (void) stepInto: (id) sender
214
[self setStatus: @"Stepping into method."];
215
[debuggerView putString: @"step\n"];
218
- (void) stepOut: (id) sender
220
[self setStatus: @"Finishing method."];
221
[debuggerView putString: @"finish\n"];
224
- (void) up: (id) sender
226
[self setStatus: @"Up to calling method."];
227
[debuggerView putString: @"up\n"];
230
- (void) down: (id) sender
232
[self setStatus: @"Down to called method."];
233
[debuggerView putString: @"down\n"];
237
- (void) setStatus: (NSString *) status
239
[statusField setStringValue: status];
242
- (NSString *) status
244
return [statusField stringValue];
249
[debuggerWindow close];
254
@implementation PCDebugger (NSToolbarDelegate)
256
- (NSToolbarItem*)toolbar: (NSToolbar*)toolbar
257
itemForItemIdentifier: (NSString*)itemIdentifier
258
willBeInsertedIntoToolbar: (BOOL)flag
260
NSToolbarItem *toolbarItem = AUTORELEASE([[NSToolbarItem alloc]
261
initWithItemIdentifier: itemIdentifier]);
263
if([itemIdentifier isEqual: @"GoItem"])
265
[toolbarItem setLabel: @"Go"];
266
[toolbarItem setImage: goImage];
267
[toolbarItem setTarget: self];
268
[toolbarItem setAction: @selector(go:)];
269
[toolbarItem setTag: 0];
271
else if([itemIdentifier isEqual: @"PauseItem"])
273
[toolbarItem setLabel: @"Pause"];
274
[toolbarItem setImage: pauseImage];
275
[toolbarItem setTarget: self];
276
[toolbarItem setAction: @selector(pause:)];
277
[toolbarItem setTag: 1];
279
else if([itemIdentifier isEqual: @"ContinueItem"])
281
[toolbarItem setLabel: @"Continue"];
282
[toolbarItem setImage: continueImage];
283
[toolbarItem setTarget: self];
284
[toolbarItem setAction: @selector(continue:)];
285
[toolbarItem setTag: 1];
287
else if([itemIdentifier isEqual: @"RestartItem"])
289
[toolbarItem setLabel: @"Restart"];
290
[toolbarItem setImage: restartImage];
291
[toolbarItem setTarget: self];
292
[toolbarItem setAction: @selector(restart:)];
293
[toolbarItem setTag: 2];
295
else if([itemIdentifier isEqual: @"NextItem"])
297
[toolbarItem setLabel: @"Next"];
298
[toolbarItem setImage: nextImage];
299
[toolbarItem setTarget: self];
300
[toolbarItem setAction: @selector(next:)];
301
[toolbarItem setTag: 3];
303
else if([itemIdentifier isEqual: @"StepIntoItem"])
305
[toolbarItem setLabel: @"Step Into"];
306
[toolbarItem setImage: stepInImage];
307
[toolbarItem setTarget: self];
308
[toolbarItem setAction: @selector(stepInto:)];
309
[toolbarItem setTag: 4];
311
else if([itemIdentifier isEqual: @"StepOutItem"])
313
[toolbarItem setLabel: @"Step Out"];
314
[toolbarItem setImage: stepOutImage];
315
[toolbarItem setTarget: self];
316
[toolbarItem setAction: @selector(stepOut:)];
317
[toolbarItem setTag: 5];
319
else if([itemIdentifier isEqual: @"UpItem"])
321
[toolbarItem setLabel: @"Up"];
322
[toolbarItem setImage: upImage];
323
[toolbarItem setTarget: self];
324
[toolbarItem setAction: @selector(up:)];
325
[toolbarItem setTag: 6];
327
else if([itemIdentifier isEqual: @"DownItem"])
329
[toolbarItem setLabel: @"Down"];
330
[toolbarItem setImage: downImage];
331
[toolbarItem setTarget: self];
332
[toolbarItem setAction: @selector(down:)];
333
[toolbarItem setTag: 7];
339
- (NSArray*) toolbarAllowedItemIdentifiers: (NSToolbar*)toolbar
341
return [NSArray arrayWithObjects: @"GoItem",
353
- (NSArray*) toolbarDefaultItemIdentifiers: (NSToolbar*)toolbar
355
return [NSArray arrayWithObjects: @"GoItem",
367
- (NSArray*) toolbarSelectableItemIdentifiers: (NSToolbar*)toolbar
369
return [NSArray arrayWithObjects: @"GoItem",