From b5d41818e23201f22eabab654e49aa090013f61e Mon Sep 17 00:00:00 2001 From: Ben Noordhuis Date: Thu, 14 Nov 2024 22:50:42 +0100 Subject: [PATCH] Fix bytecode stack frame printing (#686) Handle OP_get_loc0_loc1 specially. Fixes an off-by-one when printing variable names. Fixes: https://github.com/quickjs-ng/quickjs/issues/683 --- quickjs.c | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) diff --git a/quickjs.c b/quickjs.c index 1e776c5..73819c0 100644 --- a/quickjs.c +++ b/quickjs.c @@ -28783,8 +28783,17 @@ static void dump_byte_code(JSContext *ctx, int pass, printf(",%u", get_u16(tab + pos + 8)); break; case OP_FMT_none_loc: - idx = (op - OP_get_loc0_loc1) % 4; - goto has_loc; + if (op == OP_get_loc0_loc1) { + printf(" 0, 1 ; "); + if (var_count > 0) + print_atom(ctx, vars[0].var_name); + if (var_count > 1) + print_atom(ctx, vars[1].var_name); + } else { + idx = (op - OP_get_loc0) % 4; + goto has_loc; + } + break; case OP_FMT_loc8: idx = get_u8(tab + pos); goto has_loc;