2008-12-16 21:31:41 +00:00
|
|
|
/* All Rights reserved */
|
|
|
|
|
|
|
|
#include <AppKit/AppKit.h>
|
|
|
|
#include "PCDebugger.h"
|
2008-12-22 00:38:35 +00:00
|
|
|
#import "PCDebuggerView.h"
|
2008-12-16 21:31:41 +00:00
|
|
|
|
|
|
|
@implementation PCDebugger
|
2008-12-22 00:09:23 +00:00
|
|
|
- (id) initWithPath: (NSString *)filePath
|
2008-12-16 21:31:41 +00:00
|
|
|
{
|
2008-12-22 00:09:23 +00:00
|
|
|
if((self = [super init]) != nil)
|
2008-12-16 21:31:41 +00:00
|
|
|
{
|
|
|
|
// initialization here...
|
2008-12-22 00:09:23 +00:00
|
|
|
if([NSBundle loadNibNamed: @"PCDebugger" owner: self] == NO)
|
|
|
|
{
|
|
|
|
return nil;
|
|
|
|
}
|
2008-12-22 00:38:35 +00:00
|
|
|
[(PCDebuggerView *)debuggerView setDebugger:self];
|
2008-12-16 21:31:41 +00:00
|
|
|
}
|
|
|
|
return self;
|
|
|
|
}
|
|
|
|
|
2008-12-22 00:09:23 +00:00
|
|
|
+(id) debugExecutableAtPath: (NSString *)filePath
|
|
|
|
{
|
|
|
|
return [[self alloc] initWithPath: filePath];
|
|
|
|
}
|
|
|
|
|
|
|
|
- (void) show
|
|
|
|
{
|
|
|
|
[debuggerWindow makeKeyAndOrderFront: self];
|
|
|
|
[self startDebugger];
|
|
|
|
}
|
|
|
|
|
2008-12-16 21:31:41 +00:00
|
|
|
- (void) startDebugger
|
|
|
|
{
|
|
|
|
debuggerTask = [NSTask launchedTaskWithLaunchPath: @"/usr/bin/gdb"
|
2008-12-22 00:09:23 +00:00
|
|
|
arguments: NULL];
|
2008-12-16 21:31:41 +00:00
|
|
|
standardInput = [debuggerTask standardInput];
|
|
|
|
standardOutput = [debuggerTask standardOutput];
|
2008-12-22 00:38:35 +00:00
|
|
|
|
|
|
|
stdInStream = fdopen([standardInput fileDescriptor], "r");
|
|
|
|
if (stdInStream == NULL)
|
|
|
|
{
|
|
|
|
NSLog(@"Error creating file stream input to debugger");
|
|
|
|
return;
|
|
|
|
}
|
2008-12-16 21:31:41 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
- (void) awakeFromNib
|
|
|
|
{
|
2008-12-22 00:09:23 +00:00
|
|
|
[debuggerView setFont: [NSFont userFixedPitchFontOfSize: 0]];
|
|
|
|
}
|
|
|
|
|
|
|
|
- (NSWindow *)debuggerWindow
|
|
|
|
{
|
|
|
|
return debuggerWindow;
|
|
|
|
}
|
|
|
|
|
|
|
|
- (void)setDebuggerWindow: (NSWindow *)window
|
|
|
|
{
|
|
|
|
ASSIGN(debuggerWindow,window);
|
|
|
|
}
|
|
|
|
|
|
|
|
- (NSView *)debuggerView
|
|
|
|
{
|
|
|
|
return debuggerView;
|
|
|
|
}
|
|
|
|
|
|
|
|
- (void)setDebuggerView: (id)view
|
|
|
|
{
|
|
|
|
ASSIGN(debuggerView,view);
|
|
|
|
}
|
|
|
|
|
|
|
|
- (NSString *)path
|
|
|
|
{
|
|
|
|
return path;
|
|
|
|
}
|
|
|
|
|
|
|
|
- (void)setPath:(NSString *)p
|
|
|
|
{
|
|
|
|
ASSIGN(path,p);
|
2008-12-16 21:31:41 +00:00
|
|
|
}
|
2008-12-22 00:38:35 +00:00
|
|
|
|
|
|
|
- (void)putChar:(unichar)ch
|
|
|
|
{
|
|
|
|
fputc(ch, stdInStream);
|
|
|
|
}
|
2008-12-16 21:31:41 +00:00
|
|
|
@end
|