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
This commit is contained in:
Chris Hasiński
2026-01-24 01:24:46 +01:00
parent 97835e5678
commit d7249ab1de
+2 -5
View File
@@ -3319,12 +3319,9 @@ RETRY_TRY_BLOCK:
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);