From c7597b94d2aca9a601440708f744fc3a49857e41 Mon Sep 17 00:00:00 2001 From: Bill Currie Date: Wed, 25 Mar 2020 01:07:58 +0900 Subject: [PATCH] [qwaq] Create a debugger class Each debugger manages a single target. --- ruamoko/qwaq/Makefile.am | 1 + ruamoko/qwaq/qwaq-debug.c | 12 ++++--- ruamoko/qwaq/qwaq-debug.h | 21 +++++++++-- ruamoko/qwaq/qwaq-debugger.h | 25 +++++++++++++ ruamoko/qwaq/qwaq-debugger.r | 68 ++++++++++++++++++++++++++++++++++++ ruamoko/qwaq/qwaq-editor.h | 2 ++ ruamoko/qwaq/qwaq-editor.r | 6 ++++ 7 files changed, 129 insertions(+), 6 deletions(-) create mode 100644 ruamoko/qwaq/qwaq-debugger.h create mode 100644 ruamoko/qwaq/qwaq-debugger.r diff --git a/ruamoko/qwaq/Makefile.am b/ruamoko/qwaq/Makefile.am index 3a65cfbbf..4f81c8424 100644 --- a/ruamoko/qwaq/Makefile.am +++ b/ruamoko/qwaq/Makefile.am @@ -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 \ diff --git a/ruamoko/qwaq/qwaq-debug.c b/ruamoko/qwaq/qwaq-debug.c index 8edcf992d..ea40ab2e4 100644 --- a/ruamoko/qwaq/qwaq-debug.c +++ b/ruamoko/qwaq/qwaq-debug.c @@ -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; } diff --git a/ruamoko/qwaq/qwaq-debug.h b/ruamoko/qwaq/qwaq-debug.h index f54d25636..0eb13d4a5 100644 --- a/ruamoko/qwaq/qwaq-debug.h +++ b/ruamoko/qwaq/qwaq-debug.h @@ -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 diff --git a/ruamoko/qwaq/qwaq-debugger.h b/ruamoko/qwaq/qwaq-debugger.h new file mode 100644 index 000000000..34809def2 --- /dev/null +++ b/ruamoko/qwaq/qwaq-debugger.h @@ -0,0 +1,25 @@ +#ifndef __qwaq_debugger_h +#define __qwaq_debugger_h + +#include + +#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 diff --git a/ruamoko/qwaq/qwaq-debugger.r b/ruamoko/qwaq/qwaq-debugger.r new file mode 100644 index 000000000..bd771c679 --- /dev/null +++ b/ruamoko/qwaq/qwaq-debugger.r @@ -0,0 +1,68 @@ +#include + +#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? + [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; diff --git a/ruamoko/qwaq/qwaq-editor.h b/ruamoko/qwaq/qwaq-editor.h index 2a480103e..0680cc9dc 100644 --- a/ruamoko/qwaq/qwaq-editor.h +++ b/ruamoko/qwaq/qwaq-editor.h @@ -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; diff --git a/ruamoko/qwaq/qwaq-editor.r b/ruamoko/qwaq/qwaq-editor.r index 9d36e27ac..0c0767c6d 100644 --- a/ruamoko/qwaq/qwaq-editor.r +++ b/ruamoko/qwaq/qwaq-editor.r @@ -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];