2020-03-24 16:07:58 +00:00
|
|
|
#include <Array.h>
|
2020-03-25 01:00:18 +00:00
|
|
|
#include <QF/keys.h>
|
2020-03-24 16:07:58 +00:00
|
|
|
|
2020-03-24 16:32:52 +00:00
|
|
|
#include "qwaq-app.h"
|
2020-03-24 16:07:58 +00:00
|
|
|
#include "qwaq-curses.h"
|
|
|
|
#include "qwaq-debugger.h"
|
|
|
|
#include "qwaq-editor.h"
|
2020-03-25 01:00:18 +00:00
|
|
|
#include "qwaq-listener.h"
|
2020-03-24 16:07:58 +00:00
|
|
|
#include "qwaq-proxyview.h"
|
|
|
|
#include "qwaq-window.h"
|
|
|
|
|
|
|
|
@implementation Debugger
|
2020-03-24 16:32:52 +00:00
|
|
|
-(qdb_target_t)debug_target
|
|
|
|
{
|
|
|
|
return debug_target;
|
|
|
|
}
|
2020-03-24 16:07:58 +00:00
|
|
|
|
|
|
|
-initWithTarget:(qdb_target_t) target
|
|
|
|
{
|
|
|
|
if (!(self = [super init])) {
|
|
|
|
return nil;
|
|
|
|
}
|
|
|
|
debug_target = target;
|
|
|
|
|
|
|
|
files = [[Array array] retain];
|
2020-03-24 16:32:52 +00:00
|
|
|
source_window = [[Window alloc] initWithRect: {nil, [application size]}];
|
|
|
|
[application addView:source_window];
|
2020-03-24 16:07:58 +00:00
|
|
|
|
|
|
|
return self;
|
|
|
|
}
|
|
|
|
|
|
|
|
-(Editor *) find_file:(string) filename
|
|
|
|
{
|
|
|
|
Editor *file;
|
|
|
|
for (int i = [files count]; i-- > 0; ) {
|
|
|
|
file = [files objectAtIndex: i];
|
|
|
|
if ([file filename] == filename) {
|
|
|
|
return file;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
Rect rect = {{1, 1}, [source_window size]};
|
|
|
|
rect.extent.width -= 2;
|
|
|
|
rect.extent.height -= 2;
|
|
|
|
file = [[Editor alloc] initWithRect: rect file: filename];
|
|
|
|
[files addObject: file];
|
|
|
|
return file;
|
|
|
|
}
|
|
|
|
|
|
|
|
-(void) setup
|
|
|
|
{
|
|
|
|
qdb_state_t state = qdb_get_state (debug_target);
|
|
|
|
|
|
|
|
current_file = [self find_file: state.file];
|
|
|
|
file_proxy = [[ProxyView alloc] initWithView: current_file];
|
2020-03-24 23:28:12 +00:00
|
|
|
[[current_file gotoLine:state.line - 1] highlightLine];
|
2020-03-25 01:00:18 +00:00
|
|
|
[[current_file onEvent] addListener: self :@selector(key_event:)];
|
2020-03-24 16:07:58 +00:00
|
|
|
//FIXME id<View>?
|
|
|
|
[source_window insertSelected: (View *) file_proxy];
|
2020-03-24 16:39:56 +00:00
|
|
|
[source_window setTitle: [current_file filename]];
|
2020-03-24 16:32:52 +00:00
|
|
|
[source_window redraw];
|
2020-03-24 16:07:58 +00:00
|
|
|
}
|
|
|
|
|
2020-03-25 01:00:18 +00:00
|
|
|
-(void) show_line
|
|
|
|
{
|
|
|
|
qdb_state_t state = qdb_get_state (debug_target);
|
|
|
|
Editor *file = [self find_file: state.file];
|
|
|
|
|
|
|
|
printf ("%s:%d\n", state.file, state.line);
|
|
|
|
if (current_file != file) {
|
|
|
|
[[current_file onEvent] removeListener:self :@selector(key_event:)];
|
|
|
|
[file_proxy setView:file];
|
|
|
|
[[file onEvent] addListener:self :@selector(key_event:)];
|
|
|
|
[source_window setTitle: [file filename]];
|
|
|
|
current_file = file;
|
|
|
|
}
|
|
|
|
[[current_file gotoLine:state.line - 1] highlightLine];
|
|
|
|
[source_window redraw];
|
|
|
|
}
|
|
|
|
|
|
|
|
-(void)key_event: (ed_event_t *)_event
|
|
|
|
{
|
|
|
|
qwaq_event_t *event = _event.event;
|
|
|
|
if (event.what == qe_keydown) {
|
|
|
|
switch (event.key.code) {
|
|
|
|
case QFK_F7:
|
|
|
|
qdb_set_trace (debug_target, 1);
|
|
|
|
qdb_continue (debug_target);
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
event.what = qe_none;
|
|
|
|
}
|
|
|
|
|
2020-03-24 16:07:58 +00:00
|
|
|
-handleDebugEvent
|
|
|
|
{
|
|
|
|
if (!file_proxy) {
|
|
|
|
[self setup];
|
|
|
|
}
|
2020-03-25 01:00:18 +00:00
|
|
|
[self show_line];
|
2020-03-24 16:07:58 +00:00
|
|
|
return self;
|
|
|
|
}
|
|
|
|
|
|
|
|
@end
|
|
|
|
|
|
|
|
void qdb_set_trace (qdb_target_t target, int state) = #0;
|
|
|
|
int qdb_set_breakpoint (qdb_target_t target, unsigned staddr) = #0;
|
|
|
|
int qdb_clear_breakpoint (qdb_target_t target, unsigned staddr) = #0;
|
|
|
|
int qdb_set_watchpoint (qdb_target_t target, unsigned offset) = #0;
|
|
|
|
int qdb_clear_watchpoint (qdb_target_t target) = #0;
|
|
|
|
int qdb_continue (qdb_target_t target) = #0;
|
|
|
|
qdb_state_t qdb_get_state (qdb_target_t target) = #0;
|