From 2d5df34234d02ba6bd0e9bac5d7c0ab5d659c2d3 Mon Sep 17 00:00:00 2001 From: Bill Currie Date: Thu, 26 Mar 2020 12:30:32 +0900 Subject: [PATCH] [gamecode] Add VM enter/exit events And rename prd_exit to prd_terminate (the idea is the host will terminate the VM). This makes it possible for the debugger to pause the VM before any code, even a builtin function, is executed. Breaks the debugger source window, but only because it's not updating on file change (I think). --- include/QF/progs.h | 4 +++- libs/gamecode/pr_exec.c | 7 +++++++ ruamoko/qwaq/main.c | 2 +- 3 files changed, 11 insertions(+), 2 deletions(-) diff --git a/include/QF/progs.h b/include/QF/progs.h index c393be5a5..c08bf12d5 100644 --- a/include/QF/progs.h +++ b/include/QF/progs.h @@ -1710,7 +1710,9 @@ typedef enum { prd_trace, prd_breakpoint, prd_watchpoint, - prd_exit, // not sent by VM + prd_subenter, + prd_subexit, // current invocation of PR_ExecuteProgram finished + prd_terminate, // not sent by VM prd_runerror, prd_error, // lower level error thann prd_runerror } prdebug_t; diff --git a/libs/gamecode/pr_exec.c b/libs/gamecode/pr_exec.c index 425ec5f64..b0a7cb820 100644 --- a/libs/gamecode/pr_exec.c +++ b/libs/gamecode/pr_exec.c @@ -458,6 +458,10 @@ PR_ExecuteProgram (progs_t *pr, func_t fnum) Sys_PushSignalHook (signal_hook, pr); Sys_PushErrorHandler (error_handler, pr); + if (pr->debug_handler) { + pr->debug_handler (prd_subenter, &fnum, pr->debug_data); + } + if (!PR_CallFunction (pr, fnum)) { // called a builtin instead of progs code goto exit_program; @@ -1723,6 +1727,9 @@ op_call: } } exit_program: + if (pr->debug_handler) { + pr->debug_handler (prd_subexit, 0, pr->debug_data); + } pr->pr_argc = 0; Sys_PopErrorHandler (); Sys_PopSignalHook (); diff --git a/ruamoko/qwaq/main.c b/ruamoko/qwaq/main.c index 8c9650786..bbd66bac1 100644 --- a/ruamoko/qwaq/main.c +++ b/ruamoko/qwaq/main.c @@ -233,7 +233,7 @@ 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_exit, 0, thread->pr->debug_data); + thread->pr->debug_handler (prd_terminate, 0, thread->pr->debug_data); } thread->return_code = R_INT (thread->pr); return thread;