comparison src/vim9execute.c @ 24948:5c418c774f95 v8.2.3011

patch 8.2.3011: Vim9: cannot get argument values during debugging Commit: https://github.com/vim/vim/commit/6bc30b05e6081bcaece6d1a7fcfca238ea5a194f Author: Bram Moolenaar <Bram@vim.org> Date: Wed Jun 16 19:19:55 2021 +0200 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.
author Bram Moolenaar <Bram@vim.org>
date Wed, 16 Jun 2021 19:30:04 +0200
parents 345619f35112
children ffe784fdec57
comparison
equal deleted inserted replaced
24947:9de14748d25e 24948:5c418c774f95
1392 // Get pointer to a local variable on the stack. Negative for arguments. 1392 // Get pointer to a local variable on the stack. Negative for arguments.
1393 #define STACK_TV_VAR(idx) (((typval_T *)ectx->ec_stack.ga_data) + ectx->ec_frame_idx + STACK_FRAME_SIZE + idx) 1393 #define STACK_TV_VAR(idx) (((typval_T *)ectx->ec_stack.ga_data) + ectx->ec_frame_idx + STACK_FRAME_SIZE + idx)
1394 1394
1395 // Set when calling do_debug(). 1395 // Set when calling do_debug().
1396 static ectx_T *debug_context = NULL; 1396 static ectx_T *debug_context = NULL;
1397 static int debug_arg_count; 1397 static int debug_var_count;
1398 1398
1399 /* 1399 /*
1400 * When debugging lookup "name" and return the typeval. 1400 * When debugging lookup "name" and return the typeval.
1401 * When not found return NULL. 1401 * When not found return NULL.
1402 */ 1402 */
1403 typval_T * 1403 typval_T *
1404 lookup_debug_var(char_u *name) 1404 lookup_debug_var(char_u *name)
1405 { 1405 {
1406 int idx; 1406 int idx;
1407 dfunc_T *dfunc; 1407 dfunc_T *dfunc;
1408 ufunc_T *ufunc;
1408 ectx_T *ectx = debug_context; 1409 ectx_T *ectx = debug_context;
1410 int varargs_off;
1409 1411
1410 if (ectx == NULL) 1412 if (ectx == NULL)
1411 return NULL; 1413 return NULL;
1412 dfunc = ((dfunc_T *)def_functions.ga_data) + ectx->ec_dfunc_idx; 1414 dfunc = ((dfunc_T *)def_functions.ga_data) + ectx->ec_dfunc_idx;
1413 1415
1414 // Go through the local variable names, from last to first. 1416 // Go through the local variable names, from last to first.
1415 for (idx = debug_arg_count - 1; idx >= 0; --idx) 1417 for (idx = debug_var_count - 1; idx >= 0; --idx)
1416 { 1418 {
1417 char_u *s = ((char_u **)dfunc->df_var_names.ga_data)[idx]; 1419 if (STRCMP(((char_u **)dfunc->df_var_names.ga_data)[idx], name) == 0)
1418 if (STRCMP(s, name) == 0)
1419 return STACK_TV_VAR(idx); 1420 return STACK_TV_VAR(idx);
1420 } 1421 }
1422
1423 // Go through argument names.
1424 ufunc = dfunc->df_ufunc;
1425 varargs_off = ufunc->uf_va_name == NULL ? 0 : 1;
1426 for (idx = 0; idx < ufunc->uf_args.ga_len; ++idx)
1427 if (STRCMP(((char_u **)(ufunc->uf_args.ga_data))[idx], name) == 0)
1428 return STACK_TV(ectx->ec_frame_idx - ufunc->uf_args.ga_len
1429 - varargs_off + idx);
1430 if (ufunc->uf_va_name != NULL && STRCMP(ufunc->uf_va_name, name) == 0)
1431 return STACK_TV(ectx->ec_frame_idx - 1);
1421 1432
1422 return NULL; 1433 return NULL;
1423 } 1434 }
1424 1435
1425 /* 1436 /*
4150 ufunc_T *ufunc = (((dfunc_T *)def_functions.ga_data) 4161 ufunc_T *ufunc = (((dfunc_T *)def_functions.ga_data)
4151 + ectx->ec_dfunc_idx)->df_ufunc; 4162 + ectx->ec_dfunc_idx)->df_ufunc;
4152 4163
4153 SOURCING_LNUM = iptr->isn_lnum; 4164 SOURCING_LNUM = iptr->isn_lnum;
4154 debug_context = ectx; 4165 debug_context = ectx;
4155 debug_arg_count = iptr->isn_arg.number; 4166 debug_var_count = iptr->isn_arg.number;
4156 line = ((char_u **)ufunc->uf_lines.ga_data)[ 4167 line = ((char_u **)ufunc->uf_lines.ga_data)[
4157 iptr->isn_lnum - 1]; 4168 iptr->isn_lnum - 1];
4158 if (line == NULL) 4169 if (line == NULL)
4159 line = (char_u *)"[empty]"; 4170 line = (char_u *)"[empty]";
4160 do_debug(line); 4171 do_debug(line);