From aa02069dd1c2fd2d4b85e3ee06738cefcc4999e1 Mon Sep 17 00:00:00 2001 From: Bill Currie Date: Wed, 26 Feb 2020 13:40:26 +0900 Subject: [PATCH] Add a breakpoint flag to opcodes The progs execution code will call a breakpoint handler just before executing an instruction with the flag set. This means there's no need for the breakpoint handler to mess with execution state or even the instruction in order to continue past the breakpoint. The flag being set in a progs file is invalid. --- include/QF/pr_comp.h | 1 + include/QF/progs.h | 1 + libs/gamecode/pr_exec.c | 11 ++++++++++- 3 files changed, 12 insertions(+), 1 deletion(-) diff --git a/include/QF/pr_comp.h b/include/QF/pr_comp.h index 03f5b3a46..6458d3913 100644 --- a/include/QF/pr_comp.h +++ b/include/QF/pr_comp.h @@ -396,6 +396,7 @@ typedef enum { OP_MOD_F, OP_MOD_D, } pr_opcode_e; +#define OP_BREAK 0x8000 typedef struct opcode_s { const char *name; diff --git a/include/QF/progs.h b/include/QF/progs.h index 369360449..5abd0d1c6 100644 --- a/include/QF/progs.h +++ b/include/QF/progs.h @@ -1776,6 +1776,7 @@ struct progs_s { /// \name debugging ///@{ struct prdeb_resources_s *pr_debug_resources; + void (*breakpoint_handler) (progs_t *pr); pr_type_t *watch; int wp_conditional; pr_type_t wp_val; diff --git a/libs/gamecode/pr_exec.c b/libs/gamecode/pr_exec.c index 024594d81..b933572e4 100644 --- a/libs/gamecode/pr_exec.c +++ b/libs/gamecode/pr_exec.c @@ -440,7 +440,16 @@ PR_ExecuteProgram (progs_t *pr, func_t fnum) if (pr->pr_trace) PR_PrintStatement (pr, st, 1); - switch (st->op) { + if (st->op & OP_BREAK) { + if (pr->breakpoint_handler) { + pr->breakpoint_handler (pr); + } else { + PR_RunError (pr, "breakpoint hit"); + } + } + + pr_opcode_e op = st->op & ~OP_BREAK; + switch (op) { case OP_ADD_D: OPC_double_var = OPA_double_var + OPB_double_var; break;