patch 8.2.3011: Vim9: cannot get argument values during debugging
Problem: Vim9: cannot get argument values during debugging.
Solution: Lookup names in the list of arguments. Put debug instruction
halfway for command.
diff --git a/src/vim9compile.c b/src/vim9compile.c
index 663a52d..404c819 100644
--- a/src/vim9compile.c
+++ b/src/vim9compile.c
@@ -7711,6 +7711,7 @@
int semicolon = FALSE;
size_t varlen;
garray_T *stack = &cctx->ctx_type_stack;
+ garray_T *instr = &cctx->ctx_instr;
scope_T *scope;
lvar_T *loop_lvar; // loop iteration variable
lvar_T *var_lvar; // variable for "var"
@@ -7737,6 +7738,13 @@
if (may_get_next_line_error(wp, &p, cctx) == FAIL)
return NULL;
+ // Remove the already generated ISN_DEBUG, it is written below the ISN_FOR
+ // instruction.
+ if (cctx->ctx_compile_type == CT_DEBUG && instr->ga_len > 0
+ && ((isn_T *)instr->ga_data)[instr->ga_len - 1]
+ .isn_type == ISN_DEBUG)
+ --instr->ga_len;
+
scope = new_scope(cctx, FOR_SCOPE);
if (scope == NULL)
return NULL;
@@ -7788,11 +7796,12 @@
item_type = vartype->tt_member->tt_member;
}
- // CMDMOD_REV must come before the FOR instruction
+ // CMDMOD_REV must come before the FOR instruction.
generate_undo_cmdmods(cctx);
// "for_end" is set when ":endfor" is found
scope->se_u.se_for.fs_top_label = current_instr_idx(cctx);
+
generate_FOR(cctx, loop_lvar->lv_idx);
arg = arg_start;
@@ -7893,6 +7902,10 @@
vim_free(name);
}
+ if (cctx->ctx_compile_type == CT_DEBUG)
+ // Add ISN_DEBUG here, so that the loop variables can be inspected.
+ generate_instr_debug(cctx);
+
return arg_end;
failed:
@@ -7927,7 +7940,7 @@
// At end of ":for" scope jump back to the FOR instruction.
generate_JUMP(cctx, JUMP_ALWAYS, forscope->fs_top_label);
- // Fill in the "end" label in the FOR statement so it can jump here
+ // Fill in the "end" label in the FOR statement so it can jump here.
isn = ((isn_T *)instr->ga_data) + forscope->fs_top_label;
isn->isn_arg.forloop.for_end = instr->ga_len;
@@ -8234,6 +8247,7 @@
#ifdef FEAT_PROFILE
// the profile-start should be after the jump
if (cctx->ctx_compile_type == CT_PROFILE
+ && instr->ga_len > 0
&& ((isn_T *)instr->ga_data)[instr->ga_len - 1]
.isn_type == ISN_PROF_START)
--instr->ga_len;