[qwaq] Make debug event data available

This commit is contained in:
Bill Currie 2020-04-02 10:44:16 +09:00
parent c920c746f3
commit 6d8bc395f4
4 changed files with 51 additions and 3 deletions

View file

@ -56,6 +56,7 @@ typedef struct qwaq_target_s {
struct qwaq_debug_s *debugger;
int handle;
prdebug_t event;
void *param;
rwcond_t run_cond;
} qwaq_target_t;
@ -117,6 +118,7 @@ qwaq_debug_handler (prdebug_t debug_event, void *param, void *data)
int ret;
target->event = debug_event;
target->param = param;
event.what = qe_debug_event;
event.message.pointer_val = target->handle;
@ -294,6 +296,37 @@ qdb_get_state (progs_t *pr)
R_PACKED (pr, qdb_state_t) = state;
}
static void
qdb_get_event (progs_t *pr)
{
__auto_type debug = PR_Resources_Find (pr, "qwaq-debug");
pointer_t handle = P_INT (pr, 0);
qwaq_target_t *target = get_target (debug, __FUNCTION__, handle);
__auto_type event = &G_STRUCT (pr, qdb_event_t, P_INT (pr, 1));
memset (event, 0, sizeof (*event));
event->what = target->event;
switch (event->what) {
case prd_subenter:
event->func = *(func_t *) target->param;
break;
case prd_runerror:
case prd_error:
event->message = PR_SetReturnString (pr, *(char **) target->param);
break;
case prd_terminate:
event->exit_code = *(int *) target->param;
break;
case prd_trace:
case prd_breakpoint:
case prd_watchpoint:
case prd_subexit:
case prd_none:
break;
}
R_INT (pr) = target->event != prd_none;
}
static void
qdb_get_data (progs_t *pr)
{
@ -505,6 +538,7 @@ static builtin_t builtins[] = {
{"qdb_clear_watchpoint", qdb_clear_watchpoint, -1},
{"qdb_continue", qdb_continue, -1},
{"qdb_get_state", qdb_get_state, -1},
{"qdb_get_event", qdb_get_event, -1},
{"qdb_get_data", qdb_get_data, -1},
{"qdb_get_string|{tag qdb_target_s=}i", qdb_get_string, -1},
{"qdb_get_string|{tag qdb_target_s=}*", qdb_get_string, -1},

View file

@ -238,10 +238,11 @@ run_progs (void *data)
PR_ExecuteProgram (thread->pr, thread->main_func);
PR_PopFrame (thread->pr);
if (thread->pr->debug_handler) {
thread->pr->debug_handler (prd_terminate, 0, thread->pr->debug_data);
}
thread->return_code = R_INT (thread->pr);
if (thread->pr->debug_handler) {
thread->pr->debug_handler (prd_terminate, &thread->return_code,
thread->pr->debug_data);
}
return thread;
}

View file

@ -9,6 +9,8 @@ typedef enum {
#ifdef __QFCC__
#include <QF/pr_debug.h>
//FIXME finish unsigned in qfcc
#ifndef umax
#define umax 0x7fffffff
@ -18,6 +20,15 @@ typedef string string_t;
#endif
typedef struct qdb_event_s {
prdebug_t what;
union {
string_t message;
unsigned func;
int exit_code;
};
} qdb_event_t;
typedef struct qdb_state_s {
unsigned staddr;
unsigned func;
@ -62,6 +73,7 @@ int qdb_set_watchpoint (qdb_target_t target, unsigned offset);
int qdb_clear_watchpoint (qdb_target_t target);
int qdb_continue (qdb_target_t target);
qdb_state_t qdb_get_state (qdb_target_t target);
int qdb_get_event (qdb_target_t target, qdb_event_t *event);
int qdb_get_data (qdb_target_t target, unsigned src, unsigned len, void *dst);
@overload string qdb_get_string (qdb_target_t target, unsigned str);
// note: str is likely not valid in the host progs, it's just a convinience to

View file

@ -10,6 +10,7 @@ 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;
int qdb_get_event (qdb_target_t target, qdb_event_t *event) = #0;
int qdb_get_data (qdb_target_t target, unsigned src, unsigned len,
void *dst) = #0;
string qdb_get_string (qdb_target_t target, unsigned str) = #0;