Newer
Older
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
highlight VimgdbCurrentLine ctermbg=130 guibg=#FFE568
let s:vimgdb_dir = fnamemodify(resolve(expand('<sfile>:p')), ':h:h')
let s:next_session_id = 0
let s:sessions = {}
function! Tapi_vimgdb_goto(bufnum, arglist)
if len(a:arglist) != 3
return
endif
let session_id = a:arglist[0]
let filename = a:arglist[1]
let line = a:arglist[2]
let session = s:sessions[session_id]
" Go to source window and jump to current line
noautocmd call win_gotoid(session['source_winid'])
execute 'edit' fnameescape(filename)
execute 'normal!' line . 'G'
" Update highlighted line
if session['current_line_matchid'] != -1
call matchdelete(session['current_line_matchid'])
endif
let session['current_line_matchid'] = matchaddpos('VimgdbCurrentLine', [line])
" Switch back to debugger window
noautocmd call win_gotoid(bufwinid(a:bufnum))
endfunction
function! s:close_session(session_id)
if !has_key(s:sessions, a:session_id)
return
endif
let session = s:sessions[a:session_id]
if session['current_line_matchid'] != -1
noautocmd call win_gotoid(session['source_winid'])
call matchdelete(session['current_line_matchid'])
endif
endfunction
function! s:vimgdb(mods, gdb_args)
let session_id = s:next_session_id
let s:next_session_id = s:next_session_id + 1
let s:sessions[session_id] = {'source_winid': win_getid(), 'current_line_matchid': -1}
execute a:mods 'terminal' '++close' s:vimgdb_dir . '/gdb/gdb-wrapper' session_id a:gdb_args
execute 'autocmd BufDelete <buffer> call s:close_session(' . session_id . ')'
endfunction
command! -nargs=+ -complete=shellcmd Vimgdb call s:vimgdb('<mods>', "<args>")