Skip to content

Commit 072f1c6

Browse files
committed
patch 8.2.3417: Vim9: a failing debug expression aborts script sourcing
Problem: Vim9: a failing debug expression aborts script sourcing. Solution: Do not let expression failure abort script sourcing. (closes #8848)
1 parent 36f691f commit 072f1c6

File tree

3 files changed

+57
-8
lines changed

3 files changed

+57
-8
lines changed

src/debugger.c

Lines changed: 26 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -530,6 +530,29 @@ static garray_T prof_ga = {0, 0, sizeof(struct debuggy), 4, NULL};
530530

531531
static linenr_T debuggy_find(int file,char_u *fname, linenr_T after, garray_T *gap, int *fp);
532532

533+
/*
534+
* Evaluate the "bp->dbg_name" expression and return the result.
535+
* Restore the got_int and called_emsg flags.
536+
*/
537+
static typval_T *
538+
eval_expr_restore(struct debuggy *bp)
539+
{
540+
typval_T *tv;
541+
int prev_called_emsg = called_emsg;
542+
int prev_did_emsg = did_emsg;
543+
544+
got_int = FALSE;
545+
tv = eval_expr(bp->dbg_name, NULL);
546+
547+
// Evaluating the expression should not result in breaking the sequence of
548+
// commands.
549+
got_int = FALSE;
550+
called_emsg = prev_called_emsg;
551+
did_emsg = prev_did_emsg;
552+
553+
return tv;
554+
}
555+
533556
/*
534557
* Parse the arguments of ":profile", ":breakadd" or ":breakdel" and put them
535558
* in the entry just after the last one in dbg_breakp. Note that "dbg_name"
@@ -614,7 +637,7 @@ dbg_parsearg(
614637
{
615638
bp->dbg_name = vim_strsave(p);
616639
if (bp->dbg_name != NULL)
617-
bp->dbg_val = eval_expr(bp->dbg_name, NULL);
640+
bp->dbg_val = eval_expr_restore(bp);
618641
}
619642
else
620643
{
@@ -960,10 +983,7 @@ debuggy_find(
960983
typval_T *tv;
961984
int line = FALSE;
962985

963-
prev_got_int = got_int;
964-
got_int = FALSE;
965-
966-
tv = eval_expr(bp->dbg_name, NULL);
986+
tv = eval_expr_restore(bp);
967987
if (tv != NULL)
968988
{
969989
if (bp->dbg_val == NULL)
@@ -984,7 +1004,7 @@ debuggy_find(
9841004
debug_oldval = typval_tostring(bp->dbg_val, TRUE);
9851005
// Need to evaluate again, typval_compare() overwrites
9861006
// "tv".
987-
v = eval_expr(bp->dbg_name, NULL);
1007+
v = eval_expr_restore(bp);
9881008
debug_newval = typval_tostring(v, TRUE);
9891009
free_tv(bp->dbg_val);
9901010
bp->dbg_val = v;
@@ -1006,8 +1026,6 @@ debuggy_find(
10061026
lnum = after > 0 ? after : 1;
10071027
break;
10081028
}
1009-
1010-
got_int |= prev_got_int;
10111029
}
10121030
#endif
10131031
}

src/testdir/test_debugger.vim

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -318,7 +318,9 @@ func Test_Debugger()
318318
call RunDbgCmd(buf, 'enew! | only!')
319319

320320
call StopVimInTerminal(buf)
321+
endfunc
321322

323+
func Test_Debugger_breakadd()
322324
" Tests for :breakadd file and :breakadd here
323325
" Breakpoints should be set before sourcing the file
324326

@@ -342,10 +344,37 @@ func Test_Debugger()
342344

343345
call delete('Xtest.vim')
344346
%bw!
347+
345348
call assert_fails('breakadd here', 'E32:')
346349
call assert_fails('breakadd file Xtest.vim /\)/', 'E55:')
347350
endfunc
348351

352+
def Test_Debugger_breakadd_expr()
353+
var lines =<< trim END
354+
vim9script
355+
func g:EarlyFunc()
356+
endfunc
357+
breakadd expr DoesNotExist()
358+
func g:LaterFunc()
359+
endfunc
360+
breakdel *
361+
END
362+
writefile(lines, 'Xtest.vim')
363+
364+
# Start Vim in a terminal
365+
var buf = RunVimInTerminal('-S Xtest.vim', {wait_for_ruler: 0})
366+
call TermWait(buf)
367+
368+
# Despite the failure the functions are defined
369+
RunDbgCmd(buf, ':function g:EarlyFunc',
370+
['function EarlyFunc()', 'endfunction'], {match: 'pattern'})
371+
RunDbgCmd(buf, ':function g:LaterFunc',
372+
['function LaterFunc()', 'endfunction'], {match: 'pattern'})
373+
374+
call StopVimInTerminal(buf)
375+
call delete('Xtest.vim')
376+
enddef
377+
349378
func Test_Backtrace_Through_Source()
350379
CheckCWD
351380
let file1 =<< trim END

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+
3417,
758760
/**/
759761
3416,
760762
/**/

0 commit comments

Comments
 (0)