From c6aa061229b8a9cf8f293727b5d27f4c549e546f Mon Sep 17 00:00:00 2001 From: Bill Currie Date: Sat, 12 Feb 2022 10:19:45 +0900 Subject: [PATCH] [qwaq] Fetch Ruamoko progs locals from the stack frame Now that the data is fetched from the correct location, the locals view is useful again :). However, there seems to be a problem with array views: not sure they're showing the correct data as I was getting unexpected values in the display but normal vars seem to be ok. --- ruamoko/qwaq/builtins/debug.c | 31 ++++++++++++++++++++++++++++++ ruamoko/qwaq/debugger/debug.h | 2 ++ ruamoko/qwaq/debugger/debug.r | 2 ++ ruamoko/qwaq/debugger/localsdata.h | 1 + ruamoko/qwaq/debugger/localsdata.r | 16 +++++++++++++-- 5 files changed, 50 insertions(+), 2 deletions(-) diff --git a/ruamoko/qwaq/builtins/debug.c b/ruamoko/qwaq/builtins/debug.c index 73eb5972f..9b1d2b45e 100644 --- a/ruamoko/qwaq/builtins/debug.c +++ b/ruamoko/qwaq/builtins/debug.c @@ -649,6 +649,35 @@ qdb_get_source_line_addr (progs_t *pr) R_UINT (pr) = PR_FindSourceLineAddr (tpr, file, line); } +static void +qdb_has_data_stack (progs_t *pr) +{ + __auto_type debug = PR_Resources_Find (pr, "qwaq-debug"); + pr_ptr_t handle = P_INT (pr, 0); + qwaq_target_t *target = get_target (debug, __FUNCTION__, handle); + progs_t *tpr = target->pr; + + R_INT (pr) = tpr->progs->version == PROG_VERSION; +} + +static void +qdb_get_frame_addr (progs_t *pr) +{ + __auto_type debug = PR_Resources_Find (pr, "qwaq-debug"); + pr_ptr_t handle = P_INT (pr, 0); + qwaq_target_t *target = get_target (debug, __FUNCTION__, handle); + progs_t *tpr = target->pr; + + R_UINT (pr) = 0; + + if (tpr->progs->version == PROG_VERSION) { + if (tpr->pr_depth) { + prstack_t *frame = tpr->pr_stack + tpr->pr_depth - 1; + R_UINT (pr) = frame->stack_ptr; + } + } +} + #define bi(x,np,params...) {#x, x, -1, np, {params}} #define p(type) PR_PARAM(type) static builtin_t builtins[] = { @@ -675,6 +704,8 @@ static builtin_t builtins[] = { bi(qdb_get_auxfunction, 2, p(int), p(uint)), bi(qdb_get_local_defs, 2, p(int), p(uint)), bi(qdb_get_source_line_addr, 3, p(int), p(string), p(uint)), + bi(qdb_has_data_stack, 1, p(int)), + bi(qdb_get_frame_addr, 1, p(int)), {} }; diff --git a/ruamoko/qwaq/debugger/debug.h b/ruamoko/qwaq/debugger/debug.h index bfc0d4f88..788c3aff7 100644 --- a/ruamoko/qwaq/debugger/debug.h +++ b/ruamoko/qwaq/debugger/debug.h @@ -98,6 +98,8 @@ qdb_auxfunction_t *qdb_get_auxfunction (qdb_target_t target, unsigned fnum); qdb_def_t *qdb_get_local_defs (qdb_target_t target, unsigned fnum); unsigned qdb_get_source_line_addr(qdb_target_t target, string file, unsigned line); +int qdb_has_data_stack (qdb_target_t target); +unsigned qdb_get_frame_addr (qdb_target_t target); void traceon(); void traceoff(); diff --git a/ruamoko/qwaq/debugger/debug.r b/ruamoko/qwaq/debugger/debug.r index 3b6d25efe..523476275 100644 --- a/ruamoko/qwaq/debugger/debug.r +++ b/ruamoko/qwaq/debugger/debug.r @@ -30,3 +30,5 @@ qdb_auxfunction_t *qdb_get_auxfunction (qdb_target_t target, qdb_def_t *qdb_get_local_defs (qdb_target_t target, unsigned fnum) = #0; unsigned qdb_get_source_line_addr(qdb_target_t target, string file, unsigned line) = #0; +int qdb_has_data_stack (qdb_target_t target) = #0; +unsigned qdb_get_frame_addr (qdb_target_t target) = #0; diff --git a/ruamoko/qwaq/debugger/localsdata.h b/ruamoko/qwaq/debugger/localsdata.h index 70ca87a26..3d4080998 100644 --- a/ruamoko/qwaq/debugger/localsdata.h +++ b/ruamoko/qwaq/debugger/localsdata.h @@ -12,6 +12,7 @@ { ListenerGroup *onRowCountChanged; qdb_target_t target; + int has_stack; qfot_type_encodings_t target_encodings; unsigned current_fnum; qdb_function_t *func; diff --git a/ruamoko/qwaq/debugger/localsdata.r b/ruamoko/qwaq/debugger/localsdata.r index 68f9cc560..73b0f51cc 100644 --- a/ruamoko/qwaq/debugger/localsdata.r +++ b/ruamoko/qwaq/debugger/localsdata.r @@ -19,6 +19,8 @@ qdb_get_data (target, encodings_def.offset, sizeof(target_encodings), &target_encodings); + self.has_stack = qdb_has_data_stack (target); + self.onRowCountChanged = [[ListenerGroup listener] retain]; return self; } @@ -104,8 +106,18 @@ free_defs (LocalsData *self) -fetchData { - if (data && func.local_size && func.local_data) { - qdb_get_data (target, func.local_data, func.local_size, data); + if (data && func.local_size) { + unsigned local_data = func.local_data; + if (has_stack) { + unsigned stack_ptr = qdb_get_frame_addr (target); + local_data = 0; + if (stack_ptr) { + local_data = stack_ptr - func.local_data; + } + } + if (local_data) { + qdb_get_data (target, local_data, func.local_size, data); + } } int rowCount = def_rows[num_user_defs]; if (aux_func) {