mirror of
https://github.com/neovim/neovim.git
synced 2026-08-26 17:11:48 +00:00
vim-patch:9.2.0996: debugger: crash when evaluating a variable in a :def function frame (#41460)
Problem: In the debugger ">up" and ">frame" select an older function call
frame, but get_funccal_local_ht() and the related functions check
current_funccal while returning a dictionary of the frame that
get_funccal() selected. A :def function keeps its local variables
on the vim9 stack, its funccall_T has no l: and a: dictionaries and
is allocated cleared, so with such a frame selected the returned
hashtab has a NULL ht_array and evaluating any variable name at the
debug prompt crashes in hash_lookup().
Solution: Check the funccal that is actually used and return NULL when it has
no l: variables, so that the variable is reported as undefined
instead.
closes: vim/vim#21111
5ad47b07af
Co-authored-by: Christian Brabandt <cb@256bit.org>
Co-authored-by: Claude Opus 5 (1M context) <noreply@anthropic.com>
This commit is contained in:
@@ -1107,6 +1107,51 @@ func Test_debug_def_and_legacy_function()
|
||||
call StopVimInTerminal(buf)
|
||||
endfunc
|
||||
|
||||
" Test for using "up" in the debugger to select the frame of a :def function
|
||||
" and then evaluating a variable name
|
||||
func Test_debug_backtrace_up_def_function()
|
||||
CheckRunVimInTerminal
|
||||
CheckCWD
|
||||
let file =<< trim END
|
||||
vim9script
|
||||
def g:DefFunc()
|
||||
var defvar = 'in def'
|
||||
g:LegacyFunc('arg')
|
||||
enddef
|
||||
|
||||
func g:LegacyFunc(text)
|
||||
let legacyvar = 'in legacy'
|
||||
echo legacyvar
|
||||
endfunc
|
||||
|
||||
breakadd func 2 g:LegacyFunc
|
||||
END
|
||||
call writefile(file, 'XtestDebugUp.vim', 'D')
|
||||
|
||||
let buf = RunVimInTerminal('-S XtestDebugUp.vim', {})
|
||||
|
||||
call s:RunDbgCmd(buf, ':call DefFunc()', ['line 2: echo legacyvar'])
|
||||
call s:RunDbgCmd(buf, 'echo legacyvar', ['in legacy'])
|
||||
call s:RunDbgCmd(buf, 'echo l:legacyvar', ['in legacy'])
|
||||
call s:RunDbgCmd(buf, 'echo a:text', ['arg'])
|
||||
|
||||
" Move up to the frame of the :def function, the local variables of the
|
||||
" legacy function are not available there. This used to crash.
|
||||
call s:RunDbgCmd(buf, 'up')
|
||||
call s:RunDbgCmd(buf, 'echo legacyvar',
|
||||
\ ['E121: Undefined variable: legacyvar'])
|
||||
call s:RunDbgCmd(buf, 'echo l:legacyvar',
|
||||
\ ['E121: Undefined variable: l:legacyvar'])
|
||||
call s:RunDbgCmd(buf, 'echo a:text', ['E121: Undefined variable: a:text'])
|
||||
|
||||
" Back in the frame of the legacy function the variables are found again.
|
||||
call s:RunDbgCmd(buf, 'down')
|
||||
call s:RunDbgCmd(buf, 'echo legacyvar', ['in legacy'])
|
||||
|
||||
call s:RunDbgCmd(buf, 'cont')
|
||||
call StopVimInTerminal(buf)
|
||||
endfunc
|
||||
|
||||
func Test_debug_def_function()
|
||||
CheckRunVimInTerminal
|
||||
CheckCWD
|
||||
|
||||
Reference in New Issue
Block a user