2020-03-25 01:00:18 +00:00
|
|
|
#include <QF/keys.h>
|
2020-03-26 09:19:25 +00:00
|
|
|
#include <Array.h>
|
|
|
|
#include <string.h>
|
|
|
|
#include <types.h>
|
2020-03-24 16:07:58 +00:00
|
|
|
|
2020-03-29 17:34:08 +00:00
|
|
|
#include "ui/curses.h"
|
|
|
|
#include "ui/listener.h"
|
|
|
|
#include "ui/proxyview.h"
|
|
|
|
#include "ui/window.h"
|
|
|
|
#include "debugger/debugger.h"
|
2020-03-30 03:43:02 +00:00
|
|
|
#include "debugger/typeencodings.h"
|
2020-03-29 17:34:08 +00:00
|
|
|
#include "editor/editor.h"
|
2020-03-24 16:32:52 +00:00
|
|
|
#include "qwaq-app.h"
|
2020-03-24 16:07:58 +00:00
|
|
|
|
|
|
|
@implementation Debugger
|
2020-03-30 03:43:02 +00:00
|
|
|
-(qdb_target_t)target
|
2020-03-24 16:32:52 +00:00
|
|
|
{
|
2020-03-30 03:43:02 +00:00
|
|
|
return target;
|
2020-03-24 16:32:52 +00:00
|
|
|
}
|
2020-03-24 16:07:58 +00:00
|
|
|
|
|
|
|
-initWithTarget:(qdb_target_t) target
|
|
|
|
{
|
|
|
|
if (!(self = [super init])) {
|
|
|
|
return nil;
|
|
|
|
}
|
2020-03-30 03:43:02 +00:00
|
|
|
self.target = target;
|
2020-03-24 16:07:58 +00:00
|
|
|
|
|
|
|
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
|
|
|
|
{
|
2020-03-30 03:43:02 +00:00
|
|
|
qdb_state_t state = qdb_get_state (target);
|
2020-03-24 16:07:58 +00:00
|
|
|
|
|
|
|
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-26 09:22:40 +00:00
|
|
|
[[current_file onEvent] addListener: self :@selector(proxy_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-26 00:04:31 +00:00
|
|
|
|
|
|
|
locals_window = [[Window alloc] initWithRect: {{0, 0}, {40, 10}}];
|
|
|
|
[locals_window setBackground: color_palette[064]];
|
|
|
|
[locals_window setTitle: "Locals"];
|
2020-03-30 04:42:31 +00:00
|
|
|
locals_view = [[LocalsView alloc] initWithRect: {{1, 1}, {38, 8}}
|
|
|
|
target: target];
|
2020-03-26 00:04:31 +00:00
|
|
|
[locals_window insertSelected: locals_view];
|
|
|
|
[application addView: locals_window];
|
2020-03-26 09:22:40 +00:00
|
|
|
|
|
|
|
[[locals_view onEvent] addListener:self :@selector(proxy_event::)];
|
2020-03-24 16:07:58 +00:00
|
|
|
}
|
|
|
|
|
2020-03-25 01:00:18 +00:00
|
|
|
-(void) show_line
|
|
|
|
{
|
2020-03-30 03:43:02 +00:00
|
|
|
qdb_state_t state = qdb_get_state (target);
|
2020-03-25 01:00:18 +00:00
|
|
|
Editor *file = [self find_file: state.file];
|
|
|
|
|
|
|
|
printf ("%s:%d\n", state.file, state.line);
|
|
|
|
if (current_file != file) {
|
2020-03-26 09:22:40 +00:00
|
|
|
[[current_file onEvent] removeListener:self :@selector(proxy_event::)];
|
2020-03-25 01:00:18 +00:00
|
|
|
[file_proxy setView:file];
|
2020-03-26 09:22:40 +00:00
|
|
|
[[file onEvent] addListener:self :@selector(proxy_event::)];
|
2020-03-25 01:00:18 +00:00
|
|
|
[source_window setTitle: [file filename]];
|
|
|
|
current_file = file;
|
|
|
|
}
|
|
|
|
[[current_file gotoLine:state.line - 1] highlightLine];
|
|
|
|
[source_window redraw];
|
|
|
|
}
|
|
|
|
|
2020-03-26 00:04:31 +00:00
|
|
|
-(void)update_watchvars
|
|
|
|
{
|
2020-03-30 03:43:02 +00:00
|
|
|
qdb_state_t state = qdb_get_state (target);
|
2020-03-30 04:42:31 +00:00
|
|
|
[locals_view setFunction:state.func];
|
|
|
|
[locals_view redraw];
|
2020-03-26 00:04:31 +00:00
|
|
|
}
|
|
|
|
|
2020-03-26 00:19:22 +00:00
|
|
|
static int
|
2020-03-26 09:22:40 +00:00
|
|
|
proxy_event (Debugger *self, id proxy, qwaq_event_t *event)
|
2020-03-25 01:00:18 +00:00
|
|
|
{
|
2020-03-26 00:19:22 +00:00
|
|
|
if (event.what == qe_mouseclick && !(event.mouse.buttons & 0x78)) {
|
2020-03-26 09:22:40 +00:00
|
|
|
if (proxy == self.current_file) {
|
|
|
|
printf ("%s\n", [proxy getWordAt: {event.mouse.x, event.mouse.y}]);
|
|
|
|
[self.source_window redraw];
|
|
|
|
return 1;
|
|
|
|
}
|
2020-03-25 08:29:08 +00:00
|
|
|
} else if (event.what == qe_keydown) {
|
2020-03-25 01:00:18 +00:00
|
|
|
switch (event.key.code) {
|
|
|
|
case QFK_F7:
|
2020-03-30 03:43:02 +00:00
|
|
|
qdb_set_trace (self.target, 1);
|
|
|
|
qdb_continue (self.target);
|
2020-03-26 00:19:22 +00:00
|
|
|
return 1;
|
2020-03-25 01:00:18 +00:00
|
|
|
}
|
|
|
|
}
|
2020-03-26 00:19:22 +00:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2020-03-26 09:22:40 +00:00
|
|
|
-(void)proxy_event:(id)proxy :(qwaq_event_t *)event
|
2020-03-26 00:19:22 +00:00
|
|
|
{
|
2020-03-26 09:22:40 +00:00
|
|
|
if (proxy_event (self, proxy, event)) {
|
2020-03-26 05:16:58 +00:00
|
|
|
event.what = qe_none;
|
2020-03-26 00:19:22 +00:00
|
|
|
}
|
2020-03-25 01:00:18 +00:00
|
|
|
}
|
|
|
|
|
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-26 00:04:31 +00:00
|
|
|
[self update_watchvars];
|
2020-03-24 16:07:58 +00:00
|
|
|
return self;
|
|
|
|
}
|
|
|
|
|
|
|
|
@end
|