vim-patch:8.2.3419: a failing debug expression may make Vim unusable

Problem:    A failing debug expression may make Vim unusable.
Solution:   Suppress error messages. (closes vim/vim#8848)
0325d3967c
This commit is contained in:
Sean Dewar
2021-09-13 17:09:15 +01:00
parent 936c4ae151
commit 31ac33bf77
2 changed files with 9 additions and 19 deletions

View File

@@ -454,22 +454,14 @@ static garray_T prof_ga = { 0, 0, sizeof(struct debuggy), 4, NULL };
#define DBG_EXPR 3 #define DBG_EXPR 3
/// Evaluate the "bp->dbg_name" expression and return the result. /// Evaluate the "bp->dbg_name" expression and return the result.
/// Restore the got_int and called_emsg flags. /// Disables error messages.
static typval_T *eval_expr_restore(struct debuggy *const bp) static typval_T *eval_expr_no_emsg(struct debuggy *const bp)
FUNC_ATTR_NONNULL_ALL FUNC_ATTR_NONNULL_ALL
{ {
const int prev_called_emsg = called_emsg; // Disable error messages, a bad expression would make Vim unusable.
const int prev_did_emsg = did_emsg; emsg_off++;
got_int = false;
typval_T *const tv = eval_expr(bp->dbg_name); typval_T *const tv = eval_expr(bp->dbg_name);
emsg_off--;
// Evaluating the expression should not result in breaking the sequence of
// commands.
got_int = false;
called_emsg = prev_called_emsg;
did_emsg = prev_did_emsg;
return tv; return tv;
} }
@@ -535,7 +527,7 @@ static int dbg_parsearg(char_u *arg, garray_T *gap)
bp->dbg_name = vim_strsave(curbuf->b_ffname); bp->dbg_name = vim_strsave(curbuf->b_ffname);
} else if (bp->dbg_type == DBG_EXPR) { } else if (bp->dbg_type == DBG_EXPR) {
bp->dbg_name = vim_strsave(p); bp->dbg_name = vim_strsave(p);
bp->dbg_val = eval_expr_restore(bp); bp->dbg_val = eval_expr_no_emsg(bp);
} else { } else {
// Expand the file name in the same way as do_source(). This means // Expand the file name in the same way as do_source(). This means
// doing it twice, so that $DIR/file gets expanded when $DIR is // doing it twice, so that $DIR/file gets expanded when $DIR is
@@ -791,7 +783,7 @@ debuggy_find(
} else if (bp->dbg_type == DBG_EXPR) { } else if (bp->dbg_type == DBG_EXPR) {
bool line = false; bool line = false;
typval_T *const tv = eval_expr_restore(bp); typval_T *const tv = eval_expr_no_emsg(bp);
if (tv != NULL) { if (tv != NULL) {
if (bp->dbg_val == NULL) { if (bp->dbg_val == NULL) {
debug_oldval = typval_tostring(NULL); debug_oldval = typval_tostring(NULL);
@@ -804,7 +796,7 @@ debuggy_find(
line = true; line = true;
debug_oldval = typval_tostring(bp->dbg_val); debug_oldval = typval_tostring(bp->dbg_val);
// Need to evaluate again, typval_compare() overwrites "tv". // Need to evaluate again, typval_compare() overwrites "tv".
typval_T *const v = eval_expr_restore(bp); typval_T *const v = eval_expr_no_emsg(bp);
debug_newval = typval_tostring(v); debug_newval = typval_tostring(v);
tv_free(bp->dbg_val); tv_free(bp->dbg_val);
bp->dbg_val = v; bp->dbg_val = v;

View File

@@ -267,9 +267,7 @@ func Test_Debugger()
call RunDbgCmd(buf, 'breakd func a()', ['E475: Invalid argument: func a()']) call RunDbgCmd(buf, 'breakd func a()', ['E475: Invalid argument: func a()'])
call RunDbgCmd(buf, 'breakd func a', ['E161: Breakpoint not found: func a']) call RunDbgCmd(buf, 'breakd func a', ['E161: Breakpoint not found: func a'])
call RunDbgCmd(buf, 'breakd expr', ['E475: Invalid argument: expr']) call RunDbgCmd(buf, 'breakd expr', ['E475: Invalid argument: expr'])
call RunDbgCmd(buf, 'breakd expr x', [ call RunDbgCmd(buf, 'breakd expr x', ['E161: Breakpoint not found: expr x'])
\ 'E121: Undefined variable: x',
\ 'E161: Breakpoint not found: expr x'])
" finish the current function " finish the current function
call RunDbgCmd(buf, 'finish', [ call RunDbgCmd(buf, 'finish', [