From d7249ab1de48b2dacb7faa1f610c9e74a43e7536 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Chris=20Hasi=C5=84ski?= Date: Sat, 24 Jan 2026 01:24:46 +0100 Subject: [PATCH] Fix OP_DEBUG operand type and add NULL check for debug_op_hook 1. Change CASE(OP_DEBUG, Z) to CASE(OP_DEBUG, BBB) to match the definition in include/mruby/ops.h. The previous code declared Z (no operands) but then manually called FETCH_BBB(), which caused incorrect behavior with extended opcodes (OP_EXT1/2/3). 2. Add NULL check before calling debug_op_hook, consistent with how code_fetch_hook is handled. This prevents crashes when MRB_USE_DEBUG_HOOK is enabled but no hook function is set. Fixes: #5686 --- src/vm.c | 7 ++----- 1 file changed, 2 insertions(+), 5 deletions(-) diff --git a/src/vm.c b/src/vm.c index b3bb28a8ba..0a06cd074d 100644 --- a/src/vm.c +++ b/src/vm.c @@ -3319,12 +3319,9 @@ mrb_vm_exec(mrb_state *mrb, const struct RProc *begin_proc, const mrb_code *iseq NEXT; } - CASE(OP_DEBUG, Z) { - const mrb_code *pc = ci->pc; - FETCH_BBB(); - ci->pc = pc; + CASE(OP_DEBUG, BBB) { #ifdef MRB_USE_DEBUG_HOOK - mrb->debug_op_hook(mrb, irep, ci->pc, regs); + if (mrb->debug_op_hook) mrb->debug_op_hook(mrb, irep, ci->pc, regs); #else #ifndef MRB_NO_STDIO printf("OP_DEBUG %d %d %d\n", a, b, c);