[qwaq] Create a debugger class

Each debugger manages a single target.
This commit is contained in:
Bill Currie 2020-03-25 01:07:58 +09:00
parent e69c430abc
commit c7597b94d2
7 changed files with 129 additions and 6 deletions

View File

@ -26,6 +26,7 @@ SUFFIXES=.o .r
qwaq_app_dat_src= \
qwaq-app.r \
qwaq-button.r \
qwaq-debugger.r \
qwaq-draw.r \
qwaq-editbuffer.r \
qwaq-editor.r \

View File

@ -145,7 +145,9 @@ static void
qwaq_target_clear (progs_t *pr, void *data)
{
qwaq_target_t *target = pr->debug_data;
target_free (target->debugger, target);
if (target) {
target_free (target->debugger, target);
}
}
//FIXME need a better way to get this from one thread to the others
@ -274,10 +276,12 @@ qdb_get_state (progs_t *pr)
lineno = PR_Find_Lineno (tpr, staddr);
if (lineno) {
f = PR_Get_Lineno_Func (pr, lineno);
file = pr->pr_functions[f->function].s_file;
f = PR_Get_Lineno_Func (tpr, lineno);
//FIXME file is a permanent string. dynamic would be better
//but they're not merged (and would need refcounting)
file = PR_SetString (pr, PR_Get_Source_File (tpr, lineno));
func = f->function;
line = PR_Get_Lineno_Line (pr, lineno);
line = PR_Get_Lineno_Line (tpr, lineno);
line += f->source_line;
}

View File

@ -15,17 +15,34 @@ typedef enum {
#define umax 0x7fffffff
#endif
#else//GCC
typedef string string_t;
#endif
typedef struct qdb_state_s {
unsigned staddr;
unsigned func;
unsigned file;
string_t file;
unsigned line;
} qdb_state_t;
#ifdef __QFCC__
typedef struct qdb_target_s { int handle; } qdb_target_t;
@extern void qdb_set_trace (qdb_target_t target, int state);
@extern int qdb_set_breakpoint (qdb_target_t target, unsigned staddr);
@extern int qdb_clear_breakpoint (qdb_target_t target, unsigned staddr);
@extern int qdb_set_watchpoint (qdb_target_t target, unsigned offset);
@extern int qdb_clear_watchpoint (qdb_target_t target);
@extern int qdb_continue (qdb_target_t target);
@extern qdb_state_t qdb_get_state (qdb_target_t target);
#else//GCC
void QWAQ_Debug_Init (progs_t *pr);
void QWAQ_DebugTarget_Init (progs_t *pr);
#endif
#endif//__qwaq_debug_h

View File

@ -0,0 +1,25 @@
#ifndef __qwaq_debugger_h
#define __qwaq_debugger_h
#include <Object.h>
#include "qwaq-debug.h"
@class ProxyView;
@class Editor;
@class Window;
@class Array;
@interface Debugger : Object
{
Window *source_window;
ProxyView *file_proxy;
Array *files;
Editor *current_file;
qdb_target_t debug_target;
}
-initWithTarget:(qdb_target_t) target;
-handleDebugEvent;
@end
#endif//__qwaq_debugger_h

View File

@ -0,0 +1,68 @@
#include <Array.h>
#include "qwaq-curses.h"
#include "qwaq-debugger.h"
#include "qwaq-editor.h"
#include "qwaq-proxyview.h"
#include "qwaq-window.h"
@implementation Debugger
-initWithTarget:(qdb_target_t) target
{
if (!(self = [super init])) {
return nil;
}
debug_target = target;
files = [[Array array] retain];
//FIXME need a window manager
source_window = [[Window alloc] initWithRect: getwrect (stdscr)];
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];
//FIXME id<View>?
[source_window insertSelected: (View *) file_proxy];
}
-handleDebugEvent
{
if (!file_proxy) {
[self setup];
}
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;

View File

@ -18,8 +18,10 @@
unsigned old_cind; // previous character
Point cursor;
unsigned line_count;
string filename;
}
-initWithRect:(Rect) rect file:(string) filename;
-(string)filename;
-scrollUp:(unsigned) count;
-scrollDown:(unsigned) count;
-scrollLeft:(unsigned) count;

View File

@ -9,6 +9,7 @@
if (!(self = [super initWithRect: rect])) {
return nil;
}
self.filename = filename;
buffer = [[EditBuffer alloc] initWithFile: filename];
line_count = [buffer countLines: {0, [buffer textSize]}];
linebuffer = [DrawBuffer buffer: { xlen, 1 }];
@ -17,6 +18,11 @@
return self;
}
-(string)filename
{
return filename;
}
-draw
{
[super draw];