Skip to content

Commit 093165c

Browse files
committed
patch 8.2.3366: Vim9: debugging elseif does not stop before condition
Problem: Vim9: debugging elseif does not stop before condition. Solution: Move debug statement to after the jump. (closes #8781)
1 parent bf5f287 commit 093165c

File tree

3 files changed

+74
-2
lines changed

3 files changed

+74
-2
lines changed

src/testdir/test_vim9_disassemble.vim

Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2255,6 +2255,53 @@ def Test_debugged()
22552255
res)
22562256
enddef
22572257

2258+
def s:DebugElseif()
2259+
var b = false
2260+
if b
2261+
eval 1 + 0
2262+
silent elseif !b
2263+
eval 2 + 0
2264+
endif
2265+
enddef
2266+
2267+
def Test_debug_elseif()
2268+
var res = execute('disass debug s:DebugElseif')
2269+
assert_match('<SNR>\d*_DebugElseif\_s*' ..
2270+
'var b = false\_s*' ..
2271+
'0 DEBUG line 1-1 varcount 0\_s*' ..
2272+
'1 PUSH false\_s*' ..
2273+
'2 STORE $0\_s*' ..
2274+
2275+
'if b\_s*' ..
2276+
'3 DEBUG line 2-2 varcount 1\_s*' ..
2277+
'4 LOAD $0\_s*' ..
2278+
'5 JUMP_IF_FALSE -> 10\_s*' ..
2279+
2280+
'eval 1 + 0\_s*' ..
2281+
'6 DEBUG line 3-3 varcount 1\_s*' ..
2282+
'7 PUSHNR 1\_s*' ..
2283+
'8 DROP\_s*' ..
2284+
2285+
'silent elseif !b\_s*' ..
2286+
'9 JUMP -> 20\_s*' ..
2287+
'10 CMDMOD silent\_s*' ..
2288+
'11 DEBUG line 4-4 varcount 1\_s*' ..
2289+
'12 LOAD $0\_s*' ..
2290+
'13 INVERT -1 (!val)\_s*' ..
2291+
'14 CMDMOD_REV\_s*' ..
2292+
'15 JUMP_IF_FALSE -> 20\_s*' ..
2293+
2294+
'eval 2 + 0\_s*' ..
2295+
'16 DEBUG line 5-5 varcount 1\_s*' ..
2296+
'17 PUSHNR 2\_s*' ..
2297+
'18 DROP\_s*' ..
2298+
2299+
'endif\_s*' ..
2300+
'19 DEBUG line 6-6 varcount 1\_s*' ..
2301+
'20 RETURN void*',
2302+
res)
2303+
enddef
2304+
22582305
def s:EchoMessages()
22592306
echohl ErrorMsg | echom v:exception | echohl NONE
22602307
enddef

src/version.c

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -755,6 +755,8 @@ static char *(features[]) =
755755

756756
static int included_patches[] =
757757
{ /* Add new patch number below this line */
758+
/**/
759+
3366,
758760
/**/
759761
3365,
760762
/**/

src/vim9compile.c

Lines changed: 25 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2387,7 +2387,7 @@ misplaced_cmdmod(cctx_T *cctx)
23872387

23882388
/*
23892389
* Get the index of the current instruction.
2390-
* This compenstates for a preceding ISN_CMDMOD and ISN_PROF_START.
2390+
* This compensates for a preceding ISN_CMDMOD and ISN_PROF_START.
23912391
*/
23922392
static int
23932393
current_instr_idx(cctx_T *cctx)
@@ -7732,7 +7732,9 @@ compile_elseif(char_u *arg, cctx_T *cctx)
77327732

77337733
if (cctx->ctx_skip == SKIP_UNKNOWN)
77347734
{
7735-
int moved_cmdmod = FALSE;
7735+
int moved_cmdmod = FALSE;
7736+
int saved_debug = FALSE;
7737+
isn_T debug_isn;
77367738

77377739
// Move any CMDMOD instruction to after the jump
77387740
if (((isn_T *)instr->ga_data)[instr->ga_len - 1].isn_type == ISN_CMDMOD)
@@ -7745,14 +7747,35 @@ compile_elseif(char_u *arg, cctx_T *cctx)
77457747
moved_cmdmod = TRUE;
77467748
}
77477749

7750+
// Remove the already generated ISN_DEBUG, it is written below the
7751+
// ISN_FOR instruction.
7752+
if (cctx->ctx_compile_type == CT_DEBUG && instr->ga_len > 0
7753+
&& ((isn_T *)instr->ga_data)[instr->ga_len - 1]
7754+
.isn_type == ISN_DEBUG)
7755+
{
7756+
--instr->ga_len;
7757+
debug_isn = ((isn_T *)instr->ga_data)[instr->ga_len];
7758+
saved_debug = TRUE;
7759+
}
7760+
77487761
if (compile_jump_to_end(&scope->se_u.se_if.is_end_label,
77497762
JUMP_ALWAYS, cctx) == FAIL)
77507763
return NULL;
77517764
// previous "if" or "elseif" jumps here
77527765
isn = ((isn_T *)instr->ga_data) + scope->se_u.se_if.is_if_label;
77537766
isn->isn_arg.jump.jump_where = instr->ga_len;
7767+
77547768
if (moved_cmdmod)
77557769
++instr->ga_len;
7770+
7771+
if (saved_debug)
7772+
{
7773+
// move the debug instruction here
7774+
if (GA_GROW_FAILS(instr, 1))
7775+
return NULL;
7776+
((isn_T *)instr->ga_data)[instr->ga_len] = debug_isn;
7777+
++instr->ga_len;
7778+
}
77567779
}
77577780

77587781
// compile "expr"; if we know it evaluates to FALSE skip the block

0 commit comments

Comments
 (0)