0
0
mirror of https://github.com/vim/vim.git synced 2025-10-20 08:14:18 -04:00

runtime(termdebug): Add remote debugging capabilities

closes: #18429

Co-authored-by: Christian Brabandt <cb@256bit.org>
Signed-off-by: Miguel Barro <miguel.barro@live.com>
Signed-off-by: Christian Brabandt <cb@256bit.org>
This commit is contained in:
Miguel Barro
2025-10-08 18:15:51 +00:00
committed by Christian Brabandt
parent 143686b3c4
commit 3c5221f8ee
4 changed files with 475 additions and 52 deletions

View File

@@ -689,4 +689,86 @@ func Test_termdebug_toggle_break()
%bw!
endfunc
" Check substitution capabilities and simulate remote debugging
func Test_termdebug_remote_basic()
let bin_name = 'XTD_basicremote'
let src_name = bin_name .. '.c'
call s:generate_files(bin_name)
defer s:cleanup_files(bin_name)
" Duplicate sources to test the mapping
const pwd = getcwd()
const src_shadow_dir = "shadow"
call mkdir(src_shadow_dir)
const src_shadow_file = $"{src_shadow_dir}/{src_name}"
call filecopy(src_name, src_shadow_file)
defer delete(src_shadow_dir, 'rf')
let modes = [v:true]
" termdebug only wokrs fine if socat is available on the remote machine
" otherwise the communication pty will be unstable
if executable('socat')
let modes += [v:false]
endif
for use_prompt in modes
" Set up mock remote and mapping
let g:termdebug_config = {}
let g:termdebug_config['use_prompt'] = use_prompt
" favor socat if available
if executable('socat')
let g:termdebug_config['remote_window'] =
\ ['socat', '-d', '-d', '-', 'PTY,raw,echo=0']
else
let g:termdebug_config['remote_window'] = ['sh']
endif
let g:termdebug_config['substitute_path'] = {}
let g:termdebug_config['substitute_path'][pwd] = pwd . '/' . src_shadow_dir
defer execute("unlet g:termdebug_config")
" Launch the debugger and set breakpoints in the shadow file instead
exe $"edit {src_shadow_file}"
exe $"Termdebug ./{bin_name}"
call WaitForAssert({-> assert_true(get(g:, "termdebug_is_running", v:false))})
call WaitForAssert({-> assert_equal(3, winnr('$'))})
let gdb_buf = winbufnr(1)
wincmd b
Break 9
sleep 100m
redraw!
call assert_equal([
\ {'lnum': 9, 'id': 1014, 'name': 'debugBreakpoint1.0',
\ 'priority': 110, 'group': 'TermDebug'}],
\ sign_getplaced('', #{group: 'TermDebug'})[0].signs)
Run
call term_wait(gdb_buf, 400)
redraw!
call WaitForAssert({-> assert_equal([
\ {'lnum': 9, 'id': 12, 'name': 'debugPC', 'priority': 110,
\ 'group': 'TermDebug'},
\ {'lnum': 9, 'id': 1014, 'name': 'debugBreakpoint1.0',
\ 'priority': 110, 'group': 'TermDebug'}],
\ sign_getplaced('', #{group: 'TermDebug'})[0].signs)})
Finish
call term_wait(gdb_buf)
redraw!
call WaitForAssert({-> assert_equal([
\ {'lnum': 9, 'id': 1014, 'name': 'debugBreakpoint1.0',
\ 'priority': 110, 'group': 'TermDebug'},
\ {'lnum': 20, 'id': 12, 'name': 'debugPC',
\ 'priority': 110, 'group': 'TermDebug'}],
\ sign_getplaced('', #{group: 'TermDebug'})[0].signs)})
" Cleanup, make sure the gdb job is terminated before return
" otherwise may interfere with next test
Gdb
bw!
call WaitForAssert({-> assert_equal(1, winnr('$'))})
endfor
%bw!
endfunc
" vim: shiftwidth=2 sts=2 expandtab